feed-common 1.51.5 → 1.52.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +14 -0
- package/dist/utils/utils.d.ts +11 -1
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +32 -3
- package/dist/utils/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/utils.ts +47 -4
- package/tests/utils.spec.ts +43 -0
- package/tests/validator.spec.ts +12 -14
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# [1.52.0](https://github.com/advertikon/package-maxify-feed-common/compare/v1.51.6...v1.52.0) (2024-10-13)
|
2
|
+
|
3
|
+
|
4
|
+
### Features
|
5
|
+
|
6
|
+
* add some source tag util functions ([b53def7](https://github.com/advertikon/package-maxify-feed-common/commit/b53def7e09e6f0842766d55dc5cff84afb282b61))
|
7
|
+
|
8
|
+
## [1.51.6](https://github.com/advertikon/package-maxify-feed-common/compare/v1.51.5...v1.51.6) (2024-10-13)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* remove consoles ([4c209c7](https://github.com/advertikon/package-maxify-feed-common/commit/4c209c745172872a2379f2daa4416fb804912275))
|
14
|
+
|
1
15
|
## [1.51.5](https://github.com/advertikon/package-maxify-feed-common/compare/v1.51.4...v1.51.5) (2024-10-13)
|
2
16
|
|
3
17
|
|
package/dist/utils/utils.d.ts
CHANGED
@@ -1,4 +1,14 @@
|
|
1
|
-
import { MacroPartType } from '../types/profile.types.js';
|
1
|
+
import { MacroPartType, SelectItem } from '../types/profile.types.js';
|
2
2
|
export declare function code(): string;
|
3
3
|
export declare function parseMacrosString(textContent: string): MacroPartType[];
|
4
|
+
export declare function isJSON(input: any): input is string;
|
5
|
+
export declare function isSourceJSON(input: any): boolean;
|
6
|
+
export declare function getSourceTagParts(content: string): {
|
7
|
+
tag: string;
|
8
|
+
value: string | null;
|
9
|
+
};
|
10
|
+
export declare function getSourceTagValue(content: string): {
|
11
|
+
tag: string;
|
12
|
+
value: SelectItem[] | null;
|
13
|
+
};
|
4
14
|
//# sourceMappingURL=utils.d.ts.map
|
@@ -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;
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEtE,wBAAgB,IAAI,WAEnB;AAED,wBAAgB,iBAAiB,CAAE,WAAW,EAAE,MAAM,GAAG,aAAa,EAAE,CA4DvE;AAeD,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,MAAM,CAOhD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAYhD;AAEH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAMA;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG;IAClD,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;CAC5B,CAOA"}
|
package/dist/utils/utils.js
CHANGED
@@ -49,18 +49,47 @@ export function parseMacrosString(textContent) {
|
|
49
49
|
return parts;
|
50
50
|
}
|
51
51
|
function getMacroSubtype(tagValue) {
|
52
|
-
console.log('tagValue', tagValue);
|
53
52
|
switch (tagValue.trim().split('.')[0]) {
|
54
53
|
case 'action':
|
55
54
|
return 'action';
|
56
55
|
case 'metafield':
|
57
56
|
return 'metafield';
|
58
57
|
case 'source':
|
59
|
-
console.log('source case');
|
60
58
|
return 'source';
|
61
59
|
default:
|
62
|
-
console.log('default case');
|
63
60
|
return 'mapping';
|
64
61
|
}
|
65
62
|
}
|
63
|
+
export function isJSON(input) {
|
64
|
+
try {
|
65
|
+
JSON.parse(input);
|
66
|
+
return true;
|
67
|
+
}
|
68
|
+
catch (e) {
|
69
|
+
return false;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
export function isSourceJSON(input) {
|
73
|
+
if (!isJSON(input)) {
|
74
|
+
return false;
|
75
|
+
}
|
76
|
+
const content = JSON.parse(input);
|
77
|
+
if (Array.isArray(content)) {
|
78
|
+
return content.every((item) => item?.label !== undefined && item?.value !== undefined);
|
79
|
+
}
|
80
|
+
return content?.label !== undefined && content?.value !== undefined;
|
81
|
+
}
|
82
|
+
export function getSourceTagParts(content) {
|
83
|
+
const splitPoint = content.indexOf(":");
|
84
|
+
const tag = splitPoint !== -1 ? content.slice(0, splitPoint) : content;
|
85
|
+
const value = splitPoint !== -1 ? content.slice(splitPoint + 1) : null;
|
86
|
+
return { tag, value };
|
87
|
+
}
|
88
|
+
export function getSourceTagValue(content) {
|
89
|
+
const splitPoint = content.indexOf(":");
|
90
|
+
const tag = splitPoint !== -1 ? content.slice(0, splitPoint) : content;
|
91
|
+
const valueText = splitPoint !== -1 ? content.slice(splitPoint + 1) : null;
|
92
|
+
const value = isSourceJSON(valueText) ? JSON.parse(valueText) : null;
|
93
|
+
return { tag, value: value && !Array.isArray(value) ? [value] : value };
|
94
|
+
}
|
66
95
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils/utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,IAAI;IAChB,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAE,WAAmB;IAClD,MAAM,OAAO,GAAG,IAAI,CAAC;IACrB,MAAM,QA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UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEvE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAI/C,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,GAAG,GAAG,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IACvE,MAAM,SAAS,GAAG,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3E,MAAM,KAAK,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAmB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAE/E,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;AAC1E,CAAC"}
|
package/package.json
CHANGED
package/src/utils/utils.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { MacroPartType } from '../types/profile.types.js';
|
1
|
+
import { MacroPartType, SelectItem } from '../types/profile.types.js';
|
2
2
|
|
3
3
|
export function code () {
|
4
4
|
return (Math.random() * 1000000).toFixed(0);
|
@@ -67,17 +67,60 @@ export function parseMacrosString (textContent: string): MacroPartType[] {
|
|
67
67
|
}
|
68
68
|
|
69
69
|
function getMacroSubtype (tagValue: string): MacroPartType['subtype'] {
|
70
|
-
console.log('tagValue', tagValue);
|
71
70
|
switch (tagValue.trim().split('.')[0]) {
|
72
71
|
case 'action':
|
73
72
|
return 'action';
|
74
73
|
case 'metafield':
|
75
74
|
return 'metafield';
|
76
75
|
case 'source':
|
77
|
-
console.log('source case')
|
78
76
|
return 'source';
|
79
77
|
default:
|
80
|
-
console.log('default case')
|
81
78
|
return 'mapping';
|
82
79
|
}
|
83
80
|
}
|
81
|
+
|
82
|
+
export function isJSON(input: any): input is string {
|
83
|
+
try {
|
84
|
+
JSON.parse(input);
|
85
|
+
return true;
|
86
|
+
} catch (e) {
|
87
|
+
return false;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
export function isSourceJSON(input: any): boolean {
|
92
|
+
if (!isJSON(input)) {
|
93
|
+
return false;
|
94
|
+
}
|
95
|
+
|
96
|
+
const content = JSON.parse(input);
|
97
|
+
|
98
|
+
if (Array.isArray(content)) {
|
99
|
+
return content.every((item) => item?.label !== undefined && item?.value !== undefined);
|
100
|
+
}
|
101
|
+
|
102
|
+
return content?.label !== undefined && content?.value !== undefined;
|
103
|
+
}
|
104
|
+
|
105
|
+
export function getSourceTagParts(content: string): {
|
106
|
+
tag: string;
|
107
|
+
value: string | null;
|
108
|
+
} {
|
109
|
+
const splitPoint = content.indexOf(":");
|
110
|
+
const tag = splitPoint !== -1 ? content.slice(0, splitPoint) : content;
|
111
|
+
const value = splitPoint !== -1 ? content.slice(splitPoint + 1) : null;
|
112
|
+
|
113
|
+
return { tag, value };
|
114
|
+
}
|
115
|
+
|
116
|
+
export function getSourceTagValue(content: string): {
|
117
|
+
tag: string;
|
118
|
+
value: SelectItem[] | null;
|
119
|
+
} {
|
120
|
+
const splitPoint = content.indexOf(":");
|
121
|
+
const tag = splitPoint !== -1 ? content.slice(0, splitPoint) : content;
|
122
|
+
const valueText = splitPoint !== -1 ? content.slice(splitPoint + 1) : null;
|
123
|
+
const value = isSourceJSON(valueText) ? JSON.parse(valueText as string) : null;
|
124
|
+
|
125
|
+
return { tag, value: value && !Array.isArray(value) ? [value] : value };
|
126
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { describe, test, expect } from "vitest";
|
2
|
+
import { getSourceTagParts, getSourceTagValue, isJSON, isSourceJSON } from "../src/utils/utils";
|
3
|
+
|
4
|
+
describe("Utils", () => {
|
5
|
+
describe('Source tag', () => {
|
6
|
+
test('isJson', () => {
|
7
|
+
expect(isJSON('{"hello": "world"}')).toBe(true);
|
8
|
+
expect(isJSON('[{"hello": "world"}]')).toBe(true);
|
9
|
+
expect(isJSON(1)).toBe(true);
|
10
|
+
expect(isJSON('1')).toBe(true);
|
11
|
+
expect(isJSON(null)).toBe(true);
|
12
|
+
|
13
|
+
expect(isJSON('{"hello": "world"')).toBe(false);
|
14
|
+
});
|
15
|
+
|
16
|
+
test('isSourceJSON', () => {
|
17
|
+
expect(isSourceJSON('{"label": "hello", "value": "world"}')).toBe(true);
|
18
|
+
expect(isSourceJSON('[{"label": "hello", "value": "world"}]')).toBe(true);
|
19
|
+
|
20
|
+
expect(isSourceJSON('{"label": "hello", "value": "world"')).toBe(false);
|
21
|
+
expect(isSourceJSON('{"label": "hello": "key": "world"}')).toBe(false);
|
22
|
+
expect(isSourceJSON(1)).toBe(false);
|
23
|
+
expect(isSourceJSON('1')).toBe(false);
|
24
|
+
expect(isSourceJSON(null)).toBe(false);
|
25
|
+
});
|
26
|
+
|
27
|
+
test('getSourceTagParts', () => {
|
28
|
+
expect(getSourceTagParts('source.world')).toEqual({ tag: 'source.world', value: null });
|
29
|
+
expect(getSourceTagParts('source.world:hello')).toEqual({ tag: 'source.world', value: 'hello' });
|
30
|
+
expect(getSourceTagParts('source.world:')).toEqual({ tag: 'source.world', value: '' });
|
31
|
+
expect(getSourceTagParts('source.world:hello:world')).toEqual({ tag: 'source.world', value: 'hello:world' });
|
32
|
+
})
|
33
|
+
|
34
|
+
test('getSourceTagValue', () => {
|
35
|
+
expect(getSourceTagValue('source.world')).toEqual({ tag: 'source.world', value: null });
|
36
|
+
expect(getSourceTagValue('source.world:hello')).toEqual({ tag: 'source.world', value: null });
|
37
|
+
expect(getSourceTagValue('source.world:hello:world')).toEqual({ tag: 'source.world', value: null });
|
38
|
+
expect(getSourceTagValue('source.world:')).toEqual({ tag: 'source.world', value: null });
|
39
|
+
expect(getSourceTagValue('source.world:{"label": "hello", "value": "world"}')).toEqual({ tag: 'source.world', value: [{ label: 'hello', value: 'world' }] });
|
40
|
+
expect(getSourceTagValue('source.world:[{"label": "hello", "value": "world"}]')).toEqual({ tag: 'source.world', value: [{ label: 'hello', value: 'world' }] });
|
41
|
+
});
|
42
|
+
});
|
43
|
+
});
|
package/tests/validator.spec.ts
CHANGED
@@ -9,21 +9,19 @@ describe("Validator", () => {
|
|
9
9
|
expect(hasMacro('Hello {{source.world}} {{source.world:any value}}')).toBe(false);
|
10
10
|
});
|
11
11
|
|
12
|
-
test('language validation', () => {
|
13
|
-
expect(languageSchema.safeParse('en').success).toBe(true);
|
14
|
-
expect(languageSchema.safeParse('ES').success).toBe(true);
|
15
|
-
expect(languageSchema.safeParse('ES\nES').success).toBe(false);
|
16
|
-
expect(languageSchema.safeParse('').success).toBe(true);
|
17
|
-
expect(validateIfNoMacro('en', languageSchema).success).toBe(true);
|
18
|
-
expect(validateIfNoMacro('{{source.language:en}}', [languageSchema, z.string().min(1)]).success).toBe(true);
|
19
|
-
expect(validateIfNoMacro('{{source.language:foo}}', [languageSchema, z.string().min(1)]).success).toBe(false);
|
20
|
-
expect(validateIfNoMacro('{{source.language:}}', [languageSchema, z.string().min(2)]).success).toBe(false);
|
21
|
-
})
|
22
|
-
|
23
12
|
test('multiple validators', () => {
|
24
|
-
expect(validateIfNoMacro('en', [
|
25
|
-
expect(validateIfNoMacro('', [
|
26
|
-
expect(validateIfNoMacro('', [
|
13
|
+
expect(validateIfNoMacro('en', [z.string(), z.string().min(2)]).success).toBe(true);
|
14
|
+
expect(validateIfNoMacro('en', [z.string(), z.string().min(3)]).success).toBe(false);
|
15
|
+
expect(validateIfNoMacro('en', [z.number(), z.string().min(2)]).success).toBe(false);
|
27
16
|
});
|
17
|
+
|
18
|
+
describe('language validate', () => {
|
19
|
+
test('languageSchema', () => {
|
20
|
+
expect(languageSchema.safeParse('en').success).toBe(true);
|
21
|
+
expect(languageSchema.safeParse('ES').success).toBe(true);
|
22
|
+
expect(languageSchema.safeParse('ES\nES').success).toBe(false);
|
23
|
+
expect(languageSchema.safeParse('').success).toBe(true);
|
24
|
+
})
|
25
|
+
})
|
28
26
|
});
|
29
27
|
|