@opendatalabs/connect 0.5.0-canary.d8d3c3d → 0.6.0-canary.e07e97e

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 (68) hide show
  1. package/README.md +83 -55
  2. package/dist/core/constants.d.ts +32 -2
  3. package/dist/core/constants.d.ts.map +1 -1
  4. package/dist/core/constants.js +24 -2
  5. package/dist/core/constants.js.map +1 -1
  6. package/dist/core/errors.d.ts +43 -2
  7. package/dist/core/errors.d.ts.map +1 -1
  8. package/dist/core/errors.js +39 -0
  9. package/dist/core/errors.js.map +1 -1
  10. package/dist/core/grants.d.ts +19 -0
  11. package/dist/core/grants.d.ts.map +1 -0
  12. package/dist/core/grants.js +31 -0
  13. package/dist/core/grants.js.map +1 -0
  14. package/dist/core/index.d.ts +3 -2
  15. package/dist/core/index.d.ts.map +1 -1
  16. package/dist/core/index.js +3 -2
  17. package/dist/core/index.js.map +1 -1
  18. package/dist/core/types.d.ts +62 -1
  19. package/dist/core/types.d.ts.map +1 -1
  20. package/dist/react/ConnectButton.d.ts +16 -1
  21. package/dist/react/ConnectButton.d.ts.map +1 -1
  22. package/dist/react/ConnectButton.js +12 -5
  23. package/dist/react/ConnectButton.js.map +1 -1
  24. package/dist/react/index.d.ts +1 -0
  25. package/dist/react/index.d.ts.map +1 -1
  26. package/dist/react/index.js +1 -0
  27. package/dist/react/index.js.map +1 -1
  28. package/dist/react/useVanaConnect.d.ts +35 -2
  29. package/dist/react/useVanaConnect.d.ts.map +1 -1
  30. package/dist/react/useVanaConnect.js +36 -8
  31. package/dist/react/useVanaConnect.js.map +1 -1
  32. package/dist/react/useVanaData.d.ts +69 -0
  33. package/dist/react/useVanaData.d.ts.map +1 -0
  34. package/dist/react/useVanaData.js +131 -0
  35. package/dist/react/useVanaData.js.map +1 -0
  36. package/dist/server/config.d.ts +36 -0
  37. package/dist/server/config.d.ts.map +1 -0
  38. package/dist/server/config.js +44 -0
  39. package/dist/server/config.js.map +1 -0
  40. package/dist/server/connect.d.ts +40 -1
  41. package/dist/server/connect.d.ts.map +1 -1
  42. package/dist/server/connect.js +64 -6
  43. package/dist/server/connect.js.map +1 -1
  44. package/dist/server/data-client.d.ts +17 -0
  45. package/dist/server/data-client.d.ts.map +1 -1
  46. package/dist/server/data-client.js +24 -7
  47. package/dist/server/data-client.js.map +1 -1
  48. package/dist/server/index.d.ts +3 -1
  49. package/dist/server/index.d.ts.map +1 -1
  50. package/dist/server/index.js +3 -1
  51. package/dist/server/index.js.map +1 -1
  52. package/dist/server/manifest-signer.d.ts +22 -0
  53. package/dist/server/manifest-signer.d.ts.map +1 -1
  54. package/dist/server/manifest-signer.js +22 -0
  55. package/dist/server/manifest-signer.js.map +1 -1
  56. package/dist/server/request-signer.d.ts +18 -0
  57. package/dist/server/request-signer.d.ts.map +1 -1
  58. package/dist/server/request-signer.js +6 -0
  59. package/dist/server/request-signer.js.map +1 -1
  60. package/dist/server/session-relay.d.ts +30 -2
  61. package/dist/server/session-relay.d.ts.map +1 -1
  62. package/dist/server/session-relay.js +12 -4
  63. package/dist/server/session-relay.js.map +1 -1
  64. package/dist/server/webhook.d.ts +11 -0
  65. package/dist/server/webhook.d.ts.map +1 -0
  66. package/dist/server/webhook.js +18 -0
  67. package/dist/server/webhook.js.map +1 -0
  68. package/package.json +3 -4
