@fxhash/errors 0.0.13 → 0.0.14

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/dist/index.js CHANGED
@@ -1,541 +1,577 @@
1
- // src/errors/common.ts
2
- var UnexpectedRichErrorMessages = {
3
- dev: "Unexpected error",
4
- user: "Unexpected error"
5
- };
1
+ import { capitalize, failure, success } from "@fxhash/utils";
2
+
3
+ //#region src/errors/common.ts
4
+ /**
5
+ * Static error messages for "unexpected" errors. This payload is reused accross
6
+ * the stack for when error data is missing.
7
+ */
8
+ const UnexpectedRichErrorMessages = {
9
+ dev: "Unexpected error",
10
+ user: "Unexpected error"
11
+ };
12
+ /**
13
+ * An error which provides messages intended for devs & users. This class should
14
+ * be used accross our stack to provide meaningful error objects which can be
15
+ * used for both developers & users. When typed errors are returned, if they all
16
+ * are instances of `RichError`, then client applications can take some simple
17
+ * shortcuts to provide error feedback to both the developer and the user.
18
+ *
19
+ * @example
20
+ *
21
+ * ```ts
22
+ * export class SomeCustomError extends RichError {
23
+ * name = "SomeCustomError" as const // `code` will have same value
24
+ * messages = {
25
+ * dev: "some message for devs",
26
+ * user: "some message for users"
27
+ * }
28
+ * }
29
+ * ```
30
+ *
31
+ * ```ts
32
+ * const res = await something()
33
+ * if (res.isFailure()) {
34
+ * const err = res.error // if this is typed as `RichError`
35
+ * displayErrorOnUI(err.userMessage) // safely display user message
36
+ * }
37
+ * ```
38
+ */
6
39
  var RichError = class extends Error {
7
- constructor(messagesOverride) {
8
- super();
9
- this.messages = UnexpectedRichErrorMessages;
10
- if (messagesOverride) {
11
- this.messagesOverride = messagesOverride;
12
- }
13
- }
14
- _message(target) {
15
- return this.messagesOverride?.[target] || this.messages[target] || UnexpectedRichErrorMessages[target];
16
- }
17
- get message() {
18
- return this._message("dev");
19
- }
20
- get userMessage() {
21
- return this._message("user");
22
- }
23
- get code() {
24
- return this.name;
25
- }
26
- serialize() {
27
- return {
28
- code: this.code,
29
- messages: this.messagesOverride || this.messages
30
- };
31
- }
32
- static get code() {
33
- return this.name;
34
- }
35
- /**
36
- * Instanciates a Rich Error, trying to match the serialized error with the
37
- * provided Rich Error classes. The `code` property of the serialized payload
38
- * is matched against `RichError.name`
39
- *
40
- * @param serialized A rich error serialized
41
- * @param expected A list of Rich Error classes which are expected. If the
42
- * serialized error doesn't match any of these, UnexpectedRichError will be
43
- * returned.
44
- *
45
- * @returns An instance of Rich Error which type matches the `code` property,
46
- * or {@link UnexpectedRichError} if no match.
47
- */
48
- static parse(serialized, expected) {
49
- for (const RichErrorClass of expected) {
50
- const maybeError = new RichErrorClass(serialized.messages);
51
- if (maybeError.code === serialized.code) {
52
- return maybeError;
53
- }
54
- }
55
- return new UnexpectedRichError(serialized.messages);
56
- }
57
- /**
58
- * Returns a new instance of {@link UnexpectedRichError}
59
- * @param messagesOverride Optional overrides of default unexpected messages
60
- */
61
- static Unexpected(messagesOverride) {
62
- return new UnexpectedRichError(messagesOverride);
63
- }
64
- };
40
+ constructor(messagesOverride) {
41
+ super();
42
+ this.messages = UnexpectedRichErrorMessages;
43
+ if (messagesOverride) this.messagesOverride = messagesOverride;
44
+ }
45
+ _message(target) {
46
+ return this.messagesOverride?.[target] || this.messages[target] || UnexpectedRichErrorMessages[target];
47
+ }
48
+ get message() {
49
+ return this._message("dev");
50
+ }
51
+ get userMessage() {
52
+ return this._message("user");
53
+ }
54
+ get code() {
55
+ return this.name;
56
+ }
57
+ serialize() {
58
+ return {
59
+ code: this.code,
60
+ messages: this.messagesOverride || this.messages
61
+ };
62
+ }
63
+ static get code() {
64
+ return this.name;
65
+ }
66
+ /**
67
+ * Instanciates a Rich Error, trying to match the serialized error with the
68
+ * provided Rich Error classes. The `code` property of the serialized payload
69
+ * is matched against `RichError.name`
70
+ *
71
+ * @param serialized A rich error serialized
72
+ * @param expected A list of Rich Error classes which are expected. If the
73
+ * serialized error doesn't match any of these, UnexpectedRichError will be
74
+ * returned.
75
+ *
76
+ * @returns An instance of Rich Error which type matches the `code` property,
77
+ * or {@link UnexpectedRichError} if no match.
78
+ */
79
+ static parse(serialized, expected) {
80
+ for (const RichErrorClass of expected) {
81
+ const maybeError = new RichErrorClass(serialized.messages);
82
+ if (maybeError.code === serialized.code) return maybeError;
83
+ }
84
+ return new UnexpectedRichError(serialized.messages);
85
+ }
86
+ /**
87
+ * Returns a new instance of {@link UnexpectedRichError}
88
+ * @param messagesOverride Optional overrides of default unexpected messages
89
+ */
90
+ static Unexpected(messagesOverride) {
91
+ return new UnexpectedRichError(messagesOverride);
92
+ }
93
+ };
94
+ /**
95
+ * A general-purpose error which is thrown when no better error could be
96
+ * inferred from the available context.
97
+ */
65
98
  var UnexpectedRichError = class extends RichError {
66
- constructor() {
67
- super(...arguments);
68
- this.name = "UnexpectedRichError";
69
- this.messages = UnexpectedRichErrorMessages;
70
- }
99
+ constructor(..._args) {
100
+ super(..._args);
101
+ this.name = "UnexpectedRichError";
102
+ this.messages = UnexpectedRichErrorMessages;
103
+ }
71
104
  };
