@useinsider/guido 3.7.1 → 3.7.2-beta.b9b817e

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,31 +1,32 @@
1
1
  import { useActionsApi as x } from "./useActionsApi.js";
2
2
  import { useConfig as y } from "./useConfig.js";
3
- import { useSaveStart as w, useSaveComplete as C } from "./useGuidoActions.js";
4
- import { useSyncModuleExtractor as E } from "./useSyncModuleExtractor.js";
5
- import { useStripoApi as H } from "../services/stripoApi.js";
6
- import { useTemplatePreparation as b } from "../utils/templatePreparation.js";
7
- import { useHtmlValidator as q } from "./useHtmlValidator.js";
3
+ import { useSaveStart as w, useSaveComplete as H } from "./useGuidoActions.js";
4
+ import { useSyncModuleExtractor as q } from "./useSyncModuleExtractor.js";
5
+ import { useStripoApi as C } from "../services/stripoApi.js";
6
+ import { useTemplatePreparation as E } from "../utils/templatePreparation.js";
7
+ import { useHtmlValidator as k } from "./useHtmlValidator.js";
8
8
  import { useCouponBlockValidator as L } from "./validators/useCouponBlockValidator.js";
9
9
  import { useLiquidValidator as P } from "./validators/useLiquidValidator.js";
