@content-island/api-client 0.8.0 → 0.8.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.
Files changed (3) hide show
  1. package/README.md +8 -147
  2. package/dist/index.d.ts +22 -13
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -22,159 +22,20 @@ interface Post {
22
22
  ```
23
23
 
24
24
  ```typescript
25
- import { createClient, mapContentToModel } from '@content-island/api-client';
25
+ import { createClient } from '@content-island/api-client';
26
26
 
27
27
  const client = createClient({ accessToken: <your-token>});
28
28
 
29
- const postContents = client.getContentList({ contentType: 'post'}); // Retrieve the list of contents in the project filtered by content type, for example 'post'
30
- const englishPosts = postContents.map(content => mapContentToModel<Post>(content, 'en')); // Map the english content to your own model
31
- const spanishPosts = postContents.map(content => mapContentToModel<Post>(content, 'es')); // Map the spanish content to your own model
29
+ const postsWithDefaultLanguage = client.getContentList<Post>({ contentType: 'post'}); // Retrieve the list of contents in the project filtered by content type, for example 'post' in the
30
+ const englishPosts = client.getContentList<Post>({ contentType: 'post', language: 'en'}); // Get english posts
31
+ const spanishPosts = client.getContentList<Post>({ contentType: 'post', language: 'es'}); // Get spanish posts
32
32
 
33
33
  // Or you can retrieve a content by id
34
- const content = client.getContent('content-id'); // Retrieve a content by id
35
- const englishPost = mapContentToModel<Post>(content, 'en'); // Map the english content to your own model
36
- const spanishPost = mapContentToModel<Post>(content, 'es'); // Map the spanish content to your own model
34
+ const postById = client.getContent<Post>({ id: 'content-id', language: 'es' }); // Retrieve a content by id
35
+ const postBySomeField = client.getContent<Post>({ 'fields.title': 'post-title', language: 'es' }); // Retrieve a content by field value
37
36
 
38
37
  ```
39
38
 
40
- ### Filter by language
39
+ ### Documentation
41
40
 
42
- ```typescript
43
- import { createClient, mapContentToModel } from '@content-island/api-client';
44
-
45
- const client = createClient({ accessToken: <your-token>});
46
-
47
- const englishPostContents = client.getContentList({ contentType: 'post', language: 'en'}); // Retrieve the english posts
48
- const englishPosts = englishPostContents.map(content => mapContentToModel<Post>(content)); // Map content to your own model using the first language available, in this case 'en'
49
-
50
- // Or you can retrieve contents by multiple languages
51
- const postContents = client.getContentList({ contentType: 'post', language: { in: ['en', 'es']}}); // Retrieve the english or spanish posts
52
-
53
- // Or you can retrieve a content by id
54
- const englishContent = client.getContent('content-id', { language: 'en'}); // Retrieve a content by id
55
- const englishPost = mapContentToModel<Post>(englishContent); // Map content to your own model using the first language available, in this case 'en'
56
-
57
- ```
58
-
59
- > Check the [API/queryParams](#queryparams) section for more information about the query parameters.
60
-
61
- ## API
62
-
63
- ### `createClient(options): endpoints`
64
-
65
- Creates a client instance.
66
-
67
- #### `options`
68
-
69
- | name | type | required | description |
70
- | ------------- | -------- | -------- | ----------------------------------------------------------- |
71
- | `accessToken` | `string` | `true` | The access token of the project |
72
- | `domain` | `string` | `false` | The domain of the project. Default: `api.contentisland.net` |
73
- | `apiVersion` | `string` | `false` | The version of the API. Default: `1.0` |
74
-
75
- #### `endpoints`
76
-
77
- ##### `getProject()`
78
-
79
- Retrieves the project details by access token.
80
-
81
- ##### `getContentList(queryParams?)`
82
-
83
- Retrieves the list of contents in the project.
84
-
85
- ##### `getContent(id, queryParams?)`
86
-
87
- Retrieves a content by id.
88
-
89
- #### `queryParams`
90
-
91
- The query parameters to filter the list of contents.
92
-
93
- | Key | Value | Description |
94
- | ------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
95
- | `id` | `Filter` | The id of the content to retrieve. This is useful to retrieve a list of contents by id. For example: `client.getContentList({ id: { in: ['1', '2', '3']})` |
96
- | `contentType` | `Filter` | The content type to filter the list of contents. For example: `post` |
97
- | `language` | `Filter` | The language to filter the list of contents. For example: `en` |
98
-
99
- | Filter type | Description | Example |
100
- | ------------------ | ------------------------------------------------------------------ | ------------------------------------ |
101
- | `string` | Filter the content where the param is `equal to` this value | `{ contentType: 'post' }` |
102
- | `{ in: string[] }` | Filter the content where the param `contains some` of these values | `{ language: { in: ['en', 'es'] } }` |
103
-
104
- ### `mapContentToModel(content, language?)`
105
-
106
- Maps a list of fields to a model.
107
-
108
- ```typescript
109
- const content: Content = {
110
- id: '1',
111
- contentType: { id: '10', name: 'post' },
112
- lastUpdate: '2023-10-20T00:00:00.000Z',
113
- fields: [
114
- {
115
- id: '100',
116
- name: 'title',
117
- value: 'My title',
118
- type: 'short-text',
119
- isArray: false,
120
- language: 'en',
121
- },
122
- {
123
- id: '200',
124
- name: 'body',
125
- value: '# My long text in markdown',
126
- type: 'long-text',
127
- isArray: false,
128
- language: 'en',
129
- },
130
- {
131
- id: '300',
132
- name: 'order',
133
- value: 1,
134
- type: 'number',
135
- isArray: false,
136
- language: 'en',
137
- },
138
- {
139
- id: '400',
140
- name: 'title',
141
- value: 'Mi titutlo',
142
- type: 'short-text',
143
- isArray: false,
144
- language: 'es',
145
- },
146
- {
147
- id: '500',
148
- name: 'body',
149
- value: '# Mi texto largo en markdown',
150
- type: 'long-text',
151
- isArray: false,
152
- language: 'es',
153
- },
154
- {
155
- id: '600',
156
- name: 'order',
157
- value: 1,
158
- type: 'number',
159
- isArray: false,
160
- language: 'es',
161
- },
162
- ],
163
- };
164
-
165
- interface Post {
166
- id: string;
167
- title: string;
168
- body: string;
169
- order: number;
170
- }
171
-
172
- const post = mapContentToModel<Post>(fields); // Get the first language available, in this case 'en'
173
- console.log(post); // { id: '1', title: 'My title', body: '# My long text in markdown', order: 1 }
174
-
175
- const englishPost = mapContentToModel<Post>(fields, 'en');
176
- console.log(englishPost); // { id: '1', title: 'My title', body: '# My long text in markdown', order: 1 }
177
-
178
- const spanishPost = mapContentToModel<Post>(fields, 'es');
179
- console.log(spanishPost); // { id: '1', title: 'Mi titulo', body: '# Mi texto largo en markdown', order: 1 }
180
- ```
41
+ For more detailed documentation, please refer to the [Content Island API Client documentation](https://docs.contentisland.net/client-api/overview/).
package/dist/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ import { FieldType } from '@content-island/common';
2
+ import { Lookup } from '@content-island/common';
3
+ import { Media } from '@content-island/common';
4
+
1
5
  declare type AllowedQueryKeys<M extends Model = Model> = keyof Pick<
2
6
  Query<M>,
3
7
  'id' | 'contentType' | 'language' | Extract<keyof Query<M>, `fields.${string}`>
@@ -11,20 +15,26 @@ export declare interface ApiClient {
11
15
  getRawContent: <M extends Model = Model & Record<string, any>>(queryParam: QueryParams<M>) => Promise<Content>;
12
16
  }
13
17
 
14
- export declare interface ApiLookup {
15
- id: string;
16
- name: string;
17
- }
18
-
19
18
  export declare type ClientFilter<Type = string> = Type | { in?: Type[] };
20
19
 
21
20
  export declare interface Content {
22
21
  id: string;
23
- contentType: ApiLookup;
22
+ contentType: Lookup;
24
23
  lastUpdate: Date;
25
24
  fields: Field[];
26
25
  }
27
26
 
27
+ declare interface ContentType extends Lookup {
28
+ fields: ContentTypeField[];
29
+ }
30
+
31
+ declare interface ContentTypeField extends Lookup {
32
+ type: FieldType;
33
+ tsType: string;
34
+ isArray: boolean;
35
+ isRequired?: boolean;
36
+ }
37
+
28
38
  export declare const createClient: (options: Options) => ApiClient;
29
39
 
30
40
  export declare interface Field {
@@ -36,16 +46,15 @@ export declare interface Field {
36
46
  language: string;
37
47
  }
38
48
 
39
- export declare type FieldType = 'short-text' | 'long-text' | 'number' | 'date' | 'date-time' | 'media' | 'boolean';
49
+ export { FieldType }
50
+
51
+ export { Lookup }
40
52
 
41
53
  export declare const mapContentToModel: <M extends Model<Language> = Model<any> & Record<string, any>, Language = M["language"]>(content: Content, language?: Language) => M;
42
54
 
43
- export declare interface Media {
44
- name: string;
45
- url: string;
46
- }
55
+ export { Media }
47
56
 
48
- declare type Model<Language = string> = {
57
+ export declare type Model<Language = string> = {
49
58
  id: string;
50
59
  language?: Language;
51
60
  };
@@ -61,7 +70,7 @@ export declare interface Project {
61
70
  id: string;
62
71
  name: string;
63
72
  languages: string[];
64
- contentTypes?: ApiLookup[];
73
+ contentTypes?: ContentType[];
65
74
  }
66
75
 
67
76
  declare type Query<M extends Model = Model> = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@content-island/api-client",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "Content Island - REST API Client",
5
5
  "private": false,
6
6
  "sideEffects": false,