72
105
 
73
- // src/errors/network.ts
106
+ //#endregion
107
+ //#region src/errors/network.ts
74
108
  var NetworkRichError = class extends RichError {
75
- constructor() {
76
- super(...arguments);
77
- this.name = "NetworkRichError";
78
- this.messages = {
79
- dev: "An network error occured.",
80
- user: "Network error"
81
- };
82
- }
109
+ constructor(..._args) {
110
+ super(..._args);
111
+ this.name = "NetworkRichError";
112
+ this.messages = {
113
+ dev: "An network error occured.",
114
+ user: "Network error"
115
+ };
116
+ }
83
117
  };
84
118
 
85
- // src/errors/graphql/common.ts
86
- var GraphQLErrors = [NetworkRichError, UnexpectedRichError];
119
+ //#endregion
120
+ //#region src/errors/graphql/common.ts
121
+ const GraphQLErrors = [NetworkRichError, UnexpectedRichError];
87
122
 
88
- // src/errors/graphql/email-otp.ts
123
+ //#endregion
124
+ //#region src/errors/graphql/email-otp.ts
89
125
  var EmailOTPLockedError = class extends RichError {
90
- constructor() {
91
- super(...arguments);
92
- this.name = "EmailOTPLockedError";
93
- this.messages = {
94
- dev: "Email locked 2h because too many attempts",
95
- user: "This email is locked for verification during 2 hours because of too many attempts in a short period of time"
96
- };
97
- }
98
- };
99
- var EmailOTPRequestErrors = [
100
- EmailOTPLockedError
101
- ];
126
+ constructor(..._args) {
127
+ super(..._args);
128
+ this.name = "EmailOTPLockedError";
129
+ this.messages = {
130
+ dev: "Email locked 2h because too many attempts",
131
+ user: "This email is locked for verification during 2 hours because of too many attempts in a short period of time"
132
+ };
133
+ }
134
+ };
135
+ const EmailOTPRequestErrors = [EmailOTPLockedError];
102
136
  var EmailOTPInvalidError = class extends RichError {
103
- constructor() {
104
- super(...arguments);
105
- this.name = "EmailOTPInvalidError";
106
- this.messages = {
107
- dev: "Email verification failed because OTP is invalid",
108
- user: "The validation code is invalid"
109
- };
110
- }
137
+ constructor(..._args2) {
138
+ super(..._args2);
139
+ this.name = "EmailOTPInvalidError";
140
+ this.messages = {
141
+ dev: "Email verification failed because OTP is invalid",
142
+ user: "The validation code is invalid"
143
+ };
144
+ }
111
145
  };
112
146
  var EmailOTPExpiredError = class extends RichError {
113
- constructor() {
114
- super(...arguments);
115
- this.name = "EmailOTPExpiredError";
116
- this.messages = {
117
- dev: "Email verification failed because OTP has expired. A new OTP request must be initiated",
118
- user: "Verification code has expired. Please make another request."
119
- };
120
- }
121
- };
122
- var EmailOTPVerificationErrors = [EmailOTPInvalidError, EmailOTPExpiredError, EmailOTPLockedError];
147
+ constructor(..._args3) {
148
+ super(..._args3);
149
+ this.name = "EmailOTPExpiredError";
150
+ this.messages = {
151
+ dev: "Email verification failed because OTP has expired. A new OTP request must be initiated",
152
+ user: "Verification code has expired. Please make another request."
153
+ };
154
+ }
155
+ };
156
+ const EmailOTPVerificationErrors = [
157
+ EmailOTPInvalidError,
158
+ EmailOTPExpiredError,
159
+ EmailOTPLockedError
160
+ ];
123
161
 
124
- // src/utils/rich-error.ts
125
- import { failure, success } from "@fxhash/utils";
162
+ //#endregion
163
+ //#region src/utils/rich-error.ts
164
+ /**
165
+ * Instanciate a new {@link RichError} using a declarative object. This is
166
+ * useful when Rich Error are instanciated programmatically when type is
167
+ * unknown.
168
+ */
126
169
  function richError(params) {
127
- return Object.assign(new RichError(), params);
170
+ return Object.assign(new RichError(), params);
128
171
  }
129
172
  function isFxhashErrorExtensions(ext) {
130
- return typeof ext === "object" && ext.version === "fxhash@0.1.0";
173
+ return typeof ext === "object" && ext.version === "fxhash@0.1.0";
131
174
  }
175
+ /**
176
+ * Test whether a given value is implementing the {@link IRichErrorMessages}
177
+ * interface.
178
+ * @param value Any value
179
+ */
132
180
  function isRichErrorMessages(value) {
133
- if (typeof value !== "object") return false;
134
- return typeof value.dev === "string" || typeof value.user === "string";
181
+ if (typeof value !== "object") return false;
182
+ return typeof value.dev === "string" || typeof value.user === "string";
135
183
  }
