@alvera-ai/platform-sdk 0.8.0 → 0.10.0-rc.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/package.json CHANGED
@@ -1,46 +1,43 @@
1
1
  {
2
2
  "name": "@alvera-ai/platform-sdk",
3
- "version": "0.8.0",
3
+ "version": "0.10.0-rc.1",
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": "./src/index.ts",
8
- "module": "./src/index.ts",
9
- "types": "./src/index.ts",
7
+ "main": "./dist/index.mjs",
8
+ "module": "./dist/index.mjs",
9
+ "types": "./dist/index.d.mts",
10
10
  "exports": {
11
11
  ".": {
12
- "types": "./src/index.ts",
13
- "import": "./src/index.ts"
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
- "src",
17
+ "dist",
21
18
  "README.md",
22
19
  "LICENSE"
23
20
  ],
24
21
  "engines": {
25
22
  "node": ">=20"
26
23
  },
27
- "packageManager": "pnpm@10.20.0",
28
24
  "scripts": {
29
25
  "gen-environments": "tsx scripts/gen-environments.ts",
30
26
  "codegen": "openapi-ts && tsx scripts/patch-generated.ts",
31
27
  "check-coverage": "tsx scripts/check-sdk-coverage.ts",
32
- "regen": "pnpm gen-environments && pnpm codegen && pnpm check-coverage",
28
+ "regen": "bun run gen-environments && bun run codegen && bun run check-coverage",
29
+ "build": "tsdown",
33
30
  "typecheck": "tsc --noEmit && tsc --noEmit -p scripts/tsconfig.json",
34
- "clean": "rm -rf src/generated src/environments.generated.ts",
35
- "prepare": "pnpm gen-environments && pnpm codegen && pnpm 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"
36
33
  },
37
34
  "dependencies": {
38
- "commander": "14.0.3",
39
35
  "valibot": "1.2.0"
40
36
  },
41
37
  "devDependencies": {
42
38
  "@hey-api/openapi-ts": "0.96.0",
43
39
  "@types/node": "^25.3.3",
40
+ "tsdown": "^0.16.0",
44
41
  "tsx": "^4.19.2",
45
42
  "typescript": "5.9.3",
46
43
  "yaml": "2.6.1"
@@ -59,9 +56,10 @@
59
56
  "author": "Alvera",
60
57
  "repository": {
61
58
  "type": "git",
62
- "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"
63
61
  },
64
- "homepage": "https://github.com/alvera-ai/platform-sdk#readme",
62
+ "homepage": "https://github.com/alvera-ai/platform-sdk/tree/main/packages/sdk#readme",
65
63
  "bugs": {
66
64
  "url": "https://github.com/alvera-ai/platform-sdk/issues"
67
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,319 +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
- pnpm add @alvera-ai/platform-sdk
14
- ```
15
-
16
- ## TypeScript configuration
17
-
18
- The SDK uses [`@hey-api/client-fetch`](https://heyapi.dev/openapi-ts/clients/fetch),
19
- whose generated code references WHATWG fetch types — `BodyInit`,
20
- `RequestInit`, `Headers`, `FormData`, etc. Those names live in
21
- `lib.dom.d.ts`, not `@types/node`, so a Node-only consumer with
22
- `"lib": ["ES2022"]` in its `tsconfig.json` will see errors like
23
- `Cannot find name 'BodyInit'` when typechecking.
24
-
25
- The fix is to add `DOM` and `DOM.Iterable` to your `lib`:
26
-
27
- ```jsonc
28
- // tsconfig.json
29
- {
30
- "compilerOptions": {
31
- "lib": ["ES2022", "DOM", "DOM.Iterable"]
32
- // ^^^^^^^^^^^^^^^^^^^^^^^
33
- // Required by @hey-api/client-fetch — see
34
- // https://github.com/hey-api/openapi-ts/issues/2539
35
- // Provides type-only declarations for fetch globals.
36
- // Adds NOTHING to the runtime — Node 18+ provides real fetch
37
- // independently of these types.
38
- }
39
- }
40
- ```
41
-
42
- This is the workaround documented in hey-api's open issue
43
- [#2539](https://github.com/hey-api/openapi-ts/issues/2539); when
44
- the upstream fix lands and emits self-contained types, you can
45
- drop the `DOM` lib entries again.
46
-
47
- Browser consumers (React, Vue, Next, Nuxt, Remix) already have
48
- `DOM` and `DOM.Iterable` enabled by default — no change needed.
49
-
50
- ## Quick start
51
-
52
- ```ts
53
- import { createPlatformApi, createSession, ENVIRONMENTS } from '@alvera-ai/platform-sdk';
54
-
55
- const baseUrl = ENVIRONMENTS.prod.base_url; // or ENVIRONMENTS.local / ENVIRONMENTS.demo
56
-
57
- // 1. Exchange credentials for a session token
58
- const session = await createSession({
59
- baseUrl,
60
- email: process.env.ALVERA_EMAIL!,
61
- password: process.env.ALVERA_PASSWORD!,
62
- tenantSlug: 'acme',
63
- });
64
-
65
- // 2. Build the API client with that token
66
- const api = createPlatformApi({ baseUrl, sessionToken: session.sessionToken });
67
-
68
- // 3. Use it
69
- await api.ping();
70
-
71
- const { data: datalakes } = await api.datalakes.list('acme');
72
-
73
- const { data: ds } = await api.dataSources.create('acme', 'acme-health', {
74
- name: 'Acme EMR',
75
- uri: 'our-emr:acme',
76
- description: 'Acme EMR system',
77
- status: 'active',
78
- is_default: true,
79
- });
80
-
81
- const { data: tool } = await api.tools.create('acme', {
82
- name: 'Acme Manual Upload',
83
- intent: 'data_exchange',
84
- status: 'active',
85
- datalake_id: datalakes[0].id,
86
- data_source_id: ds.id,
87
- body: { __type__: 'manual_upload' },
88
- });
89
- ```
90
-
91
- ## Authentication
92
-
93
- The SDK uses **session-based** auth.
94
-
95
- 1. Call `createSession({ baseUrl, email, password, tenantSlug })` with your
96
- Alvera login credentials and the tenant you want to operate on.
97
- 2. The returned `sessionToken` is a Bearer token, valid for 24 hours by
98
- default (override with `expiresIn`, max 30 days).
99
- 3. Pass the token into `createPlatformApi({ baseUrl, sessionToken })`.
100
- 4. When done, optionally call `revokeSession()` to invalidate the token.
101
-
102
- ```ts
103
- import { createSession, createPlatformApi, revokeSession } from '@alvera-ai/platform-sdk';
104
-
105
- const session = await createSession({
106
- baseUrl, email, password, tenantSlug: 'acme', expiresIn: 3600,
107
- });
108
- const api = createPlatformApi({ baseUrl, sessionToken: session.sessionToken });
109
- // ... use api ...
110
- await revokeSession();
111
- ```
112
-
113
- `session.expiresAt` is an ISO-8601 timestamp — check it before long-running
114
- work and re-authenticate if needed.
115
-
116
- ## Environments
117
-
118
- The base URLs ship with the package, derived at build time from the
119
- `servers[]` block of the committed OpenAPI spec (`spec/openapi.yaml`). The
120
- generated map is exported as `ENVIRONMENTS`:
121
-
122
- ```ts
123
- import { ENVIRONMENTS, DEFAULT_ENVIRONMENT } from '@alvera-ai/platform-sdk';
124
-
125
- ENVIRONMENTS.local.base_url; // http://localhost:4000
126
- ENVIRONMENTS.demo.base_url; // https://platform-hh.alvera.ai
127
- ENVIRONMENTS.prod.base_url; // https://app.alvera.ai
128
-
129
- DEFAULT_ENVIRONMENT; // 'prod'
130
- ```
131
-
132
- The CLI resolves a base URL with this precedence (highest first):
133
-
134
- 1. `ALVERA_BASE_URL` env var (explicit URL override — useful for tunnels /
135
- ephemeral servers)
136
- 2. `base_url` pinned in the profile (written when the user passes a custom URL
137
- to `alvera configure` or `alvera login --base-url …`)
138
- 3. `ENVIRONMENTS[env].base_url` where `env` is the first of: `--env <name>`
139
- flag, `ALVERA_ENV` env var, the profile's `environment` entry, or
140
- `DEFAULT_ENVIRONMENT`
141
-
142
- Adding, renaming, or removing environments happens in the platform repo (the
143
- `servers/0` function in `lib/platform_api/api_spec.ex`); rerun
144
- `pnpm regen` in the SDK to pick up the change.
145
-
146
- ## Resources
147
-
148
- | Resource | Operations |
149
- |------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------|
150
- | `ping` | health check |
151
- | `sessions` | `verify` |
152
- | `auth` | `signUp` |
153
- | `admin` | `confirmUser` |
154
- | `tenants` | `list`, `create` |
155
- | `invitations` | `list`, `create`, `accept` |
156
- | `datasets` | `search`, `metadata`, `createUserSearch` |
157
- | `datalakes` | `list`, `get`, `create`, `metadata`, `migrate`, `createUploadLink`, `createDownloadLink` |
158
- | `dataSources` | `list`, `create`, `update` |
159
- | `tools` | `list`, `get`, `create`, `update`, `delete`, `testInvocation` |
160
- | `genericTables` | `list`, `create` |
161
- | `actionStatusUpdaters` | `list`, `create`, `update` |
162
- | `aiAgents` | `list`, `get`, `create`, `update`, `delete` |
163
- | `connectedApps` | `list`, `get`, `create`, `update`, `syncRoutes`, `resolvePage`, `updateMessageTracking` |
164
- | `dataActivationClients` | `list`, `get`, `create`, `update`, `delete`, `metadata`, `runManually`, `ingest`, `ingestFile`, `logs.list`, `logs.get` |
165
- | `interoperabilityContracts` | `list`, `get`, `create`, `update`, `delete`, `metadata`, `run` |
166
- | `mdm` | `verify` |
167
- | `workflows` | `list`, `get`, `create`, `update`, `delete`, `metadata`, `execute`, `run`, `workflowLogs.list/get/download`, `batchLogs.list/get/start/stop/refresh` |
168
-
169
- Tenant and datalake provisioning are performed by Alvera admins — contact your
170
- representative to onboard a new tenant.
171
-
172
- ## Error handling
173
-
174
- All methods throw on non-2xx responses (`throwOnError: true`). Wrap calls in
175
- `try/catch` and inspect the thrown error for status and response body.
176
-
177
- ```ts
178
- try {
179
- await api.tools.create('acme', payload);
180
- } catch (err) {
181
- console.error('Tool creation failed:', err);
182
- }
183
- ```
184
-
185
- ## CLI
186
-
187
- The package ships a companion CLI (`alvera`) for ad-hoc calls against the
188
- platform API. Install the package (globally, or via `npx`) and authenticate
189
- once — subsequent commands reuse the stored session.
190
-
191
- ```bash
192
- # Run without installing
193
- npx @alvera-ai/platform-sdk --help
194
-
195
- # Or install globally
196
- npm install -g @alvera-ai/platform-sdk
197
- alvera --help
198
- ```
199
-
200
- ### Configuration
201
-
202
- `alvera` stores state under `~/.alvera-ai/`, AWS CLI–style:
203
-
204
- | File | Purpose |
205
- |-----------------------------|---------------------------------------------------|
206
- | `~/.alvera-ai/config` | Per-profile defaults (base URL, tenant, email) |
207
- | `~/.alvera-ai/credentials` | Per-profile session token and expiration (0600) |
208
-
209
- Both files are INI. The default profile is `[default]`; additional profiles
210
- live under `[profile <name>]` in `config` and `[<name>]` in `credentials`.
211
-
212
- Every command accepts `--profile <name>` and `--env <name>`. Environment
213
- variables (`ALVERA_PROFILE`, `ALVERA_ENV`, `ALVERA_BASE_URL`, `ALVERA_TENANT`,
214
- `ALVERA_EMAIL`, `ALVERA_PASSWORD`, `ALVERA_SESSION_TOKEN`) take precedence
215
- over file values.
216
-
217
- ### Getting started
218
-
219
- ```bash
220
- alvera env list # show local / demo / prod
221
- alvera configure # pick environment + default tenant
222
- alvera login --email me@acme.com --tenant acme
223
- alvera ping
224
- alvera datalakes list
225
- alvera tools create --body-file tool.json
226
- alvera logout
227
- ```
228
-
229
- Per-command env switch (no profile edit):
230
-
231
- ```bash
232
- alvera --env local ping
233
- ALVERA_ENV=demo alvera datalakes list
234
- ```
235
-
236
- Pin an env into a profile:
237
-
238
- ```bash
239
- alvera --profile staging env use demo
240
- alvera --profile staging datalakes list
241
- ```
242
-
243
- Override the base URL for an ad-hoc host (tunnels, local branches):
244
-
245
- ```bash
246
- ALVERA_BASE_URL=https://pr-123.preview.alvera.ai alvera ping
247
- ```
248
-
249
- ### Command surface
250
-
251
- ```
252
- alvera configure
253
- alvera login [--email] [--password] [--tenant] [--base-url] [--expires-in]
254
- alvera logout
255
- alvera whoami
256
- alvera ping
257
- alvera env list | use <name>
258
-
259
- alvera datalakes list | get <id> | create
260
- alvera data-sources list <datalake> | create <datalake> | update <datalake> <id>
261
- alvera tools list | get <id> | create | update <id> | delete <id>
262
- alvera generic-tables list <datalake> | create <datalake>
263
- alvera action-status-updaters list | create | update <id>
264
- alvera ai-agents list <datalake> | get <datalake> <id> | create <datalake>
265
- | update <datalake> <id> | delete <datalake> <id>
266
- alvera sessions-verify
267
- alvera datasets search <dataset> [--datalake-id] [--page] [--page-size]
268
- alvera connected-apps list <datalake> | get <datalake> <id> | create <datalake>
269
- | update <datalake> <id> | sync-routes <datalake> <id>
270
- | resolve-page <slug> | update-message-tracking <slug>
271
- alvera data-activation-clients ingest <slug> | ingest-file <slug> <key>
272
- | upload-link <slug> <filename> [--content-type]
273
- alvera mdm verify <datalake>
274
- alvera workflows execute <workflow-slug>
275
- ```
276
-
277
- All `create` / `update` commands require `--body '<json>'` or `--body-file <path>`
278
- (use `-` for stdin). A tenant positional argument is optional when the profile
279
- has a default tenant configured. Output is pretty-printed JSON on stdout;
280
- status messages and prompts go to stderr so responses stay pipeable.
281
-
282
- ## Regenerating the typed client
283
-
284
- The typed client is generated from `spec/openapi.yaml` using
285
- [`@hey-api/openapi-ts`](https://heyapi.dev/). The spec is produced by the
286
- platform repo and committed here, so this repo is fully self-contained at CI
287
- time.
288
-
289
- To pull a newer spec from the sibling platform repo:
290
-
291
- ```bash
292
- # in the platform repo
293
- mix openapi.spec.yaml --spec PlatformApi.ApiSpec openapi.yaml
294
- git commit -am "feat(api): …"
295
-
296
- # in this repo
297
- cp ../platform/openapi.yaml spec/openapi.yaml
298
- pnpm regen # gen-environments + codegen + check-coverage
299
- pnpm build # compile to dist/
300
- git commit -am "chore: sync openapi spec"
301
- ```
302
-
303
- `pnpm regen` runs `gen-environments` (rebuilds
304
- `src/environments.generated.ts` from `servers[]`), then `codegen`, then
305
- `check-coverage`.
306
-
307
- ## Releases
308
-
309
- This package uses
310
- [release-please](https://github.com/googleapis/release-please) plus
311
- [Conventional Commits](https://www.conventionalcommits.org/). Commits on
312
- `main` of the form `feat: …`, `fix: …`, `chore: …` feed into an automated
313
- "chore(main): release X.Y.Z" PR that bumps `package.json` and updates
314
- `CHANGELOG.md`. Merging that PR tags `vX.Y.Z`, which in turn triggers the
315
- existing npm publish workflow.
316
-
317
- ## License
318
-
319
- 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
- }