@content-island/api-client 0.12.0 → 0.13.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 +1 -0
- package/dist/index.js +20 -19
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -2,41 +2,42 @@ 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
|
+
}, u = {
|
|
6
6
|
SESSION_KEY: "authorization",
|
|
7
7
|
SESSION_TYPE: "Bearer"
|
|
8
|
-
},
|
|
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
9
|
(o, n) => ({
|
|
10
10
|
...o,
|
|
11
|
-
[n.name]:
|
|
11
|
+
[n.name]: _(n) ? O(n, e) : n.value
|
|
12
12
|
}),
|
|
13
13
|
{}
|
|
14
|
-
),
|
|
15
|
-
var
|
|
16
|
-
const
|
|
17
|
-
return Object.keys(
|
|
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
18
|
id: e,
|
|
19
|
-
language:
|
|
20
|
-
|
|
19
|
+
language: r,
|
|
20
|
+
lastUpdate: n,
|
|
21
|
+
...s
|
|
21
22
|
};
|
|
22
|
-
}, T = (t, e) => Array.isArray(t == null ? void 0 : t.fields) ?
|
|
23
|
+
}, T = (t, e) => Array.isArray(t == null ? void 0 : t.fields) ? p(t.fields, t.id, e, t.lastUpdate) : {}, E = (t, e) => {
|
|
23
24
|
if (typeof e == "string" || typeof e == "boolean")
|
|
24
25
|
return `${t}=${e}`;
|
|
25
26
|
if (e.in)
|
|
26
27
|
return `${t}[in]=${e.in.join(",")}`;
|
|
27
|
-
},
|
|
28
|
+
}, A = (t) => Object.entries(t).map(([e, o]) => `${e}:${o}`).join(","), d = (t, e) => {
|
|
28
29
|
let o = "";
|
|
29
30
|
return t.take !== void 0 && (o += `take=${t.take}`), t.skip !== void 0 && (o += o ? `${e}skip=${t.skip}` : `skip=${t.skip}`), o;
|
|
30
31
|
}, L = (t, e) => Object.entries(t).reduce((o, [n, r], c) => {
|
|
31
32
|
if (n === "sort" && typeof r == "object" && r !== null && !Array.isArray(r)) {
|
|
32
|
-
const s =
|
|
33
|
+
const s = A(r);
|
|
33
34
|
return c === 0 ? `sort=${s}` : `${o}${e}sort=${s}`;
|
|
34
35
|
} else if (n === "pagination" && typeof r == "object" && r !== null) {
|
|
35
|
-
const s =
|
|
36
|
+
const s = d(r, e);
|
|
36
37
|
return c === 0 ? s : `${o}${e}${s}`;
|
|
37
38
|
} else if (r !== void 0 && n !== "sort" && n !== "pagination") {
|
|
38
39
|
const s = r;
|
|
39
|
-
return c === 0 ?
|
|
40
|
+
return c === 0 ? E(n, s) : `${o}${e}${E(n, s)}`;
|
|
40
41
|
}
|
|
41
42
|
return o;
|
|
42
43
|
}, ""), S = (t) => t && Object.keys(t).length > 0 ? `?${L(t, "&")}` : "", i = {
|
|
@@ -44,12 +45,12 @@ const N = {
|
|
|
44
45
|
CONTENT_LIST: (t) => `/contents${S(t)}`,
|
|
45
46
|
CONTENT: (t) => `/content${S(t)}`,
|
|
46
47
|
CONTENT_LIST_SIZE: (t) => t ? `/contents/size${S(t)}` : "/contents/size"
|
|
47
|
-
},
|
|
48
|
+
}, f = (t) => {
|
|
48
49
|
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;
|
|
49
50
|
return `${o}://${n}/api/${r}`;
|
|
50
|
-
}, a = async (t, e) => fetch(`${
|
|
51
|
+
}, a = async (t, e) => fetch(`${f(e)}${t}`, {
|
|
51
52
|
headers: {
|
|
52
|
-
[
|
|
53
|
+
[u.SESSION_KEY]: `${u.SESSION_TYPE} ${e.accessToken}`
|
|
53
54
|
}
|
|
54
55
|
}).then((o) => {
|
|
55
56
|
if (o.ok)
|
|
@@ -60,7 +61,7 @@ const N = {
|
|
|
60
61
|
statusText: o.statusText
|
|
61
62
|
})
|
|
62
63
|
);
|
|
63
|
-
}),
|
|
64
|
+
}), j = (t) => {
|
|
64
65
|
const e = (n) => a(i.CONTENT_LIST(n), t), o = (n) => a(i.CONTENT(n), t);
|
|
65
66
|
return {
|
|
66
67
|
getProject: () => a(i.PROJECT, t),
|
|
@@ -78,6 +79,6 @@ const N = {
|
|
|
78
79
|
};
|
|
79
80
|
};
|
|
80
81
|
export {
|
|
81
|
-
|
|
82
|
+
j as createClient,
|
|
82
83
|
T as mapContentToModel
|
|
83
84
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(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={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):[],d=(t,e)=>t.isArray?g(t.value,o=>T(o,e)):T(t.value,e),C=t=>E(t.type)&&(t.isArray?t.value.every(e=>typeof e=="object"&&"contentType"in e):typeof t.value=="object"&&"contentType"in t.value),O=(t,e)=>t.reduce((o,n)=>({...o,[n.name]:C(n)?d(n,e):n.value}),{}),I=(t,e,o,n)=>{var p;const r=o??((p=t[0])==null?void 0:p.language),a=t.filter(j=>j.language===r),s=O(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}},T=(t,e)=>Array.isArray(t==null?void 0:t.fields)?I(t.fields,t.id,e,t.lastUpdate):{},$=(t,e)=>{if(typeof e=="string"||typeof e=="boolean")return`${t}=${e}`;if(e.in)return`${t}[in]=${e.in.join(",")}`},_=t=>Object.entries(t).map(([e,o])=>`${e}:${o}`).join(","),f=(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},A=(t,e)=>Object.entries(t).reduce((o,[n,r],a)=>{if(n==="sort"&&typeof r=="object"&&r!==null&&!Array.isArray(r)){const s=_(r);return a===0?`sort=${s}`:`${o}${e}sort=${s}`}else if(n==="pagination"&&typeof r=="object"&&r!==null){const s=f(r,e);return a===0?s:`${o}${e}${s}`}else if(r!==void 0&&n!=="sort"&&n!=="pagination"){const s=r;return a===0?$(n,s):`${o}${e}${$(n,s)}`}return o},""),S=t=>t&&Object.keys(t).length>0?`?${A(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"},L=t=>{const o=(t.secureProtocol===void 0?c.IS_PRODUCTION:t.secureProtocol)?"https":"http",n=t.domain?t.domain:c.DEFAULT_API_CLIENT_DOMAIN,r=t.apiVersion?t.apiVersion:c.DEFAULT_API_CLIENT_VERSION;return`${o}://${n}/api/${r}`},l=async(t,e)=>fetch(`${L(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}))}),h=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(a=>T(a,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)}};i.createClient=h,i.mapContentToModel=T,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|