-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathOrkesConductorClient.ts
More file actions
47 lines (42 loc) · 1.38 KB
/
OrkesConductorClient.ts
File metadata and controls
47 lines (42 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import {
handleAuth,
resolveFetchFn,
resolveOrkesConfig,
wrapFetchWithRetry,
} from "./helpers";
import type { OrkesApiConfig } from "./types";
import { createClient } from "../common/open-api/client";
import { addResourcesBackwardCompatibility } from "./helpers/addResourcesBackwardCompatibility";
/**
* Takes a config with keyId and keySecret returns a promise with an instance of Client
*
* @param config (optional) OrkesApiConfig with keyId and keySecret
* @param customFetch (optional) custom fetch function
* @param requestHandler DEPRECATED! (optional) ConductorHttpRequest handler, replaced with customFetch
* @returns Client
*/
export const orkesConductorClient = async (
config?: OrkesApiConfig,
customFetch?: typeof fetch
) => {
const {
serverUrl,
keyId,
keySecret,
maxHttp2Connections,
refreshTokenInterval,
} = resolveOrkesConfig(config);
if (!serverUrl) throw new Error("Conductor server URL is not set");
const openApiClient = createClient({
baseUrl: serverUrl,
fetch: wrapFetchWithRetry(
await resolveFetchFn(customFetch, maxHttp2Connections)
),
throwOnError: true,
});
if (keyId && keySecret) {
await handleAuth(openApiClient, keyId, keySecret, refreshTokenInterval);
}
// DEPRECATED, should be replaced with return openApiClient after April 2026:
return addResourcesBackwardCompatibility(openApiClient);
};