@useinsider/guido 3.7.0-beta.830822b → 3.7.0-beta.ec4dd67

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 (35) hide show
  1. package/dist/composables/useHtmlValidator.js +165 -118
  2. package/dist/config/compiler/utils/recommendationCompilerUtils.js +28 -27
  3. package/dist/config/compiler/utils/recommendationIgnoreUtils.js +15 -0
  4. package/dist/config/migrator/recommendation/extractors.js +44 -22
  5. package/dist/config/migrator/recommendation/htmlBuilder.js +175 -169
  6. package/dist/config/migrator/recommendationMigrator.js +30 -31
  7. package/dist/enums/extensions/recommendationBlock.js +1 -3
  8. package/dist/extensions/Blocks/Recommendation/constants/selectors.js +21 -15
  9. package/dist/extensions/Blocks/Recommendation/controls/cardComposition/index.js +55 -41
  10. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +39 -38
  11. package/dist/extensions/Blocks/Recommendation/controls/main/layoutOrientation.js +44 -33
  12. package/dist/extensions/Blocks/Recommendation/controls/main/productCount.js +3 -2
  13. package/dist/extensions/Blocks/Recommendation/controls/main/productLayout.js +62 -52
  14. package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +75 -68
  15. package/dist/extensions/Blocks/Recommendation/controls/syncInfoMessage.js +7 -6
  16. package/dist/extensions/Blocks/Recommendation/extension.js +6 -5
  17. package/dist/extensions/Blocks/Recommendation/settingsPanel.js +3 -2
  18. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +8 -7
  19. package/dist/extensions/Blocks/Recommendation/templates/grid/template.js +13 -12
  20. package/dist/extensions/Blocks/Recommendation/templates/index.js +5 -4
  21. package/dist/services/recommendationApi.js +19 -31
  22. package/dist/src/composables/useHtmlValidator.d.ts +27 -0
  23. package/dist/src/composables/useHtmlValidator.test.d.ts +1 -0
  24. package/dist/src/config/compiler/utils/recommendationIgnoreUtils.d.ts +17 -0
  25. package/dist/src/config/compiler/utils/recommendationIgnoreUtils.test.d.ts +1 -0
  26. package/dist/src/config/migrator/recommendation/extractors.d.ts +15 -0
  27. package/dist/src/config/migrator/recommendation/htmlBuilder.d.ts +8 -0
  28. package/dist/src/enums/extensions/recommendationBlock.d.ts +0 -1
  29. package/dist/src/extensions/Blocks/Recommendation/constants/index.d.ts +1 -1
  30. package/dist/src/extensions/Blocks/Recommendation/constants/selectors.d.ts +21 -0
  31. package/dist/src/extensions/Blocks/Recommendation/controls/cardComposition/index.d.ts +7 -0
  32. package/dist/src/extensions/Blocks/Recommendation/controls/main/layoutOrientation.d.ts +5 -0
  33. package/dist/src/extensions/Blocks/Recommendation/controls/main/productLayout.d.ts +6 -0
  34. package/dist/src/extensions/Blocks/Recommendation/controls/main/utils.d.ts +9 -0
  35. package/package.json +1 -1
@@ -1,52 +1,40 @@
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";
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";
15
5
  return {
16
6
  fetchRecommendationCreateData: async () => {
17
7
  try {
18
- return (await o("/newsletter/recommendations/create-data")).data;
8
+ return (await r("/newsletter/recommendations/create-data")).data;
19
9
  } catch (e) {
20
10
  throw console.error("fetchUserModalState error:", e), e;
21
11
  }
22
12
  },
23
13
  fetchRecommendationFilters: async () => {
24
14
  try {
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);
15
+ const { data: e } = await r("/stripo/email-recommendation-attributes");
16
+ return e;
29
17
  } catch (e) {
30
18
  throw console.error("fetchRecommendationFilters error:", e), e;
31
19
  }
32
20
  },
33
- fetchRecommendationProducts: async (e, n) => {
34
- var i;
21
+ fetchRecommendationProducts: async (e, i) => {
22
+ var n;
35
23
  try {
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}`
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}`
42
30
  );
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;
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;
46
34
  }
47
35
  }
48
36
  };
49
37
  };
50
38
  export {
51
- f as useRecommendationApi
39
+ y as useRecommendationApi
52
40
  };
@@ -1,4 +1,31 @@
1
1
  import type { DynamicContent } from '@@/Types/generic';
