@automate.ax/client 0.98.0 → 0.99.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/README.md +14 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +18 -4
- package/package.json +2 -2
- package/src/index.ts +60 -17
package/README.md
CHANGED
|
@@ -42,7 +42,19 @@ List procedures return `{ items, pageInfo }`. When `pageInfo.hasMore` is true, p
|
|
|
42
42
|
|
|
43
43
|
The key is organization-owned and is sent in the `x-api-key` header. It does not represent a user session.
|
|
44
44
|
|
|
45
|
-
The client targets `https://automate.ax/api/rpc`.
|
|
45
|
+
The client targets `https://automate.ax/api/rpc`. Embedded and local callers can override `rpcUrl`, provide a custom `fetch`, and add per-request `headers`:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const client = createAutomateClient({
|
|
49
|
+
apiKey: process.env.AUTOMATE_AX_API_KEY!,
|
|
50
|
+
rpcUrl: "https://automate.test/api/rpc",
|
|
51
|
+
headers: () => ({ "x-request-source": "local-test" }),
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Authentication headers are set after additional headers and cannot be overridden through `headers`.
|
|
56
|
+
|
|
57
|
+
Automate.ax action runtimes use the same client with `runtimeToken`. This mode is for the active execution token supplied by the platform; it is not a replacement for an organization API key in external applications.
|
|
46
58
|
|
|
47
59
|
## User session
|
|
48
60
|
|
|
@@ -63,4 +75,4 @@ const manifest = await client.executionData.manifest({
|
|
|
63
75
|
console.log(manifest.consistency, manifest.resources)
|
|
64
76
|
```
|
|
65
77
|
|
|
66
|
-
Credential callbacks are evaluated before every request, so a client can use a refreshed token without being recreated. Supply
|
|
78
|
+
Credential callbacks are evaluated before every request, so a client can use a refreshed token without being recreated. Supply exactly one of `apiKey`, `runtimeToken`, or `sessionToken`.
|
package/dist/index.d.ts
CHANGED
|
@@ -2,15 +2,31 @@ import type { publicContract } from "@automate.ax/api-contract";
|
|
|
2
2
|
import type { ContractRouterClient } from "@orpc/contract";
|
|
3
3
|
export type AutomateClient = ContractRouterClient<typeof publicContract>;
|
|
4
4
|
type ClientCredential = string | (() => Promise<string | null | undefined> | string | null | undefined);
|
|
5
|
-
|
|
5
|
+
type HeaderInput = ConstructorParameters<typeof Headers>[0];
|
|
6
|
+
interface AutomateClientTransportOptions {
|
|
7
|
+
/** Additional request headers merged before authentication headers. */
|
|
8
|
+
headers?: HeaderInput | (() => Promise<HeaderInput> | HeaderInput);
|
|
9
|
+
/** Custom fetch transport, primarily for embedded and local environments. */
|
|
10
|
+
fetch?: (request: Request, init?: RequestInit) => Promise<Response>;
|
|
11
|
+
/** Automate.ax RPC endpoint. Defaults to the production API. */
|
|
12
|
+
rpcUrl?: string | URL;
|
|
13
|
+
}
|
|
14
|
+
export type AutomateClientOptions = AutomateClientTransportOptions & ({
|
|
6
15
|
/** Automate.ax organization API key sent through `x-api-key`. */
|
|
7
16
|
apiKey: ClientCredential;
|
|
17
|
+
runtimeToken?: never;
|
|
8
18
|
sessionToken?: never;
|
|
9
19
|
} | {
|
|
10
20
|
apiKey?: never;
|
|
21
|
+
/** Active Automate.ax execution token sent through `x-api-key`. */
|
|
22
|
+
runtimeToken: ClientCredential;
|
|
23
|
+
sessionToken?: never;
|
|
24
|
+
} | {
|
|
25
|
+
apiKey?: never;
|
|
26
|
+
runtimeToken?: never;
|
|
11
27
|
/** Automate.ax user-session bearer token. */
|
|
12
28
|
sessionToken: ClientCredential;
|
|
13
|
-
};
|
|
29
|
+
});
|
|
14
30
|
/**
|
|
15
31
|
* Creates a type-safe client for the public management API.
|
|
16
32
|
*
|
package/dist/index.js
CHANGED
|
@@ -11,13 +11,27 @@ const RPC_URL = "https://automate.ax/api/rpc";
|
|
|
11
11
|
*/
|
|
12
12
|
export function createAutomateClient(options) {
|
|
13
13
|
return createORPCClient(new RPCLink({
|
|
14
|
-
|
|
14
|
+
fetch: async (request, init) => await (options.fetch ?? globalThis.fetch)(request, {
|
|
15
|
+
...init,
|
|
16
|
+
credentials: "omit",
|
|
17
|
+
}),
|
|
18
|
+
url: options.rpcUrl ?? RPC_URL,
|
|
15
19
|
headers: async () => {
|
|
16
|
-
const headers = new Headers(
|
|
17
|
-
|
|
20
|
+
const headers = new Headers(typeof options.headers === "function"
|
|
21
|
+
? await options.headers()
|
|
22
|
+
: options.headers);
|
|
23
|
+
const usesKey = "apiKey" in options || "runtimeToken" in options;
|
|
24
|
+
const credential = "apiKey" in options
|
|
25
|
+
? options.apiKey
|
|
26
|
+
: "runtimeToken" in options
|
|
27
|
+
? options.runtimeToken
|
|
28
|
+
: options.sessionToken;
|
|
18
29
|
const value = typeof credential === "function" ? await credential() : credential;
|
|
30
|
+
headers.delete("authorization");
|
|
31
|
+
headers.delete("cookie");
|
|
32
|
+
headers.delete("x-api-key");
|
|
19
33
|
if (value) {
|
|
20
|
-
headers.set(
|
|
34
|
+
headers.set(usesKey ? "x-api-key" : "authorization", usesKey ? value : `Bearer ${value}`);
|
|
21
35
|
}
|
|
22
36
|
return headers;
|
|
23
37
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automate.ax/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.99.0",
|
|
4
4
|
"description": "Type-safe client for the Automate.ax API.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@automate.ax/api-contract": "0.
|
|
29
|
+
"@automate.ax/api-contract": "0.99.0",
|
|
30
30
|
"@orpc/client": "1.15.0",
|
|
31
31
|
"@orpc/contract": "1.15.0"
|
|
32
32
|
},
|
package/src/index.ts
CHANGED
|
@@ -12,18 +12,42 @@ type ClientCredential =
|
|
|
12
12
|
| string
|
|
13
13
|
| (() => Promise<string | null | undefined> | string | null | undefined)
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
type HeaderInput = ConstructorParameters<typeof Headers>[0]
|
|
16
|
+
|
|
17
|
+
interface AutomateClientTransportOptions {
|
|
18
|
+
/** Additional request headers merged before authentication headers. */
|
|
19
|
+
headers?: HeaderInput | (() => Promise<HeaderInput> | HeaderInput)
|
|
20
|
+
|
|
21
|
+
/** Custom fetch transport, primarily for embedded and local environments. */
|
|
22
|
+
fetch?: (request: Request, init?: RequestInit) => Promise<Response>
|
|
23
|
+
|
|
24
|
+
/** Automate.ax RPC endpoint. Defaults to the production API. */
|
|
25
|
+
rpcUrl?: string | URL
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type AutomateClientOptions = AutomateClientTransportOptions &
|
|
29
|
+
(
|
|
30
|
+
| {
|
|
31
|
+
/** Automate.ax organization API key sent through `x-api-key`. */
|
|
32
|
+
apiKey: ClientCredential
|
|
33
|
+
runtimeToken?: never
|
|
34
|
+
sessionToken?: never
|
|
35
|
+
}
|
|
36
|
+
| {
|
|
37
|
+
apiKey?: never
|
|
38
|
+
|
|
39
|
+
/** Active Automate.ax execution token sent through `x-api-key`. */
|
|
40
|
+
runtimeToken: ClientCredential
|
|
41
|
+
sessionToken?: never
|
|
42
|
+
}
|
|
43
|
+
| {
|
|
44
|
+
apiKey?: never
|
|
45
|
+
runtimeToken?: never
|
|
46
|
+
|
|
47
|
+
/** Automate.ax user-session bearer token. */
|
|
48
|
+
sessionToken: ClientCredential
|
|
49
|
+
}
|
|
50
|
+
)
|
|
27
51
|
|
|
28
52
|
/**
|
|
29
53
|
* Creates a type-safe client for the public management API.
|
|
@@ -38,17 +62,36 @@ export function createAutomateClient(
|
|
|
38
62
|
): AutomateClient {
|
|
39
63
|
return createORPCClient(
|
|
40
64
|
new RPCLink({
|
|
41
|
-
|
|
65
|
+
fetch: async (request, init) =>
|
|
66
|
+
await (options.fetch ?? globalThis.fetch)(request, {
|
|
67
|
+
...init,
|
|
68
|
+
credentials: "omit",
|
|
69
|
+
}),
|
|
70
|
+
url: options.rpcUrl ?? RPC_URL,
|
|
42
71
|
headers: async () => {
|
|
43
|
-
const headers = new Headers(
|
|
44
|
-
|
|
72
|
+
const headers = new Headers(
|
|
73
|
+
typeof options.headers === "function"
|
|
74
|
+
? await options.headers()
|
|
75
|
+
: options.headers,
|
|
76
|
+
)
|
|
77
|
+
const usesKey = "apiKey" in options || "runtimeToken" in options
|
|
78
|
+
const credential =
|
|
79
|
+
"apiKey" in options
|
|
80
|
+
? options.apiKey
|
|
81
|
+
: "runtimeToken" in options
|
|
82
|
+
? options.runtimeToken
|
|
83
|
+
: options.sessionToken
|
|
45
84
|
const value =
|
|
46
85
|
typeof credential === "function" ? await credential() : credential
|
|
47
86
|
|
|
87
|
+
headers.delete("authorization")
|
|
88
|
+
headers.delete("cookie")
|
|
89
|
+
headers.delete("x-api-key")
|
|
90
|
+
|
|
48
91
|
if (value) {
|
|
49
92
|
headers.set(
|
|
50
|
-
|
|
51
|
-
|
|
93
|
+
usesKey ? "x-api-key" : "authorization",
|
|
94
|
+
usesKey ? value : `Bearer ${value}`,
|
|
52
95
|
)
|
|
53
96
|
}
|
|
54
97
|
|