@useinsider/guido 3.26.0 → 3.27.0-beta.0dd857f

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 (124) hide show
  1. package/README.md +1 -0
  2. package/dist/@types/config/schemas.js +93 -91
  3. package/dist/@types/display-condition.js +25 -0
  4. package/dist/@types/email-be/html-validation.js +28 -0
  5. package/dist/components/Guido.vue.js +5 -5
  6. package/dist/components/Guido.vue2.js +104 -98
  7. package/dist/components/organisms/display-conditions/CodeEditorField.vue.js +17 -0
  8. package/dist/components/organisms/display-conditions/CodeEditorField.vue2.js +41 -0
  9. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.js +30 -0
  10. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue2.js +81 -0
  11. package/dist/components/organisms/display-conditions/DisplayConditionListState.vue.js +17 -0
  12. package/dist/components/organisms/display-conditions/DisplayConditionListState.vue2.js +45 -0
  13. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.js +36 -0
  14. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue2.js +63 -0
  15. package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue.js +17 -0
  16. package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue2.js +22 -0
  17. package/dist/components/organisms/onboarding/GenericOnboarding.vue.js +5 -5
  18. package/dist/components/organisms/onboarding/GenericOnboarding.vue2.js +15 -15
  19. package/dist/components/organisms/onboarding/ItemsOnboarding.vue.js +6 -6
  20. package/dist/components/organisms/onboarding/ItemsOnboarding.vue2.js +28 -27
  21. package/dist/components/organisms/onboarding/RecommendationLegacyStrategyOnboarding.vue.js +3 -3
  22. package/dist/components/organisms/onboarding/RecommendationLegacyStrategyOnboarding.vue2.js +42 -27
  23. package/dist/composables/useBlocksConfig.js +29 -20
  24. package/dist/composables/useCustomInterfaceAppearance.js +50 -50
  25. package/dist/composables/useDisplayConditions.js +116 -0
  26. package/dist/composables/useFullStoryBridge.js +10 -9
  27. package/dist/composables/useSave.js +19 -17
  28. package/dist/composables/useSaveValidation.js +134 -252
  29. package/dist/composables/useTranslations.js +14 -8
  30. package/dist/config/compiler/utils/itemsCompilerUtils.js +43 -42
  31. package/dist/config/compiler/utils/recommendationCompilerUtils.js +67 -64
  32. package/dist/enums/academy.js +1 -0
  33. package/dist/enums/display-condition.js +12 -0
  34. package/dist/enums/email-be.js +27 -0
  35. package/dist/enums/save-validation.js +2 -2
  36. package/dist/extensions/Blocks/Recommendation/controls/main/filters.js +14 -14
  37. package/dist/extensions/Blocks/Recommendation/controls/main/strategy.js +52 -40
  38. package/dist/extensions/Blocks/Recommendation/controls/syncInfoMessage.js +15 -15
  39. package/dist/extensions/Blocks/Recommendation/utils/priceFormatter.js +17 -15
  40. package/dist/extensions/Blocks/common-control.js +25 -25
  41. package/dist/extensions/DisplayConditions/bridge.js +25 -0
  42. package/dist/extensions/DisplayConditions/constants.js +26 -0
  43. package/dist/extensions/DisplayConditions/control.js +215 -0
  44. package/dist/extensions/DisplayConditions/display-conditions.css.js +226 -0
  45. package/dist/extensions/DisplayConditions/extension.js +28 -0
  46. package/dist/extensions/DisplayConditions/iconsRegistry.js +20 -0
  47. package/dist/extensions/DisplayConditions/library.js +30 -0
  48. package/dist/extensions/DisplayConditions/settingsPanel.js +17 -0
  49. package/dist/extensions/DynamicContent/dynamic-content.js +15 -17
  50. package/dist/guido.css +1 -1
  51. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +93 -92
  52. package/dist/node_modules/valibot/dist/index.js +405 -291
  53. package/dist/package.json.js +2 -2
  54. package/dist/services/displayConditionApi.js +39 -0
  55. package/dist/services/emailBe/errors/ApiError.js +50 -0
  56. package/dist/services/emailBe/errors/handleApiError.js +31 -0
  57. package/dist/services/emailBe/errors/toApiError.js +71 -0
  58. package/dist/services/emailBe/html/HtmlValidationService.js +35 -0
  59. package/dist/services/emailBe/html/index.js +6 -0
  60. package/dist/services/emailBe/http/HttpManager.js +68 -0
  61. package/dist/services/emailBe/http/RetryStack.js +24 -0
  62. package/dist/services/emailBe/http/client.js +61 -0
  63. package/dist/services/emailBe/http/index.js +10 -0
  64. package/dist/services/emailBe/http/transportErrors.js +20 -0
  65. package/dist/src/@types/config/schemas.d.ts +4 -0
  66. package/dist/src/@types/display-condition.d.ts +61 -0
  67. package/dist/src/@types/email-be/html-validation.d.ts +51 -0
  68. package/dist/src/components/organisms/display-conditions/CodeEditorField.vue.d.ts +43 -0
  69. package/dist/src/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.d.ts +2 -0
  70. package/dist/src/components/organisms/display-conditions/DisplayConditionListState.vue.d.ts +18 -0
  71. package/dist/src/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.d.ts +2 -0
  72. package/dist/src/components/organisms/display-conditions/DisplayConditionsHost.vue.d.ts +2 -0
  73. package/dist/src/composables/useConfig.d.ts +2 -0
  74. package/dist/src/composables/useDisplayConditions.d.ts +18 -0
  75. package/dist/src/composables/useSaveValidation.d.ts +2 -2
  76. package/dist/src/enums/academy.d.ts +1 -0
  77. package/dist/src/enums/display-condition.d.ts +15 -0
  78. package/dist/src/enums/email-be.d.ts +26 -0
  79. package/dist/src/enums/save-validation.d.ts +3 -15
  80. package/dist/src/extensions/Blocks/Recommendation/controls/main/strategy.d.ts +2 -0
  81. package/dist/src/extensions/Blocks/common-control.d.ts +1 -1
  82. package/dist/src/extensions/DisplayConditions/bridge.d.ts +7 -0
  83. package/dist/src/extensions/DisplayConditions/constants.d.ts +23 -0
  84. package/dist/src/extensions/DisplayConditions/control.d.ts +25 -0
  85. package/dist/src/extensions/{Blocks/_Boilerplate → DisplayConditions}/iconsRegistry.d.ts +1 -1
  86. package/dist/src/extensions/DisplayConditions/library.d.ts +8 -0
  87. package/dist/src/extensions/DisplayConditions/settingsPanel.d.ts +5 -0
  88. package/dist/src/mock/api/display-conditions.d.ts +2 -0
  89. package/dist/src/services/displayConditionApi.d.ts +8 -0
  90. package/dist/src/services/emailBe/errors/ApiError.d.ts +40 -0
  91. package/dist/src/services/emailBe/errors/handleApiError.d.ts +11 -0
  92. package/dist/src/services/emailBe/errors/toApiError.d.ts +2 -0
  93. package/dist/src/services/emailBe/html/HtmlValidationService.d.ts +8 -0
  94. package/dist/src/services/emailBe/html/index.d.ts +2 -0
  95. package/dist/src/services/emailBe/http/HttpManager.d.ts +13 -0
  96. package/dist/src/services/emailBe/http/RetryStack.d.ts +6 -0
  97. package/dist/src/services/emailBe/http/client.d.ts +3 -0
  98. package/dist/src/services/emailBe/http/index.d.ts +2 -0
  99. package/dist/src/services/emailBe/http/transportErrors.d.ts +15 -0
  100. package/dist/src/services/emailBe/http/types.d.ts +46 -0
  101. package/dist/src/stores/config.d.ts +170 -0
  102. package/dist/src/stores/display-condition.d.ts +86 -0
  103. package/dist/src/stores/onboarding.d.ts +1 -0
  104. package/dist/src/utils/displayCondition.d.ts +11 -0
  105. package/dist/src/utils/editorShadowRoot.d.ts +1 -0
  106. package/dist/src/utils/protectTableText.d.ts +2 -0
  107. package/dist/static/styles/variables.css.js +1 -0
  108. package/dist/stores/config.js +13 -6
  109. package/dist/stores/display-condition.js +29 -0
  110. package/dist/stores/onboarding.js +4 -1
  111. package/dist/utils/displayCondition.js +29 -0
  112. package/dist/utils/editorShadowRoot.js +8 -0
  113. package/dist/utils/pairProductVariables.js +29 -28
  114. package/dist/utils/protectTableText.js +22 -0
  115. package/package.json +10 -2
  116. package/dist/src/extensions/Blocks/_Boilerplate/block.d.ts +0 -11
  117. package/dist/src/extensions/Blocks/_Boilerplate/constants/controlIds.d.ts +0 -7
  118. package/dist/src/extensions/Blocks/_Boilerplate/constants/index.d.ts +0 -10
  119. package/dist/src/extensions/Blocks/_Boilerplate/constants/selectors.d.ts +0 -16
  120. package/dist/src/extensions/Blocks/_Boilerplate/control.d.ts +0 -17
  121. package/dist/src/extensions/Blocks/_Boilerplate/controls/blockBackground/index.d.ts +0 -15
  122. package/dist/src/extensions/Blocks/_Boilerplate/settingsPanel.d.ts +0 -4
  123. package/dist/src/extensions/Blocks/_Boilerplate/template.d.ts +0 -6
  124. /package/dist/src/extensions/{Blocks/_Boilerplate → DisplayConditions}/extension.d.ts +0 -0
