@janbox/contentful-marketplace-sdk 3.0.0 → 4.0.0-alpha.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 +42 -22
- package/dist/client/index.d.ts +5 -11
- package/dist/index.cjs +1 -2
- package/dist/index.js +492 -452
- package/dist/types/content-model.d.ts +38 -38
- package/dist/types/index.d.ts +0 -1
- package/dist/utils/errors.d.ts +2 -0
- package/dist/utils/query.d.ts +5 -6
- package/dist/utils/resolve.d.ts +11 -10
- package/package.json +3 -2
- package/dist/http-responses/index.d.ts +0 -3
- package/dist/types/cms.d.ts +0 -61
package/README.md
CHANGED
|
@@ -31,10 +31,8 @@ import {
|
|
|
31
31
|
} from "@janbox/contentful-marketplace-sdk";
|
|
32
32
|
|
|
33
33
|
ContentfulSDK.configure({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Authorization: `Bearer ${process.env.CMS_DELIVERY_TOKEN}`,
|
|
37
|
-
},
|
|
34
|
+
baseUrl: "https://headless-cms.ichiba.net/delivery/janbox",
|
|
35
|
+
accessToken: process.env.CMS_DELIVERY_TOKEN,
|
|
38
36
|
});
|
|
39
37
|
|
|
40
38
|
const result = await getBannerCollections({
|
|
@@ -53,35 +51,48 @@ console.log(result.items);
|
|
|
53
51
|
|
|
54
52
|
### `ContentfulSDK.configure(params)`
|
|
55
53
|
|
|
56
|
-
Configure the SDK once before calling entry methods.
|
|
54
|
+
Configure the SDK once before calling entry methods. `params` is the `ClientConfig` of [`@janbox/headless-cms-sdk`](https://www.npmjs.com/package/@janbox/headless-cms-sdk):
|
|
57
55
|
|
|
58
|
-
| Parameter
|
|
59
|
-
|
|
60
|
-
| `
|
|
61
|
-
| `
|
|
62
|
-
| `headers`
|
|
56
|
+
| Parameter | Type | Required | Description |
|
|
57
|
+
|---------------|--------------------------|----------|-------------|
|
|
58
|
+
| `baseUrl` | `string` | ✅ | Delivery API base URL, e.g. `https://headless-cms.ichiba.net/delivery/janbox`. A trailing `/` is removed. |
|
|
59
|
+
| `accessToken` | `string` | — | Delivery key, sent as `Authorization: Bearer <accessToken>` |
|
|
60
|
+
| `headers` | `Record<string, string>` | — | Extra headers for every request. They override `accessToken` (header names are case-insensitive). |
|
|
61
|
+
| `fetch` | `typeof fetch` | — | Custom `fetch`, e.g. to log or trace requests. Defaults to `globalThis.fetch`. |
|
|
62
|
+
| `timeout` | `number` | — | Timeout per attempt in ms. Default `30000`; `0` disables it |
|
|
63
|
+
| `retry` | `{ maxRetries?: number; maxDelay?: number } \| false` | — | Retry on HTTP 429. Default `{ maxRetries: 3, maxDelay: 10000 }`; `false` disables it |
|
|
63
64
|
|
|
64
65
|
```ts
|
|
65
66
|
ContentfulSDK.configure({
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
Authorization: "Bearer cdel_your-delivery-key",
|
|
69
|
-
},
|
|
67
|
+
baseUrl: "https://test-headless-cms.ichiba.net/delivery/janbox", // QC
|
|
68
|
+
accessToken: "cdel_your-delivery-key",
|
|
70
69
|
});
|
|
71
70
|
```
|
|
72
71
|
|
|
73
72
|
Notes:
|
|
74
73
|
|
|
75
|
-
- The SDK sends `GET {
|
|
74
|
+
- The SDK sends `GET {baseUrl}/entries?...` with `Accept: application/json`.
|
|
75
|
+
- The client is built from the config on first use and rebuilt whenever `baseUrl`, `accessToken`, `headers`, `fetch`, `timeout` or `retry` changes, so calling `configure` again or assigning `ContentfulSDK.config.accessToken` applies to the next request.
|
|
76
|
+
- For queries the entry functions do not cover, use the SDK client directly: `ContentfulSDK.client.getEntries(query, { resolveLinks: false })`.
|
|
76
77
|
- Keep the delivery key server-side: call the SDK from your server (route handler, BFF), never from browser JavaScript.
|
|
77
|
-
- Runtime requires `fetch` (Node.js 18+
|
|
78
|
+
- Runtime requires `fetch` (Node.js 18+).
|
|
79
|
+
|
|
80
|
+
## Breaking changes in 4.0.0
|
|
81
|
+
|
|
82
|
+
Compared with 3.0.0 (3.1.0 was only released as `3.1.0-alpha.0`):
|
|
83
|
+
|
|
84
|
+
1. `ContentfulSDK.configure` takes the `ClientConfig` of `@janbox/headless-cms-sdk`: `url` is renamed to `baseUrl`, `method` is removed, and the token can be passed as `accessToken` (or as `headers.Authorization`, as before). `fetch`, `timeout` and `retry` are new.
|
|
85
|
+
2. `ContentfulSDK.getEntries` is removed. Use `ContentfulSDK.client.getEntries(query, { resolveLinks: false })` instead.
|
|
86
|
+
3. Every error is a `CmsError` from `@janbox/headless-cms-sdk`. When an entry is not found, the functions throw a `CmsError` with `id: "NotFound"` and `status: 404` instead of `NotFoundResponse`. Check errors with `isCmsError` from `@janbox/headless-cms-sdk` (add it to your app's dependencies).
|
|
87
|
+
4. `CmsEntry`, `CmsAsset`, `CmsLink` and `CmsCollection` are removed. Use `Entry`, `Asset`, `Link` and `RawEntryCollection` from `@janbox/headless-cms-sdk`. Link fields in `TypeXxxFields` are now `Link<"Entry">` / `Link<"Asset">`.
|
|
88
|
+
5. A 30-second timeout per attempt and retries on HTTP 429 are on by default. Set `timeout: 0` or `retry: false` to turn them off.
|
|
78
89
|
|
|
79
90
|
## Breaking changes in 3.0.0
|
|
80
91
|
|
|
81
92
|
1. `url` is now the Delivery API base URL of the internal CMS, and `headers` carries the delivery key (`Authorization: Bearer cdel_...`). `method` is still accepted but ignored.
|
|
82
93
|
2. The delivery key must stay on the server, so the SDK must be called server-side.
|
|
83
94
|
3. Types built on the `contentful` package are removed: `TypeXxxSkeleton`, the generic `TypeXxx<Modifiers, Locales>` types, and the `DocArticleEntry`, `DocCategoryEntry` and `HyperlinkEntry` aliases. `TypeXxxFields` are kept as plain interfaces.
|
|
84
|
-
4. Entry ids are the new CMS ids (GUIDs). Old Contentful ids must be migrated by the apps: the CMS rejects them with `400 InvalidQuery`, which the SDK throws as `Error("Request failed: 400 ...")
|
|
95
|
+
4. Entry ids are the new CMS ids (GUIDs). Old Contentful ids must be migrated by the apps: the CMS rejects them with `400 InvalidQuery`, which the SDK throws as `Error("Request failed: 400 ...")` (a `CmsError` with `id: "InvalidQuery"` since 4.0.0).
|
|
85
96
|
|
|
86
97
|
## API Methods
|
|
87
98
|
|
|
@@ -226,21 +237,28 @@ Filters `marketCode` / `locale` with global fallback (entries where `markets` /
|
|
|
226
237
|
|
|
227
238
|
## Error Handling
|
|
228
239
|
|
|
229
|
-
`
|
|
240
|
+
Every error from the CMS is a `CmsError` of `@janbox/headless-cms-sdk` (`id`, `status`, `requestId`, `details`, `url`). The SDK README lists the `id` values.
|
|
230
241
|
|
|
231
|
-
- `
|
|
232
|
-
- `
|
|
242
|
+
- The detail functions (`getBlogPostDetail`, `getBlogCategoryDetail`, `getDocCategoryDetail`, `getDocArticleDetail`), `getPolicyAndTerms` and `getBlogPosts({ collectionId })` throw a `CmsError` with `id: "NotFound"`, `status: 404` and `message: "Entry not found"` when no entry matches.
|
|
243
|
+
- The detail functions throw `Error("Either id or slug is required.")` if neither `id` nor `slug` is provided.
|
|
244
|
+
- Calling a function before `configure` throws `Error("Client is not configured")`.
|
|
233
245
|
|
|
234
246
|
```ts
|
|
247
|
+
import { isCmsError } from "@janbox/headless-cms-sdk";
|
|
248
|
+
|
|
235
249
|
try {
|
|
236
250
|
await getDocArticleDetail({ slug: "unknown-slug" });
|
|
237
251
|
} catch (error) {
|
|
238
|
-
if (error
|
|
252
|
+
if (isCmsError(error) && error.id === "NotFound") {
|
|
239
253
|
console.log("Entry not found");
|
|
254
|
+
} else {
|
|
255
|
+
throw error;
|
|
240
256
|
}
|
|
241
257
|
}
|
|
242
258
|
```
|
|
243
259
|
|
|
260
|
+
The SDK also throws `NotFound` (404) when the CMS answers 404 for the whole endpoint, for example with a wrong `baseUrl`. If you need to tell the two apart, the error thrown by this package has `message === "Entry not found"`.
|
|
261
|
+
|
|
244
262
|
## Market/Language Filtering Behavior
|
|
245
263
|
|
|
246
264
|
When `marketCode` or `language` is provided, queries include both:
|
|
@@ -255,9 +273,11 @@ This supports global fallback content.
|
|
|
255
273
|
The package exports:
|
|
256
274
|
|
|
257
275
|
- client and entry functions from `src/client` and `src/entries`
|
|
258
|
-
- content model field types (`TypeXxxFields`)
|
|
276
|
+
- content model field types (`TypeXxxFields`) from `src/types`
|
|
259
277
|
- response item types such as `BlogPostGraphQLItem` and `DocArticleGraphQLItem` (names kept from 2.x)
|
|
260
278
|
|
|
279
|
+
CMS data, query, config and error types (`Entry`, `Asset`, `Link`, `RawEntryCollection`, `EntriesQuery`, `ClientConfig`, `CmsClient`, `CmsError`) come from `@janbox/headless-cms-sdk`; this package does not re-export them.
|
|
280
|
+
|
|
261
281
|
## Development
|
|
262
282
|
|
|
263
283
|
From repository root:
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { QueryParams } from '../utils/query';
|
|
3
|
-
export interface ContentfulSDKConfig {
|
|
4
|
-
url: string;
|
|
5
|
-
/** @deprecated Ignored: requests are always GET. Kept so existing configs still type-check. */
|
|
6
|
-
method?: string;
|
|
7
|
-
headers?: Record<string, string>;
|
|
8
|
-
}
|
|
1
|
+
import { ClientConfig, CmsClient } from '@janbox/headless-cms-sdk';
|
|
9
2
|
export declare class ContentfulSDK {
|
|
10
3
|
private static _config;
|
|
11
|
-
static
|
|
12
|
-
static
|
|
13
|
-
static
|
|
4
|
+
private static _client;
|
|
5
|
+
static get config(): ClientConfig;
|
|
6
|
+
static get client(): CmsClient;
|
|
7
|
+
static configure(config: ClientConfig): void;
|
|
14
8
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m="-sys.updatedAt",g=e=>e?{"or.market.0.fields.markets[exists]":"false","or.market.1.fields.markets.sys.contentType.sys.id":"market","or.market.1.fields.markets.fields.code":e}:{},p=e=>e?{"or.locale.0.fields.locale[exists]":"false","or.locale.1.fields.locale":e}:{},A=({id:e,slug:t})=>{if(e)return{"sys.id":e,limit:1};if(t)return{"fields.slug":t,limit:1};throw new Error("Either id or slug is required.")},w=(e,t,i=0)=>{const o=Math.max(1,Math.floor(e)),s=Math.max(1,Math.floor(t)),l=Math.max(0,Math.floor(i));return{page:o,size:s,params:{limit:s,skip:(o-1)*s+l}}},N=e=>{const t=new URLSearchParams;for(const[i,o]of Object.entries(e))o!==void 0&&t.append(i,String(o));return t};class c{static _config;static get config(){if(!this._config)throw new Error("Client is not configured");return this._config}static configure(t){this._config=t}static async getEntries(t){const{url:i,headers:o={}}=this.config,s=await fetch(`${i.replace(/\/+$/,"")}/entries?${N(t)}`,{method:"GET",headers:{Accept:"application/json",...o}});if(!s.ok){const l=await s.text();throw new Error(`Request failed: ${s.status} ${s.statusText}
|
|
2
|
-
${l}`)}return s.json()}}class h{page;total;size;items;totalPages;constructor({page:t,total:i,size:o,items:s}){this.page=t,this.total=i,this.size=o,this.items=s,this.totalPages=Math.ceil(this.total/this.size)}}const f=e=>{const t=new Map,i=new Map;for(const s of[...e.items,...e.includes?.Entry??[]])t.set(s.sys.id,s);for(const s of e.includes?.Asset??[])i.set(s.sys.id,s);const o=s=>(s&&t.get(s.sys.id))??null;return{entry:o,asset:s=>(s&&i.get(s.sys.id))??null,entries:s=>(s??[]).map(l=>o(l)).filter(l=>l!==null)}},n=e=>e??null,E=e=>{const t=e?.fields.file;return t?{url:t.url,width:t.details.image?.width??null,height:t.details.image?.height??null,contentType:t.contentType}:null},G=e=>({sys:{id:e.sys.id},url:e.fields.file?.url,width:e.fields.file?.details.image?.width??null,height:e.fields.file?.details.image?.height??null,contentType:e.fields.file?.contentType,title:n(e.fields.title),description:n(e.fields.description)}),R=(e,t)=>{if(!e||typeof e!="object")return t;const i=e;if(i.nodeType==="embedded-asset-block"){const o=i.data?.target?.sys?.id;o&&!t.includes(o)&&t.push(o)}for(const o of i.content??[])R(o,t);return t},b=(e,t)=>{if(!e)return null;const i=R(e,[]).map(o=>t.asset({sys:{type:"Link",linkType:"Asset",id:o}})).filter(o=>o!==null&&!!o.fields.file).map(G);return{json:e,links:{assets:{block:i}}}},z=e=>e?{metaTitle:n(e.fields.metaTitle),metaDescription:n(e.fields.metaDescription),metaKeywords:n(e.fields.metaKeywords),metaRobots:n(e.fields.metaRobots)}:null,B=e=>e?{sys:{id:e.sys.id},label:n(e.fields.label),url:n(e.fields.url),target:n(e.fields.target),marketHandling:n(e.fields.marketHandling)}:null,S=(e,t)=>e?{name:n(e.fields.name),avatar:E(t.asset(e.fields.avatar))}:null,q=async({slot:e,page:t=1,size:i=20,platform:o,marketCode:s,locale:l})=>{const d=w(t,i),a=await c.getEntries({content_type:"bannerCollection","fields.slot":e,"fields.platform":o||void 0,select:"sys.id,fields.name,fields.slot,fields.platform,fields.banners",include:2,order:m,...d.params,...g(s),...p(l)}),r=f(a);return new h({page:d.page,total:a.total,size:d.size,items:a.items.map(u=>({sys:{id:u.sys.id},name:n(u.fields.name),slot:n(u.fields.slot),platform:n(u.fields.platform),bannersCollection:{items:r.entries(u.fields.banners).map(C=>({sys:{id:C.sys.id},name:n(C.fields.name),hyperlink:B(r.entry(C.fields.hyperlink)),media:E(r.asset(C.fields.media))}))}}))})};class k extends Response{constructor(...t){super(t[0]??"Not Found",{status:404,...t[1]})}}const _="sys.id,sys.createdAt,sys.updatedAt,fields.title,fields.shortDescription,fields.slug,fields.categories,fields.featuredImage",I=(e,t)=>({sys:{id:e.sys.id,createdAt:e.sys.createdAt,updatedAt:e.sys.updatedAt},title:n(e.fields.title),shortDescription:n(e.fields.shortDescription),slug:n(e.fields.slug),categoriesCollection:{items:t.entries(e.fields.categories).map(i=>({sys:{id:i.sys.id},title:n(i.fields.title),slug:n(i.fields.slug),featuredImage:E(t.asset(i.fields.featuredImage))}))},featuredImage:E(t.asset(e.fields.featuredImage))}),U=async({marketCode:e,locale:t,collectionId:i,categoryId:o,page:s=1,size:l=20,skip:d=0}={})=>{const a=w(s,l,d);if(i){const P=(await c.getEntries({content_type:"blogCollection","sys.id":i,select:"sys.id,fields.posts",include:0,limit:1})).items.at(0);if(!P)throw new k;const D=(P.fields.posts??[]).filter(y=>y.sys.linkType==="Entry").map(y=>y.sys.id),T=D.slice(a.params.skip,a.params.skip+a.size);if(!T.length)return new h({page:a.page,total:D.length,size:a.size,items:[]});const v=await c.getEntries({content_type:"blogPost","sys.id[in]":T.join(","),select:_,include:2,limit:a.size}),K=f(v),H=new Map(v.items.map(y=>[y.sys.id,y]));return new h({page:a.page,total:D.length,size:a.size,items:T.map(y=>H.get(y)).filter(y=>y!==void 0).map(y=>I(y,K))})}const r=await c.getEntries({content_type:"blogPost","fields.categories.sys.id":o||void 0,select:_,include:2,order:m,...a.params,...g(e),...p(t)}),u=f(r);return new h({page:a.page,total:r.total,size:a.size,items:r.items.map(C=>I(C,u))})},Y=async({id:e,slug:t,marketCode:i,locale:o})=>{const s=A({id:e,slug:t}),l=await c.getEntries({content_type:"blogPost",...s,select:`${_},fields.author,fields.content,fields.seo`,include:2,order:m,...g(i),...p(o)}),d=l.items.at(0);if(!d)throw new k;const a=f(l);return{...I(d,a),author:S(a.entry(d.fields.author),a),content:b(d.fields.content,a),seo:z(a.entry(d.fields.seo))}},x="sys.id,fields.title,fields.slug,fields.featuredImage",L=(e,t)=>({sys:{id:e.sys.id},title:n(e.fields.title),slug:n(e.fields.slug),featuredImage:E(t.asset(e.fields.featuredImage))}),J=async({marketCode:e,locale:t,page:i=1,size:o=20}={})=>{const s=w(i,o),l=await c.getEntries({content_type:"blogCategory",select:x,include:1,order:m,...s.params,...g(e),...p(t)}),d=f(l);return new h({page:s.page,total:l.total,size:s.size,items:l.items.map(a=>L(a,d))})},Q=async({id:e,slug:t,marketCode:i,locale:o})=>{const s=A({id:e,slug:t}),l=await c.getEntries({content_type:"blogCategory",...s,select:`${x},fields.description,fields.seo`,include:1,order:m,...g(i),...p(o)}),d=l.items.at(0);if(!d)throw new k;const a=f(l);return{...L(d,a),description:n(d.fields.description),seo:z(a.entry(d.fields.seo))}},V=async({marketCode:e,locale:t,page:i=1,size:o=20}={})=>{const s=w(i,o),l=await c.getEntries({content_type:"blogCollection",select:"sys.id,fields.name,fields.type,fields.order,fields.category,fields.featuredImage",include:1,order:m,...s.params,...g(e),...p(t)}),d=f(l),a=l.items.map(r=>{const u=d.entry(r.fields.category);return{name:n(r.fields.name),type:n(r.fields.type),order:n(r.fields.order),sys:{id:r.sys.id},category:u?{sys:{id:u.sys.id},title:n(u.fields.title),slug:n(u.fields.slug)}:null,featuredImage:E(d.asset(r.fields.featuredImage))}});return new h({page:s.page,total:l.total,size:s.size,items:a.map(r=>({...r,category:r.type==="category"?r.category:null,categoryId:r.type==="category"?r.category?.sys.id??null:null,collectionId:r.type==="manual"?r.sys.id:null}))})},W=async({page:e=1,size:t=20,marketCode:i,locale:o}={})=>{const s=w(e,t),l=await c.getEntries({content_type:"brandCollection",select:"sys.id,fields.name,fields.slot,fields.brands",include:2,order:m,...s.params,...g(i),...p(o)}),d=f(l);return new h({page:s.page,total:l.total,size:s.size,items:l.items.map(a=>({sys:{id:a.sys.id},name:n(a.fields.name),slot:n(a.fields.slot),brandsCollection:{items:d.entries(a.fields.brands).map(r=>({sys:{id:r.sys.id},name:n(r.fields.name),logo:E(d.asset(r.fields.logo)),hyperlink:B(d.entry(r.fields.hyperlink))}))}}))})},M="sys.id,sys.createdAt,sys.updatedAt,fields.title,fields.slug,fields.description,fields.order,fields.seo",$="sys.id,sys.createdAt,sys.updatedAt,fields.title,fields.slug,fields.author,fields.category",O=e=>({id:e.sys.id,createdAt:e.sys.createdAt,updatedAt:e.sys.updatedAt}),j=(e,t)=>({sys:O(e),title:n(e.fields.title),slug:n(e.fields.slug),description:n(e.fields.description),order:n(e.fields.order),seo:z(t.entry(e.fields.seo))}),F=(e,t)=>{const i=t.entry(e.fields.category);return{sys:O(e),title:n(e.fields.title),slug:n(e.fields.slug),author:S(t.entry(e.fields.author),t),category:i?{title:n(i.fields.title),slug:n(i.fields.slug),description:n(i.fields.description),order:n(i.fields.order)}:null}},X=async({marketCode:e,locale:t,page:i=1,size:o=20}={})=>{const s=w(i,o),l=await c.getEntries({content_type:"documentationCategory",select:M,include:1,order:m,...s.params,...g(e),...p(t)}),d=f(l);return new h({page:s.page,total:l.total,size:s.size,items:l.items.map(a=>j(a,d))})},Z=async({id:e,slug:t,marketCode:i,locale:o})=>{const s=A({id:e,slug:t}),l=await c.getEntries({content_type:"documentationCategory",...s,select:M,include:1,order:m,...g(i),...p(o)}),d=l.items.at(0);if(!d)throw new k;return j(d,f(l))},ee=async({marketCode:e,locale:t,categorySlug:i,page:o=1,size:s=20}={})=>{const l=w(o,s),d=await c.getEntries({content_type:"documentationArticle",...i?{"fields.category.sys.contentType.sys.id":"documentationCategory","fields.category.fields.slug":i}:{},select:$,include:2,order:m,...l.params,...g(e),...p(t)}),a=f(d);return new h({page:l.page,total:d.total,size:l.size,items:d.items.map(r=>F(r,a))})},te=async({id:e,slug:t,marketCode:i,locale:o})=>{const s=A({id:e,slug:t}),l=await c.getEntries({content_type:"documentationArticle",...s,select:`${$},fields.content,fields.seo`,include:2,order:m,...g(i),...p(o)}),d=l.items.at(0);if(!d)throw new k;const a=f(l);return{...F(d,a),content:b(d.fields.content,a),seo:z(a.entry(d.fields.seo))}},se=async({page:e=1,size:t=20,marketCode:i,locale:o}={})=>{const s=w(e,t),l=await c.getEntries({content_type:"hyperlinkCollection",select:"sys.id,fields.name,fields.slot,fields.order,fields.links",include:1,order:"fields.order",...s.params,...g(i),...p(o)}),d=f(l);return new h({page:s.page,total:l.total,size:s.size,items:l.items.map(a=>({sys:{id:a.sys.id},name:n(a.fields.name),slot:n(a.fields.slot),order:n(a.fields.order),linksCollection:{items:d.entries(a.fields.links).map(r=>B(r))}}))})},ie=async({page:e=1,size:t=20,marketCode:i,locale:o}={})=>{const s=w(e,t),l=await c.getEntries({content_type:"keywordCollection",select:"sys.id,fields.name,fields.slot,fields.keywords",include:0,order:m,...s.params,...g(i),...p(o)});return new h({page:s.page,total:l.total,size:s.size,items:l.items.map(d=>({sys:{id:d.sys.id},name:n(d.fields.name),slot:n(d.fields.slot),keywords:n(d.fields.keywords)}))})},oe=async({marketCode:e,locale:t}={})=>{const i=await c.getEntries({content_type:"policyAndTerms",select:"sys.id,fields.title,fields.locale,fields.content",include:1,order:m,limit:1,...g(e),...p(t)}),o=i.items.at(0);if(!o)throw new k;return{sys:{id:o.sys.id},title:n(o.fields.title),locale:n(o.fields.locale),content:b(o.fields.content,f(i))}};exports.ContentfulSDK=c;exports.PaginatedResponse=h;exports.getBannerCollections=q;exports.getBlogCategories=J;exports.getBlogCategoryDetail=Q;exports.getBlogCollections=V;exports.getBlogPostDetail=Y;exports.getBlogPosts=U;exports.getBrandCollections=W;exports.getDocArticleDetail=te;exports.getDocArticles=ee;exports.getDocCategories=X;exports.getDocCategoryDetail=Z;exports.getHyperlinkCollections=se;exports.getKeywordCollections=ie;exports.getPolicyAndTerms=oe;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("@janbox/headless-cms-sdk"),U=["baseUrl","accessToken","headers","fetch","timeout","retry"];class d{static _config;static _client;static get config(){if(!this._config)throw new Error("Client is not configured");return this._config}static get client(){const t=this.config,i=this._client;if(i&&U.every(s=>i.builtFrom[s]===t[s]))return i.client;const l=A.createClient(t);return this._client={client:l,builtFrom:{...t}},l}static configure(t){this._config=t}}class h{page;total;size;items;totalPages;constructor({page:t,total:i,size:l,items:s}){this.page=t,this.total=i,this.size=l,this.items=s,this.totalPages=Math.ceil(this.total/this.size)}}const m="-sys.updatedAt",g=e=>e?A.or("market",[{"fields.markets[exists]":"false"},{"fields.markets.sys.contentType.sys.id":"market","fields.markets.fields.code":e}]):{},p=e=>e?A.or("locale",[{"fields.locale[exists]":"false"},{"fields.locale":e}]):{},v=({id:e,slug:t})=>{if(e)return{"sys.id":e,limit:1};if(t)return{"fields.slug":t,limit:1};throw new Error("Either id or slug is required.")},w=(e,t,i=0)=>{const l=Math.max(1,Math.floor(e)),s=Math.max(1,Math.floor(t)),n=Math.max(0,Math.floor(i));return{page:l,size:s,params:{limit:s,skip:(l-1)*s+n}}},f=e=>{const t=new Map,i=new Map;for(const s of[...e.items,...e.includes?.Entry??[]])t.set(s.sys.id,s);for(const s of e.includes?.Asset??[])i.set(s.sys.id,s);const l=s=>(s&&t.get(s.sys.id))??null;return{entry:l,asset:s=>(s&&i.get(s.sys.id))??null,entries:s=>(s??[]).map(n=>l(n)).filter(n=>n!==null)}},o=e=>e??null,k=e=>{const t=e?.fields.file;return t?{url:t.url,width:t.details.image?.width??null,height:t.details.image?.height??null,contentType:t.contentType}:null},q=e=>({sys:{id:e.sys.id},url:e.fields.file?.url,width:e.fields.file?.details.image?.width??null,height:e.fields.file?.details.image?.height??null,contentType:e.fields.file?.contentType,title:o(e.fields.title),description:o(e.fields.description)}),S=(e,t)=>{if(!e||typeof e!="object")return t;const i=e;if(i.nodeType==="embedded-asset-block"){const l=i.data?.target?.sys?.id;l&&!t.includes(l)&&t.push(l)}for(const l of i.content??[])S(l,t);return t},T=(e,t)=>{if(!e)return null;const i=S(e,[]).map(l=>t.asset({sys:{type:"Link",linkType:"Asset",id:l}})).filter(l=>l!==null&&!!l.fields.file).map(q);return{json:e,links:{assets:{block:i}}}},z=e=>e?{metaTitle:o(e.fields.metaTitle),metaDescription:o(e.fields.metaDescription),metaKeywords:o(e.fields.metaKeywords),metaRobots:o(e.fields.metaRobots)}:null,b=e=>e?{sys:{id:e.sys.id},label:o(e.fields.label),url:o(e.fields.url),target:o(e.fields.target),marketHandling:o(e.fields.marketHandling)}:null,R=(e,t)=>e?{name:o(e.fields.name),avatar:k(t.asset(e.fields.avatar))}:null,G=async({slot:e,page:t=1,size:i=20,platform:l,marketCode:s,locale:n})=>{const c=w(t,i),a=await d.client.getEntries({content_type:"bannerCollection","fields.slot":e,"fields.platform":l||void 0,select:"sys.id,fields.name,fields.slot,fields.platform,fields.banners",include:2,order:m,...c.params,...g(s),...p(n)},{resolveLinks:!1}),r=f(a);return new h({page:c.page,total:a.total,size:c.size,items:a.items.map(u=>({sys:{id:u.sys.id},name:o(u.fields.name),slot:o(u.fields.slot),platform:o(u.fields.platform),bannersCollection:{items:r.entries(u.fields.banners).map(C=>({sys:{id:C.sys.id},name:o(C.fields.name),hyperlink:b(r.entry(C.fields.hyperlink)),media:k(r.asset(C.fields.media))}))}}))})},E=()=>new A.CmsError({id:"NotFound",message:"Entry not found",url:`${d.config.baseUrl.trim().replace(/\/+$/,"")}/entries`,status:404}),I="sys.id,sys.createdAt,sys.updatedAt,fields.title,fields.shortDescription,fields.slug,fields.categories,fields.featuredImage",L=(e,t)=>({sys:{id:e.sys.id,createdAt:e.sys.createdAt,updatedAt:e.sys.updatedAt},title:o(e.fields.title),shortDescription:o(e.fields.shortDescription),slug:o(e.fields.slug),categoriesCollection:{items:t.entries(e.fields.categories).map(i=>({sys:{id:i.sys.id},title:o(i.fields.title),slug:o(i.fields.slug),featuredImage:k(t.asset(i.fields.featuredImage))}))},featuredImage:k(t.asset(e.fields.featuredImage))}),Y=async({marketCode:e,locale:t,collectionId:i,categoryId:l,page:s=1,size:n=20,skip:c=0}={})=>{const a=w(s,n,c);if(i){const B=(await d.client.getEntries({content_type:"blogCollection","sys.id":i,select:"sys.id,fields.posts",include:0,limit:1},{resolveLinks:!1})).items.at(0);if(!B)throw E();const _=(B.fields.posts??[]).filter(y=>y.sys.linkType==="Entry").map(y=>y.sys.id),D=_.slice(a.params.skip,a.params.skip+a.size);if(!D.length)return new h({page:a.page,total:_.length,size:a.size,items:[]});const P=await d.client.getEntries({content_type:"blogPost","sys.id[in]":D.join(","),select:I,include:2,limit:a.size},{resolveLinks:!1}),j=f(P),N=new Map(P.items.map(y=>[y.sys.id,y]));return new h({page:a.page,total:_.length,size:a.size,items:D.map(y=>N.get(y)).filter(y=>y!==void 0).map(y=>L(y,j))})}const r=await d.client.getEntries({content_type:"blogPost","fields.categories.sys.id":l||void 0,select:I,include:2,order:m,...a.params,...g(e),...p(t)},{resolveLinks:!1}),u=f(r);return new h({page:a.page,total:r.total,size:a.size,items:r.items.map(C=>L(C,u))})},J=async({id:e,slug:t,marketCode:i,locale:l})=>{const s=v({id:e,slug:t}),n=await d.client.getEntries({content_type:"blogPost",...s,select:`${I},fields.author,fields.content,fields.seo`,include:2,order:m,...g(i),...p(l)},{resolveLinks:!1}),c=n.items.at(0);if(!c)throw E();const a=f(n);return{...L(c,a),author:R(a.entry(c.fields.author),a),content:T(c.fields.content,a),seo:z(a.entry(c.fields.seo))}},M="sys.id,fields.title,fields.slug,fields.featuredImage",F=(e,t)=>({sys:{id:e.sys.id},title:o(e.fields.title),slug:o(e.fields.slug),featuredImage:k(t.asset(e.fields.featuredImage))}),Q=async({marketCode:e,locale:t,page:i=1,size:l=20}={})=>{const s=w(i,l),n=await d.client.getEntries({content_type:"blogCategory",select:M,include:1,order:m,...s.params,...g(e),...p(t)},{resolveLinks:!1}),c=f(n);return new h({page:s.page,total:n.total,size:s.size,items:n.items.map(a=>F(a,c))})},V=async({id:e,slug:t,marketCode:i,locale:l})=>{const s=v({id:e,slug:t}),n=await d.client.getEntries({content_type:"blogCategory",...s,select:`${M},fields.description,fields.seo`,include:1,order:m,...g(i),...p(l)},{resolveLinks:!1}),c=n.items.at(0);if(!c)throw E();const a=f(n);return{...F(c,a),description:o(c.fields.description),seo:z(a.entry(c.fields.seo))}},W=async({marketCode:e,locale:t,page:i=1,size:l=20}={})=>{const s=w(i,l),n=await d.client.getEntries({content_type:"blogCollection",select:"sys.id,fields.name,fields.type,fields.order,fields.category,fields.featuredImage",include:1,order:m,...s.params,...g(e),...p(t)},{resolveLinks:!1}),c=f(n),a=n.items.map(r=>{const u=c.entry(r.fields.category);return{name:o(r.fields.name),type:o(r.fields.type),order:o(r.fields.order),sys:{id:r.sys.id},category:u?{sys:{id:u.sys.id},title:o(u.fields.title),slug:o(u.fields.slug)}:null,featuredImage:k(c.asset(r.fields.featuredImage))}});return new h({page:s.page,total:n.total,size:s.size,items:a.map(r=>({...r,category:r.type==="category"?r.category:null,categoryId:r.type==="category"?r.category?.sys.id??null:null,collectionId:r.type==="manual"?r.sys.id:null}))})},X=async({page:e=1,size:t=20,marketCode:i,locale:l}={})=>{const s=w(e,t),n=await d.client.getEntries({content_type:"brandCollection",select:"sys.id,fields.name,fields.slot,fields.brands",include:2,order:m,...s.params,...g(i),...p(l)},{resolveLinks:!1}),c=f(n);return new h({page:s.page,total:n.total,size:s.size,items:n.items.map(a=>({sys:{id:a.sys.id},name:o(a.fields.name),slot:o(a.fields.slot),brandsCollection:{items:c.entries(a.fields.brands).map(r=>({sys:{id:r.sys.id},name:o(r.fields.name),logo:k(c.asset(r.fields.logo)),hyperlink:b(c.entry(r.fields.hyperlink))}))}}))})},x="sys.id,sys.createdAt,sys.updatedAt,fields.title,fields.slug,fields.description,fields.order,fields.seo",O="sys.id,sys.createdAt,sys.updatedAt,fields.title,fields.slug,fields.author,fields.category",K=e=>({id:e.sys.id,createdAt:e.sys.createdAt,updatedAt:e.sys.updatedAt}),H=(e,t)=>({sys:K(e),title:o(e.fields.title),slug:o(e.fields.slug),description:o(e.fields.description),order:o(e.fields.order),seo:z(t.entry(e.fields.seo))}),$=(e,t)=>{const i=t.entry(e.fields.category);return{sys:K(e),title:o(e.fields.title),slug:o(e.fields.slug),author:R(t.entry(e.fields.author),t),category:i?{title:o(i.fields.title),slug:o(i.fields.slug),description:o(i.fields.description),order:o(i.fields.order)}:null}},Z=async({marketCode:e,locale:t,page:i=1,size:l=20}={})=>{const s=w(i,l),n=await d.client.getEntries({content_type:"documentationCategory",select:x,include:1,order:m,...s.params,...g(e),...p(t)},{resolveLinks:!1}),c=f(n);return new h({page:s.page,total:n.total,size:s.size,items:n.items.map(a=>H(a,c))})},ee=async({id:e,slug:t,marketCode:i,locale:l})=>{const s=v({id:e,slug:t}),n=await d.client.getEntries({content_type:"documentationCategory",...s,select:x,include:1,order:m,...g(i),...p(l)},{resolveLinks:!1}),c=n.items.at(0);if(!c)throw E();return H(c,f(n))},te=async({marketCode:e,locale:t,categorySlug:i,page:l=1,size:s=20}={})=>{const n=w(l,s),c=await d.client.getEntries({content_type:"documentationArticle",...i?{"fields.category.sys.contentType.sys.id":"documentationCategory","fields.category.fields.slug":i}:{},select:O,include:2,order:m,...n.params,...g(e),...p(t)},{resolveLinks:!1}),a=f(c);return new h({page:n.page,total:c.total,size:n.size,items:c.items.map(r=>$(r,a))})},se=async({id:e,slug:t,marketCode:i,locale:l})=>{const s=v({id:e,slug:t}),n=await d.client.getEntries({content_type:"documentationArticle",...s,select:`${O},fields.content,fields.seo`,include:2,order:m,...g(i),...p(l)},{resolveLinks:!1}),c=n.items.at(0);if(!c)throw E();const a=f(n);return{...$(c,a),content:T(c.fields.content,a),seo:z(a.entry(c.fields.seo))}},ie=async({page:e=1,size:t=20,marketCode:i,locale:l}={})=>{const s=w(e,t),n=await d.client.getEntries({content_type:"hyperlinkCollection",select:"sys.id,fields.name,fields.slot,fields.order,fields.links",include:1,order:"fields.order",...s.params,...g(i),...p(l)},{resolveLinks:!1}),c=f(n);return new h({page:s.page,total:n.total,size:s.size,items:n.items.map(a=>({sys:{id:a.sys.id},name:o(a.fields.name),slot:o(a.fields.slot),order:o(a.fields.order),linksCollection:{items:c.entries(a.fields.links).map(r=>b(r))}}))})},le=async({page:e=1,size:t=20,marketCode:i,locale:l}={})=>{const s=w(e,t),n=await d.client.getEntries({content_type:"keywordCollection",select:"sys.id,fields.name,fields.slot,fields.keywords",include:0,order:m,...s.params,...g(i),...p(l)},{resolveLinks:!1});return new h({page:s.page,total:n.total,size:s.size,items:n.items.map(c=>({sys:{id:c.sys.id},name:o(c.fields.name),slot:o(c.fields.slot),keywords:o(c.fields.keywords)}))})},oe=async({marketCode:e,locale:t}={})=>{const i=await d.client.getEntries({content_type:"policyAndTerms",select:"sys.id,fields.title,fields.locale,fields.content",include:1,order:m,limit:1,...g(e),...p(t)},{resolveLinks:!1}),l=i.items.at(0);if(!l)throw E();return{sys:{id:l.sys.id},title:o(l.fields.title),locale:o(l.fields.locale),content:T(l.fields.content,f(i))}};exports.ContentfulSDK=d;exports.PaginatedResponse=h;exports.getBannerCollections=G;exports.getBlogCategories=Q;exports.getBlogCategoryDetail=V;exports.getBlogCollections=W;exports.getBlogPostDetail=J;exports.getBlogPosts=Y;exports.getBrandCollections=X;exports.getDocArticleDetail=se;exports.getDocArticles=te;exports.getDocCategories=Z;exports.getDocCategoryDetail=ee;exports.getHyperlinkCollections=ie;exports.getKeywordCollections=le;exports.getPolicyAndTerms=oe;
|