@cycleplatform/api-client-typescript 0.1.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.
- package/LICENSE +201 -0
- package/README.md +80 -0
- package/dist/index.mjs +87 -0
- package/dist/index.umd.js +1 -0
- package/package.json +40 -0
- package/src/generated/types.ts +13105 -0
- package/src/index.ts +36 -0
- package/tsconfig.json +26 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import createClient from "openapi-fetch";
|
|
2
|
+
import type { paths } from "./generated/types";
|
|
3
|
+
|
|
4
|
+
let authToken: string | undefined = undefined;
|
|
5
|
+
let hubScope: string | undefined = undefined;
|
|
6
|
+
let baseUrl = "https://api.cycle.io";
|
|
7
|
+
|
|
8
|
+
export function setAuthToken(token: string | undefined) {
|
|
9
|
+
authToken = token;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function setHubScope(hubId: string | undefined) {
|
|
13
|
+
hubScope = hubId;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function setBaseUrl(url: string) {
|
|
17
|
+
baseUrl = url;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const baseClient = createClient<paths>();
|
|
21
|
+
export const client = new Proxy(baseClient, {
|
|
22
|
+
get(_, key: keyof typeof baseClient) {
|
|
23
|
+
const headers: HeadersInit = {};
|
|
24
|
+
if (authToken) {
|
|
25
|
+
headers["Authorization"] = `Bearer ${authToken}`;
|
|
26
|
+
}
|
|
27
|
+
if (hubScope) {
|
|
28
|
+
headers["X-Hub-Id"] = hubScope;
|
|
29
|
+
}
|
|
30
|
+
const newClient = createClient<paths>({
|
|
31
|
+
headers,
|
|
32
|
+
baseUrl,
|
|
33
|
+
});
|
|
34
|
+
return newClient[key];
|
|
35
|
+
},
|
|
36
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"display": "Default",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"composite": false,
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"lib": [
|
|
10
|
+
"ES2023",
|
|
11
|
+
"DOM"
|
|
12
|
+
],
|
|
13
|
+
"inlineSources": false,
|
|
14
|
+
"isolatedModules": true,
|
|
15
|
+
"moduleResolution": "node",
|
|
16
|
+
"noUnusedLocals": true,
|
|
17
|
+
"noUnusedParameters": true,
|
|
18
|
+
"preserveWatchOutput": true,
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
"strict": true
|
|
21
|
+
},
|
|
22
|
+
"include": ["./src"],
|
|
23
|
+
"exclude": [
|
|
24
|
+
"node_modules"
|
|
25
|
+
]
|
|
26
|
+
}
|