@0xtrails/api 0.9.4 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-typecheck.log +2 -2
- package/CHANGELOG.md +6 -0
- package/dist/trails-api.gen.d.ts +163 -4
- package/dist/trails-api.gen.d.ts.map +1 -1
- package/dist/trails-api.gen.js +70 -7
- package/dist/trails-onramp.gen.d.ts +529 -0
- package/dist/trails-onramp.gen.d.ts.map +1 -0
- package/dist/trails-onramp.gen.js +887 -0
- package/package.json +1 -1
- package/src/trails-api.gen.ts +241 -8
- package/src/trails-onramp.gen.ts +1261 -0
|
@@ -0,0 +1,1261 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// trails-api v1-26.1.15-71ef491 3a59ec464d243ab72337d497022e9388bbfed4e0
|
|
3
|
+
// --
|
|
4
|
+
// Code generated by Webrpc-gen@v0.31.3 with typescript generator. DO NOT EDIT.
|
|
5
|
+
//
|
|
6
|
+
// webrpc-gen -schema=trails-api.ridl -target=typescript -client -service=TrailsOnramp -methodTreeShake -ignore=@api -out=./clients/onramp/trails-onramp.gen.ts
|
|
7
|
+
|
|
8
|
+
// Webrpc description and code-gen version
|
|
9
|
+
export const WebrpcVersion = "v1"
|
|
10
|
+
|
|
11
|
+
// Schema version of your RIDL schema
|
|
12
|
+
export const WebrpcSchemaVersion = "v1-26.1.15-71ef491"
|
|
13
|
+
|
|
14
|
+
// Schema hash generated from your RIDL schema
|
|
15
|
+
export const WebrpcSchemaHash = "3a59ec464d243ab72337d497022e9388bbfed4e0"
|
|
16
|
+
|
|
17
|
+
//
|
|
18
|
+
// Client interface
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
export interface TrailsOnrampClient {
|
|
22
|
+
/**
|
|
23
|
+
* GetMeldCountryDefaults returns default currency and payment methods for a country.
|
|
24
|
+
*/
|
|
25
|
+
getMeldCountryDefaults(req: GetMeldCountryDefaultsRequest, headers?: object, signal?: AbortSignal): Promise<GetMeldCountryDefaultsResponse>
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* GetMeldFiatCurrencies returns available fiat currencies for a country.
|
|
29
|
+
*/
|
|
30
|
+
getMeldFiatCurrencies(req: GetMeldFiatCurrenciesRequest, headers?: object, signal?: AbortSignal): Promise<GetMeldFiatCurrenciesResponse>
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* GetMeldPaymentMethods returns payment methods available for a fiat currency.
|
|
34
|
+
*/
|
|
35
|
+
getMeldPaymentMethods(req: GetMeldPaymentMethodsRequest, headers?: object, signal?: AbortSignal): Promise<GetMeldPaymentMethodsResponse>
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* GetMeldCryptoCurrencies returns available cryptocurrencies for a country.
|
|
39
|
+
*/
|
|
40
|
+
getMeldCryptoCurrencies(req: GetMeldCryptoCurrenciesRequest, headers?: object, signal?: AbortSignal): Promise<GetMeldCryptoCurrenciesResponse>
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* GetMeldPurchaseLimits returns purchase limits for all fiat currencies.
|
|
44
|
+
*/
|
|
45
|
+
getMeldPurchaseLimits(req: GetMeldPurchaseLimitsRequest, headers?: object, signal?: AbortSignal): Promise<GetMeldPurchaseLimitsResponse>
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* GetMeldQuote returns real-time quotes from multiple providers.
|
|
49
|
+
*/
|
|
50
|
+
getMeldQuote(req: GetMeldQuoteRequest, headers?: object, signal?: AbortSignal): Promise<GetMeldQuoteResponse>
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* CreateMeldWidgetSession creates a widget session and returns the provider URL.
|
|
54
|
+
*/
|
|
55
|
+
createMeldWidgetSession(req: CreateMeldWidgetSessionRequest, headers?: object, signal?: AbortSignal): Promise<CreateMeldWidgetSessionResponse>
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* GetMeldTransaction returns transaction details by transaction ID.
|
|
59
|
+
*/
|
|
60
|
+
getMeldTransaction(req: GetMeldTransactionRequest, headers?: object, signal?: AbortSignal): Promise<GetMeldTransactionResponse>
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* SearchMeldTransactions returns transactions matching the search criteria.
|
|
64
|
+
*/
|
|
65
|
+
searchMeldTransactions(req: SearchMeldTransactionsRequest, headers?: object, signal?: AbortSignal): Promise<SearchMeldTransactionsResponse>
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* CreateMeldBankLinkingConnection creates a bank linking connection for ACH transfers.
|
|
69
|
+
*/
|
|
70
|
+
createMeldBankLinkingConnection(req: CreateMeldBankLinkingConnectionRequest, headers?: object, signal?: AbortSignal): Promise<CreateMeldBankLinkingConnectionResponse>
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
//
|
|
75
|
+
// Schema types
|
|
76
|
+
//
|
|
77
|
+
|
|
78
|
+
export enum CCTPTransferStatus {
|
|
79
|
+
UNKNOWN = 'UNKNOWN',
|
|
80
|
+
ON_HOLD = 'ON_HOLD',
|
|
81
|
+
PENDING = 'PENDING',
|
|
82
|
+
FETCHING = 'FETCHING',
|
|
83
|
+
COMPLETE = 'COMPLETE',
|
|
84
|
+
FAILED = 'FAILED'
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export enum RelayTransferStatus {
|
|
88
|
+
UNKNOWN = 'UNKNOWN',
|
|
89
|
+
ON_HOLD = 'ON_HOLD',
|
|
90
|
+
PENDING = 'PENDING',
|
|
91
|
+
FETCHING = 'FETCHING',
|
|
92
|
+
COMPLETE = 'COMPLETE',
|
|
93
|
+
REFUNDED = 'REFUNDED',
|
|
94
|
+
FAILED = 'FAILED'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface ChainMetadata {
|
|
98
|
+
chainId: number
|
|
99
|
+
name: string
|
|
100
|
+
logoUri?: string
|
|
101
|
+
testnet?: boolean
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface CCTPTransfer {
|
|
105
|
+
id: number
|
|
106
|
+
intentId: string
|
|
107
|
+
originChainId: number
|
|
108
|
+
destinationChainId: number
|
|
109
|
+
originTxnId: number
|
|
110
|
+
originTxnHash: string
|
|
111
|
+
destinationTxnId: number
|
|
112
|
+
message: string
|
|
113
|
+
attestation: string
|
|
114
|
+
status: number
|
|
115
|
+
statusReason?: string
|
|
116
|
+
createdAt: string
|
|
117
|
+
updatedAt: string
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface RelayTransfer {
|
|
121
|
+
id: number
|
|
122
|
+
intentId: string
|
|
123
|
+
originChainId: number
|
|
124
|
+
destinationChainId: number
|
|
125
|
+
originTxnId: number
|
|
126
|
+
originTxnHash: string
|
|
127
|
+
destinationTxnId: number
|
|
128
|
+
destinationTxnHash: string
|
|
129
|
+
status: number
|
|
130
|
+
statusReason?: string
|
|
131
|
+
createdAt: string
|
|
132
|
+
updatedAt: string
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface GetMeldCountryDefaultsRequest {
|
|
136
|
+
countryCode: string
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface GetMeldCountryDefaultsResponse {
|
|
140
|
+
defaults: Array<MeldCountryDefault>
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface MeldCountryDefault {
|
|
144
|
+
countryCode: string
|
|
145
|
+
defaultCurrencyCode: string
|
|
146
|
+
defaultPaymentMethods: Array<string>
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface GetMeldFiatCurrenciesRequest {
|
|
150
|
+
countryCode: string
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface GetMeldFiatCurrenciesResponse {
|
|
154
|
+
fiatCurrencies: Array<MeldFiatCurrency>
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface MeldFiatCurrency {
|
|
158
|
+
currencyCode: string
|
|
159
|
+
name: string
|
|
160
|
+
symbolImageUrl: string
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export interface GetMeldPaymentMethodsRequest {
|
|
164
|
+
fiatCurrency: string
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface GetMeldPaymentMethodsResponse {
|
|
168
|
+
paymentMethods: Array<MeldPaymentMethod>
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface MeldPaymentMethod {
|
|
172
|
+
paymentMethod: string
|
|
173
|
+
name: string
|
|
174
|
+
paymentType: string
|
|
175
|
+
logos: MeldPaymentLogos
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface MeldPaymentLogos {
|
|
179
|
+
dark: string
|
|
180
|
+
light: string
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface GetMeldCryptoCurrenciesRequest {
|
|
184
|
+
countryCode: string
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface GetMeldCryptoCurrenciesResponse {
|
|
188
|
+
cryptoCurrencies: Array<MeldCryptoCurrency>
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface MeldCryptoCurrency {
|
|
192
|
+
currencyCode: string
|
|
193
|
+
name: string
|
|
194
|
+
chainCode: string
|
|
195
|
+
chainName: string
|
|
196
|
+
chainId?: string
|
|
197
|
+
contractAddress?: string
|
|
198
|
+
symbolImageUrl: string
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface GetMeldPurchaseLimitsRequest {
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface GetMeldPurchaseLimitsResponse {
|
|
205
|
+
limits: {[key: string]: MeldCurrencyLimits}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export interface MeldCurrencyLimits {
|
|
209
|
+
defaultAmount?: number
|
|
210
|
+
minimumAmount: number
|
|
211
|
+
maximumAmount: number
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export interface GetMeldQuoteRequest {
|
|
215
|
+
sourceAmount: string
|
|
216
|
+
sourceCurrencyCode: string
|
|
217
|
+
destinationCurrencyCode: string
|
|
218
|
+
countryCode: string
|
|
219
|
+
walletAddress: string
|
|
220
|
+
paymentMethodType?: string
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export interface GetMeldQuoteResponse {
|
|
224
|
+
quoteResponse: string
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface MeldQuote {
|
|
228
|
+
transactionType: string
|
|
229
|
+
sourceAmount: number
|
|
230
|
+
sourceAmountWithoutFees: number
|
|
231
|
+
fiatAmountWithoutFees: number
|
|
232
|
+
destinationAmountWithoutFees?: number
|
|
233
|
+
sourceCurrencyCode: string
|
|
234
|
+
countryCode: string
|
|
235
|
+
totalFee: number
|
|
236
|
+
networkFee: number
|
|
237
|
+
transactionFee: number
|
|
238
|
+
destinationAmount: number
|
|
239
|
+
destinationCurrencyCode: string
|
|
240
|
+
exchangeRate: number
|
|
241
|
+
paymentMethodType: string
|
|
242
|
+
customerScore: number
|
|
243
|
+
serviceProvider: string
|
|
244
|
+
institutionName?: string
|
|
245
|
+
lowKyc?: boolean
|
|
246
|
+
partnerFee: number
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface CreateMeldWidgetSessionRequest {
|
|
250
|
+
sessionData: MeldSessionData
|
|
251
|
+
sessionType: string
|
|
252
|
+
externalCustomerId: string
|
|
253
|
+
externalSessionId: string
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export interface MeldSessionData {
|
|
257
|
+
walletAddress: string
|
|
258
|
+
countryCode: string
|
|
259
|
+
sourceCurrencyCode: string
|
|
260
|
+
sourceAmount: string
|
|
261
|
+
destinationCurrencyCode: string
|
|
262
|
+
serviceProvider: string
|
|
263
|
+
paymentMethodType?: string
|
|
264
|
+
redirectUrl?: string
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export interface CreateMeldWidgetSessionResponse {
|
|
268
|
+
widgetSession: string
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export interface GetMeldTransactionRequest {
|
|
272
|
+
transactionId: string
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export interface GetMeldTransactionResponse {
|
|
276
|
+
transaction: MeldTransaction
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export interface SearchMeldTransactionsRequest {
|
|
280
|
+
statuses?: string
|
|
281
|
+
externalSessionIds?: string
|
|
282
|
+
externalCustomerIds?: string
|
|
283
|
+
customerIds?: string
|
|
284
|
+
sessionIds?: string
|
|
285
|
+
sessionId?: string
|
|
286
|
+
from?: string
|
|
287
|
+
to?: string
|
|
288
|
+
limit?: number
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export interface SearchMeldTransactionsResponse {
|
|
292
|
+
transactions: MeldTransactions
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export interface MeldTransaction {
|
|
296
|
+
id: string
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export interface MeldTransactions {
|
|
300
|
+
transactions: Array<MeldTransaction>
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export interface CreateMeldBankLinkingConnectionRequest {
|
|
304
|
+
externalCustomerId: string
|
|
305
|
+
institutionId?: string
|
|
306
|
+
institutionSearchString?: string
|
|
307
|
+
products?: Array<string>
|
|
308
|
+
optionalProducts?: Array<string>
|
|
309
|
+
redirectUrl?: string
|
|
310
|
+
regions?: Array<string>
|
|
311
|
+
accountPreferenceOverride?: MeldAccountPreferenceOverride
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export interface MeldAccountPreferenceOverride {
|
|
315
|
+
allowRedirect?: boolean
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export interface CreateMeldBankLinkingConnectionResponse {
|
|
319
|
+
connectionResponse: string
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
//
|
|
335
|
+
// Client
|
|
336
|
+
//
|
|
337
|
+
|
|
338
|
+
export class TrailsOnramp implements TrailsOnrampClient {
|
|
339
|
+
protected hostname: string
|
|
340
|
+
protected fetch: Fetch
|
|
341
|
+
protected path = '/rpc/TrailsOnramp/'
|
|
342
|
+
|
|
343
|
+
constructor(hostname: string, fetch: Fetch) {
|
|
344
|
+
this.hostname = hostname.replace(/\/*$/, '')
|
|
345
|
+
this.fetch = (input: RequestInfo, init?: RequestInit) => fetch(input, init)
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
private url(name: string): string {
|
|
349
|
+
return this.hostname + this.path + name
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
queryKey = {
|
|
353
|
+
getMeldCountryDefaults: (req: GetMeldCountryDefaultsRequest) => ['TrailsOnramp', 'getMeldCountryDefaults', req] as const,
|
|
354
|
+
getMeldFiatCurrencies: (req: GetMeldFiatCurrenciesRequest) => ['TrailsOnramp', 'getMeldFiatCurrencies', req] as const,
|
|
355
|
+
getMeldPaymentMethods: (req: GetMeldPaymentMethodsRequest) => ['TrailsOnramp', 'getMeldPaymentMethods', req] as const,
|
|
356
|
+
getMeldCryptoCurrencies: (req: GetMeldCryptoCurrenciesRequest) => ['TrailsOnramp', 'getMeldCryptoCurrencies', req] as const,
|
|
357
|
+
getMeldPurchaseLimits: (req: GetMeldPurchaseLimitsRequest) => ['TrailsOnramp', 'getMeldPurchaseLimits', req] as const,
|
|
358
|
+
getMeldQuote: (req: GetMeldQuoteRequest) => ['TrailsOnramp', 'getMeldQuote', req] as const,
|
|
359
|
+
createMeldWidgetSession: (req: CreateMeldWidgetSessionRequest) => ['TrailsOnramp', 'createMeldWidgetSession', req] as const,
|
|
360
|
+
getMeldTransaction: (req: GetMeldTransactionRequest) => ['TrailsOnramp', 'getMeldTransaction', req] as const,
|
|
361
|
+
searchMeldTransactions: (req: SearchMeldTransactionsRequest) => ['TrailsOnramp', 'searchMeldTransactions', req] as const,
|
|
362
|
+
createMeldBankLinkingConnection: (req: CreateMeldBankLinkingConnectionRequest) => ['TrailsOnramp', 'createMeldBankLinkingConnection', req] as const,
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
getMeldCountryDefaults = (req: GetMeldCountryDefaultsRequest, headers?: object, signal?: AbortSignal): Promise<GetMeldCountryDefaultsResponse> => {
|
|
366
|
+
return this.fetch(
|
|
367
|
+
this.url('GetMeldCountryDefaults'),
|
|
368
|
+
createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
|
|
369
|
+
return buildResponse(res).then(_data => {
|
|
370
|
+
return JsonDecode<GetMeldCountryDefaultsResponse>(_data, 'GetMeldCountryDefaultsResponse')
|
|
371
|
+
})
|
|
372
|
+
}, (error) => {
|
|
373
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
374
|
+
})
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
getMeldFiatCurrencies = (req: GetMeldFiatCurrenciesRequest, headers?: object, signal?: AbortSignal): Promise<GetMeldFiatCurrenciesResponse> => {
|
|
378
|
+
return this.fetch(
|
|
379
|
+
this.url('GetMeldFiatCurrencies'),
|
|
380
|
+
createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
|
|
381
|
+
return buildResponse(res).then(_data => {
|
|
382
|
+
return JsonDecode<GetMeldFiatCurrenciesResponse>(_data, 'GetMeldFiatCurrenciesResponse')
|
|
383
|
+
})
|
|
384
|
+
}, (error) => {
|
|
385
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
386
|
+
})
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
getMeldPaymentMethods = (req: GetMeldPaymentMethodsRequest, headers?: object, signal?: AbortSignal): Promise<GetMeldPaymentMethodsResponse> => {
|
|
390
|
+
return this.fetch(
|
|
391
|
+
this.url('GetMeldPaymentMethods'),
|
|
392
|
+
createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
|
|
393
|
+
return buildResponse(res).then(_data => {
|
|
394
|
+
return JsonDecode<GetMeldPaymentMethodsResponse>(_data, 'GetMeldPaymentMethodsResponse')
|
|
395
|
+
})
|
|
396
|
+
}, (error) => {
|
|
397
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
398
|
+
})
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
getMeldCryptoCurrencies = (req: GetMeldCryptoCurrenciesRequest, headers?: object, signal?: AbortSignal): Promise<GetMeldCryptoCurrenciesResponse> => {
|
|
402
|
+
return this.fetch(
|
|
403
|
+
this.url('GetMeldCryptoCurrencies'),
|
|
404
|
+
createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
|
|
405
|
+
return buildResponse(res).then(_data => {
|
|
406
|
+
return JsonDecode<GetMeldCryptoCurrenciesResponse>(_data, 'GetMeldCryptoCurrenciesResponse')
|
|
407
|
+
})
|
|
408
|
+
}, (error) => {
|
|
409
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
410
|
+
})
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
getMeldPurchaseLimits = (req: GetMeldPurchaseLimitsRequest, headers?: object, signal?: AbortSignal): Promise<GetMeldPurchaseLimitsResponse> => {
|
|
414
|
+
return this.fetch(
|
|
415
|
+
this.url('GetMeldPurchaseLimits'),
|
|
416
|
+
createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
|
|
417
|
+
return buildResponse(res).then(_data => {
|
|
418
|
+
return JsonDecode<GetMeldPurchaseLimitsResponse>(_data, 'GetMeldPurchaseLimitsResponse')
|
|
419
|
+
})
|
|
420
|
+
}, (error) => {
|
|
421
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
422
|
+
})
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
getMeldQuote = (req: GetMeldQuoteRequest, headers?: object, signal?: AbortSignal): Promise<GetMeldQuoteResponse> => {
|
|
426
|
+
return this.fetch(
|
|
427
|
+
this.url('GetMeldQuote'),
|
|
428
|
+
createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
|
|
429
|
+
return buildResponse(res).then(_data => {
|
|
430
|
+
return JsonDecode<GetMeldQuoteResponse>(_data, 'GetMeldQuoteResponse')
|
|
431
|
+
})
|
|
432
|
+
}, (error) => {
|
|
433
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
434
|
+
})
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
createMeldWidgetSession = (req: CreateMeldWidgetSessionRequest, headers?: object, signal?: AbortSignal): Promise<CreateMeldWidgetSessionResponse> => {
|
|
438
|
+
return this.fetch(
|
|
439
|
+
this.url('CreateMeldWidgetSession'),
|
|
440
|
+
createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
|
|
441
|
+
return buildResponse(res).then(_data => {
|
|
442
|
+
return JsonDecode<CreateMeldWidgetSessionResponse>(_data, 'CreateMeldWidgetSessionResponse')
|
|
443
|
+
})
|
|
444
|
+
}, (error) => {
|
|
445
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
446
|
+
})
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
getMeldTransaction = (req: GetMeldTransactionRequest, headers?: object, signal?: AbortSignal): Promise<GetMeldTransactionResponse> => {
|
|
450
|
+
return this.fetch(
|
|
451
|
+
this.url('GetMeldTransaction'),
|
|
452
|
+
createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
|
|
453
|
+
return buildResponse(res).then(_data => {
|
|
454
|
+
return JsonDecode<GetMeldTransactionResponse>(_data, 'GetMeldTransactionResponse')
|
|
455
|
+
})
|
|
456
|
+
}, (error) => {
|
|
457
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
458
|
+
})
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
searchMeldTransactions = (req: SearchMeldTransactionsRequest, headers?: object, signal?: AbortSignal): Promise<SearchMeldTransactionsResponse> => {
|
|
462
|
+
return this.fetch(
|
|
463
|
+
this.url('SearchMeldTransactions'),
|
|
464
|
+
createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
|
|
465
|
+
return buildResponse(res).then(_data => {
|
|
466
|
+
return JsonDecode<SearchMeldTransactionsResponse>(_data, 'SearchMeldTransactionsResponse')
|
|
467
|
+
})
|
|
468
|
+
}, (error) => {
|
|
469
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
470
|
+
})
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
createMeldBankLinkingConnection = (req: CreateMeldBankLinkingConnectionRequest, headers?: object, signal?: AbortSignal): Promise<CreateMeldBankLinkingConnectionResponse> => {
|
|
474
|
+
return this.fetch(
|
|
475
|
+
this.url('CreateMeldBankLinkingConnection'),
|
|
476
|
+
createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
|
|
477
|
+
return buildResponse(res).then(_data => {
|
|
478
|
+
return JsonDecode<CreateMeldBankLinkingConnectionResponse>(_data, 'CreateMeldBankLinkingConnectionResponse')
|
|
479
|
+
})
|
|
480
|
+
}, (error) => {
|
|
481
|
+
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
|
|
482
|
+
})
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const createHttpRequest = (body: string = '{}', headers: object = {}, signal: AbortSignal | null = null): object => {
|
|
488
|
+
const reqHeaders: { [key: string]: string } = { ...headers, 'Content-Type': 'application/json', [WebrpcHeader]: WebrpcHeaderValue }
|
|
489
|
+
return { method: 'POST', headers: reqHeaders, body, signal }
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
const buildResponse = (res: Response): Promise<any> => {
|
|
493
|
+
return res.text().then(text => {
|
|
494
|
+
let data
|
|
495
|
+
try {
|
|
496
|
+
data = JSON.parse(text)
|
|
497
|
+
} catch(error) {
|
|
498
|
+
throw WebrpcBadResponseError.new({
|
|
499
|
+
status: res.status,
|
|
500
|
+
cause: `JSON.parse(): ${error instanceof Error ? error.message : String(error)}: response text: ${text}`},
|
|
501
|
+
)
|
|
502
|
+
}
|
|
503
|
+
if (!res.ok) {
|
|
504
|
+
const code: number = (typeof data.code === 'number') ? data.code : 0
|
|
505
|
+
throw (webrpcErrorByCode[code] || WebrpcError).new(data)
|
|
506
|
+
}
|
|
507
|
+
return data
|
|
508
|
+
})
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
export const JsonEncode = <T = any>(obj: T): string => {
|
|
519
|
+
return JSON.stringify(obj)
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
export const JsonDecode = <T = any>(data: string | any, _typ: string = ''): T => {
|
|
523
|
+
let parsed: any = data
|
|
524
|
+
if (typeof data === 'string') {
|
|
525
|
+
try { parsed = JSON.parse(data) } catch (err) {
|
|
526
|
+
throw WebrpcBadResponseError.new({ cause: `JsonDecode: JSON.parse failed: ${(err as Error).message}` })
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return parsed as T
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
//
|
|
534
|
+
// Errors
|
|
535
|
+
//
|
|
536
|
+
|
|
537
|
+
type WebrpcErrorParams = { name?: string, code?: number, message?: string, status?: number, cause?: string }
|
|
538
|
+
|
|
539
|
+
export class WebrpcError extends Error {
|
|
540
|
+
code: number
|
|
541
|
+
status: number
|
|
542
|
+
|
|
543
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
544
|
+
super(error.message)
|
|
545
|
+
this.name = error.name || 'WebrpcEndpointError'
|
|
546
|
+
this.code = typeof error.code === 'number' ? error.code : 0
|
|
547
|
+
this.message = error.message || `endpoint error`
|
|
548
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
549
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
550
|
+
Object.setPrototypeOf(this, WebrpcError.prototype)
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
static new(payload: any): WebrpcError {
|
|
554
|
+
return new this({ message: payload.message, code: payload.code, status: payload.status, cause: payload.cause })
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
export class WebrpcEndpointError extends WebrpcError {
|
|
560
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
561
|
+
super(error)
|
|
562
|
+
this.name = error.name || 'WebrpcEndpoint'
|
|
563
|
+
this.code = typeof error.code === 'number' ? error.code : 0
|
|
564
|
+
this.message = error.message || `endpoint error`
|
|
565
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
566
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
567
|
+
Object.setPrototypeOf(this, WebrpcEndpointError.prototype)
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
export class WebrpcRequestFailedError extends WebrpcError {
|
|
572
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
573
|
+
super(error)
|
|
574
|
+
this.name = error.name || 'WebrpcRequestFailed'
|
|
575
|
+
this.code = typeof error.code === 'number' ? error.code : -1
|
|
576
|
+
this.message = error.message || `request failed`
|
|
577
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
578
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
579
|
+
Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype)
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
export class WebrpcBadRouteError extends WebrpcError {
|
|
584
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
585
|
+
super(error)
|
|
586
|
+
this.name = error.name || 'WebrpcBadRoute'
|
|
587
|
+
this.code = typeof error.code === 'number' ? error.code : -2
|
|
588
|
+
this.message = error.message || `bad route`
|
|
589
|
+
this.status = typeof error.status === 'number' ? error.status : 404
|
|
590
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
591
|
+
Object.setPrototypeOf(this, WebrpcBadRouteError.prototype)
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
export class WebrpcBadMethodError extends WebrpcError {
|
|
596
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
597
|
+
super(error)
|
|
598
|
+
this.name = error.name || 'WebrpcBadMethod'
|
|
599
|
+
this.code = typeof error.code === 'number' ? error.code : -3
|
|
600
|
+
this.message = error.message || `bad method`
|
|
601
|
+
this.status = typeof error.status === 'number' ? error.status : 405
|
|
602
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
603
|
+
Object.setPrototypeOf(this, WebrpcBadMethodError.prototype)
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
export class WebrpcBadRequestError extends WebrpcError {
|
|
608
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
609
|
+
super(error)
|
|
610
|
+
this.name = error.name || 'WebrpcBadRequest'
|
|
611
|
+
this.code = typeof error.code === 'number' ? error.code : -4
|
|
612
|
+
this.message = error.message || `bad request`
|
|
613
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
614
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
615
|
+
Object.setPrototypeOf(this, WebrpcBadRequestError.prototype)
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
export class WebrpcBadResponseError extends WebrpcError {
|
|
620
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
621
|
+
super(error)
|
|
622
|
+
this.name = error.name || 'WebrpcBadResponse'
|
|
623
|
+
this.code = typeof error.code === 'number' ? error.code : -5
|
|
624
|
+
this.message = error.message || `bad response`
|
|
625
|
+
this.status = typeof error.status === 'number' ? error.status : 500
|
|
626
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
627
|
+
Object.setPrototypeOf(this, WebrpcBadResponseError.prototype)
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
export class WebrpcServerPanicError extends WebrpcError {
|
|
632
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
633
|
+
super(error)
|
|
634
|
+
this.name = error.name || 'WebrpcServerPanic'
|
|
635
|
+
this.code = typeof error.code === 'number' ? error.code : -6
|
|
636
|
+
this.message = error.message || `server panic`
|
|
637
|
+
this.status = typeof error.status === 'number' ? error.status : 500
|
|
638
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
639
|
+
Object.setPrototypeOf(this, WebrpcServerPanicError.prototype)
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
export class WebrpcInternalErrorError extends WebrpcError {
|
|
644
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
645
|
+
super(error)
|
|
646
|
+
this.name = error.name || 'WebrpcInternalError'
|
|
647
|
+
this.code = typeof error.code === 'number' ? error.code : -7
|
|
648
|
+
this.message = error.message || `internal error`
|
|
649
|
+
this.status = typeof error.status === 'number' ? error.status : 500
|
|
650
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
651
|
+
Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype)
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
export class WebrpcClientAbortedError extends WebrpcError {
|
|
656
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
657
|
+
super(error)
|
|
658
|
+
this.name = error.name || 'WebrpcClientAborted'
|
|
659
|
+
this.code = typeof error.code === 'number' ? error.code : -8
|
|
660
|
+
this.message = error.message || `request aborted by client`
|
|
661
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
662
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
663
|
+
Object.setPrototypeOf(this, WebrpcClientAbortedError.prototype)
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
export class WebrpcStreamLostError extends WebrpcError {
|
|
668
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
669
|
+
super(error)
|
|
670
|
+
this.name = error.name || 'WebrpcStreamLost'
|
|
671
|
+
this.code = typeof error.code === 'number' ? error.code : -9
|
|
672
|
+
this.message = error.message || `stream lost`
|
|
673
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
674
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
675
|
+
Object.setPrototypeOf(this, WebrpcStreamLostError.prototype)
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
export class WebrpcStreamFinishedError extends WebrpcError {
|
|
680
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
681
|
+
super(error)
|
|
682
|
+
this.name = error.name || 'WebrpcStreamFinished'
|
|
683
|
+
this.code = typeof error.code === 'number' ? error.code : -10
|
|
684
|
+
this.message = error.message || `stream finished`
|
|
685
|
+
this.status = typeof error.status === 'number' ? error.status : 200
|
|
686
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
687
|
+
Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype)
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
//
|
|
693
|
+
// Schema errors
|
|
694
|
+
//
|
|
695
|
+
|
|
696
|
+
export class UnauthorizedError extends WebrpcError {
|
|
697
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
698
|
+
super(error)
|
|
699
|
+
this.name = error.name || 'Unauthorized'
|
|
700
|
+
this.code = typeof error.code === 'number' ? error.code : 1000
|
|
701
|
+
this.message = error.message || `Unauthorized access`
|
|
702
|
+
this.status = typeof error.status === 'number' ? error.status : 401
|
|
703
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
704
|
+
Object.setPrototypeOf(this, UnauthorizedError.prototype)
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
export class PermissionDeniedError extends WebrpcError {
|
|
709
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
710
|
+
super(error)
|
|
711
|
+
this.name = error.name || 'PermissionDenied'
|
|
712
|
+
this.code = typeof error.code === 'number' ? error.code : 1001
|
|
713
|
+
this.message = error.message || `Permission denied`
|
|
714
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
715
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
716
|
+
Object.setPrototypeOf(this, PermissionDeniedError.prototype)
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
export class SessionExpiredError extends WebrpcError {
|
|
721
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
722
|
+
super(error)
|
|
723
|
+
this.name = error.name || 'SessionExpired'
|
|
724
|
+
this.code = typeof error.code === 'number' ? error.code : 1002
|
|
725
|
+
this.message = error.message || `Session expired`
|
|
726
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
727
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
728
|
+
Object.setPrototypeOf(this, SessionExpiredError.prototype)
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
export class MethodNotFoundError extends WebrpcError {
|
|
733
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
734
|
+
super(error)
|
|
735
|
+
this.name = error.name || 'MethodNotFound'
|
|
736
|
+
this.code = typeof error.code === 'number' ? error.code : 1003
|
|
737
|
+
this.message = error.message || `Method not found`
|
|
738
|
+
this.status = typeof error.status === 'number' ? error.status : 404
|
|
739
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
740
|
+
Object.setPrototypeOf(this, MethodNotFoundError.prototype)
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
export class RequestConflictError extends WebrpcError {
|
|
745
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
746
|
+
super(error)
|
|
747
|
+
this.name = error.name || 'RequestConflict'
|
|
748
|
+
this.code = typeof error.code === 'number' ? error.code : 1004
|
|
749
|
+
this.message = error.message || `Conflict with target resource`
|
|
750
|
+
this.status = typeof error.status === 'number' ? error.status : 409
|
|
751
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
752
|
+
Object.setPrototypeOf(this, RequestConflictError.prototype)
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
export class AbortedError extends WebrpcError {
|
|
757
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
758
|
+
super(error)
|
|
759
|
+
this.name = error.name || 'Aborted'
|
|
760
|
+
this.code = typeof error.code === 'number' ? error.code : 1005
|
|
761
|
+
this.message = error.message || `Request aborted`
|
|
762
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
763
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
764
|
+
Object.setPrototypeOf(this, AbortedError.prototype)
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
export class GeoblockedError extends WebrpcError {
|
|
769
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
770
|
+
super(error)
|
|
771
|
+
this.name = error.name || 'Geoblocked'
|
|
772
|
+
this.code = typeof error.code === 'number' ? error.code : 1006
|
|
773
|
+
this.message = error.message || `Geoblocked region`
|
|
774
|
+
this.status = typeof error.status === 'number' ? error.status : 451
|
|
775
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
776
|
+
Object.setPrototypeOf(this, GeoblockedError.prototype)
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
export class RateLimitedError extends WebrpcError {
|
|
781
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
782
|
+
super(error)
|
|
783
|
+
this.name = error.name || 'RateLimited'
|
|
784
|
+
this.code = typeof error.code === 'number' ? error.code : 1007
|
|
785
|
+
this.message = error.message || `Rate-limited. Please slow down.`
|
|
786
|
+
this.status = typeof error.status === 'number' ? error.status : 429
|
|
787
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
788
|
+
Object.setPrototypeOf(this, RateLimitedError.prototype)
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
export class ProjectNotFoundError extends WebrpcError {
|
|
793
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
794
|
+
super(error)
|
|
795
|
+
this.name = error.name || 'ProjectNotFound'
|
|
796
|
+
this.code = typeof error.code === 'number' ? error.code : 1008
|
|
797
|
+
this.message = error.message || `Project not found`
|
|
798
|
+
this.status = typeof error.status === 'number' ? error.status : 401
|
|
799
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
800
|
+
Object.setPrototypeOf(this, ProjectNotFoundError.prototype)
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
export class AccessKeyNotFoundError extends WebrpcError {
|
|
805
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
806
|
+
super(error)
|
|
807
|
+
this.name = error.name || 'AccessKeyNotFound'
|
|
808
|
+
this.code = typeof error.code === 'number' ? error.code : 1101
|
|
809
|
+
this.message = error.message || `Access key not found`
|
|
810
|
+
this.status = typeof error.status === 'number' ? error.status : 401
|
|
811
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
812
|
+
Object.setPrototypeOf(this, AccessKeyNotFoundError.prototype)
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
export class AccessKeyMismatchError extends WebrpcError {
|
|
817
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
818
|
+
super(error)
|
|
819
|
+
this.name = error.name || 'AccessKeyMismatch'
|
|
820
|
+
this.code = typeof error.code === 'number' ? error.code : 1102
|
|
821
|
+
this.message = error.message || `Access key mismatch`
|
|
822
|
+
this.status = typeof error.status === 'number' ? error.status : 409
|
|
823
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
824
|
+
Object.setPrototypeOf(this, AccessKeyMismatchError.prototype)
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
export class InvalidOriginError extends WebrpcError {
|
|
829
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
830
|
+
super(error)
|
|
831
|
+
this.name = error.name || 'InvalidOrigin'
|
|
832
|
+
this.code = typeof error.code === 'number' ? error.code : 1103
|
|
833
|
+
this.message = error.message || `Invalid origin for Access Key`
|
|
834
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
835
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
836
|
+
Object.setPrototypeOf(this, InvalidOriginError.prototype)
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
export class InvalidServiceError extends WebrpcError {
|
|
841
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
842
|
+
super(error)
|
|
843
|
+
this.name = error.name || 'InvalidService'
|
|
844
|
+
this.code = typeof error.code === 'number' ? error.code : 1104
|
|
845
|
+
this.message = error.message || `Service not enabled for Access key`
|
|
846
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
847
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
848
|
+
Object.setPrototypeOf(this, InvalidServiceError.prototype)
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
export class UnauthorizedUserError extends WebrpcError {
|
|
853
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
854
|
+
super(error)
|
|
855
|
+
this.name = error.name || 'UnauthorizedUser'
|
|
856
|
+
this.code = typeof error.code === 'number' ? error.code : 1105
|
|
857
|
+
this.message = error.message || `Unauthorized user`
|
|
858
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
859
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
860
|
+
Object.setPrototypeOf(this, UnauthorizedUserError.prototype)
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
export class QuotaExceededError extends WebrpcError {
|
|
865
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
866
|
+
super(error)
|
|
867
|
+
this.name = error.name || 'QuotaExceeded'
|
|
868
|
+
this.code = typeof error.code === 'number' ? error.code : 1200
|
|
869
|
+
this.message = error.message || `Quota request exceeded`
|
|
870
|
+
this.status = typeof error.status === 'number' ? error.status : 429
|
|
871
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
872
|
+
Object.setPrototypeOf(this, QuotaExceededError.prototype)
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
export class QuotaRateLimitError extends WebrpcError {
|
|
877
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
878
|
+
super(error)
|
|
879
|
+
this.name = error.name || 'QuotaRateLimit'
|
|
880
|
+
this.code = typeof error.code === 'number' ? error.code : 1201
|
|
881
|
+
this.message = error.message || `Quota rate limit exceeded`
|
|
882
|
+
this.status = typeof error.status === 'number' ? error.status : 429
|
|
883
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
884
|
+
Object.setPrototypeOf(this, QuotaRateLimitError.prototype)
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
export class NoDefaultKeyError extends WebrpcError {
|
|
889
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
890
|
+
super(error)
|
|
891
|
+
this.name = error.name || 'NoDefaultKey'
|
|
892
|
+
this.code = typeof error.code === 'number' ? error.code : 1300
|
|
893
|
+
this.message = error.message || `No default access key found`
|
|
894
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
895
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
896
|
+
Object.setPrototypeOf(this, NoDefaultKeyError.prototype)
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
export class MaxAccessKeysError extends WebrpcError {
|
|
901
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
902
|
+
super(error)
|
|
903
|
+
this.name = error.name || 'MaxAccessKeys'
|
|
904
|
+
this.code = typeof error.code === 'number' ? error.code : 1301
|
|
905
|
+
this.message = error.message || `Access keys limit reached`
|
|
906
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
907
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
908
|
+
Object.setPrototypeOf(this, MaxAccessKeysError.prototype)
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
export class AtLeastOneKeyError extends WebrpcError {
|
|
913
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
914
|
+
super(error)
|
|
915
|
+
this.name = error.name || 'AtLeastOneKey'
|
|
916
|
+
this.code = typeof error.code === 'number' ? error.code : 1302
|
|
917
|
+
this.message = error.message || `You need at least one Access Key`
|
|
918
|
+
this.status = typeof error.status === 'number' ? error.status : 403
|
|
919
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
920
|
+
Object.setPrototypeOf(this, AtLeastOneKeyError.prototype)
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
export class TimeoutError extends WebrpcError {
|
|
925
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
926
|
+
super(error)
|
|
927
|
+
this.name = error.name || 'Timeout'
|
|
928
|
+
this.code = typeof error.code === 'number' ? error.code : 1900
|
|
929
|
+
this.message = error.message || `Request timed out`
|
|
930
|
+
this.status = typeof error.status === 'number' ? error.status : 408
|
|
931
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
932
|
+
Object.setPrototypeOf(this, TimeoutError.prototype)
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
export class InvalidArgumentError extends WebrpcError {
|
|
937
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
938
|
+
super(error)
|
|
939
|
+
this.name = error.name || 'InvalidArgument'
|
|
940
|
+
this.code = typeof error.code === 'number' ? error.code : 2000
|
|
941
|
+
this.message = error.message || `Invalid argument`
|
|
942
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
943
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
944
|
+
Object.setPrototypeOf(this, InvalidArgumentError.prototype)
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
export class UnexpectedError extends WebrpcError {
|
|
949
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
950
|
+
super(error)
|
|
951
|
+
this.name = error.name || 'Unexpected'
|
|
952
|
+
this.code = typeof error.code === 'number' ? error.code : 2001
|
|
953
|
+
this.message = error.message || `Unexpected server error`
|
|
954
|
+
this.status = typeof error.status === 'number' ? error.status : 500
|
|
955
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
956
|
+
Object.setPrototypeOf(this, UnexpectedError.prototype)
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
export class UnavailableError extends WebrpcError {
|
|
961
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
962
|
+
super(error)
|
|
963
|
+
this.name = error.name || 'Unavailable'
|
|
964
|
+
this.code = typeof error.code === 'number' ? error.code : 2002
|
|
965
|
+
this.message = error.message || `Unavailable resource`
|
|
966
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
967
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
968
|
+
Object.setPrototypeOf(this, UnavailableError.prototype)
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
export class QueryFailedError extends WebrpcError {
|
|
973
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
974
|
+
super(error)
|
|
975
|
+
this.name = error.name || 'QueryFailed'
|
|
976
|
+
this.code = typeof error.code === 'number' ? error.code : 2003
|
|
977
|
+
this.message = error.message || `Query failed`
|
|
978
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
979
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
980
|
+
Object.setPrototypeOf(this, QueryFailedError.prototype)
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
export class IntentStatusError extends WebrpcError {
|
|
985
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
986
|
+
super(error)
|
|
987
|
+
this.name = error.name || 'IntentStatus'
|
|
988
|
+
this.code = typeof error.code === 'number' ? error.code : 2004
|
|
989
|
+
this.message = error.message || `Invalid intent status`
|
|
990
|
+
this.status = typeof error.status === 'number' ? error.status : 422
|
|
991
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
992
|
+
Object.setPrototypeOf(this, IntentStatusError.prototype)
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
export class NotFoundError extends WebrpcError {
|
|
997
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
998
|
+
super(error)
|
|
999
|
+
this.name = error.name || 'NotFound'
|
|
1000
|
+
this.code = typeof error.code === 'number' ? error.code : 8000
|
|
1001
|
+
this.message = error.message || `Resource not found`
|
|
1002
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1003
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1004
|
+
Object.setPrototypeOf(this, NotFoundError.prototype)
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
export class UnsupportedNetworkError extends WebrpcError {
|
|
1009
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1010
|
+
super(error)
|
|
1011
|
+
this.name = error.name || 'UnsupportedNetwork'
|
|
1012
|
+
this.code = typeof error.code === 'number' ? error.code : 8008
|
|
1013
|
+
this.message = error.message || `Unsupported network`
|
|
1014
|
+
this.status = typeof error.status === 'number' ? error.status : 422
|
|
1015
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1016
|
+
Object.setPrototypeOf(this, UnsupportedNetworkError.prototype)
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
export class ClientOutdatedError extends WebrpcError {
|
|
1021
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1022
|
+
super(error)
|
|
1023
|
+
this.name = error.name || 'ClientOutdated'
|
|
1024
|
+
this.code = typeof error.code === 'number' ? error.code : 8009
|
|
1025
|
+
this.message = error.message || `Client is outdated`
|
|
1026
|
+
this.status = typeof error.status === 'number' ? error.status : 422
|
|
1027
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1028
|
+
Object.setPrototypeOf(this, ClientOutdatedError.prototype)
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
export class IntentsSkippedError extends WebrpcError {
|
|
1033
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1034
|
+
super(error)
|
|
1035
|
+
this.name = error.name || 'IntentsSkipped'
|
|
1036
|
+
this.code = typeof error.code === 'number' ? error.code : 7000
|
|
1037
|
+
this.message = error.message || `Intents skipped as client is attempting a transaction that does not require intents`
|
|
1038
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1039
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1040
|
+
Object.setPrototypeOf(this, IntentsSkippedError.prototype)
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
export class QuoteExpiredError extends WebrpcError {
|
|
1045
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1046
|
+
super(error)
|
|
1047
|
+
this.name = error.name || 'QuoteExpired'
|
|
1048
|
+
this.code = typeof error.code === 'number' ? error.code : 7001
|
|
1049
|
+
this.message = error.message || `Intent quote has expired. Please try again.`
|
|
1050
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1051
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1052
|
+
Object.setPrototypeOf(this, QuoteExpiredError.prototype)
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
export class IntentsDisabledError extends WebrpcError {
|
|
1057
|
+
constructor(error: WebrpcErrorParams = {}) {
|
|
1058
|
+
super(error)
|
|
1059
|
+
this.name = error.name || 'IntentsDisabled'
|
|
1060
|
+
this.code = typeof error.code === 'number' ? error.code : 9000
|
|
1061
|
+
this.message = error.message || `Intents service is currently unavailable`
|
|
1062
|
+
this.status = typeof error.status === 'number' ? error.status : 400
|
|
1063
|
+
if (error.cause !== undefined) this.cause = error.cause
|
|
1064
|
+
Object.setPrototypeOf(this, IntentsDisabledError.prototype)
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
|
|
1069
|
+
export enum errors {
|
|
1070
|
+
WebrpcEndpoint = 'WebrpcEndpoint',
|
|
1071
|
+
WebrpcRequestFailed = 'WebrpcRequestFailed',
|
|
1072
|
+
WebrpcBadRoute = 'WebrpcBadRoute',
|
|
1073
|
+
WebrpcBadMethod = 'WebrpcBadMethod',
|
|
1074
|
+
WebrpcBadRequest = 'WebrpcBadRequest',
|
|
1075
|
+
WebrpcBadResponse = 'WebrpcBadResponse',
|
|
1076
|
+
WebrpcServerPanic = 'WebrpcServerPanic',
|
|
1077
|
+
WebrpcInternalError = 'WebrpcInternalError',
|
|
1078
|
+
WebrpcClientAborted = 'WebrpcClientAborted',
|
|
1079
|
+
WebrpcStreamLost = 'WebrpcStreamLost',
|
|
1080
|
+
WebrpcStreamFinished = 'WebrpcStreamFinished',
|
|
1081
|
+
Unauthorized = 'Unauthorized',
|
|
1082
|
+
PermissionDenied = 'PermissionDenied',
|
|
1083
|
+
SessionExpired = 'SessionExpired',
|
|
1084
|
+
MethodNotFound = 'MethodNotFound',
|
|
1085
|
+
RequestConflict = 'RequestConflict',
|
|
1086
|
+
Aborted = 'Aborted',
|
|
1087
|
+
Geoblocked = 'Geoblocked',
|
|
1088
|
+
RateLimited = 'RateLimited',
|
|
1089
|
+
ProjectNotFound = 'ProjectNotFound',
|
|
1090
|
+
AccessKeyNotFound = 'AccessKeyNotFound',
|
|
1091
|
+
AccessKeyMismatch = 'AccessKeyMismatch',
|
|
1092
|
+
InvalidOrigin = 'InvalidOrigin',
|
|
1093
|
+
InvalidService = 'InvalidService',
|
|
1094
|
+
UnauthorizedUser = 'UnauthorizedUser',
|
|
1095
|
+
QuotaExceeded = 'QuotaExceeded',
|
|
1096
|
+
QuotaRateLimit = 'QuotaRateLimit',
|
|
1097
|
+
NoDefaultKey = 'NoDefaultKey',
|
|
1098
|
+
MaxAccessKeys = 'MaxAccessKeys',
|
|
1099
|
+
AtLeastOneKey = 'AtLeastOneKey',
|
|
1100
|
+
Timeout = 'Timeout',
|
|
1101
|
+
InvalidArgument = 'InvalidArgument',
|
|
1102
|
+
Unexpected = 'Unexpected',
|
|
1103
|
+
Unavailable = 'Unavailable',
|
|
1104
|
+
QueryFailed = 'QueryFailed',
|
|
1105
|
+
IntentStatus = 'IntentStatus',
|
|
1106
|
+
NotFound = 'NotFound',
|
|
1107
|
+
UnsupportedNetwork = 'UnsupportedNetwork',
|
|
1108
|
+
ClientOutdated = 'ClientOutdated',
|
|
1109
|
+
IntentsSkipped = 'IntentsSkipped',
|
|
1110
|
+
QuoteExpired = 'QuoteExpired',
|
|
1111
|
+
IntentsDisabled = 'IntentsDisabled',
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
export enum WebrpcErrorCodes {
|
|
1115
|
+
WebrpcEndpoint = 0,
|
|
1116
|
+
WebrpcRequestFailed = -1,
|
|
1117
|
+
WebrpcBadRoute = -2,
|
|
1118
|
+
WebrpcBadMethod = -3,
|
|
1119
|
+
WebrpcBadRequest = -4,
|
|
1120
|
+
WebrpcBadResponse = -5,
|
|
1121
|
+
WebrpcServerPanic = -6,
|
|
1122
|
+
WebrpcInternalError = -7,
|
|
1123
|
+
WebrpcClientAborted = -8,
|
|
1124
|
+
WebrpcStreamLost = -9,
|
|
1125
|
+
WebrpcStreamFinished = -10,
|
|
1126
|
+
Unauthorized = 1000,
|
|
1127
|
+
PermissionDenied = 1001,
|
|
1128
|
+
SessionExpired = 1002,
|
|
1129
|
+
MethodNotFound = 1003,
|
|
1130
|
+
RequestConflict = 1004,
|
|
1131
|
+
Aborted = 1005,
|
|
1132
|
+
Geoblocked = 1006,
|
|
1133
|
+
RateLimited = 1007,
|
|
1134
|
+
ProjectNotFound = 1008,
|
|
1135
|
+
AccessKeyNotFound = 1101,
|
|
1136
|
+
AccessKeyMismatch = 1102,
|
|
1137
|
+
InvalidOrigin = 1103,
|
|
1138
|
+
InvalidService = 1104,
|
|
1139
|
+
UnauthorizedUser = 1105,
|
|
1140
|
+
QuotaExceeded = 1200,
|
|
1141
|
+
QuotaRateLimit = 1201,
|
|
1142
|
+
NoDefaultKey = 1300,
|
|
1143
|
+
MaxAccessKeys = 1301,
|
|
1144
|
+
AtLeastOneKey = 1302,
|
|
1145
|
+
Timeout = 1900,
|
|
1146
|
+
InvalidArgument = 2000,
|
|
1147
|
+
Unexpected = 2001,
|
|
1148
|
+
Unavailable = 2002,
|
|
1149
|
+
QueryFailed = 2003,
|
|
1150
|
+
IntentStatus = 2004,
|
|
1151
|
+
NotFound = 8000,
|
|
1152
|
+
UnsupportedNetwork = 8008,
|
|
1153
|
+
ClientOutdated = 8009,
|
|
1154
|
+
IntentsSkipped = 7000,
|
|
1155
|
+
QuoteExpired = 7001,
|
|
1156
|
+
IntentsDisabled = 9000,
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
export const webrpcErrorByCode: { [code: number]: any } = {
|
|
1160
|
+
[0]: WebrpcEndpointError,
|
|
1161
|
+
[-1]: WebrpcRequestFailedError,
|
|
1162
|
+
[-2]: WebrpcBadRouteError,
|
|
1163
|
+
[-3]: WebrpcBadMethodError,
|
|
1164
|
+
[-4]: WebrpcBadRequestError,
|
|
1165
|
+
[-5]: WebrpcBadResponseError,
|
|
1166
|
+
[-6]: WebrpcServerPanicError,
|
|
1167
|
+
[-7]: WebrpcInternalErrorError,
|
|
1168
|
+
[-8]: WebrpcClientAbortedError,
|
|
1169
|
+
[-9]: WebrpcStreamLostError,
|
|
1170
|
+
[-10]: WebrpcStreamFinishedError,
|
|
1171
|
+
[1000]: UnauthorizedError,
|
|
1172
|
+
[1001]: PermissionDeniedError,
|
|
1173
|
+
[1002]: SessionExpiredError,
|
|
1174
|
+
[1003]: MethodNotFoundError,
|
|
1175
|
+
[1004]: RequestConflictError,
|
|
1176
|
+
[1005]: AbortedError,
|
|
1177
|
+
[1006]: GeoblockedError,
|
|
1178
|
+
[1007]: RateLimitedError,
|
|
1179
|
+
[1008]: ProjectNotFoundError,
|
|
1180
|
+
[1101]: AccessKeyNotFoundError,
|
|
1181
|
+
[1102]: AccessKeyMismatchError,
|
|
1182
|
+
[1103]: InvalidOriginError,
|
|
1183
|
+
[1104]: InvalidServiceError,
|
|
1184
|
+
[1105]: UnauthorizedUserError,
|
|
1185
|
+
[1200]: QuotaExceededError,
|
|
1186
|
+
[1201]: QuotaRateLimitError,
|
|
1187
|
+
[1300]: NoDefaultKeyError,
|
|
1188
|
+
[1301]: MaxAccessKeysError,
|
|
1189
|
+
[1302]: AtLeastOneKeyError,
|
|
1190
|
+
[1900]: TimeoutError,
|
|
1191
|
+
[2000]: InvalidArgumentError,
|
|
1192
|
+
[2001]: UnexpectedError,
|
|
1193
|
+
[2002]: UnavailableError,
|
|
1194
|
+
[2003]: QueryFailedError,
|
|
1195
|
+
[2004]: IntentStatusError,
|
|
1196
|
+
[8000]: NotFoundError,
|
|
1197
|
+
[8008]: UnsupportedNetworkError,
|
|
1198
|
+
[8009]: ClientOutdatedError,
|
|
1199
|
+
[7000]: IntentsSkippedError,
|
|
1200
|
+
[7001]: QuoteExpiredError,
|
|
1201
|
+
[9000]: IntentsDisabledError,
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
|
|
1206
|
+
//
|
|
1207
|
+
// Webrpc
|
|
1208
|
+
//
|
|
1209
|
+
|
|
1210
|
+
export const WebrpcHeader = "Webrpc"
|
|
1211
|
+
|
|
1212
|
+
export const WebrpcHeaderValue = "webrpc@v0.31.3;gen-typescript@v0.23.1;trails-api@v1-26.1.15-71ef491"
|
|
1213
|
+
|
|
1214
|
+
type WebrpcGenVersions = {
|
|
1215
|
+
WebrpcGenVersion: string;
|
|
1216
|
+
codeGenName: string;
|
|
1217
|
+
codeGenVersion: string;
|
|
1218
|
+
schemaName: string;
|
|
1219
|
+
schemaVersion: string;
|
|
1220
|
+
};
|
|
1221
|
+
|
|
1222
|
+
export function VersionFromHeader(headers: Headers): WebrpcGenVersions {
|
|
1223
|
+
const headerValue = headers.get(WebrpcHeader)
|
|
1224
|
+
if (!headerValue) {
|
|
1225
|
+
return {
|
|
1226
|
+
WebrpcGenVersion: "",
|
|
1227
|
+
codeGenName: "",
|
|
1228
|
+
codeGenVersion: "",
|
|
1229
|
+
schemaName: "",
|
|
1230
|
+
schemaVersion: "",
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
return parseWebrpcGenVersions(headerValue)
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
function parseWebrpcGenVersions(header: string): WebrpcGenVersions {
|
|
1238
|
+
const versions = header.split(";")
|
|
1239
|
+
if (versions.length < 3) {
|
|
1240
|
+
return {
|
|
1241
|
+
WebrpcGenVersion: "",
|
|
1242
|
+
codeGenName: "",
|
|
1243
|
+
codeGenVersion: "",
|
|
1244
|
+
schemaName: "",
|
|
1245
|
+
schemaVersion: "",
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
const [_, WebrpcGenVersion] = versions[0]!.split("@")
|
|
1250
|
+
const [codeGenName, codeGenVersion] = versions[1]!.split("@")
|
|
1251
|
+
const [schemaName, schemaVersion] = versions[2]!.split("@")
|
|
1252
|
+
|
|
1253
|
+
return {
|
|
1254
|
+
WebrpcGenVersion: WebrpcGenVersion ?? "",
|
|
1255
|
+
codeGenName: codeGenName ?? "",
|
|
1256
|
+
codeGenVersion: codeGenVersion ?? "",
|
|
1257
|
+
schemaName: schemaName ?? "",
|
|
1258
|
+
schemaVersion: schemaVersion ?? "",
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
|