@opendatalabs/vana-sdk 3.4.1-canary.e9d0aad → 3.5.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/dist/account/personal-server-lite-owner-binding.cjs +3 -3
- package/dist/account/personal-server-lite-owner-binding.cjs.map +1 -1
- package/dist/account/personal-server-lite-owner-binding.d.ts +2 -2
- package/dist/account/personal-server-lite-owner-binding.js +1 -1
- package/dist/account/personal-server-lite-owner-binding.js.map +1 -1
- package/dist/index.browser.d.ts +5 -8
- package/dist/index.browser.js +250 -416
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +258 -439
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +5 -8
- package/dist/index.node.js +250 -416
- package/dist/index.node.js.map +4 -4
- package/dist/{protocol/personal-server-lite-owner-binding.cjs → personal-server-lite/owner-binding.cjs} +5 -5
- package/dist/personal-server-lite/owner-binding.cjs.map +1 -0
- package/dist/{protocol/personal-server-lite-owner-binding.d.ts → personal-server-lite/owner-binding.d.ts} +3 -3
- package/dist/{protocol/personal-server-lite-owner-binding.js → personal-server-lite/owner-binding.js} +2 -2
- package/dist/personal-server-lite/owner-binding.js.map +1 -0
- package/dist/protocol/eip712.cjs +31 -53
- package/dist/protocol/eip712.cjs.map +1 -1
- package/dist/protocol/eip712.d.ts +43 -98
- package/dist/protocol/eip712.js +27 -47
- package/dist/protocol/eip712.js.map +1 -1
- package/dist/protocol/escrow.cjs +146 -0
- package/dist/protocol/escrow.cjs.map +1 -0
- package/dist/protocol/escrow.d.ts +336 -0
- package/dist/protocol/escrow.js +118 -0
- package/dist/protocol/escrow.js.map +1 -0
- package/dist/protocol/gateway.cjs +37 -107
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.d.ts +57 -223
- package/dist/protocol/gateway.js +37 -107
- package/dist/protocol/gateway.js.map +1 -1
- package/dist/protocol/grants.cjs +64 -27
- package/dist/protocol/grants.cjs.map +1 -1
- package/dist/protocol/grants.d.ts +13 -6
- package/dist/protocol/grants.js +63 -27
- package/dist/protocol/grants.js.map +1 -1
- package/dist/protocol/personal-server-registration.cjs +16 -4
- package/dist/protocol/personal-server-registration.cjs.map +1 -1
- package/dist/protocol/personal-server-registration.d.ts +5 -2
- package/dist/protocol/personal-server-registration.js +16 -4
- package/dist/protocol/personal-server-registration.js.map +1 -1
- package/package.json +2 -3
- package/dist/protocol/data-point-status.cjs +0 -80
- package/dist/protocol/data-point-status.cjs.map +0 -1
- package/dist/protocol/data-point-status.d.ts +0 -34
- package/dist/protocol/data-point-status.js +0 -51
- package/dist/protocol/data-point-status.js.map +0 -1
- package/dist/protocol/escrow-deposit.cjs +0 -89
- package/dist/protocol/escrow-deposit.cjs.map +0 -1
- package/dist/protocol/escrow-deposit.d.ts +0 -47
- package/dist/protocol/escrow-deposit.js +0 -60
- package/dist/protocol/escrow-deposit.js.map +0 -1
- package/dist/protocol/escrow-flow.test.d.ts +0 -21
- package/dist/protocol/fee-registry.cjs +0 -116
- package/dist/protocol/fee-registry.cjs.map +0 -1
- package/dist/protocol/fee-registry.d.ts +0 -151
- package/dist/protocol/fee-registry.js +0 -89
- package/dist/protocol/fee-registry.js.map +0 -1
- package/dist/protocol/fee-registry.test.d.ts +0 -1
- package/dist/protocol/personal-server-data.cjs +0 -71
- package/dist/protocol/personal-server-data.cjs.map +0 -1
- package/dist/protocol/personal-server-data.d.ts +0 -16
- package/dist/protocol/personal-server-data.js +0 -47
- package/dist/protocol/personal-server-data.js.map +0 -1
- package/dist/protocol/personal-server-data.test.d.ts +0 -1
- package/dist/protocol/personal-server-lite-owner-binding.cjs.map +0 -1
- package/dist/protocol/personal-server-lite-owner-binding.js.map +0 -1
- package/dist/protocol/personal-server-lite-owner-binding.test.d.ts +0 -1
- /package/dist/{protocol/data-point-status.test.d.ts → personal-server-lite/owner-binding.test.d.ts} +0 -0
- /package/dist/protocol/{escrow-deposit.test.d.ts → escrow.test.d.ts} +0 -0
|
@@ -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/files`). 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,71 +51,75 @@ 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;
|
|
61
54
|
}
|
|
62
|
-
export type GatewayGrantStatus = "pending" | "submitting" | "confirmed" | "finalized" | "reorged";
|
|
63
55
|
export interface GatewayGrantResponse {
|
|
64
56
|
id: string;
|
|
65
57
|
grantorAddress: string;
|
|
66
58
|
granteeId: string;
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
grant: string;
|
|
60
|
+
fileIds: string[];
|
|
61
|
+
status: "pending" | "confirmed";
|
|
69
62
|
addedAt: string;
|
|
70
|
-
expiresAt: string | null;
|
|
71
|
-
expired: boolean;
|
|
72
63
|
revokedAt: string | null;
|
|
73
64
|
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;
|
|
83
65
|
}
|
|
84
|
-
export
|
|
85
|
-
export interface DataPointRecord {
|
|
66
|
+
export interface GrantListItem {
|
|
86
67
|
id: string;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
68
|
+
grantorAddress: string;
|
|
69
|
+
granteeId: string;
|
|
70
|
+
grant: string;
|
|
71
|
+
fileIds: string[];
|
|
72
|
+
status: "pending" | "confirmed";
|
|
92
73
|
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;
|
|
93
89
|
}
|
|
94
|
-
export interface
|
|
95
|
-
|
|
90
|
+
export interface FileListResult {
|
|
91
|
+
files: FileRecord[];
|
|
96
92
|
cursor: string | null;
|
|
97
93
|
}
|
|
98
|
-
export interface
|
|
94
|
+
export interface ListFilesOptions {
|
|
99
95
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
96
|
+
* Include soft-deleted files in the result (each carries a non-null `deletedAt`). Default false.
|
|
97
|
+
* Used by the PS sync download worker to reconcile deletions of files it already holds locally.
|
|
102
98
|
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
includeDeleted?: boolean;
|
|
100
|
+
}
|
|
101
|
+
export interface RegisterFileParams {
|
|
102
|
+
ownerAddress: string;
|
|
103
|
+
url: string;
|
|
104
|
+
schemaId: string;
|
|
105
|
+
signature: string;
|
|
106
106
|
}
|
|
107
107
|
export interface CreateGrantParams {
|
|
108
108
|
grantorAddress: string;
|
|
109
109
|
granteeId: string;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
expiresAt: string;
|
|
110
|
+
grant: string;
|
|
111
|
+
fileIds: string[];
|
|
113
112
|
signature: string;
|
|
114
113
|
}
|
|
115
114
|
export interface RevokeGrantParams {
|
|
116
115
|
grantId: string;
|
|
117
116
|
grantorAddress: string;
|
|
118
|
-
|
|
117
|
+
signature: string;
|
|
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. */
|
|
119
123
|
signature: string;
|
|
120
124
|
}
|
|
121
125
|
export interface RegisterServerParams {
|
|
@@ -129,171 +133,6 @@ export interface RegisterServerResult {
|
|
|
129
133
|
serverId?: string;
|
|
130
134
|
alreadyRegistered: boolean;
|
|
131
135
|
}
|
|
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
|
-
}
|
|
297
136
|
export interface GatewayClient {
|
|
298
137
|
isRegisteredBuilder(address: string): Promise<boolean>;
|
|
299
138
|
getBuilder(address: string): Promise<Builder | null>;
|
|
@@ -301,28 +140,23 @@ export interface GatewayClient {
|
|
|
301
140
|
listGrantsByUser(userAddress: string): Promise<GrantListItem[]>;
|
|
302
141
|
getSchemaForScope(scope: string): Promise<Schema | null>;
|
|
303
142
|
getServer(address: string): Promise<ServerInfo | null>;
|
|
304
|
-
|
|
305
|
-
|
|
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>;
|
|
143
|
+
getFile(fileId: string): Promise<FileRecord | null>;
|
|
144
|
+
listFilesSince(owner: string, cursor: string | null, options?: ListFilesOptions): Promise<FileListResult>;
|
|
315
145
|
getSchema(schemaId: string): Promise<Schema | null>;
|
|
316
146
|
registerServer(params: RegisterServerParams): Promise<RegisterServerResult>;
|
|
317
|
-
|
|
318
|
-
|
|
147
|
+
registerFile(params: RegisterFileParams): Promise<{
|
|
148
|
+
fileId?: string;
|
|
149
|
+
}>;
|
|
319
150
|
createGrant(params: CreateGrantParams): Promise<{
|
|
320
151
|
grantId?: string;
|
|
321
152
|
}>;
|
|
322
153
|
revokeGrant(params: RevokeGrantParams): Promise<void>;
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
154
|
+
/**
|
|
155
|
+
* Soft-deletes (de-registers) a file at the gateway. Resolves on 200 and on 409
|
|
156
|
+
* (already deleted) — 409 is treated as idempotent success. Other non-2xx, including
|
|
157
|
+
* 404 (file not registered), throw; the PS delete cascade decides whether a 404 is
|
|
158
|
+
* benign (blob already gone) or a hard failure.
|
|
159
|
+
*/
|
|
160
|
+
deleteFile(params: DeleteFileParams): Promise<void>;
|
|
327
161
|
}
|
|
328
162
|
export declare function createGatewayClient(baseUrl: string): GatewayClient;
|
package/dist/protocol/gateway.js
CHANGED
|
@@ -4,6 +4,16 @@ 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
|
+
}
|
|
7
17
|
function getMutationId(body, key) {
|
|
8
18
|
const value = body[key] ?? body["id"];
|
|
9
19
|
return typeof value === "string" ? value : void 0;
|
|
@@ -53,33 +63,31 @@ function createGatewayClient(baseUrl) {
|
|
|
53
63
|
}
|
|
54
64
|
return unwrapEnvelope(res);
|
|
55
65
|
},
|
|
56
|
-
async
|
|
57
|
-
const res = await fetch(`${base}/v1/
|
|
66
|
+
async getFile(fileId) {
|
|
67
|
+
const res = await fetch(`${base}/v1/files/${fileId}`);
|
|
58
68
|
if (res.status === 404) return null;
|
|
59
69
|
if (!res.ok) {
|
|
60
70
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
61
71
|
}
|
|
62
|
-
return unwrapEnvelope(res);
|
|
72
|
+
return normalizeFileRecord(await unwrapEnvelope(res));
|
|
63
73
|
},
|
|
64
|
-
async
|
|
74
|
+
async listFilesSince(owner, cursor, options) {
|
|
65
75
|
const params = new URLSearchParams({ user: owner });
|
|
66
76
|
if (cursor !== null) {
|
|
67
77
|
params.set("cursor", cursor);
|
|
68
78
|
}
|
|
69
|
-
if (options?.
|
|
70
|
-
params.set("
|
|
71
|
-
}
|
|
72
|
-
if (options?.limit !== void 0) {
|
|
73
|
-
params.set("limit", String(options.limit));
|
|
79
|
+
if (options?.includeDeleted) {
|
|
80
|
+
params.set("includeDeleted", "true");
|
|
74
81
|
}
|
|
75
|
-
const res = await fetch(`${base}/v1/
|
|
82
|
+
const res = await fetch(`${base}/v1/files?${params.toString()}`);
|
|
76
83
|
if (!res.ok) {
|
|
77
84
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
78
85
|
}
|
|
79
86
|
const envelope = await res.json();
|
|
80
|
-
const
|
|
87
|
+
const { pagination } = envelope;
|
|
88
|
+
const nextCursor = pagination?.hasMore === false ? null : pagination?.nextCursor ?? envelope.data.cursor ?? null;
|
|
81
89
|
return {
|
|
82
|
-
|
|
90
|
+
files: envelope.data.files.map(normalizeFileRecord),
|
|
83
91
|
cursor: nextCursor
|
|
84
92
|
};
|
|
85
93
|
},
|
|
@@ -121,8 +129,8 @@ function createGatewayClient(baseUrl) {
|
|
|
121
129
|
alreadyRegistered: false
|
|
122
130
|
};
|
|
123
131
|
},
|
|
124
|
-
async
|
|
125
|
-
const res = await fetch(`${base}/v1/
|
|
132
|
+
async registerFile(params) {
|
|
133
|
+
const res = await fetch(`${base}/v1/files`, {
|
|
126
134
|
method: "POST",
|
|
127
135
|
headers: {
|
|
128
136
|
"Content-Type": "application/json",
|
|
@@ -130,57 +138,22 @@ function createGatewayClient(baseUrl) {
|
|
|
130
138
|
},
|
|
131
139
|
body: JSON.stringify({
|
|
132
140
|
ownerAddress: params.ownerAddress,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
appUrl: params.appUrl
|
|
141
|
+
url: params.url,
|
|
142
|
+
schemaId: params.schemaId
|
|
136
143
|
})
|
|
137
144
|
});
|
|
138
145
|
if (res.status === 409) {
|
|
139
146
|
const body2 = await res.json().catch(() => ({}));
|
|
140
147
|
return {
|
|
141
|
-
|
|
142
|
-
body2,
|
|
143
|
-
"builderId"
|
|
144
|
-
),
|
|
145
|
-
alreadyRegistered: true
|
|
148
|
+
fileId: getMutationId(body2, "fileId")
|
|
146
149
|
};
|
|
147
150
|
}
|
|
148
151
|
if (!res.ok) {
|
|
149
152
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
150
153
|
}
|
|
151
|
-
const body = await res.json()
|
|
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(() => ({}));
|
|
154
|
+
const body = await res.json();
|
|
178
155
|
return {
|
|
179
|
-
|
|
180
|
-
body,
|
|
181
|
-
"dataPointId"
|
|
182
|
-
),
|
|
183
|
-
expectedVersion: body.expectedVersion
|
|
156
|
+
fileId: getMutationId(body, "fileId")
|
|
184
157
|
};
|
|
185
158
|
},
|
|
186
159
|
async createGrant(params) {
|
|
@@ -193,9 +166,8 @@ function createGatewayClient(baseUrl) {
|
|
|
193
166
|
body: JSON.stringify({
|
|
194
167
|
grantorAddress: params.grantorAddress,
|
|
195
168
|
granteeId: params.granteeId,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
expiresAt: params.expiresAt
|
|
169
|
+
grant: params.grant,
|
|
170
|
+
fileIds: params.fileIds
|
|
199
171
|
})
|
|
200
172
|
});
|
|
201
173
|
if (res.status === 409) {
|
|
@@ -220,8 +192,7 @@ function createGatewayClient(baseUrl) {
|
|
|
220
192
|
Authorization: `Web3Signed ${params.signature}`
|
|
221
193
|
},
|
|
222
194
|
body: JSON.stringify({
|
|
223
|
-
grantorAddress: params.grantorAddress
|
|
224
|
-
grantVersion: params.grantVersion
|
|
195
|
+
grantorAddress: params.grantorAddress
|
|
225
196
|
})
|
|
226
197
|
});
|
|
227
198
|
if (res.status === 409) return;
|
|
@@ -229,62 +200,21 @@ function createGatewayClient(baseUrl) {
|
|
|
229
200
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
230
201
|
}
|
|
231
202
|
},
|
|
232
|
-
async
|
|
233
|
-
const res = await fetch(`${base}/v1/
|
|
234
|
-
|
|
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",
|
|
203
|
+
async deleteFile(params) {
|
|
204
|
+
const res = await fetch(`${base}/v1/files/${params.fileId}`, {
|
|
205
|
+
method: "DELETE",
|
|
264
206
|
headers: {
|
|
265
207
|
"Content-Type": "application/json",
|
|
266
208
|
Authorization: `Web3Signed ${params.signature}`
|
|
267
209
|
},
|
|
268
|
-
body: JSON.stringify(
|
|
269
|
-
|
|
270
|
-
|
|
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 ?? {})
|
|
210
|
+
body: JSON.stringify({
|
|
211
|
+
ownerAddress: params.ownerAddress
|
|
212
|
+
})
|
|
283
213
|
});
|
|
214
|
+
if (res.status === 409) return;
|
|
284
215
|
if (!res.ok) {
|
|
285
216
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
286
217
|
}
|
|
287
|
-
return await res.json();
|
|
288
218
|
}
|
|
289
219
|
};
|
|
290
220
|
}
|