@magicx-eng/ai-autocomplete-vanilla 0.39.0 → 0.41.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
@@ -80,7 +80,8 @@ const ac = new AIAutocomplete(container, {
80
80
  maskCompletedText: false, // when true, omits completed params' text from API requests (PII masking)
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
- language: "es", // BCP 47 tag sent with every suggestion request. Default: navigator.language, else "en-US"
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"
@@ -730,13 +731,14 @@ A discriminated union: `APIKeyConfig | AccessTokenConfig`.
730
731
  getAccessToken: async () => {
731
732
  const res = await fetch("/api/ac-token");
732
733
  const { access_token, expires_at } = await res.json();
733
- return { accessToken: access_token, expiresAt: expires_at };
734
+ // expires_at is Unix seconds; the SDK's expiresAt is Unix milliseconds.
735
+ return { accessToken: access_token, expiresAt: expires_at * 1000 };
734
736
  },
735
737
  endpoint: "https://api.ai-autocomplete.com/api/suggest", // optional, this is the default
736
738
  }
737
739
  ```
738
740
 
739
- The SDK handles token refresh transparently: if a request returns 401, it calls `getAccessToken` once, retries, and only surfaces an error if the retry also fails. Concurrent 401s share a single refresh call. Tokens are refreshed proactively 30 seconds before `expiresAt`.
741
+ The SDK handles token refresh transparently: if a request returns 401, it calls `getAccessToken` once, retries, and only surfaces an error if the retry also fails. Concurrent 401s share a single refresh call. Tokens are refreshed proactively 30 seconds before `expiresAt` (Unix milliseconds).
740
742
 
741
743
  ### `AutocompleteResult`
742
744
 
package/dist/index.d.mts CHANGED
@@ -138,6 +138,12 @@ interface AutocompleteResponse {
138
138
  request_at: string;
139
139
  /** The server's funnel-telemetry switch. Absent means off: send no funnel events. */
140
140
  funnel_telemetry?: boolean;
141
+ /**
142
+ * The server's phrase exact match switch. When true, a typed phrase that
143
+ * starts at the word the last request ended in can match an option
144
+ * exactly. Absent means off.
145
+ */
146
+ phrase_exact_match?: boolean;
141
147
  /** The request's `schema_version`, echoed back. */
142
148
  schema_version?: string;
143
149
  };
@@ -932,10 +938,18 @@ interface CoreOptions {
932
938
  */
933
939
  additionalContext?: Record<string, unknown>;
934
940
  /**
935
- * BCP 47 language tag (e.g. `"es"`), sent with every suggestion request.
941
+ * BCP 47 language tag (e.g. `"es"`), sent with every suggestion request and telemetry event.
936
942
  * Default: the browser language (`navigator.language`), else `"en-US"`.
943
+ * Only an explicit value selects the SDK's own UI words (Spanish for `es`, English otherwise). The browser language does not.
937
944
  */
938
945
  language?: string;
946
+ /**
947
+ * Your product id. When set, what the dropdown offers before anything is
948
+ * typed is read from a cacheable URL for your product, with no credential,
949
+ * instead of a suggestion request; it falls back to a suggestion request
950
+ * when it cannot be read.
951
+ */
952
+ productId?: string;
939
953
  /**
940
954
  * Stable id for this visitor, kept by the host across page loads (e.g. a
941
955
  * first-party cookie). Rides on funnel telemetry so searches can be joined
@@ -1366,6 +1380,7 @@ declare class AIAutocomplete {
1366
1380
  */
1367
1381
  private fireImpression;
1368
1382
  private fireTelemetry;
1383
+ private updateLanguageAttribute;
1369
1384
  private setupContainer;
1370
1385
  private buildAndRenderFull;
1371
1386
  private buildAndRenderDropdown;
@@ -2095,6 +2110,20 @@ interface RenderEditableArgs {
2095
2110
  */
2096
2111
  declare function renderEditableContent(args: RenderEditableArgs): void;
2097
2112
 
2113
+ declare const en: {
2114
+ language: string;
2115
+ proceed: string;
2116
+ select: string;
2117
+ skipHint: string;
2118
+ skip: string;
2119
+ skipLabel: string;
2120
+ products: string;
2121
+ soldOut: string;
2122
+ submit: string;
2123
+ scrollArrow: string;
2124
+ };
2125
+ type UIStrings = typeof en;
2126
+
2098
2127
  /**
2099
2128
  * The "more below" arrow for the options grid.
2100
2129
  *
@@ -2285,7 +2314,7 @@ declare function buildQuery(text: string, completedParams: CompletedParamState[]
2285
2314
  * Pure computation — no DOM access. Shared by the vanilla renderer and the
2286
2315
  * React / Angular footer components so the wording can't drift between them.
2287
2316
  */
2288
- declare function getFooterHint(optionHighlighted: boolean, isInputEmpty: boolean): {
2317
+ declare function getFooterHint(optionHighlighted: boolean, isInputEmpty: boolean, strings?: UIStrings): {
2289
2318
  key: string;
2290
2319
  hint: string;
2291
2320
  };
package/dist/index.d.ts CHANGED
@@ -138,6 +138,12 @@ interface AutocompleteResponse {
138
138
  request_at: string;
139
139
  /** The server's funnel-telemetry switch. Absent means off: send no funnel events. */
140
140
  funnel_telemetry?: boolean;
141
+ /**
142
+ * The server's phrase exact match switch. When true, a typed phrase that
143
+ * starts at the word the last request ended in can match an option
144
+ * exactly. Absent means off.
145
+ */
146
+ phrase_exact_match?: boolean;
141
147
  /** The request's `schema_version`, echoed back. */
142
148
  schema_version?: string;
143
149
  };
@@ -932,10 +938,18 @@ interface CoreOptions {
932
938
  */
933
939
  additionalContext?: Record<string, unknown>;
934
940
  /**
935
- * BCP 47 language tag (e.g. `"es"`), sent with every suggestion request.
941
+ * BCP 47 language tag (e.g. `"es"`), sent with every suggestion request and telemetry event.
936
942
  * Default: the browser language (`navigator.language`), else `"en-US"`.
943
+ * Only an explicit value selects the SDK's own UI words (Spanish for `es`, English otherwise). The browser language does not.
937
944
  */
938
945
  language?: string;
946
+ /**
947
+ * Your product id. When set, what the dropdown offers before anything is
948
+ * typed is read from a cacheable URL for your product, with no credential,
949
+ * instead of a suggestion request; it falls back to a suggestion request
950
+ * when it cannot be read.
951
+ */
952
+ productId?: string;
939
953
  /**
940
954
  * Stable id for this visitor, kept by the host across page loads (e.g. a
941
955
  * first-party cookie). Rides on funnel telemetry so searches can be joined
@@ -1366,6 +1380,7 @@ declare class AIAutocomplete {
1366
1380
  */
1367
1381
  private fireImpression;
1368
1382
  private fireTelemetry;
1383
+ private updateLanguageAttribute;
1369
1384
  private setupContainer;
1370
1385
  private buildAndRenderFull;
1371
1386
  private buildAndRenderDropdown;
@@ -2095,6 +2110,20 @@ interface RenderEditableArgs {
2095
2110
  */
2096
2111
  declare function renderEditableContent(args: RenderEditableArgs): void;
2097
2112
 
2113
+ declare const en: {
2114
+ language: string;
2115
+ proceed: string;
2116
+ select: string;
2117
+ skipHint: string;
2118
+ skip: string;
2119
+ skipLabel: string;
2120
+ products: string;
2121
+ soldOut: string;
2122
+ submit: string;
2123
+ scrollArrow: string;
2124
+ };
2125
+ type UIStrings = typeof en;
2126
+
2098
2127
  /**
2099
2128
  * The "more below" arrow for the options grid.
2100
2129
  *
@@ -2285,7 +2314,7 @@ declare function buildQuery(text: string, completedParams: CompletedParamState[]
2285
2314
  * Pure computation — no DOM access. Shared by the vanilla renderer and the
2286
2315
  * React / Angular footer components so the wording can't drift between them.
2287
2316
  */
2288
- declare function getFooterHint(optionHighlighted: boolean, isInputEmpty: boolean): {
2317
+ declare function getFooterHint(optionHighlighted: boolean, isInputEmpty: boolean, strings?: UIStrings): {
2289
2318
  key: string;
2290
2319
  hint: string;
2291
2320
  };