@janbox/contentful-marketplace-sdk 3.0.0 → 3.1.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
@@ -60,6 +60,8 @@ Configure the SDK once before calling entry methods.
60
60
  | `url` | `string` | ✅ | Delivery API base URL, e.g. `https://headless-cms.ichiba.net/delivery/janbox` |
61
61
  | `method` | `string` | — | Deprecated and ignored: requests are always `GET` |
62
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 |
63
65
 
64
66
  ```ts
65
67
  ContentfulSDK.configure({
@@ -76,12 +78,20 @@ Notes:
76
78
  - Keep the delivery key server-side: call the SDK from your server (route handler, BFF), never from browser JavaScript.
77
79
  - Runtime requires `fetch` (Node.js 18+ recommended).
78
80
 
81
+ ## Changes in 3.1.0
82
+
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`.
88
+
79
89
  ## Breaking changes in 3.0.0
80
90
 
81
91
  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
92
  2. The delivery key must stay on the server, so the SDK must be called server-side.
83
93
  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 ...")`.
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 ...")`.
85
95
 
86
96
  ## API Methods
87
97
 
@@ -5,10 +5,19 @@ export interface ContentfulSDKConfig {
5
5
  /** @deprecated Ignored: requests are always GET. Kept so existing configs still type-check. */
6
6
  method?: string;
7
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;
8
15
  }