package/README.md CHANGED
@@ -1,8 +1,14 @@
1
1
  # Vana Connect SDK
2
2
 
3
- Let your users customize your app with their own data.
3
+ Let your users bring their own data to your app.
4
4
 
5
- Users connect platforms they already use — ChatGPT, Instagram, Gmail, and more — through the [Vana Desktop App](https://www.vana.com/download), which keeps them in control of what's shared. Your app receives structured, user-consented data through a cryptographically verified grant. No scraping, no OAuth token juggling, no compliance gray areas.
5
+ ## What problem this solves
6
+
7
+ Your users already have rich personal data — ChatGPT conversations, Instagram activity, Gmail, purchase history — but it's locked inside the platforms that collected it. As a builder, you can't easily use that data to personalize onboarding, tailor recommendations, or skip lengthy signup forms.
8
+
9
+ **Data portability** means users can export their data from these platforms and grant your app scoped access to it — with their explicit consent, cryptographic verification, and full control over what's shared and when to revoke it.
10
+
11
+ Today, getting access to user data means asking for manual file uploads (high friction), scraping on their behalf (fragile and legally risky), or negotiating enterprise API deals (slow and expensive). This SDK gives you a standardized way to request and receive personal data through Vana's [Data Portability Protocol](https://docs.vana.org/), handling session creation, grant verification, and data fetching in three function calls.
6
12
 
7
13
  ## How it works
8
14
 
@@ -12,9 +18,9 @@ Your App Vana Protocol
12
18
 
13
19
  1. connect({ scopes })
14
20
  → creates session
15
- → returns deep link ──▶ 2. User opens Desktop App
16
- reviews scopes, exports data,
17
- approves grant
21
+ → returns deep link ──▶ 2. User opens DataConnect
22
+ reviews scopes, exports data,
23
+ approves grant
18
24
 
19
25
  3. Poll resolves with grant ◀── Grant signed & registered
20
26
 
@@ -22,32 +28,53 @@ Your App Vana Protocol
22
28
  → structured JSON user data over TLS
23
29
  ```
24
30
 
25
- The SDK handles session creation, cryptographic request signing, polling, and data fetching. You write three function calls; the protocol handles the rest.
31
+ The [Data Portability Protocol](https://docs.vana.org/) defines how users collect data from platforms, store it under their control (on-device or hosted), and grant third-party apps scoped access. This SDK handles session creation, cryptographic request signing, polling, and data fetching. You write three function calls; the protocol handles the rest.
26
32
 
27
- ## Where this fits in the Vana protocol
33
+ ## Getting started
28
34
 
29
- The [Data Portability Protocol](https://docs.vana.org) defines how users collect data from platforms, store it under their control (on-device or hosted), and grant third-party apps scoped access. The protocol participants are:
35
+ The fastest way to get up and running is with the **Next.js starter** a complete working app with session creation, polling, data fetching, manifest signing, and webhook handling already wired up:
30
36
 
31
- - **Personal Server** — stores and serves user data, enforces grants
32
- - **Data Portability Gateway** — fast API with eventual on-chain consistency
33
- - **Vana L1** — on-chain source of truth for grants, builder registry, and file records
37
+ ```bash
38
+ git clone https://github.com/vana-com/vana-connect.git
39
+ cd vana-connect/examples/nextjs-starter
40
+ cp .env.local.example .env.local
41
+ # Edit .env.local with your private key and APP_URL
42
+ pnpm install
43
+ pnpm dev
44
+ ```
45
+
46
+ For local development, use the pre-registered dev key in .env.local
47
+
48
+ ```
49
+ VANA_PRIVATE_KEY=0x3c05ac1a00546bc0b1b8d3a11fb908409005fac3f26d25f70711e4f632e720d3
50
+ APP_URL=http://localhost:3001
51
+ ```
34
52
 
35
- **This SDK is the builder integration layer.** It sits between your app and the protocol, abstracting the Session Relay handshake, Web3Signed authentication, and Personal Server data fetching into a clean API.
53
+ See [`examples/nextjs-starter`](./examples/nextjs-starter) for full details.
36
54
 
37
- ## Installation
55
+ ---
56
+
57
+ ## Manual integration
58
+
59
+ If you prefer to integrate the SDK into an existing project, follow the steps below.
60
+
61
+ ### Installation
38
62
 
39
63
  ```bash
40
- npm install @opendatalabs/connect
64
+ pnpm add @opendatalabs/connect
41
65
  ```
42
66
 
43
- ## Prerequisites
67
+ ### Package manager
68
+
69
+ This repo is pnpm-only for local development and examples. Use `pnpm` commands, not `npm`.
44
70
 
45
- Register as a builder through the Vana Desktop App first.
71
+ ### Prerequisites
46
72
 
73
+ First, register your app in the [Developer Portal](https://vana-developers.replit.app/). You will need to provide the URL where your app will be deployed, and then be given a private key after registration.
47
74
 
48
- ## Quickstart
75
+ ### Quickstart
49
76
 
50
- ### 1. Create a session (server)
77
+ #### 1. Create a session (server)
51
78
 
52
79
  ```typescript
53
80
  import { connect } from "@opendatalabs/connect/server";
@@ -55,17 +82,17 @@ import { connect } from "@opendatalabs/connect/server";
55
82
  const session = await connect({
56
83
  privateKey: process.env.VANA_APP_PRIVATE_KEY as `0x${string}`,
57
84
  scopes: ["chatgpt.conversations"],
58
- webhookUrl: "https://yourapp.com/api/webhook", // optional
59
- appUserId: "user-42", // optional
85
+ webhookUrl: "https://yourapp.com/api/webhook", // optional, data can be pushed to a web hook after a grant is approved
86
+ appUserId: "yourapp-user-42", // optional: this is used to corelate your app user with the data they provided
60
87
  });
61
88
 
62
89
  // Return to your frontend:
63
90
  // session.sessionId — used for polling
64
- // session.deepLinkUrl — opens the Vana Desktop App
91
+ // session.deepLinkUrl — opens the DataConnect App
65
92
  // session.expiresAt — ISO 8601 expiration
66
93
  ```
67
94
 
68
- ### 2. Poll for user approval (client)
95
+ #### 2. Poll for user approval (client)
69
96
 
70
97
  ```tsx
71
98
  import { useVanaConnect } from "@opendatalabs/connect/react";
@@ -97,10 +124,10 @@ import { ConnectButton } from "@opendatalabs/connect/react";
97
124
  sessionId={sessionId}
98
125
  onComplete={(grant) => saveGrant(grant)}
99
126
  onError={(err) => console.error(err)}
100
- />
127
+ />;
101
128
  ```
102
129
 
103
- ### 3. Fetch user data (server)
130
+ #### 3. Fetch user data (server)
104
131
 
105
132
  ```typescript
106
133
  import { getData } from "@opendatalabs/connect/server";
@@ -110,13 +137,13 @@ const data = await getData({
110
137
  grant, // GrantPayload from step 2
111
138
  });
112
139
 
113
- // Map<string, unknown> keyed by scope
114
- const conversations = data.get("chatgpt.conversations");
140
+ // Record<string, unknown> keyed by scope
141
+ const conversations = data["chatgpt.conversations"];
115
142
  ```
116
143
 
117
- ### Web App Manifest
144
+ #### Web App Manifest
118
145
 
119
- The Desktop App verifies your identity by fetching your manifest. Use `signVanaManifest()` to generate it:
146
+ The DataConnect App verifies your identity by fetching your manifest. Use `signVanaManifest()` to generate it:
120
147
 
121
148
  ```typescript
122
149
  import { signVanaManifest } from "@opendatalabs/connect/server";
@@ -142,35 +169,40 @@ const manifest = {
142
169
 
143
170
  Make sure your HTML includes `<link rel="manifest" href="/manifest.json">`.
144
171
 
172
+ ## Connectors
173
+
174
+ Available data connectors and their scopes (schema definitions):
175
+ [`vana-com/data-connectors/schemas`](https://github.com/vana-com/data-connectors/tree/main/schemas)
176
+
145
177
  ## API Reference
146
178
 
147
179
  ### Entrypoints
148
180
 
149
- | Import | Environment | Exports |
150
- | ------------------------------- | ----------- | ---------------------------------------------------------------- |
151
- | `@opendatalabs/connect/server` | Node.js | `connect()`, `getData()`, `signVanaManifest()`, low-level clients |
152
- | `@opendatalabs/connect/react` | Browser | `useVanaConnect()`, `ConnectButton` |
153
- | `@opendatalabs/connect/core` | Universal | Types, `ConnectError`, constants |
181
+ | Import | Environment | Exports |
182
+ | ------------------------------ | ----------- | ----------------------------------------------------------------- |
183
+ | `@opendatalabs/connect/server` | Node.js | `connect()`, `getData()`, `signVanaManifest()`, low-level clients |
184
+ | `@opendatalabs/connect/react` | Browser | `useVanaConnect()`, `useVanaData()`, `ConnectButton` |
185
+ | `@opendatalabs/connect/core` | Universal | Types, `ConnectError`, constants |
154
186
 
155
187
  ### `connect(config): Promise<SessionInitResult>`
156
188
 
157
189
  Creates a session on the Session Relay. Returns `sessionId`, `deepLinkUrl`, and `expiresAt`.
158
190
 
159
- | Param | Type | Required | Description |
160
- | ------------ | -------------- | -------- | ----------------------------------- |
161
- | `privateKey` | `` `0x${string}` `` | Yes | Builder private key |
162
- | `scopes` | `string[]` | Yes | Data scopes to request |
163
- | `webhookUrl` | `string` | No | URL for grant event notifications |
164
- | `appUserId` | `string` | No | Your app's user ID for correlation |
191
+ | Param | Type | Required | Description |
192
+ | ------------ | ------------------- | -------- | ---------------------------------------------------------------------- |
193
+ | `privateKey` | `` `0x${string}` `` | Yes | Builder private key |
194
+ | `scopes` | `string[]` | Yes | Data scopes to request |
195
+ | `webhookUrl` | `string` | No | Public HTTPS URL for grant event notifications (localhost is rejected) |
196
+ | `appUserId` | `string` | No | Your app's user ID for correlation |
165
197
 
166
- ### `getData(config): Promise<Map<string, unknown>>`
198
+ ### `getData(config): Promise<Record<string, unknown>>`
167
199
 
168
200
  Fetches user data from their Personal Server using a signed grant.
169
201
 
170
- | Param | Type | Required | Description |
171
- | ------------ | -------------- | -------- | ------------------------------- |
172
- | `privateKey` | `` `0x${string}` `` | Yes | Builder private key |
173
- | `grant` | `GrantPayload` | Yes | Grant from the approval step |
202
+ | Param | Type | Required | Description |
203
+ | ------------ | ------------------- | -------- | ---------------------------- |
204
+ | `privateKey` | `` `0x${string}` `` | Yes | Builder private key |
205
+ | `grant` | `GrantPayload` | Yes | Grant from the approval step |
174
206
 
175
207
  ### `useVanaConnect(config?): UseVanaConnectResult`
176
208
 
@@ -188,12 +220,12 @@ Returned when a user approves access:
188
220
 
189
221
  ```typescript
190
222
  interface GrantPayload {
191
- grantId: string; // on-chain permission ID
192
- userAddress: string; // user's wallet address
223
+ grantId: string; // on-chain permission ID
224
+ userAddress: string; // user's wallet address
193
225
  builderAddress: string; // your registered address
194
- scopes: string[]; // approved data scopes
226
+ scopes: string[]; // approved data scopes
195
227
  serverAddress?: string; // user's Personal Server
196
- appUserId?: string; // your app's user ID (if provided)
228
+ appUserId?: string; // your app's user ID (if provided)
197
229
  }
198
230
  ```
199
231
 
@@ -203,16 +235,12 @@ For full control over individual protocol interactions:
203
235
 
204
236
  ```typescript
205
237
  import {
206
- createRequestSigner, // Web3Signed header generation
207
- createSessionRelay, // Session Relay HTTP client
208
- createDataClient, // Data Gateway HTTP client
238
+ createRequestSigner, // Web3Signed header generation
239
+ createSessionRelay, // Session Relay HTTP client
240
+ createDataClient, // Data Gateway HTTP client
209
241
  } from "@opendatalabs/connect/server";
210
242
  ```
211
243
 
212
- ## Examples
213
-
214
- See [`examples/nextjs-starter`](./examples/nextjs-starter) for a complete working integration with Next.js, including manifest signing, webhook handling, and the full connect-to-data-fetch flow.
215
-
216
244
  ## License
217
245
 
218
246
  MIT
@@ -1,3 +1,33 @@
1
- export declare const SESSION_RELAY_URL = "https://session-relay-git-dev-opendatalabs.vercel.app";
2
- export declare const GATEWAY_URL = "https://data-gateway-env-dev-opendatalabs.vercel.app";
1
+ /** SDK environment selector. */
2
+ export type VanaEnvironment = "dev" | "prod";
3
+ /** URL configuration for each SDK environment. */
4
+ export declare const ENV_CONFIG: {
5
+ readonly dev: {
6
+ readonly sessionRelayUrl: "https://dev.session-relay.vana.org";
7
+ readonly gatewayUrl: "https://dev.data-gateway.vana.org";
8
+ readonly accountUrl: "https://account-dev.vana.org";
9
+ };
10
+ readonly prod: {
11
+ readonly sessionRelayUrl: "https://session-relay.vana.org";
12
+ readonly gatewayUrl: "https://data-gateway.vana.org";
13
+ readonly accountUrl: "https://account.vana.org";
14
+ };
15
+ };
16
+ /** Default environment used when none is specified. */
17
+ export declare const DEFAULT_ENVIRONMENT: VanaEnvironment;
18
+ /**
19
+ * Returns the URL configuration for the given environment.
20
+ *
21
+ * @param environment - `"dev"` or `"prod"`. Defaults to {@link DEFAULT_ENVIRONMENT}.
22
+ * @returns An object with `sessionRelayUrl` and `gatewayUrl`.
23
+ */
24
+ export declare function getEnvConfig(environment?: VanaEnvironment): {
25
+ readonly sessionRelayUrl: "https://dev.session-relay.vana.org";
26
+ readonly gatewayUrl: "https://dev.data-gateway.vana.org";
27
+ readonly accountUrl: "https://account-dev.vana.org";
28
+ } | {
29
+ readonly sessionRelayUrl: "https://session-relay.vana.org";
30
+ readonly gatewayUrl: "https://data-gateway.vana.org";
31
+ readonly accountUrl: "https://account.vana.org";
32
+ };
3
33
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,0DAC2B,CAAC;AAC1D,eAAO,MAAM,WAAW,yDACgC,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,MAAM,CAAC;AAE7C,kDAAkD;AAClD,eAAO,MAAM,UAAU;;;;;;;;;;;CAWb,CAAC;AAEX,uDAAuD;AACvD,eAAO,MAAM,mBAAmB,EAAE,eAAwB,CAAC;AAE3D;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,WAAW,CAAC,EAAE,eAAe;;;;;;;;EAEzD"}
@@ -1,3 +1,25 @@
1
- export const SESSION_RELAY_URL = "https://session-relay-git-dev-opendatalabs.vercel.app";
2
- export const GATEWAY_URL = "https://data-gateway-env-dev-opendatalabs.vercel.app";
1
+ /** URL configuration for each SDK environment. */
2
+ export const ENV_CONFIG = {
3
+ dev: {
4
+ sessionRelayUrl: "https://dev.session-relay.vana.org",
5
+ gatewayUrl: "https://dev.data-gateway.vana.org",
6
+ accountUrl: "https://account-dev.vana.org",
7
+ },
8
+ prod: {
9
+ sessionRelayUrl: "https://session-relay.vana.org",
10
+ gatewayUrl: "https://data-gateway.vana.org",
11
+ accountUrl: "https://account.vana.org",
12
+ },
13
+ };
14
+ /** Default environment used when none is specified. */
15
+ export const DEFAULT_ENVIRONMENT = "prod";
16
+ /**
17
+ * Returns the URL configuration for the given environment.
18
+ *
19
+ * @param environment - `"dev"` or `"prod"`. Defaults to {@link DEFAULT_ENVIRONMENT}.
20
+ * @returns An object with `sessionRelayUrl` and `gatewayUrl`.
21
+ */
22
+ export function getEnvConfig(environment) {
23
+ return ENV_CONFIG[environment ?? DEFAULT_ENVIRONMENT];
24
+ }
3
25
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAC5B,uDAAuD,CAAC;AAC1D,MAAM,CAAC,MAAM,WAAW,GACtB,sDAAsD,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":"AAGA,kDAAkD;AAClD,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,GAAG,EAAE;QACH,eAAe,EAAE,oCAAoC;QACrD,UAAU,EAAE,mCAAmC;QAC/C,UAAU,EAAE,8BAA8B;KAC3C;IACD,IAAI,EAAE;QACJ,eAAe,EAAE,gCAAgC;QACjD,UAAU,EAAE,+BAA+B;QAC3C,UAAU,EAAE,0BAA0B;KACvC;CACO,CAAC;AAEX,uDAAuD;AACvD,MAAM,CAAC,MAAM,mBAAmB,GAAoB,MAAM,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,WAA6B;IACxD,OAAO,UAAU,CAAC,WAAW,IAAI,mBAAmB,CAAC,CAAC;AACxD,CAAC"}
@@ -1,6 +1,47 @@
1
+ /**
2
+ * Known error codes thrown by the SDK.
3
+ *
4
+ * Use these constants for typed `catch` handling instead of comparing raw strings.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { ConnectError, ConnectErrorCode } from "@opendatalabs/connect/core";
9
+ *
10
+ * try {
11
+ * await getData({ privateKey, grant });
12
+ * } catch (err) {
13
+ * if (err instanceof ConnectError && err.code === ConnectErrorCode.SERVER_NOT_FOUND) {
14
+ * // handle missing server
15
+ * }
16
+ * }
17
+ * ```
18
+ */
19
+ export declare const ConnectErrorCode: {
20
+ readonly SESSION_INIT_FAILED: "SESSION_INIT_FAILED";
21
+ readonly SESSION_EXPIRED: "SESSION_EXPIRED";
22
+ readonly POLL_FAILED: "POLL_FAILED";
23
+ readonly POLL_TIMEOUT: "POLL_TIMEOUT";
24
+ readonly SERVER_NOT_FOUND: "SERVER_NOT_FOUND";
25
+ readonly GATEWAY_ERROR: "GATEWAY_ERROR";
26
+ readonly DATA_FETCH_FAILED: "DATA_FETCH_FAILED";
27
+ readonly LIST_SCOPES_FAILED: "LIST_SCOPES_FAILED";
28
+ readonly LIST_VERSIONS_FAILED: "LIST_VERSIONS_FAILED";
29
+ readonly CONFIG_INVALID: "CONFIG_INVALID";
30
+ readonly WEBHOOK_INVALID: "WEBHOOK_INVALID";
31
+ };
32
+ /** Union type of all known error code string values. */
33
+ export type ConnectErrorCode = (typeof ConnectErrorCode)[keyof typeof ConnectErrorCode];
34
+ /**
35
+ * Error class thrown by all SDK operations.
36
+ *
37
+ * Includes a typed {@link code} for programmatic handling and an optional
38
+ * {@link statusCode} from HTTP responses.
39
+ */
1
40
  export declare class ConnectError extends Error {
2
- readonly code: string;
41
+ /** Machine-readable error code. One of {@link ConnectErrorCode} or an arbitrary server-returned string. */
42
+ readonly code: ConnectErrorCode | (string & {});
43
+ /** HTTP status code from the upstream response, if applicable. */
3
44
  readonly statusCode?: number;
4
- constructor(message: string, code: string, statusCode?: number);
45
+ constructor(message: string, code: ConnectErrorCode | (string & {}), statusCode?: number);
5
46
  }
6
47
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;gBAEjB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;CAM/D"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;CAYnB,CAAC;AAEX,wDAAwD;AACxD,MAAM,MAAM,gBAAgB,GAC1B,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;AAE3D;;;;;GAKG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,2GAA2G;IAC3G,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;IAChD,kEAAkE;IAClE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;gBAG3B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,gBAAgB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,EACtC,UAAU,CAAC,EAAE,MAAM;CAOtB"}
@@ -1,5 +1,44 @@
1
+ /**
2
+ * Known error codes thrown by the SDK.
3
+ *
4
+ * Use these constants for typed `catch` handling instead of comparing raw strings.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { ConnectError, ConnectErrorCode } from "@opendatalabs/connect/core";
9
+ *
10
+ * try {
11
+ * await getData({ privateKey, grant });
12
+ * } catch (err) {
13
+ * if (err instanceof ConnectError && err.code === ConnectErrorCode.SERVER_NOT_FOUND) {
14
+ * // handle missing server
15
+ * }
16
+ * }
17
+ * ```
18
+ */
19
+ export const ConnectErrorCode = {
20
+ SESSION_INIT_FAILED: "SESSION_INIT_FAILED",
21
+ SESSION_EXPIRED: "SESSION_EXPIRED",
22
+ POLL_FAILED: "POLL_FAILED",
23
+ POLL_TIMEOUT: "POLL_TIMEOUT",
24
+ SERVER_NOT_FOUND: "SERVER_NOT_FOUND",
25
+ GATEWAY_ERROR: "GATEWAY_ERROR",
26
+ DATA_FETCH_FAILED: "DATA_FETCH_FAILED",
27
+ LIST_SCOPES_FAILED: "LIST_SCOPES_FAILED",
28
+ LIST_VERSIONS_FAILED: "LIST_VERSIONS_FAILED",
29
+ CONFIG_INVALID: "CONFIG_INVALID",
30
+ WEBHOOK_INVALID: "WEBHOOK_INVALID",
31
+ };
32
+ /**
33
+ * Error class thrown by all SDK operations.
34
+ *
35
+ * Includes a typed {@link code} for programmatic handling and an optional
36
+ * {@link statusCode} from HTTP responses.
37
+ */
1
38
  export class ConnectError extends Error {
39
+ /** Machine-readable error code. One of {@link ConnectErrorCode} or an arbitrary server-returned string. */
2
40
  code;
41
+ /** HTTP status code from the upstream response, if applicable. */
3
42
  statusCode;
4
43
  constructor(message, code, statusCode) {
5
44
  super(message);
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,CAAS;IACb,UAAU,CAAU;IAE7B,YAAY,OAAe,EAAE,IAAY,EAAE,UAAmB;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF"}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,mBAAmB,EAAE,qBAAqB;IAC1C,eAAe,EAAE,iBAAiB;IAClC,WAAW,EAAE,aAAa;IAC1B,YAAY,EAAE,cAAc;IAC5B,gBAAgB,EAAE,kBAAkB;IACpC,aAAa,EAAE,eAAe;IAC9B,iBAAiB,EAAE,mBAAmB;IACtC,kBAAkB,EAAE,oBAAoB;IACxC,oBAAoB,EAAE,sBAAsB;IAC5C,cAAc,EAAE,gBAAgB;IAChC,eAAe,EAAE,iBAAiB;CAC1B,CAAC;AAMX;;;;;GAKG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,2GAA2G;IAClG,IAAI,CAAmC;IAChD,kEAAkE;IACzD,UAAU,CAAU;IAE7B,YACE,OAAe,EACf,IAAsC,EACtC,UAAmB;QAEnB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF"}
@@ -0,0 +1,19 @@
1
+ import type { GrantPayload } from "./types.js";
2
+ /**
3
+ * Type guard that checks whether an unknown value has the shape of a {@link GrantPayload}.
4
+ *
5
+ * Validates the presence and types of required fields: `grantId`, `userAddress`,
6
+ * `builderAddress`, and `scopes` (non-empty string array).
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const body = await request.json();
11
+ * if (!isValidGrant(body.grant)) {
12
+ * return NextResponse.json({ error: "Invalid grant" }, { status: 400 });
13
+ * }
14
+ * // body.grant is now typed as GrantPayload
15
+ * const data = await getData({ privateKey, grant: body.grant });
16
+ * ```
17
+ */
18
+ export declare function isValidGrant(value: unknown): value is GrantPayload;
19
+ //# sourceMappingURL=grants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grants.d.ts","sourceRoot":"","sources":["../../src/core/grants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAgBlE"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Type guard that checks whether an unknown value has the shape of a {@link GrantPayload}.
3
+ *
4
+ * Validates the presence and types of required fields: `grantId`, `userAddress`,
5
+ * `builderAddress`, and `scopes` (non-empty string array).
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const body = await request.json();
10
+ * if (!isValidGrant(body.grant)) {
11
+ * return NextResponse.json({ error: "Invalid grant" }, { status: 400 });
12
+ * }
13
+ * // body.grant is now typed as GrantPayload
14
+ * const data = await getData({ privateKey, grant: body.grant });
15
+ * ```
16
+ */
17
+ export function isValidGrant(value) {
18
+ if (value === null || typeof value !== "object")
19
+ return false;
20
+ const obj = value;
21
+ return (typeof obj.grantId === "string" &&
22
+ obj.grantId.length > 0 &&
23
+ typeof obj.userAddress === "string" &&
24
+ obj.userAddress.length > 0 &&
25
+ typeof obj.builderAddress === "string" &&
26
+ obj.builderAddress.length > 0 &&
27
+ Array.isArray(obj.scopes) &&
28
+ obj.scopes.length > 0 &&
29
+ obj.scopes.every((s) => typeof s === "string" && s.length > 0));
30
+ }
31
+ //# sourceMappingURL=grants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grants.js","sourceRoot":"","sources":["../../src/core/grants.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAE9D,MAAM,GAAG,GAAG,KAAgC,CAAC;IAE7C,OAAO,CACL,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ;QAC/B,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;QACtB,OAAO,GAAG,CAAC,WAAW,KAAK,QAAQ;QACnC,GAAG,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC;QAC1B,OAAO,GAAG,CAAC,cAAc,KAAK,QAAQ;QACtC,GAAG,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC;QAC7B,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC;QACzB,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QACrB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CACxE,CAAC;AACJ,CAAC"}
@@ -1,4 +1,5 @@
1
- export { ConnectError } from "./errors.js";
2
- export { SESSION_RELAY_URL, GATEWAY_URL } from "./constants.js";
1
+ export { ConnectError, ConnectErrorCode } from "./errors.js";
2
+ export { isValidGrant } from "./grants.js";
3
+ export { getEnvConfig, ENV_CONFIG, DEFAULT_ENVIRONMENT, type VanaEnvironment, } from "./constants.js";
3
4
  export type { ConnectionStatus, SessionInitParams, SessionInitResult, SessionPollResult, GrantPayload, DataFetchParams, RequestSignerConfig, SessionRelayConfig, DataClientConfig, ConnectConfig, GetDataConfig, VanaManifestConfig, VanaManifestBlock, } from "./types.js";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAChE,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,YAAY,EACZ,UAAU,EACV,mBAAmB,EACnB,KAAK,eAAe,GACrB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,YAAY,CAAC"}
@@ -1,3 +1,4 @@
1
- export { ConnectError } from "./errors.js";
2
- export { SESSION_RELAY_URL, GATEWAY_URL } from "./constants.js";
1
+ export { ConnectError, ConnectErrorCode } from "./errors.js";
2
+ export { isValidGrant } from "./grants.js";
3
+ export { getEnvConfig, ENV_CONFIG, DEFAULT_ENVIRONMENT, } from "./constants.js";
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,YAAY,EACZ,UAAU,EACV,mBAAmB,GAEpB,MAAM,gBAAgB,CAAC"}