@content-island/api-client 0.8.3 → 0.9.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 +3 -2
- package/dist/index.js +31 -25
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare type AllowedQueryKeys<M extends Model = Model> = keyof Pick<
|
|
2
2
|
Query<M>,
|
|
3
|
-
'id' | 'contentType' | 'language' | Extract<keyof Query<M>, `fields.${string}`>
|
|
3
|
+
'id' | 'contentType' | 'language' | 'includeRelatedContent' | Extract<keyof Query<M>, `fields.${string}`>
|
|
4
4
|
>;
|
|
5
5
|
|
|
6
6
|
export declare interface ApiClient {
|
|
@@ -11,7 +11,7 @@ export declare interface ApiClient {
|
|
|
11
11
|
getRawContent: <M extends Model = Model & Record<string, any>>(queryParam: QueryParams<M>) => Promise<Content>;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export declare type ClientFilter<Type = string> = Type | { in?: Type[] };
|
|
14
|
+
export declare type ClientFilter<Type = string | boolean> = Type | { in?: Type[] };
|
|
15
15
|
|
|
16
16
|
export declare interface Content {
|
|
17
17
|
id: string;
|
|
@@ -91,6 +91,7 @@ declare type Query<M extends Model = Model> = {
|
|
|
91
91
|
lastUpdate?: ClientFilter;
|
|
92
92
|
language?: ClientFilter<M['language'] extends undefined ? string : M['language']>;
|
|
93
93
|
contentType?: ClientFilter;
|
|
94
|
+
includeRelatedContent?: boolean;
|
|
94
95
|
} & Partial<
|
|
95
96
|
Omit<
|
|
96
97
|
{
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,42 @@
|
|
|
1
|
-
const
|
|
1
|
+
const a = {
|
|
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
|
-
}, O = (t) => t.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
}, O = (t) => t == null ? void 0 : t.includes("|"), S = (t, e) => Array.isArray(t) ? t.map(e) : [], C = (t, e) => t.isArray ? S(t.value, (o) => c(o, e)) : c(t.value, e), I = (t) => O(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
|
+
(o, n) => ({
|
|
10
|
+
...o,
|
|
11
|
+
[n.name]: I(n) ? C(n, e) : n.value
|
|
12
|
+
}),
|
|
13
|
+
{}
|
|
14
|
+
), A = (t, e, o) => {
|
|
15
|
+
var l;
|
|
16
|
+
const n = o ?? ((l = t[0]) == null ? void 0 : l.language), r = t.filter((g) => g.language === n), s = _(r, n);
|
|
17
|
+
return Object.keys(s).length === 0 && console.warn(`No fields found for language "${n}" and content id "${e}"`), {
|
|
12
18
|
id: e,
|
|
13
19
|
language: n,
|
|
14
|
-
...
|
|
20
|
+
...s
|
|
15
21
|
};
|
|
16
|
-
},
|
|
17
|
-
if (typeof e == "string")
|
|
22
|
+
}, c = (t, e) => Array.isArray(t == null ? void 0 : t.fields) ? A(t.fields, t.id, e) : {}, N = (t, e) => {
|
|
23
|
+
if (typeof e == "string" || typeof e == "boolean")
|
|
18
24
|
return `${t}=${e}`;
|
|
19
25
|
if (e.in)
|
|
20
26
|
return `${t}[in]=${e.in.join(",")}`;
|
|
21
|
-
},
|
|
22
|
-
(o, [n, r],
|
|
27
|
+
}, $ = (t, e) => Object.entries(t).reduce(
|
|
28
|
+
(o, [n, r], s) => s === 0 ? N(n, r) : `${o}${e}${N(n, r)}`,
|
|
23
29
|
""
|
|
24
|
-
),
|
|
30
|
+
), E = (t) => t && Object.keys(t).length > 0 ? `?${$(t, "&")}` : "", T = {
|
|
25
31
|
PROJECT: "/project",
|
|
26
|
-
CONTENT_LIST: (t) => `/contents${
|
|
27
|
-
CONTENT: (t) => `/content${
|
|
28
|
-
},
|
|
29
|
-
const o = (t.secureProtocol === void 0 ?
|
|
32
|
+
CONTENT_LIST: (t) => `/contents${E(t)}`,
|
|
33
|
+
CONTENT: (t) => `/content${E(t)}`
|
|
34
|
+
}, d = (t) => {
|
|
35
|
+
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;
|
|
30
36
|
return `${o}://${n}/api/${r}`;
|
|
31
|
-
},
|
|
37
|
+
}, i = async (t, e) => fetch(`${d(e)}${t}`, {
|
|
32
38
|
headers: {
|
|
33
|
-
[
|
|
39
|
+
[u.SESSION_KEY]: `${u.SESSION_TYPE} ${e.accessToken}`
|
|
34
40
|
}
|
|
35
41
|
}).then((o) => {
|
|
36
42
|
if (o.ok)
|
|
@@ -41,23 +47,23 @@ const s = {
|
|
|
41
47
|
statusText: o.statusText
|
|
42
48
|
})
|
|
43
49
|
);
|
|
44
|
-
}),
|
|
45
|
-
const e = (n) => T
|
|
50
|
+
}), p = (t) => {
|
|
51
|
+
const e = (n) => i(T.CONTENT_LIST(n), t), o = (n) => i(T.CONTENT(n), t);
|
|
46
52
|
return {
|
|
47
|
-
getProject: () => T
|
|
53
|
+
getProject: () => i(T.PROJECT, t),
|
|
48
54
|
getContentList: (n) => e(n).then(
|
|
49
55
|
(r) => Array.isArray(r) ? r.map(
|
|
50
|
-
(
|
|
56
|
+
(s) => c(s, n == null ? void 0 : n.language)
|
|
51
57
|
) : []
|
|
52
58
|
),
|
|
53
59
|
getContent: (n) => o(n).then(
|
|
54
|
-
(r) =>
|
|
60
|
+
(r) => c(r, n == null ? void 0 : n.language)
|
|
55
61
|
),
|
|
56
62
|
getRawContentList: e,
|
|
57
63
|
getRawContent: o
|
|
58
64
|
};
|
|
59
65
|
};
|
|
60
66
|
export {
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
p as createClient,
|
|
68
|
+
c as mapContentToModel
|
|
63
69
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(r,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(r=typeof globalThis<"u"?globalThis:r||self,c(r.ApiClient={}))})(this,function(r){"use strict";const c={IS_PRODUCTION:!0,DEFAULT_API_CLIENT_DOMAIN:"api.contentisland.net",DEFAULT_API_CLIENT_VERSION:"1.0"},u={SESSION_KEY:"authorization",SESSION_TYPE:"Bearer"},g=e=>e==null?void 0:e.includes("|"),C=(e,t)=>Array.isArray(e)?e.map(t):[],S=(e,t)=>e.isArray?C(e.value,o=>i(o,t)):i(e.value,t),O=e=>g(e.type)&&(e.isArray?e.value.every(t=>typeof t=="object"&&"contentType"in t):typeof e.value=="object"&&"contentType"in e.value),A=(e,t)=>e.reduce((o,n)=>({...o,[n.name]:O(n)?S(n,t):n.value}),{}),I=(e,t,o)=>{var E;const n=o??((E=e[0])==null?void 0:E.language),s=e.filter(f=>f.language===n),a=A(s,n);return Object.keys(a).length===0&&console.warn(`No fields found for language "${n}" and content id "${t}"`),{id:t,language:n,...a}},i=(e,t)=>Array.isArray(e==null?void 0:e.fields)?I(e.fields,e.id,t):{},N=(e,t)=>{if(typeof t=="string"||typeof t=="boolean")return`${e}=${t}`;if(t.in)return`${e}[in]=${t.in.join(",")}`},_=(e,t)=>Object.entries(e).reduce((o,[n,s],a)=>a===0?N(n,s):`${o}${t}${N(n,s)}`,""),d=e=>e&&Object.keys(e).length>0?`?${_(e,"&")}`:"",T={PROJECT:"/project",CONTENT_LIST:e=>`/contents${d(e)}`,CONTENT:e=>`/content${d(e)}`},p=e=>{const o=(e.secureProtocol===void 0?c.IS_PRODUCTION:e.secureProtocol)?"https":"http",n=e.domain?e.domain:c.DEFAULT_API_CLIENT_DOMAIN,s=e.apiVersion?e.apiVersion:c.DEFAULT_API_CLIENT_VERSION;return`${o}://${n}/api/${s}`},l=async(e,t)=>fetch(`${p(t)}${e}`,{headers:{[u.SESSION_KEY]:`${u.SESSION_TYPE} ${t.accessToken}`}}).then(o=>{if(o.ok)return o.json();throw Error(JSON.stringify({status:o.status,statusText:o.statusText}))}),$=e=>{const t=n=>l(T.CONTENT_LIST(n),e),o=n=>l(T.CONTENT(n),e);return{getProject:()=>l(T.PROJECT,e),getContentList:n=>t(n).then(s=>Array.isArray(s)?s.map(a=>i(a,n==null?void 0:n.language)):[]),getContent:n=>o(n).then(s=>i(s,n==null?void 0:n.language)),getRawContentList:t,getRawContent:o}};r.createClient=$,r.mapContentToModel=i,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|