@opendatalabs/vana-sdk 3.15.0 → 3.17.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 (50) hide show
  1. package/README.md +107 -0
  2. package/dist/errors.cjs +94 -2
  3. package/dist/errors.cjs.map +1 -1
  4. package/dist/errors.d.ts +123 -0
  5. package/dist/errors.js +82 -1
  6. package/dist/errors.js.map +1 -1
  7. package/dist/index.browser.d.ts +4 -0
  8. package/dist/index.browser.js +1155 -14
  9. package/dist/index.browser.js.map +4 -4
  10. package/dist/index.node.cjs +1205 -15
  11. package/dist/index.node.cjs.map +4 -4
  12. package/dist/index.node.d.ts +4 -0
  13. package/dist/index.node.js +1155 -14
  14. package/dist/index.node.js.map +4 -4
  15. package/dist/protocol/gateway.cjs +16 -2
  16. package/dist/protocol/gateway.cjs.map +1 -1
  17. package/dist/protocol/gateway.d.ts +2 -0
  18. package/dist/protocol/gateway.js +16 -2
  19. package/dist/protocol/gateway.js.map +1 -1
  20. package/dist/protocol/lineage.cjs +287 -0
  21. package/dist/protocol/lineage.cjs.map +1 -0
  22. package/dist/protocol/lineage.d.ts +228 -0
  23. package/dist/protocol/lineage.js +258 -0
  24. package/dist/protocol/lineage.js.map +1 -0
  25. package/dist/protocol/lineage.test.d.ts +1 -0
  26. package/dist/protocol/personal-server-error-body.cjs +57 -0
  27. package/dist/protocol/personal-server-error-body.cjs.map +1 -0
  28. package/dist/protocol/personal-server-error-body.d.ts +18 -0
  29. package/dist/protocol/personal-server-error-body.js +32 -0
  30. package/dist/protocol/personal-server-error-body.js.map +1 -0
  31. package/dist/protocol/personal-server-write.cjs +623 -0
  32. package/dist/protocol/personal-server-write.cjs.map +1 -0
  33. package/dist/protocol/personal-server-write.d.ts +284 -0
  34. package/dist/protocol/personal-server-write.js +601 -0
  35. package/dist/protocol/personal-server-write.js.map +1 -0
  36. package/dist/protocol/personal-server-write.test.d.ts +1 -0
  37. package/dist/protocol/scope-actions.cjs +185 -0
  38. package/dist/protocol/scope-actions.cjs.map +1 -0
  39. package/dist/protocol/scope-actions.d.ts +145 -0
  40. package/dist/protocol/scope-actions.js +154 -0
  41. package/dist/protocol/scope-actions.js.map +1 -0
  42. package/dist/protocol/scope-actions.test.d.ts +1 -0
  43. package/dist/protocol/write-signer.cjs +67 -0
  44. package/dist/protocol/write-signer.cjs.map +1 -0
  45. package/dist/protocol/write-signer.d.ts +59 -0
  46. package/dist/protocol/write-signer.js +43 -0
  47. package/dist/protocol/write-signer.js.map +1 -0
  48. package/dist/protocol/write-signer.test.d.ts +1 -0
  49. package/dist/tests/mock-personal-server.d.ts +127 -0
  50. package/package.json +1 -1
package/README.md CHANGED
@@ -321,6 +321,113 @@ app. It includes the route handlers, return page, and React connect button from
321
321
  this flow, defaults to sample-data mode using `vana-com/data-connectors`, and
322
322
  can be switched to live protocol mode with environment variables.
323
323
 
324
+ ## Write into a Personal Server
325
+
326
+ A builder that holds a **write-grant** (a grant whose scope entries carry the
327
+ `write:` prefix, e.g. `write:coach.summary`; see `formatScopeEntry`) can write
328
+ records into the user's Personal Server. The SDK owns the handshake and the
329
+ signatures; the same API works from a backend (viem `privateKeyToAccount`) and
330
+ from a browser (viem `WalletClient`).
331
+
332
+ ```typescript
333
+ import { privateKeyToAccount } from "viem/accounts";
334
+ import {
335
+ openWriteSession,
336
+ writeData,
337
+ getLineage,
338
+ deriveDataPointId,
339
+ } from "@opendatalabs/vana-sdk";
340
+
341
+ const signer = privateKeyToAccount(process.env.BUILDER_KEY as `0x${string}`);
342
+
343
+ // 1. Open a session: Web3Signed handshake carrying the write-grant id.
344
+ const session = await openWriteSession({
345
+ personalServerUrl: "https://ps.example.com",
346
+ signer,
347
+ grantId: writeGrantId,
348
+ });
349
+
350
+ // 2. Write a record (compact JSON, signed proof in X-Vana-Write-Signature).
351
+ await writeData({ session, scope: "coach.notes", data: { note: "hello" } });
352
+
353
+ // 3. Write a derivative: name the data points it was computed from. Given as
354
+ // { ownerAddress, scope } the SDK derives the ids and checks the naming
355
+ // rule before signing; bare ids (deriveDataPointId) work too.
356
+ await writeData({
357
+ session,
358
+ scope: "coach.summary",
359
+ data: { summary: "..." },
360
+ lineage: [{ ownerAddress, scope: "chatgpt.conversations" }],
361
+ });
362
+
363
+ // 4. Walk the lineage: Personal Server by scope, or gateway by data point id
364
+ // (optionally `version: N` for a specific version).
365
+ const graph = await getLineage({
366
+ personalServerUrl: "https://ps.example.com",
367
+ scope: "coach.summary",
368
+ grantId: readGrantId,
369
+ signer,
370
+ });
371
+ const viaGateway = await getLineage({
372
+ gatewayUrl: "https://dp-rpc.vana.org",
373
+ dataPointId: deriveDataPointId(ownerAddress, "coach.summary"),
374
+ grantId: readGrantId,
375
+ signer,
376
+ });
377
+ ```
378
+
379
+ `writePersonalServerData({ personalServerUrl, signer, grantId, scope, data })`
380
+ does steps 1 and 2 in one call and returns the session for reuse.
381
+
382
+ What the SDK does for you:
383
+
384
+ - Sends `POST /v1/write/session` with a Web3Signed proof (the grant id is a
385
+ signed claim) and keeps the short-lived bearer in `session`.
386
+ - Sends `POST /v1/data/:scope` with the bearer and `X-Vana-Write-Signature`, a
387
+ second Web3Signed proof over the **stored** representation: the compact JSON
388
+ body for JSON writes, the `$binary` record (`binaryWriteSignedBytes`) for
389
+ `binary: { bytes, contentType, filename }` writes. The grant id is a signed
390
+ claim on that proof too.
391
+ - Every proof is single-use on the server. Transport retries (`retry`) sign a
392
+ fresh proof per attempt; an HTTP error is never retried.
393
+ - `lineage` becomes the record's top-level `lineage` field (JSON writes) or
394
+ the `lineage` field of `X-Vana-Metadata` (binary writes), so it is inside
395
+ the signed bytes either way; ids are lowercased, the server validates them
396
+ and mirrors them to `$lineage`. `lineage: []` is an explicit root statement
397
+ and is sent as such; absent or `null` makes no statement. Sending
398
+ `$writtenBy`, `$lineage`, or your own `lineage` field is refused before any
399
+ request.
400
+ - Both lineage reads are Web3Signed over the bare path
401
+ (`/v1/data/<id lowercase>/lineage[/:version]` on the gateway,
402
+ `/v1/data/:scope/lineage[/:version]` on the Personal Server; the version is
403
+ a path segment, never a query), with the grant as the signed `grantId`
404
+ claim, so a captured signature cannot be replayed for another view. The
405
+ gateway answers a uniform 404 for an unknown id and for a signer it will
406
+ not serve.
407
+
408
+ Rules on derivatives, checked by the server and (where the SDK has the
409
+ information) by the client before anything is signed: sources are data points
410
+ of the same owner (a deleted source is still a valid one, and comes back with
411
+ its `deletedAt`; one that no longer resolves comes back with `version: "0"`),
412
+ at most 256, distinct, never the record's own id, and the derived scope must
413
+ not share its first dot-segment with any source scope (a grant on `chatgpt.*`
414
+ must not read `chatgpt.summary`), so put derivatives in your app's own
415
+ namespace (`assertDerivedScopeNaming` is exported). A grant on a derived scope
416
+ confers nothing on its sources, and the other way round: the pipeline needs a
417
+ read grant on the sources and a write grant on the derived scope.
418
+
419
+ Errors are typed: `WriteSessionError` (handshake refused), `WriteUnauthorizedError`
420
+ (401), `WriteForbiddenError` (403), `WriteConflictError` (409),
421
+ `WriteLineageError` (any `LINEAGE_*` rejection: 422 `LINEAGE_SOURCE_UNKNOWN`
422
+ with `details.unknown`, 400 `LINEAGE_INVALID` /
423
+ `LINEAGE_SCOPE_UNDER_SOURCE_PREFIX`, 502 `LINEAGE_SOURCE_LOOKUP_FAILED`),
424
+ `WriteRejectedError` (other), `WriteSessionExpiredError`, `WriteTransportError`,
425
+ `WriteRequestError`, and `LineageReadError` for lineage reads. Each carries the
426
+ server's `status`, `errorCode` and `details`. Lineage entries the caller holds
427
+ no grant for come back as `{ dataPointId, redacted: true }` (narrow with
428
+ `isRedactedLineageNode`); the gateway's `proof` over the served view is passed
429
+ through.
430
+
324
431
  ## Networks
