@eldrajs/sdk 0.4.0 → 0.4.2

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/CHANGELOG.md CHANGED
@@ -9,6 +9,24 @@ platform repository.
9
9
 
10
10
  ## Unreleased
11
11
 
12
+ - **Typed product extensions (WS-439, contract 6.1.0).** `EldraProductDetails.extensions` is keyed by
13
+ the apiId of each CMS schema that extends products, and its type is the new, initially empty
14
+ `EldraProductExtensions` registry. The CMS types the Vite plugin writes now fill it in (`eldra-theme types` writes the
15
+ same augmentation, for `@eldrajs/sdk`; both ask the gateway for it with `sdkAugmentation=true`, so any other
16
+ consumer of `/cms/v1/typescript-definitions` gets plain interfaces with no `declare module`), so `product.extensions?.clothing?.material` type-checks; before generation it is
17
+ `{}`, not `unknown`. If you set the plugin's `sdkImport`, the augmentation in `cms-types.ts` names that import;
18
+ `eldra-theme types` has no such option and always targets `@eldrajs/sdk` (`--no-sdk-augmentation` leaves the block out).
19
+ Needs a gateway on contract 6.1.0 or later to return `extensions`.
20
+
21
+ - **`installIcelandicIntl()` (new entry `@eldrajs/sdk/format/intl`)** — Icelandic for code that calls
22
+ `Intl` itself (date pickers, vue-i18n, chart libraries). Where the runtime has no Icelandic data,
23
+ it patches `Intl.NumberFormat`, `Intl.DateTimeFormat`, `Number.prototype.toLocaleString` and
24
+ `Date.prototype.toLocale{,Date,Time}String` so Icelandic requests use this package's data; every
25
+ other locale stays with the runtime. Opt-in, nothing runs on import; `{ force: true }` patches
26
+ runtimes that have Icelandic too (use it on both sides of a server render), and the function the
27
+ installing call returns restores the runtime; a repeat call is a no-op. Only dates in a UTC zone
28
+ are patched; a date in another zone, the runtime's default included, stays with the runtime.
29
+
12
30
  - **Campaign attribution (WS-546, contract 5.4.0).** `captureCampaignAttribution(url?)` keeps a
13
31
  landing URL's `utm_source`, `utm_medium`, `utm_campaign` and `utm_id` (as `campaignId`, only when
14
32
  it is a uuid) in `localStorage` for 30 days, replacing an earlier landing whole; nothing else, and
package/README.md CHANGED
@@ -33,6 +33,22 @@ actually returns. Commit the folder; it is what your CI type-checks against, and
33
33
  you see the API change. Without the plugin, responses are `unknown` and you name the type at the
34
34
  call site.
35
35
 
36
+ ### Product extensions
37
+
38
+ A CMS schema flagged "extends products" attaches its fields to every product. The generated
39
+ `cms-types.ts` types them by schema apiId, so for a `clothing` schema:
40
+
41
+ ```ts
42
+ const product = await eldra.catalog.getProduct(id);
43
+ product.extensions?.clothing?.material; // string | undefined
44
+ ```
45
+
46
+ The Vite plugin (and `eldra-theme types`) request the `declare module '@eldrajs/sdk'` block with
47
+ `sdkAugmentation=true`; the endpoint omits it otherwise, so a project that does not use the SDK is never
48
+ handed a module it cannot resolve. `eldra-theme types --no-sdk-augmentation` leaves it out.
49
+
50
+ `extensions` is absent when a product has none. Without generated types it is `{}`: nothing to read.
51
+
36
52
  The full walkthrough is [docs/getting-started.md](../../docs/getting-started.md).
37
53
 
38
54
  ## Preview mode
@@ -83,6 +99,27 @@ same methods. `./format/list`, `./format/relative-time` and `./format/display-na
83
99
  Import only the entries you use; each carries its own data. The rules and what it costs are in
84
100
  [docs/icelandic-formatting.md](../../docs/icelandic-formatting.md).
85
101
 
102
+ ### Code that calls `Intl` itself
103
+
104
+ A date picker, vue-i18n's `n()`/`d()` or a chart library formats with `Intl` directly. Opt in to
105
+ Icelandic there with one call, before anything formats:
106
+
107
+ ```ts
108
+ import { installIcelandicIntl } from '@eldrajs/sdk/format/intl';
109
+
110
+ installIcelandicIntl();
111
+ ```
112
+
113
+ Where the runtime has no Icelandic, it patches `Intl.NumberFormat`, `Intl.DateTimeFormat`,
114
+ `Number.prototype.toLocaleString` and `Date.prototype.toLocale{,Date,Time}String` so a request for
115
+ Icelandic is formatted from this package's data. Every other locale goes to the runtime untouched,
116
+ so a browser on `en-GB` keeps `12/10/2026`. Where the runtime has Icelandic (Node, Safari, Firefox)
117
+ it does nothing, unless `{ force: true }`; a server render installs it with `force` on both sides so
118
+ the two match. The call that installs it returns a function that restores the runtime's `Intl`; a
119
+ later call while it is installed returns one that does nothing. Dates in a zone other than UTC, the
120
+ runtime's default included, stay with the runtime and can print in English; pass `timeZone: 'UTC'`.
121
+ Lists, relative times, names and sorting are not patched; use the functions above.
122
+
86
123
  ## What is in the client
87
124
 
88
125
  | Group | Methods |
@@ -886,8 +886,8 @@ function buildUrl(apiBaseUrl, path, query) {
886
886
  * `filter` has to be in here — a filter token is `[groupIndex:]field:op:value`
887
887
  * whose value may itself contain commas (`slug:in:a,b`), so joining several
888
888
  * tokens into one parameter runs them together and every token after the first
889
- * is lost. The catalog product filters (`categoryId`, `collectionId`, `option`
890
- * on `GET /catalog/v1/products/list` and
889
+ * is lost. The catalog product filters (`categoryId`, `collectionId`, `option`,
890
+ * `ext` on `GET /catalog/v1/products/list` and
891
891
  * `GET /catalog/v1/collections/{slug}/products`) are declared the same way, and
892
892
  * each is an OR over its values: comma-joined, `categoryId=a,b` is one id the
893
893
  * catalogue has never heard of, so a shopper ticking two categories would see
@@ -897,7 +897,8 @@ const REPEATED_QUERY_KEYS = /* @__PURE__ */ new Set([
897
897
  "filter",
898
898
  "categoryId",
899
899
  "collectionId",
900
- "option"
900
+ "option",
901
+ "ext"
901
902
  ]);
902
903
  function appendQueryValue(searchParams, key, value) {
903
904
  if (value === void 0 || value === null || value === "") return;