@embark-black-book/api-contract 0.4.0 → 0.11.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 +63 -1
- package/dist/generated/api-client.d.ts +805 -218
- package/dist/generated/api-client.js +1436 -345
- package/dist/generated/api-types.d.ts +429 -289
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/strapi-image-helpers.d.ts +47 -0
- package/dist/strapi-image-helpers.js +130 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -201,6 +201,60 @@ if (decision.shouldRefresh) {
|
|
|
201
201
|
}
|
|
202
202
|
```
|
|
203
203
|
|
|
204
|
+
## Strapi Image Helpers
|
|
205
|
+
|
|
206
|
+
Use shared image utilities to pick a deterministic format and resolve relative Strapi media URLs against the API origin.
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import {
|
|
210
|
+
getBestImageUrl,
|
|
211
|
+
type ApiMedia,
|
|
212
|
+
} from "@embark-black-book/api-contract";
|
|
213
|
+
|
|
214
|
+
function getCardImage(baseUrl: string, image: ApiMedia | null | undefined) {
|
|
215
|
+
return getBestImageUrl(baseUrl, image, 640);
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Available helpers:
|
|
220
|
+
|
|
221
|
+
- `getBestImageUrl(baseUrl, image, width, height?)`
|
|
222
|
+
- `resolveStrapiAssetUrl(baseUrl, assetUrl)`
|
|
223
|
+
|
|
224
|
+
`getBestImageUrl` uses typed media formats (`StrapiImageFormats`) and deterministic known widths:
|
|
225
|
+
|
|
226
|
+
Format selection is deterministic and uses known Strapi image sizes:
|
|
227
|
+
|
|
228
|
+
- `xsmall`: `64`
|
|
229
|
+
- `small`: `500`
|
|
230
|
+
- `medium`: `750`
|
|
231
|
+
- `large`: `1000`
|
|
232
|
+
- `xlarge`: `1920`
|
|
233
|
+
|
|
234
|
+
Selection behavior:
|
|
235
|
+
|
|
236
|
+
- Uses `max(width, height ?? 0)` as the requested render size.
|
|
237
|
+
- Picks the smallest available format whose known size is greater than or equal to that requested size.
|
|
238
|
+
- Falls back to `image.url` when only smaller formats exist.
|
|
239
|
+
- Falls back to `image.url` when `formats` is missing or empty.
|
|
240
|
+
- Resolves relative URLs (for both formats and base `image.url`) against the origin derived from `baseUrl`.
|
|
241
|
+
- Passes through absolute URLs unchanged.
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
import {
|
|
245
|
+
getBestImageUrl,
|
|
246
|
+
resolveStrapiAssetUrl,
|
|
247
|
+
type ApiMedia,
|
|
248
|
+
} from "@embark-black-book/api-contract";
|
|
249
|
+
|
|
250
|
+
function buildImageUrls(baseUrl: string, image: ApiMedia | null | undefined) {
|
|
251
|
+
const cardImage = getBestImageUrl(baseUrl, image, 640, 360);
|
|
252
|
+
const baseImage = resolveStrapiAssetUrl(baseUrl, image?.url);
|
|
253
|
+
|
|
254
|
+
return { cardImage, baseImage };
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
204
258
|
## Call Endpoint Without Token
|
|
205
259
|
|
|
206
260
|
```ts
|
|
@@ -310,7 +364,15 @@ async function renameAccordionCategory(
|
|
|
310
364
|
- Run `npm --prefix package-contract run verify:publish`.
|
|
311
365
|
- Update `package-contract/CHANGELOG.md` with release notes.
|
|
312
366
|
- Bump version in `package-contract/package.json`.
|
|
313
|
-
-
|
|
367
|
+
- cd package-contract
|
|
368
|
+
- npm publish
|
|
369
|
+
|
|
370
|
+
## Update Granular Access Token
|
|
371
|
+
|
|
372
|
+
In order to publish to the private package, a granular access token is required. Tokens can only last up to 90 days. When the token expires,
|
|
373
|
+
log in at npmjs.com and generate a new similar access token. Then update the token locally as follows:
|
|
374
|
+
|
|
375
|
+
- npm config set //registry.npmjs.org/:\_authToken=NEW_TOKEN
|
|
314
376
|
|
|
315
377
|
## Output
|
|
316
378
|
|