10
- const z = () => {
11
- const o = w(), s = C(), { validateHtml: r } = q(), { validateLiquidSyntax: n } = P(), { validateCouponBlockTags: l } = L(), { callbacks: a, isFeatureEnabled: d } = y(), { extractSyncModuleData: u } = E(), { setSyncModuleUnsubscriptionPages: c } = H(), { editorSave: m } = x();
12
- return { save: async (p = !1, f = !1) => {
13
- var i;
10
+ import { useUnsubscribeBlockValidator as B } from "./validators/useUnsubscribeBlockValidator.js";
11
+ const J = () => {
12
+ const o = w(), s = H(), { validateHtml: r } = k(), { validateLiquidSyntax: n } = P(), { validateCouponBlockTags: l } = L(), { validateUnsubscribeBlockUniqueness: d } = B(), { callbacks: i, isFeatureEnabled: u } = y(), { extractSyncModuleData: c } = q(), { setSyncModuleUnsubscriptionPages: m } = C(), { editorSave: p } = x();
13
+ return { save: async (f = !1, v = !1) => {
14
+ var a;
14
15
  o();
15
- const { prepareTemplateDetails: v } = b(), t = await v();
16
- if (!l(t.compiledHtml))
16
+ const { prepareTemplateDetails: S } = E(), t = await S();
17
+ if (!l(t.compiledHtml) || !d(t.compiledHtml))
17
18
  return;
18
- if (d("liquidSyntax")) {
19
+ if (u("liquidSyntax")) {
19
20
  if (!await n(t.compiledHtml))
20
21
  return;
21
22
  } else if (!await r(t.compiledHtml, t.dynamicContentList, !0))
22
23
  return;
23
- if ((i = a.value) != null && i.externalValidation && !await a.value.externalValidation(t) || !await m())
24
+ if ((a = i.value) != null && a.externalValidation && !await i.value.externalValidation(t) || !await p())
24
25
  return;
25
- const { unsubscribePayload: S, stripoModules: V } = u(t.rawHtml);
26
- return await c(S), t.modules = V, p || s({ ...t, silent: f }), t;
26
+ const { unsubscribePayload: V, stripoModules: b } = c(t.rawHtml);
27
+ return await m(V), t.modules = b, f || s({ ...t, silent: v }), t;
27
28
  } };
28
29
  };
29
30
  export {
30
- z as useSave
31
+ J as useSave
31
32
  };
@@ -0,0 +1,32 @@
1
+ import { ToasterTypeOptions as i } from "../../enums/toaster.js";
2
+ import { PAGE_TYPES as n } from "../../enums/unsubscribe.js";
3
+ import { UNSUBSCRIBE_BLOCK_SELECTOR as u, DATA_ATTRIBUTES as l } from "../../extensions/Blocks/Unsubscribe/utils/constants.js";
4
+ import { useToaster as T } from "../useToaster.js";
5
+ import { useTranslations as E } from "../useTranslations.js";
6
+ const m = [
7
+ {
8
+ pageType: n.GLOBAL_UNSUBSCRIBE,
9
+ messageKey: "unsubscription-preference.duplicate-global-unsub"
10
+ },
11
+ {
12
+ pageType: n.SUBSCRIPTION_PREFERENCE_CENTER,
13
+ messageKey: "unsubscription-preference.duplicate-pref-center"
14
+ }
15
+ ], g = "unsubscription-preference.duplicate-both", y = () => {
16
+ const { showToaster: o } = T(), a = E();
17
+ return { validateUnsubscribeBlockUniqueness: (c) => {
18
+ const p = new DOMParser().parseFromString(c, "text/html"), t = /* @__PURE__ */ new Map();
19
+ p.querySelectorAll(u).forEach((e) => {
20
+ const r = Number(e.getAttribute(l.PAGE_TYPE));
21
+ t.set(r, (t.get(r) ?? 0) + 1);
22
+ });
23
+ const s = m.filter((e) => (t.get(e.pageType) ?? 0) > 1).map((e) => e.messageKey);
24
+ return s.length ? (o({
25
+ type: i.Alert,
26
+ message: a(s.length > 1 ? g : s[0])
27
+ }), !1) : !0;
28
+ } };
29
+ };
30
+ export {
31
+ y as useUnsubscribeBlockValidator
32
+ };
@@ -1,6 +1,8 @@
1
1
  import { useTranslations as r } from "../../composables/useTranslations.js";
2
2
  const l = {
3
- RECOMMENDATION_API_URL: "https://recommendationv2.api.useinsider.com"
3
+ RECOMMENDATION_API_URL: "https://recommendationv2.api.useinsider.com",
4
+ // Relative path → same-origin as the embedding inone dashboard.
5
+ PRODUCT_ATTRIBUTES_PATH: "/product-attributes/get-attributes"
4
6
  }, c = {
5
7
  CLIENT_ID: "clientId"
6
8
  }, d = () => {
@@ -1,8 +1,8 @@
1
1
  import { getRecommendationFeedSourceMaps as g, getOperatorOptions as R, PriceAttributes as C } from "../../../../enums/extensions/recommendationBlock.js";
2
2
  import { useRecommendationApi as y } from "../../../../services/recommendationApi.js";
3
3
  import { useConfigStore as G } from "../../../../stores/config.js";
4
- import { defineStore as P } from "pinia";
5
- import { DEFAULT_MOBILE_CARDS_IN_ROW as D, DEFAULT_CARDS_IN_ROW as F } from "../constants/layout.js";
4
+ import { defineStore as F } from "pinia";
5
+ import { DEFAULT_MOBILE_CARDS_IN_ROW as P, DEFAULT_CARDS_IN_ROW as D } from "../constants/layout.js";
6
6
  import { EXCLUDED_ALGORITHM_IDS as w } from "../constants/defaultConfig.js";
7
7
  import { getDefaultProducts as S } from "../templates/utils.js";
8
8
  import { generateCompleteFilterQuery as b } from "../utils/filterUtil.js";
@@ -13,7 +13,7 @@ const h = y();
13
13
  let m = null, u = null, d = null;
14
14
  function k() {
15
15
  return {
16
- cardsInRow: F,
16
+ cardsInRow: D,
17
17
  currencySettings: {
18
18
  name: "USD",
19
19
  value: "USD",
@@ -27,7 +27,7 @@ function k() {
27
27
  productIds: [],
28
28
  id: 1,
29
29
  language: "en_US",
30
- mobileCardsInRow: D,
30
+ mobileCardsInRow: P,
31
31
  mobileLayoutEnabled: !1,
32
32
  orientation: "grid",
33
33
  recommendedProducts: [],
@@ -60,7 +60,7 @@ const L = () => ({
60
60
  blockStates: {},
61
61
  currentRecommendationId: null,
62
62
  configVersion: 0
63
- }), K = P("guidoRecommendationExtension", {
63
+ }), K = F("guidoRecommendationExtension", {
64
64
  state: () => L(),
65
65
  getters: {
66
66
  // ====================================================================
@@ -133,7 +133,7 @@ const L = () => ({
133
133
  value: e.text
134
134
  })),
135
135
  getFilterList() {
136
- return Object.values(this.filterList).map((t) => {
136
+ return Object.values(this.filterList).filter((t) => t.isFilterable !== 0 && t.isFilterable !== !1).map((t) => {
137
137
  let e;
138
138
  return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : C.includes(t.attributeName) ? e = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : e = t.attributeName, {
139
139
  text: t.displayName,
@@ -7,9 +7,9 @@ import { PAGE_TYPES as h } from "../../../enums/unsubscribe.js";
7
7
  import { useUnsubscribeStore as u } from "../../../stores/unsubscribe.js";
8
8
  import { Block as y, BlockCompositionType as T, ContextActionType as k, ModificationDescription as d, BlockType as I } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
9
9
  import { getDefaultTemplate as v } from "./template.js";
10
- import { DATA_ATTRIBUTES as n, UNSUBSCRIBE_EVENTS as p } from "./utils/constants.js";
10
+ import { UNSUBSCRIBE_BLOCK_SELECTOR as m, DATA_ATTRIBUTES as n, UNSUBSCRIBE_EVENTS as b } from "./utils/constants.js";
11
11
  import { parsePageList as B } from "./utils/utils.js";
12
- const C = "unsubscribe-block", m = 'a[data-unsubscribe-link="true"]', E = ".unsubscribe-block-v2", N = "{{ins-unsubscribe-link}}", U = "https://academy.insiderone.com/docs/adding-unsubscribe-pages-into-emails", R = "Removing the unsubscribe text leaves an empty block, but an active unsubscribe link is required. Undo your last action to restore the text, or delete the unsubscribe block entirely.", D = {
12
+ const C = "unsubscribe-block", E = 'a[data-unsubscribe-link="true"]', N = "{{ins-unsubscribe-link}}", U = "https://academy.insiderone.com/docs/adding-unsubscribe-pages-into-emails", R = "Removing the unsubscribe text leaves an empty block, but an active unsubscribe link is required. Undo your last action to restore the text, or delete the unsubscribe block entirely.", D = {
13
13
  [h.GLOBAL_UNSUBSCRIBE]: "{{ins-global-unsubscribe-link}}",
14
14
  [h.SUBSCRIPTION_PREFERENCE_CENTER]: "{{ins-preferences-unsubscribe-link}}"
15
15
  }, w = 3;
@@ -60,7 +60,7 @@ class H extends y {
60
60
  onDocumentInit() {
61
61
  try {
62
62
  const e = this.api.getDocumentRoot();
63
- e && "querySelectorAll" in e && e.querySelectorAll(E).forEach((t) => {
63
+ e && "querySelectorAll" in e && e.querySelectorAll(m).forEach((t) => {
64
64
  this._ensureLeadingTextGuard(t);
65
65
  });
66
66
  } catch {
@@ -90,7 +90,7 @@ class H extends y {
90
90
  _ensureLeadingTextGuard(e) {
91
91
  if (!("querySelector" in e))
92
92
  return;
93
- const t = e.querySelector(m);
93
+ const t = e.querySelector(E);
94
94
  if (!t)
95
95
  return;
96
96
  let s = t, r = s.parent();
@@ -100,8 +100,8 @@ class H extends y {
100
100
  return;
101
101
  const i = s.previousSibling();
102
102
  if (!!(i && i.getType() === "text" && i.getTextContent())) {
103
- const b = this._readBlockId(e);
104
- b && this.guardAttemptsByBlockId.delete(b);
103
+ const p = this._readBlockId(e);
104
+ p && this.guardAttemptsByBlockId.delete(p);
105
105
  return;
106
106
  }
107
107
  const g = this._getOrAssignBlockId(e);
@@ -112,13 +112,13 @@ class H extends y {
112
112
  this.guardAttemptsByBlockId.set(g, _ + 1);
113
113
  try {
114
114
  this.api.getDocumentModifier().modifyHtml(r).prepend(" ").apply(new d("Ensure unsubscribe link text guard"));
115
- } catch (b) {
116
- console.warn("[UnsubscribeBlock] Failed to ensure link text guard:", b);
115
+ } catch (p) {
116
+ console.warn("[UnsubscribeBlock] Failed to ensure link text guard:", p);
117
117
  }
118
118
  }
119
119
  }
120
120
  _hasUnsubscribeLink(e) {
121
- return "querySelector" in e ? !!e.querySelector(m) : !1;
121
+ return "querySelector" in e ? !!e.querySelector(E) : !1;
122
122
  }
123
123
  _readBlockId(e) {
124
124
  return "getAttribute" in e ? e.getAttribute(n.BLOCK_ID) : null;
@@ -152,7 +152,7 @@ class H extends y {
152
152
  let e = 0;
153
153
  try {
154
154
  const t = this.api.getDocumentRoot();
155
- t && "querySelectorAll" in t && t.querySelectorAll(E).forEach((r) => {
155
+ t && "querySelectorAll" in t && t.querySelectorAll(m).forEach((r) => {
156
156
  if ("getAttribute" in r) {
157
157
  const i = r.getAttribute(n.BLOCK_ID), l = i ? parseInt(i) : 0;
158
158
  l > e && (e = l);
@@ -183,18 +183,18 @@ class H extends y {
183
183
  this._removeSelectEventListener(), this.selectEventListener = (e) => {
184
184
  const t = e, { collectionType: s, selectedPages: r } = t.detail;
185
185
  this._updateBlock(s, r.join(","));
186
- }, document.addEventListener(p.SELECT, this.selectEventListener);
186
+ }, document.addEventListener(b.SELECT, this.selectEventListener);
187
187
  }
188
188
  _removeSelectEventListener() {
189
- this.selectEventListener && (document.removeEventListener(p.SELECT, this.selectEventListener), this.selectEventListener = null);
189
+ this.selectEventListener && (document.removeEventListener(b.SELECT, this.selectEventListener), this.selectEventListener = null);
190
190
  }
191
191
  _setupCancelEventListener() {
192
192
  this._removeCancelEventListener(), this.cancelEventListener = () => {
193
193
  this._handleCancel();
194
- }, document.addEventListener(p.CANCEL, this.cancelEventListener);
194
+ }, document.addEventListener(b.CANCEL, this.cancelEventListener);
195
195
  }
196
196
  _removeCancelEventListener() {
197
- this.cancelEventListener && (document.removeEventListener(p.CANCEL, this.cancelEventListener), this.cancelEventListener = null);
197
+ this.cancelEventListener && (document.removeEventListener(b.CANCEL, this.cancelEventListener), this.cancelEventListener = null);
198
198
  }
199
199
  _handleCancel() {
200
200
  try {
@@ -211,7 +211,7 @@ class H extends y {
211
211
  _updateBlock(e, t) {
212
212
  if (!this.currentNode || !("querySelector" in this.currentNode))
213
213
  return;
214
- const s = this.currentNode.querySelector(m);
214
+ const s = this.currentNode.querySelector(E);
215
215
  if (!s)
216
216
  return;
217
217
  const r = this._getMergeTag(e);
@@ -231,7 +231,7 @@ class H extends y {
231
231
  }
232
232
  _checkExistingBlocks() {
233
233
  const e = u();
234
- e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(E).forEach((s) => {
234
+ e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(m).forEach((s) => {
235
235
  if ("getAttribute" in s) {
236
236
  const r = s.getAttribute(n.PAGE_TYPE);
237
237
  if (r) {
@@ -1,12 +1,13 @@
1
1
  const s = {
2
2
  SELECT: "unsubscribe:select",
3
3
  CANCEL: "unsubscribe:cancel"
4
- }, e = {
4
+ }, b = {
5
5
  PAGE_TYPE: "data-unsubscribe-page-type",
6
6
  PAGE_LIST: "data-unsubscribe-page-list",
7
7
  BLOCK_ID: "data-unsubscribe-block-id"
8
- };
8
+ }, c = ".unsubscribe-block-v2";
9
9
  export {
10
- e as DATA_ATTRIBUTES,
10
+ b as DATA_ATTRIBUTES,
11
+ c as UNSUBSCRIBE_BLOCK_SELECTOR,
11
12
  s as UNSUBSCRIBE_EVENTS
12
13
  };
@@ -1,40 +1,52 @@
1
- import { useHttp as a } from "../composables/useHttp.js";
2
- import { QUERY_PARAMS as d, URLS as h } from "../enums/extensions/recommendationBlock.js";
3
- const y = () => {
4
- const { get: r } = a(), { get: s } = a({ headers: {} }), m = "6KcLM9TwheVB1mgK";
1
+ import { useHttp as d } from "../composables/useHttp.js";
2
+ import { QUERY_PARAMS as l, URLS as u } from "../enums/extensions/recommendationBlock.js";
3
+ const R = (o) => o.reduce(
4
+ (a, t, s) => (a[s] = {
5
+ attributeName: t.attributeName,
6
+ attributeJs: t.attributeJs,
7
+ attributeType: t.attributeType,
8
+ type: t.type,
9
+ displayName: t.displayName,
10
+ isFilterable: t.isFilterable
11
+ }, a),
12
+ {}
13
+ ), f = () => {
14
+ const { get: o } = d(), { get: a } = d({ headers: {} }), t = "6KcLM9TwheVB1mgK";
5
15
  return {
6
16
  fetchRecommendationCreateData: async () => {
7
17
  try {
8
- return (await r("/newsletter/recommendations/create-data")).data;
18
+ return (await o("/newsletter/recommendations/create-data")).data;
9
19
  } catch (e) {
10
20
  throw console.error("fetchUserModalState error:", e), e;
11
21
  }
12
22
  },
13
23
  fetchRecommendationFilters: async () => {
14
24
  try {
15
- const { data: e } = await r("/stripo/email-recommendation-attributes");
16
- return e;
25
+ const { data: e } = await o(
26
+ u.PRODUCT_ATTRIBUTES_PATH
27
+ ), n = Array.isArray(e) ? e : (e == null ? void 0 : e.data) ?? [];
28
+ return R(n);
17
29
  } catch (e) {
18
30
  throw console.error("fetchRecommendationFilters error:", e), e;
19
31
  }
20
32
  },
21
- fetchRecommendationProducts: async (e, i) => {
22
- var n;
33
+ fetchRecommendationProducts: async (e, n) => {
34
+ var i;
23
35
  try {
24
- const t = new URLSearchParams(Object.entries(i));
25
- t.set(d.CLIENT_ID, m);
26
- const c = decodeURIComponent(t.toString());
27
- console.debug("🏁 Recommendation API Query:", c);
28
- const o = await s(
29
- `${h.RECOMMENDATION_API_URL}/v2/${e}?${c}`
36
+ const r = new URLSearchParams(Object.entries(n));
37
+ r.set(l.CLIENT_ID, t);
38
+ const m = decodeURIComponent(r.toString());
39
+ console.debug("🏁 Recommendation API Query:", m);
40
+ const c = await a(
41
+ `${u.RECOMMENDATION_API_URL}/v2/${e}?${m}`
30
42
  );
31
- return ((n = o == null ? void 0 : o.data) == null ? void 0 : n.data) ?? [];
32
- } catch (t) {
33
- throw console.error("fetchRecommendationProducts error:", t), t;
43
+ return ((i = c == null ? void 0 : c.data) == null ? void 0 : i.data) ?? [];
44
+ } catch (r) {
45
+ throw console.error("fetchRecommendationProducts error:", r), r;
34
46
  }
35
47
  }
36
48
  };
37
49
  };
38
50
  export {
39
- y as useRecommendationApi
51
+ f as useRecommendationApi
40
52
  };
@@ -0,0 +1,3 @@
1
+ export declare const useUnsubscribeBlockValidator: () => {
2
+ validateUnsubscribeBlockUniqueness: (html: string) => boolean;
3
+ };
@@ -2,6 +2,7 @@ import type { TextValueObject } from '@@/Types/generic';
2
2
  import type { RecommendationFeedItem } from '@@/Types/recommendation';
3
3
  export declare const URLS: {
4
4
  RECOMMENDATION_API_URL: string;
5
+ PRODUCT_ATTRIBUTES_PATH: string;
5
6
  };
6
7
  export declare const QUERY_PARAMS: {
7
8
  CLIENT_ID: string;
@@ -8,3 +8,4 @@ export declare const DATA_ATTRIBUTES: {
8
8
  readonly PAGE_LIST: "data-unsubscribe-page-list";
9
9
  readonly BLOCK_ID: "data-unsubscribe-block-id";
10
10
  };
11
+ export declare const UNSUBSCRIBE_BLOCK_SELECTOR = ".unsubscribe-block-v2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.7.1",
3
+ "version": "3.7.2-beta.b9b817e",
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",
@@ -27,6 +27,8 @@
27
27
  "test": "vitest run --coverage",
28
28
  "test:watch": "vitest",
29
29
  "test:visual-update": "npx playwright test --update-snapshots --reporter html",
30
+ "test:e2e:coverage": "E2E_COVERAGE=true playwright test",
31
+ "coverage:e2e:report": "nyc report --reporter=lcov --reporter=text-summary --report-dir=coverage/e2e",
30
32
  "prepare": "husky",
31
33
  "preinstall": "rm -rf ./node_modules/.vite"
32
34
  },
@@ -74,10 +76,12 @@
74
76
  "happy-dom": "15.11.7",
75
77
  "husky": "9.1.7",
76
78
  "msw": "2.10.3",
79
+ "nyc": "17.1.0",
77
80
  "sass": "1.69.7",
78
81
  "typescript": "5.5.4",
79
82
  "typescript-eslint": "8.26.0",
80
83
  "vite-plugin-dts": "4.5.4",
84
+ "vite-plugin-istanbul": "7.0.0",
81
85
  "vitest": "2.1.9",
82
86
  "vue-tsc": "2.2.10"
83
87
  },
@@ -90,6 +94,11 @@
90
94
  "msw": {
91
95
  "workerDirectory": "public"
92
96
  },
97
+ "nyc": {
98
+ "report-dir": "coverage/e2e",
99
+ "reporter": ["lcov", "text-summary"],
100
+ "all": false
101
+ },
93
102
  "guido": {
94
103
  "stripo": {
95
104
  "version": "2.65.0"