@magicx-eng/ai-autocomplete-vanilla 0.40.0 → 0.42.0

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.
package/README.md CHANGED
@@ -81,6 +81,7 @@ const ac = new AIAutocomplete(container, {
81
81
  commitOnWordEnd: false, // true = a word still being typed never becomes a chip until a space, Enter, or Tab ends it (exact matches and server identified params). Picking an option is unchanged.
82
82
  additionalContext: { tier: "gold" }, // optional user context, to personalize suggestions and options
83
83
  language: "es", // BCP 47 tag sent with every suggestion request and telemetry event. Default: navigator.language, else "en-US"
84
+ productId: "...", // your product id: what the dropdown offers before anything is typed is read from a cacheable URL with no credential; falls back to a suggestion request
84
85
 
85
86
  // Appearance
86
87
  mode: "auto", // "light" | "dark" | "auto"
package/dist/index.d.mts CHANGED
@@ -170,10 +170,12 @@ interface MatchedItem {
170
170
  origin_id?: string;
171
171
  title: string;
172
172
  /**
173
- * The item's lowest price, verbatim as the catalog spells it ("131.00").
174
- * Not formatted for display: the currency is the storefront's to add.
173
+ * The item's price as the catalog's number ("131.00").
174
+ * The strip formats it with `currency` when the item has one.
175
175
  */
176
176
  price?: string;
177
+ /** ISO 4217 currency code. Absent when unknown. */
178
+ currency?: string;
177
179
  vendor?: string;
178
180
  /**
179
181
  * The platform's URL slug for the item, not a URL. The SDK builds a relative
@@ -403,7 +405,10 @@ interface Product {
403
405
  url?: string;
404
406
  /** Absent/null renders the placeholder tile — plenty of catalogues have no images. */
405
407
  imageUrl?: string | null;
406
- /** Pre-formatted by the integration, which is the side that knows the currency. */
408
+ /**
409
+ * Display text. The built-in strip formats it with the item's currency when the server sends one.
410
+ * A custom integration (`opts.products`) supplies its own text.
411
+ */
407
412
  price?: string;
408
413
  vendor?: string;
409
414
  /**
@@ -940,8 +945,16 @@ interface CoreOptions {
940
945
  /**
941
946
  * BCP 47 language tag (e.g. `"es"`), sent with every suggestion request and telemetry event.
942
947
  * Default: the browser language (`navigator.language`), else `"en-US"`.
948
+ * Only an explicit value selects the SDK's own UI words (Spanish for `es`, English otherwise). The browser language does not.
943
949
  */
944
950
  language?: string;
951
+ /**
952
+ * Your product id. When set, what the dropdown offers before anything is
953
+ * typed is read from a cacheable URL for your product, with no credential,
954
+ * instead of a suggestion request; it falls back to a suggestion request
955
+ * when it cannot be read.
956
+ */
957
+ productId?: string;
945
958
  /**
946
959
  * Stable id for this visitor, kept by the host across page loads (e.g. a
947
960
  * first-party cookie). Rides on funnel telemetry so searches can be joined
@@ -1372,6 +1385,7 @@ declare class AIAutocomplete {
1372
1385
  */
1373
1386
  private fireImpression;
1374
1387
  private fireTelemetry;
1388
+ private updateLanguageAttribute;
1375
1389
  private setupContainer;
1376
1390
  private buildAndRenderFull;
1377
1391
  private buildAndRenderDropdown;
@@ -2101,6 +2115,20 @@ interface RenderEditableArgs {
2101
2115
  */
2102
2116
  declare function renderEditableContent(args: RenderEditableArgs): void;
2103
2117
 
2118
+ declare const en: {
2119
+ language: string;
2120
+ proceed: string;
2121
+ select: string;
2122
+ skipHint: string;
2123
+ skip: string;
2124
+ skipLabel: string;
2125
+ products: string;
2126
+ soldOut: string;
2127
+ submit: string;
2128
+ scrollArrow: string;
2129
+ };
2130
+ type UIStrings = typeof en;
2131
+
2104
2132
  /**
2105
2133
  * The "more below" arrow for the options grid.
2106
2134
  *
@@ -2291,7 +2319,7 @@ declare function buildQuery(text: string, completedParams: CompletedParamState[]
2291
2319
  * Pure computation — no DOM access. Shared by the vanilla renderer and the
2292
2320
  * React / Angular footer components so the wording can't drift between them.
2293
2321
  */
2294
- declare function getFooterHint(optionHighlighted: boolean, isInputEmpty: boolean): {
2322
+ declare function getFooterHint(optionHighlighted: boolean, isInputEmpty: boolean, strings?: UIStrings): {
2295
2323
  key: string;
2296
2324
  hint: string;
2297
2325
  };
@@ -2325,14 +2353,14 @@ declare const PRODUCT_PATH_PREFIX = "/products/";
2325
2353
  * `url`: still activatable, still emitting `onProductSelect`, just nothing for
2326
2354
  * cmd-click to open.
2327
2355
  */
2328
- declare function productFromMatchedItem(item: MatchedItem): Product;
2356
+ declare function productFromMatchedItem(item: MatchedItem, language?: string): Product;
2329
2357
  /**
2330
2358
  * The strip's contents for a response's catalog report. `null` — no block on
2331
2359
  * the response — is an empty strip rather than "keep the previous one": the
2332
2360
  * previous items answered a previous query, and a strip must never show
2333
2361
  * results belonging to an older one.
2334
2362
  */
2335
- declare function productsFromCustomFields(report: CustomFieldsReport | null | undefined): Product[];
2363
+ declare function productsFromCustomFields(report: CustomFieldsReport | null | undefined, language?: string): Product[];
2336
2364
 
2337
2365
  declare class ModeController {
2338
2366
  private container;
package/dist/index.d.ts CHANGED
@@ -170,10 +170,12 @@ interface MatchedItem {
170
170
  origin_id?: string;
171
171
  title: string;
172
172
  /**
173
- * The item's lowest price, verbatim as the catalog spells it ("131.00").
174
- * Not formatted for display: the currency is the storefront's to add.
173
+ * The item's price as the catalog's number ("131.00").
174
+ * The strip formats it with `currency` when the item has one.
175
175
  */
176
176
  price?: string;
177
+ /** ISO 4217 currency code. Absent when unknown. */
178
+ currency?: string;
177
179
  vendor?: string;
178
180
  /**
179
181
  * The platform's URL slug for the item, not a URL. The SDK builds a relative
@@ -403,7 +405,10 @@ interface Product {
403
405
  url?: string;
404
406
  /** Absent/null renders the placeholder tile — plenty of catalogues have no images. */
405
407
  imageUrl?: string | null;
406
- /** Pre-formatted by the integration, which is the side that knows the currency. */
408
+ /**
409
+ * Display text. The built-in strip formats it with the item's currency when the server sends one.
410
+ * A custom integration (`opts.products`) supplies its own text.
411
+ */
407
412
  price?: string;
408
413
  vendor?: string;
409
414
  /**
@@ -940,8 +945,16 @@ interface CoreOptions {
940
945
  /**
941
946
  * BCP 47 language tag (e.g. `"es"`), sent with every suggestion request and telemetry event.
942
947
  * Default: the browser language (`navigator.language`), else `"en-US"`.
948
+ * Only an explicit value selects the SDK's own UI words (Spanish for `es`, English otherwise). The browser language does not.
943
949
  */
944
950
  language?: string;
951
+ /**
952
+ * Your product id. When set, what the dropdown offers before anything is
953
+ * typed is read from a cacheable URL for your product, with no credential,
954
+ * instead of a suggestion request; it falls back to a suggestion request
955
+ * when it cannot be read.
956
+ */
957
+ productId?: string;
945
958
  /**
946
959
  * Stable id for this visitor, kept by the host across page loads (e.g. a
947
960
  * first-party cookie). Rides on funnel telemetry so searches can be joined
@@ -1372,6 +1385,7 @@ declare class AIAutocomplete {
1372
1385
  */
1373
1386
  private fireImpression;
1374
1387
  private fireTelemetry;
1388
+ private updateLanguageAttribute;
1375
1389
  private setupContainer;
1376
1390
  private buildAndRenderFull;
1377
1391
  private buildAndRenderDropdown;
@@ -2101,6 +2115,20 @@ interface RenderEditableArgs {
2101
2115
  */
2102
2116
  declare function renderEditableContent(args: RenderEditableArgs): void;
2103
2117
 
2118
+ declare const en: {
2119
+ language: string;
2120
+ proceed: string;
2121
+ select: string;
2122
+ skipHint: string;
2123
+ skip: string;
2124
+ skipLabel: string;
2125
+ products: string;
2126
+ soldOut: string;
2127
+ submit: string;
2128
+ scrollArrow: string;
2129
+ };
2130
+ type UIStrings = typeof en;
2131
+
2104
2132
  /**
2105
2133
  * The "more below" arrow for the options grid.
2106
2134
  *
@@ -2291,7 +2319,7 @@ declare function buildQuery(text: string, completedParams: CompletedParamState[]
2291
2319
  * Pure computation — no DOM access. Shared by the vanilla renderer and the
2292
2320
  * React / Angular footer components so the wording can't drift between them.
2293
2321
  */
2294
- declare function getFooterHint(optionHighlighted: boolean, isInputEmpty: boolean): {
2322
+ declare function getFooterHint(optionHighlighted: boolean, isInputEmpty: boolean, strings?: UIStrings): {
2295
2323
  key: string;
2296
2324
  hint: string;
2297
2325
  };
@@ -2325,14 +2353,14 @@ declare const PRODUCT_PATH_PREFIX = "/products/";
2325
2353
  * `url`: still activatable, still emitting `onProductSelect`, just nothing for
2326
2354
  * cmd-click to open.
2327
2355
  */
2328
- declare function productFromMatchedItem(item: MatchedItem): Product;
2356
+ declare function productFromMatchedItem(item: MatchedItem, language?: string): Product;
2329
2357
  /**
2330
2358
  * The strip's contents for a response's catalog report. `null` — no block on
2331
2359
  * the response — is an empty strip rather than "keep the previous one": the
2332
2360
  * previous items answered a previous query, and a strip must never show
2333
2361
  * results belonging to an older one.
2334
2362
  */
2335
- declare function productsFromCustomFields(report: CustomFieldsReport | null | undefined): Product[];
2363
+ declare function productsFromCustomFields(report: CustomFieldsReport | null | undefined, language?: string): Product[];
2336
2364
 
2337
2365
  declare class ModeController {
2338
2366
  private container;