@content-island/api-client 0.12.0 → 0.14.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
@@ -9,6 +9,7 @@ export declare interface ApiClient {
9
9
  getRawContentList: <M extends Model = Model & Record<string, any>>(queryParam?: ContentListQueryParams<M>) => Promise<Content[]>;
10
10
  getRawContent: <M extends Model = Model & Record<string, any>>(queryParam: ContentQueryParams<M>) => Promise<Content>;
11
11
  getContentListSize: <M extends Model = Model & Record<string, any>>(queryParam?: ContentListSizeQueryParams<M>) => Promise<number>;
12
+ updateContentFieldValue: (contentId: string, fieldId: string, value: any) => Promise<boolean>;
12
13
  }
13
14
 
14
15
  export declare type ClientFilter<Type = string | boolean> = Type | {
@@ -17,8 +18,9 @@ export declare type ClientFilter<Type = string | boolean> = Type | {
17
18
 
18
19
  export declare interface Content {
19
20
  id: string;
21
+ name: string;
20
22
  contentType: Lookup;
21
- lastUpdate: Date;
23
+ lastUpdate: string;
22
24
  fields: Field[];
23
25
  }
24
26
 
@@ -272,6 +274,7 @@ export declare interface Media {
272
274
  export declare type Model<Language = string> = {
273
275
  id: string;
274
276
  language?: Language;
277
+ lastUpdate?: string;
275
278
  };
276
279
 
277
280
  export declare interface Options {
@@ -279,6 +282,7 @@ export declare interface Options {
279
282
  domain?: string;
280
283
  secureProtocol?: boolean;
281
284
  apiVersion?: string;
285
+ metadata?: string;
282
286
  }
283
287
 
284
288
  declare type Pagination = {
package/dist/index.js CHANGED
@@ -1,83 +1,114 @@
1
- const N = {
2
- IS_PRODUCTION: !0,
3
- DEFAULT_API_CLIENT_DOMAIN: "api.contentisland.net",
4
- DEFAULT_API_CLIENT_VERSION: "1.0"
5
- }, $ = {
6
- SESSION_KEY: "authorization",
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(
9
- (o, n) => ({
10
- ...o,
11
- [n.name]: O(n) ? I(n, e) : n.value
12
- }),
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}"`), {
18
- id: e,
19
- language: n,
20
- ...c
21
- };
22
- }, T = (t, e) => Array.isArray(t == null ? void 0 : t.fields) ? C(t.fields, t.id, e) : {}, u = (t, e) => {
1
+ const $ = (t, e) => {
23
2
  if (typeof e == "string" || typeof e == "boolean")
24
3
  return `${t}=${e}`;
25
4
  if (e.in)
26
5
  return `${t}[in]=${e.in.join(",")}`;
27
- }, p = (t) => Object.entries(t).map(([e, o]) => `${e}:${o}`).join(","), A = (t, e) => {
28
- let o = "";
29
- return t.take !== void 0 && (o += `take=${t.take}`), t.skip !== void 0 && (o += o ? `${e}skip=${t.skip}` : `skip=${t.skip}`), o;
30
- }, L = (t, e) => Object.entries(t).reduce((o, [n, r], c) => {
31
- if (n === "sort" && typeof r == "object" && r !== null && !Array.isArray(r)) {
32
- const s = p(r);
33
- return c === 0 ? `sort=${s}` : `${o}${e}sort=${s}`;
34
- } else if (n === "pagination" && typeof r == "object" && r !== null) {
35
- const s = A(r, e);
36
- return c === 0 ? s : `${o}${e}${s}`;
37
- } else if (r !== void 0 && n !== "sort" && n !== "pagination") {
38
- const s = r;
39
- return c === 0 ? u(n, s) : `${o}${e}${u(n, s)}`;
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)}`;
40
19
  }
41
- return o;
42
- }, ""), S = (t) => t && Object.keys(t).length > 0 ? `?${L(t, "&")}` : "", i = {
43
- PROJECT: "/project",
44
- CONTENT_LIST: (t) => `/contents${S(t)}`,
45
- CONTENT: (t) => `/content${S(t)}`,
46
- CONTENT_LIST_SIZE: (t) => t ? `/contents/size${S(t)}` : "/contents/size"
47
- }, d = (t) => {
48
- 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
- return `${o}://${n}/api/${r}`;
50
- }, a = async (t, e) => fetch(`${d(e)}${t}`, {
20
+ return r;
21
+ }, ""), u = (t) => t && Object.keys(t).length > 0 ? `?${_(t, "&")}` : "", S = {
22
+ IS_PRODUCTION: !0,
23
+ DEFAULT_API_CLIENT_DOMAIN: "api.contentisland.net",
24
+ DEFAULT_API_CLIENT_VERSION: "1.0"
25
+ }, c = {
26
+ SESSION_KEY: "authorization",
27
+ SESSION_TYPE: "Bearer",
28
+ 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}`, {
51
33
  headers: {
52
- [$.SESSION_KEY]: `${$.SESSION_TYPE} ${e.accessToken}`
34
+ [c.SESSION_KEY]: `${c.SESSION_TYPE} ${e.accessToken}`,
35
+ ...e.metadata ? { [c.METADATA_KEY]: e.metadata } : {}
53
36
  }
54
- }).then((o) => {
55
- if (o.ok)
56
- return o.json();
37
+ }).then((r) => {
38
+ if (r.ok)
39
+ return r.json();
40
+ throw Error(
41
+ JSON.stringify({
42
+ status: r.status,
43
+ statusText: r.statusText
44
+ })
45
+ );
46
+ }), C = async (t, e, r) => fetch(`${g(r)}${t}`, {
47
+ method: "PUT",
48
+ headers: {
49
+ "Content-Type": "application/json",
50
+ [c.SESSION_KEY]: `${c.SESSION_TYPE} ${r.accessToken}`,
51
+ ...r.metadata ? { [c.METADATA_KEY]: r.metadata } : {}
52
+ },
53
+ body: JSON.stringify(e)
54
+ }).then((n) => {
55
+ if (n.ok)
56
+ return !0;
57
57
  throw Error(
58
58
  JSON.stringify({
59
- status: o.status,
60
- statusText: o.statusText
59
+ status: n.status,
60
+ statusText: n.statusText
61
61
  })
62
62
  );
63
- }), f = (t) => {
64
- const e = (n) => a(i.CONTENT_LIST(n), t), o = (n) => a(i.CONTENT(n), t);
63
+ }), i = {
64
+ get: d,
65
+ 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
70
+ }),
71
+ {}
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}"`), {
76
+ id: e,
77
+ language: o,
78
+ lastUpdate: n,
79
+ ...a
80
+ };
81
+ }, E = (t, e) => Array.isArray(t == null ? void 0 : t.fields) ? j(t.fields, t.id, e, t.lastUpdate) : {}, T = {
82
+ 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);
65
88
  return {
66
- getProject: () => a(i.PROJECT, t),
89
+ getProject: () => i.get(T.PROJECT, t),
67
90
  getContentList: (n) => e(n).then(
68
- (r) => Array.isArray(r) ? r.map(
69
- (c) => T(c, n == null ? void 0 : n.language)
91
+ (o) => Array.isArray(o) ? o.map(
92
+ (s) => E(s, n == null ? void 0 : n.language)
70
93
  ) : []
71
94
  ),
72
- getContent: (n) => o(n).then(
73
- (r) => T(r, n == null ? void 0 : n.language)
95
+ getContent: (n) => r(n).then(
96
+ (o) => E(o, n == null ? void 0 : n.language)
74
97
  ),
75
98
  getRawContentList: e,
76
- getRawContent: o,
77
- getContentListSize: (n) => a(i.CONTENT_LIST_SIZE(n), t)
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}`,
103
+ {
104
+ id: o,
105
+ value: s
106
+ },
107
+ t
108
+ )
78
109
  };
79
110
  };
80
111
  export {
81
- f as createClient,
82
- T as mapContentToModel
112
+ y as createClient,
113
+ E as mapContentToModel
83
114
  };
@@ -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=(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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@content-island/api-client",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "description": "Content Island - REST API Client",
5
5
  "private": false,
6
6
  "sideEffects": false,