@content-island/api-client 0.3.1 → 0.4.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/README.md +35 -29
- package/dist/api-client.js +27 -19
- package/dist/api-client.umd.cjs +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/mappers.d.ts +2 -2
- package/dist/model.d.ts +6 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -61,45 +61,51 @@ The query parameters to filter the list of contents.
|
|
|
61
61
|
| ------------- | -------------------------------------------------------------------- |
|
|
62
62
|
| `contentType` | The content type to filter the list of contents. For example: `post` |
|
|
63
63
|
|
|
64
|
-
### `
|
|
64
|
+
### `mapContentToModel(content)`
|
|
65
65
|
|
|
66
66
|
Maps a list of fields to a model.
|
|
67
67
|
|
|
68
68
|
```typescript
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
69
|
+
const content: Content = {
|
|
70
|
+
id: '1',
|
|
71
|
+
contentType: { id: '10', name: 'post' },
|
|
72
|
+
lastUpdate: '2023-10-20T00:00:00.000Z',
|
|
73
|
+
fields: [
|
|
74
|
+
{
|
|
75
|
+
id: '100',
|
|
76
|
+
name: 'title',
|
|
77
|
+
value: 'My title',
|
|
78
|
+
type: 'short-text',
|
|
79
|
+
isArray: false,
|
|
80
|
+
language: 'en',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: '200',
|
|
84
|
+
name: 'body',
|
|
85
|
+
value: '# My body',
|
|
86
|
+
type: 'long-text',
|
|
87
|
+
isArray: false,
|
|
88
|
+
language: 'en',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: '300',
|
|
92
|
+
name: 'order',
|
|
93
|
+
value: 1,
|
|
94
|
+
type: 'number',
|
|
95
|
+
isArray: false,
|
|
96
|
+
language: 'en',
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
};
|
|
95
100
|
|
|
96
101
|
interface Post {
|
|
102
|
+
id: string;
|
|
97
103
|
title: string;
|
|
98
104
|
body: string;
|
|
99
105
|
order: number;
|
|
100
106
|
}
|
|
101
107
|
|
|
102
|
-
const post =
|
|
108
|
+
const post = mapContentToModel<Post>(fields);
|
|
103
109
|
|
|
104
|
-
console.log(post); // { title: 'My title', body: '# My body', order: 1 }
|
|
110
|
+
console.log(post); // { id: '1', title: 'My title', body: '# My body', order: 1 }
|
|
105
111
|
```
|
package/dist/api-client.js
CHANGED
|
@@ -2,41 +2,49 @@ 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
|
-
},
|
|
5
|
+
}, c = {
|
|
6
6
|
SESSION_KEY: "authorization",
|
|
7
7
|
SESSION_TYPE: "Bearer"
|
|
8
|
+
}, i = (t, e) => {
|
|
9
|
+
if (typeof e == "string")
|
|
10
|
+
return `${t}=${e}`;
|
|
11
|
+
if (e.in)
|
|
12
|
+
return `${t}[in]=${e.in.join(",")}`;
|
|
8
13
|
}, S = (t, e) => Object.entries(t).reduce(
|
|
9
|
-
(
|
|
14
|
+
(r, [n, T], E) => E === 0 ? i(n, T) : `${r}${e}${i(n, T)}`,
|
|
10
15
|
""
|
|
11
|
-
), N = (t) => t && Object.keys(t).length > 0 ? `?${S(t, "&")}` : "",
|
|
16
|
+
), N = (t) => t && Object.keys(t).length > 0 ? `?${S(t, "&")}` : "", s = {
|
|
12
17
|
PROYECT: "/project",
|
|
13
18
|
CONTENT_LIST: (t) => `/contents${N(t)}`,
|
|
14
19
|
CONTENT: (t, e) => {
|
|
15
|
-
const
|
|
16
|
-
return `/contents/${t}${
|
|
20
|
+
const r = N(e);
|
|
21
|
+
return `/contents/${t}${r}`;
|
|
17
22
|
}
|
|
18
23
|
}, _ = (t) => {
|
|
19
|
-
const e = "https",
|
|
20
|
-
return `${e}://${
|
|
21
|
-
},
|
|
24
|
+
const e = "https", r = t.domain ? t.domain : a.DEFAULT_API_CLIENT_DOMAIN, n = t.apiVersion ? t.apiVersion : a.DEFAULT_API_CLIENT_VERSION;
|
|
25
|
+
return `${e}://${r}/api/${n}`;
|
|
26
|
+
}, o = async (t, e) => fetch(`${_(e)}${t}`, {
|
|
22
27
|
headers: {
|
|
23
|
-
[
|
|
28
|
+
[c.SESSION_KEY]: `${c.SESSION_TYPE} ${e.accessToken}`
|
|
24
29
|
}
|
|
25
|
-
}).then((
|
|
26
|
-
if (
|
|
27
|
-
return
|
|
30
|
+
}).then((r) => {
|
|
31
|
+
if (r.ok)
|
|
32
|
+
return r.json();
|
|
28
33
|
throw Error(
|
|
29
34
|
JSON.stringify({
|
|
30
|
-
status:
|
|
31
|
-
statusText:
|
|
35
|
+
status: r.status,
|
|
36
|
+
statusText: r.statusText
|
|
32
37
|
})
|
|
33
38
|
);
|
|
34
39
|
}), O = (t) => ({
|
|
35
|
-
getProject: () =>
|
|
36
|
-
getContentList: (e) =>
|
|
37
|
-
getContent: (e,
|
|
38
|
-
}), I = (t) => t.reduce((e,
|
|
40
|
+
getProject: () => o(s.PROYECT, t),
|
|
41
|
+
getContentList: (e) => o(s.CONTENT_LIST(e), t),
|
|
42
|
+
getContent: (e, r) => o(s.CONTENT(e, r), t)
|
|
43
|
+
}), I = (t) => t.reduce((e, r) => ({ ...e, [r.name]: r.value }), {}), u = (t) => Array.isArray(t == null ? void 0 : t.fields) ? {
|
|
44
|
+
id: t.id,
|
|
45
|
+
...I(t.fields)
|
|
46
|
+
} : {};
|
|
39
47
|
export {
|
|
40
48
|
O as createClient,
|
|
41
|
-
|
|
49
|
+
u as mapContentToModel
|
|
42
50
|
};
|
package/dist/api-client.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(o,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(o=typeof globalThis<"u"?globalThis:o||self,r(o.ApiClient={}))})(this,function(o){"use strict";const r={IS_PRODUCTION:!0,DEFAULT_API_CLIENT_DOMAIN:"api.contentisland.net",DEFAULT_API_CLIENT_VERSION:"1.0"},
|
|
1
|
+
(function(o,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(o=typeof globalThis<"u"?globalThis:o||self,r(o.ApiClient={}))})(this,function(o){"use strict";const r={IS_PRODUCTION:!0,DEFAULT_API_CLIENT_DOMAIN:"api.contentisland.net",DEFAULT_API_CLIENT_VERSION:"1.0"},a={SESSION_KEY:"authorization",SESSION_TYPE:"Bearer"},c=(e,t)=>{if(typeof t=="string")return`${e}=${t}`;if(t.in)return`${e}[in]=${t.in.join(",")}`},d=(e,t)=>Object.entries(e).reduce((n,[i,N],I)=>I===0?c(i,N):`${n}${t}${c(i,N)}`,""),u=e=>e&&Object.keys(e).length>0?`?${d(e,"&")}`:"",s={PROYECT:"/project",CONTENT_LIST:e=>`/contents${u(e)}`,CONTENT:(e,t)=>{const n=u(t);return`/contents/${e}${n}`}},E=e=>{const t="https",n=e.domain?e.domain:r.DEFAULT_API_CLIENT_DOMAIN,i=e.apiVersion?e.apiVersion:r.DEFAULT_API_CLIENT_VERSION;return`${t}://${n}/api/${i}`},T=async(e,t)=>fetch(`${E(t)}${e}`,{headers:{[a.SESSION_KEY]:`${a.SESSION_TYPE} ${t.accessToken}`}}).then(n=>{if(n.ok)return n.json();throw Error(JSON.stringify({status:n.status,statusText:n.statusText}))}),S=e=>({getProject:()=>T(s.PROYECT,e),getContentList:t=>T(s.CONTENT_LIST(t),e),getContent:(t,n)=>T(s.CONTENT(t,n),e)}),O=e=>e.reduce((t,n)=>({...t,[n.name]:n.value}),{}),_=e=>Array.isArray(e==null?void 0:e.fields)?{id:e.id,...O(e.fields)}:{};o.createClient=S,o.mapContentToModel=_,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
package/dist/constants.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { Project, Content, Field, FieldType, Resource, ApiLookup } from '@content-island/b2b-api-model';
|
|
2
2
|
export { createClient } from './client.js';
|
|
3
3
|
export type { ApiClient, Options } from './client.js';
|
|
4
|
-
export {
|
|
4
|
+
export { mapContentToModel } from './mappers.js';
|
package/dist/mappers.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
1
|
+
import { Content } from '@content-island/b2b-api-model';
|
|
2
|
+
export declare const mapContentToModel: <Model>(content: Content) => Model;
|
package/dist/model.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
import { Query } from '@content-island/b2b-api-model';
|
|
1
2
|
import { ALLOWED_QUERIES } from './constants.js';
|
|
2
|
-
export type
|
|
3
|
+
export type Filter = string | {
|
|
4
|
+
in?: string[];
|
|
5
|
+
};
|
|
6
|
+
export type AllowedQuery = keyof typeof ALLOWED_QUERIES;
|
|
7
|
+
export type QueryParams = Pick<Query<Filter>, AllowedQuery>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@content-island/api-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Content Island - REST API Client",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Lemoncode",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"test:watch": "vitest -c ./config/test/config.ts"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@content-island/b2b-api-model": "^0.
|
|
31
|
+
"@content-island/b2b-api-model": "^0.3.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"dotenv": "^16.3.1",
|