feed-common 1.20.5 → 1.22.0

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.0](https://github.com/advertikon/package-maxify-feed-common/compare/v1.21.0...v1.22.0) (2024-07-28)
2
+
3
+
4
+ ### Features
5
+
6
+ * add metafield support to macro parser ([c85df83](https://github.com/advertikon/package-maxify-feed-common/commit/c85df83ecea5c6599afad706f99332646fc63e2b))
7
+
8
+ # [1.21.0](https://github.com/advertikon/package-maxify-feed-common/compare/v1.20.5...v1.21.0) (2024-07-28)
9
+
10
+
11
+ ### Features
12
+
13
+ * add metafield subtype to MacroPartType ([544f0a8](https://github.com/advertikon/package-maxify-feed-common/commit/544f0a8bbede6c9c2516f4a89feb3acf16ed33eb))
14
+
1
15
  ## [1.20.5](https://github.com/advertikon/package-maxify-feed-common/compare/v1.20.4...v1.20.5) (2024-07-24)
2
16
 
3
17
 
@@ -71,7 +71,7 @@ export declare enum XMLFeedType {
71
71
  export type MacroPartType = {
72
72
  content: string;
73
73
  type: 'macro' | 'string';
74
- subtype?: 'mapping' | 'action';
74
+ subtype?: 'mapping' | 'action' | 'metafield';
75
75
  };
76
76
  export type XmlFeedEntryType = {
77
77
  id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"profile.types.d.ts","sourceRoot":"","sources":["../../src/types/profile.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,KAAK,CAAC;AAE1C,MAAM,MAAM,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1D,MAAM,MAAM,6BAA6B,GAAG,UAAU,CAAC;AAEvD,MAAM,MAAM,2BAA2B,GAAG;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,6BAA6B,EAAE,CAAC;IAC3C,KAAK,E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AC1D,CAAC;AAEF,oBAAY,WAAW;IACnB,MAAM,WAAW;IACjB,QAAQ,aAAa;CACxB;AAED,MAAM,MAAM,aAAa,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAC;IACzB,OAAO,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,WAAW,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,GAAC,MAAM,KAAK,mBAAmB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9D,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,kBAAkB,CAAC;CAC9B,CAAC"}
@@ -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 'meta':
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,CA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AE/D,IAAI,UAAU,KAAK,CAAC,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,MAAM;YACP,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.20.5",
3
+ "version": "1.22.0",
4
4
  "description": "Maxify feed common library",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -76,7 +76,7 @@ export enum XMLFeedType {
76
76
  export type MacroPartType = {
77
77
  content: string;
78
78
  type: 'macro' | 'string';
79
- subtype?: 'mapping' | 'action';
79
+ subtype?: 'mapping' | 'action' | 'metafield';
80
80
  };
81
81
 
82
82
  export type XmlFeedEntryType = {
@@ -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 'meta':
74
+ return 'metafield';
75
+ default:
76
+ return 'mapping';
77
+ }
72
78
  }