9
16
  export declare class ContentfulSDK {
10
17
  private static _config;
18
+ private static _client;
11
19
  static get config(): ContentfulSDKConfig;
20
+ private static get client();
12
21
  static configure(params: ContentfulSDKConfig): void;
13
22
  static getEntries<T = CmsEntry>(params: QueryParams): Promise<CmsCollection<T>>;
14
23
  }
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
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 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;
package/dist/index.js CHANGED
@@ -1,61 +1,32 @@
1
- const m = "-sys.updatedAt", g = (e) => e ? {
2
- "or.market.0.fields.markets[exists]": "false",
3
- "or.market.1.fields.markets.sys.contentType.sys.id": "market",
4
- "or.market.1.fields.markets.fields.code": e
5
- } : {}, p = (e) => e ? {
6
- "or.locale.0.fields.locale[exists]": "false",
7
- "or.locale.1.fields.locale": e
8
- } : {}, z = ({ id: e, slug: t }) => {
9
- if (e)
10
- return { "sys.id": e, limit: 1 };
11
- if (t)
12
- return { "fields.slug": t, limit: 1 };
13
- throw new Error("Either id or slug is required.");
14
- }, w = (e, t, i = 0) => {
15
- const o = Math.max(1, Math.floor(e)), s = Math.max(1, Math.floor(t)), l = Math.max(0, Math.floor(i));
16
- return {
17
- page: o,
18
- size: s,
19
- params: {
20
- limit: s,
21
- skip: (o - 1) * s + l
22
- }
23
- };
24
- }, N = (e) => {
25
- const t = new URLSearchParams();
26
- for (const [i, o] of Object.entries(e))
27
- o !== void 0 && t.append(i, String(o));
28
- return t;
29
- };
30
- class c {
1
+ import { createClient as q, isCmsError as G, or as P } from "@janbox/headless-cms-sdk";
2
+ const U = (e) => G(e) && e.status !== void 0 && (e.status < 200 || e.status > 299) ? new Error(`Request failed: ${e.status} ${e.id}
3
+ ${e.message}`, { cause: e }) : e;
4
+ class r {
31
5
  static _config;
6
+ static _client;
32
7
  static get config() {
33
8
  if (!this._config)
34
9
  throw new Error("Client is not configured");
35
10
  return this._config;
36
11
  }
12
+ // 3.0.0 read the config on every request, so rebuild whenever a field the client uses changed.
13
+ static get client() {
14
+ const { url: t, headers: i, timeout: l, retry: s } = this.config, o = this._client;
15
+ if (o && o.builtFrom.url === t && o.builtFrom.headers === i && o.builtFrom.timeout === l && o.builtFrom.retry === s)
16
+ return o.client;
17
+ const n = q({ baseUrl: t, headers: i, timeout: l, retry: s });
18
+ return this._client = { client: n, builtFrom: { url: t, headers: i, timeout: l, retry: s } }, n;
19
+ }
37
20
  static configure(t) {
38
21
  this._config = t;
39
22
  }
40
23
  static async getEntries(t) {
41
- const { url: i, headers: o = {} } = this.config, s = await fetch(
42
- `${i.replace(/\/+$/, "")}/entries?${N(t)}`,
43
- {
44
- method: "GET",
45
- headers: {
46
- Accept: "application/json",
47
- ...o
48
- }
49
- }
50
- );
51
- if (!s.ok) {
52
- const l = await s.text();
53
- throw new Error(
54
- `Request failed: ${s.status} ${s.statusText}
55
- ${l}`
56
- );
24
+ const i = this.client;
25
+ try {
26
+ return await i.getEntries(t, { resolveLinks: !1 });
27
+ } catch (l) {
28
+ throw U(l);
57
29
  }
58
- return s.json();
59
30
  }
60
31
  }
61
32
  class h {
@@ -67,25 +38,50 @@ class h {
67
38
  constructor({
68
39
  page: t,
69
40
  total: i,
70
- size: o,
41
+ size: l,
71
42
  items: s
72
43
  }) {
73
- this.page = t, this.total = i, this.size = o, this.items = s, this.totalPages = Math.ceil(this.total / this.size);
44
+ this.page = t, this.total = i, this.size = l, this.items = s, this.totalPages = Math.ceil(this.total / this.size);
74
45
  }
75
46
  }
76
- const f = (e) => {
47
+ const p = "-sys.updatedAt", g = (e) => e ? P("market", [
48
+ { "fields.markets[exists]": "false" },
49
+ {
50
+ "fields.markets.sys.contentType.sys.id": "market",
51
+ "fields.markets.fields.code": e
52
+ }
53
+ ]) : {}, u = (e) => e ? P("locale", [
54
+ { "fields.locale[exists]": "false" },
55
+ { "fields.locale": e }
56
+ ]) : {}, k = ({ id: e, slug: t }) => {
57
+ if (e)
58
+ return { "sys.id": e, limit: 1 };
59
+ if (t)
60
+ return { "fields.slug": t, limit: 1 };
61
+ throw new Error("Either id or slug is required.");
62
+ }, w = (e, t, i = 0) => {
63
+ const l = Math.max(1, Math.floor(e)), s = Math.max(1, Math.floor(t)), o = Math.max(0, Math.floor(i));
64
+ return {
65
+ page: l,
66
+ size: s,
67
+ params: {
68
+ limit: s,
69
+ skip: (l - 1) * s + o
70
+ }
71
+ };
72
+ }, f = (e) => {
77
73
  const t = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
78
74
  for (const s of [...e.items, ...e.includes?.Entry ?? []])
79
75
  t.set(s.sys.id, s);
80
76
  for (const s of e.includes?.Asset ?? [])
81
77
  i.set(s.sys.id, s);
82
- const o = (s) => (s && t.get(s.sys.id)) ?? null;
78
+ const l = (s) => (s && t.get(s.sys.id)) ?? null;
83
79
  return {
84
- entry: o,
80
+ entry: l,
85
81
  asset: (s) => (s && i.get(s.sys.id)) ?? null,
86
- entries: (s) => (s ?? []).map((l) => o(l)).filter((l) => l !== null)
82
+ entries: (s) => (s ?? []).map((o) => l(o)).filter((o) => o !== null)
87
83
  };
88
- }, n = (e) => e ?? null, C = (e) => {
84
+ }, a = (e) => e ?? null, C = (e) => {
89
85
  const t = e?.fields.file;
90
86
  return t ? {
91
87
  url: t.url,
@@ -93,88 +89,88 @@ const f = (e) => {
93
89
  height: t.details.image?.height ?? null,
94
90
  contentType: t.contentType
95
91
  } : null;
96
- }, G = (e) => ({
92
+ }, Y = (e) => ({
97
93
  sys: { id: e.sys.id },
98
94
  url: e.fields.file?.url,
99
95
  width: e.fields.file?.details.image?.width ?? null,
100
96
  height: e.fields.file?.details.image?.height ?? null,
101
97
  contentType: e.fields.file?.contentType,
102
- title: n(e.fields.title),
103
- description: n(e.fields.description)
104
- }), B = (e, t) => {
98
+ title: a(e.fields.title),
99
+ description: a(e.fields.description)
100
+ }), F = (e, t) => {
105
101
  if (!e || typeof e != "object")
106
102
  return t;
107
103
  const i = e;
108
104
  if (i.nodeType === "embedded-asset-block") {
109
- const o = i.data?.target?.sys?.id;
110
- o && !t.includes(o) && t.push(o);
105
+ const l = i.data?.target?.sys?.id;
106
+ l && !t.includes(l) && t.push(l);
111
107
  }
112
- for (const o of i.content ?? [])
113
- B(o, t);
108
+ for (const l of i.content ?? [])
109
+ F(l, t);
114
110
  return t;
115
111
  }, D = (e, t) => {
116
112
  if (!e)
117
113
  return null;
118
- const i = B(e, []).map((o) => t.asset({ sys: { type: "Link", linkType: "Asset", id: o } })).filter((o) => o !== null && !!o.fields.file).map(G);
114
+ const i = F(e, []).map((l) => t.asset({ sys: { type: "Link", linkType: "Asset", id: l } })).filter((l) => l !== null && !!l.fields.file).map(Y);
119
115
  return { json: e, links: { assets: { block: i } } };
120
116
  }, A = (e) => e ? {
121
- metaTitle: n(e.fields.metaTitle),
122
- metaDescription: n(e.fields.metaDescription),
123
- metaKeywords: n(e.fields.metaKeywords),
124
- metaRobots: n(e.fields.metaRobots)
117
+ metaTitle: a(e.fields.metaTitle),
118
+ metaDescription: a(e.fields.metaDescription),
119
+ metaKeywords: a(e.fields.metaKeywords),
120
+ metaRobots: a(e.fields.metaRobots)
125
121
  } : null, v = (e) => e ? {
126
122
  sys: { id: e.sys.id },
127
- label: n(e.fields.label),
128
- url: n(e.fields.url),
129
- target: n(e.fields.target),
130
- marketHandling: n(e.fields.marketHandling)
131
- } : null, x = (e, t) => e ? {
132
- name: n(e.fields.name),
123
+ label: a(e.fields.label),
124
+ url: a(e.fields.url),
125
+ target: a(e.fields.target),
126
+ marketHandling: a(e.fields.marketHandling)
127
+ } : null, L = (e, t) => e ? {
128
+ name: a(e.fields.name),
133
129
  avatar: C(t.asset(e.fields.avatar))
134
- } : null, q = async ({
130
+ } : null, Q = async ({
135
131
  slot: e,
136
132
  page: t = 1,
137
133
  size: i = 20,
138
- platform: o,
134
+ platform: l,
139
135
  marketCode: s,
140
- locale: l
136
+ locale: o
141
137
  }) => {
142
- const d = w(t, i), a = await c.getEntries({
138
+ const n = w(t, i), d = await r.getEntries({
143
139
  content_type: "bannerCollection",
144
140
  "fields.slot": e,
145
- "fields.platform": o || void 0,
141
+ "fields.platform": l || void 0,
146
142
  select: "sys.id,fields.name,fields.slot,fields.platform,fields.banners",
147
143
  include: 2,
148
- order: m,
149
- ...d.params,
144
+ order: p,
145
+ ...n.params,
150
146
  ...g(s),
151
- ...p(l)
152
- }), r = f(a);
147
+ ...u(o)
148
+ }), c = f(d);
153
149
  return new h({
154
- page: d.page,
155
- total: a.total,
156
- size: d.size,
157
- items: a.items.map(
158
- (u) => ({
159
- sys: { id: u.sys.id },
160
- name: n(u.fields.name),
161
- slot: n(u.fields.slot),
162
- platform: n(u.fields.platform),
150
+ page: n.page,
151
+ total: d.total,
152
+ size: n.size,
153
+ items: d.items.map(
154
+ (m) => ({
155
+ sys: { id: m.sys.id },
156
+ name: a(m.fields.name),
157
+ slot: a(m.fields.slot),
158
+ platform: a(m.fields.platform),
163
159
  bannersCollection: {
164
- items: r.entries(u.fields.banners).map((E) => ({
160
+ items: c.entries(m.fields.banners).map((E) => ({
165
161
  sys: { id: E.sys.id },
166
- name: n(E.fields.name),
162
+ name: a(E.fields.name),
167
163
  hyperlink: v(
168
- r.entry(E.fields.hyperlink)
164
+ c.entry(E.fields.hyperlink)
169
165
  ),
170
- media: C(r.asset(E.fields.media))
166
+ media: C(c.asset(E.fields.media))
171
167
  }))
172
168
  }
173
169
  })
174
170
  )
175
171
  });
176
172
  };
177
- class k extends Response {
173
+ class z extends Response {
178
174
  constructor(...t) {
179
175
  super(t[0] ?? "Not Found", {
180
176
  status: 404,
@@ -182,36 +178,36 @@ class k extends Response {
182
178
  });
183
179
  }
184
180
  }
185
- const I = "sys.id,sys.createdAt,sys.updatedAt,fields.title,fields.shortDescription,fields.slug,fields.categories,fields.featuredImage", b = (e, t) => ({
181
+ const b = "sys.id,sys.createdAt,sys.updatedAt,fields.title,fields.shortDescription,fields.slug,fields.categories,fields.featuredImage", T = (e, t) => ({
186
182
  sys: {
187
183
  id: e.sys.id,
188
184
  createdAt: e.sys.createdAt,
189
185
  updatedAt: e.sys.updatedAt
190
186
  },
191
- title: n(e.fields.title),
192
- shortDescription: n(e.fields.shortDescription),
193
- slug: n(e.fields.slug),
187
+ title: a(e.fields.title),
188
+ shortDescription: a(e.fields.shortDescription),
189
+ slug: a(e.fields.slug),
194
190
  categoriesCollection: {
195
191
  items: t.entries(e.fields.categories).map((i) => ({
196
192
  sys: { id: i.sys.id },
197
- title: n(i.fields.title),
198
- slug: n(i.fields.slug),
193
+ title: a(i.fields.title),
194
+ slug: a(i.fields.slug),
199
195
  featuredImage: C(t.asset(i.fields.featuredImage))
200
196
  }))
201
197
  },
202
198
  featuredImage: C(t.asset(e.fields.featuredImage))
203
- }), U = async ({
199
+ }), V = async ({
204
200
  marketCode: e,
205
201
  locale: t,
206
202
  collectionId: i,
207
- categoryId: o,
203
+ categoryId: l,
208
204
  page: s = 1,
209
- size: l = 20,
210
- skip: d = 0
205
+ size: o = 20,
206
+ skip: n = 0
211
207
  } = {}) => {
212
- const a = w(s, l, d);
208
+ const d = w(s, o, n);
213
209
  if (i) {
214
- const R = (await c.getEntries({
210
+ const R = (await r.getEntries({
215
211
  content_type: "blogCollection",
216
212
  "sys.id": i,
217
213
  select: "sys.id,fields.posts",
@@ -219,404 +215,404 @@ const I = "sys.id,sys.createdAt,sys.updatedAt,fields.title,fields.shortDescripti
219
215
  limit: 1
220
216
  })).items.at(0);
221
217
  if (!R)
222
- throw new k();
223
- const _ = (R.fields.posts ?? []).filter((y) => y.sys.linkType === "Entry").map((y) => y.sys.id), T = _.slice(a.params.skip, a.params.skip + a.size);
224
- if (!T.length)
218
+ throw new z();
219
+ const _ = (R.fields.posts ?? []).filter((y) => y.sys.linkType === "Entry").map((y) => y.sys.id), I = _.slice(d.params.skip, d.params.skip + d.size);
220
+ if (!I.length)
225
221
  return new h({
226
- page: a.page,
222
+ page: d.page,
227
223
  total: _.length,
228
- size: a.size,
224
+ size: d.size,
229
225
  items: []
230
226
  });
231
- const P = await c.getEntries({
227
+ const B = await r.getEntries({
232
228
  content_type: "blogPost",
233
- "sys.id[in]": T.join(","),
234
- select: I,
229
+ "sys.id[in]": I.join(","),
230
+ select: b,
235
231
  include: 2,
236
- limit: a.size
237
- }), H = f(P), K = new Map(P.items.map((y) => [y.sys.id, y]));
232
+ limit: d.size
233
+ }), N = f(B), j = new Map(B.items.map((y) => [y.sys.id, y]));
238
234
  return new h({
239
- page: a.page,
235
+ page: d.page,
240
236
  total: _.length,
241
- size: a.size,
242
- items: T.map((y) => K.get(y)).filter((y) => y !== void 0).map((y) => b(y, H))
237
+ size: d.size,
238
+ items: I.map((y) => j.get(y)).filter((y) => y !== void 0).map((y) => T(y, N))
243
239
  });
244
240
  }
245
- const r = await c.getEntries({
241
+ const c = await r.getEntries({
246
242
  content_type: "blogPost",
247
- "fields.categories.sys.id": o || void 0,
248
- select: I,
243
+ "fields.categories.sys.id": l || void 0,
244
+ select: b,
249
245
  include: 2,
250
- order: m,
251
- ...a.params,
246
+ order: p,
247
+ ...d.params,
252
248
  ...g(e),
253
- ...p(t)
254
- }), u = f(r);
249
+ ...u(t)
250
+ }), m = f(c);
255
251
  return new h({
256
- page: a.page,
257
- total: r.total,
258
- size: a.size,
259
- items: r.items.map((E) => b(E, u))
252
+ page: d.page,
253
+ total: c.total,
254
+ size: d.size,
255
+ items: c.items.map((E) => T(E, m))
260
256
  });
261
- }, Y = async ({
257
+ }, W = async ({
262
258
  id: e,
263
259
  slug: t,
264
260
  marketCode: i,
265
- locale: o
261
+ locale: l
266
262
  }) => {
267
- const s = z({ id: e, slug: t }), l = await c.getEntries({
263
+ const s = k({ id: e, slug: t }), o = await r.getEntries({
268
264
  content_type: "blogPost",
269
265
  ...s,
270
- select: `${I},fields.author,fields.content,fields.seo`,
266
+ select: `${b},fields.author,fields.content,fields.seo`,
271
267
  include: 2,
272
- order: m,
268
+ order: p,
273
269
  ...g(i),
274
- ...p(o)
275
- }), d = l.items.at(0);
276
- if (!d)
277
- throw new k();
278
- const a = f(l);
270
+ ...u(l)
271
+ }), n = o.items.at(0);
272
+ if (!n)
273
+ throw new z();
274
+ const d = f(o);
279
275
  return {
280
- ...b(d, a),
281
- author: x(a.entry(d.fields.author), a),
282
- content: D(d.fields.content, a),
283
- seo: A(a.entry(d.fields.seo))
276
+ ...T(n, d),
277
+ author: L(d.entry(n.fields.author), d),
278
+ content: D(n.fields.content, d),
279
+ seo: A(d.entry(n.fields.seo))
284
280
  };
285
- }, S = "sys.id,fields.title,fields.slug,fields.featuredImage", L = (e, t) => ({
281
+ }, x = "sys.id,fields.title,fields.slug,fields.featuredImage", M = (e, t) => ({
286
282
  sys: { id: e.sys.id },
287
- title: n(e.fields.title),
288
- slug: n(e.fields.slug),
283
+ title: a(e.fields.title),
284
+ slug: a(e.fields.slug),
289
285
  featuredImage: C(t.asset(e.fields.featuredImage))
290
- }), J = async ({
286
+ }), X = async ({
291
287
  marketCode: e,
292
288
  locale: t,
293
289
  page: i = 1,
294
- size: o = 20
290
+ size: l = 20
295
291
  } = {}) => {
296
- const s = w(i, o), l = await c.getEntries({
292
+ const s = w(i, l), o = await r.getEntries({
297
293
  content_type: "blogCategory",
298
- select: S,
294
+ select: x,
299
295
  include: 1,
300
- order: m,
296
+ order: p,
301
297
  ...s.params,
302
298
  ...g(e),
303
- ...p(t)
304
- }), d = f(l);
299
+ ...u(t)
300
+ }), n = f(o);
305
301
  return new h({
306
302
  page: s.page,
307
- total: l.total,
303
+ total: o.total,
308
304
  size: s.size,
309
- items: l.items.map((a) => L(a, d))
305
+ items: o.items.map((d) => M(d, n))
310
306
  });
311
- }, Q = async ({
307
+ }, Z = async ({
312
308
  id: e,
313
309
  slug: t,
314
310
  marketCode: i,
315
- locale: o
311
+ locale: l
316
312
  }) => {
317
- const s = z({ id: e, slug: t }), l = await c.getEntries({
313
+ const s = k({ id: e, slug: t }), o = await r.getEntries({
318
314
  content_type: "blogCategory",
319
315
  ...s,
320
- select: `${S},fields.description,fields.seo`,
316
+ select: `${x},fields.description,fields.seo`,
321
317
  include: 1,
322
- order: m,
318
+ order: p,
323
319
  ...g(i),
324
- ...p(o)
325
- }), d = l.items.at(0);
326
- if (!d)
327
- throw new k();
328
- const a = f(l);
320
+ ...u(l)
321
+ }), n = o.items.at(0);
322
+ if (!n)
323
+ throw new z();
324
+ const d = f(o);
329
325
  return {
330
- ...L(d, a),
331
- description: n(d.fields.description),
332
- seo: A(a.entry(d.fields.seo))
326
+ ...M(n, d),
327
+ description: a(n.fields.description),
328
+ seo: A(d.entry(n.fields.seo))
333
329
  };
334
- }, V = async ({
330
+ }, ee = async ({
335
331
  marketCode: e,
336
332
  locale: t,
337
333
  page: i = 1,
338
- size: o = 20
334
+ size: l = 20
339
335
  } = {}) => {
340
- const s = w(i, o), l = await c.getEntries({
336
+ const s = w(i, l), o = await r.getEntries({
341
337
  content_type: "blogCollection",
342
338
  select: "sys.id,fields.name,fields.type,fields.order,fields.category,fields.featuredImage",
343
339
  include: 1,
344
- order: m,
340
+ order: p,
345
341
  ...s.params,
346
342
  ...g(e),
347
- ...p(t)
348
- }), d = f(l), a = l.items.map((r) => {
349
- const u = d.entry(r.fields.category);
343
+ ...u(t)
344
+ }), n = f(o), d = o.items.map((c) => {
345
+ const m = n.entry(c.fields.category);
350
346
  return {
351
- name: n(r.fields.name),
352
- type: n(r.fields.type),
353
- order: n(r.fields.order),
354
- sys: { id: r.sys.id },
355
- category: u ? {
356
- sys: { id: u.sys.id },
357
- title: n(u.fields.title),
358
- slug: n(u.fields.slug)
347
+ name: a(c.fields.name),
348
+ type: a(c.fields.type),
349
+ order: a(c.fields.order),
350
+ sys: { id: c.sys.id },
351
+ category: m ? {
352
+ sys: { id: m.sys.id },
353
+ title: a(m.fields.title),
354
+ slug: a(m.fields.slug)
359
355
  } : null,
360
- featuredImage: C(d.asset(r.fields.featuredImage))
356
+ featuredImage: C(n.asset(c.fields.featuredImage))
361
357
  };
362
358
  });
363
359
  return new h({
364
360
  page: s.page,
365
- total: l.total,
361
+ total: o.total,
366
362
  size: s.size,
367
- items: a.map((r) => ({
368
- ...r,
369
- category: r.type === "category" ? r.category : null,
370
- categoryId: r.type === "category" ? r.category?.sys.id ?? null : null,
371
- collectionId: r.type === "manual" ? r.sys.id : null
363
+ items: d.map((c) => ({
364
+ ...c,
365
+ category: c.type === "category" ? c.category : null,
366
+ categoryId: c.type === "category" ? c.category?.sys.id ?? null : null,
367
+ collectionId: c.type === "manual" ? c.sys.id : null
372
368
  }))
373
369
  });
374
- }, W = async ({
370
+ }, te = async ({
375
371
  page: e = 1,
376
372
  size: t = 20,
377
373
  marketCode: i,
378
- locale: o
374
+ locale: l
379
375
  } = {}) => {
380
- const s = w(e, t), l = await c.getEntries({
376
+ const s = w(e, t), o = await r.getEntries({
381
377
  content_type: "brandCollection",
382
378
  select: "sys.id,fields.name,fields.slot,fields.brands",
383
379
  include: 2,
384
- order: m,
380
+ order: p,
385
381
  ...s.params,
386
382
  ...g(i),
387
- ...p(o)
388
- }), d = f(l);
383
+ ...u(l)
384
+ }), n = f(o);
389
385
  return new h({
390
386
  page: s.page,
391
- total: l.total,
387
+ total: o.total,
392
388
  size: s.size,
393
- items: l.items.map(
394
- (a) => ({
395
- sys: { id: a.sys.id },
396
- name: n(a.fields.name),
397
- slot: n(a.fields.slot),
389
+ items: o.items.map(
390
+ (d) => ({
391
+ sys: { id: d.sys.id },
392
+ name: a(d.fields.name),
393
+ slot: a(d.fields.slot),
398
394
  brandsCollection: {
399
- items: d.entries(a.fields.brands).map((r) => ({
400
- sys: { id: r.sys.id },
401
- name: n(r.fields.name),
402
- logo: C(d.asset(r.fields.logo)),
395
+ items: n.entries(d.fields.brands).map((c) => ({
396
+ sys: { id: c.sys.id },
397
+ name: a(c.fields.name),
398
+ logo: C(n.asset(c.fields.logo)),
403
399
  hyperlink: v(
404
- d.entry(r.fields.hyperlink)
400
+ n.entry(c.fields.hyperlink)
405
401
  )
406
402
  }))
407
403
  }
408
404
  })
409
405
  )
410
406
  });
411
- }, 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) => ({
407
+ }, S = "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", $ = (e) => ({
412
408
  id: e.sys.id,
413
409
  createdAt: e.sys.createdAt,
414
410
  updatedAt: e.sys.updatedAt
415
- }), j = (e, t) => ({
416
- sys: O(e),
417
- title: n(e.fields.title),
418
- slug: n(e.fields.slug),
419
- description: n(e.fields.description),
420
- order: n(e.fields.order),
411
+ }), H = (e, t) => ({
412
+ sys: $(e),
413
+ title: a(e.fields.title),
414
+ slug: a(e.fields.slug),
415
+ description: a(e.fields.description),
416
+ order: a(e.fields.order),
421
417
  seo: A(t.entry(e.fields.seo))
422
- }), F = (e, t) => {
418
+ }), K = (e, t) => {
423
419
  const i = t.entry(e.fields.category);
424
420
  return {
425
- sys: O(e),
426
- title: n(e.fields.title),
427
- slug: n(e.fields.slug),
428
- author: x(t.entry(e.fields.author), t),
421
+ sys: $(e),
422
+ title: a(e.fields.title),
423
+ slug: a(e.fields.slug),
424
+ author: L(t.entry(e.fields.author), t),
429
425
  category: i ? {
430
- title: n(i.fields.title),
431
- slug: n(i.fields.slug),
432
- description: n(i.fields.description),
433
- order: n(i.fields.order)
426
+ title: a(i.fields.title),
427
+ slug: a(i.fields.slug),
428
+ description: a(i.fields.description),
429
+ order: a(i.fields.order)
434
430
  } : null
435
431
  };
436
- }, X = async ({
432
+ }, se = async ({
437
433
  marketCode: e,
438
434
  locale: t,
439
435
  page: i = 1,
440
- size: o = 20
436
+ size: l = 20
441
437
  } = {}) => {
442
- const s = w(i, o), l = await c.getEntries({
438
+ const s = w(i, l), o = await r.getEntries({
443
439
  content_type: "documentationCategory",
444
- select: M,
440
+ select: S,
445
441
  include: 1,
446
- order: m,
442
+ order: p,
447
443
  ...s.params,
448
444
  ...g(e),
449
- ...p(t)
450
- }), d = f(l);
445
+ ...u(t)
446
+ }), n = f(o);
451
447
  return new h({
452
448
  page: s.page,
453
- total: l.total,
449
+ total: o.total,
454
450
  size: s.size,
455
- items: l.items.map((a) => j(a, d))
451
+ items: o.items.map((d) => H(d, n))
456
452
  });
457
- }, Z = async ({
453
+ }, ie = async ({
458
454
  id: e,
459
455
  slug: t,
460
456
  marketCode: i,
461
- locale: o
457
+ locale: l
462
458
  }) => {
463
- const s = z({ id: e, slug: t }), l = await c.getEntries({
459
+ const s = k({ id: e, slug: t }), o = await r.getEntries({
464
460
  content_type: "documentationCategory",
465
461
  ...s,
466
- select: M,
462
+ select: S,
467
463
  include: 1,
468
- order: m,
464
+ order: p,
469
465
  ...g(i),
470
- ...p(o)
471
- }), d = l.items.at(0);
472
- if (!d)
473
- throw new k();
474
- return j(d, f(l));
475
- }, ee = async ({
466
+ ...u(l)
467
+ }), n = o.items.at(0);
468
+ if (!n)
469
+ throw new z();
470
+ return H(n, f(o));
471
+ }, le = async ({
476
472
  marketCode: e,
477
473
  locale: t,
478
474
  categorySlug: i,
479
- page: o = 1,
475
+ page: l = 1,
480
476
  size: s = 20
481
477
  } = {}) => {
482
- const l = w(o, s), d = await c.getEntries({
478
+ const o = w(l, s), n = await r.getEntries({
483
479
  content_type: "documentationArticle",
484
480
  ...i ? {
485
481
  "fields.category.sys.contentType.sys.id": "documentationCategory",
486
482
  "fields.category.fields.slug": i
487
483
  } : {},
488
- select: $,
484
+ select: O,
489
485
  include: 2,
490
- order: m,
491
- ...l.params,
486
+ order: p,
487
+ ...o.params,
492
488
  ...g(e),
493
- ...p(t)
494
- }), a = f(d);
489
+ ...u(t)
490
+ }), d = f(n);
495
491
  return new h({
496
- page: l.page,
497
- total: d.total,
498
- size: l.size,
499
- items: d.items.map((r) => F(r, a))
492
+ page: o.page,
493
+ total: n.total,
494
+ size: o.size,
495
+ items: n.items.map((c) => K(c, d))
500
496
  });
501
- }, te = async ({
497
+ }, oe = async ({
502
498
  id: e,
503
499
  slug: t,
504
500
  marketCode: i,
505
- locale: o
501
+ locale: l
506
502
  }) => {
507
- const s = z({ id: e, slug: t }), l = await c.getEntries({
503
+ const s = k({ id: e, slug: t }), o = await r.getEntries({
508
504
  content_type: "documentationArticle",
509
505
  ...s,
510
- select: `${$},fields.content,fields.seo`,
506
+ select: `${O},fields.content,fields.seo`,
511
507
  include: 2,
512
- order: m,
508
+ order: p,
513
509
  ...g(i),
514
- ...p(o)
515
- }), d = l.items.at(0);
516
- if (!d)
517
- throw new k();
518
- const a = f(l);
510
+ ...u(l)
511
+ }), n = o.items.at(0);
512
+ if (!n)
513
+ throw new z();
514
+ const d = f(o);
519
515
  return {
520
- ...F(d, a),
521
- content: D(d.fields.content, a),
522
- seo: A(a.entry(d.fields.seo))
516
+ ...K(n, d),
517
+ content: D(n.fields.content, d),
518
+ seo: A(d.entry(n.fields.seo))
523
519
  };
524
- }, se = async ({
520
+ }, ne = async ({
525
521
  page: e = 1,
526
522
  size: t = 20,
527
523
  marketCode: i,
528
- locale: o
524
+ locale: l
529
525
  } = {}) => {
530
- const s = w(e, t), l = await c.getEntries({
526
+ const s = w(e, t), o = await r.getEntries({
531
527
  content_type: "hyperlinkCollection",
532
528
  select: "sys.id,fields.name,fields.slot,fields.order,fields.links",
533
529
  include: 1,
534
530
  order: "fields.order",
535
531
  ...s.params,
536
532
  ...g(i),
537
- ...p(o)
538
- }), d = f(l);
533
+ ...u(l)
534
+ }), n = f(o);
539
535
  return new h({
540
536
  page: s.page,
541
- total: l.total,
537
+ total: o.total,
542
538
  size: s.size,
543
- items: l.items.map(
544
- (a) => ({
545
- sys: { id: a.sys.id },
546
- name: n(a.fields.name),
547
- slot: n(a.fields.slot),
548
- order: n(a.fields.order),
539
+ items: o.items.map(
540
+ (d) => ({
541
+ sys: { id: d.sys.id },
542
+ name: a(d.fields.name),
543
+ slot: a(d.fields.slot),
544
+ order: a(d.fields.order),
549
545
  linksCollection: {
550
- items: d.entries(a.fields.links).map((r) => v(r))
546
+ items: n.entries(d.fields.links).map((c) => v(c))
551
547
  }
552
548
  })
553
549
  )
554
550
  });
555
- }, ie = async ({
551
+ }, ae = async ({
556
552
  page: e = 1,
557
553
  size: t = 20,
558
554
  marketCode: i,
559
- locale: o
555
+ locale: l
560
556
  } = {}) => {
561
- const s = w(e, t), l = await c.getEntries({
557
+ const s = w(e, t), o = await r.getEntries({
562
558
  content_type: "keywordCollection",
563
559
  select: "sys.id,fields.name,fields.slot,fields.keywords",
564
560
  include: 0,
565
- order: m,
561
+ order: p,
566
562
  ...s.params,
567
563
  ...g(i),
568
- ...p(o)
564
+ ...u(l)
569
565
  });
570
566
  return new h({
571
567
  page: s.page,
572
- total: l.total,
568
+ total: o.total,
573
569
  size: s.size,
574
- items: l.items.map(
575
- (d) => ({
576
- sys: { id: d.sys.id },
577
- name: n(d.fields.name),
578
- slot: n(d.fields.slot),
579
- keywords: n(d.fields.keywords)
570
+ items: o.items.map(
571
+ (n) => ({
572
+ sys: { id: n.sys.id },
573
+ name: a(n.fields.name),
574
+ slot: a(n.fields.slot),
575
+ keywords: a(n.fields.keywords)
580
576
  })
581
577
  )
582
578
  });
583
- }, oe = async ({
579
+ }, de = async ({
584
580
  marketCode: e,
585
581
  locale: t
586
582
  } = {}) => {
587
- const i = await c.getEntries({
583
+ const i = await r.getEntries({
588
584
  content_type: "policyAndTerms",
589
585
  select: "sys.id,fields.title,fields.locale,fields.content",
590
586
  include: 1,
591
- order: m,
587
+ order: p,
592
588
  limit: 1,
593
589
  ...g(e),
594
- ...p(t)
595
- }), o = i.items.at(0);
596
- if (!o)
597
- throw new k();
590
+ ...u(t)
591
+ }), l = i.items.at(0);
592
+ if (!l)
593
+ throw new z();
598
594
  return {
599
- sys: { id: o.sys.id },
600
- title: n(o.fields.title),
601
- locale: n(o.fields.locale),
602
- content: D(o.fields.content, f(i))
595
+ sys: { id: l.sys.id },
596
+ title: a(l.fields.title),
597
+ locale: a(l.fields.locale),
598
+ content: D(l.fields.content, f(i))
603
599
  };
604
600
  };
605
601
  export {
606
- c as ContentfulSDK,
602
+ r as ContentfulSDK,
607
603
  h as PaginatedResponse,
608
- q as getBannerCollections,
609
- J as getBlogCategories,
610
- Q as getBlogCategoryDetail,
611
- V as getBlogCollections,
612
- Y as getBlogPostDetail,
613
- U as getBlogPosts,
614
- W as getBrandCollections,
615
- te as getDocArticleDetail,
616
- ee as getDocArticles,
617
- X as getDocCategories,
618
- Z as getDocCategoryDetail,
619
- se as getHyperlinkCollections,
620
- ie as getKeywordCollections,
621
- oe as getPolicyAndTerms
604
+ Q as getBannerCollections,
605
+ X as getBlogCategories,
606
+ Z as getBlogCategoryDetail,
607
+ ee as getBlogCollections,
608
+ W as getBlogPostDetail,
609
+ V as getBlogPosts,
610
+ te as getBrandCollections,
611
+ oe as getDocArticleDetail,
612
+ le as getDocArticles,
613
+ se as getDocCategories,
614
+ ie as getDocCategoryDetail,
615
+ ne as getHyperlinkCollections,
616
+ ae as getKeywordCollections,
617
+ de as getPolicyAndTerms
622
618
  };
@@ -14,4 +14,3 @@ export declare const paging: (page: number, size: number, extraSkip?: number) =>
14
14
  skip: number;
15
15
  };
16
16
  };
17
- export declare const toSearchParams: (params: QueryParams) => URLSearchParams;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@janbox/contentful-marketplace-sdk",
3
- "version": "3.0.0",
3
+ "version": "3.1.0-alpha.0",
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -17,7 +17,8 @@
17
17
  "type": "module",
18
18
  "sideEffects": false,
19
19
  "dependencies": {
20
- "@contentful/rich-text-types": "^16.8.5"
20
+ "@contentful/rich-text-types": "^16.8.5",
21
+ "@janbox/headless-cms-sdk": "^0.1.0"
21
22
  },
22
23
  "scripts": {
23
24
  "dev": "vite",