@alvera-ai/platform-sdk 0.7.3 → 0.9.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 +25 -19
- package/package.json +3 -4
- package/src/cli/auth.ts +174 -0
- package/src/cli/env.ts +49 -0
- package/src/cli/helpers.ts +128 -0
- package/src/cli/init.ts +123 -0
- package/src/cli/raw.ts +65 -0
- package/src/cli/resources.ts +789 -0
- package/src/cli/workflows.ts +246 -0
- package/src/cli.ts +15 -1347
- package/src/client.ts +30 -8
- package/src/config.ts +4 -0
- package/src/generated/sdk.gen.ts +932 -932
- package/src/generated/types.gen.ts +7220 -7220
- package/src/generated/valibot.gen.ts +4349 -4341
- package/src/index.ts +1 -0
package/src/client.ts
CHANGED
|
@@ -317,10 +317,9 @@ export async function revokeSession(): Promise<void> {
|
|
|
317
317
|
// Config
|
|
318
318
|
// ---------------------------------------------------------------------------
|
|
319
319
|
|
|
320
|
-
export
|
|
321
|
-
baseUrl: string;
|
|
322
|
-
|
|
323
|
-
}
|
|
320
|
+
export type ApiConfig =
|
|
321
|
+
| { baseUrl: string; sessionToken: string }
|
|
322
|
+
| { baseUrl: string; apiKey: string };
|
|
324
323
|
|
|
325
324
|
// ---------------------------------------------------------------------------
|
|
326
325
|
// Factories — two named entry points
|
|
@@ -359,17 +358,40 @@ export interface DatasetMetadataOptions {
|
|
|
359
358
|
genericTableId?: string;
|
|
360
359
|
}
|
|
361
360
|
|
|
361
|
+
function authHeaders(config: ApiConfig): Record<string, string> {
|
|
362
|
+
if ('apiKey' in config) return { 'X-API-Key': config.apiKey };
|
|
363
|
+
return { Authorization: `Bearer ${config.sessionToken}` };
|
|
364
|
+
}
|
|
365
|
+
|
|
362
366
|
export function createPlatformApi(config: ApiConfig): PlatformApi {
|
|
363
367
|
const baseUrl = config.baseUrl.replace(/\/$/, '');
|
|
364
|
-
|
|
365
|
-
client.setConfig({ baseUrl, headers });
|
|
368
|
+
client.setConfig({ baseUrl, headers: authHeaders(config) });
|
|
366
369
|
return _buildApi(client);
|
|
367
370
|
}
|
|
368
371
|
|
|
369
372
|
export function createIsolatedPlatformApi(config: ApiConfig): PlatformApi {
|
|
370
373
|
const baseUrl = config.baseUrl.replace(/\/$/, '');
|
|
371
|
-
|
|
372
|
-
|
|
374
|
+
return _buildApi(createClient({ baseUrl, headers: authHeaders(config) }));
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export function createUnvalidatedPlatformApi(config: ApiConfig): PlatformApi {
|
|
378
|
+
const baseUrl = config.baseUrl.replace(/\/$/, '');
|
|
379
|
+
const inner = createClient({ baseUrl, headers: authHeaders(config) });
|
|
380
|
+
const strip = (options: Record<string, unknown>) => {
|
|
381
|
+
const { responseValidator: _, ...rest } = options;
|
|
382
|
+
return rest;
|
|
383
|
+
};
|
|
384
|
+
const unvalidated = new Proxy(inner, {
|
|
385
|
+
get(target, prop, receiver) {
|
|
386
|
+
const val = Reflect.get(target, prop, receiver);
|
|
387
|
+
if (typeof val === 'function' && typeof prop === 'string' &&
|
|
388
|
+
['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'request'].includes(prop)) {
|
|
389
|
+
return (options: Record<string, unknown>) => val.call(target, strip(options));
|
|
390
|
+
}
|
|
391
|
+
return val;
|
|
392
|
+
},
|
|
393
|
+
}) as Client;
|
|
394
|
+
return _buildApi(unvalidated);
|
|
373
395
|
}
|
|
374
396
|
|
|
375
397
|
function _buildApi(myClient: Client) {
|
package/src/config.ts
CHANGED
|
@@ -23,6 +23,7 @@ export interface ProfileConfig {
|
|
|
23
23
|
export interface ProfileCreds {
|
|
24
24
|
session_token?: string;
|
|
25
25
|
expires_at?: string;
|
|
26
|
+
api_key?: string;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export interface ResolvedProfile {
|
|
@@ -33,6 +34,7 @@ export interface ResolvedProfile {
|
|
|
33
34
|
email: string | null;
|
|
34
35
|
sessionToken: string | null;
|
|
35
36
|
expiresAt: string | null;
|
|
37
|
+
apiKey: string | null;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
function isEnvironmentName(name: string): name is EnvironmentName {
|
|
@@ -195,6 +197,8 @@ export function resolveProfile(profile: string): ResolvedProfile {
|
|
|
195
197
|
sessionToken:
|
|
196
198
|
process.env.ALVERA_SESSION_TOKEN ?? creds.session_token ?? null,
|
|
197
199
|
expiresAt: creds.expires_at ?? null,
|
|
200
|
+
apiKey:
|
|
201
|
+
process.env.ALVERA_API_KEY ?? creds.api_key ?? null,
|
|
198
202
|
};
|
|
199
203
|
}
|
|
200
204
|
|