@useinsider/guido 3.17.0-beta.dc7f4d2 → 3.17.0-beta.ec0523a

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 (43) hide show
  1. package/dist/components/Guido.vue.js +8 -8
  2. package/dist/components/Guido.vue2.js +76 -78
  3. package/dist/components/organisms/AutoSaveController.vue2.js +8 -9
  4. package/dist/components/organisms/header/EditorActions.vue.js +2 -2
  5. package/dist/components/organisms/header/EditorActions.vue2.js +43 -74
  6. package/dist/components/organisms/header/LeftSlot.vue.js +5 -5
  7. package/dist/components/organisms/header/LeftSlot.vue2.js +23 -46
  8. package/dist/components/wrappers/WpDrawer.vue.js +7 -9
  9. package/dist/components/wrappers/WpDrawer.vue2.js +1 -1
  10. package/dist/composables/useHtmlCompiler.js +26 -37
  11. package/dist/composables/useHtmlValidator.js +0 -2
  12. package/dist/composables/useSave.js +41 -84
  13. package/dist/composables/validators/useCouponBlockValidator.js +21 -24
  14. package/dist/composables/validators/useUnsubscribeBlockValidator.js +27 -34
  15. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +26 -33
  16. package/dist/guido.css +1 -1
  17. package/dist/src/components/Guido.vue.d.ts +1 -17
  18. package/dist/src/components/organisms/header/EditorActions.vue.d.ts +1 -17
  19. package/dist/src/components/organisms/header/HeaderWrapper.vue.d.ts +1 -17
  20. package/dist/src/components/organisms/header/RightSlot.vue.d.ts +1 -17
  21. package/dist/src/components/wrappers/WpDrawer.vue.d.ts +3 -4
  22. package/dist/src/composables/useHtmlValidator.d.ts +0 -21
  23. package/dist/src/composables/useSave.d.ts +1 -6
  24. package/dist/src/composables/validators/useCouponBlockValidator.d.ts +0 -3
  25. package/dist/src/composables/validators/useUnsubscribeBlockValidator.d.ts +0 -10
  26. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +0 -5
  27. package/dist/src/stores/config.d.ts +0 -5
  28. package/dist/src/utils/templatePreparation.d.ts +0 -30
  29. package/dist/stores/config.js +6 -13
  30. package/dist/utils/templatePreparation.js +25 -28
  31. package/package.json +1 -1
  32. package/dist/components/organisms/validation/ValidationErrorDrawer.vue.js +0 -20
  33. package/dist/components/organisms/validation/ValidationErrorDrawer.vue2.js +0 -48
  34. package/dist/composables/useSaveValidation.js +0 -279
  35. package/dist/composables/useSaveValidationRollout.js +0 -9
  36. package/dist/enums/save-validation.js +0 -4
  37. package/dist/src/@types/save-validation.d.ts +0 -19
  38. package/dist/src/components/organisms/validation/ValidationErrorDrawer.vue.d.ts +0 -2
  39. package/dist/src/composables/useSaveValidation.d.ts +0 -6
  40. package/dist/src/composables/useSaveValidationRollout.d.ts +0 -3
  41. package/dist/src/enums/save-validation.d.ts +0 -27
  42. package/dist/src/stores/save-validation.d.ts +0 -22
  43. package/dist/stores/save-validation.js +0 -30
@@ -10,11 +10,11 @@ interface Props {
10
10
  status: boolean;
11
11
  titleText: string;
12
12
  }
13
- declare var __VLS_13: {}, __VLS_15: {};
13
+ declare var __VLS_12: {}, __VLS_14: {};
14
14
  type __VLS_Slots = {} & {
15
- headerBottomSlot?: (props: typeof __VLS_13) => any;
15
+ headerBottomSlot?: (props: typeof __VLS_12) => any;
16
16
  } & {
17
- default?: (props: typeof __VLS_15) => any;
17
+ default?: (props: typeof __VLS_14) => any;
18
18
  };
