@0xsequence/marketplace 2.0.23

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,2115 @@
1
+ /* eslint-disable */
2
+ // marketplace-api 272a2d3c9208fb21b84c88a2a8cbd9ab8e29964d
3
+ // --
4
+ // Code generated by webrpc-gen@v0.21.1 with typescript generator. DO NOT EDIT.
5
+ //
6
+ // webrpc-gen -schema=marketplace.ridl -target=typescript -client -out=./clients/marketplace.gen.ts
7
+
8
+ export const WebrpcHeader = 'Webrpc'
9
+
10
+ export const WebrpcHeaderValue =
11
+ 'webrpc@v0.21.1;gen-typescript@v0.15.1;marketplace-api@v0.0.0-272a2d3c9208fb21b84c88a2a8cbd9ab8e29964d'
12
+
13
+ // WebRPC description and code-gen version
14
+ export const WebRPCVersion = 'v1'
15
+
16
+ // Schema version of your RIDL schema
17
+ export const WebRPCSchemaVersion = ''
18
+
19
+ // Schema hash generated from your RIDL schema
20
+ export const WebRPCSchemaHash = '272a2d3c9208fb21b84c88a2a8cbd9ab8e29964d'
21
+
22
+ type WebrpcGenVersions = {
23
+ webrpcGenVersion: string
24
+ codeGenName: string
25
+ codeGenVersion: string
26
+ schemaName: string
27
+ schemaVersion: string
28
+ }
29
+
30
+ export function VersionFromHeader(headers: Headers): WebrpcGenVersions {
31
+ const headerValue = headers.get(WebrpcHeader)
32
+ if (!headerValue) {
33
+ return {
34
+ webrpcGenVersion: '',
35
+ codeGenName: '',
36
+ codeGenVersion: '',
37
+ schemaName: '',
38
+ schemaVersion: ''
39
+ }
40
+ }
41
+
42
+ return parseWebrpcGenVersions(headerValue)
43
+ }
44
+
45
+ function parseWebrpcGenVersions(header: string): WebrpcGenVersions {
46
+ const versions = header.split(';')
47
+ if (versions.length < 3) {
48
+ return {
49
+ webrpcGenVersion: '',
50
+ codeGenName: '',
51
+ codeGenVersion: '',
52
+ schemaName: '',
53
+ schemaVersion: ''
54
+ }
55
+ }
56
+
57
+ const [_, webrpcGenVersion] = versions[0].split('@')
58
+ const [codeGenName, codeGenVersion] = versions[1].split('@')
59
+ const [schemaName, schemaVersion] = versions[2].split('@')
60
+
61
+ return {
62
+ webrpcGenVersion,
63
+ codeGenName,
64
+ codeGenVersion,
65
+ schemaName,
66
+ schemaVersion
67
+ }
68
+ }
69
+
70
+ //
71
+ // Types
72
+ //
73
+
74
+ export interface TokenMetadata {
75
+ tokenId: string
76
+ name: string
77
+ description?: string
78
+ image?: string
79
+ video?: string
80
+ audio?: string
81
+ properties?: { [key: string]: any }
82
+ attributes: Array<{ [key: string]: any }>
83
+ image_data?: string
84
+ external_url?: string
85
+ background_color?: string
86
+ animation_url?: string
87
+ decimals?: number
88
+ updatedAt?: string
89
+ assets?: Array<Asset>
90
+ }
91
+
92
+ export interface Asset {
93
+ id: number
94
+ collectionId: number
95
+ tokenId: string
96
+ url?: string
97
+ metadataField: string
98
+ name?: string
99
+ filesize?: number
100
+ mimeType?: string
101
+ width?: number
102
+ height?: number
103
+ updatedAt?: string
104
+ }
105
+
106
+ export enum SortOrder {
107
+ DESC = 'DESC',
108
+ ASC = 'ASC'
109
+ }
110
+
111
+ export enum PropertyType {
112
+ INT = 'INT',
113
+ STRING = 'STRING',
114
+ ARRAY = 'ARRAY',
115
+ GENERIC = 'GENERIC'
116
+ }
117
+
118
+ export enum MarketplaceKind {
119
+ unknown = 'unknown',
120
+ sequence_marketplace_v1 = 'sequence_marketplace_v1',
121
+ sequence_marketplace_v2 = 'sequence_marketplace_v2',
122
+ opensea = 'opensea',
123
+ magic_eden = 'magic_eden',
124
+ mintify = 'mintify',
125
+ looks_rare = 'looks_rare',
126
+ x2y2 = 'x2y2',
127
+ sudo_swap = 'sudo_swap',
128
+ coinbase = 'coinbase',
129
+ rarible = 'rarible',
130
+ nftx = 'nftx',
131
+ foundation = 'foundation',
132
+ manifold = 'manifold',
133
+ zora = 'zora',
134
+ blur = 'blur',
135
+ super_rare = 'super_rare',
136
+ okx = 'okx',
137
+ element = 'element',
138
+ aqua_xyz = 'aqua_xyz',
139
+ auranft_co = 'auranft_co'
140
+ }
141
+
142
+ export enum OrderbookKind {
143
+ unknown = 'unknown',
144
+ sequence_marketplace_v1 = 'sequence_marketplace_v1',
145
+ sequence_marketplace_v2 = 'sequence_marketplace_v2',
146
+ blur = 'blur',
147
+ opensea = 'opensea',
148
+ looks_rare = 'looks_rare',
149
+ reservoir = 'reservoir',
150
+ x2y2 = 'x2y2'
151
+ }
152
+
153
+ export enum SourceKind {
154
+ unknown = 'unknown',
155
+ external = 'external',
156
+ sequence_marketplace_v1 = 'sequence_marketplace_v1',
157
+ sequence_marketplace_v2 = 'sequence_marketplace_v2'
158
+ }
159
+
160
+ export enum OrderSide {
161
+ unknown = 'unknown',
162
+ listing = 'listing',
163
+ offer = 'offer'
164
+ }
165
+
166
+ export enum OrderStatus {
167
+ unknown = 'unknown',
168
+ active = 'active',
169
+ inactive = 'inactive',
170
+ expired = 'expired',
171
+ cancelled = 'cancelled',
172
+ filled = 'filled'
173
+ }
174
+
175
+ export enum ContractType {
176
+ UNKNOWN = 'UNKNOWN',
177
+ ERC20 = 'ERC20',
178
+ ERC721 = 'ERC721',
179
+ ERC1155 = 'ERC1155'
180
+ }
181
+
182
+ export enum CollectionStatus {
183
+ unknown = 'unknown',
184
+ created = 'created',
185
+ syncing_metadata = 'syncing_metadata',
186
+ synced_metadata = 'synced_metadata',
187
+ syncing_tokens = 'syncing_tokens',
188
+ synced_tokens = 'synced_tokens',
189
+ syncing_orders = 'syncing_orders',
190
+ active = 'active',
191
+ failed = 'failed',
192
+ inactive = 'inactive'
193
+ }
194
+
195
+ export enum ProjectStatus {
196
+ unknown = 'unknown',
197
+ active = 'active',
198
+ inactive = 'inactive'
199
+ }
200
+
201
+ export enum CollectibleStatus {
202
+ unknown = 'unknown',
203
+ active = 'active',
204
+ inactive = 'inactive'
205
+ }
206
+
207
+ export enum WalletKind {
208
+ unknown = 'unknown',
209
+ sequence = 'sequence'
210
+ }
211
+
212
+ export enum StepType {
213
+ unknown = 'unknown',
214
+ tokenApproval = 'tokenApproval',
215
+ buy = 'buy',
216
+ sell = 'sell',
217
+ createListing = 'createListing',
218
+ createOffer = 'createOffer',
219
+ signEIP712 = 'signEIP712',
220
+ signEIP191 = 'signEIP191'
221
+ }
222
+
223
+ export enum TransactionCrypto {
224
+ none = 'none',
225
+ partially = 'partially',
226
+ all = 'all'
227
+ }
228
+
229
+ export enum TransactionNFTCheckoutProvider {
230
+ unknown = 'unknown',
231
+ sardine = 'sardine',
232
+ transak = 'transak'
233
+ }
234
+
235
+ export enum TransactionOnRampProvider {
236
+ unknown = 'unknown',
237
+ sardine = 'sardine',
238
+ transak = 'transak'
239
+ }
240
+
241
+ export enum TransactionSwapProvider {
242
+ unknown = 'unknown',
243
+ zerox = 'zerox'
244
+ }
245
+
246
+ export enum ExecuteType {
247
+ unknown = 'unknown',
248
+ order = 'order'
249
+ }
250
+
251
+ export interface Page {
252
+ page: number
253
+ pageSize: number
254
+ more?: boolean
255
+ sort?: Array<SortBy>
256
+ }
257
+
258
+ export interface SortBy {
259
+ column: string
260
+ order: SortOrder
261
+ }
262
+
263
+ export interface Filter {
264
+ text?: string
265
+ properties?: Array<PropertyFilter>
266
+ }
267
+
268
+ export interface PropertyFilter {
269
+ name: string
270
+ type: PropertyType
271
+ min?: number
272
+ max?: number
273
+ values?: Array<any>
274
+ }
275
+
276
+ export interface CollectiblesFilter {
277
+ includeEmpty: boolean
278
+ searchText?: string
279
+ properties?: Array<PropertyFilter>
280
+ marketplaces?: Array<MarketplaceKind>
281
+ inAccounts?: Array<string>
282
+ notInAccounts?: Array<string>
283
+ ordersCreatedBy?: Array<string>
284
+ ordersNotCreatedBy?: Array<string>
285
+ }
286
+
287
+ export interface Order {
288
+ orderId: string
289
+ marketplace: MarketplaceKind
290
+ side: OrderSide
291
+ status: OrderStatus
292
+ chainId: number
293
+ collectionContractAddress: string
294
+ tokenId: string
295
+ createdBy: string
296
+ priceAmount: string
297
+ priceAmountFormatted: string
298
+ priceAmountNet: string
299
+ priceAmountNetFormatted: string
300
+ priceCurrencyAddress: string
301
+ priceDecimals: number
302
+ priceUSD: number
303
+ quantityInitial: string
304
+ quantityInitialFormatted: string
305
+ quantityRemaining: string
306
+ quantityRemainingFormatted: string
307
+ quantityAvailable: string
308
+ quantityAvailableFormatted: string
309
+ quantityDecimals: number
310
+ feeBps: number
311
+ feeBreakdown: Array<FeeBreakdown>
312
+ validFrom: string
313
+ validUntil: string
314
+ blockNumber: number
315
+ orderCreatedAt?: string
316
+ orderUpdatedAt?: string
317
+ createdAt: string
318
+ updatedAt: string
319
+ deletedAt?: string
320
+ }
321
+
322
+ export interface FeeBreakdown {
323
+ kind: string
324
+ recipientAddress: string
325
+ bps: number
326
+ }
327
+
328
+ export interface CollectibleOrder {
329
+ metadata: TokenMetadata
330
+ order?: Order
331
+ }
332
+
333
+ export interface OrderFilter {
334
+ createdBy?: Array<string>
335
+ marketplace?: Array<MarketplaceKind>
336
+ currencies?: Array<string>
337
+ }
338
+
339
+ export interface Activity {
340
+ type: string
341
+ fromAddress: string
342
+ toAddress: string
343
+ txHash: string
344
+ timestamp: number
345
+ tokenId: string
346
+ tokenImage: string
347
+ tokenName: string
348
+ currency?: Currency
349
+ }
350
+
351
+ export interface Collection {
352
+ status: CollectionStatus
353
+ chainId: number
354
+ contractAddress: string
355
+ contractType: ContractType
356
+ tokenQuantityDecimals: number
357
+ config: CollectionConfig
358
+ createdAt: string
359
+ updatedAt: string
360
+ deletedAt?: string
361
+ }
362
+
363
+ export interface CollectionConfig {
364
+ lastSynced: { [key: string]: CollectionLastSynced }
365
+ collectiblesSynced: string
366
+ }
367
+
368
+ export interface CollectionLastSynced {
369
+ allOrders: string
370
+ newOrders: string
371
+ }
372
+
373
+ export interface Project {
374
+ projectId: number
375
+ chainId: number
376
+ contractAddress: string
377
+ status: ProjectStatus
378
+ createdAt: string
379
+ updatedAt: string
380
+ deletedAt?: string
381
+ }
382
+
383
+ export interface Collectible {
384
+ chainId: number
385
+ contractAddress: string
386
+ status: CollectibleStatus
387
+ tokenId: string
388
+ createdAt: string
389
+ updatedAt: string
390
+ deletedAt?: string
391
+ }
392
+
393
+ export interface Currency {
394
+ chainId: number
395
+ contractAddress: string
396
+ name: string
397
+ symbol: string
398
+ decimals: number
399
+ imageUrl: string
400
+ exchangeRate: number
401
+ defaultChainCurrency: boolean
402
+ nativeCurrency: boolean
403
+ createdAt: string
404
+ updatedAt: string
405
+ deletedAt?: string
406
+ }
407
+
408
+ export interface OrderData {
409
+ orderId: string
410
+ quantity: string
411
+ }
412
+
413
+ export interface AdditionalFee {
414
+ amount: string
415
+ receiver: string
416
+ }
417
+
418
+ export interface Step {
419
+ id: StepType
420
+ data: string
421
+ to: string
422
+ value: string
423
+ signature?: Signature
424
+ post?: PostRequest
425
+ executeType?: ExecuteType
426
+ }
427
+
428
+ export interface PostRequest {
429
+ endpoint: string
430
+ method: string
431
+ body: any
432
+ }
433
+
434
+ export interface CreateReq {
435
+ tokenId: string
436
+ quantity: string
437
+ expiry: string
438
+ currencyAddress: string
439
+ pricePerToken: string
440
+ }
441
+
442
+ export interface GetOrdersInput {
443
+ contractAddress: string
444
+ orderId: string
445
+ marketplace: MarketplaceKind
446
+ }
447
+
448
+ export interface Signature {
449
+ domain: Domain
450
+ types: any
451
+ primaryType: string
452
+ value: any
453
+ }
454
+
455
+ export interface Domain {
456
+ name: string
457
+ version: string
458
+ chainId: number
459
+ verifyingContract: string
460
+ }
461
+
462
+ export interface CheckoutOptionsMarketplaceOrder {
463
+ contractAddress: string
464
+ orderId: string
465
+ marketplace: MarketplaceKind
466
+ }
467
+
468
+ export interface CheckoutOptionsItem {
469
+ tokenId: string
470
+ quantity: string
471
+ }
472
+
473
+ export interface CheckoutOptions {
474
+ crypto: TransactionCrypto
475
+ swap: Array<TransactionSwapProvider>
476
+ nftCheckout: Array<TransactionNFTCheckoutProvider>
477
+ onRamp: Array<TransactionOnRampProvider>
478
+ }
479
+
480
+ export interface Admin {
481
+ createCollection(args: CreateCollectionArgs, headers?: object, signal?: AbortSignal): Promise<CreateCollectionReturn>
482
+ getCollection(args: GetCollectionArgs, headers?: object, signal?: AbortSignal): Promise<GetCollectionReturn>
483
+ listCollections(args: ListCollectionsArgs, headers?: object, signal?: AbortSignal): Promise<ListCollectionsReturn>
484
+ deleteCollection(args: DeleteCollectionArgs, headers?: object, signal?: AbortSignal): Promise<DeleteCollectionReturn>
485
+ syncCollection(args: SyncCollectionArgs, headers?: object, signal?: AbortSignal): Promise<SyncCollectionReturn>
486
+ createCurrency(args: CreateCurrencyArgs, headers?: object, signal?: AbortSignal): Promise<CreateCurrencyReturn>
487
+ createCurrencies(args: CreateCurrenciesArgs, headers?: object, signal?: AbortSignal): Promise<CreateCurrenciesReturn>
488
+ updateCurrency(args: UpdateCurrencyArgs, headers?: object, signal?: AbortSignal): Promise<UpdateCurrencyReturn>
489
+ listCurrencies(headers?: object, signal?: AbortSignal): Promise<ListCurrenciesReturn>
490
+ deleteCurrency(args: DeleteCurrencyArgs, headers?: object, signal?: AbortSignal): Promise<DeleteCurrencyReturn>
491
+ }
492
+
493
+ export interface CreateCollectionArgs {
494
+ projectId: number
495
+ contractAddress: string
496
+ }
497
+
498
+ export interface CreateCollectionReturn {
499
+ collection: Collection
500
+ }
501
+ export interface GetCollectionArgs {
502
+ projectId: number
503
+ contractAddress: string
504
+ }
505
+
506
+ export interface GetCollectionReturn {
507
+ collection: Collection
508
+ }
509
+ export interface ListCollectionsArgs {
510
+ projectId: number
511
+ page?: Page
512
+ }
513
+
514
+ export interface ListCollectionsReturn {
515
+ collections: Array<Collection>
516
+ page?: Page
517
+ }
518
+ export interface DeleteCollectionArgs {
519
+ projectId: number
520
+ contractAddress: string
521
+ }
522
+
523
+ export interface DeleteCollectionReturn {
524
+ collection: Collection
525
+ }
526
+ export interface SyncCollectionArgs {
527
+ projectId: number
528
+ contractAddress: string
529
+ }
530
+
531
+ export interface SyncCollectionReturn {
532
+ collection: Collection
533
+ }
534
+ export interface CreateCurrencyArgs {
535
+ currency: Currency
536
+ }
537
+
538
+ export interface CreateCurrencyReturn {
539
+ currency: Currency
540
+ }
541
+ export interface CreateCurrenciesArgs {
542
+ currencies: Array<Currency>
543
+ }
544
+
545
+ export interface CreateCurrenciesReturn {
546
+ currency: { [key: string]: Currency }
547
+ }
548
+ export interface UpdateCurrencyArgs {
549
+ currency: Currency
550
+ }
551
+
552
+ export interface UpdateCurrencyReturn {
553
+ currency: Currency
554
+ }
555
+ export interface ListCurrenciesArgs {}
556
+
557
+ export interface ListCurrenciesReturn {
558
+ currencies: Array<Currency>
559
+ }
560
+ export interface DeleteCurrencyArgs {
561
+ chainId: number
562
+ contractAddress: string
563
+ }
564
+
565
+ export interface DeleteCurrencyReturn {
566
+ currency: Currency
567
+ }
568
+
569
+ export interface Marketplace {
570
+ listCurrencies(headers?: object, signal?: AbortSignal): Promise<ListCurrenciesReturn>
571
+ getCollectible(args: GetCollectibleArgs, headers?: object, signal?: AbortSignal): Promise<GetCollectibleReturn>
572
+ getLowestPriceOfferForCollectible(
573
+ args: GetLowestPriceOfferForCollectibleArgs,
574
+ headers?: object,
575
+ signal?: AbortSignal
576
+ ): Promise<GetLowestPriceOfferForCollectibleReturn>
577
+ getHighestPriceOfferForCollectible(
578
+ args: GetHighestPriceOfferForCollectibleArgs,
579
+ headers?: object,
580
+ signal?: AbortSignal
581
+ ): Promise<GetHighestPriceOfferForCollectibleReturn>
582
+ getLowestPriceListingForCollectible(
583
+ args: GetLowestPriceListingForCollectibleArgs,
584
+ headers?: object,
585
+ signal?: AbortSignal
586
+ ): Promise<GetLowestPriceListingForCollectibleReturn>
587
+ getHighestPriceListingForCollectible(
588
+ args: GetHighestPriceListingForCollectibleArgs,
589
+ headers?: object,
590
+ signal?: AbortSignal
591
+ ): Promise<GetHighestPriceListingForCollectibleReturn>
592
+ listListingsForCollectible(
593
+ args: ListListingsForCollectibleArgs,
594
+ headers?: object,
595
+ signal?: AbortSignal
596
+ ): Promise<ListListingsForCollectibleReturn>
597
+ listOffersForCollectible(
598
+ args: ListOffersForCollectibleArgs,
599
+ headers?: object,
600
+ signal?: AbortSignal
601
+ ): Promise<ListOffersForCollectibleReturn>
602
+ getCollectibleLowestOffer(
603
+ args: GetCollectibleLowestOfferArgs,
604
+ headers?: object,
605
+ signal?: AbortSignal
606
+ ): Promise<GetCollectibleLowestOfferReturn>
607
+ getCollectibleHighestOffer(
608
+ args: GetCollectibleHighestOfferArgs,
609
+ headers?: object,
610
+ signal?: AbortSignal
611
+ ): Promise<GetCollectibleHighestOfferReturn>
612
+ getCollectibleLowestListing(
613
+ args: GetCollectibleLowestListingArgs,
614
+ headers?: object,
615
+ signal?: AbortSignal
616
+ ): Promise<GetCollectibleLowestListingReturn>
617
+ getCollectibleHighestListing(
618
+ args: GetCollectibleHighestListingArgs,
619
+ headers?: object,
620
+ signal?: AbortSignal
621
+ ): Promise<GetCollectibleHighestListingReturn>
622
+ listCollectibleListings(
623
+ args: ListCollectibleListingsArgs,
624
+ headers?: object,
625
+ signal?: AbortSignal
626
+ ): Promise<ListCollectibleListingsReturn>
627
+ listCollectibleOffers(
628
+ args: ListCollectibleOffersArgs,
629
+ headers?: object,
630
+ signal?: AbortSignal
631
+ ): Promise<ListCollectibleOffersReturn>
632
+ generateBuyTransaction(
633
+ args: GenerateBuyTransactionArgs,
634
+ headers?: object,
635
+ signal?: AbortSignal
636
+ ): Promise<GenerateBuyTransactionReturn>
637
+ generateSellTransaction(
638
+ args: GenerateSellTransactionArgs,
639
+ headers?: object,
640
+ signal?: AbortSignal
641
+ ): Promise<GenerateSellTransactionReturn>
642
+ generateListingTransaction(
643
+ args: GenerateListingTransactionArgs,
644
+ headers?: object,
645
+ signal?: AbortSignal
646
+ ): Promise<GenerateListingTransactionReturn>
647
+ generateOfferTransaction(
648
+ args: GenerateOfferTransactionArgs,
649
+ headers?: object,
650
+ signal?: AbortSignal
651
+ ): Promise<GenerateOfferTransactionReturn>
652
+ execute(args: ExecuteArgs, headers?: object, signal?: AbortSignal): Promise<ExecuteReturn>
653
+ listCollectibles(args: ListCollectiblesArgs, headers?: object, signal?: AbortSignal): Promise<ListCollectiblesReturn>
654
+ getCountOfAllCollectibles(
655
+ args: GetCountOfAllCollectiblesArgs,
656
+ headers?: object,
657
+ signal?: AbortSignal
658
+ ): Promise<GetCountOfAllCollectiblesReturn>
659
+ getCountOfFilteredCollectibles(
660
+ args: GetCountOfFilteredCollectiblesArgs,
661
+ headers?: object,
662
+ signal?: AbortSignal
663
+ ): Promise<GetCountOfFilteredCollectiblesReturn>
664
+ getFloorOrder(args: GetFloorOrderArgs, headers?: object, signal?: AbortSignal): Promise<GetFloorOrderReturn>
665
+ listCollectiblesWithLowestListing(
666
+ args: ListCollectiblesWithLowestListingArgs,
667
+ headers?: object,
668
+ signal?: AbortSignal
669
+ ): Promise<ListCollectiblesWithLowestListingReturn>
670
+ listCollectiblesWithHighestOffer(
671
+ args: ListCollectiblesWithHighestOfferArgs,
672
+ headers?: object,
673
+ signal?: AbortSignal
674
+ ): Promise<ListCollectiblesWithHighestOfferReturn>
675
+ syncOrder(args: SyncOrderArgs, headers?: object, signal?: AbortSignal): Promise<SyncOrderReturn>
676
+ syncOrders(args: SyncOrdersArgs, headers?: object, signal?: AbortSignal): Promise<SyncOrdersReturn>
677
+ getOrders(args: GetOrdersArgs, headers?: object, signal?: AbortSignal): Promise<GetOrdersReturn>
678
+ checkoutOptionsMarketplace(
679
+ args: CheckoutOptionsMarketplaceArgs,
680
+ headers?: object,
681
+ signal?: AbortSignal
682
+ ): Promise<CheckoutOptionsMarketplaceReturn>
683
+ checkoutOptionsSalesContract(
684
+ args: CheckoutOptionsSalesContractArgs,
685
+ headers?: object,
686
+ signal?: AbortSignal
687
+ ): Promise<CheckoutOptionsSalesContractReturn>
688
+ }
689
+
690
+ export interface ListCurrenciesArgs {}
691
+
692
+ export interface ListCurrenciesReturn {
693
+ currencies: Array<Currency>
694
+ }
695
+ export interface GetCollectibleArgs {
696
+ contractAddress: string
697
+ tokenId: string
698
+ }
699
+
700
+ export interface GetCollectibleReturn {
701
+ metadata: TokenMetadata
702
+ }
703
+ export interface GetLowestPriceOfferForCollectibleArgs {
704
+ contractAddress: string
705
+ tokenId: string
706
+ filter?: OrderFilter
707
+ }
708
+
709
+ export interface GetLowestPriceOfferForCollectibleReturn {
710
+ order: Order
711
+ }
712
+ export interface GetHighestPriceOfferForCollectibleArgs {
713
+ contractAddress: string
714
+ tokenId: string
715
+ filter?: OrderFilter
716
+ }
717
+
718
+ export interface GetHighestPriceOfferForCollectibleReturn {
719
+ order: Order
720
+ }
721
+ export interface GetLowestPriceListingForCollectibleArgs {
722
+ contractAddress: string
723
+ tokenId: string
724
+ filter?: OrderFilter
725
+ }
726
+
727
+ export interface GetLowestPriceListingForCollectibleReturn {
728
+ order: Order
729
+ }
730
+ export interface GetHighestPriceListingForCollectibleArgs {
731
+ contractAddress: string
732
+ tokenId: string
733
+ filter?: OrderFilter
734
+ }
735
+
736
+ export interface GetHighestPriceListingForCollectibleReturn {
737
+ order: Order
738
+ }
739
+ export interface ListListingsForCollectibleArgs {
740
+ contractAddress: string
741
+ tokenId: string
742
+ filter?: OrderFilter
743
+ page?: Page
744
+ }
745
+
746
+ export interface ListListingsForCollectibleReturn {
747
+ listings: Array<Order>
748
+ page?: Page
749
+ }
750
+ export interface ListOffersForCollectibleArgs {
751
+ contractAddress: string
752
+ tokenId: string
753
+ filter?: OrderFilter
754
+ page?: Page
755
+ }
756
+
757
+ export interface ListOffersForCollectibleReturn {
758
+ offers: Array<Order>
759
+ page?: Page
760
+ }
761
+ export interface GetCollectibleLowestOfferArgs {
762
+ contractAddress: string
763
+ tokenId: string
764
+ filter?: OrderFilter
765
+ }
766
+
767
+ export interface GetCollectibleLowestOfferReturn {
768
+ order?: Order
769
+ }
770
+ export interface GetCollectibleHighestOfferArgs {
771
+ contractAddress: string
772
+ tokenId: string
773
+ filter?: OrderFilter
774
+ }
775
+
776
+ export interface GetCollectibleHighestOfferReturn {
777
+ order?: Order
778
+ }
779
+ export interface GetCollectibleLowestListingArgs {
780
+ contractAddress: string
781
+ tokenId: string
782
+ filter?: OrderFilter
783
+ }
784
+
785
+ export interface GetCollectibleLowestListingReturn {
786
+ order?: Order
787
+ }
788
+ export interface GetCollectibleHighestListingArgs {
789
+ contractAddress: string
790
+ tokenId: string
791
+ filter?: OrderFilter
792
+ }
793
+
794
+ export interface GetCollectibleHighestListingReturn {
795
+ order?: Order
796
+ }
797
+ export interface ListCollectibleListingsArgs {
798
+ contractAddress: string
799
+ tokenId: string
800
+ filter?: OrderFilter
801
+ page?: Page
802
+ }
803
+
804
+ export interface ListCollectibleListingsReturn {
805
+ listings: Array<Order>
806
+ page?: Page
807
+ }
808
+ export interface ListCollectibleOffersArgs {
809
+ contractAddress: string
810
+ tokenId: string
811
+ filter?: OrderFilter
812
+ page?: Page
813
+ }
814
+
815
+ export interface ListCollectibleOffersReturn {
816
+ offers: Array<Order>
817
+ page?: Page
818
+ }
819
+ export interface GenerateBuyTransactionArgs {
820
+ collectionAddress: string
821
+ buyer: string
822
+ marketplace: MarketplaceKind
823
+ ordersData: Array<OrderData>
824
+ additionalFees: Array<AdditionalFee>
825
+ walletType?: WalletKind
826
+ }
827
+
828
+ export interface GenerateBuyTransactionReturn {
829
+ steps: Array<Step>
830
+ }
831
+ export interface GenerateSellTransactionArgs {
832
+ collectionAddress: string
833
+ seller: string
834
+ marketplace: MarketplaceKind
835
+ ordersData: Array<OrderData>
836
+ additionalFees: Array<AdditionalFee>
837
+ walletType?: WalletKind
838
+ }
839
+
840
+ export interface GenerateSellTransactionReturn {
841
+ steps: Array<Step>
842
+ }
843
+ export interface GenerateListingTransactionArgs {
844
+ collectionAddress: string
845
+ owner: string
846
+ contractType: ContractType
847
+ orderbook: OrderbookKind
848
+ listing: CreateReq
849
+ walletType?: WalletKind
850
+ }
851
+
852
+ export interface GenerateListingTransactionReturn {
853
+ steps: Array<Step>
854
+ }
855
+ export interface GenerateOfferTransactionArgs {
856
+ collectionAddress: string
857
+ maker: string
858
+ contractType: ContractType
859
+ orderbook: OrderbookKind
860
+ offer: CreateReq
861
+ walletType?: WalletKind
862
+ }
863
+
864
+ export interface GenerateOfferTransactionReturn {
865
+ steps: Array<Step>
866
+ }
867
+ export interface ExecuteArgs {
868
+ signature: string
869
+ executeType: ExecuteType
870
+ body: any
871
+ }
872
+
873
+ export interface ExecuteReturn {
874
+ orderId: string
875
+ }
876
+ export interface ListCollectiblesArgs {
877
+ side: OrderSide
878
+ contractAddress: string
879
+ filter?: CollectiblesFilter
880
+ page?: Page
881
+ }
882
+
883
+ export interface ListCollectiblesReturn {
884
+ collectibles: Array<CollectibleOrder>
885
+ page?: Page
886
+ }
887
+ export interface GetCountOfAllCollectiblesArgs {
888
+ contractAddress: string
889
+ }
890
+
891
+ export interface GetCountOfAllCollectiblesReturn {
892
+ count: number
893
+ }
894
+ export interface GetCountOfFilteredCollectiblesArgs {
895
+ side: OrderSide
896
+ contractAddress: string
897
+ filter?: CollectiblesFilter
898
+ }
899
+
900
+ export interface GetCountOfFilteredCollectiblesReturn {
901
+ count: number
902
+ }
903
+ export interface GetFloorOrderArgs {
904
+ contractAddress: string
905
+ filter?: CollectiblesFilter
906
+ }
907
+
908
+ export interface GetFloorOrderReturn {
909
+ collectible: CollectibleOrder
910
+ }
911
+ export interface ListCollectiblesWithLowestListingArgs {
912
+ contractAddress: string
913
+ filter?: CollectiblesFilter
914
+ page?: Page
915
+ }
916
+
917
+ export interface ListCollectiblesWithLowestListingReturn {
918
+ collectibles: Array<CollectibleOrder>
919
+ page?: Page
920
+ }
921
+ export interface ListCollectiblesWithHighestOfferArgs {
922
+ contractAddress: string
923
+ filter?: CollectiblesFilter
924
+ page?: Page
925
+ }
926
+
927
+ export interface ListCollectiblesWithHighestOfferReturn {
928
+ collectibles: Array<CollectibleOrder>
929
+ page?: Page
930
+ }
931
+ export interface SyncOrderArgs {
932
+ order: Order
933
+ }
934
+
935
+ export interface SyncOrderReturn {}
936
+ export interface SyncOrdersArgs {
937
+ orders: Array<Order>
938
+ }
939
+
940
+ export interface SyncOrdersReturn {}
941
+ export interface GetOrdersArgs {
942
+ input: Array<GetOrdersInput>
943
+ page?: Page
944
+ }
945
+
946
+ export interface GetOrdersReturn {
947
+ orders: Array<Order>
948
+ page?: Page
949
+ }
950
+ export interface CheckoutOptionsMarketplaceArgs {
951
+ wallet: string
952
+ orders: Array<CheckoutOptionsMarketplaceOrder>
953
+ additionalFee: number
954
+ }
955
+
956
+ export interface CheckoutOptionsMarketplaceReturn {
957
+ options: CheckoutOptions
958
+ }
959
+ export interface CheckoutOptionsSalesContractArgs {
960
+ wallet: string
961
+ contractAddress: string
962
+ collectionAddress: string
963
+ items: Array<CheckoutOptionsItem>
964
+ }
965
+
966
+ export interface CheckoutOptionsSalesContractReturn {
967
+ options: CheckoutOptions
968
+ }
969
+
970
+ //
971
+ // Client
972
+ //
973
+ export class Admin implements Admin {
974
+ protected hostname: string
975
+ protected fetch: Fetch
976
+ protected path = '/rpc/Admin/'
977
+
978
+ constructor(hostname: string, fetch: Fetch) {
979
+ this.hostname = hostname.replace(/\/*$/, '')
980
+ this.fetch = (input: RequestInfo, init?: RequestInit) => fetch(input, init)
981
+ }
982
+
983
+ private url(name: string): string {
984
+ return this.hostname + this.path + name
985
+ }
986
+
987
+ createCollection = (args: CreateCollectionArgs, headers?: object, signal?: AbortSignal): Promise<CreateCollectionReturn> => {
988
+ return this.fetch(this.url('CreateCollection'), createHTTPRequest(args, headers, signal)).then(
989
+ res => {
990
+ return buildResponse(res).then(_data => {
991
+ return {
992
+ collection: <Collection>_data.collection
993
+ }
994
+ })
995
+ },
996
+ error => {
997
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
998
+ }
999
+ )
1000
+ }
1001
+
1002
+ getCollection = (args: GetCollectionArgs, headers?: object, signal?: AbortSignal): Promise<GetCollectionReturn> => {
1003
+ return this.fetch(this.url('GetCollection'), createHTTPRequest(args, headers, signal)).then(
1004
+ res => {
1005
+ return buildResponse(res).then(_data => {
1006
+ return {
1007
+ collection: <Collection>_data.collection
1008
+ }
1009
+ })
1010
+ },
1011
+ error => {
1012
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1013
+ }
1014
+ )
1015
+ }
1016
+
1017
+ listCollections = (args: ListCollectionsArgs, headers?: object, signal?: AbortSignal): Promise<ListCollectionsReturn> => {
1018
+ return this.fetch(this.url('ListCollections'), createHTTPRequest(args, headers, signal)).then(
1019
+ res => {
1020
+ return buildResponse(res).then(_data => {
1021
+ return {
1022
+ collections: <Array<Collection>>_data.collections,
1023
+ page: <Page>_data.page
1024
+ }
1025
+ })
1026
+ },
1027
+ error => {
1028
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1029
+ }
1030
+ )
1031
+ }
1032
+
1033
+ deleteCollection = (args: DeleteCollectionArgs, headers?: object, signal?: AbortSignal): Promise<DeleteCollectionReturn> => {
1034
+ return this.fetch(this.url('DeleteCollection'), createHTTPRequest(args, headers, signal)).then(
1035
+ res => {
1036
+ return buildResponse(res).then(_data => {
1037
+ return {
1038
+ collection: <Collection>_data.collection
1039
+ }
1040
+ })
1041
+ },
1042
+ error => {
1043
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1044
+ }
1045
+ )
1046
+ }
1047
+
1048
+ syncCollection = (args: SyncCollectionArgs, headers?: object, signal?: AbortSignal): Promise<SyncCollectionReturn> => {
1049
+ return this.fetch(this.url('SyncCollection'), createHTTPRequest(args, headers, signal)).then(
1050
+ res => {
1051
+ return buildResponse(res).then(_data => {
1052
+ return {
1053
+ collection: <Collection>_data.collection
1054
+ }
1055
+ })
1056
+ },
1057
+ error => {
1058
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1059
+ }
1060
+ )
1061
+ }
1062
+
1063
+ createCurrency = (args: CreateCurrencyArgs, headers?: object, signal?: AbortSignal): Promise<CreateCurrencyReturn> => {
1064
+ return this.fetch(this.url('CreateCurrency'), createHTTPRequest(args, headers, signal)).then(
1065
+ res => {
1066
+ return buildResponse(res).then(_data => {
1067
+ return {
1068
+ currency: <Currency>_data.currency
1069
+ }
1070
+ })
1071
+ },
1072
+ error => {
1073
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1074
+ }
1075
+ )
1076
+ }
1077
+
1078
+ createCurrencies = (args: CreateCurrenciesArgs, headers?: object, signal?: AbortSignal): Promise<CreateCurrenciesReturn> => {
1079
+ return this.fetch(this.url('CreateCurrencies'), createHTTPRequest(args, headers, signal)).then(
1080
+ res => {
1081
+ return buildResponse(res).then(_data => {
1082
+ return {
1083
+ currency: <{ [key: string]: Currency }>_data.currency
1084
+ }
1085
+ })
1086
+ },
1087
+ error => {
1088
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1089
+ }
1090
+ )
1091
+ }
1092
+
1093
+ updateCurrency = (args: UpdateCurrencyArgs, headers?: object, signal?: AbortSignal): Promise<UpdateCurrencyReturn> => {
1094
+ return this.fetch(this.url('UpdateCurrency'), createHTTPRequest(args, headers, signal)).then(
1095
+ res => {
1096
+ return buildResponse(res).then(_data => {
1097
+ return {
1098
+ currency: <Currency>_data.currency
1099
+ }
1100
+ })
1101
+ },
1102
+ error => {
1103
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1104
+ }
1105
+ )
1106
+ }
1107
+
1108
+ listCurrencies = (headers?: object, signal?: AbortSignal): Promise<ListCurrenciesReturn> => {
1109
+ return this.fetch(this.url('ListCurrencies'), createHTTPRequest({}, headers, signal)).then(
1110
+ res => {
1111
+ return buildResponse(res).then(_data => {
1112
+ return {
1113
+ currencies: <Array<Currency>>_data.currencies
1114
+ }
1115
+ })
1116
+ },
1117
+ error => {
1118
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1119
+ }
1120
+ )
1121
+ }
1122
+
1123
+ deleteCurrency = (args: DeleteCurrencyArgs, headers?: object, signal?: AbortSignal): Promise<DeleteCurrencyReturn> => {
1124
+ return this.fetch(this.url('DeleteCurrency'), createHTTPRequest(args, headers, signal)).then(
1125
+ res => {
1126
+ return buildResponse(res).then(_data => {
1127
+ return {
1128
+ currency: <Currency>_data.currency
1129
+ }
1130
+ })
1131
+ },
1132
+ error => {
1133
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1134
+ }
1135
+ )
1136
+ }
1137
+ }
1138
+ export class Marketplace implements Marketplace {
1139
+ protected hostname: string
1140
+ protected fetch: Fetch
1141
+ protected path = '/rpc/Marketplace/'
1142
+
1143
+ constructor(hostname: string, fetch: Fetch) {
1144
+ this.hostname = hostname.replace(/\/*$/, '')
1145
+ this.fetch = (input: RequestInfo, init?: RequestInit) => fetch(input, init)
1146
+ }
1147
+
1148
+ private url(name: string): string {
1149
+ return this.hostname + this.path + name
1150
+ }
1151
+
1152
+ listCurrencies = (headers?: object, signal?: AbortSignal): Promise<ListCurrenciesReturn> => {
1153
+ return this.fetch(this.url('ListCurrencies'), createHTTPRequest({}, headers, signal)).then(
1154
+ res => {
1155
+ return buildResponse(res).then(_data => {
1156
+ return {
1157
+ currencies: <Array<Currency>>_data.currencies
1158
+ }
1159
+ })
1160
+ },
1161
+ error => {
1162
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1163
+ }
1164
+ )
1165
+ }
1166
+
1167
+ getCollectible = (args: GetCollectibleArgs, headers?: object, signal?: AbortSignal): Promise<GetCollectibleReturn> => {
1168
+ return this.fetch(this.url('GetCollectible'), createHTTPRequest(args, headers, signal)).then(
1169
+ res => {
1170
+ return buildResponse(res).then(_data => {
1171
+ return {
1172
+ metadata: <TokenMetadata>_data.metadata
1173
+ }
1174
+ })
1175
+ },
1176
+ error => {
1177
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1178
+ }
1179
+ )
1180
+ }
1181
+
1182
+ getLowestPriceOfferForCollectible = (
1183
+ args: GetLowestPriceOfferForCollectibleArgs,
1184
+ headers?: object,
1185
+ signal?: AbortSignal
1186
+ ): Promise<GetLowestPriceOfferForCollectibleReturn> => {
1187
+ return this.fetch(this.url('GetLowestPriceOfferForCollectible'), createHTTPRequest(args, headers, signal)).then(
1188
+ res => {
1189
+ return buildResponse(res).then(_data => {
1190
+ return {
1191
+ order: <Order>_data.order
1192
+ }
1193
+ })
1194
+ },
1195
+ error => {
1196
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1197
+ }
1198
+ )
1199
+ }
1200
+
1201
+ getHighestPriceOfferForCollectible = (
1202
+ args: GetHighestPriceOfferForCollectibleArgs,
1203
+ headers?: object,
1204
+ signal?: AbortSignal
1205
+ ): Promise<GetHighestPriceOfferForCollectibleReturn> => {
1206
+ return this.fetch(this.url('GetHighestPriceOfferForCollectible'), createHTTPRequest(args, headers, signal)).then(
1207
+ res => {
1208
+ return buildResponse(res).then(_data => {
1209
+ return {
1210
+ order: <Order>_data.order
1211
+ }
1212
+ })
1213
+ },
1214
+ error => {
1215
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1216
+ }
1217
+ )
1218
+ }
1219
+
1220
+ getLowestPriceListingForCollectible = (
1221
+ args: GetLowestPriceListingForCollectibleArgs,
1222
+ headers?: object,
1223
+ signal?: AbortSignal
1224
+ ): Promise<GetLowestPriceListingForCollectibleReturn> => {
1225
+ return this.fetch(this.url('GetLowestPriceListingForCollectible'), createHTTPRequest(args, headers, signal)).then(
1226
+ res => {
1227
+ return buildResponse(res).then(_data => {
1228
+ return {
1229
+ order: <Order>_data.order
1230
+ }
1231
+ })
1232
+ },
1233
+ error => {
1234
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1235
+ }
1236
+ )
1237
+ }
1238
+
1239
+ getHighestPriceListingForCollectible = (
1240
+ args: GetHighestPriceListingForCollectibleArgs,
1241
+ headers?: object,
1242
+ signal?: AbortSignal
1243
+ ): Promise<GetHighestPriceListingForCollectibleReturn> => {
1244
+ return this.fetch(this.url('GetHighestPriceListingForCollectible'), createHTTPRequest(args, headers, signal)).then(
1245
+ res => {
1246
+ return buildResponse(res).then(_data => {
1247
+ return {
1248
+ order: <Order>_data.order
1249
+ }
1250
+ })
1251
+ },
1252
+ error => {
1253
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1254
+ }
1255
+ )
1256
+ }
1257
+
1258
+ listListingsForCollectible = (
1259
+ args: ListListingsForCollectibleArgs,
1260
+ headers?: object,
1261
+ signal?: AbortSignal
1262
+ ): Promise<ListListingsForCollectibleReturn> => {
1263
+ return this.fetch(this.url('ListListingsForCollectible'), createHTTPRequest(args, headers, signal)).then(
1264
+ res => {
1265
+ return buildResponse(res).then(_data => {
1266
+ return {
1267
+ listings: <Array<Order>>_data.listings,
1268
+ page: <Page>_data.page
1269
+ }
1270
+ })
1271
+ },
1272
+ error => {
1273
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1274
+ }
1275
+ )
1276
+ }
1277
+
1278
+ listOffersForCollectible = (
1279
+ args: ListOffersForCollectibleArgs,
1280
+ headers?: object,
1281
+ signal?: AbortSignal
1282
+ ): Promise<ListOffersForCollectibleReturn> => {
1283
+ return this.fetch(this.url('ListOffersForCollectible'), createHTTPRequest(args, headers, signal)).then(
1284
+ res => {
1285
+ return buildResponse(res).then(_data => {
1286
+ return {
1287
+ offers: <Array<Order>>_data.offers,
1288
+ page: <Page>_data.page
1289
+ }
1290
+ })
1291
+ },
1292
+ error => {
1293
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1294
+ }
1295
+ )
1296
+ }
1297
+
1298
+ getCollectibleLowestOffer = (
1299
+ args: GetCollectibleLowestOfferArgs,
1300
+ headers?: object,
1301
+ signal?: AbortSignal
1302
+ ): Promise<GetCollectibleLowestOfferReturn> => {
1303
+ return this.fetch(this.url('GetCollectibleLowestOffer'), createHTTPRequest(args, headers, signal)).then(
1304
+ res => {
1305
+ return buildResponse(res).then(_data => {
1306
+ return {
1307
+ order: <Order>_data.order
1308
+ }
1309
+ })
1310
+ },
1311
+ error => {
1312
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1313
+ }
1314
+ )
1315
+ }
1316
+
1317
+ getCollectibleHighestOffer = (
1318
+ args: GetCollectibleHighestOfferArgs,
1319
+ headers?: object,
1320
+ signal?: AbortSignal
1321
+ ): Promise<GetCollectibleHighestOfferReturn> => {
1322
+ return this.fetch(this.url('GetCollectibleHighestOffer'), createHTTPRequest(args, headers, signal)).then(
1323
+ res => {
1324
+ return buildResponse(res).then(_data => {
1325
+ return {
1326
+ order: <Order>_data.order
1327
+ }
1328
+ })
1329
+ },
1330
+ error => {
1331
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1332
+ }
1333
+ )
1334
+ }
1335
+
1336
+ getCollectibleLowestListing = (
1337
+ args: GetCollectibleLowestListingArgs,
1338
+ headers?: object,
1339
+ signal?: AbortSignal
1340
+ ): Promise<GetCollectibleLowestListingReturn> => {
1341
+ return this.fetch(this.url('GetCollectibleLowestListing'), createHTTPRequest(args, headers, signal)).then(
1342
+ res => {
1343
+ return buildResponse(res).then(_data => {
1344
+ return {
1345
+ order: <Order>_data.order
1346
+ }
1347
+ })
1348
+ },
1349
+ error => {
1350
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1351
+ }
1352
+ )
1353
+ }
1354
+
1355
+ getCollectibleHighestListing = (
1356
+ args: GetCollectibleHighestListingArgs,
1357
+ headers?: object,
1358
+ signal?: AbortSignal
1359
+ ): Promise<GetCollectibleHighestListingReturn> => {
1360
+ return this.fetch(this.url('GetCollectibleHighestListing'), createHTTPRequest(args, headers, signal)).then(
1361
+ res => {
1362
+ return buildResponse(res).then(_data => {
1363
+ return {
1364
+ order: <Order>_data.order
1365
+ }
1366
+ })
1367
+ },
1368
+ error => {
1369
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1370
+ }
1371
+ )
1372
+ }
1373
+
1374
+ listCollectibleListings = (
1375
+ args: ListCollectibleListingsArgs,
1376
+ headers?: object,
1377
+ signal?: AbortSignal
1378
+ ): Promise<ListCollectibleListingsReturn> => {
1379
+ return this.fetch(this.url('ListCollectibleListings'), createHTTPRequest(args, headers, signal)).then(
1380
+ res => {
1381
+ return buildResponse(res).then(_data => {
1382
+ return {
1383
+ listings: <Array<Order>>_data.listings,
1384
+ page: <Page>_data.page
1385
+ }
1386
+ })
1387
+ },
1388
+ error => {
1389
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1390
+ }
1391
+ )
1392
+ }
1393
+
1394
+ listCollectibleOffers = (
1395
+ args: ListCollectibleOffersArgs,
1396
+ headers?: object,
1397
+ signal?: AbortSignal
1398
+ ): Promise<ListCollectibleOffersReturn> => {
1399
+ return this.fetch(this.url('ListCollectibleOffers'), createHTTPRequest(args, headers, signal)).then(
1400
+ res => {
1401
+ return buildResponse(res).then(_data => {
1402
+ return {
1403
+ offers: <Array<Order>>_data.offers,
1404
+ page: <Page>_data.page
1405
+ }
1406
+ })
1407
+ },
1408
+ error => {
1409
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1410
+ }
1411
+ )
1412
+ }
1413
+
1414
+ generateBuyTransaction = (
1415
+ args: GenerateBuyTransactionArgs,
1416
+ headers?: object,
1417
+ signal?: AbortSignal
1418
+ ): Promise<GenerateBuyTransactionReturn> => {
1419
+ return this.fetch(this.url('GenerateBuyTransaction'), createHTTPRequest(args, headers, signal)).then(
1420
+ res => {
1421
+ return buildResponse(res).then(_data => {
1422
+ return {
1423
+ steps: <Array<Step>>_data.steps
1424
+ }
1425
+ })
1426
+ },
1427
+ error => {
1428
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1429
+ }
1430
+ )
1431
+ }
1432
+
1433
+ generateSellTransaction = (
1434
+ args: GenerateSellTransactionArgs,
1435
+ headers?: object,
1436
+ signal?: AbortSignal
1437
+ ): Promise<GenerateSellTransactionReturn> => {
1438
+ return this.fetch(this.url('GenerateSellTransaction'), createHTTPRequest(args, headers, signal)).then(
1439
+ res => {
1440
+ return buildResponse(res).then(_data => {
1441
+ return {
1442
+ steps: <Array<Step>>_data.steps
1443
+ }
1444
+ })
1445
+ },
1446
+ error => {
1447
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1448
+ }
1449
+ )
1450
+ }
1451
+
1452
+ generateListingTransaction = (
1453
+ args: GenerateListingTransactionArgs,
1454
+ headers?: object,
1455
+ signal?: AbortSignal
1456
+ ): Promise<GenerateListingTransactionReturn> => {
1457
+ return this.fetch(this.url('GenerateListingTransaction'), createHTTPRequest(args, headers, signal)).then(
1458
+ res => {
1459
+ return buildResponse(res).then(_data => {
1460
+ return {
1461
+ steps: <Array<Step>>_data.steps
1462
+ }
1463
+ })
1464
+ },
1465
+ error => {
1466
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1467
+ }
1468
+ )
1469
+ }
1470
+
1471
+ generateOfferTransaction = (
1472
+ args: GenerateOfferTransactionArgs,
1473
+ headers?: object,
1474
+ signal?: AbortSignal
1475
+ ): Promise<GenerateOfferTransactionReturn> => {
1476
+ return this.fetch(this.url('GenerateOfferTransaction'), createHTTPRequest(args, headers, signal)).then(
1477
+ res => {
1478
+ return buildResponse(res).then(_data => {
1479
+ return {
1480
+ steps: <Array<Step>>_data.steps
1481
+ }
1482
+ })
1483
+ },
1484
+ error => {
1485
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1486
+ }
1487
+ )
1488
+ }
1489
+
1490
+ execute = (args: ExecuteArgs, headers?: object, signal?: AbortSignal): Promise<ExecuteReturn> => {
1491
+ return this.fetch(this.url('Execute'), createHTTPRequest(args, headers, signal)).then(
1492
+ res => {
1493
+ return buildResponse(res).then(_data => {
1494
+ return {
1495
+ orderId: <string>_data.orderId
1496
+ }
1497
+ })
1498
+ },
1499
+ error => {
1500
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1501
+ }
1502
+ )
1503
+ }
1504
+
1505
+ listCollectibles = (args: ListCollectiblesArgs, headers?: object, signal?: AbortSignal): Promise<ListCollectiblesReturn> => {
1506
+ return this.fetch(this.url('ListCollectibles'), createHTTPRequest(args, headers, signal)).then(
1507
+ res => {
1508
+ return buildResponse(res).then(_data => {
1509
+ return {
1510
+ collectibles: <Array<CollectibleOrder>>_data.collectibles,
1511
+ page: <Page>_data.page
1512
+ }
1513
+ })
1514
+ },
1515
+ error => {
1516
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1517
+ }
1518
+ )
1519
+ }
1520
+
1521
+ getCountOfAllCollectibles = (
1522
+ args: GetCountOfAllCollectiblesArgs,
1523
+ headers?: object,
1524
+ signal?: AbortSignal
1525
+ ): Promise<GetCountOfAllCollectiblesReturn> => {
1526
+ return this.fetch(this.url('GetCountOfAllCollectibles'), createHTTPRequest(args, headers, signal)).then(
1527
+ res => {
1528
+ return buildResponse(res).then(_data => {
1529
+ return {
1530
+ count: <number>_data.count
1531
+ }
1532
+ })
1533
+ },
1534
+ error => {
1535
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1536
+ }
1537
+ )
1538
+ }
1539
+
1540
+ getCountOfFilteredCollectibles = (
1541
+ args: GetCountOfFilteredCollectiblesArgs,
1542
+ headers?: object,
1543
+ signal?: AbortSignal
1544
+ ): Promise<GetCountOfFilteredCollectiblesReturn> => {
1545
+ return this.fetch(this.url('GetCountOfFilteredCollectibles'), createHTTPRequest(args, headers, signal)).then(
1546
+ res => {
1547
+ return buildResponse(res).then(_data => {
1548
+ return {
1549
+ count: <number>_data.count
1550
+ }
1551
+ })
1552
+ },
1553
+ error => {
1554
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1555
+ }
1556
+ )
1557
+ }
1558
+
1559
+ getFloorOrder = (args: GetFloorOrderArgs, headers?: object, signal?: AbortSignal): Promise<GetFloorOrderReturn> => {
1560
+ return this.fetch(this.url('GetFloorOrder'), createHTTPRequest(args, headers, signal)).then(
1561
+ res => {
1562
+ return buildResponse(res).then(_data => {
1563
+ return {
1564
+ collectible: <CollectibleOrder>_data.collectible
1565
+ }
1566
+ })
1567
+ },
1568
+ error => {
1569
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1570
+ }
1571
+ )
1572
+ }
1573
+
1574
+ listCollectiblesWithLowestListing = (
1575
+ args: ListCollectiblesWithLowestListingArgs,
1576
+ headers?: object,
1577
+ signal?: AbortSignal
1578
+ ): Promise<ListCollectiblesWithLowestListingReturn> => {
1579
+ return this.fetch(this.url('ListCollectiblesWithLowestListing'), createHTTPRequest(args, headers, signal)).then(
1580
+ res => {
1581
+ return buildResponse(res).then(_data => {
1582
+ return {
1583
+ collectibles: <Array<CollectibleOrder>>_data.collectibles,
1584
+ page: <Page>_data.page
1585
+ }
1586
+ })
1587
+ },
1588
+ error => {
1589
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1590
+ }
1591
+ )
1592
+ }
1593
+
1594
+ listCollectiblesWithHighestOffer = (
1595
+ args: ListCollectiblesWithHighestOfferArgs,
1596
+ headers?: object,
1597
+ signal?: AbortSignal
1598
+ ): Promise<ListCollectiblesWithHighestOfferReturn> => {
1599
+ return this.fetch(this.url('ListCollectiblesWithHighestOffer'), createHTTPRequest(args, headers, signal)).then(
1600
+ res => {
1601
+ return buildResponse(res).then(_data => {
1602
+ return {
1603
+ collectibles: <Array<CollectibleOrder>>_data.collectibles,
1604
+ page: <Page>_data.page
1605
+ }
1606
+ })
1607
+ },
1608
+ error => {
1609
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1610
+ }
1611
+ )
1612
+ }
1613
+
1614
+ syncOrder = (args: SyncOrderArgs, headers?: object, signal?: AbortSignal): Promise<SyncOrderReturn> => {
1615
+ return this.fetch(this.url('SyncOrder'), createHTTPRequest(args, headers, signal)).then(
1616
+ res => {
1617
+ return buildResponse(res).then(_data => {
1618
+ return {}
1619
+ })
1620
+ },
1621
+ error => {
1622
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1623
+ }
1624
+ )
1625
+ }
1626
+
1627
+ syncOrders = (args: SyncOrdersArgs, headers?: object, signal?: AbortSignal): Promise<SyncOrdersReturn> => {
1628
+ return this.fetch(this.url('SyncOrders'), createHTTPRequest(args, headers, signal)).then(
1629
+ res => {
1630
+ return buildResponse(res).then(_data => {
1631
+ return {}
1632
+ })
1633
+ },
1634
+ error => {
1635
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1636
+ }
1637
+ )
1638
+ }
1639
+
1640
+ getOrders = (args: GetOrdersArgs, headers?: object, signal?: AbortSignal): Promise<GetOrdersReturn> => {
1641
+ return this.fetch(this.url('GetOrders'), createHTTPRequest(args, headers, signal)).then(
1642
+ res => {
1643
+ return buildResponse(res).then(_data => {
1644
+ return {
1645
+ orders: <Array<Order>>_data.orders,
1646
+ page: <Page>_data.page
1647
+ }
1648
+ })
1649
+ },
1650
+ error => {
1651
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1652
+ }
1653
+ )
1654
+ }
1655
+
1656
+ checkoutOptionsMarketplace = (
1657
+ args: CheckoutOptionsMarketplaceArgs,
1658
+ headers?: object,
1659
+ signal?: AbortSignal
1660
+ ): Promise<CheckoutOptionsMarketplaceReturn> => {
1661
+ return this.fetch(this.url('CheckoutOptionsMarketplace'), createHTTPRequest(args, headers, signal)).then(
1662
+ res => {
1663
+ return buildResponse(res).then(_data => {
1664
+ return {
1665
+ options: <CheckoutOptions>_data.options
1666
+ }
1667
+ })
1668
+ },
1669
+ error => {
1670
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1671
+ }
1672
+ )
1673
+ }
1674
+
1675
+ checkoutOptionsSalesContract = (
1676
+ args: CheckoutOptionsSalesContractArgs,
1677
+ headers?: object,
1678
+ signal?: AbortSignal
1679
+ ): Promise<CheckoutOptionsSalesContractReturn> => {
1680
+ return this.fetch(this.url('CheckoutOptionsSalesContract'), createHTTPRequest(args, headers, signal)).then(
1681
+ res => {
1682
+ return buildResponse(res).then(_data => {
1683
+ return {
1684
+ options: <CheckoutOptions>_data.options
1685
+ }
1686
+ })
1687
+ },
1688
+ error => {
1689
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
1690
+ }
1691
+ )
1692
+ }
1693
+ }
1694
+
1695
+ const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => {
1696
+ const reqHeaders: { [key: string]: string } = { ...headers, 'Content-Type': 'application/json' }
1697
+ reqHeaders[WebrpcHeader] = WebrpcHeaderValue
1698
+
1699
+ return {
1700
+ method: 'POST',
1701
+ headers: reqHeaders,
1702
+ body: JSON.stringify(body || {}),
1703
+ signal
1704
+ }
1705
+ }
1706
+
1707
+ const buildResponse = (res: Response): Promise<any> => {
1708
+ return res.text().then(text => {
1709
+ let data
1710
+ try {
1711
+ data = JSON.parse(text)
1712
+ } catch (error) {
1713
+ let message = ''
1714
+ if (error instanceof Error) {
1715
+ message = error.message
1716
+ }
1717
+ throw WebrpcBadResponseError.new({
1718
+ status: res.status,
1719
+ cause: `JSON.parse(): ${message}: response text: ${text}`
1720
+ })
1721
+ }
1722
+ if (!res.ok) {
1723
+ const code: number = typeof data.code === 'number' ? data.code : 0
1724
+ throw (webrpcErrorByCode[code] || WebrpcError).new(data)
1725
+ }
1726
+ return data
1727
+ })
1728
+ }
1729
+
1730
+ //
1731
+ // Errors
1732
+ //
1733
+
1734
+ export class WebrpcError extends Error {
1735
+ name: string
1736
+ code: number
1737
+ message: string
1738
+ status: number
1739
+ cause?: string
1740
+
1741
+ /** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */
1742
+ msg: string
1743
+
1744
+ constructor(name: string, code: number, message: string, status: number, cause?: string) {
1745
+ super(message)
1746
+ this.name = name || 'WebrpcError'
1747
+ this.code = typeof code === 'number' ? code : 0
1748
+ this.message = message || `endpoint error ${this.code}`
1749
+ this.msg = this.message
1750
+ this.status = typeof status === 'number' ? status : 0
1751
+ this.cause = cause
1752
+ Object.setPrototypeOf(this, WebrpcError.prototype)
1753
+ }
1754
+
1755
+ static new(payload: any): WebrpcError {
1756
+ return new this(payload.error, payload.code, payload.message || payload.msg, payload.status, payload.cause)
1757
+ }
1758
+ }
1759
+
1760
+ // Webrpc errors
1761
+
1762
+ export class WebrpcEndpointError extends WebrpcError {
1763
+ constructor(
1764
+ name: string = 'WebrpcEndpoint',
1765
+ code: number = 0,
1766
+ message: string = 'endpoint error',
1767
+ status: number = 0,
1768
+ cause?: string
1769
+ ) {
1770
+ super(name, code, message, status, cause)
1771
+ Object.setPrototypeOf(this, WebrpcEndpointError.prototype)
1772
+ }
1773
+ }
1774
+
1775
+ export class WebrpcRequestFailedError extends WebrpcError {
1776
+ constructor(
1777
+ name: string = 'WebrpcRequestFailed',
1778
+ code: number = -1,
1779
+ message: string = 'request failed',
1780
+ status: number = 0,
1781
+ cause?: string
1782
+ ) {
1783
+ super(name, code, message, status, cause)
1784
+ Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype)
1785
+ }
1786
+ }
1787
+
1788
+ export class WebrpcBadRouteError extends WebrpcError {
1789
+ constructor(
1790
+ name: string = 'WebrpcBadRoute',
1791
+ code: number = -2,
1792
+ message: string = 'bad route',
1793
+ status: number = 0,
1794
+ cause?: string
1795
+ ) {
1796
+ super(name, code, message, status, cause)
1797
+ Object.setPrototypeOf(this, WebrpcBadRouteError.prototype)
1798
+ }
1799
+ }
1800
+
1801
+ export class WebrpcBadMethodError extends WebrpcError {
1802
+ constructor(
1803
+ name: string = 'WebrpcBadMethod',
1804
+ code: number = -3,
1805
+ message: string = 'bad method',
1806
+ status: number = 0,
1807
+ cause?: string
1808
+ ) {
1809
+ super(name, code, message, status, cause)
1810
+ Object.setPrototypeOf(this, WebrpcBadMethodError.prototype)
1811
+ }
1812
+ }
1813
+
1814
+ export class WebrpcBadRequestError extends WebrpcError {
1815
+ constructor(
1816
+ name: string = 'WebrpcBadRequest',
1817
+ code: number = -4,
1818
+ message: string = 'bad request',
1819
+ status: number = 0,
1820
+ cause?: string
1821
+ ) {
1822
+ super(name, code, message, status, cause)
1823
+ Object.setPrototypeOf(this, WebrpcBadRequestError.prototype)
1824
+ }
1825
+ }
1826
+
1827
+ export class WebrpcBadResponseError extends WebrpcError {
1828
+ constructor(
1829
+ name: string = 'WebrpcBadResponse',
1830
+ code: number = -5,
1831
+ message: string = 'bad response',
1832
+ status: number = 0,
1833
+ cause?: string
1834
+ ) {
1835
+ super(name, code, message, status, cause)
1836
+ Object.setPrototypeOf(this, WebrpcBadResponseError.prototype)
1837
+ }
1838
+ }
1839
+
1840
+ export class WebrpcServerPanicError extends WebrpcError {
1841
+ constructor(
1842
+ name: string = 'WebrpcServerPanic',
1843
+ code: number = -6,
1844
+ message: string = 'server panic',
1845
+ status: number = 0,
1846
+ cause?: string
1847
+ ) {
1848
+ super(name, code, message, status, cause)
1849
+ Object.setPrototypeOf(this, WebrpcServerPanicError.prototype)
1850
+ }
1851
+ }
1852
+
1853
+ export class WebrpcInternalErrorError extends WebrpcError {
1854
+ constructor(
1855
+ name: string = 'WebrpcInternalError',
1856
+ code: number = -7,
1857
+ message: string = 'internal error',
1858
+ status: number = 0,
1859
+ cause?: string
1860
+ ) {
1861
+ super(name, code, message, status, cause)
1862
+ Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype)
1863
+ }
1864
+ }
1865
+
1866
+ export class WebrpcClientDisconnectedError extends WebrpcError {
1867
+ constructor(
1868
+ name: string = 'WebrpcClientDisconnected',
1869
+ code: number = -8,
1870
+ message: string = 'client disconnected',
1871
+ status: number = 0,
1872
+ cause?: string
1873
+ ) {
1874
+ super(name, code, message, status, cause)
1875
+ Object.setPrototypeOf(this, WebrpcClientDisconnectedError.prototype)
1876
+ }
1877
+ }
1878
+
1879
+ export class WebrpcStreamLostError extends WebrpcError {
1880
+ constructor(
1881
+ name: string = 'WebrpcStreamLost',
1882
+ code: number = -9,
1883
+ message: string = 'stream lost',
1884
+ status: number = 0,
1885
+ cause?: string
1886
+ ) {
1887
+ super(name, code, message, status, cause)
1888
+ Object.setPrototypeOf(this, WebrpcStreamLostError.prototype)
1889
+ }
1890
+ }
1891
+
1892
+ export class WebrpcStreamFinishedError extends WebrpcError {
1893
+ constructor(
1894
+ name: string = 'WebrpcStreamFinished',
1895
+ code: number = -10,
1896
+ message: string = 'stream finished',
1897
+ status: number = 0,
1898
+ cause?: string
1899
+ ) {
1900
+ super(name, code, message, status, cause)
1901
+ Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype)
1902
+ }
1903
+ }
1904
+
1905
+ // Schema errors
1906
+
1907
+ export class UnauthorizedError extends WebrpcError {
1908
+ constructor(
1909
+ name: string = 'Unauthorized',
1910
+ code: number = 1000,
1911
+ message: string = 'Unauthorized access',
1912
+ status: number = 0,
1913
+ cause?: string
1914
+ ) {
1915
+ super(name, code, message, status, cause)
1916
+ Object.setPrototypeOf(this, UnauthorizedError.prototype)
1917
+ }
1918
+ }
1919
+
1920
+ export class PermissionDeniedError extends WebrpcError {
1921
+ constructor(
1922
+ name: string = 'PermissionDenied',
1923
+ code: number = 1001,
1924
+ message: string = 'Permission denied',
1925
+ status: number = 0,
1926
+ cause?: string
1927
+ ) {
1928
+ super(name, code, message, status, cause)
1929
+ Object.setPrototypeOf(this, PermissionDeniedError.prototype)
1930
+ }
1931
+ }
1932
+
1933
+ export class SessionExpiredError extends WebrpcError {
1934
+ constructor(
1935
+ name: string = 'SessionExpired',
1936
+ code: number = 1002,
1937
+ message: string = 'Session expired',
1938
+ status: number = 0,
1939
+ cause?: string
1940
+ ) {
1941
+ super(name, code, message, status, cause)
1942
+ Object.setPrototypeOf(this, SessionExpiredError.prototype)
1943
+ }
1944
+ }
1945
+
1946
+ export class MethodNotFoundError extends WebrpcError {
1947
+ constructor(
1948
+ name: string = 'MethodNotFound',
1949
+ code: number = 1003,
1950
+ message: string = 'Method not found',
1951
+ status: number = 0,
1952
+ cause?: string
1953
+ ) {
1954
+ super(name, code, message, status, cause)
1955
+ Object.setPrototypeOf(this, MethodNotFoundError.prototype)
1956
+ }
1957
+ }
1958
+
1959
+ export class TimeoutError extends WebrpcError {
1960
+ constructor(
1961
+ name: string = 'Timeout',
1962
+ code: number = 2000,
1963
+ message: string = 'Request timed out',
1964
+ status: number = 0,
1965
+ cause?: string
1966
+ ) {
1967
+ super(name, code, message, status, cause)
1968
+ Object.setPrototypeOf(this, TimeoutError.prototype)
1969
+ }
1970
+ }
1971
+
1972
+ export class InvalidArgumentError extends WebrpcError {
1973
+ constructor(
1974
+ name: string = 'InvalidArgument',
1975
+ code: number = 2001,
1976
+ message: string = 'Invalid argument',
1977
+ status: number = 0,
1978
+ cause?: string
1979
+ ) {
1980
+ super(name, code, message, status, cause)
1981
+ Object.setPrototypeOf(this, InvalidArgumentError.prototype)
1982
+ }
1983
+ }
1984
+
1985
+ export class NotFoundError extends WebrpcError {
1986
+ constructor(
1987
+ name: string = 'NotFound',
1988
+ code: number = 3000,
1989
+ message: string = 'Resource not found',
1990
+ status: number = 0,
1991
+ cause?: string
1992
+ ) {
1993
+ super(name, code, message, status, cause)
1994
+ Object.setPrototypeOf(this, NotFoundError.prototype)
1995
+ }
1996
+ }
1997
+
1998
+ export class UserNotFoundError extends WebrpcError {
1999
+ constructor(
2000
+ name: string = 'UserNotFound',
2001
+ code: number = 3001,
2002
+ message: string = 'User not found',
2003
+ status: number = 0,
2004
+ cause?: string
2005
+ ) {
2006
+ super(name, code, message, status, cause)
2007
+ Object.setPrototypeOf(this, UserNotFoundError.prototype)
2008
+ }
2009
+ }
2010
+
2011
+ export class ProjectNotFoundError extends WebrpcError {
2012
+ constructor(
2013
+ name: string = 'ProjectNotFound',
2014
+ code: number = 3002,
2015
+ message: string = 'Project not found',
2016
+ status: number = 0,
2017
+ cause?: string
2018
+ ) {
2019
+ super(name, code, message, status, cause)
2020
+ Object.setPrototypeOf(this, ProjectNotFoundError.prototype)
2021
+ }
2022
+ }
2023
+
2024
+ export class InvalidTierError extends WebrpcError {
2025
+ constructor(
2026
+ name: string = 'InvalidTier',
2027
+ code: number = 3003,
2028
+ message: string = 'Invalid subscription tier',
2029
+ status: number = 0,
2030
+ cause?: string
2031
+ ) {
2032
+ super(name, code, message, status, cause)
2033
+ Object.setPrototypeOf(this, InvalidTierError.prototype)
2034
+ }
2035
+ }
2036
+
2037
+ export class ProjectLimitReachedError extends WebrpcError {
2038
+ constructor(
2039
+ name: string = 'ProjectLimitReached',
2040
+ code: number = 3005,
2041
+ message: string = 'Project limit reached',
2042
+ status: number = 0,
2043
+ cause?: string
2044
+ ) {
2045
+ super(name, code, message, status, cause)
2046
+ Object.setPrototypeOf(this, ProjectLimitReachedError.prototype)
2047
+ }
2048
+ }
2049
+
2050
+ export class NotImplementedError extends WebrpcError {
2051
+ constructor(
2052
+ name: string = 'NotImplemented',
2053
+ code: number = 9999,
2054
+ message: string = 'Not Implemented',
2055
+ status: number = 0,
2056
+ cause?: string
2057
+ ) {
2058
+ super(name, code, message, status, cause)
2059
+ Object.setPrototypeOf(this, NotImplementedError.prototype)
2060
+ }
2061
+ }
2062
+
2063
+ export enum errors {
2064
+ WebrpcEndpoint = 'WebrpcEndpoint',
2065
+ WebrpcRequestFailed = 'WebrpcRequestFailed',
2066
+ WebrpcBadRoute = 'WebrpcBadRoute',
2067
+ WebrpcBadMethod = 'WebrpcBadMethod',
2068
+ WebrpcBadRequest = 'WebrpcBadRequest',
2069
+ WebrpcBadResponse = 'WebrpcBadResponse',
2070
+ WebrpcServerPanic = 'WebrpcServerPanic',
2071
+ WebrpcInternalError = 'WebrpcInternalError',
2072
+ WebrpcClientDisconnected = 'WebrpcClientDisconnected',
2073
+ WebrpcStreamLost = 'WebrpcStreamLost',
2074
+ WebrpcStreamFinished = 'WebrpcStreamFinished',
2075
+ Unauthorized = 'Unauthorized',
2076
+ PermissionDenied = 'PermissionDenied',
2077
+ SessionExpired = 'SessionExpired',
2078
+ MethodNotFound = 'MethodNotFound',
2079
+ Timeout = 'Timeout',
2080
+ InvalidArgument = 'InvalidArgument',
2081
+ NotFound = 'NotFound',
2082
+ UserNotFound = 'UserNotFound',
2083
+ ProjectNotFound = 'ProjectNotFound',
2084
+ InvalidTier = 'InvalidTier',
2085
+ ProjectLimitReached = 'ProjectLimitReached',
2086
+ NotImplemented = 'NotImplemented'
2087
+ }
2088
+
2089
+ const webrpcErrorByCode: { [code: number]: any } = {
2090
+ [0]: WebrpcEndpointError,
2091
+ [-1]: WebrpcRequestFailedError,
2092
+ [-2]: WebrpcBadRouteError,
2093
+ [-3]: WebrpcBadMethodError,
2094
+ [-4]: WebrpcBadRequestError,
2095
+ [-5]: WebrpcBadResponseError,
2096
+ [-6]: WebrpcServerPanicError,
2097
+ [-7]: WebrpcInternalErrorError,
2098
+ [-8]: WebrpcClientDisconnectedError,
2099
+ [-9]: WebrpcStreamLostError,
2100
+ [-10]: WebrpcStreamFinishedError,
2101
+ [1000]: UnauthorizedError,
2102
+ [1001]: PermissionDeniedError,
2103
+ [1002]: SessionExpiredError,
2104
+ [1003]: MethodNotFoundError,
2105
+ [2000]: TimeoutError,
2106
+ [2001]: InvalidArgumentError,
2107
+ [3000]: NotFoundError,
2108
+ [3001]: UserNotFoundError,
2109
+ [3002]: ProjectNotFoundError,
2110
+ [3003]: InvalidTierError,
2111
+ [3005]: ProjectLimitReachedError,
2112
+ [9999]: NotImplementedError
2113
+ }
2114
+
2115
+ export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>