@useinsider/guido 3.15.0-beta.0b5dc39 → 3.15.0-beta.0cbd17f

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,15 +1,16 @@
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 F } from "pinia";
4
+ import { defineStore as P } from "pinia";
5
5
  import "../constants/selectors.js";
6
- import { DEFAULT_MOBILE_CARDS_IN_ROW as P, DEFAULT_CARDS_IN_ROW as D } from "../constants/layout.js";
6
+ import { DEFAULT_MOBILE_CARDS_IN_ROW as F, DEFAULT_CARDS_IN_ROW as D } from "../constants/layout.js";
7
7
  import { EXCLUDED_ALGORITHM_IDS as w } from "../constants/defaultConfig.js";
8
8
  import { getDefaultProducts as S } from "../templates/utils.js";
9
9
  import { generateCompleteFilterQuery as b } from "../utils/filterUtil.js";
10
10
  import { getPartnerRecommendationParams as v } from "../utils/partnerCustomizations.js";
11
- import { isFilterValid as N } from "../validation/filterSchema.js";
12
- import { isConfigValid as x } from "../validation/requiredFields.js";
11
+ import { sanitizeProductIds as N } from "../utils/productIds.js";
12
+ import { isFilterValid as x } from "../validation/filterSchema.js";
13
+ import { isConfigValid as L } from "../validation/requiredFields.js";
13
14
  const h = y();
14
15
  let m = null, u = null, d = null;
