@0xsequence/relayer 1.9.24 → 1.9.26

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.
@@ -1,9 +1,9 @@
1
1
  /* eslint-disable */
2
- // sequence-relayer v0.4.1 13cf0e854e8127ae83218cc188ef0e7456241c96
2
+ // sequence-relayer v0.4.1 1e27d0fd295aa5897878939595ef0c6adc54b1a3
3
3
  // --
4
- // Code generated by webrpc-gen@v0.12.x-dev with typescript@v0.10.0 generator. DO NOT EDIT.
4
+ // Code generated by webrpc-gen@v0.18.6 with typescript generator. DO NOT EDIT.
5
5
  //
6
- // webrpc-gen -schema=relayer.ridl -target=typescript@v0.10.0 -client -out=./clients/relayer.gen.ts
6
+ // webrpc-gen -schema=relayer.ridl -target=typescript -client -out=./clients/relayer.gen.ts
7
7
 
8
8
  // WebRPC description and code-gen version
9
9
  export const WebRPCVersion = 'v1'
@@ -12,7 +12,7 @@ export const WebRPCVersion = 'v1'
12
12
  export const WebRPCSchemaVersion = 'v0.4.1'
13
13
 
14
14
  // Schema hash generated from your RIDL schema
15
- export const WebRPCSchemaHash = '13cf0e854e8127ae83218cc188ef0e7456241c96'
15
+ export const WebRPCSchemaHash = '1e27d0fd295aa5897878939595ef0c6adc54b1a3'
16
16
 
17
17
  //
18
18
  // Types
@@ -27,6 +27,7 @@ export enum ETHTxnStatus {
27
27
  PARTIALLY_FAILED = 'PARTIALLY_FAILED',
28
28
  FAILED = 'FAILED'
29
29
  }
