@0xsequence/builder 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@0xsequence/builder",
3
+ "version": "2.2.0",
4
+ "description": "builder sub-package for Sequence",
5
+ "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/builder",
6
+ "source": "src/index.ts",
7
+ "main": "dist/0xsequence-builder.cjs.js",
8
+ "module": "dist/0xsequence-builder.esm.js",
9
+ "author": "Horizon Blockchain Games",
10
+ "license": "Apache-2.0",
11
+ "dependencies": {},
12
+ "peerDependencies": {},
13
+ "devDependencies": {},
14
+ "files": [
15
+ "src",
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "test": "echo",
20
+ "typecheck": "tsc --noEmit"
21
+ }
22
+ }
@@ -0,0 +1,683 @@
1
+ /* eslint-disable */
2
+ // NOTE: this is just a subset of the builder api to scope down the
3
+ // surface area of the client.
4
+ //
5
+ // In the future we can include additional interfaces as needed.
6
+ export const WebrpcHeader = "Webrpc"
7
+
8
+ export const WebrpcHeaderValue = "webrpc@v0.22.0;gen-typescript@v0.16.1;sequence-builder@v0.1.0"
9
+
10
+ // WebRPC description and code-gen version
11
+ export const WebRPCVersion = "v1"
12
+
13
+ // Schema version of your RIDL schema
14
+ export const WebRPCSchemaVersion = "v0.1.0"
15
+
16
+ // Schema hash generated from your RIDL schema
17
+ export const WebRPCSchemaHash = "5b580e1afeb26e0b4a8ee026271e2466760da0aa"
18
+
19
+ type WebrpcGenVersions = {
20
+ webrpcGenVersion: string;
21
+ codeGenName: string;
22
+ codeGenVersion: string;
23
+ schemaName: string;
24
+ schemaVersion: string;
25
+ };
26
+
27
+ export function VersionFromHeader(headers: Headers): WebrpcGenVersions {
28
+ const headerValue = headers.get(WebrpcHeader);
29
+ if (!headerValue) {
30
+ return {
31
+ webrpcGenVersion: "",
32
+ codeGenName: "",
33
+ codeGenVersion: "",
34
+ schemaName: "",
35
+ schemaVersion: "",
36
+ };
37
+ }
38
+
39
+ return parseWebrpcGenVersions(headerValue);
40
+ }
41
+
42
+ function parseWebrpcGenVersions(header: string): WebrpcGenVersions {
43
+ const versions = header.split(";");
44
+ if (versions.length < 3) {
45
+ return {
46
+ webrpcGenVersion: "",
47
+ codeGenName: "",
48
+ codeGenVersion: "",
49
+ schemaName: "",
50
+ schemaVersion: "",
51
+ };
52
+ }
53
+
54
+ const [_, webrpcGenVersion] = versions[0].split("@");
55
+ const [codeGenName, codeGenVersion] = versions[1].split("@");
56
+ const [schemaName, schemaVersion] = versions[2].split("@");
57
+
58
+ return {
59
+ webrpcGenVersion,
60
+ codeGenName,
61
+ codeGenVersion,
62
+ schemaName,
63
+ schemaVersion,
64
+ };
65
+ }
66
+
67
+ //
68
+ // Types
69
+ //
70
+
71
+ export interface AudienceContact {
72
+ id?: number
73
+ audienceId: number
74
+ name?: string
75
+ address: string
76
+ email?: string
77
+ userIp?: string
78
+ stage?: number
79
+ createdAt?: string
80
+ updatedAt?: string
81
+ }
82
+
83
+ export interface AudienceRegistrationStatus {
84
+ totalCount: number
85
+ }
86
+
87
+ export interface WalletProof {
88
+ address: string
89
+ message: string
90
+ signature: string
91
+ chainId: number
92
+ }
93
+
94
+ export interface Builder {
95
+ ping(headers?: object, signal?: AbortSignal): Promise<PingReturn>
96
+ registerAudienceContact(args: RegisterAudienceContactArgs, headers?: object, signal?: AbortSignal): Promise<RegisterAudienceContactReturn>
97
+ getRegisteredAudienceContact(args: GetRegisteredAudienceContactArgs, headers?: object, signal?: AbortSignal): Promise<GetRegisteredAudienceContactReturn>
98
+ getAudienceRegistrationPublicStatus(args: GetAudienceRegistrationPublicStatusArgs, headers?: object, signal?: AbortSignal): Promise<GetAudienceRegistrationPublicStatusReturn>
99
+ isAudienceContactRegistered(args: IsAudienceContactRegisteredArgs, headers?: object, signal?: AbortSignal): Promise<IsAudienceContactRegisteredReturn>
100
+ }
101
+
102
+ export interface PingArgs {
103
+ }
104
+
105
+ export interface PingReturn {
106
+ status: boolean
107
+ }
108
+
109
+ export interface RegisterAudienceContactArgs {
110
+ projectId: number
111
+ audienceId: number
112
+ contact: AudienceContact
113
+ walletProof: WalletProof
114
+ }
115
+
116
+ export interface RegisterAudienceContactReturn {
117
+ ok: boolean
118
+ }
119
+ export interface GetRegisteredAudienceContactArgs {
120
+ projectId: number
121
+ audienceId: number
122
+ walletProof: WalletProof
123
+ }
124
+
125
+ export interface GetRegisteredAudienceContactReturn {
126
+ contact: AudienceContact
127
+ }
128
+ export interface GetAudienceRegistrationPublicStatusArgs {
129
+ projectId: number
130
+ audienceId: number
131
+ }
132
+
133
+ export interface GetAudienceRegistrationPublicStatusReturn {
134
+ status: AudienceRegistrationStatus
135
+ }
136
+ export interface IsAudienceContactRegisteredArgs {
137
+ projectId: number
138
+ audienceId: number
139
+ walletAddress: string
140
+ }
141
+
142
+ export interface IsAudienceContactRegisteredReturn {
143
+ registered: boolean
144
+ }
145
+
146
+
147
+ //
148
+ // Client
149
+ //
150
+ export class Builder implements Builder {
151
+ protected hostname: string
152
+ protected fetch: Fetch
153
+ protected path = '/rpc/Builder/'
154
+
155
+ constructor(hostname: string, fetch: Fetch) {
156
+ this.hostname = hostname.replace(/\/*$/, '')
157
+ this.fetch = (input: RequestInfo, init?: RequestInit) => fetch(input, init)
158
+ }
159
+
160
+ private url(name: string): string {
161
+ return this.hostname + this.path + name
162
+ }
163
+
164
+ ping = (headers?: object, signal?: AbortSignal): Promise<PingReturn> => {
165
+ return this.fetch(
166
+ this.url('Ping'),
167
+ createHTTPRequest({}, headers, signal)
168
+ ).then((res) => {
169
+ return buildResponse(res).then(_data => {
170
+ return {
171
+ status: <boolean>(_data.status),
172
+ }
173
+ })
174
+ }, (error) => {
175
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
176
+ })
177
+ }
178
+
179
+ registerAudienceContact = (args: RegisterAudienceContactArgs, headers?: object, signal?: AbortSignal): Promise<RegisterAudienceContactReturn> => {
180
+ return this.fetch(
181
+ this.url('RegisterAudienceContact'),
182
+ createHTTPRequest(args, headers, signal)).then((res) => {
183
+ return buildResponse(res).then(_data => {
184
+ return {
185
+ ok: <boolean>(_data.ok),
186
+ }
187
+ })
188
+ }, (error) => {
189
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
190
+ })
191
+ }
192
+
193
+ getRegisteredAudienceContact = (args: GetRegisteredAudienceContactArgs, headers?: object, signal?: AbortSignal): Promise<GetRegisteredAudienceContactReturn> => {
194
+ return this.fetch(
195
+ this.url('GetRegisteredAudienceContact'),
196
+ createHTTPRequest(args, headers, signal)).then((res) => {
197
+ return buildResponse(res).then(_data => {
198
+ return {
199
+ contact: <AudienceContact>(_data.contact),
200
+ }
201
+ })
202
+ }, (error) => {
203
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
204
+ })
205
+ }
206
+
207
+ getAudienceRegistrationPublicStatus = (args: GetAudienceRegistrationPublicStatusArgs, headers?: object, signal?: AbortSignal): Promise<GetAudienceRegistrationPublicStatusReturn> => {
208
+ return this.fetch(
209
+ this.url('GetAudienceRegistrationPublicStatus'),
210
+ createHTTPRequest(args, headers, signal)).then((res) => {
211
+ return buildResponse(res).then(_data => {
212
+ return {
213
+ status: <AudienceRegistrationStatus>(_data.status),
214
+ }
215
+ })
216
+ }, (error) => {
217
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
218
+ })
219
+ }
220
+
221
+ isAudienceContactRegistered = (args: IsAudienceContactRegisteredArgs, headers?: object, signal?: AbortSignal): Promise<IsAudienceContactRegisteredReturn> => {
222
+ return this.fetch(
223
+ this.url('IsAudienceContactRegistered'),
224
+ createHTTPRequest(args, headers, signal)).then((res) => {
225
+ return buildResponse(res).then(_data => {
226
+ return {
227
+ registered: <boolean>(_data.registered),
228
+ }
229
+ })
230
+ }, (error) => {
231
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
232
+ })
233
+ }
234
+
235
+ }
236
+
237
+ const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => {
238
+ const reqHeaders: {[key: string]: string} = { ...headers, 'Content-Type': 'application/json' }
239
+ reqHeaders[WebrpcHeader] = WebrpcHeaderValue
240
+
241
+ return {
242
+ method: 'POST',
243
+ headers: reqHeaders,
244
+ body: JSON.stringify(body || {}),
245
+ signal
246
+ }
247
+ }
248
+
249
+ const buildResponse = (res: Response): Promise<any> => {
250
+ return res.text().then(text => {
251
+ let data
252
+ try {
253
+ data = JSON.parse(text)
254
+ } catch(error) {
255
+ let message = ''
256
+ if (error instanceof Error) {
257
+ message = error.message
258
+ }
259
+ throw WebrpcBadResponseError.new({
260
+ status: res.status,
261
+ cause: `JSON.parse(): ${message}: response text: ${text}`},
262
+ )
263
+ }
264
+ if (!res.ok) {
265
+ const code: number = (typeof data.code === 'number') ? data.code : 0
266
+ throw (webrpcErrorByCode[code] || WebrpcError).new(data)
267
+ }
268
+ return data
269
+ })
270
+ }
271
+
272
+ //
273
+ // Errors
274
+ //
275
+
276
+ export class WebrpcError extends Error {
277
+ name: string
278
+ code: number
279
+ message: string
280
+ status: number
281
+ cause?: string
282
+
283
+ /** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */
284
+ msg: string
285
+
286
+ constructor(name: string, code: number, message: string, status: number, cause?: string) {
287
+ super(message)
288
+ this.name = name || 'WebrpcError'
289
+ this.code = typeof code === 'number' ? code : 0
290
+ this.message = message || `endpoint error ${this.code}`
291
+ this.msg = this.message
292
+ this.status = typeof status === 'number' ? status : 0
293
+ this.cause = cause
294
+ Object.setPrototypeOf(this, WebrpcError.prototype)
295
+ }
296
+
297
+ static new(payload: any): WebrpcError {
298
+ return new this(payload.error, payload.code, payload.message || payload.msg, payload.status, payload.cause)
299
+ }
300
+ }
301
+
302
+ // Webrpc errors
303
+
304
+ export class WebrpcEndpointError extends WebrpcError {
305
+ constructor(
306
+ name: string = 'WebrpcEndpoint',
307
+ code: number = 0,
308
+ message: string = 'endpoint error',
309
+ status: number = 0,
310
+ cause?: string
311
+ ) {
312
+ super(name, code, message, status, cause)
313
+ Object.setPrototypeOf(this, WebrpcEndpointError.prototype)
314
+ }
315
+ }
316
+
317
+ export class WebrpcRequestFailedError extends WebrpcError {
318
+ constructor(
319
+ name: string = 'WebrpcRequestFailed',
320
+ code: number = -1,
321
+ message: string = 'request failed',
322
+ status: number = 0,
323
+ cause?: string
324
+ ) {
325
+ super(name, code, message, status, cause)
326
+ Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype)
327
+ }
328
+ }
329
+
330
+ export class WebrpcBadRouteError extends WebrpcError {
331
+ constructor(
332
+ name: string = 'WebrpcBadRoute',
333
+ code: number = -2,
334
+ message: string = 'bad route',
335
+ status: number = 0,
336
+ cause?: string
337
+ ) {
338
+ super(name, code, message, status, cause)
339
+ Object.setPrototypeOf(this, WebrpcBadRouteError.prototype)
340
+ }
341
+ }
342
+
343
+ export class WebrpcBadMethodError extends WebrpcError {
344
+ constructor(
345
+ name: string = 'WebrpcBadMethod',
346
+ code: number = -3,
347
+ message: string = 'bad method',
348
+ status: number = 0,
349
+ cause?: string
350
+ ) {
351
+ super(name, code, message, status, cause)
352
+ Object.setPrototypeOf(this, WebrpcBadMethodError.prototype)
353
+ }
354
+ }
355
+
356
+ export class WebrpcBadRequestError extends WebrpcError {
357
+ constructor(
358
+ name: string = 'WebrpcBadRequest',
359
+ code: number = -4,
360
+ message: string = 'bad request',
361
+ status: number = 0,
362
+ cause?: string
363
+ ) {
364
+ super(name, code, message, status, cause)
365
+ Object.setPrototypeOf(this, WebrpcBadRequestError.prototype)
366
+ }
367
+ }
368
+
369
+ export class WebrpcBadResponseError extends WebrpcError {
370
+ constructor(
371
+ name: string = 'WebrpcBadResponse',
372
+ code: number = -5,
373
+ message: string = 'bad response',
374
+ status: number = 0,
375
+ cause?: string
376
+ ) {
377
+ super(name, code, message, status, cause)
378
+ Object.setPrototypeOf(this, WebrpcBadResponseError.prototype)
379
+ }
380
+ }
381
+
382
+ export class WebrpcServerPanicError extends WebrpcError {
383
+ constructor(
384
+ name: string = 'WebrpcServerPanic',
385
+ code: number = -6,
386
+ message: string = 'server panic',
387
+ status: number = 0,
388
+ cause?: string
389
+ ) {
390
+ super(name, code, message, status, cause)
391
+ Object.setPrototypeOf(this, WebrpcServerPanicError.prototype)
392
+ }
393
+ }
394
+
395
+ export class WebrpcInternalErrorError extends WebrpcError {
396
+ constructor(
397
+ name: string = 'WebrpcInternalError',
398
+ code: number = -7,
399
+ message: string = 'internal error',
400
+ status: number = 0,
401
+ cause?: string
402
+ ) {
403
+ super(name, code, message, status, cause)
404
+ Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype)
405
+ }
406
+ }
407
+
408
+ export class WebrpcClientDisconnectedError extends WebrpcError {
409
+ constructor(
410
+ name: string = 'WebrpcClientDisconnected',
411
+ code: number = -8,
412
+ message: string = 'client disconnected',
413
+ status: number = 0,
414
+ cause?: string
415
+ ) {
416
+ super(name, code, message, status, cause)
417
+ Object.setPrototypeOf(this, WebrpcClientDisconnectedError.prototype)
418
+ }
419
+ }
420
+
421
+ export class WebrpcStreamLostError extends WebrpcError {
422
+ constructor(
423
+ name: string = 'WebrpcStreamLost',
424
+ code: number = -9,
425
+ message: string = 'stream lost',
426
+ status: number = 0,
427
+ cause?: string
428
+ ) {
429
+ super(name, code, message, status, cause)
430
+ Object.setPrototypeOf(this, WebrpcStreamLostError.prototype)
431
+ }
432
+ }
433
+
434
+ export class WebrpcStreamFinishedError extends WebrpcError {
435
+ constructor(
436
+ name: string = 'WebrpcStreamFinished',
437
+ code: number = -10,
438
+ message: string = 'stream finished',
439
+ status: number = 0,
440
+ cause?: string
441
+ ) {
442
+ super(name, code, message, status, cause)
443
+ Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype)
444
+ }
445
+ }
446
+
447
+
448
+ // Schema errors
449
+
450
+ export class UnauthorizedError extends WebrpcError {
451
+ constructor(
452
+ name: string = 'Unauthorized',
453
+ code: number = 1000,
454
+ message: string = 'Unauthorized access',
455
+ status: number = 0,
456
+ cause?: string
457
+ ) {
458
+ super(name, code, message, status, cause)
459
+ Object.setPrototypeOf(this, UnauthorizedError.prototype)
460
+ }
461
+ }
462
+
463
+ export class PermissionDeniedError extends WebrpcError {
464
+ constructor(
465
+ name: string = 'PermissionDenied',
466
+ code: number = 1001,
467
+ message: string = 'Permission denied',
468
+ status: number = 0,
469
+ cause?: string
470
+ ) {
471
+ super(name, code, message, status, cause)
472
+ Object.setPrototypeOf(this, PermissionDeniedError.prototype)
473
+ }
474
+ }
475
+
476
+ export class SessionExpiredError extends WebrpcError {
477
+ constructor(
478
+ name: string = 'SessionExpired',
479
+ code: number = 1002,
480
+ message: string = 'Session expired',
481
+ status: number = 0,
482
+ cause?: string
483
+ ) {
484
+ super(name, code, message, status, cause)
485
+ Object.setPrototypeOf(this, SessionExpiredError.prototype)
486
+ }
487
+ }
488
+
489
+ export class MethodNotFoundError extends WebrpcError {
490
+ constructor(
491
+ name: string = 'MethodNotFound',
492
+ code: number = 1003,
493
+ message: string = 'Method not found',
494
+ status: number = 0,
495
+ cause?: string
496
+ ) {
497
+ super(name, code, message, status, cause)
498
+ Object.setPrototypeOf(this, MethodNotFoundError.prototype)
499
+ }
500
+ }
501
+
502
+ export class RequestConflictError extends WebrpcError {
503
+ constructor(
504
+ name: string = 'RequestConflict',
505
+ code: number = 1004,
506
+ message: string = 'Conflict with target resource',
507
+ status: number = 0,
508
+ cause?: string
509
+ ) {
510
+ super(name, code, message, status, cause)
511
+ Object.setPrototypeOf(this, RequestConflictError.prototype)
512
+ }
513
+ }
514
+
515
+ export class ServiceDisabledError extends WebrpcError {
516
+ constructor(
517
+ name: string = 'ServiceDisabled',
518
+ code: number = 1005,
519
+ message: string = 'Service disabled',
520
+ status: number = 0,
521
+ cause?: string
522
+ ) {
523
+ super(name, code, message, status, cause)
524
+ Object.setPrototypeOf(this, ServiceDisabledError.prototype)
525
+ }
526
+ }
527
+
528
+ export class TimeoutError extends WebrpcError {
529
+ constructor(
530
+ name: string = 'Timeout',
531
+ code: number = 2000,
532
+ message: string = 'Request timed out',
533
+ status: number = 0,
534
+ cause?: string
535
+ ) {
536
+ super(name, code, message, status, cause)
537
+ Object.setPrototypeOf(this, TimeoutError.prototype)
538
+ }
539
+ }
540
+
541
+ export class InvalidArgumentError extends WebrpcError {
542
+ constructor(
543
+ name: string = 'InvalidArgument',
544
+ code: number = 2001,
545
+ message: string = 'Invalid argument',
546
+ status: number = 0,
547
+ cause?: string
548
+ ) {
549
+ super(name, code, message, status, cause)
550
+ Object.setPrototypeOf(this, InvalidArgumentError.prototype)
551
+ }
552
+ }
553
+
554
+ export class NotFoundError extends WebrpcError {
555
+ constructor(
556
+ name: string = 'NotFound',
557
+ code: number = 3000,
558
+ message: string = 'Resource not found',
559
+ status: number = 0,
560
+ cause?: string
561
+ ) {
562
+ super(name, code, message, status, cause)
563
+ Object.setPrototypeOf(this, NotFoundError.prototype)
564
+ }
565
+ }
566
+
567
+ export class UserNotFoundError extends WebrpcError {
568
+ constructor(
569
+ name: string = 'UserNotFound',
570
+ code: number = 3001,
571
+ message: string = 'User not found',
572
+ status: number = 0,
573
+ cause?: string
574
+ ) {
575
+ super(name, code, message, status, cause)
576
+ Object.setPrototypeOf(this, UserNotFoundError.prototype)
577
+ }
578
+ }
579
+
580
+ export class ProjectNotFoundError extends WebrpcError {
581
+ constructor(
582
+ name: string = 'ProjectNotFound',
583
+ code: number = 3002,
584
+ message: string = 'Project not found',
585
+ status: number = 0,
586
+ cause?: string
587
+ ) {
588
+ super(name, code, message, status, cause)
589
+ Object.setPrototypeOf(this, ProjectNotFoundError.prototype)
590
+ }
591
+ }
592
+
593
+ export class AlreadyCollaboratorError extends WebrpcError {
594
+ constructor(
595
+ name: string = 'AlreadyCollaborator',
596
+ code: number = 4001,
597
+ message: string = 'Already a collaborator',
598
+ status: number = 0,
599
+ cause?: string
600
+ ) {
601
+ super(name, code, message, status, cause)
602
+ Object.setPrototypeOf(this, AlreadyCollaboratorError.prototype)
603
+ }
604
+ }
605
+
606
+
607
+ export enum errors {
608
+ WebrpcEndpoint = 'WebrpcEndpoint',
609
+ WebrpcRequestFailed = 'WebrpcRequestFailed',
610
+ WebrpcBadRoute = 'WebrpcBadRoute',
611
+ WebrpcBadMethod = 'WebrpcBadMethod',
612
+ WebrpcBadRequest = 'WebrpcBadRequest',
613
+ WebrpcBadResponse = 'WebrpcBadResponse',
614
+ WebrpcServerPanic = 'WebrpcServerPanic',
615
+ WebrpcInternalError = 'WebrpcInternalError',
616
+ WebrpcClientDisconnected = 'WebrpcClientDisconnected',
617
+ WebrpcStreamLost = 'WebrpcStreamLost',
618
+ WebrpcStreamFinished = 'WebrpcStreamFinished',
619
+ Unauthorized = 'Unauthorized',
620
+ PermissionDenied = 'PermissionDenied',
621
+ SessionExpired = 'SessionExpired',
622
+ MethodNotFound = 'MethodNotFound',
623
+ RequestConflict = 'RequestConflict',
624
+ ServiceDisabled = 'ServiceDisabled',
625
+ Timeout = 'Timeout',
626
+ InvalidArgument = 'InvalidArgument',
627
+ NotFound = 'NotFound',
628
+ UserNotFound = 'UserNotFound',
629
+ ProjectNotFound = 'ProjectNotFound',
630
+ }
631
+
632
+ export enum WebrpcErrorCodes {
633
+ WebrpcEndpoint = 0,
634
+ WebrpcRequestFailed = -1,
635
+ WebrpcBadRoute = -2,
636
+ WebrpcBadMethod = -3,
637
+ WebrpcBadRequest = -4,
638
+ WebrpcBadResponse = -5,
639
+ WebrpcServerPanic = -6,
640
+ WebrpcInternalError = -7,
641
+ WebrpcClientDisconnected = -8,
642
+ WebrpcStreamLost = -9,
643
+ WebrpcStreamFinished = -10,
644
+ Unauthorized = 1000,
645
+ PermissionDenied = 1001,
646
+ SessionExpired = 1002,
647
+ MethodNotFound = 1003,
648
+ RequestConflict = 1004,
649
+ ServiceDisabled = 1005,
650
+ Timeout = 2000,
651
+ InvalidArgument = 2001,
652
+ NotFound = 3000,
653
+ UserNotFound = 3001,
654
+ ProjectNotFound = 3002,
655
+ }
656
+
657
+ export const webrpcErrorByCode: { [code: number]: any } = {
658
+ [0]: WebrpcEndpointError,
659
+ [-1]: WebrpcRequestFailedError,
660
+ [-2]: WebrpcBadRouteError,
661
+ [-3]: WebrpcBadMethodError,
662
+ [-4]: WebrpcBadRequestError,
663
+ [-5]: WebrpcBadResponseError,
664
+ [-6]: WebrpcServerPanicError,
665
+ [-7]: WebrpcInternalErrorError,
666
+ [-8]: WebrpcClientDisconnectedError,
667
+ [-9]: WebrpcStreamLostError,
668
+ [-10]: WebrpcStreamFinishedError,
669
+ [1000]: UnauthorizedError,
670
+ [1001]: PermissionDeniedError,
671
+ [1002]: SessionExpiredError,
672
+ [1003]: MethodNotFoundError,
673
+ [1004]: RequestConflictError,
674
+ [1005]: ServiceDisabledError,
675
+ [2000]: TimeoutError,
676
+ [2001]: InvalidArgumentError,
677
+ [3000]: NotFoundError,
678
+ [3001]: UserNotFoundError,
679
+ [3002]: ProjectNotFoundError,
680
+ }
681
+
682
+ export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>
683
+