@useinsider/guido 1.0.2-beta.0e6f88a → 1.0.2-beta.110deb9
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DynamicContent } from '@@/Types/generic';
|
|
1
2
|
export declare const useHtmlValidator: () => {
|
|
2
|
-
validateHtml: (html: string, customFields:
|
|
3
|
+
validateHtml: (html: string, customFields: DynamicContent[], isOnSaveValidation?: boolean) => Promise<boolean>;
|
|
3
4
|
};
|
|
@@ -1,85 +1,92 @@
|
|
|
1
|
-
import { useConfig as
|
|
2
|
-
import { TemplateTypes as
|
|
1
|
+
import { useConfig as H } from "./useConfig.js";
|
|
2
|
+
import { TemplateTypes as V } from "../enums/defaults.js";
|
|
3
3
|
import { DISPLAY_CONDITIONS_REGEX as B, DISPLAY_CONDITIONS_EXCEPTIONS_REGEX as _, CampaignCouldNotBeSavedKey as D, CanNotMakeAnyChangesForRunningKey as P } from "../enums/html-validator.js";
|
|
4
|
-
import { ToasterTypeOptions as
|
|
4
|
+
import { ToasterTypeOptions as l } from "../enums/toaster.js";
|
|
5
5
|
import { useRecommendationStore as R } from "../stores/recommendation.js";
|
|
6
|
-
import { base64EncodeWithSpecialChars as
|
|
7
|
-
import { useHttp as
|
|
8
|
-
import { useToaster as
|
|
9
|
-
import { useTranslations as
|
|
6
|
+
import { base64EncodeWithSpecialChars as $ } from "../utils/base64.js";
|
|
7
|
+
import { useHttp as j } from "./useHttp.js";
|
|
8
|
+
import { useToaster as G } from "./useToaster.js";
|
|
9
|
+
import { useTranslations as X } from "./useTranslations.js";
|
|
10
10
|
const te = () => {
|
|
11
11
|
var d;
|
|
12
|
-
const { showToaster:
|
|
12
|
+
const { showToaster: c } = G(), { post: y } = j(), { config: h } = H(), o = X(), m = R(), u = ((d = h.partner) == null ? void 0 : d.messageType) === V.transactional, C = async (e) => {
|
|
13
13
|
const t = await y(
|
|
14
14
|
"/newsletter/template-library/check-template-html-body",
|
|
15
|
-
{ html:
|
|
16
|
-
), { status: n, message:
|
|
17
|
-
return n ||
|
|
18
|
-
type:
|
|
19
|
-
message: n === void 0 ?
|
|
20
|
-
}),
|
|
21
|
-
type:
|
|
22
|
-
message:
|
|
15
|
+
{ html: $(e) }
|
|
16
|
+
), { status: n, message: a } = t.data;
|
|
17
|
+
return n || c({
|
|
18
|
+
type: l.Alert,
|
|
19
|
+
message: n === void 0 ? a : o("newsletter.invalid-url-link-for-toaster")
|
|
20
|
+
}), o(D), a === o(P) && c({
|
|
21
|
+
type: l.Alert,
|
|
22
|
+
message: o("newsletter.already-in-progress")
|
|
23
23
|
}), n;
|
|
24
24
|
}, v = (e) => !["if", "endif", "else", "elif", "now"].includes(e.toLowerCase()), w = (e) => ["if", "endif"].includes(e.toLowerCase()), S = (e, s) => {
|
|
25
25
|
const t = e.match(/({%(.*?)%})/g);
|
|
26
26
|
let n = !0;
|
|
27
|
-
return t !== null && !u && t.forEach((
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
const [
|
|
31
|
-
v(
|
|
32
|
-
type:
|
|
33
|
-
message:
|
|
27
|
+
return t !== null && !u && t.forEach((a) => {
|
|
28
|
+
const i = a.slice(2, -2).trim().match(/(".*?"|[^"\s]+)(?=\s*|\s*$)/g);
|
|
29
|
+
if (i && i.length > 0) {
|
|
30
|
+
const [r] = i;
|
|
31
|
+
v(r) && !s.includes(r) && (c({
|
|
32
|
+
type: l.Warning,
|
|
33
|
+
message: o("custom-fields.invalid-custom-fields")
|
|
34
34
|
}), n = !1);
|
|
35
35
|
}
|
|
36
36
|
}), n;
|
|
37
37
|
}, b = async (e, s, t) => {
|
|
38
38
|
const n = t ? await C(e) : !0;
|
|
39
39
|
return S(e, s) && n;
|
|
40
|
-
}, E = (e) => e.length > 0 ? !0 : (
|
|
41
|
-
type:
|
|
42
|
-
message:
|
|
43
|
-
}), !1),
|
|
40
|
+
}, E = (e) => e.length > 0 ? !0 : (c({
|
|
41
|
+
type: l.Warning,
|
|
42
|
+
message: o("newsletter.html-content-is-empty")
|
|
43
|
+
}), !1), A = (e) => {
|
|
44
44
|
const s = (e.match(/{/gm) || []).length, t = (e.match(/}/gm) || []).length;
|
|
45
|
-
return s > t &&
|
|
46
|
-
type:
|
|
47
|
-
message:
|
|
48
|
-
}), s < t &&
|
|
49
|
-
type:
|
|
50
|
-
message:
|
|
45
|
+
return s > t && c({
|
|
46
|
+
type: l.Warning,
|
|
47
|
+
message: o("custom-fields.missing-closing-braces")
|
|
48
|
+
}), s < t && c({
|
|
49
|
+
type: l.Warning,
|
|
50
|
+
message: o("custom-fields.missing-opening-braces")
|
|
51
51
|
}), s === t;
|
|
52
|
-
},
|
|
52
|
+
}, x = (e) => {
|
|
53
53
|
const s = e.match(/{{\s*(\w+\s+((\w+\|\w+)|(\w+)))\s*}}/gm) === null;
|
|
54
|
-
return s ||
|
|
55
|
-
type:
|
|
56
|
-
message:
|
|
54
|
+
return s || c({
|
|
55
|
+
type: l.Warning,
|
|
56
|
+
message: o("custom-fields.invalid-custom-fields")
|
|
57
57
|
}), s;
|
|
58
58
|
}, T = (e, s) => {
|
|
59
59
|
const t = e.match(/{{([a-zA-Z0-9_\s]*)}}/gm);
|
|
60
60
|
if (t && !u) {
|
|
61
|
-
const n = s.map((
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
const n = new Set(s.map((i) => i.toLowerCase())), a = [];
|
|
62
|
+
if (t.forEach((i) => {
|
|
63
|
+
const r = i.slice(2, -2).trim().toLowerCase();
|
|
64
|
+
(!n.has(r) || r === "") && a.push(r);
|
|
65
|
+
}), a.length > 0) {
|
|
66
|
+
const i = `
|
|
67
|
+
<ul>
|
|
68
|
+
${a.map((r) => `<li>${r}</li>`).join("")}
|
|
69
|
+
</ul>
|
|
70
|
+
`;
|
|
71
|
+
return c({
|
|
72
|
+
type: l.Alert,
|
|
73
|
+
message: o("custom-fields.invalid-custom-fields") + i
|
|
74
|
+
}), !1;
|
|
75
|
+
}
|
|
69
76
|
}
|
|
70
77
|
return !0;
|
|
71
78
|
}, k = (e) => {
|
|
72
79
|
const s = e.match(/{%(.*?)%}/g), t = [];
|
|
73
80
|
let n = !0;
|
|
74
|
-
if (s && s.forEach((
|
|
75
|
-
const
|
|
76
|
-
(!
|
|
77
|
-
type:
|
|
78
|
-
message:
|
|
79
|
-
}), n = !1),
|
|
80
|
-
f.trim() === "=" && (
|
|
81
|
-
type:
|
|
82
|
-
message:
|
|
81
|
+
if (s && s.forEach((a) => {
|
|
82
|
+
const i = a.match(B), r = a.match(_), O = (i == null ? void 0 : i.join("")) || "";
|
|
83
|
+
(!i || a !== O) && !r && (c({
|
|
84
|
+
type: l.Alert,
|
|
85
|
+
message: o("newsletter.display-conditions-invalid-syntax")
|
|
86
|
+
}), n = !1), i && i.forEach((f) => {
|
|
87
|
+
f.trim() === "=" && (c({
|
|
88
|
+
type: l.Alert,
|
|
89
|
+
message: o("custom-conditions.wrong-equality-operators")
|
|
83
90
|
}), n = !1);
|
|
84
91
|
const g = f.match(/^[a-zA-Z]*$/g);
|
|
85
92
|
g && g.forEach((p) => {
|
|
@@ -87,42 +94,45 @@ const te = () => {
|
|
|
87
94
|
});
|
|
88
95
|
});
|
|
89
96
|
}), t.length) {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
type:
|
|
93
|
-
message:
|
|
97
|
+
const a = t.filter((r) => r === "if"), i = t.filter((r) => r === "endif");
|
|
98
|
+
a.length !== i.length && (c({
|
|
99
|
+
type: l.Alert,
|
|
100
|
+
message: o("custom-conditions.missing-if-endif-tag")
|
|
94
101
|
}), n = !1);
|
|
95
102
|
}
|
|
96
103
|
return n;
|
|
97
|
-
},
|
|
104
|
+
}, F = (e) => {
|
|
98
105
|
const s = (e.match(/{% /gm) || []).length, t = (e.match(/ %}/gm) || []).length, n = s === t;
|
|
99
|
-
return n ||
|
|
100
|
-
type:
|
|
101
|
-
message:
|
|
106
|
+
return n || c({
|
|
107
|
+
type: l.Warning,
|
|
108
|
+
message: o("custom-conditions.no-space-after-braces")
|
|
102
109
|
}), n;
|
|
103
|
-
},
|
|
104
|
-
type:
|
|
105
|
-
message:
|
|
106
|
-
}), !1) : !0,
|
|
107
|
-
type:
|
|
108
|
-
message:
|
|
109
|
-
}), !1) : !0,
|
|
110
|
+
}, I = (e) => (e.match(/({%(.*?)%})/g) || []).filter((t) => t.includes("if")).map((t) => (t.match(/{{.*}}/gm) || []).length).reduce((t, n) => t + n, 0) > 0 ? (c({
|
|
111
|
+
type: l.Warning,
|
|
112
|
+
message: o("custom-conditions.no-braces-inside-if-tag")
|
|
113
|
+
}), !1) : !0, W = () => m.recommendationConfigs && Object.values(m.recommendationConfigs).find((s) => s.filters.find((t) => t.value === "")) !== void 0 ? (c({
|
|
114
|
+
type: l.Alert,
|
|
115
|
+
message: o("newsletter.fill-all-necessary-fields")
|
|
116
|
+
}), !1) : !0, L = (e) => {
|
|
110
117
|
const s = /src="[^"]*\.(svg|pst)"/gm;
|
|
111
|
-
return e.match(s) === null ? !0 : (
|
|
112
|
-
type:
|
|
113
|
-
message:
|
|
118
|
+
return e.match(s) === null ? !0 : (c({
|
|
119
|
+
type: l.Alert,
|
|
120
|
+
message: o("newsletter.invalid-image-type")
|
|
114
121
|
}), !1);
|
|
115
|
-
},
|
|
122
|
+
}, N = (e) => {
|
|
116
123
|
const n = new DOMParser().parseFromString(e, "text/html").querySelectorAll(".checkbox-block-v2");
|
|
117
|
-
return Array.from(n).find((
|
|
118
|
-
var
|
|
119
|
-
return !((
|
|
120
|
-
}) ? (
|
|
121
|
-
type:
|
|
122
|
-
message:
|
|
124
|
+
return Array.from(n).find((i) => {
|
|
125
|
+
var r;
|
|
126
|
+
return !((r = i.id) != null && r.trim());
|
|
127
|
+
}) ? (c({
|
|
128
|
+
type: l.Alert,
|
|
129
|
+
message: o("unsubscribe-templates.select-checkbox-groups")
|
|
123
130
|
}), !1) : !0;
|
|
124
131
|
};
|
|
125
|
-
return { validateHtml: async (e, s, t = !1) =>
|
|
132
|
+
return { validateHtml: async (e, s, t = !1) => {
|
|
133
|
+
const n = s.map((i) => i.value);
|
|
134
|
+
return await b(e, n, t) && E(e) && A(e) && x(e) && T(e, n) && k(e) && F(e) && I(e) && W() && L(e) && N(e);
|
|
135
|
+
} };
|
|
126
136
|
};
|
|
127
137
|
export {
|
|
128
138
|
te as useHtmlValidator
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { useSaveStart as i, useSaveComplete as
|
|
2
|
-
import { useTemplatePreparation as
|
|
3
|
-
import { useHtmlValidator as
|
|
1
|
+
import { useSaveStart as i, useSaveComplete as m } from "./useGuidoActions.js";
|
|
2
|
+
import { useTemplatePreparation as n } from "../utils/templatePreparation.js";
|
|
3
|
+
import { useHtmlValidator as l } from "./useHtmlValidator.js";
|
|
4
4
|
const f = () => {
|
|
5
|
-
const e = i(), a =
|
|
5
|
+
const e = i(), a = m(), { validateHtml: s } = l();
|
|
6
6
|
return { save: async (o = !1) => {
|
|
7
7
|
e();
|
|
8
|
-
const { prepareTemplateDetails: r } =
|
|
9
|
-
if (await s(t.compiledHtml,
|
|
8
|
+
const { prepareTemplateDetails: r } = n(), t = await r();
|
|
9
|
+
if (await s(t.compiledHtml, t.dynamicContentList, !0))
|
|
10
10
|
return o || a(t), t;
|
|
11
11
|
} };
|
|
12
12
|
};
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { DynamicContent, MergeTag } from '@@/Types/generic';
|
|
2
2
|
export declare const dynamicContentToMergeTags: (dynamicContentList: DynamicContent[]) => MergeTag[];
|
|
3
3
|
export declare const getCsrfToken: () => string;
|
|
4
|
+
/**
|
|
5
|
+
* URL Parameter utilities
|
|
6
|
+
*/
|
|
7
|
+
export declare const getUrlParams: () => URLSearchParams;
|
|
8
|
+
export declare const getUrlParam: (paramName: string, defaultValue?: string) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useinsider/guido",
|
|
3
|
-
"version": "1.0.2-beta.
|
|
3
|
+
"version": "1.0.2-beta.110deb9",
|
|
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",
|