@content-island/api-client 0.10.0 → 0.11.0
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/dist/index.d.ts +225 -15
- package/dist/index.js +41 -27
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
declare type AllowedModelFields<M extends Model, ValueType> = Partial<Omit<{
|
|
2
|
+
[K in keyof M as M[K] extends string | number | boolean ? `fields.${string & K}` : never]?: ValueType;
|
|
3
|
+
}, 'fields.id' | 'fields.language'>>;
|
|
4
|
+
|
|
1
5
|
export declare interface ApiClient {
|
|
2
6
|
getProject: () => Promise<Project>;
|
|
3
|
-
getContentList: <M extends Model = Model & Record<string, any>>(queryParam?:
|
|
4
|
-
getContent: <M extends Model = Model & Record<string, any>>(queryParam:
|
|
5
|
-
getRawContentList: <M extends Model = Model & Record<string, any>>(queryParam?:
|
|
6
|
-
getRawContent: <M extends Model = Model & Record<string, any>>(queryParam:
|
|
7
|
+
getContentList: <M extends Model = Model & Record<string, any>>(queryParam?: ContentListQueryParams<M>) => Promise<M[]>;
|
|
8
|
+
getContent: <M extends Model = Model & Record<string, any>>(queryParam: ContentQueryParams<M>) => Promise<M>;
|
|
9
|
+
getRawContentList: <M extends Model = Model & Record<string, any>>(queryParam?: ContentListQueryParams<M>) => Promise<Content[]>;
|
|
10
|
+
getRawContent: <M extends Model = Model & Record<string, any>>(queryParam: ContentQueryParams<M>) => Promise<Content>;
|
|
11
|
+
getContentListSize: <M extends Model = Model & Record<string, any>>(queryParam?: ContentListSizeQueryParams<M>) => Promise<number>;
|
|
7
12
|
}
|
|
8
13
|
|
|
9
14
|
export declare type ClientFilter<Type = string | boolean> = Type | {
|
|
@@ -17,6 +22,12 @@ export declare interface Content {
|
|
|
17
22
|
fields: Field[];
|
|
18
23
|
}
|
|
19
24
|
|
|
25
|
+
export declare type ContentListQueryParams<M extends Model = Model & Record<string, any>> = QueryParams<M>;
|
|
26
|
+
|
|
27
|
+
export declare type ContentListSizeQueryParams<M extends Model = Model & Record<string, any>> = Omit<QueryParams<M>, 'sort' | 'pagination' | 'includeRelatedContent'>;
|
|
28
|
+
|
|
29
|
+
export declare type ContentQueryParams<M extends Model = Model & Record<string, any>> = Omit<QueryParams<M>, 'sort' | 'pagination'>;
|
|
30
|
+
|
|
20
31
|
declare interface ContentType extends Lookup {
|
|
21
32
|
fields: ContentTypeField[];
|
|
22
33
|
}
|
|
@@ -52,6 +63,200 @@ export declare type FieldType =
|
|
|
52
63
|
| 'color'
|
|
53
64
|
| FieldEntityType;
|
|
54
65
|
|
|
66
|
+
declare type FilterableFields<M extends Model = Model> = {
|
|
67
|
+
id?: ClientFilter;
|
|
68
|
+
lastUpdate?: ClientFilter;
|
|
69
|
+
language?: ClientFilter<M['language'] extends undefined ? string : M['language']>;
|
|
70
|
+
contentType?: ClientFilter;
|
|
71
|
+
includeRelatedContent?: boolean;
|
|
72
|
+
} & AllowedModelFields<M, ClientFilter>;
|
|
73
|
+
|
|
74
|
+
declare type LanguageCode =
|
|
75
|
+
| 'aa'
|
|
76
|
+
| 'ab'
|
|
77
|
+
| 'ae'
|
|
78
|
+
| 'af'
|
|
79
|
+
| 'ak'
|
|
80
|
+
| 'am'
|
|
81
|
+
| 'an'
|
|
82
|
+
| 'ar'
|
|
83
|
+
| 'as'
|
|
84
|
+
| 'av'
|
|
85
|
+
| 'ay'
|
|
86
|
+
| 'az'
|
|
87
|
+
| 'ba'
|
|
88
|
+
| 'be'
|
|
89
|
+
| 'bg'
|
|
90
|
+
| 'bh'
|
|
91
|
+
| 'bi'
|
|
92
|
+
| 'bm'
|
|
93
|
+
| 'bn'
|
|
94
|
+
| 'bo'
|
|
95
|
+
| 'br'
|
|
96
|
+
| 'bs'
|
|
97
|
+
| 'ca'
|
|
98
|
+
| 'ce'
|
|
99
|
+
| 'ch'
|
|
100
|
+
| 'co'
|
|
101
|
+
| 'cr'
|
|
102
|
+
| 'cs'
|
|
103
|
+
| 'cu'
|
|
104
|
+
| 'cv'
|
|
105
|
+
| 'cy'
|
|
106
|
+
| 'da'
|
|
107
|
+
| 'de'
|
|
108
|
+
| 'dv'
|
|
109
|
+
| 'dz'
|
|
110
|
+
| 'ee'
|
|
111
|
+
| 'el'
|
|
112
|
+
| 'en'
|
|
113
|
+
| 'eo'
|
|
114
|
+
| 'es'
|
|
115
|
+
| 'et'
|
|
116
|
+
| 'eu'
|
|
117
|
+
| 'fa'
|
|
118
|
+
| 'ff'
|
|
119
|
+
| 'fi'
|
|
120
|
+
| 'fj'
|
|
121
|
+
| 'fo'
|
|
122
|
+
| 'fr'
|
|
123
|
+
| 'fy'
|
|
124
|
+
| 'ga'
|
|
125
|
+
| 'gd'
|
|
126
|
+
| 'gl'
|
|
127
|
+
| 'gn'
|
|
128
|
+
| 'gu'
|
|
129
|
+
| 'gv'
|
|
130
|
+
| 'ha'
|
|
131
|
+
| 'he'
|
|
132
|
+
| 'hi'
|
|
133
|
+
| 'ho'
|
|
134
|
+
| 'hr'
|
|
135
|
+
| 'ht'
|
|
136
|
+
| 'hu'
|
|
137
|
+
| 'hy'
|
|
138
|
+
| 'hz'
|
|
139
|
+
| 'ia'
|
|
140
|
+
| 'id'
|
|
141
|
+
| 'ie'
|
|
142
|
+
| 'ig'
|
|
143
|
+
| 'ii'
|
|
144
|
+
| 'ik'
|
|
145
|
+
| 'io'
|
|
146
|
+
| 'is'
|
|
147
|
+
| 'it'
|
|
148
|
+
| 'iu'
|
|
149
|
+
| 'ja'
|
|
150
|
+
| 'jv'
|
|
151
|
+
| 'ka'
|
|
152
|
+
| 'kg'
|
|
153
|
+
| 'ki'
|
|
154
|
+
| 'kj'
|
|
155
|
+
| 'kk'
|
|
156
|
+
| 'kl'
|
|
157
|
+
| 'km'
|
|
158
|
+
| 'kn'
|
|
159
|
+
| 'ko'
|
|
160
|
+
| 'kr'
|
|
161
|
+
| 'ks'
|
|
162
|
+
| 'ku'
|
|
163
|
+
| 'kv'
|
|
164
|
+
| 'kw'
|
|
165
|
+
| 'ky'
|
|
166
|
+
| 'la'
|
|
167
|
+
| 'lb'
|
|
168
|
+
| 'lg'
|
|
169
|
+
| 'li'
|
|
170
|
+
| 'ln'
|
|
171
|
+
| 'lo'
|
|
172
|
+
| 'lt'
|
|
173
|
+
| 'lu'
|
|
174
|
+
| 'lv'
|
|
175
|
+
| 'mg'
|
|
176
|
+
| 'mh'
|
|
177
|
+
| 'mi'
|
|
178
|
+
| 'mk'
|
|
179
|
+
| 'ml'
|
|
180
|
+
| 'mn'
|
|
181
|
+
| 'mr'
|
|
182
|
+
| 'ms'
|
|
183
|
+
| 'mt'
|
|
184
|
+
| 'my'
|
|
185
|
+
| 'na'
|
|
186
|
+
| 'nb'
|
|
187
|
+
| 'nd'
|
|
188
|
+
| 'ne'
|
|
189
|
+
| 'ng'
|
|
190
|
+
| 'nl'
|
|
191
|
+
| 'nn'
|
|
192
|
+
| 'no'
|
|
193
|
+
| 'nr'
|
|
194
|
+
| 'nv'
|
|
195
|
+
| 'ny'
|
|
196
|
+
| 'oc'
|
|
197
|
+
| 'oj'
|
|
198
|
+
| 'om'
|
|
199
|
+
| 'or'
|
|
200
|
+
| 'os'
|
|
201
|
+
| 'pa'
|
|
202
|
+
| 'pi'
|
|
203
|
+
| 'pl'
|
|
204
|
+
| 'ps'
|
|
205
|
+
| 'pt'
|
|
206
|
+
| 'qu'
|
|
207
|
+
| 'rm'
|
|
208
|
+
| 'rn'
|
|
209
|
+
| 'ro'
|
|
210
|
+
| 'ru'
|
|
211
|
+
| 'rw'
|
|
212
|
+
| 'sa'
|
|
213
|
+
| 'sc'
|
|
214
|
+
| 'sd'
|
|
215
|
+
| 'se'
|
|
216
|
+
| 'sg'
|
|
217
|
+
| 'si'
|
|
218
|
+
| 'sk'
|
|
219
|
+
| 'sl'
|
|
220
|
+
| 'sm'
|
|
221
|
+
| 'sn'
|
|
222
|
+
| 'so'
|
|
223
|
+
| 'sq'
|
|
224
|
+
| 'sr'
|
|
225
|
+
| 'ss'
|
|
226
|
+
| 'st'
|
|
227
|
+
| 'su'
|
|
228
|
+
| 'sv'
|
|
229
|
+
| 'sw'
|
|
230
|
+
| 'ta'
|
|
231
|
+
| 'te'
|
|
232
|
+
| 'tg'
|
|
233
|
+
| 'th'
|
|
234
|
+
| 'ti'
|
|
235
|
+
| 'tk'
|
|
236
|
+
| 'tl'
|
|
237
|
+
| 'tn'
|
|
238
|
+
| 'to'
|
|
239
|
+
| 'tr'
|
|
240
|
+
| 'ts'
|
|
241
|
+
| 'tt'
|
|
242
|
+
| 'tw'
|
|
243
|
+
| 'ty'
|
|
244
|
+
| 'ug'
|
|
245
|
+
| 'uk'
|
|
246
|
+
| 'ur'
|
|
247
|
+
| 'uz'
|
|
248
|
+
| 've'
|
|
249
|
+
| 'vi'
|
|
250
|
+
| 'vo'
|
|
251
|
+
| 'wa'
|
|
252
|
+
| 'wo'
|
|
253
|
+
| 'xh'
|
|
254
|
+
| 'yi'
|
|
255
|
+
| 'yo'
|
|
256
|
+
| 'za'
|
|
257
|
+
| 'zh'
|
|
258
|
+
| 'zu';
|
|
259
|
+
|
|
55
260
|
export declare interface Lookup<ID = string> {
|
|
56
261
|
id: ID;
|
|
57
262
|
name: string;
|
|
@@ -76,23 +281,28 @@ export declare interface Options {
|
|
|
76
281
|
apiVersion?: string;
|
|
77
282
|
}
|
|
78
283
|
|
|
284
|
+
declare type Pagination = {
|
|
285
|
+
take?: number;
|
|
286
|
+
skip?: number;
|
|
287
|
+
};
|
|
288
|
+
|
|
79
289
|
export declare interface Project {
|
|
80
290
|
id: string;
|
|
81
291
|
name: string;
|
|
82
|
-
languages:
|
|
292
|
+
languages: LanguageCode[];
|
|
83
293
|
contentTypes?: ContentType[];
|
|
84
294
|
}
|
|
85
295
|
|
|
86
|
-
declare type
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
296
|
+
declare type QueryParams<M extends Model = Model & Record<string, any>> = FilterableFields<M> & {
|
|
297
|
+
sort?: SortableFields<M>;
|
|
298
|
+
pagination?: Pagination;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
declare type SortableFields<M extends Model> = {
|
|
302
|
+
contentType?: SortOrder;
|
|
303
|
+
lastUpdate?: SortOrder;
|
|
304
|
+
} & AllowedModelFields<M, SortOrder>;
|
|
95
305
|
|
|
96
|
-
|
|
306
|
+
declare type SortOrder = 'asc' | 'desc';
|
|
97
307
|
|
|
98
308
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,42 +1,55 @@
|
|
|
1
|
-
const
|
|
1
|
+
const N = {
|
|
2
2
|
IS_PRODUCTION: !0,
|
|
3
3
|
DEFAULT_API_CLIENT_DOMAIN: "api.contentisland.net",
|
|
4
4
|
DEFAULT_API_CLIENT_VERSION: "1.0"
|
|
5
|
-
},
|
|
5
|
+
}, $ = {
|
|
6
6
|
SESSION_KEY: "authorization",
|
|
7
7
|
SESSION_TYPE: "Bearer"
|
|
8
|
-
},
|
|
8
|
+
}, g = (t) => t == null ? void 0 : t.includes("|"), l = (t, e) => Array.isArray(t) ? t.map(e) : [], I = (t, e) => t.isArray ? l(t.value, (o) => T(o, e)) : T(t.value, e), O = (t) => g(t.type) && (t.isArray ? t.value.every((e) => typeof e == "object" && "contentType" in e) : typeof t.value == "object" && "contentType" in t.value), _ = (t, e) => t.reduce(
|
|
9
9
|
(o, n) => ({
|
|
10
10
|
...o,
|
|
11
|
-
[n.name]:
|
|
11
|
+
[n.name]: O(n) ? I(n, e) : n.value
|
|
12
12
|
}),
|
|
13
13
|
{}
|
|
14
|
-
),
|
|
15
|
-
var
|
|
16
|
-
const n = o ?? ((
|
|
17
|
-
return Object.keys(
|
|
14
|
+
), C = (t, e, o) => {
|
|
15
|
+
var s;
|
|
16
|
+
const n = o ?? ((s = t[0]) == null ? void 0 : s.language), r = t.filter((E) => E.language === n), c = _(r, n);
|
|
17
|
+
return Object.keys(c).length === 0 && console.warn(`No fields found for language "${n}" and content id "${e}"`), {
|
|
18
18
|
id: e,
|
|
19
19
|
language: n,
|
|
20
|
-
...
|
|
20
|
+
...c
|
|
21
21
|
};
|
|
22
|
-
},
|
|
22
|
+
}, T = (t, e) => Array.isArray(t == null ? void 0 : t.fields) ? C(t.fields, t.id, e) : {}, u = (t, e) => {
|
|
23
23
|
if (typeof e == "string" || typeof e == "boolean")
|
|
24
24
|
return `${t}=${e}`;
|
|
25
25
|
if (e.in)
|
|
26
26
|
return `${t}[in]=${e.in.join(",")}`;
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
}, p = (t) => Object.entries(t).map(([e, o]) => `${e}:${o}`).join(","), A = (t, e) => {
|
|
28
|
+
let o = "";
|
|
29
|
+
return t.take !== void 0 && (o += `take=${t.take}`), t.skip !== void 0 && (o += o ? `${e}skip=${t.skip}` : `skip=${t.skip}`), o;
|
|
30
|
+
}, L = (t, e) => Object.entries(t).reduce((o, [n, r], c) => {
|
|
31
|
+
if (n === "sort" && typeof r == "object" && r !== null && !Array.isArray(r)) {
|
|
32
|
+
const s = p(r);
|
|
33
|
+
return c === 0 ? `sort=${s}` : `${o}${e}sort=${s}`;
|
|
34
|
+
} else if (n === "pagination" && typeof r == "object" && r !== null) {
|
|
35
|
+
const s = A(r, e);
|
|
36
|
+
return c === 0 ? s : `${o}${e}${s}`;
|
|
37
|
+
} else if (r !== void 0 && n !== "sort" && n !== "pagination") {
|
|
38
|
+
const s = r;
|
|
39
|
+
return c === 0 ? u(n, s) : `${o}${e}${u(n, s)}`;
|
|
40
|
+
}
|
|
41
|
+
return o;
|
|
42
|
+
}, ""), S = (t) => t && Object.keys(t).length > 0 ? `?${L(t, "&")}` : "", i = {
|
|
31
43
|
PROJECT: "/project",
|
|
32
|
-
CONTENT_LIST: (t) => `/contents${
|
|
33
|
-
CONTENT: (t) => `/content${
|
|
44
|
+
CONTENT_LIST: (t) => `/contents${S(t)}`,
|
|
45
|
+
CONTENT: (t) => `/content${S(t)}`,
|
|
46
|
+
CONTENT_LIST_SIZE: (t) => t ? `/contents/size${S(t)}` : "/contents/size"
|
|
34
47
|
}, d = (t) => {
|
|
35
|
-
const o = (t.secureProtocol === void 0 ?
|
|
48
|
+
const o = (t.secureProtocol === void 0 ? N.IS_PRODUCTION : t.secureProtocol) ? "https" : "http", n = t.domain ? t.domain : N.DEFAULT_API_CLIENT_DOMAIN, r = t.apiVersion ? t.apiVersion : N.DEFAULT_API_CLIENT_VERSION;
|
|
36
49
|
return `${o}://${n}/api/${r}`;
|
|
37
|
-
},
|
|
50
|
+
}, a = async (t, e) => fetch(`${d(e)}${t}`, {
|
|
38
51
|
headers: {
|
|
39
|
-
[
|
|
52
|
+
[$.SESSION_KEY]: `${$.SESSION_TYPE} ${e.accessToken}`
|
|
40
53
|
}
|
|
41
54
|
}).then((o) => {
|
|
42
55
|
if (o.ok)
|
|
@@ -47,23 +60,24 @@ const a = {
|
|
|
47
60
|
statusText: o.statusText
|
|
48
61
|
})
|
|
49
62
|
);
|
|
50
|
-
}),
|
|
51
|
-
const e = (n) => i
|
|
63
|
+
}), f = (t) => {
|
|
64
|
+
const e = (n) => a(i.CONTENT_LIST(n), t), o = (n) => a(i.CONTENT(n), t);
|
|
52
65
|
return {
|
|
53
|
-
getProject: () => i
|
|
66
|
+
getProject: () => a(i.PROJECT, t),
|
|
54
67
|
getContentList: (n) => e(n).then(
|
|
55
68
|
(r) => Array.isArray(r) ? r.map(
|
|
56
|
-
(
|
|
69
|
+
(c) => T(c, n == null ? void 0 : n.language)
|
|
57
70
|
) : []
|
|
58
71
|
),
|
|
59
72
|
getContent: (n) => o(n).then(
|
|
60
|
-
(r) =>
|
|
73
|
+
(r) => T(r, n == null ? void 0 : n.language)
|
|
61
74
|
),
|
|
62
75
|
getRawContentList: e,
|
|
63
|
-
getRawContent: o
|
|
76
|
+
getRawContent: o,
|
|
77
|
+
getContentListSize: (n) => a(i.CONTENT_LIST_SIZE(n), t)
|
|
64
78
|
};
|
|
65
79
|
};
|
|
66
80
|
export {
|
|
67
|
-
|
|
68
|
-
|
|
81
|
+
f as createClient,
|
|
82
|
+
T as mapContentToModel
|
|
69
83
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(c,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(c=typeof globalThis<"u"?globalThis:c||self,a(c.ApiClient={}))})(this,function(c){"use strict";const a={IS_PRODUCTION:!0,DEFAULT_API_CLIENT_DOMAIN:"api.contentisland.net",DEFAULT_API_CLIENT_VERSION:"1.0"},N={SESSION_KEY:"authorization",SESSION_TYPE:"Bearer"},E=t=>t==null?void 0:t.includes("|"),g=(t,e)=>Array.isArray(t)?t.map(e):[],p=(t,e)=>t.isArray?g(t.value,o=>T(o,e)):T(t.value,e),d=t=>E(t.type)&&(t.isArray?t.value.every(e=>typeof e=="object"&&"contentType"in e):typeof t.value=="object"&&"contentType"in t.value),C=(t,e)=>t.reduce((o,n)=>({...o,[n.name]:d(n)?p(n,e):n.value}),{}),O=(t,e,o)=>{var s;const n=o??((s=t[0])==null?void 0:s.language),r=t.filter(h=>h.language===n),i=C(r,n);return Object.keys(i).length===0&&console.warn(`No fields found for language "${n}" and content id "${e}"`),{id:e,language:n,...i}},T=(t,e)=>Array.isArray(t==null?void 0:t.fields)?O(t.fields,t.id,e):{},$=(t,e)=>{if(typeof e=="string"||typeof e=="boolean")return`${t}=${e}`;if(e.in)return`${t}[in]=${e.in.join(",")}`},I=t=>Object.entries(t).map(([e,o])=>`${e}:${o}`).join(","),_=(t,e)=>{let o="";return t.take!==void 0&&(o+=`take=${t.take}`),t.skip!==void 0&&(o+=o?`${e}skip=${t.skip}`:`skip=${t.skip}`),o},f=(t,e)=>Object.entries(t).reduce((o,[n,r],i)=>{if(n==="sort"&&typeof r=="object"&&r!==null&&!Array.isArray(r)){const s=I(r);return i===0?`sort=${s}`:`${o}${e}sort=${s}`}else if(n==="pagination"&&typeof r=="object"&&r!==null){const s=_(r,e);return i===0?s:`${o}${e}${s}`}else if(r!==void 0&&n!=="sort"&&n!=="pagination"){const s=r;return i===0?$(n,s):`${o}${e}${$(n,s)}`}return o},""),S=t=>t&&Object.keys(t).length>0?`?${f(t,"&")}`:"",u={PROJECT:"/project",CONTENT_LIST:t=>`/contents${S(t)}`,CONTENT:t=>`/content${S(t)}`,CONTENT_LIST_SIZE:t=>t?`/contents/size${S(t)}`:"/contents/size"},A=t=>{const o=(t.secureProtocol===void 0?a.IS_PRODUCTION:t.secureProtocol)?"https":"http",n=t.domain?t.domain:a.DEFAULT_API_CLIENT_DOMAIN,r=t.apiVersion?t.apiVersion:a.DEFAULT_API_CLIENT_VERSION;return`${o}://${n}/api/${r}`},l=async(t,e)=>fetch(`${A(e)}${t}`,{headers:{[N.SESSION_KEY]:`${N.SESSION_TYPE} ${e.accessToken}`}}).then(o=>{if(o.ok)return o.json();throw Error(JSON.stringify({status:o.status,statusText:o.statusText}))}),L=t=>{const e=n=>l(u.CONTENT_LIST(n),t),o=n=>l(u.CONTENT(n),t);return{getProject:()=>l(u.PROJECT,t),getContentList:n=>e(n).then(r=>Array.isArray(r)?r.map(i=>T(i,n==null?void 0:n.language)):[]),getContent:n=>o(n).then(r=>T(r,n==null?void 0:n.language)),getRawContentList:e,getRawContent:o,getContentListSize:n=>l(u.CONTENT_LIST_SIZE(n),t)}};c.createClient=L,c.mapContentToModel=T,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|