@faable/deploy-sdk 1.0.5 → 1.0.7
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/FaableDeployApi.d.ts +88 -4
- package/dist/FaableDeployApi.d.ts.map +1 -1
- package/dist/FaableDeployApi.js +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/package.json +3 -4
- package/dist/api/FaableApi.d.ts +0 -16
- package/dist/api/FaableApi.d.ts.map +0 -1
- package/dist/api/FaableApi.js +0 -14
- package/dist/auth/apikey.d.ts +0 -4
- package/dist/auth/apikey.d.ts.map +0 -1
- package/dist/auth/apikey.js +0 -17
- package/dist/core-types/AuthInterface.d.ts +0 -5
- package/dist/core-types/AuthInterface.d.ts.map +0 -1
- package/dist/core-types/AuthInterface.js +0 -1
- package/dist/core-types/StrategyInterface.d.ts +0 -5
- package/dist/core-types/StrategyInterface.d.ts.map +0 -1
- package/dist/core-types/StrategyInterface.js +0 -1
- package/dist/fetcher/Fetcher.d.ts +0 -20
- package/dist/fetcher/Fetcher.d.ts.map +0 -1
- package/dist/fetcher/Fetcher.js +0 -1
- package/dist/fetcher/fetcher_axios.d.ts +0 -4
- package/dist/fetcher/fetcher_axios.d.ts.map +0 -1
- package/dist/fetcher/fetcher_axios.js +0 -53
- package/dist/helpers/authorize-client-credentials.d.ts +0 -17
- package/dist/helpers/authorize-client-credentials.d.ts.map +0 -1
- package/dist/helpers/authorize-client-credentials.js +0 -38
- package/dist/helpers/authorize.d.ts +0 -9
- package/dist/helpers/authorize.d.ts.map +0 -1
- package/dist/helpers/authorize.js +0 -39
- package/dist/helpers/error_handler.d.ts +0 -4
- package/dist/helpers/error_handler.d.ts.map +0 -1
- package/dist/helpers/error_handler.js +0 -7
- package/dist/helpers/paginator.d.ts +0 -15
- package/dist/helpers/paginator.d.ts.map +0 -1
- package/dist/helpers/paginator.js +0 -28
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FaableApi, ApiParams } from "@faable/sdk-base";
|
|
2
2
|
export declare class DeployApi extends FaableApi {
|
|
3
3
|
constructor(params?: ApiParams);
|
|
4
4
|
getDeployment(id: string): Promise<{
|
|
@@ -39,12 +39,96 @@ export declare class DeployApi extends FaableApi {
|
|
|
39
39
|
createdAt: string;
|
|
40
40
|
}>;
|
|
41
41
|
listApps(): {
|
|
42
|
-
all: () => Promise<
|
|
43
|
-
|
|
42
|
+
all: () => Promise<{
|
|
43
|
+
id: string;
|
|
44
|
+
profile?: {
|
|
45
|
+
id: string;
|
|
46
|
+
slug: string;
|
|
47
|
+
name?: string;
|
|
48
|
+
description: string;
|
|
49
|
+
is_team: boolean;
|
|
50
|
+
owner_id: string;
|
|
51
|
+
stripe_sub?: string | null;
|
|
52
|
+
createdAt: string;
|
|
53
|
+
} | string | unknown;
|
|
54
|
+
team: string;
|
|
55
|
+
name: string;
|
|
56
|
+
description: string;
|
|
57
|
+
slug: string;
|
|
58
|
+
url: string;
|
|
59
|
+
active: boolean;
|
|
60
|
+
runtime: import("./api/types.js").components["schemas"]["AppRuntime"];
|
|
61
|
+
runtime_strategy: ("next" | "wordpress") | null;
|
|
62
|
+
instance_type: string;
|
|
63
|
+
region: string;
|
|
64
|
+
creator: string;
|
|
65
|
+
metadata: {
|
|
66
|
+
[key: string]: unknown;
|
|
67
|
+
};
|
|
68
|
+
status: import("./api/types.js").components["schemas"]["AppStatus"];
|
|
69
|
+
createdAt: string;
|
|
70
|
+
}[]>;
|
|
71
|
+
first: () => Promise<import("@faable/sdk-base/dist/helpers/paginator.js").Page<{
|
|
72
|
+
id: string;
|
|
73
|
+
profile?: {
|
|
74
|
+
id: string;
|
|
75
|
+
slug: string;
|
|
76
|
+
name?: string;
|
|
77
|
+
description: string;
|
|
78
|
+
is_team: boolean;
|
|
79
|
+
owner_id: string;
|
|
80
|
+
stripe_sub?: string | null;
|
|
81
|
+
createdAt: string;
|
|
82
|
+
} | string | unknown;
|
|
83
|
+
team: string;
|
|
84
|
+
name: string;
|
|
85
|
+
description: string;
|
|
86
|
+
slug: string;
|
|
87
|
+
url: string;
|
|
88
|
+
active: boolean;
|
|
89
|
+
runtime: import("./api/types.js").components["schemas"]["AppRuntime"];
|
|
90
|
+
runtime_strategy: ("next" | "wordpress") | null;
|
|
91
|
+
instance_type: string;
|
|
92
|
+
region: string;
|
|
93
|
+
creator: string;
|
|
94
|
+
metadata: {
|
|
95
|
+
[key: string]: unknown;
|
|
96
|
+
};
|
|
97
|
+
status: import("./api/types.js").components["schemas"]["AppStatus"];
|
|
98
|
+
createdAt: string;
|
|
99
|
+
}>>;
|
|
44
100
|
pass: (params?: {
|
|
45
101
|
cursor?: string;
|
|
46
102
|
pageSize?: string;
|
|
47
|
-
}) => Promise<import("
|
|
103
|
+
}) => Promise<import("@faable/sdk-base/dist/helpers/paginator.js").Page<{
|
|
104
|
+
id: string;
|
|
105
|
+
profile?: {
|
|
106
|
+
id: string;
|
|
107
|
+
slug: string;
|
|
108
|
+
name?: string;
|
|
109
|
+
description: string;
|
|
110
|
+
is_team: boolean;
|
|
111
|
+
owner_id: string;
|
|
112
|
+
stripe_sub?: string | null;
|
|
113
|
+
createdAt: string;
|
|
114
|
+
} | string | unknown;
|
|
115
|
+
team: string;
|
|
116
|
+
name: string;
|
|
117
|
+
description: string;
|
|
118
|
+
slug: string;
|
|
119
|
+
url: string;
|
|
120
|
+
active: boolean;
|
|
121
|
+
runtime: import("./api/types.js").components["schemas"]["AppRuntime"];
|
|
122
|
+
runtime_strategy: ("next" | "wordpress") | null;
|
|
123
|
+
instance_type: string;
|
|
124
|
+
region: string;
|
|
125
|
+
creator: string;
|
|
126
|
+
metadata: {
|
|
127
|
+
[key: string]: unknown;
|
|
128
|
+
};
|
|
129
|
+
status: import("./api/types.js").components["schemas"]["AppStatus"];
|
|
130
|
+
createdAt: string;
|
|
131
|
+
}>>;
|
|
48
132
|
};
|
|
49
133
|
updateStatus<T>(id: string, data: T): Promise<unknown>;
|
|
50
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FaableDeployApi.d.ts","sourceRoot":"","sources":["../src/FaableDeployApi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FaableDeployApi.d.ts","sourceRoot":"","sources":["../src/FaableDeployApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGxD,qBAAa,SAAU,SAAQ,SAAS;gBAC1B,MAAM,CAAC,EAAE,SAAS;IAO9B,aAAa,CAAC,EAAE,EAAE,MAAM;;;;gBAaov2B,8CAAsB;;;;IAVly2B,MAAM,CAAC,EAAE,EAAE,MAAM;;;;;gBAU8qnB,CAAC;;;;sBAA6I,CAAC;;;;;;;;;iBAAyU,8CAAsB;;;;;;;;gBAAyf,8CAAsB;;;IAP5rpB,QAAQ;;;;;;oBAOurnB,CAAC;;;;0BAA6I,CAAC;;;;;;;;;qBAAyU,8CAAsB;;;;;;;;oBAAyf,8CAAsB;;;;;;;;oBAA7/B,CAAC;;;;0BAA6I,CAAC;;;;;;;;;;;;;;;;;;;;;kBAT50nB,CAAC;oBAA0B,CAAC;;;;;;oBASiqnB,CAAC;;;;0BAA6I,CAAC;;;;;;;;;qBAAyU,8CAAsB;;;;;;;;oBAAyf,8CAAsB;;;;IAJ5rpB,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;CAGpC"}
|
package/dist/FaableDeployApi.js
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faable/deploy-sdk",
|
|
3
|
-
"
|
|
3
|
+
"description": "Codebase for SDK building",
|
|
4
|
+
"version": "1.0.7",
|
|
4
5
|
"author": "Marc Pomar <marc@faable.com>",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
@@ -10,9 +11,7 @@
|
|
|
10
11
|
"access": "public"
|
|
11
12
|
},
|
|
12
13
|
"dependencies": {
|
|
13
|
-
"
|
|
14
|
-
"jwt-decode": "^4.0.0",
|
|
15
|
-
"ramda": "^0.30.1"
|
|
14
|
+
"@faable/sdk-base": "^1.0.10"
|
|
16
15
|
},
|
|
17
16
|
"devDependencies": {
|
|
18
17
|
"@septh/ts-run": "^1.3.0",
|
package/dist/api/FaableApi.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { AuthInterface } from "../core-types/AuthInterface.js";
|
|
2
|
-
import { Fetcher, FetcherCreateParams } from "../fetcher/Fetcher.js";
|
|
3
|
-
import { Paginator } from "../helpers/paginator.js";
|
|
4
|
-
export type ApiParams = {
|
|
5
|
-
baseURL?: string;
|
|
6
|
-
fetcher?: FetcherCreateParams;
|
|
7
|
-
auth?: AuthInterface<any, any>;
|
|
8
|
-
debug?: boolean;
|
|
9
|
-
};
|
|
10
|
-
export declare abstract class FaableApi {
|
|
11
|
-
protected fetcher: Fetcher;
|
|
12
|
-
protected paginator: Paginator;
|
|
13
|
-
constructor(params?: ApiParams);
|
|
14
|
-
static create<T extends abstract new (...args: any) => any>(this: T, params?: ApiParams): InstanceType<T>;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=FaableApi.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FaableApi.d.ts","sourceRoot":"","sources":["../../src/api/FaableApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAErE,OAAO,EAAkB,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpE,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,IAAI,CAAC,EAAE,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC/B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,8BAAsB,SAAS;IAC7B,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC;IAC3B,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC;gBAEnB,MAAM,GAAE,SAAc;IAKlC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,EACxD,IAAI,EAAE,CAAC,EACP,MAAM,GAAE,SAAc,GACrB,YAAY,CAAC,CAAC,CAAC;CAInB"}
|
package/dist/api/FaableApi.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { fetcher_axios } from "../fetcher/fetcher_axios.js";
|
|
2
|
-
import { buildPaginator } from "../helpers/paginator.js";
|
|
3
|
-
export class FaableApi {
|
|
4
|
-
fetcher;
|
|
5
|
-
paginator;
|
|
6
|
-
constructor(params = {}) {
|
|
7
|
-
this.fetcher = fetcher_axios(params);
|
|
8
|
-
this.paginator = buildPaginator(this.fetcher);
|
|
9
|
-
}
|
|
10
|
-
static create(params = {}) {
|
|
11
|
-
let Cns = this;
|
|
12
|
-
return new Cns(params);
|
|
13
|
-
}
|
|
14
|
-
}
|
package/dist/auth/apikey.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apikey.d.ts","sourceRoot":"","sources":["../../src/auth/apikey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAGvE,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEzD,eAAO,MAAM,gBAAgB,EAAE,iBAAiB,CAAC,gBAAgB,EAAE,GAAG,EAAE,GAAG,CAoB1E,CAAC"}
|
package/dist/auth/apikey.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const APIKEY_ENV_NAME = "FAABLE_APIKEY";
|
|
2
|
-
export const createApikeyAuth = (apikey) => {
|
|
3
|
-
// Default to environment variable
|
|
4
|
-
apikey = apikey || process.env[APIKEY_ENV_NAME];
|
|
5
|
-
if (!apikey) {
|
|
6
|
-
throw new Error(`[@faable/deploy-sdk] No apikey passed to createApikeyAuth. Pass an apikey or use ${APIKEY_ENV_NAME} environment variable`);
|
|
7
|
-
}
|
|
8
|
-
const auth = async () => {
|
|
9
|
-
return {
|
|
10
|
-
headers: {
|
|
11
|
-
authorization: `basic ${btoa(`${apikey}:${apikey}`)}`,
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
return Object.assign(auth, { hook: auth });
|
|
16
|
-
};
|
|
17
|
-
let m = createApikeyAuth();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AuthInterface.d.ts","sourceRoot":"","sources":["../../src/core-types/AuthInterface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa,CAC5B,WAAW,SAAS,GAAG,EAAE,EACzB,cAAc,SAAS,GAAG;IAE1B,CAAC,GAAG,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAChD,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;CACzD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { AuthInterface } from "./AuthInterface.js";
|
|
2
|
-
export interface StrategyInterface<StrategyOptions extends any[], AuthOptions extends any[], Authentication extends object> {
|
|
3
|
-
(...args: StrategyOptions): AuthInterface<AuthOptions, Authentication>;
|
|
4
|
-
}
|
|
5
|
-
//# sourceMappingURL=StrategyInterface.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StrategyInterface.d.ts","sourceRoot":"","sources":["../../src/core-types/StrategyInterface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,MAAM,WAAW,iBAAiB,CAChC,eAAe,SAAS,GAAG,EAAE,EAC7B,WAAW,SAAS,GAAG,EAAE,EACzB,cAAc,SAAS,MAAM;IAE7B,CAAC,GAAG,IAAI,EAAE,eAAe,GAAG,aAAa,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;CACxE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
type Method = "get" | "GET" | "delete" | "DELETE" | "head" | "HEAD" | "options" | "OPTIONS" | "post" | "POST" | "put" | "PUT" | "patch" | "PATCH" | "purge" | "PURGE" | "link" | "LINK" | "unlink" | "UNLINK";
|
|
2
|
-
export type FetcherRequestParams = {
|
|
3
|
-
url: string;
|
|
4
|
-
method?: Method;
|
|
5
|
-
params?: any;
|
|
6
|
-
};
|
|
7
|
-
export type Headers = {
|
|
8
|
-
authorization?: string;
|
|
9
|
-
};
|
|
10
|
-
export type FetcherCreateParams = {
|
|
11
|
-
headers?: Headers;
|
|
12
|
-
};
|
|
13
|
-
export type Fetcher = {
|
|
14
|
-
get: <T>(url: string) => Promise<T>;
|
|
15
|
-
post: <T>(url: string, data: any) => Promise<T>;
|
|
16
|
-
request: <T>(params: FetcherRequestParams) => Promise<T>;
|
|
17
|
-
check: <T>(url: string, status?: number) => Promise<boolean>;
|
|
18
|
-
};
|
|
19
|
-
export {};
|
|
20
|
-
//# sourceMappingURL=Fetcher.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Fetcher.d.ts","sourceRoot":"","sources":["../../src/fetcher/Fetcher.ts"],"names":[],"mappings":"AAAA,KAAK,MAAM,GACP,KAAK,GACL,KAAK,GACL,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,MAAM,GACN,SAAS,GACT,SAAS,GACT,MAAM,GACN,MAAM,GACN,KAAK,GACL,KAAK,GACL,OAAO,GACP,OAAO,GACP,OAAO,GACP,OAAO,GACP,MAAM,GACN,MAAM,GACN,QAAQ,GACR,QAAQ,CAAC;AACb,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,GAAG,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IACpC,IAAI,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAChD,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,oBAAoB,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IACzD,KAAK,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9D,CAAC"}
|
package/dist/fetcher/Fetcher.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher_axios.d.ts","sourceRoot":"","sources":["../../src/fetcher/fetcher_axios.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAShD,eAAO,MAAM,aAAa,YAAY,SAAS,KAAQ,OAiDtD,CAAC"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import { FaableApiError } from "../helpers/error_handler.js";
|
|
3
|
-
const handleErrorInterceptor = async (e) => {
|
|
4
|
-
const data = e.response?.data;
|
|
5
|
-
throw new FaableApiError(`FaableApiError: ${data?.message} (status=${e.response?.status}, url=${e.response?.config.url})`);
|
|
6
|
-
};
|
|
7
|
-
export const fetcher_axios = (params = {}) => {
|
|
8
|
-
const instance = axios.create({
|
|
9
|
-
baseURL: params.baseURL,
|
|
10
|
-
...(params.fetcher || {}),
|
|
11
|
-
});
|
|
12
|
-
instance.interceptors.request.use(async (req) => {
|
|
13
|
-
const auth_data = params.auth && (await params.auth.hook());
|
|
14
|
-
req.headers = auth_data?.headers;
|
|
15
|
-
return req;
|
|
16
|
-
});
|
|
17
|
-
// Add base interceptor
|
|
18
|
-
instance.interceptors.response.use((res) => {
|
|
19
|
-
if (params.debug) {
|
|
20
|
-
console.log(`[${res.status} ${res.statusText}] ${res.config.url}`);
|
|
21
|
-
}
|
|
22
|
-
return res;
|
|
23
|
-
}, handleErrorInterceptor);
|
|
24
|
-
return {
|
|
25
|
-
get: async (url) => {
|
|
26
|
-
const res = await instance.request({
|
|
27
|
-
method: "GET",
|
|
28
|
-
url,
|
|
29
|
-
});
|
|
30
|
-
return res.data;
|
|
31
|
-
},
|
|
32
|
-
post: async (url, data) => {
|
|
33
|
-
const res = await instance.request({
|
|
34
|
-
method: "POST",
|
|
35
|
-
url,
|
|
36
|
-
data,
|
|
37
|
-
});
|
|
38
|
-
return res.data;
|
|
39
|
-
},
|
|
40
|
-
request: async (params) => {
|
|
41
|
-
const res = await instance.request(params);
|
|
42
|
-
return res.data;
|
|
43
|
-
},
|
|
44
|
-
check: async (url) => {
|
|
45
|
-
const res = await instance.request({
|
|
46
|
-
method: "GET",
|
|
47
|
-
url,
|
|
48
|
-
validateStatus: () => true,
|
|
49
|
-
});
|
|
50
|
-
return res.status == 200;
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export type ClientCredentialsConfig = {
|
|
2
|
-
domain: string;
|
|
3
|
-
clientId: string;
|
|
4
|
-
clientSecret: string;
|
|
5
|
-
};
|
|
6
|
-
export interface ClientCredentialsResponse {
|
|
7
|
-
access_token: string;
|
|
8
|
-
}
|
|
9
|
-
export declare class ClientCredentialsFlow {
|
|
10
|
-
private config;
|
|
11
|
-
constructor(config: ClientCredentialsConfig);
|
|
12
|
-
private response?;
|
|
13
|
-
private isTokenExpired;
|
|
14
|
-
private _getToken;
|
|
15
|
-
getToken(): Promise<string>;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=authorize-client-credentials.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorize-client-credentials.d.ts","sourceRoot":"","sources":["../../src/helpers/authorize-client-credentials.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,WAAW,yBAAyB;IACxC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,qBAAqB;IACpB,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,uBAAuB;IAEnD,OAAO,CAAC,QAAQ,CAAC,CAA4B;IAE7C,OAAO,CAAC,cAAc;YAUR,SAAS;IAgBjB,QAAQ;CASf"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import { jwtDecode } from "jwt-decode";
|
|
3
|
-
export class ClientCredentialsFlow {
|
|
4
|
-
config;
|
|
5
|
-
constructor(config) {
|
|
6
|
-
this.config = config;
|
|
7
|
-
}
|
|
8
|
-
response;
|
|
9
|
-
isTokenExpired() {
|
|
10
|
-
if (!this.response)
|
|
11
|
-
throw new Error("No token");
|
|
12
|
-
let { exp } = jwtDecode(this.response?.access_token);
|
|
13
|
-
if (!exp) {
|
|
14
|
-
throw new Error("Missing expire date");
|
|
15
|
-
}
|
|
16
|
-
const currentSeconds = new Date().getTime() / 1000;
|
|
17
|
-
return currentSeconds > exp;
|
|
18
|
-
}
|
|
19
|
-
async _getToken() {
|
|
20
|
-
const params = new URLSearchParams();
|
|
21
|
-
params.append("grant_type", "client_credentials");
|
|
22
|
-
params.append("client_id", this.config.clientId);
|
|
23
|
-
params.append("client_secret", this.config.clientSecret);
|
|
24
|
-
const res = await axios.post(this.config.domain + "/oauth/token", params);
|
|
25
|
-
this.response = res.data;
|
|
26
|
-
console.log(`[${this.config.domain}] ✅ Client Credentials flow completed `);
|
|
27
|
-
return this.response;
|
|
28
|
-
}
|
|
29
|
-
async getToken() {
|
|
30
|
-
if (!this.response || this.isTokenExpired()) {
|
|
31
|
-
await this._getToken();
|
|
32
|
-
}
|
|
33
|
-
if (!this.response?.access_token) {
|
|
34
|
-
throw new Error("Cannot get token");
|
|
35
|
-
}
|
|
36
|
-
return this.response?.access_token;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from "axios";
|
|
2
|
-
import { ClientCredentialsConfig } from "./authorize-client-credentials.js";
|
|
3
|
-
interface AuthConfig {
|
|
4
|
-
client?: AxiosInstance;
|
|
5
|
-
client_credentials?: ClientCredentialsConfig;
|
|
6
|
-
}
|
|
7
|
-
export declare const authorize: (_config?: AuthConfig) => AxiosInstance;
|
|
8
|
-
export {};
|
|
9
|
-
//# sourceMappingURL=authorize.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../src/helpers/authorize.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,EAEL,uBAAuB,EACxB,MAAM,mCAAmC,CAAC;AAE3C,UAAU,UAAU;IAClB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,kBAAkB,CAAC,EAAE,uBAAuB,CAAC;CAC9C;AAED,eAAO,MAAM,SAAS,aAAc,UAAU,kBA6C7C,CAAC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import { ClientCredentialsFlow, } from "./authorize-client-credentials.js";
|
|
3
|
-
export const authorize = (_config) => {
|
|
4
|
-
const authDomain = process.env.FAABLEAUTH_DOMAIN || _config?.client_credentials?.domain || "";
|
|
5
|
-
if (!authDomain) {
|
|
6
|
-
throw new Error("Setup Faable Auth failed, missing env FAABLEAUTH_DOMAIN");
|
|
7
|
-
}
|
|
8
|
-
const client_credentials_config = {
|
|
9
|
-
domain: authDomain,
|
|
10
|
-
clientId: process.env.FAABLEAUTH_CLIENT_ID ||
|
|
11
|
-
_config?.client_credentials?.clientId ||
|
|
12
|
-
"",
|
|
13
|
-
clientSecret: process.env.FAABLEAUTH_CLIENT_SECRET ||
|
|
14
|
-
_config?.client_credentials?.clientSecret ||
|
|
15
|
-
"",
|
|
16
|
-
};
|
|
17
|
-
// Reuse client or setup a new one
|
|
18
|
-
const client = _config?.client || axios.create({ baseURL: authDomain });
|
|
19
|
-
// Config is OK
|
|
20
|
-
let enable_client_credentials = false;
|
|
21
|
-
if (client_credentials_config.domain &&
|
|
22
|
-
client_credentials_config.clientId &&
|
|
23
|
-
client_credentials_config.clientSecret) {
|
|
24
|
-
enable_client_credentials = true;
|
|
25
|
-
console.log(`[${client_credentials_config.domain}] Using client credentials`);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
console.warn(`Client credentials not configured`);
|
|
29
|
-
}
|
|
30
|
-
const flow = new ClientCredentialsFlow(client_credentials_config);
|
|
31
|
-
client.interceptors.request.use(async function (config) {
|
|
32
|
-
if (enable_client_credentials) {
|
|
33
|
-
const token = await flow.getToken();
|
|
34
|
-
config.headers.set("Authorization", `Bearer ${token}`);
|
|
35
|
-
}
|
|
36
|
-
return config;
|
|
37
|
-
});
|
|
38
|
-
return client;
|
|
39
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error_handler.d.ts","sourceRoot":"","sources":["../../src/helpers/error_handler.ts"],"names":[],"mappings":"AAAA,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,GAAG,EAAE,MAAM;CAKxB"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Fetcher, FetcherRequestParams } from "../fetcher/Fetcher.js";
|
|
2
|
-
export interface Page<T> {
|
|
3
|
-
next: string | null;
|
|
4
|
-
results: T[];
|
|
5
|
-
}
|
|
6
|
-
export type Paginator = ReturnType<typeof buildPaginator>;
|
|
7
|
-
export declare const buildPaginator: (fetcher: Fetcher) => <T>(req: FetcherRequestParams) => {
|
|
8
|
-
all: () => Promise<T[]>;
|
|
9
|
-
first: () => Promise<Page<T>>;
|
|
10
|
-
pass: (params?: {
|
|
11
|
-
cursor?: string;
|
|
12
|
-
pageSize?: string;
|
|
13
|
-
}) => Promise<Page<T>>;
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=paginator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paginator.d.ts","sourceRoot":"","sources":["../../src/helpers/paginator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAEtE,MAAM,WAAW,IAAI,CAAC,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,CAAC,EAAE,CAAC;CACd;AACD,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAC1D,eAAO,MAAM,cAAc,YACf,OAAO,MAChB,CAAC,OAAO,oBAAoB;;;oBAiBJ;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE;CAU9D,CAAC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export const buildPaginator = (fetcher) => (req) => {
|
|
2
|
-
return {
|
|
3
|
-
all: async () => {
|
|
4
|
-
const pages = [];
|
|
5
|
-
let data;
|
|
6
|
-
do {
|
|
7
|
-
data = await fetcher.request({
|
|
8
|
-
...req,
|
|
9
|
-
params: { ...req.params, next: data && data?.next },
|
|
10
|
-
});
|
|
11
|
-
pages.push(data);
|
|
12
|
-
} while (data.next);
|
|
13
|
-
return pages.map((page) => page.results).flat();
|
|
14
|
-
},
|
|
15
|
-
first: async () => {
|
|
16
|
-
return fetcher.request(req);
|
|
17
|
-
},
|
|
18
|
-
pass: async (params = {}) => {
|
|
19
|
-
return fetcher.request({
|
|
20
|
-
...req,
|
|
21
|
-
params: {
|
|
22
|
-
...req.params,
|
|
23
|
-
...params,
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
};
|