@faable/deploy-sdk 1.0.0 → 1.0.2

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.
Files changed (44) hide show
  1. package/.github/workflows/release.yml +1 -0
  2. package/dist/FaableDeployApi.d.ts +60 -0
  3. package/dist/FaableDeployApi.d.ts.map +1 -0
  4. package/dist/FaableDeployApi.js +29 -0
  5. package/{src/api/api-types.ts → dist/api/api-types.d.ts} +5 -15
  6. package/dist/api/api-types.d.ts.map +1 -0
  7. package/dist/api/api-types.js +1 -0
  8. package/dist/auth/apikey.d.ts +3 -0
  9. package/dist/auth/apikey.d.ts.map +1 -0
  10. package/dist/auth/apikey.js +7 -0
  11. package/dist/fetcher/Fetcher.d.ts +21 -0
  12. package/dist/fetcher/Fetcher.d.ts.map +1 -0
  13. package/dist/fetcher/Fetcher.js +1 -0
  14. package/dist/fetcher/fetcher_axios.d.ts +3 -0
  15. package/dist/fetcher/fetcher_axios.d.ts.map +1 -0
  16. package/dist/fetcher/fetcher_axios.js +43 -0
  17. package/dist/helpers/authorize-client-credentials.d.ts +17 -0
  18. package/dist/helpers/authorize-client-credentials.d.ts.map +1 -0
  19. package/dist/helpers/authorize-client-credentials.js +38 -0
  20. package/dist/helpers/authorize.d.ts +9 -0
  21. package/dist/helpers/authorize.d.ts.map +1 -0
  22. package/dist/helpers/authorize.js +39 -0
  23. package/dist/helpers/error_handler.d.ts +4 -0
  24. package/dist/helpers/error_handler.d.ts.map +1 -0
  25. package/dist/helpers/error_handler.js +7 -0
  26. package/dist/helpers/paginator.d.ts +15 -0
  27. package/dist/helpers/paginator.d.ts.map +1 -0
  28. package/dist/helpers/paginator.js +28 -0
  29. package/dist/index.d.ts +5 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +4 -0
  32. package/package.json +1 -1
  33. package/src/FaableDeployApi.test.ts +0 -13
  34. package/src/FaableDeployApi.ts +0 -40
  35. package/src/api/types.d.ts +0 -2021
  36. package/src/auth/apikey.ts +0 -11
  37. package/src/fetcher/Fetcher.ts +0 -42
  38. package/src/fetcher/fetcher_axios.ts +0 -50
  39. package/src/helpers/authorize-client-credentials.ts +0 -54
  40. package/src/helpers/authorize.ts +0 -58
  41. package/src/helpers/error_handler.ts +0 -7
  42. package/src/helpers/paginator.ts +0 -37
  43. package/src/index.ts +0 -1
  44. package/tsconfig.json +0 -16
@@ -14,6 +14,7 @@ jobs:
14
14
  cache: npm
