@janbox/contentful-marketplace-sdk 3.1.0-alpha.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 CHANGED
@@ -31,10 +31,8 @@ import {
31
31
  } from "@janbox/contentful-marketplace-sdk";
32
32
 
33
33
  ContentfulSDK.configure({
34
- url: "https://headless-cms.ichiba.net/delivery/janbox",
35
- headers: {
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,45 +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 | Type | Required | Description |
59
- |-----------|--------------------------|----------|-------------------------------------------|
60
- | `url` | `string` | ✅ | Delivery API base URL, e.g. `https://headless-cms.ichiba.net/delivery/janbox` |
61
- | `method` | `string` | — | Deprecated and ignored: requests are always `GET` |
62
- | `headers` | `Record<string, string>` | — | Custom headers, usually `Authorization: Bearer cdel_...` |
63
- | `timeout` | `number` | — | Timeout per attempt in ms. Default `30000`; `0` disables it |
64
- | `retry` | `{ maxRetries?: number; maxDelay?: number } \| false` | — | Retry on HTTP 429. Default `{ maxRetries: 3, maxDelay: 10000 }`; `false` disables it |
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 |
65
64
 
66
65
  ```ts
67
66
  ContentfulSDK.configure({
68
- url: "https://test-headless-cms.ichiba.net/delivery/janbox", // QC
69
- headers: {
70
- Authorization: "Bearer cdel_your-delivery-key",
71
- },
67
+ baseUrl: "https://test-headless-cms.ichiba.net/delivery/janbox", // QC
68
+ accessToken: "cdel_your-delivery-key",
72
69
  });
73
70
  ```
74
71
 
75
72
  Notes:
76
73
 
77
- - The SDK sends `GET {url}/entries?...` with `Accept: application/json`. Custom headers are merged on top.
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 })`.
78
77
  - Keep the delivery key server-side: call the SDK from your server (route handler, BFF), never from browser JavaScript.
79
- - Runtime requires `fetch` (Node.js 18+ recommended).
78
+ - Runtime requires `fetch` (Node.js 18+).
80
79
 
81
- ## Changes in 3.1.0
80
+ ## Breaking changes in 4.0.0
82
81
 
83
- 1. Requests go through [`@janbox/headless-cms-sdk`](https://www.npmjs.com/package/@janbox/headless-cms-sdk). The public API is unchanged.
84
- 2. 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.
85
- 3. Errors:
86
- - A non-2xx response throws `Error("Request failed: {status} {id}\n{message}")`. The `Request failed: {status}` prefix is unchanged; the rest now comes from the CMS error. The original error, with `requestId` and `details`, is in `error.cause`.
87
- - Network errors, timeouts and invalid responses throw an error with `name === "CmsError"` and `id` set to `NetworkError`, `Timeout` or `InvalidResponse`.
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.
88
89
 
89
90
  ## Breaking changes in 3.0.0
90
91
 
91
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.
92
93
  2. The delivery key must stay on the server, so the SDK must be called server-side.
93
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.
94
- 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 InvalidQuery ...")`.
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).
95
96
 
96
97
  ## API Methods
97
98
 