@@ -0,0 +1,116 @@
1
+ import { useToaster as M } from "./useToaster.js";
2
+ import { useTranslations as x } from "./useTranslations.js";
3
+ import { ACADEMY_LINKS as L } from "../enums/academy.js";
4
+ import { DisplayConditionSourceType as y, DISPLAY_CONDITION_LIMITS as s, DisplayConditionEvent as I } from "../enums/display-condition.js";
5
+ import { ToasterTypeOptions as l } from "../enums/toaster.js";
6
+ import { useDisplayConditionApi as O } from "../services/displayConditionApi.js";
7
+ import { useConfigStore as q } from "../stores/config.js";
8
+ import { useDisplayConditionStore as P } from "../stores/display-condition.js";
9
+ import { findInvalidCodeFields as Y, nextConditionId as w } from "../utils/displayCondition.js";
10
+ import { escapeHtml as R } from "../utils/htmlEscape.js";
11
+ import { computed as b } from "vue";
12
+ const B = "email-editor.display-conditions", i = B, F = 409, S = (n, m, r) => ({
13
+ id: w(),
14
+ name: n.name.trim(),
15
+ description: n.description.trim(),
16
+ beforeScript: n.codeBefore,
17
+ afterScript: n.codeAfter,
18
+ extraData: JSON.stringify(r === void 0 ? { source: m } : { source: m, savedId: r })
19
+ }), v = (n) => ({
20
+ name: n.name,
21
+ description: n.description,
22
+ codeBefore: n.codeBefore,
23
+ codeAfter: n.codeAfter
24
+ }), ne = () => {
25
+ const n = P(), m = q(), r = O(), o = x(), { showToaster: p } = M(), u = b(
26
+ () => m.isFeatureEnabled("liquidSyntax") ? "liquid" : "pongo"
27
+ ), f = (e) => {
28
+ const t = { condition: e };
29
+ return document.dispatchEvent(new CustomEvent(I.APPLY, { detail: t })), n.close(), t.applied === !0;
30
+ }, D = () => {
31
+ n.view !== "none" && (document.dispatchEvent(new CustomEvent(I.CANCEL)), n.close());
32
+ }, N = (e) => {
33
+ if (e.mode === "select") {
34
+ n.openSelect();
35
+ return;
36
+ }
37
+ n.openCreate(e.mode === "edit" ? e.current : null);
38
+ }, $ = async () => {
39
+ const e = ++n.listRequest;
40
+ n.listStatus = "loading";
41
+ try {
42
+ const t = await r.list(u.value);
43
+ e === n.listRequest && (n.list = t, n.listStatus = "loaded");
44
+ } catch (t) {
45
+ console.warn("Display conditions could not be loaded.", t), e === n.listRequest && (n.listStatus = "error");
46
+ }
47
+ }, h = (e) => {
48
+ const t = {}, d = e.name.trim();
49
+ d ? d.length < s.NAME_MIN ? t.name = o(`${i}.error-name-min`, { min: s.NAME_MIN }) : d.length > s.NAME_MAX && (t.name = o(`${i}.error-name-max`, { max: s.NAME_MAX })) : t.name = o(`${i}.error-name-required`);
50
+ const { DESCRIPTION_MAX: C } = s;
51
+ e.description.trim().length > C && (t.description = o(`${i}.error-description-max`, { max: C }));
52
+ const g = Y(e.codeBefore, e.codeAfter, u.value);
53
+ return ["codeBefore", "codeAfter"].forEach((a) => {
54
+ e[a].trim() ? g.includes(a) ? t[a] = o(`${i}.error-code-invalid`) : e[a].length > s.CODE_MAX && (t[a] = o(`${i}.error-code-max`, { max: s.CODE_MAX })) : t[a] = o(`${i}.error-code-required`);
55
+ }), t;
56
+ }, A = (e, t) => {
57
+ p(e ? { type: l.Success, message: t } : { type: l.Error, message: o("products.something-went-wrong") });
58
+ }, T = (e) => o(
59
+ `${i}.${e}`,
60
+ {
61
+ academyLink: `<a href="${L.EMAIL_DISPLAY_CONDITIONS}" target="_blank" style="color: #0A2ECC; text-decoration: underline;">${o(`${i}.academy`)}</a>`
62
+ }
63
+ ), _ = () => {
64
+ p({ type: l.Error, message: o(`${i}.validation-failed`) });
65
+ }, c = (e) => ({ name: R(e) }), E = (e, t) => {
66
+ e != null && e.authReported || (console.warn(t, e), p({ type: l.Error, message: t }));
67
+ };
68
+ return {
69
+ syntax: u,
70
+ handleOpen: N,
71
+ cancel: D,
72
+ loadList: $,
73
+ validate: h,
74
+ notifyInvalid: _,
75
+ describeWithAcademyLink: T,
76
+ createInline: (e) => {
77
+ A(
78
+ f(S(e, y.INLINE)),
79
+ o(`${i}.created`, c(e.name.trim()))
80
+ );
81
+ },
82
+ createAndSave: async (e) => {
83
+ try {
84
+ const t = await r.create(e, u.value);
85
+ return n.list = [t, ...n.list.filter((d) => d.id !== t.id)], A(
86
+ f(S(v(t), y.SAVED, t.id)),
87
+ o(`${i}.created-and-saved`, c(t.name))
88
+ ), {};
89
+ } catch (t) {
90
+ return (t == null ? void 0 : t.status) === F ? { name: o(`${i}.error-name-exists`) } : (E(t, o(`${i}.save-failed`, c(e.name.trim()))), null);
91
+ }
92
+ },
93
+ select: (e) => {
94
+ A(
95
+ f(S(v(e), y.SAVED, e.id)),
96
+ o(`${i}.applied`, c(e.name))
97
+ );
98
+ },
99
+ deleteSaved: async (e) => {
100
+ try {
101
+ await r.remove(e.id), n.list = n.list.filter((t) => t.id !== e.id), p({
102
+ type: l.Success,
103
+ message: o(`${i}.deleted`, c(e.name))
104
+ });
105
+ } catch (t) {
106
+ E(t, o(`${i}.delete-failed`));
107
+ } finally {
108
+ n.pendingDelete = null;
109
+ }
110
+ }
111
+ };
112
+ };
113
+ export {
114
+ B as DISPLAY_CONDITIONS_TRANS_KEY,
115
+ ne as useDisplayConditions
116
+ };
@@ -1,15 +1,16 @@
1
+ import { findEditorShadowRoot as i } from "../utils/editorShadowRoot.js";
1
2
  import { FULLSTORY_BRIDGE_SCRIPT_URL as s } from "../utils/fullStoryScripts.js";
