@content-island/api-client 0.14.1 → 0.16.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 +48 -9
- package/dist/index.js +10 -8
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare type AllowedModelFields<M extends Model, ValueType> = Partial<Omit<{
|
|
2
|
-
[K in keyof M as M[K] extends
|
|
2
|
+
[K in keyof M as IsPrimitive<NonNullable<M[K]>> extends true ? `fields.${string & K}` : never]?: ValueType;
|
|
3
3
|
}, 'fields.id' | 'fields.language'>>;
|
|
4
4
|
|
|
5
5
|
export declare interface ApiClient {
|
|
@@ -12,8 +12,15 @@ export declare interface ApiClient {
|
|
|
12
12
|
updateContentFieldValue: (contentId: string, fieldId: string, value: any) => Promise<boolean>;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
declare interface BaseModel {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
type: ModelType;
|
|
19
|
+
}
|
|
20
|
+
|
|
15
21
|
export declare type ClientFilter<Type = string | boolean> = Type | {
|
|
16
22
|
in?: Type[];
|
|
23
|
+
ne?: Type;
|
|
17
24
|
};
|
|
18
25
|
|
|
19
26
|
export declare interface Content {
|
|
@@ -30,10 +37,6 @@ export declare type ContentListSizeQueryParams<M extends Model = Model & Record<
|
|
|
30
37
|
|
|
31
38
|
export declare type ContentQueryParams<M extends Model = Model & Record<string, any>> = Omit<QueryParams<M>, 'sort' | 'pagination'>;
|
|
32
39
|
|
|
33
|
-
declare interface ContentType extends Lookup {
|
|
34
|
-
fields: ContentTypeField[];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
40
|
declare interface ContentTypeField extends Lookup {
|
|
38
41
|
type: FieldType;
|
|
39
42
|
tsType: string;
|
|
@@ -43,6 +46,27 @@ declare interface ContentTypeField extends Lookup {
|
|
|
43
46
|
|
|
44
47
|
export declare const createClient: (options: Options) => ApiClient;
|
|
45
48
|
|
|
49
|
+
declare interface Entity extends BaseModel {
|
|
50
|
+
type: 'entity';
|
|
51
|
+
fieldList?: Field_2[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
declare type EntityContentType = Omit<Entity, 'fieldList'> & {
|
|
55
|
+
fields: ContentTypeField[];
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
declare interface Enum extends BaseModel {
|
|
59
|
+
type: 'enum';
|
|
60
|
+
values: EnumValue[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
declare type EnumContentType = Enum;
|
|
64
|
+
|
|
65
|
+
declare interface EnumValue {
|
|
66
|
+
id: string;
|
|
67
|
+
value: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
46
70
|
export declare interface Field {
|
|
47
71
|
id: string;
|
|
48
72
|
name: string;
|
|
@@ -52,7 +76,14 @@ export declare interface Field {
|
|
|
52
76
|
language: string;
|
|
53
77
|
}
|
|
54
78
|
|
|
55
|
-
declare
|
|
79
|
+
declare interface Field_2 {
|
|
80
|
+
id: string;
|
|
81
|
+
name: string;
|
|
82
|
+
type: FieldType;
|
|
83
|
+
isArray: boolean;
|
|
84
|
+
order: number;
|
|
85
|
+
validations?: Validation[];
|
|
86
|
+
}
|
|
56
87
|
|
|
57
88
|
export declare type FieldType =
|
|
58
89
|
| 'short-text'
|
|
@@ -63,16 +94,18 @@ export declare type FieldType =
|
|
|
63
94
|
| 'media'
|
|
64
95
|
| 'boolean'
|
|
65
96
|
| 'color'
|
|
66
|
-
|
|
|
97
|
+
| RelatedModelType;
|
|
67
98
|
|
|
68
99
|
declare type FilterableFields<M extends Model = Model> = {
|
|
69
100
|
id?: ClientFilter;
|
|
70
101
|
lastUpdate?: ClientFilter;
|
|
71
|
-
language?:
|
|
102
|
+
language?: M['language'];
|
|
72
103
|
contentType?: ClientFilter;
|
|
73
104
|
includeRelatedContent?: boolean;
|
|
74
105
|
} & AllowedModelFields<M, ClientFilter>;
|
|
75
106
|
|
|
107
|
+
declare type IsPrimitive<T> = [T] extends [string | number | boolean] ? true : false;
|
|
108
|
+
|
|
76
109
|
export declare type LanguageCode =
|
|
77
110
|
| 'aa'
|
|
78
111
|
| 'ab'
|
|
@@ -277,6 +310,8 @@ export declare type Model<Language = string> = {
|
|
|
277
310
|
lastUpdate?: string;
|
|
278
311
|
};
|
|
279
312
|
|
|
313
|
+
declare type ModelType = 'entity' | 'enum';
|
|
314
|
+
|
|
280
315
|
export declare interface Options {
|
|
281
316
|
accessToken: string;
|
|
282
317
|
domain?: string;
|
|
@@ -294,7 +329,7 @@ export declare interface Project {
|
|
|
294
329
|
id: string;
|
|
295
330
|
name: string;
|
|
296
331
|
languages: LanguageCode[];
|
|
297
|
-
contentTypes?:
|
|
332
|
+
contentTypes?: (EntityContentType | EnumContentType)[];
|
|
298
333
|
}
|
|
299
334
|
|
|
300
335
|
declare type QueryParams<M extends Model = Model & Record<string, any>> = FilterableFields<M> & {
|
|
@@ -302,6 +337,8 @@ declare type QueryParams<M extends Model = Model & Record<string, any>> = Filter
|
|
|
302
337
|
pagination?: Pagination;
|
|
303
338
|
};
|
|
304
339
|
|
|
340
|
+
declare type RelatedModelType = `${string}|${string}`;
|
|
341
|
+
|
|
305
342
|
declare type SortableFields<M extends Model> = {
|
|
306
343
|
contentType?: SortOrder;
|
|
307
344
|
lastUpdate?: SortOrder;
|
|
@@ -309,4 +346,6 @@ declare type SortableFields<M extends Model> = {
|
|
|
309
346
|
|
|
310
347
|
declare type SortOrder = 'asc' | 'desc';
|
|
311
348
|
|
|
349
|
+
declare type Validation = { name: string; customArgs?: any };
|
|
350
|
+
|
|
312
351
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
const
|
|
1
|
+
const N = (t, e) => {
|
|
2
2
|
if (typeof e == "string" || typeof e == "boolean")
|
|
3
3
|
return `${t}=${e}`;
|
|
4
4
|
if (e.in)
|
|
5
5
|
return `${t}[in]=${e.in.join(",")}`;
|
|
6
|
+
if (e.ne)
|
|
7
|
+
return `${t}[ne]=${e.ne}`;
|
|
6
8
|
}, A = (t) => Object.entries(t).map(([e, n]) => `${e}:${n}`).join(","), O = (t, e) => {
|
|
7
9
|
let n = "";
|
|
8
10
|
return t.take !== void 0 && (n += `take=${t.take}`), t.skip !== void 0 && (n += n ? `${e}skip=${t.skip}` : `skip=${t.skip}`), n;
|
|
@@ -15,10 +17,10 @@ const $ = (t, e) => {
|
|
|
15
17
|
return a === 0 ? r : `${n}${e}${r}`;
|
|
16
18
|
} else if (s !== void 0 && o !== "sort" && o !== "pagination") {
|
|
17
19
|
const r = s;
|
|
18
|
-
return a === 0 ?
|
|
20
|
+
return a === 0 ? N(o, r) : `${n}${e}${N(o, r)}`;
|
|
19
21
|
}
|
|
20
22
|
return n;
|
|
21
|
-
}, ""), S = (t) => t && Object.keys(t).length > 0 ? `?${_(t, "&")}` : "",
|
|
23
|
+
}, ""), S = (t) => t && Object.keys(t).length > 0 ? `?${_(t, "&")}` : "", $ = {
|
|
22
24
|
IS_PRODUCTION: !0,
|
|
23
25
|
DEFAULT_API_CLIENT_DOMAIN: "api.contentisland.net",
|
|
24
26
|
DEFAULT_API_CLIENT_VERSION: "1.0"
|
|
@@ -27,7 +29,7 @@ const $ = (t, e) => {
|
|
|
27
29
|
SESSION_TYPE: "Bearer",
|
|
28
30
|
METADATA_KEY: "x-metadata"
|
|
29
31
|
}, l = (t) => {
|
|
30
|
-
const n = (t.secureProtocol === void 0 ?
|
|
32
|
+
const n = (t.secureProtocol === void 0 ? $.IS_PRODUCTION : t.secureProtocol) ? "https" : "http", o = t.domain ? t.domain : $.DEFAULT_API_CLIENT_DOMAIN, s = t.apiVersion ? t.apiVersion : $.DEFAULT_API_CLIENT_VERSION;
|
|
31
33
|
return `${n}://${o}/api/${s}`;
|
|
32
34
|
}, d = async (t, e) => fetch(`${l(e)}${t}`, {
|
|
33
35
|
headers: {
|
|
@@ -63,22 +65,22 @@ const $ = (t, e) => {
|
|
|
63
65
|
}), T = {
|
|
64
66
|
get: d,
|
|
65
67
|
put: C
|
|
66
|
-
}, I = (t) => t == null ? void 0 : t.includes("|"), p = (t, e) => Array.isArray(t) ? t.map(e) : [], L = (t, e) => t.isArray ? p(t.value, (n) => E(n, e)) : E(t.value, e), f = (t) => I(t.type) && (t.isArray ? t.value.every((e) => typeof e == "object" && "contentType" in e) : typeof t.value == "object" && "contentType" in t.value),
|
|
68
|
+
}, I = (t) => t == null ? void 0 : t.includes("|"), p = (t, e) => Array.isArray(t) ? t.map(e) : [], L = (t, e) => t.isArray ? p(t.value, (n) => E(n, e)) : E(t.value, e), f = (t) => I(t.type) && (t.isArray ? t.value.every((e) => typeof e == "object" && "contentType" in e) : typeof t.value == "object" && "contentType" in t.value), h = (t, e) => t.reduce(
|
|
67
69
|
(n, o) => ({
|
|
68
70
|
...n,
|
|
69
71
|
[o.name]: f(o) ? L(o, e) : o.value
|
|
70
72
|
}),
|
|
71
73
|
{}
|
|
72
|
-
),
|
|
74
|
+
), y = (t, e, n, o) => {
|
|
73
75
|
var c;
|
|
74
|
-
const s = n ?? ((c = t[0]) == null ? void 0 : c.language), a = t.filter((g) => g.language === s), r =
|
|
76
|
+
const s = n ?? ((c = t[0]) == null ? void 0 : c.language), a = t.filter((g) => g.language === s), r = h(a, s);
|
|
75
77
|
return Object.keys(r).length === 0 && console.warn(`No fields found for language "${s}" and content id "${e}"`), {
|
|
76
78
|
id: e,
|
|
77
79
|
language: s,
|
|
78
80
|
lastUpdate: o,
|
|
79
81
|
...r
|
|
80
82
|
};
|
|
81
|
-
}, E = (t, e) => Array.isArray(t == null ? void 0 : t.fields) ?
|
|
83
|
+
}, E = (t, e) => Array.isArray(t == null ? void 0 : t.fields) ? y(t.fields, t.id, e, t.lastUpdate) : {}, u = {
|
|
82
84
|
PROJECT: "/project",
|
|
83
85
|
CONTENT_LIST: (t) => `/contents${S(t)}`,
|
|
84
86
|
CONTENT: (t) => `/content${S(t)}`,
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(i,T){typeof exports=="object"&&typeof module<"u"?T(exports):typeof define=="function"&&define.amd?define(["exports"],T):(i=typeof globalThis<"u"?globalThis:i||self,T(i.ApiClient={}))})(this,function(i){"use strict";const T=(t,e)=>{if(typeof e=="string"||typeof e=="boolean")return`${t}=${e}`;if(e.in)return`${t}[in]=${e.in.join(",")}`},A=t=>Object.entries(t).map(([e,n])=>`${e}:${n}`).join(","),O=(t,e)=>{let n="";return t.take!==void 0&&(n+=`take=${t.take}`),t.skip!==void 0&&(n+=n?`${e}skip=${t.skip}`:`skip=${t.skip}`),n},C=(t,e)=>Object.entries(t).reduce((n,[a,
|
|
1
|
+
(function(i,T){typeof exports=="object"&&typeof module<"u"?T(exports):typeof define=="function"&&define.amd?define(["exports"],T):(i=typeof globalThis<"u"?globalThis:i||self,T(i.ApiClient={}))})(this,function(i){"use strict";const T=(t,e)=>{if(typeof e=="string"||typeof e=="boolean")return`${t}=${e}`;if(e.in)return`${t}[in]=${e.in.join(",")}`;if(e.ne)return`${t}[ne]=${e.ne}`},A=t=>Object.entries(t).map(([e,n])=>`${e}:${n}`).join(","),O=(t,e)=>{let n="";return t.take!==void 0&&(n+=`take=${t.take}`),t.skip!==void 0&&(n+=n?`${e}skip=${t.skip}`:`skip=${t.skip}`),n},C=(t,e)=>Object.entries(t).reduce((n,[a,r],o)=>{if(a==="sort"&&typeof r=="object"&&r!==null&&!Array.isArray(r)){const s=A(r);return o===0?`sort=${s}`:`${n}${e}sort=${s}`}else if(a==="pagination"&&typeof r=="object"&&r!==null){const s=O(r,e);return o===0?s:`${n}${e}${s}`}else if(r!==void 0&&a!=="sort"&&a!=="pagination"){const s=r;return o===0?T(a,s):`${n}${e}${T(a,s)}`}return n},""),S=t=>t&&Object.keys(t).length>0?`?${C(t,"&")}`:"",d={IS_PRODUCTION:!0,DEFAULT_API_CLIENT_DOMAIN:"api.contentisland.net",DEFAULT_API_CLIENT_VERSION:"1.0"},u={SESSION_KEY:"authorization",SESSION_TYPE:"Bearer",METADATA_KEY:"x-metadata"},N=t=>{const n=(t.secureProtocol===void 0?d.IS_PRODUCTION:t.secureProtocol)?"https":"http",a=t.domain?t.domain:d.DEFAULT_API_CLIENT_DOMAIN,r=t.apiVersion?t.apiVersion:d.DEFAULT_API_CLIENT_VERSION;return`${n}://${a}/api/${r}`},g={get:async(t,e)=>fetch(`${N(e)}${t}`,{headers:{[u.SESSION_KEY]:`${u.SESSION_TYPE} ${e.accessToken}`,...e.metadata?{[u.METADATA_KEY]:e.metadata}:{}}}).then(n=>{if(n.ok)return n.json();throw Error(JSON.stringify({status:n.status,statusText:n.statusText}))}),put:async(t,e,n)=>fetch(`${N(n)}${t}`,{method:"PUT",headers:{"Content-Type":"application/json",[u.SESSION_KEY]:`${u.SESSION_TYPE} ${n.accessToken}`,...n.metadata?{[u.METADATA_KEY]:n.metadata}:{}},body:JSON.stringify(e)}).then(a=>{if(a.ok)return!0;throw Error(JSON.stringify({status:a.status,statusText:a.statusText}))})},_=t=>t==null?void 0:t.includes("|"),p=(t,e)=>Array.isArray(t)?t.map(e):[],f=(t,e)=>t.isArray?p(t.value,n=>l(n,e)):l(t.value,e),I=t=>_(t.type)&&(t.isArray?t.value.every(e=>typeof e=="object"&&"contentType"in e):typeof t.value=="object"&&"contentType"in t.value),L=(t,e)=>t.reduce((n,a)=>({...n,[a.name]:I(a)?f(a,e):a.value}),{}),h=(t,e,n,a)=>{var c;const r=n??((c=t[0])==null?void 0:c.language),o=t.filter($=>$.language===r),s=L(o,r);return Object.keys(s).length===0&&console.warn(`No fields found for language "${r}" and content id "${e}"`),{id:e,language:r,lastUpdate:a,...s}},l=(t,e)=>Array.isArray(t==null?void 0:t.fields)?h(t.fields,t.id,e,t.lastUpdate):{},E={PROJECT:"/project",CONTENT_LIST:t=>`/contents${S(t)}`,CONTENT:t=>`/content${S(t)}`,CONTENT_LIST_SIZE:t=>t?`/contents/size${S(t)}`:"/contents/size"},y=t=>{const e=o=>g.get(E.CONTENT_LIST(o),t),n=o=>g.get(E.CONTENT(o),t),a=()=>g.get(E.PROJECT,t),r=async()=>{var s;const o=await a();return(s=o==null?void 0:o.languages)==null?void 0:s[0]};return{getProject:a,getContentList:async o=>{const s=await e(o),c=(o==null?void 0:o.language)??await r();return Array.isArray(s)?s.map($=>l($,c)):[]},getContent:async o=>{const s=await n(o),c=(o==null?void 0:o.language)??await r();return l(s,c)},getRawContentList:e,getRawContent:n,getContentListSize:o=>g.get(E.CONTENT_LIST_SIZE(o),t),updateContentFieldValue:(o,s,c)=>g.put(`${E.CONTENT(null)}/${o}`,{id:s,value:c},t)}};i.createClient=y,i.mapContentToModel=l,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|