15
15
  node-version: lts/*
16
16
  - run: npm ci
17
+ - run: npm run build
17
18
  - run: npm run release
18
19
  env:
19
20
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,60 @@
1
+ import { Page } from "./helpers/paginator.js";
2
+ import { FetcherCreateParams } from "./fetcher/Fetcher.js";
3
+ type ApiParams = {
4
+ fetcher?: FetcherCreateParams;
5
+ auth?: FetcherCreateParams;
6
+ };
7
+ export declare class FaableDeployApi {
8
+ private fetcher;
9
+ private paginator;
10
+ constructor(params?: ApiParams);
11
+ getDeployment(id: string): Promise<{
12
+ id: string;
13
+ app_id: string;
14
+ image: string;
15
+ status: import("./api/types.js").components["schemas"]["DeploymentStatus"];
16
+ user: string | null;
17
+ createdAt: string;
18
+ }>;
19
+ getApp(id: string): Promise<{
20
+ id: string;
21
+ profile?: {
22
+ id: string;
23
+ slug: string;
24
+ name?: string;
25
+ description: string;
26
+ is_team: boolean;
27
+ owner_id: string;
28
+ stripe_sub?: string | null;
29
+ createdAt: string;
30
+ } | string | unknown;
31
+ team: string;
32
+ name: string;
33
+ description: string;
34
+ slug: string;
35
+ url: string;
36
+ active: boolean;
37
+ runtime: import("./api/types.js").components["schemas"]["AppRuntime"];
38
+ runtime_strategy: ("next" | "wordpress") | null;
39
+ instance_type: string;
40
+ region: string;
41
+ creator: string;
42
+ metadata: {
43
+ [key: string]: unknown;
44
+ };
45
+ status: import("./api/types.js").components["schemas"]["AppStatus"];
46
+ createdAt: string;
47
+ }>;
48
+ listApps(): {
49
+ all: () => Promise<unknown[]>;
50
+ first: () => Promise<Page<unknown>>;
51
+ pass: (params?: {
52
+ cursor?: string;
53
+ pageSize?: string;
54
+ }) => Promise<Page<unknown>>;
55
+ };
56
+ updateStatus<T>(id: string, data: T): Promise<unknown>;
57
+ }
58
+ export declare const faableapi: (params?: ApiParams) => FaableDeployApi;
59
+ export {};
60
+ //# sourceMappingURL=FaableDeployApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FaableDeployApi.d.ts","sourceRoot":"","sources":["../src/FaableDeployApi.ts"],"names":[],"mappings":"AACA,OAAO,EAA6B,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAEzE,OAAO,EAAW,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEpE,KAAK,SAAS,GAAG;IACf,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,IAAI,CAAC,EAAE,mBAAmB,CAAC;CAC5B,CAAC;AAEF,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,SAAS,CAAY;gBAEjB,MAAM,GAAE,SAAc;IASlC,aAAa,CAAC,EAAE,EAAE,MAAM;;;;gBAiBmx1B,8CAAsB;;;;IAdj01B,MAAM,CAAC,EAAE,EAAE,MAAM;;;;;gBAc6smB,CAAC;;;;sBAA6I,CAAC;;;;;;;;;iBAAyU,8CAAsB;;;;;;;;gBAAyf,8CAAsB;;;IAX3toB,QAAQ;;;;;;;;IAGR,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;CAGpC;AAED,eAAO,MAAM,SAAS,YAAY,SAAS,oBAE1C,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { buildPaginator } from "./helpers/paginator.js";
2
+ import { fetcher_axios } from "./fetcher/fetcher_axios.js";
3
+ export class FaableDeployApi {
4
+ fetcher;
5
+ paginator;
6
+ constructor(params = {}) {
7
+ this.fetcher = fetcher_axios({
8
+ baseURL: "https://api.faable.com",
9
+ ...params.fetcher,
10
+ ...params.auth,
11
+ });
12
+ this.paginator = buildPaginator(this.fetcher);
13
+ }
14
+ getDeployment(id) {
15
+ return this.fetcher.get(`/deployment/${id}`);
16
+ }
17
+ getApp(id) {
18
+ return this.fetcher.get(`/app/${id}`);
19
+ }
20
+ listApps() {
21
+ return this.paginator({ url: "/app" });
22
+ }
23
+ updateStatus(id, data) {
24
+ return this.fetcher.post(`/status/${id}`, data);
25
+ }
26
+ }
27
+ export const faableapi = (params = {}) => {
28
+ return new FaableDeployApi(params);
29
+ };
@@ -1,5 +1,4 @@
1
1
  import { components } from "./types.js";
2
-
3
2
  export type App = components["schemas"]["App"];
4
3
  export type AppStatus = components["schemas"]["AppStatus"];
5
4
  export type AppRuntime = components["schemas"]["AppRuntime"];
@@ -8,25 +7,16 @@ export type Deployment = components["schemas"]["Deployment"];
8
7
  export type DeploymentStatus = components["schemas"]["DeploymentStatus"];
9
8
  export type Secret = components["schemas"]["Secret"];
10
9
  export type Domain = components["schemas"]["Domain"];
11
-
12
10
  export type Volume = components["schemas"]["Volume"];
13
-
14
- export type EventSecretsCreateBatchEvent =
15
- components["schemas"]["Event_secret.create_batch"];
16
- export type EventDeploymentCreated =
17
- components["schemas"]["Event_deployment.created"];
11
+ export type EventSecretsCreateBatchEvent = components["schemas"]["Event_secret.create_batch"];
12
+ export type EventDeploymentCreated = components["schemas"]["Event_deployment.created"];
18
13
  export type EventAppDelete = components["schemas"]["Event_app.delete"];
19
14
  export type EventAppCreate = components["schemas"]["Event_app.create"];
20
15
  export type EventAppUpdate = components["schemas"]["Event_app.update"];
21
-
22
16
  export type EventDomainCreate = components["schemas"]["Event_domain.create"];
23
17
  export type EventDomainUpdate = components["schemas"]["Event_domain.update"];
24
-
25
18
  export type EventVolumeCreate = components["schemas"]["Event_volume.create"];
26
19
  export type EventVolumeDelete = components["schemas"]["Event_volume.delete"];
27
-
28
- export type EventSecretsUpdated =
29
- components["schemas"]["Event_secret.create_batch"];
30
-
31
- export type EventDeploymentStatusUpdate =
32
- components["schemas"]["Event_deployment.update_status"];
20
+ export type EventSecretsUpdated = components["schemas"]["Event_secret.create_batch"];
21
+ export type EventDeploymentStatusUpdate = components["schemas"]["Event_deployment.update_status"];
22
+ //# sourceMappingURL=api-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-types.d.ts","sourceRoot":"","sources":["../../src/api/api-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;AAC/C,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,CAAC;AAC3D,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,CAAC;AAC7D,MAAM,MAAM,kBAAkB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,oBAAoB,CAAC,CAAC;AAC7E,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,CAAC;AAC7D,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC;AACzE,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC;AACrD,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC;AAErD,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC;AAErD,MAAM,MAAM,4BAA4B,GACtC,UAAU,CAAC,SAAS,CAAC,CAAC,2BAA2B,CAAC,CAAC;AACrD,MAAM,MAAM,sBAAsB,GAChC,UAAU,CAAC,SAAS,CAAC,CAAC,0BAA0B,CAAC,CAAC;AACpD,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC;AACvE,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC;AACvE,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC;AAEvE,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,qBAAqB,CAAC,CAAC;AAC7E,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,qBAAqB,CAAC,CAAC;AAE7E,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,qBAAqB,CAAC,CAAC;AAC7E,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,qBAAqB,CAAC,CAAC;AAE7E,MAAM,MAAM,mBAAmB,GAC7B,UAAU,CAAC,SAAS,CAAC,CAAC,2BAA2B,CAAC,CAAC;AAErD,MAAM,MAAM,2BAA2B,GACrC,UAAU,CAAC,SAAS,CAAC,CAAC,gCAAgC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { FetcherCreateParams } from "../fetcher/Fetcher.js";
2
+ export declare const createApikeyAuth: (apikey?: string) => FetcherCreateParams;
3
+ //# sourceMappingURL=apikey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apikey.d.ts","sourceRoot":"","sources":["../../src/auth/apikey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,eAAO,MAAM,gBAAgB,YACnB,MAAM,KACb,mBAMF,CAAC"}
@@ -0,0 +1,7 @@
1
+ export const createApikeyAuth = (apikey = process.env.FAABLE_APIKEY || "") => {
2
+ return {
3
+ headers: {
4
+ authorization: `basic ${btoa(`${apikey}:${apikey}`)}`,
5
+ },
6
+ };
7
+ };
@@ -0,0 +1,21 @@
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
+ baseURL?: string;
12
+ headers?: Headers;
13
+ };
14
+ export type Fetcher = {
15
+ get: <T>(url: string) => Promise<T>;
16
+ post: <T>(url: string, data: any) => Promise<T>;
17
+ request: <T>(params: FetcherRequestParams) => Promise<T>;
18
+ check: <T>(url: string, status?: number) => Promise<boolean>;
19
+ };
20
+ export {};
21
+ //# sourceMappingURL=Fetcher.d.ts.map
@@ -0,0 +1 @@
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,MAAM,CAAC;IACjB,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"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { Fetcher, FetcherCreateParams } from "./Fetcher.js";
2
+ export declare const fetcher_axios: (params?: FetcherCreateParams) => Fetcher;
3
+ //# sourceMappingURL=fetcher_axios.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetcher_axios.d.ts","sourceRoot":"","sources":["../../src/fetcher/fetcher_axios.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAS5D,eAAO,MAAM,aAAa,YAAY,mBAAmB,KAAQ,OAqChE,CAAC"}
@@ -0,0 +1,43 @@
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(params);
9
+ // Add base interceptor
10
+ instance.interceptors.response.use((res) => {
11
+ //console.log(`Request ${res.config.url}`);
12
+ return res;
13
+ }, handleErrorInterceptor);
14
+ return {
15
+ get: async (url) => {
16
+ const res = await instance.request({
17
+ method: "GET",
18
+ url,
19
+ });
20
+ return res.data;
21
+ },
22
+ post: async (url, data) => {
23
+ const res = await instance.request({
24
+ method: "GET",
25
+ url,
26
+ data,
27
+ });
28
+ return res.data;
29
+ },
30
+ request: async (params) => {
31
+ const res = await instance.request(params);
32
+ return res.data;
33
+ },
34
+ check: async (url) => {
35
+ const res = await instance.request({
36
+ method: "GET",
37
+ url,
38
+ validateStatus: () => true,
39
+ });
40
+ return res.status == 200;
41
+ },
42
+ };
43
+ };
@@ -0,0 +1,17 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,38 @@
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
+ }
@@ -0,0 +1,9 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,39 @@
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
+ };
@@ -0,0 +1,4 @@
1
+ export declare class FaableApiError extends Error {
2
+ constructor(msg: string);
3
+ }
4
+ //# sourceMappingURL=error_handler.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,7 @@
1
+ export class FaableApiError extends Error {
2
+ constructor(msg) {
3
+ super(msg);
4
+ this.name = "FaableApiError";
5
+ Object.setPrototypeOf(this, FaableApiError.prototype);
6
+ }
7
+ }
@@ -0,0 +1,15 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,28 @@
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
+ };
@@ -0,0 +1,5 @@
1
+ export * from "./FaableDeployApi.js";
2
+ import * as auth from "./auth/apikey.js";
3
+ import * as types from "./api/api-types.js";
4
+ export { types, auth };
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AACzC,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./FaableDeployApi.js";
2
+ import * as auth from "./auth/apikey.js";
3
+ import * as types from "./api/api-types.js";
4
+ export { types, auth };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faable/deploy-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "author": "Marc Pomar <marc@faable.com>",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,13 +0,0 @@
1
- import test from "ava";
2
- import { faableapi } from "./FaableDeployApi.js";
3
- import { createApikeyAuth } from "./auth/apikey.js";
4
-
5
- test("instance", async (t) => {
6
- const auth = createApikeyAuth();
7
- const api = faableapi({
8
- auth,
9
- });
10
- const app = await api.getApp("app_64f312b7347d780011861a0f");
11
- console.log(app);
12
- t.pass();
13
- });
@@ -1,40 +0,0 @@
1
- import { Deployment, App } from "./api/api-types.js";
2
- import { buildPaginator, Paginator, Page } from "./helpers/paginator.js";
3
- import { fetcher_axios } from "./fetcher/fetcher_axios.js";
4
- import { Fetcher, FetcherCreateParams } from "./fetcher/Fetcher.js";
5
-
6
- type ApiParams = {
7
- fetcher?: FetcherCreateParams;
8
- auth?: FetcherCreateParams;
9
- };
10
-
11
- export class FaableDeployApi {
12
- private fetcher: Fetcher;
13
- private paginator: Paginator;
14
-
15
- constructor(params: ApiParams = {}) {
16
- this.fetcher = fetcher_axios({
17
- baseURL: "https://api.faable.com",
18
- ...params.fetcher,
19
- ...params.auth,
20
- });
21
- this.paginator = buildPaginator(this.fetcher);
22
- }
23
-
24
- getDeployment(id: string) {
25
- return this.fetcher.get<Deployment>(`/deployment/${id}`);
26
- }
27
- getApp(id: string) {
28
- return this.fetcher.get<App>(`/app/${id}`);
29
- }
30
- listApps() {
31
- return this.paginator({ url: "/app" });
32
- }
33
- updateStatus<T>(id: string, data: T) {
34
- return this.fetcher.post(`/status/${id}`, data);
35
- }
36
- }
37
-
38
- export const faableapi = (params: ApiParams = {}) => {
39
- return new FaableDeployApi(params);
40
- };