@useinsider/guido 3.21.2-beta.4b0fed7 → 3.21.2-beta.5a809f7

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.
Files changed (24) hide show
  1. package/dist/composables/useSave.js +75 -68
  2. package/dist/composables/validators/useHtmlDocumentCountValidator.js +22 -0
  3. package/dist/config/migrator/recommendation/extractors.js +36 -27
  4. package/dist/config/migrator/recommendation/htmlBuilder.js +99 -105
  5. package/dist/config/migrator/recommendation/settingsMapper.js +13 -15
  6. package/dist/config/migrator/recommendationMigrator.js +62 -59
  7. package/dist/extensions/Blocks/Recommendation/controls/cardComposition/index.js +20 -19
  8. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +101 -100
  9. package/dist/extensions/Blocks/Recommendation/templates/grid/template.js +23 -22
  10. package/dist/extensions/Blocks/Recommendation/templates/list/template.js +19 -18
  11. package/dist/extensions/Blocks/Recommendation/templates/utils.js +82 -91
  12. package/dist/extensions/Blocks/Recommendation/utils/inlinePriceOrder.js +12 -0
  13. package/dist/extensions/Blocks/Recommendation/utils/legacyStrategyMap.js +2 -0
  14. package/dist/services/templateLibraryApi.js +36 -31
  15. package/dist/src/composables/validators/useHtmlDocumentCountValidator.d.ts +3 -0
  16. package/dist/src/config/migrator/recommendation/extractors.d.ts +6 -0
  17. package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +1 -1
  18. package/dist/src/extensions/Blocks/Recommendation/templates/utils.d.ts +1 -13
  19. package/dist/src/extensions/Blocks/Recommendation/utils/inlinePriceOrder.d.ts +9 -0
  20. package/dist/src/extensions/Blocks/Recommendation/utils/legacyStrategyMap.d.ts +2 -20
  21. package/dist/src/utils/templatePreparation.d.ts +2 -1
  22. package/dist/utils/pairProductVariables.js +98 -90
  23. package/dist/utils/templatePreparation.js +30 -30
  24. package/package.json +1 -1
