@eldrajs/sdk 0.2.7 → 0.2.9
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 +23 -0
- package/README.md +65 -2
- package/THIRD-PARTY-NOTICES.md +18 -0
- package/dist/client-t66vCzJf.js +693 -0
- package/dist/format/date.d.ts +4 -0
- package/dist/format/date.js +12214 -0
- package/dist/format/display-names.d.ts +4 -0
- package/dist/format/display-names.js +4905 -0
- package/dist/format/list.d.ts +4 -0
- package/dist/format/list.js +902 -0
- package/dist/format/relative-time.d.ts +4 -0
- package/dist/format/relative-time.js +1546 -0
- package/dist/format.d.ts +12 -0
- package/dist/format.js +72 -0
- package/dist/index.d.ts +11 -5
- package/dist/index.js +2 -2
- package/dist/locale-DOZdbAbY.js +4011 -0
- package/dist/number-D3Vt6TOL.js +9585 -0
- package/dist/{types-C0yabGuL.d.ts → types-B40H01uK.d.ts} +127 -10
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +1 -1
- package/package.json +32 -3
- package/dist/client-DVn7qqKo.js +0 -347
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,29 @@ platform repository.
|
|
|
9
9
|
|
|
10
10
|
## Unreleased
|
|
11
11
|
|
|
12
|
+
- **Icelandic formatting that prints the same on every runtime: `@eldrajs/sdk/format`.**
|
|
13
|
+
`numberFormat`, `formatPrice` and `comparator`/`compareIcelandic`, plus `./format/date`,
|
|
14
|
+
`./format/list`, `./format/relative-time` and `./format/display-names`. Icelandic and English come
|
|
15
|
+
from the package's own CLDR 48.2 data, so Chrome and Cloudflare Workers, which lack it, print what
|
|
16
|
+
Node and Safari do; every other locale goes to the runtime's `Intl`. Dates are UTC. No new
|
|
17
|
+
runtime dependency: the formatjs code is bundled.
|
|
18
|
+
- **A request that answered `429` or `503` is retried instead of failing.** The gateway rate-limits a
|
|
19
|
+
client by requests per minute, which a static build of a real catalogue meets routinely. The
|
|
20
|
+
default `fetch` transport now repeats an **idempotent** request (`GET`/`HEAD`/`OPTIONS` — never a
|
|
21
|
+
`POST`, which may already have been applied), and one whose connection dropped (`fetch failed`,
|
|
22
|
+
`ECONNRESET` and the rest), honouring `Retry-After` in seconds or as an HTTP-date (up to a minute)
|
|
23
|
+
and otherwise waiting `250 ms × 2^attempt` capped at 5 s with jitter, for at most five attempts
|
|
24
|
+
including the first. Configurable as `retry: { attempts, baseDelayMs, maxDelayMs }` on
|
|
25
|
+
`createEldraClient` (`EldraRetryOptions`); `{ attempts: 0 }` is one request and no waiting. Every
|
|
26
|
+
other status is unchanged, and a consumer-supplied `httpClient` is left alone — the retry belongs
|
|
27
|
+
to the transport, and a replaced transport is the consumer's own. A caller's `AbortSignal` ends a
|
|
28
|
+
retry during the wait as well as during the request, rejecting with the signal's own reason. A
|
|
29
|
+
dropped connection is told apart from a **malformed** request by the shape `fetch` reports (a known
|
|
30
|
+
network message, or a retryable `code` on the error or its `cause`): an unparseable URL, an invalid
|
|
31
|
+
header name or a `GET` with a body fails on the first attempt, because repeating it can only fail
|
|
32
|
+
the same way. **This is a minor**: the behaviour is a repair, but `retry` is a new public option
|
|
33
|
+
and `EldraRetryOptions` a new exported type.
|
|
34
|
+
|
|
12
35
|
- `analyticsTrackerScript`'s documentation no longer says events always reach the gateway; with
|
|
13
36
|
`eventOrigin` set they go to that first-party proxy.
|
|
14
37
|
|
package/README.md
CHANGED
|
@@ -61,6 +61,27 @@ const image = responsiveImage(product.thumbnail, {
|
|
|
61
61
|
parts on their own. Anything that is not an Eldra media asset comes back unchanged. The variants,
|
|
62
62
|
choosing `sizes`, and avoiding layout shift are in [docs/images.md](../../docs/images.md).
|
|
63
63
|
|
|
64
|
+
## Icelandic formatting
|
|
65
|
+
|
|
66
|
+
Chrome, Edge and Cloudflare Workers ship without Icelandic locale data, and `Intl` then prints
|
|
67
|
+
English without an error (`ISK 1,234,567` for `1.234.567 kr.`), which also breaks hydration. The
|
|
68
|
+
`./format` entries print Icelandic and English the same on every runtime:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { comparator, formatPrice, numberFormat } from '@eldrajs/sdk/format';
|
|
72
|
+
import { dateTimeFormat } from '@eldrajs/sdk/format/date';
|
|
73
|
+
|
|
74
|
+
formatPrice(12900, 'ISK', 'is-IS'); // "12.900 kr."
|
|
75
|
+
formatPrice(12900, 'ISK', 'en-US'); // "ISK 12,900"
|
|
76
|
+
dateTimeFormat('is-IS', { dateStyle: 'long' }).format(date); // "12. október 2026"
|
|
77
|
+
towns.sort(comparator('is-IS')); // Akureyri, Ísafjörður, Þórshöfn, Ölfus
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Each takes the options of the `Intl` constructor it is named after and returns an object with the
|
|
81
|
+
same methods. `./format/list`, `./format/relative-time` and `./format/display-names` cover the rest.
|
|
82
|
+
Import only the entries you use; each carries its own data. The rules and what it costs are in
|
|
83
|
+
[docs/icelandic-formatting.md](../../docs/icelandic-formatting.md).
|
|
84
|
+
|
|
64
85
|
## What is in the client
|
|
65
86
|
|
|
66
87
|
| Group | Methods |
|
|
@@ -68,10 +89,52 @@ choosing `sizes`, and avoiding layout shift are in [docs/images.md](../../docs/i
|
|
|
68
89
|
| `catalog` | `listProducts`, `getProduct`, `listCategories`, `listCollections`, `getCollection`, `listCollectionProducts`, `search` |
|
|
69
90
|
| `cms` | `list`, `get`, `getEntryByUniqueField`, `resolveEntryList` |
|
|
70
91
|
| `cart` | `addItem`, `get`, `updateItem`, `removeItem`, `applyDiscount`, `removeDiscount` |
|
|
71
|
-
| `checkout` | `
|
|
92
|
+
| `checkout` | `url` |
|
|
72
93
|
| `orders` | `get`, `recover` |
|
|
73
94
|
| `inventory` | `availability` |
|
|
74
|
-
| `features` | `getOrganization`, `list`, `isEnabled`, `getCapabilities`
|
|
95
|
+
| `features` | `getOrganization`, `list`, `isEnabled`, `getCapabilities`, `getCommerce` |
|
|
96
|
+
| `platform` | `config` |
|
|
97
|
+
|
|
98
|
+
`checkout.url({ cartId, locale })` is where a storefront sends the shopper. The platform hosts the
|
|
99
|
+
checkout page, so the client asks the platform where (`platform.config()`, a public read cached per
|
|
100
|
+
client instance, sent without the organisation header because the route takes none) and returns
|
|
101
|
+
`{checkoutUrl}/checkout/{orgId}/{cartId}`. It rejects — with a different message for each cause, and
|
|
102
|
+
the read failure as `cause` where there was one — when the platform published no checkout URL, when
|
|
103
|
+
the config could not be read, and when what was published is not an absolute `http(s)` URL. A
|
|
104
|
+
storefront should treat all three as "no Check out to show" rather than something to report to a
|
|
105
|
+
shopper.
|
|
106
|
+
|
|
107
|
+
`features.getCommerce()` answers what the store sells in — `{ currency, taxInclusivePricing,
|
|
108
|
+
defaultTaxRate }` — or `null` when the organisation publishes no commerce settings, which is the
|
|
109
|
+
honest answer for a store that has not configured any: a storefront can then render a price as a
|
|
110
|
+
number rather than under a currency symbol nobody chose. It reads the same organisation document the
|
|
111
|
+
rest of the group reads, so a caller already holding an `EldraOrganizationDetails` should take
|
|
112
|
+
`commerce` off it instead of asking again.
|
|
113
|
+
|
|
114
|
+
## Retrying what the gateway refused for now
|
|
115
|
+
|
|
116
|
+
The gateway rate-limits a client by requests per minute, so a static build of a real catalogue —
|
|
117
|
+
thousands of reads from one address in a few minutes — meets that limit routinely. A `429` is not an
|
|
118
|
+
answer, and neither is a `503` while the gateway restarts or a connection the network drops, so the
|
|
119
|
+
client asks again: **idempotent requests only** (`GET`/`HEAD`/`OPTIONS` — a `POST` that timed out may
|
|
120
|
+
well have been applied), at most five attempts including the first, honouring `Retry-After` (seconds
|
|
121
|
+
or HTTP-date, up to a minute) and otherwise waiting 250 ms doubled per attempt, capped at 5 s, with
|
|
122
|
+
jitter. Every other status — a `404`, a `422`, a `401` — is returned on the first answer, as before.
|
|
123
|
+
The caller's `AbortSignal` ends it immediately, during a wait as much as during a request. A dropped connection is told apart from a **malformed** request — an
|
|
124
|
+
unparseable URL, an invalid header name, a `GET` with a body — which fails on the first attempt,
|
|
125
|
+
because repeating it can only fail the same way.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
const eldra = createEldraClient({
|
|
129
|
+
orgId: 'your-organisation-id',
|
|
130
|
+
retry: { attempts: 5, baseDelayMs: 250, maxDelayMs: 5000 }, // the defaults
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// One request, no waiting:
|
|
134
|
+
createEldraClient({ orgId: 'your-organisation-id', retry: { attempts: 0 } });
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
A consumer-supplied `httpClient` replaces the transport, so the retry is that client's own.
|
|
75
138
|
|
|
76
139
|
Every failed request throws `EldraHttpError` with `status`, the problem's category `code` (such as
|
|
77
140
|
`NOT_FOUND`) and its specific `errorId` (such as `CART_NOT_FOUND`); branch on `errorId`.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
The `./format` entries bundle code from [formatjs](https://github.com/formatjs/formatjs) (`@formatjs/intl-numberformat`, `-datetimeformat`, `-listformat`, `-relativetimeformat`, `-displaynames`, `@formatjs/bigdecimal`, `@formatjs/intl-localematcher`, `@formatjs/fast-memoize`) and locale data derived from the Unicode CLDR. formatjs is distributed under this licence:
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2023 FormatJS
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The locale data is derived from the Unicode Common Locale Data Repository, under the
|
|
18
|
+
[Unicode License v3](https://www.unicode.org/license.txt).
|