@janbox/contentful-marketplace-sdk 0.0.4 → 0.0.5

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.
@@ -1,6 +1,9 @@
1
1
  import { ContentfulClientApi, CreateClientParams } from 'contentful';
2
2
  export declare class ContentfulSDK {
3
3
  private static _client;
4
+ private static _clientParams;
5
+ static get clientParams(): CreateClientParams;
4
6
  static get client(): ContentfulClientApi<undefined>;
5
7
  static configure(params: CreateClientParams): void;
8
+ static graphqlQuery<T extends object>(query: string, variables?: Record<string, any>): Promise<T>;
6
9
  }
@@ -1,7 +1,24 @@
1
- import { EntriesQueries } from 'contentful';
2
- import { TypeFooterMenuSkeleton } from '../types';
3
- export declare const listFooterMenuEntries: ({ query, marketId, language, }: {
1
+ export type FooterMenuGraphQLResponse = {
2
+ footerMenuCollection: {
3
+ items: Array<{
4
+ sys: {
5
+ id: string;
6
+ };
7
+ name: string;
8
+ childrenCollection: {
9
+ items: Array<{
10
+ sys: {
11
+ id: string;
12
+ };
13
+ label: string;
14
+ url: string;
15
+ target: string;
16
+ }>;
17
+ };
18
+ }>;
19
+ };
20
+ };
21
+ export declare const listFooterMenuEntries: ({ marketId, language, }: {
4
22
  marketId: string;
5
23
  language: string;
6
- query?: Partial<EntriesQueries<TypeFooterMenuSkeleton, "WITHOUT_UNRESOLVABLE_LINKS">>;
7
- }) => Promise<import('contentful').EntryCollection<TypeFooterMenuSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>>;
24
+ }) => Promise<FooterMenuGraphQLResponse>;
package/dist/index.cjs CHANGED
@@ -1 +1,32 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("contentful");class n{static _client;static get client(){if(!this._client)throw new Error("Client is not initialized");return this._client}static configure(e){this._client=o.createClient(e)}}const r=async({query:t,marketId:e,language:s})=>n.client.withoutUnresolvableLinks.getEntries({"fields.market.sys.contentType.sys.id":"market","fields.market.fields.marketId":e,"fields.language.sys.contentType.sys.id":"language","fields.language.fields.code":s,...t,content_type:"banner"});class a extends Response{constructor(...e){super(e[0]??"Not Found",{status:404,...e[1]})}}const d=async({query:t,marketId:e,language:s})=>n.client.withoutUnresolvableLinks.getEntries({"fields.market.sys.contentType.sys.id":"market","fields.market.fields.marketId":e,"fields.language.sys.contentType.sys.id":"language","fields.language.fields.code":s,select:["fields.title","fields.category","fields.slug","fields.featuredImage","fields.shortDescription"],content_type:"blogPost",...t}),c=async({query:t,marketId:e,language:s})=>{const i=await n.client.withoutUnresolvableLinks.getEntries({select:["fields.title","fields.category","fields.slug","fields.featuredImage","fields.shortDescription","fields.author","fields.content","fields.seo","sys.updatedAt"],"fields.market.sys.contentType.sys.id":"market","fields.market.fields.marketId":e,"fields.language.sys.contentType.sys.id":"language","fields.language.fields.code":s,content_type:"blogPost",limit:1,...t}).then(l=>l.items.at(0));if(!i)throw new a;return i},y=async({query:t,marketId:e,language:s})=>n.client.withoutUnresolvableLinks.getEntries({"fields.market.sys.contentType.sys.id":"market","fields.market.fields.marketId":e,"fields.language.sys.contentType.sys.id":"language","fields.language.fields.code":s,...t,content_type:"documentationCategory"}),f=async({query:t,marketId:e,language:s})=>{const i=await n.client.withoutUnresolvableLinks.getEntries({"fields.market.sys.contentType.sys.id":"market","fields.market.fields.marketId":e,"fields.language.sys.contentType.sys.id":"language","fields.language.fields.code":s,...t,content_type:"documentationCategory",limit:1}).then(l=>l.items.at(0));if(!i)throw new a;return i},g=({query:t,marketId:e,language:s})=>n.client.withoutUnresolvableLinks.getEntries({"fields.market.sys.contentType.sys.id":"market","fields.market.fields.marketId":e,"fields.language.sys.contentType.sys.id":"language","fields.language.fields.code":s,...t,content_type:"documentationArticle"}),u=async({query:t,marketId:e,language:s})=>{const i=await n.client.withoutUnresolvableLinks.getEntries({"fields.market.sys.contentType.sys.id":"market","fields.market.fields.marketId":e,"fields.language.sys.contentType.sys.id":"language","fields.language.fields.code":s,...t,content_type:"documentationArticle",limit:1}).then(l=>l.items.at(0));if(!i)throw new a;return i},m=async({query:t,marketId:e,language:s})=>n.client.withoutUnresolvableLinks.getEntries({"fields.market.sys.contentType.sys.id":"market","fields.market.fields.marketId":e,"fields.language.sys.contentType.sys.id":"language","fields.language.fields.code":s,select:["fields.name","fields.children"],content_type:"footerMenu",...t});exports.ContentfulSDK=n;exports.findBlogPostEntry=c;exports.findDocArticleEntry=u;exports.findDocCategoryEntry=f;exports.listBannerEntries=r;exports.listBlogPostEntries=d;exports.listDocArticleEntries=g;exports.listDocCategoryEntries=y;exports.listFooterMenuEntries=m;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("contentful");class i{static _client;static _clientParams;static get clientParams(){if(!this._clientParams)throw new Error("Client is not configured");return this._clientParams}static get client(){return this._client||(this._client=y.createClient(this.clientParams)),this._client}static configure(e){this._clientParams={...e,environment:e.environment??"master"}}static async graphqlQuery(e,s={}){const{space:n,accessToken:r,environment:c="master"}=this.clientParams,a=await fetch(`https://graphql.contentful.com/content/v1/spaces/${n}/environments/${c}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({query:e,variables:s})});if(!a.ok){const d=await a.text();throw new Error(`GraphQL request failed: ${a.status} ${a.statusText}
2
+ ${d}`)}const l=await a.json();if(l.errors)throw new Error(`GraphQL errors: ${JSON.stringify(l.errors,null,2)}`);return l.data}}const g=async({query:t,marketId:e,language:s})=>i.client.withoutUnresolvableLinks.getEntries({"fields.market.sys.contentType.sys.id":"market","fields.market.fields.marketId":e,"fields.language.sys.contentType.sys.id":"language","fields.language.fields.code":s,...t,content_type:"banner"});class o extends Response{constructor(...e){super(e[0]??"Not Found",{status:404,...e[1]})}}const f=async({query:t,marketId:e,language:s})=>i.client.withoutUnresolvableLinks.getEntries({"fields.market.sys.contentType.sys.id":"market","fields.market.fields.marketId":e,"fields.language.sys.contentType.sys.id":"language","fields.language.fields.code":s,select:["fields.title","fields.category","fields.slug","fields.featuredImage","fields.shortDescription"],content_type:"blogPost",...t}),u=async({query:t,marketId:e,language:s})=>{const n=await i.client.withoutUnresolvableLinks.getEntries({select:["fields.title","fields.category","fields.slug","fields.featuredImage","fields.shortDescription","fields.author","fields.content","fields.seo","sys.updatedAt"],"fields.market.sys.contentType.sys.id":"market","fields.market.fields.marketId":e,"fields.language.sys.contentType.sys.id":"language","fields.language.fields.code":s,content_type:"blogPost",limit:1,...t}).then(r=>r.items.at(0));if(!n)throw new o;return n},m=async({query:t,marketId:e,language:s})=>i.client.withoutUnresolvableLinks.getEntries({"fields.market.sys.contentType.sys.id":"market","fields.market.fields.marketId":e,"fields.language.sys.contentType.sys.id":"language","fields.language.fields.code":s,...t,content_type:"documentationCategory"}),k=async({query:t,marketId:e,language:s})=>{const n=await i.client.withoutUnresolvableLinks.getEntries({"fields.market.sys.contentType.sys.id":"market","fields.market.fields.marketId":e,"fields.language.sys.contentType.sys.id":"language","fields.language.fields.code":s,...t,content_type:"documentationCategory",limit:1}).then(r=>r.items.at(0));if(!n)throw new o;return n},h=({query:t,marketId:e,language:s})=>i.client.withoutUnresolvableLinks.getEntries({"fields.market.sys.contentType.sys.id":"market","fields.market.fields.marketId":e,"fields.language.sys.contentType.sys.id":"language","fields.language.fields.code":s,...t,content_type:"documentationArticle"}),p=async({query:t,marketId:e,language:s})=>{const n=await i.client.withoutUnresolvableLinks.getEntries({"fields.market.sys.contentType.sys.id":"market","fields.market.fields.marketId":e,"fields.language.sys.contentType.sys.id":"language","fields.language.fields.code":s,...t,content_type:"documentationArticle",limit:1}).then(r=>r.items.at(0));if(!n)throw new o;return n},w=async({marketId:t,language:e})=>i.graphqlQuery(`
3
+ query ($marketId: String!, $language: String!) {
4
+ footerMenuCollection(where: {
5
+ market: {
6
+ OR: [
7
+ {
8
+ marketId_exists: false
9
+ }, {
10
+ marketId: $marketId
11
+ }
12
+ ]
13
+ },
14
+ language: {
15
+ code: $language
16
+ }
17
+ }) {
18
+ items {
19
+ sys { id }
20
+ name
21
+ childrenCollection {
22
+ items {
23
+ sys { id }
24
+ label
25
+ url
26
+ target
27
+ }
28
+ }
29
+ }
30
+ }
31
+ }
32
+ `,{marketId:t,language:e});exports.ContentfulSDK=i;exports.findBlogPostEntry=u;exports.findDocArticleEntry=p;exports.findDocCategoryEntry=k;exports.listBannerEntries=g;exports.listBlogPostEntries=f;exports.listDocArticleEntries=h;exports.listDocCategoryEntries=m;exports.listFooterMenuEntries=w;
package/dist/index.js CHANGED
@@ -1,17 +1,50 @@
1
- import { createClient as o } from "contentful";
1
+ import { createClient as y } from "contentful";
2
2
  class i {
3
3
  static _client;
4
+ static _clientParams;
4
5
  // static getter
6
+ static get clientParams() {
7
+ if (!this._clientParams)
8
+ throw new Error("Client is not configured");
9
+ return this._clientParams;
10
+ }
5
11
  static get client() {
6
- if (!this._client)
7
- throw new Error("Client is not initialized");
8
- return this._client;
12
+ return this._client || (this._client = y(this.clientParams)), this._client;
9
13
  }
10
14
  static configure(e) {
11
- this._client = o(e);
15
+ this._clientParams = {
16
+ ...e,
17
+ environment: e.environment ?? "master"
18
+ };
19
+ }
20
+ static async graphqlQuery(e, s = {}) {
21
+ const { space: n, accessToken: a, environment: c = "master" } = this.clientParams, r = await fetch(
22
+ `https://graphql.contentful.com/content/v1/spaces/${n}/environments/${c}`,
23
+ {
24
+ method: "POST",
25
+ headers: {
26
+ "Content-Type": "application/json",
27
+ Authorization: `Bearer ${a}`
28
+ },
29
+ body: JSON.stringify({ query: e, variables: s })
30
+ }
31
+ );
32
+ if (!r.ok) {
33
+ const d = await r.text();
34
+ throw new Error(
35
+ `GraphQL request failed: ${r.status} ${r.statusText}
36
+ ${d}`
37
+ );
38
+ }
39
+ const l = await r.json();
40
+ if (l.errors)
41
+ throw new Error(
42
+ `GraphQL errors: ${JSON.stringify(l.errors, null, 2)}`
43
+ );
44
+ return l.data;
12
45
  }
13
46
  }