30
+
30
31
  export enum TransferType {
31
32
  SEND = 'SEND',
32
33
  RECEIVE = 'RECEIVE',
@@ -35,11 +36,13 @@ export enum TransferType {
35
36
  BURN = 'BURN',
36
37
  UNKNOWN = 'UNKNOWN'
37
38
  }
39
+
38
40
  export enum FeeTokenType {
39
41
  UNKNOWN = 'UNKNOWN',
40
42
  ERC20_TOKEN = 'ERC20_TOKEN',
41
43
  ERC1155_TOKEN = 'ERC1155_TOKEN'
42
44
  }
45
+
43
46
  export enum SortOrder {
44
47
  DESC = 'DESC',
45
48
  ASC = 'ASC'
@@ -59,6 +62,7 @@ export interface RuntimeStatus {
59
62
  ver: string
60
63
  branch: string
61
64
  commitHash: string
65
+ useEIP1559: boolean
62
66
  senders: Array<SenderStatus>
63
67
  checks: RuntimeChecks
64
68
  numTxnsRelayed: NumTxnsRelayed
@@ -267,40 +271,63 @@ export interface SortBy {
267
271
  }
268
272
 
269
273
  export interface Relayer {
270
- ping(headers?: object): Promise<PingReturn>
271
- version(headers?: object): Promise<VersionReturn>
272
- runtimeStatus(headers?: object): Promise<RuntimeStatusReturn>
273
- getSequenceContext(headers?: object): Promise<GetSequenceContextReturn>
274
- getChainID(headers?: object): Promise<GetChainIDReturn>
275
- sendMetaTxn(args: SendMetaTxnArgs, headers?: object): Promise<SendMetaTxnReturn>
276
- getMetaTxnNonce(args: GetMetaTxnNonceArgs, headers?: object): Promise<GetMetaTxnNonceReturn>
277
- getMetaTxnReceipt(args: GetMetaTxnReceiptArgs, headers?: object): Promise<GetMetaTxnReceiptReturn>
278
- simulate(args: SimulateArgs, headers?: object): Promise<SimulateReturn>
279
- updateMetaTxnGasLimits(args: UpdateMetaTxnGasLimitsArgs, headers?: object): Promise<UpdateMetaTxnGasLimitsReturn>
280
- feeTokens(headers?: object): Promise<FeeTokensReturn>
281
- feeOptions(args: FeeOptionsArgs, headers?: object): Promise<FeeOptionsReturn>
282
- getMetaTxnNetworkFeeOptions(args: GetMetaTxnNetworkFeeOptionsArgs, headers?: object): Promise<GetMetaTxnNetworkFeeOptionsReturn>
283
- getMetaTransactions(args: GetMetaTransactionsArgs, headers?: object): Promise<GetMetaTransactionsReturn>
284
- sentTransactions(args: SentTransactionsArgs, headers?: object): Promise<SentTransactionsReturn>
285
- pendingTransactions(args: PendingTransactionsArgs, headers?: object): Promise<PendingTransactionsReturn>
286
- getGasTank(args: GetGasTankArgs, headers?: object): Promise<GetGasTankReturn>
287
- addGasTank(args: AddGasTankArgs, headers?: object): Promise<AddGasTankReturn>
288
- updateGasTank(args: UpdateGasTankArgs, headers?: object): Promise<UpdateGasTankReturn>
289
- getGasSponsor(args: GetGasSponsorArgs, headers?: object): Promise<GetGasSponsorReturn>
290
- listGasSponsors(args: ListGasSponsorsArgs, headers?: object): Promise<ListGasSponsorsReturn>
291
- addGasSponsor(args: AddGasSponsorArgs, headers?: object): Promise<AddGasSponsorReturn>
292
- updateGasSponsor(args: UpdateGasSponsorArgs, headers?: object): Promise<UpdateGasSponsorReturn>
293
- removeGasSponsor(args: RemoveGasSponsorArgs, headers?: object): Promise<RemoveGasSponsorReturn>
294
- reportGasSponsorUsage(args: ReportGasSponsorUsageArgs, headers?: object): Promise<ReportGasSponsorUsageReturn>
274
+ ping(headers?: object, signal?: AbortSignal): Promise<PingReturn>
275
+ version(headers?: object, signal?: AbortSignal): Promise<VersionReturn>
276
+ runtimeStatus(headers?: object, signal?: AbortSignal): Promise<RuntimeStatusReturn>
277
+ getSequenceContext(headers?: object, signal?: AbortSignal): Promise<GetSequenceContextReturn>
278
+ getChainID(headers?: object, signal?: AbortSignal): Promise<GetChainIDReturn>
279
+ sendMetaTxn(args: SendMetaTxnArgs, headers?: object, signal?: AbortSignal): Promise<SendMetaTxnReturn>
280
+ getMetaTxnNonce(args: GetMetaTxnNonceArgs, headers?: object, signal?: AbortSignal): Promise<GetMetaTxnNonceReturn>
281
+ getMetaTxnReceipt(args: GetMetaTxnReceiptArgs, headers?: object, signal?: AbortSignal): Promise<GetMetaTxnReceiptReturn>
282
+ simulate(args: SimulateArgs, headers?: object, signal?: AbortSignal): Promise<SimulateReturn>
283
+ updateMetaTxnGasLimits(
284
+ args: UpdateMetaTxnGasLimitsArgs,
285
+ headers?: object,
286
+ signal?: AbortSignal
287
+ ): Promise<UpdateMetaTxnGasLimitsReturn>
288
+ feeTokens(headers?: object, signal?: AbortSignal): Promise<FeeTokensReturn>
289
+ feeOptions(args: FeeOptionsArgs, headers?: object, signal?: AbortSignal): Promise<FeeOptionsReturn>
290
+ getMetaTxnNetworkFeeOptions(
291
+ args: GetMetaTxnNetworkFeeOptionsArgs,
292
+ headers?: object,
293
+ signal?: AbortSignal
294
+ ): Promise<GetMetaTxnNetworkFeeOptionsReturn>
295
+ getMetaTransactions(args: GetMetaTransactionsArgs, headers?: object, signal?: AbortSignal): Promise<GetMetaTransactionsReturn>
296
+ sentTransactions(args: SentTransactionsArgs, headers?: object, signal?: AbortSignal): Promise<SentTransactionsReturn>
297
+ pendingTransactions(args: PendingTransactionsArgs, headers?: object, signal?: AbortSignal): Promise<PendingTransactionsReturn>
298
+ getGasTank(args: GetGasTankArgs, headers?: object, signal?: AbortSignal): Promise<GetGasTankReturn>
299
+ addGasTank(args: AddGasTankArgs, headers?: object, signal?: AbortSignal): Promise<AddGasTankReturn>
300
+ updateGasTank(args: UpdateGasTankArgs, headers?: object, signal?: AbortSignal): Promise<UpdateGasTankReturn>
301
+ getGasSponsor(args: GetGasSponsorArgs, headers?: object, signal?: AbortSignal): Promise<GetGasSponsorReturn>
302
+ addressGasSponsors(args: AddressGasSponsorsArgs, headers?: object, signal?: AbortSignal): Promise<AddressGasSponsorsReturn>
303
+ listGasSponsors(args: ListGasSponsorsArgs, headers?: object, signal?: AbortSignal): Promise<ListGasSponsorsReturn>
304
+ addGasSponsor(args: AddGasSponsorArgs, headers?: object, signal?: AbortSignal): Promise<AddGasSponsorReturn>
305
+ updateGasSponsor(args: UpdateGasSponsorArgs, headers?: object, signal?: AbortSignal): Promise<UpdateGasSponsorReturn>
306
+ removeGasSponsor(args: RemoveGasSponsorArgs, headers?: object, signal?: AbortSignal): Promise<RemoveGasSponsorReturn>
307
+ reportGasSponsorUsage(
308
+ args: ReportGasSponsorUsageArgs,
309
+ headers?: object,
310
+ signal?: AbortSignal
311
+ ): Promise<ReportGasSponsorUsageReturn>
295
312
  nextGasTankBalanceAdjustmentNonce(
296
313
  args: NextGasTankBalanceAdjustmentNonceArgs,
297
- headers?: object
314
+ headers?: object,
315
+ signal?: AbortSignal
298
316
  ): Promise<NextGasTankBalanceAdjustmentNonceReturn>
299
- adjustGasTankBalance(args: AdjustGasTankBalanceArgs, headers?: object): Promise<AdjustGasTankBalanceReturn>
300
- getGasTankBalanceAdjustment(args: GetGasTankBalanceAdjustmentArgs, headers?: object): Promise<GetGasTankBalanceAdjustmentReturn>
317
+ adjustGasTankBalance(
318
+ args: AdjustGasTankBalanceArgs,
319
+ headers?: object,
320
+ signal?: AbortSignal
321
+ ): Promise<AdjustGasTankBalanceReturn>
322
+ getGasTankBalanceAdjustment(
323
+ args: GetGasTankBalanceAdjustmentArgs,
324
+ headers?: object,
325
+ signal?: AbortSignal
326
+ ): Promise<GetGasTankBalanceAdjustmentReturn>
301
327
  listGasTankBalanceAdjustments(
302
328
  args: ListGasTankBalanceAdjustmentsArgs,
303
- headers?: object
329
+ headers?: object,
330
+ signal?: AbortSignal
304
331
  ): Promise<ListGasTankBalanceAdjustmentsReturn>
305
332
  }
306
333
 
@@ -458,6 +485,15 @@ export interface GetGasSponsorArgs {
458
485
  export interface GetGasSponsorReturn {
459
486
  gasSponsor: GasSponsor
460
487
  }
488
+ export interface AddressGasSponsorsArgs {
489
+ address: string
490
+ page?: Page
491
+ }
492
+
493
+ export interface AddressGasSponsorsReturn {
494
+ page: Page
495
+ gasSponsors: Array<GasSponsor>
496
+ }
461
497
  export interface ListGasSponsorsArgs {
462
498
  projectId: number
463
499
  gasTankId: number
@@ -559,334 +595,518 @@ export class Relayer implements Relayer {
559
595
  return this.hostname + this.path + name
560
596
  }
561
597
 
562
- ping = (headers?: object): Promise<PingReturn> => {
563
- return this.fetch(this.url('Ping'), createHTTPRequest({}, headers)).then(res => {
564
- return buildResponse(res).then(_data => {
565
- return {
566
- status: <boolean>_data.status
567
- }
568
- })
569
- })
598
+ ping = (headers?: object, signal?: AbortSignal): Promise<PingReturn> => {
599
+ return this.fetch(this.url('Ping'), createHTTPRequest({}, headers, signal)).then(
600
+ res => {
601
+ return buildResponse(res).then(_data => {
602
+ return {
603
+ status: <boolean>_data.status
604
+ }
605
+ })
606
+ },
607
+ error => {
608
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
609
+ }
610
+ )
570
611
  }
571
612
 
572
- version = (headers?: object): Promise<VersionReturn> => {
573
- return this.fetch(this.url('Version'), createHTTPRequest({}, headers)).then(res => {
574
- return buildResponse(res).then(_data => {
575
- return {
576
- version: <Version>_data.version
577
- }
578
- })
579
- })
613
+ version = (headers?: object, signal?: AbortSignal): Promise<VersionReturn> => {
614
+ return this.fetch(this.url('Version'), createHTTPRequest({}, headers, signal)).then(
615
+ res => {
616
+ return buildResponse(res).then(_data => {
617
+ return {
618
+ version: <Version>_data.version
619
+ }
620
+ })
621
+ },
622
+ error => {
623
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
624
+ }
625
+ )
580
626
  }
581
627
 
582
- runtimeStatus = (headers?: object): Promise<RuntimeStatusReturn> => {
583
- return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers)).then(res => {
584
- return buildResponse(res).then(_data => {
585
- return {
586
- status: <RuntimeStatus>_data.status
587
- }
588
- })
589
- })
628
+ runtimeStatus = (headers?: object, signal?: AbortSignal): Promise<RuntimeStatusReturn> => {
629
+ return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers, signal)).then(
630
+ res => {
631
+ return buildResponse(res).then(_data => {
632
+ return {
633
+ status: <RuntimeStatus>_data.status
634
+ }
635
+ })
636
+ },
637
+ error => {
638
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
639
+ }
640
+ )
590
641
  }
591
642
 
592
- getSequenceContext = (headers?: object): Promise<GetSequenceContextReturn> => {
593
- return this.fetch(this.url('GetSequenceContext'), createHTTPRequest({}, headers)).then(res => {
594
- return buildResponse(res).then(_data => {
595
- return {
596
- data: <SequenceContext>_data.data
597
- }
598
- })
599
- })
643
+ getSequenceContext = (headers?: object, signal?: AbortSignal): Promise<GetSequenceContextReturn> => {
644
+ return this.fetch(this.url('GetSequenceContext'), createHTTPRequest({}, headers, signal)).then(
645
+ res => {
646
+ return buildResponse(res).then(_data => {
647
+ return {
648
+ data: <SequenceContext>_data.data
649
+ }
650
+ })
651
+ },
652
+ error => {
653
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
654
+ }
655
+ )
600
656
  }
601
657
 
602
- getChainID = (headers?: object): Promise<GetChainIDReturn> => {
603
- return this.fetch(this.url('GetChainID'), createHTTPRequest({}, headers)).then(res => {
604
- return buildResponse(res).then(_data => {
605
- return {
606
- chainID: <number>_data.chainID
607
- }
608
- })
609
- })
658
+ getChainID = (headers?: object, signal?: AbortSignal): Promise<GetChainIDReturn> => {
659
+ return this.fetch(this.url('GetChainID'), createHTTPRequest({}, headers, signal)).then(
660
+ res => {
661
+ return buildResponse(res).then(_data => {
662
+ return {
663
+ chainID: <number>_data.chainID
664
+ }
665
+ })
666
+ },
667
+ error => {
668
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
669
+ }
670
+ )
610
671
  }
611
672
 
612
- sendMetaTxn = (args: SendMetaTxnArgs, headers?: object): Promise<SendMetaTxnReturn> => {
613
- return this.fetch(this.url('SendMetaTxn'), createHTTPRequest(args, headers)).then(res => {
614
- return buildResponse(res).then(_data => {
615
- return {
616
- status: <boolean>_data.status,
617
- txnHash: <string>_data.txnHash
618
- }
619
- })
620
- })
673
+ sendMetaTxn = (args: SendMetaTxnArgs, headers?: object, signal?: AbortSignal): Promise<SendMetaTxnReturn> => {
674
+ return this.fetch(this.url('SendMetaTxn'), createHTTPRequest(args, headers, signal)).then(
675
+ res => {
676
+ return buildResponse(res).then(_data => {
677
+ return {
678
+ status: <boolean>_data.status,
679
+ txnHash: <string>_data.txnHash
680
+ }
681
+ })
682
+ },
683
+ error => {
684
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
685
+ }
686
+ )
621
687
  }
622
688
 
623
- getMetaTxnNonce = (args: GetMetaTxnNonceArgs, headers?: object): Promise<GetMetaTxnNonceReturn> => {
624
- return this.fetch(this.url('GetMetaTxnNonce'), createHTTPRequest(args, headers)).then(res => {
625
- return buildResponse(res).then(_data => {
626
- return {
627
- nonce: <string>_data.nonce
628
- }
629
- })
630
- })
689
+ getMetaTxnNonce = (args: GetMetaTxnNonceArgs, headers?: object, signal?: AbortSignal): Promise<GetMetaTxnNonceReturn> => {
690
+ return this.fetch(this.url('GetMetaTxnNonce'), createHTTPRequest(args, headers, signal)).then(
691
+ res => {
692
+ return buildResponse(res).then(_data => {
693
+ return {
694
+ nonce: <string>_data.nonce
695
+ }
696
+ })
697
+ },
698
+ error => {
699
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
700
+ }
701
+ )
631
702
  }
632
703
 
633
- getMetaTxnReceipt = (args: GetMetaTxnReceiptArgs, headers?: object): Promise<GetMetaTxnReceiptReturn> => {
634
- return this.fetch(this.url('GetMetaTxnReceipt'), createHTTPRequest(args, headers)).then(res => {
635
- return buildResponse(res).then(_data => {
636
- return {
637
- receipt: <MetaTxnReceipt>_data.receipt
638
- }
639
- })
640
- })
704
+ getMetaTxnReceipt = (args: GetMetaTxnReceiptArgs, headers?: object, signal?: AbortSignal): Promise<GetMetaTxnReceiptReturn> => {
705
+ return this.fetch(this.url('GetMetaTxnReceipt'), createHTTPRequest(args, headers, signal)).then(
706
+ res => {
707
+ return buildResponse(res).then(_data => {
708
+ return {
709
+ receipt: <MetaTxnReceipt>_data.receipt
710
+ }
711
+ })
712
+ },
713
+ error => {
714
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
715
+ }
716
+ )
641
717
  }
642
718
 
643
- simulate = (args: SimulateArgs, headers?: object): Promise<SimulateReturn> => {
644
- return this.fetch(this.url('Simulate'), createHTTPRequest(args, headers)).then(res => {
645
- return buildResponse(res).then(_data => {
646
- return {
647
- results: <Array<SimulateResult>>_data.results
648
- }
649
- })
650
- })
719
+ simulate = (args: SimulateArgs, headers?: object, signal?: AbortSignal): Promise<SimulateReturn> => {
720
+ return this.fetch(this.url('Simulate'), createHTTPRequest(args, headers, signal)).then(
721
+ res => {
722
+ return buildResponse(res).then(_data => {
723
+ return {
724
+ results: <Array<SimulateResult>>_data.results
725
+ }
726
+ })
727
+ },
728
+ error => {
729
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
730
+ }
731
+ )
651
732
  }
652
733
 
653
- updateMetaTxnGasLimits = (args: UpdateMetaTxnGasLimitsArgs, headers?: object): Promise<UpdateMetaTxnGasLimitsReturn> => {
654
- return this.fetch(this.url('UpdateMetaTxnGasLimits'), createHTTPRequest(args, headers)).then(res => {
655
- return buildResponse(res).then(_data => {
656
- return {
657
- payload: <string>_data.payload
658
- }
659
- })
660
- })
734
+ updateMetaTxnGasLimits = (
735
+ args: UpdateMetaTxnGasLimitsArgs,
736
+ headers?: object,
737
+ signal?: AbortSignal
738
+ ): Promise<UpdateMetaTxnGasLimitsReturn> => {
739
+ return this.fetch(this.url('UpdateMetaTxnGasLimits'), createHTTPRequest(args, headers, signal)).then(
740
+ res => {
741
+ return buildResponse(res).then(_data => {
742
+ return {
743
+ payload: <string>_data.payload
744
+ }
745
+ })
746
+ },
747
+ error => {
748
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
749
+ }
750
+ )
661
751
  }
662
752
 
663
- feeTokens = (headers?: object): Promise<FeeTokensReturn> => {
664
- return this.fetch(this.url('FeeTokens'), createHTTPRequest({}, headers)).then(res => {
665
- return buildResponse(res).then(_data => {
666
- return {
667
- isFeeRequired: <boolean>_data.isFeeRequired,
668
- tokens: <Array<FeeToken>>_data.tokens
669
- }
670
- })
671
- })
753
+ feeTokens = (headers?: object, signal?: AbortSignal): Promise<FeeTokensReturn> => {
754
+ return this.fetch(this.url('FeeTokens'), createHTTPRequest({}, headers, signal)).then(
755
+ res => {
756
+ return buildResponse(res).then(_data => {
757
+ return {
758
+ isFeeRequired: <boolean>_data.isFeeRequired,
759
+ tokens: <Array<FeeToken>>_data.tokens
760
+ }
761
+ })
762
+ },
763
+ error => {
764
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
765
+ }
766
+ )
672
767
  }
673
768
 
674
- feeOptions = (args: FeeOptionsArgs, headers?: object): Promise<FeeOptionsReturn> => {
675
- return this.fetch(this.url('FeeOptions'), createHTTPRequest(args, headers)).then(res => {
676
- return buildResponse(res).then(_data => {
677
- return {
678
- options: <Array<FeeOption>>_data.options,
679
- sponsored: <boolean>_data.sponsored,
680
- quote: <string>_data.quote
681
- }
682
- })
683
- })
769
+ feeOptions = (args: FeeOptionsArgs, headers?: object, signal?: AbortSignal): Promise<FeeOptionsReturn> => {
770
+ return this.fetch(this.url('FeeOptions'), createHTTPRequest(args, headers, signal)).then(
771
+ res => {
772
+ return buildResponse(res).then(_data => {
773
+ return {
774
+ options: <Array<FeeOption>>_data.options,
775
+ sponsored: <boolean>_data.sponsored,
776
+ quote: <string>_data.quote
777
+ }
778
+ })
779
+ },
780
+ error => {
781
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
782
+ }
783
+ )
684
784
  }
685
785
 
686
786
  getMetaTxnNetworkFeeOptions = (
687
787
  args: GetMetaTxnNetworkFeeOptionsArgs,
688
- headers?: object
788
+ headers?: object,
789
+ signal?: AbortSignal
689
790
  ): Promise<GetMetaTxnNetworkFeeOptionsReturn> => {
690
- return this.fetch(this.url('GetMetaTxnNetworkFeeOptions'), createHTTPRequest(args, headers)).then(res => {
691
- return buildResponse(res).then(_data => {
692
- return {
693
- options: <Array<FeeOption>>_data.options
694
- }
695
- })
696
- })
791
+ return this.fetch(this.url('GetMetaTxnNetworkFeeOptions'), createHTTPRequest(args, headers, signal)).then(
792
+ res => {
793
+ return buildResponse(res).then(_data => {
794
+ return {
795
+ options: <Array<FeeOption>>_data.options
796
+ }
797
+ })
798
+ },
799
+ error => {
800
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
801
+ }
802
+ )
697
803
  }
698
804
 
699
- getMetaTransactions = (args: GetMetaTransactionsArgs, headers?: object): Promise<GetMetaTransactionsReturn> => {
700
- return this.fetch(this.url('GetMetaTransactions'), createHTTPRequest(args, headers)).then(res => {
701
- return buildResponse(res).then(_data => {
702
- return {
703
- page: <Page>_data.page,
704
- transactions: <Array<MetaTxnLog>>_data.transactions
705
- }
706
- })
707
- })
805
+ getMetaTransactions = (
806
+ args: GetMetaTransactionsArgs,
807
+ headers?: object,
808
+ signal?: AbortSignal
809
+ ): Promise<GetMetaTransactionsReturn> => {
810
+ return this.fetch(this.url('GetMetaTransactions'), createHTTPRequest(args, headers, signal)).then(
811
+ res => {
812
+ return buildResponse(res).then(_data => {
813
+ return {
814
+ page: <Page>_data.page,
815
+ transactions: <Array<MetaTxnLog>>_data.transactions
816
+ }
817
+ })
818
+ },
819
+ error => {
820
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
821
+ }
822
+ )
708
823
  }
709
824
 
710
- sentTransactions = (args: SentTransactionsArgs, headers?: object): Promise<SentTransactionsReturn> => {
711
- return this.fetch(this.url('SentTransactions'), createHTTPRequest(args, headers)).then(res => {
712
- return buildResponse(res).then(_data => {
713
- return {
714
- page: <Page>_data.page,
715
- transactions: <Array<Transaction>>_data.transactions
716
- }
717
- })
718
- })
825
+ sentTransactions = (args: SentTransactionsArgs, headers?: object, signal?: AbortSignal): Promise<SentTransactionsReturn> => {
826
+ return this.fetch(this.url('SentTransactions'), createHTTPRequest(args, headers, signal)).then(
827
+ res => {
828
+ return buildResponse(res).then(_data => {
829
+ return {
830
+ page: <Page>_data.page,
831
+ transactions: <Array<Transaction>>_data.transactions
832
+ }
833
+ })
834
+ },
835
+ error => {
836
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
837
+ }
838
+ )
719
839
  }
720
840
 
721
- pendingTransactions = (args: PendingTransactionsArgs, headers?: object): Promise<PendingTransactionsReturn> => {
722
- return this.fetch(this.url('PendingTransactions'), createHTTPRequest(args, headers)).then(res => {
723
- return buildResponse(res).then(_data => {
724
- return {
725
- page: <Page>_data.page,
726
- transactions: <Array<Transaction>>_data.transactions
727
- }
728
- })
729
- })
841
+ pendingTransactions = (
842
+ args: PendingTransactionsArgs,
843
+ headers?: object,
844
+ signal?: AbortSignal
845
+ ): Promise<PendingTransactionsReturn> => {
846
+ return this.fetch(this.url('PendingTransactions'), createHTTPRequest(args, headers, signal)).then(
847
+ res => {
848
+ return buildResponse(res).then(_data => {
849
+ return {
850
+ page: <Page>_data.page,
851
+ transactions: <Array<Transaction>>_data.transactions
852
+ }
853
+ })
854
+ },
855
+ error => {
856
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
857
+ }
858
+ )
730
859
  }
731
860
 
732
- getGasTank = (args: GetGasTankArgs, headers?: object): Promise<GetGasTankReturn> => {
733
- return this.fetch(this.url('GetGasTank'), createHTTPRequest(args, headers)).then(res => {
734
- return buildResponse(res).then(_data => {
735
- return {
736
- gasTank: <GasTank>_data.gasTank
737
- }
738
- })
739
- })
861
+ getGasTank = (args: GetGasTankArgs, headers?: object, signal?: AbortSignal): Promise<GetGasTankReturn> => {
862
+ return this.fetch(this.url('GetGasTank'), createHTTPRequest(args, headers, signal)).then(
863
+ res => {
864
+ return buildResponse(res).then(_data => {
865
+ return {
866
+ gasTank: <GasTank>_data.gasTank
867
+ }
868
+ })
869
+ },
870
+ error => {
871
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
872
+ }
873
+ )
740
874
  }
741
875
 
742
- addGasTank = (args: AddGasTankArgs, headers?: object): Promise<AddGasTankReturn> => {
743
- return this.fetch(this.url('AddGasTank'), createHTTPRequest(args, headers)).then(res => {
744
- return buildResponse(res).then(_data => {
745
- return {
746
- status: <boolean>_data.status,
747
- gasTank: <GasTank>_data.gasTank
748
- }
749
- })
750
- })
876
+ addGasTank = (args: AddGasTankArgs, headers?: object, signal?: AbortSignal): Promise<AddGasTankReturn> => {
877
+ return this.fetch(this.url('AddGasTank'), createHTTPRequest(args, headers, signal)).then(
878
+ res => {
879
+ return buildResponse(res).then(_data => {
880
+ return {
881
+ status: <boolean>_data.status,
882
+ gasTank: <GasTank>_data.gasTank
883
+ }
884
+ })
885
+ },
886
+ error => {
887
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
888
+ }
889
+ )
751
890
  }
752
891
 
753
- updateGasTank = (args: UpdateGasTankArgs, headers?: object): Promise<UpdateGasTankReturn> => {
754
- return this.fetch(this.url('UpdateGasTank'), createHTTPRequest(args, headers)).then(res => {
755
- return buildResponse(res).then(_data => {
756
- return {
757
- status: <boolean>_data.status,
758
- gasTank: <GasTank>_data.gasTank
759
- }
760
- })
761
- })
892
+ updateGasTank = (args: UpdateGasTankArgs, headers?: object, signal?: AbortSignal): Promise<UpdateGasTankReturn> => {
893
+ return this.fetch(this.url('UpdateGasTank'), createHTTPRequest(args, headers, signal)).then(
894
+ res => {
895
+ return buildResponse(res).then(_data => {
896
+ return {
897
+ status: <boolean>_data.status,
898
+ gasTank: <GasTank>_data.gasTank
899
+ }
900
+ })
901
+ },
902
+ error => {
903
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
904
+ }
905
+ )
762
906
  }
763
907
 
764
- getGasSponsor = (args: GetGasSponsorArgs, headers?: object): Promise<GetGasSponsorReturn> => {
765
- return this.fetch(this.url('GetGasSponsor'), createHTTPRequest(args, headers)).then(res => {
766
- return buildResponse(res).then(_data => {
767
- return {
768
- gasSponsor: <GasSponsor>_data.gasSponsor
769
- }
770
- })
771
- })
908
+ getGasSponsor = (args: GetGasSponsorArgs, headers?: object, signal?: AbortSignal): Promise<GetGasSponsorReturn> => {
909
+ return this.fetch(this.url('GetGasSponsor'), createHTTPRequest(args, headers, signal)).then(
910
+ res => {
911
+ return buildResponse(res).then(_data => {
912
+ return {
913
+ gasSponsor: <GasSponsor>_data.gasSponsor
914
+ }
915
+ })
916
+ },
917
+ error => {
918
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
919
+ }
920
+ )
772
921
  }
773
922
 
774
- listGasSponsors = (args: ListGasSponsorsArgs, headers?: object): Promise<ListGasSponsorsReturn> => {
775
- return this.fetch(this.url('ListGasSponsors'), createHTTPRequest(args, headers)).then(res => {
776
- return buildResponse(res).then(_data => {
777
- return {
778
- page: <Page>_data.page,
779
- gasSponsors: <Array<GasSponsor>>_data.gasSponsors
780
- }
781
- })
782
- })
923
+ addressGasSponsors = (
924
+ args: AddressGasSponsorsArgs,
925
+ headers?: object,
926
+ signal?: AbortSignal
927
+ ): Promise<AddressGasSponsorsReturn> => {
928
+ return this.fetch(this.url('AddressGasSponsors'), createHTTPRequest(args, headers, signal)).then(
929
+ res => {
930
+ return buildResponse(res).then(_data => {
931
+ return {
932
+ page: <Page>_data.page,
933
+ gasSponsors: <Array<GasSponsor>>_data.gasSponsors
934
+ }
935
+ })
936
+ },
937
+ error => {
938
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
939
+ }
940
+ )
783
941
  }
784
942
 
785
- addGasSponsor = (args: AddGasSponsorArgs, headers?: object): Promise<AddGasSponsorReturn> => {
786
- return this.fetch(this.url('AddGasSponsor'), createHTTPRequest(args, headers)).then(res => {
787
- return buildResponse(res).then(_data => {
788
- return {
789
- status: <boolean>_data.status,
790
- gasSponsor: <GasSponsor>_data.gasSponsor
791
- }
792
- })
793
- })
943
+ listGasSponsors = (args: ListGasSponsorsArgs, headers?: object, signal?: AbortSignal): Promise<ListGasSponsorsReturn> => {
944
+ return this.fetch(this.url('ListGasSponsors'), createHTTPRequest(args, headers, signal)).then(
945
+ res => {
946
+ return buildResponse(res).then(_data => {
947
+ return {
948
+ page: <Page>_data.page,
949
+ gasSponsors: <Array<GasSponsor>>_data.gasSponsors
950
+ }
951
+ })
952
+ },
953
+ error => {
954
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
955
+ }
956
+ )
794
957
  }
795
958
 
796
- updateGasSponsor = (args: UpdateGasSponsorArgs, headers?: object): Promise<UpdateGasSponsorReturn> => {
797
- return this.fetch(this.url('UpdateGasSponsor'), createHTTPRequest(args, headers)).then(res => {
798
- return buildResponse(res).then(_data => {
799
- return {
800
- status: <boolean>_data.status,
801
- gasSponsor: <GasSponsor>_data.gasSponsor
802
- }
803
- })
804
- })
959
+ addGasSponsor = (args: AddGasSponsorArgs, headers?: object, signal?: AbortSignal): Promise<AddGasSponsorReturn> => {
960
+ return this.fetch(this.url('AddGasSponsor'), createHTTPRequest(args, headers, signal)).then(
961
+ res => {
962
+ return buildResponse(res).then(_data => {
963
+ return {
964
+ status: <boolean>_data.status,
965
+ gasSponsor: <GasSponsor>_data.gasSponsor
966
+ }
967
+ })
968
+ },
969
+ error => {
970
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
971
+ }
972
+ )
805
973
  }
806
974
 
807
- removeGasSponsor = (args: RemoveGasSponsorArgs, headers?: object): Promise<RemoveGasSponsorReturn> => {
808
- return this.fetch(this.url('RemoveGasSponsor'), createHTTPRequest(args, headers)).then(res => {
809
- return buildResponse(res).then(_data => {
810
- return {
811
- status: <boolean>_data.status
812
- }
813
- })
814
- })
975
+ updateGasSponsor = (args: UpdateGasSponsorArgs, headers?: object, signal?: AbortSignal): Promise<UpdateGasSponsorReturn> => {
976
+ return this.fetch(this.url('UpdateGasSponsor'), createHTTPRequest(args, headers, signal)).then(
977
+ res => {
978
+ return buildResponse(res).then(_data => {
979
+ return {
980
+ status: <boolean>_data.status,
981
+ gasSponsor: <GasSponsor>_data.gasSponsor
982
+ }
983
+ })
984
+ },
985
+ error => {
986
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
987
+ }
988
+ )
815
989
  }
816
990
 
817
- reportGasSponsorUsage = (args: ReportGasSponsorUsageArgs, headers?: object): Promise<ReportGasSponsorUsageReturn> => {
818
- return this.fetch(this.url('ReportGasSponsorUsage'), createHTTPRequest(args, headers)).then(res => {
819
- return buildResponse(res).then(_data => {
820
- return {
821
- gasSponsorUsage: <Array<GasSponsorUsage>>_data.gasSponsorUsage
822
- }
823
- })
824
- })
991
+ removeGasSponsor = (args: RemoveGasSponsorArgs, headers?: object, signal?: AbortSignal): Promise<RemoveGasSponsorReturn> => {
992
+ return this.fetch(this.url('RemoveGasSponsor'), createHTTPRequest(args, headers, signal)).then(
993
+ res => {
994
+ return buildResponse(res).then(_data => {
995
+ return {
996
+ status: <boolean>_data.status
997
+ }
998
+ })
999
+ },
1000
+ error => {
1001
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1002
+ }
1003
+ )
1004
+ }
1005
+
1006
+ reportGasSponsorUsage = (
1007
+ args: ReportGasSponsorUsageArgs,
1008
+ headers?: object,
1009
+ signal?: AbortSignal
1010
+ ): Promise<ReportGasSponsorUsageReturn> => {
1011
+ return this.fetch(this.url('ReportGasSponsorUsage'), createHTTPRequest(args, headers, signal)).then(
1012
+ res => {
1013
+ return buildResponse(res).then(_data => {
1014
+ return {
1015
+ gasSponsorUsage: <Array<GasSponsorUsage>>_data.gasSponsorUsage
1016
+ }
1017
+ })
1018
+ },
1019
+ error => {
1020
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1021
+ }
1022
+ )
825
1023
  }
826
1024
 
827
1025
  nextGasTankBalanceAdjustmentNonce = (
828
1026
  args: NextGasTankBalanceAdjustmentNonceArgs,
829
- headers?: object
1027
+ headers?: object,
1028
+ signal?: AbortSignal
830
1029
  ): Promise<NextGasTankBalanceAdjustmentNonceReturn> => {
831
- return this.fetch(this.url('NextGasTankBalanceAdjustmentNonce'), createHTTPRequest(args, headers)).then(res => {
832
- return buildResponse(res).then(_data => {
833
- return {
834
- nonce: <number>_data.nonce
835
- }
836
- })
837
- })
1030
+ return this.fetch(this.url('NextGasTankBalanceAdjustmentNonce'), createHTTPRequest(args, headers, signal)).then(
1031
+ res => {
1032
+ return buildResponse(res).then(_data => {
1033
+ return {
1034
+ nonce: <number>_data.nonce
1035
+ }
1036
+ })
1037
+ },
1038
+ error => {
1039
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1040
+ }
1041
+ )
838
1042
  }
839
1043
 
840
- adjustGasTankBalance = (args: AdjustGasTankBalanceArgs, headers?: object): Promise<AdjustGasTankBalanceReturn> => {
841
- return this.fetch(this.url('AdjustGasTankBalance'), createHTTPRequest(args, headers)).then(res => {
842
- return buildResponse(res).then(_data => {
843
- return {
844
- status: <boolean>_data.status,
845
- adjustment: <GasTankBalanceAdjustment>_data.adjustment
846
- }
847
- })
848
- })
1044
+ adjustGasTankBalance = (
1045
+ args: AdjustGasTankBalanceArgs,
1046
+ headers?: object,
1047
+ signal?: AbortSignal
1048
+ ): Promise<AdjustGasTankBalanceReturn> => {
1049
+ return this.fetch(this.url('AdjustGasTankBalance'), createHTTPRequest(args, headers, signal)).then(
1050
+ res => {
1051
+ return buildResponse(res).then(_data => {
1052
+ return {
1053
+ status: <boolean>_data.status,
1054
+ adjustment: <GasTankBalanceAdjustment>_data.adjustment
1055
+ }
1056
+ })
1057
+ },
1058
+ error => {
1059
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1060
+ }
1061
+ )
849
1062
  }
850
1063
 
851
1064
  getGasTankBalanceAdjustment = (
852
1065
  args: GetGasTankBalanceAdjustmentArgs,
853
- headers?: object
1066
+ headers?: object,
1067
+ signal?: AbortSignal
854
1068
  ): Promise<GetGasTankBalanceAdjustmentReturn> => {
855
- return this.fetch(this.url('GetGasTankBalanceAdjustment'), createHTTPRequest(args, headers)).then(res => {
856
- return buildResponse(res).then(_data => {
857
- return {
858
- adjustment: <GasTankBalanceAdjustment>_data.adjustment
859
- }
860
- })
861
- })
1069
+ return this.fetch(this.url('GetGasTankBalanceAdjustment'), createHTTPRequest(args, headers, signal)).then(
1070
+ res => {
1071
+ return buildResponse(res).then(_data => {
1072
+ return {
1073
+ adjustment: <GasTankBalanceAdjustment>_data.adjustment
1074
+ }
1075
+ })
1076
+ },
1077
+ error => {
1078
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1079
+ }
1080
+ )
862
1081
  }
863
1082
 
864
1083
  listGasTankBalanceAdjustments = (
865
1084
  args: ListGasTankBalanceAdjustmentsArgs,
866
- headers?: object
1085
+ headers?: object,
1086
+ signal?: AbortSignal
867
1087
  ): Promise<ListGasTankBalanceAdjustmentsReturn> => {
868
- return this.fetch(this.url('ListGasTankBalanceAdjustments'), createHTTPRequest(args, headers)).then(res => {
869
- return buildResponse(res).then(_data => {
870
- return {
871
- page: <Page>_data.page,
872
- adjustments: <Array<GasTankBalanceAdjustment>>_data.adjustments
873
- }
874
- })
875
- })
1088
+ return this.fetch(this.url('ListGasTankBalanceAdjustments'), createHTTPRequest(args, headers, signal)).then(
1089
+ res => {
1090
+ return buildResponse(res).then(_data => {
1091
+ return {
1092
+ page: <Page>_data.page,
1093
+ adjustments: <Array<GasTankBalanceAdjustment>>_data.adjustments
1094
+ }
1095
+ })
1096
+ },
1097
+ error => {
1098
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1099
+ }
1100
+ )
876
1101
  }
877
1102
  }
878
1103
 
879
- export interface WebRPCError extends Error {
880
- code: string
881
- msg: string
882
- status: number
883
- }
884
-
885
- const createHTTPRequest = (body: object = {}, headers: object = {}): object => {
1104
+ const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => {
886
1105
  return {
887
1106
  method: 'POST',
888
1107
  headers: { ...headers, 'Content-Type': 'application/json' },
889
- body: JSON.stringify(body || {})
1108
+ body: JSON.stringify(body || {}),
1109
+ signal
890
1110
  }
891
1111
  }
892
1112
 
@@ -895,14 +1115,347 @@ const buildResponse = (res: Response): Promise<any> => {
895
1115
  let data
896
1116
  try {
897
1117
  data = JSON.parse(text)
898
- } catch (err) {
899
- throw { code: 'unknown', msg: `expecting JSON, got: ${text}`, status: res.status } as WebRPCError
1118
+ } catch (error) {
1119
+ let message = ''
1120
+ if (error instanceof Error) {
1121
+ message = error.message
1122
+ }
1123
+ throw WebrpcBadResponseError.new({
1124
+ status: res.status,
1125
+ cause: `JSON.parse(): ${message}: response text: ${text}`
1126
+ })
900
1127
  }
901
1128
  if (!res.ok) {
902
- throw data // webrpc error response
1129
+ const code: number = typeof data.code === 'number' ? data.code : 0
1130
+ throw (webrpcErrorByCode[code] || WebrpcError).new(data)
903
1131
  }
904
1132
  return data
905
1133
  })
906
1134
  }
907
1135
 
1136
+ //
1137
+ // Errors
1138
+ //
1139
+
1140
+ export class WebrpcError extends Error {
1141
+ name: string
1142
+ code: number
1143
+ message: string
1144
+ status: number
1145
+ cause?: string
1146
+
1147
+ /** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */
1148
+ msg: string
1149
+
1150
+ constructor(name: string, code: number, message: string, status: number, cause?: string) {
1151
+ super(message)
1152
+ this.name = name || 'WebrpcError'
1153
+ this.code = typeof code === 'number' ? code : 0
1154
+ this.message = message || `endpoint error ${this.code}`
1155
+ this.msg = this.message
1156
+ this.status = typeof status === 'number' ? status : 0
1157
+ this.cause = cause
1158
+ Object.setPrototypeOf(this, WebrpcError.prototype)
1159
+ }
1160
+
1161
+ static new(payload: any): WebrpcError {
1162
+ return new this(payload.error, payload.code, payload.message || payload.msg, payload.status, payload.cause)
1163
+ }
1164
+ }
1165
+
1166
+ // Webrpc errors
1167
+
1168
+ export class WebrpcEndpointError extends WebrpcError {
1169
+ constructor(
1170
+ name: string = 'WebrpcEndpoint',
1171
+ code: number = 0,
1172
+ message: string = 'endpoint error',
1173
+ status: number = 0,
1174
+ cause?: string
1175
+ ) {
1176
+ super(name, code, message, status, cause)
1177
+ Object.setPrototypeOf(this, WebrpcEndpointError.prototype)
1178
+ }
1179
+ }
1180
+
1181
+ export class WebrpcRequestFailedError extends WebrpcError {
1182
+ constructor(
1183
+ name: string = 'WebrpcRequestFailed',
1184
+ code: number = -1,
1185
+ message: string = 'request failed',
1186
+ status: number = 0,
1187
+ cause?: string
1188
+ ) {
1189
+ super(name, code, message, status, cause)
1190
+ Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype)
1191
+ }
1192
+ }
1193
+
1194
+ export class WebrpcBadRouteError extends WebrpcError {
1195
+ constructor(
1196
+ name: string = 'WebrpcBadRoute',
1197
+ code: number = -2,
1198
+ message: string = 'bad route',
1199
+ status: number = 0,
1200
+ cause?: string
1201
+ ) {
1202
+ super(name, code, message, status, cause)
1203
+ Object.setPrototypeOf(this, WebrpcBadRouteError.prototype)
1204
+ }
1205
+ }
1206
+
1207
+ export class WebrpcBadMethodError extends WebrpcError {
1208
+ constructor(
1209
+ name: string = 'WebrpcBadMethod',
1210
+ code: number = -3,
1211
+ message: string = 'bad method',
1212
+ status: number = 0,
1213
+ cause?: string
1214
+ ) {
1215
+ super(name, code, message, status, cause)
1216
+ Object.setPrototypeOf(this, WebrpcBadMethodError.prototype)
1217
+ }
1218
+ }
1219
+
1220
+ export class WebrpcBadRequestError extends WebrpcError {
1221
+ constructor(
1222
+ name: string = 'WebrpcBadRequest',
1223
+ code: number = -4,
1224
+ message: string = 'bad request',
1225
+ status: number = 0,
1226
+ cause?: string
1227
+ ) {
1228
+ super(name, code, message, status, cause)
1229
+ Object.setPrototypeOf(this, WebrpcBadRequestError.prototype)
1230
+ }
1231
+ }
1232
+
1233
+ export class WebrpcBadResponseError extends WebrpcError {
1234
+ constructor(
1235
+ name: string = 'WebrpcBadResponse',
1236
+ code: number = -5,
1237
+ message: string = 'bad response',
1238
+ status: number = 0,
1239
+ cause?: string
1240
+ ) {
1241
+ super(name, code, message, status, cause)
1242
+ Object.setPrototypeOf(this, WebrpcBadResponseError.prototype)
1243
+ }
1244
+ }
1245
+
1246
+ export class WebrpcServerPanicError extends WebrpcError {
1247
+ constructor(
1248
+ name: string = 'WebrpcServerPanic',
1249
+ code: number = -6,
1250
+ message: string = 'server panic',
1251
+ status: number = 0,
1252
+ cause?: string
1253
+ ) {
1254
+ super(name, code, message, status, cause)
1255
+ Object.setPrototypeOf(this, WebrpcServerPanicError.prototype)
1256
+ }
1257
+ }
1258
+
1259
+ export class WebrpcInternalErrorError extends WebrpcError {
1260
+ constructor(
1261
+ name: string = 'WebrpcInternalError',
1262
+ code: number = -7,
1263
+ message: string = 'internal error',
1264
+ status: number = 0,
1265
+ cause?: string
1266
+ ) {
1267
+ super(name, code, message, status, cause)
1268
+ Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype)
1269
+ }
1270
+ }
1271
+
1272
+ export class WebrpcClientDisconnectedError extends WebrpcError {
1273
+ constructor(
1274
+ name: string = 'WebrpcClientDisconnected',
1275
+ code: number = -8,
1276
+ message: string = 'client disconnected',
1277
+ status: number = 0,
1278
+ cause?: string
1279
+ ) {
1280
+ super(name, code, message, status, cause)
1281
+ Object.setPrototypeOf(this, WebrpcClientDisconnectedError.prototype)
1282
+ }
1283
+ }
1284
+
1285
+ export class WebrpcStreamLostError extends WebrpcError {
1286
+ constructor(
1287
+ name: string = 'WebrpcStreamLost',
1288
+ code: number = -9,
1289
+ message: string = 'stream lost',
1290
+ status: number = 0,
1291
+ cause?: string
1292
+ ) {
1293
+ super(name, code, message, status, cause)
1294
+ Object.setPrototypeOf(this, WebrpcStreamLostError.prototype)
1295
+ }
1296
+ }
1297
+
1298
+ export class WebrpcStreamFinishedError extends WebrpcError {
1299
+ constructor(
1300
+ name: string = 'WebrpcStreamFinished',
1301
+ code: number = -10,
1302
+ message: string = 'stream finished',
1303
+ status: number = 0,
1304
+ cause?: string
1305
+ ) {
1306
+ super(name, code, message, status, cause)
1307
+ Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype)
1308
+ }
1309
+ }
1310
+
1311
+ // Schema errors
1312
+
1313
+ export class UnauthorizedError extends WebrpcError {
1314
+ constructor(
1315
+ name: string = 'Unauthorized',
1316
+ code: number = 1000,
1317
+ message: string = 'Unauthorized access',
1318
+ status: number = 0,
1319
+ cause?: string
1320
+ ) {
1321
+ super(name, code, message, status, cause)
1322
+ Object.setPrototypeOf(this, UnauthorizedError.prototype)
1323
+ }
1324
+ }
1325
+
1326
+ export class PermissionDeniedError extends WebrpcError {
1327
+ constructor(
1328
+ name: string = 'PermissionDenied',
1329
+ code: number = 1001,
1330
+ message: string = 'Permission denied',
1331
+ status: number = 0,
1332
+ cause?: string
1333
+ ) {
1334
+ super(name, code, message, status, cause)
1335
+ Object.setPrototypeOf(this, PermissionDeniedError.prototype)
1336
+ }
1337
+ }
1338
+
1339
+ export class MethodNotFoundError extends WebrpcError {
1340
+ constructor(
1341
+ name: string = 'MethodNotFound',
1342
+ code: number = 1003,
1343
+ message: string = 'Method not found',
1344
+ status: number = 0,
1345
+ cause?: string
1346
+ ) {
1347
+ super(name, code, message, status, cause)
1348
+ Object.setPrototypeOf(this, MethodNotFoundError.prototype)
1349
+ }
1350
+ }
1351
+
1352
+ export class AbortedError extends WebrpcError {
1353
+ constructor(
1354
+ name: string = 'Aborted',
1355
+ code: number = 1005,
1356
+ message: string = 'Request aborted',
1357
+ status: number = 0,
1358
+ cause?: string
1359
+ ) {
1360
+ super(name, code, message, status, cause)
1361
+ Object.setPrototypeOf(this, AbortedError.prototype)
1362
+ }
1363
+ }
1364
+
1365
+ export class InvalidArgumentError extends WebrpcError {
1366
+ constructor(
1367
+ name: string = 'InvalidArgument',
1368
+ code: number = 2001,
1369
+ message: string = 'Invalid argument',
1370
+ status: number = 0,
1371
+ cause?: string
1372
+ ) {
1373
+ super(name, code, message, status, cause)
1374
+ Object.setPrototypeOf(this, InvalidArgumentError.prototype)
1375
+ }
1376
+ }
1377
+
1378
+ export class UnavailableError extends WebrpcError {
1379
+ constructor(
1380
+ name: string = 'Unavailable',
1381
+ code: number = 2002,
1382
+ message: string = 'Unavailable resource',
1383
+ status: number = 0,
1384
+ cause?: string
1385
+ ) {
1386
+ super(name, code, message, status, cause)
1387
+ Object.setPrototypeOf(this, UnavailableError.prototype)
1388
+ }
1389
+ }
1390
+
1391
+ export class QueryFailedError extends WebrpcError {
1392
+ constructor(
1393
+ name: string = 'QueryFailed',
1394
+ code: number = 2003,
1395
+ message: string = 'Query failed',
1396
+ status: number = 0,
1397
+ cause?: string
1398
+ ) {
1399
+ super(name, code, message, status, cause)
1400
+ Object.setPrototypeOf(this, QueryFailedError.prototype)
1401
+ }
1402
+ }
1403
+
1404
+ export class NotFoundError extends WebrpcError {
1405
+ constructor(
1406
+ name: string = 'NotFound',
1407
+ code: number = 3000,
1408
+ message: string = 'Resource not found',
1409
+ status: number = 0,
1410
+ cause?: string
1411
+ ) {
1412
+ super(name, code, message, status, cause)
1413
+ Object.setPrototypeOf(this, NotFoundError.prototype)
1414
+ }
1415
+ }
1416
+
1417
+ export enum errors {
1418
+ WebrpcEndpoint = 'WebrpcEndpoint',
1419
+ WebrpcRequestFailed = 'WebrpcRequestFailed',
1420
+ WebrpcBadRoute = 'WebrpcBadRoute',
1421
+ WebrpcBadMethod = 'WebrpcBadMethod',
1422
+ WebrpcBadRequest = 'WebrpcBadRequest',
1423
+ WebrpcBadResponse = 'WebrpcBadResponse',
1424
+ WebrpcServerPanic = 'WebrpcServerPanic',
1425
+ WebrpcInternalError = 'WebrpcInternalError',
1426
+ WebrpcClientDisconnected = 'WebrpcClientDisconnected',
1427
+ WebrpcStreamLost = 'WebrpcStreamLost',
1428
+ WebrpcStreamFinished = 'WebrpcStreamFinished',
1429
+ Unauthorized = 'Unauthorized',
1430
+ PermissionDenied = 'PermissionDenied',
1431
+ MethodNotFound = 'MethodNotFound',
1432
+ Aborted = 'Aborted',
1433
+ InvalidArgument = 'InvalidArgument',
1434
+ Unavailable = 'Unavailable',
1435
+ QueryFailed = 'QueryFailed',
1436
+ NotFound = 'NotFound'
1437
+ }
1438
+
1439
+ const webrpcErrorByCode: { [code: number]: any } = {
1440
+ [0]: WebrpcEndpointError,
1441
+ [-1]: WebrpcRequestFailedError,
1442
+ [-2]: WebrpcBadRouteError,
1443
+ [-3]: WebrpcBadMethodError,
1444
+ [-4]: WebrpcBadRequestError,
1445
+ [-5]: WebrpcBadResponseError,
1446
+ [-6]: WebrpcServerPanicError,
1447
+ [-7]: WebrpcInternalErrorError,
1448
+ [-8]: WebrpcClientDisconnectedError,
1449
+ [-9]: WebrpcStreamLostError,
1450
+ [-10]: WebrpcStreamFinishedError,
1451
+ [1000]: UnauthorizedError,
1452
+ [1001]: PermissionDeniedError,
1453
+ [1003]: MethodNotFoundError,
1454
+ [1005]: AbortedError,
1455
+ [2001]: InvalidArgumentError,
1456
+ [2002]: UnavailableError,
1457
+ [2003]: QueryFailedError,
1458
+ [3000]: NotFoundError
1459
+ }
1460
+
908
1461
  export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>