184
+ /**
185
+ * Parses the GraphQL error object into a RichError. This function detects
186
+ * fxhash error extensions for outputting user error messages returned by
187
+ * the backend.
188
+ *
189
+ * @param error A GraphQL error response
190
+ *
191
+ * @returns An "untyped" rich error constructed by parsing the GraphQL error
192
+ */
136
193
  function richErrorFromGraphQLError(error) {
137
- if (error.graphQLErrors.length > 0) {
138
- const gqlError = error.graphQLErrors[0];
139
- if (isFxhashErrorExtensions(gqlError.extensions)) {
140
- return richError({
141
- name: gqlError.extensions.richError.code,
142
- messages: gqlError.extensions.richError.messages
143
- });
144
- }
145
- return new UnexpectedRichError();
146
- }
147
- if (error.networkError) {
148
- return new NetworkRichError();
149
- }
150
- return new UnexpectedRichError();
194
+ if (error.graphQLErrors.length > 0) {
195
+ const gqlError = error.graphQLErrors[0];
196
+ if (isFxhashErrorExtensions(gqlError.extensions)) return richError({
197
+ name: gqlError.extensions.richError.code,
198
+ messages: gqlError.extensions.richError.messages
199
+ });
200
+ return new UnexpectedRichError();
201
+ }
202
+ if (error.networkError) return new NetworkRichError();
203
+ return new UnexpectedRichError();
151
204
  }
205
+ /**
206
+ * Parses the GraphQL error response to find the fxhash GraphQL error extension,
207
+ * which is used to instanciate a Rich Error from a list of provided RichErrors.
208
+ * The `name` constant property of such classes will be compared to the `code`
209
+ * property of the fxhash error extension to find a match.
210
+ *
211
+ * @param graphQLError GraphQL error response
212
+ * @param expectedErrors An array of RichError classes which will be parsed to
213
+ * find matches between the RichError `name` constant and the `code` returned
214
+ * by the GraphQL fxhash error extension.
215
+ *
216
+ * @returns A RichError instance matchin the error code, or
217
+ * {@link NetworkRichError} if a network error occured, else
218
+ * {@link UnexpectedRichError}
219
+ */
152
220
  function typedRichErrorFromGraphQLError(graphQLError, expectedErrors) {
153
- if (graphQLError.networkError) {
154
- return new NetworkRichError();
155
- }
156
- if (graphQLError.graphQLErrors.length > 0) {
157
- const gqlError = graphQLError.graphQLErrors[0];
158
- if (isFxhashErrorExtensions(gqlError.extensions)) {
159
- return RichError.parse(gqlError.extensions.richError, expectedErrors);
160
- }
161
- return new UnexpectedRichError();
162
- }
163
- return new UnexpectedRichError();
221
+ if (graphQLError.networkError) return new NetworkRichError();
222
+ if (graphQLError.graphQLErrors.length > 0) {
223
+ const gqlError = graphQLError.graphQLErrors[0];
224
+ if (isFxhashErrorExtensions(gqlError.extensions)) return RichError.parse(gqlError.extensions.richError, expectedErrors);
225
+ return new UnexpectedRichError();
226
+ }
227
+ return new UnexpectedRichError();
164
228
  }
229
+ /**
230
+ * Returns a `Result<Data, TypedRichError>` by parsing a GraphQL response. If
231
+ * the response has an error, {@link typedRichErrorFromGraphQLError} will be
232
+ * called with such error to return a proper error instance based on the error
233
+ * code in the fxhash graphql error extension (or a a generic error if none).
234
+ *
235
+ * @param operationResult A GraphQL response from fxhash hasura endpoint
236
+ * @param getData A function which takes the response and returns the data (if
237
+ * no data is found it should return `null` | `undefined`, in which case it will
238
+ * fail with UnexpectedError)
239
+ * @param potentialErrors An array of Rich Error classes which could be found in
240
+ * the error response.
241
+ *
242
+ * @example
243
+ *
244
+ * ```ts
245
+ * const emailRequestOTP = async (email) => {
246
+ * return richResultFromGraphQLResponse(
247
+ * await gqlWrapper.client().mutation(Mu_Web3AuthEmailRequestOTP, {
248
+ * email,
249
+ * }),
250
+ * res => res.data?.web3auth_email_request_otp,
251
+ * EmailOTPRequestErrors
252
+ * )
253
+ * },
254
+ * ```
255
+ */
165
256
  function richResultFromGraphQLResponse(operationResult, getData, potentialErrors) {
166
- const res = operationResult;
167
- if (res.error) {
168
- return failure(typedRichErrorFromGraphQLError(res.error, potentialErrors));
169
- }
170
- const data = getData(res);
171
- return data ? success(data) : failure(
172
- new UnexpectedRichError({
173
- dev: "Expected data missing from GraphQL response"
174
- })
175
- );
257
+ const res = operationResult;
258
+ if (res.error) return failure(typedRichErrorFromGraphQLError(res.error, potentialErrors));
259
+ const data = getData(res);
260
+ return data ? success(data) : failure(new UnexpectedRichError({ dev: "Expected data missing from GraphQL response" }));
176
261
  }
262
+ /**
263
+ * Test if an error is of a certain error kind, among a list of [errors] or
264
+ * [list of errors]. This allows testing multiple array of errors, which are
265
+ * defined quite a lot throughout the errors stack.
266
+ *
267
+ * @param error The error which needs to be tested
268
+ * @param kinds List of [errors]/[array of errors]
269
+ *
270
+ * @returns boolean if error is of given kind
271
+ *
272
+ * @example
273
+ *
274
+ * ```ts
275
+ * isErrorOfKind(
276
+ * someErr,
277
+ * UnexpectedRichError,
278
+ * [SuperError, BigError],
279
+ * SimpleError
280
+ * )
281
+ * ```
282
+ */
177
283
  function isErrorOfKind(error, ...kinds) {
178
- for (const kind of kinds) {
179
- if (Array.isArray(kind)) {
180
- if (isErrorOfKind(error, ...kind)) return true;
181
- } else {
182
- if (error.name === kind.name) return true;
183
- if (error.name === kind.errorType) return true;
184
- }
185
- }
186
- return false;
284
+ for (const kind of kinds) if (Array.isArray(kind)) {
285
+ if (isErrorOfKind(error, ...kind)) return true;
286
+ } else {
287
+ if (error.name === kind.name) return true;
288
+ if (error.name === kind.errorType) return true;
289
+ }
290
+ return false;
187
291
  }
