@useinsider/guido 3.3.0-beta.e7d65e1 → 3.3.0-beta.fb07834
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/composables/useHtmlValidator.js +41 -36
- package/dist/extensions/Blocks/Recommendation/store/recommendation.js +24 -15
- package/dist/extensions/Blocks/Recommendation/validation/requiredFields.js +33 -0
- package/dist/services/unsubscribeApi.js +6 -6
- package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +7 -1
- package/dist/src/extensions/Blocks/Recommendation/validation/requiredFields.d.ts +21 -0
- package/package.json +1 -1
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
import { useConfig as
|
|
2
|
-
import { TemplateTypes as
|
|
3
|
-
import { DISPLAY_CONDITIONS_REGEX as
|
|
1
|
+
import { useConfig as _ } from "./useConfig.js";
|
|
2
|
+
import { TemplateTypes as H } from "../enums/defaults.js";
|
|
3
|
+
import { DISPLAY_CONDITIONS_REGEX as P, DISPLAY_CONDITIONS_EXCEPTIONS_REGEX as G, CampaignCouldNotBeSavedKey as M, CanNotMakeAnyChangesForRunningKey as $ } from "../enums/html-validator.js";
|
|
4
4
|
import { ToasterTypeOptions as c } from "../enums/toaster.js";
|
|
5
|
-
import { itemsBlockDynamicVariables as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
import { itemsBlockDynamicVariables as q } from "../extensions/Blocks/Items/enums/productEnums.js";
|
|
6
|
+
import { useRecommendationExtensionStore as X } from "../extensions/Blocks/Recommendation/store/recommendation.js";
|
|
7
|
+
import { RecommendationRequiredFieldsKey as j } from "../extensions/Blocks/Recommendation/validation/requiredFields.js";
|
|
8
|
+
import { useRecommendationStore as K } from "../stores/recommendation.js";
|
|
9
|
+
import { base64EncodeWithSpecialChars as z } from "../utils/base64.js";
|
|
10
|
+
import { useHttp as U } from "./useHttp.js";
|
|
11
|
+
import { useToaster as Y } from "./useToaster.js";
|
|
12
|
+
import { useTranslations as Z } from "./useTranslations.js";
|
|
13
|
+
const J = /recommendation-id="(\d+)"/g;
|
|
14
|
+
function Q(a) {
|
|
15
|
+
return [...a.matchAll(J)].map((u) => u[1]);
|
|
14
16
|
}
|
|
15
|
-
function
|
|
17
|
+
function ee(a, u) {
|
|
16
18
|
return u.some((d) => a.startsWith(`${d}_`));
|
|
17
19
|
}
|
|
18
|
-
const
|
|
20
|
+
const ge = () => {
|
|
19
21
|
var y, h;
|
|
20
|
-
const { showToaster: a } =
|
|
22
|
+
const { showToaster: a } = Y(), { post: u } = U(), { config: d } = _(), r = Z(), g = K(), S = X(), p = ((h = (y = d.value) == null ? void 0 : y.partner) == null ? void 0 : h.messageType) === H.transactional, b = async (e) => {
|
|
21
23
|
const t = await u(
|
|
22
24
|
"/newsletter/template-library/check-template-html-body",
|
|
23
|
-
{ html:
|
|
25
|
+
{ html: z(e) }
|
|
24
26
|
), { status: n, message: l } = t.data;
|
|
25
27
|
return n || a({
|
|
26
28
|
type: c.Alert,
|
|
27
29
|
message: n === void 0 ? l : r("newsletter.invalid-url-link-for-toaster")
|
|
28
|
-
}), r(
|
|
30
|
+
}), r(M), l === r($) && a({
|
|
29
31
|
type: c.Alert,
|
|
30
32
|
message: r("newsletter.already-in-progress")
|
|
31
33
|
}), n;
|
|
32
|
-
}, w = (e) => !["if", "endif", "else", "elif", "now"].includes(e.toLowerCase()),
|
|
34
|
+
}, w = (e) => !["if", "endif", "else", "elif", "now"].includes(e.toLowerCase()), E = (e) => ["if", "endif"].includes(e.toLowerCase()), A = (e, s) => {
|
|
33
35
|
const t = e.match(/({%(.*?)%})/g);
|
|
34
36
|
let n = !0;
|
|
35
37
|
return t !== null && !p && t.forEach((l) => {
|
|
@@ -42,13 +44,13 @@ const ce = () => {
|
|
|
42
44
|
}), n = !1);
|
|
43
45
|
}
|
|
44
46
|
}), n;
|
|
45
|
-
},
|
|
47
|
+
}, k = async (e, s, t) => {
|
|
46
48
|
const n = t ? await b(e) : !0;
|
|
47
|
-
return
|
|
48
|
-
},
|
|
49
|
+
return A(e, s) && n;
|
|
50
|
+
}, x = (e) => e.length > 0 ? !0 : (a({
|
|
49
51
|
type: c.Warning,
|
|
50
52
|
message: r("newsletter.html-content-is-empty")
|
|
51
|
-
}), !1),
|
|
53
|
+
}), !1), I = (e) => {
|
|
52
54
|
const s = (e.match(/{/gm) || []).length, t = (e.match(/}/gm) || []).length;
|
|
53
55
|
return s > t && a({
|
|
54
56
|
type: c.Warning,
|
|
@@ -57,7 +59,7 @@ const ce = () => {
|
|
|
57
59
|
type: c.Warning,
|
|
58
60
|
message: r("custom-fields.missing-opening-braces")
|
|
59
61
|
}), s === t;
|
|
60
|
-
},
|
|
62
|
+
}, F = (e) => {
|
|
61
63
|
const s = e.match(/{{\s*(\w+\s+((\w+\|\w+)|(\w+)))\s*}}/gm) === null;
|
|
62
64
|
return s || a({
|
|
63
65
|
type: c.Warning,
|
|
@@ -66,10 +68,10 @@ const ce = () => {
|
|
|
66
68
|
}, T = (e, s) => {
|
|
67
69
|
const t = e.match(/{{([a-zA-Z0-9_\s]*)}}/gm);
|
|
68
70
|
if (t && !p) {
|
|
69
|
-
const n = new Set(s.map((i) => i.toLowerCase())), l =
|
|
71
|
+
const n = new Set(s.map((i) => i.toLowerCase())), l = Q(e), o = [];
|
|
70
72
|
if (t.forEach((i) => {
|
|
71
73
|
const m = i.slice(2, -2).trim().toLowerCase();
|
|
72
|
-
(!n.has(m) || m === "") && !
|
|
74
|
+
(!n.has(m) || m === "") && !ee(m, l) && o.push(m);
|
|
73
75
|
}), o.length > 0) {
|
|
74
76
|
const i = `
|
|
75
77
|
<ul>
|
|
@@ -83,11 +85,11 @@ const ce = () => {
|
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
return !0;
|
|
86
|
-
},
|
|
88
|
+
}, R = (e) => {
|
|
87
89
|
const s = e.match(/{%(.*?)%}/g), t = [];
|
|
88
90
|
let n = !0;
|
|
89
91
|
if (s && s.forEach((l) => {
|
|
90
|
-
const o = l.match(
|
|
92
|
+
const o = l.match(P), i = l.match(G), m = (o == null ? void 0 : o.join("")) || "";
|
|
91
93
|
(!o || l !== m) && !i && (a({
|
|
92
94
|
type: c.Alert,
|
|
93
95
|
message: r("newsletter.display-conditions-invalid-syntax")
|
|
@@ -98,7 +100,7 @@ const ce = () => {
|
|
|
98
100
|
}), n = !1);
|
|
99
101
|
const v = f.match(/^[a-zA-Z]*$/g);
|
|
100
102
|
v && v.forEach((C) => {
|
|
101
|
-
|
|
103
|
+
E(C) && t.push(C);
|
|
102
104
|
});
|
|
103
105
|
});
|
|
104
106
|
}), t.length) {
|
|
@@ -109,25 +111,28 @@ const ce = () => {
|
|
|
109
111
|
}), n = !1);
|
|
110
112
|
}
|
|
111
113
|
return n;
|
|
112
|
-
},
|
|
114
|
+
}, B = (e) => {
|
|
113
115
|
const s = (e.match(/{% /gm) || []).length, t = (e.match(/ %}/gm) || []).length, n = s === t;
|
|
114
116
|
return n || a({
|
|
115
117
|
type: c.Warning,
|
|
116
118
|
message: r("custom-conditions.no-space-after-braces")
|
|
117
119
|
}), n;
|
|
118
|
-
},
|
|
120
|
+
}, W = (e) => (e.match(/({%(.*?)%})/g) || []).filter((t) => t.includes("if")).map((t) => (t.match(/{{.*}}/gm) || []).length).reduce((t, n) => t + n, 0) > 0 ? (a({
|
|
119
121
|
type: c.Warning,
|
|
120
122
|
message: r("custom-conditions.no-braces-inside-if-tag")
|
|
123
|
+
}), !1) : !0, N = () => S.hasInvalidBlock() ? (a({
|
|
124
|
+
type: c.Alert,
|
|
125
|
+
message: r(j)
|
|
121
126
|
}), !1) : !0, O = () => g.recommendationConfigs && Object.values(g.recommendationConfigs).find((s) => s.filters.find((t) => t.value === "")) !== void 0 ? (a({
|
|
122
127
|
type: c.Alert,
|
|
123
128
|
message: r("newsletter.fill-all-necessary-fields")
|
|
124
|
-
}), !1) : !0,
|
|
129
|
+
}), !1) : !0, D = (e) => {
|
|
125
130
|
const s = /src="[^"]*\.(svg|pst)"/gm;
|
|
126
131
|
return e.match(s) === null ? !0 : (a({
|
|
127
132
|
type: c.Alert,
|
|
128
133
|
message: r("newsletter.invalid-image-type")
|
|
129
134
|
}), !1);
|
|
130
|
-
},
|
|
135
|
+
}, L = (e) => {
|
|
131
136
|
const n = new DOMParser().parseFromString(e, "text/html").querySelectorAll(".checkbox-block-v2");
|
|
132
137
|
return Array.from(n).find((o) => {
|
|
133
138
|
var i;
|
|
@@ -136,7 +141,7 @@ const ce = () => {
|
|
|
136
141
|
type: c.Alert,
|
|
137
142
|
message: r("unsubscribe-templates.select-checkbox-groups")
|
|
138
143
|
}), !1) : !0;
|
|
139
|
-
},
|
|
144
|
+
}, V = (e) => {
|
|
140
145
|
const n = new DOMParser().parseFromString(e, "text/html").querySelectorAll(".radio-button-v2");
|
|
141
146
|
return Array.from(n).find((o) => {
|
|
142
147
|
var i;
|
|
@@ -150,12 +155,12 @@ const ce = () => {
|
|
|
150
155
|
var o, i;
|
|
151
156
|
const n = [
|
|
152
157
|
...s.map((m) => m.value),
|
|
153
|
-
...
|
|
158
|
+
...q,
|
|
154
159
|
...((i = (o = d.value) == null ? void 0 : o.template) == null ? void 0 : i.customFieldAttributes) ?? []
|
|
155
160
|
];
|
|
156
|
-
return await
|
|
161
|
+
return await k(e, n, t) && x(e) && I(e) && F(e) && T(e, n) && R(e) && B(e) && W(e) && N() && O() && D(e) && L(e) && V(e);
|
|
157
162
|
} };
|
|
158
163
|
};
|
|
159
164
|
export {
|
|
160
|
-
|
|
165
|
+
ge as useHtmlValidator
|
|
161
166
|
};
|
|
@@ -7,8 +7,9 @@ import { EXCLUDED_ALGORITHM_IDS as D } from "../constants/defaultConfig.js";
|
|
|
7
7
|
import { getDefaultProducts as g } from "../templates/utils.js";
|
|
8
8
|
import { generateCompleteFilterQuery as b } from "../utils/filterUtil.js";
|
|
9
9
|
import { isFilterValid as w } from "../validation/filterSchema.js";
|
|
10
|
+
import { isConfigValid as v } from "../validation/requiredFields.js";
|
|
10
11
|
const h = C();
|
|
11
|
-
let
|
|
12
|
+
let m = null, u = null, d = null;
|
|
12
13
|
function k() {
|
|
13
14
|
return {
|
|
14
15
|
cardsInRow: F,
|
|
@@ -48,7 +49,7 @@ function I() {
|
|
|
48
49
|
filterSnapshot: null
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
|
-
const
|
|
52
|
+
const N = () => ({
|
|
52
53
|
recommendationCampaignUrls: {},
|
|
53
54
|
activePredictiveAlgorithms: [],
|
|
54
55
|
languages: {},
|
|
@@ -57,8 +58,8 @@ const v = () => ({
|
|
|
57
58
|
blockStates: {},
|
|
58
59
|
currentRecommendationId: null,
|
|
59
60
|
configVersion: 0
|
|
60
|
-
}),
|
|
61
|
-
state: () =>
|
|
61
|
+
}), M = P("guidoRecommendationExtension", {
|
|
62
|
+
state: () => N(),
|
|
62
63
|
getters: {
|
|
63
64
|
// ====================================================================
|
|
64
65
|
// Proxy Getters — Backward Compatible Access to Current Block State
|
|
@@ -293,11 +294,11 @@ const v = () => ({
|
|
|
293
294
|
// ====================================================================
|
|
294
295
|
async fetchRecommendationCreateData() {
|
|
295
296
|
if (!this.activePredictiveAlgorithms.length) {
|
|
296
|
-
if (
|
|
297
|
-
await
|
|
297
|
+
if (m) {
|
|
298
|
+
await m;
|
|
298
299
|
return;
|
|
299
300
|
}
|
|
300
|
-
|
|
301
|
+
m = (async () => {
|
|
301
302
|
const {
|
|
302
303
|
activePredictiveAlgorithms: t,
|
|
303
304
|
languages: e,
|
|
@@ -310,26 +311,26 @@ const v = () => ({
|
|
|
310
311
|
this.currencyList = r;
|
|
311
312
|
})();
|
|
312
313
|
try {
|
|
313
|
-
await
|
|
314
|
+
await m;
|
|
314
315
|
} finally {
|
|
315
|
-
|
|
316
|
+
m = null;
|
|
316
317
|
}
|
|
317
318
|
}
|
|
318
319
|
},
|
|
319
320
|
async fetchRecommendationFilters() {
|
|
320
321
|
if (!Object.keys(this.filterList).length) {
|
|
321
|
-
if (
|
|
322
|
-
await
|
|
322
|
+
if (u) {
|
|
323
|
+
await u;
|
|
323
324
|
return;
|
|
324
325
|
}
|
|
325
|
-
|
|
326
|
+
u = (async () => {
|
|
326
327
|
const t = await h.fetchRecommendationFilters();
|
|
327
328
|
this.filterList = t;
|
|
328
329
|
})();
|
|
329
330
|
try {
|
|
330
|
-
await
|
|
331
|
+
await u;
|
|
331
332
|
} finally {
|
|
332
|
-
|
|
333
|
+
u = null;
|
|
333
334
|
}
|
|
334
335
|
}
|
|
335
336
|
},
|
|
@@ -398,6 +399,14 @@ const v = () => ({
|
|
|
398
399
|
generateFilterQuery() {
|
|
399
400
|
return b(this.recommendationConfigs.filters);
|
|
400
401
|
},
|
|
402
|
+
/**
|
|
403
|
+
* Validation-only check invoked at save-CTA time. Defined as an action
|
|
404
|
+
* (not a getter) so reading it does not register reactive tracking on
|
|
405
|
+
* every block's recommendationConfigs across user edits.
|
|
406
|
+
*/
|
|
407
|
+
hasInvalidBlock() {
|
|
408
|
+
return Object.values(this.blockStates).some((t) => !v(t.recommendationConfigs, this));
|
|
409
|
+
},
|
|
401
410
|
// ====================================================================
|
|
402
411
|
// Per-Block Product Fetching
|
|
403
412
|
// ====================================================================
|
|
@@ -443,5 +452,5 @@ const v = () => ({
|
|
|
443
452
|
}
|
|
444
453
|
});
|
|
445
454
|
export {
|
|
446
|
-
|
|
455
|
+
M as useRecommendationExtensionStore
|
|
447
456
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const o = [
|
|
2
|
+
{
|
|
3
|
+
key: "locale",
|
|
4
|
+
getValue: (e) => e.language,
|
|
5
|
+
getAvailableOptions: (e) => Object.keys(e.languages)
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
key: "currency",
|
|
9
|
+
getValue: (e) => e.currencySettings.value,
|
|
10
|
+
getAvailableOptions: (e) => e.currencyList.map((n) => n.text)
|
|
11
|
+
}
|
|
12
|
+
], l = "newsletter.recommendation-fill-required-fields";
|
|
13
|
+
function u(e, n) {
|
|
14
|
+
return o.filter((t) => {
|
|
15
|
+
var a;
|
|
16
|
+
if (t.condition && !t.condition(e))
|
|
17
|
+
return !1;
|
|
18
|
+
const i = t.getValue(e);
|
|
19
|
+
if (!i)
|
|
20
|
+
return !0;
|
|
21
|
+
const r = (a = t.getAvailableOptions) == null ? void 0 : a.call(t, n);
|
|
22
|
+
return r !== void 0 && !r.includes(i);
|
|
23
|
+
}).map((t) => t.key);
|
|
24
|
+
}
|
|
25
|
+
function s(e, n) {
|
|
26
|
+
return u(e, n).length === 0;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
o as REQUIRED_RECOMMENDATION_FIELDS,
|
|
30
|
+
l as RecommendationRequiredFieldsKey,
|
|
31
|
+
u as getInvalidFields,
|
|
32
|
+
s as isConfigValid
|
|
33
|
+
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { useHttp as t } from "../composables/useHttp.js";
|
|
2
|
-
import { useToaster as
|
|
2
|
+
import { useToaster as n } from "../composables/useToaster.js";
|
|
3
3
|
const u = () => {
|
|
4
|
-
const { get:
|
|
4
|
+
const { get: r } = t(), { handleError: s } = n();
|
|
5
5
|
return { getUnsubscribePages: async () => {
|
|
6
6
|
try {
|
|
7
|
-
const { data:
|
|
8
|
-
return
|
|
9
|
-
} catch (
|
|
10
|
-
return s(
|
|
7
|
+
const { data: e = [] } = await r("/unsubscribe-pages/get-all");
|
|
8
|
+
return e;
|
|
9
|
+
} catch (e) {
|
|
10
|
+
return s(e, "Failed to fetch unsubscribe pages"), [];
|
|
11
11
|
}
|
|
12
12
|
} };
|
|
13
13
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Orientation, Languages, Currency, NumericSeparator, FiltersResponse, Filter, RecommendationProduct } from '@@/Types/recommendation';
|
|
2
|
-
interface PerBlockConfigs {
|
|
2
|
+
export interface PerBlockConfigs {
|
|
3
3
|
cardsInRow: number;
|
|
4
4
|
currencySettings: {
|
|
5
5
|
name: string;
|
|
@@ -272,6 +272,12 @@ export declare const useRecommendationExtensionStore: import("pinia").StoreDefin
|
|
|
272
272
|
deleteFilter(filter: Filter): void;
|
|
273
273
|
addFilter(filter: Filter): void;
|
|
274
274
|
generateFilterQuery(): string;
|
|
275
|
+
/**
|
|
276
|
+
* Validation-only check invoked at save-CTA time. Defined as an action
|
|
277
|
+
* (not a getter) so reading it does not register reactive tracking on
|
|
278
|
+
* every block's recommendationConfigs across user edits.
|
|
279
|
+
*/
|
|
280
|
+
hasInvalidBlock(): boolean;
|
|
275
281
|
fetchRecommendationProducts(): Promise<void>;
|
|
276
282
|
_doFetchProducts(): Promise<void>;
|
|
277
283
|
}>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PerBlockConfigs } from '../store/recommendation';
|
|
2
|
+
import type { Currency, Languages } from '@@/Types/recommendation';
|
|
3
|
+
/**
|
|
4
|
+
* Structural slice of the recommendation extension store that descriptors may read.
|
|
5
|
+
* Add new fields here when a future descriptor needs them.
|
|
6
|
+
*/
|
|
7
|
+
export interface ExtensionStoreSlice {
|
|
8
|
+
languages: Languages;
|
|
9
|
+
currencyList: Currency[];
|
|
10
|
+
}
|
|
11
|
+
interface RequiredField {
|
|
12
|
+
key: string;
|
|
13
|
+
getValue: (config: PerBlockConfigs) => string;
|
|
14
|
+
getAvailableOptions?: (store: ExtensionStoreSlice) => string[];
|
|
15
|
+
condition?: (config: PerBlockConfigs) => boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare const REQUIRED_RECOMMENDATION_FIELDS: RequiredField[];
|
|
18
|
+
export declare const RecommendationRequiredFieldsKey = "newsletter.recommendation-fill-required-fields";
|
|
19
|
+
export declare function getInvalidFields(config: PerBlockConfigs, store: ExtensionStoreSlice): string[];
|
|
20
|
+
export declare function isConfigValid(config: PerBlockConfigs, store: ExtensionStoreSlice): boolean;
|
|
21
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useinsider/guido",
|
|
3
|
-
"version": "3.3.0-beta.
|
|
3
|
+
"version": "3.3.0-beta.fb07834",
|
|
4
4
|
"description": "Guido is a Vue + TypeScript wrapper for Email Plugin. Easily embed the email editor in your Vue applications.",
|
|
5
5
|
"main": "./dist/guido.umd.cjs",
|
|
6
6
|
"module": "./dist/library.js",
|