@0xsequence/userdata 3.0.0-beta.10

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.
@@ -0,0 +1,686 @@
1
+ /* eslint-disable */
2
+ // userdata v0.1.0 99a19ff0218eda6f5e544642d0fd72f66736bdaf
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 = '99a19ff0218eda6f5e544642d0fd72f66736bdaf'
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
+
33
+ //
34
+ // Schema types
35
+ //
36
+
37
+ export interface Wallet {
38
+ address: string
39
+ ecosystem: number
40
+ }
41
+
42
+ export interface Signer {
43
+ address: string
44
+ kind: string
45
+ email?: string
46
+ }
47
+
48
+ export interface WalletSigner {
49
+ walletAddress: string
50
+ signerAddress: string
51
+ }
52
+
53
+ export interface Session {
54
+ walletAddress: string
55
+ sessionAddress: string
56
+ ipAddress: string
57
+ userAgent: string
58
+ originUrl: string
59
+ appUrl: string
60
+ createdAt: string
61
+ }
62
+
63
+ export interface SessionProps {
64
+ address: string
65
+ appUrl: string
66
+ }
67
+
68
+ export interface GetCapabilitiesRequest {}
69
+
70
+ export interface GetCapabilitiesResponse {
71
+ supportedMethods: Array<string>
72
+ }
73
+
74
+ export interface GetAccessTokenRequest {
75
+ ethauthProof: string
76
+ chainId: string
77
+ }
78
+
79
+ export interface GetAccessTokenResponse {
80
+ accessToken: string
81
+ refreshToken: string
82
+ expiresIn: number
83
+ }
84
+
85
+ export interface GetIdentityTokenRequest {
86
+ claims: { [key: string]: any }
87
+ }
88
+
89
+ export interface GetIdentityTokenResponse {
90
+ idToken: string
91
+ }
92
+
93
+ //
94
+ // Client
95
+ //
96
+
97
+ export class UserData implements UserDataClient {
98
+ protected hostname: string
99
+ protected fetch: Fetch
100
+ protected path = '/rpc/UserData/'
101
+
102
+ constructor(hostname: string, fetch: Fetch) {
103
+ this.hostname = hostname.replace(/\/*$/, '')
104
+ this.fetch = (input: RequestInfo, init?: RequestInit) => fetch(input, init)
105
+ }
106
+
107
+ private url(name: string): string {
108
+ return this.hostname + this.path + name
109
+ }
110
+
111
+ queryKey = {
112
+ getCapabilities: () => ['UserData', 'getCapabilities'] as const,
113
+ getAccessToken: (req: GetAccessTokenRequest) => ['UserData', 'getAccessToken', req] as const,
114
+ getIdentityToken: (req: GetIdentityTokenRequest) => ['UserData', 'getIdentityToken', req] as const,
115
+ }
116
+
117
+ getCapabilities = (headers?: object, signal?: AbortSignal): Promise<GetCapabilitiesResponse> => {
118
+ return this.fetch(this.url('GetCapabilities'), createHttpRequest('{}', headers, signal)).then(
119
+ (res) => {
120
+ return buildResponse(res).then((_data) => {
121
+ return JsonDecode<GetCapabilitiesResponse>(_data, 'GetCapabilitiesResponse')
122
+ })
123
+ },
124
+ (error) => {
125
+ throw WebrpcRequestFailedError.new({
126
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
127
+ })
128
+ },
129
+ )
130
+ }
131
+
132
+ getAccessToken = (
133
+ req: GetAccessTokenRequest,
134
+ headers?: object,
135
+ signal?: AbortSignal,
136
+ ): Promise<GetAccessTokenResponse> => {
137
+ return this.fetch(
138
+ this.url('GetAccessToken'),
139
+ createHttpRequest(JsonEncode(req, 'GetAccessTokenRequest'), headers, signal),
140
+ ).then(
141
+ (res) => {
142
+ return buildResponse(res).then((_data) => {
143
+ return JsonDecode<GetAccessTokenResponse>(_data, 'GetAccessTokenResponse')
144
+ })
145
+ },
146
+ (error) => {
147
+ throw WebrpcRequestFailedError.new({
148
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
149
+ })
150
+ },
151
+ )
152
+ }
153
+
154
+ getIdentityToken = (
155
+ req: GetIdentityTokenRequest,
156
+ headers?: object,
157
+ signal?: AbortSignal,
158
+ ): Promise<GetIdentityTokenResponse> => {
159
+ return this.fetch(
160
+ this.url('GetIdentityToken'),
161
+ createHttpRequest(JsonEncode(req, 'GetIdentityTokenRequest'), headers, signal),
162
+ ).then(
163
+ (res) => {
164
+ return buildResponse(res).then((_data) => {
165
+ return JsonDecode<GetIdentityTokenResponse>(_data, 'GetIdentityTokenResponse')
166
+ })
167
+ },
168
+ (error) => {
169
+ throw WebrpcRequestFailedError.new({
170
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
171
+ })
172
+ },
173
+ )
174
+ }
175
+ }
176
+
177
+ const createHttpRequest = (body: string = '{}', headers: object = {}, signal: AbortSignal | null = null): object => {
178
+ const reqHeaders: { [key: string]: string } = { ...headers, 'Content-Type': 'application/json' }
179
+ return { method: 'POST', headers: reqHeaders, body, signal }
180
+ }
181
+
182
+ const buildResponse = (res: Response): Promise<any> => {
183
+ return res.text().then((text) => {
184
+ let data
185
+ try {
186
+ data = JSON.parse(text)
187
+ } catch (error) {
188
+ throw WebrpcBadResponseError.new({
189
+ status: res.status,
190
+ cause: `JSON.parse(): ${error instanceof Error ? error.message : String(error)}: response text: ${text}`,
191
+ })
192
+ }
193
+ if (!res.ok) {
194
+ const code: number = typeof data.code === 'number' ? data.code : 0
195
+ throw (webrpcErrorByCode[code] || WebrpcError).new(data)
196
+ }
197
+ return data
198
+ })
199
+ }
200
+
201
+ export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>
202
+
203
+ export const JsonEncode = <T = any>(obj: T, _typ: string = ''): string => {
204
+ return JSON.stringify(obj)
205
+ }
206
+
207
+ export const JsonDecode = <T = any>(data: string | any, _typ: string = ''): T => {
208
+ let parsed: any = data
209
+ if (typeof data === 'string') {
210
+ try {
211
+ parsed = JSON.parse(data)
212
+ } catch (err) {
213
+ throw WebrpcBadResponseError.new({ cause: `JsonDecode: JSON.parse failed: ${(err as Error).message}` })
214
+ }
215
+ }
216
+ return parsed as T
217
+ }
218
+
219
+ //
220
+ // Errors
221
+ //
222
+
223
+ type WebrpcErrorParams = { name?: string; code?: number; message?: string; status?: number; cause?: string }
224
+
225
+ export class WebrpcError extends Error {
226
+ code: number
227
+ status: number
228
+
229
+ constructor(error: WebrpcErrorParams = {}) {
230
+ super(error.message)
231
+ this.name = error.name || 'WebrpcEndpointError'
232
+ this.code = typeof error.code === 'number' ? error.code : 0
233
+ this.message = error.message || `endpoint error`
234
+ this.status = typeof error.status === 'number' ? error.status : 400
235
+ if (error.cause !== undefined) this.cause = error.cause
236
+ Object.setPrototypeOf(this, WebrpcError.prototype)
237
+ }
238
+
239
+ static new(payload: any): WebrpcError {
240
+ return new this({ message: payload.message, code: payload.code, status: payload.status, cause: payload.cause })
241
+ }
242
+ }
243
+
244
+ export class WebrpcEndpointError extends WebrpcError {
245
+ constructor(error: WebrpcErrorParams = {}) {
246
+ super(error)
247
+ this.name = error.name || 'WebrpcEndpoint'
248
+ this.code = typeof error.code === 'number' ? error.code : 0
249
+ this.message = error.message || `endpoint error`
250
+ this.status = typeof error.status === 'number' ? error.status : 400
251
+ if (error.cause !== undefined) this.cause = error.cause
252
+ Object.setPrototypeOf(this, WebrpcEndpointError.prototype)
253
+ }
254
+ }
255
+
256
+ export class WebrpcRequestFailedError extends WebrpcError {
257
+ constructor(error: WebrpcErrorParams = {}) {
258
+ super(error)
259
+ this.name = error.name || 'WebrpcRequestFailed'
260
+ this.code = typeof error.code === 'number' ? error.code : -1
261
+ this.message = error.message || `request failed`
262
+ this.status = typeof error.status === 'number' ? error.status : 400
263
+ if (error.cause !== undefined) this.cause = error.cause
264
+ Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype)
265
+ }
266
+ }
267
+
268
+ export class WebrpcBadRouteError extends WebrpcError {
269
+ constructor(error: WebrpcErrorParams = {}) {
270
+ super(error)
271
+ this.name = error.name || 'WebrpcBadRoute'
272
+ this.code = typeof error.code === 'number' ? error.code : -2
273
+ this.message = error.message || `bad route`
274
+ this.status = typeof error.status === 'number' ? error.status : 404
275
+ if (error.cause !== undefined) this.cause = error.cause
276
+ Object.setPrototypeOf(this, WebrpcBadRouteError.prototype)
277
+ }
278
+ }
279
+
280
+ export class WebrpcBadMethodError extends WebrpcError {
281
+ constructor(error: WebrpcErrorParams = {}) {
282
+ super(error)
283
+ this.name = error.name || 'WebrpcBadMethod'
284
+ this.code = typeof error.code === 'number' ? error.code : -3
285
+ this.message = error.message || `bad method`
286
+ this.status = typeof error.status === 'number' ? error.status : 405
287
+ if (error.cause !== undefined) this.cause = error.cause
288
+ Object.setPrototypeOf(this, WebrpcBadMethodError.prototype)
289
+ }
290
+ }
291
+
292
+ export class WebrpcBadRequestError extends WebrpcError {
293
+ constructor(error: WebrpcErrorParams = {}) {
294
+ super(error)
295
+ this.name = error.name || 'WebrpcBadRequest'
296
+ this.code = typeof error.code === 'number' ? error.code : -4
297
+ this.message = error.message || `bad request`
298
+ this.status = typeof error.status === 'number' ? error.status : 400
299
+ if (error.cause !== undefined) this.cause = error.cause
300
+ Object.setPrototypeOf(this, WebrpcBadRequestError.prototype)
301
+ }
302
+ }
303
+
304
+ export class WebrpcBadResponseError extends WebrpcError {
305
+ constructor(error: WebrpcErrorParams = {}) {
306
+ super(error)
307
+ this.name = error.name || 'WebrpcBadResponse'
308
+ this.code = typeof error.code === 'number' ? error.code : -5
309
+ this.message = error.message || `bad response`
310
+ this.status = typeof error.status === 'number' ? error.status : 500
311
+ if (error.cause !== undefined) this.cause = error.cause
312
+ Object.setPrototypeOf(this, WebrpcBadResponseError.prototype)
313
+ }
314
+ }
315
+
316
+ export class WebrpcServerPanicError extends WebrpcError {
317
+ constructor(error: WebrpcErrorParams = {}) {
318
+ super(error)
319
+ this.name = error.name || 'WebrpcServerPanic'
320
+ this.code = typeof error.code === 'number' ? error.code : -6
321
+ this.message = error.message || `server panic`
322
+ this.status = typeof error.status === 'number' ? error.status : 500
323
+ if (error.cause !== undefined) this.cause = error.cause
324
+ Object.setPrototypeOf(this, WebrpcServerPanicError.prototype)
325
+ }
326
+ }
327
+
328
+ export class WebrpcInternalErrorError extends WebrpcError {
329
+ constructor(error: WebrpcErrorParams = {}) {
330
+ super(error)
331
+ this.name = error.name || 'WebrpcInternalError'
332
+ this.code = typeof error.code === 'number' ? error.code : -7
333
+ this.message = error.message || `internal error`
334
+ this.status = typeof error.status === 'number' ? error.status : 500
335
+ if (error.cause !== undefined) this.cause = error.cause
336
+ Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype)
337
+ }
338
+ }
339
+
340
+ export class WebrpcClientAbortedError extends WebrpcError {
341
+ constructor(error: WebrpcErrorParams = {}) {
342
+ super(error)
343
+ this.name = error.name || 'WebrpcClientAborted'
344
+ this.code = typeof error.code === 'number' ? error.code : -8
345
+ this.message = error.message || `request aborted by client`
346
+ this.status = typeof error.status === 'number' ? error.status : 400
347
+ if (error.cause !== undefined) this.cause = error.cause
348
+ Object.setPrototypeOf(this, WebrpcClientAbortedError.prototype)
349
+ }
350
+ }
351
+
352
+ export class WebrpcStreamLostError extends WebrpcError {
353
+ constructor(error: WebrpcErrorParams = {}) {
354
+ super(error)
355
+ this.name = error.name || 'WebrpcStreamLost'
356
+ this.code = typeof error.code === 'number' ? error.code : -9
357
+ this.message = error.message || `stream lost`
358
+ this.status = typeof error.status === 'number' ? error.status : 400
359
+ if (error.cause !== undefined) this.cause = error.cause
360
+ Object.setPrototypeOf(this, WebrpcStreamLostError.prototype)
361
+ }
362
+ }
363
+
364
+ export class WebrpcStreamFinishedError extends WebrpcError {
365
+ constructor(error: WebrpcErrorParams = {}) {
366
+ super(error)
367
+ this.name = error.name || 'WebrpcStreamFinished'
368
+ this.code = typeof error.code === 'number' ? error.code : -10
369
+ this.message = error.message || `stream finished`
370
+ this.status = typeof error.status === 'number' ? error.status : 200
371
+ if (error.cause !== undefined) this.cause = error.cause
372
+ Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype)
373
+ }
374
+ }
375
+
376
+ //
377
+ // Schema errors
378
+ //
379
+
380
+ export class UnauthorizedError extends WebrpcError {
381
+ constructor(error: WebrpcErrorParams = {}) {
382
+ super(error)
383
+ this.name = error.name || 'Unauthorized'
384
+ this.code = typeof error.code === 'number' ? error.code : 1000
385
+ this.message = error.message || `Unauthorized access`
386
+ this.status = typeof error.status === 'number' ? error.status : 401
387
+ if (error.cause !== undefined) this.cause = error.cause
388
+ Object.setPrototypeOf(this, UnauthorizedError.prototype)
389
+ }
390
+ }
391
+
392
+ export class PermissionDeniedError extends WebrpcError {
393
+ constructor(error: WebrpcErrorParams = {}) {
394
+ super(error)
395
+ this.name = error.name || 'PermissionDenied'
396
+ this.code = typeof error.code === 'number' ? error.code : 1001
397
+ this.message = error.message || `Permission denied`
398
+ this.status = typeof error.status === 'number' ? error.status : 403
399
+ if (error.cause !== undefined) this.cause = error.cause
400
+ Object.setPrototypeOf(this, PermissionDeniedError.prototype)
401
+ }
402
+ }
403
+
404
+ export class SessionExpiredError extends WebrpcError {
405
+ constructor(error: WebrpcErrorParams = {}) {
406
+ super(error)
407
+ this.name = error.name || 'SessionExpired'
408
+ this.code = typeof error.code === 'number' ? error.code : 1002
409
+ this.message = error.message || `Session expired`
410
+ this.status = typeof error.status === 'number' ? error.status : 403
411
+ if (error.cause !== undefined) this.cause = error.cause
412
+ Object.setPrototypeOf(this, SessionExpiredError.prototype)
413
+ }
414
+ }
415
+
416
+ export class MethodNotFoundError extends WebrpcError {
417
+ constructor(error: WebrpcErrorParams = {}) {
418
+ super(error)
419
+ this.name = error.name || 'MethodNotFound'
420
+ this.code = typeof error.code === 'number' ? error.code : 1003
421
+ this.message = error.message || `Method not found`
422
+ this.status = typeof error.status === 'number' ? error.status : 404
423
+ if (error.cause !== undefined) this.cause = error.cause
424
+ Object.setPrototypeOf(this, MethodNotFoundError.prototype)
425
+ }
426
+ }
427
+
428
+ export class RequestConflictError extends WebrpcError {
429
+ constructor(error: WebrpcErrorParams = {}) {
430
+ super(error)
431
+ this.name = error.name || 'RequestConflict'
432
+ this.code = typeof error.code === 'number' ? error.code : 1004
433
+ this.message = error.message || `Conflict with target resource`
434
+ this.status = typeof error.status === 'number' ? error.status : 409
435
+ if (error.cause !== undefined) this.cause = error.cause
436
+ Object.setPrototypeOf(this, RequestConflictError.prototype)
437
+ }
438
+ }
439
+
440
+ export class AbortedError extends WebrpcError {
441
+ constructor(error: WebrpcErrorParams = {}) {
442
+ super(error)
443
+ this.name = error.name || 'Aborted'
444
+ this.code = typeof error.code === 'number' ? error.code : 1005
445
+ this.message = error.message || `Request aborted`
446
+ this.status = typeof error.status === 'number' ? error.status : 400
447
+ if (error.cause !== undefined) this.cause = error.cause
448
+ Object.setPrototypeOf(this, AbortedError.prototype)
449
+ }
450
+ }
451
+
452
+ export class GeoblockedError extends WebrpcError {
453
+ constructor(error: WebrpcErrorParams = {}) {
454
+ super(error)
455
+ this.name = error.name || 'Geoblocked'
456
+ this.code = typeof error.code === 'number' ? error.code : 1006
457
+ this.message = error.message || `Geoblocked region`
458
+ this.status = typeof error.status === 'number' ? error.status : 451
459
+ if (error.cause !== undefined) this.cause = error.cause
460
+ Object.setPrototypeOf(this, GeoblockedError.prototype)
461
+ }
462
+ }
463
+
464
+ export class RateLimitedError extends WebrpcError {
465
+ constructor(error: WebrpcErrorParams = {}) {
466
+ super(error)
467
+ this.name = error.name || 'RateLimited'
468
+ this.code = typeof error.code === 'number' ? error.code : 1007
469
+ this.message = error.message || `Rate-limited. Please slow down.`
470
+ this.status = typeof error.status === 'number' ? error.status : 429
471
+ if (error.cause !== undefined) this.cause = error.cause
472
+ Object.setPrototypeOf(this, RateLimitedError.prototype)
473
+ }
474
+ }
475
+
476
+ export class ProjectNotFoundError extends WebrpcError {
477
+ constructor(error: WebrpcErrorParams = {}) {
478
+ super(error)
479
+ this.name = error.name || 'ProjectNotFound'
480
+ this.code = typeof error.code === 'number' ? error.code : 1008
481
+ this.message = error.message || `Project not found`
482
+ this.status = typeof error.status === 'number' ? error.status : 401
483
+ if (error.cause !== undefined) this.cause = error.cause
484
+ Object.setPrototypeOf(this, ProjectNotFoundError.prototype)
485
+ }
486
+ }
487
+
488
+ export class InvalidArgumentError extends WebrpcError {
489
+ constructor(error: WebrpcErrorParams = {}) {
490
+ super(error)
491
+ this.name = error.name || 'InvalidArgument'
492
+ this.code = typeof error.code === 'number' ? error.code : 2000
493
+ this.message = error.message || `Invalid argument`
494
+ this.status = typeof error.status === 'number' ? error.status : 400
495
+ if (error.cause !== undefined) this.cause = error.cause
496
+ Object.setPrototypeOf(this, InvalidArgumentError.prototype)
497
+ }
498
+ }
499
+
500
+ export class UnavailableError extends WebrpcError {
501
+ constructor(error: WebrpcErrorParams = {}) {
502
+ super(error)
503
+ this.name = error.name || 'Unavailable'
504
+ this.code = typeof error.code === 'number' ? error.code : 2002
505
+ this.message = error.message || `Unavailable resource`
506
+ this.status = typeof error.status === 'number' ? error.status : 400
507
+ if (error.cause !== undefined) this.cause = error.cause
508
+ Object.setPrototypeOf(this, UnavailableError.prototype)
509
+ }
510
+ }
511
+
512
+ export class QueryFailedError extends WebrpcError {
513
+ constructor(error: WebrpcErrorParams = {}) {
514
+ super(error)
515
+ this.name = error.name || 'QueryFailed'
516
+ this.code = typeof error.code === 'number' ? error.code : 2003
517
+ this.message = error.message || `Query failed`
518
+ this.status = typeof error.status === 'number' ? error.status : 400
519
+ if (error.cause !== undefined) this.cause = error.cause
520
+ Object.setPrototypeOf(this, QueryFailedError.prototype)
521
+ }
522
+ }
523
+
524
+ export class NotFoundError extends WebrpcError {
525
+ constructor(error: WebrpcErrorParams = {}) {
526
+ super(error)
527
+ this.name = error.name || 'NotFound'
528
+ this.code = typeof error.code === 'number' ? error.code : 3000
529
+ this.message = error.message || `Resource not found`
530
+ this.status = typeof error.status === 'number' ? error.status : 400
531
+ if (error.cause !== undefined) this.cause = error.cause
532
+ Object.setPrototypeOf(this, NotFoundError.prototype)
533
+ }
534
+ }
535
+
536
+ export class UnsupportedNetworkError extends WebrpcError {
537
+ constructor(error: WebrpcErrorParams = {}) {
538
+ super(error)
539
+ this.name = error.name || 'UnsupportedNetwork'
540
+ this.code = typeof error.code === 'number' ? error.code : 3008
541
+ this.message = error.message || `Unsupported network`
542
+ this.status = typeof error.status === 'number' ? error.status : 422
543
+ if (error.cause !== undefined) this.cause = error.cause
544
+ Object.setPrototypeOf(this, UnsupportedNetworkError.prototype)
545
+ }
546
+ }
547
+
548
+ export enum errors {
549
+ WebrpcEndpoint = 'WebrpcEndpoint',
550
+ WebrpcRequestFailed = 'WebrpcRequestFailed',
551
+ WebrpcBadRoute = 'WebrpcBadRoute',
552
+ WebrpcBadMethod = 'WebrpcBadMethod',
553
+ WebrpcBadRequest = 'WebrpcBadRequest',
554
+ WebrpcBadResponse = 'WebrpcBadResponse',
555
+ WebrpcServerPanic = 'WebrpcServerPanic',
556
+ WebrpcInternalError = 'WebrpcInternalError',
557
+ WebrpcClientAborted = 'WebrpcClientAborted',
558
+ WebrpcStreamLost = 'WebrpcStreamLost',
559
+ WebrpcStreamFinished = 'WebrpcStreamFinished',
560
+ Unauthorized = 'Unauthorized',
561
+ PermissionDenied = 'PermissionDenied',
562
+ SessionExpired = 'SessionExpired',
563
+ MethodNotFound = 'MethodNotFound',
564
+ RequestConflict = 'RequestConflict',
565
+ Aborted = 'Aborted',
566
+ Geoblocked = 'Geoblocked',
567
+ RateLimited = 'RateLimited',
568
+ ProjectNotFound = 'ProjectNotFound',
569
+ InvalidArgument = 'InvalidArgument',
570
+ Unavailable = 'Unavailable',
571
+ QueryFailed = 'QueryFailed',
572
+ NotFound = 'NotFound',
573
+ UnsupportedNetwork = 'UnsupportedNetwork',
574
+ }
575
+
576
+ export enum WebrpcErrorCodes {
577
+ WebrpcEndpoint = 0,
578
+ WebrpcRequestFailed = -1,
579
+ WebrpcBadRoute = -2,
580
+ WebrpcBadMethod = -3,
581
+ WebrpcBadRequest = -4,
582
+ WebrpcBadResponse = -5,
583
+ WebrpcServerPanic = -6,
584
+ WebrpcInternalError = -7,
585
+ WebrpcClientAborted = -8,
586
+ WebrpcStreamLost = -9,
587
+ WebrpcStreamFinished = -10,
588
+ Unauthorized = 1000,
589
+ PermissionDenied = 1001,
590
+ SessionExpired = 1002,
591
+ MethodNotFound = 1003,
592
+ RequestConflict = 1004,
593
+ Aborted = 1005,
594
+ Geoblocked = 1006,
595
+ RateLimited = 1007,
596
+ ProjectNotFound = 1008,
597
+ InvalidArgument = 2000,
598
+ Unavailable = 2002,
599
+ QueryFailed = 2003,
600
+ NotFound = 3000,
601
+ UnsupportedNetwork = 3008,
602
+ }
603
+
604
+ export const webrpcErrorByCode: { [code: number]: any } = {
605
+ [0]: WebrpcEndpointError,
606
+ [-1]: WebrpcRequestFailedError,
607
+ [-2]: WebrpcBadRouteError,
608
+ [-3]: WebrpcBadMethodError,
609
+ [-4]: WebrpcBadRequestError,
610
+ [-5]: WebrpcBadResponseError,
611
+ [-6]: WebrpcServerPanicError,
612
+ [-7]: WebrpcInternalErrorError,
613
+ [-8]: WebrpcClientAbortedError,
614
+ [-9]: WebrpcStreamLostError,
615
+ [-10]: WebrpcStreamFinishedError,
616
+ [1000]: UnauthorizedError,
617
+ [1001]: PermissionDeniedError,
618
+ [1002]: SessionExpiredError,
619
+ [1003]: MethodNotFoundError,
620
+ [1004]: RequestConflictError,
621
+ [1005]: AbortedError,
622
+ [1006]: GeoblockedError,
623
+ [1007]: RateLimitedError,
624
+ [1008]: ProjectNotFoundError,
625
+ [2000]: InvalidArgumentError,
626
+ [2002]: UnavailableError,
627
+ [2003]: QueryFailedError,
628
+ [3000]: NotFoundError,
629
+ [3008]: UnsupportedNetworkError,
630
+ }
631
+
632
+ //
633
+ // Webrpc
634
+ //
635
+
636
+ export const WebrpcHeader = 'Webrpc'
637
+
638
+ export const WebrpcHeaderValue = 'webrpc@v0.30.2;gen-typescript@v0.22.2;userdata@v0.1.0'
639
+
640
+ type WebrpcGenVersions = {
641
+ WebrpcGenVersion: string
642
+ codeGenName: string
643
+ codeGenVersion: string
644
+ schemaName: string
645
+ schemaVersion: string
646
+ }
647
+
648
+ export function VersionFromHeader(headers: Headers): WebrpcGenVersions {
649
+ const headerValue = headers.get(WebrpcHeader)
650
+ if (!headerValue) {
651
+ return {
652
+ WebrpcGenVersion: '',
653
+ codeGenName: '',
654
+ codeGenVersion: '',
655
+ schemaName: '',
656
+ schemaVersion: '',
657
+ }
658
+ }
659
+
660
+ return parseWebrpcGenVersions(headerValue)
661
+ }
662
+
663
+ function parseWebrpcGenVersions(header: string): WebrpcGenVersions {
664
+ const versions = header.split(';')
665
+ if (versions.length < 3) {
666
+ return {
667
+ WebrpcGenVersion: '',
668
+ codeGenName: '',
669
+ codeGenVersion: '',
670
+ schemaName: '',
671
+ schemaVersion: '',
672
+ }
673
+ }
674
+
675
+ const [_, WebrpcGenVersion] = versions[0]!.split('@')
676
+ const [codeGenName, codeGenVersion] = versions[1]!.split('@')
677
+ const [schemaName, schemaVersion] = versions[2]!.split('@')
678
+
679
+ return {
680
+ WebrpcGenVersion: WebrpcGenVersion ?? '',
681
+ codeGenName: codeGenName ?? '',
682
+ codeGenVersion: codeGenVersion ?? '',
683
+ schemaName: schemaName ?? '',
684
+ schemaVersion: schemaVersion ?? '',
685
+ }
686
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "@repo/typescript-config/base.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "types": ["node"]
7
+ },
8
+ "include": ["src"],
9
+ "exclude": ["node_modules", "dist"]
10
+ }