19
19
  declare const __VLS_component: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToOption<Props>, {
20
20
  className: string;
@@ -26,7 +26,6 @@ declare const __VLS_component: import("vue").DefineComponent<__VLS_WithDefaults<
26
26
  cancelOrBackButtonEvent: () => void;
27
27
  onCloseEvent: () => void;
28
28
  primaryButtonEvent: () => void;
29
- secondaryButtonEvent: () => void;
30
29
  }, string, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<Props>, {
31
30
  className: string;
32
31
  size: string;
@@ -1,12 +1,5 @@
1
1
  import type { DynamicContent } from '@@/Types/generic';
2
2
  import type { FiltersResponse } from '@@/Types/recommendation';
3
- /**
4
- * Extracts recommendation block IDs directly from the HTML by parsing
5
- * the recommendation-id attribute on block elements.
6
- * This avoids depending on store state which may not be populated
7
- * when the settings panel hasn't been opened yet (e.g., saved templates).
8
- */
9
- export declare function getRecommendationBlockIds(html: string): string[];
10
3
  /**
11
4
  * Parses a `{{recoId_index_attributeName}}` variable (already stripped of the
12
5
  * braces/whitespace) into its recommendation id and attribute name. Returns
@@ -34,20 +27,6 @@ export declare function buildPartnerAttributeNameSet(filterList: FiltersResponse
34
27
  * before, so flagging it would false-positive on merge tags like `{{user.name}}`.
35
28
  */
36
29
  export declare function findInvalidCustomFields(html: string, validCustomFields: string[], recommendationBlockIds: string[], ignoredIds: Set<string>, ignoredAttributeNames: Set<string> | null): string[];
37
- /**
38
- * Returns the invalid `{{ ... }}` dynamic-content tags found in the HTML.
39
- *
40
- * A tag's variable name is the part before the first `|` (everything after it is the fallback).
41
- * Surrounding whitespace is always allowed (trimmed). A tag is valid only when the variable name
42
- * is an allowed system token, or it is a clean identifier (`[A-Za-z0-9_.]`) and — when a `|` is
43
- * present — the fallback after it is not empty. Otherwise the tag is invalid (e.g.
44
- * `{{Api Response: OA1 Main Item Url}}` — spaces/`:` — or `{{bounce|}}` — empty fallback).
45
- *
46
- * `data-*` block-config attribute values are excluded from the scan: blocks such as Items/cart
47
- * store product merge tags (`data-product_button_link="{{Abandoned Cart Item (1) Url}}"`) that the
48
- * backend resolves through its own pipeline, so they must not be treated as user-authored tags.
49
- */
50
- export declare function getInvalidDynamicContentTags(html: string): string[];
51
30
  export declare const useHtmlValidator: () => {
52
31
  validateHtml: (html: string, customFields: DynamicContent[], isOnSaveValidation?: boolean) => Promise<boolean>;
53
32
  };
@@ -1,9 +1,4 @@
1
1
  import type { SavedTemplateDetails } from '@@/Types/stripo';
2
- type SaveDetails = Omit<SavedTemplateDetails, 'metadata' | 'silent'>;
3
- type SaveResult = SaveDetails | undefined;
4
2
  export declare const useSave: () => {
5
- save: (suppressEmit?: boolean, silent?: boolean) => Promise<SaveResult>;
6
- saveWithErrors: () => Promise<SaveResult>;
7
- saveRawOnly: () => Promise<SaveResult>;
3
+ save: (suppressEmit?: boolean, silent?: boolean) => Promise<Omit<SavedTemplateDetails, "metadata" | "silent"> | undefined>;
8
4
  };
9
- export {};
@@ -1,6 +1,3 @@
1
- export declare const COUPON_TAG_MODIFIED_KEY = "newsletter.coupon-tag-modified";
2
- /** Pure core: the tag text of every coupon block whose code was modified. */
3
- export declare function findInvalidCouponBlocks(html: string): string[];
4
1
  export declare const useCouponBlockValidator: () => {
5
2
  validateCouponBlockTags: (html: string) => boolean;
6
3
  };
@@ -1,14 +1,4 @@
1
- declare const SINGLETON_BLOCK_RULES: {
2
- pageType: number;
3
- messageKey: string;
4
- }[];
5
- export declare const EMPTY_BLOCK_KEY = "unsubscription-preference.select-page-to-continue";
6
- /** Pure core: the singleton rules whose page type appears more than once. */
7
- export declare function findDuplicateUnsubPageTypes(html: string): typeof SINGLETON_BLOCK_RULES;
8
- /** Pure core: count of unsubscribe blocks with no page type or page list chosen. */
9
- export declare function countUnsubBlocksWithoutPage(html: string): number;
10
1
  export declare const useUnsubscribeBlockValidator: () => {
11
2
  validateUnsubscribeBlockUniqueness: (html: string) => boolean;
12
3
  validateUnsubscribeBlockHasTemplate: (html: string) => boolean;
13
4
  };
14
- export {};
@@ -286,11 +286,6 @@ export declare const useRecommendationExtensionStore: import("pinia").StoreDefin
286
286
  * every block's recommendationConfigs across user edits.
287
287
  */
288
288
  hasInvalidBlock(): boolean;
289
- /**
290
- * Per-instance counterpart to `hasInvalidBlock`: the ids of every block
291
- * that fails required-field validation, one drawer row each (SD-147430).
292
- */
293
- invalidBlockIds(): string[];
294
289
  fetchRecommendationProducts(): Promise<void>;
295
290
  _doFetchProducts(): Promise<void>;
296
291
  }>;
