@content-island/api-client 0.13.0 → 0.14.1

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