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