@faable/deploy-sdk 1.0.4 → 1.0.6

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.
@@ -1,12 +1,5 @@
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;
1
+ import { FaableApi, ApiParams } from "@faable/sdk-base";
2
+ export declare class DeployApi extends FaableApi {
10
3
  constructor(params?: ApiParams);
11
4
  getDeployment(id: string): Promise<{
12
5
  id: string;
@@ -47,14 +40,12 @@ export declare class FaableDeployApi {
47
40
  }>;
48
41
  listApps(): {
49
42
  all: () => Promise<unknown[]>;
50
- first: () => Promise<Page<unknown>>;
43
+ first: () => Promise<import("@faable/sdk-base/dist/helpers/paginator.js").Page<unknown>>;
51
44
  pass: (params?: {
52
45
  cursor?: string;
53
46
  pageSize?: string;
54
- }) => Promise<Page<unknown>>;
47
+ }) => Promise<import("@faable/sdk-base/dist/helpers/paginator.js").Page<unknown>>;
55
48
  };
56
49
  updateStatus<T>(id: string, data: T): Promise<unknown>;
57
50
  }
58
- export declare const faableapi: (params?: ApiParams) => FaableDeployApi;
59
- export {};
60
51
  //# sourceMappingURL=FaableDeployApi.d.ts.map
@@ -1 +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"}
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;;;;gBAayv2B,8CAAsB;;;;IAVvy2B,MAAM,CAAC,EAAE,EAAE,MAAM;;;;;gBAUmrnB,CAAC;;;;sBAA6I,CAAC;;;;;;;;;iBAAyU,8CAAsB;;;;;;;;gBAAyf,8CAAsB;;;IAPjspB,QAAQ;;;;kBAFN,CAAC;oBAA0B,CAAC;;;IAK9B,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;CAGpC"}
@@ -1,15 +1,10 @@
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({
1
+ import { FaableApi } from "@faable/sdk-base";
2
+ export class DeployApi extends FaableApi {
3
+ constructor(params) {
4
+ super({
5
+ ...params,
8
6
  baseURL: "https://api.faable.com",
9
- ...params.fetcher,
10
- ...params.auth,
11
7
  });
12
- this.paginator = buildPaginator(this.fetcher);
13
8
  }
14
9
  getDeployment(id) {
15
10
  return this.fetcher.get(`/deployment/${id}`);
@@ -24,6 +19,3 @@ export class FaableDeployApi {
24
19
  return this.fetcher.post(`/status/${id}`, data);
25
20
  }
26
21
  }
27
- export const faableapi = (params = {}) => {
28
- return new FaableDeployApi(params);
29
- };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from "./FaableDeployApi.js";
2
- import * as auth from "./auth/apikey.js";
3
2
  import * as types from "./api/api-types.js";
4
- export { types, auth };
3
+ export { types };
5
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
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
@@ -1,4 +1,3 @@
1
1
  export * from "./FaableDeployApi.js";
2
- import * as auth from "./auth/apikey.js";
3
2
  import * as types from "./api/api-types.js";
4
- export { types, auth };
3
+ export { types };
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@faable/deploy-sdk",
3
- "version": "1.0.4",
3
+ "description": "Codebase for SDK building",
4
+ "version": "1.0.6",
4
5
  "author": "Marc Pomar <marc@faable.com>",
5
6
  "main": "dist/index.js",
6
7
  "types": "dist/index.d.ts",
@@ -10,12 +11,12 @@
10
11
  "access": "public"
11
12
  },
12
13
  "dependencies": {
13
- "axios": "^1.7.7",
14
- "jwt-decode": "^4.0.0"
14
+ "@faable/sdk-base": "^1.0.10"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@septh/ts-run": "^1.3.0",
18
18
  "@types/node": "^22.5.5",
19
+ "@types/ramda": "^0.30.2",
19
20
  "ava": "^6.1.3",
20
21
  "dotenv": "^16.4.5",
21
22
  "openapi-typescript": "^7.4.0",
@@ -1,3 +0,0 @@
1
- import { FetcherCreateParams } from "../fetcher/Fetcher.js";
2
- export declare const createApikeyAuth: (apikey?: string) => FetcherCreateParams;
3
- //# sourceMappingURL=apikey.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,7 +0,0 @@
1
- export const createApikeyAuth = (apikey = process.env.FAABLE_APIKEY || "") => {
2
- return {
3
- headers: {
4
- authorization: `basic ${btoa(`${apikey}:${apikey}`)}`,
5
- },
6
- };
7
- };
@@ -1,21 +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
- 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
@@ -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,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"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import { Fetcher, FetcherCreateParams } from "./Fetcher.js";
2
- export declare const fetcher_axios: (params?: FetcherCreateParams) => Fetcher;
3
- //# sourceMappingURL=fetcher_axios.d.ts.map
@@ -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,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAS5D,eAAO,MAAM,aAAa,YAAY,mBAAmB,KAAQ,OAqChE,CAAC"}
@@ -1,43 +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(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: "POST",
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
- };
@@ -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,4 +0,0 @@
1
- export declare class FaableApiError extends Error {
2
- constructor(msg: string);
3
- }
4
- //# sourceMappingURL=error_handler.d.ts.map
@@ -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,7 +0,0 @@
1
- export class FaableApiError extends Error {
2
- constructor(msg) {
3
- super(msg);
4
- this.name = "FaableApiError";
5
- Object.setPrototypeOf(this, FaableApiError.prototype);
6
- }
7
- }
@@ -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
- };