@magicx-eng/ai-autocomplete-react 0.67.4 → 0.67.6

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
@@ -159,7 +159,7 @@ A suggestion with `type: { kind: "multi_select" }` shows checkbox options and a
159
159
 
160
160
  ### Location search
161
161
 
162
- A location parameter the server sends without options gets a search field that looks up any city or address through the MagicX server. If `apiConfig.endpoint` points at a proxy with its own path, set `apiConfig.locationEndpoint` too. `locationSearch: false` takes typed text only, and an `optionOverrides` entry for the parameter replaces the search. Details: [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-react/REFERENCE.md), under "Location search".
162
+ A location parameter the server sends without options gets a search field that looks up any city or address through the location search endpoint (the hosted service's by default). If `apiConfig.endpoint` points at a proxy with its own path, set `apiConfig.locationEndpoint` too. `locationSearch: false` takes typed text only, and an `optionOverrides` entry for the parameter replaces the search. Details: [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-react/REFERENCE.md), under "Location search"; to replace every endpoint, see "Using your own server" there.
163
163
 
164
164
  ## Tier 2: Hook + Dropdown
165
165
 
@@ -329,7 +329,7 @@ The dropdown shows a row of product cards under the options whenever there are p
329
329
 
330
330
  Each response that read the catalog says which of the query's constraints it applied (`applied_filters`), which it dropped (`dropped_filters`) and how many items are left (`items.total`). Read it from `customFields` from the hook, or from `custom_fields` on `AutocompleteResult`. `null` means no catalog was read for that response. Details: [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-react/REFERENCE.md), under "The catalog report".
331
331
 
332
- When the search finds no item, `blocking_filters` names each condition whose removal finds items, with the count. The SDK greys out those chips and gives each a "×" that removes it, even with `showChipRemove` off. The chips are `blockingChips` from the hook; the opacity is the `--aia-blocking-chip-opacity` token (default `0.5`).
332
+ When the search finds no item, `blocking_filters` names each condition whose removal finds items, with the count. The SDK gives each of those chips a "×" that removes it, even with `showChipRemove` off; the chips look the same as every other chip. The chips are `blockingChips` from the hook, and each carries the class `magicx-aia-segment--blocking` for a page that wants to style them.
333
333
 
334
334
  #### Change product cards before display
335
335
 
@@ -367,6 +367,9 @@ A discriminated union: `APIKeyConfig | AccessTokenConfig`.
367
367
  | `apiKey?` | `string` | API key for Authorization header. |
368
368
  | `authScheme?` | `"Bearer" \| "Basic"` | Auth header scheme. Default: `"Bearer"`. |
369
369
  | `endpoint?` | `string` | Full URL for the suggest endpoint. Default: `"https://api.ai-autocomplete.com/api/suggest"`. |
370
+ | `locationEndpoint?` | `string` | Location search URL. Default: beside `endpoint` (`…/suggest` → `…/locations/autocomplete`). |
371
+ | `telemetryEndpoint?` | `string` | Telemetry events URL. Default: beside `endpoint` (`…/suggest` → `…/telemetry/events`). |
372
+ | `startingStateEndpoint?` | `string` | Base URL the starting state is read from (`{base}/{productId}/{language}`). Default: beside `endpoint` (`…/suggest` → `…/starting-state`). |
370
373
  | `appIdentifier?` | `string` | Value for the `X-App-Identifier` header. |
371
374
  | `headers?` | `Record<string, string>` | Additional headers merged into every request. |
372
375
 
@@ -393,6 +396,9 @@ A discriminated union: `APIKeyConfig | AccessTokenConfig`.
393
396
  | `getAccessToken` | `() => Promise<AccessTokenResult>` | **Required.** Called when the SDK needs a token. |
394
397
  | `accessToken?` | `string` | Initial token. Avoids one round-trip on mount. |
395
398
  | `endpoint?` | `string` | Suggest endpoint URL. Default: `"https://api.ai-autocomplete.com/api/suggest"`. |
399
+ | `locationEndpoint?` | `string` | Location search URL. Default: beside `endpoint` (`…/suggest` → `…/locations/autocomplete`). |
400
+ | `telemetryEndpoint?` | `string` | Telemetry events URL. Default: beside `endpoint` (`…/suggest` → `…/telemetry/events`). |
401
+ | `startingStateEndpoint?` | `string` | Base URL the starting state is read from (`{base}/{productId}/{language}`). Default: beside `endpoint` (`…/suggest` → `…/starting-state`). |
396
402
  | `appIdentifier?` | `string` | Value for the `X-App-Identifier` header. |
397
403
  | `headers?` | `Record<string, string>` | Additional headers merged into every request. |
398
404
 
@@ -575,48 +581,7 @@ On a phone or tablet, the shopper can put the keyboard away to see the whole dro
575
581
 
576
582
  ### Selector Hooks
577
583
 
578
- For styling beyond the CSS variables, target these stable `data-aia-*` attributes (CSS-module class hashes are not part of the public API):
579
-
580
- | Attribute | Element |
581
- |---|---|
582
- | `[data-aia-input-wrapper]` | Wrapper around the editor area and the submit button — one of the two roots the SDK isolates from page CSS (the dropdown is the other) |
583
- | `[data-aia-editor]` | Editor area wrapping the contentEditable + inline pill list |
584
- | `[data-aia-input]` | The Tier 1 contentEditable `<div>` that owns typed text and bold completed params. (Replaces the previous `[data-aia-textarea]` selector.) |
585
- | `[data-aia-pill-list-container]` | Inline sibling of the editor that holds unfilled-suggestion pills |
586
- | `[data-aia-submit]` | Submit button |
587
- | `[data-aia-pill]` | Each unfilled-suggestion pill |
588
- | `[data-aia-pillbar]` | Pill bar container inside the dropdown |
589
- | `[data-aia-pill-scroll]` | Scrollable pill region inside the bar — carries the horizontal scroll and right-edge fade mask |
590
- | `[data-aia-skip]` | The pill bar's "skip" button: at the header's trailing edge, or alone at the end of a skip-only row. Tune via `--aia-skip-font-size` / `--aia-skip-color` / `--aia-skip-color-hover` / `--aia-skip-hover-bg` |
591
- | `[data-aia-hint-el]` | The empty box's hint: the lead-in and the first starting options, one at a time. Tune via `--aia-hint-color` / `--aia-hint-font-weight` / `--aia-hint-icon-opacity` |
592
- | `[data-aia-option]` | Each suggestion option |
593
- | `[data-aia-scroll-arrow]` | The "more below" arrow on the dropdown — carries `data-aia-visible` while shown |
594
- | `[data-aia-dropdown]` | The dropdown root (listbox). Carries `data-aia-has-products` while the product strip has cards, and `data-aia-fit` while it is fitted to a short screen (see [Short screens](#short-screens)). |
595
- | `[data-aia-datepicker]` | The calendar, rendered in place of the option list for a date parameter |
596
- | `[data-aia-time-wheel]` | The time wheel, rendered in place of the option list for a time parameter |
597
- | `[data-aia-location]` | The location search, rendered in place of the option list for a location parameter without options (`[data-aia-location-input]` is its field, `[data-aia-location-row]` each place) |
598
- | `[data-aia-date-month]` | The "March 2026" header label |
599
- | `[data-aia-date-prev]` / `[data-aia-date-next]` | The month arrows |
600
- | `[data-aia-date-grid]` | The 7-column grid of day cells |
601
- | `[data-aia-date-cell]` | Each day cell. Also carries `[data-aia-option]`, so option-level styling applies to both bodies |
602
- | `[data-aia-products]` | Product strip section (label + row) |
603
- | `[data-aia-products-row]` | The horizontally scrolling row of cards |
604
- | `[data-aia-product]` | Each product card |
605
- | `[data-aia-product-placeholder]` | Media tile showing the placeholder pictogram (`productImageFallback: "image"`) after a missing/blank URL or load error. The existing hook is unchanged. |
606
- | `[data-aia-product-initial]` | The media tile itself when it shows the title initial (`productImageFallback: "initial"`). Decorative (`aria-hidden="true"`); target it to style the background, color, font size and border radius. |
607
-
608
- Completed params render as inline `<strong>` elements inside the editor. Override their weight with `[data-aia-input] strong { font-weight: 700; }` — a selector that names the editor wins without `!important`, while a bare `strong { … }` page rule is kept out by the isolation reset.
609
-
610
- ```css
611
- /* Solid (non-glass) dropdown */
612
- .my-autocomplete [data-aia-dropdown] {
613
- background: #fff;
614
- box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
615
- backdrop-filter: none;
616
- }
617
- ```
618
-
619
- ---
584
+ For styling beyond the CSS variables, the stable `data-aia-*` attributes to target are listed in [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-react/REFERENCE.md), under "Selector hooks".
620
585
 
621
586
  ## Sessions
622
587
 
@@ -685,4 +650,11 @@ The hook's `isLoading` is true while an answer is pending, the same flag it rais
685
650
 
686
651
  ## License
687
652
 
688
- MIT.
653
+ The SDK in this repository is licensed under the [MIT License](./LICENSE).
654
+
655
+ By default the SDK sends requests to the hosted Intent-1 service operated by
656
+ MagicX. That server call is modular: every endpoint is configurable, and the
657
+ default can be replaced with a self-hosted or third-party server (see
658
+ ["Using your own server"](./REFERENCE.md#using-your-own-server)).
659
+
660
+ The hosted Intent-1 service is a separate service, governed by MagicX's own [Terms & Conditions](https://ai-autocomplete.com/legal/terms), not by the SDK's license. The MIT license covers the SDK code only. No rights in the hosted service or in any server-side method are granted through it.
package/REFERENCE.md CHANGED
@@ -653,8 +653,8 @@ locations is the server's call: it marks them `type: { kind: "location" }`.
653
653
  - **With options** (a catalog with a `city` field, say), it is an ordinary
654
654
  option list. Nothing changes.
655
655
  - **Without options**, the dropdown shows a search field instead. Typing in it
656
- searches places through the MagicX server, which proxies a location provider,
657
- and lists what it finds; any city, address or landmark can be picked.
656
+ searches places through the location search endpoint and
657
+ lists what it finds; any city, address or landmark can be picked.
658
658
  What the user types in the main input is searched there too, cut to its
659
659
  place-name end ("going to paris" searches "paris"; "to san fran" searches
660
660
  "san fran"). Typing in the field itself takes over until it loses focus, and
@@ -818,6 +818,7 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
818
818
  | `--aia-time-font-size` | `15px` | `15px` | The time wheel's numbers and its `:` separator. |
819
819
  | `--aia-time-band-bg` | white at 8% | white at 8% | The band behind the wheels' top rows — the chosen time. |
820
820
  | `--aia-confirm-bg` | `#262626` | `#a6a6a6` | The solid fill of a checked multi-select checkbox (and, in dark mode, of the Done buttons). |
821
+ | `--aia-checkbox-border` | the option text at 65% | the option text at 65% | Border of an unticked multi-select checkbox. Defaults to the option text colour so the box stays visible when the dropdown border is faint or transparent; a ticked box uses `--aia-confirm-bg`. |
821
822
  | `--aia-confirm-bg-hover` | `#404040` | `#b8b8b8` | The Done buttons on hover in dark mode. |
822
823
  | `--aia-confirm-color` | `#ffffff` | `#000000` | The checkbox's checkmark (and, in dark mode, the Done buttons' text). |
823
824
  | `--aia-done-bg` / `--aia-done-bg-hover` / `--aia-done-color` | `#e4e8f0` / `#d8dde8` / `#2a3150` | `--aia-confirm-*` | The Done buttons (multi-select and time wheel). |
@@ -847,6 +848,51 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
847
848
 
848
849
  Legacy `--aia-color-*` variables are still supported as fallbacks.
849
850
 
851
+ ## Selector hooks
852
+
853
+ For styling beyond the CSS variables, target these stable `data-aia-*` attributes (CSS-module class hashes are not part of the public API):
854
+
855
+ | Attribute | Element |
856
+ |---|---|
857
+ | `[data-aia-input-wrapper]` | Wrapper around the editor area and the submit button — one of the two roots the SDK isolates from page CSS (the dropdown is the other) |
858
+ | `[data-aia-editor]` | Editor area wrapping the contentEditable + inline pill list |
859
+ | `[data-aia-input]` | The Tier 1 contentEditable `<div>` that owns typed text and bold completed params. (Replaces the previous `[data-aia-textarea]` selector.) |
860
+ | `[data-aia-pill-list-container]` | Inline sibling of the editor that holds unfilled-suggestion pills |
861
+ | `[data-aia-submit]` | Submit button |
862
+ | `[data-aia-pill]` | Each unfilled-suggestion pill |
863
+ | `[data-aia-pillbar]` | Pill bar container inside the dropdown |
864
+ | `[data-aia-pill-scroll]` | Scrollable pill region inside the bar — carries the horizontal scroll and right-edge fade mask |
865
+ | `[data-aia-skip]` | The pill bar's "skip" button: at the header's trailing edge, or alone at the end of a skip-only row. Tune via `--aia-skip-font-size` / `--aia-skip-color` / `--aia-skip-color-hover` / `--aia-skip-hover-bg` |
866
+ | `[data-aia-hint-el]` | The empty box's hint: the lead-in and the first starting options, one at a time. Tune via `--aia-hint-color` / `--aia-hint-font-weight` / `--aia-hint-icon-opacity` |
867
+ | `[data-aia-option]` | Each suggestion option |
868
+ | `[data-aia-scroll-arrow]` | The "more below" arrow on the dropdown — carries `data-aia-visible` while shown |
869
+ | `[data-aia-dropdown]` | The dropdown root (listbox). Carries `data-aia-has-products` while the product strip has cards, and `data-aia-fit` while it is fitted to a short screen (see [Short screens](./README.md#short-screens)). |
870
+ | `[data-aia-datepicker]` | The calendar, rendered in place of the option list for a date parameter |
871
+ | `[data-aia-time-wheel]` | The time wheel, rendered in place of the option list for a time parameter |
872
+ | `[data-aia-location]` | The location search, rendered in place of the option list for a location parameter without options (`[data-aia-location-input]` is its field, `[data-aia-location-row]` each place) |
873
+ | `[data-aia-date-month]` | The "March 2026" header label |
874
+ | `[data-aia-date-prev]` / `[data-aia-date-next]` | The month arrows |
875
+ | `[data-aia-date-grid]` | The 7-column grid of day cells |
876
+ | `[data-aia-date-cell]` | Each day cell. Also carries `[data-aia-option]`, so option-level styling applies to both bodies |
877
+ | `[data-aia-products]` | Product strip section (label + row) |
878
+ | `[data-aia-products-row]` | The horizontally scrolling row of cards |
879
+ | `[data-aia-product]` | Each product card |
880
+ | `[data-aia-product-placeholder]` | Media tile showing the placeholder pictogram (`productImageFallback: "image"`) after a missing/blank URL or load error. The existing hook is unchanged. |
881
+ | `[data-aia-product-initial]` | The media tile itself when it shows the title initial (`productImageFallback: "initial"`). Decorative (`aria-hidden="true"`); target it to style the background, color, font size and border radius. |
882
+
883
+ Completed params render as inline `<strong>` elements inside the editor. Override their weight with `[data-aia-input] strong { font-weight: 700; }` — a selector that names the editor wins without `!important`, while a bare `strong { … }` page rule is kept out by the isolation reset.
884
+
885
+ ```css
886
+ /* Solid (non-glass) dropdown */
887
+ .my-autocomplete [data-aia-dropdown] {
888
+ background: #fff;
889
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
890
+ backdrop-filter: none;
891
+ }
892
+ ```
893
+
894
+ ---
895
+
850
896
  ## Visitor id kept by the SDK
851
897
 
852
898
  Without `visitorId`, the SDK can keep the id for you. Pass `analyticsConsent` so it knows the visitor's choice: `true` (allowed), `false` (declined), or `undefined` (not answered yet). Once allowed, it keeps a UUID v4 in the first-party cookie `aia_vid` for a year, renewed on use; declined, it removes that cookie. This needs the feature to be enabled for your account, and nothing is stored without `analyticsConsent`.
@@ -877,3 +923,71 @@ onSubmit: (result) => {
877
923
  ```
878
924
 
879
925
  The id of the last search the current tab handed off (a submit or a product pick) is also kept in `sessionStorage` under `aia:last-search`, as `{ id, at }`, where `at` is when it was handed off, in milliseconds since the epoch.
926
+
927
+ ## Using your own server
928
+
929
+ By default the SDK sends its requests to the hosted Intent-1 service. Every
930
+ endpoint is replaceable through `apiConfig`, so the widget can talk to your own
931
+ server, a proxy, or a third-party service instead.
932
+
933
+ | Request | Method and URL | Option | Default |
934
+ |---|---|---|---|
935
+ | Suggestions | `POST {endpoint}` | `endpoint` | the hosted service's `…/api/suggest` |
936
+ | Starting state (only with `productId`) | `GET {base}/{productId}/{language}` | `startingStateEndpoint` (the base) | beside `endpoint`: `…/starting-state` |
937
+ | Location search | `POST {locationEndpoint}` | `locationEndpoint` | beside `endpoint`: `…/locations/autocomplete` |
938
+ | Telemetry events | `POST {telemetryEndpoint}` | `telemetryEndpoint` | beside `endpoint`: `…/telemetry/events` |
939
+
940
+ On the hosted service, the starting state is served from its CDN host
941
+ (`cdn.ai-autocomplete.com`) rather than the API host, so an allowlist for the
942
+ default setup (a Content Security Policy's `connect-src`, say) needs both.
943
+
944
+ "Beside `endpoint`" means the `/suggest` at the end of the endpoint's path is
945
+ replaced, keeping its origin, any path prefix and query
946
+ (`https://search.example.com/v1/suggest` → `https://search.example.com/v1/telemetry/events`).
947
+ When `endpoint` does not end in `/suggest` and one of the other options is not
948
+ set, that request is not sent:
949
+
950
+ - **Telemetry:** no events are sent.
951
+ - **Starting state:** it is asked for with an ordinary suggestion request (empty query) instead.
952
+ - **Location search:** the field takes typed text only.
953
+
954
+ ```tsx
955
+ <AIAutocomplete
956
+ apiConfig={{
957
+ endpoint: "https://search.example.com/v1/complete",
958
+ // Needed because the endpoint above does not end in /suggest:
959
+ telemetryEndpoint: "https://search.example.com/v1/events",
960
+ startingStateEndpoint: "https://search.example.com/v1/start",
961
+ locationEndpoint: "https://search.example.com/v1/places",
962
+ }}
963
+ />
964
+ ```
965
+
966
+ The suggestion, location search and telemetry requests carry the same
967
+ headers: `Content-Type: application/json`, your `apiConfig.headers`,
968
+ `X-App-Identifier` when `appIdentifier` is set, and an `Authorization` header
969
+ from your API key or access token. The starting-state GET carries none of
970
+ them (no custom headers and no `Authorization`), so it can be served from a
971
+ cache; as a plain GET it still sends the page's cookies to a same-origin
972
+ endpoint. With your own
973
+ endpoint, the SDK opens no connection to the hosted service's hosts, including
974
+ the image CDN it otherwise warms up; images load from whatever URLs your
975
+ responses carry.
976
+
977
+ What each request sends and expects:
978
+
979
+ - **Suggestions:** the request body is `AutocompleteRequest` and the response
980
+ `AutocompleteResponse`, both exported as types by
981
+ `@magicx-eng/ai-autocomplete-vanilla`. The response's optional `custom_fields`
982
+ block is described in [The catalog report](#the-catalog-report-customfields).
983
+ - **Starting state:** the response is the same `AutocompleteResponse`; see
984
+ [Starting state](#starting-state). `{language}` is the lowercase primary
985
+ language subtag (`es` for `es-MX`), or `zh-TW` for Traditional Chinese; the
986
+ segment is left off when the language tag has no usable subtag.
987
+ - **Location search:** the body is `{ query, session_token, language }` and the
988
+ response `{ places: [{ id, name, secondary? }] }` (the `LocationPlace` type).
989
+ A 404 turns the search off for the rest of the session; see
990
+ [Location search](#location-search).
991
+ - **Telemetry:** a fire-and-forget body of `source`, `session_id`, `type`, `at`
992
+ and `query_data`, plus `visitor_id`, `search_id`, `request_id` and
993
+ `language` when known. The response is ignored.
package/dist/index.js CHANGED
@@ -157,30 +157,6 @@
157
157
  background: var(--aia-completed-pill-bg-active, rgba(189, 189, 189, 0.35));
158
158
  }
159
159
 
160
- /* A chip whose removal finds items when the search found none (custom_fields.blocking_filters).
161
- Greyed out at half opacity. After the hover rule, so it stays greyed while pointed at. */
162
- :where(.aia-input-IW-P-) strong[class~="magicx-aia-segment--blocking"] {
163
- opacity: var(--aia-blocking-chip-opacity, 0.5);
164
- }
165
-
166
- /* The \xD7 of a greyed chip keeps its normal weight: its opacity multiplies with the chip's, so it is divided back out. */
167
- :where(.aia-input-IW-P-)
168
- strong[class~="magicx-aia-segment--blocking"]
169
- span[class~="magicx-aia-segment-remove"] {
170
- opacity: calc(var(--aia-chip-remove-opacity, 0.32) / var(--aia-blocking-chip-opacity, 0.5));
171
- }
172
-
173
- @media (hover: hover) {
174
- :where(.aia-input-IW-P-)
175
- strong[class~="magicx-aia-segment--blocking"]
176
- span[class~="magicx-aia-segment-remove"]:hover {
177
- opacity: calc(
178
- var(--aia-chip-remove-opacity-hover, 0.7) /
179
- var(--aia-blocking-chip-opacity, 0.5)
180
- );
181
- }
182
- }
183
-
184
160
  /* The picked option's icon inside a completed chip (see \`icon_svg\` on
185
161
  CompletedParamState). Inline-block, one em square and sat on the text
186
162
  baseline; the chip is one inline-block, so the icon never ends a line
@@ -3232,15 +3208,25 @@
3232
3208
  on the inner content instead (next rule). */
3233
3209
  }
3234
3210
 
3211
+ /* Each entrance keyframe also moves \`outline-offset\`, which draws nothing here
3212
+ (the content has no outline). It is there because Chrome runs an animation
3213
+ of only opacity or transform apart from normal painting, and a row whose
3214
+ entrance was still running that way when the panel's dissolve around it
3215
+ ended could stay on its first frame (transparent and 7px low) until
3216
+ something repainted it: with the pointer off the panel after a pick, an
3217
+ option stayed invisible until it was hovered. An animation that also moves
3218
+ a property Chrome paints normally runs with normal painting. */
3235
3219
  @keyframes aia-fadeIn-I8u35 {
3236
3220
  from {
3237
3221
  opacity: 0;
3222
+ outline-offset: 0.5px;
3238
3223
  }
3239
3224
  }
3240
3225
 
3241
3226
  @keyframes aia-riseIn-etXZT {
3242
3227
  from {
3243
3228
  transform: translateY(7px);
3229
+ outline-offset: 0.5px;
3244
3230
  }
3245
3231
  }
3246
3232
 
@@ -3623,7 +3609,17 @@
3623
3609
  flex: 0 0 18px;
3624
3610
  width: 18px;
3625
3611
  height: 18px;
3626
- border: 1px solid var(--aia-border);
3612
+ /* Its own border, not the dropdown's: stores often set --aia-border
3613
+ faint or transparent, which left the box visible only on hover. */
3614
+ border: 1.5px solid
3615
+ var(
3616
+ --aia-checkbox-border,
3617
+ color-mix(
3618
+ in srgb,
3619
+ var(--aia-option-color, var(--aia-color-text-default, #262626)) 65%,
3620
+ transparent
3621
+ )
3622
+ );
3627
3623
  border-radius: 6px;
3628
3624
  background: var(--aia-surface);
3629
3625
  color: transparent;