2
+ import type { FiltersResponse } from '@@/Types/recommendation';
3
+ /**
4
+ * Parses a `{{recoId_index_attributeName}}` variable (already stripped of the
5
+ * braces/whitespace) into its recommendation id and attribute name. Returns
6
+ * null for anything that isn't a well-formed recommendation variable.
7
+ */
8
+ export declare function parseRecommendationVariable(field: string): {
9
+ recoId: string;
10
+ attribute: string;
11
+ } | null;
12
+ /**
13
+ * Builds the set of attribute forms valid inside partner-authored
14
+ * `{{recoId_index_attribute}}` variables: the built-in compiler attributes plus
15
+ * each account attribute in its canonical token form — bare for
16
+ * `defaultAttribute`, `product_attribute.<name>` for `productAttribute`. Using
17
+ * `resolveProductAttrValue` (the same producer the block builder uses) keeps the
18
+ * validator's notion of "valid form" identical to what is actually emitted.
19
+ */
20
+ export declare function buildPartnerAttributeNameSet(filterList: FiltersResponse): Set<string>;
21
+ /**
22
+ * Returns the `{{...}}` custom fields in the HTML that are invalid. Partner
23
+ * attributes in `ins-skip-compile` blocks (recoId ∈ ignoredIds) are checked
24
+ * against `ignoredAttributeNames`; Guido-generated reco variables and known merge
25
+ * tags pass. An unrecognized dotted token is ignored: it was never captured
26
+ * before, so flagging it would false-positive on merge tags like `{{user.name}}`.
27
+ */
28
+ export declare function findInvalidCustomFields(html: string, validCustomFields: string[], recommendationBlockIds: string[], ignoredIds: Set<string>, ignoredAttributeNames: Set<string> | null): string[];
2
29
  export declare const useHtmlValidator: () => {
3
30
  validateHtml: (html: string, customFields: DynamicContent[], isOnSaveValidation?: boolean) => Promise<boolean>;
4
31
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Returns true when a recommendation block has opted out of Guido's
3
+ * product-data → template-variable substitution. Partners signal opt-out by
4
+ * adding the `ins-skip-compile` class on the `.recommendation-block-v2`
5
+ * element. Only the variable substitution is skipped — campaign URL building,
6
+ * hidden-row removal, Outlook image widths, discount conditions, text-trim CSS
7
+ * and general HTML optimizations still apply. See `CSS_CLASS_SKIP_COMPILE` for
8
+ * the full scope.
9
+ */
10
+ export declare function isIgnoredRecommendationBlock(block: Element): boolean;
11
+ /**
12
+ * DOM-parses the HTML once and returns the set of `recommendation-id`
13
+ * values that belong to ignored blocks. Use this in regex/string-based
14
+ * compiler rules where the rule processes flat matches and only has the
15
+ * extracted block ID rather than a DOM Element reference.
16
+ */
17
+ export declare function getIgnoredRecommendationBlockIds(html: string): Set<string>;
@@ -5,3 +5,18 @@ export declare function extractTitleText(block: Element): string;
5
5
  * the caller treats that as "no segment background".
6
6
  */
7
7
  export declare function extractCardBgColor(block: Element): string;
8
+ /**
9
+ * Reads the legacy block's own `currency-*` attributes into a
10
+ * `currencySettings`-shaped object that `mapCurrency` understands. Used as a
11
+ * fallback when the external recommendationConfigs map has no entry for this
12
+ * block, so the migrated block keeps its real currency instead of defaulting.
13
+ * Returns undefined when the block carries no `currency` attribute.
14
+ */
15
+ export declare function extractCurrencyFromBlock(block: Element): Record<string, string> | undefined;
16
+ /**
17
+ * True when a PM has manually opted the legacy block out of content
18
+ * regeneration by adding the `ins-skip-compile` class. Detected before rebuild
19
+ * so the migrator preserves the partner's markup verbatim (keeping their
20
+ * hand-authored variables) instead of regenerating the block.
21
+ */
22
+ export declare function isPartnerManagedBlock(block: Element): boolean;
@@ -8,4 +8,12 @@ export declare function buildBlockHtml(params: {
8
8
  extraClasses?: string;
9
9
  legacyId?: string;
10
10
  legacyBgColor?: string;
11
+ /**
12
+ * When set, the block's existing inner HTML is preserved verbatim instead
13
+ * of regenerating product rows — used for partner-customized blocks so
14
+ * their hand-authored `{{...}}` variables survive migration.
15
+ */
16
+ preserveInnerHtml?: string;
17
+ /** Adds the `ins-skip-compile` opt-out class to the migrated block. */
18
+ skipCompile?: boolean;
11
19
  }): string;
@@ -2,7 +2,6 @@ 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;
6
5
  };
