@tryvira/sdk 0.1.93 → 0.1.95
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 +9 -7
- package/dist/index.js +8 -6
- package/dist/sdks/js-client.d.ts +6 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Compound execution plans can be persisted with `saveCompoundTaskPlan(plan, {idem
|
|
|
15
15
|
## Install
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
npm install @tryvira/sdk@0.1.
|
|
18
|
+
npm install @tryvira/sdk@0.1.94
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
Configure the organization, project, and environment for every request. Keep the API
|
|
@@ -214,12 +214,14 @@ const events = await vira.listTaskRunEvents("customer-report-run-001");
|
|
|
214
214
|
- Send an idempotency key with mutations.
|
|
215
215
|
- Treat `401`/`403` as credential or scope errors; do not retry blindly.
|
|
216
216
|
|
|
217
|
-
For host-managed
|
|
218
|
-
`ViraClient`. The provider is called
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
217
|
+
For a host-managed, rotating Vira customer API key, pass
|
|
218
|
+
`apiCredentialProvider: async () => key` to `ViraClient`. The provider is called
|
|
219
|
+
for each API request and sends the credential in `x-vira-api-key`; Vira resolves
|
|
220
|
+
the tenant from that persisted credential. Supabase/Better Auth OAuth access
|
|
221
|
+
tokens are identity tokens, not Vira API credentials, and are rejected by this
|
|
222
|
+
client. The deprecated `accessTokenProvider` option remains as a compatibility
|
|
223
|
+
alias and has the same Vira API-key requirement. When either provider is set,
|
|
224
|
+
it takes precedence over `apiKey`.
|
|
223
225
|
- Treat a runtime deny or abstain as a governed decision, not permission to bypass Vira.
|
|
224
226
|
- Persist request IDs and receipts with application logs for support and audit.
|
|
225
227
|
|
package/dist/index.js
CHANGED
|
@@ -113,7 +113,7 @@ var ViraClient = class {
|
|
|
113
113
|
packs;
|
|
114
114
|
baseUrl;
|
|
115
115
|
apiKey;
|
|
116
|
-
|
|
116
|
+
apiCredentialProvider;
|
|
117
117
|
operatorDelegationTokenProvider;
|
|
118
118
|
fetcher;
|
|
119
119
|
timeoutMs;
|
|
@@ -124,7 +124,7 @@ var ViraClient = class {
|
|
|
124
124
|
constructor(options) {
|
|
125
125
|
this.baseUrl = normalizeBaseUrl(options.baseUrl, options.allowInsecureLocalhost === true);
|
|
126
126
|
this.apiKey = options.apiKey;
|
|
127
|
-
this.
|
|
127
|
+
this.apiCredentialProvider = options.apiCredentialProvider ?? options.accessTokenProvider;
|
|
128
128
|
this.operatorDelegationTokenProvider = options.operatorDelegationTokenProvider;
|
|
129
129
|
this.fetcher = options.fetcher ?? fetch;
|
|
130
130
|
this.timeoutMs = Math.max(
|
|
@@ -257,10 +257,12 @@ var ViraClient = class {
|
|
|
257
257
|
const delegation = (await this.operatorDelegationTokenProvider?.())?.trim();
|
|
258
258
|
if (!delegation) throw new Error("SDK_OPERATOR_DELEGATION_REQUIRED");
|
|
259
259
|
headers["x-vira-delegation"] = delegation;
|
|
260
|
-
} else if (this.
|
|
261
|
-
const
|
|
262
|
-
if (!
|
|
263
|
-
|
|
260
|
+
} else if (this.apiCredentialProvider) {
|
|
261
|
+
const credential = (await this.apiCredentialProvider())?.trim();
|
|
262
|
+
if (!credential) throw new Error("SDK_API_CREDENTIAL_REQUIRED");
|
|
263
|
+
if (/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(credential))
|
|
264
|
+
throw new Error("SDK_OAUTH_IDENTITY_TOKEN_UNSUPPORTED");
|
|
265
|
+
headers["x-vira-api-key"] = credential;
|
|
264
266
|
} else if (this.apiKey) {
|
|
265
267
|
if (this.apiKey.startsWith("vira_live_")) headers["x-vira-api-key"] = this.apiKey;
|
|
266
268
|
else {
|
package/dist/sdks/js-client.d.ts
CHANGED
|
@@ -14,13 +14,16 @@ export interface SdkRequest {
|
|
|
14
14
|
body?: Readonly<Record<string, unknown>>;
|
|
15
15
|
}
|
|
16
16
|
export type SdkFailureMode = "throw" | "open";
|
|
17
|
+
export type ViraApiCredentialProvider = () => string | null | undefined | Promise<string | null | undefined>;
|
|
17
18
|
export interface ViraClientOptions {
|
|
18
19
|
baseUrl: string;
|
|
19
20
|
/** Explicit opt-in for plain HTTP on loopback during local development only. */
|
|
20
21
|
allowInsecureLocalhost?: boolean;
|
|
21
22
|
apiKey?: string;
|
|
22
|
-
/**
|
|
23
|
-
|
|
23
|
+
/** Returns a Vira customer API key; called once per API request. Never pass a Supabase/Better Auth OAuth JWT. */
|
|
24
|
+
apiCredentialProvider?: ViraApiCredentialProvider;
|
|
25
|
+
/** @deprecated Use apiCredentialProvider. This has always been a Vira credential slot, not an OAuth-token exchange. */
|
|
26
|
+
accessTokenProvider?: ViraApiCredentialProvider;
|
|
24
27
|
/** Server-side only: fresh Studio-signed operator delegation, never a browser OAuth token. */
|
|
25
28
|
operatorDelegationTokenProvider?: () => string | null | undefined | Promise<string | null | undefined>;
|
|
26
29
|
fetcher?: typeof fetch;
|
|
@@ -930,7 +933,7 @@ export declare class ViraClient {
|
|
|
930
933
|
readonly packs: ViraLearningNamespaces['packs'];
|
|
931
934
|
private readonly baseUrl;
|
|
932
935
|
private readonly apiKey?;
|
|
933
|
-
private readonly
|
|
936
|
+
private readonly apiCredentialProvider?;
|
|
934
937
|
private readonly operatorDelegationTokenProvider?;
|
|
935
938
|
private readonly fetcher;
|
|
936
939
|
private readonly timeoutMs;
|