@@ -2106,11 +2106,6 @@ export declare const useConfigStore: import("pinia").StoreDefinition<"guido-conf
2106
2106
  };
2107
2107
  } | null;
2108
2108
  } & import("pinia").PiniaCustomStateProperties<ConfigStoreState>) => number;
2109
- /**
2110
- * Transactional campaigns keep the hard save block. Reactive getter, so
2111
- * consumers stay safe in setup where a raw config read snapshots null (SD-147945).
2112
- */
2113
- isTransactional(): boolean;
2114
2109
  /**
2115
2110
  * Get the username
2116
2111
  */
@@ -15,36 +15,6 @@ import type { SavedTemplateDetails } from '@@/Types/stripo';
15
15
  * same source), so it is reliably present regardless of how the block was added.
16
16
  */
17
17
  export declare function getHtmlReferencedUnsubscribePages(html: string): number[];
18
- /**
19
- * Hydrates the recommendation extension store from the persisted `esd-ext-config`
20
- * JSON blob on each `.recommendation-block-v2` element in the raw editor HTML.
21
- *
22
- * Why this runs before `compileHtml`:
23
- * The HTML compiler's `prepareRecommendationBlocks` rule asks
24
- * `useRecommendation.buildCampaignUrl(id)` to assemble each block's API URL
25
- * from `blockStates[id].recommendationConfigs`. That Pinia entry is normally
26
- * populated by `RecommendationBlockControl._syncNodeConfigToStore`, which
27
- * only fires when the user *selects* the block. Saving without ever
28
- * selecting a migrated block would otherwise build the URL from empty/
29
- * default state and the campaign URL would not be saved.
30
- *
31
- * Why we read raw HTML, not compiled HTML:
32
- * Stripo's `compileEmail()` strips editor-only attributes (`esd-*`) from the
33
- * compiled output, so `esd-ext-config` is gone by the time the compiler
34
- * pipeline sees the HTML. The raw HTML from `getTemplateData()` preserves
35
- * the attribute as the migrator wrote it.
36
- *
37
- * Reference data pre-load:
38
- * When the template has recommendation blocks, this also pre-loads the
39
- * shared reference data (languages / currency list) so the save-time
40
- * required-fields validator can check each block's locale and currency
41
- * against the partner's real options. Best-effort — on a fetch failure the
42
- * validator degrades to its empty-list guard (`requiredFields.ts`) instead
43
- * of blocking the save or stranding the Save button.
44
- */
45
- declare function hydrateRecommendationStoreFromRawHtml(rawHtml: string): Promise<void>;
46
18
  export declare const useTemplatePreparation: () => {
47
19
  prepareTemplateDetails: () => Promise<Omit<SavedTemplateDetails, "metadata">>;
48
- hydrateRecommendationStore: typeof hydrateRecommendationStoreFromRawHtml;
49
20
  };
50
- export {};
@@ -1,8 +1,8 @@
1
- import { MessageType as o } from "../@types/config/schemas.js";
1
+ import "../@types/config/schemas.js";
2
2
  import "../@types/config/defaults.js";
