@content-island/api-client 0.13.0 → 0.14.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 +5 -2
- package/dist/index.js +93 -63
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare interface ApiClient {
|
|
|
9
9
|
getRawContentList: <M extends Model = Model & Record<string, any>>(queryParam?: ContentListQueryParams<M>) => Promise<Content[]>;
|
|
10
10
|
getRawContent: <M extends Model = Model & Record<string, any>>(queryParam: ContentQueryParams<M>) => Promise<Content>;
|
|
11
11
|
getContentListSize: <M extends Model = Model & Record<string, any>>(queryParam?: ContentListSizeQueryParams<M>) => Promise<number>;
|
|
12
|
+
updateContentFieldValue: (contentId: string, fieldId: string, value: any) => Promise<boolean>;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export declare type ClientFilter<Type = string | boolean> = Type | {
|
|
@@ -17,8 +18,9 @@ export declare type ClientFilter<Type = string | boolean> = Type | {
|
|
|
17
18
|
|
|
18
19
|
export declare interface Content {
|
|
19
20
|
id: string;
|
|
21
|
+
name: string;
|
|
20
22
|
contentType: Lookup;
|
|
21
|
-
lastUpdate:
|
|
23
|
+
lastUpdate: string;
|
|
22
24
|
fields: Field[];
|
|
23
25
|
}
|
|
24
26
|
|
|
@@ -272,7 +274,7 @@ export declare interface Media {
|
|
|
272
274
|
export declare type Model<Language = string> = {
|
|
273
275
|
id: string;
|
|
274
276
|
language?: Language;
|
|
275
|
-
lastUpdate?:
|
|
277
|
+
lastUpdate?: string;
|
|
276
278
|
};
|
|
277
279
|
|
|
278
280
|
export declare interface Options {
|
|
@@ -280,6 +282,7 @@ export declare interface Options {
|
|
|
280
282
|
domain?: string;
|
|
281
283
|
secureProtocol?: boolean;
|
|
282
284
|
apiVersion?: string;
|
|
285
|
+
metadata?: string;
|
|
283
286
|
}
|
|
284
287
|
|
|
285
288
|
declare type Pagination = {
|
package/dist/index.js
CHANGED
|
@@ -1,84 +1,114 @@
|
|
|
1
|
-
const
|
|
2
|
-
IS_PRODUCTION: !0,
|
|
3
|
-
DEFAULT_API_CLIENT_DOMAIN: "api.contentisland.net",
|
|
4
|
-
DEFAULT_API_CLIENT_VERSION: "1.0"
|
|
5
|
-
}, u = {
|
|
6
|
-
SESSION_KEY: "authorization",
|
|
7
|
-
SESSION_TYPE: "Bearer"
|
|
8
|
-
}, l = (t) => t == null ? void 0 : t.includes("|"), I = (t, e) => Array.isArray(t) ? t.map(e) : [], O = (t, e) => t.isArray ? I(t.value, (o) => T(o, e)) : T(t.value, e), _ = (t) => l(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(
|
|
9
|
-
(o, n) => ({
|
|
10
|
-
...o,
|
|
11
|
-
[n.name]: _(n) ? O(n, e) : n.value
|
|
12
|
-
}),
|
|
13
|
-
{}
|
|
14
|
-
), p = (t, e, o, n) => {
|
|
15
|
-
var $;
|
|
16
|
-
const r = o ?? (($ = t[0]) == null ? void 0 : $.language), c = t.filter((g) => g.language === r), s = C(c, r);
|
|
17
|
-
return Object.keys(s).length === 0 && console.warn(`No fields found for language "${r}" and content id "${e}"`), {
|
|
18
|
-
id: e,
|
|
19
|
-
language: r,
|
|
20
|
-
lastUpdate: n,
|
|
21
|
-
...s
|
|
22
|
-
};
|
|
23
|
-
}, T = (t, e) => Array.isArray(t == null ? void 0 : t.fields) ? p(t.fields, t.id, e, t.lastUpdate) : {}, E = (t, e) => {
|
|
1
|
+
const $ = (t, e) => {
|
|
24
2
|
if (typeof e == "string" || typeof e == "boolean")
|
|
25
3
|
return `${t}=${e}`;
|
|
26
4
|
if (e.in)
|
|
27
5
|
return `${t}[in]=${e.in.join(",")}`;
|
|
28
|
-
}, A = (t) => Object.entries(t).map(([e,
|
|
29
|
-
let
|
|
30
|
-
return t.take !== void 0 && (
|
|
31
|
-
},
|
|
32
|
-
if (n === "sort" && typeof
|
|
33
|
-
const
|
|
34
|
-
return
|
|
35
|
-
} else if (n === "pagination" && typeof
|
|
36
|
-
const
|
|
37
|
-
return
|
|
38
|
-
} else if (
|
|
39
|
-
const
|
|
40
|
-
return
|
|
6
|
+
}, A = (t) => Object.entries(t).map(([e, r]) => `${e}:${r}`).join(","), O = (t, e) => {
|
|
7
|
+
let r = "";
|
|
8
|
+
return t.take !== void 0 && (r += `take=${t.take}`), t.skip !== void 0 && (r += r ? `${e}skip=${t.skip}` : `skip=${t.skip}`), r;
|
|
9
|
+
}, _ = (t, e) => Object.entries(t).reduce((r, [n, o], s) => {
|
|
10
|
+
if (n === "sort" && typeof o == "object" && o !== null && !Array.isArray(o)) {
|
|
11
|
+
const a = A(o);
|
|
12
|
+
return s === 0 ? `sort=${a}` : `${r}${e}sort=${a}`;
|
|
13
|
+
} else if (n === "pagination" && typeof o == "object" && o !== null) {
|
|
14
|
+
const a = O(o, e);
|
|
15
|
+
return s === 0 ? a : `${r}${e}${a}`;
|
|
16
|
+
} else if (o !== void 0 && n !== "sort" && n !== "pagination") {
|
|
17
|
+
const a = o;
|
|
18
|
+
return s === 0 ? $(n, a) : `${r}${e}${$(n, a)}`;
|
|
41
19
|
}
|
|
42
|
-
return
|
|
43
|
-
}, ""),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
},
|
|
20
|
+
return r;
|
|
21
|
+
}, ""), u = (t) => t && Object.keys(t).length > 0 ? `?${_(t, "&")}` : "", S = {
|
|
22
|
+
IS_PRODUCTION: !0,
|
|
23
|
+
DEFAULT_API_CLIENT_DOMAIN: "api.contentisland.net",
|
|
24
|
+
DEFAULT_API_CLIENT_VERSION: "1.0"
|
|
25
|
+
}, c = {
|
|
26
|
+
SESSION_KEY: "authorization",
|
|
27
|
+
SESSION_TYPE: "Bearer",
|
|
28
|
+
METADATA_KEY: "x-metadata"
|
|
29
|
+
}, g = (t) => {
|
|
30
|
+
const r = (t.secureProtocol === void 0 ? S.IS_PRODUCTION : t.secureProtocol) ? "https" : "http", n = t.domain ? t.domain : S.DEFAULT_API_CLIENT_DOMAIN, o = t.apiVersion ? t.apiVersion : S.DEFAULT_API_CLIENT_VERSION;
|
|
31
|
+
return `${r}://${n}/api/${o}`;
|
|
32
|
+
}, d = async (t, e) => fetch(`${g(e)}${t}`, {
|
|
52
33
|
headers: {
|
|
53
|
-
[
|
|
34
|
+
[c.SESSION_KEY]: `${c.SESSION_TYPE} ${e.accessToken}`,
|
|
35
|
+
...e.metadata ? { [c.METADATA_KEY]: e.metadata } : {}
|
|
54
36
|
}
|
|
55
|
-
}).then((
|
|
56
|
-
if (
|
|
57
|
-
return
|
|
37
|
+
}).then((r) => {
|
|
38
|
+
if (r.ok)
|
|
39
|
+
return r.json();
|
|
40
|
+
throw Error(
|
|
41
|
+
JSON.stringify({
|
|
42
|
+
status: r.status,
|
|
43
|
+
statusText: r.statusText
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
}), C = async (t, e, r) => fetch(`${g(r)}${t}`, {
|
|
47
|
+
method: "PUT",
|
|
48
|
+
headers: {
|
|
49
|
+
"Content-Type": "application/json",
|
|
50
|
+
[c.SESSION_KEY]: `${c.SESSION_TYPE} ${r.accessToken}`,
|
|
51
|
+
...r.metadata ? { [c.METADATA_KEY]: r.metadata } : {}
|
|
52
|
+
},
|
|
53
|
+
body: JSON.stringify(e)
|
|
54
|
+
}).then((n) => {
|
|
55
|
+
if (n.ok)
|
|
56
|
+
return !0;
|
|
58
57
|
throw Error(
|
|
59
58
|
JSON.stringify({
|
|
60
|
-
status:
|
|
61
|
-
statusText:
|
|
59
|
+
status: n.status,
|
|
60
|
+
statusText: n.statusText
|
|
62
61
|
})
|
|
63
62
|
);
|
|
64
|
-
}),
|
|
65
|
-
|
|
63
|
+
}), i = {
|
|
64
|
+
get: d,
|
|
65
|
+
put: C
|
|
66
|
+
}, I = (t) => t == null ? void 0 : t.includes("|"), p = (t, e) => Array.isArray(t) ? t.map(e) : [], f = (t, e) => t.isArray ? p(t.value, (r) => E(r, e)) : E(t.value, e), L = (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
|
+
(r, n) => ({
|
|
68
|
+
...r,
|
|
69
|
+
[n.name]: L(n) ? f(n, e) : n.value
|
|
70
|
+
}),
|
|
71
|
+
{}
|
|
72
|
+
), j = (t, e, r, n) => {
|
|
73
|
+
var N;
|
|
74
|
+
const o = r ?? ((N = t[0]) == null ? void 0 : N.language), s = t.filter((l) => l.language === o), a = h(s, o);
|
|
75
|
+
return Object.keys(a).length === 0 && console.warn(`No fields found for language "${o}" and content id "${e}"`), {
|
|
76
|
+
id: e,
|
|
77
|
+
language: o,
|
|
78
|
+
lastUpdate: n,
|
|
79
|
+
...a
|
|
80
|
+
};
|
|
81
|
+
}, E = (t, e) => Array.isArray(t == null ? void 0 : t.fields) ? j(t.fields, t.id, e, t.lastUpdate) : {}, T = {
|
|
82
|
+
PROJECT: "/project",
|
|
83
|
+
CONTENT_LIST: (t) => `/contents${u(t)}`,
|
|
84
|
+
CONTENT: (t) => `/content${u(t)}`,
|
|
85
|
+
CONTENT_LIST_SIZE: (t) => t ? `/contents/size${u(t)}` : "/contents/size"
|
|
86
|
+
}, y = (t) => {
|
|
87
|
+
const e = (n) => i.get(T.CONTENT_LIST(n), t), r = (n) => i.get(T.CONTENT(n), t);
|
|
66
88
|
return {
|
|
67
|
-
getProject: () =>
|
|
89
|
+
getProject: () => i.get(T.PROJECT, t),
|
|
68
90
|
getContentList: (n) => e(n).then(
|
|
69
|
-
(
|
|
70
|
-
(
|
|
91
|
+
(o) => Array.isArray(o) ? o.map(
|
|
92
|
+
(s) => E(s, n == null ? void 0 : n.language)
|
|
71
93
|
) : []
|
|
72
94
|
),
|
|
73
|
-
getContent: (n) =>
|
|
74
|
-
(
|
|
95
|
+
getContent: (n) => r(n).then(
|
|
96
|
+
(o) => E(o, n == null ? void 0 : n.language)
|
|
75
97
|
),
|
|
76
98
|
getRawContentList: e,
|
|
77
|
-
getRawContent:
|
|
78
|
-
getContentListSize: (n) =>
|
|
99
|
+
getRawContent: r,
|
|
100
|
+
getContentListSize: (n) => i.get(T.CONTENT_LIST_SIZE(n), t),
|
|
101
|
+
updateContentFieldValue: (n, o, s) => i.put(
|
|
102
|
+
`${T.CONTENT(null)}/${n}`,
|
|
103
|
+
{
|
|
104
|
+
id: o,
|
|
105
|
+
value: s
|
|
106
|
+
},
|
|
107
|
+
t
|
|
108
|
+
)
|
|
79
109
|
};
|
|
80
110
|
};
|
|
81
111
|
export {
|
|
82
|
-
|
|
83
|
-
|
|
112
|
+
y as createClient,
|
|
113
|
+
E as mapContentToModel
|
|
84
114
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(i,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(i=typeof globalThis<"u"?globalThis:i||self,c(i.ApiClient={}))})(this,function(i){"use strict";const c=
|
|
1
|
+
(function(i,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(i=typeof globalThis<"u"?globalThis:i||self,c(i.ApiClient={}))})(this,function(i){"use strict";const c=(t,e)=>{if(typeof e=="string"||typeof e=="boolean")return`${t}=${e}`;if(e.in)return`${t}[in]=${e.in.join(",")}`},g=t=>Object.entries(t).map(([e,o])=>`${e}:${o}`).join(","),A=(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},O=(t,e)=>Object.entries(t).reduce((o,[n,r],a)=>{if(n==="sort"&&typeof r=="object"&&r!==null&&!Array.isArray(r)){const s=g(r);return a===0?`sort=${s}`:`${o}${e}sort=${s}`}else if(n==="pagination"&&typeof r=="object"&&r!==null){const s=A(r,e);return a===0?s:`${o}${e}${s}`}else if(r!==void 0&&n!=="sort"&&n!=="pagination"){const s=r;return a===0?c(n,s):`${o}${e}${c(n,s)}`}return o},""),l=t=>t&&Object.keys(t).length>0?`?${O(t,"&")}`:"",d={IS_PRODUCTION:!0,DEFAULT_API_CLIENT_DOMAIN:"api.contentisland.net",DEFAULT_API_CLIENT_VERSION:"1.0"},T={SESSION_KEY:"authorization",SESSION_TYPE:"Bearer",METADATA_KEY:"x-metadata"},N=t=>{const o=(t.secureProtocol===void 0?d.IS_PRODUCTION:t.secureProtocol)?"https":"http",n=t.domain?t.domain:d.DEFAULT_API_CLIENT_DOMAIN,r=t.apiVersion?t.apiVersion:d.DEFAULT_API_CLIENT_VERSION;return`${o}://${n}/api/${r}`},u={get:async(t,e)=>fetch(`${N(e)}${t}`,{headers:{[T.SESSION_KEY]:`${T.SESSION_TYPE} ${e.accessToken}`,...e.metadata?{[T.METADATA_KEY]:e.metadata}:{}}}).then(o=>{if(o.ok)return o.json();throw Error(JSON.stringify({status:o.status,statusText:o.statusText}))}),put:async(t,e,o)=>fetch(`${N(o)}${t}`,{method:"PUT",headers:{"Content-Type":"application/json",[T.SESSION_KEY]:`${T.SESSION_TYPE} ${o.accessToken}`,...o.metadata?{[T.METADATA_KEY]:o.metadata}:{}},body:JSON.stringify(e)}).then(n=>{if(n.ok)return!0;throw Error(JSON.stringify({status:n.status,statusText:n.statusText}))})},p=t=>t==null?void 0:t.includes("|"),C=(t,e)=>Array.isArray(t)?t.map(e):[],_=(t,e)=>t.isArray?C(t.value,o=>E(o,e)):E(t.value,e),f=t=>p(t.type)&&(t.isArray?t.value.every(e=>typeof e=="object"&&"contentType"in e):typeof t.value=="object"&&"contentType"in t.value),I=(t,e)=>t.reduce((o,n)=>({...o,[n.name]:f(n)?_(n,e):n.value}),{}),h=(t,e,o,n)=>{var $;const r=o??(($=t[0])==null?void 0:$.language),a=t.filter(y=>y.language===r),s=I(a,r);return Object.keys(s).length===0&&console.warn(`No fields found for language "${r}" and content id "${e}"`),{id:e,language:r,lastUpdate:n,...s}},E=(t,e)=>Array.isArray(t==null?void 0:t.fields)?h(t.fields,t.id,e,t.lastUpdate):{},S={PROJECT:"/project",CONTENT_LIST:t=>`/contents${l(t)}`,CONTENT:t=>`/content${l(t)}`,CONTENT_LIST_SIZE:t=>t?`/contents/size${l(t)}`:"/contents/size"},L=t=>{const e=n=>u.get(S.CONTENT_LIST(n),t),o=n=>u.get(S.CONTENT(n),t);return{getProject:()=>u.get(S.PROJECT,t),getContentList:n=>e(n).then(r=>Array.isArray(r)?r.map(a=>E(a,n==null?void 0:n.language)):[]),getContent:n=>o(n).then(r=>E(r,n==null?void 0:n.language)),getRawContentList:e,getRawContent:o,getContentListSize:n=>u.get(S.CONTENT_LIST_SIZE(n),t),updateContentFieldValue:(n,r,a)=>u.put(`${S.CONTENT(null)}/${n}`,{id:r,value:a},t)}};i.createClient=L,i.mapContentToModel=E,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|