@@ -236,21 +237,28 @@ Filters `marketCode` / `locale` with global fallback (entries where `markets` /
236
237
 
237
238
  ## Error Handling
238
239
 
239
- `getBlogPostDetail`, `getDocCategoryDetail`, and `getDocArticleDetail` throw:
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.
240
241
 
241
- - `Error("Either id or slug is required.")` if neither `id` nor `slug` is provided.
242
- - `Response` with status `404` when no entry is found.
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")`.
243
245
 
244
246
  ```ts
247
+ import { isCmsError } from "@janbox/headless-cms-sdk";
248
+
245
249
  try {
246
250
  await getDocArticleDetail({ slug: "unknown-slug" });
247
251
  } catch (error) {
248
- if (error instanceof Response && error.status === 404) {
252
+ if (isCmsError(error) && error.id === "NotFound") {
249
253
  console.log("Entry not found");
254
+ } else {
255
+ throw error;
250
256
  }
251
257
  }
252
258
  ```
253
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
+
254
262
  ## Market/Language Filtering Behavior
255
263
 
256
264
  When `marketCode` or `language` is provided, queries include both:
@@ -265,9 +273,11 @@ This supports global fallback content.
265
273
  The package exports:
266
274
 
267
275
  - client and entry functions from `src/client` and `src/entries`
268
- - content model field types (`TypeXxxFields`) and CMS response types (`CmsEntry`, `CmsAsset`, `CmsLink`, `CmsCollection`) from `src/types`
276
+ - content model field types (`TypeXxxFields`) from `src/types`
269
277
  - response item types such as `BlogPostGraphQLItem` and `DocArticleGraphQLItem` (names kept from 2.x)
270
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
+
271
281
  ## Development
272
282
 
273
283
  From repository root:
@@ -1,23 +1,8 @@
1
- import { CmsCollection, CmsEntry } from '../types';
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
- /** Timeout per attempt in ms. Defaults to 30000; 0 disables it. */
9
- timeout?: number;
10
- /** Retry on 429. Defaults to { maxRetries: 3, maxDelay: 10000 }; false disables it. */
11
- retry?: {
12
- maxRetries?: number;
13
- maxDelay?: number;
14
- } | false;
15
- }
1
+ import { ClientConfig, CmsClient } from '@janbox/headless-cms-sdk';
16
2
  export declare class ContentfulSDK {
17
3
  private static _config;
18
4
  private static _client;
19
- static get config(): ContentfulSDKConfig;
20
- private static get client();
21
- static configure(params: ContentfulSDKConfig): void;
22
- static getEntries<T = CmsEntry>(params: QueryParams): Promise<CmsCollection<T>>;
5
+ static get config(): ClientConfig;
6
+ static get client(): CmsClient;
7
+ static configure(config: ClientConfig): void;
23
8
  }
