feed-common 1.21.0 → 1.22.1

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.22.1](https://github.com/advertikon/package-maxify-feed-common/compare/v1.22.0...v1.22.1) (2024-07-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * fix metafield parser ([ded430a](https://github.com/advertikon/package-maxify-feed-common/commit/ded430a194d1ac20eb467cf60be94e291c6ae099))
7
+
8
+ # [1.22.0](https://github.com/advertikon/package-maxify-feed-common/compare/v1.21.0...v1.22.0) (2024-07-28)
9
+
10
+
11
+ ### Features
12
+
13
+ * add metafield support to macro parser ([c85df83](https://github.com/advertikon/package-maxify-feed-common/commit/c85df83ecea5c6599afad706f99332646fc63e2b))
14
+
1
15
  # [1.21.0](https://github.com/advertikon/package-maxify-feed-common/compare/v1.20.5...v1.21.0) (2024-07-28)
2
16
 
3
17
 
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,wBAAgB,IAAI,WAEnB;AAED,wBAAgB,iBAAiB,CAAE,WAAW,EAAE,MAAM,GAAG,aAAa,EAAE,CAiEvE"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,wBAAgB,IAAI,WAEnB;AAED,wBAAgB,iBAAiB,CAAE,WAAW,EAAE,MAAM,GAAG,aAAa,EAAE,CA4DvE"}
@@ -7,10 +7,12 @@ export function parseMacrosString(textContent) {
7
7
  let startPos = 0;
8
8
  const parts = [];
9
9
  if (!textContent) {
10
- return [{
10
+ return [
11
+ {
11
12
  content: '',
12
13
  type: 'string',
13
- }];
14
+ },
15
+ ];
14
16
  }
15
17
  while (startPos !== -1 && startPos < textContent.length) {
16
18
  const nextStartPos = textContent.indexOf(openTag, startPos);
@@ -40,10 +42,20 @@ export function parseMacrosString(textContent) {
40
42
  parts.push({
41
43
  content: tagValue.trim(),
42
44
  type: 'macro',
43
- subtype: tagValue.trim().split('.')[0] === 'action' ? 'action' : 'mapping',
45
+ subtype: getMacroSubtype(tagValue),
44
46
  });
45
47
  startPos = nextEndPos + closeTag.length;
46
48
  }
47
49
  return parts;
48
50
  }
51
+ function getMacroSubtype(tagValue) {
52
+ switch (tagValue.trim().split('.')[0]) {
53
+ case 'action':
54
+ return 'action';
55
+ case 'metafield':
56
+ return 'metafield';
57
+ default:
58
+ return 'mapping';
59
+ }
60
+ }
49
61
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAE,WAAmB;IACpD,MAAM,OAAO,GAAG,IAAI,CAAC;IACrB,MAAM,QAAQ,GAAG,IAAI,CAAC;IACtB,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,MAAM,KAAK,GAAoB,EAAE,CAAC;IAElC,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,CAAC;gBACN,OAAO,EAAE,EAAE;gBACX,IAAI,EAAE,QAAQ;aACf,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,QAAQ,KAAK,CAAC,CAAC,IAAI,QAAQ,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC;QACxD,MAAM,YAAY,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAE5D,IAAI,YAAY,KAAK,CAAC,CAAC,EAAE,CAAC;YACxB,KAAK,CAAC,IAAI,CAAC;gBACT,OAAO,E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,CAAC,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CACX,oDAAoD,WAAW,mBAAmB,YAAY,EAAE,CACnG,CAAC;QACN,CAAC;QAED,wGAAwG;QACxG,MAAM,mBAAmB,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAExF,IAAI,mBAAmB,KAAK,CAAC,CAAC,IAAI,mBAAmB,GAAG,UAAU,EAAE,CAAC;YACjE,MAAM,IAAI,KAAK,CACX,6DAA6D,WAAW,mBAAmB,YAAY,EAAE,CAC5G,CAAC;QACN,CAAC;QAED,MAAM,QAAQ,GAAG,WAAW,CAAC,SAAS,CAAC,YAAY,GAAG,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAElF,KAAK,CAAC,IAAI,CAAC;YACP,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE;YACxB,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,eAAe,CAAC,QAAQ,CAAC;SACrC,CAAC,CAAC;QAEH,QAAQ,GAAG,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC5C,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,eAAe,CAAE,QAAgB;IACtC,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACpC,KAAK,QAAQ;YACT,OAAO,QAAQ,CAAC;QACpB,KAAK,WAAW;YACZ,OAAO,WAAW,CAAC;QACvB;YACI,OAAO,SAAS,CAAC;IACzB,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feed-common",
3
- "version": "1.21.0",
3
+ "version": "1.22.1",
4
4
  "description": "Maxify feed common library",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -1,72 +1,78 @@
1
1
  import { MacroPartType } from '../types/profile.types.js';
2
2
 
3
3
  export function code () {
4
- return (Math.random() * 1000000).toFixed(0);
4
+ return (Math.random() * 1000000).toFixed(0);
5
5
  }
6
6
 
7
7
  export function parseMacrosString (textContent: string): MacroPartType[] {
8
- const openTag = '{{';
9
- const closeTag = '}}';
10
- let startPos = 0;
11
- const parts: MacroPartType[] = [];
8
+ const openTag = '{{';
9
+ const closeTag = '}}';
10
+ let startPos = 0;
11
+ const parts: MacroPartType[] = [];
12
12
 
13
- if (!textContent) {
14
- return [{
15
- content: '',
16
- type: 'string',
17
- }]
18
- }
13
+ if (!textContent) {
14
+ return [
15
+ {
16
+ content: '',
17
+ type: 'string',
18
+ },
19
+ ];
20
+ }
19
21
 
20
- while (startPos !== -1 && startPos < textContent.length) {
21
- const nextStartPos = textContent.indexOf(openTag, startPos);
22
+ while (startPos !== -1 && startPos < textContent.length) {
23
+ const nextStartPos = textContent.indexOf(openTag, startPos);
22
24
 
23
- if (nextStartPos === -1) {
24
- parts.push({
25
- content: textContent.substring(startPos),
26
- type: 'string',
27
- });
28
- break;
29
- } else if (nextStartPos > startPos) {
30
- parts.push({
31
- content: textContent.substring(startPos, nextStartPos),
32
- type: 'string',
33
- });
34
- }
25
+ if (nextStartPos === -1) {
26
+ parts.push({
27
+ content: textContent.substring(startPos),
28
+ type: 'string',
29
+ });
30
+ break;
31
+ } else if (nextStartPos > startPos) {
32
+ parts.push({
33
+ content: textContent.substring(startPos, nextStartPos),
34
+ type: 'string',
35
+ });
36
+ }
35
37
 
36
- const nextEndPos = textContent.indexOf(closeTag, nextStartPos);
38
+ const nextEndPos = textContent.indexOf(closeTag, nextStartPos);
37
39
 
38
- if (nextEndPos === -1) {
39
- throw new Error(
40
- `[TAG PARSER] Cannot find closing tag for string '${textContent}' starting from ${nextStartPos}`
41
- );
42
- }
40
+ if (nextEndPos === -1) {
41
+ throw new Error(
42
+ `[TAG PARSER] Cannot find closing tag for string '${textContent}' starting from ${nextStartPos}`
43
+ );
44
+ }
43
45
 
44
- // console.log('check for nex opening tag', textContent.indexOf(openTag, nextStartPos + openTag.length))
45
- const checkNextOpeningTag = textContent.indexOf(
46
- openTag,
47
- nextStartPos + openTag.length
48
- );
46
+ // console.log('check for nex opening tag', textContent.indexOf(openTag, nextStartPos + openTag.length))
47
+ const checkNextOpeningTag = textContent.indexOf(openTag, nextStartPos + openTag.length);
49
48
 
50
- if (checkNextOpeningTag !== -1 && checkNextOpeningTag < nextEndPos) {
51
- throw new Error(
52
- `[TAG PARSER] Expecting closing tag, found opening tag in '${textContent}' starting from ${nextStartPos}`
53
- );
54
- }
49
+ if (checkNextOpeningTag !== -1 && checkNextOpeningTag < nextEndPos) {
50
+ throw new Error(
51
+ `[TAG PARSER] Expecting closing tag, found opening tag in '${textContent}' starting from ${nextStartPos}`
52
+ );
53
+ }
55
54
 
56
- const tagValue = textContent.substring(
57
- nextStartPos + openTag.length,
58
- nextEndPos
59
- );
55
+ const tagValue = textContent.substring(nextStartPos + openTag.length, nextEndPos);
60
56
 
61
- parts.push({
62
- content: tagValue.trim(),
63
- type: 'macro',
64
- subtype:
65
- tagValue.trim().split('.')[0] === 'action' ? 'action' : 'mapping',
66
- });
57
+ parts.push({
58
+ content: tagValue.trim(),
59
+ type: 'macro',
60
+ subtype: getMacroSubtype(tagValue),
61
+ });
67
62
 
68
- startPos = nextEndPos + closeTag.length;
69
- }
63
+ startPos = nextEndPos + closeTag.length;
64
+ }
65
+
66
+ return parts;
67
+ }
70
68
 
71
- return parts;
69
+ function getMacroSubtype (tagValue: string): MacroPartType['subtype'] {
70
+ switch (tagValue.trim().split('.')[0]) {
71
+ case 'action':
72
+ return 'action';
73
+ case 'metafield':
74
+ return 'metafield';
75
+ default:
76
+ return 'mapping';
77
+ }
72
78
  }