325
432
 
326
433
  | Network | Chain ID | RPC URL |
package/dist/errors.cjs CHANGED
@@ -21,10 +21,12 @@ __export(errors_exports, {
21
21
  BlockchainError: () => BlockchainError,
22
22
  ContractNotFoundError: () => ContractNotFoundError,
23
23
  InvalidConfigurationError: () => InvalidConfigurationError,
24
+ LineageReadError: () => LineageReadError,
24
25
  NetworkError: () => NetworkError,
25
26
  NonceError: () => NonceError,
26
27
  PermissionError: () => PermissionError,
27
28
  PersonalServerError: () => PersonalServerError,
29
+ PersonalServerWriteError: () => PersonalServerWriteError,
28
30
  ReadOnlyError: () => ReadOnlyError,
29
31
  RelayerError: () => RelayerError,
30
32
  SerializationError: () => SerializationError,
@@ -32,7 +34,16 @@ __export(errors_exports, {
32
34
  SignatureError: () => SignatureError,
33
35
  TransactionPendingError: () => TransactionPendingError,
34
36
  UserRejectedRequestError: () => UserRejectedRequestError,
35
- VanaError: () => VanaError
37
+ VanaError: () => VanaError,
38
+ WriteConflictError: () => WriteConflictError,
39
+ WriteForbiddenError: () => WriteForbiddenError,
40
+ WriteLineageError: () => WriteLineageError,
41
+ WriteRejectedError: () => WriteRejectedError,
42
+ WriteRequestError: () => WriteRequestError,
43
+ WriteSessionError: () => WriteSessionError,
44
+ WriteSessionExpiredError: () => WriteSessionExpiredError,
45
+ WriteTransportError: () => WriteTransportError,
46
+ WriteUnauthorizedError: () => WriteUnauthorizedError
36
47
  });
37
48
  module.exports = __toCommonJS(errors_exports);
38
49
  class VanaError extends Error {
@@ -175,15 +186,87 @@ class TransactionPendingError extends VanaError {
175
186
  };
176
187
  }
177
188
  }
189
+ class PersonalServerWriteError extends VanaError {
190
+ constructor(message, code, status, errorCode = null, details) {
191
+ super(message, code);
192
+ this.status = status;
193
+ this.errorCode = errorCode;
194
+ this.details = details;
195
+ }
196
+ status;
197
+ errorCode;
198
+ details;
199
+ }
200
+ class WriteRequestError extends PersonalServerWriteError {
201
+ constructor(message, details) {
202
+ super(message, "WRITE_INVALID_REQUEST", void 0, null, details);
203
+ }
204
+ }
205
+ class WriteTransportError extends PersonalServerWriteError {
206
+ constructor(message, attempts, cause) {
207
+ super(message, "WRITE_TRANSPORT_ERROR", void 0, null, { attempts });
208
+ this.attempts = attempts;
209
+ this.cause = cause;
210
+ }
211
+ attempts;
212
+ }
213
+ class WriteSessionError extends PersonalServerWriteError {
214
+ constructor(message, status, errorCode = null, details) {
215
+ super(message, "WRITE_SESSION_REJECTED", status, errorCode, details);
216
+ }
217
+ }
218
+ class WriteSessionExpiredError extends PersonalServerWriteError {
219
+ constructor(message, details) {
220
+ super(message, "WRITE_SESSION_EXPIRED", void 0, null, details);
221
+ }
222
+ }
223
+ class WriteUnauthorizedError extends PersonalServerWriteError {
224
+ constructor(message, errorCode = null, details) {
225
+ super(message, "WRITE_UNAUTHORIZED", 401, errorCode, details);
226
+ }
227
+ }
228
+ class WriteForbiddenError extends PersonalServerWriteError {
229
+ constructor(message, errorCode = null, details) {
230
+ super(message, "WRITE_FORBIDDEN", 403, errorCode, details);
231
+ }
232
+ }
233
+ class WriteConflictError extends PersonalServerWriteError {
234
+ constructor(message, errorCode = null, details) {
235
+ super(message, "WRITE_CONFLICT", 409, errorCode, details);
236
+ }
237
+ }
238
+ class WriteLineageError extends PersonalServerWriteError {
239
+ constructor(message, status = 422, errorCode = null, details) {
240
+ super(message, "WRITE_LINEAGE_REJECTED", status, errorCode, details);
241
+ }
242
+ }
243
+ class WriteRejectedError extends PersonalServerWriteError {
244
+ constructor(message, status, errorCode = null, details) {
245
+ super(message, "WRITE_REJECTED", status, errorCode, details);
246
+ }
247
+ }
248
+ class LineageReadError extends VanaError {
249
+ constructor(message, status, errorCode = null, details) {
250
+ super(message, "LINEAGE_READ_ERROR");
251
+ this.status = status;
252
+ this.errorCode = errorCode;
253
+ this.details = details;
254
+ }
255
+ status;
256
+ errorCode;
257
+ details;
258
+ }
178
259
  // Annotate the CommonJS export names for ESM import in node:
179
260
  0 && (module.exports = {
180
261
  BlockchainError,
181
262
  ContractNotFoundError,
182
263
  InvalidConfigurationError,
264
+ LineageReadError,
183
265
  NetworkError,
184
266
  NonceError,
185
267
  PermissionError,
186
268
  PersonalServerError,
269
+ PersonalServerWriteError,
187
270
  ReadOnlyError,
188
271
  RelayerError,
189
272
  SerializationError,
@@ -191,6 +274,15 @@ class TransactionPendingError extends VanaError {
191
274
  SignatureError,
192
275
  TransactionPendingError,
193
276
  UserRejectedRequestError,
194
- VanaError
277
+ VanaError,
278
+ WriteConflictError,
279
+ WriteForbiddenError,
280
+ WriteLineageError,
281
+ WriteRejectedError,
282
+ WriteRequestError,
283
+ WriteSessionError,
284
+ WriteSessionExpiredError,
285
+ WriteTransportError,
286
+ WriteUnauthorizedError
195
287
  });
196
288
  //# sourceMappingURL=errors.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Base error class for all Vana SDK errors with structured error codes.\n *\n * @remarks\n * This abstract base class provides a foundation for all SDK-specific errors with\n * consistent error codes and stack trace handling. All Vana SDK errors extend this\n * class to provide structured error information that applications can handle\n * programmatically. The error code enables differentiation between error types\n * without relying on string matching.\n * @category Error Handling\n */\nexport class VanaError extends Error {\n constructor(\n message: string,\n public readonly code?: string,\n ) {\n super(message);\n this.name = this.constructor.name;\n\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n}\n\n/**\n * Thrown when gasless transaction submission via relayer fails.\n *\n * @remarks\n * This error occurs when the relayer service is unavailable, returns an error,\n * or fails to process a gasless transaction. It includes the HTTP status code\n * and response details when available to help with debugging relayer issues.\n * @category Error Handling\n */\nexport class RelayerError extends VanaError {\n constructor(\n message: string,\n public readonly statusCode?: number,\n public readonly response?: unknown,\n ) {\n super(message, \"RELAYER_ERROR\");\n }\n}\n\n/**\n * Thrown when the user rejects a wallet signature request.\n *\n * @remarks\n * This error occurs when users decline to sign transactions or typed data through\n * their wallet interface. It's a normal part of user interaction and should be\n * handled gracefully by applications without treating it as a system error.\n * @category Error Handling\n */\nexport class UserRejectedRequestError extends VanaError {\n constructor(message: string = \"User rejected the signature request\") {\n super(message, \"USER_REJECTED_REQUEST\");\n }\n}\n\n/**\n * Thrown when the SDK configuration contains invalid or missing parameters.\n *\n * @remarks\n * This error occurs during SDK initialization when required configuration\n * parameters are missing, invalid, or incompatible. Common causes include\n * missing wallet clients, invalid chain IDs, malformed storage provider\n * configurations, or incompatible parameter combinations.\n *\n * Applications should catch this error during initialization and provide\n * clear feedback to users about configuration requirements.\n *\n * @example\n * ```typescript\n * try {\n * const vana = Vana({\n * chainId: 999999, // Invalid chain ID\n * account: null // Missing account\n * });\n * } catch (error) {\n * if (error instanceof InvalidConfigurationError) {\n * console.error('Configuration error:', error.message);\n * // Show user-friendly configuration help\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class InvalidConfigurationError extends VanaError {\n constructor(message: string) {\n super(message, \"INVALID_CONFIGURATION\");\n }\n}\n\n/**\n * Thrown when a required Vana protocol contract is not deployed on the current chain.\n *\n * @remarks\n * This error occurs when attempting to interact with contracts that are not\n * available on the connected blockchain network. It includes the contract name\n * and chain ID to help identify deployment issues or incorrect network configuration.\n * @category Error Handling\n */\nexport class ContractNotFoundError extends VanaError {\n constructor(contractName: string, chainId: number) {\n super(\n `Contract ${contractName} not found on chain ${chainId}`,\n \"CONTRACT_NOT_FOUND\",\n );\n }\n}\n\n/**\n * Thrown when blockchain operations fail due to network, contract, or transaction issues.\n *\n * @remarks\n * This error encompasses various blockchain-related failures including network\n * connectivity issues, contract execution failures, insufficient gas, invalid\n * transaction parameters, or smart contract reverts. The original error is\n * preserved to provide detailed debugging information while maintaining a\n * consistent SDK error interface.\n *\n * Common causes:\n * - Network connectivity problems\n * - Insufficient gas or gas price too low\n * - Contract function reverts\n * - Invalid transaction parameters\n * - Blockchain congestion or downtime\n *\n * @example\n * ```typescript\n * try {\n * await vana.permissions.grant({\n * grantee: '0x742d35...',\n * operation: 'read'\n * });\n * } catch (error) {\n * if (error instanceof BlockchainError) {\n * console.error('Blockchain operation failed:', error.message);\n *\n * // Check if it's a network issue\n * if (error.originalError?.message.includes('network')) {\n * // Retry with exponential backoff\n * await retryOperation();\n * }\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class BlockchainError extends VanaError {\n constructor(\n message: string,\n public readonly originalError?: Error,\n ) {\n super(message, \"BLOCKCHAIN_ERROR\");\n }\n}\n\n/**\n * Thrown when data serialization or deserialization operations fail.\n *\n * @remarks\n * This error occurs when the SDK cannot properly serialize parameters for\n * blockchain transactions, IPFS storage, or API calls. Common causes include\n * circular references in objects, unsupported data types, or malformed JSON.\n * It's typically encountered during grant file creation, storage operations,\n * or when preparing transaction data.\n *\n * @example\n * ```typescript\n * try {\n * // Object with circular reference causes serialization error\n * const obj = { name: 'test' };\n * obj.self = obj; // Circular reference\n *\n * await vana.data.upload({\n * content: obj,\n * filename: 'data.json'\n * });\n * } catch (error) {\n * if (error instanceof SerializationError) {\n * console.error('Data serialization failed:', error.message);\n * // Clean data before retry\n * const cleanedData = removeCircularReferences(obj);\n * await vana.data.upload({\n * content: cleanedData,\n * filename: 'data.json'\n * });\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class SerializationError extends VanaError {\n constructor(message: string) {\n super(message, \"SERIALIZATION_ERROR\");\n }\n}\n\n/**\n * Thrown when a signature operation fails or cannot be completed.\n *\n * @remarks\n * This error occurs when wallet signature operations fail due to disconnection,\n * locked accounts, or other wallet-related issues. It preserves the original\n * error for debugging while providing consistent error handling across the SDK.\n *\n * Recovery strategies:\n * - Check wallet connection and account unlock status\n * - Retry operation with explicit user interaction\n * - For gasless operations, consider switching to direct transactions\n *\n * @example\n * ```typescript\n * try {\n * await vana.permissions.grant({ grantee: '0x...' });\n * } catch (error) {\n * if (error instanceof SignatureError) {\n * // Prompt user to unlock wallet\n * await promptWalletUnlock();\n * // Retry operation\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class SignatureError extends VanaError {\n constructor(\n message: string,\n public readonly originalError?: Error,\n ) {\n super(message, \"SIGNATURE_ERROR\");\n }\n}\n\n/**\n * Thrown when network communication fails during API calls or blockchain interactions.\n *\n * @remarks\n * This error encompasses network connectivity issues, API unavailability,\n * timeout errors, and CORS restrictions. It's commonly encountered during\n * IPFS operations, subgraph queries, or RPC calls.\n *\n * Recovery strategies:\n * - Check network connectivity\n * - Retry with exponential backoff\n * - Verify API endpoints are accessible\n * - Switch to alternative network providers or gateways\n *\n * @example\n * ```typescript\n * try {\n * const files = await vana.data.getUserFiles({ owner: '0x...' });\n * } catch (error) {\n * if (error instanceof NetworkError) {\n * // Implement retry with exponential backoff\n * await retryWithBackoff(() => vana.data.getUserFiles({ owner: '0x...' }));\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class NetworkError extends VanaError {\n constructor(\n message: string,\n public readonly originalError?: Error,\n ) {\n super(message, \"NETWORK_ERROR\");\n }\n}\n\n/**\n * Thrown when transaction nonce retrieval fails during gasless operations.\n *\n * @remarks\n * This error occurs when the SDK cannot retrieve the user's current nonce from\n * smart contracts, preventing gasless transaction submission. Nonces are critical\n * for preventing replay attacks in signed transactions.\n *\n * Recovery strategies:\n * - Retry nonce retrieval after brief delay\n * - Check wallet connection and account status\n * - Use manual nonce specification if supported by the operation\n * - Switch to direct transactions as fallback\n *\n * @example\n * ```typescript\n * try {\n * await vana.permissions.grant({ grantee: '0x...' });\n * } catch (error) {\n * if (error instanceof NonceError) {\n * // Wait and retry\n * await delay(1000);\n * await vana.permissions.grant({ grantee: '0x...' });\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class NonceError extends VanaError {\n constructor(message: string) {\n super(message, \"NONCE_ERROR\");\n }\n}\n\n/**\n * Thrown when personal server operations fail or cannot be completed.\n *\n * @remarks\n * This error occurs during interactions with personal servers for computation\n * requests, identity retrieval, or operation status checks. Common causes include\n * server unavailability, untrusted server status, or invalid permission grants.\n *\n * Recovery strategies:\n * - Verify server URL accessibility\n * - Check server trust status via `vana.permissions.getTrustedServers()`\n * - Ensure valid permissions exist for the operation\n * - Retry after server becomes available\n *\n * @example\n * ```typescript\n * try {\n * const result = await vana.server.createOperation({ permissionId: 123 });\n * } catch (error) {\n * if (error instanceof PersonalServerError) {\n * // Check if server is trusted\n * const trustedServers = await vana.permissions.getTrustedServers();\n * if (!trustedServers.includes(serverId)) {\n * await vana.permissions.trustServer({ serverId });\n * }\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class PersonalServerError extends VanaError {\n constructor(\n message: string,\n public readonly originalError?: Error,\n ) {\n super(message, \"PERSONAL_SERVER_ERROR\");\n }\n}\n\n/**\n * Thrown when attempting to register a server with a URL different from its existing registration.\n *\n * @remarks\n * This error occurs when trying to add or trust a server that's already registered\n * on-chain with a different URL. Server URLs are immutable once registered to\n * maintain consistency and security. Applications should use the existing URL\n * or register a new server with a different ID.\n *\n * @example\n * ```typescript\n * try {\n * await vana.permissions.addAndTrustServer({\n * serverId: 1,\n * serverUrl: 'https://new-url.com',\n * publicKey: '0x...'\n * });\n * } catch (error) {\n * if (error instanceof ServerUrlMismatchError) {\n * console.log(`Server already registered with: ${error.existingUrl}`);\n * // Use existing URL or register new server\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class ServerUrlMismatchError extends VanaError {\n constructor(existingUrl: string, providedUrl: string, serverId: string) {\n super(\n `Server ${serverId} is already registered with URL \"${existingUrl}\". Cannot change to \"${providedUrl}\".`,\n \"SERVER_URL_MISMATCH\",\n );\n this.existingUrl = existingUrl;\n this.providedUrl = providedUrl;\n this.serverId = serverId;\n }\n\n public readonly existingUrl: string;\n public readonly providedUrl: string;\n public readonly serverId: string;\n}\n\n/**\n * Thrown when permission grant, revoke, or validation operations fail.\n *\n * @remarks\n * This error occurs during permission management operations including grants,\n * revocations, and permission validation checks. Common causes include invalid\n * grantee addresses, expired permissions, or insufficient privileges.\n *\n * @example\n * ```typescript\n * try {\n * await vana.permissions.revoke({ permissionId: 999999 });\n * } catch (error) {\n * if (error instanceof PermissionError) {\n * console.error('Permission operation failed:', error.message);\n * // Permission may not exist or user may not be owner\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class PermissionError extends VanaError {\n constructor(\n message: string,\n public readonly originalError?: Error,\n ) {\n super(message, \"PERMISSION_ERROR\");\n }\n}\n\n/**\n * Thrown when attempting to perform write operations without a wallet client.\n *\n * @remarks\n * This error occurs when trying to execute operations that require wallet\n * interaction (signing, encrypting, or submitting transactions) while the SDK\n * is initialized in read-only mode without a wallet client. To perform write\n * operations, the SDK must be initialized with a wallet client.\n *\n * Common operations that require a wallet:\n * - Signing transactions or typed data\n * - Encrypting or decrypting files\n * - Granting or revoking permissions\n * - Uploading data to IPFS\n * - Submitting blockchain transactions\n *\n * @example\n * ```typescript\n * try {\n * // This will throw if no wallet client is provided\n * await vana.data.decryptFile({ fileId: 'abc123' });\n * } catch (error) {\n * if (error instanceof ReadOnlyError) {\n * console.error(`Cannot ${error.operation}: ${error.message}`);\n * // Initialize with wallet client to enable write operations\n * const vanaWithWallet = Vana({\n * walletClient: createWalletClient(...)\n * });\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class ReadOnlyError extends VanaError {\n constructor(\n operation: string,\n suggestion: string = \"Initialize the SDK with a walletClient to perform this operation\",\n ) {\n super(\n `Operation '${operation}' requires a wallet client. ${suggestion}`,\n \"READ_ONLY_ERROR\",\n );\n this.operation = operation;\n this.suggestion = suggestion;\n }\n\n /** The operation that was attempted */\n public readonly operation: string;\n /** Suggested solution for fixing the error */\n public readonly suggestion: string;\n}\n\n/**\n * Thrown when a long-running transaction operation times out or fails during polling.\n *\n * @remarks\n * This error occurs when asynchronous relayer operations exceed the configured timeout\n * or encounter non-recoverable errors during status polling. It preserves the operation ID\n * to allow recovery and status checking at a later time.\n *\n * The error includes:\n * - Operation ID for recovery and status checking\n * - Last known status before failure\n * - Original error details\n *\n * Recovery strategies:\n * - Save the operation ID for later status checking\n * - Implement manual recovery flow using the operation ID\n * - Check transaction status through alternative means\n * - Contact support if operation remains stuck\n *\n * @example\n * ```typescript\n * try {\n * const result = await vana.permissions.grant({\n * grantee: '0x...',\n * files: [1, 2, 3]\n * });\n * } catch (error) {\n * if (error instanceof TransactionPendingError) {\n * // Save operation ID for recovery\n * localStorage.setItem('pending_operation', error.operationId);\n *\n * // Show recovery UI\n * showRecoveryDialog({\n * operationId: error.operationId,\n * lastStatus: error.lastKnownStatus\n * });\n *\n * // Attempt recovery later\n * const status = await vana.checkOperationStatus(error.operationId);\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class TransactionPendingError extends VanaError {\n constructor(\n /** The operation ID that can be used for status checking */\n public readonly operationId: string,\n message: string,\n /** The last known status of the operation before failure */\n public readonly lastKnownStatus?: unknown,\n ) {\n super(\n `Transaction operation pending: ${message} (operationId: ${operationId})`,\n \"TRANSACTION_PENDING\",\n );\n }\n\n /**\n * Converts the error to a JSON-serializable format.\n *\n * @remarks\n * Useful for logging, storage, or transmission of error details.\n *\n * @returns JSON representation of the error\n */\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n operationId: this.operationId,\n lastKnownStatus: this.lastKnownStatus,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWO,MAAM,kBAAkB,MAAM;AAAA,EACnC,YACE,SACgB,MAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO,KAAK,YAAY;AAG7B,QAAI,MAAM,mBAAmB;AAC3B,YAAM,kBAAkB,MAAM,KAAK,WAAW;AAAA,IAChD;AAAA,EACF;AAAA,EATkB;AAUpB;AAWO,MAAM,qBAAqB,UAAU;AAAA,EAC1C,YACE,SACgB,YACA,UAChB;AACA,UAAM,SAAS,eAAe;AAHd;AACA;AAAA,EAGlB;AAAA,EAJkB;AAAA,EACA;AAIpB;AAWO,MAAM,iCAAiC,UAAU;AAAA,EACtD,YAAY,UAAkB,uCAAuC;AACnE,UAAM,SAAS,uBAAuB;AAAA,EACxC;AACF;AA8BO,MAAM,kCAAkC,UAAU;AAAA,EACvD,YAAY,SAAiB;AAC3B,UAAM,SAAS,uBAAuB;AAAA,EACxC;AACF;AAWO,MAAM,8BAA8B,UAAU;A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B,oEACrB;AACA;AAAA,MACE,cAAc,SAAS,+BAA+B,UAAU;AAAA,MAChE;AAAA,IACF;AACA,SAAK,YAAY;AACjB,SAAK,aAAa;AAAA,EACpB;AAAA;AAAA,EAGgB;AAAA;AAAA,EAEA;AAClB;AA8CO,MAAM,gCAAgC,UAAU;AAAA,EACrD,YAEkB,aAChB,SAEgB,iBAChB;AACA;AAAA,MACE,kCAAkC,OAAO,kBAAkB,WAAW;AAAA,MACtE;AAAA,IACF;AARgB;AAGA;AAAA,EAMlB;AAAA,EATkB;AAAA,EAGA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBlB,SAAkC;AAChC,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,aAAa,KAAK;AAAA,MAClB,iBAAiB,KAAK;AAAA,IACxB;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Base error class for all Vana SDK errors with structured error codes.\n *\n * @remarks\n * This abstract base class provides a foundation for all SDK-specific errors with\n * consistent error codes and stack trace handling. All Vana SDK errors extend this\n * class to provide structured error information that applications can handle\n * programmatically. The error code enables differentiation between error types\n * without relying on string matching.\n * @category Error Handling\n */\nexport class VanaError extends Error {\n constructor(\n message: string,\n public readonly code?: string,\n ) {\n super(message);\n this.name = this.constructor.name;\n\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n}\n\n/**\n * Thrown when gasless transaction submission via relayer fails.\n *\n * @remarks\n * This error occurs when the relayer service is unavailable, returns an error,\n * or fails to process a gasless transaction. It includes the HTTP status code\n * and response details when available to help with debugging relayer issues.\n * @category Error Handling\n */\nexport class RelayerError extends VanaError {\n constructor(\n message: string,\n public readonly statusCode?: number,\n public readonly response?: unknown,\n ) {\n super(message, \"RELAYER_ERROR\");\n }\n}\n\n/**\n * Thrown when the user rejects a wallet signature request.\n *\n * @remarks\n * This error occurs when users decline to sign transactions or typed data through\n * their wallet interface. It's a normal part of user interaction and should be\n * handled gracefully by applications without treating it as a system error.\n * @category Error Handling\n */\nexport class UserRejectedRequestError extends VanaError {\n constructor(message: string = \"User rejected the signature request\") {\n super(message, \"USER_REJECTED_REQUEST\");\n }\n}\n\n/**\n * Thrown when the SDK configuration contains invalid or missing parameters.\n *\n * @remarks\n * This error occurs during SDK initialization when required configuration\n * parameters are missing, invalid, or incompatible. Common causes include\n * missing wallet clients, invalid chain IDs, malformed storage provider\n * configurations, or incompatible parameter combinations.\n *\n * Applications should catch this error during initialization and provide\n * clear feedback to users about configuration requirements.\n *\n * @example\n * ```typescript\n * try {\n * const vana = Vana({\n * chainId: 999999, // Invalid chain ID\n * account: null // Missing account\n * });\n * } catch (error) {\n * if (error instanceof InvalidConfigurationError) {\n * console.error('Configuration error:', error.message);\n * // Show user-friendly configuration help\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class InvalidConfigurationError extends VanaError {\n constructor(message: string) {\n super(message, \"INVALID_CONFIGURATION\");\n }\n}\n\n/**\n * Thrown when a required Vana protocol contract is not deployed on the current chain.\n *\n * @remarks\n * This error occurs when attempting to interact with contracts that are not\n * available on the connected blockchain network. It includes the contract name\n * and chain ID to help identify deployment issues or incorrect network configuration.\n * @category Error Handling\n */\nexport class ContractNotFoundError extends VanaError {\n constructor(contractName: string, chainId: number) {\n super(\n `Contract ${contractName} not found on chain ${chainId}`,\n \"CONTRACT_NOT_FOUND\",\n );\n }\n}\n\n/**\n * Thrown when blockchain operations fail due to network, contract, or transaction issues.\n *\n * @remarks\n * This error encompasses various blockchain-related failures including network\n * connectivity issues, contract execution failures, insufficient gas, invalid\n * transaction parameters, or smart contract reverts. The original error is\n * preserved to provide detailed debugging information while maintaining a\n * consistent SDK error interface.\n *\n * Common causes:\n * - Network connectivity problems\n * - Insufficient gas or gas price too low\n * - Contract function reverts\n * - Invalid transaction parameters\n * - Blockchain congestion or downtime\n *\n * @example\n * ```typescript\n * try {\n * await vana.permissions.grant({\n * grantee: '0x742d35...',\n * operation: 'read'\n * });\n * } catch (error) {\n * if (error instanceof BlockchainError) {\n * console.error('Blockchain operation failed:', error.message);\n *\n * // Check if it's a network issue\n * if (error.originalError?.message.includes('network')) {\n * // Retry with exponential backoff\n * await retryOperation();\n * }\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class BlockchainError extends VanaError {\n constructor(\n message: string,\n public readonly originalError?: Error,\n ) {\n super(message, \"BLOCKCHAIN_ERROR\");\n }\n}\n\n/**\n * Thrown when data serialization or deserialization operations fail.\n *\n * @remarks\n * This error occurs when the SDK cannot properly serialize parameters for\n * blockchain transactions, IPFS storage, or API calls. Common causes include\n * circular references in objects, unsupported data types, or malformed JSON.\n * It's typically encountered during grant file creation, storage operations,\n * or when preparing transaction data.\n *\n * @example\n * ```typescript\n * try {\n * // Object with circular reference causes serialization error\n * const obj = { name: 'test' };\n * obj.self = obj; // Circular reference\n *\n * await vana.data.upload({\n * content: obj,\n * filename: 'data.json'\n * });\n * } catch (error) {\n * if (error instanceof SerializationError) {\n * console.error('Data serialization failed:', error.message);\n * // Clean data before retry\n * const cleanedData = removeCircularReferences(obj);\n * await vana.data.upload({\n * content: cleanedData,\n * filename: 'data.json'\n * });\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class SerializationError extends VanaError {\n constructor(message: string) {\n super(message, \"SERIALIZATION_ERROR\");\n }\n}\n\n/**\n * Thrown when a signature operation fails or cannot be completed.\n *\n * @remarks\n * This error occurs when wallet signature operations fail due to disconnection,\n * locked accounts, or other wallet-related issues. It preserves the original\n * error for debugging while providing consistent error handling across the SDK.\n *\n * Recovery strategies:\n * - Check wallet connection and account unlock status\n * - Retry operation with explicit user interaction\n * - For gasless operations, consider switching to direct transactions\n *\n * @example\n * ```typescript\n * try {\n * await vana.permissions.grant({ grantee: '0x...' });\n * } catch (error) {\n * if (error instanceof SignatureError) {\n * // Prompt user to unlock wallet\n * await promptWalletUnlock();\n * // Retry operation\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class SignatureError extends VanaError {\n constructor(\n message: string,\n public readonly originalError?: Error,\n ) {\n super(message, \"SIGNATURE_ERROR\");\n }\n}\n\n/**\n * Thrown when network communication fails during API calls or blockchain interactions.\n *\n * @remarks\n * This error encompasses network connectivity issues, API unavailability,\n * timeout errors, and CORS restrictions. It's commonly encountered during\n * IPFS operations, subgraph queries, or RPC calls.\n *\n * Recovery strategies:\n * - Check network connectivity\n * - Retry with exponential backoff\n * - Verify API endpoints are accessible\n * - Switch to alternative network providers or gateways\n *\n * @example\n * ```typescript\n * try {\n * const files = await vana.data.getUserFiles({ owner: '0x...' });\n * } catch (error) {\n * if (error instanceof NetworkError) {\n * // Implement retry with exponential backoff\n * await retryWithBackoff(() => vana.data.getUserFiles({ owner: '0x...' }));\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class NetworkError extends VanaError {\n constructor(\n message: string,\n public readonly originalError?: Error,\n ) {\n super(message, \"NETWORK_ERROR\");\n }\n}\n\n/**\n * Thrown when transaction nonce retrieval fails during gasless operations.\n *\n * @remarks\n * This error occurs when the SDK cannot retrieve the user's current nonce from\n * smart contracts, preventing gasless transaction submission. Nonces are critical\n * for preventing replay attacks in signed transactions.\n *\n * Recovery strategies:\n * - Retry nonce retrieval after brief delay\n * - Check wallet connection and account status\n * - Use manual nonce specification if supported by the operation\n * - Switch to direct transactions as fallback\n *\n * @example\n * ```typescript\n * try {\n * await vana.permissions.grant({ grantee: '0x...' });\n * } catch (error) {\n * if (error instanceof NonceError) {\n * // Wait and retry\n * await delay(1000);\n * await vana.permissions.grant({ grantee: '0x...' });\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class NonceError extends VanaError {\n constructor(message: string) {\n super(message, \"NONCE_ERROR\");\n }\n}\n\n/**\n * Thrown when personal server operations fail or cannot be completed.\n *\n * @remarks\n * This error occurs during interactions with personal servers for computation\n * requests, identity retrieval, or operation status checks. Common causes include\n * server unavailability, untrusted server status, or invalid permission grants.\n *\n * Recovery strategies:\n * - Verify server URL accessibility\n * - Check server trust status via `vana.permissions.getTrustedServers()`\n * - Ensure valid permissions exist for the operation\n * - Retry after server becomes available\n *\n * @example\n * ```typescript\n * try {\n * const result = await vana.server.createOperation({ permissionId: 123 });\n * } catch (error) {\n * if (error instanceof PersonalServerError) {\n * // Check if server is trusted\n * const trustedServers = await vana.permissions.getTrustedServers();\n * if (!trustedServers.includes(serverId)) {\n * await vana.permissions.trustServer({ serverId });\n * }\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class PersonalServerError extends VanaError {\n constructor(\n message: string,\n public readonly originalError?: Error,\n ) {\n super(message, \"PERSONAL_SERVER_ERROR\");\n }\n}\n\n/**\n * Thrown when attempting to register a server with a URL different from its existing registration.\n *\n * @remarks\n * This error occurs when trying to add or trust a server that's already registered\n * on-chain with a different URL. Server URLs are immutable once registered to\n * maintain consistency and security. Applications should use the existing URL\n * or register a new server with a different ID.\n *\n * @example\n * ```typescript\n * try {\n * await vana.permissions.addAndTrustServer({\n * serverId: 1,\n * serverUrl: 'https://new-url.com',\n * publicKey: '0x...'\n * });\n * } catch (error) {\n * if (error instanceof ServerUrlMismatchError) {\n * console.log(`Server already registered with: ${error.existingUrl}`);\n * // Use existing URL or register new server\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class ServerUrlMismatchError extends VanaError {\n constructor(existingUrl: string, providedUrl: string, serverId: string) {\n super(\n `Server ${serverId} is already registered with URL \"${existingUrl}\". Cannot change to \"${providedUrl}\".`,\n \"SERVER_URL_MISMATCH\",\n );\n this.existingUrl = existingUrl;\n this.providedUrl = providedUrl;\n this.serverId = serverId;\n }\n\n public readonly existingUrl: string;\n public readonly providedUrl: string;\n public readonly serverId: string;\n}\n\n/**\n * Thrown when permission grant, revoke, or validation operations fail.\n *\n * @remarks\n * This error occurs during permission management operations including grants,\n * revocations, and permission validation checks. Common causes include invalid\n * grantee addresses, expired permissions, or insufficient privileges.\n *\n * @example\n * ```typescript\n * try {\n * await vana.permissions.revoke({ permissionId: 999999 });\n * } catch (error) {\n * if (error instanceof PermissionError) {\n * console.error('Permission operation failed:', error.message);\n * // Permission may not exist or user may not be owner\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class PermissionError extends VanaError {\n constructor(\n message: string,\n public readonly originalError?: Error,\n ) {\n super(message, \"PERMISSION_ERROR\");\n }\n}\n\n/**\n * Thrown when attempting to perform write operations without a wallet client.\n *\n * @remarks\n * This error occurs when trying to execute operations that require wallet\n * interaction (signing, encrypting, or submitting transactions) while the SDK\n * is initialized in read-only mode without a wallet client. To perform write\n * operations, the SDK must be initialized with a wallet client.\n *\n * Common operations that require a wallet:\n * - Signing transactions or typed data\n * - Encrypting or decrypting files\n * - Granting or revoking permissions\n * - Uploading data to IPFS\n * - Submitting blockchain transactions\n *\n * @example\n * ```typescript\n * try {\n * // This will throw if no wallet client is provided\n * await vana.data.decryptFile({ fileId: 'abc123' });\n * } catch (error) {\n * if (error instanceof ReadOnlyError) {\n * console.error(`Cannot ${error.operation}: ${error.message}`);\n * // Initialize with wallet client to enable write operations\n * const vanaWithWallet = Vana({\n * walletClient: createWalletClient(...)\n * });\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class ReadOnlyError extends VanaError {\n constructor(\n operation: string,\n suggestion: string = \"Initialize the SDK with a walletClient to perform this operation\",\n ) {\n super(\n `Operation '${operation}' requires a wallet client. ${suggestion}`,\n \"READ_ONLY_ERROR\",\n );\n this.operation = operation;\n this.suggestion = suggestion;\n }\n\n /** The operation that was attempted */\n public readonly operation: string;\n /** Suggested solution for fixing the error */\n public readonly suggestion: string;\n}\n\n/**\n * Thrown when a long-running transaction operation times out or fails during polling.\n *\n * @remarks\n * This error occurs when asynchronous relayer operations exceed the configured timeout\n * or encounter non-recoverable errors during status polling. It preserves the operation ID\n * to allow recovery and status checking at a later time.\n *\n * The error includes:\n * - Operation ID for recovery and status checking\n * - Last known status before failure\n * - Original error details\n *\n * Recovery strategies:\n * - Save the operation ID for later status checking\n * - Implement manual recovery flow using the operation ID\n * - Check transaction status through alternative means\n * - Contact support if operation remains stuck\n *\n * @example\n * ```typescript\n * try {\n * const result = await vana.permissions.grant({\n * grantee: '0x...',\n * files: [1, 2, 3]\n * });\n * } catch (error) {\n * if (error instanceof TransactionPendingError) {\n * // Save operation ID for recovery\n * localStorage.setItem('pending_operation', error.operationId);\n *\n * // Show recovery UI\n * showRecoveryDialog({\n * operationId: error.operationId,\n * lastStatus: error.lastKnownStatus\n * });\n *\n * // Attempt recovery later\n * const status = await vana.checkOperationStatus(error.operationId);\n * }\n * }\n * ```\n * @category Error Handling\n */\nexport class TransactionPendingError extends VanaError {\n constructor(\n /** The operation ID that can be used for status checking */\n public readonly operationId: string,\n message: string,\n /** The last known status of the operation before failure */\n public readonly lastKnownStatus?: unknown,\n ) {\n super(\n `Transaction operation pending: ${message} (operationId: ${operationId})`,\n \"TRANSACTION_PENDING\",\n );\n }\n\n /**\n * Converts the error to a JSON-serializable format.\n *\n * @remarks\n * Useful for logging, storage, or transmission of error details.\n *\n * @returns JSON representation of the error\n */\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n operationId: this.operationId,\n lastKnownStatus: this.lastKnownStatus,\n };\n }\n}\n\n/**\n * Personal Server error codes a Write API call can surface in\n * {@link PersonalServerWriteError.errorCode}.\n *\n * @remarks\n * The `WRITE_*` and `LINEAGE_*` codes are specific to the Write API; the\n * rest are the shared protocol codes the write policy reuses. The string\n * escape hatch keeps codes introduced by a newer Personal Server readable.\n * @category Error Handling\n */\nexport type PersonalServerWriteErrorCode =\n | \"WRITE_SESSION_AUTH_FAILED\"\n | \"WRITE_SESSION_PROOF_REQUIRED\"\n | \"WRITE_SESSION_PROOF_REPLAY\"\n | \"GRANT_ID_REQUIRED\"\n | \"WRITE_ATTRIBUTION_REQUIRED\"\n | \"WRITE_ATTRIBUTION_INVALID\"\n | \"WRITE_ATTRIBUTION_SIGNER_MISMATCH\"\n | \"WRITE_ATTRIBUTION_GRANT_MISMATCH\"\n | \"WRITE_ATTRIBUTION_REPLAY\"\n | \"WRITE_BODY_NOT_CANONICAL\"\n | \"LINEAGE_INVALID\"\n | \"LINEAGE_SCOPE_UNDER_SOURCE_PREFIX\"\n | \"LINEAGE_SOURCE_UNKNOWN\"\n | \"LINEAGE_SOURCE_LOOKUP_FAILED\"\n | \"LINEAGE_FORBIDDEN\"\n | \"LINEAGE_GATEWAY_ERROR\"\n | \"LINEAGE_UNAVAILABLE\"\n | \"LINEAGE_CASCADE_UNAVAILABLE\"\n | \"LINEAGE_SIGNATURE_REQUIRED\"\n | \"LINEAGE_SIGNATURE_INVALID\"\n | \"INVALID_CASCADE\"\n | \"INVALID_VERSION\"\n | \"NOT_FOUND\"\n | \"MISSING_AUTH\"\n | \"INVALID_SIGNATURE\"\n | \"UNREGISTERED_BUILDER\"\n | \"GRANT_REQUIRED\"\n | \"GRANT_REVOKED\"\n | \"GRANT_EXPIRED\"\n | \"GRANT_OWNER_MISMATCH\"\n | \"SCOPE_MISMATCH\"\n | \"INVALID_BODY\"\n | \"CONTENT_TOO_LARGE\"\n | \"PS_UNAVAILABLE\"\n | \"SERVER_NOT_CONFIGURED\"\n | \"INTERNAL_ERROR\"\n | (string & {});\n\n/**\n * Base class for every Personal Server Write API failure.\n *\n * @remarks\n * `status` is the HTTP status the Personal Server answered with (absent for\n * failures raised before a request was sent or when no response arrived),\n * `errorCode` is the Personal Server's protocol error code when the body\n * carried one, and `details` is the server-supplied detail object.\n * @category Error Handling\n */\nexport class PersonalServerWriteError extends VanaError {\n constructor(\n message: string,\n code: string,\n public readonly status?: number,\n public readonly errorCode: PersonalServerWriteErrorCode | null = null,\n public readonly details?: Record<string, unknown>,\n ) {\n super(message, code);\n }\n}\n\n/**\n * Thrown before any request is sent when the write input is invalid: no\n * payload, a payload that is not a JSON object, a reserved `$writtenBy` /\n * `$lineage` key, a malformed lineage source id, or an unusable signer.\n * @category Error Handling\n */\nexport class WriteRequestError extends PersonalServerWriteError {\n constructor(message: string, details?: Record<string, unknown>) {\n super(message, \"WRITE_INVALID_REQUEST\", undefined, null, details);\n }\n}\n\n/**\n * Thrown when the transport failed (fetch threw) on every attempt.\n *\n * @remarks\n * A write whose response was lost may still have been stored: the Personal\n * Server commits before answering. Check the scope before re-sending the\n * same record.\n * @category Error Handling\n */\nexport class WriteTransportError extends PersonalServerWriteError {\n constructor(\n message: string,\n public readonly attempts: number,\n cause?: unknown,\n ) {\n super(message, \"WRITE_TRANSPORT_ERROR\", undefined, null, { attempts });\n this.cause = cause;\n }\n}\n\n/**\n * Thrown when `POST /v1/write/session` refused the handshake (any non-2xx),\n * or answered with a body the SDK cannot read.\n * @category Error Handling\n */\nexport class WriteSessionError extends PersonalServerWriteError {\n constructor(\n message: string,\n status?: number,\n errorCode: PersonalServerWriteErrorCode | null = null,\n details?: Record<string, unknown>,\n ) {\n super(message, \"WRITE_SESSION_REJECTED\", status, errorCode, details);\n }\n}\n\n/**\n * Thrown by {@link writeData} when the session's bearer token has passed its\n * `expires_in` lifetime. Open a new session; nothing was sent.\n * @category Error Handling\n */\nexport class WriteSessionExpiredError extends PersonalServerWriteError {\n constructor(message: string, details?: Record<string, unknown>) {\n super(message, \"WRITE_SESSION_EXPIRED\", undefined, null, details);\n }\n}\n\n/**\n * Thrown when a write answered 401.\n *\n * @remarks\n * `WRITE_ATTRIBUTION_*` codes describe the per-write proof. A plain\n * `INVALID_SIGNATURE` or `MISSING_AUTH` on a write usually means the session\n * token is no longer known to the Personal Server (expired, or the server\n * restarted and dropped its in-memory sessions): open a new session.\n * @category Error Handling\n */\nexport class WriteUnauthorizedError extends PersonalServerWriteError {\n constructor(\n message: string,\n errorCode: PersonalServerWriteErrorCode | null = null,\n details?: Record<string, unknown>,\n ) {\n super(message, \"WRITE_UNAUTHORIZED\", 401, errorCode, details);\n }\n}\n\n/**\n * Thrown when a write answered 403: the live grant no longer authorizes it\n * (revoked, expired, wrong owner) or the scope is outside its write patterns.\n * @category Error Handling\n */\nexport class WriteForbiddenError extends PersonalServerWriteError {\n constructor(\n message: string,\n errorCode: PersonalServerWriteErrorCode | null = null,\n details?: Record<string, unknown>,\n ) {\n super(message, \"WRITE_FORBIDDEN\", 403, errorCode, details);\n }\n}\n\n/**\n * Thrown when a write answered 409 (the record conflicts with server state).\n * @category Error Handling\n */\nexport class WriteConflictError extends PersonalServerWriteError {\n constructor(\n message: string,\n errorCode: PersonalServerWriteErrorCode | null = null,\n details?: Record<string, unknown>,\n ) {\n super(message, \"WRITE_CONFLICT\", 409, errorCode, details);\n }\n}\n\n/**\n * Thrown when the Personal Server rejected the write's lineage: 422\n * `LINEAGE_SOURCE_UNKNOWN` (`details.unknown` lists the offending ids), 400\n * `LINEAGE_INVALID` / `LINEAGE_SCOPE_UNDER_SOURCE_PREFIX`, or 502\n * `LINEAGE_SOURCE_LOOKUP_FAILED`.\n * @category Error Handling\n */\nexport class WriteLineageError extends PersonalServerWriteError {\n constructor(\n message: string,\n status = 422,\n errorCode: PersonalServerWriteErrorCode | null = null,\n details?: Record<string, unknown>,\n ) {\n super(message, \"WRITE_LINEAGE_REJECTED\", status, errorCode, details);\n }\n}\n\n/**\n * Thrown when a write answered any other non-2xx status (400 for a body the\n * server cannot store, 413 for an oversized payload, 5xx).\n * @category Error Handling\n */\nexport class WriteRejectedError extends PersonalServerWriteError {\n constructor(\n message: string,\n status: number,\n errorCode: PersonalServerWriteErrorCode | null = null,\n details?: Record<string, unknown>,\n ) {\n super(message, \"WRITE_REJECTED\", status, errorCode, details);\n }\n}\n\n/**\n * Thrown when a lineage read (Personal Server or gateway) fails: a non-2xx\n * answer, a body that is not a lineage graph, a malformed data point id, or\n * a transport failure.\n * @category Error Handling\n */\nexport class LineageReadError extends VanaError {\n constructor(\n message: string,\n public readonly status?: number,\n public readonly errorCode: PersonalServerWriteErrorCode | null = null,\n public readonly details?: Record<string, unknown>,\n ) {\n super(message, \"LINEAGE_READ_ER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AS,kBAAkB,KAAK,WAAW,OAAO;AAAA,EAC1D;AACF;AASO,MAAM,0BAA0B,yBAAyB;AAAA,EAC9D,YACE,SACA,SAAS,KACT,YAAiD,MACjD,SACA;AACA,UAAM,SAAS,0BAA0B,QAAQ,WAAW,OAAO;AAAA,EACrE;AACF;AAOO,MAAM,2BAA2B,yBAAyB;AAAA,EAC/D,YACE,SACA,QACA,YAAiD,MACjD,SACA;AACA,UAAM,SAAS,kBAAkB,QAAQ,WAAW,OAAO;AAAA,EAC7D;AACF;AAQO,MAAM,yBAAyB,UAAU;AAAA,EAC9C,YACE,SACgB,QACA,YAAiD,MACjD,SAChB;AACA,UAAM,SAAS,oBAAoB;AAJnB;AACA;AACA;AAAA,EAGlB;AAAA,EALkB;AAAA,EACA;AAAA,EACA;AAIpB;","names":[]}
package/dist/errors.d.ts CHANGED
@@ -450,3 +450,126 @@ export declare class TransactionPendingError extends VanaError {
450
450
  */
451
451
  toJSON(): Record<string, unknown>;
452
452
  }
453
+ /**
454
+ * Personal Server error codes a Write API call can surface in
455
+ * {@link PersonalServerWriteError.errorCode}.
456
+ *
457
+ * @remarks
458
+ * The `WRITE_*` and `LINEAGE_*` codes are specific to the Write API; the
459
+ * rest are the shared protocol codes the write policy reuses. The string
460
+ * escape hatch keeps codes introduced by a newer Personal Server readable.
461
+ * @category Error Handling
462
+ */
463
+ export type PersonalServerWriteErrorCode = "WRITE_SESSION_AUTH_FAILED" | "WRITE_SESSION_PROOF_REQUIRED" | "WRITE_SESSION_PROOF_REPLAY" | "GRANT_ID_REQUIRED" | "WRITE_ATTRIBUTION_REQUIRED" | "WRITE_ATTRIBUTION_INVALID" | "WRITE_ATTRIBUTION_SIGNER_MISMATCH" | "WRITE_ATTRIBUTION_GRANT_MISMATCH" | "WRITE_ATTRIBUTION_REPLAY" | "WRITE_BODY_NOT_CANONICAL" | "LINEAGE_INVALID" | "LINEAGE_SCOPE_UNDER_SOURCE_PREFIX" | "LINEAGE_SOURCE_UNKNOWN" | "LINEAGE_SOURCE_LOOKUP_FAILED" | "LINEAGE_FORBIDDEN" | "LINEAGE_GATEWAY_ERROR" | "LINEAGE_UNAVAILABLE" | "LINEAGE_CASCADE_UNAVAILABLE" | "LINEAGE_SIGNATURE_REQUIRED" | "LINEAGE_SIGNATURE_INVALID" | "INVALID_CASCADE" | "INVALID_VERSION" | "NOT_FOUND" | "MISSING_AUTH" | "INVALID_SIGNATURE" | "UNREGISTERED_BUILDER" | "GRANT_REQUIRED" | "GRANT_REVOKED" | "GRANT_EXPIRED" | "GRANT_OWNER_MISMATCH" | "SCOPE_MISMATCH" | "INVALID_BODY" | "CONTENT_TOO_LARGE" | "PS_UNAVAILABLE" | "SERVER_NOT_CONFIGURED" | "INTERNAL_ERROR" | (string & {});
464
+ /**
465
+ * Base class for every Personal Server Write API failure.
466
+ *
467
+ * @remarks
468
+ * `status` is the HTTP status the Personal Server answered with (absent for
469
+ * failures raised before a request was sent or when no response arrived),
470
+ * `errorCode` is the Personal Server's protocol error code when the body
471
+ * carried one, and `details` is the server-supplied detail object.
472
+ * @category Error Handling
473
+ */
474
+ export declare class PersonalServerWriteError extends VanaError {
475
+ readonly status?: number | undefined;
476
+ readonly errorCode: PersonalServerWriteErrorCode | null;
477
+ readonly details?: Record<string, unknown> | undefined;
478
+ constructor(message: string, code: string, status?: number | undefined, errorCode?: PersonalServerWriteErrorCode | null, details?: Record<string, unknown> | undefined);
479
+ }
480
+ /**
481
+ * Thrown before any request is sent when the write input is invalid: no
482
+ * payload, a payload that is not a JSON object, a reserved `$writtenBy` /
483
+ * `$lineage` key, a malformed lineage source id, or an unusable signer.
484
+ * @category Error Handling
485
+ */
486
+ export declare class WriteRequestError extends PersonalServerWriteError {
487
+ constructor(message: string, details?: Record<string, unknown>);
488
+ }
489
+ /**
490
+ * Thrown when the transport failed (fetch threw) on every attempt.
491
+ *
492
+ * @remarks
493
+ * A write whose response was lost may still have been stored: the Personal
494
+ * Server commits before answering. Check the scope before re-sending the
495
+ * same record.
496
+ * @category Error Handling
497
+ */
498
+ export declare class WriteTransportError extends PersonalServerWriteError {
499
+ readonly attempts: number;
500
+ constructor(message: string, attempts: number, cause?: unknown);
501
+ }
502
+ /**
503
+ * Thrown when `POST /v1/write/session` refused the handshake (any non-2xx),
504
+ * or answered with a body the SDK cannot read.
505
+ * @category Error Handling
506
+ */
507
+ export declare class WriteSessionError extends PersonalServerWriteError {
508
+ constructor(message: string, status?: number, errorCode?: PersonalServerWriteErrorCode | null, details?: Record<string, unknown>);
509
+ }
510
+ /**
511
+ * Thrown by {@link writeData} when the session's bearer token has passed its
512
+ * `expires_in` lifetime. Open a new session; nothing was sent.
513
+ * @category Error Handling
514
+ */
515
+ export declare class WriteSessionExpiredError extends PersonalServerWriteError {
516
+ constructor(message: string, details?: Record<string, unknown>);
517
+ }
518
+ /**
519
+ * Thrown when a write answered 401.
520
+ *
521
+ * @remarks
522
+ * `WRITE_ATTRIBUTION_*` codes describe the per-write proof. A plain
523
+ * `INVALID_SIGNATURE` or `MISSING_AUTH` on a write usually means the session
524
+ * token is no longer known to the Personal Server (expired, or the server
525
+ * restarted and dropped its in-memory sessions): open a new session.
526
+ * @category Error Handling
527
+ */
528
+ export declare class WriteUnauthorizedError extends PersonalServerWriteError {
529
+ constructor(message: string, errorCode?: PersonalServerWriteErrorCode | null, details?: Record<string, unknown>);
530
+ }
531
+ /**
532
+ * Thrown when a write answered 403: the live grant no longer authorizes it
533
+ * (revoked, expired, wrong owner) or the scope is outside its write patterns.
534
+ * @category Error Handling
535
+ */
536
+ export declare class WriteForbiddenError extends PersonalServerWriteError {
537
+ constructor(message: string, errorCode?: PersonalServerWriteErrorCode | null, details?: Record<string, unknown>);
538
+ }
539
+ /**
540
+ * Thrown when a write answered 409 (the record conflicts with server state).
541
+ * @category Error Handling
542
+ */
543
+ export declare class WriteConflictError extends PersonalServerWriteError {
544
+ constructor(message: string, errorCode?: PersonalServerWriteErrorCode | null, details?: Record<string, unknown>);
545
+ }
546
+ /**
547
+ * Thrown when the Personal Server rejected the write's lineage: 422
548
+ * `LINEAGE_SOURCE_UNKNOWN` (`details.unknown` lists the offending ids), 400
549
+ * `LINEAGE_INVALID` / `LINEAGE_SCOPE_UNDER_SOURCE_PREFIX`, or 502
550
+ * `LINEAGE_SOURCE_LOOKUP_FAILED`.
551
+ * @category Error Handling
552
+ */
553
+ export declare class WriteLineageError extends PersonalServerWriteError {
554
+ constructor(message: string, status?: number, errorCode?: PersonalServerWriteErrorCode | null, details?: Record<string, unknown>);
555
+ }
556
+ /**
557
+ * Thrown when a write answered any other non-2xx status (400 for a body the
558
+ * server cannot store, 413 for an oversized payload, 5xx).
559
+ * @category Error Handling
560
+ */
561
+ export declare class WriteRejectedError extends PersonalServerWriteError {
562
+ constructor(message: string, status: number, errorCode?: PersonalServerWriteErrorCode | null, details?: Record<string, unknown>);
563
+ }
564
+ /**
565
+ * Thrown when a lineage read (Personal Server or gateway) fails: a non-2xx
566
+ * answer, a body that is not a lineage graph, a malformed data point id, or
567
+ * a transport failure.
568
+ * @category Error Handling
569
+ */
570
+ export declare class LineageReadError extends VanaError {
571
+ readonly status?: number | undefined;
572
+ readonly errorCode: PersonalServerWriteErrorCode | null;
573
+ readonly details?: Record<string, unknown> | undefined;
574
+ constructor(message: string, status?: number | undefined, errorCode?: PersonalServerWriteErrorCode | null, details?: Record<string, unknown> | undefined);
575
+ }
package/dist/errors.js CHANGED
@@ -138,14 +138,86 @@ class TransactionPendingError extends VanaError {
138
138
  };
139
139
  }
140
140
  }
