@eldrajs/sdk 0.2.7 → 0.2.8
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 +17 -0
- package/README.md +44 -2
- package/dist/client-t66vCzJf.js +693 -0
- package/dist/index.d.ts +11 -5
- package/dist/index.js +2 -2
- 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 +1 -1
- package/dist/client-DVn7qqKo.js +0 -347
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,23 @@ platform repository.
|
|
|
9
9
|
|
|
10
10
|
## Unreleased
|
|
11
11
|
|
|
12
|
+
- **A request that answered `429` or `503` is retried instead of failing.** The gateway rate-limits a
|
|
13
|
+
client by requests per minute, which a static build of a real catalogue meets routinely. The
|
|
14
|
+
default `fetch` transport now repeats an **idempotent** request (`GET`/`HEAD`/`OPTIONS` — never a
|
|
15
|
+
`POST`, which may already have been applied), and one whose connection dropped (`fetch failed`,
|
|
16
|
+
`ECONNRESET` and the rest), honouring `Retry-After` in seconds or as an HTTP-date (up to a minute)
|
|
17
|
+
and otherwise waiting `250 ms × 2^attempt` capped at 5 s with jitter, for at most five attempts
|
|
18
|
+
including the first. Configurable as `retry: { attempts, baseDelayMs, maxDelayMs }` on
|
|
19
|
+
`createEldraClient` (`EldraRetryOptions`); `{ attempts: 0 }` is one request and no waiting. Every
|
|
20
|
+
other status is unchanged, and a consumer-supplied `httpClient` is left alone — the retry belongs
|
|
21
|
+
to the transport, and a replaced transport is the consumer's own. A caller's `AbortSignal` ends a
|
|
22
|
+
retry during the wait as well as during the request, rejecting with the signal's own reason. A
|
|
23
|
+
dropped connection is told apart from a **malformed** request by the shape `fetch` reports (a known
|
|
24
|
+
network message, or a retryable `code` on the error or its `cause`): an unparseable URL, an invalid
|
|
25
|
+
header name or a `GET` with a body fails on the first attempt, because repeating it can only fail
|
|
26
|
+
the same way. **This is a minor**: the behaviour is a repair, but `retry` is a new public option
|
|
27
|
+
and `EldraRetryOptions` a new exported type.
|
|
28
|
+
|
|
12
29
|
- `analyticsTrackerScript`'s documentation no longer says events always reach the gateway; with
|
|
13
30
|
`eventOrigin` set they go to that first-party proxy.
|
|
14
31
|
|
package/README.md
CHANGED
|
@@ -68,10 +68,52 @@ choosing `sizes`, and avoiding layout shift are in [docs/images.md](../../docs/i
|
|
|
68
68
|
| `catalog` | `listProducts`, `getProduct`, `listCategories`, `listCollections`, `getCollection`, `listCollectionProducts`, `search` |
|
|
69
69
|
| `cms` | `list`, `get`, `getEntryByUniqueField`, `resolveEntryList` |
|
|
70
70
|
| `cart` | `addItem`, `get`, `updateItem`, `removeItem`, `applyDiscount`, `removeDiscount` |
|
|
71
|
-
| `checkout` | `
|
|
71
|
+
| `checkout` | `url` |
|
|
72
72
|
| `orders` | `get`, `recover` |
|
|
73
73
|
| `inventory` | `availability` |
|
|
74
|
-
| `features` | `getOrganization`, `list`, `isEnabled`, `getCapabilities`
|
|
74
|
+
| `features` | `getOrganization`, `list`, `isEnabled`, `getCapabilities`, `getCommerce` |
|
|
75
|
+
| `platform` | `config` |
|
|
76
|
+
|
|
77
|
+
`checkout.url({ cartId, locale })` is where a storefront sends the shopper. The platform hosts the
|
|
78
|
+
checkout page, so the client asks the platform where (`platform.config()`, a public read cached per
|
|
79
|
+
client instance, sent without the organisation header because the route takes none) and returns
|
|
80
|
+
`{checkoutUrl}/checkout/{orgId}/{cartId}`. It rejects — with a different message for each cause, and
|
|
81
|
+
the read failure as `cause` where there was one — when the platform published no checkout URL, when
|
|
82
|
+
the config could not be read, and when what was published is not an absolute `http(s)` URL. A
|
|
83
|
+
storefront should treat all three as "no Check out to show" rather than something to report to a
|
|
84
|
+
shopper.
|
|
85
|
+
|
|
86
|
+
`features.getCommerce()` answers what the store sells in — `{ currency, taxInclusivePricing,
|
|
87
|
+
defaultTaxRate }` — or `null` when the organisation publishes no commerce settings, which is the
|
|
88
|
+
honest answer for a store that has not configured any: a storefront can then render a price as a
|
|
89
|
+
number rather than under a currency symbol nobody chose. It reads the same organisation document the
|
|
90
|
+
rest of the group reads, so a caller already holding an `EldraOrganizationDetails` should take
|
|
91
|
+
`commerce` off it instead of asking again.
|
|
92
|
+
|
|
93
|
+
## Retrying what the gateway refused for now
|
|
94
|
+
|
|
95
|
+
The gateway rate-limits a client by requests per minute, so a static build of a real catalogue —
|
|
96
|
+
thousands of reads from one address in a few minutes — meets that limit routinely. A `429` is not an
|
|
97
|
+
answer, and neither is a `503` while the gateway restarts or a connection the network drops, so the
|
|
98
|
+
client asks again: **idempotent requests only** (`GET`/`HEAD`/`OPTIONS` — a `POST` that timed out may
|
|
99
|
+
well have been applied), at most five attempts including the first, honouring `Retry-After` (seconds
|
|
100
|
+
or HTTP-date, up to a minute) and otherwise waiting 250 ms doubled per attempt, capped at 5 s, with
|
|
101
|
+
jitter. Every other status — a `404`, a `422`, a `401` — is returned on the first answer, as before.
|
|
102
|
+
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
|
|
103
|
+
unparseable URL, an invalid header name, a `GET` with a body — which fails on the first attempt,
|
|
104
|
+
because repeating it can only fail the same way.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
const eldra = createEldraClient({
|
|
108
|
+
orgId: 'your-organisation-id',
|
|
109
|
+
retry: { attempts: 5, baseDelayMs: 250, maxDelayMs: 5000 }, // the defaults
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// One request, no waiting:
|
|
113
|
+
createEldraClient({ orgId: 'your-organisation-id', retry: { attempts: 0 } });
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
A consumer-supplied `httpClient` replaces the transport, so the retry is that client's own.
|
|
75
117
|
|
|
76
118
|
Every failed request throws `EldraHttpError` with `status`, the problem's category `code` (such as
|
|
77
119
|
`NOT_FOUND`) and its specific `errorId` (such as `CART_NOT_FOUND`); branch on `errorId`.
|