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