@alvera-ai/platform-sdk 0.9.0 → 0.10.0-rc.2
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/dist/index.d.mts +48599 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +9637 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +14 -15
- package/LICENSE +0 -21
- package/README.md +0 -320
- package/src/cli/auth.ts +0 -174
- package/src/cli/env.ts +0 -49
- package/src/cli/helpers.ts +0 -128
- package/src/cli/init.ts +0 -123
- package/src/cli/raw.ts +0 -65
- package/src/cli/resources.ts +0 -789
- package/src/cli/workflows.ts +0 -246
- package/src/cli.ts +0 -54
- package/src/client.ts +0 -952
- package/src/config.ts +0 -209
- package/src/environments.generated.ts +0 -16
- package/src/generated/client/client.gen.ts +0 -298
- package/src/generated/client/index.ts +0 -25
- package/src/generated/client/types.gen.ts +0 -214
- package/src/generated/client/utils.gen.ts +0 -316
- package/src/generated/client.gen.ts +0 -16
- package/src/generated/core/auth.gen.ts +0 -41
- package/src/generated/core/bodySerializer.gen.ts +0 -82
- package/src/generated/core/params.gen.ts +0 -169
- package/src/generated/core/pathSerializer.gen.ts +0 -171
- package/src/generated/core/queryKeySerializer.gen.ts +0 -117
- package/src/generated/core/serverSentEvents.gen.ts +0 -242
- package/src/generated/core/types.gen.ts +0 -104
- package/src/generated/core/utils.gen.ts +0 -140
- package/src/generated/index.ts +0 -4
- package/src/generated/sdk.gen.ts +0 -1836
- package/src/generated/types.gen.ts +0 -13801
- package/src/generated/valibot.gen.ts +0 -7079
- package/src/index.ts +0 -70
package/package.json
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alvera-ai/platform-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0-rc.2",
|
|
4
4
|
"description": "Typed SDK for the Alvera platform API — manage data sources, tools, generic tables, AI agents, and action status updaters.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
|
-
"main": "./
|
|
8
|
-
"module": "./
|
|
9
|
-
"types": "./
|
|
7
|
+
"main": "./dist/index.mjs",
|
|
8
|
+
"module": "./dist/index.mjs",
|
|
9
|
+
"types": "./dist/index.d.mts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"types": "./
|
|
13
|
-
"import": "./
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"import": "./dist/index.mjs"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
-
"bin": {
|
|
17
|
-
"alvera": "./src/cli.ts"
|
|
18
|
-
},
|
|
19
16
|
"files": [
|
|
20
|
-
"
|
|
17
|
+
"dist",
|
|
21
18
|
"README.md",
|
|
22
19
|
"LICENSE"
|
|
23
20
|
],
|
|
@@ -29,17 +26,18 @@
|
|
|
29
26
|
"codegen": "openapi-ts && tsx scripts/patch-generated.ts",
|
|
30
27
|
"check-coverage": "tsx scripts/check-sdk-coverage.ts",
|
|
31
28
|
"regen": "bun run gen-environments && bun run codegen && bun run check-coverage",
|
|
29
|
+
"build": "tsdown",
|
|
32
30
|
"typecheck": "tsc --noEmit && tsc --noEmit -p scripts/tsconfig.json",
|
|
33
|
-
"clean": "rm -rf src/generated src/environments.generated.ts",
|
|
34
|
-
"prepare": "bun run gen-environments && bun run codegen && bun run check-coverage"
|
|
31
|
+
"clean": "rm -rf dist src/generated src/environments.generated.ts",
|
|
32
|
+
"prepare": "bun run gen-environments && bun run codegen && bun run check-coverage && bun run build"
|
|
35
33
|
},
|
|
36
34
|
"dependencies": {
|
|
37
|
-
"commander": "14.0.3",
|
|
38
35
|
"valibot": "1.2.0"
|
|
39
36
|
},
|
|
40
37
|
"devDependencies": {
|
|
41
38
|
"@hey-api/openapi-ts": "0.96.0",
|
|
42
39
|
"@types/node": "^25.3.3",
|
|
40
|
+
"tsdown": "^0.16.0",
|
|
43
41
|
"tsx": "^4.19.2",
|
|
44
42
|
"typescript": "5.9.3",
|
|
45
43
|
"yaml": "2.6.1"
|
|
@@ -58,9 +56,10 @@
|
|
|
58
56
|
"author": "Alvera",
|
|
59
57
|
"repository": {
|
|
60
58
|
"type": "git",
|
|
61
|
-
"url": "git+https://github.com/alvera-ai/platform-sdk.git"
|
|
59
|
+
"url": "git+https://github.com/alvera-ai/platform-sdk.git",
|
|
60
|
+
"directory": "packages/sdk"
|
|
62
61
|
},
|
|
63
|
-
"homepage": "https://github.com/alvera-ai/platform-sdk#readme",
|
|
62
|
+
"homepage": "https://github.com/alvera-ai/platform-sdk/tree/main/packages/sdk#readme",
|
|
64
63
|
"bugs": {
|
|
65
64
|
"url": "https://github.com/alvera-ai/platform-sdk/issues"
|
|
66
65
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Alvera
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/README.md
DELETED
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
# @alvera-ai/platform-sdk
|
|
2
|
-
|
|
3
|
-
Typed TypeScript SDK for the Alvera platform API.
|
|
4
|
-
|
|
5
|
-
Manage the resources that live under a tenant — data sources, tools, generic
|
|
6
|
-
tables, action status updaters, AI agents — with full type safety.
|
|
7
|
-
|
|
8
|
-
## Install
|
|
9
|
-
|
|
10
|
-
```bash
|
|
11
|
-
npm install @alvera-ai/platform-sdk
|
|
12
|
-
# or
|
|
13
|
-
bun add @alvera-ai/platform-sdk
|
|
14
|
-
# or
|
|
15
|
-
pnpm add @alvera-ai/platform-sdk
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## TypeScript configuration
|
|
19
|
-
|
|
20
|
-
The SDK uses [`@hey-api/client-fetch`](https://heyapi.dev/openapi-ts/clients/fetch),
|
|
21
|
-
whose generated code references WHATWG fetch types — `BodyInit`,
|
|
22
|
-
`RequestInit`, `Headers`, `FormData`, etc. Those names live in
|
|
23
|
-
`lib.dom.d.ts`, not `@types/node`, so a Node-only consumer with
|
|
24
|
-
`"lib": ["ES2022"]` in its `tsconfig.json` will see errors like
|
|
25
|
-
`Cannot find name 'BodyInit'` when typechecking.
|
|
26
|
-
|
|
27
|
-
The fix is to add `DOM` and `DOM.Iterable` to your `lib`:
|
|
28
|
-
|
|
29
|
-
```jsonc
|
|
30
|
-
// tsconfig.json
|
|
31
|
-
{
|
|
32
|
-
"compilerOptions": {
|
|
33
|
-
"lib": ["ES2022", "DOM", "DOM.Iterable"]
|
|
34
|
-
// ^^^^^^^^^^^^^^^^^^^^^^^
|
|
35
|
-
// Required by @hey-api/client-fetch — see
|
|
36
|
-
// https://github.com/hey-api/openapi-ts/issues/2539
|
|
37
|
-
// Provides type-only declarations for fetch globals.
|
|
38
|
-
// Adds NOTHING to the runtime — Node 18+ provides real fetch
|
|
39
|
-
// independently of these types.
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
This is the workaround documented in hey-api's open issue
|
|
45
|
-
[#2539](https://github.com/hey-api/openapi-ts/issues/2539); when
|
|
46
|
-
the upstream fix lands and emits self-contained types, you can
|
|
47
|
-
drop the `DOM` lib entries again.
|
|
48
|
-
|
|
49
|
-
Browser consumers (React, Vue, Next, Nuxt, Remix) already have
|
|
50
|
-
`DOM` and `DOM.Iterable` enabled by default — no change needed.
|
|
51
|
-
|
|
52
|
-
## Quick start
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
import { createPlatformApi, createSession, ENVIRONMENTS } from '@alvera-ai/platform-sdk';
|
|
56
|
-
|
|
57
|
-
const baseUrl = ENVIRONMENTS.prod.base_url; // or ENVIRONMENTS.local / ENVIRONMENTS.demo
|
|
58
|
-
|
|
59
|
-
// 1. Exchange credentials for a session token
|
|
60
|
-
const session = await createSession({
|
|
61
|
-
baseUrl,
|
|
62
|
-
email: process.env.ALVERA_EMAIL!,
|
|
63
|
-
password: process.env.ALVERA_PASSWORD!,
|
|
64
|
-
tenantSlug: 'acme',
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// 2. Build the API client with that token
|
|
68
|
-
const api = createPlatformApi({ baseUrl, sessionToken: session.sessionToken });
|
|
69
|
-
|
|
70
|
-
// 3. Use it
|
|
71
|
-
await api.ping();
|
|
72
|
-
|
|
73
|
-
const { data: datalakes } = await api.datalakes.list('acme');
|
|
74
|
-
|
|
75
|
-
const { data: ds } = await api.dataSources.create('acme', 'acme-health', {
|
|
76
|
-
name: 'Acme EMR',
|
|
77
|
-
uri: 'our-emr:acme',
|
|
78
|
-
description: 'Acme EMR system',
|
|
79
|
-
status: 'active',
|
|
80
|
-
is_default: true,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
const { data: tool } = await api.tools.create('acme', {
|
|
84
|
-
name: 'Acme Manual Upload',
|
|
85
|
-
intent: 'data_exchange',
|
|
86
|
-
status: 'active',
|
|
87
|
-
datalake_id: datalakes[0].id,
|
|
88
|
-
data_source_id: ds.id,
|
|
89
|
-
body: { __type__: 'manual_upload' },
|
|
90
|
-
});
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
## Authentication
|
|
94
|
-
|
|
95
|
-
The SDK uses **session-based** auth.
|
|
96
|
-
|
|
97
|
-
1. Call `createSession({ baseUrl, email, password, tenantSlug })` with your
|
|
98
|
-
Alvera login credentials and the tenant you want to operate on.
|
|
99
|
-
2. The returned `sessionToken` is a Bearer token, valid for 24 hours by
|
|
100
|
-
default (override with `expiresIn`, max 30 days).
|
|
101
|
-
3. Pass the token into `createPlatformApi({ baseUrl, sessionToken })`.
|
|
102
|
-
4. When done, optionally call `revokeSession()` to invalidate the token.
|
|
103
|
-
|
|
104
|
-
```ts
|
|
105
|
-
import { createSession, createPlatformApi, revokeSession } from '@alvera-ai/platform-sdk';
|
|
106
|
-
|
|
107
|
-
const session = await createSession({
|
|
108
|
-
baseUrl, email, password, tenantSlug: 'acme', expiresIn: 3600,
|
|
109
|
-
});
|
|
110
|
-
const api = createPlatformApi({ baseUrl, sessionToken: session.sessionToken });
|
|
111
|
-
// ... use api ...
|
|
112
|
-
await revokeSession();
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
`session.expiresAt` is an ISO-8601 timestamp — check it before long-running
|
|
116
|
-
work and re-authenticate if needed.
|
|
117
|
-
|
|
118
|
-
## Environments
|
|
119
|
-
|
|
120
|
-
The base URLs ship with the package, derived at build time from the
|
|
121
|
-
`servers[]` block of the committed OpenAPI spec (`spec/openapi.yaml`). The
|
|
122
|
-
generated map is exported as `ENVIRONMENTS`:
|
|
123
|
-
|
|
124
|
-
```ts
|
|
125
|
-
import { ENVIRONMENTS, DEFAULT_ENVIRONMENT } from '@alvera-ai/platform-sdk';
|
|
126
|
-
|
|
127
|
-
ENVIRONMENTS.local.base_url; // http://localhost:4000
|
|
128
|
-
ENVIRONMENTS.demo.base_url; // https://platform-hh.alvera.ai
|
|
129
|
-
ENVIRONMENTS.prod.base_url; // https://app.alvera.ai
|
|
130
|
-
|
|
131
|
-
DEFAULT_ENVIRONMENT; // 'prod'
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
The CLI resolves a base URL with this precedence (highest first):
|
|
135
|
-
|
|
136
|
-
1. `ALVERA_BASE_URL` env var (explicit URL override — useful for tunnels /
|
|
137
|
-
ephemeral servers)
|
|
138
|
-
2. `base_url` pinned in the profile (written when the user passes a custom URL
|
|
139
|
-
to `alvera configure` or `alvera login --base-url …`)
|
|
140
|
-
3. `ENVIRONMENTS[env].base_url` where `env` is the first of: `--env <name>`
|
|
141
|
-
flag, `ALVERA_ENV` env var, the profile's `environment` entry, or
|
|
142
|
-
`DEFAULT_ENVIRONMENT`
|
|
143
|
-
|
|
144
|
-
Adding, renaming, or removing environments happens in the platform repo (the
|
|
145
|
-
`servers/0` function in `lib/platform_api/api_spec.ex`); rerun
|
|
146
|
-
`bun run regen` in the SDK to pick up the change.
|
|
147
|
-
|
|
148
|
-
## Resources
|
|
149
|
-
|
|
150
|
-
| Resource | Operations |
|
|
151
|
-
|------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------|
|
|
152
|
-
| `ping` | health check |
|
|
153
|
-
| `sessions` | `verify` |
|
|
154
|
-
| `auth` | `signUp` |
|
|
155
|
-
| `admin` | `confirmUser` |
|
|
156
|
-
| `tenants` | `list`, `create` |
|
|
157
|
-
| `invitations` | `list`, `create`, `accept` |
|
|
158
|
-
| `datasets` | `search`, `metadata`, `createUserSearch` |
|
|
159
|
-
| `datalakes` | `list`, `get`, `create`, `metadata`, `migrate`, `createUploadLink`, `createDownloadLink` |
|
|
160
|
-
| `dataSources` | `list`, `create`, `update` |
|
|
161
|
-
| `tools` | `list`, `get`, `create`, `update`, `delete`, `testInvocation` |
|
|
162
|
-
| `genericTables` | `list`, `create` |
|
|
163
|
-
| `actionStatusUpdaters` | `list`, `create`, `update` |
|
|
164
|
-
| `aiAgents` | `list`, `get`, `create`, `update`, `delete` |
|
|
165
|
-
| `connectedApps` | `list`, `get`, `create`, `update`, `syncRoutes`, `resolvePage`, `updateMessageTracking` |
|
|
166
|
-
| `dataActivationClients` | `list`, `get`, `create`, `update`, `delete`, `metadata`, `runManually`, `ingest`, `ingestFile`, `logs.list`, `logs.get` |
|
|
167
|
-
| `interoperabilityContracts` | `list`, `get`, `create`, `update`, `delete`, `metadata`, `run` |
|
|
168
|
-
| `mdm` | `verify` |
|
|
169
|
-
| `workflows` | `list`, `get`, `create`, `update`, `delete`, `metadata`, `execute`, `run`, `workflowLogs.list/get/download`, `batchLogs.list/get/start/stop/refresh` |
|
|
170
|
-
|
|
171
|
-
Tenant and datalake provisioning are performed by Alvera admins — contact your
|
|
172
|
-
representative to onboard a new tenant.
|
|
173
|
-
|
|
174
|
-
## Error handling
|
|
175
|
-
|
|
176
|
-
All methods throw on non-2xx responses (`throwOnError: true`). Wrap calls in
|
|
177
|
-
`try/catch` and inspect the thrown error for status and response body.
|
|
178
|
-
|
|
179
|
-
```ts
|
|
180
|
-
try {
|
|
181
|
-
await api.tools.create('acme', payload);
|
|
182
|
-
} catch (err) {
|
|
183
|
-
console.error('Tool creation failed:', err);
|
|
184
|
-
}
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
## CLI
|
|
188
|
-
|
|
189
|
-
The package ships a companion CLI (`alvera`) for ad-hoc calls against the
|
|
190
|
-
platform API. Install the package (globally, or via `npx`) and authenticate
|
|
191
|
-
once — subsequent commands reuse the stored session.
|
|
192
|
-
|
|
193
|
-
```bash
|
|
194
|
-
# Run without installing
|
|
195
|
-
npx @alvera-ai/platform-sdk --help
|
|
196
|
-
|
|
197
|
-
# Or install globally
|
|
198
|
-
npm install -g @alvera-ai/platform-sdk
|
|
199
|
-
alvera --help
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
### Configuration
|
|
203
|
-
|
|
204
|
-
`alvera` stores state under `~/.alvera-ai/`, AWS CLI–style:
|
|
205
|
-
|
|
206
|
-
| File | Purpose |
|
|
207
|
-
|-----------------------------|---------------------------------------------------|
|
|
208
|
-
| `~/.alvera-ai/config` | Per-profile defaults (base URL, tenant, email) |
|
|
209
|
-
| `~/.alvera-ai/credentials` | Per-profile session token and expiration (0600) |
|
|
210
|
-
|
|
211
|
-
Both files are INI. The default profile is `[default]`; additional profiles
|
|
212
|
-
live under `[profile <name>]` in `config` and `[<name>]` in `credentials`.
|
|
213
|
-
|
|
214
|
-
Every command accepts `--profile <name>` and `--env <name>`. Environment
|
|
215
|
-
variables (`ALVERA_PROFILE`, `ALVERA_ENV`, `ALVERA_BASE_URL`, `ALVERA_TENANT`,
|
|
216
|
-
`ALVERA_EMAIL`, `ALVERA_PASSWORD`, `ALVERA_SESSION_TOKEN`) take precedence
|
|
217
|
-
over file values.
|
|
218
|
-
|
|
219
|
-
### Getting started
|
|
220
|
-
|
|
221
|
-
```bash
|
|
222
|
-
alvera env list # show local / demo / prod
|
|
223
|
-
alvera configure # pick environment + default tenant
|
|
224
|
-
alvera login --email me@acme.com --tenant acme
|
|
225
|
-
alvera ping
|
|
226
|
-
alvera datalakes list
|
|
227
|
-
alvera tools create --body-file tool.json
|
|
228
|
-
alvera logout
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
Per-command env switch (no profile edit):
|
|
232
|
-
|
|
233
|
-
```bash
|
|
234
|
-
alvera --env local ping
|
|
235
|
-
ALVERA_ENV=demo alvera datalakes list
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
Pin an env into a profile:
|
|
239
|
-
|
|
240
|
-
```bash
|
|
241
|
-
alvera --profile staging env use demo
|
|
242
|
-
alvera --profile staging datalakes list
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
Override the base URL for an ad-hoc host (tunnels, local branches):
|
|
246
|
-
|
|
247
|
-
```bash
|
|
248
|
-
ALVERA_BASE_URL=https://pr-123.preview.alvera.ai alvera ping
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
### Command surface
|
|
252
|
-
|
|
253
|
-
```
|
|
254
|
-
alvera configure
|
|
255
|
-
alvera login [--email] [--password] [--tenant] [--base-url] [--expires-in]
|
|
256
|
-
alvera logout
|
|
257
|
-
alvera whoami
|
|
258
|
-
alvera ping
|
|
259
|
-
alvera env list | use <name>
|
|
260
|
-
|
|
261
|
-
alvera datalakes list | get <id> | create
|
|
262
|
-
alvera data-sources list <datalake> | create <datalake> | update <datalake> <id>
|
|
263
|
-
alvera tools list | get <id> | create | update <id> | delete <id>
|
|
264
|
-
alvera generic-tables list <datalake> | create <datalake>
|
|
265
|
-
alvera action-status-updaters list | create | update <id>
|
|
266
|
-
alvera ai-agents list <datalake> | get <datalake> <id> | create <datalake>
|
|
267
|
-
| update <datalake> <id> | delete <datalake> <id>
|
|
268
|
-
alvera sessions-verify
|
|
269
|
-
alvera datasets search <dataset> [--datalake-id] [--page] [--page-size]
|
|
270
|
-
alvera connected-apps list <datalake> | get <datalake> <id> | create <datalake>
|
|
271
|
-
| update <datalake> <id> | sync-routes <datalake> <id>
|
|
272
|
-
| resolve-page <slug> | update-message-tracking <slug>
|
|
273
|
-
alvera data-activation-clients ingest <slug> | ingest-file <slug> <key>
|
|
274
|
-
| upload-link <slug> <filename> [--content-type]
|
|
275
|
-
alvera mdm verify <datalake>
|
|
276
|
-
alvera workflows execute <workflow-slug>
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
All `create` / `update` commands require `--body '<json>'` or `--body-file <path>`
|
|
280
|
-
(use `-` for stdin). A tenant positional argument is optional when the profile
|
|
281
|
-
has a default tenant configured. Output is pretty-printed JSON on stdout;
|
|
282
|
-
status messages and prompts go to stderr so responses stay pipeable.
|
|
283
|
-
|
|
284
|
-
## Regenerating the typed client
|
|
285
|
-
|
|
286
|
-
The typed client is generated from `spec/openapi.yaml` using
|
|
287
|
-
[`@hey-api/openapi-ts`](https://heyapi.dev/). The spec is produced by the
|
|
288
|
-
platform repo and committed here, so this repo is fully self-contained at CI
|
|
289
|
-
time.
|
|
290
|
-
|
|
291
|
-
To pull a newer spec from the sibling platform repo:
|
|
292
|
-
|
|
293
|
-
```bash
|
|
294
|
-
# in the platform repo
|
|
295
|
-
mix openapi.spec.yaml --spec PlatformApi.ApiSpec openapi.yaml
|
|
296
|
-
git commit -am "feat(api): …"
|
|
297
|
-
|
|
298
|
-
# in this repo
|
|
299
|
-
cp ../platform/openapi.yaml spec/openapi.yaml
|
|
300
|
-
bun run regen # gen-environments + codegen + check-coverage
|
|
301
|
-
git commit -am "chore: sync openapi spec"
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
`bun run regen` runs `gen-environments` (rebuilds
|
|
305
|
-
`src/environments.generated.ts` from `servers[]`), then `codegen`, then
|
|
306
|
-
`check-coverage`.
|
|
307
|
-
|
|
308
|
-
## Releases
|
|
309
|
-
|
|
310
|
-
This package uses
|
|
311
|
-
[release-please](https://github.com/googleapis/release-please) plus
|
|
312
|
-
[Conventional Commits](https://www.conventionalcommits.org/). Commits on
|
|
313
|
-
`main` of the form `feat: …`, `fix: …`, `chore: …` feed into an automated
|
|
314
|
-
"chore(main): release X.Y.Z" PR that bumps `package.json` and updates
|
|
315
|
-
`CHANGELOG.md`. Merging that PR tags `vX.Y.Z`, which in turn triggers the
|
|
316
|
-
existing npm publish workflow.
|
|
317
|
-
|
|
318
|
-
## License
|
|
319
|
-
|
|
320
|
-
MIT
|
package/src/cli/auth.ts
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { createSession, createUnvalidatedPlatformApi, revokeSession } from '../client.js';
|
|
3
|
-
import {
|
|
4
|
-
CONFIG_PATHS,
|
|
5
|
-
ENVIRONMENTS,
|
|
6
|
-
clearProfileCreds,
|
|
7
|
-
getProfileName,
|
|
8
|
-
readProfileConfig,
|
|
9
|
-
resolveProfile,
|
|
10
|
-
writeProfileConfig,
|
|
11
|
-
writeProfileCreds,
|
|
12
|
-
} from '../config.js';
|
|
13
|
-
import { type GlobalOpts, authedApi, die, out, prompt, run } from './helpers.js';
|
|
14
|
-
|
|
15
|
-
const ENVIRONMENT_NAMES = Object.keys(ENVIRONMENTS);
|
|
16
|
-
|
|
17
|
-
export function register(program: Command): void {
|
|
18
|
-
program
|
|
19
|
-
.command('configure')
|
|
20
|
-
.description('Interactively set defaults (environment, tenant, email) for a profile')
|
|
21
|
-
.action(async () => {
|
|
22
|
-
const profile = getProfileName(program.opts<GlobalOpts>().profile);
|
|
23
|
-
const current = resolveProfile(profile);
|
|
24
|
-
const currentCfg = readProfileConfig(profile);
|
|
25
|
-
|
|
26
|
-
const options = ENVIRONMENT_NAMES.map(
|
|
27
|
-
(name) => `${name} (${ENVIRONMENTS[name as keyof typeof ENVIRONMENTS].base_url})`,
|
|
28
|
-
).join(', ');
|
|
29
|
-
const defaultChoice = currentCfg.environment ?? current.environment;
|
|
30
|
-
const envInput =
|
|
31
|
-
(await prompt(`Environment [${defaultChoice}] — one of: ${options}, or a custom URL: `)) ||
|
|
32
|
-
defaultChoice;
|
|
33
|
-
|
|
34
|
-
const patch: { environment?: string; base_url?: string; tenant_slug?: string; email?: string } = {};
|
|
35
|
-
const unset: Array<'environment' | 'base_url'> = [];
|
|
36
|
-
if (ENVIRONMENT_NAMES.includes(envInput)) {
|
|
37
|
-
patch.environment = envInput;
|
|
38
|
-
unset.push('base_url');
|
|
39
|
-
} else if (/^https?:\/\//.test(envInput)) {
|
|
40
|
-
patch.base_url = envInput;
|
|
41
|
-
unset.push('environment');
|
|
42
|
-
} else {
|
|
43
|
-
die(
|
|
44
|
-
`"${envInput}" is not a known environment or a URL. ` +
|
|
45
|
-
`Valid: ${ENVIRONMENT_NAMES.join(', ')} or http(s)://…`,
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
patch.tenant_slug =
|
|
50
|
-
(await prompt(`Default tenant slug [${current.tenantSlug ?? ''}]: `)) || current.tenantSlug || '';
|
|
51
|
-
patch.email = (await prompt(`Email [${current.email ?? ''}]: `)) || current.email || '';
|
|
52
|
-
writeProfileConfig(profile, patch, unset);
|
|
53
|
-
process.stderr.write(`Saved profile "${profile}" → ${CONFIG_PATHS.config}\n`);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
program
|
|
57
|
-
.command('login')
|
|
58
|
-
.description('Exchange credentials for a session token and store it')
|
|
59
|
-
.option('--email <email>')
|
|
60
|
-
.option('--password <password>')
|
|
61
|
-
.option('--tenant <slug>')
|
|
62
|
-
.option('--base-url <url>')
|
|
63
|
-
.option('--expires-in <seconds>', 'session duration (default 86400, max 2592000)')
|
|
64
|
-
.action(async (opts: Record<string, string>) => {
|
|
65
|
-
const profile = getProfileName(program.opts<GlobalOpts>().profile);
|
|
66
|
-
const current = resolveProfile(profile);
|
|
67
|
-
const baseUrl = opts.baseUrl ?? current.baseUrl;
|
|
68
|
-
const email = opts.email ?? current.email ?? (await prompt('Email: '));
|
|
69
|
-
const password = opts.password ?? process.env.ALVERA_PASSWORD ?? (await prompt('Password: ', { hidden: true }));
|
|
70
|
-
const tenant = opts.tenant ?? current.tenantSlug ?? (await prompt('Tenant slug: '));
|
|
71
|
-
if (!email || !password || !tenant) die('email, password, and tenant are required');
|
|
72
|
-
|
|
73
|
-
await run(async () => {
|
|
74
|
-
const session = await createSession({
|
|
75
|
-
baseUrl,
|
|
76
|
-
email,
|
|
77
|
-
password,
|
|
78
|
-
tenantSlug: tenant,
|
|
79
|
-
expiresIn: opts.expiresIn ? Number(opts.expiresIn) : undefined,
|
|
80
|
-
});
|
|
81
|
-
writeProfileConfig(profile, {
|
|
82
|
-
...(opts.baseUrl ? { base_url: baseUrl } : {}),
|
|
83
|
-
tenant_slug: tenant,
|
|
84
|
-
email,
|
|
85
|
-
});
|
|
86
|
-
clearProfileCreds(profile);
|
|
87
|
-
writeProfileCreds(profile, {
|
|
88
|
-
session_token: session.sessionToken,
|
|
89
|
-
expires_at: session.expiresAt ?? '',
|
|
90
|
-
});
|
|
91
|
-
const tenantLabel = session.tenant ? `tenant "${session.tenant.slug}"` : 'no tenant';
|
|
92
|
-
process.stderr.write(
|
|
93
|
-
`Logged in as ${email} → ${tenantLabel} (profile "${profile}").\n` +
|
|
94
|
-
`Token stored in ${CONFIG_PATHS.credentials}\n` +
|
|
95
|
-
(session.expiresAt ? `Expires at ${session.expiresAt}\n` : ''),
|
|
96
|
-
);
|
|
97
|
-
return undefined;
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
program
|
|
102
|
-
.command('logout')
|
|
103
|
-
.description('Revoke the current session and clear stored credentials')
|
|
104
|
-
.action(async () => {
|
|
105
|
-
const profile = getProfileName(program.opts<GlobalOpts>().profile);
|
|
106
|
-
const resolved = resolveProfile(profile);
|
|
107
|
-
if (resolved.sessionToken) {
|
|
108
|
-
createUnvalidatedPlatformApi({ baseUrl: resolved.baseUrl, sessionToken: resolved.sessionToken });
|
|
109
|
-
try {
|
|
110
|
-
await revokeSession();
|
|
111
|
-
} catch {
|
|
112
|
-
// Token may already be invalid/expired — clear local state anyway.
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
clearProfileCreds(profile);
|
|
116
|
-
process.stderr.write(`Cleared credentials for profile "${profile}".\n`);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
program
|
|
120
|
-
.command('whoami')
|
|
121
|
-
.description('Print the current profile configuration')
|
|
122
|
-
.action(() => {
|
|
123
|
-
const profile = getProfileName(program.opts<GlobalOpts>().profile);
|
|
124
|
-
const resolved = resolveProfile(profile);
|
|
125
|
-
out({
|
|
126
|
-
profile: resolved.profile,
|
|
127
|
-
environment: resolved.environment,
|
|
128
|
-
baseUrl: resolved.baseUrl,
|
|
129
|
-
tenantSlug: resolved.tenantSlug,
|
|
130
|
-
email: resolved.email,
|
|
131
|
-
hasSessionToken: Boolean(resolved.sessionToken),
|
|
132
|
-
expiresAt: resolved.expiresAt,
|
|
133
|
-
hasApiKey: Boolean(resolved.apiKey),
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
program
|
|
138
|
-
.command('set-api-key')
|
|
139
|
-
.description('Store an API key for the current profile (used instead of session token)')
|
|
140
|
-
.argument('[key]', 'API key (omit to read from prompt or ALVERA_API_KEY)')
|
|
141
|
-
.action(async (key?: string) => {
|
|
142
|
-
const profile = getProfileName(program.opts<GlobalOpts>().profile);
|
|
143
|
-
const apiKey = key ?? process.env.ALVERA_API_KEY ?? (await prompt('API key: ', { hidden: true }));
|
|
144
|
-
if (!apiKey) die('API key is required');
|
|
145
|
-
clearProfileCreds(profile);
|
|
146
|
-
writeProfileCreds(profile, { api_key: apiKey });
|
|
147
|
-
process.stderr.write(
|
|
148
|
-
`API key stored for profile "${profile}" → ${CONFIG_PATHS.credentials}\n` +
|
|
149
|
-
`(session token cleared)\n`,
|
|
150
|
-
);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
program
|
|
154
|
-
.command('ping')
|
|
155
|
-
.description('Health check')
|
|
156
|
-
.action(async () => {
|
|
157
|
-
await run(async () => {
|
|
158
|
-
const { api } = authedApi(program.opts<GlobalOpts>());
|
|
159
|
-
const { data } = await api.ping();
|
|
160
|
-
return data;
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
program
|
|
165
|
-
.command('sessions-verify')
|
|
166
|
-
.description('Verify the current session token via the API')
|
|
167
|
-
.action(async () => {
|
|
168
|
-
await run(async () => {
|
|
169
|
-
const { api } = authedApi(program.opts<GlobalOpts>());
|
|
170
|
-
const { data } = await api.sessions.verify();
|
|
171
|
-
return data;
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
}
|
package/src/cli/env.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import {
|
|
3
|
-
DEFAULT_ENVIRONMENT,
|
|
4
|
-
ENVIRONMENTS,
|
|
5
|
-
getProfileName,
|
|
6
|
-
resolveProfile,
|
|
7
|
-
writeProfileConfig,
|
|
8
|
-
} from '../config.js';
|
|
9
|
-
import { type GlobalOpts, die, out } from './helpers.js';
|
|
10
|
-
|
|
11
|
-
const ENVIRONMENT_NAMES = Object.keys(ENVIRONMENTS);
|
|
12
|
-
|
|
13
|
-
export function register(program: Command): void {
|
|
14
|
-
const envCmd = program
|
|
15
|
-
.command('env')
|
|
16
|
-
.description('List and switch Alvera API environments');
|
|
17
|
-
|
|
18
|
-
envCmd
|
|
19
|
-
.command('list')
|
|
20
|
-
.description('List available environments (from spec/openapi.yaml)')
|
|
21
|
-
.action(() => {
|
|
22
|
-
const profile = getProfileName(program.opts<GlobalOpts>().profile);
|
|
23
|
-
const resolved = resolveProfile(profile);
|
|
24
|
-
out(
|
|
25
|
-
ENVIRONMENT_NAMES.map((name) => ({
|
|
26
|
-
name,
|
|
27
|
-
baseUrl: ENVIRONMENTS[name as keyof typeof ENVIRONMENTS].base_url,
|
|
28
|
-
description: ENVIRONMENTS[name as keyof typeof ENVIRONMENTS].description,
|
|
29
|
-
default: name === DEFAULT_ENVIRONMENT,
|
|
30
|
-
active: name === resolved.environment,
|
|
31
|
-
})),
|
|
32
|
-
);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
envCmd
|
|
36
|
-
.command('use <name>')
|
|
37
|
-
.description('Persist the selected environment to the profile (clears any custom base_url)')
|
|
38
|
-
.action((name: string) => {
|
|
39
|
-
if (!ENVIRONMENT_NAMES.includes(name)) {
|
|
40
|
-
die(`unknown environment "${name}". Valid: ${ENVIRONMENT_NAMES.join(', ')}`);
|
|
41
|
-
}
|
|
42
|
-
const profile = getProfileName(program.opts<GlobalOpts>().profile);
|
|
43
|
-
writeProfileConfig(profile, { environment: name }, ['base_url']);
|
|
44
|
-
process.stderr.write(
|
|
45
|
-
`Profile "${profile}" now uses environment "${name}" ` +
|
|
46
|
-
`(${ENVIRONMENTS[name as keyof typeof ENVIRONMENTS].base_url}).\n`,
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
}
|