@automate.ax/client 0.7.0 → 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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # `@automate.ax/client`
2
2
 
3
- Type-safe client for the complete Automate.ax API contract.
3
+ Type-safe client for the public Automate.ax management API.
4
4
 
5
5
  ## Install
6
6
 
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import type { contract } from "@automate.ax/api-contract";
1
+ import type { publicContract } from "@automate.ax/api-contract";
2
2
  import type { ContractRouterClient } from "@orpc/contract";
3
- export type AutomateClient = ContractRouterClient<typeof contract>;
3
+ export type AutomateClient = ContractRouterClient<typeof publicContract>;
4
4
  export interface AutomateClientOptions {
5
5
  /** Automate.ax API key sent through the `x-api-key` header. */
6
6
  apiKey: string | (() => Promise<string | null | undefined> | string | null | undefined);
7
7
  }
8
8
  /**
9
- * Creates a type-safe client for every procedure in the public API contract.
9
+ * Creates a type-safe client for the public management API.
10
10
  *
11
11
  * Credential callbacks are evaluated for every request, allowing callers to
12
12
  * rotate API keys without recreating the client.
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { createORPCClient } from "@orpc/client";
2
2
  import { RPCLink } from "@orpc/client/fetch";
3
3
  const RPC_URL = "https://automate.ax/api/rpc";
4
4
  /**
5
- * Creates a type-safe client for every procedure in the public API contract.
5
+ * Creates a type-safe client for the public management API.
6
6
  *
7
7
  * Credential callbacks are evaluated for every request, allowing callers to
8
8
  * rotate API keys without recreating the client.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automate.ax/client",
3
- "version": "0.7.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.7.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
+ }