@opendatalabs/vana-sdk 3.5.1 → 3.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 +116 -0
- package/dist/direct/access-request-client.cjs +104 -0
- package/dist/direct/access-request-client.cjs.map +1 -0
- package/dist/direct/access-request-client.d.ts +51 -0
- package/dist/direct/access-request-client.js +79 -0
- package/dist/direct/access-request-client.js.map +1 -0
- package/dist/direct/access-request-client.test.d.ts +1 -0
- package/dist/direct/connect-flow.cjs +152 -0
- package/dist/direct/connect-flow.cjs.map +1 -0
- package/dist/direct/connect-flow.d.ts +85 -0
- package/dist/direct/connect-flow.js +128 -0
- package/dist/direct/connect-flow.js.map +1 -0
- package/dist/direct/connect-flow.test.d.ts +1 -0
- package/dist/direct/controller.cjs +129 -0
- package/dist/direct/controller.cjs.map +1 -0
- package/dist/direct/controller.d.ts +152 -0
- package/dist/direct/controller.js +109 -0
- package/dist/direct/controller.js.map +1 -0
- package/dist/direct/controller.test.d.ts +1 -0
- package/dist/direct/endpoints.cjs +45 -0
- package/dist/direct/endpoints.cjs.map +1 -0
- package/dist/direct/endpoints.d.ts +22 -0
- package/dist/direct/endpoints.js +19 -0
- package/dist/direct/endpoints.js.map +1 -0
- package/dist/direct/errors.cjs +65 -0
- package/dist/direct/errors.cjs.map +1 -0
- package/dist/direct/errors.d.ts +44 -0
- package/dist/direct/errors.js +38 -0
- package/dist/direct/errors.js.map +1 -0
- package/dist/direct/escrow-payment.cjs +96 -0
- package/dist/direct/escrow-payment.cjs.map +1 -0
- package/dist/direct/escrow-payment.d.ts +81 -0
- package/dist/direct/escrow-payment.js +72 -0
- package/dist/direct/escrow-payment.js.map +1 -0
- package/dist/direct/escrow-payment.test.d.ts +1 -0
- package/dist/direct/personal-server-read.cjs +149 -0
- package/dist/direct/personal-server-read.cjs.map +1 -0
- package/dist/direct/personal-server-read.d.ts +103 -0
- package/dist/direct/personal-server-read.js +124 -0
- package/dist/direct/personal-server-read.js.map +1 -0
- package/dist/direct/personal-server-read.test.d.ts +1 -0
- package/dist/direct/types.cjs +35 -0
- package/dist/direct/types.cjs.map +1 -0
- package/dist/direct/types.d.ts +205 -0
- package/dist/direct/types.js +11 -0
- package/dist/direct/types.js.map +1 -0
- package/dist/direct/use-direct-vana-connect.cjs +68 -0
- package/dist/direct/use-direct-vana-connect.cjs.map +1 -0
- package/dist/direct/use-direct-vana-connect.d.ts +45 -0
- package/dist/direct/use-direct-vana-connect.js +46 -0
- package/dist/direct/use-direct-vana-connect.js.map +1 -0
- package/dist/index.browser.d.ts +7 -3
- package/dist/index.browser.js +438 -157
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +461 -162
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +7 -3
- package/dist/index.node.js +438 -157
- package/dist/index.node.js.map +4 -4
- package/dist/protocol/data-point-status.cjs +80 -0
- package/dist/protocol/data-point-status.cjs.map +1 -0
- package/dist/protocol/data-point-status.d.ts +34 -0
- package/dist/protocol/data-point-status.js +51 -0
- package/dist/protocol/data-point-status.js.map +1 -0
- package/dist/protocol/data-point-status.test.d.ts +1 -0
- package/dist/protocol/eip712.cjs +53 -31
- package/dist/protocol/eip712.cjs.map +1 -1
- package/dist/protocol/eip712.d.ts +98 -43
- package/dist/protocol/eip712.js +47 -27
- package/dist/protocol/eip712.js.map +1 -1
- package/dist/protocol/escrow-deposit.cjs +89 -0
- package/dist/protocol/escrow-deposit.cjs.map +1 -0
- package/dist/protocol/escrow-deposit.d.ts +47 -0
- package/dist/protocol/escrow-deposit.js +60 -0
- package/dist/protocol/escrow-deposit.js.map +1 -0
- package/dist/protocol/escrow-deposit.test.d.ts +1 -0
- package/dist/protocol/escrow-flow.test.d.ts +21 -0
- package/dist/protocol/fee-registry.cjs +116 -0
- package/dist/protocol/fee-registry.cjs.map +1 -0
- package/dist/protocol/fee-registry.d.ts +151 -0
- package/dist/protocol/fee-registry.js +89 -0
- package/dist/protocol/fee-registry.js.map +1 -0
- package/dist/protocol/fee-registry.test.d.ts +1 -0
- package/dist/protocol/gateway.cjs +107 -37
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.d.ts +223 -57
- package/dist/protocol/gateway.js +107 -37
- package/dist/protocol/gateway.js.map +1 -1
- package/dist/protocol/grants.cjs +27 -64
- package/dist/protocol/grants.cjs.map +1 -1
- package/dist/protocol/grants.d.ts +6 -13
- package/dist/protocol/grants.js +27 -63
- package/dist/protocol/grants.js.map +1 -1
- package/dist/protocol/personal-server-data.cjs +71 -0
- package/dist/protocol/personal-server-data.cjs.map +1 -0
- package/dist/protocol/personal-server-data.d.ts +16 -0
- package/dist/protocol/personal-server-data.js +47 -0
- package/dist/protocol/personal-server-data.js.map +1 -0
- package/dist/protocol/personal-server-data.test.d.ts +1 -0
- package/dist/protocol/personal-server-lite-owner-binding.cjs +93 -0
- package/dist/protocol/personal-server-lite-owner-binding.cjs.map +1 -0
- package/dist/protocol/personal-server-lite-owner-binding.d.ts +44 -0
- package/dist/protocol/personal-server-lite-owner-binding.js +65 -0
- package/dist/protocol/personal-server-lite-owner-binding.js.map +1 -0
- package/dist/protocol/personal-server-lite-owner-binding.test.d.ts +1 -0
- package/dist/react.cjs +32 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.ts +33 -0
- package/dist/react.js +11 -0
- package/dist/react.js.map +1 -0
- package/dist/server.cjs +73 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.ts +32 -0
- package/dist/server.js +55 -0
- package/dist/server.js.map +1 -0
- package/package.json +20 -1
|
@@ -3,7 +3,7 @@ export interface GatewayEnvelope<T> {
|
|
|
3
3
|
proof: GatewayProof;
|
|
4
4
|
/**
|
|
5
5
|
* Cursor-based pagination metadata, present on list endpoints (e.g.
|
|
6
|
-
* `GET /v1/
|
|
6
|
+
* `GET /v1/data`). A sibling of `data`, not nested inside it — so callers
|
|
7
7
|
* that need it must read the full envelope rather than going through
|
|
8
8
|
* `unwrapEnvelope`, which intentionally returns only `data`.
|
|
9
9
|
*/
|
|
@@ -51,75 +51,71 @@ export interface ServerInfo {
|
|
|
51
51
|
publicKey: string;
|
|
52
52
|
serverUrl: string;
|
|
53
53
|
addedAt: string;
|
|
54
|
+
revokedAt: string | null;
|
|
55
|
+
}
|
|
56
|
+
export interface GatewayGrantFee {
|
|
57
|
+
asset: string;
|
|
58
|
+
registrationFee: string;
|
|
59
|
+
dataAccessFee: string;
|
|
60
|
+
totalDue: string;
|
|
54
61
|
}
|
|
62
|
+
export type GatewayGrantStatus = "pending" | "submitting" | "confirmed" | "finalized" | "reorged";
|
|
55
63
|
export interface GatewayGrantResponse {
|
|
56
64
|
id: string;
|
|
57
65
|
grantorAddress: string;
|
|
58
66
|
granteeId: string;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
status: "pending" | "confirmed";
|
|
67
|
+
scopes: string[];
|
|
68
|
+
status: GatewayGrantStatus;
|
|
62
69
|
addedAt: string;
|
|
70
|
+
expiresAt: string | null;
|
|
71
|
+
expired: boolean;
|
|
63
72
|
revokedAt: string | null;
|
|
64
73
|
revocationSignature: string | null;
|
|
74
|
+
paymentStatus: "pending" | "paid";
|
|
75
|
+
paidAt: string | null;
|
|
76
|
+
paidBy: string | null;
|
|
77
|
+
grantVersion: string;
|
|
78
|
+
settleTxHash: string | null;
|
|
79
|
+
settleSubmittedAt: string | null;
|
|
80
|
+
revocationTxHash: string | null;
|
|
81
|
+
revocationSubmittedAt: string | null;
|
|
82
|
+
fee: GatewayGrantFee;
|
|
65
83
|
}
|
|
66
|
-
export
|
|
84
|
+
export type GrantListItem = GatewayGrantResponse;
|
|
85
|
+
export interface DataPointRecord {
|
|
67
86
|
id: string;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
87
|
+
ownerAddress: string;
|
|
88
|
+
scope: string;
|
|
89
|
+
dataHash: string;
|
|
90
|
+
metadataHash: string;
|
|
91
|
+
expectedVersion: string;
|
|
73
92
|
addedAt: string;
|
|
74
|
-
revokedAt: string | null;
|
|
75
|
-
revocationSignature: string | null;
|
|
76
|
-
}
|
|
77
|
-
export interface FileRecord {
|
|
78
|
-
fileId: string;
|
|
79
|
-
owner: string;
|
|
80
|
-
url: string;
|
|
81
|
-
schemaId: string;
|
|
82
|
-
createdAt: string;
|
|
83
|
-
/**
|
|
84
|
-
* Soft-deletion timestamp (ISO 8601), or null if the file is active. Always present
|
|
85
|
-
* (`normalizeFileRecord` populates it); non-null only when the gateway returns deletion state
|
|
86
|
-
* (e.g. listed with `includeDeleted`). Drives the PS sync delete-reconciliation.
|
|
87
|
-
*/
|
|
88
|
-
deletedAt: string | null;
|
|
89
93
|
}
|
|
90
|
-
export interface
|
|
91
|
-
|
|
94
|
+
export interface DataPointListResult {
|
|
95
|
+
dataPoints: DataPointRecord[];
|
|
92
96
|
cursor: string | null;
|
|
93
97
|
}
|
|
94
|
-
export interface
|
|
98
|
+
export interface ListDataPointsOptions {
|
|
95
99
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
100
|
+
* Only return rows added at or after this ISO 8601 timestamp. Used by sync
|
|
101
|
+
* loops that want incremental tails — pass the last seen `addedAt`.
|
|
98
102
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
ownerAddress: string;
|
|
103
|
-
url: string;
|
|
104
|
-
schemaId: string;
|
|
105
|
-
signature: string;
|
|
103
|
+
since?: string;
|
|
104
|
+
/** Page size. Capped at 1000 by the gateway. */
|
|
105
|
+
limit?: number;
|
|
106
106
|
}
|
|
107
107
|
export interface CreateGrantParams {
|
|
108
108
|
grantorAddress: string;
|
|
109
109
|
granteeId: string;
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
scopes: string[];
|
|
111
|
+
grantVersion: string;
|
|
112
|
+
expiresAt: string;
|
|
112
113
|
signature: string;
|
|
113
114
|
}
|
|
114
115
|
export interface RevokeGrantParams {
|
|
115
116
|
grantId: string;
|
|
116
117
|
grantorAddress: string;
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
export interface DeleteFileParams {
|
|
120
|
-
fileId: string;
|
|
121
|
-
ownerAddress: string;
|
|
122
|
-
/** EIP-712 FileDeletion signature, signed by the owner or the owner's registered server. */
|
|
118
|
+
grantVersion: string;
|
|
123
119
|
signature: string;
|
|
124
120
|
}
|
|
125
121
|
export interface RegisterServerParams {
|
|
@@ -133,6 +129,171 @@ export interface RegisterServerResult {
|
|
|
133
129
|
serverId?: string;
|
|
134
130
|
alreadyRegistered: boolean;
|
|
135
131
|
}
|
|
132
|
+
export interface RegisterBuilderParams {
|
|
133
|
+
ownerAddress: string;
|
|
134
|
+
granteeAddress: string;
|
|
135
|
+
publicKey: string;
|
|
136
|
+
appUrl: string;
|
|
137
|
+
signature: string;
|
|
138
|
+
}
|
|
139
|
+
export interface RegisterBuilderResult {
|
|
140
|
+
builderId?: string;
|
|
141
|
+
alreadyRegistered: boolean;
|
|
142
|
+
}
|
|
143
|
+
export interface RegisterDataPointParams {
|
|
144
|
+
ownerAddress: string;
|
|
145
|
+
scope: string;
|
|
146
|
+
dataHash: string;
|
|
147
|
+
metadataHash: string;
|
|
148
|
+
expectedVersion: string;
|
|
149
|
+
signature: string;
|
|
150
|
+
}
|
|
151
|
+
export interface RegisterDataPointResult {
|
|
152
|
+
dataPointId?: string;
|
|
153
|
+
expectedVersion?: string;
|
|
154
|
+
}
|
|
155
|
+
export interface AccessRecord {
|
|
156
|
+
dataPointId: string;
|
|
157
|
+
version: string;
|
|
158
|
+
accessor: string;
|
|
159
|
+
recordId: string;
|
|
160
|
+
signature: string;
|
|
161
|
+
}
|
|
162
|
+
export interface PayForOperationParams {
|
|
163
|
+
payerAddress: string;
|
|
164
|
+
opType: string;
|
|
165
|
+
opId: string;
|
|
166
|
+
asset: string;
|
|
167
|
+
amount: string;
|
|
168
|
+
paymentNonce: string;
|
|
169
|
+
signature: string;
|
|
170
|
+
accessRecord?: AccessRecord;
|
|
171
|
+
}
|
|
172
|
+
export interface PayForOperationResult {
|
|
173
|
+
opType: string;
|
|
174
|
+
opId: string;
|
|
175
|
+
payerAddress: string;
|
|
176
|
+
asset: string;
|
|
177
|
+
amount: string;
|
|
178
|
+
breakdown: {
|
|
179
|
+
registrationFee: string;
|
|
180
|
+
dataAccessFee: string;
|
|
181
|
+
registrationPaid: boolean;
|
|
182
|
+
};
|
|
183
|
+
paymentNonce: string;
|
|
184
|
+
paidAt: string;
|
|
185
|
+
}
|
|
186
|
+
export type SettleOpType = "grant" | "server" | "data" | "access" | "builder" | "data-status";
|
|
187
|
+
export type SettleItem = {
|
|
188
|
+
opType: SettleOpType;
|
|
189
|
+
opId: string;
|
|
190
|
+
status: "submitting" | "confirmed";
|
|
191
|
+
settleTxHash: string | null;
|
|
192
|
+
settleSubmittedAt: string | null;
|
|
193
|
+
chainBlockHeight: string | null;
|
|
194
|
+
revocationTxHash: string | null;
|
|
195
|
+
revocationSubmittedAt: string | null;
|
|
196
|
+
placeholder: boolean;
|
|
197
|
+
} | {
|
|
198
|
+
opType: SettleOpType;
|
|
199
|
+
opId: string;
|
|
200
|
+
status: "skipped";
|
|
201
|
+
reason: string;
|
|
202
|
+
} | {
|
|
203
|
+
opType: SettleOpType;
|
|
204
|
+
opId: string;
|
|
205
|
+
status: "failed";
|
|
206
|
+
error: string;
|
|
207
|
+
};
|
|
208
|
+
export interface SettlePromoteResult {
|
|
209
|
+
opType: SettleOpType;
|
|
210
|
+
opId: string;
|
|
211
|
+
status: "confirmed" | "failed" | "pending" | "skipped";
|
|
212
|
+
txHash: string;
|
|
213
|
+
chainBlockHeight: string | null;
|
|
214
|
+
reason?: string;
|
|
215
|
+
}
|
|
216
|
+
export interface SettleReconcileItem {
|
|
217
|
+
opId: string;
|
|
218
|
+
status: "finalized" | "reorged" | "unchanged";
|
|
219
|
+
chainBlockHeight: string | null;
|
|
220
|
+
settleTxHash: string | null;
|
|
221
|
+
reason?: string;
|
|
222
|
+
}
|
|
223
|
+
export interface SettleParams {
|
|
224
|
+
limit?: number;
|
|
225
|
+
}
|
|
226
|
+
export interface SettleResult {
|
|
227
|
+
scanned: number;
|
|
228
|
+
submitted: number;
|
|
229
|
+
confirmed: number;
|
|
230
|
+
skipped: number;
|
|
231
|
+
failed: number;
|
|
232
|
+
items: SettleItem[];
|
|
233
|
+
promoted: {
|
|
234
|
+
count: number;
|
|
235
|
+
items: SettlePromoteResult[];
|
|
236
|
+
};
|
|
237
|
+
reconciled: {
|
|
238
|
+
scanned: number;
|
|
239
|
+
finalized: number;
|
|
240
|
+
reorged: number;
|
|
241
|
+
unchanged: number;
|
|
242
|
+
items: SettleReconcileItem[];
|
|
243
|
+
};
|
|
244
|
+
paced?: {
|
|
245
|
+
iterations: number;
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
export interface EscrowBalanceEntry {
|
|
249
|
+
asset: string;
|
|
250
|
+
balance: string;
|
|
251
|
+
pendingAmount: string;
|
|
252
|
+
authorizedAmount: string;
|
|
253
|
+
availableAmount: string;
|
|
254
|
+
updatedAt: string | null;
|
|
255
|
+
}
|
|
256
|
+
export interface EscrowDepositSubmitted {
|
|
257
|
+
txHash: string;
|
|
258
|
+
submittedAt: string;
|
|
259
|
+
claimedAsset: string;
|
|
260
|
+
claimedAmount: string;
|
|
261
|
+
}
|
|
262
|
+
export interface EscrowDepositFinalized {
|
|
263
|
+
txHash: string;
|
|
264
|
+
finalizedAt: string | null;
|
|
265
|
+
blockNumber: string | null;
|
|
266
|
+
claimedAsset: string;
|
|
267
|
+
claimedAmount: string;
|
|
268
|
+
}
|
|
269
|
+
export interface EscrowDepositFailed {
|
|
270
|
+
txHash: string;
|
|
271
|
+
submittedAt: string;
|
|
272
|
+
claimedAsset: string;
|
|
273
|
+
claimedAmount: string;
|
|
274
|
+
lastError: string | null;
|
|
275
|
+
}
|
|
276
|
+
export interface EscrowBalance {
|
|
277
|
+
account: string;
|
|
278
|
+
balances: EscrowBalanceEntry[];
|
|
279
|
+
deposits: {
|
|
280
|
+
submitted: EscrowDepositSubmitted[];
|
|
281
|
+
finalized: EscrowDepositFinalized[];
|
|
282
|
+
failed: EscrowDepositFailed[];
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
export interface SubmitDepositParams {
|
|
286
|
+
txHash: string;
|
|
287
|
+
}
|
|
288
|
+
export interface DepositState {
|
|
289
|
+
txHash: string;
|
|
290
|
+
account: string;
|
|
291
|
+
status: string;
|
|
292
|
+
blockNumber: string | null;
|
|
293
|
+
submittedAt: string;
|
|
294
|
+
finalizedAt: string | null;
|
|
295
|
+
lastError: string | null;
|
|
296
|
+
}
|
|
136
297
|
export interface GatewayClient {
|
|
137
298
|
isRegisteredBuilder(address: string): Promise<boolean>;
|
|
138
299
|
getBuilder(address: string): Promise<Builder | null>;
|
|
@@ -140,23 +301,28 @@ export interface GatewayClient {
|
|
|
140
301
|
listGrantsByUser(userAddress: string): Promise<GrantListItem[]>;
|
|
141
302
|
getSchemaForScope(scope: string): Promise<Schema | null>;
|
|
142
303
|
getServer(address: string): Promise<ServerInfo | null>;
|
|
143
|
-
|
|
144
|
-
|
|
304
|
+
/**
|
|
305
|
+
* Fetch a single data point by its deterministic id (keccak256 of (owner, scope)).
|
|
306
|
+
* Returns null on 404. The gateway omits `status` from the response body — read it
|
|
307
|
+
* from the on-chain DataRegistryV2 contract when you need the canonical lifecycle state.
|
|
308
|
+
*/
|
|
309
|
+
getDataPoint(dataPointId: string): Promise<DataPointRecord | null>;
|
|
310
|
+
/**
|
|
311
|
+
* Page through an owner's data points. Cursor is opaque; pass `null` for the first
|
|
312
|
+
* page and feed back `result.cursor` until it returns null.
|
|
313
|
+
*/
|
|
314
|
+
listDataPointsByOwner(owner: string, cursor: string | null, options?: ListDataPointsOptions): Promise<DataPointListResult>;
|
|
145
315
|
getSchema(schemaId: string): Promise<Schema | null>;
|
|
146
316
|
registerServer(params: RegisterServerParams): Promise<RegisterServerResult>;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}>;
|
|
317
|
+
registerBuilder(params: RegisterBuilderParams): Promise<RegisterBuilderResult>;
|
|
318
|
+
registerDataPoint(params: RegisterDataPointParams): Promise<RegisterDataPointResult>;
|
|
150
319
|
createGrant(params: CreateGrantParams): Promise<{
|
|
151
320
|
grantId?: string;
|
|
152
321
|
}>;
|
|
153
322
|
revokeGrant(params: RevokeGrantParams): Promise<void>;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
* benign (blob already gone) or a hard failure.
|
|
159
|
-
*/
|
|
160
|
-
deleteFile(params: DeleteFileParams): Promise<void>;
|
|
323
|
+
getEscrowBalance(account: string): Promise<EscrowBalance>;
|
|
324
|
+
submitEscrowDeposit(params: SubmitDepositParams): Promise<DepositState>;
|
|
325
|
+
payForOperation(params: PayForOperationParams): Promise<PayForOperationResult>;
|
|
326
|
+
settle(params?: SettleParams): Promise<SettleResult>;
|
|
161
327
|
}
|
|
162
328
|
export declare function createGatewayClient(baseUrl: string): GatewayClient;
|
package/dist/protocol/gateway.js
CHANGED
|
@@ -4,16 +4,6 @@ function createGatewayClient(baseUrl) {
|
|
|
4
4
|
const envelope = await res.json();
|
|
5
5
|
return envelope.data;
|
|
6
6
|
}
|
|
7
|
-
function normalizeFileRecord(record) {
|
|
8
|
-
return {
|
|
9
|
-
fileId: record.fileId ?? record.id ?? "",
|
|
10
|
-
owner: record.owner ?? record.ownerAddress ?? "",
|
|
11
|
-
url: record.url,
|
|
12
|
-
schemaId: record.schemaId,
|
|
13
|
-
createdAt: record.createdAt ?? record.addedAt ?? "",
|
|
14
|
-
deletedAt: record.deletedAt ?? null
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
7
|
function getMutationId(body, key) {
|
|
18
8
|
const value = body[key] ?? body["id"];
|
|
19
9
|
return typeof value === "string" ? value : void 0;
|
|
@@ -63,31 +53,33 @@ function createGatewayClient(baseUrl) {
|
|
|
63
53
|
}
|
|
64
54
|
return unwrapEnvelope(res);
|
|
65
55
|
},
|
|
66
|
-
async
|
|
67
|
-
const res = await fetch(`${base}/v1/
|
|
56
|
+
async getDataPoint(dataPointId) {
|
|
57
|
+
const res = await fetch(`${base}/v1/data/${dataPointId}`);
|
|
68
58
|
if (res.status === 404) return null;
|
|
69
59
|
if (!res.ok) {
|
|
70
60
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
71
61
|
}
|
|
72
|
-
return
|
|
62
|
+
return unwrapEnvelope(res);
|
|
73
63
|
},
|
|
74
|
-
async
|
|
64
|
+
async listDataPointsByOwner(owner, cursor, options) {
|
|
75
65
|
const params = new URLSearchParams({ user: owner });
|
|
76
66
|
if (cursor !== null) {
|
|
77
67
|
params.set("cursor", cursor);
|
|
78
68
|
}
|
|
79
|
-
if (options?.
|
|
80
|
-
params.set("
|
|
69
|
+
if (options?.since) {
|
|
70
|
+
params.set("since", options.since);
|
|
71
|
+
}
|
|
72
|
+
if (options?.limit !== void 0) {
|
|
73
|
+
params.set("limit", String(options.limit));
|
|
81
74
|
}
|
|
82
|
-
const res = await fetch(`${base}/v1/
|
|
75
|
+
const res = await fetch(`${base}/v1/data?${params.toString()}`);
|
|
83
76
|
if (!res.ok) {
|
|
84
77
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
85
78
|
}
|
|
86
79
|
const envelope = await res.json();
|
|
87
|
-
const
|
|
88
|
-
const nextCursor = pagination?.hasMore === false ? null : pagination?.nextCursor ?? envelope.data.cursor ?? null;
|
|
80
|
+
const nextCursor = envelope.pagination?.hasMore === false ? null : envelope.pagination?.nextCursor ?? null;
|
|
89
81
|
return {
|
|
90
|
-
|
|
82
|
+
dataPoints: envelope.data.dataPoints,
|
|
91
83
|
cursor: nextCursor
|
|
92
84
|
};
|
|
93
85
|
},
|
|
@@ -129,8 +121,8 @@ function createGatewayClient(baseUrl) {
|
|
|
129
121
|
alreadyRegistered: false
|
|
130
122
|
};
|
|
131
123
|
},
|
|
132
|
-
async
|
|
133
|
-
const res = await fetch(`${base}/v1/
|
|
124
|
+
async registerBuilder(params) {
|
|
125
|
+
const res = await fetch(`${base}/v1/builders`, {
|
|
134
126
|
method: "POST",
|
|
135
127
|
headers: {
|
|
136
128
|
"Content-Type": "application/json",
|
|
@@ -138,22 +130,57 @@ function createGatewayClient(baseUrl) {
|
|
|
138
130
|
},
|
|
139
131
|
body: JSON.stringify({
|
|
140
132
|
ownerAddress: params.ownerAddress,
|
|
141
|
-
|
|
142
|
-
|
|
133
|
+
granteeAddress: params.granteeAddress,
|
|
134
|
+
publicKey: params.publicKey,
|
|
135
|
+
appUrl: params.appUrl
|
|
143
136
|
})
|
|
144
137
|
});
|
|
145
138
|
if (res.status === 409) {
|
|
146
139
|
const body2 = await res.json().catch(() => ({}));
|
|
147
140
|
return {
|
|
148
|
-
|
|
141
|
+
builderId: getMutationId(
|
|
142
|
+
body2,
|
|
143
|
+
"builderId"
|
|
144
|
+
),
|
|
145
|
+
alreadyRegistered: true
|
|
149
146
|
};
|
|
150
147
|
}
|
|
151
148
|
if (!res.ok) {
|
|
152
149
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
153
150
|
}
|
|
154
|
-
const body = await res.json();
|
|
151
|
+
const body = await res.json().catch(() => ({}));
|
|
152
|
+
return {
|
|
153
|
+
builderId: getMutationId(body, "builderId"),
|
|
154
|
+
alreadyRegistered: false
|
|
155
|
+
};
|
|
156
|
+
},
|
|
157
|
+
async registerDataPoint(params) {
|
|
158
|
+
const res = await fetch(`${base}/v1/data`, {
|
|
159
|
+
method: "POST",
|
|
160
|
+
headers: {
|
|
161
|
+
"Content-Type": "application/json",
|
|
162
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
163
|
+
},
|
|
164
|
+
body: JSON.stringify({
|
|
165
|
+
ownerAddress: params.ownerAddress,
|
|
166
|
+
scope: params.scope,
|
|
167
|
+
dataHash: params.dataHash,
|
|
168
|
+
metadataHash: params.metadataHash,
|
|
169
|
+
expectedVersion: params.expectedVersion
|
|
170
|
+
})
|
|
171
|
+
});
|
|
172
|
+
if (!res.ok) {
|
|
173
|
+
const body2 = await res.json().catch(() => ({}));
|
|
174
|
+
const detail = body2.error ?? res.statusText;
|
|
175
|
+
throw new Error(`Gateway error: ${res.status} ${detail}`);
|
|
176
|
+
}
|
|
177
|
+
const body = await res.json().catch(() => ({}));
|
|
155
178
|
return {
|
|
156
|
-
|
|
179
|
+
dataPointId: getMutationId(
|
|
180
|
+
body,
|
|
181
|
+
"dataPointId"
|
|
182
|
+
),
|
|
183
|
+
expectedVersion: body.expectedVersion
|
|
157
184
|
};
|
|
158
185
|
},
|
|
159
186
|
async createGrant(params) {
|
|
@@ -166,8 +193,9 @@ function createGatewayClient(baseUrl) {
|
|
|
166
193
|
body: JSON.stringify({
|
|
167
194
|
grantorAddress: params.grantorAddress,
|
|
168
195
|
granteeId: params.granteeId,
|
|
169
|
-
|
|
170
|
-
|
|
196
|
+
scopes: params.scopes,
|
|
197
|
+
grantVersion: params.grantVersion,
|
|
198
|
+
expiresAt: params.expiresAt
|
|
171
199
|
})
|
|
172
200
|
});
|
|
173
201
|
if (res.status === 409) {
|
|
@@ -192,7 +220,8 @@ function createGatewayClient(baseUrl) {
|
|
|
192
220
|
Authorization: `Web3Signed ${params.signature}`
|
|
193
221
|
},
|
|
194
222
|
body: JSON.stringify({
|
|
195
|
-
grantorAddress: params.grantorAddress
|
|
223
|
+
grantorAddress: params.grantorAddress,
|
|
224
|
+
grantVersion: params.grantVersion
|
|
196
225
|
})
|
|
197
226
|
});
|
|
198
227
|
if (res.status === 409) return;
|
|
@@ -200,21 +229,62 @@ function createGatewayClient(baseUrl) {
|
|
|
200
229
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
201
230
|
}
|
|
202
231
|
},
|
|
203
|
-
async
|
|
204
|
-
const res = await fetch(`${base}/v1/
|
|
205
|
-
|
|
232
|
+
async getEscrowBalance(account) {
|
|
233
|
+
const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
|
|
234
|
+
if (!res.ok) {
|
|
235
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
236
|
+
}
|
|
237
|
+
return await res.json();
|
|
238
|
+
},
|
|
239
|
+
async submitEscrowDeposit(params) {
|
|
240
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
241
|
+
method: "POST",
|
|
242
|
+
headers: { "Content-Type": "application/json" },
|
|
243
|
+
body: JSON.stringify({ txHash: params.txHash })
|
|
244
|
+
});
|
|
245
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
246
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
247
|
+
}
|
|
248
|
+
return await res.json();
|
|
249
|
+
},
|
|
250
|
+
async payForOperation(params) {
|
|
251
|
+
const body = {
|
|
252
|
+
payerAddress: params.payerAddress,
|
|
253
|
+
opType: params.opType,
|
|
254
|
+
opId: params.opId,
|
|
255
|
+
asset: params.asset,
|
|
256
|
+
amount: params.amount,
|
|
257
|
+
paymentNonce: params.paymentNonce
|
|
258
|
+
};
|
|
259
|
+
if (params.accessRecord) {
|
|
260
|
+
body["accessRecord"] = params.accessRecord;
|
|
261
|
+
}
|
|
262
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
263
|
+
method: "POST",
|
|
206
264
|
headers: {
|
|
207
265
|
"Content-Type": "application/json",
|
|
208
266
|
Authorization: `Web3Signed ${params.signature}`
|
|
209
267
|
},
|
|
210
|
-
body: JSON.stringify(
|
|
211
|
-
|
|
212
|
-
|
|
268
|
+
body: JSON.stringify(body)
|
|
269
|
+
});
|
|
270
|
+
if (!res.ok) {
|
|
271
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
272
|
+
}
|
|
273
|
+
return await res.json();
|
|
274
|
+
},
|
|
275
|
+
async settle(params) {
|
|
276
|
+
const res = await fetch(`${base}/v1/settle`, {
|
|
277
|
+
method: "POST",
|
|
278
|
+
headers: { "Content-Type": "application/json" },
|
|
279
|
+
// The gateway accepts an empty body; only `limit` is recognised.
|
|
280
|
+
// Always send a JSON body so the gateway's req.body shape parse
|
|
281
|
+
// doesn't have to deal with an undefined.
|
|
282
|
+
body: JSON.stringify(params ?? {})
|
|
213
283
|
});
|
|
214
|
-
if (res.status === 409) return;
|
|
215
284
|
if (!res.ok) {
|
|
216
285
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
217
286
|
}
|
|
287
|
+
return await res.json();
|
|
218
288
|
}
|
|
219
289
|
};
|
|
220
290
|
}
|