@0xsequence/marketplace-sdk 0.8.10 → 0.8.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/fluffy-jokes-lay.md +5 -0
- package/.changeset/wise-bugs-boil.md +8 -0
- package/CHANGELOG.md +16 -3
- package/dist/{chunk-DWTLVJAW.js → chunk-6OPMUCGX.js} +1 -1
- package/dist/chunk-6OPMUCGX.js.map +1 -0
- package/dist/{chunk-O34GCB47.js → chunk-L6KWLCER.js} +4 -4
- package/dist/chunk-L6KWLCER.js.map +1 -0
- package/dist/{chunk-Y2HJO2VY.js → chunk-LAP2CKLN.js} +56 -3
- package/dist/chunk-LAP2CKLN.js.map +1 -0
- package/dist/{chunk-Y63BOO6M.js → chunk-LECCEZAO.js} +1 -1
- package/dist/{chunk-WH5BZC7W.js → chunk-N7SQWS2R.js} +3 -3
- package/dist/{chunk-7F27CJZW.js → chunk-OAOONM4S.js} +682 -439
- package/dist/chunk-OAOONM4S.js.map +1 -0
- package/dist/chunk-QY52UADF.js +107 -0
- package/dist/chunk-QY52UADF.js.map +1 -0
- package/dist/{chunk-UJSF7PSC.js → chunk-TNAR3XEF.js} +3766 -765
- package/dist/chunk-TNAR3XEF.js.map +1 -0
- package/dist/chunk-XABYNWXO.js +549 -0
- package/dist/chunk-XABYNWXO.js.map +1 -0
- package/dist/chunk-YB5UUF2G.js +11 -0
- package/dist/chunk-YB5UUF2G.js.map +1 -0
- package/dist/{chunk-M6NJ73Y5.js → chunk-YWGFI4PN.js} +87 -24
- package/dist/chunk-YWGFI4PN.js.map +1 -0
- package/dist/{create-config-CAQcvjl6.d.ts → create-config-DLMvMTkZ.d.ts} +2 -2
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.js +14 -15
- package/dist/{listTokenMetadata-DO4ChDjn.d.ts → marketCurrencies-enNVYwBk.d.ts} +77 -3
- package/dist/{marketplace.gen-DQzWciwC.d.ts → marketplace.gen-D24veUQs.d.ts} +3 -2
- package/dist/marketplaceConfig-BwNAbLPw.d.ts +21 -0
- package/dist/new-marketplace-types-BCw19X9S.d.ts +102 -0
- package/dist/react/_internal/api/index.d.ts +3 -3
- package/dist/react/_internal/api/index.js +1 -1
- package/dist/react/_internal/databeat/index.css +2764 -0
- package/dist/react/_internal/databeat/index.css.map +1 -0
- package/dist/react/_internal/databeat/index.d.ts +1 -1
- package/dist/react/_internal/databeat/index.js +12 -12
- package/dist/react/_internal/index.d.ts +61 -9
- package/dist/react/_internal/index.js +3 -3
- package/dist/react/_internal/wagmi/index.d.ts +5 -6
- package/dist/react/_internal/wagmi/index.js +1 -1
- package/dist/react/hooks/index.css +2764 -0
- package/dist/react/hooks/index.css.map +1 -0
- package/dist/react/hooks/index.d.ts +71 -222
- package/dist/react/hooks/index.js +16 -20
- package/dist/react/hooks/options/index.d.ts +5 -4
- package/dist/react/hooks/options/index.js +9 -7
- package/dist/react/index.css +1 -1
- package/dist/react/index.css.map +1 -1
- package/dist/react/index.d.ts +9 -9
- package/dist/react/index.js +28 -34
- package/dist/react/queries/index.d.ts +3 -3
- package/dist/react/queries/index.js +15 -4
- package/dist/react/ssr/index.d.ts +3 -3
- package/dist/react/ssr/index.js +6 -5
- package/dist/react/ssr/index.js.map +1 -1
- package/dist/react/ui/components/collectible-card/index.css +1 -1
- package/dist/react/ui/components/collectible-card/index.css.map +1 -1
- package/dist/react/ui/components/collectible-card/index.d.ts +3 -2
- package/dist/react/ui/components/collectible-card/index.js +12 -17
- package/dist/react/ui/icons/index.js +6 -6
- package/dist/react/ui/index.css +1 -1
- package/dist/react/ui/index.css.map +1 -1
- package/dist/react/ui/index.d.ts +1 -1
- package/dist/react/ui/index.js +12 -17
- package/dist/react/ui/modals/_internal/components/actionModal/index.css +2764 -0
- package/dist/react/ui/modals/_internal/components/actionModal/index.css.map +1 -0
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +12 -12
- package/dist/sdk-config-qorA0TgF.d.ts +165 -0
- package/dist/{services-CMSb9ipU.d.ts → services-WrshxCqc.d.ts} +2 -2
- package/dist/types/index.d.ts +5 -4
- package/dist/types/index.js +7 -7
- package/dist/{index-MlUK9AQE.d.ts → useCollection-YAdXfVO7.d.ts} +1 -2
- package/dist/utils/abi/index.js +4 -4
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +8 -7
- package/package.json +15 -15
- package/src/react/_internal/api/__mocks__/builder.msw.ts +157 -80
- package/src/react/_internal/api/builder-api.ts +2 -2
- package/src/react/_internal/api/builder.gen.ts +667 -112
- package/src/react/_internal/api/marketplace.gen.ts +1981 -1316
- package/src/react/_internal/types.ts +1 -13
- package/src/react/_internal/wagmi/__tests__/create-config.test.ts +99 -84
- package/src/react/_internal/wagmi/create-config.ts +8 -4
- package/src/react/_internal/wagmi/get-connectors.ts +24 -19
- package/src/react/hooks/__tests__/__snapshots__/useListCollections.test.tsx.snap +114 -0
- package/src/react/hooks/__tests__/__snapshots__/useMarketplaceConfig.test.tsx.snap +85 -83
- package/src/react/hooks/__tests__/useFilters.test.tsx +0 -16
- package/src/react/hooks/__tests__/useInventory.test.tsx +16 -16
- package/src/react/hooks/__tests__/useListCollections.test.tsx +23 -56
- package/src/react/hooks/__tests__/{useCurrencies.test.tsx → useMarketCurrencies.test.tsx} +21 -15
- package/src/react/hooks/__tests__/useMarketplaceConfig.test.tsx +2 -59
- package/src/react/hooks/index.ts +2 -1
- package/src/react/hooks/useBalanceOfCollectible.tsx +5 -3
- package/src/react/hooks/useConvertPriceToUSD.tsx +1 -1
- package/src/react/hooks/useFilters.tsx +14 -22
- package/src/react/hooks/useGetTokenSuppliesMap.ts +28 -0
- package/src/react/hooks/useInventory.tsx +4 -3
- package/src/react/hooks/useListBalances.tsx +5 -3
- package/src/react/hooks/useListCollectibles.tsx +5 -3
- package/src/react/hooks/useListCollections.tsx +14 -76
- package/src/react/hooks/useMarketCurrencies.tsx +8 -0
- package/src/react/hooks/useMarketplaceConfig.tsx +0 -2
- package/src/react/queries/index.ts +1 -0
- package/src/react/queries/inventory.ts +1 -1
- package/src/react/queries/listCollections.ts +118 -0
- package/src/react/queries/marketCurrencies.ts +77 -0
- package/src/react/queries/marketplaceConfig.ts +83 -55
- package/src/react/ssr/__tests__/__snapshots__/create-ssr-client.test.ts.snap +85 -83
- package/src/react/ui/components/collectible-card/__tests__/Media.test.tsx +41 -1
- package/src/react/ui/components/collectible-card/media/Media.tsx +11 -6
- package/src/react/ui/components/collectible-card/media/MediaSkeleton.tsx +1 -1
- package/src/react/ui/components/collectible-card/media/types.ts +1 -0
- package/src/react/ui/modals/BuyModal/ERC1155QuantityModal.tsx +9 -3
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useFees.test.tsx +31 -21
- package/src/react/ui/modals/BuyModal/hooks/useFees.ts +3 -2
- package/src/react/ui/modals/CreateListingModal/Modal.tsx +3 -5
- package/src/react/ui/modals/CreateListingModal/hooks/useCreateListing.tsx +5 -3
- package/src/react/ui/modals/CreateListingModal/hooks/useTransactionSteps.tsx +2 -2
- package/src/react/ui/modals/MakeOfferModal/Modal.tsx +2 -3
- package/src/react/ui/modals/MakeOfferModal/hooks/useMakeOffer.tsx +4 -3
- package/src/react/ui/modals/SellModal/Modal.tsx +0 -1
- package/src/react/ui/modals/SellModal/hooks/useTransactionSteps.tsx +2 -2
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +0 -1
- package/src/react/ui/modals/TransferModal/index.tsx +0 -1
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/__tests__/index.test.tsx +2 -2
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +7 -6
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/__tests__/SelectWaasFeeOptions.test.tsx +13 -7
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/index.tsx +3 -5
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/useWaasFeeOptionManager.tsx +5 -3
- package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +2 -2
- package/src/react/ui/modals/_internal/hooks/useSelectWaasFeeOptions.ts +2 -12
- package/src/types/index.ts +1 -6
- package/src/types/new-marketplace-types.ts +119 -0
- package/src/types/sdk-config.ts +18 -2
- package/src/types/types.ts +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/chunk-7F27CJZW.js.map +0 -1
- package/dist/chunk-A7BVFBWB.js +0 -81
- package/dist/chunk-A7BVFBWB.js.map +0 -1
- package/dist/chunk-D7RVSZAQ.js +0 -332
- package/dist/chunk-D7RVSZAQ.js.map +0 -1
- package/dist/chunk-DWTLVJAW.js.map +0 -1
- package/dist/chunk-FGM57QUU.js +0 -128
- package/dist/chunk-FGM57QUU.js.map +0 -1
- package/dist/chunk-JKCF7HEA.js +0 -1
- package/dist/chunk-JKCF7HEA.js.map +0 -1
- package/dist/chunk-KTST7ORH.js +0 -53
- package/dist/chunk-KTST7ORH.js.map +0 -1
- package/dist/chunk-M6NJ73Y5.js.map +0 -1
- package/dist/chunk-N7BPFK46.js +0 -1
- package/dist/chunk-N7BPFK46.js.map +0 -1
- package/dist/chunk-O34GCB47.js.map +0 -1
- package/dist/chunk-RVIUUJTP.js +0 -76
- package/dist/chunk-RVIUUJTP.js.map +0 -1
- package/dist/chunk-SXVUTSMT.js +0 -2895
- package/dist/chunk-SXVUTSMT.js.map +0 -1
- package/dist/chunk-UJSF7PSC.js.map +0 -1
- package/dist/chunk-Y2HJO2VY.js.map +0 -1
- package/dist/marketplaceConfig-D0MXemEl.d.ts +0 -17
- package/dist/sdk-config-onSPBxJj.d.ts +0 -134
- package/dist/types-B8xzPEKX.d.ts +0 -68
- package/src/react/hooks/useCurrencies.tsx +0 -77
- /package/dist/{chunk-Y63BOO6M.js.map → chunk-LECCEZAO.js.map} +0 -0
- /package/dist/{chunk-WH5BZC7W.js.map → chunk-N7SQWS2R.js.map} +0 -0
|
@@ -1,35 +1,71 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// Relevant parts for lookupMarketplace & common Webrpc utilities
|
|
3
|
+
// sequence-builder v0.1.0 52bd730f3b821fe99051d69ced824442369efe4a
|
|
4
|
+
// --
|
|
5
|
+
// Code generated by webrpc-gen@v0.26.0 with typescript generator. DO NOT EDIT.
|
|
6
|
+
//
|
|
7
|
+
// webrpc-gen -schema=builder.main.ridl -target=typescript -client -out=../../webapp/src/rpc/proto/builder.gen.ts
|
|
8
|
+
|
|
2
9
|
import { OrderbookKind } from "./marketplace.gen";
|
|
3
10
|
|
|
4
|
-
|
|
11
|
+
export const WebrpcHeader = "Webrpc";
|
|
12
|
+
export const WebrpcHeaderValue =
|
|
13
|
+
"webrpc@v0.26.0;gen-typescript@v0.17.0;sequence-builder@v0.1.0";
|
|
14
|
+
|
|
15
|
+
//
|
|
16
|
+
// Types for lookupMarketplace
|
|
17
|
+
//
|
|
18
|
+
|
|
19
|
+
export enum MarketplaceWalletType {
|
|
20
|
+
UNIVERSAL = "UNIVERSAL",
|
|
21
|
+
EMBEDDED = "EMBEDDED",
|
|
22
|
+
ECOSYSTEM = "ECOSYSTEM",
|
|
23
|
+
}
|
|
5
24
|
|
|
6
|
-
export
|
|
25
|
+
export enum FilterCondition {
|
|
26
|
+
ENTIRE_KEY = "ENTIRE_KEY",
|
|
27
|
+
SPECIFIC_VALUE = "SPECIFIC_VALUE",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface LookupMarketplaceArgs {
|
|
7
31
|
projectId?: number;
|
|
8
|
-
|
|
32
|
+
domain?: string;
|
|
9
33
|
}
|
|
10
34
|
|
|
11
|
-
export interface
|
|
35
|
+
export interface LookupMarketplaceReturn {
|
|
36
|
+
marketplace: Marketplace;
|
|
37
|
+
marketCollections: Array<MarketCollection>;
|
|
38
|
+
shopCollections: Array<ShopCollection>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface Marketplace {
|
|
42
|
+
projectId: number;
|
|
12
43
|
settings: MarketplaceSettings;
|
|
44
|
+
market: MarketplacePage;
|
|
45
|
+
shop: MarketplacePage;
|
|
46
|
+
createdAt?: string;
|
|
47
|
+
updatedAt?: string;
|
|
13
48
|
}
|
|
14
49
|
|
|
15
50
|
export interface MarketplaceSettings {
|
|
16
|
-
|
|
51
|
+
style: { [key: string]: any };
|
|
17
52
|
publisherId: string;
|
|
18
53
|
title: string;
|
|
19
|
-
shortDescription: string;
|
|
20
54
|
socials: MarketplaceSocials;
|
|
21
55
|
faviconUrl: string;
|
|
22
|
-
|
|
23
|
-
collections: Array<MarketplaceCollection>;
|
|
24
|
-
walletOptions: MarketplaceWalletOptions;
|
|
25
|
-
landingPageLayout: string;
|
|
56
|
+
walletOptions: MarketplaceWallet;
|
|
26
57
|
logoUrl: string;
|
|
27
|
-
|
|
28
|
-
fontUrl?: string;
|
|
29
|
-
ogImage?: string;
|
|
58
|
+
fontUrl: string;
|
|
30
59
|
accessKey?: string;
|
|
31
60
|
}
|
|
32
61
|
|
|
62
|
+
export interface MarketplacePage {
|
|
63
|
+
enabled: boolean;
|
|
64
|
+
title: string;
|
|
65
|
+
bannerUrl: string;
|
|
66
|
+
ogImage: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
33
69
|
export interface MarketplaceSocials {
|
|
34
70
|
twitter: string;
|
|
35
71
|
discord: string;
|
|
@@ -39,17 +75,46 @@ export interface MarketplaceSocials {
|
|
|
39
75
|
youtube: string;
|
|
40
76
|
}
|
|
41
77
|
|
|
42
|
-
export interface
|
|
43
|
-
|
|
78
|
+
export interface MarketplaceWallet {
|
|
79
|
+
walletType: MarketplaceWalletType;
|
|
80
|
+
oidcIssuers: { [key: string]: string };
|
|
81
|
+
connectors: Array<string>;
|
|
82
|
+
includeEIP6963Wallets: boolean;
|
|
83
|
+
ecosystem?: MarketplaceWalletEcosystem;
|
|
84
|
+
embedded?: MarketplaceWalletEmbedded;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface MarketplaceWalletEcosystem {
|
|
88
|
+
walletUrl: string;
|
|
89
|
+
walletAppName: string;
|
|
90
|
+
logoLightUrl?: string;
|
|
91
|
+
logoDarkUrl?: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface MarketplaceWalletEmbedded {
|
|
95
|
+
tenantKey: string;
|
|
96
|
+
emailEnabled: boolean;
|
|
97
|
+
providers: Array<OpenIdProvider>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface OpenIdProvider {
|
|
101
|
+
iss: string;
|
|
102
|
+
aud: Array<string>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface MarketCollection {
|
|
106
|
+
id: number;
|
|
107
|
+
projectId: number;
|
|
44
108
|
chainId: number;
|
|
45
|
-
|
|
46
|
-
|
|
109
|
+
itemsAddress: string;
|
|
110
|
+
contractType: string;
|
|
47
111
|
bannerUrl: string;
|
|
48
112
|
feePercentage: number;
|
|
49
113
|
currencyOptions: Array<string>;
|
|
50
114
|
destinationMarketplace: OrderbookKind;
|
|
51
115
|
filterSettings?: CollectionFilterSettings;
|
|
52
|
-
|
|
116
|
+
createdAt?: string;
|
|
117
|
+
updatedAt?: string;
|
|
53
118
|
}
|
|
54
119
|
|
|
55
120
|
export interface CollectionFilterSettings {
|
|
@@ -57,159 +122,649 @@ export interface CollectionFilterSettings {
|
|
|
57
122
|
exclusions: Array<MetadataFilterRule>;
|
|
58
123
|
}
|
|
59
124
|
|
|
60
|
-
export interface OpenIdProvider {
|
|
61
|
-
iss: string;
|
|
62
|
-
aud: Array<string>;
|
|
63
|
-
}
|
|
64
125
|
export interface MetadataFilterRule {
|
|
65
126
|
key: string;
|
|
66
127
|
condition: FilterCondition;
|
|
67
128
|
value?: string;
|
|
68
129
|
}
|
|
69
130
|
|
|
70
|
-
export interface
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
ecosystem?: EcosystemWalletSettings;
|
|
82
|
-
waas?: MarketplaceWalletWaasSettings;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export interface EcosystemWalletSettings {
|
|
86
|
-
walletUrl: string;
|
|
87
|
-
walletAppName: string;
|
|
88
|
-
logoLightUrl?: string;
|
|
89
|
-
logoDarkUrl?: string;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export enum MarketplaceWallet {
|
|
93
|
-
UNIVERSAL = "UNIVERSAL",
|
|
94
|
-
EMBEDDED = "EMBEDDED",
|
|
95
|
-
ECOSYSTEM = "ECOSYSTEM",
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export enum MarketplaceType {
|
|
99
|
-
AMM = "AMM",
|
|
100
|
-
P2P = "P2P",
|
|
101
|
-
SEQUENCE = "SEQUENCE",
|
|
102
|
-
ORDERBOOK = "ORDERBOOK",
|
|
131
|
+
export interface ShopCollection {
|
|
132
|
+
id: number;
|
|
133
|
+
projectId: number;
|
|
134
|
+
chainId: number;
|
|
135
|
+
itemsAddress: string;
|
|
136
|
+
saleAddress: string;
|
|
137
|
+
name: string;
|
|
138
|
+
bannerUrl: string;
|
|
139
|
+
saleBannerUrl: string;
|
|
140
|
+
createdAt?: string;
|
|
141
|
+
updatedAt?: string;
|
|
103
142
|
}
|
|
104
143
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
144
|
+
//
|
|
145
|
+
// Service Interface Definition for MarketplaceService (relevant part)
|
|
146
|
+
//
|
|
147
|
+
export interface MarketplaceService {
|
|
148
|
+
/**
|
|
149
|
+
* Public Methods
|
|
150
|
+
*/
|
|
151
|
+
lookupMarketplace(
|
|
152
|
+
args: LookupMarketplaceArgs,
|
|
153
|
+
headers?: object,
|
|
154
|
+
signal?: AbortSignal
|
|
155
|
+
): Promise<LookupMarketplaceReturn>;
|
|
108
156
|
}
|
|
109
157
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
) => Promise<Response>;
|
|
158
|
+
//
|
|
159
|
+
// Errors (Complete set from original)
|
|
160
|
+
//
|
|
114
161
|
|
|
115
|
-
export class
|
|
162
|
+
export class WebrpcError extends Error {
|
|
116
163
|
name: string;
|
|
117
164
|
code: number;
|
|
118
165
|
message: string;
|
|
119
166
|
status: number;
|
|
120
167
|
cause?: string;
|
|
121
168
|
|
|
169
|
+
/** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */
|
|
170
|
+
msg: string;
|
|
171
|
+
|
|
122
172
|
constructor(
|
|
123
|
-
name
|
|
124
|
-
code
|
|
125
|
-
message
|
|
126
|
-
status
|
|
173
|
+
name: string,
|
|
174
|
+
code: number,
|
|
175
|
+
message: string,
|
|
176
|
+
status: number,
|
|
127
177
|
cause?: string
|
|
128
178
|
) {
|
|
129
179
|
super(message);
|
|
130
|
-
this.name = name;
|
|
131
|
-
this.code = code;
|
|
132
|
-
this.message = message
|
|
133
|
-
this.
|
|
180
|
+
this.name = name || "WebrpcError";
|
|
181
|
+
this.code = typeof code === "number" ? code : 0;
|
|
182
|
+
this.message = message || `endpoint error ${this.code}`;
|
|
183
|
+
this.msg = this.message;
|
|
184
|
+
this.status = typeof status === "number" ? status : 0;
|
|
134
185
|
this.cause = cause;
|
|
135
|
-
Object.setPrototypeOf(this,
|
|
186
|
+
Object.setPrototypeOf(this, WebrpcError.prototype);
|
|
136
187
|
}
|
|
137
188
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
payload.name,
|
|
189
|
+
static new(payload: any): WebrpcError {
|
|
190
|
+
return new this(
|
|
191
|
+
payload.error,
|
|
142
192
|
payload.code,
|
|
143
|
-
payload.
|
|
193
|
+
payload.message || payload.msg,
|
|
144
194
|
payload.status,
|
|
145
195
|
payload.cause
|
|
146
196
|
);
|
|
147
197
|
}
|
|
148
198
|
}
|
|
149
199
|
|
|
150
|
-
|
|
151
|
-
body: object = {},
|
|
152
|
-
headers: object = {},
|
|
153
|
-
signal: AbortSignal | null = null
|
|
154
|
-
): object => {
|
|
155
|
-
return {
|
|
156
|
-
method: "POST",
|
|
157
|
-
headers: {
|
|
158
|
-
Accept: "application/json",
|
|
159
|
-
"Content-Type": "application/json",
|
|
160
|
-
...headers,
|
|
161
|
-
},
|
|
162
|
-
body: JSON.stringify(body || {}),
|
|
163
|
-
mode: "cors",
|
|
164
|
-
signal: signal || null,
|
|
165
|
-
};
|
|
166
|
-
};
|
|
200
|
+
// Webrpc errors
|
|
167
201
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
202
|
+
export class WebrpcEndpointError extends WebrpcError {
|
|
203
|
+
constructor(
|
|
204
|
+
name: string = "WebrpcEndpoint",
|
|
205
|
+
code: number = 0,
|
|
206
|
+
message: string = `endpoint error`,
|
|
207
|
+
status: number = 0,
|
|
208
|
+
cause?: string
|
|
209
|
+
) {
|
|
210
|
+
super(name, code, message, status, cause);
|
|
211
|
+
Object.setPrototypeOf(this, WebrpcEndpointError.prototype);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export class WebrpcRequestFailedError extends WebrpcError {
|
|
216
|
+
constructor(
|
|
217
|
+
name: string = "WebrpcRequestFailed",
|
|
218
|
+
code: number = -1,
|
|
219
|
+
message: string = `request failed`,
|
|
220
|
+
status: number = 0,
|
|
221
|
+
cause?: string
|
|
222
|
+
) {
|
|
223
|
+
super(name, code, message, status, cause);
|
|
224
|
+
Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export class WebrpcBadRouteError extends WebrpcError {
|
|
229
|
+
constructor(
|
|
230
|
+
name: string = "WebrpcBadRoute",
|
|
231
|
+
code: number = -2,
|
|
232
|
+
message: string = `bad route`,
|
|
233
|
+
status: number = 0,
|
|
234
|
+
cause?: string
|
|
235
|
+
) {
|
|
236
|
+
super(name, code, message, status, cause);
|
|
237
|
+
Object.setPrototypeOf(this, WebrpcBadRouteError.prototype);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export class WebrpcBadMethodError extends WebrpcError {
|
|
242
|
+
constructor(
|
|
243
|
+
name: string = "WebrpcBadMethod",
|
|
244
|
+
code: number = -3,
|
|
245
|
+
message: string = `bad method`,
|
|
246
|
+
status: number = 0,
|
|
247
|
+
cause?: string
|
|
248
|
+
) {
|
|
249
|
+
super(name, code, message, status, cause);
|
|
250
|
+
Object.setPrototypeOf(this, WebrpcBadMethodError.prototype);
|
|
173
251
|
}
|
|
174
|
-
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export class WebrpcBadRequestError extends WebrpcError {
|
|
255
|
+
constructor(
|
|
256
|
+
name: string = "WebrpcBadRequest",
|
|
257
|
+
code: number = -4,
|
|
258
|
+
message: string = `bad request`,
|
|
259
|
+
status: number = 0,
|
|
260
|
+
cause?: string
|
|
261
|
+
) {
|
|
262
|
+
super(name, code, message, status, cause);
|
|
263
|
+
Object.setPrototypeOf(this, WebrpcBadRequestError.prototype);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export class WebrpcBadResponseError extends WebrpcError {
|
|
268
|
+
constructor(
|
|
269
|
+
name: string = "WebrpcBadResponse",
|
|
270
|
+
code: number = -5,
|
|
271
|
+
message: string = `bad response`,
|
|
272
|
+
status: number = 0,
|
|
273
|
+
cause?: string
|
|
274
|
+
) {
|
|
275
|
+
super(name, code, message, status, cause);
|
|
276
|
+
Object.setPrototypeOf(this, WebrpcBadResponseError.prototype);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export class WebrpcServerPanicError extends WebrpcError {
|
|
281
|
+
constructor(
|
|
282
|
+
name: string = "WebrpcServerPanic",
|
|
283
|
+
code: number = -6,
|
|
284
|
+
message: string = `server panic`,
|
|
285
|
+
status: number = 0,
|
|
286
|
+
cause?: string
|
|
287
|
+
) {
|
|
288
|
+
super(name, code, message, status, cause);
|
|
289
|
+
Object.setPrototypeOf(this, WebrpcServerPanicError.prototype);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export class WebrpcInternalErrorError extends WebrpcError {
|
|
294
|
+
// Name as per original
|
|
295
|
+
constructor(
|
|
296
|
+
name: string = "WebrpcInternalError",
|
|
297
|
+
code: number = -7,
|
|
298
|
+
message: string = `internal error`,
|
|
299
|
+
status: number = 0,
|
|
300
|
+
cause?: string
|
|
301
|
+
) {
|
|
302
|
+
super(name, code, message, status, cause);
|
|
303
|
+
Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export class WebrpcClientDisconnectedError extends WebrpcError {
|
|
308
|
+
constructor(
|
|
309
|
+
name: string = "WebrpcClientDisconnected",
|
|
310
|
+
code: number = -8,
|
|
311
|
+
message: string = `client disconnected`,
|
|
312
|
+
status: number = 0,
|
|
313
|
+
cause?: string
|
|
314
|
+
) {
|
|
315
|
+
super(name, code, message, status, cause);
|
|
316
|
+
Object.setPrototypeOf(this, WebrpcClientDisconnectedError.prototype);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export class WebrpcStreamLostError extends WebrpcError {
|
|
321
|
+
constructor(
|
|
322
|
+
name: string = "WebrpcStreamLost",
|
|
323
|
+
code: number = -9,
|
|
324
|
+
message: string = `stream lost`,
|
|
325
|
+
status: number = 0,
|
|
326
|
+
cause?: string
|
|
327
|
+
) {
|
|
328
|
+
super(name, code, message, status, cause);
|
|
329
|
+
Object.setPrototypeOf(this, WebrpcStreamLostError.prototype);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export class WebrpcStreamFinishedError extends WebrpcError {
|
|
334
|
+
constructor(
|
|
335
|
+
name: string = "WebrpcStreamFinished",
|
|
336
|
+
code: number = -10,
|
|
337
|
+
message: string = `stream finished`,
|
|
338
|
+
status: number = 0,
|
|
339
|
+
cause?: string
|
|
340
|
+
) {
|
|
341
|
+
super(name, code, message, status, cause);
|
|
342
|
+
Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// Schema errors
|
|
347
|
+
|
|
348
|
+
export class UnauthorizedError extends WebrpcError {
|
|
349
|
+
constructor(
|
|
350
|
+
name: string = "Unauthorized",
|
|
351
|
+
code: number = 1000,
|
|
352
|
+
message: string = `Unauthorized access`,
|
|
353
|
+
status: number = 0,
|
|
354
|
+
cause?: string
|
|
355
|
+
) {
|
|
356
|
+
super(name, code, message, status, cause);
|
|
357
|
+
Object.setPrototypeOf(this, UnauthorizedError.prototype);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export class PermissionDeniedError extends WebrpcError {
|
|
362
|
+
constructor(
|
|
363
|
+
name: string = "PermissionDenied",
|
|
364
|
+
code: number = 1001,
|
|
365
|
+
message: string = `Permission denied`,
|
|
366
|
+
status: number = 0,
|
|
367
|
+
cause?: string
|
|
368
|
+
) {
|
|
369
|
+
super(name, code, message, status, cause);
|
|
370
|
+
Object.setPrototypeOf(this, PermissionDeniedError.prototype);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export class SessionExpiredError extends WebrpcError {
|
|
375
|
+
constructor(
|
|
376
|
+
name: string = "SessionExpired",
|
|
377
|
+
code: number = 1002,
|
|
378
|
+
message: string = `Session expired`,
|
|
379
|
+
status: number = 0,
|
|
380
|
+
cause?: string
|
|
381
|
+
) {
|
|
382
|
+
super(name, code, message, status, cause);
|
|
383
|
+
Object.setPrototypeOf(this, SessionExpiredError.prototype);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export class MethodNotFoundError extends WebrpcError {
|
|
388
|
+
constructor(
|
|
389
|
+
name: string = "MethodNotFound",
|
|
390
|
+
code: number = 1003,
|
|
391
|
+
message: string = `Method not found`,
|
|
392
|
+
status: number = 0,
|
|
393
|
+
cause?: string
|
|
394
|
+
) {
|
|
395
|
+
super(name, code, message, status, cause);
|
|
396
|
+
Object.setPrototypeOf(this, MethodNotFoundError.prototype);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export class RequestConflictError extends WebrpcError {
|
|
401
|
+
constructor(
|
|
402
|
+
name: string = "RequestConflict",
|
|
403
|
+
code: number = 1004,
|
|
404
|
+
message: string = `Conflict with target resource`,
|
|
405
|
+
status: number = 0,
|
|
406
|
+
cause?: string
|
|
407
|
+
) {
|
|
408
|
+
super(name, code, message, status, cause);
|
|
409
|
+
Object.setPrototypeOf(this, RequestConflictError.prototype);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export class ServiceDisabledError extends WebrpcError {
|
|
414
|
+
constructor(
|
|
415
|
+
name: string = "ServiceDisabled",
|
|
416
|
+
code: number = 1005,
|
|
417
|
+
message: string = `Service disabled`,
|
|
418
|
+
status: number = 0,
|
|
419
|
+
cause?: string
|
|
420
|
+
) {
|
|
421
|
+
super(name, code, message, status, cause);
|
|
422
|
+
Object.setPrototypeOf(this, ServiceDisabledError.prototype);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
export class TimeoutError extends WebrpcError {
|
|
427
|
+
constructor(
|
|
428
|
+
name: string = "Timeout",
|
|
429
|
+
code: number = 2000,
|
|
430
|
+
message: string = `Request timed out`,
|
|
431
|
+
status: number = 0,
|
|
432
|
+
cause?: string
|
|
433
|
+
) {
|
|
434
|
+
super(name, code, message, status, cause);
|
|
435
|
+
Object.setPrototypeOf(this, TimeoutError.prototype);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export class InvalidArgumentError extends WebrpcError {
|
|
440
|
+
constructor(
|
|
441
|
+
name: string = "InvalidArgument",
|
|
442
|
+
code: number = 2001,
|
|
443
|
+
message: string = `Invalid argument`,
|
|
444
|
+
status: number = 0,
|
|
445
|
+
cause?: string
|
|
446
|
+
) {
|
|
447
|
+
super(name, code, message, status, cause);
|
|
448
|
+
Object.setPrototypeOf(this, InvalidArgumentError.prototype);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export class NotFoundError extends WebrpcError {
|
|
453
|
+
constructor(
|
|
454
|
+
name: string = "NotFound",
|
|
455
|
+
code: number = 3000,
|
|
456
|
+
message: string = `Resource not found`,
|
|
457
|
+
status: number = 0,
|
|
458
|
+
cause?: string
|
|
459
|
+
) {
|
|
460
|
+
super(name, code, message, status, cause);
|
|
461
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
export class UserNotFoundError extends WebrpcError {
|
|
466
|
+
constructor(
|
|
467
|
+
name: string = "UserNotFound",
|
|
468
|
+
code: number = 3001,
|
|
469
|
+
message: string = `User not found`,
|
|
470
|
+
status: number = 0,
|
|
471
|
+
cause?: string
|
|
472
|
+
) {
|
|
473
|
+
super(name, code, message, status, cause);
|
|
474
|
+
Object.setPrototypeOf(this, UserNotFoundError.prototype);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
export class ProjectNotFoundError extends WebrpcError {
|
|
479
|
+
constructor(
|
|
480
|
+
name: string = "ProjectNotFound",
|
|
481
|
+
code: number = 3002,
|
|
482
|
+
message: string = `Project not found`,
|
|
483
|
+
status: number = 0,
|
|
484
|
+
cause?: string
|
|
485
|
+
) {
|
|
486
|
+
super(name, code, message, status, cause);
|
|
487
|
+
Object.setPrototypeOf(this, ProjectNotFoundError.prototype);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
export class InvalidTierError extends WebrpcError {
|
|
492
|
+
constructor(
|
|
493
|
+
name: string = "InvalidTier",
|
|
494
|
+
code: number = 3003,
|
|
495
|
+
message: string = `Invalid subscription tier`,
|
|
496
|
+
status: number = 0,
|
|
497
|
+
cause?: string
|
|
498
|
+
) {
|
|
499
|
+
super(name, code, message, status, cause);
|
|
500
|
+
Object.setPrototypeOf(this, InvalidTierError.prototype);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
export class EmailTemplateExistsError extends WebrpcError {
|
|
505
|
+
constructor(
|
|
506
|
+
name: string = "EmailTemplateExists",
|
|
507
|
+
code: number = 3004,
|
|
508
|
+
message: string = `Email Template exists`,
|
|
509
|
+
status: number = 0,
|
|
510
|
+
cause?: string
|
|
511
|
+
) {
|
|
512
|
+
super(name, code, message, status, cause);
|
|
513
|
+
Object.setPrototypeOf(this, EmailTemplateExistsError.prototype);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
export class SubscriptionLimitError extends WebrpcError {
|
|
518
|
+
constructor(
|
|
519
|
+
name: string = "SubscriptionLimit",
|
|
520
|
+
code: number = 3005,
|
|
521
|
+
message: string = `Subscription limit reached`,
|
|
522
|
+
status: number = 0,
|
|
523
|
+
cause?: string
|
|
524
|
+
) {
|
|
525
|
+
super(name, code, message, status, cause);
|
|
526
|
+
Object.setPrototypeOf(this, SubscriptionLimitError.prototype);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export class FeatureNotIncludedError extends WebrpcError {
|
|
531
|
+
constructor(
|
|
532
|
+
name: string = "FeatureNotIncluded",
|
|
533
|
+
code: number = 3006,
|
|
534
|
+
message: string = `Feature not included`,
|
|
535
|
+
status: number = 0,
|
|
536
|
+
cause?: string
|
|
537
|
+
) {
|
|
538
|
+
super(name, code, message, status, cause);
|
|
539
|
+
Object.setPrototypeOf(this, FeatureNotIncludedError.prototype);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
export class InvalidNetworkError extends WebrpcError {
|
|
544
|
+
constructor(
|
|
545
|
+
name: string = "InvalidNetwork",
|
|
546
|
+
code: number = 3007,
|
|
547
|
+
message: string = `Invalid network`,
|
|
548
|
+
status: number = 0,
|
|
549
|
+
cause?: string
|
|
550
|
+
) {
|
|
551
|
+
super(name, code, message, status, cause);
|
|
552
|
+
Object.setPrototypeOf(this, InvalidNetworkError.prototype);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
export class InvitationExpiredError extends WebrpcError {
|
|
557
|
+
constructor(
|
|
558
|
+
name: string = "InvitationExpired",
|
|
559
|
+
code: number = 4000,
|
|
560
|
+
message: string = `Invitation code is expired`,
|
|
561
|
+
status: number = 0,
|
|
562
|
+
cause?: string
|
|
563
|
+
) {
|
|
564
|
+
super(name, code, message, status, cause);
|
|
565
|
+
Object.setPrototypeOf(this, InvitationExpiredError.prototype);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
export class AlreadyCollaboratorError extends WebrpcError {
|
|
570
|
+
constructor(
|
|
571
|
+
name: string = "AlreadyCollaborator",
|
|
572
|
+
code: number = 4001,
|
|
573
|
+
message: string = `Already a collaborator`,
|
|
574
|
+
status: number = 0,
|
|
575
|
+
cause?: string
|
|
576
|
+
) {
|
|
577
|
+
super(name, code, message, status, cause);
|
|
578
|
+
Object.setPrototypeOf(this, AlreadyCollaboratorError.prototype);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
export enum errors {
|
|
583
|
+
WebrpcEndpoint = "WebrpcEndpoint",
|
|
584
|
+
WebrpcRequestFailed = "WebrpcRequestFailed",
|
|
585
|
+
WebrpcBadRoute = "WebrpcBadRoute",
|
|
586
|
+
WebrpcBadMethod = "WebrpcBadMethod",
|
|
587
|
+
WebrpcBadRequest = "WebrpcBadRequest",
|
|
588
|
+
WebrpcBadResponse = "WebrpcBadResponse",
|
|
589
|
+
WebrpcServerPanic = "WebrpcServerPanic",
|
|
590
|
+
WebrpcInternalError = "WebrpcInternalError",
|
|
591
|
+
WebrpcClientDisconnected = "WebrpcClientDisconnected",
|
|
592
|
+
WebrpcStreamLost = "WebrpcStreamLost",
|
|
593
|
+
WebrpcStreamFinished = "WebrpcStreamFinished",
|
|
594
|
+
Unauthorized = "Unauthorized",
|
|
595
|
+
PermissionDenied = "PermissionDenied",
|
|
596
|
+
SessionExpired = "SessionExpired",
|
|
597
|
+
MethodNotFound = "MethodNotFound",
|
|
598
|
+
RequestConflict = "RequestConflict",
|
|
599
|
+
ServiceDisabled = "ServiceDisabled",
|
|
600
|
+
Timeout = "Timeout",
|
|
601
|
+
InvalidArgument = "InvalidArgument",
|
|
602
|
+
NotFound = "NotFound",
|
|
603
|
+
UserNotFound = "UserNotFound",
|
|
604
|
+
ProjectNotFound = "ProjectNotFound",
|
|
605
|
+
InvalidTier = "InvalidTier",
|
|
606
|
+
EmailTemplateExists = "EmailTemplateExists",
|
|
607
|
+
SubscriptionLimit = "SubscriptionLimit",
|
|
608
|
+
FeatureNotIncluded = "FeatureNotIncluded",
|
|
609
|
+
InvalidNetwork = "InvalidNetwork",
|
|
610
|
+
InvitationExpired = "InvitationExpired",
|
|
611
|
+
AlreadyCollaborator = "AlreadyCollaborator",
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
export enum WebrpcErrorCodes {
|
|
615
|
+
WebrpcEndpoint = 0,
|
|
616
|
+
WebrpcRequestFailed = -1,
|
|
617
|
+
WebrpcBadRoute = -2,
|
|
618
|
+
WebrpcBadMethod = -3,
|
|
619
|
+
WebrpcBadRequest = -4,
|
|
620
|
+
WebrpcBadResponse = -5,
|
|
621
|
+
WebrpcServerPanic = -6,
|
|
622
|
+
WebrpcInternalError = -7,
|
|
623
|
+
WebrpcClientDisconnected = -8,
|
|
624
|
+
WebrpcStreamLost = -9,
|
|
625
|
+
WebrpcStreamFinished = -10,
|
|
626
|
+
Unauthorized = 1000,
|
|
627
|
+
PermissionDenied = 1001,
|
|
628
|
+
SessionExpired = 1002,
|
|
629
|
+
MethodNotFound = 1003,
|
|
630
|
+
RequestConflict = 1004,
|
|
631
|
+
ServiceDisabled = 1005,
|
|
632
|
+
Timeout = 2000,
|
|
633
|
+
InvalidArgument = 2001,
|
|
634
|
+
NotFound = 3000,
|
|
635
|
+
UserNotFound = 3001,
|
|
636
|
+
ProjectNotFound = 3002,
|
|
637
|
+
InvalidTier = 3003,
|
|
638
|
+
EmailTemplateExists = 3004,
|
|
639
|
+
SubscriptionLimit = 3005,
|
|
640
|
+
FeatureNotIncluded = 3006,
|
|
641
|
+
InvalidNetwork = 3007,
|
|
642
|
+
InvitationExpired = 4000,
|
|
643
|
+
AlreadyCollaborator = 4001,
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
export const webrpcErrorByCode: { [code: number]: any } = {
|
|
647
|
+
[0]: WebrpcEndpointError,
|
|
648
|
+
[-1]: WebrpcRequestFailedError,
|
|
649
|
+
[-2]: WebrpcBadRouteError,
|
|
650
|
+
[-3]: WebrpcBadMethodError,
|
|
651
|
+
[-4]: WebrpcBadRequestError,
|
|
652
|
+
[-5]: WebrpcBadResponseError,
|
|
653
|
+
[-6]: WebrpcServerPanicError,
|
|
654
|
+
[-7]: WebrpcInternalErrorError, // Name as per original
|
|
655
|
+
[-8]: WebrpcClientDisconnectedError,
|
|
656
|
+
[-9]: WebrpcStreamLostError,
|
|
657
|
+
[-10]: WebrpcStreamFinishedError,
|
|
658
|
+
[1000]: UnauthorizedError,
|
|
659
|
+
[1001]: PermissionDeniedError,
|
|
660
|
+
[1002]: SessionExpiredError,
|
|
661
|
+
[1003]: MethodNotFoundError,
|
|
662
|
+
[1004]: RequestConflictError,
|
|
663
|
+
[1005]: ServiceDisabledError,
|
|
664
|
+
[2000]: TimeoutError,
|
|
665
|
+
[2001]: InvalidArgumentError,
|
|
666
|
+
[3000]: NotFoundError,
|
|
667
|
+
[3001]: UserNotFoundError,
|
|
668
|
+
[3002]: ProjectNotFoundError,
|
|
669
|
+
[3003]: InvalidTierError,
|
|
670
|
+
[3004]: EmailTemplateExistsError,
|
|
671
|
+
[3005]: SubscriptionLimitError,
|
|
672
|
+
[3006]: FeatureNotIncludedError,
|
|
673
|
+
[3007]: InvalidNetworkError,
|
|
674
|
+
[4000]: InvitationExpiredError,
|
|
675
|
+
[4001]: AlreadyCollaboratorError,
|
|
175
676
|
};
|
|
176
677
|
|
|
177
|
-
|
|
678
|
+
//
|
|
679
|
+
// Client Implementation for MarketplaceService (relevant part)
|
|
680
|
+
//
|
|
681
|
+
export type Fetch = (
|
|
682
|
+
input: RequestInfo,
|
|
683
|
+
init?: RequestInit
|
|
684
|
+
) => Promise<Response>;
|
|
685
|
+
|
|
686
|
+
export class MarketplaceService {
|
|
178
687
|
protected hostname: string;
|
|
179
688
|
protected fetch: Fetch;
|
|
180
|
-
protected path = "/rpc/
|
|
689
|
+
protected path = "/rpc/MarketplaceService/";
|
|
181
690
|
|
|
182
691
|
constructor(hostname: string, fetch: Fetch) {
|
|
183
|
-
this.hostname = hostname;
|
|
184
|
-
this.fetch = fetch;
|
|
692
|
+
this.hostname = hostname.replace(/\/*$/, "");
|
|
693
|
+
this.fetch = (input: RequestInfo, init?: RequestInit) => fetch(input, init);
|
|
185
694
|
}
|
|
186
695
|
|
|
187
696
|
private url(name: string): string {
|
|
188
697
|
return this.hostname + this.path + name;
|
|
189
698
|
}
|
|
190
699
|
|
|
191
|
-
|
|
192
|
-
args:
|
|
700
|
+
lookupMarketplace = (
|
|
701
|
+
args: LookupMarketplaceArgs,
|
|
193
702
|
headers?: object,
|
|
194
703
|
signal?: AbortSignal
|
|
195
|
-
): Promise<
|
|
704
|
+
): Promise<LookupMarketplaceReturn> => {
|
|
196
705
|
return this.fetch(
|
|
197
|
-
this.url("
|
|
706
|
+
this.url("LookupMarketplace"),
|
|
198
707
|
createHTTPRequest(args, headers, signal)
|
|
199
708
|
).then(
|
|
200
709
|
(res) => {
|
|
201
710
|
return buildResponse(res).then((_data) => {
|
|
202
711
|
return {
|
|
203
|
-
|
|
204
|
-
|
|
712
|
+
marketplace: <Marketplace>_data.marketplace,
|
|
713
|
+
marketCollections: <Array<MarketCollection>>_data.marketCollections,
|
|
714
|
+
shopCollections: <Array<ShopCollection>>_data.shopCollections,
|
|
205
715
|
};
|
|
206
716
|
});
|
|
207
717
|
},
|
|
208
718
|
(error) => {
|
|
209
719
|
throw WebrpcRequestFailedError.new({
|
|
210
|
-
cause: `
|
|
720
|
+
cause: `lookupMarketplace(): ${error.message || ""}`,
|
|
211
721
|
});
|
|
212
722
|
}
|
|
213
723
|
);
|
|
214
724
|
};
|
|
215
725
|
}
|
|
726
|
+
|
|
727
|
+
//
|
|
728
|
+
// Helper Functions
|
|
729
|
+
//
|
|
730
|
+
const createHTTPRequest = (
|
|
731
|
+
body: object = {},
|
|
732
|
+
headers: object = {},
|
|
733
|
+
signal: AbortSignal | null = null
|
|
734
|
+
): object => {
|
|
735
|
+
const reqHeaders: { [key: string]: string } = {
|
|
736
|
+
...headers,
|
|
737
|
+
"Content-Type": "application/json",
|
|
738
|
+
};
|
|
739
|
+
reqHeaders[WebrpcHeader] = WebrpcHeaderValue;
|
|
740
|
+
|
|
741
|
+
return {
|
|
742
|
+
method: "POST",
|
|
743
|
+
headers: reqHeaders,
|
|
744
|
+
body: JSON.stringify(body || {}),
|
|
745
|
+
signal,
|
|
746
|
+
};
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
const buildResponse = (res: Response): Promise<any> => {
|
|
750
|
+
return res.text().then((text) => {
|
|
751
|
+
let data;
|
|
752
|
+
try {
|
|
753
|
+
data = JSON.parse(text);
|
|
754
|
+
} catch (error) {
|
|
755
|
+
let message = "";
|
|
756
|
+
if (error instanceof Error) {
|
|
757
|
+
message = error.message;
|
|
758
|
+
}
|
|
759
|
+
throw WebrpcBadResponseError.new({
|
|
760
|
+
status: res.status,
|
|
761
|
+
cause: `JSON.parse(): ${message}: response text: ${text}`,
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
if (!res.ok) {
|
|
765
|
+
const code: number = typeof data.code === "number" ? data.code : 0;
|
|
766
|
+
throw (webrpcErrorByCode[code] || WebrpcError).new(data);
|
|
767
|
+
}
|
|
768
|
+
return data;
|
|
769
|
+
});
|
|
770
|
+
};
|