188
292
 
189
- // src/errors/graphql/oauth.ts
190
- import { capitalize } from "@fxhash/utils";
191
- var couldntSignIn = (provider) => `Couldn't sign in using ${capitalize(provider)}`;
293
+ //#endregion
294
+ //#region src/errors/graphql/oauth.ts
295
+ const couldntSignIn = (provider) => `Couldn't sign in using ${capitalize(provider)}`;
192
296
  var OAuthTokenVerificationError = class extends RichError {
193
- constructor(par) {
194
- super(
195
- isRichErrorMessages(par) ? par : {
196
- dev: `The provided ${capitalize(par)} OAuth token could not be verified against ${capitalize(par)} services.`,
197
- user: couldntSignIn(par)
198
- }
199
- );
200
- this.name = "OAuthTokenVerificationError";
201
- }
297
+ constructor(par) {
298
+ super(isRichErrorMessages(par) ? par : {
299
+ dev: `The provided ${capitalize(par)} OAuth token could not be verified against ${capitalize(par)} services.`,
300
+ user: couldntSignIn(par)
301
+ });
302
+ this.name = "OAuthTokenVerificationError";
303
+ }
202
304
  };
203
305
  var OAuthMissingInfoError = class extends RichError {
204
- constructor(par, missing) {
205
- super(
206
- isRichErrorMessages(par) ? par : {
207
- dev: `Some user information is missing at the end of the ${capitalize(par)} OAuth authentication flow: ${missing?.join(", ")}. This shouldn't happen and requires investigation from the fxhash team. Please forward this issue to our team.`,
208
- user: couldntSignIn(par)
209
- }
210
- );
211
- this.name = "OAuthMissingInfoError";
212
- }
213
- };
214
- var OAuthErrors = [OAuthTokenVerificationError, OAuthMissingInfoError];
306
+ constructor(par, missing) {
307
+ super(isRichErrorMessages(par) ? par : {
308
+ dev: `Some user information is missing at the end of the ${capitalize(par)} OAuth authentication flow: ${missing?.join(", ")}. This shouldn't happen and requires investigation from the fxhash team. Please forward this issue to our team.`,
309
+ user: couldntSignIn(par)
310
+ });
311
+ this.name = "OAuthMissingInfoError";
312
+ }
313
+ };
314
+ const OAuthErrors = [OAuthTokenVerificationError, OAuthMissingInfoError];
215
315
 
216
- // src/errors/graphql/wallet-linking.ts
316
+ //#endregion
317
+ //#region src/errors/graphql/wallet-linking.ts
217
318
  var WalletAlreadyOtherAccountMainWalletError = class extends RichError {
218
- constructor() {
219
- super(...arguments);
220
- this.name = "WalletAlreadyOtherAccountMainWalletError";
221
- this.messages = {
222
- dev: "Wallet is already the main wallet of another account.",
223
- user: "This wallet is already registered as the main wallet for another account. To link this wallet to your current account, you need to delete the account associated with this wallet first. Please log in to the other account and proceed to delete the account from the profile menu. After this, you can link the wallet to this account."
224
- };
225
- }
226
- };
227
- WalletAlreadyOtherAccountMainWalletError.errorType = "WalletAlreadyOtherAccountMainWalletError";
319
+ constructor(..._args) {
320
+ super(..._args);
321
+ this.name = "WalletAlreadyOtherAccountMainWalletError";
322
+ this.messages = {
323
+ dev: "Wallet is already the main wallet of another account.",
324
+ user: "This wallet is already registered as the main wallet for another account. To link this wallet to your current account, you need to delete the account associated with this wallet first. Please log in to the other account and proceed to delete the account from the profile menu. After this, you can link the wallet to this account."
325
+ };
326
+ }
327
+ static {
328
+ this.errorType = "WalletAlreadyOtherAccountMainWalletError";
329
+ }
330
+ };
228
331
  var WalletAlreadyLinkedError = class extends RichError {
229
- constructor() {
230
- super(...arguments);
231
- this.name = "WalletAlreadyLinkedError";
232
- this.messages = {
233
- dev: "Wallet is already linked to another account (not as the main wallet)",
234
- user: "This wallet is already associated to another account. You must first connect to your other account and unlink this wallet from it."
235
- };
236
- }
237
- };
238
- WalletAlreadyLinkedError.errorType = "WalletAlreadyLinkedError";
332
+ constructor(..._args2) {
333
+ super(..._args2);
334
+ this.name = "WalletAlreadyLinkedError";
335
+ this.messages = {
336
+ dev: "Wallet is already linked to another account (not as the main wallet)",
337
+ user: "This wallet is already associated to another account. You must first connect to your other account and unlink this wallet from it."
338
+ };
339
+ }
340
+ static {
341
+ this.errorType = "WalletAlreadyLinkedError";
342
+ }
343
+ };
239
344
  var AccountAlreadyLinkedOnNetworkError = class extends RichError {
240
- constructor(par) {
241
- super(
242
- isRichErrorMessages(par) ? par : {
243
- dev: `Account already linked to a wallet on ${par.toLowerCase()}. There can only be one wallet per network linked to each account.`,
244
- user: `Your account is already linked to a wallet on ${par.toLowerCase()}`
245
- }
246
- );
247
- this.name = "AccountAlreadyLinkedOnNetworkError";
248
- }
249
- };
250
- var LinkWalletErrors = [
251
- WalletAlreadyOtherAccountMainWalletError,
252
- WalletAlreadyLinkedError,
253
- AccountAlreadyLinkedOnNetworkError
345
+ constructor(par) {
346
+ super(isRichErrorMessages(par) ? par : {
347
+ dev: `Account already linked to a wallet on ${par.toLowerCase()}. There can only be one wallet per network linked to each account.`,
348
+ user: `Your account is already linked to a wallet on ${par.toLowerCase()}`
349
+ });
350
+ this.name = "AccountAlreadyLinkedOnNetworkError";
351
+ }
352
+ };
353
+ const LinkWalletErrors = [
354
+ WalletAlreadyOtherAccountMainWalletError,
355
+ WalletAlreadyLinkedError,
356
+ AccountAlreadyLinkedOnNetworkError
254
357
  ];
