@minipim/sdk 0.5.0 → 0.7.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 +43 -1
- package/dist/index.cjs +1 -3
- package/dist/index.d.cts +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +1 -3
- package/dist/openapi.d.cts +940 -77
- package/dist/openapi.d.ts +940 -77
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -126,7 +126,11 @@ for await (const p of paginate<Product>(pim, '/v1/products', { query: { status:
|
|
|
126
126
|
const all = await collectAll<Product>(pim, '/v1/products');
|
|
127
127
|
```
|
|
128
128
|
|
|
129
|
-
`paginate` manages `limit`/`offset`, honors the server's `hasMore`, and defaults to the 200-row max page size (override with `pageSize`).
|
|
129
|
+
`paginate` manages `limit`/`offset`, honors the server's `hasMore`, and defaults to the 200-row max page size (override with `pageSize`).
|
|
130
|
+
|
|
131
|
+
`withTotal: true` is supported by **`/v1/products` only** — it adds one `COUNT(*)`, so leave it off on hot reads. Other list endpoints never return `total`, and as of v0.7.0 their types say so rather than declaring a field that was always `undefined`.
|
|
132
|
+
|
|
133
|
+
Against API **0.14.0 and newer, `hasMore` is present and exact on every list endpoint** — the server reads one row past the page, so a final page that happens to be exactly full reports `false` instead of sending you after an empty one. Older deployments omitted `hasMore` everywhere except `/v1/products`; `paginate` keeps a short-page fallback for those, which is the whole reason not to hand-roll the loop.
|
|
130
134
|
|
|
131
135
|
Endpoints that return a **plain array** instead of the envelope (`/v1/categories` without `?limit=`, `/v1/attributes`, `/v1/products/{id}/variants`) are handled too (v0.3.0+): the array is treated as the one-and-only page, so `collectAll` works uniformly across every list endpoint.
|
|
132
136
|
|
|
@@ -167,6 +171,44 @@ await pim.GET('/v1/products', {
|
|
|
167
171
|
|
|
168
172
|
Needs API **0.9.0+**. Check `GET /healthz`.
|
|
169
173
|
|
|
174
|
+
## Tags
|
|
175
|
+
|
|
176
|
+
Tags are **canonicalized on write**, so what you read back is not verbatim what you sent:
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
await pim.POST('/v1/content', { body: { /* … */ tags: ['Buying Guide', 'buying guide', 'FAQ!'] } });
|
|
180
|
+
// stored, and returned as: ['buying-guide', 'faq']
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Each tag is lower-cased, stripped of diacritics, has runs of non-alphanumerics collapsed to `-`, is trimmed of leading/trailing `-`, and is truncated to **60 characters**. Empties are dropped and duplicates removed (first occurrence wins), so **the array you get back can be shorter than the one you sent**. Note that the schema's `maxLength` is 80: two tags differing only past character 60 collapse into one.
|
|
184
|
+
|
|
185
|
+
This is deliberate — it is what makes `Featured`, `featured` and `FEATURED` one tag rather than three. Filters are canonicalized identically, so you never have to pre-slugify one:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
await pim.GET('/v1/content', { params: { query: { tag: 'Buying Guide' } } }); // matches buying-guide
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
`tag` is repeatable and ANDs: `{ tag: ['guide', 'seo'] }` returns only pages carrying both. `GET /v1/products/tags` and `GET /v1/content/tags` list the vocabulary actually in use, with counts — two **separate** vocabularies, since an editorial tag and a merchandising tag rarely mean the same thing.
|
|
192
|
+
|
|
193
|
+
Documented in the field descriptions from API **0.14.1+**, and in these types from v0.7.0.
|
|
194
|
+
|
|
195
|
+
## Uploading files
|
|
196
|
+
|
|
197
|
+
`POST /v1/media` is `multipart/form-data`, not JSON. The file field is named `file`; everything else is optional and lets you attach the upload in the same request:
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
const form = new FormData();
|
|
201
|
+
form.append('file', blob, 'sell-sheet.pdf');
|
|
202
|
+
form.append('entityType', 'product'); // 'product' | 'variant' | 'content_page'
|
|
203
|
+
form.append('entityId', productId);
|
|
204
|
+
form.append('role', 'technical'); // hero | gallery | thumbnail | technical | lifestyle | swatch
|
|
205
|
+
form.append('altText', JSON.stringify({ en_US: 'Sell sheet' })); // a JSON *string*, not an object
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
`altText` is parsed as JSON and parse failures are swallowed, so passing a real object silently stores no alt text. Send `JSON.stringify(...)`.
|
|
209
|
+
|
|
210
|
+
Requires API **0.14.0+** to appear in the spec at all — before that this endpoint published no request body, so generated clients had nothing for it.
|
|
211
|
+
|
|
170
212
|
## Attribute helpers
|
|
171
213
|
|
|
172
214
|
Attribute values are `unknown` and keyed by `(locale, channel)`. List responses return the raw `{ code: [{ locale, channel, value }] }` shape (only product *detail* with `?locale=&channel=` returns a flat `resolvedAttributes`). The SDK ships the flatten + coercion helpers so you don't reimplement them:
|
package/dist/index.cjs
CHANGED
|
@@ -80,9 +80,7 @@ async function* paginate(client, path, opts = {}) {
|
|
|
80
80
|
params: { query: { ...opts.query ?? {}, limit: pageSize, offset } }
|
|
81
81
|
});
|
|
82
82
|
if (error || !data) {
|
|
83
|
-
throw new Error(
|
|
84
|
-
`paginate ${path} failed at offset ${offset} (HTTP ${response?.status})`
|
|
85
|
-
);
|
|
83
|
+
throw new Error(`paginate ${path} failed at offset ${offset} (HTTP ${response?.status})`);
|
|
86
84
|
}
|
|
87
85
|
if (Array.isArray(data)) {
|
|
88
86
|
for (const item of data) yield item;
|
package/dist/index.d.cts
CHANGED
|
@@ -77,9 +77,18 @@ type MinipimClient = Client<paths>;
|
|
|
77
77
|
declare function createMinipimClient(opts: CreateMinipimClientOptions): MinipimClient;
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
* Generic pagination helper.
|
|
81
|
-
* `{ data, limit, offset, hasMore }
|
|
82
|
-
*
|
|
80
|
+
* Generic pagination helper. MiniPim list endpoints return
|
|
81
|
+
* `{ data, limit, offset, hasMore }`, where `hasMore` is always present and
|
|
82
|
+
* exact — the server fetches one row past the page to decide it, so a final
|
|
83
|
+
* page that is exactly full reports `false` instead of sending you after an
|
|
84
|
+
* empty one. Yields one item at a time.
|
|
85
|
+
*
|
|
86
|
+
* `hasMore` stays OPTIONAL in the type below, and the short-page fallback
|
|
87
|
+
* stays, deliberately: this client talks to whatever version the deployment is
|
|
88
|
+
* running, and API ≤ 0.13.0 omitted the field everywhere except
|
|
89
|
+
* `/v1/products`. Keeping the fallback means an older instance paginates
|
|
90
|
+
* correctly rather than reading one page and stopping — which is exactly the
|
|
91
|
+
* bug a hand-rolled `while (hasMore)` loop hit against those versions.
|
|
83
92
|
*
|
|
84
93
|
* Typed loosely on purpose — openapi-fetch's per-path generics don't
|
|
85
94
|
* compose into a single reusable signature without a lot of conditional-
|
package/dist/index.d.ts
CHANGED
|
@@ -77,9 +77,18 @@ type MinipimClient = Client<paths>;
|
|
|
77
77
|
declare function createMinipimClient(opts: CreateMinipimClientOptions): MinipimClient;
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
* Generic pagination helper.
|
|
81
|
-
* `{ data, limit, offset, hasMore }
|
|
82
|
-
*
|
|
80
|
+
* Generic pagination helper. MiniPim list endpoints return
|
|
81
|
+
* `{ data, limit, offset, hasMore }`, where `hasMore` is always present and
|
|
82
|
+
* exact — the server fetches one row past the page to decide it, so a final
|
|
83
|
+
* page that is exactly full reports `false` instead of sending you after an
|
|
84
|
+
* empty one. Yields one item at a time.
|
|
85
|
+
*
|
|
86
|
+
* `hasMore` stays OPTIONAL in the type below, and the short-page fallback
|
|
87
|
+
* stays, deliberately: this client talks to whatever version the deployment is
|
|
88
|
+
* running, and API ≤ 0.13.0 omitted the field everywhere except
|
|
89
|
+
* `/v1/products`. Keeping the fallback means an older instance paginates
|
|
90
|
+
* correctly rather than reading one page and stopping — which is exactly the
|
|
91
|
+
* bug a hand-rolled `while (hasMore)` loop hit against those versions.
|
|
83
92
|
*
|
|
84
93
|
* Typed loosely on purpose — openapi-fetch's per-path generics don't
|
|
85
94
|
* compose into a single reusable signature without a lot of conditional-
|
package/dist/index.js
CHANGED
|
@@ -28,9 +28,7 @@ async function* paginate(client, path, opts = {}) {
|
|
|
28
28
|
params: { query: { ...opts.query ?? {}, limit: pageSize, offset } }
|
|
29
29
|
});
|
|
30
30
|
if (error || !data) {
|
|
31
|
-
throw new Error(
|
|
32
|
-
`paginate ${path} failed at offset ${offset} (HTTP ${response?.status})`
|
|
33
|
-
);
|
|
31
|
+
throw new Error(`paginate ${path} failed at offset ${offset} (HTTP ${response?.status})`);
|
|
34
32
|
}
|
|
35
33
|
if (Array.isArray(data)) {
|
|
36
34
|
for (const item of data) yield item;
|