@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.
@@ -0,0 +1,887 @@
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
+ // Webrpc description and code-gen version
8
+ export const WebrpcVersion = "v1";
9
+ // Schema version of your RIDL schema
10
+ export const WebrpcSchemaVersion = "v1-26.1.15-71ef491";
11
+ // Schema hash generated from your RIDL schema
12
+ export const WebrpcSchemaHash = "3a59ec464d243ab72337d497022e9388bbfed4e0";
13
+ //
14
+ // Schema types
15
+ //
16
+ export var CCTPTransferStatus;
17
+ (function (CCTPTransferStatus) {
18
+ CCTPTransferStatus["UNKNOWN"] = "UNKNOWN";
19
+ CCTPTransferStatus["ON_HOLD"] = "ON_HOLD";
20
+ CCTPTransferStatus["PENDING"] = "PENDING";
21
+ CCTPTransferStatus["FETCHING"] = "FETCHING";
22
+ CCTPTransferStatus["COMPLETE"] = "COMPLETE";
23
+ CCTPTransferStatus["FAILED"] = "FAILED";
24
+ })(CCTPTransferStatus || (CCTPTransferStatus = {}));
25
+ export var RelayTransferStatus;
26
+ (function (RelayTransferStatus) {
27
+ RelayTransferStatus["UNKNOWN"] = "UNKNOWN";
28
+ RelayTransferStatus["ON_HOLD"] = "ON_HOLD";
29
+ RelayTransferStatus["PENDING"] = "PENDING";
30
+ RelayTransferStatus["FETCHING"] = "FETCHING";
31
+ RelayTransferStatus["COMPLETE"] = "COMPLETE";
32
+ RelayTransferStatus["REFUNDED"] = "REFUNDED";
33
+ RelayTransferStatus["FAILED"] = "FAILED";
34
+ })(RelayTransferStatus || (RelayTransferStatus = {}));
35
+ //
36
+ // Client
37
+ //
38
+ export class TrailsOnramp {
39
+ hostname;
40
+ fetch;
41
+ path = '/rpc/TrailsOnramp/';
42
+ constructor(hostname, fetch) {
43
+ this.hostname = hostname.replace(/\/*$/, '');
44
+ this.fetch = (input, init) => fetch(input, init);
45
+ }
46
+ url(name) {
47
+ return this.hostname + this.path + name;
48
+ }
49
+ queryKey = {
50
+ getMeldCountryDefaults: (req) => ['TrailsOnramp', 'getMeldCountryDefaults', req],
51
+ getMeldFiatCurrencies: (req) => ['TrailsOnramp', 'getMeldFiatCurrencies', req],
52
+ getMeldPaymentMethods: (req) => ['TrailsOnramp', 'getMeldPaymentMethods', req],
53
+ getMeldCryptoCurrencies: (req) => ['TrailsOnramp', 'getMeldCryptoCurrencies', req],
54
+ getMeldPurchaseLimits: (req) => ['TrailsOnramp', 'getMeldPurchaseLimits', req],
55
+ getMeldQuote: (req) => ['TrailsOnramp', 'getMeldQuote', req],
56
+ createMeldWidgetSession: (req) => ['TrailsOnramp', 'createMeldWidgetSession', req],
57
+ getMeldTransaction: (req) => ['TrailsOnramp', 'getMeldTransaction', req],
58
+ searchMeldTransactions: (req) => ['TrailsOnramp', 'searchMeldTransactions', req],
59
+ createMeldBankLinkingConnection: (req) => ['TrailsOnramp', 'createMeldBankLinkingConnection', req],
60
+ };
61
+ getMeldCountryDefaults = (req, headers, signal) => {
62
+ return this.fetch(this.url('GetMeldCountryDefaults'), createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
63
+ return buildResponse(res).then(_data => {
64
+ return JsonDecode(_data, 'GetMeldCountryDefaultsResponse');
65
+ });
66
+ }, (error) => {
67
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
68
+ });
69
+ };
70
+ getMeldFiatCurrencies = (req, headers, signal) => {
71
+ return this.fetch(this.url('GetMeldFiatCurrencies'), createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
72
+ return buildResponse(res).then(_data => {
73
+ return JsonDecode(_data, 'GetMeldFiatCurrenciesResponse');
74
+ });
75
+ }, (error) => {
76
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
77
+ });
78
+ };
79
+ getMeldPaymentMethods = (req, headers, signal) => {
80
+ return this.fetch(this.url('GetMeldPaymentMethods'), createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
81
+ return buildResponse(res).then(_data => {
82
+ return JsonDecode(_data, 'GetMeldPaymentMethodsResponse');
83
+ });
84
+ }, (error) => {
85
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
86
+ });
87
+ };
88
+ getMeldCryptoCurrencies = (req, headers, signal) => {
89
+ return this.fetch(this.url('GetMeldCryptoCurrencies'), createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
90
+ return buildResponse(res).then(_data => {
91
+ return JsonDecode(_data, 'GetMeldCryptoCurrenciesResponse');
92
+ });
93
+ }, (error) => {
94
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
95
+ });
96
+ };
97
+ getMeldPurchaseLimits = (req, headers, signal) => {
98
+ return this.fetch(this.url('GetMeldPurchaseLimits'), createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
99
+ return buildResponse(res).then(_data => {
100
+ return JsonDecode(_data, 'GetMeldPurchaseLimitsResponse');
101
+ });
102
+ }, (error) => {
103
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
104
+ });
105
+ };
106
+ getMeldQuote = (req, headers, signal) => {
107
+ return this.fetch(this.url('GetMeldQuote'), createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
108
+ return buildResponse(res).then(_data => {
109
+ return JsonDecode(_data, 'GetMeldQuoteResponse');
110
+ });
111
+ }, (error) => {
112
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
113
+ });
114
+ };
115
+ createMeldWidgetSession = (req, headers, signal) => {
116
+ return this.fetch(this.url('CreateMeldWidgetSession'), createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
117
+ return buildResponse(res).then(_data => {
118
+ return JsonDecode(_data, 'CreateMeldWidgetSessionResponse');
119
+ });
120
+ }, (error) => {
121
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
122
+ });
123
+ };
124
+ getMeldTransaction = (req, headers, signal) => {
125
+ return this.fetch(this.url('GetMeldTransaction'), createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
126
+ return buildResponse(res).then(_data => {
127
+ return JsonDecode(_data, 'GetMeldTransactionResponse');
128
+ });
129
+ }, (error) => {
130
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
131
+ });
132
+ };
133
+ searchMeldTransactions = (req, headers, signal) => {
134
+ return this.fetch(this.url('SearchMeldTransactions'), createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
135
+ return buildResponse(res).then(_data => {
136
+ return JsonDecode(_data, 'SearchMeldTransactionsResponse');
137
+ });
138
+ }, (error) => {
139
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
140
+ });
141
+ };
142
+ createMeldBankLinkingConnection = (req, headers, signal) => {
143
+ return this.fetch(this.url('CreateMeldBankLinkingConnection'), createHttpRequest(JsonEncode(req), headers, signal)).then((res) => {
144
+ return buildResponse(res).then(_data => {
145
+ return JsonDecode(_data, 'CreateMeldBankLinkingConnectionResponse');
146
+ });
147
+ }, (error) => {
148
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
149
+ });
150
+ };
151
+ }
152
+ const createHttpRequest = (body = '{}', headers = {}, signal = null) => {
153
+ const reqHeaders = { ...headers, 'Content-Type': 'application/json', [WebrpcHeader]: WebrpcHeaderValue };
154
+ return { method: 'POST', headers: reqHeaders, body, signal };
155
+ };
156
+ const buildResponse = (res) => {
157
+ return res.text().then(text => {
158
+ let data;
159
+ try {
160
+ data = JSON.parse(text);
161
+ }
162
+ catch (error) {
163
+ throw WebrpcBadResponseError.new({
164
+ status: res.status,
165
+ cause: `JSON.parse(): ${error instanceof Error ? error.message : String(error)}: response text: ${text}`
166
+ });
167
+ }
168
+ if (!res.ok) {
169
+ const code = (typeof data.code === 'number') ? data.code : 0;
170
+ throw (webrpcErrorByCode[code] || WebrpcError).new(data);
171
+ }
172
+ return data;
173
+ });
174
+ };
175
+ export const JsonEncode = (obj) => {
176
+ return JSON.stringify(obj);
177
+ };
178
+ export const JsonDecode = (data, _typ = '') => {
179
+ let parsed = data;
180
+ if (typeof data === 'string') {
181
+ try {
182
+ parsed = JSON.parse(data);
183
+ }
184
+ catch (err) {
185
+ throw WebrpcBadResponseError.new({ cause: `JsonDecode: JSON.parse failed: ${err.message}` });
186
+ }
187
+ }
188
+ return parsed;
189
+ };
190
+ export class WebrpcError extends Error {
191
+ code;
192
+ status;
193
+ constructor(error = {}) {
194
+ super(error.message);
195
+ this.name = error.name || 'WebrpcEndpointError';
196
+ this.code = typeof error.code === 'number' ? error.code : 0;
197
+ this.message = error.message || `endpoint error`;
198
+ this.status = typeof error.status === 'number' ? error.status : 400;
199
+ if (error.cause !== undefined)
200
+ this.cause = error.cause;
201
+ Object.setPrototypeOf(this, WebrpcError.prototype);
202
+ }
203
+ static new(payload) {
204
+ return new this({ message: payload.message, code: payload.code, status: payload.status, cause: payload.cause });
205
+ }
206
+ }
207
+ export class WebrpcEndpointError extends WebrpcError {
208
+ constructor(error = {}) {
209
+ super(error);
210
+ this.name = error.name || 'WebrpcEndpoint';
211
+ this.code = typeof error.code === 'number' ? error.code : 0;
212
+ this.message = error.message || `endpoint error`;
213
+ this.status = typeof error.status === 'number' ? error.status : 400;
214
+ if (error.cause !== undefined)
215
+ this.cause = error.cause;
216
+ Object.setPrototypeOf(this, WebrpcEndpointError.prototype);
217
+ }
218
+ }
219
+ export class WebrpcRequestFailedError extends WebrpcError {
220
+ constructor(error = {}) {
221
+ super(error);
222
+ this.name = error.name || 'WebrpcRequestFailed';
223
+ this.code = typeof error.code === 'number' ? error.code : -1;
224
+ this.message = error.message || `request failed`;
225
+ this.status = typeof error.status === 'number' ? error.status : 400;
226
+ if (error.cause !== undefined)
227
+ this.cause = error.cause;
228
+ Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype);
229
+ }
230
+ }
231
+ export class WebrpcBadRouteError extends WebrpcError {
232
+ constructor(error = {}) {
233
+ super(error);
234
+ this.name = error.name || 'WebrpcBadRoute';
235
+ this.code = typeof error.code === 'number' ? error.code : -2;
236
+ this.message = error.message || `bad route`;
237
+ this.status = typeof error.status === 'number' ? error.status : 404;
238
+ if (error.cause !== undefined)
239
+ this.cause = error.cause;
240
+ Object.setPrototypeOf(this, WebrpcBadRouteError.prototype);
241
+ }
242
+ }
243
+ export class WebrpcBadMethodError extends WebrpcError {
244
+ constructor(error = {}) {
245
+ super(error);
246
+ this.name = error.name || 'WebrpcBadMethod';
247
+ this.code = typeof error.code === 'number' ? error.code : -3;
248
+ this.message = error.message || `bad method`;
249
+ this.status = typeof error.status === 'number' ? error.status : 405;
250
+ if (error.cause !== undefined)
251
+ this.cause = error.cause;
252
+ Object.setPrototypeOf(this, WebrpcBadMethodError.prototype);
253
+ }
254
+ }
255
+ export class WebrpcBadRequestError extends WebrpcError {
256
+ constructor(error = {}) {
257
+ super(error);
258
+ this.name = error.name || 'WebrpcBadRequest';
259
+ this.code = typeof error.code === 'number' ? error.code : -4;
260
+ this.message = error.message || `bad request`;
261
+ this.status = typeof error.status === 'number' ? error.status : 400;
262
+ if (error.cause !== undefined)
263
+ this.cause = error.cause;
264
+ Object.setPrototypeOf(this, WebrpcBadRequestError.prototype);
265
+ }
266
+ }
267
+ export class WebrpcBadResponseError extends WebrpcError {
268
+ constructor(error = {}) {
269
+ super(error);
270
+ this.name = error.name || 'WebrpcBadResponse';
271
+ this.code = typeof error.code === 'number' ? error.code : -5;
272
+ this.message = error.message || `bad response`;
273
+ this.status = typeof error.status === 'number' ? error.status : 500;
274
+ if (error.cause !== undefined)
275
+ this.cause = error.cause;
276
+ Object.setPrototypeOf(this, WebrpcBadResponseError.prototype);
277
+ }
278
+ }
279
+ export class WebrpcServerPanicError extends WebrpcError {
280
+ constructor(error = {}) {
281
+ super(error);
282
+ this.name = error.name || 'WebrpcServerPanic';
283
+ this.code = typeof error.code === 'number' ? error.code : -6;
284
+ this.message = error.message || `server panic`;
285
+ this.status = typeof error.status === 'number' ? error.status : 500;
286
+ if (error.cause !== undefined)
287
+ this.cause = error.cause;
288
+ Object.setPrototypeOf(this, WebrpcServerPanicError.prototype);
289
+ }
290
+ }
291
+ export class WebrpcInternalErrorError extends WebrpcError {
292
+ constructor(error = {}) {
293
+ super(error);
294
+ this.name = error.name || 'WebrpcInternalError';
295
+ this.code = typeof error.code === 'number' ? error.code : -7;
296
+ this.message = error.message || `internal error`;
297
+ this.status = typeof error.status === 'number' ? error.status : 500;
298
+ if (error.cause !== undefined)
299
+ this.cause = error.cause;
300
+ Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype);
301
+ }
302
+ }
303
+ export class WebrpcClientAbortedError extends WebrpcError {
304
+ constructor(error = {}) {
305
+ super(error);
306
+ this.name = error.name || 'WebrpcClientAborted';
307
+ this.code = typeof error.code === 'number' ? error.code : -8;
308
+ this.message = error.message || `request aborted by client`;
309
+ this.status = typeof error.status === 'number' ? error.status : 400;
310
+ if (error.cause !== undefined)
311
+ this.cause = error.cause;
312
+ Object.setPrototypeOf(this, WebrpcClientAbortedError.prototype);
313
+ }
314
+ }
315
+ export class WebrpcStreamLostError extends WebrpcError {
316
+ constructor(error = {}) {
317
+ super(error);
318
+ this.name = error.name || 'WebrpcStreamLost';
319
+ this.code = typeof error.code === 'number' ? error.code : -9;
320
+ this.message = error.message || `stream lost`;
321
+ this.status = typeof error.status === 'number' ? error.status : 400;
322
+ if (error.cause !== undefined)
323
+ this.cause = error.cause;
324
+ Object.setPrototypeOf(this, WebrpcStreamLostError.prototype);
325
+ }
326
+ }
327
+ export class WebrpcStreamFinishedError extends WebrpcError {
328
+ constructor(error = {}) {
329
+ super(error);
330
+ this.name = error.name || 'WebrpcStreamFinished';
331
+ this.code = typeof error.code === 'number' ? error.code : -10;
332
+ this.message = error.message || `stream finished`;
333
+ this.status = typeof error.status === 'number' ? error.status : 200;
334
+ if (error.cause !== undefined)
335
+ this.cause = error.cause;
336
+ Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype);
337
+ }
338
+ }
339
+ //
340
+ // Schema errors
341
+ //
342
+ export class UnauthorizedError extends WebrpcError {
343
+ constructor(error = {}) {
344
+ super(error);
345
+ this.name = error.name || 'Unauthorized';
346
+ this.code = typeof error.code === 'number' ? error.code : 1000;
347
+ this.message = error.message || `Unauthorized access`;
348
+ this.status = typeof error.status === 'number' ? error.status : 401;
349
+ if (error.cause !== undefined)
350
+ this.cause = error.cause;
351
+ Object.setPrototypeOf(this, UnauthorizedError.prototype);
352
+ }
353
+ }
354
+ export class PermissionDeniedError extends WebrpcError {
355
+ constructor(error = {}) {
356
+ super(error);
357
+ this.name = error.name || 'PermissionDenied';
358
+ this.code = typeof error.code === 'number' ? error.code : 1001;
359
+ this.message = error.message || `Permission denied`;
360
+ this.status = typeof error.status === 'number' ? error.status : 403;
361
+ if (error.cause !== undefined)
362
+ this.cause = error.cause;
363
+ Object.setPrototypeOf(this, PermissionDeniedError.prototype);
364
+ }
365
+ }
366
+ export class SessionExpiredError extends WebrpcError {
367
+ constructor(error = {}) {
368
+ super(error);
369
+ this.name = error.name || 'SessionExpired';
370
+ this.code = typeof error.code === 'number' ? error.code : 1002;
371
+ this.message = error.message || `Session expired`;
372
+ this.status = typeof error.status === 'number' ? error.status : 403;
373
+ if (error.cause !== undefined)
374
+ this.cause = error.cause;
375
+ Object.setPrototypeOf(this, SessionExpiredError.prototype);
376
+ }
377
+ }
378
+ export class MethodNotFoundError extends WebrpcError {
379
+ constructor(error = {}) {
380
+ super(error);
381
+ this.name = error.name || 'MethodNotFound';
382
+ this.code = typeof error.code === 'number' ? error.code : 1003;
383
+ this.message = error.message || `Method not found`;
384
+ this.status = typeof error.status === 'number' ? error.status : 404;
385
+ if (error.cause !== undefined)
386
+ this.cause = error.cause;
387
+ Object.setPrototypeOf(this, MethodNotFoundError.prototype);
388
+ }
389
+ }
390
+ export class RequestConflictError extends WebrpcError {
391
+ constructor(error = {}) {
392
+ super(error);
393
+ this.name = error.name || 'RequestConflict';
394
+ this.code = typeof error.code === 'number' ? error.code : 1004;
395
+ this.message = error.message || `Conflict with target resource`;
396
+ this.status = typeof error.status === 'number' ? error.status : 409;
397
+ if (error.cause !== undefined)
398
+ this.cause = error.cause;
399
+ Object.setPrototypeOf(this, RequestConflictError.prototype);
400
+ }
401
+ }
402
+ export class AbortedError extends WebrpcError {
403
+ constructor(error = {}) {
404
+ super(error);
405
+ this.name = error.name || 'Aborted';
406
+ this.code = typeof error.code === 'number' ? error.code : 1005;
407
+ this.message = error.message || `Request aborted`;
408
+ this.status = typeof error.status === 'number' ? error.status : 400;
409
+ if (error.cause !== undefined)
410
+ this.cause = error.cause;
411
+ Object.setPrototypeOf(this, AbortedError.prototype);
412
+ }
413
+ }
414
+ export class GeoblockedError extends WebrpcError {
415
+ constructor(error = {}) {
416
+ super(error);
417
+ this.name = error.name || 'Geoblocked';
418
+ this.code = typeof error.code === 'number' ? error.code : 1006;
419
+ this.message = error.message || `Geoblocked region`;
420
+ this.status = typeof error.status === 'number' ? error.status : 451;
421
+ if (error.cause !== undefined)
422
+ this.cause = error.cause;
423
+ Object.setPrototypeOf(this, GeoblockedError.prototype);
424
+ }
425
+ }
426
+ export class RateLimitedError extends WebrpcError {
427
+ constructor(error = {}) {
428
+ super(error);
429
+ this.name = error.name || 'RateLimited';
430
+ this.code = typeof error.code === 'number' ? error.code : 1007;
431
+ this.message = error.message || `Rate-limited. Please slow down.`;
432
+ this.status = typeof error.status === 'number' ? error.status : 429;
433
+ if (error.cause !== undefined)
434
+ this.cause = error.cause;
435
+ Object.setPrototypeOf(this, RateLimitedError.prototype);
436
+ }
437
+ }
438
+ export class ProjectNotFoundError extends WebrpcError {
439
+ constructor(error = {}) {
440
+ super(error);
441
+ this.name = error.name || 'ProjectNotFound';
442
+ this.code = typeof error.code === 'number' ? error.code : 1008;
443
+ this.message = error.message || `Project not found`;
444
+ this.status = typeof error.status === 'number' ? error.status : 401;
445
+ if (error.cause !== undefined)
446
+ this.cause = error.cause;
447
+ Object.setPrototypeOf(this, ProjectNotFoundError.prototype);
448
+ }
449
+ }
450
+ export class AccessKeyNotFoundError extends WebrpcError {
451
+ constructor(error = {}) {
452
+ super(error);
453
+ this.name = error.name || 'AccessKeyNotFound';
454
+ this.code = typeof error.code === 'number' ? error.code : 1101;
455
+ this.message = error.message || `Access key not found`;
456
+ this.status = typeof error.status === 'number' ? error.status : 401;
457
+ if (error.cause !== undefined)
458
+ this.cause = error.cause;
459
+ Object.setPrototypeOf(this, AccessKeyNotFoundError.prototype);
460
+ }
461
+ }
462
+ export class AccessKeyMismatchError extends WebrpcError {
463
+ constructor(error = {}) {
464
+ super(error);
465
+ this.name = error.name || 'AccessKeyMismatch';
466
+ this.code = typeof error.code === 'number' ? error.code : 1102;
467
+ this.message = error.message || `Access key mismatch`;
468
+ this.status = typeof error.status === 'number' ? error.status : 409;
469
+ if (error.cause !== undefined)
470
+ this.cause = error.cause;
471
+ Object.setPrototypeOf(this, AccessKeyMismatchError.prototype);
472
+ }
473
+ }
474
+ export class InvalidOriginError extends WebrpcError {
475
+ constructor(error = {}) {
476
+ super(error);
477
+ this.name = error.name || 'InvalidOrigin';
478
+ this.code = typeof error.code === 'number' ? error.code : 1103;
479
+ this.message = error.message || `Invalid origin for Access Key`;
480
+ this.status = typeof error.status === 'number' ? error.status : 403;
481
+ if (error.cause !== undefined)
482
+ this.cause = error.cause;
483
+ Object.setPrototypeOf(this, InvalidOriginError.prototype);
484
+ }
485
+ }
486
+ export class InvalidServiceError extends WebrpcError {
487
+ constructor(error = {}) {
488
+ super(error);
489
+ this.name = error.name || 'InvalidService';
490
+ this.code = typeof error.code === 'number' ? error.code : 1104;
491
+ this.message = error.message || `Service not enabled for Access key`;
492
+ this.status = typeof error.status === 'number' ? error.status : 403;
493
+ if (error.cause !== undefined)
494
+ this.cause = error.cause;
495
+ Object.setPrototypeOf(this, InvalidServiceError.prototype);
496
+ }
497
+ }
498
+ export class UnauthorizedUserError extends WebrpcError {
499
+ constructor(error = {}) {
500
+ super(error);
501
+ this.name = error.name || 'UnauthorizedUser';
502
+ this.code = typeof error.code === 'number' ? error.code : 1105;
503
+ this.message = error.message || `Unauthorized user`;
504
+ this.status = typeof error.status === 'number' ? error.status : 403;
505
+ if (error.cause !== undefined)
506
+ this.cause = error.cause;
507
+ Object.setPrototypeOf(this, UnauthorizedUserError.prototype);
508
+ }
509
+ }
510
+ export class QuotaExceededError extends WebrpcError {
511
+ constructor(error = {}) {
512
+ super(error);
513
+ this.name = error.name || 'QuotaExceeded';
514
+ this.code = typeof error.code === 'number' ? error.code : 1200;
515
+ this.message = error.message || `Quota request exceeded`;
516
+ this.status = typeof error.status === 'number' ? error.status : 429;
517
+ if (error.cause !== undefined)
518
+ this.cause = error.cause;
519
+ Object.setPrototypeOf(this, QuotaExceededError.prototype);
520
+ }
521
+ }
522
+ export class QuotaRateLimitError extends WebrpcError {
523
+ constructor(error = {}) {
524
+ super(error);
525
+ this.name = error.name || 'QuotaRateLimit';
526
+ this.code = typeof error.code === 'number' ? error.code : 1201;
527
+ this.message = error.message || `Quota rate limit exceeded`;
528
+ this.status = typeof error.status === 'number' ? error.status : 429;
529
+ if (error.cause !== undefined)
530
+ this.cause = error.cause;
531
+ Object.setPrototypeOf(this, QuotaRateLimitError.prototype);
532
+ }
533
+ }
534
+ export class NoDefaultKeyError extends WebrpcError {
535
+ constructor(error = {}) {
536
+ super(error);
537
+ this.name = error.name || 'NoDefaultKey';
538
+ this.code = typeof error.code === 'number' ? error.code : 1300;
539
+ this.message = error.message || `No default access key found`;
540
+ this.status = typeof error.status === 'number' ? error.status : 403;
541
+ if (error.cause !== undefined)
542
+ this.cause = error.cause;
543
+ Object.setPrototypeOf(this, NoDefaultKeyError.prototype);
544
+ }
545
+ }
546
+ export class MaxAccessKeysError extends WebrpcError {
547
+ constructor(error = {}) {
548
+ super(error);
549
+ this.name = error.name || 'MaxAccessKeys';
550
+ this.code = typeof error.code === 'number' ? error.code : 1301;
551
+ this.message = error.message || `Access keys limit reached`;
552
+ this.status = typeof error.status === 'number' ? error.status : 403;
553
+ if (error.cause !== undefined)
554
+ this.cause = error.cause;
555
+ Object.setPrototypeOf(this, MaxAccessKeysError.prototype);
556
+ }
557
+ }
558
+ export class AtLeastOneKeyError extends WebrpcError {
559
+ constructor(error = {}) {
560
+ super(error);
561
+ this.name = error.name || 'AtLeastOneKey';
562
+ this.code = typeof error.code === 'number' ? error.code : 1302;
563
+ this.message = error.message || `You need at least one Access Key`;
564
+ this.status = typeof error.status === 'number' ? error.status : 403;
565
+ if (error.cause !== undefined)
566
+ this.cause = error.cause;
567
+ Object.setPrototypeOf(this, AtLeastOneKeyError.prototype);
568
+ }
569
+ }
570
+ export class TimeoutError extends WebrpcError {
571
+ constructor(error = {}) {
572
+ super(error);
573
+ this.name = error.name || 'Timeout';
574
+ this.code = typeof error.code === 'number' ? error.code : 1900;
575
+ this.message = error.message || `Request timed out`;
576
+ this.status = typeof error.status === 'number' ? error.status : 408;
577
+ if (error.cause !== undefined)
578
+ this.cause = error.cause;
579
+ Object.setPrototypeOf(this, TimeoutError.prototype);
580
+ }
581
+ }
582
+ export class InvalidArgumentError extends WebrpcError {
583
+ constructor(error = {}) {
584
+ super(error);
585
+ this.name = error.name || 'InvalidArgument';
586
+ this.code = typeof error.code === 'number' ? error.code : 2000;
587
+ this.message = error.message || `Invalid argument`;
588
+ this.status = typeof error.status === 'number' ? error.status : 400;
589
+ if (error.cause !== undefined)
590
+ this.cause = error.cause;
591
+ Object.setPrototypeOf(this, InvalidArgumentError.prototype);
592
+ }
593
+ }
594
+ export class UnexpectedError extends WebrpcError {
595
+ constructor(error = {}) {
596
+ super(error);
597
+ this.name = error.name || 'Unexpected';
598
+ this.code = typeof error.code === 'number' ? error.code : 2001;
599
+ this.message = error.message || `Unexpected server error`;
600
+ this.status = typeof error.status === 'number' ? error.status : 500;
601
+ if (error.cause !== undefined)
602
+ this.cause = error.cause;
603
+ Object.setPrototypeOf(this, UnexpectedError.prototype);
604
+ }
605
+ }
606
+ export class UnavailableError extends WebrpcError {
607
+ constructor(error = {}) {
608
+ super(error);
609
+ this.name = error.name || 'Unavailable';
610
+ this.code = typeof error.code === 'number' ? error.code : 2002;
611
+ this.message = error.message || `Unavailable resource`;
612
+ this.status = typeof error.status === 'number' ? error.status : 400;
613
+ if (error.cause !== undefined)
614
+ this.cause = error.cause;
615
+ Object.setPrototypeOf(this, UnavailableError.prototype);
616
+ }
617
+ }
618
+ export class QueryFailedError extends WebrpcError {
619
+ constructor(error = {}) {
620
+ super(error);
621
+ this.name = error.name || 'QueryFailed';
622
+ this.code = typeof error.code === 'number' ? error.code : 2003;
623
+ this.message = error.message || `Query failed`;
624
+ this.status = typeof error.status === 'number' ? error.status : 400;
625
+ if (error.cause !== undefined)
626
+ this.cause = error.cause;
627
+ Object.setPrototypeOf(this, QueryFailedError.prototype);
628
+ }
629
+ }
630
+ export class IntentStatusError extends WebrpcError {
631
+ constructor(error = {}) {
632
+ super(error);
633
+ this.name = error.name || 'IntentStatus';
634
+ this.code = typeof error.code === 'number' ? error.code : 2004;
635
+ this.message = error.message || `Invalid intent status`;
636
+ this.status = typeof error.status === 'number' ? error.status : 422;
637
+ if (error.cause !== undefined)
638
+ this.cause = error.cause;
639
+ Object.setPrototypeOf(this, IntentStatusError.prototype);
640
+ }
641
+ }
642
+ export class NotFoundError extends WebrpcError {
643
+ constructor(error = {}) {
644
+ super(error);
645
+ this.name = error.name || 'NotFound';
646
+ this.code = typeof error.code === 'number' ? error.code : 8000;
647
+ this.message = error.message || `Resource not found`;
648
+ this.status = typeof error.status === 'number' ? error.status : 400;
649
+ if (error.cause !== undefined)
650
+ this.cause = error.cause;
651
+ Object.setPrototypeOf(this, NotFoundError.prototype);
652
+ }
653
+ }
654
+ export class UnsupportedNetworkError extends WebrpcError {
655
+ constructor(error = {}) {
656
+ super(error);
657
+ this.name = error.name || 'UnsupportedNetwork';
658
+ this.code = typeof error.code === 'number' ? error.code : 8008;
659
+ this.message = error.message || `Unsupported network`;
660
+ this.status = typeof error.status === 'number' ? error.status : 422;
661
+ if (error.cause !== undefined)
662
+ this.cause = error.cause;
663
+ Object.setPrototypeOf(this, UnsupportedNetworkError.prototype);
664
+ }
665
+ }
666
+ export class ClientOutdatedError extends WebrpcError {
667
+ constructor(error = {}) {
668
+ super(error);
669
+ this.name = error.name || 'ClientOutdated';
670
+ this.code = typeof error.code === 'number' ? error.code : 8009;
671
+ this.message = error.message || `Client is outdated`;
672
+ this.status = typeof error.status === 'number' ? error.status : 422;
673
+ if (error.cause !== undefined)
674
+ this.cause = error.cause;
675
+ Object.setPrototypeOf(this, ClientOutdatedError.prototype);
676
+ }
677
+ }
678
+ export class IntentsSkippedError extends WebrpcError {
679
+ constructor(error = {}) {
680
+ super(error);
681
+ this.name = error.name || 'IntentsSkipped';
682
+ this.code = typeof error.code === 'number' ? error.code : 7000;
683
+ this.message = error.message || `Intents skipped as client is attempting a transaction that does not require intents`;
684
+ this.status = typeof error.status === 'number' ? error.status : 400;
685
+ if (error.cause !== undefined)
686
+ this.cause = error.cause;
687
+ Object.setPrototypeOf(this, IntentsSkippedError.prototype);
688
+ }
689
+ }
690
+ export class QuoteExpiredError extends WebrpcError {
691
+ constructor(error = {}) {
692
+ super(error);
693
+ this.name = error.name || 'QuoteExpired';
694
+ this.code = typeof error.code === 'number' ? error.code : 7001;
695
+ this.message = error.message || `Intent quote has expired. Please try again.`;
696
+ this.status = typeof error.status === 'number' ? error.status : 400;
697
+ if (error.cause !== undefined)
698
+ this.cause = error.cause;
699
+ Object.setPrototypeOf(this, QuoteExpiredError.prototype);
700
+ }
701
+ }
702
+ export class IntentsDisabledError extends WebrpcError {
703
+ constructor(error = {}) {
704
+ super(error);
705
+ this.name = error.name || 'IntentsDisabled';
706
+ this.code = typeof error.code === 'number' ? error.code : 9000;
707
+ this.message = error.message || `Intents service is currently unavailable`;
708
+ this.status = typeof error.status === 'number' ? error.status : 400;
709
+ if (error.cause !== undefined)
710
+ this.cause = error.cause;
711
+ Object.setPrototypeOf(this, IntentsDisabledError.prototype);
712
+ }
713
+ }
714
+ export var errors;
715
+ (function (errors) {
716
+ errors["WebrpcEndpoint"] = "WebrpcEndpoint";
717
+ errors["WebrpcRequestFailed"] = "WebrpcRequestFailed";
718
+ errors["WebrpcBadRoute"] = "WebrpcBadRoute";
719
+ errors["WebrpcBadMethod"] = "WebrpcBadMethod";
720
+ errors["WebrpcBadRequest"] = "WebrpcBadRequest";
721
+ errors["WebrpcBadResponse"] = "WebrpcBadResponse";
722
+ errors["WebrpcServerPanic"] = "WebrpcServerPanic";
723
+ errors["WebrpcInternalError"] = "WebrpcInternalError";
724
+ errors["WebrpcClientAborted"] = "WebrpcClientAborted";
725
+ errors["WebrpcStreamLost"] = "WebrpcStreamLost";
726
+ errors["WebrpcStreamFinished"] = "WebrpcStreamFinished";
727
+ errors["Unauthorized"] = "Unauthorized";
728
+ errors["PermissionDenied"] = "PermissionDenied";
729
+ errors["SessionExpired"] = "SessionExpired";
730
+ errors["MethodNotFound"] = "MethodNotFound";
731
+ errors["RequestConflict"] = "RequestConflict";
732
+ errors["Aborted"] = "Aborted";
733
+ errors["Geoblocked"] = "Geoblocked";
734
+ errors["RateLimited"] = "RateLimited";
735
+ errors["ProjectNotFound"] = "ProjectNotFound";
736
+ errors["AccessKeyNotFound"] = "AccessKeyNotFound";
737
+ errors["AccessKeyMismatch"] = "AccessKeyMismatch";
738
+ errors["InvalidOrigin"] = "InvalidOrigin";
739
+ errors["InvalidService"] = "InvalidService";
740
+ errors["UnauthorizedUser"] = "UnauthorizedUser";
741
+ errors["QuotaExceeded"] = "QuotaExceeded";
742
+ errors["QuotaRateLimit"] = "QuotaRateLimit";
743
+ errors["NoDefaultKey"] = "NoDefaultKey";
744
+ errors["MaxAccessKeys"] = "MaxAccessKeys";
745
+ errors["AtLeastOneKey"] = "AtLeastOneKey";
746
+ errors["Timeout"] = "Timeout";
747
+ errors["InvalidArgument"] = "InvalidArgument";
748
+ errors["Unexpected"] = "Unexpected";
749
+ errors["Unavailable"] = "Unavailable";
750
+ errors["QueryFailed"] = "QueryFailed";
751
+ errors["IntentStatus"] = "IntentStatus";
752
+ errors["NotFound"] = "NotFound";
753
+ errors["UnsupportedNetwork"] = "UnsupportedNetwork";
754
+ errors["ClientOutdated"] = "ClientOutdated";
755
+ errors["IntentsSkipped"] = "IntentsSkipped";
756
+ errors["QuoteExpired"] = "QuoteExpired";
757
+ errors["IntentsDisabled"] = "IntentsDisabled";
758
+ })(errors || (errors = {}));
759
+ export var WebrpcErrorCodes;
760
+ (function (WebrpcErrorCodes) {
761
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcEndpoint"] = 0] = "WebrpcEndpoint";
762
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcRequestFailed"] = -1] = "WebrpcRequestFailed";
763
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadRoute"] = -2] = "WebrpcBadRoute";
764
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadMethod"] = -3] = "WebrpcBadMethod";
765
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadRequest"] = -4] = "WebrpcBadRequest";
766
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadResponse"] = -5] = "WebrpcBadResponse";
767
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcServerPanic"] = -6] = "WebrpcServerPanic";
768
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcInternalError"] = -7] = "WebrpcInternalError";
769
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcClientAborted"] = -8] = "WebrpcClientAborted";
770
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcStreamLost"] = -9] = "WebrpcStreamLost";
771
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcStreamFinished"] = -10] = "WebrpcStreamFinished";
772
+ WebrpcErrorCodes[WebrpcErrorCodes["Unauthorized"] = 1000] = "Unauthorized";
773
+ WebrpcErrorCodes[WebrpcErrorCodes["PermissionDenied"] = 1001] = "PermissionDenied";
774
+ WebrpcErrorCodes[WebrpcErrorCodes["SessionExpired"] = 1002] = "SessionExpired";
775
+ WebrpcErrorCodes[WebrpcErrorCodes["MethodNotFound"] = 1003] = "MethodNotFound";
776
+ WebrpcErrorCodes[WebrpcErrorCodes["RequestConflict"] = 1004] = "RequestConflict";
777
+ WebrpcErrorCodes[WebrpcErrorCodes["Aborted"] = 1005] = "Aborted";
778
+ WebrpcErrorCodes[WebrpcErrorCodes["Geoblocked"] = 1006] = "Geoblocked";
779
+ WebrpcErrorCodes[WebrpcErrorCodes["RateLimited"] = 1007] = "RateLimited";
780
+ WebrpcErrorCodes[WebrpcErrorCodes["ProjectNotFound"] = 1008] = "ProjectNotFound";
781
+ WebrpcErrorCodes[WebrpcErrorCodes["AccessKeyNotFound"] = 1101] = "AccessKeyNotFound";
782
+ WebrpcErrorCodes[WebrpcErrorCodes["AccessKeyMismatch"] = 1102] = "AccessKeyMismatch";
783
+ WebrpcErrorCodes[WebrpcErrorCodes["InvalidOrigin"] = 1103] = "InvalidOrigin";
784
+ WebrpcErrorCodes[WebrpcErrorCodes["InvalidService"] = 1104] = "InvalidService";
785
+ WebrpcErrorCodes[WebrpcErrorCodes["UnauthorizedUser"] = 1105] = "UnauthorizedUser";
786
+ WebrpcErrorCodes[WebrpcErrorCodes["QuotaExceeded"] = 1200] = "QuotaExceeded";
787
+ WebrpcErrorCodes[WebrpcErrorCodes["QuotaRateLimit"] = 1201] = "QuotaRateLimit";
788
+ WebrpcErrorCodes[WebrpcErrorCodes["NoDefaultKey"] = 1300] = "NoDefaultKey";
789
+ WebrpcErrorCodes[WebrpcErrorCodes["MaxAccessKeys"] = 1301] = "MaxAccessKeys";
790
+ WebrpcErrorCodes[WebrpcErrorCodes["AtLeastOneKey"] = 1302] = "AtLeastOneKey";
791
+ WebrpcErrorCodes[WebrpcErrorCodes["Timeout"] = 1900] = "Timeout";
792
+ WebrpcErrorCodes[WebrpcErrorCodes["InvalidArgument"] = 2000] = "InvalidArgument";
793
+ WebrpcErrorCodes[WebrpcErrorCodes["Unexpected"] = 2001] = "Unexpected";
794
+ WebrpcErrorCodes[WebrpcErrorCodes["Unavailable"] = 2002] = "Unavailable";
795
+ WebrpcErrorCodes[WebrpcErrorCodes["QueryFailed"] = 2003] = "QueryFailed";
796
+ WebrpcErrorCodes[WebrpcErrorCodes["IntentStatus"] = 2004] = "IntentStatus";
797
+ WebrpcErrorCodes[WebrpcErrorCodes["NotFound"] = 8000] = "NotFound";
798
+ WebrpcErrorCodes[WebrpcErrorCodes["UnsupportedNetwork"] = 8008] = "UnsupportedNetwork";
799
+ WebrpcErrorCodes[WebrpcErrorCodes["ClientOutdated"] = 8009] = "ClientOutdated";
800
+ WebrpcErrorCodes[WebrpcErrorCodes["IntentsSkipped"] = 7000] = "IntentsSkipped";
801
+ WebrpcErrorCodes[WebrpcErrorCodes["QuoteExpired"] = 7001] = "QuoteExpired";
802
+ WebrpcErrorCodes[WebrpcErrorCodes["IntentsDisabled"] = 9000] = "IntentsDisabled";
803
+ })(WebrpcErrorCodes || (WebrpcErrorCodes = {}));
804
+ export const webrpcErrorByCode = {
805
+ [0]: WebrpcEndpointError,
806
+ [-1]: WebrpcRequestFailedError,
807
+ [-2]: WebrpcBadRouteError,
808
+ [-3]: WebrpcBadMethodError,
809
+ [-4]: WebrpcBadRequestError,
810
+ [-5]: WebrpcBadResponseError,
811
+ [-6]: WebrpcServerPanicError,
812
+ [-7]: WebrpcInternalErrorError,
813
+ [-8]: WebrpcClientAbortedError,
814
+ [-9]: WebrpcStreamLostError,
815
+ [-10]: WebrpcStreamFinishedError,
816
+ [1000]: UnauthorizedError,
817
+ [1001]: PermissionDeniedError,
818
+ [1002]: SessionExpiredError,
819
+ [1003]: MethodNotFoundError,
820
+ [1004]: RequestConflictError,
821
+ [1005]: AbortedError,
822
+ [1006]: GeoblockedError,
823
+ [1007]: RateLimitedError,
824
+ [1008]: ProjectNotFoundError,
825
+ [1101]: AccessKeyNotFoundError,
826
+ [1102]: AccessKeyMismatchError,
827
+ [1103]: InvalidOriginError,
828
+ [1104]: InvalidServiceError,
829
+ [1105]: UnauthorizedUserError,
830
+ [1200]: QuotaExceededError,
831
+ [1201]: QuotaRateLimitError,
832
+ [1300]: NoDefaultKeyError,
833
+ [1301]: MaxAccessKeysError,
834
+ [1302]: AtLeastOneKeyError,
835
+ [1900]: TimeoutError,
836
+ [2000]: InvalidArgumentError,
837
+ [2001]: UnexpectedError,
838
+ [2002]: UnavailableError,
839
+ [2003]: QueryFailedError,
840
+ [2004]: IntentStatusError,
841
+ [8000]: NotFoundError,
842
+ [8008]: UnsupportedNetworkError,
843
+ [8009]: ClientOutdatedError,
844
+ [7000]: IntentsSkippedError,
845
+ [7001]: QuoteExpiredError,
846
+ [9000]: IntentsDisabledError,
847
+ };
848
+ //
849
+ // Webrpc
850
+ //
851
+ export const WebrpcHeader = "Webrpc";
852
+ export const WebrpcHeaderValue = "webrpc@v0.31.3;gen-typescript@v0.23.1;trails-api@v1-26.1.15-71ef491";
853
+ export function VersionFromHeader(headers) {
854
+ const headerValue = headers.get(WebrpcHeader);
855
+ if (!headerValue) {
856
+ return {
857
+ WebrpcGenVersion: "",
858
+ codeGenName: "",
859
+ codeGenVersion: "",
860
+ schemaName: "",
861
+ schemaVersion: "",
862
+ };
863
+ }
864
+ return parseWebrpcGenVersions(headerValue);
865
+ }
866
+ function parseWebrpcGenVersions(header) {
867
+ const versions = header.split(";");
868
+ if (versions.length < 3) {
869
+ return {
870
+ WebrpcGenVersion: "",
871
+ codeGenName: "",
872
+ codeGenVersion: "",
873
+ schemaName: "",
874
+ schemaVersion: "",
875
+ };
876
+ }
877
+ const [_, WebrpcGenVersion] = versions[0].split("@");
878
+ const [codeGenName, codeGenVersion] = versions[1].split("@");
879
+ const [schemaName, schemaVersion] = versions[2].split("@");
880
+ return {
881
+ WebrpcGenVersion: WebrpcGenVersion ?? "",
882
+ codeGenName: codeGenName ?? "",
883
+ codeGenVersion: codeGenVersion ?? "",
884
+ schemaName: schemaName ?? "",
885
+ schemaVersion: schemaVersion ?? "",
886
+ };
887
+ }