255
358
  var WalletNotLinkedToAccountError = class extends RichError {
256
- constructor() {
257
- super(...arguments);
258
- this.name = "WalletNotLinkedToAccountError";
259
- this.messages = {
260
- dev: "Wallet cannot be unlinked because it's not linked to the account currently authenticated",
261
- user: "The wallet cannot be unlinked because it isn't linked to your account."
262
- };
263
- }
359
+ constructor(..._args3) {
360
+ super(..._args3);
361
+ this.name = "WalletNotLinkedToAccountError";
362
+ this.messages = {
363
+ dev: "Wallet cannot be unlinked because it's not linked to the account currently authenticated",
364
+ user: "The wallet cannot be unlinked because it isn't linked to your account."
365
+ };
366
+ }
264
367
  };
265
368
  var MainWalletCannotBeUnlinkedError = class extends RichError {
266
- constructor() {
267
- super(...arguments);
268
- this.name = "MainWalletCannotBeUnlinkedError";
269
- this.messages = {
270
- dev: "The main wallet of an account cannot be unlinked from the account.",
271
- user: "This wallet is the main one associated with your account, as such it cannot be unlinked."
272
- };
273
- }
274
- };
275
- var UnlinkWalletErrors = [WalletNotLinkedToAccountError, MainWalletCannotBeUnlinkedError];
369
+ constructor(..._args4) {
370
+ super(..._args4);
371
+ this.name = "MainWalletCannotBeUnlinkedError";
372
+ this.messages = {
373
+ dev: "The main wallet of an account cannot be unlinked from the account.",
374
+ user: "This wallet is the main one associated with your account, as such it cannot be unlinked."
375
+ };
376
+ }
377
+ };
378
+ const UnlinkWalletErrors = [WalletNotLinkedToAccountError, MainWalletCannotBeUnlinkedError];
276
379
 
277
- // src/errors/core.ts
380
+ //#endregion
381
+ //#region src/errors/core.ts
278
382
  var WalletSourceRequestConnectionRejectedError = class extends RichError {
279
- constructor() {
280
- super(...arguments);
281
- this.name = "WalletSourceRequestConnectionRejectedError";
282
- this.messages = {
283
- dev: "The connection request was rejected by the user",
284
- user: "It looks like you've rejected the connection request - if you didn't mean to, please try again"
285
- };
286
- }
383
+ constructor(..._args) {
384
+ super(..._args);
385
+ this.name = "WalletSourceRequestConnectionRejectedError";
386
+ this.messages = {
387
+ dev: "The connection request was rejected by the user",
388
+ user: "It looks like you've rejected the connection request - if you didn't mean to, please try again"
389
+ };
390
+ }
287
391
  };
288
392
  var WalletSourceRequestConnectionUnknownError = class extends RichError {
289
- constructor(par) {
290
- super(
291
- isRichErrorMessages(par) ? par : {
292
- dev: `An unknown error occurred while requesting a connection: ${par}`,
293
- user: "An unknown error occurred while trying to connect to your wallet - please try again"
294
- }
295
- );
296
- this.name = "WalletSourceRequestConnectionUnknownError";
297
- }
393
+ constructor(par) {
394
+ super(isRichErrorMessages(par) ? par : {
395
+ dev: `An unknown error occurred while requesting a connection: ${par}`,
396
+ user: "An unknown error occurred while trying to connect to your wallet - please try again"
397
+ });
398
+ this.name = "WalletSourceRequestConnectionUnknownError";
399
+ }
298
400
  };
299
401
  var WalletSourceRequestConnectionWalletNotAvailableError = class extends RichError {
300
- constructor(par) {
301
- super(
302
- isRichErrorMessages(par) ? par : {
303
- dev: `The wallet source for ${par} is not available`,
304
- user: "An unknown error occurred while trying to connect to your wallet - please try again"
305
- }
306
- );
307
- this.name = "WalletSourceRequestConnectionWalletNotAvailableError";
308
- }
309
- };
310
- var WalletSourceRequestConnectionErrors = [
311
- WalletSourceRequestConnectionRejectedError,
312
- WalletSourceRequestConnectionUnknownError,
313
- WalletSourceRequestConnectionWalletNotAvailableError
402
+ constructor(par) {
403
+ super(isRichErrorMessages(par) ? par : {
404
+ dev: `The wallet source for ${par} is not available`,
405
+ user: "An unknown error occurred while trying to connect to your wallet - please try again"
406
+ });
407
+ this.name = "WalletSourceRequestConnectionWalletNotAvailableError";
408
+ }
409
+ };
410
+ const WalletSourceRequestConnectionErrors = [
411
+ WalletSourceRequestConnectionRejectedError,
412
+ WalletSourceRequestConnectionUnknownError,
413
+ WalletSourceRequestConnectionWalletNotAvailableError
314
414
  ];
