@opendatalabs/vana-sdk 3.20.1 → 3.22.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.
Files changed (40) hide show
  1. package/README.md +64 -0
  2. package/dist/direct/access-request-client.cjs +100 -2
  3. package/dist/direct/access-request-client.cjs.map +1 -1
  4. package/dist/direct/access-request-client.d.ts +23 -1
  5. package/dist/direct/access-request-client.js +98 -1
  6. package/dist/direct/access-request-client.js.map +1 -1
  7. package/dist/direct/controller.cjs +4 -0
  8. package/dist/direct/controller.cjs.map +1 -1
  9. package/dist/direct/controller.d.ts +10 -1
  10. package/dist/direct/controller.js +6 -1
  11. package/dist/direct/controller.js.map +1 -1
  12. package/dist/direct/types.cjs.map +1 -1
  13. package/dist/direct/types.d.ts +45 -0
  14. package/dist/direct/types.js.map +1 -1
  15. package/dist/index.browser.d.ts +2 -1
  16. package/dist/index.browser.js +186 -0
  17. package/dist/index.browser.js.map +4 -4
  18. package/dist/index.node.cjs +196 -0
  19. package/dist/index.node.cjs.map +4 -4
  20. package/dist/index.node.d.ts +2 -1
  21. package/dist/index.node.js +186 -0
  22. package/dist/index.node.js.map +4 -4
  23. package/dist/protocol/derivative-questions.cjs +22 -0
  24. package/dist/protocol/derivative-questions.cjs.map +1 -1
  25. package/dist/protocol/derivative-questions.d.ts +53 -0
  26. package/dist/protocol/derivative-questions.js +19 -0
  27. package/dist/protocol/derivative-questions.js.map +1 -1
  28. package/dist/protocol/derivative-status.cjs +209 -0
  29. package/dist/protocol/derivative-status.cjs.map +1 -0
  30. package/dist/protocol/derivative-status.d.ts +196 -0
  31. package/dist/protocol/derivative-status.js +190 -0
  32. package/dist/protocol/derivative-status.js.map +1 -0
  33. package/dist/protocol/derivative-status.test.d.ts +1 -0
  34. package/dist/server.cjs +4 -2
  35. package/dist/server.cjs.map +1 -1
  36. package/dist/server.d.ts +2 -2
  37. package/dist/server.js +4 -2
  38. package/dist/server.js.map +1 -1
  39. package/dist/tests/mock-personal-server.d.ts +9 -0
  40. package/package.json +1 -1
