@janbox/contentful-marketplace-sdk 0.0.1 → 0.0.3

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 ADDED
@@ -0,0 +1,363 @@
1
+ # iChiba Contentful SDK
2
+
3
+ A TypeScript SDK for accessing iChiba marketplace content from Contentful CMS. This SDK provides type-safe methods to retrieve banners, blog posts, documentation articles, and other content types with market and language filtering support.
4
+
5
+ ## Features
6
+
7
+ - 🔒 **Type-safe**: Full TypeScript support with auto-generated types from Contentful schemas
8
+ - 🌐 **Multi-market**: Built-in filtering by market and language
9
+ - 📝 **Content Types**: Support for banners, blog posts, documentation, and more
10
+ - 🚀 **Easy to use**: Simple API with intuitive method names
11
+ - 🎯 **Selective queries**: Optimized queries with field selection
12
+ - ⚡ **Performance**: Built on top of the official Contentful SDK
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ # Using npm
18
+ npm install @janbox/contentful-marketplace-sdk
19
+
20
+ # Using yarn
21
+ yarn add @janbox/contentful-marketplace-sdk
22
+
23
+ # Using pnpm
24
+ pnpm add @janbox/contentful-marketplace-sdk
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ### 1. Configure the SDK
30
+
31
+ ```typescript
32
+ import { ContentfulSDK } from '@janbox/contentful-marketplace-sdk';
33
+
34
+ // Initialize the SDK with your Contentful credentials
35
+ ContentfulSDK.configure({
36
+ space: 'your-space-id',
37
+ accessToken: 'your-access-token',
38
+ environment: 'master', // optional, defaults to 'master'
39
+ });
40
+ ```
41
+
42
+ ### 2. Fetch Content
43
+
44
+ ```typescript
45
+ import {
46
+ listBannerEntries,
47
+ listBlogPostEntries,
48
+ findBlogPostEntry,
49
+ listDocCategoryEntries,
50
+ listDocArticleEntries
51
+ } from '@janbox/contentful-marketplace-sdk';
52
+
53
+ // Get banners for a specific market and language
54
+ const banners = await listBannerEntries({
55
+ marketId: 'vn',
56
+ language: 'vi',
57
+ query: {
58
+ 'fields.platform[in]': 'WEB',
59
+ limit: 10
60
+ }
61
+ });
62
+
63
+ // Get blog posts
64
+ const blogPosts = await listBlogPostEntries({
65
+ marketId: 'vn',
66
+ language: 'vi',
67
+ query: {
68
+ order: '-sys.createdAt',
69
+ limit: 5
70
+ }
71
+ });
72
+
73
+ // Find a specific blog post by slug
74
+ const blogPost = await findBlogPostEntry({
75
+ marketId: 'vn',
76
+ language: 'vi',
77
+ query: {
78
+ 'fields.slug': 'how-to-shop-online'
79
+ }
80
+ });
81
+
82
+ // Get documentation categories
83
+ const docCategories = await listDocCategoryEntries({
84
+ marketId: 'vn',
85
+ language: 'vi',
86
+ query: {
87
+ order: 'fields.order'
88
+ }
89
+ });
90
+ ```
91
+
92
+ ## Supported Content Types
93
+
94
+ ### 🎯 Banners
95
+ - **Type**: `banner`
96
+ - **Methods**: `listBannerEntries()`
97
+ - **Fields**: name, image, redirectUrl, market, language, platform
98
+ - **Platforms**: `MOBILE`, `WEB`
99
+
100
+ ### 📝 Blog Posts
101
+ - **Type**: `blogPost`
102
+ - **Methods**: `listBlogPostEntries()`, `findBlogPostEntry()`
103
+ - **Fields**: title, slug, author, featuredImage, content, category, shortDescription, seo
104
+ - **Features**: Related posts, categories, SEO metadata
105
+
106
+ ### 📚 Documentation
107
+ - **Types**: `documentationCategory`, `documentationArticle`
108
+ - **Methods**: `listDocCategoryEntries()`, `findDocCategoryEntry()`, `listDocArticleEntries()`, `findDocArticleEntry()`
109
+ - **Features**: Hierarchical categories, searchable articles, SVG icons
110
+
111
+ ### 👤 Authors
112
+ - **Type**: `author`
113
+ - **Fields**: name, avatar
114
+
115
+ ### 🏷️ Categories
116
+ - **Types**: `blogCategory`, `documentationCategory`
117
+ - **Features**: SEO support, hierarchical organization
118
+
119
+ ### 🔍 SEO Metadata
120
+ - **Type**: `seo`
121
+ - **Fields**: metaTitle, metaDescription, metaKeywords, metaRobots
122
+
123
+ ## API Reference
124
+
125
+ ### Configuration
126
+
127
+ #### `ContentfulSDK.configure(params)`
128
+
129
+ Configure the SDK with Contentful credentials.
130
+
131
+ ```typescript
132
+ ContentfulSDK.configure({
133
+ space: string, // Your Contentful space ID
134
+ accessToken: string, // Your Contentful access token
135
+ environment?: string, // Environment (default: 'master')
136
+ host?: string, // Custom host (optional)
137
+ // ... other Contentful client options
138
+ });
139
+ ```
140
+
141
+ ### Banner Methods
142
+
143
+ #### `listBannerEntries(options)`
144
+
145
+ Retrieve multiple banner entries.
146
+
147
+ ```typescript
148
+ const banners = await listBannerEntries({
149
+ marketId: 'vn',
150
+ language: 'vi',
151
+ query: {
152
+ 'fields.platform[in]': 'WEB,MOBILE',
153
+ limit: 10,
154
+ order: '-sys.createdAt'
155
+ }
156
+ });
157
+ ```
158
+
159
+ ### Blog Methods
160
+
161
+ #### `listBlogPostEntries(options)`
162
+
163
+ Retrieve multiple blog post entries with basic fields.
164
+
165
+ ```typescript
166
+ const posts = await listBlogPostEntries({
167
+ marketId: 'vn',
168
+ language: 'vi',
169
+ query: {
170
+ 'fields.category.sys.id': 'category-id',
171
+ limit: 10,
172
+ skip: 0
173
+ }
174
+ });
175
+ ```
176
+
177
+ #### `findBlogPostEntry(options)`
178
+
179
+ Retrieve a single blog post with full content.
180
+
181
+ ```typescript
182
+ const post = await findBlogPostEntry({
183
+ marketId: 'vn',
184
+ language: 'vi',
185
+ query: {
186
+ 'fields.slug': 'my-blog-post'
187
+ }
188
+ });
189
+ ```
190
+
191
+ ### Documentation Methods
192
+
193
+ #### `listDocCategoryEntries(options)`
194
+
195
+ Retrieve documentation categories.
196
+
197
+ ```typescript
198
+ const categories = await listDocCategoryEntries({
199
+ marketId: 'vn',
200
+ language: 'vi',
201
+ query: {
202
+ order: 'fields.order'
203
+ }
204
+ });
205
+ ```
206
+
207
+ #### `findDocCategoryEntry(options)`
208
+
209
+ Find a specific documentation category.
210
+
211
+ ```typescript
212
+ const category = await findDocCategoryEntry({
213
+ marketId: 'vn',
214
+ language: 'vi',
215
+ query: {
216
+ 'fields.slug': 'getting-started'
217
+ }
218
+ });
219
+ ```
220
+
221
+ #### `listDocArticleEntries(options)`
222
+
223
+ Retrieve documentation articles.
224
+
225
+ ```typescript
226
+ const articles = await listDocArticleEntries({
227
+ marketId: 'vn',
228
+ language: 'vi',
229
+ query: {
230
+ 'fields.category.sys.id': 'category-id',
231
+ order: '-sys.updatedAt'
232
+ }
233
+ });
234
+ ```
235
+
236
+ #### `findDocArticleEntry(options)`
237
+
238
+ Find a specific documentation article.
239
+
240
+ ```typescript
241
+ const article = await findDocArticleEntry({
242
+ marketId: 'vn',
243
+ language: 'vi',
244
+ query: {
245
+ 'fields.slug': 'payment-methods'
246
+ }
247
+ });
248
+ ```
249
+
250
+ ## Error Handling
251
+
252
+ The SDK includes built-in error handling for common scenarios:
253
+
254
+ ```typescript
255
+ import { NotFoundResponse } from '@janbox/contentful-marketplace-sdk';
256
+
257
+ try {
258
+ const post = await findBlogPostEntry({
259
+ marketId: 'vn',
260
+ language: 'vi',
261
+ query: { 'fields.slug': 'non-existent-post' }
262
+ });
263
+ } catch (error) {
264
+ if (error instanceof NotFoundResponse) {
265
+ console.log('Blog post not found');
266
+ }
267
+ }
268
+ ```
269
+
270
+ ## Type Definitions
271
+
272
+ The SDK exports comprehensive TypeScript types for all content:
273
+
274
+ ```typescript
275
+ import type {
276
+ // Entry Types
277
+ BannerEntry,
278
+ BlogPostEntry,
279
+ DocCategoryEntry,
280
+ DocArticleEntry,
281
+
282
+ // Skeleton Types
283
+ TypeBannerSkeleton,
284
+ TypeBlogPostSkeleton,
285
+ TypeDocumentationCategorySkeleton,
286
+ TypeDocumentationArticleSkeleton,
287
+
288
+ // Field Types
289
+ TypeBannerFields,
290
+ TypeBlogPostFields,
291
+ // ... and many more
292
+ } from '@janbox/contentful-marketplace-sdk';
293
+ ```
294
+
295
+ ## Query Options
296
+
297
+ All list methods accept Contentful's standard query parameters:
298
+
299
+ - `limit`: Number of entries to return (max 1000)
300
+ - `skip`: Number of entries to skip
301
+ - `order`: Sort order (e.g., '-sys.createdAt', 'fields.title')
302
+ - `fields.*`: Filter by field values
303
+ - `sys.*`: Filter by system properties
304
+ - `include`: Include linked entries (0-10)
305
+ - `select`: Choose specific fields to return
306
+
307
+ ## Development
308
+
309
+ ### Prerequisites
310
+
311
+ - Node.js 18+
312
+ - pnpm 8+
313
+
314
+ ### Setup
315
+
316
+ ```bash
317
+ # Clone the repository
318
+ git clone https://github.com/your-org/ichiba-contentful-sdk.git
319
+
320
+ # Install dependencies
321
+ pnpm install
322
+
323
+ # Build the SDK
324
+ pnpm build:packages
325
+ ```
326
+
327
+ ### Project Structure
328
+
329
+ ```
330
+ ichiba-contentful-sdk/
331
+ ├── packages/
332
+ │ └── marketplace-sdk/
333
+ │ ├── src/
334
+ │ │ ├── client/ # SDK client configuration
335
+ │ │ ├── entries/ # Content type methods
336
+ │ │ ├── http-responses/ # Custom error responses
337
+ │ │ ├── types/ # TypeScript type definitions
338
+ │ │ └── index.ts # Main export file
339
+ │ ├── dist/ # Built files
340
+ │ └── package.json
341
+ ├── examples/ # Usage examples
342
+ └── package.json
343
+ ```
344
+
345
+ ## Contributing
346
+
347
+ 1. Fork the repository
348
+ 2. Create a feature branch: `git checkout -b feature/amazing-feature`
349
+ 3. Commit your changes: `git commit -m 'Add amazing feature'`
350
+ 4. Push to the branch: `git push origin feature/amazing-feature`
351
+ 5. Open a Pull Request
352
+
353
+ ## License
354
+
355
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
356
+
357
+ ## Support
358
+
359
+ For questions and support, please contact the iChiba development team or create an issue in the repository.
360
+
361
+ ---
362
+
363
+ **Built with ❤️ by the iChiba team**
@@ -1,5 +1,6 @@
1
1
  import { TypeBannerSkeleton } from '../types';
