@brazosd/node 0.0.0-stage → 0.1.1
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 +128 -2
- package/index.d.ts +6686 -0
- package/index.js +9603 -0
- package/package.json +42 -4
package/README.md
CHANGED
|
@@ -1,3 +1,129 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Brazosd Node.js SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Node.js 22+ ESM client generated from Brazosd's OpenAPI schemas, with automatic cloud-function identity and no runtime dependencies.
|
|
4
|
+
|
|
5
|
+
Install the public npm package:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @brazosd/node
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
For installations in mainland China, use the npm mirror:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @brazosd/node --registry=https://registry.npmmirror.com
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Include the installed runtime dependencies in your deployment package. Cloud
|
|
18
|
+
functions do not install packages during startup. To test local SDK changes,
|
|
19
|
+
run `npm pack ./sdks/node` and install the resulting archive instead.
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import { createClient } from '@brazosd/node';
|
|
23
|
+
|
|
24
|
+
const brazosd = createClient();
|
|
25
|
+
const snapshots = await brazosd.api.listSnapshots();
|
|
26
|
+
const agents = await brazosd.api.listAgents({ limit: 20 });
|
|
27
|
+
const functions = await brazosd.serverless.listApps();
|
|
28
|
+
const organizations = await brazosd.anclax.listOrgs();
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Methods use OpenAPI operation IDs and a single options object when parameters are present. Request and response types come from the schema. The three API groups are:
|
|
32
|
+
|
|
33
|
+
| Property | Schema source | Base path |
|
|
34
|
+
| --- | --- | --- |
|
|
35
|
+
| `api` | `api/openapi/v1/` | `/api/v1` |
|
|
36
|
+
| `serverless` | `app/serverless/api/openapi.yaml` | `/api/v1/serverless` |
|
|
37
|
+
| `anclax` | The Anclax version pinned by `go.mod` | `/api/v1` |
|
|
38
|
+
|
|
39
|
+
All declared operations are generated, including Cloud Drive, sessions, snapshots, agents, organization management, cloud functions and SQLite databases. Availability is still determined by the caller's existing permissions and the endpoint's credential requirements.
|
|
40
|
+
|
|
41
|
+
## Cloud Drive
|
|
42
|
+
|
|
43
|
+
Cloud Drive uses the generated operations directly:
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
import { createHash } from 'node:crypto';
|
|
47
|
+
import { createClient } from '@brazosd/node';
|
|
48
|
+
|
|
49
|
+
const brazosd = createClient();
|
|
50
|
+
const directory = '@brazosd://org.drive/123/reports';
|
|
51
|
+
await brazosd.api.createCloudDriveDirectory({ requestBody: { path: directory } });
|
|
52
|
+
|
|
53
|
+
const path = `${directory}/today.json`;
|
|
54
|
+
const data = JSON.stringify({ visits: 42 });
|
|
55
|
+
await brazosd.api.uploadCloudDriveFile({
|
|
56
|
+
path,
|
|
57
|
+
sha256: createHash('sha256').update(data).digest('hex'),
|
|
58
|
+
formData: { file: new File([data], 'today.json', { type: 'application/json' }) },
|
|
59
|
+
overwrite: true,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const response = await brazosd.api.downloadCloudDrive({ path });
|
|
63
|
+
const report = await response.json();
|
|
64
|
+
const entries = await brazosd.api.getCloudDrive({ path: directory });
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Use your organization's numeric ID. `getCloudDrive` returns an array for a directory or a streaming `Response` for a file. `downloadCloudDrive` always returns a `Response`. Binary responses and declared download redirects remain streams; JSON responses are parsed. Download redirects never forward authentication headers or cookies to object storage. Writes are not redirected or retried.
|
|
68
|
+
|
|
69
|
+
For large uploads, use Node's `openAsBlob` to construct a file-backed `File`, and compute SHA-256 with `createReadStream` and `createHash` before uploading. The generated multipart transport accepts `File`/`Blob`, not filesystem paths. `ifMatch` accepts the current SHA-256 for optimistic concurrency. Other operations include `statCloudDrive`, `copyCloudDrive`, `moveCloudDrive` and `deleteCloudDrive`.
|
|
70
|
+
|
|
71
|
+
## Authentication and permissions
|
|
72
|
+
|
|
73
|
+
Inside a cloud function, `createClient()` reads the access token and internal API URL from `/run/brazosd/identity/credentials.json`. The trusted runtime refreshes credentials and atomically replaces that file. Reads are coalesced and cached for at most one second, bounded by credential expiry. The SDK never reads a refresh token. Warm-pool instances have no user identity; credentials are absent from deployment packages and development snapshots.
|
|
74
|
+
|
|
75
|
+
A service user follows the same API authorization rules as other organization users. Enterprise service users start without grants; use existing user/group policies to grant API and resource access. Changes apply to subsequent API requests. Deactivating the service user or retiring the instance revokes access, including Anclax APIs. Creating a client does not grant permissions.
|
|
76
|
+
|
|
77
|
+
For development outside a function, supply your own authorized credential:
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
const client = createClient({
|
|
81
|
+
apiUrl: 'http://localhost:2910/api/v1',
|
|
82
|
+
credentials: async () => ({ accessToken: process.env.BRAZOSD_ACCESS_TOKEN }),
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Each client keeps its own URL, credential provider and request configuration. Concurrent clients do not share global authentication state. Public operations work without credentials when `apiUrl` is supplied. A schema-defined `Authorization` parameter, when present, takes precedence over the client's credential provider.
|
|
87
|
+
|
|
88
|
+
## Errors and cancellation
|
|
89
|
+
|
|
90
|
+
API errors throw `BrazosdError` with `status` and a bounded response `body`. Handle permission errors, conflicts and throttling explicitly. Generated calls return a `CancelablePromise`: call `.cancel()` before completion to abort the HTTP request. Cancellation rejects with `CancelError`. A client-wide `signal` is also supported; cancel a returned stream through its `Response.body`.
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
const controller = new AbortController();
|
|
94
|
+
const client = createClient({ signal: controller.signal });
|
|
95
|
+
const pending = client.api.listSnapshots();
|
|
96
|
+
// Call pending.cancel() or controller.abort() when the operation is no longer needed.
|
|
97
|
+
const snapshots = await pending;
|
|
98
|
+
|
|
99
|
+
const rangedClient = createClient({ headers: { Range: 'bytes=0-1023' } });
|
|
100
|
+
const part = await rangedClient.api.downloadCloudDrive({ path: '@brazosd://org.drive/123/video.mp4' });
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Regeneration and validation
|
|
104
|
+
|
|
105
|
+
Releases use `sdks/node/VERSION` independently of the server version. Changing
|
|
106
|
+
that file on `main` triggers `.github/workflows/publish-sdk.yaml`, which tests
|
|
107
|
+
the SDK, publishes to npm, requests npmmirror synchronization, and verifies
|
|
108
|
+
installation from the mirror. Rerun a failed mirror synchronization with the same
|
|
109
|
+
version; changed package contents require a new version.
|
|
110
|
+
|
|
111
|
+
After the first npm publication, configure a GitHub Actions trusted publisher for
|
|
112
|
+
`cloudcarver/brazosd`, workflow `publish-sdk.yaml`, with direct publishing
|
|
113
|
+
allowed. The workflow uses OIDC and does not need an npm token. Run
|
|
114
|
+
`node scripts/publish.mjs --dry-run` in this directory to validate packaging
|
|
115
|
+
without publishing.
|
|
116
|
+
|
|
117
|
+
```sh
|
|
118
|
+
make gen-sdk-node
|
|
119
|
+
cd sdks/node
|
|
120
|
+
npm test
|
|
121
|
+
npm run typecheck
|
|
122
|
+
npm pack
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Generation uses `openapi-typescript-codegen`, the same generator as the web frontend, pinned to version 0.29.0. It requires the repository Anclax binary (`.anclax/bin/anclax`, overridable with `ANCLAX`), Go and Node.js. After `npm ci`, `npm run generate` also works directly in this directory.
|
|
126
|
+
|
|
127
|
+
Edit the OpenAPI sources and `src/`, then regenerate. The script bundles the core schema, reads the backend's pinned Anclax schema, generates independent clients and bundles `index.js` plus `index.d.ts`. Intermediate `src/generated/` files are ignored. Only the public bundle, declarations and README are packaged. Do not edit generated artifacts directly. No service-specific authentication or manually maintained Cloud Drive methods are needed.
|
|
128
|
+
|
|
129
|
+
See [workload identity](../../docs/api/workload-identity.md) for credential lifecycle and deployment configuration.
|