@automate.ax/client 0.3.0 → 0.4.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 +3 -4
- package/dist/index.d.ts +5 -17
- package/dist/index.js +8 -16
- package/package.json +11 -5
package/README.md
CHANGED
|
@@ -11,9 +11,9 @@ bun add @automate.ax/client
|
|
|
11
11
|
## API key
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
import {
|
|
14
|
+
import { createAutomateClient } from "@automate.ax/client"
|
|
15
15
|
|
|
16
|
-
const client =
|
|
16
|
+
const client = createAutomateClient({
|
|
17
17
|
apiKey: process.env.AUTOMATE_AX_API_KEY!,
|
|
18
18
|
})
|
|
19
19
|
|
|
@@ -23,5 +23,4 @@ const projects = await client.project.list()
|
|
|
23
23
|
The key is organization-owned and is sent in the `x-api-key` header. It does
|
|
24
24
|
not represent a user session.
|
|
25
25
|
|
|
26
|
-
The client targets `https://automate.ax/api/rpc
|
|
27
|
-
or `fetch` to customize its transport.
|
|
26
|
+
The client targets `https://automate.ax/api/rpc`.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
import type { contract } from "@automate.ax/api-contract";
|
|
2
2
|
import type { ContractRouterClient } from "@orpc/contract";
|
|
3
|
-
export type
|
|
4
|
-
export
|
|
5
|
-
export type Fetch = (request: Request, init?: RequestInit) => Promise<Response>;
|
|
6
|
-
type HeadersInit = ConstructorParameters<typeof Headers>[0];
|
|
7
|
-
interface ClientBaseOptions {
|
|
8
|
-
/** Overrides the default `https://automate.ax/api/rpc` endpoint. */
|
|
9
|
-
url?: URL | string;
|
|
10
|
-
/** Adds request headers before the authentication header is applied. */
|
|
11
|
-
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
12
|
-
/** Overrides the global Fetch implementation used for requests. */
|
|
13
|
-
fetch?: Fetch;
|
|
14
|
-
}
|
|
15
|
-
export interface ClientOptions extends ClientBaseOptions {
|
|
3
|
+
export type AutomateClient = ContractRouterClient<typeof contract>;
|
|
4
|
+
export interface AutomateClientOptions {
|
|
16
5
|
/** Automate.ax API key sent through the `x-api-key` header. */
|
|
17
|
-
apiKey:
|
|
6
|
+
apiKey: string | (() => Promise<string | null | undefined> | string | null | undefined);
|
|
18
7
|
}
|
|
19
8
|
/**
|
|
20
9
|
* Creates a type-safe client for every procedure in the public API contract.
|
|
@@ -22,7 +11,6 @@ export interface ClientOptions extends ClientBaseOptions {
|
|
|
22
11
|
* Credential callbacks are evaluated for every request, allowing callers to
|
|
23
12
|
* rotate API keys without recreating the client.
|
|
24
13
|
*
|
|
25
|
-
* @param options -
|
|
14
|
+
* @param options - API authentication options.
|
|
26
15
|
*/
|
|
27
|
-
export declare function
|
|
28
|
-
export {};
|
|
16
|
+
export declare function createAutomateClient(options: AutomateClientOptions): AutomateClient;
|
package/dist/index.js
CHANGED
|
@@ -1,33 +1,25 @@
|
|
|
1
1
|
import { createORPCClient } from "@orpc/client";
|
|
2
2
|
import { RPCLink } from "@orpc/client/fetch";
|
|
3
|
-
const
|
|
3
|
+
const RPC_URL = "https://automate.ax/api/rpc";
|
|
4
4
|
/**
|
|
5
5
|
* Creates a type-safe client for every procedure in the public API contract.
|
|
6
6
|
*
|
|
7
7
|
* Credential callbacks are evaluated for every request, allowing callers to
|
|
8
8
|
* rotate API keys without recreating the client.
|
|
9
9
|
*
|
|
10
|
-
* @param options -
|
|
10
|
+
* @param options - API authentication options.
|
|
11
11
|
*/
|
|
12
|
-
export function
|
|
13
|
-
const customFetch = options.fetch;
|
|
12
|
+
export function createAutomateClient(options) {
|
|
14
13
|
return createORPCClient(new RPCLink({
|
|
15
|
-
url:
|
|
14
|
+
url: RPC_URL,
|
|
16
15
|
headers: async () => {
|
|
17
|
-
const headers = new Headers(
|
|
18
|
-
|
|
19
|
-
: options.headers);
|
|
20
|
-
const credential = typeof options.apiKey === "function"
|
|
16
|
+
const headers = new Headers();
|
|
17
|
+
const apiKey = typeof options.apiKey === "function"
|
|
21
18
|
? await options.apiKey()
|
|
22
19
|
: options.apiKey;
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
headers.set("x-api-key", credential);
|
|
20
|
+
if (apiKey)
|
|
21
|
+
headers.set("x-api-key", apiKey);
|
|
27
22
|
return headers;
|
|
28
23
|
},
|
|
29
|
-
...(customFetch && {
|
|
30
|
-
fetch: (request, init) => customFetch(request, init),
|
|
31
|
-
}),
|
|
32
24
|
}));
|
|
33
25
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automate.ax/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Type-safe client for the Automate.ax API.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -23,21 +23,27 @@
|
|
|
23
23
|
"cjs": false
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@automate.ax/api-contract": "0.1
|
|
26
|
+
"@automate.ax/api-contract": "0.3.1",
|
|
27
27
|
"@orpc/client": "1.13.14",
|
|
28
28
|
"@orpc/contract": "1.13.14"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@internal/config": "0.0.0",
|
|
32
32
|
"@types/bun": "latest",
|
|
33
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
34
|
+
"@zachsents/oxlint-config": "^0.4.1",
|
|
35
|
+
"concurrently": "^10.0.4",
|
|
36
|
+
"eslint": "^9.39.5",
|
|
37
|
+
"oxlint": "^1.76.0",
|
|
38
|
+
"oxlint-tsgolint": "^7.0.2001",
|
|
33
39
|
"zshy": "^0.7.2"
|
|
34
40
|
},
|
|
35
41
|
"scripts": {
|
|
36
42
|
"typecheck": "tsc --noEmit",
|
|
37
|
-
"lint": "oxlint --type-aware",
|
|
38
|
-
"lint:fix": "oxlint --type-aware --fix-suggestions",
|
|
43
|
+
"lint": "concurrently --success all --kill-others-on-fail \"oxlint --type-aware\" \"bun --bun eslint .\"",
|
|
44
|
+
"lint:fix": "concurrently --success all --kill-others-on-fail \"oxlint --type-aware --fix --fix-suggestions\" \"bun --bun eslint . --fix\"",
|
|
39
45
|
"check": "bun run typecheck && bun run lint",
|
|
40
|
-
"test": "bun test",
|
|
46
|
+
"test": "bun test --pass-with-no-tests",
|
|
41
47
|
"build": "zshy -p tsconfig.build.json",
|
|
42
48
|
"prepublishOnly": "bun run check && bun run test && bun run build"
|
|
43
49
|
},
|