@janbox/contentful-marketplace-sdk 0.0.3 → 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.
- package/dist/client/index.d.ts +3 -0
- package/dist/entries/footer-menu.d.ts +24 -0
- package/dist/entries/index.d.ts +1 -0
- package/dist/index.cjs +32 -1
- package/dist/index.js +97 -27
- package/dist/types/index.d.ts +25 -0
- package/package.json +6 -3
package/dist/client/index.d.ts
CHANGED
|
@@ -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
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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, }: {
|
|
22
|
+
marketId: string;
|
|
23
|
+
language: string;
|
|
24
|
+
}) => Promise<FooterMenuGraphQLResponse>;
|
package/dist/entries/index.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1 +1,32 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
|
|
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
|
-
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
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
|
-
),
|
|
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((
|
|
113
|
+
}).then((a) => a.items.at(0));
|
|
81
114
|
if (!n)
|
|
82
|
-
throw new
|
|
115
|
+
throw new o();
|
|
83
116
|
return n;
|
|
84
|
-
},
|
|
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
|
-
),
|
|
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((
|
|
143
|
+
}).then((a) => a.items.at(0));
|
|
111
144
|
if (!n)
|
|
112
|
-
throw new
|
|
145
|
+
throw new o();
|
|
113
146
|
return n;
|
|
114
|
-
},
|
|
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
|
-
),
|
|
160
|
+
), w = async ({
|
|
128
161
|
query: t,
|
|
129
162
|
marketId: e,
|
|
130
163
|
language: s
|
|
@@ -137,18 +170,55 @@ const c = async ({
|
|
|
137
170
|
...t,
|
|
138
171
|
content_type: "documentationArticle",
|
|
139
172
|
limit: 1
|
|
140
|
-
}).then((
|
|
173
|
+
}).then((a) => a.items.at(0));
|
|
141
174
|
if (!n)
|
|
142
|
-
throw new
|
|
175
|
+
throw new o();
|
|
143
176
|
return n;
|
|
144
|
-
}
|
|
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
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
`, {
|
|
211
|
+
marketId: t,
|
|
212
|
+
language: e
|
|
213
|
+
});
|
|
145
214
|
export {
|
|
146
215
|
i as ContentfulSDK,
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
|
154
224
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -71,6 +71,22 @@ export interface TypeDocumentationCategoryFields {
|
|
|
71
71
|
}
|
|
72
72
|
export type TypeDocumentationCategorySkeleton = EntrySkeletonType<TypeDocumentationCategoryFields, "documentationCategory">;
|
|
73
73
|
export type TypeDocumentationCategory<Modifiers extends ChainModifiers, Locales extends LocaleCode = LocaleCode> = Entry<TypeDocumentationCategorySkeleton, Modifiers, Locales>;
|
|
74
|
+
export interface TypeFooterMenuFields {
|
|
75
|
+
name: EntryFieldTypes.Symbol;
|
|
76
|
+
children: EntryFieldTypes.Array<EntryFieldTypes.EntryLink<TypeHyperlinkSkeleton>>;
|
|
77
|
+
language: EntryFieldTypes.EntryLink<TypeLanguageSkeleton>;
|
|
78
|
+
market?: EntryFieldTypes.EntryLink<TypeMarketSkeleton>;
|
|
79
|
+
}
|
|
80
|
+
export type TypeFooterMenuSkeleton = EntrySkeletonType<TypeFooterMenuFields, "footerMenu">;
|
|
81
|
+
export type TypeFooterMenu<Modifiers extends ChainModifiers, Locales extends LocaleCode = LocaleCode> = Entry<TypeFooterMenuSkeleton, Modifiers, Locales>;
|
|
82
|
+
export interface TypeHyperlinkFields {
|
|
83
|
+
label: EntryFieldTypes.Symbol;
|
|
84
|
+
url: EntryFieldTypes.Symbol;
|
|
85
|
+
target: EntryFieldTypes.Symbol<"_blank" | "_self">;
|
|
86
|
+
basePath?: EntryFieldTypes.Symbol<"/{{country}}/{{language}}">;
|
|
87
|
+
}
|
|
88
|
+
export type TypeHyperlinkSkeleton = EntrySkeletonType<TypeHyperlinkFields, "hyperlink">;
|
|
89
|
+
export type TypeHyperlink<Modifiers extends ChainModifiers, Locales extends LocaleCode = LocaleCode> = Entry<TypeHyperlinkSkeleton, Modifiers, Locales>;
|
|
74
90
|
export interface TypeLanguageFields {
|
|
75
91
|
name: EntryFieldTypes.Symbol;
|
|
76
92
|
code: EntryFieldTypes.Symbol;
|
|
@@ -89,6 +105,15 @@ export interface TypeMarketFields {
|
|
|
89
105
|
}
|
|
90
106
|
export type TypeMarketSkeleton = EntrySkeletonType<TypeMarketFields, "market">;
|
|
91
107
|
export type TypeMarket<Modifiers extends ChainModifiers, Locales extends LocaleCode = LocaleCode> = Entry<TypeMarketSkeleton, Modifiers, Locales>;
|
|
108
|
+
export interface TypeNoticeFields {
|
|
109
|
+
title: EntryFieldTypes.Symbol;
|
|
110
|
+
content: EntryFieldTypes.RichText;
|
|
111
|
+
market: EntryFieldTypes.EntryLink<TypeMarketSkeleton>;
|
|
112
|
+
language: EntryFieldTypes.EntryLink<TypeLanguageSkeleton>;
|
|
113
|
+
variant?: EntryFieldTypes.Array<EntryFieldTypes.Symbol<"Featured" | "Promotion" | "Urgent">>;
|
|
114
|
+
}
|
|
115
|
+
export type TypeNoticeSkeleton = EntrySkeletonType<TypeNoticeFields, "notice">;
|
|
116
|
+
export type TypeNotice<Modifiers extends ChainModifiers, Locales extends LocaleCode = LocaleCode> = Entry<TypeNoticeSkeleton, Modifiers, Locales>;
|
|
92
117
|
export interface TypeSeoFields {
|
|
93
118
|
metaTitle: EntryFieldTypes.Symbol;
|
|
94
119
|
metaDescription?: EntryFieldTypes.Text;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@janbox/contentful-marketplace-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"main": "./dist/index.cjs",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -21,7 +21,10 @@
|
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"dev": "vite",
|
|
24
|
-
"build": "tsc && vite build",
|
|
25
|
-
"preview": "vite preview"
|
|
24
|
+
"build": "tsc -p tsconfig.build.json && vite build",
|
|
25
|
+
"preview": "vite preview",
|
|
26
|
+
"test": "vitest",
|
|
27
|
+
"test:ui": "vitest --ui",
|
|
28
|
+
"test:coverage": "vitest --coverage"
|
|
26
29
|
}
|
|
27
30
|
}
|