315
415
  var NoWalletConnectedForNetworkError = class extends RichError {
316
- constructor(par) {
317
- super(
318
- isRichErrorMessages(par) ? par : {
319
- dev: `${par} - No wallet is connected to the client`,
320
- user: "A wallet needs to be connected before performing this action"
321
- }
322
- );
323
- this.name = "NoWalletConnectedForNetworkError";
324
- }
416
+ constructor(par) {
417
+ super(isRichErrorMessages(par) ? par : {
418
+ dev: `${par} - No wallet is connected to the client`,
419
+ user: "A wallet needs to be connected before performing this action"
420
+ });
421
+ this.name = "NoWalletConnectedForNetworkError";
422
+ }
325
423
  };
326
424
 
327
- // src/errors/wallet-api.ts
425
+ //#endregion
426
+ //#region src/errors/wallet-api.ts
328
427
  var WalletAPIRpcUnknownNetworkError = class extends RichError {
329
- constructor(par) {
330
- super(
331
- isRichErrorMessages(par) ? par : {
332
- dev: `Could not check rpc health for network: ${par}`,
333
- user: "Rpc health check failed"
334
- }
335
- );
336
- this.name = "WalletApiRpcHealthError";
337
- }
428
+ constructor(par) {
429
+ super(isRichErrorMessages(par) ? par : {
430
+ dev: `Could not check rpc health for network: ${par}`,
431
+ user: "Rpc health check failed"
432
+ });
433
+ this.name = "WalletApiRpcHealthError";
434
+ }
338
435
  };
339
436
  var WalletAPIInvalidRequestError = class extends RichError {
340
- constructor(par) {
341
- const details = Array.isArray(par) ? `
342
- Validation errors:
343
- ${par.map((err) => ` - ${err.path.join(".")}: ${err.message}`).join("\n")}` : "";
344
- super(
345
- isRichErrorMessages(par) ? par : {
346
- dev: `Invalid operation request payload.${details}`,
347
- user: "Invalid request. Please check your input and try again."
348
- }
349
- );
350
- this.name = "WalletAPIInvalidRequestError";
351
- }
437
+ constructor(par) {
438
+ const details = Array.isArray(par) ? `\nValidation errors:\n${par.map((err) => ` - ${err.path.join(".")}: ${err.message}`).join("\n")}` : "";
439
+ super(isRichErrorMessages(par) ? par : {
440
+ dev: `Invalid operation request payload.${details}`,
441
+ user: "Invalid request. Please check your input and try again."
442
+ });
443
+ this.name = "WalletAPIInvalidRequestError";
444
+ }
352
445
  };
353
446
  var WalletAPIFetchError = class extends RichError {
354
- constructor(par, statusCode, attempt, maxRetries) {
355
- super(
356
- isRichErrorMessages(par) ? par : {
357
- dev: `Request to ${par} failed (status: ${statusCode}) on attempt ${attempt}/${maxRetries}`,
358
- user: "Failed to fetch required data. Please try again later."
359
- }
360
- );
361
- this.name = "WalletAPIFetchError";
362
- }
447
+ constructor(par, statusCode, attempt, maxRetries) {
448
+ super(isRichErrorMessages(par) ? par : {
449
+ dev: `Request to ${par} failed (status: ${statusCode}) on attempt ${attempt}/${maxRetries}`,
450
+ user: "Failed to fetch required data. Please try again later."
451
+ });
452
+ this.name = "WalletAPIFetchError";
453
+ }
363
454
  };
364
455
  var WalletAPIFetchTimeoutError = class extends RichError {
365
- constructor(par, maxRetries, finalError) {
366
- const errorMessage = finalError instanceof Error ? finalError.message : String(finalError);
367
- super(
368
- isRichErrorMessages(par) ? par : {
369
- dev: `Request to ${par} failed after ${maxRetries} retries. Final error: ${errorMessage}`,
370
- user: "Service temporarily unavailable. Please try again later."
371
- }
372
- );
373
- this.name = "WalletAPIFetchTimeoutError";
374
- }
456
+ constructor(par, maxRetries, finalError) {
457
+ const errorMessage = finalError instanceof Error ? finalError.message : String(finalError);
458
+ super(isRichErrorMessages(par) ? par : {
459
+ dev: `Request to ${par} failed after ${maxRetries} retries. Final error: ${errorMessage}`,
460
+ user: "Service temporarily unavailable. Please try again later."
461
+ });
462
+ this.name = "WalletAPIFetchTimeoutError";
463
+ }
375
464
  };
376
465
  var WalletAPIInvalidURLError = class extends RichError {
377
- constructor(par) {
378
- super(
379
- isRichErrorMessages(par) ? par : {
380
- dev: `Invalid URL provided: ${par}`,
381
- user: "Invalid request URL configuration."
382
- }
383
- );
384
- this.name = "WalletAPIInvalidURLError";
385
- }
386
- };
387
- var WalletAPIErrors = [
388
- WalletAPIRpcUnknownNetworkError,
389
- WalletAPIInvalidRequestError,
390
- WalletAPIFetchError,
391
- WalletAPIFetchTimeoutError,
392
- WalletAPIInvalidURLError
466
+ constructor(par) {
467
+ super(isRichErrorMessages(par) ? par : {
468
+ dev: `Invalid URL provided: ${par}`,
469
+ user: "Invalid request URL configuration."
470
+ });
471
+ this.name = "WalletAPIInvalidURLError";
472
+ }
473
+ };
474
+ const WalletAPIErrors = [
475
+ WalletAPIRpcUnknownNetworkError,
476
+ WalletAPIInvalidRequestError,
477
+ WalletAPIFetchError,
478
+ WalletAPIFetchTimeoutError,
479
+ WalletAPIInvalidURLError
393
480
  ];