7
6
  export declare const QUERY_PARAMS: {
8
7
  CLIENT_ID: string;
@@ -8,6 +8,6 @@
8
8
  */
9
9
  export { RecommendationBlockId } from './blockIds';
10
10
  export { RecommendationControlId } from './controlIds';
11
- export { BLOCK_ROOT_SELECTOR, CONTAINER_SELECTOR, DESKTOP_CONTAINER_SELECTOR, MOBILE_CONTAINER_SELECTOR, MOBILE_ROW_SELECTOR, CSS_CLASS_RECO_BUTTON, CURRENCY_ATTR, ATTR_PRODUCT_IMAGE, ATTR_PRODUCT_NAME, ATTR_PRODUCT_PRICE, ATTR_PRODUCT_OLD_PRICE, ATTR_PRODUCT_OMNIBUS_PRICE, ATTR_PRODUCT_OMNIBUS_DISCOUNT, ATTR_PRODUCT_BUTTON, ATTR_CUSTOM_PREFIX, ATTR_DATA_CUSTOM_ATTRIBUTES, ATTR_PRODUCT_ATTR, BUILT_IN_DEFAULT_ATTRIBUTES, } from './selectors';
11
+ export { BLOCK_ROOT_SELECTOR, CONTAINER_SELECTOR, DESKTOP_CONTAINER_SELECTOR, MOBILE_CONTAINER_SELECTOR, MOBILE_ROW_SELECTOR, CSS_CLASS_RECO_BUTTON, CSS_CLASS_SKIP_COMPILE, RECOMMENDATION_VARIABLE_BUILTIN_ATTRIBUTES, CURRENCY_ATTR, ATTR_PRODUCT_IMAGE, ATTR_PRODUCT_NAME, ATTR_PRODUCT_PRICE, ATTR_PRODUCT_OLD_PRICE, ATTR_PRODUCT_OMNIBUS_PRICE, ATTR_PRODUCT_OMNIBUS_DISCOUNT, ATTR_PRODUCT_BUTTON, ATTR_CUSTOM_PREFIX, ATTR_DATA_CUSTOM_ATTRIBUTES, ATTR_PRODUCT_ATTR, BUILT_IN_DEFAULT_ATTRIBUTES, } from './selectors';
12
12
  export { LAYOUT_VALUES, LAYOUT_OPTIONS, DEFAULT_PRODUCTS_PER_ROW, DEFAULT_CARDS_IN_ROW, DEFAULT_MOBILE_CARDS_IN_ROW, MAX_PRODUCT_COUNT, MIN_PRODUCT_COUNT, MAX_PRODUCTS_PER_ROW, MIN_PRODUCTS_PER_ROW, MAX_MOBILE_PRODUCTS_PER_ROW, MIN_MOBILE_PRODUCTS_PER_ROW, DEFAULT_COLUMN_SPACING, DEFAULT_ROW_SPACING, DEFAULT_MOBILE_COLUMN_SPACING, DEFAULT_MOBILE_ROW_SPACING, MIN_SPACING, MAX_SPACING, SPACING_STEP, } from './layout';
13
13
  export { DEFAULT_NODE_CONFIG, DEFAULT_CURRENCY, DEFAULT_COMPOSITION, DEFAULT_VISIBILITY, CURRENT_CONFIG_VERSION, EXCLUDED_ALGORITHM_IDS, } from './defaultConfig';
@@ -23,6 +23,18 @@ export declare const MOBILE_ROW_SELECTOR = ".ins-recommendation-mobile-row";
23
23
  * `{{cId_pIdx_url}}` template variable.
24
24
  */
25
25
  export declare const CSS_CLASS_RECO_BUTTON = "reco-v3-button";
26
+ /**
27
+ * Opt-out class for partners who want to inject their own template variables
28
+ * into a recommendation block. When present on `.recommendation-block-v2`,
29
+ * Guido skips ONLY its product-data → template-variable substitution
30
+ * (`replaceProductAttributes`) for that block — partners author their own
31
+ * `{{recoId_index_attribute}}` variables. Everything else (campaign URL
32
+ * building, hidden-row removal, Outlook image widths, text-trim CSS, discount
33
+ * conditions, store hydration, store-level config validation, and general HTML
34
+ * optimizations) still applies. The class is preserved in the final compiled
35
+ * output so partners may use it for their own styling.
36
+ */
37
+ export declare const CSS_CLASS_SKIP_COMPILE = "ins-skip-compile";
26
38
  /**
27
39
  * Currency HTML attributes set on the block element
28
40
  * These are read by the HTML compiler at runtime to format prices
@@ -61,3 +73,12 @@ export declare const ATTR_PRODUCT_ATTR = "product-attr";
61
73
  * Used to exclude these from the custom attribute dropdown to prevent duplication with toggles.
62
74
  */
63
75
  export declare const BUILT_IN_DEFAULT_ATTRIBUTES: Set<string>;
76
+ /**
77
+ * Attribute names valid inside a `{{recoId_index_attributeName}}` template
78
+ * variable regardless of the account's custom attribute list. Every built-in
79
+ * composition attribute is valid, plus `currency` and `discount` which the
80
+ * compiler emits but are not composition toggles. Custom attributes are
81
+ * validated separately against the account's fetched attribute list
82
+ * (`stripo/email-recommendation-attributes`).
83
+ */
84
+ export declare const RECOMMENDATION_VARIABLE_BUILTIN_ATTRIBUTES: Set<string>;
@@ -17,6 +17,13 @@ export declare class RecommendationCardCompositionControl extends CommonControl
17
17
  getId(): string;
18
18
  getTemplate(): string;
19
19
  onRender(): void;
20
+ /**
21
+ * Card composition restructures the block (toggles/reorders/adds attribute
22
+ * cells), which would corrupt a partner-managed (`ins-skip-compile`) block's
23
+ * preserved markup. There is no native tab-disable API, so the whole control
24
+ * container is rendered inert (greyed + non-interactive) instead.
25
+ */
26
+ _syncDisabledState(): void;
20
27
  onTemplateNodeUpdated(node: ImmutableHtmlNode): void;
21
28
  onDestroy(): void;
22
29
  private _initializeComposition;
@@ -21,6 +21,11 @@ export declare class LayoutOrientationControl extends CommonControl {
21
21
  getTemplate(): string;
22
22
  onRender(): void;
23
23
  onTemplateNodeUpdated(node: ImmutableHtmlNode): void;
24
+ /**
25
+ * Layout orientation restructures the whole block, which is meaningless for
26
+ * partner-managed (`ins-skip-compile`) blocks — disable the control there.
27
+ */
28
+ _syncDisabledState(): void;
24
29
  _setFormValues(): void;
25
30
  /**
26
31
  * Handles layout change
@@ -30,6 +30,12 @@ export declare class ProductLayoutControl extends CommonControl {
30
30
  getTemplate(): string;
31
31
  onRender(): void;
32
32
  onTemplateNodeUpdated(node: ImmutableHtmlNode): void;
33
+ /**
34
+ * Products-per-row and mobile-layout restructure the block, which is
35
+ * meaningless for partner-managed (`ins-skip-compile`) blocks — disable
36
+ * these inputs there. Disabling coexists with the visibility logic above.
37
+ */
38
+ _syncDisabledState(): void;
33
39
  onDestroy(): void;
34
40
  _setFormValues(): void;
35
41
  /**
@@ -35,6 +35,15 @@ interface DocumentModifier {
35
35
  * @returns The block element or null if not found
36
36
  */
37
37
  export declare function getBlockElement(currentNode: ImmutableHtmlNode | null | undefined): ImmutableHtmlNode | null;
38
+ /**
39
+ * True when the recommendation block has opted out of Guido's content
40
+ * regeneration via the `ins-skip-compile` class. Partner-managed blocks carry
41
+ * hand-authored `{{...}}` variables in their cells, so Guido must never
42
+ * overwrite their content with product data (regenerate / in-place update).
43
+ * @param currentNode - The current template node
44
+ * @returns True if the block opted out of content regeneration
45
+ */
46
+ export declare function isPartnerManagedBlock(currentNode: ImmutableHtmlNode | null | undefined): boolean;
38
47
  /**
39
48
  * Gets the current layout orientation from the block's data attribute
40
49
  * Supports both old (horizontal/vertical) and new (list/grid) values for backward compatibility
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.7.0-beta.830822b",
3
+ "version": "3.7.0-beta.ec4dd67",
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",