@content-island/api-client 0.1.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.
@@ -0,0 +1,34 @@
1
+ const r = {
2
+ sessionKey: "authorization",
3
+ sessionType: "Bearer"
4
+ }, i = {
5
+ DEFAULT_B2B_BASE_URL: "https://dev-content-island-b2b.azurewebsites.net/api/1.0"
6
+ }, l = (t) => {
7
+ const { accessToken: e, baseUrl: n = i.DEFAULT_B2B_BASE_URL } = t;
8
+ return {
9
+ get: async (s) => fetch(`${n}/${s}`, {
10
+ headers: {
11
+ [r.sessionKey]: `${r.sessionType} ${e}`
12
+ }
13
+ }).then((o) => o.json())
14
+ };
15
+ }, u = (t, e) => {
16
+ var n;
17
+ return (n = t.find((s) => s.name === e)) == null ? void 0 : n.value;
18
+ }, c = (t) => Array.isArray(t.filterList) ? `?${y(t.filterList, "&")}` : "", y = (t, e) => Array.isArray(t) ? t.reduce(
19
+ (n, s, o, a) => a.length - 1 === o ? n += s : n += `${s}${e} `,
20
+ ""
21
+ ) : "", $ = {
22
+ projectList: () => "/projects",
23
+ project: (t) => `/projects/${t}`,
24
+ contentList: (t) => `/contents${c(t)}`,
25
+ content: (t) => {
26
+ const e = c(t);
27
+ return `/contents/${t.id}${e}`;
28
+ }
29
+ };
30
+ export {
31
+ $ as API_URLS,
32
+ l as createContentIslandClient,
33
+ u as mapFieldToValue
34
+ };
@@ -0,0 +1 @@
1
+ (function(t,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(t=typeof globalThis<"u"?globalThis:t||self,o(t.ApiClient={}))})(this,function(t){"use strict";const o={sessionKey:"authorization",sessionType:"Bearer"},a={DEFAULT_B2B_BASE_URL:"https://dev-content-island-b2b.azurewebsites.net/api/1.0"},d=e=>{const{accessToken:n,baseUrl:s=a.DEFAULT_B2B_BASE_URL}=e;return{get:async i=>fetch(`${s}/${i}`,{headers:{[o.sessionKey]:`${o.sessionType} ${n}`}}).then(r=>r.json())}},l=(e,n)=>{var s;return(s=e.find(i=>i.name===n))==null?void 0:s.value},c=e=>Array.isArray(e.filterList)?`?${u(e.filterList,"&")}`:"",u=(e,n)=>Array.isArray(e)?e.reduce((s,i,r,f)=>f.length-1===r?s+=i:s+=`${i}${n} `,""):"",y={projectList:()=>"/projects",project:e=>`/projects/${e}`,contentList:e=>`/contents${c(e)}`,content:e=>{const n=c(e);return`/contents/${e.id}${n}`}};t.API_URLS=y,t.createContentIslandClient=d,t.mapFieldToValue=l,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,9 @@
1
+ interface Options {
2
+ accessToken: string;
3
+ baseUrl?: string;
4
+ }
5
+ export interface ContentIslandClient {
6
+ get: <Entity>(url: string) => Promise<Entity>;
7
+ }
8
+ export declare const createContentIslandClient: (options: Options) => ContentIslandClient;
9
+ export {};
@@ -0,0 +1,7 @@
1
+ export declare const authConstants: {
2
+ sessionKey: string;
3
+ sessionType: string;
4
+ };
5
+ export declare const envConstants: {
6
+ DEFAULT_B2B_BASE_URL: string;
7
+ };
@@ -0,0 +1,4 @@
1
+ export type { Project, Content, Field, FieldType, Resource, LookupApi } from '@content-island/b2b-api-model';
2
+ export * from './client';
3
+ export * from './mappers';
4
+ export * from './urls';
@@ -0,0 +1,2 @@
1
+ import { Field } from '@content-island/b2b-api-model';
2
+ export declare const mapFieldToValue: <Entity>(fields: Field[], key: keyof Entity) => any;
package/dist/urls.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ interface BaseParams {
2
+ filterList: string[];
3
+ }
4
+ interface ContentParams extends BaseParams {
5
+ id: string;
6
+ }
7
+ export declare const API_URLS: {
8
+ projectList: () => string;
9
+ project: (id: string) => string;
10
+ contentList: (params: BaseParams) => string;
11
+ content: (params: ContentParams) => string;
12
+ };
13
+ export {};
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@content-island/api-client",
3
+ "version": "0.1.0",
4
+ "description": "Content Island - REST API Client",
5
+ "private": false,
6
+ "author": "Lemoncode",
7
+ "license": "MIT",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "type": "module",
12
+ "module": "./dist/api-client.js",
13
+ "main": "./dist/api-client.umd.cjs",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/api-client.js",
18
+ "require": "./dist/api-client.umd.cjs",
19
+ "types": "./dist/index.d.ts"
20
+ }
21
+ },
22
+ "scripts": {
23
+ "prebuild": "if-env NODE_ENV=development && sh ./create-dev-env.sh || echo noop",
24
+ "build": "vite build",
25
+ "type-check": "tsc --noEmit",
26
+ "type-check:watch": "npm run type-check -- --watch --preserveWatchOutput"
27
+ },
28
+ "dependencies": {
29
+ "@content-island/b2b-api-model": "*"
30
+ },
31
+ "devDependencies": {
32
+ "dotenv": "^16.3.1",
33
+ "if-env": "^1.0.4",
34
+ "typescript": "^5.2.2",
35
+ "vite": "^4.4.9",
36
+ "vite-plugin-dts": "^3.5.3"
37
+ }
38
+ }