@faable/sdk-base 1.0.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/.github/workflows/release.yml +21 -0
- package/README.md +20 -0
- package/ava.config.cjs +7 -0
- package/dist/FaableApi.d.ts +16 -0
- package/dist/FaableApi.d.ts.map +1 -0
- package/dist/FaableApi.js +14 -0
- package/dist/auth/apikey.d.ts +4 -0
- package/dist/auth/apikey.d.ts.map +1 -0
- package/dist/auth/apikey.js +16 -0
- package/dist/auth/client_credentials/client_credentials.d.ts +14 -0
- package/dist/auth/client_credentials/client_credentials.d.ts.map +1 -0
- package/dist/auth/client_credentials/client_credentials.js +73 -0
- package/dist/auth/client_credentials/store.d.ts +8 -0
- package/dist/auth/client_credentials/store.d.ts.map +1 -0
- package/dist/auth/client_credentials/store.js +15 -0
- package/dist/fetcher/Fetcher.d.ts +20 -0
- package/dist/fetcher/Fetcher.d.ts.map +1 -0
- package/dist/fetcher/Fetcher.js +1 -0
- package/dist/fetcher/fetcher_axios.d.ts +4 -0
- package/dist/fetcher/fetcher_axios.d.ts.map +1 -0
- package/dist/fetcher/fetcher_axios.js +53 -0
- package/dist/helpers/error_handler.d.ts +4 -0
- package/dist/helpers/error_handler.d.ts.map +1 -0
- package/dist/helpers/error_handler.js +7 -0
- package/dist/helpers/paginator.d.ts +15 -0
- package/dist/helpers/paginator.d.ts.map +1 -0
- package/dist/helpers/paginator.js +28 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/types/AuthInterface.d.ts +5 -0
- package/dist/types/AuthInterface.d.ts.map +1 -0
- package/dist/types/AuthInterface.js +1 -0
- package/dist/types/StrategyInterface.d.ts +5 -0
- package/dist/types/StrategyInterface.d.ts.map +1 -0
- package/dist/types/StrategyInterface.js +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
"on":
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- main
|
|
6
|
+
jobs:
|
|
7
|
+
release:
|
|
8
|
+
name: release
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
- uses: actions/setup-node@v3
|
|
13
|
+
with:
|
|
14
|
+
cache: npm
|
|
15
|
+
node-version: lts/*
|
|
16
|
+
- run: npm ci
|
|
17
|
+
- run: npm run build
|
|
18
|
+
- run: npm run release
|
|
19
|
+
env:
|
|
20
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
21
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Faable Deploy SDK
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://faable.com">
|
|
5
|
+
<h1 align="center">SDK Builder base code</h1>
|
|
6
|
+
</a>
|
|
7
|
+
<p align="center">Build SDK Clients for Faable APIs</p>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
<a aria-label="NPM version" href="https://www.npmjs.com/package/@faable/sdk-generic">
|
|
12
|
+
<img alt="" src="https://img.shields.io/npm/v/@faable/sdk-generic.svg?style=for-the-badge&labelColor=000000">
|
|
13
|
+
</a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @faable/sdk-generic
|
|
20
|
+
```
|
package/ava.config.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AuthInterface } from "./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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FaableApi.d.ts","sourceRoot":"","sources":["../src/FaableApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEpE,OAAO,EAAkB,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnE,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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apikey.d.ts","sourceRoot":"","sources":["../../src/auth/apikey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAGlE,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEzD,eAAO,MAAM,gBAAgB,EAAE,iBAAiB,CAAC,gBAAgB,CAoBhE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { StrategyInterface } from "../../types/StrategyInterface.js";
|
|
2
|
+
type Params = {
|
|
3
|
+
client_id: string;
|
|
4
|
+
client_secret: string;
|
|
5
|
+
domain: string;
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type ClientCredentialsAuthParams = Partial<[Partial<Params>]>;
|
|
9
|
+
export interface ClientCredentialsResponse {
|
|
10
|
+
access_token: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const createClientCredentials: StrategyInterface<ClientCredentialsAuthParams>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=client_credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client_credentials.d.ts","sourceRoot":"","sources":["../../../src/auth/client_credentials/client_credentials.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAKrE,KAAK,MAAM,GAAG;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAMrE,MAAM,WAAW,yBAAyB;IACxC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,uBAAuB,EAAE,iBAAiB,CACrD,2BAA2B,CAyF5B,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { fetcher_axios } from "../../fetcher/fetcher_axios.js";
|
|
2
|
+
import { jwtDecode } from "jwt-decode";
|
|
3
|
+
import { createTokenStore } from "./store.js";
|
|
4
|
+
import PQueue from "p-queue";
|
|
5
|
+
const CLIENT_ID_ENV = "FAABLEAUTH_CLIENT_ID";
|
|
6
|
+
const CLIENT_SECRET_ENV = "FAABLEAUTH_CLIENT_SECRET";
|
|
7
|
+
const AUTH_DOMAIN = "FAABLEAUTH_DOMAIN";
|
|
8
|
+
export const createClientCredentials = (params) => {
|
|
9
|
+
const client_id = params?.client_id || process.env[CLIENT_ID_ENV];
|
|
10
|
+
const client_secret = params?.client_secret || process.env[CLIENT_SECRET_ENV];
|
|
11
|
+
const auth_domain = params?.domain || process.env[AUTH_DOMAIN];
|
|
12
|
+
const debug = params?.debug;
|
|
13
|
+
if (!client_id) {
|
|
14
|
+
throw new Error(`No client_id set in createClientCredentials. Use ${CLIENT_ID_ENV} environment variable`);
|
|
15
|
+
}
|
|
16
|
+
if (!client_secret) {
|
|
17
|
+
throw new Error(`No client_secret set in createClientCredentials. Use ${CLIENT_SECRET_ENV} environment variable`);
|
|
18
|
+
}
|
|
19
|
+
if (!auth_domain) {
|
|
20
|
+
throw new Error(`No domain set in createClientCredentials. Use ${AUTH_DOMAIN} environment variable`);
|
|
21
|
+
}
|
|
22
|
+
const store = createTokenStore();
|
|
23
|
+
const queue = new PQueue({ concurrency: 1, timeout: 20 * 1000 });
|
|
24
|
+
const isTokenExpired = (token) => {
|
|
25
|
+
const { access_token } = token;
|
|
26
|
+
let { exp } = jwtDecode(access_token);
|
|
27
|
+
if (!exp) {
|
|
28
|
+
throw new Error("Missing expire date");
|
|
29
|
+
}
|
|
30
|
+
const currentSeconds = new Date().getTime() / 1000;
|
|
31
|
+
return currentSeconds > exp;
|
|
32
|
+
};
|
|
33
|
+
const fetcher = fetcher_axios({
|
|
34
|
+
baseURL: auth_domain,
|
|
35
|
+
});
|
|
36
|
+
const requestToken = async () => {
|
|
37
|
+
const params = new URLSearchParams();
|
|
38
|
+
params.append("grant_type", "client_credentials");
|
|
39
|
+
params.append("client_id", client_id);
|
|
40
|
+
params.append("client_secret", client_secret);
|
|
41
|
+
const token_response = await fetcher.post("/oauth/token", params);
|
|
42
|
+
// Save token in store
|
|
43
|
+
store.saveToken(token_response);
|
|
44
|
+
return token_response;
|
|
45
|
+
};
|
|
46
|
+
const getToken = async () => {
|
|
47
|
+
let token = store.getToken();
|
|
48
|
+
// We don't have a token or it's expired
|
|
49
|
+
if (!token || isTokenExpired(token)) {
|
|
50
|
+
token = await requestToken();
|
|
51
|
+
}
|
|
52
|
+
return token;
|
|
53
|
+
};
|
|
54
|
+
const getTokenWithLimits = async () => {
|
|
55
|
+
const token = await queue.add(() => getToken());
|
|
56
|
+
if (!token) {
|
|
57
|
+
throw new Error("Cannot get a token from auth service");
|
|
58
|
+
}
|
|
59
|
+
return token;
|
|
60
|
+
};
|
|
61
|
+
const auth = async () => {
|
|
62
|
+
const key = `token-${Math.floor(Math.random() * 1000).toFixed(0)}`;
|
|
63
|
+
debug && console.time(key);
|
|
64
|
+
let token = await getTokenWithLimits();
|
|
65
|
+
debug && console.timeLog(key, "completed token fetch");
|
|
66
|
+
return {
|
|
67
|
+
headers: {
|
|
68
|
+
authorization: `Bearer ${token.access_token}`,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
return Object.assign(auth, { hook: auth });
|
|
73
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface ClientCredentialsResponse {
|
|
2
|
+
access_token: string;
|
|
3
|
+
}
|
|
4
|
+
export declare const createTokenStore: () => {
|
|
5
|
+
saveToken: (token: ClientCredentialsResponse) => ClientCredentialsResponse;
|
|
6
|
+
getToken: () => ClientCredentialsResponse | null;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/auth/client_credentials/store.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,yBAAyB;IACxC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,gBAAgB;uBAMD,yBAAyB;;CASpD,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const createTokenStore = () => {
|
|
2
|
+
let _stored_token;
|
|
3
|
+
const getToken = () => {
|
|
4
|
+
return _stored_token;
|
|
5
|
+
};
|
|
6
|
+
const saveToken = (token) => {
|
|
7
|
+
_stored_token = token;
|
|
8
|
+
console.log(`[SDK] Token stored successfully`);
|
|
9
|
+
return _stored_token;
|
|
10
|
+
};
|
|
11
|
+
return {
|
|
12
|
+
saveToken,
|
|
13
|
+
getToken,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
|
@@ -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,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 @@
|
|
|
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,iBAAiB,CAAC;AAS5C,eAAO,MAAM,aAAa,YAAY,SAAS,KAAQ,OAiDtD,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
};
|
|
@@ -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,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
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./FaableApi.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthInterface.d.ts","sourceRoot":"","sources":["../../src/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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AuthInterface } from "./AuthInterface.js";
|
|
2
|
+
export interface StrategyInterface<StrategyOptions extends any[], AuthOptions extends any[] = any, Authentication extends any = any> {
|
|
3
|
+
(...args: StrategyOptions): AuthInterface<AuthOptions, Authentication>;
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=StrategyInterface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StrategyInterface.d.ts","sourceRoot":"","sources":["../../src/types/StrategyInterface.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,MAAM,WAAW,iBAAiB,CAChC,eAAe,SAAS,GAAG,EAAE,EAC7B,WAAW,SAAS,GAAG,EAAE,GAAG,GAAG,EAC/B,cAAc,SAAS,GAAG,GAAG,GAAG;IAEhC,CAAC,GAAG,IAAI,EAAE,eAAe,GAAG,aAAa,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;CACxE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@faable/sdk-base",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"author": "Marc Pomar <marc@faable.com>",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"axios": "^1.7.7",
|
|
14
|
+
"jwt-decode": "^4.0.0",
|
|
15
|
+
"p-queue": "^8.0.1",
|
|
16
|
+
"ramda": "^0.30.1"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@septh/ts-run": "^1.3.0",
|
|
20
|
+
"@types/node": "^22.5.5",
|
|
21
|
+
"@types/ramda": "^0.30.2",
|
|
22
|
+
"ava": "^6.1.3",
|
|
23
|
+
"dotenv": "^16.4.5",
|
|
24
|
+
"openapi-typescript": "^7.4.0",
|
|
25
|
+
"rimraf": "^6.0.1",
|
|
26
|
+
"semantic-release": "^24.1.1",
|
|
27
|
+
"tsimp": "^2.0.11",
|
|
28
|
+
"tsx": "^4.19.1",
|
|
29
|
+
"typescript": "^5.6.2"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"generate-types": "openapi-typescript https://api.faable.com/docs/json -o src/api/types.ts",
|
|
33
|
+
"prebuild": "rimraf dist",
|
|
34
|
+
"build": "tsc",
|
|
35
|
+
"test": "ava",
|
|
36
|
+
"release": "semantic-release"
|
|
37
|
+
},
|
|
38
|
+
"release": {
|
|
39
|
+
"branches": [
|
|
40
|
+
"main"
|
|
41
|
+
],
|
|
42
|
+
"plugins": [
|
|
43
|
+
"@semantic-release/release-notes-generator",
|
|
44
|
+
"@semantic-release/github",
|
|
45
|
+
[
|
|
46
|
+
"@semantic-release/npm"
|
|
47
|
+
]
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
}
|