2
- const l = () => ({ injectFullStory: () => {
3
- var c;
4
- const n = window;
5
- if (typeof n._fs_org != "string" || !n._fs_org)
3
+ const d = () => ({ injectFullStory: () => {
4
+ var n;
5
+ const e = window;
6
+ if (typeof e._fs_org != "string" || !e._fs_org)
6
7
  return;
7
- const e = document.querySelector("ui-editor"), o = (c = e == null ? void 0 : e.shadowRoot) == null ? void 0 : c.querySelector("iframe"), r = o == null ? void 0 : o.contentDocument;
8
- if (!r || r.querySelector('script[data-fullstory-bridge="true"]'))
8
+ const o = (n = i()) == null ? void 0 : n.querySelector("iframe"), t = o == null ? void 0 : o.contentDocument;
9
+ if (!t || t.querySelector('script[data-fullstory-bridge="true"]'))
9
10
  return;
10
- const t = r.createElement("script");
11
- t.src = s, t.async = !0, t.crossOrigin = "anonymous", t.dataset.fullstoryBridge = "true", r.head.appendChild(t);
11
+ const r = t.createElement("script");
12
+ r.src = s, r.async = !0, r.crossOrigin = "anonymous", r.dataset.fullstoryBridge = "true", t.head.appendChild(r);
12
13
  } });
13
14
  export {
14
- l as useFullStoryBridge
15
+ d as useFullStoryBridge
15
16
  };
@@ -16,40 +16,40 @@ import { useHtmlValidator as tt } from "./useHtmlValidator.js";
16
16
  import { useToaster as et } from "./useToaster.js";
17
17
  import { useCouponBlockValidator as ot } from "./validators/useCouponBlockValidator.js";
18
18
  import { useHtmlDocumentCountValidator as it } from "./validators/useHtmlDocumentCountValidator.js";
19
- import { useLiquidValidator as st } from "./validators/useLiquidValidator.js";
20
- import { useSyncModuleBlockValidator as rt } from "./validators/useSyncModuleBlockValidator.js";
19
+ import { useLiquidValidator as rt } from "./validators/useLiquidValidator.js";
20
+ import { useSyncModuleBlockValidator as st } from "./validators/useSyncModuleBlockValidator.js";
21
21
  import { useUnsubscribeBlockValidator as at } from "./validators/useUnsubscribeBlockValidator.js";
22
22
  const Pt = () => {
23
- const n = I(), S = N(), { validateHtml: y } = tt(), { validateLiquidSyntax: b } = st(), { validateCouponBlockTags: H } = ot(), {
23
+ const n = I(), S = N(), { validateHtml: y } = tt(), { validateLiquidSyntax: b } = rt(), { validateCouponBlockTags: H } = ot(), {
24
24
  validateUnsubscribeBlockUniqueness: E,
25
25
  validateUnsubscribeBlockHasTemplate: g,
26
26
  validateNoInsiderUnsubscribeCode: V
27
- } = at(), { validateSyncModuleBlocks: l } = rt(), { validateSingleHtmlDocument: c } = it(), { callbacks: a, isFeatureEnabled: u } = D(), { extractSyncModuleData: x } = G(), { setSyncModuleUnsubscriptionPages: k } = K(), { editorSave: C, getTemplateData: m } = O(), { showToaster: h } = et(), { getBlockedDomains: B, resolveToast: T } = $(), { prepareTemplateDetails: p } = Z(), { collectSaveValidationErrors: L } = j(), { isEnabled: P } = z(), U = Y(), A = X(), w = Q(), { runExclusive: d } = F(), f = async (t, e, i) => {
27
+ } = at(), { validateSyncModuleBlocks: l } = st(), { validateSingleHtmlDocument: c } = it(), { callbacks: a, isFeatureEnabled: u } = D(), { extractSyncModuleData: x } = G(), { setSyncModuleUnsubscriptionPages: k } = K(), { editorSave: C, getTemplateData: m } = O(), { showToaster: h } = et(), { getBlockedDomains: B, resolveToast: T } = $(), { prepareTemplateDetails: p } = Z(), { collectSaveValidationErrors: L } = j(), { isEnabled: P } = z(), U = Y(), A = X(), w = Q(), { runExclusive: d } = F(), f = async (t, e, i) => {
28
28
  if (!u("allowlistEnabled"))
29
29
  return !1;
30
30
  const o = await B(t, e);
31
31
  if (!o.length)
32
32
  return !1;
33
33
  if (!i) {
34
- const s = await T(o);
35
- s != null && s.message && h({
34
+ const r = await T(o);
35
+ r != null && r.message && h({
36
36
  type: J.Warning,
37
- message: s.message,
38
- actionButton: s.actionButton
37
+ message: r.message,
38
+ actionButton: r.actionButton
39
39
  });
40
40
  }
41
41
  return !0;
42
42
  }, M = async (t, e) => !H(t.compiledHtml) || u("blockUnsubscribeLinks") && !V(t.rawHtml, e) || !E(t.compiledHtml) || !g(t.compiledHtml) ? !1 : u("liquidSyntax") ? b(t.compiledHtml) : y(t.compiledHtml, t.dynamicContentList, !0), v = async (t, e) => {
43
43
  if (!await C())
44
44
  return;
45
- const { unsubscribePayload: o, stripoModules: s } = x(t.rawHtml);
46
- if (await k(o), t.modules = s, !e.suppress) {
47
- const r = e.blankCompiled ? { compiledHtml: "", ampHtml: "" } : {};
48
- S({ ...t, ...r, silent: e.silent });
45
+ const { unsubscribePayload: o, stripoModules: r } = x(t.rawHtml);
46
+ if (await k(o), t.modules = r, !e.suppress) {
47
+ const s = e.blankCompiled ? { compiledHtml: "", ampHtml: "" } : {};
48
+ S({ ...t, ...s, silent: e.silent });
49
49
  }
50
50
  return t;
51
51
  }, W = async (t, e) => {
52
- var s;
52
+ var r;
53
53
  n();
54
54
  const i = await m();
55
55
  if (!c(i.html, e))
@@ -57,18 +57,20 @@ const Pt = () => {
57
57
  const o = await p(i);
58
58
  if (l(o.rawHtml, e)) {
59
59
  if (P.value && !e) {
60
- const r = await L(
60
+ const s = await L(
61
61
  o.compiledHtml,
62
62
  o.dynamicContentList,
63
63
  o.rawHtml
64
64
  );
65
- if (r.length) {
66
- U.open(r, "save");
65
+ if (!s)
66
+ return;
67
+ if (s.length) {
68
+ U.open(s, "save");
67
69
  return;
68
70
  }
69
71
  } else if (!await M(o, e))
70
72
  return;
71
- if (!((s = a.value) != null && s.externalValidation && !await a.value.externalValidation(o)) && !await f(o.compiledHtml, o.css, e))
73
+ if (!((r = a.value) != null && r.externalValidation && !await a.value.externalValidation(o)) && !await f(o.compiledHtml, o.css, e))
72
74
  return v(o, { silent: e, suppress: t });
73
75
  }
74
76
  }, R = async () => {
@@ -1,289 +1,171 @@
1
- import { getIgnoredRecommendationBlockIds as Y } from "../config/compiler/utils/recommendationIgnoreUtils.js";
2
- import { CanNotMakeAnyChangesForRunningKey as k, DISPLAY_CONDITIONS_REGEX as U, DISPLAY_CONDITIONS_EXCEPTIONS_REGEX as M } from "../enums/html-validator.js";
3
- import { SaveValidationRule as o } from "../enums/save-validation.js";
4
- import { ToasterTypeOptions as r } from "../enums/toaster.js";
5
- import { BLOCK_ROOT_SELECTOR as x } from "../extensions/Blocks/Checkbox/constants/selectors.js";
6
- import { itemsBlockDynamicVariables as W } from "../extensions/Blocks/Items/enums/productEnums.js";
7
- import { BLOCK_ROOT_SELECTOR as G } from "../extensions/Blocks/RadioButton/constants/selectors.js";
8
- import { useRecommendationExtensionStore as P } from "../extensions/Blocks/Recommendation/store/recommendation.js";
9
- import { getInvalidFields as q, STRATEGY_FIELD_KEY as H, RecommendationAssignStrategyKey as V, RecommendationRequiredFieldsKey as X } from "../extensions/Blocks/Recommendation/validation/requiredFields.js";
10
- import { useConfigStore as j } from "../stores/config.js";
11
- import { useDynamicContentStore as z } from "../stores/dynamic-content.js";
12
- import { useRecommendationStore as $ } from "../stores/recommendation.js";
13
- import { base64EncodeWithSpecialChars as T } from "../utils/base64.js";
14
- import { escapeHtml as Q } from "../utils/htmlEscape.js";
15
- import { useTemplatePreparation as Z } from "../utils/templatePreparation.js";
16
- import { useActionsApi as J } from "./useActionsApi.js";
17
- import { useConfig as ee } from "./useConfig.js";
18
- import { useHtmlCompiler as te } from "./useHtmlCompiler.js";
19
- import { buildPartnerAttributeNameSet as ne, getInvalidDynamicContentTags as ie, getRecommendationBlockIds as oe, findInvalidCustomFields as re } from "./useHtmlValidator.js";
20
- import { useHttp as se } from "./useHttp.js";
21
- import { useTranslations as ae } from "./useTranslations.js";
22
- import { findInvalidCouponBlocks as ce, COUPON_TAG_MODIFIED_KEY as le } from "./validators/useCouponBlockValidator.js";
23
- import { hasInsiderUnsubscribeCode as ue, EXTERNALLY_MANAGED_UNSUBSCRIBE_KEY as me, findDuplicateUnsubPageTypes as de, countUnsubBlocksWithoutPage as pe, EMPTY_BLOCK_KEY as ge } from "./validators/useUnsubscribeBlockValidator.js";
24
- const fe = "newsletter.html-content-is-empty", ye = "custom-fields.missing-closing-braces", Ee = "custom-fields.missing-opening-braces", S = "custom-fields.invalid-custom-fields", Ie = "newsletter.display-conditions-invalid-syntax", Se = "custom-conditions.wrong-equality-operators", _e = "custom-conditions.missing-if-endif-tag", Ce = "custom-conditions.no-space-after-braces", he = "custom-conditions.no-braces-inside-if-tag", ke = "newsletter.fill-all-necessary-fields", Te = "newsletter.invalid-image-type", Fe = "unsubscribe-templates.select-checkbox-groups", be = "unsubscribe-templates.select-radio-button-groups", F = "newsletter.invalid-url-link-for-toaster", b = "journey-builder.liquid-validation-failed", Re = "/newsletter/template-library/check-template-html-body", Le = /src="[^"]*\.(svg|pst)"/gm, L = /({%(.*?)%})/g, Ne = ["if", "endif", "else", "elif", "now"], Oe = (t) => !Ne.includes(t.toLowerCase()), Ae = (t) => ["if", "endif"].includes(t.toLowerCase());
25
- function De(t) {
26
- return ce(t).map((i) => ({
27
- rule: o.CouponTagModified,
28
- type: r.Warning,
29
- key: le,
30
- detail: i
31
- }));
1
+ import { getIgnoredRecommendationBlockIds as A } from "../config/compiler/utils/recommendationIgnoreUtils.js";
2
+ import { HtmlSyntax as I } from "../enums/email-be.js";
3
+ import { DISPLAY_CONDITIONS_REGEX as B } from "../enums/html-validator.js";
4
+ import { SaveValidationRule as m } from "../enums/save-validation.js";
5
+ import { ToasterTypeOptions as l } from "../enums/toaster.js";
6
+ import { BLOCK_ROOT_SELECTOR as U } from "../extensions/Blocks/Checkbox/constants/selectors.js";
7
+ import { itemsBlockDynamicVariables as h } from "../extensions/Blocks/Items/enums/productEnums.js";
8
+ import { BLOCK_ROOT_SELECTOR as w } from "../extensions/Blocks/RadioButton/constants/selectors.js";
9
+ import { useRecommendationExtensionStore as K } from "../extensions/Blocks/Recommendation/store/recommendation.js";
10
+ import { getInvalidFields as x, STRATEGY_FIELD_KEY as G, RecommendationAssignStrategyKey as M, RecommendationRequiredFieldsKey as Y } from "../extensions/Blocks/Recommendation/validation/requiredFields.js";
11
+ import { htmlValidationService as H } from "../services/emailBe/html/index.js";
12
+ import { useConfigStore as P } from "../stores/config.js";
13
+ import { useDynamicContentStore as q } from "../stores/dynamic-content.js";
14
+ import { useRecommendationStore as V } from "../stores/recommendation.js";
15
+ import { escapeHtml as b } from "../utils/htmlEscape.js";
16
+ import { useTemplatePreparation as W } from "../utils/templatePreparation.js";
17
+ import { useActionsApi as X } from "./useActionsApi.js";
18
+ import { useConfig as j } from "./useConfig.js";
19
+ import { useHtmlCompiler as z } from "./useHtmlCompiler.js";
20
+ import { buildPartnerAttributeNameSet as $, getInvalidDynamicContentTags as Q, getRecommendationBlockIds as Z, findInvalidCustomFields as J } from "./useHtmlValidator.js";
21
+ import { useTranslations as tt } from "./useTranslations.js";
22
+ import { hasInsiderUnsubscribeCode as et, EXTERNALLY_MANAGED_UNSUBSCRIBE_KEY as nt } from "./validators/useUnsubscribeBlockValidator.js";
23
+ const E = "custom-fields.invalid-custom-fields", it = "custom-conditions.missing-if-endif-tag", ot = "newsletter.fill-all-necessary-fields", rt = "unsubscribe-templates.select-checkbox-groups", st = "unsubscribe-templates.select-radio-button-groups", at = /({%(.*?)%})/g, ct = ["unsubscribe-page-not-selected"], mt = ["malformed-merge-tag"], lt = "liquid-syntax-error", dt = ["if", "endif", "else", "elif", "now"], ut = (t) => !dt.includes(t.toLowerCase()), ft = (t) => ["if", "endif"].includes(t.toLowerCase());
24
+ function pt({ code: t, details: n }) {
25
+ return ct.includes(t) ? "" : (t === lt ? n.slice(1) : n).join(", ");
32
26
  }
33
- function ve(t) {
34
- return de(t).map((i) => ({
35
- rule: o.DuplicateUnsubBlock,
36
- type: r.Error,
37
- key: i.messageKey
38
- }));
27
+ function gt(t) {
28
+ const n = pt(t);
29
+ return {
30
+ rule: m.EmailBeHtml,
31
+ type: l.Error,
32
+ key: t.trans.key,
33
+ params: t.trans.replace,
34
+ ...n ? { detail: n } : {}
35
+ };
39
36
  }
40
- function Ke(t) {
41
- return Array.from({ length: pe(t) }, () => ({
42
- rule: o.UnsubBlockMissingTemplate,
43
- type: r.Warning,
44
- key: ge
45
- }));
46
- }
47
- function Be(t) {
48
- return ue(t) ? [{
49
- rule: o.ExternallyManagedUnsubscribe,
50
- type: r.Warning,
51
- key: me
37
+ function Et(t) {
38
+ return et(t) ? [{
39
+ rule: m.ExternallyManagedUnsubscribe,
40
+ type: l.Warning,
41
+ key: nt
52
42
  }] : [];
53
43
  }
54
- function we(t, i) {
55
- const n = t.match(L);
56
- if (!n)
44
+ function yt(t, n) {
45
+ const r = t.match(at);
46
+ if (!r)
57
47
  return [];
58
- const u = [];
59
- return n.forEach((m) => {
60
- const c = m.slice(2, -2).trim().match(/(".*?"|[^"\s]+)(?=\s*|\s*$)/g);
61
- if (c && c.length > 0) {
62
- const [d] = c;
63
- Oe(d) && !i.includes(d) && u.push({
64
- rule: o.CustomFieldScript,
65
- type: r.Warning,
66
- key: S,
67
- detail: d
48
+ const s = [];
49
+ return r.forEach((o) => {
50
+ const d = o.slice(2, -2).trim().match(/(".*?"|[^"\s]+)(?=\s*|\s*$)/g);
51
+ if (d && d.length > 0) {
52
+ const [u] = d;
53
+ ut(u) && !n.includes(u) && s.push({
54
+ rule: m.CustomFieldScript,
55
+ type: l.Warning,
56
+ key: E,
57
+ detail: u
68
58
  });
69
59
  }
70
- }), u;
71
- }
72
- function Ye(t) {
73
- return t.length > 0 ? [] : [{ rule: o.EmptyHtml, type: r.Warning, key: fe }];
60
+ }), s;
74
61
  }
75
- function Ue(t) {
76
- const i = (t.match(/{/gm) || []).length, n = (t.match(/}/gm) || []).length;
77
- return i > n ? [{
78
- rule: o.MismatchedBraces,
79
- type: r.Warning,
80
- key: ye
81
- }] : i < n ? [{
82
- rule: o.MismatchedBraces,
83
- type: r.Warning,
84
- key: Ee
85
- }] : [];
86
- }
87
- function Me(t) {
88
- return ie(t).map((i) => ({
89
- rule: o.InvalidDynamicTag,
90
- type: r.Warning,
91
- key: S,
92
- detail: i
62
+ function St(t) {
63
+ return Q(t).map((n) => ({
64
+ rule: m.InvalidDynamicTag,
65
+ type: l.Warning,
66
+ key: E,
67
+ detail: n
93
68
  }));
94
69
  }
95
- function xe(t, i, n, u) {
96
- const m = oe(t);
97
- return re(t, i, m, n, u).map((c) => ({
98
- rule: o.InvalidCustomField,
99
- type: r.Error,
100
- key: S,
101
- detail: c
70
+ function Ct(t, n, r, s) {
71
+ const o = Z(t);
72
+ return J(t, n, o, r, s).map((d) => ({
73
+ rule: m.InvalidCustomField,
74
+ type: l.Error,
75
+ key: E,
76
+ detail: d
102
77
  }));
103
78
  }
104
- function We(t) {
105
- const i = t.match(/{%(.*?)%}/g), n = [], u = [];
106
- if (i && i.forEach((m) => {
107
- const c = m.match(U), d = m.match(M), I = (c == null ? void 0 : c.join("")) || "";
108
- (!c || m !== I) && !d && u.push({
109
- rule: o.ConditionsSyntax,
110
- type: r.Error,
111
- key: Ie,
112
- detail: m
113
- }), c && c.forEach((g) => {
114
- g.trim() === "=" && u.push({
115
- rule: o.WrongEqualityOperator,
116
- type: r.Error,
117
- key: Se
118
- }), (g.match(/^[a-zA-Z]*$/g) ?? []).forEach((f) => {
119
- Ae(f) && n.push(f);
120
- });
121
- });
122
- }), n.length) {
123
- const m = n.filter((d) => d === "if").length, c = n.filter((d) => d === "endif").length;
124
- m !== c && u.push({
125
- rule: o.MissingIfEndif,
126
- type: r.Error,
127
- key: _e
128
- });
129
- }
130
- return u;
79
+ function It(t) {
80
+ const n = (t.match(/{%(.*?)%}/g) ?? []).flatMap((o) => o.match(B) ?? []).flatMap((o) => o.match(/^[a-zA-Z]*$/g) ?? []).filter(ft), r = n.filter((o) => o === "if").length, s = n.filter((o) => o === "endif").length;
81
+ return r === s ? [] : [{ rule: m.MissingIfEndif, type: l.Error, key: it }];
131
82
  }
132
- function Ge(t) {
133
- const i = (t.match(/{% /gm) || []).length, n = (t.match(/ %}/gm) || []).length;
134
- return i === n ? [] : [{
135
- rule: o.ConditionTagSpacing,
136
- type: r.Warning,
137
- key: Ce
138
- }];
83
+ function _(t, n, r, s) {
84
+ const o = new DOMParser().parseFromString(t, "text/html");
85
+ return Array.from(o.querySelectorAll(n)).filter((d) => {
86
+ var u;
87
+ return !((u = d.id) != null && u.trim());
88
+ }).map(() => ({ rule: r, type: l.Error, key: s }));
139
89
  }
140
- function Pe(t) {
141
- return (t.match(L) || []).filter((n) => n.includes("if")).map((n) => (n.match(/{{.*}}/gm) || []).length).reduce((n, u) => n + u, 0) === 0 ? [] : [{
142
- rule: o.BracesInsideIfTag,
143
- type: r.Warning,
144
- key: he
145
- }];
146
- }
147
- function qe(t) {
148
- return (t.match(Le) ?? []).map((i) => ({
149
- rule: o.InvalidImageType,
150
- type: r.Error,
151
- key: Te,
152
- detail: i
153
- }));
154
- }
155
- function R(t, i, n, u) {
156
- const m = new DOMParser().parseFromString(t, "text/html");
157
- return Array.from(m.querySelectorAll(i)).filter((c) => {
158
- var d;
159
- return !((d = c.id) != null && d.trim());
160
- }).map(() => ({ rule: n, type: r.Error, key: u }));
161
- }
162
- const ft = () => {
163
- const { config: t, isFeatureEnabled: i } = ee(), n = ae(), { post: u } = se(), { getCompiledEmail: m, getTemplateData: c } = J(), { compileHtml: d } = te(), { hydrateRecommendationStore: I } = Z(), g = z(), f = $(), y = P(), N = j(), O = (e) => ({
90
+ const _t = (t) => t && Object.fromEntries(Object.entries(t).map(([n, r]) => [n, b(String(r))])), Vt = () => {
91
+ const { config: t, isFeatureEnabled: n } = j(), r = tt(), { getCompiledEmail: s, getTemplateData: o } = X(), { compileHtml: d } = z(), { hydrateRecommendationStore: u } = W(), F = q(), O = V(), p = K(), R = P(), D = (e) => ({
164
92
  rule: e.rule,
165
93
  type: e.type,
166
94
  detail: e.detail,
167
- message: "key" in e ? n(e.key) : Q(e.message)
168
- }), A = async (e) => {
95
+ message: "key" in e ? r(e.key, _t(e.params)) : b(e.message)
96
+ }), T = async (e) => {
169
97
  if (e.size === 0)
170
98
  return /* @__PURE__ */ new Set();
171
99
  try {
172
- await y.fetchRecommendationFilters();
100
+ await p.fetchRecommendationFilters();
173
101
  } catch {
174
102
  return null;
175
103
  }
176
- return ne(y.filterList);
177
- }, D = async (e) => {
178
- try {
179
- const a = await u(Re, { html: T(e) }), { status: s, message: l } = a.data, p = [], E = s === void 0 && !!l && l !== n(F);
180
- return s || p.push({
181
- rule: o.InvalidLinks,
182
- type: r.Error,
183
- ...E ? { message: l } : { key: F }
184
- }), l === n(k) && p.push({
185
- rule: o.LinkCheckInProgress,
186
- type: r.Error,
187
- key: k
188
- }), p;
189
- } catch (a) {
190
- return console.warn("Link-check collector failed; skipping the link rule.", a), [];
191
- }
192
- }, v = async (e) => {
193
- try {
194
- const a = await u("/newsletter/contents/validate-syntax", [{
195
- identifier: "default",
196
- syntax: "liquid",
197
- contents: {
198
- subject: null,
199
- preheader: null,
200
- html: T(e),
201
- ampHtml: null
202
- }
203
- }]);
204
- if (!Array.isArray(a.data)) {
205
- const l = a.data;
206
- return [{
207
- rule: o.LiquidSyntax,
208
- type: r.Warning,
209
- message: l.message ?? n(b)
210
- }];
211
- }
212
- const [s] = a.data;
213
- return Object.values((s == null ? void 0 : s.errors) ?? {}).map((l) => ({
214
- rule: o.LiquidSyntax,
215
- type: r.Warning,
216
- message: l.replace(/^line \d+:\s*/, "")
217
- }));
218
- } catch (a) {
219
- if (a != null && a.authReported)
220
- throw a;
221
- return [{
222
- rule: o.LiquidSyntax,
223
- type: r.Error,
224
- message: n(b)
225
- }];
226
- }
227
- }, K = () => {
228
- const e = Object.values(y.blockStates).map((s) => q(s.recommendationConfigs, y)).filter((s) => s.length > 0).map((s) => {
229
- const l = s.every((p) => p === H);
104
+ return $(p.filterList);
105
+ }, k = async (e) => {
106
+ const a = await H.validate({
107
+ html: e,
108
+ syntax: n("liquidSyntax") ? I.LIQUID : I.PONGO
109
+ });
110
+ return a.ok ? a.data.errors.filter((i) => !mt.includes(i.code)).map(gt) : null;
111
+ }, v = () => {
112
+ const e = Object.values(p.blockStates).map((i) => x(i.recommendationConfigs, p)).filter((i) => i.length > 0).map((i) => {
113
+ const c = i.every((f) => f === G);
230
114
  return {
231
- rule: o.RecommendationRequiredFields,
232
- type: l ? r.Warning : r.Error,
233
- key: l ? V : X
115
+ rule: m.RecommendationRequiredFields,
116
+ type: c ? l.Warning : l.Error,
117
+ key: c ? M : Y
234
118
  };
235
- }), a = (f.recommendationConfigs ?? []).filter((s) => s.filters.some((l) => l.value === "")).map(() => ({
236
- rule: o.RecommendationFilters,
237
- type: r.Error,
238
- key: ke
119
+ }), a = (O.recommendationConfigs ?? []).filter((i) => i.filters.some((c) => c.value === "")).map(() => ({
120
+ rule: m.RecommendationFilters,
121
+ type: l.Error,
122
+ key: ot
239
123
  }));
240
124
  return [...e, ...a];
241
- }, B = async (e, a) => {
242
- var C, h;
243
- const s = [
244
- ...a.map((w) => w.value),
245
- ...W,
246
- ...((h = (C = t.value) == null ? void 0 : C.template) == null ? void 0 : h.customFieldAttributes) ?? []
247
- ], l = Y(e), p = await A(l), { isTransactional: E } = N;
125
+ }, L = async (e, a) => {
126
+ var S, C;
127
+ const i = [
128
+ ...a.map((N) => N.value),
129
+ ...h,
130
+ ...((C = (S = t.value) == null ? void 0 : S.template) == null ? void 0 : C.customFieldAttributes) ?? []
131
+ ], c = A(e), f = await T(c), { isTransactional: g } = R;
248
132
  return [
249
- ...await D(e),
250
- ...E ? [] : we(e, s),
251
- ...Ye(e),
252
- ...Ue(e),
253
- ...Me(e),
254
- ...E ? [] : xe(e, s, l, p),
255
- ...We(e),
256
- ...Ge(e),
257
- ...Pe(e),
258
- ...K(),
259
- ...qe(e),
260
- ...R(
133
+ ...g ? [] : yt(e, i),
134
+ ...St(e),
135
+ ...g ? [] : Ct(e, i, c, f),
136
+ ...It(e),
137
+ ...v(),
138
+ ..._(
261
139
  e,
262
- x,
263
- o.CheckboxUnsubGroup,
264
- Fe
140
+ U,
141
+ m.CheckboxUnsubGroup,
142
+ rt
265
143
  ),
266
- ...R(
144
+ ..._(
267
145
  e,
268
- G,
269
- o.RadioButtonUnsubGroup,
270
- be
146
+ w,
147
+ m.RadioButtonUnsubGroup,
148
+ st
271
149
  )
272
150
  ];
273
- }, _ = async (e, a, s) => [
274
- ...De(e),
275
- ...i("blockUnsubscribeLinks") ? Be(s) : [],
276
- ...ve(e),
277
- ...Ke(e),
278
- ...i("liquidSyntax") ? await v(e) : await B(e, a)
279
- ].map(O);
280
- return { collectSaveValidationErrors: _, validateCurrentTemplate: async () => {
281
- const { html: e } = await c();
282
- await I(e);
283
- const { html: a } = await m({ minimize: !0, resetDataSavedFlag: !1 }), { compiledHtml: s } = d(a);
284
- return _(s, g.getSelectedDynamicContentList, e);
151
+ }, y = async (e, a, i) => {
152
+ const [c, f] = await Promise.all([
153
+ k(e),
154
+ n("liquidSyntax") ? [] : L(e, a)
155
+ ]);
156
+ return c ? [
157
+ ...c,
158
+ ...n("blockUnsubscribeLinks") ? Et(i) : [],
159
+ ...f
160
+ ].map(D) : null;
161
+ };
162
+ return { collectSaveValidationErrors: y, validateCurrentTemplate: async () => {
163
+ const { html: e } = await o();
164
+ await u(e);
165
+ const { html: a } = await s({ minimize: !0, resetDataSavedFlag: !1 }), { compiledHtml: i } = d(a);
166
+ return y(i, F.getSelectedDynamicContentList, e);
285
167
  } };
286
168
  };
287
169
  export {
288
- ft as useSaveValidation
170
+ Vt as useSaveValidation
289
171
  };