3
- import { parseConfig as r } from "../@types/config/validator.js";
4
- import { defineStore as a } from "pinia";
5
- const g = a("guido-config", {
3
+ import { parseConfig as o } from "../@types/config/validator.js";
4
+ import { defineStore as r } from "pinia";
5
+ const f = r("guido-config", {
6
6
  state: () => ({
7
7
  initialized: !1,
8
8
  config: null
@@ -113,13 +113,6 @@ const g = a("guido-config", {
113
113
  var e, n;
114
114
  return ((n = (e = i.config) == null ? void 0 : e.partner) == null ? void 0 : n.messageType) ?? 1;
115
115
  },
116
- /**
117
- * Transactional campaigns keep the hard save block. Reactive getter, so
118
- * consumers stay safe in setup where a raw config read snapshots null (SD-147945).
119
- */
120
- isTransactional() {
121
- return this.messageType === o.TRANSACTIONAL;
122
- },
123
116
  /**
124
117
  * Get the username
125
118
  */
@@ -150,7 +143,7 @@ const g = a("guido-config", {
150
143
  * Initialize the config store with validated configuration
151
144
  */
152
145
  init(i) {
153
- const e = r(i);
146
+ const e = o(i);
154
147
  this.config = e, this.initialized = !0;
155
148
  },
156
149
  /**
@@ -162,5 +155,5 @@ const g = a("guido-config", {
162
155
  }
163
156
  });
164
157
  export {
165
- g as useConfigStore
158
+ f as useConfigStore
166
159
  };
@@ -1,27 +1,27 @@
1
- import { useActionsApi as R } from "../composables/useActionsApi.js";
1
+ import { useActionsApi as k } from "../composables/useActionsApi.js";
2
2
  import { useConfig as U } from "../composables/useConfig.js";
3
3
  import { useHtmlCompiler as x } from "../composables/useHtmlCompiler.js";
4
4
  import { DEFAULT_CURRENCY as d, DEFAULT_NODE_CONFIG as s } from "../extensions/Blocks/Recommendation/constants/defaultConfig.js";
5
- import { useRecommendationExtensionStore as T } from "../extensions/Blocks/Recommendation/store/recommendation.js";
5
+ import { useRecommendationExtensionStore as C } from "../extensions/Blocks/Recommendation/store/recommendation.js";
6
6
  import { mapLegacyStrategy as L } from "../extensions/Blocks/Recommendation/utils/legacyStrategyMap.js";
7
7
  import { DATA_ATTRIBUTES as A } from "../extensions/Blocks/Unsubscribe/utils/constants.js";
8
- import { parsePageList as N } from "../extensions/Blocks/Unsubscribe/utils/utils.js";
9
- import { useDynamicContentStore as z } from "../stores/dynamic-content.js";
10
- import { useEditorStore as _ } from "../stores/editor.js";
11
- import { useUnsubscribeStore as v } from "../stores/unsubscribe.js";
12
- import { assignTrackingIds as O } from "./linkTrackingIds.js";
13
- function M(m) {
8
+ import { parsePageList as R } from "../extensions/Blocks/Unsubscribe/utils/utils.js";
9
+ import { useDynamicContentStore as N } from "../stores/dynamic-content.js";
10
+ import { useEditorStore as z } from "../stores/editor.js";
11
+ import { useUnsubscribeStore as _ } from "../stores/unsubscribe.js";
12
+ import { assignTrackingIds as v } from "./linkTrackingIds.js";
13
+ function O(m) {
14
14
  const n = new DOMParser().parseFromString(m, "text/html").querySelectorAll(`[${A.PAGE_LIST}]`), t = [];
15
15
  return n.forEach((i) => {
16
16
  const o = i.getAttribute(A.PAGE_LIST);
17
- o && t.push(...N(o));
17
+ o && t.push(...R(o));
18
18
  }), [...new Set(t)];
19
19
  }
20
- async function C(m) {
20
+ async function M(m) {
21
21
  const a = new DOMParser().parseFromString(m, "text/html").querySelectorAll(".recommendation-block-v2");
22
22
  if (a.length === 0)
23
23
  return;
24
- const n = T();
24
+ const n = C();
25
25
  a.forEach((t) => {
26
26
  var r, l, g, f, c;
27
27
  const i = t.getAttribute("recommendation-id"), o = i ? Number(i) : NaN;
@@ -68,39 +68,39 @@ async function C(m) {
68
68
  }
69
69
  }
70
70
  const Z = () => {
71
- const m = z(), u = _(), a = v(), { getCompiledEmail: n, getTemplateData: t, updateHtmlAndCss: i } = R(), { compileHtml: o, compileAmpHtml: p } = x(), { isFeatureEnabled: e } = U();
71
+ const m = N(), u = z(), a = _(), { getCompiledEmail: n, getTemplateData: t, updateHtmlAndCss: i } = k(), { compileHtml: o, compileAmpHtml: p } = x(), { isFeatureEnabled: e } = U();
72
72
  return {
73
73
  prepareTemplateDetails: async () => {
74
74
  let { html: r, css: l, syncModulesIds: g = [] } = await t();
75
75
  if (e("linkTrackingIds"))
76
76
  try {
77
- const { html: y, changed: I, nextSeq: k } = O(r, u.trackIdSessionFloor);
78
- u.trackIdSessionFloor = k, I && (r = y, await i(y, l));
77
+ const { html: y, changed: H, nextSeq: I } = v(r, u.trackIdSessionFloor);
78
+ u.trackIdSessionFloor = I, H && (r = y, await i(y, l));
79
79
  } catch (y) {
80
80
  console.error("Tracking-id step failed, saving anyway:", y);
81
81
  }
82
- const { html: f, ampHtml: c = "", ampErrors: w = [] } = await n({
82
+ const { html: f, ampHtml: c = "", ampErrors: T = [] } = await n({
83
83
  minimize: !0,
84
84
  resetDataSavedFlag: !1
85
85
  });
86
- a.selectedUnsubscribePages.length && await a.fetchTemplates(), await C(r);
87
- const { compiledHtml: D, stats: S, appliedRules: E } = o(f), P = c && p(c).compiledHtml, F = m.getSelectedDynamicContentList, H = T(), b = M(r);
86
+ a.selectedUnsubscribePages.length && await a.fetchTemplates(), await M(r);
87
+ const { compiledHtml: w, stats: S, appliedRules: D } = o(f), E = c && p(c).compiledHtml, P = m.getSelectedDynamicContentList, F = C(), b = O(r);
88
88
  return console.debug("HTML Compilation Stats:", {
89
89
  originalSize: S.originalSize,
90
90
  compiledSize: S.compiledSize,
91
91
  reduction: `${S.reductionPercentage.toFixed(2)}%`,
92
- appliedRules: E,
92
+ appliedRules: D,
93
93
  executionTime: `${S.executionTime.toFixed(2)}ms`
94
94
  }), {
95
- dynamicContentList: F,
96
- compiledHtml: D,
95
+ dynamicContentList: P,
96
+ compiledHtml: w,
97
97
  rawHtml: r,
98
98
  css: l,
99
- ampHtml: P,
100
- ampErrors: w,
99
+ ampHtml: E,
100
+ ampErrors: T,
101
101
  modules: g.map(Number),
102
102
  recommendation: {
103
- campaignUrls: H.recommendationCampaignUrls,
103
+ campaignUrls: F.recommendationCampaignUrls,
104
104
  configs: {}
105
105
  },
106
106
  unsubscribe: {
@@ -108,13 +108,10 @@ const Z = () => {
108
108
  config: b
109
109
  }
110
110
  };
111
- },
112
- // Exposed so the back/test validate-only path can seed the reco store the
113
- // same way a full save does (required-field findings depend on it).
114
- hydrateRecommendationStore: C
111
+ }
115
112
  };
116
113
  };
117
114
  export {
118
- M as getHtmlReferencedUnsubscribePages,
115
+ O as getHtmlReferencedUnsubscribePages,
119
116
  Z as useTemplatePreparation
120
117
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.17.0-beta.dc7f4d2",
3
+ "version": "3.17.0-beta.ec0523a",
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",
@@ -1,20 +0,0 @@
1
- import n from "./ValidationErrorDrawer.vue2.js";
2
- /* empty css */
3
- import s from "../../../_virtual/_plugin-vue2_normalizer.js";
4
- var i = function() {
5
- var r = this, o = r._self._c, t = r._self._setupProxy;
6
- return o(t.WpDrawer, { attrs: { id: "guido__validation-error-drawer", size: "small", "footer-button-group-options": t.footerButtonGroupOptions, status: t.store.isDrawerOpen, "title-text": t.titleText }, on: { onCloseEvent: t.handleClose, primaryButtonEvent: t.handleClose, secondaryButtonEvent: t.handleSaveAndContinue } }, [o("div", { staticClass: "d-f f-d-c validation-error-list" }, r._l(t.rows, function(e, a) {
7
- return o("div", { key: a, staticClass: "d-f a-i-c validation-error-row" }, [o(t.InIcons, { staticClass: "validation-error-row__icon i-c-12", attrs: { name: "filled-caution-triangle" } }), o("span", { staticClass: "validation-error-row__text" }, [r._v(r._s(e))])], 1);
8
- }), 0)]);
9
- }, l = [], _ = /* @__PURE__ */ s(
10
- n,
11
- i,
12
- l,
13
- !1,
14
- null,
15
- "856367aa"
16
- );
17
- const p = _.exports;
18
- export {
19
- p as default
20
- };
@@ -1,48 +0,0 @@
1
- import { defineComponent as m, ref as p, computed as a } from "vue";
2
- import f from "../../wrappers/WpDrawer.vue.js";
3
- import { useSave as S } from "../../../composables/useSave.js";
4
- import { useTranslations as v } from "../../../composables/useTranslations.js";
5
- import { useConfigStore as g } from "../../../stores/config.js";
6
- import { useEditorStore as y } from "../../../stores/editor.js";
7
- import { useSaveValidationStore as _ } from "../../../stores/save-validation.js";
8
- import { InIcons as h } from "@useinsider/design-system-vue";
9
- const O = /* @__PURE__ */ m({
10
- __name: "ValidationErrorDrawer",
11
- setup(w) {
12
- const r = v(), e = _(), n = y(), s = g(), { saveWithErrors: i } = S(), o = p(!1), l = a(() => `${r("email-editor.validation-errors")} (${e.errorCount})`), u = a(() => {
13
- const t = {
14
- primaryButton: {
15
- styling: "solid",
16
- type: "primary",
17
- labelText: r("email-editor.update-design")
18
- }
19
- };
20
- return !s.isTransactional && e.intent !== "test" && (t.secondaryButton = {
21
- styling: "solid",
22
- type: "subtle-primary",
23
- labelText: r("email-editor.save-and-continue"),
24
- loadingStatus: o.value
25
- }), t;
26
- }), d = a(() => e.errors.map((t) => {
27
- const c = t.detail ? ` (${t.detail})` : "";
28
- return `${t.message}${c}`;
29
- }));
30
- return { __sfc: !0, trans: r, store: e, editorStore: n, configStore: s, saveWithErrors: i, isSaving: o, titleText: l, footerButtonGroupOptions: u, rows: d, handleClose: () => {
31
- e.isDrawerOpen && e.close();
32
- }, handleSaveAndContinue: async () => {
33
- if (!o.value) {
34
- o.value = !0, n.loadingStatus = !0;
35
- try {
36
- await i() ? e.close() : n.loadingStatus = !1;
37
- } catch (t) {
38
- console.warn("Soft-save failed; keeping the drawer open.", t), n.loadingStatus = !1;
39
- } finally {
40
- o.value = !1;
41
- }
42
- }
43
- }, WpDrawer: f, InIcons: h };
44
- }
45
- });
46
- export {
47
- O as default
48
- };
@@ -1,279 +0,0 @@
1
- import { getIgnoredRecommendationBlockIds as B } from "../config/compiler/utils/recommendationIgnoreUtils.js";
2
- import { CanNotMakeAnyChangesForRunningKey as k, DISPLAY_CONDITIONS_REGEX as Y, DISPLAY_CONDITIONS_EXCEPTIONS_REGEX as x } 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 U } from "../extensions/Blocks/Checkbox/constants/selectors.js";
6
- import { itemsBlockDynamicVariables as M } from "../extensions/Blocks/Items/enums/productEnums.js";
7
- import { BLOCK_ROOT_SELECTOR as P } from "../extensions/Blocks/RadioButton/constants/selectors.js";
8
- import { useRecommendationExtensionStore as W } from "../extensions/Blocks/Recommendation/store/recommendation.js";
9
- import { RecommendationRequiredFieldsKey as G } from "../extensions/Blocks/Recommendation/validation/requiredFields.js";
10
- import { useConfigStore as q } from "../stores/config.js";
11
- import { useDynamicContentStore as H } from "../stores/dynamic-content.js";
12
- import { useRecommendationStore as V } from "../stores/recommendation.js";
13
- import { base64EncodeWithSpecialChars as T } from "../utils/base64.js";
14
- import { useTemplatePreparation as X } from "../utils/templatePreparation.js";
15
- import { useActionsApi as j } from "./useActionsApi.js";
16
- import { useConfig as z } from "./useConfig.js";
17
- import { useHtmlCompiler as $ } from "./useHtmlCompiler.js";
18
- import { buildPartnerAttributeNameSet as Q, getInvalidDynamicContentTags as Z, getRecommendationBlockIds as J, findInvalidCustomFields as tt } from "./useHtmlValidator.js";
19
- import { useHttp as et } from "./useHttp.js";
20
- import { useTranslations as nt } from "./useTranslations.js";
21
- import { findInvalidCouponBlocks as it, COUPON_TAG_MODIFIED_KEY as ot } from "./validators/useCouponBlockValidator.js";
22
- import { findDuplicateUnsubPageTypes as rt, countUnsubBlocksWithoutPage as st, EMPTY_BLOCK_KEY as at } from "./validators/useUnsubscribeBlockValidator.js";
23
- const ct = "newsletter.html-content-is-empty", lt = "custom-fields.missing-closing-braces", ut = "custom-fields.missing-opening-braces", I = "custom-fields.invalid-custom-fields", mt = "newsletter.display-conditions-invalid-syntax", dt = "custom-conditions.wrong-equality-operators", pt = "custom-conditions.missing-if-endif-tag", gt = "custom-conditions.no-space-after-braces", ft = "custom-conditions.no-braces-inside-if-tag", yt = "newsletter.fill-all-necessary-fields", Et = "newsletter.invalid-image-type", It = "unsubscribe-templates.select-checkbox-groups", St = "unsubscribe-templates.select-radio-button-groups", Ct = "newsletter.invalid-url-link-for-toaster", F = "journey-builder.liquid-validation-failed", _t = "/newsletter/template-library/check-template-html-body", ht = /src="[^"]*\.(svg|pst)"/gm, R = /({%(.*?)%})/g, kt = ["if", "endif", "else", "elif", "now"], Tt = (e) => !kt.includes(e.toLowerCase()), Ft = (e) => ["if", "endif"].includes(e.toLowerCase());
24
- function Ot(e) {
25
- return it(e).map((i) => ({
26
- rule: o.CouponTagModified,
27
- type: r.Warning,
28
- key: ot,
29
- detail: i
30
- }));
31
- }
32
- function Rt(e) {
33
- return rt(e).map((i) => ({
34
- rule: o.DuplicateUnsubBlock,
35
- type: r.Error,
36
- key: i.messageKey
37
- }));
38
- }
39
- function Lt(e) {
40
- return Array.from({ length: st(e) }, () => ({
41
- rule: o.UnsubBlockMissingTemplate,
42
- type: r.Warning,
43
- key: at
44
- }));
45
- }
46
- function Nt(e, i) {
47
- const n = e.match(R);
48
- if (!n)
49
- return [];
50
- const a = [];
51
- return n.forEach((u) => {
52
- const s = u.slice(2, -2).trim().match(/(".*?"|[^"\s]+)(?=\s*|\s*$)/g);
53
- if (s && s.length > 0) {
54
- const [m] = s;
55
- Tt(m) && !i.includes(m) && a.push({
56
- rule: o.CustomFieldScript,
57
- type: r.Warning,
58
- key: I,
59
- detail: m
60
- });
61
- }
62
- }), a;
63
- }
64
- function bt(e) {
65
- return e.length > 0 ? [] : [{ rule: o.EmptyHtml, type: r.Warning, key: ct }];
66
- }
67
- function At(e) {
68
- const i = (e.match(/{/gm) || []).length, n = (e.match(/}/gm) || []).length;
69
- return i > n ? [{
70
- rule: o.MismatchedBraces,
71
- type: r.Warning,
72
- key: lt
73
- }] : i < n ? [{
74
- rule: o.MismatchedBraces,
75
- type: r.Warning,
76
- key: ut
77
- }] : [];
78
- }
79
- function Dt(e) {
80
- return Z(e).map((i) => ({
81
- rule: o.InvalidDynamicTag,
82
- type: r.Warning,
83
- key: I,
84
- detail: i
85
- }));
86
- }
87
- function vt(e, i, n, a) {
88
- const u = J(e);
89
- return tt(e, i, u, n, a).map((s) => ({
90
- rule: o.InvalidCustomField,
91
- type: r.Error,
92
- key: I,
93
- detail: s
94
- }));
95
- }
96
- function Kt(e) {
97
- const i = e.match(/{%(.*?)%}/g), n = [], a = [];
98
- if (i && i.forEach((u) => {
99
- const s = u.match(Y), m = u.match(x), y = (s == null ? void 0 : s.join("")) || "";
100
- (!s || u !== y) && !m && a.push({
101
- rule: o.ConditionsSyntax,
102
- type: r.Error,
103
- key: mt,
104
- detail: u
105
- }), s && s.forEach((g) => {
106
- g.trim() === "=" && a.push({
107
- rule: o.WrongEqualityOperator,
108
- type: r.Error,
109
- key: dt
110
- }), (g.match(/^[a-zA-Z]*$/g) ?? []).forEach((f) => {
111
- Ft(f) && n.push(f);
112
- });
113
- });
114
- }), n.length) {
115
- const u = n.filter((m) => m === "if").length, s = n.filter((m) => m === "endif").length;
116
- u !== s && a.push({
117
- rule: o.MissingIfEndif,
118
- type: r.Error,
119
- key: pt
120
- });
121
- }
122
- return a;
123
- }
124
- function wt(e) {
125
- const i = (e.match(/{% /gm) || []).length, n = (e.match(/ %}/gm) || []).length;
126
- return i === n ? [] : [{
127
- rule: o.ConditionTagSpacing,
128
- type: r.Warning,
129
- key: gt
130
- }];
131
- }
132
- function Bt(e) {
133
- return (e.match(R) || []).filter((n) => n.includes("if")).map((n) => (n.match(/{{.*}}/gm) || []).length).reduce((n, a) => n + a, 0) === 0 ? [] : [{
134
- rule: o.BracesInsideIfTag,
135
- type: r.Warning,
136
- key: ft
137
- }];
138
- }
139
- function Yt(e) {
140
- return (e.match(ht) ?? []).map((i) => ({
141
- rule: o.InvalidImageType,
142
- type: r.Error,
143
- key: Et,
144
- detail: i
145
- }));
146
- }
147
- function O(e, i, n, a) {
148
- const u = new DOMParser().parseFromString(e, "text/html");
149
- return Array.from(u.querySelectorAll(i)).filter((s) => {
150
- var m;
151
- return !((m = s.id) != null && m.trim());
152
- }).map(() => ({ rule: n, type: r.Error, key: a }));
153
- }
154
- const ae = () => {
155
- const { config: e, isFeatureEnabled: i } = z(), n = nt(), { post: a } = et(), { getCompiledEmail: u, getTemplateData: s } = j(), { compileHtml: m } = $(), { hydrateRecommendationStore: y } = X(), g = H(), f = V(), E = W(), L = q(), N = (t) => ({
156
- rule: t.rule,
157
- type: t.type,
158
- detail: t.detail,
159
- message: "key" in t ? n(t.key) : t.message
160
- }), b = async (t) => {
161
- if (t.size === 0)
162
- return /* @__PURE__ */ new Set();
163
- try {
164
- await E.fetchRecommendationFilters();
165
- } catch {
166
- return null;
167
- }
168
- return Q(E.filterList);
169
- }, A = async (t) => {
170
- try {
171
- const l = await a(_t, { html: T(t) }), { status: c, message: d } = l.data, p = [];
172
- return c || p.push({
173
- rule: o.InvalidLinks,
174
- type: r.Error,
175
- // status===undefined means a bare message instead of a boolean; surface it,
176
- // but fall back to the canned key when it's missing so a malformed body
177
- // never renders a literal 'undefined' row (SD-147430).
178
- ...c === void 0 && d ? { message: d } : { key: Ct }
179
- }), d === n(k) && p.push({
180
- rule: o.LinkCheckInProgress,
181
- type: r.Error,
182
- key: k
183
- }), p;
184
- } catch (l) {
185
- return console.warn("Link-check collector failed; skipping the link rule.", l), [];
186
- }
187
- }, D = async (t) => {
188
- try {
189
- const l = await a("/newsletter/contents/validate-syntax", [{
190
- identifier: "default",
191
- syntax: "liquid",
192
- contents: {
193
- subject: null,
194
- preheader: null,
195
- html: T(t),
196
- ampHtml: null
197
- }
198
- }]);
199
- if (!Array.isArray(l.data)) {
200
- const d = l.data;
201
- return [{
202
- rule: o.LiquidSyntax,
203
- type: r.Warning,
204
- message: d.message ?? n(F)
205
- }];
206
- }
207
- const [c] = l.data;
208
- return Object.values((c == null ? void 0 : c.errors) ?? {}).map((d) => ({
209
- rule: o.LiquidSyntax,
210
- type: r.Warning,
211
- message: d.replace(/^line \d+:\s*/, "")
212
- }));
213
- } catch {
214
- return [{
215
- rule: o.LiquidSyntax,
216
- type: r.Error,
217
- message: n(F)
218
- }];
219
- }
220
- }, v = () => {
221
- const t = E.invalidBlockIds().map((c) => ({
222
- rule: o.RecommendationRequiredFields,
223
- type: r.Error,
224
- key: G,
225
- detail: c
226
- })), l = (f.recommendationConfigs ?? []).filter((c) => c.filters.some((d) => d.value === "")).map(() => ({
227
- rule: o.RecommendationFilters,
228
- type: r.Error,
229
- key: yt
230
- }));
231
- return [...t, ...l];
232
- }, K = async (t, l) => {
233
- var _, h;
234
- const c = [
235
- ...l.map((w) => w.value),
236
- ...M,
237
- ...((h = (_ = e.value) == null ? void 0 : _.template) == null ? void 0 : h.customFieldAttributes) ?? []
238
- ], d = B(t), p = await b(d), { isTransactional: C } = L;
239
- return [
240
- ...await A(t),
241
- ...C ? [] : Nt(t, c),
242
- ...bt(t),
243
- ...At(t),
244
- ...Dt(t),
245
- ...C ? [] : vt(t, c, d, p),
246
- ...Kt(t),
247
- ...wt(t),
248
- ...Bt(t),
249
- ...v(),
250
- ...Yt(t),
251
- ...O(
252
- t,
253
- U,
254
- o.CheckboxUnsubGroup,
255
- It
256
- ),
257
- ...O(
258
- t,
259
- P,
260
- o.RadioButtonUnsubGroup,
261
- St
262
- )
263
- ];
264
- }, S = async (t, l) => [
265
- ...Ot(t),
266
- ...Rt(t),
267
- ...Lt(t),
268
- ...i("liquidSyntax") ? await D(t) : await K(t, l)
269
- ].map(N);
270
- return { collectSaveValidationErrors: S, validateCurrentTemplate: async () => {
271
- const { html: t } = await s();
272
- await y(t);
273
- const { html: l } = await u({ minimize: !0, resetDataSavedFlag: !1 }), { compiledHtml: c } = m(l);
274
- return S(c, g.getSelectedDynamicContentList);
275
- } };
276
- };
277
- export {
278
- ae as useSaveValidation
279
- };