@0xsequence/userdata 0.0.0-20260210155835
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/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +69 -0
- package/LICENSE +202 -0
- package/README.md +3 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/userdata.gen.d.ts +588 -0
- package/dist/userdata.gen.d.ts.map +1 -0
- package/dist/userdata.gen.js +891 -0
- package/package.json +28 -0
- package/src/index.ts +36 -0
- package/src/userdata.gen.ts +1729 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,1729 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// userdata v0.1.0 88764bb5f99353e11d849a1aa8f8a998501ffedb
|
|
3
|
+
// --
|
|
4
|
+
// Code generated by Webrpc-gen@v0.30.2 with typescript generator. DO NOT EDIT.
|
|
5
|
+
//
|
|
6
|
+
// webrpc-gen -schema=userdata.ridl -target=typescript -client -out=./clients/userdata.gen.ts
|
|
7
|
+
|
|
8
|
+
// Webrpc description and code-gen version
|
|
9
|
+
export const WebrpcVersion = 'v1'
|
|
10
|
+
|
|
11
|
+
// Schema version of your RIDL schema
|
|
12
|
+
export const WebrpcSchemaVersion = 'v0.1.0'
|
|
13
|
+
|
|
14
|
+
// Schema hash generated from your RIDL schema
|
|
15
|
+
export const WebrpcSchemaHash = '88764bb5f99353e11d849a1aa8f8a998501ffedb'
|
|
16
|
+
|
|
17
|
+
//
|
|
18
|
+
// Client interface
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
export interface UserDataClient {
|
|
22
|
+
getCapabilities(headers?: object, signal?: AbortSignal): Promise<GetCapabilitiesResponse>
|
|
23
|
+
|
|
24
|
+
getAccessToken(req: GetAccessTokenRequest, headers?: object, signal?: AbortSignal): Promise<GetAccessTokenResponse>
|
|
25
|
+
|
|
26
|
+
getIdentityToken(
|
|
27
|
+
req: GetIdentityTokenRequest,
|
|
28
|
+
headers?: object,
|
|
29
|
+
signal?: AbortSignal,
|
|
30
|
+
): Promise<GetIdentityTokenResponse>
|
|
31
|
+
|
|
32
|
+
getWalletPreferences(
|
|
33
|
+
req: GetWalletPreferencesRequest,
|
|
34
|
+
headers?: object,
|
|
35
|
+
signal?: AbortSignal,
|
|
36
|
+
): Promise<GetWalletPreferencesResponse>
|
|
37
|
+
|
|
38
|
+
putWalletPreferences(
|
|
39
|
+
req: PutWalletPreferencesRequest,
|
|
40
|
+
headers?: object,
|
|
41
|
+
signal?: AbortSignal,
|
|
42
|
+
): Promise<PutWalletPreferencesResponse>
|
|
43
|
+
|
|
44
|
+
listWalletSigners(
|
|
45
|
+
req: ListWalletSignersRequest,
|
|
46
|
+
headers?: object,
|
|
47
|
+
signal?: AbortSignal,
|
|
48
|
+
): Promise<ListWalletSignersResponse>
|
|
49
|
+
|
|
50
|
+
putWalletSigner(req: PutWalletSignerRequest, headers?: object, signal?: AbortSignal): Promise<PutWalletSignerResponse>
|
|
51
|
+
|
|
52
|
+
deleteWalletSigner(
|
|
53
|
+
req: DeleteWalletSignerRequest,
|
|
54
|
+
headers?: object,
|
|
55
|
+
signal?: AbortSignal,
|
|
56
|
+
): Promise<DeleteWalletSignerResponse>
|
|
57
|
+
|
|
58
|
+
listSessions(req: ListSessionsRequest, headers?: object, signal?: AbortSignal): Promise<ListSessionsResponse>
|
|
59
|
+
|
|
60
|
+
putSession(req: PutSessionRequest, headers?: object, signal?: AbortSignal): Promise<PutSessionResponse>
|
|
61
|
+
|
|
62
|
+
deleteSession(req: DeleteSessionRequest, headers?: object, signal?: AbortSignal): Promise<DeleteSessionResponse>
|
|
63
|
+
|
|
64
|
+
listContacts(req: ListContactsRequest, headers?: object, signal?: AbortSignal): Promise<ListContactsResponse>
|
|
65
|
+
|
|
66
|
+
putContact(req: PutContactRequest, headers?: object, signal?: AbortSignal): Promise<PutContactResponse>
|
|
67
|
+
|
|
68
|
+
deleteContact(req: DeleteContactRequest, headers?: object, signal?: AbortSignal): Promise<DeleteContactResponse>
|
|
69
|
+
|
|
70
|
+
listWatchedWallets(
|
|
71
|
+
req: ListWatchedWalletsRequest,
|
|
72
|
+
headers?: object,
|
|
73
|
+
signal?: AbortSignal,
|
|
74
|
+
): Promise<ListWatchedWalletsResponse>
|
|
75
|
+
|
|
76
|
+
putWatchedWallet(
|
|
77
|
+
req: PutWatchedWalletRequest,
|
|
78
|
+
headers?: object,
|
|
79
|
+
signal?: AbortSignal,
|
|
80
|
+
): Promise<PutWatchedWalletResponse>
|
|
81
|
+
|
|
82
|
+
deleteWatchedWallet(
|
|
83
|
+
req: DeleteWatchedWalletRequest,
|
|
84
|
+
headers?: object,
|
|
85
|
+
signal?: AbortSignal,
|
|
86
|
+
): Promise<DeleteWatchedWalletResponse>
|
|
87
|
+
|
|
88
|
+
listDiscoverFavorites(
|
|
89
|
+
req: ListDiscoverFavoritesRequest,
|
|
90
|
+
headers?: object,
|
|
91
|
+
signal?: AbortSignal,
|
|
92
|
+
): Promise<ListDiscoverFavoritesResponse>
|
|
93
|
+
|
|
94
|
+
putDiscoverFavorite(
|
|
95
|
+
req: PutDiscoverFavoriteRequest,
|
|
96
|
+
headers?: object,
|
|
97
|
+
signal?: AbortSignal,
|
|
98
|
+
): Promise<PutDiscoverFavoriteResponse>
|
|
99
|
+
|
|
100
|
+
deleteDiscoverFavorite(
|
|
101
|
+
req: DeleteDiscoverFavoriteRequest,
|
|
102
|
+
headers?: object,
|
|
103
|
+
signal?: AbortSignal,
|
|
104
|
+
): Promise<DeleteDiscoverFavoriteResponse>
|
|
105
|
+
|
|
106
|
+
listDiscoverHistory(
|
|
107
|
+
req: ListDiscoverHistoryRequest,
|
|
108
|
+
headers?: object,
|
|
109
|
+
signal?: AbortSignal,
|
|
110
|
+
): Promise<ListDiscoverHistoryResponse>
|
|
111
|
+
|
|
112
|
+
putDiscoverHistory(
|
|
113
|
+
req: PutDiscoverHistoryRequest,
|
|
114
|
+
headers?: object,
|
|
115
|
+
signal?: AbortSignal,
|
|
116
|
+
): Promise<PutDiscoverHistoryResponse>
|
|
117
|
+
|
|
118
|
+
deleteDiscoverHistory(
|
|
119
|
+
req: DeleteDiscoverHistoryRequest,
|
|
120
|
+
headers?: object,
|
|
121
|
+
signal?: AbortSignal,
|
|
122
|
+
): Promise<DeleteDiscoverHistoryResponse>
|
|
123
|
+
|
|
124
|
+
listTokenFavorites(
|
|
125
|
+
req: ListTokenFavoritesRequest,
|
|
126
|
+
headers?: object,
|
|
127
|
+
signal?: AbortSignal,
|
|
128
|
+
): Promise<ListTokenFavoritesResponse>
|
|
129
|
+
|
|
130
|
+
putTokenFavorite(
|
|
131
|
+
req: PutTokenFavoriteRequest,
|
|
132
|
+
headers?: object,
|
|
133
|
+
signal?: AbortSignal,
|
|
134
|
+
): Promise<PutTokenFavoriteResponse>
|
|
135
|
+
|
|
136
|
+
deleteTokenFavorite(
|
|
137
|
+
req: DeleteTokenFavoriteRequest,
|
|
138
|
+
headers?: object,
|
|
139
|
+
signal?: AbortSignal,
|
|
140
|
+
): Promise<DeleteTokenFavoriteResponse>
|
|
141
|
+
|
|
142
|
+
listHiddenTokens(
|
|
143
|
+
req: ListHiddenTokensRequest,
|
|
144
|
+
headers?: object,
|
|
145
|
+
signal?: AbortSignal,
|
|
146
|
+
): Promise<ListHiddenTokensResponse>
|
|
147
|
+
|
|
148
|
+
putHiddenToken(req: PutHiddenTokenRequest, headers?: object, signal?: AbortSignal): Promise<PutHiddenTokenResponse>
|
|
149
|
+
|
|
150
|
+
deleteHiddenToken(
|
|
151
|
+
req: DeleteHiddenTokenRequest,
|
|
152
|
+
headers?: object,
|
|
153
|
+
signal?: AbortSignal,
|
|
154
|
+
): Promise<DeleteHiddenTokenResponse>
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
//
|
|
158
|
+
// Schema types
|
|
159
|
+
//
|
|
160
|
+
|
|
161
|
+
export interface Version {
|
|
162
|
+
webrpcVersion: string
|
|
163
|
+
schemaVersion: string
|
|
164
|
+
schemaHash: string
|
|
165
|
+
appVersion: string
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface RuntimeStatus {
|
|
169
|
+
healthOK: boolean
|
|
170
|
+
startTime: string
|
|
171
|
+
uptime: number
|
|
172
|
+
ver: string
|
|
173
|
+
branch: string
|
|
174
|
+
commitHash: string
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export interface Wallet {
|
|
178
|
+
address: string
|
|
179
|
+
ecosystem?: number
|
|
180
|
+
preferences: WalletPreferences
|
|
181
|
+
updatedAt: string
|
|
182
|
+
createdAt: string
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface WalletPreferences {
|
|
186
|
+
manualSigning?: boolean
|
|
187
|
+
hideUnlistedTokens?: boolean
|
|
188
|
+
hideCollectibles?: boolean
|
|
189
|
+
includeTestnets?: boolean
|
|
190
|
+
currency?: string
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface WalletSigner {
|
|
194
|
+
walletAddress: string
|
|
195
|
+
signerAddress: string
|
|
196
|
+
kind: string
|
|
197
|
+
email?: string
|
|
198
|
+
updatedAt: string
|
|
199
|
+
createdAt: string
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface Session {
|
|
203
|
+
walletAddress: string
|
|
204
|
+
sessionAddress: string
|
|
205
|
+
ipAddress: string
|
|
206
|
+
userAgent: string
|
|
207
|
+
originUrl: string
|
|
208
|
+
appUrl: string
|
|
209
|
+
createdAt: string
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export interface Contact {
|
|
213
|
+
walletAddress: string
|
|
214
|
+
contactAddress: string
|
|
215
|
+
nickname: string
|
|
216
|
+
updatedAt: string
|
|
217
|
+
createdAt: string
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export interface WatchedWallet {
|
|
221
|
+
walletAddress: string
|
|
222
|
+
watchedAddress: string
|
|
223
|
+
nickname: string
|
|
224
|
+
updatedAt: string
|
|
225
|
+
createdAt: string
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export interface DiscoverFavorite {
|
|
229
|
+
walletAddress: string
|
|
230
|
+
id: number
|
|
231
|
+
dappId: string
|
|
232
|
+
createdAt: string
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export interface DiscoverHistory {
|
|
236
|
+
walletAddress: string
|
|
237
|
+
id: number
|
|
238
|
+
dappId: string
|
|
239
|
+
accessedAt: string
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface TokenFavorite {
|
|
243
|
+
walletAddress: string
|
|
244
|
+
id: number
|
|
245
|
+
chainId: string
|
|
246
|
+
contractAddress: string
|
|
247
|
+
tokenId: string
|
|
248
|
+
createdAt: string
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export interface HiddenToken {
|
|
252
|
+
walletAddress: string
|
|
253
|
+
id: number
|
|
254
|
+
chainId: string
|
|
255
|
+
contractAddress: string
|
|
256
|
+
tokenId?: string
|
|
257
|
+
createdAt: string
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export interface SessionProps {
|
|
261
|
+
address: string
|
|
262
|
+
appUrl: string
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export interface WalletSignerProps {
|
|
266
|
+
address: string
|
|
267
|
+
kind: string
|
|
268
|
+
email?: string
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export interface ContactProps {
|
|
272
|
+
address: string
|
|
273
|
+
nickname?: string
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export interface DiscoverProps {
|
|
277
|
+
dappId: string
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export interface TokenFavoriteProps {
|
|
281
|
+
chainId: string
|
|
282
|
+
contractAddress: string
|
|
283
|
+
tokenId: string
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export interface HiddenTokenProps {
|
|
287
|
+
chainId: string
|
|
288
|
+
contractAddress: string
|
|
289
|
+
tokenId?: string
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export interface WatchedWalletProps {
|
|
293
|
+
watchedAddress: string
|
|
294
|
+
nickname?: string
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export interface GetCapabilitiesRequest {}
|
|
298
|
+
|
|
299
|
+
export interface GetCapabilitiesResponse {
|
|
300
|
+
supportedMethods: Array<string>
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export interface GetAccessTokenRequest {
|
|
304
|
+
ethauthProof: string
|
|
305
|
+
chainId: string
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export interface GetAccessTokenResponse {
|
|
309
|
+
accessToken: string
|
|
310
|
+
refreshToken: string
|
|
311
|
+
expiresIn: number
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export interface GetIdentityTokenRequest {
|
|
315
|
+
claims: { [key: string]: any }
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export interface GetIdentityTokenResponse {
|
|
319
|
+
idToken: string
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export interface GetWalletPreferencesRequest {
|
|
323
|
+
wallet: string
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export interface GetWalletPreferencesResponse {
|
|
327
|
+
preferences: WalletPreferences
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export interface PutWalletPreferencesRequest {
|
|
331
|
+
wallet: string
|
|
332
|
+
preferences: WalletPreferences
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export interface PutWalletPreferencesResponse {}
|
|
336
|
+
|
|
337
|
+
export interface ListWalletSignersRequest {
|
|
338
|
+
wallet: string
|
|
339
|
+
pageSize: number
|
|
340
|
+
cursor: string
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export interface ListWalletSignersResponse {
|
|
344
|
+
signers: Array<WalletSigner>
|
|
345
|
+
nextCursor: string
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export interface PutWalletSignerRequest {
|
|
349
|
+
wallet: string
|
|
350
|
+
signer: WalletSignerProps
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export interface PutWalletSignerResponse {
|
|
354
|
+
signer: WalletSigner
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export interface DeleteWalletSignerRequest {
|
|
358
|
+
wallet: string
|
|
359
|
+
signer: string
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export interface DeleteWalletSignerResponse {}
|
|
363
|
+
|
|
364
|
+
export interface ListSessionsRequest {
|
|
365
|
+
wallet: string
|
|
366
|
+
pageSize: number
|
|
367
|
+
cursor: string
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export interface ListSessionsResponse {
|
|
371
|
+
sessions: Array<Session>
|
|
372
|
+
nextCursor: string
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export interface PutSessionRequest {
|
|
376
|
+
wallet: string
|
|
377
|
+
session: SessionProps
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export interface PutSessionResponse {
|
|
381
|
+
session: Session
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export interface DeleteSessionRequest {
|
|
385
|
+
wallet: string
|
|
386
|
+
session: string
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export interface DeleteSessionResponse {}
|
|
390
|
+
|
|
391
|
+
export interface ListContactsRequest {
|
|
392
|
+
wallet: string
|
|
393
|
+
pageSize: number
|
|
394
|
+
cursor: string
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export interface ListContactsResponse {
|
|
398
|
+
contacts: Array<Contact>
|
|
399
|
+
nextCursor: string
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export interface PutContactRequest {
|
|
403
|
+
wallet: string
|
|
404
|
+
contact: ContactProps
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export interface PutContactResponse {
|
|
408
|
+
contact: Contact
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export interface DeleteContactRequest {
|
|
412
|
+
wallet: string
|
|
413
|
+
contact: string
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export interface DeleteContactResponse {}
|
|
417
|
+
|
|
418
|
+
export interface ListWatchedWalletsRequest {
|
|
419
|
+
wallet: string
|
|
420
|
+
pageSize: number
|
|
421
|
+
cursor: string
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export interface ListWatchedWalletsResponse {
|
|
425
|
+
watchedWallets: Array<WatchedWallet>
|
|
426
|
+
nextCursor: string
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
export interface PutWatchedWalletRequest {
|
|
430
|
+
wallet: string
|
|
431
|
+
watchedWallet: WatchedWalletProps
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export interface PutWatchedWalletResponse {
|
|
435
|
+
watchedWallet: WatchedWallet
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export interface DeleteWatchedWalletRequest {
|
|
439
|
+
wallet: string
|
|
440
|
+
watchedWallet: string
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export interface DeleteWatchedWalletResponse {}
|
|
444
|
+
|
|
445
|
+
export interface ListDiscoverFavoritesRequest {
|
|
446
|
+
wallet: string
|
|
447
|
+
pageSize: number
|
|
448
|
+
cursor: string
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export interface ListDiscoverFavoritesResponse {
|
|
452
|
+
favorites: Array<DiscoverFavorite>
|
|
453
|
+
nextCursor: string
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
export interface PutDiscoverFavoriteRequest {
|
|
457
|
+
wallet: string
|
|
458
|
+
favorite: DiscoverProps
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export interface PutDiscoverFavoriteResponse {
|
|
462
|
+
favorite: DiscoverFavorite
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
export interface DeleteDiscoverFavoriteRequest {
|
|
466
|
+
wallet: string
|
|
467
|
+
id: number
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
export interface DeleteDiscoverFavoriteResponse {}
|
|
471
|
+
|
|
472
|
+
export interface ListDiscoverHistoryRequest {
|
|
473
|
+
wallet: string
|
|
474
|
+
pageSize: number
|
|
475
|
+
cursor: string
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
export interface ListDiscoverHistoryResponse {
|
|
479
|
+
history: Array<DiscoverHistory>
|
|
480
|
+
nextCursor: string
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
export interface PutDiscoverHistoryRequest {
|
|
484
|
+
wallet: string
|
|
485
|
+
history: DiscoverProps
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
export interface PutDiscoverHistoryResponse {
|
|
489
|
+
history: DiscoverHistory
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
export interface DeleteDiscoverHistoryRequest {
|
|
493
|
+
wallet: string
|
|
494
|
+
id: number
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export interface DeleteDiscoverHistoryResponse {}
|
|
498
|
+
|
|
499
|
+
export interface ListTokenFavoritesRequest {
|
|
500
|
+
wallet: string
|
|
501
|
+
pageSize: number
|
|
502
|
+
cursor: string
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
export interface ListTokenFavoritesResponse {
|
|
506
|
+
favorites: Array<TokenFavorite>
|
|
507
|
+
nextCursor: string
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
export interface PutTokenFavoriteRequest {
|
|
511
|
+
wallet: string
|
|
512
|
+
favorite: TokenFavoriteProps
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
export interface PutTokenFavoriteResponse {
|
|
516
|
+
favorite: TokenFavorite
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
export interface DeleteTokenFavoriteRequest {
|
|
520
|
+
wallet: string
|
|
521
|
+
id: number
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export interface DeleteTokenFavoriteResponse {}
|
|
525
|
+
|
|
526
|
+
export interface ListHiddenTokensRequest {
|
|
527
|
+
wallet: string
|
|
528
|
+
pageSize: number
|
|
529
|
+
cursor: string
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export interface ListHiddenTokensResponse {
|
|
533
|
+
hiddenTokens: Array<HiddenToken>
|
|
534
|
+
nextCursor: string
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
export interface PutHiddenTokenRequest {
|
|
538
|
+
wallet: string
|
|
539
|
+
token: HiddenTokenProps
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
export interface PutHiddenTokenResponse {
|
|
543
|
+
hiddenToken: HiddenToken
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
export interface DeleteHiddenTokenRequest {
|
|
547
|
+
wallet: string
|
|
548
|
+
id: number
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
export interface DeleteHiddenTokenResponse {}
|
|
552
|
+
|
|
553
|
+
//
|
|
554
|
+
// Client
|
|
555
|
+
//
|
|
556
|
+
|
|
557
|
+
export class UserData implements UserDataClient {
|
|
558
|
+
protected hostname: string
|
|
559
|
+
protected fetch: Fetch
|
|
560
|
+
protected path = '/rpc/UserData/'
|
|
561
|
+
|
|
562
|
+
constructor(hostname: string, fetch: Fetch) {
|
|
563
|
+
this.hostname = hostname.replace(/\/*$/, '')
|
|
564
|
+
this.fetch = (input: RequestInfo, init?: RequestInit) => fetch(input, init)
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
private url(name: string): string {
|
|
568
|
+
return this.hostname + this.path + name
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
queryKey = {
|
|
572
|
+
getCapabilities: () => ['UserData', 'getCapabilities'] as const,
|
|
573
|
+
getAccessToken: (req: GetAccessTokenRequest) => ['UserData', 'getAccessToken', req] as const,
|
|
574
|
+
getIdentityToken: (req: GetIdentityTokenRequest) => ['UserData', 'getIdentityToken', req] as const,
|
|
575
|
+
getWalletPreferences: (req: GetWalletPreferencesRequest) => ['UserData', 'getWalletPreferences', req] as const,
|
|
576
|
+
putWalletPreferences: (req: PutWalletPreferencesRequest) => ['UserData', 'putWalletPreferences', req] as const,
|
|
577
|
+
listWalletSigners: (req: ListWalletSignersRequest) => ['UserData', 'listWalletSigners', req] as const,
|
|
578
|
+
putWalletSigner: (req: PutWalletSignerRequest) => ['UserData', 'putWalletSigner', req] as const,
|
|
579
|
+
deleteWalletSigner: (req: DeleteWalletSignerRequest) => ['UserData', 'deleteWalletSigner', req] as const,
|
|
580
|
+
listSessions: (req: ListSessionsRequest) => ['UserData', 'listSessions', req] as const,
|
|
581
|
+
putSession: (req: PutSessionRequest) => ['UserData', 'putSession', req] as const,
|
|
582
|
+
deleteSession: (req: DeleteSessionRequest) => ['UserData', 'deleteSession', req] as const,
|
|
583
|
+
listContacts: (req: ListContactsRequest) => ['UserData', 'listContacts', req] as const,
|
|
584
|
+
putContact: (req: PutContactRequest) => ['UserData', 'putContact', req] as const,
|
|
585
|
+
deleteContact: (req: DeleteContactRequest) => ['UserData', 'deleteContact', req] as const,
|
|
586
|
+
listWatchedWallets: (req: ListWatchedWalletsRequest) => ['UserData', 'listWatchedWallets', req] as const,
|
|
587
|
+
putWatchedWallet: (req: PutWatchedWalletRequest) => ['UserData', 'putWatchedWallet', req] as const,
|
|
588
|
+
deleteWatchedWallet: (req: DeleteWatchedWalletRequest) => ['UserData', 'deleteWatchedWallet', req] as const,
|
|
589
|
+
listDiscoverFavorites: (req: ListDiscoverFavoritesRequest) => ['UserData', 'listDiscoverFavorites', req] as const,
|
|
590
|
+
putDiscoverFavorite: (req: PutDiscoverFavoriteRequest) => ['UserData', 'putDiscoverFavorite', req] as const,
|
|
591
|
+
deleteDiscoverFavorite: (req: DeleteDiscoverFavoriteRequest) =>
|
|
592
|
+
['UserData', 'deleteDiscoverFavorite', req] as const,
|
|
593
|
+
listDiscoverHistory: (req: ListDiscoverHistoryRequest) => ['UserData', 'listDiscoverHistory', req] as const,
|
|
594
|
+
putDiscoverHistory: (req: PutDiscoverHistoryRequest) => ['UserData', 'putDiscoverHistory', req] as const,
|
|
595
|
+
deleteDiscoverHistory: (req: DeleteDiscoverHistoryRequest) => ['UserData', 'deleteDiscoverHistory', req] as const,
|
|
596
|
+
listTokenFavorites: (req: ListTokenFavoritesRequest) => ['UserData', 'listTokenFavorites', req] as const,
|
|
597
|
+
putTokenFavorite: (req: PutTokenFavoriteRequest) => ['UserData', 'putTokenFavorite', req] as const,
|
|
598
|
+
deleteTokenFavorite: (req: DeleteTokenFavoriteRequest) => ['UserData', 'deleteTokenFavorite', req] as const,
|
|
599
|
+
listHiddenTokens: (req: ListHiddenTokensRequest) => ['UserData', 'listHiddenTokens', req] as const,
|
|
600
|
+
putHiddenToken: (req: PutHiddenTokenRequest) => ['UserData', 'putHiddenToken', req] as const,
|
|
601
|
+
deleteHiddenToken: (req: DeleteHiddenTokenRequest) => ['UserData', 'deleteHiddenToken', req] as const,
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
getCapabilities = (headers?: object, signal?: AbortSignal): Promise<GetCapabilitiesResponse> => {
|
|
605
|
+
return this.fetch(this.url('GetCapabilities'), createHttpRequest('{}', headers, signal)).then(
|
|
606
|
+
(res) => {
|
|
607
|
+
return buildResponse(res).then((_data) => {
|
|
608
|
+
return JsonDecode<GetCapabilitiesResponse>(_data, 'GetCapabilitiesResponse')
|
|
609
|
+
})
|
|
610
|
+
},
|
|
611
|
+
(error) => {
|
|
612
|
+
throw WebrpcRequestFailedError.new({
|
|
613
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
614
|
+
})
|
|
615
|
+
},
|
|
616
|
+
)
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
getAccessToken = (
|
|
620
|
+
req: GetAccessTokenRequest,
|
|
621
|
+
headers?: object,
|
|
622
|
+
signal?: AbortSignal,
|
|
623
|
+
): Promise<GetAccessTokenResponse> => {
|
|
624
|
+
return this.fetch(
|
|
625
|
+
this.url('GetAccessToken'),
|
|
626
|
+
createHttpRequest(JsonEncode(req, 'GetAccessTokenRequest'), headers, signal),
|
|
627
|
+
).then(
|
|
628
|
+
(res) => {
|
|
629
|
+
return buildResponse(res).then((_data) => {
|
|
630
|
+
return JsonDecode<GetAccessTokenResponse>(_data, 'GetAccessTokenResponse')
|
|
631
|
+
})
|
|
632
|
+
},
|
|
633
|
+
(error) => {
|
|
634
|
+
throw WebrpcRequestFailedError.new({
|
|
635
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
636
|
+
})
|
|
637
|
+
},
|
|
638
|
+
)
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
getIdentityToken = (
|
|
642
|
+
req: GetIdentityTokenRequest,
|
|
643
|
+
headers?: object,
|
|
644
|
+
signal?: AbortSignal,
|
|
645
|
+
): Promise<GetIdentityTokenResponse> => {
|
|
646
|
+
return this.fetch(
|
|
647
|
+
this.url('GetIdentityToken'),
|
|
648
|
+
createHttpRequest(JsonEncode(req, 'GetIdentityTokenRequest'), headers, signal),
|
|
649
|
+
).then(
|
|
650
|
+
(res) => {
|
|
651
|
+
return buildResponse(res).then((_data) => {
|
|
652
|
+
return JsonDecode<GetIdentityTokenResponse>(_data, 'GetIdentityTokenResponse')
|
|
653
|
+
})
|
|
654
|
+
},
|
|
655
|
+
(error) => {
|
|
656
|
+
throw WebrpcRequestFailedError.new({
|
|
657
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
658
|
+
})
|
|
659
|
+
},
|
|
660
|
+
)
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
getWalletPreferences = (
|
|
664
|
+
req: GetWalletPreferencesRequest,
|
|
665
|
+
headers?: object,
|
|
666
|
+
signal?: AbortSignal,
|
|
667
|
+
): Promise<GetWalletPreferencesResponse> => {
|
|
668
|
+
return this.fetch(
|
|
669
|
+
this.url('GetWalletPreferences'),
|
|
670
|
+
createHttpRequest(JsonEncode(req, 'GetWalletPreferencesRequest'), headers, signal),
|
|
671
|
+
).then(
|
|
672
|
+
(res) => {
|
|
673
|
+
return buildResponse(res).then((_data) => {
|
|
674
|
+
return JsonDecode<GetWalletPreferencesResponse>(_data, 'GetWalletPreferencesResponse')
|
|
675
|
+
})
|
|
676
|
+
},
|
|
677
|
+
(error) => {
|
|
678
|
+
throw WebrpcRequestFailedError.new({
|
|
679
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
680
|
+
})
|
|
681
|
+
},
|
|
682
|
+
)
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
putWalletPreferences = (
|
|
686
|
+
req: PutWalletPreferencesRequest,
|
|
687
|
+
headers?: object,
|
|
688
|
+
signal?: AbortSignal,
|
|
689
|
+
): Promise<PutWalletPreferencesResponse> => {
|
|
690
|
+
return this.fetch(
|
|
691
|
+
this.url('PutWalletPreferences'),
|
|
692
|
+
createHttpRequest(JsonEncode(req, 'PutWalletPreferencesRequest'), headers, signal),
|
|
693
|
+
).then(
|
|
694
|
+
(res) => {
|
|
695
|
+
return buildResponse(res).then((_data) => {
|
|
696
|
+
return JsonDecode<PutWalletPreferencesResponse>(_data, 'PutWalletPreferencesResponse')
|
|
697
|
+
})
|
|
698
|
+
},
|
|
699
|
+
(error) => {
|
|
700
|
+
throw WebrpcRequestFailedError.new({
|
|
701
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
702
|
+
})
|
|
703
|
+
},
|
|
704
|
+
)
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
listWalletSigners = (
|
|
708
|
+
req: ListWalletSignersRequest,
|
|
709
|
+
headers?: object,
|
|
710
|
+
signal?: AbortSignal,
|
|
711
|
+
): Promise<ListWalletSignersResponse> => {
|
|
712
|
+
return this.fetch(
|
|
713
|
+
this.url('ListWalletSigners'),
|
|
714
|
+
createHttpRequest(JsonEncode(req, 'ListWalletSignersRequest'), headers, signal),
|
|
715
|
+
).then(
|
|
716
|
+
(res) => {
|
|
717
|
+
return buildResponse(res).then((_data) => {
|
|
718
|
+
return JsonDecode<ListWalletSignersResponse>(_data, 'ListWalletSignersResponse')
|
|
719
|
+
})
|
|
720
|
+
},
|
|
721
|
+
(error) => {
|
|
722
|
+
throw WebrpcRequestFailedError.new({
|
|
723
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
724
|
+
})
|
|
725
|
+
},
|
|
726
|
+
)
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
putWalletSigner = (
|
|
730
|
+
req: PutWalletSignerRequest,
|
|
731
|
+
headers?: object,
|
|
732
|
+
signal?: AbortSignal,
|
|
733
|
+
): Promise<PutWalletSignerResponse> => {
|
|
734
|
+
return this.fetch(
|
|
735
|
+
this.url('PutWalletSigner'),
|
|
736
|
+
createHttpRequest(JsonEncode(req, 'PutWalletSignerRequest'), headers, signal),
|
|
737
|
+
).then(
|
|
738
|
+
(res) => {
|
|
739
|
+
return buildResponse(res).then((_data) => {
|
|
740
|
+
return JsonDecode<PutWalletSignerResponse>(_data, 'PutWalletSignerResponse')
|
|
741
|
+
})
|
|
742
|
+
},
|
|
743
|
+
(error) => {
|
|
744
|
+
throw WebrpcRequestFailedError.new({
|
|
745
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
746
|
+
})
|
|
747
|
+
},
|
|
748
|
+
)
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
deleteWalletSigner = (
|
|
752
|
+
req: DeleteWalletSignerRequest,
|
|
753
|
+
headers?: object,
|
|
754
|
+
signal?: AbortSignal,
|
|
755
|
+
): Promise<DeleteWalletSignerResponse> => {
|
|
756
|
+
return this.fetch(
|
|
757
|
+
this.url('DeleteWalletSigner'),
|
|
758
|
+
createHttpRequest(JsonEncode(req, 'DeleteWalletSignerRequest'), headers, signal),
|
|
759
|
+
).then(
|
|
760
|
+
(res) => {
|
|
761
|
+
return buildResponse(res).then((_data) => {
|
|
762
|
+
return JsonDecode<DeleteWalletSignerResponse>(_data, 'DeleteWalletSignerResponse')
|
|
763
|
+
})
|
|
764
|
+
},
|
|
765
|
+
(error) => {
|
|
766
|
+
throw WebrpcRequestFailedError.new({
|
|
767
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
768
|
+
})
|
|
769
|
+
},
|
|
770
|
+
)
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
listSessions = (req: ListSessionsRequest, headers?: object, signal?: AbortSignal): Promise<ListSessionsResponse> => {
|
|
774
|
+
return this.fetch(
|
|
775
|
+
this.url('ListSessions'),
|
|
776
|
+
createHttpRequest(JsonEncode(req, 'ListSessionsRequest'), headers, signal),
|
|
777
|
+
).then(
|
|
778
|
+
(res) => {
|
|
779
|
+
return buildResponse(res).then((_data) => {
|
|
780
|
+
return JsonDecode<ListSessionsResponse>(_data, 'ListSessionsResponse')
|
|
781
|
+
})
|
|
782
|
+
},
|
|
783
|
+
(error) => {
|
|
784
|
+
throw WebrpcRequestFailedError.new({
|
|
785
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
786
|
+
})
|
|
787
|
+
},
|
|
788
|
+
)
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
putSession = (req: PutSessionRequest, headers?: object, signal?: AbortSignal): Promise<PutSessionResponse> => {
|
|
792
|
+
return this.fetch(
|
|
793
|
+
this.url('PutSession'),
|
|
794
|
+
createHttpRequest(JsonEncode(req, 'PutSessionRequest'), headers, signal),
|
|
795
|
+
).then(
|
|
796
|
+
(res) => {
|
|
797
|
+
return buildResponse(res).then((_data) => {
|
|
798
|
+
return JsonDecode<PutSessionResponse>(_data, 'PutSessionResponse')
|
|
799
|
+
})
|
|
800
|
+
},
|
|
801
|
+
(error) => {
|
|
802
|
+
throw WebrpcRequestFailedError.new({
|
|
803
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
804
|
+
})
|
|
805
|
+
},
|
|
806
|
+
)
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
deleteSession = (
|
|
810
|
+
req: DeleteSessionRequest,
|
|
811
|
+
headers?: object,
|
|
812
|
+
signal?: AbortSignal,
|
|
813
|
+
): Promise<DeleteSessionResponse> => {
|
|
814
|
+
return this.fetch(
|
|
815
|
+
this.url('DeleteSession'),
|
|
816
|
+
createHttpRequest(JsonEncode(req, 'DeleteSessionRequest'), headers, signal),
|
|
817
|
+
).then(
|
|
818
|
+
(res) => {
|
|
819
|
+
return buildResponse(res).then((_data) => {
|
|
820
|
+
return JsonDecode<DeleteSessionResponse>(_data, 'DeleteSessionResponse')
|
|
821
|
+
})
|
|
822
|
+
},
|
|
823
|
+
(error) => {
|
|
824
|
+
throw WebrpcRequestFailedError.new({
|
|
825
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
826
|
+
})
|
|
827
|
+
},
|
|
828
|
+
)
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
listContacts = (req: ListContactsRequest, headers?: object, signal?: AbortSignal): Promise<ListContactsResponse> => {
|
|
832
|
+
return this.fetch(
|
|
833
|
+
this.url('ListContacts'),
|
|
834
|
+
createHttpRequest(JsonEncode(req, 'ListContactsRequest'), headers, signal),
|
|
835
|
+
).then(
|
|
836
|
+
(res) => {
|
|
837
|
+
return buildResponse(res).then((_data) => {
|
|
838
|
+
return JsonDecode<ListContactsResponse>(_data, 'ListContactsResponse')
|
|
839
|
+
})
|
|
840
|
+
},
|
|
841
|
+
(error) => {
|
|
842
|
+
throw WebrpcRequestFailedError.new({
|
|
843
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
844
|
+
})
|
|
845
|
+
},
|
|
846
|
+
)
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
putContact = (req: PutContactRequest, headers?: object, signal?: AbortSignal): Promise<PutContactResponse> => {
|
|
850
|
+
return this.fetch(
|
|
851
|
+
this.url('PutContact'),
|
|
852
|
+
createHttpRequest(JsonEncode(req, 'PutContactRequest'), headers, signal),
|
|
853
|
+
).then(
|
|
854
|
+
(res) => {
|
|
855
|
+
return buildResponse(res).then((_data) => {
|
|
856
|
+
return JsonDecode<PutContactResponse>(_data, 'PutContactResponse')
|
|
857
|
+
})
|
|
858
|
+
},
|
|
859
|
+
(error) => {
|
|
860
|
+
throw WebrpcRequestFailedError.new({
|
|
861
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
862
|
+
})
|
|
863
|
+
},
|
|
864
|
+
)
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
deleteContact = (
|
|
868
|
+
req: DeleteContactRequest,
|
|
869
|
+
headers?: object,
|
|
870
|
+
signal?: AbortSignal,
|
|
871
|
+
): Promise<DeleteContactResponse> => {
|
|
872
|
+
return this.fetch(
|
|
873
|
+
this.url('DeleteContact'),
|
|
874
|
+
createHttpRequest(JsonEncode(req, 'DeleteContactRequest'), headers, signal),
|
|
875
|
+
).then(
|
|
876
|
+
(res) => {
|
|
877
|
+
return buildResponse(res).then((_data) => {
|
|
878
|
+
return JsonDecode<DeleteContactResponse>(_data, 'DeleteContactResponse')
|
|
879
|
+
})
|
|
880
|
+
},
|
|
881
|
+
(error) => {
|
|
882
|
+
throw WebrpcRequestFailedError.new({
|
|
883
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
884
|
+
})
|
|
885
|
+
},
|
|
886
|
+
)
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
listWatchedWallets = (
|
|
890
|
+
req: ListWatchedWalletsRequest,
|
|
891
|
+
headers?: object,
|
|
892
|
+
signal?: AbortSignal,
|
|
893
|
+
): Promise<ListWatchedWalletsResponse> => {
|
|
894
|
+
return this.fetch(
|
|
895
|
+
this.url('ListWatchedWallets'),
|
|
896
|
+
createHttpRequest(JsonEncode(req, 'ListWatchedWalletsRequest'), headers, signal),
|
|
897
|
+
).then(
|
|
898
|
+
(res) => {
|
|
899
|
+
return buildResponse(res).then((_data) => {
|
|
900
|
+
return JsonDecode<ListWatchedWalletsResponse>(_data, 'ListWatchedWalletsResponse')
|
|
901
|
+
})
|
|
902
|
+
},
|
|
903
|
+
(error) => {
|
|
904
|
+
throw WebrpcRequestFailedError.new({
|
|
905
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
906
|
+
})
|
|
907
|
+
},
|
|
908
|
+
)
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
putWatchedWallet = (
|
|
912
|
+
req: PutWatchedWalletRequest,
|
|
913
|
+
headers?: object,
|
|
914
|
+
signal?: AbortSignal,
|
|
915
|
+
): Promise<PutWatchedWalletResponse> => {
|
|
916
|
+
return this.fetch(
|
|
917
|
+
this.url('PutWatchedWallet'),
|
|
918
|
+
createHttpRequest(JsonEncode(req, 'PutWatchedWalletRequest'), headers, signal),
|
|
919
|
+
).then(
|
|
920
|
+
(res) => {
|
|
921
|
+
return buildResponse(res).then((_data) => {
|
|
922
|
+
return JsonDecode<PutWatchedWalletResponse>(_data, 'PutWatchedWalletResponse')
|
|
923
|
+
})
|
|
924
|
+
},
|
|
925
|
+
(error) => {
|
|
926
|
+
throw WebrpcRequestFailedError.new({
|
|
927
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
928
|
+
})
|
|
929
|
+
},
|
|
930
|
+
)
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
deleteWatchedWallet = (
|
|
934
|
+
req: DeleteWatchedWalletRequest,
|
|
935
|
+
headers?: object,
|
|
936
|
+
signal?: AbortSignal,
|
|
937
|
+
): Promise<DeleteWatchedWalletResponse> => {
|
|
938
|
+
return this.fetch(
|
|
939
|
+
this.url('DeleteWatchedWallet'),
|
|
940
|
+
createHttpRequest(JsonEncode(req, 'DeleteWatchedWalletRequest'), headers, signal),
|
|
941
|
+
).then(
|
|
942
|
+
(res) => {
|
|
943
|
+
return buildResponse(res).then((_data) => {
|
|
944
|
+
return JsonDecode<DeleteWatchedWalletResponse>(_data, 'DeleteWatchedWalletResponse')
|
|
945
|
+
})
|
|
946
|
+
},
|
|
947
|
+
(error) => {
|
|
948
|
+
throw WebrpcRequestFailedError.new({
|
|
949
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
950
|
+
})
|
|
951
|
+
},
|
|
952
|
+
)
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
listDiscoverFavorites = (
|
|
956
|
+
req: ListDiscoverFavoritesRequest,
|
|
957
|
+
headers?: object,
|
|
958
|
+
signal?: AbortSignal,
|
|
959
|
+
): Promise<ListDiscoverFavoritesResponse> => {
|
|
960
|
+
return this.fetch(
|
|
961
|
+
this.url('ListDiscoverFavorites'),
|
|
962
|
+
createHttpRequest(JsonEncode(req, 'ListDiscoverFavoritesRequest'), headers, signal),
|
|
963
|
+
).then(
|
|
964
|
+
(res) => {
|
|
965
|
+
return buildResponse(res).then((_data) => {
|
|
966
|
+
return JsonDecode<ListDiscoverFavoritesResponse>(_data, 'ListDiscoverFavoritesResponse')
|
|
967
|
+
})
|
|
968
|
+
},
|
|
969
|
+
(error) => {
|
|
970
|
+
throw WebrpcRequestFailedError.new({
|
|
971
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
972
|
+
})
|
|
973
|
+
},
|
|
974
|
+
)
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
putDiscoverFavorite = (
|
|
978
|
+
req: PutDiscoverFavoriteRequest,
|
|
979
|
+
headers?: object,
|
|
980
|
+
signal?: AbortSignal,
|
|
981
|
+
): Promise<PutDiscoverFavoriteResponse> => {
|
|
982
|
+
return this.fetch(
|
|
983
|
+
this.url('PutDiscoverFavorite'),
|
|
984
|
+
createHttpRequest(JsonEncode(req, 'PutDiscoverFavoriteRequest'), headers, signal),
|
|
985
|
+
).then(
|
|
986
|
+
(res) => {
|
|
987
|
+
return buildResponse(res).then((_data) => {
|
|
988
|
+
return JsonDecode<PutDiscoverFavoriteResponse>(_data, 'PutDiscoverFavoriteResponse')
|
|
989
|
+
})
|
|
990
|
+
},
|
|
991
|
+
(error) => {
|
|
992
|
+
throw WebrpcRequestFailedError.new({
|
|
993
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
994
|
+
})
|
|
995
|
+
},
|
|
996
|
+
)
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
deleteDiscoverFavorite = (
|
|
1000
|
+
req: DeleteDiscoverFavoriteRequest,
|
|
1001
|
+
headers?: object,
|
|
1002
|
+
signal?: AbortSignal,
|
|
1003
|
+
): Promise<DeleteDiscoverFavoriteResponse> => {
|
|
1004
|
+
return this.fetch(
|
|
1005
|
+
this.url('DeleteDiscoverFavorite'),
|
|
1006
|
+
createHttpRequest(JsonEncode(req, 'DeleteDiscoverFavoriteRequest'), headers, signal),
|
|
1007
|
+
).then(
|
|
1008
|
+
(res) => {
|
|
1009
|
+
return buildResponse(res).then((_data) => {
|
|
1010
|
+
return JsonDecode<DeleteDiscoverFavoriteResponse>(_data, 'DeleteDiscoverFavoriteResponse')
|
|
1011
|
+
})
|
|
1012
|
+
},
|
|
1013
|
+
(error) => {
|
|
1014
|
+
throw WebrpcRequestFailedError.new({
|
|
1015
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
1016
|
+
})
|
|
1017
|
+
},
|
|
1018
|
+
)
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
listDiscoverHistory = (
|
|
1022
|
+
req: ListDiscoverHistoryRequest,
|
|
1023
|
+
headers?: object,
|
|
1024
|
+
signal?: AbortSignal,
|
|
1025
|
+
): Promise<ListDiscoverHistoryResponse> => {
|
|
1026
|
+
return this.fetch(
|
|
1027
|
+
this.url('ListDiscoverHistory'),
|
|
1028
|
+
createHttpRequest(JsonEncode(req, 'ListDiscoverHistoryRequest'), headers, signal),
|
|
1029
|
+
).then(
|
|
1030
|
+
(res) => {
|
|
1031
|
+
return buildResponse(res).then((_data) => {
|
|
1032
|
+
return JsonDecode<ListDiscoverHistoryResponse>(_data, 'ListDiscoverHistoryResponse')
|
|
1033
|
+
})
|
|
1034
|
+
},
|
|
1035
|
+
(error) => {
|
|
1036
|
+
throw WebrpcRequestFailedError.new({
|
|
1037
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
1038
|
+
})
|
|
1039
|
+
},
|
|
1040
|
+
)
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
putDiscoverHistory = (
|
|
1044
|
+
req: PutDiscoverHistoryRequest,
|
|
1045
|
+
headers?: object,
|
|
1046
|
+
signal?: AbortSignal,
|
|
1047
|
+
): Promise<PutDiscoverHistoryResponse> => {
|
|
1048
|
+
return this.fetch(
|
|
1049
|
+
this.url('PutDiscoverHistory'),
|
|
1050
|
+
createHttpRequest(JsonEncode(req, 'PutDiscoverHistoryRequest'), headers, signal),
|
|
1051
|
+
).then(
|
|
1052
|
+
(res) => {
|
|
1053
|
+
return buildResponse(res).then((_data) => {
|
|
1054
|
+
return JsonDecode<PutDiscoverHistoryResponse>(_data, 'PutDiscoverHistoryResponse')
|
|
1055
|
+
})
|
|
1056
|
+
},
|
|
1057
|
+
(error) => {
|
|
1058
|
+
throw WebrpcRequestFailedError.new({
|
|
1059
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
1060
|
+
})
|
|
1061
|
+
},
|
|
1062
|
+
)
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
deleteDiscoverHistory = (
|
|
1066
|
+
req: DeleteDiscoverHistoryRequest,
|
|
1067
|
+
headers?: object,
|
|
1068
|
+
signal?: AbortSignal,
|
|
1069
|
+
): Promise<DeleteDiscoverHistoryResponse> => {
|
|
1070
|
+
return this.fetch(
|
|
1071
|
+
this.url('DeleteDiscoverHistory'),
|
|
1072
|
+
createHttpRequest(JsonEncode(req, 'DeleteDiscoverHistoryRequest'), headers, signal),
|
|
1073
|
+
).then(
|
|
1074
|
+
(res) => {
|
|
1075
|
+
return buildResponse(res).then((_data) => {
|
|
1076
|
+
return JsonDecode<DeleteDiscoverHistoryResponse>(_data, 'DeleteDiscoverHistoryResponse')
|
|
1077
|
+
})
|
|
1078
|
+
},
|
|
1079
|
+
(error) => {
|
|
1080
|
+
throw WebrpcRequestFailedError.new({
|
|
1081
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
1082
|
+
})
|
|
1083
|
+
},
|
|
1084
|
+
)
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
listTokenFavorites = (
|
|
1088
|
+
req: ListTokenFavoritesRequest,
|
|
1089
|
+
headers?: object,
|
|
1090
|
+
signal?: AbortSignal,
|
|
1091
|
+
): Promise<ListTokenFavoritesResponse> => {
|
|
1092
|
+
return this.fetch(
|
|
1093
|
+
this.url('ListTokenFavorites'),
|
|
1094
|
+
createHttpRequest(JsonEncode(req, 'ListTokenFavoritesRequest'), headers, signal),
|
|
1095
|
+
).then(
|
|
1096
|
+
(res) => {
|
|
1097
|
+
return buildResponse(res).then((_data) => {
|
|
1098
|
+
return JsonDecode<ListTokenFavoritesResponse>(_data, 'ListTokenFavoritesResponse')
|
|
1099
|
+
})
|
|
1100
|
+
},
|
|
1101
|
+
(error) => {
|
|
1102
|
+
throw WebrpcRequestFailedError.new({
|
|
1103
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
1104
|
+
})
|
|
1105
|
+
},
|
|
1106
|
+
)
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
putTokenFavorite = (
|
|
1110
|
+
req: PutTokenFavoriteRequest,
|
|
1111
|
+
headers?: object,
|
|
1112
|
+
signal?: AbortSignal,
|
|
1113
|
+
): Promise<PutTokenFavoriteResponse> => {
|
|
1114
|
+
return this.fetch(
|
|
1115
|
+
this.url('PutTokenFavorite'),
|
|
1116
|
+
createHttpRequest(JsonEncode(req, 'PutTokenFavoriteRequest'), headers, signal),
|
|
1117
|
+
).then(
|
|
1118
|
+
(res) => {
|
|
1119
|
+
return buildResponse(res).then((_data) => {
|
|
1120
|
+
return JsonDecode<PutTokenFavoriteResponse>(_data, 'PutTokenFavoriteResponse')
|
|
1121
|
+
})
|
|
1122
|
+
},
|
|
1123
|
+
(error) => {
|
|
1124
|
+
throw WebrpcRequestFailedError.new({
|
|
1125
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
1126
|
+
})
|
|
1127
|
+
},
|
|
1128
|
+
)
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
deleteTokenFavorite = (
|
|
1132
|
+
req: DeleteTokenFavoriteRequest,
|
|
1133
|
+
headers?: object,
|
|
1134
|
+
signal?: AbortSignal,
|
|
1135
|
+
): Promise<DeleteTokenFavoriteResponse> => {
|
|
1136
|
+
return this.fetch(
|
|
1137
|
+
this.url('DeleteTokenFavorite'),
|
|
1138
|
+
createHttpRequest(JsonEncode(req, 'DeleteTokenFavoriteRequest'), headers, signal),
|
|
1139
|
+
).then(
|
|
1140
|
+
(res) => {
|
|
1141
|
+
return buildResponse(res).then((_data) => {
|
|
1142
|
+
return JsonDecode<DeleteTokenFavoriteResponse>(_data, 'DeleteTokenFavoriteResponse')
|
|
1143
|
+
})
|
|
1144
|
+
},
|
|
1145
|
+
(error) => {
|
|
1146
|
+
throw WebrpcRequestFailedError.new({
|
|
1147
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
1148
|
+
})
|
|
1149
|
+
},
|
|
1150
|
+
)
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
listHiddenTokens = (
|
|
1154
|
+
req: ListHiddenTokensRequest,
|
|
1155
|
+
headers?: object,
|
|
1156
|
+
signal?: AbortSignal,
|
|
1157
|
+
): Promise<ListHiddenTokensResponse> => {
|
|
1158
|
+
return this.fetch(
|
|
1159
|
+
this.url('ListHiddenTokens'),
|
|
1160
|
+
createHttpRequest(JsonEncode(req, 'ListHiddenTokensRequest'), headers, signal),
|
|
1161
|
+
).then(
|
|
1162
|
+
(res) => {
|
|
1163
|
+
return buildResponse(res).then((_data) => {
|
|
1164
|
+
return JsonDecode<ListHiddenTokensResponse>(_data, 'ListHiddenTokensResponse')
|
|
1165
|
+
})
|
|
1166
|
+
},
|
|
1167
|
+
(error) => {
|
|
1168
|
+
throw WebrpcRequestFailedError.new({
|
|
1169
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
1170
|
+
})
|
|
1171
|
+
},
|
|
1172
|
+
)
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
putHiddenToken = (
|
|
1176
|
+
req: PutHiddenTokenRequest,
|
|
1177
|
+
headers?: object,
|
|
1178
|
+
signal?: AbortSignal,
|
|
1179
|
+
): Promise<PutHiddenTokenResponse> => {
|
|
1180
|
+
return this.fetch(
|
|
1181
|
+
this.url('PutHiddenToken'),
|
|
1182
|
+
createHttpRequest(JsonEncode(req, 'PutHiddenTokenRequest'), headers, signal),
|
|
1183
|
+
).then(
|
|
1184
|
+
(res) => {
|
|
1185
|
+
return buildResponse(res).then((_data) => {
|
|
1186
|
+
return JsonDecode<PutHiddenTokenResponse>(_data, 'PutHiddenTokenResponse')
|
|
1187
|
+
})
|
|
1188
|
+
},
|
|
1189
|
+
(error) => {
|
|
1190
|
+
throw WebrpcRequestFailedError.new({
|
|
1191
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
1192
|
+
})
|
|
1193
|
+
},
|
|
1194
|
+
)
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
deleteHiddenToken = (
|
|
1198
|
+
req: DeleteHiddenTokenRequest,
|
|
1199
|
+
headers?: object,
|
|
1200
|
+
signal?: AbortSignal,
|
|
1201
|
+
): Promise<DeleteHiddenTokenResponse> => {
|
|
1202
|
+
return this.fetch(
|
|
1203
|
+
this.url('DeleteHiddenToken'),
|
|
1204
|
+
createHttpRequest(JsonEncode(req, 'DeleteHiddenTokenRequest'), headers, signal),
|
|
1205
|
+
).then(
|
|
1206
|
+
(res) => {
|
|
1207
|
+
return buildResponse(res).then((_data) => {
|
|
1208
|
+
return JsonDecode<DeleteHiddenTokenResponse>(_data, 'DeleteHiddenTokenResponse')
|
|
1209
|
+
})
|
|
1210
|
+
},
|
|
1211
|
+
(error) => {
|
|
1212
|
+
throw WebrpcRequestFailedError.new({
|
|
1213
|
+
cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
|
|
1214
|
+
})
|
|
1215
|
+
},
|
|
1216
|
+
)
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
const createHttpRequest = (body: string = '{}', headers: object = {}, signal: AbortSignal | null = null): object => {
|
|
1221
|
+
const reqHeaders: { [key: string]: string } = { ...headers, 'Content-Type': 'application/json' }
|
|
1222
|
+
return { method: 'POST', headers: reqHeaders, body, signal }
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
const buildResponse = (res: Response): Promise<any> => {
|
|
1226
|
+
return res.text().then((text) => {
|
|
1227
|
+
let data
|
|
1228
|
+
try {
|
|
1229
|
+
data = JSON.parse(text)
|
|
1230
|
+
} catch (error) {
|
|
1231
|
+
throw WebrpcBadResponseError.new({
|
|
1232
|
+
status: res.status,
|
|
1233
|
+
cause: `JSON.parse(): ${error instanceof Error ? error.message : String(error)}: response text: ${text}`,
|
|
1234
|
+
})
|
|
1235
|
+
}
|
|
1236
|
+
if (!res.ok) {
|
|
1237
|
+
const code: number = typeof data.code === 'number' ? data.code : 0
|
|
1238
|
+
throw (webrpcErrorByCode[code] || WebrpcError).new(data)
|
|
1239
|
+
}
|
|
1240
|
+
return data
|
|
1241
|
+
})
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>
|
|
1245
|
+
|
|
1246
|
+
export const JsonEncode = <T = any>(obj: T, _typ: string = ''): string => {
|
|
1247
|
+
return JSON.stringify(obj)
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
export const JsonDecode = <T = any>(data: string | any, _typ: string = ''): T => {
|
|
1251
|
+
let parsed: any = data
|
|
1252
|
+
if (typeof data === 'string') {
|
|
1253
|
+
try {
|
|
1254
|
+
parsed = JSON.parse(data)
|
|
1255
|
+
} catch (err) {
|
|
1256
|
+
throw WebrpcBadResponseError.new({ cause: `JsonDecode: JSON.parse failed: ${(err as Error).message}` })
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
return parsed as T
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
//
|
|
1263
|
+
// Errors
|
|
1264
|
+
//
|
|
1265
|
+
|
|
1266
|
+
type WebrpcErrorParams = { name?: string; code?: number; message?: string; status?: number; cause?: string }
|
|
1267
|
+
|
|
1268
|
+
export class WebrpcError extends Error {
|
|
1269
|
+
code: number
|
|
1270
|
+
status: number
|
|
1271
|
+
|
|
1272
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1273
|
+
super(error.message)
|
|
1274
|
+
this.name = error.name || 'WebrpcEndpointError'
|
|
1275
|
+
this.code = typeof error.code === 'number' ? error.code : 0
|
|
1276
|
+
this.message = error.message || `endpoint error`
|
|
1277
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1278
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1279
|
+
Object.setPrototypeOf(this, WebrpcError.prototype)
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
static new(payload: any): WebrpcError {
|
|
1283
|
+
return new this({ message: payload.message, code: payload.code, status: payload.status, cause: payload.cause })
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
export class WebrpcEndpointError extends WebrpcError {
|
|
1288
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1289
|
+
super(error)
|
|
1290
|
+
this.name = error.name || 'WebrpcEndpoint'
|
|
1291
|
+
this.code = typeof error.code === 'number' ? error.code : 0
|
|
1292
|
+
this.message = error.message || `endpoint error`
|
|
1293
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1294
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1295
|
+
Object.setPrototypeOf(this, WebrpcEndpointError.prototype)
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
export class WebrpcRequestFailedError extends WebrpcError {
|
|
1300
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1301
|
+
super(error)
|
|
1302
|
+
this.name = error.name || 'WebrpcRequestFailed'
|
|
1303
|
+
this.code = typeof error.code === 'number' ? error.code : -1
|
|
1304
|
+
this.message = error.message || `request failed`
|
|
1305
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1306
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1307
|
+
Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype)
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
export class WebrpcBadRouteError extends WebrpcError {
|
|
1312
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1313
|
+
super(error)
|
|
1314
|
+
this.name = error.name || 'WebrpcBadRoute'
|
|
1315
|
+
this.code = typeof error.code === 'number' ? error.code : -2
|
|
1316
|
+
this.message = error.message || `bad route`
|
|
1317
|
+
this.status = typeof error.status === 'number' ? error.status : 404
|
|
1318
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1319
|
+
Object.setPrototypeOf(this, WebrpcBadRouteError.prototype)
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
export class WebrpcBadMethodError extends WebrpcError {
|
|
1324
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1325
|
+
super(error)
|
|
1326
|
+
this.name = error.name || 'WebrpcBadMethod'
|
|
1327
|
+
this.code = typeof error.code === 'number' ? error.code : -3
|
|
1328
|
+
this.message = error.message || `bad method`
|
|
1329
|
+
this.status = typeof error.status === 'number' ? error.status : 405
|
|
1330
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1331
|
+
Object.setPrototypeOf(this, WebrpcBadMethodError.prototype)
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
export class WebrpcBadRequestError extends WebrpcError {
|
|
1336
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1337
|
+
super(error)
|
|
1338
|
+
this.name = error.name || 'WebrpcBadRequest'
|
|
1339
|
+
this.code = typeof error.code === 'number' ? error.code : -4
|
|
1340
|
+
this.message = error.message || `bad request`
|
|
1341
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1342
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1343
|
+
Object.setPrototypeOf(this, WebrpcBadRequestError.prototype)
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
export class WebrpcBadResponseError extends WebrpcError {
|
|
1348
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1349
|
+
super(error)
|
|
1350
|
+
this.name = error.name || 'WebrpcBadResponse'
|
|
1351
|
+
this.code = typeof error.code === 'number' ? error.code : -5
|
|
1352
|
+
this.message = error.message || `bad response`
|
|
1353
|
+
this.status = typeof error.status === 'number' ? error.status : 500
|
|
1354
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1355
|
+
Object.setPrototypeOf(this, WebrpcBadResponseError.prototype)
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
export class WebrpcServerPanicError extends WebrpcError {
|
|
1360
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1361
|
+
super(error)
|
|
1362
|
+
this.name = error.name || 'WebrpcServerPanic'
|
|
1363
|
+
this.code = typeof error.code === 'number' ? error.code : -6
|
|
1364
|
+
this.message = error.message || `server panic`
|
|
1365
|
+
this.status = typeof error.status === 'number' ? error.status : 500
|
|
1366
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1367
|
+
Object.setPrototypeOf(this, WebrpcServerPanicError.prototype)
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
export class WebrpcInternalErrorError extends WebrpcError {
|
|
1372
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1373
|
+
super(error)
|
|
1374
|
+
this.name = error.name || 'WebrpcInternalError'
|
|
1375
|
+
this.code = typeof error.code === 'number' ? error.code : -7
|
|
1376
|
+
this.message = error.message || `internal error`
|
|
1377
|
+
this.status = typeof error.status === 'number' ? error.status : 500
|
|
1378
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1379
|
+
Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype)
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
export class WebrpcClientAbortedError extends WebrpcError {
|
|
1384
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1385
|
+
super(error)
|
|
1386
|
+
this.name = error.name || 'WebrpcClientAborted'
|
|
1387
|
+
this.code = typeof error.code === 'number' ? error.code : -8
|
|
1388
|
+
this.message = error.message || `request aborted by client`
|
|
1389
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1390
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1391
|
+
Object.setPrototypeOf(this, WebrpcClientAbortedError.prototype)
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
export class WebrpcStreamLostError extends WebrpcError {
|
|
1396
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1397
|
+
super(error)
|
|
1398
|
+
this.name = error.name || 'WebrpcStreamLost'
|
|
1399
|
+
this.code = typeof error.code === 'number' ? error.code : -9
|
|
1400
|
+
this.message = error.message || `stream lost`
|
|
1401
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1402
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1403
|
+
Object.setPrototypeOf(this, WebrpcStreamLostError.prototype)
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
export class WebrpcStreamFinishedError extends WebrpcError {
|
|
1408
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1409
|
+
super(error)
|
|
1410
|
+
this.name = error.name || 'WebrpcStreamFinished'
|
|
1411
|
+
this.code = typeof error.code === 'number' ? error.code : -10
|
|
1412
|
+
this.message = error.message || `stream finished`
|
|
1413
|
+
this.status = typeof error.status === 'number' ? error.status : 200
|
|
1414
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1415
|
+
Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype)
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
//
|
|
1420
|
+
// Schema errors
|
|
1421
|
+
//
|
|
1422
|
+
|
|
1423
|
+
export class UnauthorizedError extends WebrpcError {
|
|
1424
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1425
|
+
super(error)
|
|
1426
|
+
this.name = error.name || 'Unauthorized'
|
|
1427
|
+
this.code = typeof error.code === 'number' ? error.code : 1000
|
|
1428
|
+
this.message = error.message || `Unauthorized access`
|
|
1429
|
+
this.status = typeof error.status === 'number' ? error.status : 401
|
|
1430
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1431
|
+
Object.setPrototypeOf(this, UnauthorizedError.prototype)
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
export class PermissionDeniedError extends WebrpcError {
|
|
1436
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1437
|
+
super(error)
|
|
1438
|
+
this.name = error.name || 'PermissionDenied'
|
|
1439
|
+
this.code = typeof error.code === 'number' ? error.code : 1001
|
|
1440
|
+
this.message = error.message || `Permission denied`
|
|
1441
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
1442
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1443
|
+
Object.setPrototypeOf(this, PermissionDeniedError.prototype)
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
export class SessionExpiredError extends WebrpcError {
|
|
1448
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1449
|
+
super(error)
|
|
1450
|
+
this.name = error.name || 'SessionExpired'
|
|
1451
|
+
this.code = typeof error.code === 'number' ? error.code : 1002
|
|
1452
|
+
this.message = error.message || `Session expired`
|
|
1453
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
1454
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1455
|
+
Object.setPrototypeOf(this, SessionExpiredError.prototype)
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
export class MethodNotFoundError extends WebrpcError {
|
|
1460
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1461
|
+
super(error)
|
|
1462
|
+
this.name = error.name || 'MethodNotFound'
|
|
1463
|
+
this.code = typeof error.code === 'number' ? error.code : 1003
|
|
1464
|
+
this.message = error.message || `Method not found`
|
|
1465
|
+
this.status = typeof error.status === 'number' ? error.status : 404
|
|
1466
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1467
|
+
Object.setPrototypeOf(this, MethodNotFoundError.prototype)
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
export class RequestConflictError extends WebrpcError {
|
|
1472
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1473
|
+
super(error)
|
|
1474
|
+
this.name = error.name || 'RequestConflict'
|
|
1475
|
+
this.code = typeof error.code === 'number' ? error.code : 1004
|
|
1476
|
+
this.message = error.message || `Conflict with target resource`
|
|
1477
|
+
this.status = typeof error.status === 'number' ? error.status : 409
|
|
1478
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1479
|
+
Object.setPrototypeOf(this, RequestConflictError.prototype)
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
export class AbortedError extends WebrpcError {
|
|
1484
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1485
|
+
super(error)
|
|
1486
|
+
this.name = error.name || 'Aborted'
|
|
1487
|
+
this.code = typeof error.code === 'number' ? error.code : 1005
|
|
1488
|
+
this.message = error.message || `Request aborted`
|
|
1489
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1490
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1491
|
+
Object.setPrototypeOf(this, AbortedError.prototype)
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
export class GeoblockedError extends WebrpcError {
|
|
1496
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1497
|
+
super(error)
|
|
1498
|
+
this.name = error.name || 'Geoblocked'
|
|
1499
|
+
this.code = typeof error.code === 'number' ? error.code : 1006
|
|
1500
|
+
this.message = error.message || `Geoblocked region`
|
|
1501
|
+
this.status = typeof error.status === 'number' ? error.status : 451
|
|
1502
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1503
|
+
Object.setPrototypeOf(this, GeoblockedError.prototype)
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
export class RateLimitedError extends WebrpcError {
|
|
1508
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1509
|
+
super(error)
|
|
1510
|
+
this.name = error.name || 'RateLimited'
|
|
1511
|
+
this.code = typeof error.code === 'number' ? error.code : 1007
|
|
1512
|
+
this.message = error.message || `Rate-limited. Please slow down.`
|
|
1513
|
+
this.status = typeof error.status === 'number' ? error.status : 429
|
|
1514
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1515
|
+
Object.setPrototypeOf(this, RateLimitedError.prototype)
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
export class ProjectNotFoundError extends WebrpcError {
|
|
1520
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1521
|
+
super(error)
|
|
1522
|
+
this.name = error.name || 'ProjectNotFound'
|
|
1523
|
+
this.code = typeof error.code === 'number' ? error.code : 1008
|
|
1524
|
+
this.message = error.message || `Project not found`
|
|
1525
|
+
this.status = typeof error.status === 'number' ? error.status : 401
|
|
1526
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1527
|
+
Object.setPrototypeOf(this, ProjectNotFoundError.prototype)
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
export class InvalidArgumentError extends WebrpcError {
|
|
1532
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1533
|
+
super(error)
|
|
1534
|
+
this.name = error.name || 'InvalidArgument'
|
|
1535
|
+
this.code = typeof error.code === 'number' ? error.code : 2000
|
|
1536
|
+
this.message = error.message || `Invalid argument`
|
|
1537
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1538
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1539
|
+
Object.setPrototypeOf(this, InvalidArgumentError.prototype)
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
export class UnavailableError extends WebrpcError {
|
|
1544
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1545
|
+
super(error)
|
|
1546
|
+
this.name = error.name || 'Unavailable'
|
|
1547
|
+
this.code = typeof error.code === 'number' ? error.code : 2002
|
|
1548
|
+
this.message = error.message || `Unavailable resource`
|
|
1549
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1550
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1551
|
+
Object.setPrototypeOf(this, UnavailableError.prototype)
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
export class QueryFailedError extends WebrpcError {
|
|
1556
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1557
|
+
super(error)
|
|
1558
|
+
this.name = error.name || 'QueryFailed'
|
|
1559
|
+
this.code = typeof error.code === 'number' ? error.code : 2003
|
|
1560
|
+
this.message = error.message || `Query failed`
|
|
1561
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1562
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1563
|
+
Object.setPrototypeOf(this, QueryFailedError.prototype)
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
export class NotFoundError extends WebrpcError {
|
|
1568
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1569
|
+
super(error)
|
|
1570
|
+
this.name = error.name || 'NotFound'
|
|
1571
|
+
this.code = typeof error.code === 'number' ? error.code : 3000
|
|
1572
|
+
this.message = error.message || `Resource not found`
|
|
1573
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1574
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1575
|
+
Object.setPrototypeOf(this, NotFoundError.prototype)
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
export class UnsupportedNetworkError extends WebrpcError {
|
|
1580
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1581
|
+
super(error)
|
|
1582
|
+
this.name = error.name || 'UnsupportedNetwork'
|
|
1583
|
+
this.code = typeof error.code === 'number' ? error.code : 3008
|
|
1584
|
+
this.message = error.message || `Unsupported network`
|
|
1585
|
+
this.status = typeof error.status === 'number' ? error.status : 422
|
|
1586
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1587
|
+
Object.setPrototypeOf(this, UnsupportedNetworkError.prototype)
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
export enum errors {
|
|
1592
|
+
WebrpcEndpoint = 'WebrpcEndpoint',
|
|
1593
|
+
WebrpcRequestFailed = 'WebrpcRequestFailed',
|
|
1594
|
+
WebrpcBadRoute = 'WebrpcBadRoute',
|
|
1595
|
+
WebrpcBadMethod = 'WebrpcBadMethod',
|
|
1596
|
+
WebrpcBadRequest = 'WebrpcBadRequest',
|
|
1597
|
+
WebrpcBadResponse = 'WebrpcBadResponse',
|
|
1598
|
+
WebrpcServerPanic = 'WebrpcServerPanic',
|
|
1599
|
+
WebrpcInternalError = 'WebrpcInternalError',
|
|
1600
|
+
WebrpcClientAborted = 'WebrpcClientAborted',
|
|
1601
|
+
WebrpcStreamLost = 'WebrpcStreamLost',
|
|
1602
|
+
WebrpcStreamFinished = 'WebrpcStreamFinished',
|
|
1603
|
+
Unauthorized = 'Unauthorized',
|
|
1604
|
+
PermissionDenied = 'PermissionDenied',
|
|
1605
|
+
SessionExpired = 'SessionExpired',
|
|
1606
|
+
MethodNotFound = 'MethodNotFound',
|
|
1607
|
+
RequestConflict = 'RequestConflict',
|
|
1608
|
+
Aborted = 'Aborted',
|
|
1609
|
+
Geoblocked = 'Geoblocked',
|
|
1610
|
+
RateLimited = 'RateLimited',
|
|
1611
|
+
ProjectNotFound = 'ProjectNotFound',
|
|
1612
|
+
InvalidArgument = 'InvalidArgument',
|
|
1613
|
+
Unavailable = 'Unavailable',
|
|
1614
|
+
QueryFailed = 'QueryFailed',
|
|
1615
|
+
NotFound = 'NotFound',
|
|
1616
|
+
UnsupportedNetwork = 'UnsupportedNetwork',
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
export enum WebrpcErrorCodes {
|
|
1620
|
+
WebrpcEndpoint = 0,
|
|
1621
|
+
WebrpcRequestFailed = -1,
|
|
1622
|
+
WebrpcBadRoute = -2,
|
|
1623
|
+
WebrpcBadMethod = -3,
|
|
1624
|
+
WebrpcBadRequest = -4,
|
|
1625
|
+
WebrpcBadResponse = -5,
|
|
1626
|
+
WebrpcServerPanic = -6,
|
|
1627
|
+
WebrpcInternalError = -7,
|
|
1628
|
+
WebrpcClientAborted = -8,
|
|
1629
|
+
WebrpcStreamLost = -9,
|
|
1630
|
+
WebrpcStreamFinished = -10,
|
|
1631
|
+
Unauthorized = 1000,
|
|
1632
|
+
PermissionDenied = 1001,
|
|
1633
|
+
SessionExpired = 1002,
|
|
1634
|
+
MethodNotFound = 1003,
|
|
1635
|
+
RequestConflict = 1004,
|
|
1636
|
+
Aborted = 1005,
|
|
1637
|
+
Geoblocked = 1006,
|
|
1638
|
+
RateLimited = 1007,
|
|
1639
|
+
ProjectNotFound = 1008,
|
|
1640
|
+
InvalidArgument = 2000,
|
|
1641
|
+
Unavailable = 2002,
|
|
1642
|
+
QueryFailed = 2003,
|
|
1643
|
+
NotFound = 3000,
|
|
1644
|
+
UnsupportedNetwork = 3008,
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
export const webrpcErrorByCode: { [code: number]: any } = {
|
|
1648
|
+
[0]: WebrpcEndpointError,
|
|
1649
|
+
[-1]: WebrpcRequestFailedError,
|
|
1650
|
+
[-2]: WebrpcBadRouteError,
|
|
1651
|
+
[-3]: WebrpcBadMethodError,
|
|
1652
|
+
[-4]: WebrpcBadRequestError,
|
|
1653
|
+
[-5]: WebrpcBadResponseError,
|
|
1654
|
+
[-6]: WebrpcServerPanicError,
|
|
1655
|
+
[-7]: WebrpcInternalErrorError,
|
|
1656
|
+
[-8]: WebrpcClientAbortedError,
|
|
1657
|
+
[-9]: WebrpcStreamLostError,
|
|
1658
|
+
[-10]: WebrpcStreamFinishedError,
|
|
1659
|
+
[1000]: UnauthorizedError,
|
|
1660
|
+
[1001]: PermissionDeniedError,
|
|
1661
|
+
[1002]: SessionExpiredError,
|
|
1662
|
+
[1003]: MethodNotFoundError,
|
|
1663
|
+
[1004]: RequestConflictError,
|
|
1664
|
+
[1005]: AbortedError,
|
|
1665
|
+
[1006]: GeoblockedError,
|
|
1666
|
+
[1007]: RateLimitedError,
|
|
1667
|
+
[1008]: ProjectNotFoundError,
|
|
1668
|
+
[2000]: InvalidArgumentError,
|
|
1669
|
+
[2002]: UnavailableError,
|
|
1670
|
+
[2003]: QueryFailedError,
|
|
1671
|
+
[3000]: NotFoundError,
|
|
1672
|
+
[3008]: UnsupportedNetworkError,
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
//
|
|
1676
|
+
// Webrpc
|
|
1677
|
+
//
|
|
1678
|
+
|
|
1679
|
+
export const WebrpcHeader = 'Webrpc'
|
|
1680
|
+
|
|
1681
|
+
export const WebrpcHeaderValue = 'webrpc@v0.30.2;gen-typescript@v0.22.2;userdata@v0.1.0'
|
|
1682
|
+
|
|
1683
|
+
type WebrpcGenVersions = {
|
|
1684
|
+
WebrpcGenVersion: string
|
|
1685
|
+
codeGenName: string
|
|
1686
|
+
codeGenVersion: string
|
|
1687
|
+
schemaName: string
|
|
1688
|
+
schemaVersion: string
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
export function VersionFromHeader(headers: Headers): WebrpcGenVersions {
|
|
1692
|
+
const headerValue = headers.get(WebrpcHeader)
|
|
1693
|
+
if (!headerValue) {
|
|
1694
|
+
return {
|
|
1695
|
+
WebrpcGenVersion: '',
|
|
1696
|
+
codeGenName: '',
|
|
1697
|
+
codeGenVersion: '',
|
|
1698
|
+
schemaName: '',
|
|
1699
|
+
schemaVersion: '',
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
return parseWebrpcGenVersions(headerValue)
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
function parseWebrpcGenVersions(header: string): WebrpcGenVersions {
|
|
1707
|
+
const versions = header.split(';')
|
|
1708
|
+
if (versions.length < 3) {
|
|
1709
|
+
return {
|
|
1710
|
+
WebrpcGenVersion: '',
|
|
1711
|
+
codeGenName: '',
|
|
1712
|
+
codeGenVersion: '',
|
|
1713
|
+
schemaName: '',
|
|
1714
|
+
schemaVersion: '',
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
const [_, WebrpcGenVersion] = versions[0]!.split('@')
|
|
1719
|
+
const [codeGenName, codeGenVersion] = versions[1]!.split('@')
|
|
1720
|
+
const [schemaName, schemaVersion] = versions[2]!.split('@')
|
|
1721
|
+
|
|
1722
|
+
return {
|
|
1723
|
+
WebrpcGenVersion: WebrpcGenVersion ?? '',
|
|
1724
|
+
codeGenName: codeGenName ?? '',
|
|
1725
|
+
codeGenVersion: codeGenVersion ?? '',
|
|
1726
|
+
schemaName: schemaName ?? '',
|
|
1727
|
+
schemaVersion: schemaVersion ?? '',
|
|
1728
|
+
}
|
|
1729
|
+
}
|