@automate.ax/client 0.76.0 → 0.77.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 +42 -1
- package/dist/index.d.ts +12 -5
- package/dist/index.js +6 -6
- package/package.json +2 -2
- package/src/index.ts +26 -12
package/README.md
CHANGED
|
@@ -17,9 +17,50 @@ const client = createAutomateClient({
|
|
|
17
17
|
apiKey: process.env.AUTOMATE_AX_API_KEY!,
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
-
const
|
|
20
|
+
const firstPage = await client.project.list({ limit: 25 })
|
|
21
|
+
|
|
22
|
+
for (const project of firstPage.items) {
|
|
23
|
+
console.log(project.name)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (firstPage.items[0]) {
|
|
27
|
+
const automations = await client.automation.list({
|
|
28
|
+
projectId: firstPage.items[0].id,
|
|
29
|
+
limit: 25,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
if (automations.items[0]) {
|
|
33
|
+
const automation = await client.automation.get({
|
|
34
|
+
automationId: automations.items[0].id,
|
|
35
|
+
})
|
|
36
|
+
console.log(automation.triggers)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
21
39
|
```
|
|
22
40
|
|
|
41
|
+
List procedures return `{ items, pageInfo }`. When `pageInfo.hasMore` is true, pass `pageInfo.nextCursor` as the next request's `cursor`.
|
|
42
|
+
|
|
23
43
|
The key is organization-owned and is sent in the `x-api-key` header. It does not represent a user session.
|
|
24
44
|
|
|
25
45
|
The client targets `https://automate.ax/api/rpc`.
|
|
46
|
+
|
|
47
|
+
## User session
|
|
48
|
+
|
|
49
|
+
User-scoped procedures, including execution-data discovery, use a signed-in user's bearer session:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { createAutomateClient } from "@automate.ax/client"
|
|
53
|
+
|
|
54
|
+
const client = createAutomateClient({
|
|
55
|
+
sessionToken: process.env.AUTOMATE_SESSION_TOKEN!,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const manifest = await client.executionData.manifest({
|
|
59
|
+
projectId: "proj_01...",
|
|
60
|
+
since: "2026-08-01T00:00:00Z",
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
console.log(manifest.consistency, manifest.resources)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Credential callbacks are evaluated before every request, so a client can use a refreshed token without being recreated. Supply either `apiKey` or `sessionToken`.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
type ClientCredential = string | (() => Promise<string | null | undefined> | string | null | undefined);
|
|
5
|
+
export type AutomateClientOptions = {
|
|
6
|
+
/** Automate.ax organization API key sent through `x-api-key`. */
|
|
7
|
+
apiKey: ClientCredential;
|
|
8
|
+
sessionToken?: never;
|
|
9
|
+
} | {
|
|
10
|
+
apiKey?: never;
|
|
11
|
+
/** Automate.ax user-session bearer token. */
|
|
12
|
+
sessionToken: ClientCredential;
|
|
13
|
+
};
|
|
8
14
|
/**
|
|
9
15
|
* Creates a type-safe client for the public management API.
|
|
10
16
|
*
|
|
11
17
|
* Credential callbacks are evaluated for every request, allowing callers to
|
|
12
|
-
* rotate API keys without recreating the client.
|
|
18
|
+
* rotate API keys or user-session tokens without recreating the client.
|
|
13
19
|
*
|
|
14
20
|
* @param options - API authentication options.
|
|
15
21
|
*/
|
|
16
22
|
export declare function createAutomateClient(options: AutomateClientOptions): AutomateClient;
|
|
23
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const RPC_URL = "https://automate.ax/api/rpc";
|
|
|
5
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
|
-
* rotate API keys without recreating the client.
|
|
8
|
+
* rotate API keys or user-session tokens without recreating the client.
|
|
9
9
|
*
|
|
10
10
|
* @param options - API authentication options.
|
|
11
11
|
*/
|
|
@@ -14,11 +14,11 @@ export function createAutomateClient(options) {
|
|
|
14
14
|
url: RPC_URL,
|
|
15
15
|
headers: async () => {
|
|
16
16
|
const headers = new Headers();
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
const credential = options.apiKey ?? options.sessionToken;
|
|
18
|
+
const value = typeof credential === "function" ? await credential() : credential;
|
|
19
|
+
if (value) {
|
|
20
|
+
headers.set(options.apiKey === undefined ? "authorization" : "x-api-key", options.apiKey === undefined ? `Bearer ${value}` : value);
|
|
21
|
+
}
|
|
22
22
|
return headers;
|
|
23
23
|
},
|
|
24
24
|
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automate.ax/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.77.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.77.0",
|
|
30
30
|
"@orpc/client": "1.15.0",
|
|
31
31
|
"@orpc/contract": "1.15.0"
|
|
32
32
|
},
|
package/src/index.ts
CHANGED
|
@@ -8,18 +8,28 @@ const RPC_URL = "https://automate.ax/api/rpc"
|
|
|
8
8
|
// this is an exception to the "no branding in code" rule
|
|
9
9
|
export type AutomateClient = ContractRouterClient<typeof publicContract>
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
type ClientCredential =
|
|
12
|
+
| string
|
|
13
|
+
| (() => Promise<string | null | undefined> | string | null | undefined)
|
|
14
|
+
|
|
15
|
+
export type AutomateClientOptions =
|
|
16
|
+
| {
|
|
17
|
+
/** Automate.ax organization API key sent through `x-api-key`. */
|
|
18
|
+
apiKey: ClientCredential
|
|
19
|
+
sessionToken?: never
|
|
20
|
+
}
|
|
21
|
+
| {
|
|
22
|
+
apiKey?: never
|
|
23
|
+
|
|
24
|
+
/** Automate.ax user-session bearer token. */
|
|
25
|
+
sessionToken: ClientCredential
|
|
26
|
+
}
|
|
17
27
|
|
|
18
28
|
/**
|
|
19
29
|
* Creates a type-safe client for the public management API.
|
|
20
30
|
*
|
|
21
31
|
* Credential callbacks are evaluated for every request, allowing callers to
|
|
22
|
-
* rotate API keys without recreating the client.
|
|
32
|
+
* rotate API keys or user-session tokens without recreating the client.
|
|
23
33
|
*
|
|
24
34
|
* @param options - API authentication options.
|
|
25
35
|
*/
|
|
@@ -31,12 +41,16 @@ export function createAutomateClient(
|
|
|
31
41
|
url: RPC_URL,
|
|
32
42
|
headers: async () => {
|
|
33
43
|
const headers = new Headers()
|
|
34
|
-
const apiKey
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
: options.apiKey
|
|
44
|
+
const credential = options.apiKey ?? options.sessionToken
|
|
45
|
+
const value =
|
|
46
|
+
typeof credential === "function" ? await credential() : credential
|
|
38
47
|
|
|
39
|
-
if (
|
|
48
|
+
if (value) {
|
|
49
|
+
headers.set(
|
|
50
|
+
options.apiKey === undefined ? "authorization" : "x-api-key",
|
|
51
|
+
options.apiKey === undefined ? `Bearer ${value}` : value,
|
|
52
|
+
)
|
|
53
|
+
}
|
|
40
54
|
|
|
41
55
|
return headers
|
|
42
56
|
},
|