2
- import { EntriesQueries } from 'contentful';
2
+ import { EntriesQueries, Entry } from 'contentful';
3
+ export type BannerEntry = Entry<TypeBannerSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>;
3
4
  export declare const listBannerEntries: ({ query, marketId, language, }: {
4
5
  marketId: string;
5
6
  language: string;
@@ -0,0 +1,13 @@
1
+ import { EntriesQueries, Entry } from 'contentful';
2
+ import { TypeBlogPostSkeleton } from '../types';
3
+ export type BlogPostEntry = Entry<TypeBlogPostSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>;
4
+ export declare const listBlogPostEntries: ({ query, marketId, language, }: {
5
+ marketId: string;
6
+ language: string;
7
+ query?: Partial<EntriesQueries<TypeBlogPostSkeleton, "WITHOUT_UNRESOLVABLE_LINKS">>;
8
+ }) => Promise<import('contentful').EntryCollection<TypeBlogPostSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>>;
9
+ export declare const findBlogPostEntry: ({ query, marketId, language, }: {
10
+ marketId: string;
11
+ language: string;
12
+ query: Partial<EntriesQueries<TypeBlogPostSkeleton, "WITHOUT_UNRESOLVABLE_LINKS">>;
13
+ }) => Promise<Entry<TypeBlogPostSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>>;
@@ -0,0 +1,30 @@
1
+ import { EntriesQueries, Entry } from 'contentful';
2
+ import { TypeDocumentationArticleSkeleton, TypeDocumentationCategorySkeleton } from '../types';
3
+ /**
4
+ * Documentation category entry
5
+ */
6
+ export type DocCategoryEntry = Entry<TypeDocumentationCategorySkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>;
7
+ export declare const listDocCategoryEntries: ({ query, marketId, language, }: {
8
+ query: Partial<EntriesQueries<TypeDocumentationCategorySkeleton, "WITHOUT_UNRESOLVABLE_LINKS">>;
9
+ marketId: string;
10
+ language: string;
11
+ }) => Promise<import('contentful').EntryCollection<TypeDocumentationCategorySkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>>;
12
+ export declare const findDocCategoryEntry: ({ query, marketId, language, }: {
13
+ query: Partial<EntriesQueries<TypeDocumentationCategorySkeleton, "WITHOUT_UNRESOLVABLE_LINKS">>;
14
+ marketId: string;
15
+ language: string;
16
+ }) => Promise<Entry<TypeDocumentationCategorySkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>>;
17
+ /**
18
+ * Documentation article entry
19
+ */
20
+ export type DocArticleEntry = Entry<TypeDocumentationArticleSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>;
21
+ export declare const listDocArticleEntries: ({ query, marketId, language, }: {
22
+ query: Partial<EntriesQueries<TypeDocumentationArticleSkeleton, "WITHOUT_UNRESOLVABLE_LINKS">>;
23
+ marketId: string;
24
+ language: string;
25
+ }) => Promise<import('contentful').EntryCollection<TypeDocumentationArticleSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>>;
26
+ export declare const findDocArticleEntry: ({ query, marketId, language, }: {
27
+ query: Partial<EntriesQueries<TypeDocumentationArticleSkeleton, "WITHOUT_UNRESOLVABLE_LINKS">>;
28
+ marketId: string;
29
+ language: string;
30
+ }) => Promise<Entry<TypeDocumentationArticleSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>>;
@@ -1 +1,3 @@
1
1
  export * from './banner';
2
+ export * from './blog';
3
+ export * from './documentation';
@@ -0,0 +1,3 @@
1
+ export declare class NotFoundResponse extends Response {
2
+ constructor(...args: ConstructorParameters<typeof Response>);
3
+ }
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=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=s.createClient(e)}}const l=async({query:t,marketId:e,language:i})=>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":i,...t,content_type:"banner"});exports.ContentfulSDK=n;exports.listBannerEntries=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("contentful");class i{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})=>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 a extends Response{constructor(...e){super(e[0]??"Not Found",{status:404,...e[1]})}}const d=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}),c=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(l=>l.items.at(0));if(!n)throw new a;return n},y=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"}),f=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(l=>l.items.at(0));if(!n)throw new a;return n},g=({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"}),u=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(l=>l.items.at(0));if(!n)throw new a;return n};exports.ContentfulSDK=i;exports.findBlogPostEntry=c;exports.findDocArticleEntry=u;exports.findDocCategoryEntry=f;exports.listBannerEntries=r;exports.listBlogPostEntries=d;exports.listDocArticleEntries=g;exports.listDocCategoryEntries=y;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createClient as n } from "contentful";
2
- class s {
1
+ import { createClient as o } from "contentful";
2
+ class i {
3
3
  static _client;
4
4
  // static getter
5
5
  static get client() {
@@ -7,23 +7,148 @@ class s {
7
7
  throw new Error("Client is not initialized");
8
8
  return this._client;
9
9
  }
10
- static configure(t) {
11
- this._client = n(t);
10
+ static configure(e) {
11
+ this._client = o(e);
12
12
  }
13
13
  }
14
- const r = async ({
15
- query: e,
16
- marketId: t,
17
- language: i
18
- }) => s.client.withoutUnresolvableLinks.getEntries({
19
- "fields.market.sys.contentType.sys.id": "market",
20
- "fields.market.fields.marketId": t,
21
- "fields.language.sys.contentType.sys.id": "language",
22
- "fields.language.fields.code": i,
23
- ...e,
24
- content_type: "banner"
25
- });
14
+ const d = async ({
15
+ query: t,
16
+ marketId: e,
17
+ language: s
18
+ }) => i.client.withoutUnresolvableLinks.getEntries(
19
+ {
20
+ "fields.market.sys.contentType.sys.id": "market",
21
+ "fields.market.fields.marketId": e,
22
+ "fields.language.sys.contentType.sys.id": "language",
23
+ "fields.language.fields.code": s,
24
+ ...t,
25
+ content_type: "banner"
26
+ }
27
+ );
28
+ class a extends Response {
29
+ constructor(...e) {
30
+ super(e[0] ?? "Not Found", {
31
+ status: 404,
32
+ ...e[1]
33
+ });
34
+ }
35
+ }
36
+ const c = async ({
37
+ query: t,
38
+ marketId: e,
39
+ language: s
40
+ }) => i.client.withoutUnresolvableLinks.getEntries(
41
+ {
42
+ "fields.market.sys.contentType.sys.id": "market",
43
+ "fields.market.fields.marketId": e,
44
+ "fields.language.sys.contentType.sys.id": "language",
45
+ "fields.language.fields.code": s,
46
+ select: [
47
+ "fields.title",
48
+ "fields.category",
49
+ "fields.slug",
50
+ "fields.featuredImage",
51
+ "fields.shortDescription"
52
+ ],
53
+ content_type: "blogPost",
54
+ ...t
55
+ }
56
+ ), y = async ({
57
+ query: t,
58
+ marketId: e,
59
+ language: s
60
+ }) => {
61
+ const n = await i.client.withoutUnresolvableLinks.getEntries({
62
+ select: [
63
+ "fields.title",
64
+ "fields.category",
65
+ "fields.slug",
66
+ "fields.featuredImage",
67
+ "fields.shortDescription",
68
+ "fields.author",
69
+ "fields.content",
70
+ "fields.seo",
71
+ "sys.updatedAt"
72
+ ],
73
+ "fields.market.sys.contentType.sys.id": "market",
74
+ "fields.market.fields.marketId": e,
75
+ "fields.language.sys.contentType.sys.id": "language",
76
+ "fields.language.fields.code": s,
77
+ content_type: "blogPost",
78
+ limit: 1,
79
+ ...t
80
+ }).then((l) => l.items.at(0));
81
+ if (!n)
82
+ throw new a();
83
+ return n;
84
+ }, f = async ({
85
+ query: t,
86
+ marketId: e,
87
+ language: s
88
+ }) => i.client.withoutUnresolvableLinks.getEntries(
89
+ {
90
+ "fields.market.sys.contentType.sys.id": "market",
91
+ "fields.market.fields.marketId": e,
92
+ "fields.language.sys.contentType.sys.id": "language",
93
+ "fields.language.fields.code": s,
94
+ ...t,
95
+ content_type: "documentationCategory"
96
+ }
97
+ ), g = async ({
98
+ query: t,
99
+ marketId: e,
100
+ language: s
101
+ }) => {
102
+ const n = await i.client.withoutUnresolvableLinks.getEntries({
103
+ "fields.market.sys.contentType.sys.id": "market",
104
+ "fields.market.fields.marketId": e,
105
+ "fields.language.sys.contentType.sys.id": "language",
106
+ "fields.language.fields.code": s,
107
+ ...t,
108
+ content_type: "documentationCategory",
109
+ limit: 1
110
+ }).then((l) => l.items.at(0));
111
+ if (!n)
112
+ throw new a();
113
+ return n;
114
+ }, u = ({
115
+ query: t,
116
+ marketId: e,
117
+ language: s
118
+ }) => i.client.withoutUnresolvableLinks.getEntries(
119
+ {
120
+ "fields.market.sys.contentType.sys.id": "market",
121
+ "fields.market.fields.marketId": e,
122
+ "fields.language.sys.contentType.sys.id": "language",
123
+ "fields.language.fields.code": s,
124
+ ...t,
125
+ content_type: "documentationArticle"
126
+ }
127
+ ), m = async ({
128
+ query: t,
129
+ marketId: e,
130
+ language: s
131
+ }) => {
132
+ const n = await i.client.withoutUnresolvableLinks.getEntries({
133
+ "fields.market.sys.contentType.sys.id": "market",
134
+ "fields.market.fields.marketId": e,
135
+ "fields.language.sys.contentType.sys.id": "language",
136
+ "fields.language.fields.code": s,
137
+ ...t,
138
+ content_type: "documentationArticle",
139
+ limit: 1
140
+ }).then((l) => l.items.at(0));
141
+ if (!n)
142
+ throw new a();
143
+ return n;
144
+ };
26
145
  export {
27
- s as ContentfulSDK,
28
- r as listBannerEntries
146
+ i as ContentfulSDK,
147
+ y as findBlogPostEntry,
148
+ m as findDocArticleEntry,
149
+ g as findDocCategoryEntry,
150
+ d as listBannerEntries,
151
+ c as listBlogPostEntries,
152
+ u as listDocArticleEntries,
153
+ f as listDocCategoryEntries
29
154
  };
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@janbox/contentful-marketplace-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist/**/*",
9
+ "README.md"
10
+ ],
7
11
  "exports": {
8
12
  ".": {
9
13
  "import": "./dist/index.js",
@@ -12,12 +16,12 @@
12
16
  },
13
17
  "type": "module",
14
18
  "sideEffects": false,
19
+ "peerDependencies": {
20
+ "contentful": ">=11"
21
+ },
15
22
  "scripts": {
16
23
  "dev": "vite",
17
24
  "build": "tsc && vite build",
18
25
  "preview": "vite preview"
19
- },
20
- "peerDependencies": {
21
- "contentful": ">=11"
22
26
  }
23
- }
27
+ }
@@ -1,22 +0,0 @@
1
- import {
2
- type ContentfulClientApi,
3
- createClient,
4
- type CreateClientParams,
5
- } from "contentful";
6
-
7
- export class ContentfulSDK {
8
- private static _client: ContentfulClientApi<undefined> | undefined;
9
-
10
- // static getter
11
-
12
- static get client() {
13
- if (!this._client) {
14
- throw new Error("Client is not initialized");
15
- }
16
- return this._client;
17
- }
18
-
19
- static configure(params: CreateClientParams) {
20
- this._client = createClient(params);
21
- }
22
- }
@@ -1,23 +0,0 @@
1
- import { ContentfulSDK } from "@/client";
2
- import type { TypeBannerSkeleton } from "@/types";
3
- import type { EntriesQueries } from "contentful";
4
-
5
- export const listBannerEntries = async ({
6
- query,
7
- marketId,
8
- language,
9
- }: {
10
- marketId: string;
11
- language: string;
12
- query?: Partial<EntriesQueries<TypeBannerSkeleton, 'WITHOUT_UNRESOLVABLE_LINKS'>>;
13
- }) => {
14
- return ContentfulSDK.client.withoutUnresolvableLinks.getEntries<TypeBannerSkeleton>({
15
- 'fields.market.sys.contentType.sys.id': 'market',
16
- 'fields.market.fields.marketId': marketId,
17
- 'fields.language.sys.contentType.sys.id': 'language',
18
- 'fields.language.fields.code': language,
19
- ...query,
20
- content_type: 'banner',
21
- });
22
- };
23
-
@@ -1 +0,0 @@
1
- export * from "./banner";
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./client";
2
- export * from "./entries";
3
- export * from "./types";
@@ -1,177 +0,0 @@
1
- import type {
2
- ChainModifiers,
3
- Entry,
4
- EntryFieldTypes,
5
- EntrySkeletonType,
6
- LocaleCode,
7
- } from "contentful";
8
-
9
- export interface TypeAuthorFields {
10
- name: EntryFieldTypes.Symbol;
11
- avatar?: EntryFieldTypes.AssetLink;
12
- }
13
-
14
- export type TypeAuthorSkeleton = EntrySkeletonType<TypeAuthorFields, "author">;
15
- export type TypeAuthor<
16
- Modifiers extends ChainModifiers,
17
- Locales extends LocaleCode = LocaleCode
18
- > = Entry<TypeAuthorSkeleton, Modifiers, Locales>;
19
-
20
- export interface TypeBannerFields {
21
- name: EntryFieldTypes.Symbol;
22
- image: EntryFieldTypes.AssetLink;
23
- redirectUrl?: EntryFieldTypes.Symbol;
24
- market: EntryFieldTypes.EntryLink<TypeMarketSkeleton>;
25
- language: EntryFieldTypes.EntryLink<TypeLanguageSkeleton>;
26
- platform: EntryFieldTypes.Array<EntryFieldTypes.Symbol<"MOBILE" | "WEB">>;
27
- }
28
-
29
- export type TypeBannerSkeleton = EntrySkeletonType<TypeBannerFields, "banner">;
30
- export type TypeBanner<
31
- Modifiers extends ChainModifiers,
32
- Locales extends LocaleCode = LocaleCode
33
- > = Entry<TypeBannerSkeleton, Modifiers, Locales>;
34
-
35
- export interface TypeBlogCategoryFields {
36
- title: EntryFieldTypes.Symbol;
37
- slug: EntryFieldTypes.Symbol;
38
- description?: EntryFieldTypes.RichText;
39
- publishedDate?: EntryFieldTypes.Date;
40
- market: EntryFieldTypes.EntryLink<TypeMarketSkeleton>;
41
- language: EntryFieldTypes.EntryLink<TypeLanguageSkeleton>;
42
- seo?: EntryFieldTypes.EntryLink<TypeSeoSkeleton>;
43
- }
44
-
45
- export type TypeBlogCategorySkeleton = EntrySkeletonType<
46
- TypeBlogCategoryFields,
47
- "blogCategory"
48
- >;
49
- export type TypeBlogCategory<
50
- Modifiers extends ChainModifiers,
51
- Locales extends LocaleCode = LocaleCode
52
- > = Entry<TypeBlogCategorySkeleton, Modifiers, Locales>;
53
-
54
- export interface TypeBlogPostFields {
55
- title: EntryFieldTypes.Symbol;
56
- shortDescription?: EntryFieldTypes.Text;
57
- slug: EntryFieldTypes.Symbol;
58
- author?: EntryFieldTypes.EntryLink<TypeAuthorSkeleton>;
59
- featuredImage: EntryFieldTypes.AssetLink;
60
- content: EntryFieldTypes.RichText;
61
- relatedBlogPosts?: EntryFieldTypes.Array<
62
- EntryFieldTypes.EntryLink<TypeBlogPostSkeleton>
63
- >;
64
- category?: EntryFieldTypes.EntryLink<TypeBlogCategorySkeleton>;
65
- market: EntryFieldTypes.EntryLink<TypeMarketSkeleton>;
66
- language: EntryFieldTypes.EntryLink<TypeLanguageSkeleton>;
67
- seo?: EntryFieldTypes.EntryLink<TypeSeoSkeleton>;
68
- }
69
-
70
- export type TypeBlogPostSkeleton = EntrySkeletonType<
71
- TypeBlogPostFields,
72
- "blogPost"
73
- >;
74
- export type TypeBlogPost<
75
- Modifiers extends ChainModifiers,
76
- Locales extends LocaleCode = LocaleCode
77
- > = Entry<TypeBlogPostSkeleton, Modifiers, Locales>;
78
-
79
- export interface TypeComponentSvgFields {
80
- name: EntryFieldTypes.Symbol;
81
- source: EntryFieldTypes.Text;
82
- }
83
-
84
- export type TypeComponentSvgSkeleton = EntrySkeletonType<
85
- TypeComponentSvgFields,
86
- "componentSvg"
87
- >;
88
- export type TypeComponentSvg<
89
- Modifiers extends ChainModifiers,
90
- Locales extends LocaleCode = LocaleCode
91
- > = Entry<TypeComponentSvgSkeleton, Modifiers, Locales>;
92
-
93
- export interface TypeDocumentationArticleFields {
94
- title: EntryFieldTypes.Symbol;
95
- slug: EntryFieldTypes.Symbol;
96
- content: EntryFieldTypes.RichText;
97
- author?: EntryFieldTypes.EntryLink<TypeAuthorSkeleton>;
98
- category?: EntryFieldTypes.EntryLink<TypeDocumentationCategorySkeleton>;
99
- market: EntryFieldTypes.EntryLink<TypeMarketSkeleton>;
100
- language: EntryFieldTypes.EntryLink<TypeLanguageSkeleton>;
101
- seo?: EntryFieldTypes.EntryLink<TypeSeoSkeleton>;
102
- }
103
-
104
- export type TypeDocumentationArticleSkeleton = EntrySkeletonType<
105
- TypeDocumentationArticleFields,
106
- "documentationArticle"
107
- >;
108
- export type TypeDocumentationArticle<
109
- Modifiers extends ChainModifiers,
110
- Locales extends LocaleCode = LocaleCode
111
- > = Entry<TypeDocumentationArticleSkeleton, Modifiers, Locales>;
112
-
113
- export interface TypeDocumentationCategoryFields {
114
- title: EntryFieldTypes.Symbol;
115
- slug: EntryFieldTypes.Symbol;
116
- description?: EntryFieldTypes.Symbol;
117
- order?: EntryFieldTypes.Integer;
118
- icon?: EntryFieldTypes.EntryLink<TypeComponentSvgSkeleton>;
119
- market: EntryFieldTypes.EntryLink<TypeMarketSkeleton>;
120
- language: EntryFieldTypes.EntryLink<TypeLanguageSkeleton>;
121
- seo?: EntryFieldTypes.EntryLink<TypeSeoSkeleton>;
122
- }
123
-
124
- export type TypeDocumentationCategorySkeleton = EntrySkeletonType<
125
- TypeDocumentationCategoryFields,
126
- "documentationCategory"
127
- >;
128
- export type TypeDocumentationCategory<
129
- Modifiers extends ChainModifiers,
130
- Locales extends LocaleCode = LocaleCode
131
- > = Entry<TypeDocumentationCategorySkeleton, Modifiers, Locales>;
132
-
133
- export interface TypeLanguageFields {
134
- name: EntryFieldTypes.Symbol;
135
- code: EntryFieldTypes.Symbol;
136
- }
137
-
138
- export type TypeLanguageSkeleton = EntrySkeletonType<
139
- TypeLanguageFields,
140
- "language"
141
- >;
142
- export type TypeLanguage<
143
- Modifiers extends ChainModifiers,
144
- Locales extends LocaleCode = LocaleCode
145
- > = Entry<TypeLanguageSkeleton, Modifiers, Locales>;
146
-
147
- export interface TypeMarketFields {
148
- marketId: EntryFieldTypes.Symbol;
149
- marketName: EntryFieldTypes.Symbol;
150
- description?: EntryFieldTypes.Text;
151
- isPrimary?: EntryFieldTypes.Boolean;
152
- currency?: EntryFieldTypes.Symbol;
153
- status?: EntryFieldTypes.Number;
154
- isDeleted?: EntryFieldTypes.Boolean;
155
- createdAt?: EntryFieldTypes.Date;
156
- }
157
-
158
- export type TypeMarketSkeleton = EntrySkeletonType<TypeMarketFields, "market">;
159
- export type TypeMarket<
160
- Modifiers extends ChainModifiers,
161
- Locales extends LocaleCode = LocaleCode
162
- > = Entry<TypeMarketSkeleton, Modifiers, Locales>;
163
-
164
- export interface TypeSeoFields {
165
- metaTitle: EntryFieldTypes.Symbol;
166
- metaDescription?: EntryFieldTypes.Text;
167
- metaKeywords?: EntryFieldTypes.Array<EntryFieldTypes.Symbol>;
168
- metaRobots?: EntryFieldTypes.Array<
169
- EntryFieldTypes.Symbol<"follow" | "index" | "nofollow" | "noindex">
170
- >;
171
- }
172
-
173
- export type TypeSeoSkeleton = EntrySkeletonType<TypeSeoFields, "seo">;
174
- export type TypeSeo<
175
- Modifiers extends ChainModifiers,
176
- Locales extends LocaleCode = LocaleCode
177
- > = Entry<TypeSeoSkeleton, Modifiers, Locales>;
package/tsconfig.json DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "useDefineForClassFields": true,
5
- "module": "ESNext",
6
- "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
- "skipLibCheck": true,
8
-
9
- /* Bundler mode */
10
- "moduleResolution": "bundler",
11
- "allowImportingTsExtensions": true,
12
- "verbatimModuleSyntax": true,
13
- "moduleDetection": "force",
14
- "noEmit": true,
15
-
16
- /* Linting */
17
- "strict": true,
18
- "noUnusedLocals": true,
19
- "noUnusedParameters": true,
20
- "erasableSyntaxOnly": true,
21
- "noFallthroughCasesInSwitch": true,
22
- "noUncheckedSideEffectImports": true,
23
- "baseUrl": ".",
24
- "paths": {
25
- "@/*": ["./src/*"]
26
- }
27
- },
28
- "include": ["src"]
29
- }
package/vite.config.ts DELETED
@@ -1,23 +0,0 @@
1
- import { defineConfig } from "vite";
2
- import { dirname, resolve } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import dts from "vite-plugin-dts";
5
- import tsconfigPaths from "vite-tsconfig-paths";
6
- import { peerDependencies } from "./package.json";
7
-
8
- const __dirname = dirname(fileURLToPath(import.meta.url));
9
-
10
- // https://vitejs.dev/config/
11
- export default defineConfig({
12
- build: {
13
- lib: {
14
- formats: ["cjs", "es"],
15
- entry: resolve(__dirname, "src/index.ts"),
16
- fileName: "index",
17
- },
18
- rollupOptions: {
19
- external: Object.keys(peerDependencies),
20
- },
21
- },
22
- plugins: [dts(), tsconfigPaths()],
23
- });