15
16
  function k() {
@@ -28,7 +29,7 @@ function k() {
28
29
  productIds: [],
29
30
  id: 1,
30
31
  language: "en_US",
31
- mobileCardsInRow: P,
32
+ mobileCardsInRow: F,
32
33
  mobileLayoutEnabled: !1,
33
34
  orientation: "grid",
34
35
  recommendedProducts: [],
@@ -54,7 +55,7 @@ function I() {
54
55
  filterSnapshot: null
55
56
  };
56
57
  }
57
- const L = () => ({
58
+ const U = () => ({
58
59
  recommendationCampaignUrls: {},
59
60
  activePredictiveAlgorithms: [],
60
61
  languages: {},
@@ -63,8 +64,8 @@ const L = () => ({
63
64
  blockStates: {},
64
65
  currentRecommendationId: null,
65
66
  configVersion: 0
66
- }), $ = F("guidoRecommendationExtension", {
67
- state: () => L(),
67
+ }), H = P("guidoRecommendationExtension", {
68
+ state: () => U(),
68
69
  getters: {
69
70
  // ====================================================================
70
71
  // Proxy Getters — Backward Compatible Access to Current Block State
@@ -383,7 +384,7 @@ const L = () => ({
383
384
  const n = [...e.recommendationConfigs.filters];
384
385
  n[r] = {
385
386
  ...t,
386
- isValid: N(t)
387
+ isValid: x(t)
387
388
  }, e.recommendationConfigs.filters = n;
388
389
  }
389
390
  },
@@ -429,7 +430,7 @@ const L = () => ({
429
430
  * every block's recommendationConfigs across user edits.
430
431
  */
431
432
  hasInvalidBlock() {
432
- return Object.values(this.blockStates).some((t) => !x(t.recommendationConfigs, this));
433
+ return Object.values(this.blockStates).some((t) => !L(t.recommendationConfigs, this));
433
434
  },
434
435
  // ====================================================================
435
436
  // Per-Block Product Fetching
@@ -458,7 +459,7 @@ const L = () => ({
458
459
  details: !0,
459
460
  campaignId: o.variationId
460
461
  };
461
- r.strategy === "manualMerchandising" ? a.productId = r.productIds.join(",") : r.strategy === "similarViewed" && (a.productId = "{itemId}"), r.strategy === "userBased" && (a.userId = "{user_id}"), c && (a.filter = c), r.shuffleProducts && (a.shuffle = !0), Object.assign(
462
+ r.strategy === "manualMerchandising" ? a.productId = N(r.productIds) : r.strategy === "similarViewed" && (a.productId = "{itemId}"), r.strategy === "userBased" && (a.userId = "{user_id}"), c && (a.filter = c), r.shuffleProducts && (a.shuffle = !0), Object.assign(
462
463
  a,
463
464
  v(o.partnerName, r.strategy)
464
465
  );
@@ -479,5 +480,5 @@ const L = () => ({
479
480
  }
480
481
  });
481
482
  export {
482
- $ as useRecommendationExtensionStore
483
+ H as useRecommendationExtensionStore
483
484
  };
@@ -0,0 +1,6 @@
1
+ function n(t) {
2
+ return t.map((i) => String(i ?? "").trim()).filter(Boolean).join(",");
3
+ }
4
+ export {
5
+ n as sanitizeProductIds
6
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Builds the request/URL `productId` value from raw product ID segments.
3
+ * Trimming happens here — NOT on input change — so the user's in-progress
4
+ * text (trailing commas, spaces) is never rewritten under the caret (SD-147111).
5
+ */
6
+ export declare function sanitizeProductIds(ids: readonly (string | number | null | undefined)[]): string;
@@ -1,88 +1,100 @@
1
- import { productPairs as q } from "../extensions/Blocks/Items/enums/productEnums.js";
2
- import { DefaultConfigValues as O } from "../extensions/Blocks/Items/enums/settingsEnums.js";
3
- import { preserveTextStyles as C } from "./preserveTextStyles.js";
4
- import { unwrapProductNameLinks as U } from "./unwrapProductNameLink.js";
5
- function Y(L) {
6
- const H = L.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), b = new DOMParser().parseFromString(H, "text/html");
7
- U(b);
8
- const R = q.PAIRS_FOR_EXTENSION;
9
- Object.entries(R).forEach(([r, u]) => {
10
- b.querySelectorAll(".ins-product-td").forEach((l) => {
11
- const h = l.getAttribute("data-number") || "1", $ = l.getAttribute("data-type") || "CART_ITEMS";
12
- l.querySelectorAll(`[product-attr="${r}"]`).forEach((t) => {
13
- var F, I, w;
14
- const T = t.getAttribute("data-type") || $, f = t.getAttribute("data-number") || h, d = u[T];
15
- if (d)
16
- switch (r) {
1
+ import { productPairs as L } from "../extensions/Blocks/Items/enums/productEnums.js";
2
+ import { DefaultConfigValues as V } from "../extensions/Blocks/Items/enums/settingsEnums.js";
3
+ import { escapeReplacement as G } from "../extensions/Blocks/Items/utils/nodeConfigUtils.js";
4
+ import { preserveTextStyles as F } from "./preserveTextStyles.js";
5
+ import { unwrapProductNameLinks as X } from "./unwrapProductNameLink.js";
6
+ const x = {
7
+ CART_ITEMS: "ins_apr",
8
+ BROWSED_ITEMS: "browsed_item",
9
+ PURCHASED_ITEMS: "purchased_item"
10
+ }, N = (S) => S.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->");
11
+ function v(S, H, g) {
12
+ let $ = H;
13
+ for (; $ > 0 && /\s/.test(S[$ - 1]); )
14
+ $ -= 1;
15
+ return g.some((I) => S.endsWith(I, $));
16
+ }
17
+ function J(S) {
18
+ const H = N(S), g = new DOMParser().parseFromString(H, "text/html");
19
+ X(g);
20
+ const $ = L.PAIRS_FOR_EXTENSION;
21
+ Object.entries($).forEach(([n, d]) => {
22
+ g.querySelectorAll(".ins-product-td").forEach((r) => {
23
+ const E = r.getAttribute("data-number") || "1", m = r.getAttribute("data-type") || "CART_ITEMS";
24
+ r.querySelectorAll(`[product-attr="${n}"]`).forEach((t) => {
25
+ var T, P, D;
26
+ const R = t.getAttribute("data-type") || m, o = t.getAttribute("data-number") || E, f = d[R];
27
+ if (f)
28
+ switch (n) {
17
29
  case "imageSrc": {
18
- let e = null, c = null;
19
- if (t.tagName === "IMG" ? (e = t, c = e.closest("a")) : (e = t.querySelector("img"), c = t.querySelector("a") || t.closest("a")), !e)
30
+ let e = null, s = null;
31
+ if (t.tagName === "IMG" ? (e = t, s = e.closest("a")) : (e = t.querySelector("img"), s = t.querySelector("a") || t.closest("a")), !e)
20
32
  break;
21
- const i = d.DEFAULT, a = d.ATTR;
22
- if (i && e.src) {
23
- const o = e.src;
24
- i.some((E) => {
25
- const s = E.split("/").pop() || "", g = o.split("/").pop() || "";
26
- return o.includes(E) || o.includes(s) || g === s;
27
- }) && (e.src = `{{${a}_${f}}}`);
33
+ const a = f.DEFAULT, l = f.ATTR;
34
+ if (a && e.src) {
35
+ const i = e.src;
36
+ a.some((b) => {
37
+ const u = b.split("/").pop() || "", y = i.split("/").pop() || "";
38
+ return i.includes(b) || i.includes(u) || y === u;
39
+ }) && (e.src = `{{${l}_${o}}}`);
28
40
  }
29
- const n = (I = (F = R.name) == null ? void 0 : F[T]) == null ? void 0 : I.ATTR;
30
- if (n && e.setAttribute("alt", `{{${n}_${f}}}`), c) {
31
- const o = (w = R.itemLink) == null ? void 0 : w[T];
32
- if (o) {
33
- const A = o.HREF, E = o.DEFAULT_HREF || "#!", s = c.href;
34
- (s === "#" || s === "" || s.endsWith("#!") || s.endsWith(E) || s === `${window.location.href}${E}` || !s || s === window.location.href) && (c.href = `{{${A}_${f}}}`);
41
+ const c = (P = (T = $.name) == null ? void 0 : T[R]) == null ? void 0 : P.ATTR;
42
+ if (c && e.setAttribute("alt", `{{${c}_${o}}}`), s) {
43
+ const i = (D = $.itemLink) == null ? void 0 : D[R];
44
+ if (i) {
45
+ const _ = i.HREF, b = i.DEFAULT_HREF || "#!", u = s.href;
46
+ (u === "#" || u === "" || u.endsWith("#!") || u.endsWith(b) || u === `${window.location.href}${b}` || !u || u === window.location.href) && (s.href = `{{${_}_${o}}}`);
35
47
  }
36
48
  }
37
49
  break;
38
50
  }
39
51
  case "name": {
40
- const e = d, c = e.ATTR, i = e.DEFAULT_HREF || "#!", a = e.HREF;
41
- t.textContent && (t.innerHTML = C(t, `{{${c}_${f}}}`));
42
- const n = t.closest("a") || (t.tagName === "A" ? t : null);
43
- if (n && a) {
44
- const o = n.href, A = `${window.location.href}${i}`;
45
- (o === A || o.endsWith(i)) && (n.href = `{{${a}_${f}}}`);
52
+ const e = f, s = e.ATTR, a = e.DEFAULT_HREF || "#!", l = e.HREF;
53
+ t.textContent && (t.innerHTML = F(t, `{{${s}_${o}}}`));
54
+ const c = t.closest("a") || (t.tagName === "A" ? t : null);
55
+ if (c && l) {
56
+ const i = c.href, _ = `${window.location.href}${a}`;
57
+ (i === _ || i.endsWith(a)) && (c.href = `{{${l}_${o}}}`);
46
58
  }
47
59
  break;
48
60
  }
49
61
  case "price":
50
62
  case "originalPrice": {
51
- const e = d, c = t.getAttribute("data-formated"), i = t.getAttribute("data-single_price"), a = c === "true", n = i === "true", o = t.getAttribute("data-curency") || "before";
52
- let A;
53
- n ? A = a ? e.SINGLE_PRICE_FORMATTED : e.SINGLE_PRICE : A = a ? e.PRICE_FORMATTED : e.PRICE;
54
- const E = e.CURRENCY;
55
- let s = `{{${A}_${f}}}`;
56
- const g = (t.getAttribute("data-currency_symbol") || "").trim(), N = g !== "" && g !== O.productPriceCurrencySymbolControlValue;
57
- let m = "";
58
- N ? m = g : E && (m = `{{${E}_${f}}}`), m && (s = o === "after" ? `${s} ${m}` : `${m} ${s}`), t.innerHTML = C(t, s);
63
+ const e = f, s = t.getAttribute("data-formated"), a = t.getAttribute("data-single_price"), l = s === "true", c = a === "true", i = t.getAttribute("data-curency") || "before";
64
+ let _;
65
+ c ? _ = l ? e.SINGLE_PRICE_FORMATTED : e.SINGLE_PRICE : _ = l ? e.PRICE_FORMATTED : e.PRICE;
66
+ const b = e.CURRENCY;
67
+ let u = `{{${_}_${o}}}`;
68
+ const y = (t.getAttribute("data-currency_symbol") || "").trim(), W = y !== "" && y !== V.productPriceCurrencySymbolControlValue;
69
+ let C = "";
70
+ W ? C = y : b && (C = `{{${b}_${o}}}`), C && (u = i === "after" ? `${u} ${C}` : `${C} ${u}`), t.innerHTML = F(t, u);
59
71
  break;
60
72
  }
61
73
  case "quantity": {
62
- const e = d, c = e.ATTR, i = e.DEFAULT;
63
- t.textContent && t.textContent.trim() === i && (t.innerHTML = C(t, `{{${c}_${f}}}`));
74
+ const e = f, s = e.ATTR, a = e.DEFAULT;
75
+ t.textContent && t.textContent.trim() === a && (t.innerHTML = F(t, `{{${s}_${o}}}`));
64
76
  break;
65
77
  }
66
78
  case "button": {
67
- const e = d, c = e.HREF, i = e.DEFAULT_HREF || "#!", a = t.tagName === "A" ? t : t.querySelector("a");
68
- if (a) {
69
- const n = a.href || "", o = `${window.location.href}${i}`;
70
- (n === "" || n === "#" || n === o || n.endsWith(i) || n.endsWith("#!") || n === window.location.href) && (a.href = `{{${c}_${f}}}`);
79
+ const e = f, s = e.HREF, a = e.DEFAULT_HREF || "#!", l = t.tagName === "A" ? t : t.querySelector("a");
80
+ if (l) {
81
+ const c = l.href || "", i = `${window.location.href}${a}`;
82
+ (c === "" || c === "#" || c === i || c.endsWith(a) || c.endsWith("#!") || c === window.location.href) && (l.href = `{{${s}_${o}}}`);
71
83
  }
72
84
  break;
73
85
  }
74
86
  case "itemLink": {
75
- const e = d, c = e.HREF, i = e.DEFAULT_HREF || "#!", a = t;
76
- if (a.href) {
77
- const n = a.href, o = `${window.location.href}${i}`;
78
- (n === o || n.endsWith(i)) && (a.href = `{{${c}_${f}}}`);
87
+ const e = f, s = e.HREF, a = e.DEFAULT_HREF || "#!", l = t;
88
+ if (l.href) {
89
+ const c = l.href, i = `${window.location.href}${a}`;
90
+ (c === i || c.endsWith(a)) && (l.href = `{{${s}_${o}}}`);
79
91
  }
80
92
  break;
81
93
  }
82
94
  default: {
83
- if ("ATTR" in d) {
84
- const e = d.ATTR;
85
- t.textContent && (t.innerHTML = C(t, `{{${e}_${f}}}`));
95
+ if ("ATTR" in f) {
96
+ const e = f.ATTR;
97
+ t.textContent && (t.innerHTML = F(t, `{{${e}_${o}}}`));
86
98
  }
87
99
  break;
88
100
  }
@@ -90,55 +102,49 @@ function Y(L) {
90
102
  });
91
103
  });
92
104
  });
93
- const k = H.match(/<!DOCTYPE[^>]*>/i), P = k ? `${k[0]}
94
- ` : "", D = b.querySelectorAll(".ins-product-td"), M = [];
95
- D.forEach((r) => {
96
- const u = r.getAttribute("data-type") || "CART_ITEMS", p = r.getAttribute("data-number") || "1", l = r.outerHTML;
105
+ const I = H.match(/<!DOCTYPE[^>]*>/i), O = I ? `${I[0]}
106
+ ` : "", q = g.querySelectorAll(".ins-product-td"), M = [];
107
+ q.forEach((n) => {
108
+ const d = n.getAttribute("data-type") || "CART_ITEMS", p = n.getAttribute("data-number") || "1", r = n.outerHTML;
97
109
  M.push({
98
- element: r,
99
- outerHtml: l,
100
- type: u,
110
+ element: n,
111
+ outerHtml: r,
112
+ type: d,
101
113
  number: p
102
114
  });
103
115
  });
104
- let _ = P + b.documentElement.outerHTML;
105
- M.reverse().forEach(({ outerHtml: r, type: u, number: p }) => {
106
- let l = "";
107
- switch (u) {
108
- case "CART_ITEMS":
109
- l = "ins_apr_total_product_kind";
110
- break;
111
- case "BROWSED_ITEMS":
112
- l = "browsed_item_total_product_kind";
113
- break;
114
- case "PURCHASED_ITEMS":
115
- l = "purchased_item_total_product_kind";
116
- break;
117
- }
118
- if (l) {
119
- const $ = parseInt(p) - 1, T = `${`{% if ${l} > ${$} %}`}${r}{% endif %}`;
120
- _ = _.replace(r, T);
116
+ let A = O + g.documentElement.outerHTML;
117
+ M.reverse().forEach(({ outerHtml: n, type: d, number: p }) => {
118
+ const r = x[d], E = r ? `${r}_total_product_kind` : "";
119
+ if (E) {
120
+ const h = parseInt(p) - 1, o = `${`{% if ${E} > ${h} %}`}${n}{% endif %}`;
121
+ A = A.replace(n, G(o));
121
122
  }
122
123
  });
123
- const x = b.querySelectorAll('[product-attr="originalPrice"][data-type="CART_ITEMS"]'), S = [];
124
- return x.forEach((r) => {
125
- var $;
126
- const u = r.getAttribute("data-number"), p = r.getAttribute("data-type");
127
- if (!u || p !== "CART_ITEMS" || (($ = r.closest(".ins-product-td")) == null ? void 0 : $.getAttribute("data-nodup")) === "false")
124
+ const U = g.querySelectorAll('[product-attr="originalPrice"][data-type]'), w = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Set();
125
+ return U.forEach((n) => {
126
+ var t;
127
+ const d = n.getAttribute("data-number"), p = n.getAttribute("data-type");
128
+ if (!d || !x[p])
128
129
  return;
129
- const h = r.closest(".product-original-price-class");
130
- if (h) {
131
- const y = h.outerHTML;
132
- S.some((T) => T.tdOuterHtml === y) || S.push({ tdOuterHtml: y, number: u });
133
- }
134
- }), S.reverse().forEach(({ tdOuterHtml: r, number: u }) => {
135
- const p = `{% if ins_apr_price_${u} != ins_apr_originalprice_${u} %}`;
136
- if (!_.includes(p) && !r.includes("{% if")) {
137
- const h = `${p}${r}{% endif %}`;
138
- _ = _.replace(r, h);
130
+ const r = n.closest(".product-original-price-class");
131
+ if (!r || k.has(r))
132
+ return;
133
+ k.add(r);
134
+ const E = r.outerHTML, m = (t = n.closest(".ins-product-td")) == null ? void 0 : t.getAttribute("data-nodup"), h = w.get(E) ?? { number: d, type: p, wrap: [] };
135
+ h.wrap.push(m !== "false"), w.set(E, h);
136
+ }), w.forEach(({ number: n, type: d, wrap: p }, r) => {
137
+ if (r.includes("{% if") || !p.some(Boolean))
138
+ return;
139
+ const E = L.PAIRS_FOR_EXTENSION.price[d].PRICE, m = L.PAIRS_FOR_EXTENSION.originalPrice[d].PRICE, h = `{% if ${E}_${n} != ${m}_${n} %}`, t = [h, N(h)];
140
+ let R = "", o = 0, f = 0, T = A.indexOf(r);
141
+ for (; T !== -1; ) {
142
+ const P = p[f] === !0 && !v(A, T, t);
143
+ R += A.slice(o, T) + (P ? `${h}${r}{% endif %}` : r), o = T + r.length, f += 1, T = A.indexOf(r, o);
139
144
  }
140
- }), _.replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
145
+ A = R + A.slice(o);
146
+ }), A.replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
141
147
  }
142
148
  export {
143
- Y as pairProductVariables
149
+ J as pairProductVariables
144
150
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.15.0-beta.0b5dc39",
3
+ "version": "3.15.0-beta.0cbd17f",
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",