394
481
 
395
- // src/errors/web3auth.ts
482
+ //#endregion
483
+ //#region src/errors/web3auth.ts
396
484
  var Web3AuthFrameNotLoading = class extends RichError {
397
- constructor(par1, error) {
398
- const _error = error ? typeof error === "string" ? error : error.type : "/";
399
- super(
400
- isRichErrorMessages(par1) ? par1 : {
401
- dev: `Fxhash embedded wallet iframe (at "${par1}") could not be loaded. The following error was retured: ${_error}`,
402
- user: "Fxhash embedded wallet has not loaded"
403
- }
404
- );
405
- this.name = "Web3AuthFrameNotLoading";
406
- }
485
+ constructor(par1, error) {
486
+ const _error = error ? typeof error === "string" ? error : error.type : "/";
487
+ super(isRichErrorMessages(par1) ? par1 : {
488
+ dev: `Fxhash embedded wallet iframe (at "${par1}") could not be loaded. The following error was retured: ${_error}`,
489
+ user: "Fxhash embedded wallet has not loaded"
490
+ });
491
+ this.name = "Web3AuthFrameNotLoading";
492
+ }
407
493
  };
408
494
  var Web3AuthFrameNotResponding = class extends RichError {
409
- constructor(url) {
410
- super({
411
- dev: `Fxhash embedded wallet iframe (at "${url}") is not responding to requests`,
412
- user: "Fxhash embedded wallet is not responding"
413
- });
414
- this.name = "Web3AuthFrameNotResponding";
415
- }
495
+ constructor(url) {
496
+ super({
497
+ dev: `Fxhash embedded wallet iframe (at "${url}") is not responding to requests`,
498
+ user: "Fxhash embedded wallet is not responding"
499
+ });
500
+ this.name = "Web3AuthFrameNotResponding";
501
+ }
416
502
  };
417
503
  var Web3AuthFrameNotInitialized = class extends RichError {
418
- constructor() {
419
- super(...arguments);
420
- this.name = "Web3AuthFrameNotInitialized";
421
- this.messages = {
422
- dev: "Fxhash embedded wallet <iframe> hasn't been initialized while it should have",
423
- user: "Fxhash embedded wallet wasn't initialized"
424
- };
425
- }
504
+ constructor(..._args) {
505
+ super(..._args);
506
+ this.name = "Web3AuthFrameNotInitialized";
507
+ this.messages = {
508
+ dev: "Fxhash embedded wallet <iframe> hasn't been initialized while it should have",
509
+ user: "Fxhash embedded wallet wasn't initialized"
510
+ };
511
+ }
426
512
  };
427
513
  var Web3AuthFrameAuthenticationError = class extends RichError {
428
- constructor() {
429
- super(...arguments);
430
- this.name = "Web3AuthFrameAuthenticationError";
431
- this.messages = {
432
- dev: "An error occurred when attempting to authenticate on Web3Auth",
433
- user: "Authentication error"
434
- };
435
- }
514
+ constructor(..._args2) {
515
+ super(..._args2);
516
+ this.name = "Web3AuthFrameAuthenticationError";
517
+ this.messages = {
518
+ dev: "An error occurred when attempting to authenticate on Web3Auth",
519
+ user: "Authentication error"
520
+ };
521
+ }
436
522
  };
437
523
  var Web3AuthFrameFxhashAuthenticationError = class extends RichError {
438
- constructor() {
439
- super(...arguments);
440
- this.name = "Web3AuthFrameFxhashAuthenticationError";
441
- this.messages = {
442
- dev: "An error occurred when attempting to authenticate on fxhash",
443
- user: "Authentication error"
444
- };
445
- }
524
+ constructor(..._args3) {
525
+ super(..._args3);
526
+ this.name = "Web3AuthFrameFxhashAuthenticationError";
527
+ this.messages = {
528
+ dev: "An error occurred when attempting to authenticate on fxhash",
529
+ user: "Authentication error"
530
+ };
531
+ }
446
532
  };
447
533
  var Web3AuthFrameLogoutFailedError = class extends RichError {
448
- constructor() {
449
- super(...arguments);
450
- this.name = "Web3AuthFrameLogoutFailedError";
451
- this.messages = {
452
- dev: "Logout failed. This is likely an issue on fxhash end.",
453
- user: "Could not logout your account. Please try again."
454
- };
455
- }
534
+ constructor(..._args4) {
535
+ super(..._args4);
536
+ this.name = "Web3AuthFrameLogoutFailedError";
537
+ this.messages = {
538
+ dev: "Logout failed. This is likely an issue on fxhash end.",
539
+ user: "Could not logout your account. Please try again."
540
+ };
541
+ }
456
542
  };
457
543
  var Web3AuthInitializationFailedError = class extends RichError {
458
- constructor() {
459
- super(...arguments);
460
- this.name = "Web3AuthInitializationFailedError";
461
- this.messages = {
462
- dev: "Web3Auth initialization failed, as such the embedded wallet cannot be constructed and used. If this issue persists, please raise it on Github.",
463
- user: "Could not initialize embedded wallet."
464
- };
465
- }
544
+ constructor(..._args5) {
545
+ super(..._args5);
546
+ this.name = "Web3AuthInitializationFailedError";
547
+ this.messages = {
548
+ dev: "Web3Auth initialization failed, as such the embedded wallet cannot be constructed and used. If this issue persists, please raise it on Github.",
549
+ user: "Could not initialize embedded wallet."
550
+ };
551
+ }
466
552
  };
