@tryvira/sdk 0.1.94 → 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 CHANGED
@@ -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 OAuth, pass `accessTokenProvider: async () => token` to
218
- `ViraClient`. The provider is called for each API request and its result is
219
- sent only as `Authorization: Bearer`; keep refresh, expiry, and revocation
220
- handling in the host's secure credential store. When configured, this provider
221
- takes precedence over `apiKey`. Existing scoped API-key configuration remains
222
- supported.
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
- accessTokenProvider;
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.accessTokenProvider = options.accessTokenProvider;
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.accessTokenProvider) {
261
- const accessToken = (await this.accessTokenProvider())?.trim();
262
- if (!accessToken) throw new Error("SDK_ACCESS_TOKEN_REQUIRED");
263
- headers.authorization = `Bearer ${accessToken}`;
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 {
@@ -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
- /** Host-managed OAuth access token provider; called once per API request. */
23
- accessTokenProvider?: () => string | null | undefined | Promise<string | null | undefined>;
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 accessTokenProvider?;
936
+ private readonly apiCredentialProvider?;
934
937
  private readonly operatorDelegationTokenProvider?;
935
938
  private readonly fetcher;
936
939
  private readonly timeoutMs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryvira/sdk",
3
- "version": "0.1.94",
3
+ "version": "0.1.95",
4
4
  "description": "Typed Vira SDK for connect-once, observation and governed runtime execution.",
5
5
  "keywords": [
6
6
  "vira",