|
1 | 1 | import { ConductorClientWithAuth } from "./ConductorClientWithAuth"; |
2 | | -import { OrkesHttpRequest } from "./request/OrkesHttpRequest"; |
3 | | -import { HttpRequestConstructor, OrkesApiConfig } from "./types"; |
4 | | - |
5 | | -const REFRESH_TOKEN_IN_MILLISECONDS = 30 * 60 * 1000; |
| 2 | +import { resolveFetchFn, resolveOrkesConfig } from "./helpers"; |
| 3 | +import { createOrkesHttpRequest } from "./request/createOrkesHttpRequest"; |
| 4 | +import type { FetchFn, OrkesApiConfig } from "./types"; |
| 5 | +import { REFRESH_TOKEN_IN_MILLISECONDS } from "./constants"; |
6 | 6 |
|
7 | 7 | /** |
8 | 8 | * Takes a config with keyId and keySecret returns a promise with an instance of ConductorClient |
9 | 9 | * |
10 | 10 | * @param config (optional) OrkesApiConfig with keyId and keySecret |
11 | | - * @param HttpRequest (optional) Custom request class, could be used to pass in a custom fetch function |
| 11 | + * @param customFetch (optional) custom fetch function |
12 | 12 | * @returns |
13 | 13 | */ |
14 | 14 | export const orkesConductorClient = async ( |
15 | 15 | config?: Partial<OrkesApiConfig>, |
16 | | - HttpRequest: HttpRequestConstructor = OrkesHttpRequest |
| 16 | + customFetch?: FetchFn |
17 | 17 | ) => { |
18 | | - const serverUrl = process.env.CONDUCTOR_SERVER_URL || config?.serverUrl; |
| 18 | + const { serverUrl, keyId, keySecret } = resolveOrkesConfig(config); |
19 | 19 |
|
20 | 20 | if (!serverUrl) throw new Error("Conductor server URL is not set"); |
21 | 21 |
|
22 | | - const keyId = process.env.CONDUCTOR_AUTH_KEY || config?.keyId; |
23 | | - const keySecret = process.env.CONDUCTOR_AUTH_SECRET || config?.keySecret; |
24 | | - |
25 | 22 | const conductorClientWithAuth = new ConductorClientWithAuth( |
26 | 23 | { ...config, BASE: serverUrl }, |
27 | | - HttpRequest |
| 24 | + createOrkesHttpRequest(resolveFetchFn(customFetch)) |
28 | 25 | ); |
29 | 26 |
|
30 | 27 | if (keyId && keySecret) { |
|
0 commit comments