@content-island/api-client 0.8.2 → 0.9.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,10 +1,6 @@
1
- import { FieldType } from '@content-island/common';
2
- import { Lookup } from '@content-island/common';
3
- import { Media } from '@content-island/common';
4
-
5
1
  declare type AllowedQueryKeys<M extends Model = Model> = keyof Pick<
6
2
  Query<M>,
7
- 'id' | 'contentType' | 'language' | Extract<keyof Query<M>, `fields.${string}`>
3
+ 'id' | 'contentType' | 'language' | 'includeRelatedContent' | Extract<keyof Query<M>, `fields.${string}`>
8
4
  >;
9
5
 
10
6
  export declare interface ApiClient {
@@ -15,7 +11,7 @@ export declare interface ApiClient {
15
11
  getRawContent: <M extends Model = Model & Record<string, any>>(queryParam: QueryParams<M>) => Promise<Content>;
16
12
  }
17
13
 
18
- export declare type ClientFilter<Type = string> = Type | { in?: Type[] };
14
+ export declare type ClientFilter<Type = string | boolean> = Type | { in?: Type[] };
19
15
 
20
16
  export declare interface Content {
21
17
  id: string;
@@ -46,13 +42,30 @@ export declare interface Field {
46
42
  language: string;
47
43
  }
48
44
 
49
- export { FieldType }
50
-
51
- export { Lookup }
45
+ declare type FieldEntityType = `${string}|${string}`;
46
+
47
+ export declare type FieldType =
48
+ | 'short-text'
49
+ | 'long-text'
50
+ | 'number'
51
+ | 'date'
52
+ | 'date-time'
53
+ | 'media'
54
+ | 'boolean'
55
+ | 'color'
56
+ | FieldEntityType;
57
+
58
+ export declare interface Lookup<ID = string> {
59
+ id: ID;
60
+ name: string;
61
+ }
52
62
 
53
63
  export declare const mapContentToModel: <M extends Model<Language> = Model<any> & Record<string, any>, Language = M["language"]>(content: Content, language?: Language) => M;
54
64
 
55
- export { Media }
65
+ export declare interface Media {
66
+ name: string;
67
+ url: string;
68
+ }
56
69
 
57
70
  export declare type Model<Language = string> = {
58
71
  id: string;
@@ -78,6 +91,7 @@ declare type Query<M extends Model = Model> = {
78
91
  lastUpdate?: ClientFilter;
79
92
  language?: ClientFilter<M['language'] extends undefined ? string : M['language']>;
80
93
  contentType?: ClientFilter;
94
+ includeRelatedContent?: boolean;
81
95
  } & Partial<
82
96
  Omit<
83
97
  {
package/dist/index.js CHANGED
@@ -1,36 +1,42 @@
1
- const s = {
1
+ const a = {
2
2
  IS_PRODUCTION: !0,
3
3
  DEFAULT_API_CLIENT_DOMAIN: "api.contentisland.net",
4
4
  DEFAULT_API_CLIENT_VERSION: "1.0"
5
- }, l = {
5
+ }, u = {
6
6
  SESSION_KEY: "authorization",
7
7
  SESSION_TYPE: "Bearer"
8
- }, O = (t) => t.reduce((e, o) => ({ ...e, [o.name]: o.value }), {}), S = (t, e, o) => {
9
- var i;
10
- const n = o ?? ((i = t[0]) == null ? void 0 : i.language), r = t.filter((u) => u.language === n), c = O(r);
11
- return Object.keys(c).length === 0 && console.warn(`No fields found for language "${n}" and content id "${e}"`), {
8
+ }, O = (t) => t == null ? void 0 : t.includes("|"), S = (t, e) => Array.isArray(t) ? t.map(e) : [], C = (t, e) => t.isArray ? S(t.value, (o) => c(o, e)) : c(t.value, e), I = (t) => O(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]: I(n) ? C(n, e) : n.value
12
+ }),
13
+ {}
14
+ ), A = (t, e, o) => {
15
+ var l;
16
+ const n = o ?? ((l = t[0]) == null ? void 0 : l.language), r = t.filter((g) => g.language === n), s = _(r, n);
17
+ return Object.keys(s).length === 0 && console.warn(`No fields found for language "${n}" and content id "${e}"`), {
12
18
  id: e,
13
19
  language: n,
14
- ...c
20
+ ...s
15
21
  };
16
- }, N = (t, e) => Array.isArray(t == null ? void 0 : t.fields) ? S(t.fields, t.id, e) : {}, E = (t, e) => {
17
- if (typeof e == "string")
22
+ }, c = (t, e) => Array.isArray(t == null ? void 0 : t.fields) ? A(t.fields, t.id, e) : {}, N = (t, e) => {
23
+ if (typeof e == "string" || typeof e == "boolean")
18
24
  return `${t}=${e}`;
19
25
  if (e.in)
20
26
  return `${t}[in]=${e.in.join(",")}`;
21
- }, I = (t, e) => Object.entries(t).reduce(
22
- (o, [n, r], c) => c === 0 ? E(n, r) : `${o}${e}${E(n, r)}`,
27
+ }, $ = (t, e) => Object.entries(t).reduce(
28
+ (o, [n, r], s) => s === 0 ? N(n, r) : `${o}${e}${N(n, r)}`,
23
29
  ""
24
- ), g = (t) => t && Object.keys(t).length > 0 ? `?${I(t, "&")}` : "", a = {
30
+ ), E = (t) => t && Object.keys(t).length > 0 ? `?${$(t, "&")}` : "", T = {
25
31
  PROJECT: "/project",
26
- CONTENT_LIST: (t) => `/contents${g(t)}`,
27
- CONTENT: (t) => `/content${g(t)}`
28
- }, _ = (t) => {
29
- const o = (t.secureProtocol === void 0 ? s.IS_PRODUCTION : t.secureProtocol) ? "https" : "http", n = t.domain ? t.domain : s.DEFAULT_API_CLIENT_DOMAIN, r = t.apiVersion ? t.apiVersion : s.DEFAULT_API_CLIENT_VERSION;
32
+ CONTENT_LIST: (t) => `/contents${E(t)}`,
33
+ CONTENT: (t) => `/content${E(t)}`
34
+ }, d = (t) => {
35
+ 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;
30
36
  return `${o}://${n}/api/${r}`;
31
- }, T = async (t, e) => fetch(`${_(e)}${t}`, {
37
+ }, i = async (t, e) => fetch(`${d(e)}${t}`, {
32
38
  headers: {
33
- [l.SESSION_KEY]: `${l.SESSION_TYPE} ${e.accessToken}`
39
+ [u.SESSION_KEY]: `${u.SESSION_TYPE} ${e.accessToken}`
34
40
  }
35
41
  }).then((o) => {
36
42
  if (o.ok)
@@ -41,23 +47,23 @@ const s = {
41
47
  statusText: o.statusText
42
48
  })
43
49
  );
44
- }), d = (t) => {
45
- const e = (n) => T(a.CONTENT_LIST(n), t), o = (n) => T(a.CONTENT(n), t);
50
+ }), p = (t) => {
51
+ const e = (n) => i(T.CONTENT_LIST(n), t), o = (n) => i(T.CONTENT(n), t);
46
52
  return {
47
- getProject: () => T(a.PROJECT, t),
53
+ getProject: () => i(T.PROJECT, t),
48
54
  getContentList: (n) => e(n).then(
49
55
  (r) => Array.isArray(r) ? r.map(
50
- (c) => N(c, n == null ? void 0 : n.language)
56
+ (s) => c(s, n == null ? void 0 : n.language)
51
57
  ) : []
52
58
  ),
53
59
  getContent: (n) => o(n).then(
54
- (r) => N(r, n == null ? void 0 : n.language)
60
+ (r) => c(r, n == null ? void 0 : n.language)
55
61
  ),
56
62
  getRawContentList: e,
57
63
  getRawContent: o
58
64
  };
59
65
  };
60
66
  export {
61
- d as createClient,
62
- N as mapContentToModel
67
+ p as createClient,
68
+ c as mapContentToModel
63
69
  };
@@ -1 +1 @@
1
- (function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.ApiClient={}))})(this,function(s){"use strict";const c={IS_PRODUCTION:!0,DEFAULT_API_CLIENT_DOMAIN:"api.contentisland.net",DEFAULT_API_CLIENT_VERSION:"1.0"},u={SESSION_KEY:"authorization",SESSION_TYPE:"Bearer"},E=e=>e.reduce((t,o)=>({...t,[o.name]:o.value}),{}),S=(e,t,o)=>{var g;const n=o??((g=e[0])==null?void 0:g.language),i=e.filter(I=>I.language===n),r=E(i);return Object.keys(r).length===0&&console.warn(`No fields found for language "${n}" and content id "${t}"`),{id:t,language:n,...r}},l=(e,t)=>Array.isArray(e==null?void 0:e.fields)?S(e.fields,e.id,t):{},d=(e,t)=>{if(typeof t=="string")return`${e}=${t}`;if(t.in)return`${e}[in]=${t.in.join(",")}`},O=(e,t)=>Object.entries(e).reduce((o,[n,i],r)=>r===0?d(n,i):`${o}${t}${d(n,i)}`,""),N=e=>e&&Object.keys(e).length>0?`?${O(e,"&")}`:"",a={PROJECT:"/project",CONTENT_LIST:e=>`/contents${N(e)}`,CONTENT:e=>`/content${N(e)}`},f=e=>{const o=(e.secureProtocol===void 0?c.IS_PRODUCTION:e.secureProtocol)?"https":"http",n=e.domain?e.domain:c.DEFAULT_API_CLIENT_DOMAIN,i=e.apiVersion?e.apiVersion:c.DEFAULT_API_CLIENT_VERSION;return`${o}://${n}/api/${i}`},T=async(e,t)=>fetch(`${f(t)}${e}`,{headers:{[u.SESSION_KEY]:`${u.SESSION_TYPE} ${t.accessToken}`}}).then(o=>{if(o.ok)return o.json();throw Error(JSON.stringify({status:o.status,statusText:o.statusText}))}),C=e=>{const t=n=>T(a.CONTENT_LIST(n),e),o=n=>T(a.CONTENT(n),e);return{getProject:()=>T(a.PROJECT,e),getContentList:n=>t(n).then(i=>Array.isArray(i)?i.map(r=>l(r,n==null?void 0:n.language)):[]),getContent:n=>o(n).then(i=>l(i,n==null?void 0:n.language)),getRawContentList:t,getRawContent:o}};s.createClient=C,s.mapContentToModel=l,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(r,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(r=typeof globalThis<"u"?globalThis:r||self,c(r.ApiClient={}))})(this,function(r){"use strict";const c={IS_PRODUCTION:!0,DEFAULT_API_CLIENT_DOMAIN:"api.contentisland.net",DEFAULT_API_CLIENT_VERSION:"1.0"},u={SESSION_KEY:"authorization",SESSION_TYPE:"Bearer"},g=e=>e==null?void 0:e.includes("|"),C=(e,t)=>Array.isArray(e)?e.map(t):[],S=(e,t)=>e.isArray?C(e.value,o=>i(o,t)):i(e.value,t),O=e=>g(e.type)&&(e.isArray?e.value.every(t=>typeof t=="object"&&"contentType"in t):typeof e.value=="object"&&"contentType"in e.value),A=(e,t)=>e.reduce((o,n)=>({...o,[n.name]:O(n)?S(n,t):n.value}),{}),I=(e,t,o)=>{var E;const n=o??((E=e[0])==null?void 0:E.language),s=e.filter(f=>f.language===n),a=A(s,n);return Object.keys(a).length===0&&console.warn(`No fields found for language "${n}" and content id "${t}"`),{id:t,language:n,...a}},i=(e,t)=>Array.isArray(e==null?void 0:e.fields)?I(e.fields,e.id,t):{},N=(e,t)=>{if(typeof t=="string"||typeof t=="boolean")return`${e}=${t}`;if(t.in)return`${e}[in]=${t.in.join(",")}`},_=(e,t)=>Object.entries(e).reduce((o,[n,s],a)=>a===0?N(n,s):`${o}${t}${N(n,s)}`,""),d=e=>e&&Object.keys(e).length>0?`?${_(e,"&")}`:"",T={PROJECT:"/project",CONTENT_LIST:e=>`/contents${d(e)}`,CONTENT:e=>`/content${d(e)}`},p=e=>{const o=(e.secureProtocol===void 0?c.IS_PRODUCTION:e.secureProtocol)?"https":"http",n=e.domain?e.domain:c.DEFAULT_API_CLIENT_DOMAIN,s=e.apiVersion?e.apiVersion:c.DEFAULT_API_CLIENT_VERSION;return`${o}://${n}/api/${s}`},l=async(e,t)=>fetch(`${p(t)}${e}`,{headers:{[u.SESSION_KEY]:`${u.SESSION_TYPE} ${t.accessToken}`}}).then(o=>{if(o.ok)return o.json();throw Error(JSON.stringify({status:o.status,statusText:o.statusText}))}),$=e=>{const t=n=>l(T.CONTENT_LIST(n),e),o=n=>l(T.CONTENT(n),e);return{getProject:()=>l(T.PROJECT,e),getContentList:n=>t(n).then(s=>Array.isArray(s)?s.map(a=>i(a,n==null?void 0:n.language)):[]),getContent:n=>o(n).then(s=>i(s,n==null?void 0:n.language)),getRawContentList:t,getRawContent:o}};r.createClient=$,r.mapContentToModel=i,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@content-island/api-client",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "description": "Content Island - REST API Client",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -29,6 +29,7 @@
29
29
  "test:watch": "vitest -c ./config/test/config.ts"
30
30
  },
31
31
  "devDependencies": {
32
- "@content-island/b2b-api-model": "*"
32
+ "@content-island/b2b-api-model": "*",
33
+ "@content-island/common": "*"
33
34
  }
34
35
  }