@content-island/api-client 0.11.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 CHANGED
@@ -71,7 +71,7 @@ declare type FilterableFields<M extends Model = Model> = {
71
71
  includeRelatedContent?: boolean;
72
72
  } & AllowedModelFields<M, ClientFilter>;
73
73
 
74
- declare type LanguageCode =
74
+ export declare type LanguageCode =
75
75
  | 'aa'
76
76
  | 'ab'
77
77
  | 'ae'
@@ -272,6 +272,7 @@ export declare interface Media {
272
272
  export declare type Model<Language = string> = {
273
273
  id: string;
274
274
  language?: Language;
275
+ lastUpdate?: Date;
275
276
  };
276
277
 
277
278
  export declare interface Options {
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
- }, g = (t) => t == null ? void 0 : t.includes("|"), l = (t, e) => Array.isArray(t) ? t.map(e) : [], I = (t, e) => t.isArray ? l(t.value, (o) => T(o, e)) : T(t.value, e), O = (t) => g(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(
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]: O(n) ? I(n, e) : n.value
11
+ [n.name]: _(n) ? O(n, e) : n.value
12
12
  }),
13
13
  {}
14
- ), C = (t, e, o) => {
15
- var s;
16
- const n = o ?? ((s = t[0]) == null ? void 0 : s.language), r = t.filter((E) => E.language === n), c = _(r, n);
17
- return Object.keys(c).length === 0 && console.warn(`No fields found for language "${n}" and content id "${e}"`), {
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: n,
20
- ...c
19
+ language: r,
20
+ lastUpdate: n,
21
+ ...s
21
22
  };
22
- }, T = (t, e) => Array.isArray(t == null ? void 0 : t.fields) ? C(t.fields, t.id, e) : {}, u = (t, e) => {
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
- }, p = (t) => Object.entries(t).map(([e, o]) => `${e}:${o}`).join(","), A = (t, e) => {
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 = p(r);
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 = A(r, e);
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 ? u(n, s) : `${o}${e}${u(n, s)}`;
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
- }, d = (t) => {
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(`${d(e)}${t}`, {
51
+ }, a = async (t, e) => fetch(`${f(e)}${t}`, {
51
52
  headers: {
52
- [$.SESSION_KEY]: `${$.SESSION_TYPE} ${e.accessToken}`
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
- }), f = (t) => {
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
- f as createClient,
82
+ j as createClient,
82
83
  T as mapContentToModel
83
84
  };
@@ -1 +1 @@
1
- (function(c,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(c=typeof globalThis<"u"?globalThis:c||self,a(c.ApiClient={}))})(this,function(c){"use strict";const a={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):[],p=(t,e)=>t.isArray?g(t.value,o=>T(o,e)):T(t.value,e),d=t=>E(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((o,n)=>({...o,[n.name]:d(n)?p(n,e):n.value}),{}),O=(t,e,o)=>{var s;const n=o??((s=t[0])==null?void 0:s.language),r=t.filter(h=>h.language===n),i=C(r,n);return Object.keys(i).length===0&&console.warn(`No fields found for language "${n}" and content id "${e}"`),{id:e,language:n,...i}},T=(t,e)=>Array.isArray(t==null?void 0:t.fields)?O(t.fields,t.id,e):{},$=(t,e)=>{if(typeof e=="string"||typeof e=="boolean")return`${t}=${e}`;if(e.in)return`${t}[in]=${e.in.join(",")}`},I=t=>Object.entries(t).map(([e,o])=>`${e}:${o}`).join(","),_=(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},f=(t,e)=>Object.entries(t).reduce((o,[n,r],i)=>{if(n==="sort"&&typeof r=="object"&&r!==null&&!Array.isArray(r)){const s=I(r);return i===0?`sort=${s}`:`${o}${e}sort=${s}`}else if(n==="pagination"&&typeof r=="object"&&r!==null){const s=_(r,e);return i===0?s:`${o}${e}${s}`}else if(r!==void 0&&n!=="sort"&&n!=="pagination"){const s=r;return i===0?$(n,s):`${o}${e}${$(n,s)}`}return o},""),S=t=>t&&Object.keys(t).length>0?`?${f(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"},A=t=>{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;return`${o}://${n}/api/${r}`},l=async(t,e)=>fetch(`${A(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}))}),L=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(i=>T(i,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)}};c.createClient=L,c.mapContentToModel=T,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@content-island/api-client",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "Content Island - REST API Client",
5
5
  "private": false,
6
6
  "sideEffects": false,