feed-common 1.17.0 → 1.18.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,10 @@
1
+ # [1.18.0](https://github.com/advertikon/package-maxify-feed-common/compare/v1.17.0...v1.18.0) (2024-07-03)
2
+
3
+
4
+ ### Features
5
+
6
+ * add format macro helper function ([9336462](https://github.com/advertikon/package-maxify-feed-common/commit/9336462ee3fe381f17402b19467fe055b8625ace))
7
+
1
8
  # [1.17.0](https://github.com/advertikon/package-maxify-feed-common/compare/v1.16.2...v1.17.0) (2024-07-01)
2
9
 
3
10
 
@@ -26,7 +26,7 @@ export type ProductUploadMapSource = {
26
26
  required: boolean;
27
27
  label: string;
28
28
  attribute: string;
29
- type: 'select' | 'multiselect' | 'text' | 'number';
29
+ type: 'select' | 'multiselect' | 'text' | 'number' | 'macro-input';
30
30
  choices?: OptionType[];
31
31
  rules: ProductUploadRuleFilterType['value'][];
32
32
  description?: string;
@@ -67,5 +67,10 @@ export declare enum XMLFeedType {
67
67
  Custom = "Custom",
68
68
  Facebook = "Facebook"
69
69
  }
70
+ export type MacroPartType = {
71
+ content: string;
72
+ type: 'macro' | 'string';
73
+ subtype?: 'mapping' | 'action';
74
+ };
70
75
  export {};
71
76
  //# sourceMappingURL=profile.types.d.ts.map
@@ -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;AAEzF,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,EAAE,MAAM,CAAC;IACd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O,CAAC;IAChB,KAAK,EAAE,kBAAkB,CAAC;IAC1B,QAAQ,EAAE,oBAAoB,EAAE,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,wBAAwB,GAAG;IAC1D,iBAAiB,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAE/C,MAAM,MAAM,kBAAkB,GAAG;IAC7B,QAAQ,EAAE,wBAAwB,EAAE,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,qBAAqB,EAAE,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC;CAC1D,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,CAAC;CAClC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"profile.types.js","sourceRoot":"","sources":["../../src/types/profile.types.ts"],"names":[],"mappings":"AAsEA,MAAM,CAAN,IAAY,WAGT;AAHH,WAAY,WAAW;IACnB,gCAAiB,CAAA;IACjB,oCAAqB,CAAA;AACvB,CAAC,EAHS,WAAW,KAAX,WAAW,QAGpB"}
1
+ {"version":3,"file":"profile.types.js","sourceRoot":"","sources":["../../src/types/profile.types.ts"],"names":[],"mappings":"AAqEA,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACnB,gCAAiB,CAAA;IACjB,oCAAqB,CAAA;AACzB,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB"}
@@ -1,2 +1,4 @@
1
+ import { MacroPartType } from '../types/profile.types.js';
1
2
  export declare function code(): string;
3
+ export declare function parseMacrosString(textContent: string): MacroPartType[];
2
4
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,IAAI,WAEnB"}
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,CA0DvE"}
@@ -1,4 +1,43 @@
1
1
  export function code() {
2
2
  return (Math.random() * 1000000).toFixed(0);
3
3
  }
4
+ export function parseMacrosString(textContent) {
5
+ const openTag = '{{';
6
+ const closeTag = '}}';
7
+ let startPos = 0;
8
+ const parts = [];
9
+ while (startPos !== -1 && startPos < textContent.length) {
10
+ const nextStartPos = textContent.indexOf(openTag, startPos);
11
+ if (nextStartPos === -1) {
12
+ parts.push({
13
+ content: textContent.substring(startPos),
14
+ type: 'string',
15
+ });
16
+ break;
17
+ }
18
+ else if (nextStartPos > startPos) {
19
+ parts.push({
20
+ content: textContent.substring(startPos, nextStartPos),
21
+ type: 'string',
22
+ });
23
+ }
24
+ const nextEndPos = textContent.indexOf(closeTag, nextStartPos);
25
+ if (nextEndPos === -1) {
26
+ throw new Error(`[TAG PARSER] Cannot find closing tag for string '${textContent}' starting from ${nextStartPos}`);
27
+ }
28
+ // console.log('check for nex opening tag', textContent.indexOf(openTag, nextStartPos + openTag.length))
29
+ const checkNextOpeningTag = textContent.indexOf(openTag, nextStartPos + openTag.length);
30
+ if (checkNextOpeningTag !== -1 && checkNextOpeningTag < nextEndPos) {
31
+ throw new Error(`[TAG PARSER] Expecting closing tag, found opening tag in '${textContent}' starting from ${nextStartPos}`);
32
+ }
33
+ const tagValue = textContent.substring(nextStartPos + openTag.length, nextEndPos);
34
+ parts.push({
35
+ content: tagValue.trim(),
36
+ type: 'macro',
37
+ subtype: tagValue.trim().split('.')[0] === 'action' ? 'action' : 'mapping',
38
+ });
39
+ startPos = nextEndPos + closeTag.length;
40
+ }
41
+ return parts;
42
+ }
4
43
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC"}
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,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,EAAE,WAAW,CAAC,SAAS,CAAC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AC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feed-common",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "description": "Maxify feed common library",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -21,7 +21,7 @@ export type ProductUploadMapSource = {
21
21
  required: boolean;
22
22
  label: string;
23
23
  attribute: string;
24
- type: 'select' | 'multiselect' | 'text' | 'number';
24
+ type: 'select' | 'multiselect' | 'text' | 'number' | 'macro-input';
25
25
  choices?: OptionType[];
26
26
  rules: ProductUploadRuleFilterType['value'][];
27
27
  description?: string;
@@ -45,11 +45,11 @@ export type BaseProductUploadProfile = {
45
45
  mappings: ProductUploadMapping[];
46
46
  };
47
47
 
48
- export type ProductUploadProfile = BaseProductUploadProfile & {
48
+ export type ProductUploadProfile = BaseProductUploadProfile & {
49
49
  profileIdTemplate: string;
50
50
  };
51
51
 
52
- export type XmlFeed = BaseProductUploadProfile;
52
+ export type XmlFeed = BaseProductUploadProfile;
53
53
 
54
54
  export type ProductUploadRules = {
55
55
  sections: ProductUploadRuleSection[];
@@ -67,8 +67,13 @@ export type ProductUploadRuleItem = {
67
67
  value: string | number | string[] | number[] | boolean;
68
68
  };
69
69
 
70
-
71
70
  export enum XMLFeedType {
72
71
  Custom = 'Custom',
73
72
  Facebook = 'Facebook',
74
- }
73
+ }
74
+
75
+ export type MacroPartType = {
76
+ content: string;
77
+ type: 'macro' | 'string';
78
+ subtype?: 'mapping' | 'action';
79
+ };
@@ -1,3 +1,65 @@
1
+ import { MacroPartType } from '../types/profile.types.js';
2
+
1
3
  export function code () {
2
4
  return (Math.random() * 1000000).toFixed(0);
3
5
  }
6
+
7
+ export function parseMacrosString (textContent: string): MacroPartType[] {
8
+ const openTag = '{{';
9
+ const closeTag = '}}';
10
+ let startPos = 0;
11
+ const parts: MacroPartType[] = [];
12
+
13
+ while (startPos !== -1 && startPos < textContent.length) {
14
+ const nextStartPos = textContent.indexOf(openTag, startPos);
15
+
16
+ if (nextStartPos === -1) {
17
+ parts.push({
18
+ content: textContent.substring(startPos),
19
+ type: 'string',
20
+ });
21
+ break;
22
+ } else if (nextStartPos > startPos) {
23
+ parts.push({
24
+ content: textContent.substring(startPos, nextStartPos),
25
+ type: 'string',
26
+ });
27
+ }
28
+
29
+ const nextEndPos = textContent.indexOf(closeTag, nextStartPos);
30
+
31
+ if (nextEndPos === -1) {
32
+ throw new Error(
33
+ `[TAG PARSER] Cannot find closing tag for string '${textContent}' starting from ${nextStartPos}`
34
+ );
35
+ }
36
+
37
+ // console.log('check for nex opening tag', textContent.indexOf(openTag, nextStartPos + openTag.length))
38
+ const checkNextOpeningTag = textContent.indexOf(
39
+ openTag,
40
+ nextStartPos + openTag.length
41
+ );
42
+
43
+ if (checkNextOpeningTag !== -1 && checkNextOpeningTag < nextEndPos) {
44
+ throw new Error(
45
+ `[TAG PARSER] Expecting closing tag, found opening tag in '${textContent}' starting from ${nextStartPos}`
46
+ );
47
+ }
48
+
49
+ const tagValue = textContent.substring(
50
+ nextStartPos + openTag.length,
51
+ nextEndPos
52
+ );
53
+
54
+ parts.push({
55
+ content: tagValue.trim(),
56
+ type: 'macro',
57
+ subtype:
58
+ tagValue.trim().split('.')[0] === 'action' ? 'action' : 'mapping',
59
+ });
60
+
61
+ startPos = nextEndPos + closeTag.length;
62
+ }
63
+
64
+ return parts;
65
+ }