@@ -1,84 +1,91 @@
1
- import { useActionsApi as R } from "./useActionsApi.js";
2
- import { useConfig as q } from "./useConfig.js";
3
- import { useEditorLock as O } from "./useEditorLock.js";
4
- import { useSaveStart as D, useSaveComplete as F } from "./useGuidoActions.js";
5
- import { useSaveValidation as j } from "./useSaveValidation.js";
6
- import { useSaveValidationRollout as z } from "./useSaveValidationRollout.js";
7
- import { useSyncModuleExtractor as G } from "./useSyncModuleExtractor.js";
8
- import { ToasterTypeOptions as I } from "../enums/toaster.js";
9
- import { useStripoApi as J } from "../services/stripoApi.js";
10
- import { useConfigStore as K } from "../stores/config.js";
11
- import { useDynamicContentStore as N } from "../stores/dynamic-content.js";
12
- import { useSaveValidationStore as Q } from "../stores/save-validation.js";
13
- import { useTemplatePreparation as X, getHtmlReferencedUnsubscribePages as Y } from "../utils/templatePreparation.js";
14
- import { useAllowlist as Z } from "./useAllowlist.js";
15
- import { useHtmlValidator as _ } from "./useHtmlValidator.js";
16
- import { useToaster as $ } from "./useToaster.js";
17
- import { useCouponBlockValidator as tt } from "./validators/useCouponBlockValidator.js";
18
- import { useLiquidValidator as et } from "./validators/useLiquidValidator.js";
19
- import { useSyncModuleBlockValidator as ot } from "./validators/useSyncModuleBlockValidator.js";
20
- import { useUnsubscribeBlockValidator as st } from "./validators/useUnsubscribeBlockValidator.js";
21
- const Bt = () => {
22
- const a = D(), p = F(), { validateHtml: v } = _(), { validateLiquidSyntax: S } = et(), { validateCouponBlockTags: y } = tt(), { validateUnsubscribeBlockUniqueness: w, validateUnsubscribeBlockHasTemplate: E } = st(), { validateSyncModuleBlocks: n } = ot(), { callbacks: r, isFeatureEnabled: d } = q(), { extractSyncModuleData: b } = G(), { setSyncModuleUnsubscriptionPages: g } = J(), { editorSave: H, getTemplateData: V } = R(), { showToaster: x } = $(), { getBlockedDomains: k, resolveToast: C } = Z(), { prepareTemplateDetails: m } = X(), { collectSaveValidationErrors: B } = j(), { isEnabled: h } = z(), T = Q(), P = N(), f = K(), { runExclusive: l } = O(), c = async (t, e, o) => {
23
- if (!d("allowlistEnabled"))
1
+ import { useActionsApi as q } from "./useActionsApi.js";
2
+ import { useConfig as O } from "./useConfig.js";
3
+ import { useEditorLock as D } from "./useEditorLock.js";
4
+ import { useSaveStart as F, useSaveComplete as j } from "./useGuidoActions.js";
5
+ import { useSaveValidation as z } from "./useSaveValidation.js";
6
+ import { useSaveValidationRollout as G } from "./useSaveValidationRollout.js";
7
+ import { useSyncModuleExtractor as I } from "./useSyncModuleExtractor.js";
8
+ import { ToasterTypeOptions as J } from "../enums/toaster.js";
9
+ import { useStripoApi as K } from "../services/stripoApi.js";
10
+ import { useConfigStore as N } from "../stores/config.js";
11
+ import { useDynamicContentStore as Q } from "../stores/dynamic-content.js";
12
+ import { useSaveValidationStore as X } from "../stores/save-validation.js";
13
+ import { useTemplatePreparation as Y, getHtmlReferencedUnsubscribePages as Z } from "../utils/templatePreparation.js";
14
+ import { useAllowlist as _ } from "./useAllowlist.js";
15
+ import { useHtmlValidator as $ } from "./useHtmlValidator.js";
16
+ import { useToaster as tt } from "./useToaster.js";
17
+ import { useCouponBlockValidator as et } from "./validators/useCouponBlockValidator.js";
18
+ import { useHtmlDocumentCountValidator as ot } from "./validators/useHtmlDocumentCountValidator.js";
19
+ import { useLiquidValidator as it } from "./validators/useLiquidValidator.js";
20
+ import { useSyncModuleBlockValidator as st } from "./validators/useSyncModuleBlockValidator.js";
21
+ import { useUnsubscribeBlockValidator as at } from "./validators/useUnsubscribeBlockValidator.js";
22
+ const Pt = () => {
23
+ const n = F(), w = j(), { validateHtml: y } = $(), { validateLiquidSyntax: E } = it(), { validateCouponBlockTags: b } = et(), { validateUnsubscribeBlockUniqueness: g, validateUnsubscribeBlockHasTemplate: H } = at(), { validateSyncModuleBlocks: l } = st(), { validateSingleHtmlDocument: c } = ot(), { callbacks: r, isFeatureEnabled: v } = O(), { extractSyncModuleData: V } = I(), { setSyncModuleUnsubscriptionPages: x } = K(), { editorSave: C, getTemplateData: u } = q(), { showToaster: k } = tt(), { getBlockedDomains: h, resolveToast: B } = _(), { prepareTemplateDetails: p } = Y(), { collectSaveValidationErrors: T } = z(), { isEnabled: P } = G(), L = X(), U = Q(), S = N(), { runExclusive: m } = D(), d = async (t, e, i) => {
24
+ if (!v("allowlistEnabled"))
24
25
  return !1;
25
- const i = await k(t, e);
26
- if (!i.length)
26
+ const o = await h(t, e);
27
+ if (!o.length)
27
28
  return !1;
28
- if (!o) {
29
- const s = await C(i);
30
- s != null && s.message && x({
31
- type: I.Warning,
29
+ if (!i) {
30
+ const s = await B(o);
31
+ s != null && s.message && k({
32
+ type: J.Warning,
32
33
  message: s.message,
33
34
  actionButton: s.actionButton
34
35
  });
35
36
  }
36
37
  return !0;
37
- }, L = async (t) => !y(t.compiledHtml) || !w(t.compiledHtml) || !E(t.compiledHtml) ? !1 : d("liquidSyntax") ? S(t.compiledHtml) : v(t.compiledHtml, t.dynamicContentList, !0), u = async (t, e) => {
38
- if (!await H())
38
+ }, A = async (t) => !b(t.compiledHtml) || !g(t.compiledHtml) || !H(t.compiledHtml) ? !1 : v("liquidSyntax") ? E(t.compiledHtml) : y(t.compiledHtml, t.dynamicContentList, !0), f = async (t, e) => {
39
+ if (!await C())
39
40
  return;
40
- const { unsubscribePayload: i, stripoModules: s } = b(t.rawHtml);
41
- if (await g(i), t.modules = s, !e.suppress) {
42
- const W = e.blankCompiled ? { compiledHtml: "", ampHtml: "" } : {};
43
- p({ ...t, ...W, silent: e.silent });
41
+ const { unsubscribePayload: o, stripoModules: s } = V(t.rawHtml);
42
+ if (await x(o), t.modules = s, !e.suppress) {
43
+ const a = e.blankCompiled ? { compiledHtml: "", ampHtml: "" } : {};
44
+ w({ ...t, ...a, silent: e.silent });
44
45
  }
45
46
  return t;
46
- }, U = async (t, e) => {
47
- var i;
48
- a();
49
- const o = await m();
50
- if (n(o.rawHtml, e)) {
51
- if (h.value && !e) {
52
- const s = await B(
47
+ }, M = async (t, e) => {
48
+ var s;
49
+ n();
50
+ const i = await u();
51
+ if (!c(i.html, e))
52
+ return;
53
+ const o = await p(i);
54
+ if (l(o.rawHtml, e)) {
55
+ if (P.value && !e) {
56
+ const a = await T(
53
57
  o.compiledHtml,
54
58
  o.dynamicContentList
55
59
  );
56
- if (s.length) {
57
- T.open(s, "save");
60
+ if (a.length) {
61
+ L.open(a, "save");
58
62
  return;
59
63
  }
60
- } else if (!await L(o))
64
+ } else if (!await A(o))
61
65
  return;
62
- if (!((i = r.value) != null && i.externalValidation && !await r.value.externalValidation(o)) && !await c(o.compiledHtml, o.css, e))
63
- return u(o, { silent: e, suppress: t });
66
+ if (!((s = r.value) != null && s.externalValidation && !await r.value.externalValidation(o)) && !await d(o.compiledHtml, o.css, e))
67
+ return f(o, { silent: e, suppress: t });
64
68
  }
65
- }, A = async () => {
66
- var e;
67
- if (!f.allowSaveWithErrors)
69
+ }, W = async () => {
70
+ var i;
71
+ if (!S.allowSaveWithErrors)
72
+ return;
73
+ n();
74
+ const t = await u();
75
+ if (!c(t.html, !1))
68
76
  return;
69
- a();
70
- const t = await m();
71
- if (n(t.rawHtml, !1) && !((e = r.value) != null && e.externalValidation && !await r.value.externalValidation(t)) && !await c(t.compiledHtml, t.css, !1))
72
- return u(t, { silent: !1, blankCompiled: !0 });
73
- }, M = async () => {
74
- if (!f.allowSaveWithErrors)
77
+ const e = await p(t);
78
+ if (l(e.rawHtml, !1) && !((i = r.value) != null && i.externalValidation && !await r.value.externalValidation(e)) && !await d(e.compiledHtml, e.css, !1))
79
+ return f(e, { silent: !1, blankCompiled: !0 });
80
+ }, R = async () => {
81
+ if (!S.allowSaveWithErrors)
75
82
  return;
76
- a();
77
- const { html: t, css: e } = await V();
78
- if (!n(t, !0) || await c(t, e, !0))
83
+ n();
84
+ const { html: t, css: e } = await u();
85
+ if (!c(t, !0) || !l(t, !0) || await d(t, e, !0))
79
86
  return;
80
- const o = Y(t), i = {
81
- dynamicContentList: P.getSelectedDynamicContentList,
87
+ const i = Z(t), o = {
88
+ dynamicContentList: U.getSelectedDynamicContentList,
82
89
  compiledHtml: "",
83
90
  rawHtml: t,
84
91
  css: e,
@@ -88,16 +95,16 @@ const Bt = () => {
88
95
  // No campaignUrls: hosts overwrite their stored map with any object, and raw HTML can't rebuild it.
89
96
  recommendation: { configs: {} },
90
97
  unsubscribe: {
91
- status: o.length > 0,
92
- config: o
98
+ status: i.length > 0,
99
+ config: i
93
100
  }
94
101
  };
95
- return u(i, { silent: !0 });
102
+ return f(o, { silent: !0 });
96
103
  };
97
- return { save: (t = !1, e = !1) => l(
98
- () => U(t, e)
99
- ), saveWithErrors: () => l(A), saveRawOnly: () => l(M) };
104
+ return { save: (t = !1, e = !1) => m(
105
+ () => M(t, e)
106
+ ), saveWithErrors: () => m(W), saveRawOnly: () => m(R) };
100
107
  };
101
108
  export {
102
- Bt as useSave
109
+ Pt as useSave
103
110
  };
@@ -0,0 +1,22 @@
1
+ import { useToaster as i } from "../useToaster.js";
2
+ import { useTranslations as m } from "../useTranslations.js";
3
+ import { ToasterTypeOptions as c } from "../../enums/toaster.js";
4
+ const u = "newsletter.multiple-html-designs-detected", r = `(?:[^>"']|"[^"]*"|'[^']*')*`, a = "style|script|noscript|xmp|iframe|noembed|noframes|textarea|title", T = /<html(?=[\s>/])/gi, A = new RegExp(
5
+ `<!--[\\s\\S]*?-->|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>|<(${a})(?=[\\s/>])${r}>[\\s\\S]*?</\\1\\s*>|<([a-zA-Z][\\w:-]*)${r}>`,
6
+ "gi"
7
+ ), p = (e) => Array.from(e.matchAll(A)).filter(([, , t]) => (t == null ? void 0 : t.toLowerCase()) === "html").length, g = () => {
8
+ const { showToaster: e } = i(), t = m();
9
+ return { validateSingleHtmlDocument: (o, l = !1) => {
10
+ var n;
11
+ if ((((n = o.match(T)) == null ? void 0 : n.length) ?? 0) < 2)
12
+ return !0;
13
+ const s = p(o);
14
+ return s <= 1 ? !0 : (console.debug("guido:save:blocked", { reason: "multiple-html-documents", htmlRootCount: s }), l || e({
15
+ type: c.Warning,
16
+ message: t(u)
17
+ }), !1);
18
+ } };
19
+ };
20
+ export {
21
+ g as useHtmlDocumentCountValidator
22
+ };
@@ -1,54 +1,62 @@
1
- import { CURRENCY_ATTR as c, CSS_CLASS_SKIP_COMPILE as a } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
2
- const m = "You May Also Like!";
3
- function S(t) {
1
+ import { CURRENCY_ATTR as c, CSS_CLASS_SKIP_COMPILE as p } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
2
+ const a = "You May Also Like!";
3
+ function C(t) {
4
4
  var o;
5
5
  const e = t.querySelector(".ext-recommendation-title");
6
6
  if (!e)
7
- return m;
7
+ return a;
8
8
  const r = (o = e.textContent) == null ? void 0 : o.trim();
9
- return r && r.length > 0 ? r : m;
9
+ return r && r.length > 0 ? r : a;
10
10
  }
11
- function T(t) {
11
+ function S(t) {
12
12
  const e = t.querySelector(".ext-recommendation-title");
13
13
  return e ? !/display\s*:\s*none/i.test(e.getAttribute("style") ?? "") : !1;
14
14
  }
15
- function f(t) {
15
+ function g(t) {
16
16
  var r;
17
17
  const e = t.querySelector(".ext-recommendation-title");
18
18
  return !!e && !((r = e == null ? void 0 : e.textContent) != null && r.trim());
19
19
  }
20
- function g(t) {
20
+ function T(t) {
21
21
  const e = t.querySelector(".ext-product-price"), r = t.querySelector(".ext-product-original-price");
22
22
  return !e || !r ? !1 : e.compareDocumentPosition(r) === Node.DOCUMENT_POSITION_PRECEDING;
23
23
  }
24
+ function m(t) {
25
+ return /(?:^|;)\s*display\s*:\s*table-cell/i.test(t.getAttribute("style") ?? "");
26
+ }
27
+ function y(t) {
28
+ var o, n;
29
+ const e = (o = t.querySelector(".ext-product-price")) == null ? void 0 : o.closest("tr"), r = (n = t.querySelector(".ext-product-original-price")) == null ? void 0 : n.closest("tr");
30
+ return !e || !r || e === r ? !1 : !m(e) && !m(r);
31
+ }
24
32
  const d = /* @__PURE__ */ new Map([
25
33
  ["p_name", ".ext-product-name p"],
26
34
  ["p_price", ".ext-product-price p"],
27
35
  ["p_original_price", ".ext-product-original-price p"]
28
36
  ]);
29
- function p(t) {
37
+ function A(t) {
30
38
  const e = ((t == null ? void 0 : t.getAttribute("style")) ?? "").match(/(?:^|;)\s*color\s*:\s*([^;]+)/i);
31
39
  return (e == null ? void 0 : e[1].trim()) || void 0;
32
40
  }
33
- const A = "ins-trim-text";
34
- function x(t, e) {
41
+ const f = "ins-trim-text";
42
+ function E(t, e) {
35
43
  return t == null ? void 0 : t.map((r) => {
36
- var s, l;
44
+ var u, l;
37
45
  const o = d.get(r.variable ?? "");
38
46
  if (!o)
39
47
  return r;
40
- const n = e.querySelector(o), u = (l = (s = r.theme) == null ? void 0 : s.textColor) != null && l.color ? void 0 : p(n), i = r.variable === "p_name" && (n == null ? void 0 : n.classList.contains(A));
41
- return !u && !i ? r : {
48
+ const n = e.querySelector(o), s = (l = (u = r.theme) == null ? void 0 : u.textColor) != null && l.color ? void 0 : A(n), i = r.variable === "p_name" && (n == null ? void 0 : n.classList.contains(f));
49
+ return !s && !i ? r : {
42
50
  ...r,
43
51
  theme: {
44
52
  ...r.theme,
45
- ...u ? { textColor: { color: u } } : {},
53
+ ...s ? { textColor: { color: s } } : {},
46
54
  ...i ? { textTrimming: !0 } : {}
47
55
  }
48
56
  };
49
57
  });
50
58
  }
51
- function E(t) {
59
+ function _(t) {
52
60
  const e = [
53
61
  t,
54
62
  ...Array.from(t.querySelectorAll(".product-card, .ext-recommendation-card"))
@@ -62,7 +70,7 @@ function E(t) {
62
70
  return i && i[1] ? (r = i[1].trim(), !0) : !1;
63
71
  }), r;
64
72
  }
65
- function _(t) {
73
+ function R(t) {
66
74
  const e = t.getAttribute(c.CURRENCY);
67
75
  if (!e)
68
76
  return;
@@ -78,16 +86,17 @@ function _(t) {
78
86
  thousandSeparator: t.getAttribute(c.THOUSAND_SEPARATOR) ?? ""
79
87
  };
80
88
  }
81
- function y(t) {
82
- return t.classList.contains(a);
89
+ function L(t) {
90
+ return t.classList.contains(p);
83
91
  }
84
92
  export {
85
- E as extractCardBgColor,
86
- _ as extractCurrencyFromBlock,
87
- S as extractTitleText,
88
- f as hasEmptyTitle,
89
- T as hasVisibleTitle,
90
- g as isOldPriceFirst,
91
- y as isPartnerManagedBlock,
92
- x as withRenderedTextTheme
93
+ _ as extractCardBgColor,
94
+ R as extractCurrencyFromBlock,
95
+ C as extractTitleText,
96
+ g as hasEmptyTitle,
97
+ S as hasVisibleTitle,
98
+ T as isOldPriceFirst,
99
+ L as isPartnerManagedBlock,
100
+ y as isPriceOnNextLine,
101
+ E as withRenderedTextTheme
93
102
  };