@content-island/api-client 0.15.0 → 0.16.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
@@ -1,5 +1,5 @@
1
1
  declare type AllowedModelFields<M extends Model, ValueType> = Partial<Omit<{
2
- [K in keyof M as M[K] extends string | number | boolean ? `fields.${string & K}` : never]?: ValueType;
2
+ [K in keyof M as IsPrimitive<NonNullable<M[K]>> extends true ? `fields.${string & K}` : never]?: ValueType;
3
3
  }, 'fields.id' | 'fields.language'>>;
4
4
 
5
5
  export declare interface ApiClient {
@@ -12,6 +12,12 @@ export declare interface ApiClient {
12
12
  updateContentFieldValue: (contentId: string, fieldId: string, value: any) => Promise<boolean>;
13
13
  }
14
14
 
15
+ declare interface BaseModel {
16
+ id: string;
17
+ name: string;
18
+ type: ModelType;
19
+ }
20
+
15
21
  export declare type ClientFilter<Type = string | boolean> = Type | {
16
22
  in?: Type[];
17
23
  ne?: Type;
@@ -31,10 +37,6 @@ export declare type ContentListSizeQueryParams<M extends Model = Model & Record<
31
37
 
32
38
  export declare type ContentQueryParams<M extends Model = Model & Record<string, any>> = Omit<QueryParams<M>, 'sort' | 'pagination'>;
33
39
 
34
- declare interface ContentType extends Lookup {
35
- fields: ContentTypeField[];
36
- }
37
-
38
40
  declare interface ContentTypeField extends Lookup {
39
41
  type: FieldType;
40
42
  tsType: string;
@@ -44,6 +46,27 @@ declare interface ContentTypeField extends Lookup {
44
46
 
45
47
  export declare const createClient: (options: Options) => ApiClient;
46
48
 
49
+ declare interface Entity extends BaseModel {
50
+ type: 'entity';
51
+ fieldList?: Field_2[];
52
+ }
53
+
54
+ declare type EntityContentType = Omit<Entity, 'fieldList'> & {
55
+ fields: ContentTypeField[];
56
+ };
57
+
58
+ declare interface Enum extends BaseModel {
59
+ type: 'enum';
60
+ values: EnumValue[];
61
+ }
62
+
63
+ declare type EnumContentType = Enum;
64
+
65
+ declare interface EnumValue {
66
+ id: string;
67
+ value: string;
68
+ }
69
+
47
70
  export declare interface Field {
48
71
  id: string;
49
72
  name: string;
@@ -53,7 +76,14 @@ export declare interface Field {
53
76
  language: string;
54
77
  }
55
78
 
56
- declare type FieldEntityType = `${string}|${string}`;
79
+ declare interface Field_2 {
80
+ id: string;
81
+ name: string;
82
+ type: FieldType;
83
+ isArray: boolean;
84
+ order: number;
85
+ validations?: Validation[];
86
+ }
57
87
 
58
88
  export declare type FieldType =
59
89
  | 'short-text'
@@ -64,7 +94,7 @@ export declare type FieldType =
64
94
  | 'media'
65
95
  | 'boolean'
66
96
  | 'color'
67
- | FieldEntityType;
97
+ | RelatedModelType;
68
98
 
69
99
  declare type FilterableFields<M extends Model = Model> = {
70
100
  id?: ClientFilter;
@@ -74,6 +104,8 @@ declare type FilterableFields<M extends Model = Model> = {
74
104
  includeRelatedContent?: boolean;
75
105
  } & AllowedModelFields<M, ClientFilter>;
76
106
 
107
+ declare type IsPrimitive<T> = [T] extends [string | number | boolean] ? true : false;
108
+
77
109
  export declare type LanguageCode =
78
110
  | 'aa'
79
111
  | 'ab'
@@ -278,6 +310,8 @@ export declare type Model<Language = string> = {
278
310
  lastUpdate?: string;
279
311
  };
280
312
 
313
+ declare type ModelType = 'entity' | 'enum';
314
+
281
315
  export declare interface Options {
282
316
  accessToken: string;
283
317
  domain?: string;
@@ -295,7 +329,7 @@ export declare interface Project {
295
329
  id: string;
296
330
  name: string;
297
331
  languages: LanguageCode[];
298
- contentTypes?: ContentType[];
332
+ contentTypes?: (EntityContentType | EnumContentType)[];
299
333
  }
300
334
 
301
335
  declare type QueryParams<M extends Model = Model & Record<string, any>> = FilterableFields<M> & {
@@ -303,6 +337,8 @@ declare type QueryParams<M extends Model = Model & Record<string, any>> = Filter
303
337
  pagination?: Pagination;
304
338
  };
305
339
 
340
+ declare type RelatedModelType = `${string}|${string}`;
341
+
306
342
  declare type SortableFields<M extends Model> = {
307
343
  contentType?: SortOrder;
308
344
  lastUpdate?: SortOrder;
@@ -310,4 +346,6 @@ declare type SortableFields<M extends Model> = {
310
346
 
311
347
  declare type SortOrder = 'asc' | 'desc';
312
348
 
349
+ declare type Validation = { name: string; customArgs?: any };
350
+
313
351
  export { }
@@ -1 +1 @@
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"})});
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=>l(n,e)):l(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),L=(t,e)=>t.reduce((n,a)=>({...n,[a.name]:I(a)?f(a,e):a.value}),{}),h=(t,e,n,a)=>{var c;const r=n??((c=t[0])==null?void 0:c.language),o=t.filter($=>$.language===r),s=L(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}},l=(t,e)=>Array.isArray(t==null?void 0:t.fields)?h(t.fields,t.id,e,t.lastUpdate):{},E={PROJECT:"/project",CONTENT_LIST:t=>`/contents${S(t)}`,CONTENT:t=>`/content${S(t)}`,CONTENT_LIST_SIZE:t=>t?`/contents/size${S(t)}`:"/contents/size"},y=t=>{const e=o=>g.get(E.CONTENT_LIST(o),t),n=o=>g.get(E.CONTENT(o),t),a=()=>g.get(E.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($=>l($,c)):[]},getContent:async o=>{const s=await n(o),c=(o==null?void 0:o.language)??await r();return l(s,c)},getRawContentList:e,getRawContent:n,getContentListSize:o=>g.get(E.CONTENT_LIST_SIZE(o),t),updateContentFieldValue:(o,s,c)=>g.put(`${E.CONTENT(null)}/${o}`,{id:s,value:c},t)}};i.createClient=y,i.mapContentToModel=l,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.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Content Island - REST API Client",
5
5
  "private": false,
6
6
  "sideEffects": false,