14
- const d = async ({
47
+ const f = async ({
15
48
  query: t,
16
49
  marketId: e,
17
50
  language: s
@@ -25,7 +58,7 @@ const d = async ({
25
58
  content_type: "banner"
26
59
  }
27
60
  );
28
- class a extends Response {
61
+ class o extends Response {
29
62
  constructor(...e) {
30
63
  super(e[0] ?? "Not Found", {
31
64
  status: 404,
@@ -33,7 +66,7 @@ class a extends Response {
33
66
  });
34
67
  }
35
68
  }
36
- const c = async ({
69
+ const u = async ({
37
70
  query: t,
38
71
  marketId: e,
39
72
  language: s
@@ -53,7 +86,7 @@ const c = async ({
53
86
  content_type: "blogPost",
54
87
  ...t
55
88
  }
56
- ), f = async ({
89
+ ), m = async ({
57
90
  query: t,
58
91
  marketId: e,
59
92
  language: s
@@ -77,11 +110,11 @@ const c = async ({
77
110
  content_type: "blogPost",
78
111
  limit: 1,
79
112
  ...t
80
- }).then((l) => l.items.at(0));
113
+ }).then((a) => a.items.at(0));
81
114
  if (!n)
82
- throw new a();
115
+ throw new o();
83
116
  return n;
84
- }, y = async ({
117
+ }, k = async ({
85
118
  query: t,
86
119
  marketId: e,
87
120
  language: s
@@ -94,7 +127,7 @@ const c = async ({
94
127
  ...t,
95
128
  content_type: "documentationCategory"
96
129
  }
97
- ), g = async ({
130
+ ), p = async ({
98
131
  query: t,
99
132
  marketId: e,
100
133
  language: s
@@ -107,11 +140,11 @@ const c = async ({
107
140
  ...t,
108
141
  content_type: "documentationCategory",
109
142
  limit: 1
110
- }).then((l) => l.items.at(0));
143
+ }).then((a) => a.items.at(0));
111
144
  if (!n)
112
- throw new a();
145
+ throw new o();
113
146
  return n;
114
- }, u = ({
147
+ }, h = ({
115
148
  query: t,
116
149
  marketId: e,
117
150
  language: s
@@ -124,7 +157,7 @@ const c = async ({
124
157
  ...t,
125
158
  content_type: "documentationArticle"
126
159
  }
127
- ), m = async ({
160
+ ), w = async ({
128
161
  query: t,
129
162
  marketId: e,
130
163
  language: s
@@ -137,33 +170,55 @@ const c = async ({
137
170
  ...t,
138
171
  content_type: "documentationArticle",
139
172
  limit: 1
140
- }).then((l) => l.items.at(0));
173
+ }).then((a) => a.items.at(0));
141
174
  if (!n)
142
- throw new a();
175
+ throw new o();
143
176
  return n;
144
- }, k = async ({
145
- query: t,
146
- marketId: e,
147
- language: s
148
- }) => i.client.withoutUnresolvableLinks.getEntries(
149
- {
150
- "fields.market.sys.contentType.sys.id": "market",
151
- "fields.market.fields.marketId": e,
152
- "fields.language.sys.contentType.sys.id": "language",
153
- "fields.language.fields.code": s,
154
- select: ["fields.name", "fields.children"],
155
- content_type: "footerMenu",
156
- ...t
177
+ }, T = async ({
178
+ marketId: t,
179
+ language: e
180
+ }) => i.graphqlQuery(`
181
+ query ($marketId: String!, $language: String!) {
182
+ footerMenuCollection(where: {
183
+ market: {
184
+ OR: [
185
+ {
186
+ marketId_exists: false
187
+ }, {
188
+ marketId: $marketId
189
+ }
190
+ ]
191
+ },
192
+ language: {
193
+ code: $language
194
+ }
195
+ }) {
196
+ items {
197
+ sys { id }
198
+ name
199
+ childrenCollection {
200
+ items {
201
+ sys { id }
202
+ label
203
+ url
204
+ target
205
+ }
206
+ }
207
+ }
157
208
  }
158
- );
209
+ }
210
+ `, {
211
+ marketId: t,
212
+ language: e
213
+ });
159
214
  export {
160
215
  i as ContentfulSDK,
161
- f as findBlogPostEntry,
162
- m as findDocArticleEntry,
163
- g as findDocCategoryEntry,
164
- d as listBannerEntries,
165
- c as listBlogPostEntries,
166
- u as listDocArticleEntries,
167
- y as listDocCategoryEntries,
168
- k as listFooterMenuEntries
216
+ m as findBlogPostEntry,
217
+ w as findDocArticleEntry,
218
+ p as findDocCategoryEntry,
219
+ f as listBannerEntries,
220
+ u as listBlogPostEntries,
221
+ h as listDocArticleEntries,
222
+ k as listDocCategoryEntries,
223
+ T as listFooterMenuEntries
169
224
  };
@@ -75,7 +75,7 @@ export interface TypeFooterMenuFields {
75
75
  name: EntryFieldTypes.Symbol;
76
76
  children: EntryFieldTypes.Array<EntryFieldTypes.EntryLink<TypeHyperlinkSkeleton>>;
77
77
  language: EntryFieldTypes.EntryLink<TypeLanguageSkeleton>;
78
- market: EntryFieldTypes.EntryLink<TypeMarketSkeleton>;
78
+ market?: EntryFieldTypes.EntryLink<TypeMarketSkeleton>;
79
79
  }
80
80
  export type TypeFooterMenuSkeleton = EntrySkeletonType<TypeFooterMenuFields, "footerMenu">;
81
81
  export type TypeFooterMenu<Modifiers extends ChainModifiers, Locales extends LocaleCode = LocaleCode> = Entry<TypeFooterMenuSkeleton, Modifiers, Locales>;
@@ -83,6 +83,7 @@ export interface TypeHyperlinkFields {
83
83
  label: EntryFieldTypes.Symbol;
84
84
  url: EntryFieldTypes.Symbol;
85
85
  target: EntryFieldTypes.Symbol<"_blank" | "_self">;
86
+ basePath?: EntryFieldTypes.Symbol<"/{{country}}/{{language}}">;
86
87
  }
87
88
  export type TypeHyperlinkSkeleton = EntrySkeletonType<TypeHyperlinkFields, "hyperlink">;
88
89
  export type TypeHyperlink<Modifiers extends ChainModifiers, Locales extends LocaleCode = LocaleCode> = Entry<TypeHyperlinkSkeleton, Modifiers, Locales>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@janbox/contentful-marketplace-sdk",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",