467
553
  var Web3AuthFrameUnknownError = class extends RichError {
468
- constructor() {
469
- super(...arguments);
470
- this.name = "Web3AuthFrameUnknownError";
471
- this.messages = {
472
- dev: "An unexpected error was raised using Web3Auth",
473
- user: UnexpectedRichErrorMessages.user
474
- };
475
- }
476
- };
477
- var Web3AuthFrameErrors = {
478
- init: [Web3AuthInitializationFailedError],
479
- getSessionDetails: [Web3AuthFrameAuthenticationError],
480
- login: [
481
- Web3AuthFrameAuthenticationError,
482
- Web3AuthFrameFxhashAuthenticationError,
483
- Web3AuthFrameUnknownError
484
- ],
485
- logout: [Web3AuthFrameLogoutFailedError]
486
- };
487
- var AllWeb3AuthFrameErrors = Array().concat.apply(
488
- [],
489
- Object.values(Web3AuthFrameErrors)
490
- );
491
- export {
492
- AccountAlreadyLinkedOnNetworkError,
493
- AllWeb3AuthFrameErrors,
494
- EmailOTPExpiredError,
495
- EmailOTPInvalidError,
496
- EmailOTPLockedError,
497
- EmailOTPRequestErrors,
498
- EmailOTPVerificationErrors,
499
- GraphQLErrors,
500
- LinkWalletErrors,
501
- MainWalletCannotBeUnlinkedError,
502
- NetworkRichError,
503
- NoWalletConnectedForNetworkError,
504
- OAuthErrors,
505
- OAuthMissingInfoError,
506
- OAuthTokenVerificationError,
507
- RichError,
508
- UnexpectedRichError,
509
- UnexpectedRichErrorMessages,
510
- UnlinkWalletErrors,
511
- WalletAPIErrors,
512
- WalletAPIFetchError,
513
- WalletAPIFetchTimeoutError,
514
- WalletAPIInvalidRequestError,
515
- WalletAPIInvalidURLError,
516
- WalletAPIRpcUnknownNetworkError,
517
- WalletAlreadyLinkedError,
518
- WalletAlreadyOtherAccountMainWalletError,
519
- WalletNotLinkedToAccountError,
520
- WalletSourceRequestConnectionErrors,
521
- WalletSourceRequestConnectionRejectedError,
522
- WalletSourceRequestConnectionUnknownError,
523
- WalletSourceRequestConnectionWalletNotAvailableError,
524
- Web3AuthFrameAuthenticationError,
525
- Web3AuthFrameErrors,
526
- Web3AuthFrameFxhashAuthenticationError,
527
- Web3AuthFrameLogoutFailedError,
528
- Web3AuthFrameNotInitialized,
529
- Web3AuthFrameNotLoading,
530
- Web3AuthFrameNotResponding,
531
- Web3AuthFrameUnknownError,
532
- Web3AuthInitializationFailedError,
533
- isErrorOfKind,
534
- isFxhashErrorExtensions,
535
- isRichErrorMessages,
536
- richError,
537
- richErrorFromGraphQLError,
538
- richResultFromGraphQLResponse,
539
- typedRichErrorFromGraphQLError
540
- };
554
+ constructor(..._args6) {
555
+ super(..._args6);
556
+ this.name = "Web3AuthFrameUnknownError";
557
+ this.messages = {
558
+ dev: "An unexpected error was raised using Web3Auth",
559
+ user: UnexpectedRichErrorMessages.user
560
+ };
561
+ }
562
+ };
563
+ const Web3AuthFrameErrors = {
564
+ init: [Web3AuthInitializationFailedError],
565
+ getSessionDetails: [Web3AuthFrameAuthenticationError],
566
+ login: [
567
+ Web3AuthFrameAuthenticationError,
568
+ Web3AuthFrameFxhashAuthenticationError,
569
+ Web3AuthFrameUnknownError
570
+ ],
571
+ logout: [Web3AuthFrameLogoutFailedError]
572
+ };
573
+ const AllWeb3AuthFrameErrors = Array().concat.apply([], Object.values(Web3AuthFrameErrors));
574
+
575
+ //#endregion
576
+ export { AccountAlreadyLinkedOnNetworkError, AllWeb3AuthFrameErrors, EmailOTPExpiredError, EmailOTPInvalidError, EmailOTPLockedError, EmailOTPRequestErrors, EmailOTPVerificationErrors, GraphQLErrors, LinkWalletErrors, MainWalletCannotBeUnlinkedError, NetworkRichError, NoWalletConnectedForNetworkError, OAuthErrors, OAuthMissingInfoError, OAuthTokenVerificationError, RichError, UnexpectedRichError, UnexpectedRichErrorMessages, UnlinkWalletErrors, WalletAPIErrors, WalletAPIFetchError, WalletAPIFetchTimeoutError, WalletAPIInvalidRequestError, WalletAPIInvalidURLError, WalletAPIRpcUnknownNetworkError, WalletAlreadyLinkedError, WalletAlreadyOtherAccountMainWalletError, WalletNotLinkedToAccountError, WalletSourceRequestConnectionErrors, WalletSourceRequestConnectionRejectedError, WalletSourceRequestConnectionUnknownError, WalletSourceRequestConnectionWalletNotAvailableError, Web3AuthFrameAuthenticationError, Web3AuthFrameErrors, Web3AuthFrameFxhashAuthenticationError, Web3AuthFrameLogoutFailedError, Web3AuthFrameNotInitialized, Web3AuthFrameNotLoading, Web3AuthFrameNotResponding, Web3AuthFrameUnknownError, Web3AuthInitializationFailedError, isErrorOfKind, isFxhashErrorExtensions, isRichErrorMessages, richError, richErrorFromGraphQLError, richResultFromGraphQLResponse, typedRichErrorFromGraphQLError };
541
577
  //# sourceMappingURL=index.js.map