@content-island/api-client 0.14.1 → 0.15.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 +2 -1
- package/dist/index.js +10 -8
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare interface ApiClient {
|
|
|
14
14
|
|
|
15
15
|
export declare type ClientFilter<Type = string | boolean> = Type | {
|
|
16
16
|
in?: Type[];
|
|
17
|
+
ne?: Type;
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
export declare interface Content {
|
|
@@ -68,7 +69,7 @@ export declare type FieldType =
|
|
|
68
69
|
declare type FilterableFields<M extends Model = Model> = {
|
|
69
70
|
id?: ClientFilter;
|
|
70
71
|
lastUpdate?: ClientFilter;
|
|
71
|
-
language?:
|
|
72
|
+
language?: M['language'];
|
|
72
73
|
contentType?: ClientFilter;
|
|
73
74
|
includeRelatedContent?: boolean;
|
|
74
75
|
} & AllowedModelFields<M, ClientFilter>;
|
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=>E(n,e)):E(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),y=(t,e)=>t.reduce((n,a)=>({...n,[a.name]:I(a)?f(a,e):a.value}),{}),L=(t,e,n,a)=>{var c;const r=n??((c=t[0])==null?void 0:c.language),o=t.filter($=>$.language===r),s=y(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}},E=(t,e)=>Array.isArray(t==null?void 0:t.fields)?L(t.fields,t.id,e,t.lastUpdate):{},l={PROJECT:"/project",CONTENT_LIST:t=>`/contents${S(t)}`,CONTENT:t=>`/content${S(t)}`,CONTENT_LIST_SIZE:t=>t?`/contents/size${S(t)}`:"/contents/size"},h=t=>{const e=o=>g.get(l.CONTENT_LIST(o),t),n=o=>g.get(l.CONTENT(o),t),a=()=>g.get(l.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($=>E($,c)):[]},getContent:async o=>{const s=await n(o),c=(o==null?void 0:o.language)??await r();return E(s,c)},getRawContentList:e,getRawContent:n,getContentListSize:o=>g.get(l.CONTENT_LIST_SIZE(o),t),updateContentFieldValue:(o,s,c)=>g.put(`${l.CONTENT(null)}/${o}`,{id:s,value:c},t)}};i.createClient=h,i.mapContentToModel=E,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|