@@ -1186,9 +1186,13 @@ __export(index_node_exports, {
1186
1186
  ContractNotFoundError: () => ContractNotFoundError,
1187
1187
  DATA_ACCESS_OP_TYPE: () => DATA_ACCESS_OP_TYPE,
1188
1188
  DATA_REGISTRY_STATUS_ABI: () => DATA_REGISTRY_STATUS_ABI,
1189
+ DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS: () => DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS,
1190
+ DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS: () => DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS,
1189
1191
  DEFAULT_QUESTION_POLL_INTERVAL_MS: () => DEFAULT_QUESTION_POLL_INTERVAL_MS,
1190
1192
  DEFAULT_QUESTION_TIMEOUT_MS: () => DEFAULT_QUESTION_TIMEOUT_MS,
1193
+ DERIVATIVE_ERROR_CODES: () => DERIVATIVE_ERROR_CODES,
1191
1194
  DERIVATIVE_QUESTIONS_PATH: () => DERIVATIVE_QUESTIONS_PATH,
1195
+ DERIVATIVE_STATUS_PATH: () => DERIVATIVE_STATUS_PATH,
1192
1196
  DataFileEnvelopeSchema: () => DataFileEnvelopeSchema,
1193
1197
  DataPointDeletedError: () => DataPointDeletedError,
1194
1198
  DataPointNotFoundError: () => DataPointNotFoundError,
@@ -1197,6 +1201,7 @@ __export(index_node_exports, {
1197
1201
  DerivativeComputeUnavailableError: () => DerivativeComputeUnavailableError,
1198
1202
  DerivativeCycleError: () => DerivativeCycleError,
1199
1203
  DerivativeDerivedScopeRequiredError: () => DerivativeDerivedScopeRequiredError,
1204
+ DerivativeErrorCodeSchema: () => DerivativeErrorCodeSchema,
1200
1205
  DerivativeQuestionFailedError: () => DerivativeQuestionFailedError,
1201
1206
  DerivativeQuestionInvalidError: () => DerivativeQuestionInvalidError,
1202
1207
  DerivativeQuestionNotFoundError: () => DerivativeQuestionNotFoundError,
@@ -1204,6 +1209,7 @@ __export(index_node_exports, {
1204
1209
  DerivativeQuestionSchema: () => DerivativeQuestionSchema,
1205
1210
  DerivativeQuestionTimeoutError: () => DerivativeQuestionTimeoutError,
1206
1211
  DerivativeSourceNotGrantedError: () => DerivativeSourceNotGrantedError,
1212
+ DerivativeStatusSchema: () => DerivativeStatusSchema,
1207
1213
  DropboxStorage: () => DropboxStorage,
1208
1214
  ECIESError: () => ECIESError,
1209
1215
  ESCROW_DEPOSIT_ABI: () => ESCROW_DEPOSIT_ABI2,
@@ -1339,6 +1345,7 @@ __export(index_node_exports, {
1339
1345
  decryptWithPassword: () => decryptWithPassword,
1340
1346
  deleteDataPoint: () => deleteDataPoint,
1341
1347
  deleteQuestion: () => deleteQuestion,
1348
+ derivativeStatusTarget: () => derivativeStatusTarget,
1342
1349
  deriveDataPointId: () => deriveDataPointId,
1343
1350
  deriveMasterKey: () => deriveMasterKey,
1344
1351
  deriveScopeKey: () => deriveScopeKey,
@@ -1362,6 +1369,7 @@ __export(index_node_exports, {
1362
1369
  getContractAddress: () => getContractAddress,
1363
1370
  getContractController: () => getContractController,
1364
1371
  getContractInfo: () => getContractInfo,
1372
+ getDerivativeStatus: () => getDerivativeStatus,
1365
1373
  getFee: () => getFee,
1366
1374
  getGatewayLineage: () => getGatewayLineage,
1367
1375
  getLineage: () => getLineage,
@@ -1377,6 +1385,7 @@ __export(index_node_exports, {
1377
1385
  isDataPointId: () => isDataPointId,
1378
1386
  isDataPointTombstone: () => isDataPointTombstone,
1379
1387
  isDataPortabilityGatewayConfig: () => isDataPortabilityGatewayConfig,
1388
+ isDerivativeStatusSettled: () => isDerivativeStatusSettled,
1380
1389
  isECIESEncrypted: () => isECIESEncrypted,
1381
1390
  isPlatformSupported: () => isPlatformSupported,
1382
1391
  isRedactedLineageNode: () => isRedactedLineageNode,
@@ -1424,6 +1433,7 @@ __export(index_node_exports, {
1424
1433
  verifyGrantRegistration: () => verifyGrantRegistration,
1425
1434
  verifyPkceChallenge: () => verifyPkceChallenge,
1426
1435
  verifyWeb3Signed: () => verifyWeb3Signed,
1436
+ waitForDerivativeStatus: () => waitForDerivativeStatus,
1427
1437
  waitForQuestion: () => waitForQuestion,
1428
1438
  writeData: () => writeData,
1429
1439
  writePersonalServerData: () => writePersonalServerData
@@ -34662,6 +34672,13 @@ var QUESTION_STATUSES = [
34662
34672
  "failed",
34663
34673
  "stale"
34664
34674
  ];
34675
+ var DERIVATIVE_ERROR_CODES = [
34676
+ "inference_unavailable",
34677
+ "source_missing",
34678
+ "grant_invalid",
34679
+ "internal"
34680
+ ];
34681
+ var DerivativeErrorCodeSchema = import_zod5.z.enum(DERIVATIVE_ERROR_CODES);
34665
34682
  var QuestionStatusSchema = import_zod5.z.enum(QUESTION_STATUSES);
34666
34683
  var QuestionRegisteredBySchema = import_zod5.z.union([
34667
34684
  import_zod5.z.object({ kind: import_zod5.z.literal("owner") }),
@@ -34683,6 +34700,14 @@ var DerivativeQuestionSchema = import_zod5.z.object({
34683
34700
  status: QuestionStatusSchema,
34684
34701
  /** A short reason, set only while `status` is `failed`. */
34685
34702
  error: nullableString,
34703
+ /**
34704
+ * The coarse failure class behind `error`, set only while `status` is
34705
+ * `failed`. `null` from a Personal Server that predates the class
34706
+ * (`personal-server-ts` before the status route).
34707
+ */
34708
+ errorCode: DerivativeErrorCodeSchema.nullish().transform(
34709
+ (value) => value ?? null
34710
+ ),
34686
34711
  createdAt: import_zod5.z.string(),
34687
34712
  updatedAt: nullableString,
34688
34713
  /** When the last compute finished, or `null` while `pending`. */
@@ -34815,6 +34840,7 @@ async function questionErrorFromResponse(response, body) {
34815
34840
  );
34816
34841
  }
34817
34842
  }
34843
+ var personalServerErrorFromQuestionResponse = questionErrorFromResponse;
34818
34844
  async function sendOnce(params, resolved, session, spec, bodyBytes) {
34819
34845
  return sendWithFreshProof(
34820
34846
  spec.label,
@@ -35094,6 +35120,166 @@ async function askPersonalServer(params) {
35094
35120
  return { registration, record };
35095
35121
  }
35096
35122
 
35123
+ // src/protocol/derivative-status.ts
35124
+ var import_zod6 = require("zod");
35125
+ var DERIVATIVE_STATUS_PATH = "/v1/derivatives/status";
35126
+ var DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS = 12e4;
35127
+ var DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS = 2e3;
35128
+ var nullable = (schema) => schema.nullish().transform((value) => value ?? null);
35129
+ var DerivativeStatusSchema = import_zod6.z.object({
35130
+ derivedScope: import_zod6.z.string().min(1),
35131
+ status: QuestionStatusSchema,
35132
+ /** When the last compute finished, or `null` if none ever has. */
35133
+ lastComputedAt: nullable(import_zod6.z.string()),
35134
+ /** Local version of the derived record the last compute wrote. */
35135
+ derivedVersion: nullable(import_zod6.z.number()),
35136
+ derivedCollectedAt: nullable(import_zod6.z.string()),
35137
+ /** The failure class; `null` unless `status` is `failed`. */
35138
+ errorCode: nullable(DerivativeErrorCodeSchema),
35139
+ /**
35140
+ * Seconds until the Personal Server's next automatic retry, or `null` when
35141
+ * none is pending or running — the terminal signature. Poll on this cadence
35142
+ * rather than guessing one.
35143
+ */
35144
+ retryAfterSeconds: nullable(import_zod6.z.number())
35145
+ });
35146
+ function derivativeStatusTarget(derivedScope) {
35147
+ return `${DERIVATIVE_STATUS_PATH}?derivedScope=${encodeURIComponent(derivedScope)}`;
35148
+ }
35149
+ function normalizeBaseUrl3(url) {
35150
+ return url.replace(/\/+$/, "");
35151
+ }
35152
+ function resolveFetch3(fetchFn) {
35153
+ const resolved = fetchFn ?? globalThis.fetch;
35154
+ if (resolved === void 0) {
35155
+ throw new WriteRequestError("No fetch implementation available");
35156
+ }
35157
+ return resolved;
35158
+ }
35159
+ function requireDerivedScope(derivedScope) {
35160
+ if (typeof derivedScope !== "string" || derivedScope.length === 0) {
35161
+ throw new WriteRequestError("derivedScope is required");
35162
+ }
35163
+ return derivedScope;
35164
+ }
35165
+ function sleep3(ms, signal) {
35166
+ if (ms <= 0) return Promise.resolve();
35167
+ return new Promise((resolve, reject) => {
35168
+ const timer = setTimeout(() => {
35169
+ signal?.removeEventListener("abort", onAbort);
35170
+ resolve();
35171
+ }, ms);
35172
+ const onAbort = () => {
35173
+ clearTimeout(timer);
35174
+ reject(abortError2(signal));
35175
+ };
35176
+ signal?.addEventListener("abort", onAbort, { once: true });
35177
+ });
35178
+ }
35179
+ function timeoutError(latest, timeoutMs) {
35180
+ return new DerivativeQuestionTimeoutError(
35181
+ `Derived scope ${latest.derivedScope} was still ${latest.status} after ${timeoutMs}ms`,
35182
+ {
35183
+ derivedScope: latest.derivedScope,
35184
+ status: latest.status,
35185
+ errorCode: latest.errorCode,
35186
+ retryAfterSeconds: latest.retryAfterSeconds,
35187
+ timeoutMs
35188
+ }
35189
+ );
35190
+ }
35191
+ function abortError2(signal) {
35192
+ const reason = signal?.reason;
35193
+ return reason instanceof Error ? reason : new WriteRequestError("Derivative status wait was aborted");
35194
+ }
35195
+ function isDerivativeStatusSettled(status) {
35196
+ if (status.status === "ready") return true;
35197
+ return status.status === "failed" && status.retryAfterSeconds === null;
35198
+ }
35199
+ async function getDerivativeStatus(params) {
35200
+ const derivedScope = requireDerivedScope(params.derivedScope);
35201
+ const fetchFn = resolveFetch3(params.fetch);
35202
+ const baseUrl = normalizeBaseUrl3(params.personalServerUrl);
35203
+ const signer = resolveWriteSigner(params.signer, { account: params.account });
35204
+ const headers = new Headers(params.headers);
35205
+ headers.set(
35206
+ "Authorization",
35207
+ await buildWeb3SignedHeader({
35208
+ signMessage: signer.signMessage,
35209
+ aud: params.audience ?? baseUrl,
35210
+ method: "GET",
35211
+ uri: DERIVATIVE_STATUS_PATH,
35212
+ grantId: params.grantId
35213
+ })
35214
+ );
35215
+ let response;
35216
+ try {
35217
+ response = await fetchFn(
35218
+ `${baseUrl}${derivativeStatusTarget(derivedScope)}`,
35219
+ {
35220
+ method: "GET",
35221
+ headers,
35222
+ ...params.signal ? { signal: params.signal } : {}
35223
+ }
35224
+ );
35225
+ } catch (err) {
35226
+ throw new WriteTransportError(
35227
+ `Derivative status read failed: ${err instanceof Error ? err.message : String(err)}`,
35228
+ 1,
35229
+ err
35230
+ );
35231
+ }
35232
+ if (!response.ok) {
35233
+ throw await personalServerErrorFromQuestionResponse(
35234
+ response
35235
+ );
35236
+ }
35237
+ let body;
35238
+ try {
35239
+ body = await response.json();
35240
+ } catch (err) {
35241
+ throw new DerivativeQuestionRejectedError(
35242
+ "Derivative status response is not JSON",
35243
+ response.status,
35244
+ null,
35245
+ { cause: err instanceof Error ? err.message : String(err) }
35246
+ );
35247
+ }
35248
+ const parsed = DerivativeStatusSchema.safeParse(body);
35249
+ if (!parsed.success) {
35250
+ throw new DerivativeQuestionRejectedError(
35251
+ "Derivative status response is not a status view",
35252
+ response.status,
35253
+ null,
35254
+ { issues: parsed.error.issues }
35255
+ );
35256
+ }
35257
+ return parsed.data;
35258
+ }
35259
+ async function waitForDerivativeStatus(params) {
35260
+ const timeoutMs = Math.max(
35261
+ 0,
35262
+ params.timeoutMs ?? DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS
35263
+ );
35264
+ const pollIntervalMs = Math.max(
35265
+ 0,
35266
+ params.pollIntervalMs ?? DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS
35267
+ );
35268
+ const deadline = Date.now() + timeoutMs;
35269
+ for (; ; ) {
35270
+ if (params.signal?.aborted) throw abortError2(params.signal);
35271
+ const latest = await getDerivativeStatus(params);
35272
+ if (isDerivativeStatusSettled(latest)) return latest;
35273
+ const remaining = deadline - Date.now();
35274
+ if (remaining <= 0) throw timeoutError(latest, timeoutMs);
35275
+ const waitMs = latest.retryAfterSeconds === null ? pollIntervalMs : latest.retryAfterSeconds * 1e3;
35276
+ if (waitMs > remaining) {
35277
+ throw timeoutError(latest, timeoutMs);
35278
+ }
35279
+ await sleep3(waitMs, params.signal);
35280
+ }
35281
+ }
35282
+
35097
35283
  // src/protocol/gateway.ts
35098
35284
  function withGrantPermissions(grant) {
35099
35285
  const stripped = { ...grant };
@@ -36175,9 +36361,13 @@ async function parsePSError(response) {
36175
36361
  ContractNotFoundError,
36176
36362
  DATA_ACCESS_OP_TYPE,
36177
36363
  DATA_REGISTRY_STATUS_ABI,
36364
+ DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS,
36365
+ DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS,
36178
36366
  DEFAULT_QUESTION_POLL_INTERVAL_MS,
36179
36367
  DEFAULT_QUESTION_TIMEOUT_MS,
36368
+ DERIVATIVE_ERROR_CODES,
36180
36369
  DERIVATIVE_QUESTIONS_PATH,
36370
+ DERIVATIVE_STATUS_PATH,
36181
36371
  DataFileEnvelopeSchema,
36182
36372
  DataPointDeletedError,
36183
36373
  DataPointNotFoundError,
@@ -36186,6 +36376,7 @@ async function parsePSError(response) {
36186
36376
  DerivativeComputeUnavailableError,
36187
36377
  DerivativeCycleError,
36188
36378
  DerivativeDerivedScopeRequiredError,
36379
+ DerivativeErrorCodeSchema,
36189
36380
  DerivativeQuestionFailedError,
36190
36381
  DerivativeQuestionInvalidError,
36191
36382
  DerivativeQuestionNotFoundError,
@@ -36193,6 +36384,7 @@ async function parsePSError(response) {
36193
36384
  DerivativeQuestionSchema,
36194
36385
  DerivativeQuestionTimeoutError,
36195
36386
  DerivativeSourceNotGrantedError,
36387
+ DerivativeStatusSchema,
36196
36388
  DropboxStorage,
36197
36389
  ECIESError,
36198
36390
  ESCROW_DEPOSIT_ABI,
@@ -36328,6 +36520,7 @@ async function parsePSError(response) {
36328
36520
  decryptWithPassword,
36329
36521
  deleteDataPoint,
36330
36522
  deleteQuestion,
36523
+ derivativeStatusTarget,
36331
36524
  deriveDataPointId,
36332
36525
  deriveMasterKey,
36333
36526
  deriveScopeKey,
@@ -36351,6 +36544,7 @@ async function parsePSError(response) {
36351
36544
  getContractAddress,
36352
36545
  getContractController,
36353
36546
  getContractInfo,
36547
+ getDerivativeStatus,
36354
36548
  getFee,
36355
36549
  getGatewayLineage,
36356
36550
  getLineage,
@@ -36366,6 +36560,7 @@ async function parsePSError(response) {
36366
36560
  isDataPointId,
36367
36561
  isDataPointTombstone,
36368
36562
  isDataPortabilityGatewayConfig,
36563
+ isDerivativeStatusSettled,
36369
36564
  isECIESEncrypted,
36370
36565
  isPlatformSupported,
36371
36566
  isRedactedLineageNode,
@@ -36413,6 +36608,7 @@ async function parsePSError(response) {
36413
36608
  verifyGrantRegistration,
36414
36609
  verifyPkceChallenge,
36415
36610
  verifyWeb3Signed,
36611
+ waitForDerivativeStatus,
36416
36612
  waitForQuestion,
36417
36613
  writeData,
36418
36614
  writePersonalServerData