@content-island/api-client 0.14.0 → 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 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?: ClientFilter<M['language'] extends undefined ? string : M['language']>;
72
+ language?: M['language'];
72
73
  contentType?: ClientFilter;
73
74
  includeRelatedContent?: boolean;
74
75
  } & AllowedModelFields<M, ClientFilter>;
package/dist/index.js CHANGED
@@ -1,114 +1,120 @@
1
- const $ = (t, e) => {
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
- }, 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)}`;
6
+ if (e.ne)
7
+ return `${t}[ne]=${e.ne}`;
8
+ }, A = (t) => Object.entries(t).map(([e, n]) => `${e}:${n}`).join(","), O = (t, e) => {
9
+ let n = "";
10
+ return t.take !== void 0 && (n += `take=${t.take}`), t.skip !== void 0 && (n += n ? `${e}skip=${t.skip}` : `skip=${t.skip}`), n;
11
+ }, _ = (t, e) => Object.entries(t).reduce((n, [o, s], a) => {
12
+ if (o === "sort" && typeof s == "object" && s !== null && !Array.isArray(s)) {
13
+ const r = A(s);
14
+ return a === 0 ? `sort=${r}` : `${n}${e}sort=${r}`;
15
+ } else if (o === "pagination" && typeof s == "object" && s !== null) {
16
+ const r = O(s, e);
17
+ return a === 0 ? r : `${n}${e}${r}`;
18
+ } else if (s !== void 0 && o !== "sort" && o !== "pagination") {
19
+ const r = s;
20
+ return a === 0 ? N(o, r) : `${n}${e}${N(o, r)}`;
19
21
  }
20
- return r;
21
- }, ""), u = (t) => t && Object.keys(t).length > 0 ? `?${_(t, "&")}` : "", S = {
22
+ return n;
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"
25
- }, c = {
27
+ }, i = {
26
28
  SESSION_KEY: "authorization",
27
29
  SESSION_TYPE: "Bearer",
28
30
  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}`, {
31
+ }, l = (t) => {
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;
33
+ return `${n}://${o}/api/${s}`;
34
+ }, d = async (t, e) => fetch(`${l(e)}${t}`, {
33
35
  headers: {
34
- [c.SESSION_KEY]: `${c.SESSION_TYPE} ${e.accessToken}`,
35
- ...e.metadata ? { [c.METADATA_KEY]: e.metadata } : {}
36
+ [i.SESSION_KEY]: `${i.SESSION_TYPE} ${e.accessToken}`,
37
+ ...e.metadata ? { [i.METADATA_KEY]: e.metadata } : {}
36
38
  }
37
- }).then((r) => {
38
- if (r.ok)
39
- return r.json();
39
+ }).then((n) => {
40
+ if (n.ok)
41
+ return n.json();
40
42
  throw Error(
41
43
  JSON.stringify({
42
- status: r.status,
43
- statusText: r.statusText
44
+ status: n.status,
45
+ statusText: n.statusText
44
46
  })
45
47
  );
46
- }), C = async (t, e, r) => fetch(`${g(r)}${t}`, {
48
+ }), C = async (t, e, n) => fetch(`${l(n)}${t}`, {
47
49
  method: "PUT",
48
50
  headers: {
49
51
  "Content-Type": "application/json",
50
- [c.SESSION_KEY]: `${c.SESSION_TYPE} ${r.accessToken}`,
51
- ...r.metadata ? { [c.METADATA_KEY]: r.metadata } : {}
52
+ [i.SESSION_KEY]: `${i.SESSION_TYPE} ${n.accessToken}`,
53
+ ...n.metadata ? { [i.METADATA_KEY]: n.metadata } : {}
52
54
  },
53
55
  body: JSON.stringify(e)
54
- }).then((n) => {
55
- if (n.ok)
56
+ }).then((o) => {
57
+ if (o.ok)
56
58
  return !0;
57
59
  throw Error(
58
60
  JSON.stringify({
59
- status: n.status,
60
- statusText: n.statusText
61
+ status: o.status,
62
+ statusText: o.statusText
61
63
  })
62
64
  );
63
- }), i = {
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) : [], 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
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(
69
+ (n, o) => ({
70
+ ...n,
71
+ [o.name]: f(o) ? L(o, e) : o.value
70
72
  }),
71
73
  {}
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}"`), {
74
+ ), y = (t, e, n, o) => {
75
+ var c;
76
+ const s = n ?? ((c = t[0]) == null ? void 0 : c.language), a = t.filter((g) => g.language === s), r = h(a, s);
77
+ return Object.keys(r).length === 0 && console.warn(`No fields found for language "${s}" and content id "${e}"`), {
76
78
  id: e,
77
- language: o,
78
- lastUpdate: n,
79
- ...a
79
+ language: s,
80
+ lastUpdate: o,
81
+ ...r
80
82
  };
81
- }, E = (t, e) => Array.isArray(t == null ? void 0 : t.fields) ? j(t.fields, t.id, e, t.lastUpdate) : {}, T = {
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
- 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);
85
+ CONTENT_LIST: (t) => `/contents${S(t)}`,
86
+ CONTENT: (t) => `/content${S(t)}`,
87
+ CONTENT_LIST_SIZE: (t) => t ? `/contents/size${S(t)}` : "/contents/size"
88
+ }, j = (t) => {
89
+ const e = (a) => T.get(u.CONTENT_LIST(a), t), n = (a) => T.get(u.CONTENT(a), t), o = () => T.get(u.PROJECT, t), s = async () => {
90
+ var r;
91
+ const a = await o();
92
+ return (r = a == null ? void 0 : a.languages) == null ? void 0 : r[0];
93
+ };
88
94
  return {
89
- getProject: () => i.get(T.PROJECT, t),
90
- getContentList: (n) => e(n).then(
91
- (o) => Array.isArray(o) ? o.map(
92
- (s) => E(s, n == null ? void 0 : n.language)
93
- ) : []
94
- ),
95
- getContent: (n) => r(n).then(
96
- (o) => E(o, n == null ? void 0 : n.language)
97
- ),
95
+ getProject: o,
96
+ getContentList: async (a) => {
97
+ const r = await e(a), c = (a == null ? void 0 : a.language) ?? await s();
98
+ return Array.isArray(r) ? r.map((g) => E(g, c)) : [];
99
+ },
100
+ getContent: async (a) => {
101
+ const r = await n(a), c = (a == null ? void 0 : a.language) ?? await s();
102
+ return E(r, c);
103
+ },
98
104
  getRawContentList: e,
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}`,
105
+ getRawContent: n,
106
+ getContentListSize: (a) => T.get(u.CONTENT_LIST_SIZE(a), t),
107
+ updateContentFieldValue: (a, r, c) => T.put(
108
+ `${u.CONTENT(null)}/${a}`,
103
109
  {
104
- id: o,
105
- value: s
110
+ id: r,
111
+ value: c
106
112
  },
107
113
  t
108
114
  )
109
115
  };
110
116
  };
111
117
  export {
112
- y as createClient,
118
+ j as createClient,
113
119
  E as mapContentToModel
114
120
  };
@@ -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=(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"})});
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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@content-island/api-client",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "Content Island - REST API Client",
5
5
  "private": false,
6
6
  "sideEffects": false,