package/dist/index.cjs CHANGED
@@ -1,2 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("@janbox/headless-cms-sdk"),N=e=>k.isCmsError(e)&&e.status!==void 0&&(e.status<200||e.status>299)?new Error(`Request failed: ${e.status} ${e.id}
2
- ${e.message}`,{cause:e}):e;class r{static _config;static _client;static get config(){if(!this._config)throw new Error("Client is not configured");return this._config}static get client(){const{url:t,headers:i,timeout:l,retry:s}=this.config,o=this._client;if(o&&o.builtFrom.url===t&&o.builtFrom.headers===i&&o.builtFrom.timeout===l&&o.builtFrom.retry===s)return o.client;const n=k.createClient({baseUrl:t,headers:i,timeout:l,retry:s});return this._client={client:n,builtFrom:{url:t,headers:i,timeout:l,retry:s}},n}static configure(t){this._config=t}static async getEntries(t){const i=this.client;try{return await i.getEntries(t,{resolveLinks:!1})}catch(l){throw N(l)}}}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 p="-sys.updatedAt",g=e=>e?k.or("market",[{"fields.markets[exists]":"false"},{"fields.markets.sys.contentType.sys.id":"market","fields.markets.fields.code":e}]):{},u=e=>e?k.or("locale",[{"fields.locale[exists]":"false"},{"fields.locale":e}]):{},z=({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)),o=Math.max(0,Math.floor(i));return{page:l,size:s,params:{limit:s,skip:(l-1)*s+o}}},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(o=>l(o)).filter(o=>o!==null)}},a=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:a(e.fields.title),description:a(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},B=(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(G);return{json:e,links:{assets:{block:i}}}},_=e=>e?{metaTitle:a(e.fields.metaTitle),metaDescription:a(e.fields.metaDescription),metaKeywords:a(e.fields.metaKeywords),metaRobots:a(e.fields.metaRobots)}:null,v=e=>e?{sys:{id:e.sys.id},label:a(e.fields.label),url:a(e.fields.url),target:a(e.fields.target),marketHandling:a(e.fields.marketHandling)}:null,F=(e,t)=>e?{name:a(e.fields.name),avatar:E(t.asset(e.fields.avatar))}:null,U=async({slot:e,page:t=1,size:i=20,platform:l,marketCode:s,locale:o})=>{const n=w(t,i),c=await r.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:p,...n.params,...g(s),...u(o)}),d=f(c);return new h({page:n.page,total:c.total,size:n.size,items:c.items.map(m=>({sys:{id:m.sys.id},name:a(m.fields.name),slot:a(m.fields.slot),platform:a(m.fields.platform),bannersCollection:{items:d.entries(m.fields.banners).map(C=>({sys:{id:C.sys.id},name:a(C.fields.name),hyperlink:v(d.entry(C.fields.hyperlink)),media:E(d.asset(C.fields.media))}))}}))})};class A extends Response{constructor(...t){super(t[0]??"Not Found",{status:404,...t[1]})}}const I="sys.id,sys.createdAt,sys.updatedAt,fields.title,fields.shortDescription,fields.slug,fields.categories,fields.featuredImage",T=(e,t)=>({sys:{id:e.sys.id,createdAt:e.sys.createdAt,updatedAt:e.sys.updatedAt},title:a(e.fields.title),shortDescription:a(e.fields.shortDescription),slug:a(e.fields.slug),categoriesCollection:{items:t.entries(e.fields.categories).map(i=>({sys:{id:i.sys.id},title:a(i.fields.title),slug:a(i.fields.slug),featuredImage:E(t.asset(i.fields.featuredImage))}))},featuredImage:E(t.asset(e.fields.featuredImage))}),Y=async({marketCode:e,locale:t,collectionId:i,categoryId:l,page:s=1,size:o=20,skip:n=0}={})=>{const c=w(s,o,n);if(i){const P=(await r.getEntries({content_type:"blogCollection","sys.id":i,select:"sys.id,fields.posts",include:0,limit:1})).items.at(0);if(!P)throw new A;const D=(P.fields.posts??[]).filter(y=>y.sys.linkType==="Entry").map(y=>y.sys.id),b=D.slice(c.params.skip,c.params.skip+c.size);if(!b.length)return new h({page:c.page,total:D.length,size:c.size,items:[]});const R=await r.getEntries({content_type:"blogPost","sys.id[in]":b.join(","),select:I,include:2,limit:c.size}),j=f(R),q=new Map(R.items.map(y=>[y.sys.id,y]));return new h({page:c.page,total:D.length,size:c.size,items:b.map(y=>q.get(y)).filter(y=>y!==void 0).map(y=>T(y,j))})}const d=await r.getEntries({content_type:"blogPost","fields.categories.sys.id":l||void 0,select:I,include:2,order:p,...c.params,...g(e),...u(t)}),m=f(d);return new h({page:c.page,total:d.total,size:c.size,items:d.items.map(C=>T(C,m))})},J=async({id:e,slug:t,marketCode:i,locale:l})=>{const s=z({id:e,slug:t}),o=await r.getEntries({content_type:"blogPost",...s,select:`${I},fields.author,fields.content,fields.seo`,include:2,order:p,...g(i),...u(l)}),n=o.items.at(0);if(!n)throw new A;const c=f(o);return{...T(n,c),author:F(c.entry(n.fields.author),c),content:B(n.fields.content,c),seo:_(c.entry(n.fields.seo))}},L="sys.id,fields.title,fields.slug,fields.featuredImage",M=(e,t)=>({sys:{id:e.sys.id},title:a(e.fields.title),slug:a(e.fields.slug),featuredImage:E(t.asset(e.fields.featuredImage))}),Q=async({marketCode:e,locale:t,page:i=1,size:l=20}={})=>{const s=w(i,l),o=await r.getEntries({content_type:"blogCategory",select:L,include:1,order:p,...s.params,...g(e),...u(t)}),n=f(o);return new h({page:s.page,total:o.total,size:s.size,items:o.items.map(c=>M(c,n))})},V=async({id:e,slug:t,marketCode:i,locale:l})=>{const s=z({id:e,slug:t}),o=await r.getEntries({content_type:"blogCategory",...s,select:`${L},fields.description,fields.seo`,include:1,order:p,...g(i),...u(l)}),n=o.items.at(0);if(!n)throw new A;const c=f(o);return{...M(n,c),description:a(n.fields.description),seo:_(c.entry(n.fields.seo))}},W=async({marketCode:e,locale:t,page:i=1,size:l=20}={})=>{const s=w(i,l),o=await r.getEntries({content_type:"blogCollection",select:"sys.id,fields.name,fields.type,fields.order,fields.category,fields.featuredImage",include:1,order:p,...s.params,...g(e),...u(t)}),n=f(o),c=o.items.map(d=>{const m=n.entry(d.fields.category);return{name:a(d.fields.name),type:a(d.fields.type),order:a(d.fields.order),sys:{id:d.sys.id},category:m?{sys:{id:m.sys.id},title:a(m.fields.title),slug:a(m.fields.slug)}:null,featuredImage:E(n.asset(d.fields.featuredImage))}});return new h({page:s.page,total:o.total,size:s.size,items:c.map(d=>({...d,category:d.type==="category"?d.category:null,categoryId:d.type==="category"?d.category?.sys.id??null:null,collectionId:d.type==="manual"?d.sys.id:null}))})},X=async({page:e=1,size:t=20,marketCode:i,locale:l}={})=>{const s=w(e,t),o=await r.getEntries({content_type:"brandCollection",select:"sys.id,fields.name,fields.slot,fields.brands",include:2,order:p,...s.params,...g(i),...u(l)}),n=f(o);return new h({page:s.page,total:o.total,size:s.size,items:o.items.map(c=>({sys:{id:c.sys.id},name:a(c.fields.name),slot:a(c.fields.slot),brandsCollection:{items:n.entries(c.fields.brands).map(d=>({sys:{id:d.sys.id},name:a(d.fields.name),logo:E(n.asset(d.fields.logo)),hyperlink:v(n.entry(d.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}),$=(e,t)=>({sys:K(e),title:a(e.fields.title),slug:a(e.fields.slug),description:a(e.fields.description),order:a(e.fields.order),seo:_(t.entry(e.fields.seo))}),H=(e,t)=>{const i=t.entry(e.fields.category);return{sys:K(e),title:a(e.fields.title),slug:a(e.fields.slug),author:F(t.entry(e.fields.author),t),category:i?{title:a(i.fields.title),slug:a(i.fields.slug),description:a(i.fields.description),order:a(i.fields.order)}:null}},Z=async({marketCode:e,locale:t,page:i=1,size:l=20}={})=>{const s=w(i,l),o=await r.getEntries({content_type:"documentationCategory",select:x,include:1,order:p,...s.params,...g(e),...u(t)}),n=f(o);return new h({page:s.page,total:o.total,size:s.size,items:o.items.map(c=>$(c,n))})},ee=async({id:e,slug:t,marketCode:i,locale:l})=>{const s=z({id:e,slug:t}),o=await r.getEntries({content_type:"documentationCategory",...s,select:x,include:1,order:p,...g(i),...u(l)}),n=o.items.at(0);if(!n)throw new A;return $(n,f(o))},te=async({marketCode:e,locale:t,categorySlug:i,page:l=1,size:s=20}={})=>{const o=w(l,s),n=await r.getEntries({content_type:"documentationArticle",...i?{"fields.category.sys.contentType.sys.id":"documentationCategory","fields.category.fields.slug":i}:{},select:O,include:2,order:p,...o.params,...g(e),...u(t)}),c=f(n);return new h({page:o.page,total:n.total,size:o.size,items:n.items.map(d=>H(d,c))})},se=async({id:e,slug:t,marketCode:i,locale:l})=>{const s=z({id:e,slug:t}),o=await r.getEntries({content_type:"documentationArticle",...s,select:`${O},fields.content,fields.seo`,include:2,order:p,...g(i),...u(l)}),n=o.items.at(0);if(!n)throw new A;const c=f(o);return{...H(n,c),content:B(n.fields.content,c),seo:_(c.entry(n.fields.seo))}},ie=async({page:e=1,size:t=20,marketCode:i,locale:l}={})=>{const s=w(e,t),o=await r.getEntries({content_type:"hyperlinkCollection",select:"sys.id,fields.name,fields.slot,fields.order,fields.links",include:1,order:"fields.order",...s.params,...g(i),...u(l)}),n=f(o);return new h({page:s.page,total:o.total,size:s.size,items:o.items.map(c=>({sys:{id:c.sys.id},name:a(c.fields.name),slot:a(c.fields.slot),order:a(c.fields.order),linksCollection:{items:n.entries(c.fields.links).map(d=>v(d))}}))})},le=async({page:e=1,size:t=20,marketCode:i,locale:l}={})=>{const s=w(e,t),o=await r.getEntries({content_type:"keywordCollection",select:"sys.id,fields.name,fields.slot,fields.keywords",include:0,order:p,...s.params,...g(i),...u(l)});return new h({page:s.page,total:o.total,size:s.size,items:o.items.map(n=>({sys:{id:n.sys.id},name:a(n.fields.name),slot:a(n.fields.slot),keywords:a(n.fields.keywords)}))})},oe=async({marketCode:e,locale:t}={})=>{const i=await r.getEntries({content_type:"policyAndTerms",select:"sys.id,fields.title,fields.locale,fields.content",include:1,order:p,limit:1,...g(e),...u(t)}),l=i.items.at(0);if(!l)throw new A;return{sys:{id:l.sys.id},title:a(l.fields.title),locale:a(l.fields.locale),content:B(l.fields.content,f(i))}};exports.ContentfulSDK=r;exports.PaginatedResponse=h;exports.getBannerCollections=U;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;
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;