@janbox/contentful-marketplace-sdk 1.0.1 → 1.0.2
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 +52 -24
- package/dist/entries/banner-collection.d.ts +3 -3
- package/dist/entries/blog.d.ts +24 -24
- package/dist/entries/brand-collection.d.ts +3 -3
- package/dist/entries/documentation.d.ts +24 -24
- package/dist/entries/hyperlink-collection.d.ts +3 -3
- package/dist/entries/keyword-collection.d.ts +3 -3
- package/dist/index.cjs +40 -91
- package/dist/index.js +369 -405
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ TypeScript SDK for querying iChiba marketplace content from Contentful GraphQL.
|
|
|
6
6
|
|
|
7
7
|
- Typed API for marketplace content entries.
|
|
8
8
|
- Built-in market/language filtering in query builders.
|
|
9
|
-
-
|
|
9
|
+
- Single-entry methods with 404 handling.
|
|
10
10
|
- Works in both ESM and CJS builds.
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
@@ -29,7 +29,7 @@ yarn add @janbox/contentful-marketplace-sdk contentful
|
|
|
29
29
|
```ts
|
|
30
30
|
import {
|
|
31
31
|
ContentfulSDK,
|
|
32
|
-
|
|
32
|
+
listBannerCollections,
|
|
33
33
|
} from "@janbox/contentful-marketplace-sdk";
|
|
34
34
|
import type { CreateClientParams } from "contentful";
|
|
35
35
|
|
|
@@ -41,7 +41,7 @@ const clientOptions: CreateClientParams = {
|
|
|
41
41
|
|
|
42
42
|
ContentfulSDK.configure(clientOptions);
|
|
43
43
|
|
|
44
|
-
const result = await
|
|
44
|
+
const result = await listBannerCollections({
|
|
45
45
|
slot: "home_hero",
|
|
46
46
|
marketCode: "vn",
|
|
47
47
|
language: "en",
|
|
@@ -78,10 +78,10 @@ All methods return `{ data: ... }`.
|
|
|
78
78
|
|
|
79
79
|
### Banner Collection
|
|
80
80
|
|
|
81
|
-
- `
|
|
81
|
+
- `listBannerCollections(options)`
|
|
82
82
|
|
|
83
83
|
```ts
|
|
84
|
-
await
|
|
84
|
+
await listBannerCollections({
|
|
85
85
|
slot: "home_hero",
|
|
86
86
|
limit: 20,
|
|
87
87
|
platform: "WEB",
|
|
@@ -92,71 +92,96 @@ await listBannerCollectionEntries({
|
|
|
92
92
|
|
|
93
93
|
### Blog
|
|
94
94
|
|
|
95
|
-
- `
|
|
96
|
-
- `
|
|
95
|
+
- `listBlogPosts(options?)`
|
|
96
|
+
- `getBlogPostDetail({ id } | { slug })`
|
|
97
97
|
|
|
98
98
|
```ts
|
|
99
|
-
const posts = await
|
|
99
|
+
const posts = await listBlogPosts({
|
|
100
100
|
marketCode: "vn",
|
|
101
101
|
language: "en",
|
|
102
102
|
limit: 10,
|
|
103
103
|
skip: 0,
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
-
const post = await
|
|
106
|
+
const post = await getBlogPostDetail({
|
|
107
107
|
slug: "how-to-shop-online",
|
|
108
108
|
marketCode: "vn",
|
|
109
109
|
language: "en",
|
|
110
110
|
});
|
|
111
|
+
|
|
112
|
+
const postById = await getBlogPostDetail({
|
|
113
|
+
id: "1a2b3c4d5e",
|
|
114
|
+
marketCode: "vn",
|
|
115
|
+
language: "en",
|
|
116
|
+
});
|
|
111
117
|
```
|
|
112
118
|
|
|
113
119
|
### Documentation
|
|
114
120
|
|
|
115
|
-
- `
|
|
116
|
-
- `
|
|
117
|
-
- `
|
|
118
|
-
- `
|
|
121
|
+
- `listDocCategories(options?)`
|
|
122
|
+
- `getDocCategoryDetail({ id } | { slug })`
|
|
123
|
+
- `listDocArticles(options?)`
|
|
124
|
+
- `getDocArticleDetail({ id } | { slug })`
|
|
119
125
|
|
|
120
126
|
```ts
|
|
121
|
-
const categories = await
|
|
127
|
+
const categories = await listDocCategories({
|
|
122
128
|
marketCode: "vn",
|
|
123
129
|
language: "en",
|
|
124
130
|
limit: 10,
|
|
125
131
|
});
|
|
126
132
|
|
|
127
|
-
const
|
|
133
|
+
const category = await getDocCategoryDetail({
|
|
134
|
+
slug: "getting-started",
|
|
135
|
+
marketCode: "vn",
|
|
136
|
+
language: "en",
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const categoryById = await getDocCategoryDetail({
|
|
140
|
+
id: "1a2b3c4d5e",
|
|
141
|
+
marketCode: "vn",
|
|
142
|
+
language: "en",
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const articles = await listDocArticles({
|
|
128
146
|
categorySlug: "getting-started",
|
|
129
147
|
marketCode: "vn",
|
|
130
148
|
language: "en",
|
|
131
149
|
limit: 10,
|
|
132
150
|
});
|
|
151
|
+
// listDocArticles returns summary fields only (no content, no seo)
|
|
133
152
|
|
|
134
|
-
const article = await
|
|
153
|
+
const article = await getDocArticleDetail({
|
|
135
154
|
slug: "payment-methods",
|
|
136
155
|
marketCode: "vn",
|
|
137
156
|
language: "en",
|
|
138
157
|
});
|
|
158
|
+
|
|
159
|
+
const articleById = await getDocArticleDetail({
|
|
160
|
+
id: "1a2b3c4d5e",
|
|
161
|
+
marketCode: "vn",
|
|
162
|
+
language: "en",
|
|
163
|
+
});
|
|
139
164
|
```
|
|
140
165
|
|
|
141
166
|
### Brand / Hyperlink / Keyword Collections
|
|
142
167
|
|
|
143
|
-
- `
|
|
144
|
-
- `
|
|
145
|
-
- `
|
|
168
|
+
- `listBrandCollections(options?)`
|
|
169
|
+
- `listHyperlinkCollections(options?)`
|
|
170
|
+
- `listKeywordCollections(options?)`
|
|
146
171
|
|
|
147
172
|
```ts
|
|
148
|
-
const brands = await
|
|
173
|
+
const brands = await listBrandCollections({
|
|
149
174
|
marketCode: "vn",
|
|
150
175
|
language: "en",
|
|
151
176
|
limit: 20,
|
|
152
177
|
});
|
|
153
178
|
|
|
154
|
-
const links = await
|
|
179
|
+
const links = await listHyperlinkCollections({
|
|
155
180
|
marketCode: "vn",
|
|
156
181
|
language: "en",
|
|
157
182
|
});
|
|
158
183
|
|
|
159
|
-
const keywords = await
|
|
184
|
+
const keywords = await listKeywordCollections({
|
|
160
185
|
marketCode: "vn",
|
|
161
186
|
language: "en",
|
|
162
187
|
limit: 20,
|
|
@@ -165,11 +190,14 @@ const keywords = await listKeywordCollectionEntries({
|
|
|
165
190
|
|
|
166
191
|
## Error Handling
|
|
167
192
|
|
|
168
|
-
`
|
|
193
|
+
`getBlogPostDetail`, `getDocCategoryDetail`, and `getDocArticleDetail` throw:
|
|
194
|
+
|
|
195
|
+
- `Error("Either id or slug is required.")` if neither `id` nor `slug` is provided.
|
|
196
|
+
- `Response` with status `404` when no entry is found.
|
|
169
197
|
|
|
170
198
|
```ts
|
|
171
199
|
try {
|
|
172
|
-
await
|
|
200
|
+
await getDocArticleDetail({ slug: "unknown-slug" });
|
|
173
201
|
} catch (error) {
|
|
174
202
|
if (error instanceof Response && error.status === 404) {
|
|
175
203
|
console.log("Entry not found");
|
|
@@ -21,14 +21,14 @@ export type BannerCollectionGraphQLItem = {
|
|
|
21
21
|
}>;
|
|
22
22
|
};
|
|
23
23
|
} & Pick<BannerCollectionEntry["fields"], "name" | "slot" | "platform">;
|
|
24
|
-
export type
|
|
24
|
+
export type ListBannerCollectionsResponse = {
|
|
25
25
|
data: BannerCollectionGraphQLItem[];
|
|
26
26
|
};
|
|
27
|
-
export declare const
|
|
27
|
+
export declare const listBannerCollections: ({ slot, limit, platform, marketCode, language, }: {
|
|
28
28
|
slot: BannerCollectionEntry["fields"]["slot"];
|
|
29
29
|
limit?: number;
|
|
30
30
|
platform?: BannerCollectionEntry["fields"]["platform"][number];
|
|
31
31
|
marketCode?: string;
|
|
32
32
|
language?: string;
|
|
33
|
-
}) => Promise<
|
|
33
|
+
}) => Promise<ListBannerCollectionsResponse>;
|
|
34
34
|
export {};
|
package/dist/entries/blog.d.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
1
|
import { TypeBlogPostSkeleton } from '../types';
|
|
2
2
|
import { Entry, EntrySys } from 'contentful';
|
|
3
3
|
type BlogPostEntry = Entry<TypeBlogPostSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>;
|
|
4
|
-
type GraphQLEntrySys = Pick<EntrySys, "id">;
|
|
4
|
+
type GraphQLEntrySys = Pick<EntrySys, "id" | "createdAt" | "updatedAt">;
|
|
5
5
|
type GraphQLAsset = {
|
|
6
6
|
url: string;
|
|
7
7
|
width: number | null;
|
|
8
8
|
height: number | null;
|
|
9
9
|
contentType: string;
|
|
10
10
|
};
|
|
11
|
+
type GraphQLSeo = {
|
|
12
|
+
metaTitle: string;
|
|
13
|
+
metaDescription: string | null;
|
|
14
|
+
metaKeywords: string[] | null;
|
|
15
|
+
metaRobots: string[] | null;
|
|
16
|
+
};
|
|
17
|
+
type BlogPostCategoryGraphQLItem = {
|
|
18
|
+
title: string;
|
|
19
|
+
slug: string;
|
|
20
|
+
};
|
|
11
21
|
export type BlogPostGraphQLItem = {
|
|
12
22
|
sys: GraphQLEntrySys;
|
|
13
|
-
category:
|
|
14
|
-
sys: GraphQLEntrySys;
|
|
15
|
-
title: string;
|
|
16
|
-
slug: string;
|
|
17
|
-
} | null;
|
|
23
|
+
category: BlogPostCategoryGraphQLItem | null;
|
|
18
24
|
featuredImage: GraphQLAsset | null;
|
|
19
25
|
} & Pick<BlogPostEntry["fields"], "title" | "shortDescription" | "slug">;
|
|
20
|
-
export
|
|
26
|
+
export interface BlogPostDetailGraphQLItem extends BlogPostGraphQLItem {
|
|
21
27
|
author: {
|
|
22
|
-
sys: GraphQLEntrySys;
|
|
23
28
|
name: string;
|
|
24
29
|
avatar: GraphQLAsset | null;
|
|
25
30
|
} | null;
|
|
26
31
|
content: {
|
|
27
32
|
json: BlogPostEntry["fields"]["content"];
|
|
28
|
-
}
|
|
29
|
-
seo:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
metaDescription: string | null;
|
|
33
|
-
metaKeywords: string[] | null;
|
|
34
|
-
metaRobots: string[] | null;
|
|
35
|
-
} | null;
|
|
36
|
-
};
|
|
37
|
-
export type ListBlogPostEntriesResponse = {
|
|
33
|
+
};
|
|
34
|
+
seo: GraphQLSeo | null;
|
|
35
|
+
}
|
|
36
|
+
export type ListBlogPostsResponse = {
|
|
38
37
|
data: BlogPostGraphQLItem[];
|
|
39
38
|
};
|
|
40
|
-
export type
|
|
39
|
+
export type GetBlogPostDetailResponse = {
|
|
41
40
|
data: BlogPostDetailGraphQLItem;
|
|
42
41
|
};
|
|
43
|
-
export declare const
|
|
42
|
+
export declare const listBlogPosts: ({ marketCode, language, limit, skip, }?: {
|
|
44
43
|
marketCode?: string;
|
|
45
44
|
language?: string;
|
|
46
45
|
limit?: number;
|
|
47
46
|
skip?: number;
|
|
48
|
-
}) => Promise<
|
|
49
|
-
export declare const
|
|
50
|
-
|
|
47
|
+
}) => Promise<ListBlogPostsResponse>;
|
|
48
|
+
export declare const getBlogPostDetail: ({ id, slug, marketCode, language, }: {
|
|
49
|
+
id?: string;
|
|
50
|
+
slug?: string;
|
|
51
51
|
marketCode?: string;
|
|
52
52
|
language?: string;
|
|
53
|
-
}) => Promise<
|
|
53
|
+
}) => Promise<GetBlogPostDetailResponse>;
|
|
54
54
|
export {};
|
|
@@ -11,12 +11,12 @@ export type BrandCollectionGraphQLItem = {
|
|
|
11
11
|
} & Pick<BrandEntry["fields"], "name" | "slug">>;
|
|
12
12
|
};
|
|
13
13
|
} & Pick<BrandCollectionEntry["fields"], "name" | "slot">;
|
|
14
|
-
export type
|
|
14
|
+
export type ListBrandCollectionsResponse = {
|
|
15
15
|
data: BrandCollectionGraphQLItem[];
|
|
16
16
|
};
|
|
17
|
-
export declare const
|
|
17
|
+
export declare const listBrandCollections: ({ limit, marketCode, language, }?: {
|
|
18
18
|
limit?: number;
|
|
19
19
|
marketCode?: string;
|
|
20
20
|
language?: string;
|
|
21
|
-
}) => Promise<
|
|
21
|
+
}) => Promise<ListBrandCollectionsResponse>;
|
|
22
22
|
export {};
|
|
@@ -2,7 +2,7 @@ import { TypeDocumentationArticleSkeleton, TypeDocumentationCategorySkeleton } f
|
|
|
2
2
|
import { Entry, EntrySys } from 'contentful';
|
|
3
3
|
export type DocCategoryEntry = Entry<TypeDocumentationCategorySkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>;
|
|
4
4
|
export type DocArticleEntry = Entry<TypeDocumentationArticleSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>;
|
|
5
|
-
type GraphQLEntrySys = Pick<EntrySys, "id">;
|
|
5
|
+
type GraphQLEntrySys = Pick<EntrySys, "id" | "createdAt" | "updatedAt">;
|
|
6
6
|
type GraphQLAsset = {
|
|
7
7
|
url: string | null;
|
|
8
8
|
width: number | null;
|
|
@@ -10,7 +10,6 @@ type GraphQLAsset = {
|
|
|
10
10
|
contentType: string | null;
|
|
11
11
|
};
|
|
12
12
|
type GraphQLSeo = {
|
|
13
|
-
sys: GraphQLEntrySys;
|
|
14
13
|
metaTitle: string;
|
|
15
14
|
metaDescription: string | null;
|
|
16
15
|
metaKeywords: string[] | null;
|
|
@@ -20,55 +19,56 @@ export type DocCategoryGraphQLItem = {
|
|
|
20
19
|
sys: GraphQLEntrySys;
|
|
21
20
|
seo: GraphQLSeo | null;
|
|
22
21
|
} & Pick<DocCategoryEntry["fields"], "title" | "slug" | "description" | "order">;
|
|
22
|
+
type DocArticleCategoryGraphQLItem = Pick<DocCategoryEntry["fields"], "title" | "slug" | "description" | "order">;
|
|
23
23
|
export type DocArticleGraphQLItem = {
|
|
24
24
|
sys: GraphQLEntrySys;
|
|
25
|
-
category:
|
|
26
|
-
sys: GraphQLEntrySys;
|
|
27
|
-
seo: GraphQLSeo | null;
|
|
28
|
-
} & Pick<DocCategoryEntry["fields"], "title" | "slug" | "description" | "order">) | null;
|
|
25
|
+
category: DocArticleCategoryGraphQLItem;
|
|
29
26
|
author: {
|
|
30
|
-
sys: GraphQLEntrySys;
|
|
31
27
|
name: string;
|
|
32
28
|
avatar: GraphQLAsset | null;
|
|
33
29
|
} | null;
|
|
30
|
+
} & Pick<DocArticleEntry["fields"], "title" | "slug">;
|
|
31
|
+
export interface DocArticleDetailGraphQLItem extends DocArticleGraphQLItem {
|
|
34
32
|
content: {
|
|
35
33
|
json: DocArticleEntry["fields"]["content"];
|
|
36
|
-
}
|
|
34
|
+
};
|
|
37
35
|
seo: GraphQLSeo | null;
|
|
38
|
-
}
|
|
39
|
-
export type
|
|
36
|
+
}
|
|
37
|
+
export type ListDocCategoriesResponse = {
|
|
40
38
|
data: DocCategoryGraphQLItem[];
|
|
41
39
|
};
|
|
42
|
-
export type
|
|
40
|
+
export type GetDocCategoryDetailResponse = {
|
|
43
41
|
data: DocCategoryGraphQLItem;
|
|
44
42
|
};
|
|
45
|
-
export type
|
|
43
|
+
export type ListDocArticlesResponse = {
|
|
46
44
|
data: DocArticleGraphQLItem[];
|
|
47
45
|
};
|
|
48
|
-
export type
|
|
49
|
-
data:
|
|
46
|
+
export type GetDocArticleDetailResponse = {
|
|
47
|
+
data: DocArticleDetailGraphQLItem;
|
|
50
48
|
};
|
|
51
|
-
export declare const
|
|
49
|
+
export declare const listDocCategories: ({ marketCode, language, limit, skip, }?: {
|
|
52
50
|
marketCode?: string;
|
|
53
51
|
language?: string;
|
|
54
52
|
limit?: number;
|
|
55
53
|
skip?: number;
|
|
56
|
-
}) => Promise<
|
|
57
|
-
export declare const
|
|
58
|
-
|
|
54
|
+
}) => Promise<ListDocCategoriesResponse>;
|
|
55
|
+
export declare const getDocCategoryDetail: ({ id, slug, marketCode, language, }: {
|
|
56
|
+
id?: string;
|
|
57
|
+
slug?: string;
|
|
59
58
|
marketCode?: string;
|
|
60
59
|
language?: string;
|
|
61
|
-
}) => Promise<
|
|
62
|
-
export declare const
|
|
60
|
+
}) => Promise<GetDocCategoryDetailResponse>;
|
|
61
|
+
export declare const listDocArticles: ({ marketCode, language, categorySlug, limit, skip, }?: {
|
|
63
62
|
marketCode?: string;
|
|
64
63
|
language?: string;
|
|
65
64
|
categorySlug?: string;
|
|
66
65
|
limit?: number;
|
|
67
66
|
skip?: number;
|
|
68
|
-
}) => Promise<
|
|
69
|
-
export declare const
|
|
70
|
-
|
|
67
|
+
}) => Promise<ListDocArticlesResponse>;
|
|
68
|
+
export declare const getDocArticleDetail: ({ id, slug, marketCode, language, }: {
|
|
69
|
+
id?: string;
|
|
70
|
+
slug?: string;
|
|
71
71
|
marketCode?: string;
|
|
72
72
|
language?: string;
|
|
73
|
-
}) => Promise<
|
|
73
|
+
}) => Promise<GetDocArticleDetailResponse>;
|
|
74
74
|
export {};
|
|
@@ -11,11 +11,11 @@ export type HyperlinkCollectionGraphQLItem = {
|
|
|
11
11
|
} & Pick<HyperlinkEntry["fields"], "label" | "url" | "target" | "includesMarketCode">>;
|
|
12
12
|
};
|
|
13
13
|
} & Pick<HyperlinkCollectionEntry["fields"], "name" | "slot" | "order">;
|
|
14
|
-
export type
|
|
14
|
+
export type ListHyperlinkCollectionsResponse = {
|
|
15
15
|
data: HyperlinkCollectionGraphQLItem[];
|
|
16
16
|
};
|
|
17
|
-
export declare const
|
|
17
|
+
export declare const listHyperlinkCollections: ({ marketCode, language, }?: {
|
|
18
18
|
marketCode?: string;
|
|
19
19
|
language?: string;
|
|
20
|
-
}) => Promise<
|
|
20
|
+
}) => Promise<ListHyperlinkCollectionsResponse>;
|
|
21
21
|
export {};
|
|
@@ -5,12 +5,12 @@ type GraphQLEntrySys = Pick<EntrySys, "id">;
|
|
|
5
5
|
export type KeywordCollectionGraphQLItem = {
|
|
6
6
|
sys: GraphQLEntrySys;
|
|
7
7
|
} & Pick<KeywordCollectionEntry["fields"], "name" | "slot" | "keywords">;
|
|
8
|
-
export type
|
|
8
|
+
export type ListKeywordCollectionsResponse = {
|
|
9
9
|
data: KeywordCollectionGraphQLItem[];
|
|
10
10
|
};
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const listKeywordCollections: ({ limit, marketCode, language, }?: {
|
|
12
12
|
limit?: number;
|
|
13
13
|
marketCode?: string;
|
|
14
14
|
language?: string;
|
|
15
|
-
}) => Promise<
|
|
15
|
+
}) => Promise<ListKeywordCollectionsResponse>;
|
|
16
16
|
export {};
|