@janbox/contentful-marketplace-sdk 0.0.2 → 0.0.4
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 +363 -0
- package/dist/entries/banner.d.ts +2 -1
- package/dist/entries/blog.d.ts +13 -0
- package/dist/entries/documentation.d.ts +30 -0
- package/dist/entries/footer-menu.d.ts +7 -0
- package/dist/entries/index.d.ts +3 -0
- package/dist/http-responses/index.d.ts +3 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +158 -18
- package/dist/types/index.d.ts +24 -0
- package/package.json +12 -8
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**
|
package/dist/entries/banner.d.ts
CHANGED
|
@@ -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>>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EntriesQueries } from 'contentful';
|
|
2
|
+
import { TypeFooterMenuSkeleton } from '../types';
|
|
3
|
+
export declare const listFooterMenuEntries: ({ query, marketId, language, }: {
|
|
4
|
+
marketId: string;
|
|
5
|
+
language: string;
|
|
6
|
+
query?: Partial<EntriesQueries<TypeFooterMenuSkeleton, "WITHOUT_UNRESOLVABLE_LINKS">>;
|
|
7
|
+
}) => Promise<import('contentful').EntryCollection<TypeFooterMenuSkeleton, "WITHOUT_UNRESOLVABLE_LINKS", string>>;
|
package/dist/entries/index.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createClient as
|
|
2
|
-
class
|
|
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,163 @@ class s {
|
|
|
7
7
|
throw new Error("Client is not initialized");
|
|
8
8
|
return this._client;
|
|
9
9
|
}
|
|
10
|
-
static configure(
|
|
11
|
-
this._client =
|
|
10
|
+
static configure(e) {
|
|
11
|
+
this._client = o(e);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
const
|
|
15
|
-
query:
|
|
16
|
-
marketId:
|
|
17
|
-
language:
|
|
18
|
-
}) =>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
), f = 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
|
+
}, y = 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
|
+
}, 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
|
|
157
|
+
}
|
|
158
|
+
);
|
|
26
159
|
export {
|
|
27
|
-
|
|
28
|
-
|
|
160
|
+
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
|
|
29
169
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -71,6 +71,21 @@ 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
|
+
}
|
|
87
|
+
export type TypeHyperlinkSkeleton = EntrySkeletonType<TypeHyperlinkFields, "hyperlink">;
|
|
88
|
+
export type TypeHyperlink<Modifiers extends ChainModifiers, Locales extends LocaleCode = LocaleCode> = Entry<TypeHyperlinkSkeleton, Modifiers, Locales>;
|
|
74
89
|
export interface TypeLanguageFields {
|
|
75
90
|
name: EntryFieldTypes.Symbol;
|
|
76
91
|
code: EntryFieldTypes.Symbol;
|
|
@@ -89,6 +104,15 @@ export interface TypeMarketFields {
|
|
|
89
104
|
}
|
|
90
105
|
export type TypeMarketSkeleton = EntrySkeletonType<TypeMarketFields, "market">;
|
|
91
106
|
export type TypeMarket<Modifiers extends ChainModifiers, Locales extends LocaleCode = LocaleCode> = Entry<TypeMarketSkeleton, Modifiers, Locales>;
|
|
107
|
+
export interface TypeNoticeFields {
|
|
108
|
+
title: EntryFieldTypes.Symbol;
|
|
109
|
+
content: EntryFieldTypes.RichText;
|
|
110
|
+
market: EntryFieldTypes.EntryLink<TypeMarketSkeleton>;
|
|
111
|
+
language: EntryFieldTypes.EntryLink<TypeLanguageSkeleton>;
|
|
112
|
+
variant?: EntryFieldTypes.Array<EntryFieldTypes.Symbol<"Featured" | "Promotion" | "Urgent">>;
|
|
113
|
+
}
|
|
114
|
+
export type TypeNoticeSkeleton = EntrySkeletonType<TypeNoticeFields, "notice">;
|
|
115
|
+
export type TypeNotice<Modifiers extends ChainModifiers, Locales extends LocaleCode = LocaleCode> = Entry<TypeNoticeSkeleton, Modifiers, Locales>;
|
|
92
116
|
export interface TypeSeoFields {
|
|
93
117
|
metaTitle: EntryFieldTypes.Symbol;
|
|
94
118
|
metaDescription?: EntryFieldTypes.Text;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@janbox/contentful-marketplace-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"main": "./dist/index.cjs",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"dist/**/*"
|
|
8
|
+
"dist/**/*",
|
|
9
|
+
"README.md"
|
|
9
10
|
],
|
|
10
11
|
"exports": {
|
|
11
12
|
".": {
|
|
@@ -15,12 +16,15 @@
|
|
|
15
16
|
},
|
|
16
17
|
"type": "module",
|
|
17
18
|
"sideEffects": false,
|
|
18
|
-
"scripts": {
|
|
19
|
-
"dev": "vite",
|
|
20
|
-
"build": "tsc && vite build",
|
|
21
|
-
"preview": "vite preview"
|
|
22
|
-
},
|
|
23
19
|
"peerDependencies": {
|
|
24
20
|
"contentful": ">=11"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"dev": "vite",
|
|
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"
|
|
25
29
|
}
|
|
26
|
-
}
|
|
30
|
+
}
|