@automate.ax/client 0.7.1 → 0.8.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/package.json +8 -3
- package/src/index.ts +45 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automate.ax/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Type-safe client for the Automate.ax API.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -20,10 +20,13 @@
|
|
|
20
20
|
"exports": {
|
|
21
21
|
".": "./src/index.ts"
|
|
22
22
|
},
|
|
23
|
-
"cjs": false
|
|
23
|
+
"cjs": false,
|
|
24
|
+
"conditions": {
|
|
25
|
+
"bun": "src"
|
|
26
|
+
}
|
|
24
27
|
},
|
|
25
28
|
"dependencies": {
|
|
26
|
-
"@automate.ax/api-contract": "0.
|
|
29
|
+
"@automate.ax/api-contract": "0.8.0",
|
|
27
30
|
"@orpc/client": "1.13.14",
|
|
28
31
|
"@orpc/contract": "1.13.14"
|
|
29
32
|
},
|
|
@@ -49,6 +52,7 @@
|
|
|
49
52
|
},
|
|
50
53
|
"files": [
|
|
51
54
|
"dist",
|
|
55
|
+
"src",
|
|
52
56
|
"README.md",
|
|
53
57
|
"LICENSE"
|
|
54
58
|
],
|
|
@@ -60,6 +64,7 @@
|
|
|
60
64
|
},
|
|
61
65
|
"exports": {
|
|
62
66
|
".": {
|
|
67
|
+
"bun": "./src/index.ts",
|
|
63
68
|
"types": "./dist/index.d.ts",
|
|
64
69
|
"default": "./dist/index.js"
|
|
65
70
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { publicContract } from "@automate.ax/api-contract"
|
|
2
|
+
import { createORPCClient } from "@orpc/client"
|
|
3
|
+
import { RPCLink } from "@orpc/client/fetch"
|
|
4
|
+
import type { ContractRouterClient } from "@orpc/contract"
|
|
5
|
+
|
|
6
|
+
const RPC_URL = "https://automate.ax/api/rpc"
|
|
7
|
+
|
|
8
|
+
// this is an exception to the "no branding in code" rule
|
|
9
|
+
export type AutomateClient = ContractRouterClient<typeof publicContract>
|
|
10
|
+
|
|
11
|
+
export interface AutomateClientOptions {
|
|
12
|
+
/** Automate.ax API key sent through the `x-api-key` header. */
|
|
13
|
+
apiKey:
|
|
14
|
+
| string
|
|
15
|
+
| (() => Promise<string | null | undefined> | string | null | undefined)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates a type-safe client for the public management API.
|
|
20
|
+
*
|
|
21
|
+
* Credential callbacks are evaluated for every request, allowing callers to
|
|
22
|
+
* rotate API keys without recreating the client.
|
|
23
|
+
*
|
|
24
|
+
* @param options - API authentication options.
|
|
25
|
+
*/
|
|
26
|
+
export function createAutomateClient(
|
|
27
|
+
options: AutomateClientOptions,
|
|
28
|
+
): AutomateClient {
|
|
29
|
+
return createORPCClient(
|
|
30
|
+
new RPCLink({
|
|
31
|
+
url: RPC_URL,
|
|
32
|
+
headers: async () => {
|
|
33
|
+
const headers = new Headers()
|
|
34
|
+
const apiKey =
|
|
35
|
+
typeof options.apiKey === "function"
|
|
36
|
+
? await options.apiKey()
|
|
37
|
+
: options.apiKey
|
|
38
|
+
|
|
39
|
+
if (apiKey) headers.set("x-api-key", apiKey)
|
|
40
|
+
|
|
41
|
+
return headers
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
44
|
+
)
|
|
45
|
+
}
|