@opendatalabs/connect 0.5.0 → 0.6.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.
- package/README.md +149 -49
- package/dist/core/constants.d.ts +28 -2
- package/dist/core/constants.d.ts.map +1 -1
- package/dist/core/constants.js +23 -2
- package/dist/core/constants.js.map +1 -1
- package/dist/core/errors.d.ts +43 -2
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +39 -0
- package/dist/core/errors.js.map +1 -1
- package/dist/core/grants.d.ts +19 -0
- package/dist/core/grants.d.ts.map +1 -0
- package/dist/core/grants.js +31 -0
- package/dist/core/grants.js.map +1 -0
- package/dist/core/index.d.ts +3 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/types.d.ts +61 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/react/ConnectButton.d.ts +15 -0
- package/dist/react/ConnectButton.d.ts.map +1 -1
- package/dist/react/ConnectButton.js +8 -1
- package/dist/react/ConnectButton.js.map +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/useVanaConnect.d.ts +33 -0
- package/dist/react/useVanaConnect.d.ts.map +1 -1
- package/dist/react/useVanaConnect.js +29 -3
- package/dist/react/useVanaConnect.js.map +1 -1
- package/dist/react/useVanaData.d.ts +67 -0
- package/dist/react/useVanaData.d.ts.map +1 -0
- package/dist/react/useVanaData.js +125 -0
- package/dist/react/useVanaData.js.map +1 -0
- package/dist/server/config.d.ts +36 -0
- package/dist/server/config.d.ts.map +1 -0
- package/dist/server/config.js +44 -0
- package/dist/server/config.js.map +1 -0
- package/dist/server/connect.d.ts +40 -1
- package/dist/server/connect.d.ts.map +1 -1
- package/dist/server/connect.js +46 -5
- package/dist/server/connect.js.map +1 -1
- package/dist/server/data-client.d.ts +17 -0
- package/dist/server/data-client.d.ts.map +1 -1
- package/dist/server/data-client.js +24 -7
- package/dist/server/data-client.js.map +1 -1
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/manifest-signer.d.ts +22 -0
- package/dist/server/manifest-signer.d.ts.map +1 -1
- package/dist/server/manifest-signer.js +22 -0
- package/dist/server/manifest-signer.js.map +1 -1
- package/dist/server/request-signer.d.ts +18 -0
- package/dist/server/request-signer.d.ts.map +1 -1
- package/dist/server/request-signer.js +6 -0
- package/dist/server/request-signer.js.map +1 -1
- package/dist/server/session-relay.d.ts +22 -0
- package/dist/server/session-relay.d.ts.map +1 -1
- package/dist/server/session-relay.js +12 -4
- package/dist/server/session-relay.js.map +1 -1
- package/dist/server/webhook.d.ts +11 -0
- package/dist/server/webhook.d.ts.map +1 -0
- package/dist/server/webhook.js +18 -0
- package/dist/server/webhook.js.map +1 -0
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Vana Connect SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Let your users customize your app with their own data.
|
|
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.
|
|
6
|
+
|
|
7
|
+
## How it works
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
Your App Vana Protocol
|
|
11
|
+
────────────────────────────── ──────────────────────────────
|
|
12
|
+
|
|
13
|
+
1. connect({ scopes })
|
|
14
|
+
→ creates session
|
|
15
|
+
→ returns deep link ──▶ 2. User opens Desktop App
|
|
16
|
+
reviews scopes, exports data,
|
|
17
|
+
approves grant
|
|
18
|
+
|
|
19
|
+
3. Poll resolves with grant ◀── Grant signed & registered
|
|
20
|
+
|
|
21
|
+
4. getData({ grant }) ──▶ 5. Personal Server returns
|
|
22
|
+
→ structured JSON user data over TLS
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The SDK handles session creation, cryptographic request signing, polling, and data fetching. You write three function calls; the protocol handles the rest.
|
|
26
|
+
|
|
27
|
+
## Where this fits in the Vana protocol
|
|
28
|
+
|
|
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:
|
|
30
|
+
|
|
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
|
|
34
|
+
|
|
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.
|
|
4
36
|
|
|
5
37
|
## Installation
|
|
6
38
|
|
|
@@ -8,37 +40,36 @@ SDK for integrating Vana Data Portability "Connect data" flows into builder appl
|
|
|
8
40
|
npm install @opendatalabs/connect
|
|
9
41
|
```
|
|
10
42
|
|
|
11
|
-
##
|
|
43
|
+
## Prerequisites
|
|
12
44
|
|
|
13
|
-
|
|
14
|
-
| ------------------------------ | ----------- | ----------------------------------------------------------------- |
|
|
15
|
-
| `@opendatalabs/connect/server` | Node.js | `connect()`, `getData()`, `signVanaManifest()`, low-level clients |
|
|
16
|
-
| `@opendatalabs/connect/react` | Browser | Polling hook, connect button |
|
|
17
|
-
| `@opendatalabs/connect/core` | Universal | Shared types, errors, and constants |
|
|
45
|
+
Register as a builder through the Vana Desktop App first.
|
|
18
46
|
|
|
19
|
-
##
|
|
47
|
+
## Quickstart
|
|
20
48
|
|
|
21
|
-
### 1.
|
|
49
|
+
### 1. Create a session (server)
|
|
22
50
|
|
|
23
51
|
```typescript
|
|
24
52
|
import { connect } from "@opendatalabs/connect/server";
|
|
25
53
|
|
|
26
54
|
const session = await connect({
|
|
27
|
-
privateKey: process.env.
|
|
55
|
+
privateKey: process.env.VANA_APP_PRIVATE_KEY as `0x${string}`,
|
|
28
56
|
scopes: ["chatgpt.conversations"],
|
|
57
|
+
webhookUrl: "https://yourapp.com/api/webhook", // optional
|
|
58
|
+
appUserId: "user-42", // optional
|
|
29
59
|
});
|
|
30
60
|
|
|
31
|
-
//
|
|
32
|
-
// session.
|
|
33
|
-
// session.
|
|
61
|
+
// Return to your frontend:
|
|
62
|
+
// session.sessionId — used for polling
|
|
63
|
+
// session.deepLinkUrl — opens the Vana Desktop App
|
|
64
|
+
// session.expiresAt — ISO 8601 expiration
|
|
34
65
|
```
|
|
35
66
|
|
|
36
|
-
### 2. Poll for approval (client)
|
|
67
|
+
### 2. Poll for user approval (client)
|
|
37
68
|
|
|
38
69
|
```tsx
|
|
39
70
|
import { useVanaConnect } from "@opendatalabs/connect/react";
|
|
40
71
|
|
|
41
|
-
function
|
|
72
|
+
function ConnectData({ sessionId }: { sessionId: string }) {
|
|
42
73
|
const { connect, status, grant, deepLinkUrl } = useVanaConnect();
|
|
43
74
|
|
|
44
75
|
useEffect(() => {
|
|
@@ -46,72 +77,141 @@ function ConnectPage({ sessionId }: { sessionId: string }) {
|
|
|
46
77
|
}, [sessionId]);
|
|
47
78
|
|
|
48
79
|
if (status === "waiting" && deepLinkUrl) {
|
|
49
|
-
return <a href={deepLinkUrl}>
|
|
80
|
+
return <a href={deepLinkUrl}>Connect your data</a>;
|
|
50
81
|
}
|
|
51
|
-
|
|
52
82
|
if (status === "approved" && grant) {
|
|
53
|
-
|
|
83
|
+
// grant.grantId, grant.userAddress, grant.scopes are available
|
|
84
|
+
return <p>Connected.</p>;
|
|
54
85
|
}
|
|
55
|
-
|
|
56
|
-
return <p>Status: {status}</p>;
|
|
86
|
+
return <p>{status}</p>;
|
|
57
87
|
}
|
|
58
88
|
```
|
|
59
89
|
|
|
60
|
-
|
|
90
|
+
Or use the pre-built button:
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
import { ConnectButton } from "@opendatalabs/connect/react";
|
|
94
|
+
|
|
95
|
+
<ConnectButton
|
|
96
|
+
sessionId={sessionId}
|
|
97
|
+
onComplete={(grant) => saveGrant(grant)}
|
|
98
|
+
onError={(err) => console.error(err)}
|
|
99
|
+
/>;
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 3. Fetch user data (server)
|
|
61
103
|
|
|
62
104
|
```typescript
|
|
63
105
|
import { getData } from "@opendatalabs/connect/server";
|
|
64
106
|
|
|
65
107
|
const data = await getData({
|
|
66
|
-
privateKey: process.env.
|
|
67
|
-
grant, // GrantPayload from
|
|
108
|
+
privateKey: process.env.VANA_APP_PRIVATE_KEY as `0x${string}`,
|
|
109
|
+
grant, // GrantPayload from step 2
|
|
68
110
|
});
|
|
69
111
|
|
|
70
|
-
//
|
|
112
|
+
// Record<string, unknown> keyed by scope
|
|
113
|
+
const conversations = data["chatgpt.conversations"];
|
|
71
114
|
```
|
|
72
115
|
|
|
73
|
-
###
|
|
116
|
+
### Web App Manifest
|
|
117
|
+
|
|
118
|
+
The Desktop App verifies your identity by fetching your manifest. Use `signVanaManifest()` to generate it:
|
|
74
119
|
|
|
75
120
|
```typescript
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
121
|
+
import { signVanaManifest } from "@opendatalabs/connect/server";
|
|
122
|
+
|
|
123
|
+
// In your manifest route handler (e.g. Next.js /manifest.json/route.ts):
|
|
124
|
+
const vanaBlock = await signVanaManifest({
|
|
125
|
+
privateKey: process.env.VANA_APP_PRIVATE_KEY as `0x${string}`,
|
|
126
|
+
appUrl: "https://yourapp.com",
|
|
127
|
+
privacyPolicyUrl: "https://yourapp.com/privacy",
|
|
128
|
+
termsUrl: "https://yourapp.com/terms",
|
|
129
|
+
supportUrl: "https://yourapp.com/support",
|
|
130
|
+
webhookUrl: "https://yourapp.com/api/webhook",
|
|
82
131
|
});
|
|
132
|
+
|
|
133
|
+
const manifest = {
|
|
134
|
+
name: "Your App",
|
|
135
|
+
short_name: "YourApp",
|
|
136
|
+
start_url: "/",
|
|
137
|
+
display: "standalone",
|
|
138
|
+
vana: vanaBlock, // signed identity block
|
|
139
|
+
};
|
|
83
140
|
```
|
|
84
141
|
|
|
85
|
-
|
|
142
|
+
Make sure your HTML includes `<link rel="manifest" href="/manifest.json">`.
|
|
143
|
+
|
|
144
|
+
## API Reference
|
|
145
|
+
|
|
146
|
+
### Entrypoints
|
|
147
|
+
|
|
148
|
+
| Import | Environment | Exports |
|
|
149
|
+
| ------------------------------ | ----------- | ----------------------------------------------------------------- |
|
|
150
|
+
| `@opendatalabs/connect/server` | Node.js | `connect()`, `getData()`, `signVanaManifest()`, low-level clients |
|
|
151
|
+
| `@opendatalabs/connect/react` | Browser | `useVanaConnect()`, `useVanaData()`, `ConnectButton` |
|
|
152
|
+
| `@opendatalabs/connect/core` | Universal | Types, `ConnectError`, constants |
|
|
153
|
+
|
|
154
|
+
### `connect(config): Promise<SessionInitResult>`
|
|
155
|
+
|
|
156
|
+
Creates a session on the Session Relay. Returns `sessionId`, `deepLinkUrl`, and `expiresAt`.
|
|
157
|
+
|
|
158
|
+
| Param | Type | Required | Description |
|
|
159
|
+
| ------------ | ------------------- | -------- | ---------------------------------------------------------------------- |
|
|
160
|
+
| `privateKey` | `` `0x${string}` `` | Yes | Builder private key |
|
|
161
|
+
| `scopes` | `string[]` | Yes | Data scopes to request |
|
|
162
|
+
| `webhookUrl` | `string` | No | Public HTTPS URL for grant event notifications (localhost is rejected) |
|
|
163
|
+
| `appUserId` | `string` | No | Your app's user ID for correlation |
|
|
164
|
+
|
|
165
|
+
### `getData(config): Promise<Record<string, unknown>>`
|
|
166
|
+
|
|
167
|
+
Fetches user data from their Personal Server using a signed grant.
|
|
168
|
+
|
|
169
|
+
| Param | Type | Required | Description |
|
|
170
|
+
| ------------ | ------------------- | -------- | ---------------------------- |
|
|
171
|
+
| `privateKey` | `` `0x${string}` `` | Yes | Builder private key |
|
|
172
|
+
| `grant` | `GrantPayload` | Yes | Grant from the approval step |
|
|
173
|
+
|
|
174
|
+
### `useVanaConnect(config?): UseVanaConnectResult`
|
|
175
|
+
|
|
176
|
+
React hook that polls the Session Relay and manages connection state.
|
|
86
177
|
|
|
87
178
|
```typescript
|
|
88
|
-
|
|
179
|
+
const { connect, status, grant, error, deepLinkUrl, reset } = useVanaConnect();
|
|
180
|
+
```
|
|
89
181
|
|
|
90
|
-
|
|
91
|
-
privateKey: process.env.VANA_PRIVATE_KEY as `0x${string}`,
|
|
92
|
-
appUrl: "https://your-app.example.com",
|
|
93
|
-
privacyPolicyUrl: "https://your-app.example.com/privacy",
|
|
94
|
-
termsUrl: "https://your-app.example.com/terms",
|
|
95
|
-
supportUrl: "https://your-app.example.com/support",
|
|
96
|
-
webhookUrl: "https://your-app.example.com/api/webhook",
|
|
97
|
-
});
|
|
182
|
+
`status` transitions: `idle` → `connecting` → `waiting` → `approved` | `denied` | `expired` | `error`
|
|
98
183
|
|
|
99
|
-
|
|
100
|
-
|
|
184
|
+
### `GrantPayload`
|
|
185
|
+
|
|
186
|
+
Returned when a user approves access:
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
interface GrantPayload {
|
|
190
|
+
grantId: string; // on-chain permission ID
|
|
191
|
+
userAddress: string; // user's wallet address
|
|
192
|
+
builderAddress: string; // your registered address
|
|
193
|
+
scopes: string[]; // approved data scopes
|
|
194
|
+
serverAddress?: string; // user's Personal Server
|
|
195
|
+
appUserId?: string; // your app's user ID (if provided)
|
|
196
|
+
}
|
|
101
197
|
```
|
|
102
198
|
|
|
103
|
-
###
|
|
199
|
+
### Low-level clients
|
|
104
200
|
|
|
105
|
-
For full control
|
|
201
|
+
For full control over individual protocol interactions:
|
|
106
202
|
|
|
107
203
|
```typescript
|
|
108
204
|
import {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
205
|
+
createRequestSigner, // Web3Signed header generation
|
|
206
|
+
createSessionRelay, // Session Relay HTTP client
|
|
207
|
+
createDataClient, // Data Gateway HTTP client
|
|
112
208
|
} from "@opendatalabs/connect/server";
|
|
113
209
|
```
|
|
114
210
|
|
|
211
|
+
## Examples
|
|
212
|
+
|
|
213
|
+
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.
|
|
214
|
+
|
|
115
215
|
## License
|
|
116
216
|
|
|
117
217
|
MIT
|
package/dist/core/constants.d.ts
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
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://session-relay-git-dev-opendatalabs.vercel.app";
|
|
7
|
+
readonly gatewayUrl: "https://data-gateway-env-dev-opendatalabs.vercel.app";
|
|
8
|
+
};
|
|
9
|
+
readonly prod: {
|
|
10
|
+
readonly sessionRelayUrl: "https://session-relay-git-dev-opendatalabs.vercel.app";
|
|
11
|
+
readonly gatewayUrl: "https://data-gateway-env-dev-opendatalabs.vercel.app";
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/** Default environment used when none is specified. */
|
|
15
|
+
export declare const DEFAULT_ENVIRONMENT: VanaEnvironment;
|
|
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 declare function getEnvConfig(environment?: VanaEnvironment): {
|
|
23
|
+
readonly sessionRelayUrl: "https://session-relay-git-dev-opendatalabs.vercel.app";
|
|
24
|
+
readonly gatewayUrl: "https://data-gateway-env-dev-opendatalabs.vercel.app";
|
|
25
|
+
} | {
|
|
26
|
+
readonly sessionRelayUrl: "https://session-relay-git-dev-opendatalabs.vercel.app";
|
|
27
|
+
readonly gatewayUrl: "https://data-gateway-env-dev-opendatalabs.vercel.app";
|
|
28
|
+
};
|
|
3
29
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":"AAAA,
|
|
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;;;;;;;;;CAUb,CAAC;AAEX,uDAAuD;AACvD,eAAO,MAAM,mBAAmB,EAAE,eAAwB,CAAC;AAE3D;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,WAAW,CAAC,EAAE,eAAe;;;;;;EAEzD"}
|
package/dist/core/constants.js
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
export const
|
|
1
|
+
/** URL configuration for each SDK environment. */
|
|
2
|
+
export const ENV_CONFIG = {
|
|
3
|
+
dev: {
|
|
4
|
+
sessionRelayUrl: "https://session-relay-git-dev-opendatalabs.vercel.app",
|
|
5
|
+
gatewayUrl: "https://data-gateway-env-dev-opendatalabs.vercel.app",
|
|
6
|
+
},
|
|
7
|
+
prod: {
|
|
8
|
+
// TODO: Replace with actual production URLs
|
|
9
|
+
sessionRelayUrl: "https://session-relay-git-dev-opendatalabs.vercel.app",
|
|
10
|
+
gatewayUrl: "https://data-gateway-env-dev-opendatalabs.vercel.app",
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
/** Default environment used when none is specified. */
|
|
14
|
+
export const DEFAULT_ENVIRONMENT = "prod";
|
|
15
|
+
/**
|
|
16
|
+
* Returns the URL configuration for the given environment.
|
|
17
|
+
*
|
|
18
|
+
* @param environment - `"dev"` or `"prod"`. Defaults to {@link DEFAULT_ENVIRONMENT}.
|
|
19
|
+
* @returns An object with `sessionRelayUrl` and `gatewayUrl`.
|
|
20
|
+
*/
|
|
21
|
+
export function getEnvConfig(environment) {
|
|
22
|
+
return ENV_CONFIG[environment ?? DEFAULT_ENVIRONMENT];
|
|
23
|
+
}
|
|
3
24
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":"
|
|
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,uDAAuD;QACxE,UAAU,EAAE,sDAAsD;KACnE;IACD,IAAI,EAAE;QACJ,4CAA4C;QAC5C,eAAe,EAAE,uDAAuD;QACxE,UAAU,EAAE,sDAAsD;KACnE;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"}
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -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
|
-
|
|
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;
|
|
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"}
|
package/dist/core/errors.js
CHANGED
|
@@ -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);
|
package/dist/core/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;
|
|
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"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { ConnectError } from "./errors.js";
|
|
2
|
-
export {
|
|
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
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -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;
|
|
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"}
|
package/dist/core/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { ConnectError } from "./errors.js";
|
|
2
|
-
export {
|
|
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
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,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"}
|