141
+ class PersonalServerWriteError extends VanaError {
142
+ constructor(message, code, status, errorCode = null, details) {
143
+ super(message, code);
144
+ this.status = status;
145
+ this.errorCode = errorCode;
146
+ this.details = details;
147
+ }
148
+ status;
149
+ errorCode;
150
+ details;
151
+ }
152
+ class WriteRequestError extends PersonalServerWriteError {
153
+ constructor(message, details) {
154
+ super(message, "WRITE_INVALID_REQUEST", void 0, null, details);
155
+ }
156
+ }
157
+ class WriteTransportError extends PersonalServerWriteError {
158
+ constructor(message, attempts, cause) {
159
+ super(message, "WRITE_TRANSPORT_ERROR", void 0, null, { attempts });
160
+ this.attempts = attempts;
161
+ this.cause = cause;
162
+ }
163
+ attempts;
164
+ }
165
+ class WriteSessionError extends PersonalServerWriteError {
166
+ constructor(message, status, errorCode = null, details) {
167
+ super(message, "WRITE_SESSION_REJECTED", status, errorCode, details);
168
+ }
169
+ }
170
+ class WriteSessionExpiredError extends PersonalServerWriteError {
171
+ constructor(message, details) {
172
+ super(message, "WRITE_SESSION_EXPIRED", void 0, null, details);
173
+ }
174
+ }
175
+ class WriteUnauthorizedError extends PersonalServerWriteError {
176
+ constructor(message, errorCode = null, details) {
177
+ super(message, "WRITE_UNAUTHORIZED", 401, errorCode, details);
178
+ }
179
+ }
180
+ class WriteForbiddenError extends PersonalServerWriteError {
181
+ constructor(message, errorCode = null, details) {
182
+ super(message, "WRITE_FORBIDDEN", 403, errorCode, details);
183
+ }
184
+ }
185
+ class WriteConflictError extends PersonalServerWriteError {
186
+ constructor(message, errorCode = null, details) {
187
+ super(message, "WRITE_CONFLICT", 409, errorCode, details);
188
+ }
189
+ }
190
+ class WriteLineageError extends PersonalServerWriteError {
191
+ constructor(message, status = 422, errorCode = null, details) {
192
+ super(message, "WRITE_LINEAGE_REJECTED", status, errorCode, details);
193
+ }
194
+ }
195
+ class WriteRejectedError extends PersonalServerWriteError {
196
+ constructor(message, status, errorCode = null, details) {
197
+ super(message, "WRITE_REJECTED", status, errorCode, details);
198
+ }
199
+ }
200
+ class LineageReadError extends VanaError {
201
+ constructor(message, status, errorCode = null, details) {
202
+ super(message, "LINEAGE_READ_ERROR");
203
+ this.status = status;
204
+ this.errorCode = errorCode;
205
+ this.details = details;
206
+ }
207
+ status;
208
+ errorCode;
209
+ details;
210
+ }
141
211
  export {
142
212
  BlockchainError,
143
213
  ContractNotFoundError,
144
214
  InvalidConfigurationError,
215
+ LineageReadError,
145
216
  NetworkError,
146
217
  NonceError,
147
218
  PermissionError,
148
219
  PersonalServerError,
220
+ PersonalServerWriteError,
149
221
  ReadOnlyError,
150
222
  RelayerError,
151
223
  SerializationError,
@@ -153,6 +225,15 @@ export {
153
225
  SignatureError,
154
226
  TransactionPendingError,
155
227
  UserRejectedRequestError,
156
- VanaError
228
+ VanaError,
229
+ WriteConflictError,
230
+ WriteForbiddenError,
231
+ WriteLineageError,
232
+ WriteRejectedError,
233
+ WriteRequestError,
234
+ WriteSessionError,
235
+ WriteSessionExpiredError,
236
+ WriteTransportError,
237
+ WriteUnauthorizedError
157
238
  };
158
239
  //# sourceMappingURL=errors.js.map