1
0
Эх сурвалжийг харах

feat: support new line in http request block

Ahmad Kholid 2 жил өмнө
parent
commit
5ecb52609e

+ 1 - 1
package.json

@@ -30,7 +30,7 @@
     "*.{js,ts,vue}": "eslint --fix"
   },
   "dependencies": {
-    "@braks/vue-flow": "^0.4.27",
+    "@braks/vue-flow": "^0.4.30",
     "@codemirror/lang-javascript": "^6.0.0",
     "@codemirror/lang-json": "^6.0.0",
     "@codemirror/language": "^6.0.0",

+ 3 - 2
src/utils/referenceData/index.js

@@ -6,6 +6,7 @@ export default function ({ block, refKeys, data }) {
   if (!refKeys || refKeys.length === 0) return block;
 
   const copyBlock = cloneDeep(block);
+  const options = { stringify: block.label === 'webhook' };
   const addReplacedValue = (value) => {
     if (!copyBlock.replacedValue) copyBlock.replacedValue = {};
 
@@ -19,7 +20,7 @@ export default function ({ block, refKeys, data }) {
 
     if (Array.isArray(currentData)) {
       currentData.forEach((str, index) => {
-        const replacedStr = mustacheReplacer(str, data);
+        const replacedStr = mustacheReplacer(str, data, options);
 
         addReplacedValue(replacedStr.list);
         objectPath.set(
@@ -29,7 +30,7 @@ export default function ({ block, refKeys, data }) {
         );
       });
     } else if (typeof currentData === 'string') {
-      const replacedStr = mustacheReplacer(currentData, data);
+      const replacedStr = mustacheReplacer(currentData, data, options);
 
       addReplacedValue(replacedStr.list);
       objectPath.set(copyBlock.data, blockDataKey, replacedStr.value);

+ 17 - 4
src/utils/referenceData/mustacheReplacer.js

@@ -156,13 +156,13 @@ export function keyParser(key, data) {
   return { dataKey: 'table', path };
 }
 
-function replacer(str, { regex, tagLen, modifyPath, data }) {
+function replacer(str, { regex, tagLen, modifyPath, data, stringify }) {
   const replaceResult = {
     list: {},
     value: str,
   };
 
-  replaceResult.value = str.replace(regex, (match) => {
+  replaceResult.value = str.replace(regex, (match, p1, offset) => {
     let key = match.slice(tagLen, -tagLen).trim();
 
     if (!key) return '';
@@ -195,7 +195,19 @@ function replacer(str, { regex, tagLen, modifyPath, data }) {
       result = objectPath.get(data[dataKey], path) ?? match;
     }
 
-    result = typeof result === 'string' ? result : JSON.stringify(result);
+    result =
+      typeof result === 'string' && !stringify
+        ? result
+        : JSON.stringify(result);
+
+    if (stringify) {
+      const isQuote = (char) => char === '"';
+      const isInsideQuote =
+        isQuote(str[offset - 1]) && isQuote(str[match.length + offset]);
+
+      if (isInsideQuote) result = result.slice(1, -1);
+    }
+
     replaceResult.list[match] = result?.slice(0, 512) ?? result;
 
     return result;
@@ -204,7 +216,7 @@ function replacer(str, { regex, tagLen, modifyPath, data }) {
   return replaceResult;
 }
 
-export default function (str, refData) {
+export default function (str, refData, { stringify = false } = {}) {
   if (!str || typeof str !== 'string') return '';
 
   const data = { ...refData, functions };
@@ -213,6 +225,7 @@ export default function (str, refData) {
   const replacedStr = replacer(`${str}`, {
     data,
     tagLen: 2,
+    stringify,
     regex: /\{\{(.*?)\}\}/g,
     modifyPath: (path) => {
       const { value, list } = replacer(path, {

+ 3 - 0
src/utils/webhookUtil.js

@@ -14,6 +14,9 @@ const renderContent = (content, contentType) => {
 
 const filterHeaders = (headers) => {
   const filteredHeaders = {};
+
+  if (!headers) return filteredHeaders;
+
   headers.forEach((item) => {
     if (item.name && item.value) {
       filteredHeaders[item.name] = item.value;

+ 22 - 22
yarn.lock

@@ -907,12 +907,12 @@
     "@babel/helper-validator-identifier" "^7.18.6"
     to-fast-properties "^2.0.0"
 
-"@braks/vue-flow@^0.4.27":
-  version "0.4.27"
-  resolved "https://registry.yarnpkg.com/@braks/vue-flow/-/vue-flow-0.4.27.tgz#4f3b6ad14c9f3c65dc593490a141bd2c5d048438"
-  integrity sha512-iM54qI6pX7tOV2XQuMXETKePankHOy99DYDLBo4lCM5V7msNqcRwdiQDGbGTVCHgm0vTGaUzHh3Rr2skZ+SZyg==
+"@braks/vue-flow@^0.4.30":
+  version "0.4.30"
+  resolved "https://registry.yarnpkg.com/@braks/vue-flow/-/vue-flow-0.4.30.tgz#8412ad52ace44413e8301b70c74f9ce6fee55bf9"
+  integrity sha512-e+rlnGj+9MvDCAioUF08GgpENCJ5E322knHD3azXHwmyUMk5wUR6id5ULSQ3ySl9m2NR4oouOL3BxiivIa7i9A==
   dependencies:
-    "@vueuse/core" "^8.7.5"
+    "@vueuse/core" "^8.9.4"
     d3-drag "^3.0.0"
     d3-selection "^3.0.0"
     d3-zoom "^3.0.0"
@@ -1734,20 +1734,20 @@
   resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.2.37.tgz#8e6adc3f2759af52f0e85863dfb0b711ecc5c702"
   integrity sha512-4rSJemR2NQIo9Klm1vabqWjD8rs/ZaJSzMxkMNeJS6lHiUjjUeYFbooN19NgFjztubEKh3WlZUeOLVdbbUWHsw==
 
-"@vueuse/core@^8.7.5":
-  version "8.7.5"
-  resolved "https://registry.yarnpkg.com/@vueuse/core/-/core-8.7.5.tgz#e74a888251ea11a9d432068ce18cbdfc4f810251"
-  integrity sha512-tqgzeZGoZcXzoit4kOGLWJibDMLp0vdm6ZO41SSUQhkhtrPhAg6dbIEPiahhUu6sZAmSYvVrZgEr5aKD51nrLA==
+"@vueuse/core@^8.9.4":
+  version "8.9.4"
+  resolved "https://registry.yarnpkg.com/@vueuse/core/-/core-8.9.4.tgz#c7db40f19390b3c9f4ff9294a30461497f62ec19"
+  integrity sha512-B/Mdj9TK1peFyWaPof+Zf/mP9XuGAngaJZBwPaXBvU3aCTZlx3ltlrFFFyMV4iGBwsjSCeUCgZrtkEj9dS2Y3Q==
   dependencies:
     "@types/web-bluetooth" "^0.0.14"
-    "@vueuse/metadata" "8.7.5"
-    "@vueuse/shared" "8.7.5"
+    "@vueuse/metadata" "8.9.4"
+    "@vueuse/shared" "8.9.4"
     vue-demi "*"
 
-"@vueuse/metadata@8.7.5":
-  version "8.7.5"
-  resolved "https://registry.yarnpkg.com/@vueuse/metadata/-/metadata-8.7.5.tgz#c7f2b21d873d1604a8860ed9c5728d8f3295f00a"
-  integrity sha512-emJZKRQSaEnVqmlu39NpNp8iaW+bPC2kWykWoWOZMSlO/0QVEmO/rt8A5VhOEJTKLX3vwTevqbiRy9WJRwVOQg==
+"@vueuse/metadata@8.9.4":
+  version "8.9.4"
+  resolved "https://registry.yarnpkg.com/@vueuse/metadata/-/metadata-8.9.4.tgz#a4132db33e4c1b1023636acfa20aa7b37ab3d978"
+  integrity sha512-IwSfzH80bnJMzqhaapqJl9JRIiyQU0zsRGEgnxN6jhq7992cPUJIRfV+JHRIZXjYqbwt07E1gTEp0R0zPJ1aqw==
 
 "@vueuse/rxjs@^8.9.2":
   version "8.9.2"
@@ -1757,13 +1757,6 @@
     "@vueuse/shared" "8.9.2"
     vue-demi "*"
 
-"@vueuse/shared@8.7.5":
-  version "8.7.5"
-  resolved "https://registry.yarnpkg.com/@vueuse/shared/-/shared-8.7.5.tgz#06fb08f6f8fc9e90be9d1e033fa443de927172b0"
-  integrity sha512-THXPvMBFmg6Gf6AwRn/EdTh2mhqwjGsB2Yfp374LNQSQVKRHtnJ0I42bsZTn7nuEliBxqUrGQm/lN6qUHmhJLw==
-  dependencies:
-    vue-demi "*"
-
 "@vueuse/shared@8.9.2":
   version "8.9.2"
   resolved "https://registry.yarnpkg.com/@vueuse/shared/-/shared-8.9.2.tgz#d8a46f73ae2a971754ea9572505239bfbc311e2a"
@@ -1771,6 +1764,13 @@
   dependencies:
     vue-demi "*"
 
+"@vueuse/shared@8.9.4":
+  version "8.9.4"
+  resolved "https://registry.yarnpkg.com/@vueuse/shared/-/shared-8.9.4.tgz#c9741c30ffb666b50d62f0dd80b76119fd47573e"
+  integrity sha512-wt+T30c4K6dGRMVqPddexEVLa28YwxW5OFIPmzUHICjphfAuBFTTdDoyqREZNDOFJZ44ARH1WWQNCUK8koJ+Ag==
+  dependencies:
+    vue-demi "*"
+
 "@vuex-orm/core@^0.36.4":
   version "0.36.4"
   resolved "https://registry.yarnpkg.com/@vuex-orm/core/-/core-0.36.4.tgz#9e2b1b8dfd74c2a508f1862ffa3e4a2c1e4cc60c"