@janbox/contentful-marketplace-sdk 1.0.0 → 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 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
- - `find*` methods with 404 handling.
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
- listBannerCollectionEntries,
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 listBannerCollectionEntries({
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
- - `listBannerCollectionEntries(options)`
81
+ - `listBannerCollections(options)`
82
82
 
83
83
  ```ts
84
- await listBannerCollectionEntries({
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
- - `listBlogPostEntries(options?)`
96
- - `findBlogPostEntry(options)`
95
+ - `listBlogPosts(options?)`
96
+ - `getBlogPostDetail({ id } | { slug })`
97
97
 
98
98
  ```ts
99
- const posts = await listBlogPostEntries({
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 findBlogPostEntry({
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
- - `listDocCategoryEntries(options?)`
116
- - `findDocCategoryEntry(options)`
117
- - `listDocArticleEntries(options?)`
118
- - `findDocArticleEntry(options)`
121
+ - `listDocCategories(options?)`
122
+ - `getDocCategoryDetail({ id } | { slug })`
123
+ - `listDocArticles(options?)`
124
+ - `getDocArticleDetail({ id } | { slug })`
119
125
 
120
126
  ```ts
121
- const categories = await listDocCategoryEntries({
127
+ const categories = await listDocCategories({
122
128
  marketCode: "vn",
123
129
  language: "en",
124
130
  limit: 10,
125
131
  });
126
132
 
127
- const articles = await listDocArticleEntries({
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 findDocArticleEntry({
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
- - `listBrandCollectionEntries(options?)`
144
- - `listHyperlinkCollectionEntries(options?)`
145
- - `listKeywordCollectionEntries(options?)`
168
+ - `listBrandCollections(options?)`
169
+ - `listHyperlinkCollections(options?)`
170
+ - `listKeywordCollections(options?)`
146
171
 
147
172
  ```ts
148
- const brands = await listBrandCollectionEntries({
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 listHyperlinkCollectionEntries({
179
+ const links = await listHyperlinkCollections({
155
180
  marketCode: "vn",
156
181
  language: "en",
157
182
  });
158
183
 
159
- const keywords = await listKeywordCollectionEntries({
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
- `findBlogPostEntry`, `findDocCategoryEntry`, and `findDocArticleEntry` throw a `Response` with status `404` when not found.
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 findDocArticleEntry({ slug: "unknown-slug" });
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");
@@ -3,7 +3,7 @@ import { Entry, EntrySys } from 'contentful';
3
3
  import { HyperlinkEntry } from './hyperlink';
4
4
  type BannerCollectionEntry = Entry<TypeBannerCollectionSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>;
5
5
  type GraphQLEntrySys = Pick<EntrySys, "id">;
6
- type BannerCollectionGraphQLItem = {
6
+ export type BannerCollectionGraphQLItem = {
7
7
  sys: GraphQLEntrySys;
8
8
  bannersCollection: {
9
9
  items: Array<{
@@ -21,19 +21,14 @@ type BannerCollectionGraphQLItem = {
21
21
  }>;
22
22
  };
23
23
  } & Pick<BannerCollectionEntry["fields"], "name" | "slot" | "platform">;
24
- type BannerCollectionGraphQLResponse = {
25
- bannerCollectionCollection: {
26
- items: Array<BannerCollectionGraphQLItem>;
27
- };
28
- };
29
- export type ListBannerCollectionEntriesResponse = {
30
- data: BannerCollectionGraphQLResponse["bannerCollectionCollection"]["items"];
24
+ export type ListBannerCollectionsResponse = {
25
+ data: BannerCollectionGraphQLItem[];
31
26
  };
32
- export declare const listBannerCollectionEntries: ({ slot, limit, platform, marketCode, language, }: {
27
+ export declare const listBannerCollections: ({ slot, limit, platform, marketCode, language, }: {
33
28
  slot: BannerCollectionEntry["fields"]["slot"];
34
29
  limit?: number;
35
30
  platform?: BannerCollectionEntry["fields"]["platform"][number];
36
31
  marketCode?: string;
37
32
  language?: string;
38
- }) => Promise<ListBannerCollectionEntriesResponse>;
33
+ }) => Promise<ListBannerCollectionsResponse>;
39
34
  export {};
@@ -1,59 +1,54 @@
1
1
  import { TypeBlogPostSkeleton } from '../types';
2
2
  import { Entry, EntrySys } from 'contentful';
3
- export type BlogPostEntry = Entry<TypeBlogPostSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>;
4
- type GraphQLEntrySys = Pick<EntrySys, "id">;
3
+ type BlogPostEntry = Entry<TypeBlogPostSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>;
4
+ type GraphQLEntrySys = Pick<EntrySys, "id" | "createdAt" | "updatedAt">;
5
5
  type GraphQLAsset = {
6
- url: string | null;
6
+ url: string;
7
7
  width: number | null;
8
8
  height: number | null;
9
- contentType: string | null;
9
+ contentType: string;
10
10
  };
11
- type BlogPostGraphQLItem = {
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
+ };
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
- type BlogPostDetailGraphQLItem = BlogPostGraphQLItem & {
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
- } | null;
29
- seo: {
30
- sys: GraphQLEntrySys;
31
- metaTitle: string;
32
- metaDescription: string | null;
33
- metaKeywords: string[] | null;
34
- metaRobots: string[] | null;
35
- } | null;
36
- };
37
- type BlogPostGraphQLResponse = {
38
- blogPostCollection: {
39
- items: Array<BlogPostGraphQLItem>;
40
33
  };
34
+ seo: GraphQLSeo | null;
35
+ }
36
+ export type ListBlogPostsResponse = {
37
+ data: BlogPostGraphQLItem[];
41
38
  };
42
- export type ListBlogPostEntriesResponse = {
43
- data: BlogPostGraphQLResponse["blogPostCollection"]["items"];
44
- };
45
- export type FindBlogPostEntryResponse = {
39
+ export type GetBlogPostDetailResponse = {
46
40
  data: BlogPostDetailGraphQLItem;
47
41
  };
48
- export declare const listBlogPostEntries: ({ marketCode, language, limit, skip, }?: {
42
+ export declare const listBlogPosts: ({ marketCode, language, limit, skip, }?: {
49
43
  marketCode?: string;
50
44
  language?: string;
51
45
  limit?: number;
52
46
  skip?: number;
53
- }) => Promise<ListBlogPostEntriesResponse>;
54
- export declare const findBlogPostEntry: ({ slug, marketCode, language, }: {
55
- slug: string;
47
+ }) => Promise<ListBlogPostsResponse>;
48
+ export declare const getBlogPostDetail: ({ id, slug, marketCode, language, }: {
49
+ id?: string;
50
+ slug?: string;
56
51
  marketCode?: string;
57
52
  language?: string;
58
- }) => Promise<FindBlogPostEntryResponse>;
53
+ }) => Promise<GetBlogPostDetailResponse>;
59
54
  export {};
@@ -1,26 +1,22 @@
1
- import { TypeBrandCollectionSkeleton } from '../types';
1
+ import { TypeBrandCollectionSkeleton, TypeBrandSkeleton } from '../types';
2
2
  import { Entry, EntrySys } from 'contentful';
3
- import { BrandEntry } from './brand';
3
+ type BrandEntry = Entry<TypeBrandSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>;
4
4
  type BrandCollectionEntry = Entry<TypeBrandCollectionSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>;
5
5
  type GraphQLEntrySys = Pick<EntrySys, "id">;
6
- type BrandCollectionGraphQLResponse = {
7
- brandCollectionCollection: {
6
+ export type BrandCollectionGraphQLItem = {
7
+ sys: GraphQLEntrySys;
8
+ brandsCollection: {
8
9
  items: Array<{
9
10
  sys: GraphQLEntrySys;
10
- brandsCollection: {
11
- items: Array<{
12
- sys: GraphQLEntrySys;
13
- } & Pick<BrandEntry["fields"], "name" | "slug">>;
14
- };
15
- } & Pick<BrandCollectionEntry["fields"], "name" | "slot">>;
11
+ } & Pick<BrandEntry["fields"], "name" | "slug">>;
16
12
  };
13
+ } & Pick<BrandCollectionEntry["fields"], "name" | "slot">;
14
+ export type ListBrandCollectionsResponse = {
15
+ data: BrandCollectionGraphQLItem[];
17
16
  };
18
- export type ListBrandCollectionEntriesResponse = {
19
- data: BrandCollectionGraphQLResponse["brandCollectionCollection"]["items"];
20
- };
21
- export declare const listBrandCollectionEntries: ({ limit, marketCode, language, }?: {
17
+ export declare const listBrandCollections: ({ limit, marketCode, language, }?: {
22
18
  limit?: number;
23
19
  marketCode?: string;
24
20
  language?: string;
25
- }) => Promise<ListBrandCollectionEntriesResponse>;
21
+ }) => Promise<ListBrandCollectionsResponse>;
26
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,75 +10,65 @@ 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;
17
16
  metaRobots: string[] | null;
18
17
  };
19
- type DocCategoryGraphQLItem = {
18
+ export type DocCategoryGraphQLItem = {
20
19
  sys: GraphQLEntrySys;
21
20
  seo: GraphQLSeo | null;
22
21
  } & Pick<DocCategoryEntry["fields"], "title" | "slug" | "description" | "order">;
23
- type DocArticleGraphQLItem = {
22
+ type DocArticleCategoryGraphQLItem = Pick<DocCategoryEntry["fields"], "title" | "slug" | "description" | "order">;
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
- } | null;
37
- seo: GraphQLSeo | null;
38
- } & Pick<DocArticleEntry["fields"], "title" | "slug">;
39
- type DocCategoryGraphQLResponse = {
40
- documentationCategoryCollection: {
41
- items: Array<DocCategoryGraphQLItem>;
42
34
  };
35
+ seo: GraphQLSeo | null;
36
+ }
37
+ export type ListDocCategoriesResponse = {
38
+ data: DocCategoryGraphQLItem[];
43
39
  };
44
- type DocArticleGraphQLResponse = {
45
- documentationArticleCollection: {
46
- items: Array<DocArticleGraphQLItem>;
47
- };
48
- };
49
- export type ListDocCategoryEntriesResponse = {
50
- data: DocCategoryGraphQLResponse["documentationCategoryCollection"]["items"];
51
- };
52
- export type FindDocCategoryEntryResponse = {
40
+ export type GetDocCategoryDetailResponse = {
53
41
  data: DocCategoryGraphQLItem;
54
42
  };
55
- export type ListDocArticleEntriesResponse = {
56
- data: DocArticleGraphQLResponse["documentationArticleCollection"]["items"];
43
+ export type ListDocArticlesResponse = {
44
+ data: DocArticleGraphQLItem[];
57
45
  };
58
- export type FindDocArticleEntryResponse = {
59
- data: DocArticleGraphQLResponse["documentationArticleCollection"]["items"][number];
46
+ export type GetDocArticleDetailResponse = {
47
+ data: DocArticleDetailGraphQLItem;
60
48
  };
61
- export declare const listDocCategoryEntries: ({ marketCode, language, limit, skip, }?: {
49
+ export declare const listDocCategories: ({ marketCode, language, limit, skip, }?: {
62
50
  marketCode?: string;
63
51
  language?: string;
64
52
  limit?: number;
65
53
  skip?: number;
66
- }) => Promise<ListDocCategoryEntriesResponse>;
67
- export declare const findDocCategoryEntry: ({ slug, marketCode, language, }: {
68
- slug: string;
54
+ }) => Promise<ListDocCategoriesResponse>;
55
+ export declare const getDocCategoryDetail: ({ id, slug, marketCode, language, }: {
56
+ id?: string;
57
+ slug?: string;
69
58
  marketCode?: string;
70
59
  language?: string;
71
- }) => Promise<FindDocCategoryEntryResponse>;
72
- export declare const listDocArticleEntries: ({ marketCode, language, categorySlug, limit, skip, }?: {
60
+ }) => Promise<GetDocCategoryDetailResponse>;
61
+ export declare const listDocArticles: ({ marketCode, language, categorySlug, limit, skip, }?: {
73
62
  marketCode?: string;
74
63
  language?: string;
75
64
  categorySlug?: string;
76
65
  limit?: number;
77
66
  skip?: number;
78
- }) => Promise<ListDocArticleEntriesResponse>;
79
- export declare const findDocArticleEntry: ({ slug, marketCode, language, }: {
80
- slug: string;
67
+ }) => Promise<ListDocArticlesResponse>;
68
+ export declare const getDocArticleDetail: ({ id, slug, marketCode, language, }: {
69
+ id?: string;
70
+ slug?: string;
81
71
  marketCode?: string;
82
72
  language?: string;
83
- }) => Promise<FindDocArticleEntryResponse>;
73
+ }) => Promise<GetDocArticleDetailResponse>;
84
74
  export {};
@@ -3,23 +3,19 @@ import { Entry, EntrySys } from 'contentful';
3
3
  import { HyperlinkEntry } from './hyperlink';
4
4
  type HyperlinkCollectionEntry = Entry<TypeHyperlinkCollectionSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>;
5
5
  type GraphQLEntrySys = Pick<EntrySys, "id">;
6
- type HyperlinkCollectionGraphQLResponse = {
7
- hyperlinkCollectionCollection: {
6
+ export type HyperlinkCollectionGraphQLItem = {
7
+ sys: GraphQLEntrySys;
8
+ linksCollection: {
8
9
  items: Array<{
9
10
  sys: GraphQLEntrySys;
10
- linksCollection: {
11
- items: Array<{
12
- sys: GraphQLEntrySys;
13
- } & Pick<HyperlinkEntry["fields"], "label" | "url" | "target" | "includesMarketCode">>;
14
- };
15
- } & Pick<HyperlinkCollectionEntry["fields"], "name" | "slot" | "order">>;
11
+ } & Pick<HyperlinkEntry["fields"], "label" | "url" | "target" | "includesMarketCode">>;
16
12
  };
13
+ } & Pick<HyperlinkCollectionEntry["fields"], "name" | "slot" | "order">;
14
+ export type ListHyperlinkCollectionsResponse = {
15
+ data: HyperlinkCollectionGraphQLItem[];
17
16
  };
18
- export type ListHyperlinkCollectionEntriesResponse = {
19
- data: HyperlinkCollectionGraphQLResponse["hyperlinkCollectionCollection"]["items"];
20
- };
21
- export declare const listHyperlinkCollectionEntries: ({ marketCode, language, }?: {
17
+ export declare const listHyperlinkCollections: ({ marketCode, language, }?: {
22
18
  marketCode?: string;
23
19
  language?: string;
24
- }) => Promise<ListHyperlinkCollectionEntriesResponse>;
20
+ }) => Promise<ListHyperlinkCollectionsResponse>;
25
21
  export {};
@@ -2,19 +2,15 @@ import { TypeKeywordCollectionSkeleton } from '../types';
2
2
  import { Entry, EntrySys } from 'contentful';
3
3
  type KeywordCollectionEntry = Entry<TypeKeywordCollectionSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>;
4
4
  type GraphQLEntrySys = Pick<EntrySys, "id">;
5
- type KeywordCollectionGraphQLResponse = {
6
- keywordCollectionCollection: {
7
- items: Array<{
8
- sys: GraphQLEntrySys;
9
- } & Pick<KeywordCollectionEntry["fields"], "name" | "slot" | "keywords">>;
10
- };
5
+ export type KeywordCollectionGraphQLItem = {
6
+ sys: GraphQLEntrySys;
7
+ } & Pick<KeywordCollectionEntry["fields"], "name" | "slot" | "keywords">;
8
+ export type ListKeywordCollectionsResponse = {
9
+ data: KeywordCollectionGraphQLItem[];
11
10
  };
12
- export type ListKeywordCollectionEntriesResponse = {
13
- data: KeywordCollectionGraphQLResponse["keywordCollectionCollection"]["items"];
14
- };
15
- export declare const listKeywordCollectionEntries: ({ limit, marketCode, language, }?: {
11
+ export declare const listKeywordCollections: ({ limit, marketCode, language, }?: {
16
12
  limit?: number;
17
13
  marketCode?: string;
18
14
  language?: string;
19
- }) => Promise<ListKeywordCollectionEntriesResponse>;
15
+ }) => Promise<ListKeywordCollectionsResponse>;
20
16
  export {};