@fxhash/errors 0.0.10 → 0.0.12

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.
@@ -1,5 +1,6 @@
1
1
  import { IRichErrorMessages, RichError, RichErrorUnion } from "../common.js";
2
2
  export declare class WalletAlreadyOtherAccountMainWalletError extends RichError {
3
+ static readonly errorType = "WalletAlreadyOtherAccountMainWalletError";
3
4
  name: "WalletAlreadyOtherAccountMainWalletError";
4
5
  messages: {
5
6
  dev: string
@@ -7,6 +8,7 @@ export declare class WalletAlreadyOtherAccountMainWalletError extends RichError
7
8
  };
8
9
  }
9
10
  export declare class WalletAlreadyLinkedError extends RichError {
11
+ static readonly errorType = "WalletAlreadyLinkedError";
10
12
  name: "WalletAlreadyLinkedError";
11
13
  messages: {
12
14
  dev: string
package/dist/index.js CHANGED
@@ -47,8 +47,9 @@ var RichError = class extends Error {
47
47
  */
48
48
  static parse(serialized, expected) {
49
49
  for (const RichErrorClass of expected) {
50
- if (RichErrorClass.code === serialized.code) {
51
- return new RichErrorClass(serialized.messages);
50
+ const maybeError = new RichErrorClass(serialized.messages);
51
+ if (maybeError.code === serialized.code) {
52
+ return maybeError;
52
53
  }
53
54
  }
54
55
  return new UnexpectedRichError(serialized.messages);
@@ -179,6 +180,7 @@ function isErrorOfKind(error, ...kinds) {
179
180
  if (isErrorOfKind(error, ...kind)) return true;
180
181
  } else {
181
182
  if (error.name === kind.name) return true;
183
+ if (error.name === kind.errorType) return true;
182
184
  }
183
185
  }
184
186
  return false;
@@ -222,6 +224,7 @@ var WalletAlreadyOtherAccountMainWalletError = class extends RichError {
222
224
  };
223
225
  }
224
226
  };
227
+ WalletAlreadyOtherAccountMainWalletError.errorType = "WalletAlreadyOtherAccountMainWalletError";
225
228
  var WalletAlreadyLinkedError = class extends RichError {
226
229
  constructor() {
227
230
  super(...arguments);
@@ -232,6 +235,7 @@ var WalletAlreadyLinkedError = class extends RichError {
232
235
  };
233
236
  }
234
237
  };
238
+ WalletAlreadyLinkedError.errorType = "WalletAlreadyLinkedError";
235
239
  var AccountAlreadyLinkedOnNetworkError = class extends RichError {
236
240
  constructor(par) {
237
241
  super(
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors/common.ts","../src/errors/network.ts","../src/errors/graphql/common.ts","../src/errors/graphql/email-otp.ts","../src/utils/rich-error.ts","../src/errors/graphql/oauth.ts","../src/errors/graphql/wallet-linking.ts","../src/errors/core.ts","../src/errors/wallet-api.ts","../src/errors/web3auth.ts"],"sourcesContent":["import type { IEquatableError } from \"@fxhash/utils\"\n\n/**\n * Rich Error Messages are messages with extra data for a better usage of errors\n * passed through the stack. Traditionally, error messages are intended for\n * developers only (and some custom implementation for user error feedback is\n * required for clean UIs).\n */\nexport interface IRichErrorMessages {\n dev?: string\n user?: string\n}\n\n/**\n * Static error messages for \"unexpected\" errors. This payload is reused accross\n * the stack for when error data is missing.\n */\nexport const UnexpectedRichErrorMessages: Readonly<\n Required<IRichErrorMessages>\n> = {\n dev: \"Unexpected error\",\n user: \"Unexpected error\",\n} as const\n\n/**\n * Flatenned Rich Error interface so that Rich Errors can also be passed in a\n * more convenient way. The purpose of this interface is to provide back-\n * compatibility with `Error`, as well as providing an unambiguous `userMessage`\n * property which can be used by front-end applications.\n */\nexport interface IRichError {\n /**\n * Message intended for developers\n */\n message: string\n /**\n * Message intended for users\n */\n userMessage: string\n}\n\n/**\n * An error which provides messages intended for devs & users. This class should\n * be used accross our stack to provide meaningful error objects which can be\n * used for both developers & users. When typed errors are returned, if they all\n * are instances of `RichError`, then client applications can take some simple\n * shortcuts to provide error feedback to both the developer and the user.\n *\n * @example\n *\n * ```ts\n * export class SomeCustomError extends RichError {\n * name = \"SomeCustomError\" as const // `code` will have same value\n * messages = {\n * dev: \"some message for devs\",\n * user: \"some message for users\"\n * }\n * }\n * ```\n *\n * ```ts\n * const res = await something()\n * if (res.isFailure()) {\n * const err = res.error // if this is typed as `RichError`\n * displayErrorOnUI(err.userMessage) // safely display user message\n * }\n * ```\n */\nexport class RichError extends Error implements IRichError, IEquatableError {\n messages: IRichErrorMessages = UnexpectedRichErrorMessages\n messagesOverride: IRichErrorMessages | undefined\n\n constructor(messagesOverride?: IRichErrorMessages) {\n super()\n if (messagesOverride) {\n this.messagesOverride = messagesOverride\n }\n }\n\n private _message(target: \"dev\" | \"user\") {\n return (\n this.messagesOverride?.[target] ||\n this.messages[target] ||\n UnexpectedRichErrorMessages[target]\n )\n }\n\n get message(): string {\n return this._message(\"dev\")\n }\n\n get userMessage(): string {\n return this._message(\"user\")\n }\n\n get code(): string {\n return this.name\n }\n\n public serialize(): IRichErrorSerialized {\n return {\n code: this.code,\n messages: this.messagesOverride || this.messages,\n }\n }\n\n static get code(): string {\n return this.name\n }\n\n /**\n * Instanciates a Rich Error, trying to match the serialized error with the\n * provided Rich Error classes. The `code` property of the serialized payload\n * is matched against `RichError.name`\n *\n * @param serialized A rich error serialized\n * @param expected A list of Rich Error classes which are expected. If the\n * serialized error doesn't match any of these, UnexpectedRichError will be\n * returned.\n *\n * @returns An instance of Rich Error which type matches the `code` property,\n * or {@link UnexpectedRichError} if no match.\n */\n static parse<T extends (typeof RichError)[]>(\n serialized: IRichErrorSerialized,\n expected: T\n ): RichErrorUnion<T> | UnexpectedRichError {\n for (const RichErrorClass of expected) {\n if (RichErrorClass.code === serialized.code) {\n return new RichErrorClass(serialized.messages) as InstanceType<\n T[number]\n >\n }\n }\n return new UnexpectedRichError(serialized.messages)\n }\n\n /**\n * Returns a new instance of {@link UnexpectedRichError}\n * @param messagesOverride Optional overrides of default unexpected messages\n */\n static Unexpected(\n messagesOverride?: IRichErrorMessages\n ): UnexpectedRichError {\n return new UnexpectedRichError(messagesOverride)\n }\n}\n\n/**\n * A Rich error serialized,\n */\nexport interface IRichErrorSerialized {\n code: string\n messages?: IRichErrorMessages\n}\n\n/**\n * A general-purpose error which is thrown when no better error could be\n * inferred from the available context.\n */\nexport class UnexpectedRichError extends RichError {\n name = \"UnexpectedRichError\" as const\n messages: typeof UnexpectedRichErrorMessages = UnexpectedRichErrorMessages\n}\n\n/**\n * Creates an Union of Rich Error instance types from an array of Rich Error\n * classes.\n */\nexport type RichErrorUnion<T extends (typeof RichError)[]> = InstanceType<\n T[number]\n>\n","import { RichError } from \"./common.js\"\n\nexport class NetworkRichError extends RichError {\n name = \"NetworkRichError\" as const\n messages = {\n dev: \"An network error occured.\",\n user: \"Network error\",\n }\n}\n","import {\n IRichErrorSerialized,\n RichError,\n RichErrorUnion,\n UnexpectedRichError,\n} from \"../common.js\"\nimport { NetworkRichError } from \"../network.js\"\n\n/**\n * Format of the GraphQL error extensions returned by the GraphQL API.\n */\nexport interface IFxhashGraphQLErrorExtensions {\n version: \"fxhash@0.1.0\"\n richError: IRichErrorSerialized\n}\n\nexport const GraphQLErrors: (\n | typeof UnexpectedRichError\n | typeof NetworkRichError\n)[] = [NetworkRichError, UnexpectedRichError]\n\nexport type WithGqlErrors<T extends RichError> =\n | T\n | RichErrorUnion<typeof GraphQLErrors>\n","import { RichError, RichErrorUnion } from \"../common.js\"\n\nexport class EmailOTPLockedError extends RichError {\n name = \"EmailOTPLockedError\" as const\n messages = {\n dev: \"Email locked 2h because too many attempts\",\n user: \"This email is locked for verification during 2 hours because of too many attempts in a short period of time\",\n }\n}\n\nexport const EmailOTPRequestErrors: (typeof EmailOTPLockedError)[] = [\n EmailOTPLockedError,\n]\nexport type EmailOTPRequestError = RichErrorUnion<typeof EmailOTPRequestErrors>\n\nexport class EmailOTPInvalidError extends RichError {\n name = \"EmailOTPInvalidError\" as const\n messages = {\n dev: \"Email verification failed because OTP is invalid\",\n user: \"The validation code is invalid\",\n }\n}\n\nexport class EmailOTPExpiredError extends RichError {\n name = \"EmailOTPExpiredError\" as const\n messages = {\n dev: \"Email verification failed because OTP has expired. A new OTP request must be initiated\",\n user: \"Verification code has expired. Please make another request.\",\n }\n}\n\nexport const EmailOTPVerificationErrors: (\n | typeof EmailOTPLockedError\n | typeof EmailOTPInvalidError\n | typeof EmailOTPExpiredError\n)[] = [EmailOTPInvalidError, EmailOTPExpiredError, EmailOTPLockedError]\nexport type EmailOTPVerificationError = RichErrorUnion<\n typeof EmailOTPVerificationErrors\n>\n","import type { CombinedError, OperationResult } from \"@urql/core\"\nimport {\n IFxhashGraphQLErrorExtensions,\n IRichErrorMessages,\n NetworkRichError,\n RichError,\n UnexpectedRichError,\n WithGqlErrors,\n} from \"../index.js\"\nimport { IEquatableError, Result, failure, success } from \"@fxhash/utils\"\n\nexport type TypeOfRichError<T extends RichError> = {\n new (): T\n parse: (typeof RichError)[\"parse\"]\n Unexpected: (typeof RichError)[\"Unexpected\"]\n code: (typeof RichError)[\"code\"]\n}\n\n/**\n * Instanciate a new {@link RichError} using a declarative object. This is\n * useful when Rich Error are instanciated programmatically when type is\n * unknown.\n */\nexport function richError(params: {\n name: string\n messages?: IRichErrorMessages\n}) {\n return Object.assign(new RichError(), params) as RichError\n}\n\nexport function isFxhashErrorExtensions(\n ext: any\n): ext is IFxhashGraphQLErrorExtensions {\n return typeof ext === \"object\" && ext.version === \"fxhash@0.1.0\"\n}\n\n/**\n * Test whether a given value is implementing the {@link IRichErrorMessages}\n * interface.\n * @param value Any value\n */\nexport function isRichErrorMessages(value: any): value is IRichErrorMessages {\n if (typeof value !== \"object\") return false\n return typeof value.dev === \"string\" || typeof value.user === \"string\"\n}\n\n/**\n * Parses the GraphQL error object into a RichError. This function detects\n * fxhash error extensions for outputting user error messages returned by\n * the backend.\n *\n * @param error A GraphQL error response\n *\n * @returns An \"untyped\" rich error constructed by parsing the GraphQL error\n */\nexport function richErrorFromGraphQLError(\n error: CombinedError\n): RichError | UnexpectedRichError | NetworkRichError {\n if (error.graphQLErrors.length > 0) {\n const gqlError = error.graphQLErrors[0]\n if (isFxhashErrorExtensions(gqlError.extensions)) {\n return richError({\n name: gqlError.extensions.richError.code,\n messages: gqlError.extensions.richError.messages,\n })\n }\n return new UnexpectedRichError()\n }\n if (error.networkError) {\n return new NetworkRichError()\n }\n return new UnexpectedRichError()\n}\n\n/**\n * Parses the GraphQL error response to find the fxhash GraphQL error extension,\n * which is used to instanciate a Rich Error from a list of provided RichErrors.\n * The `name` constant property of such classes will be compared to the `code`\n * property of the fxhash error extension to find a match.\n *\n * @param graphQLError GraphQL error response\n * @param expectedErrors An array of RichError classes which will be parsed to\n * find matches between the RichError `name` constant and the `code` returned\n * by the GraphQL fxhash error extension.\n *\n * @returns A RichError instance matchin the error code, or\n * {@link NetworkRichError} if a network error occured, else\n * {@link UnexpectedRichError}\n */\nexport function typedRichErrorFromGraphQLError<T extends (typeof RichError)[]>(\n graphQLError: CombinedError,\n expectedErrors: T\n): WithGqlErrors<InstanceType<T[number]>> {\n if (graphQLError.networkError) {\n return new NetworkRichError()\n }\n if (graphQLError.graphQLErrors.length > 0) {\n const gqlError = graphQLError.graphQLErrors[0]\n if (isFxhashErrorExtensions(gqlError.extensions)) {\n return RichError.parse(gqlError.extensions.richError, expectedErrors)\n }\n return new UnexpectedRichError()\n }\n return new UnexpectedRichError()\n}\n\n/**\n * Returns a `Result<Data, TypedRichError>` by parsing a GraphQL response. If\n * the response has an error, {@link typedRichErrorFromGraphQLError} will be\n * called with such error to return a proper error instance based on the error\n * code in the fxhash graphql error extension (or a a generic error if none).\n *\n * @param operationResult A GraphQL response from fxhash hasura endpoint\n * @param getData A function which takes the response and returns the data (if\n * no data is found it should return `null` | `undefined`, in which case it will\n * fail with UnexpectedError)\n * @param potentialErrors An array of Rich Error classes which could be found in\n * the error response.\n *\n * @example\n *\n * ```ts\n * const emailRequestOTP = async (email) => {\n * return richResultFromGraphQLResponse(\n * await gqlWrapper.client().mutation(Mu_Web3AuthEmailRequestOTP, {\n * email,\n * }),\n * res => res.data?.web3auth_email_request_otp,\n * EmailOTPRequestErrors\n * )\n * },\n * ```\n */\nexport function richResultFromGraphQLResponse<\n T extends (typeof RichError)[],\n Data = any,\n ExtractedData = any,\n>(\n operationResult: OperationResult<Data>,\n getData: (result: OperationResult<Data>) => ExtractedData | undefined | null,\n potentialErrors: T\n): Result<ExtractedData, WithGqlErrors<InstanceType<T[number]>>> {\n const res = operationResult\n if (res.error) {\n return failure(typedRichErrorFromGraphQLError(res.error, potentialErrors))\n }\n const data = getData(res)\n return data\n ? success(data)\n : failure(\n new UnexpectedRichError({\n dev: \"Expected data missing from GraphQL response\",\n })\n )\n}\n\n/**\n * Test if an error is of a certain error kind, among a list of [errors] or\n * [list of errors]. This allows testing multiple array of errors, which are\n * defined quite a lot throughout the errors stack.\n *\n * @param error The error which needs to be tested\n * @param kinds List of [errors]/[array of errors]\n *\n * @returns boolean if error is of given kind\n *\n * @example\n *\n * ```ts\n * isErrorOfKind(\n * someErr,\n * UnexpectedRichError,\n * [SuperError, BigError],\n * SimpleError\n * )\n * ```\n */\nexport function isErrorOfKind<\n Errors extends (IEquatableError | IEquatableError[])[],\n>(\n error: IEquatableError,\n ...kinds: Errors\n): error is Instance<Flatten<Errors>> {\n for (const kind of kinds) {\n if (Array.isArray(kind)) {\n if (isErrorOfKind(error, ...kind)) return true\n } else {\n if (error.name === kind.name) return true\n }\n }\n return false\n}\n\ntype Flatten<T> = T extends (infer U)[] ? Flatten<U> : T\ntype Instance<T> = T extends abstract new (...args: any) => any\n ? InstanceType<T>\n : T\n","import { isRichErrorMessages } from \"../../utils/rich-error.js\"\nimport { IRichErrorMessages, RichError, RichErrorUnion } from \"../common.js\"\nimport { capitalize } from \"@fxhash/utils\"\n\ntype OAuthProvider = \"google\" | \"discord\"\n\nconst couldntSignIn = (provider: OAuthProvider) =>\n `Couldn't sign in using ${capitalize(provider)}`\n\nexport class OAuthTokenVerificationError extends RichError {\n name = \"OAuthTokenVerificationError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(provider: OAuthProvider)\n constructor(par: IRichErrorMessages | OAuthProvider) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `The provided ${capitalize(par)} OAuth token could not be verified against ${capitalize(par)} services.`,\n user: couldntSignIn(par),\n }\n )\n }\n}\n\nexport class OAuthMissingInfoError extends RichError {\n name = \"OAuthMissingInfoError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(provider: OAuthProvider, missing: string[])\n constructor(par: IRichErrorMessages | OAuthProvider, missing?: string[]) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n 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.`,\n user: couldntSignIn(par),\n }\n )\n }\n}\n\nexport const OAuthErrors: (\n | typeof OAuthTokenVerificationError\n | typeof OAuthMissingInfoError\n)[] = [OAuthTokenVerificationError, OAuthMissingInfoError]\nexport type OAuthError = RichErrorUnion<typeof OAuthErrors>\n","import { isRichErrorMessages } from \"../../utils/rich-error.js\"\nimport { IRichErrorMessages, RichError, RichErrorUnion } from \"../common.js\"\n\nexport class WalletAlreadyOtherAccountMainWalletError extends RichError {\n name = \"WalletAlreadyOtherAccountMainWalletError\" as const\n messages = {\n dev: \"Wallet is already the main wallet of another account.\",\n 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.\",\n }\n}\n\nexport class WalletAlreadyLinkedError extends RichError {\n name = \"WalletAlreadyLinkedError\" as const\n messages = {\n dev: \"Wallet is already linked to another account (not as the main wallet)\",\n user: \"This wallet is already associated to another account. You must first connect to your other account and unlink this wallet from it.\",\n }\n}\n\nexport class AccountAlreadyLinkedOnNetworkError extends RichError {\n name = \"AccountAlreadyLinkedOnNetworkError\" as const\n constructor(messages: IRichErrorMessages)\n constructor(network: string)\n constructor(par: IRichErrorMessages | string) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `Account already linked to a wallet on ${par.toLowerCase()}. There can only be one wallet per network linked to each account.`,\n user: `Your account is already linked to a wallet on ${par.toLowerCase()}`,\n }\n )\n }\n}\n\nexport const LinkWalletErrors: (\n | typeof WalletAlreadyOtherAccountMainWalletError\n | typeof WalletAlreadyLinkedError\n | typeof AccountAlreadyLinkedOnNetworkError\n)[] = [\n WalletAlreadyOtherAccountMainWalletError,\n WalletAlreadyLinkedError,\n AccountAlreadyLinkedOnNetworkError,\n]\nexport type LinkWalletError = RichErrorUnion<typeof LinkWalletErrors>\n\nexport class WalletNotLinkedToAccountError extends RichError {\n name = \"WalletNotLinkedToAccountError\" as const\n messages = {\n dev: \"Wallet cannot be unlinked because it's not linked to the account currently authenticated\",\n user: \"The wallet cannot be unlinked because it isn't linked to your account.\",\n }\n}\n\nexport class MainWalletCannotBeUnlinkedError extends RichError {\n name = \"MainWalletCannotBeUnlinkedError\" as const\n messages = {\n dev: \"The main wallet of an account cannot be unlinked from the account.\",\n user: \"This wallet is the main one associated with your account, as such it cannot be unlinked.\",\n }\n}\n\nexport const UnlinkWalletErrors: (\n | typeof WalletNotLinkedToAccountError\n | typeof MainWalletCannotBeUnlinkedError\n)[] = [WalletNotLinkedToAccountError, MainWalletCannotBeUnlinkedError]\nexport type UnlinkWalletError = RichErrorUnion<typeof UnlinkWalletErrors>\n","import { isRichErrorMessages } from \"../utils/rich-error.js\"\nimport { IRichErrorMessages, RichError, RichErrorUnion } from \"./common.js\"\n\nexport class WalletSourceRequestConnectionRejectedError extends RichError {\n name = \"WalletSourceRequestConnectionRejectedError\" as const\n messages = {\n dev: \"The connection request was rejected by the user\",\n user: \"It looks like you've rejected the connection request - if you didn't mean to, please try again\",\n }\n}\n\nexport class WalletSourceRequestConnectionUnknownError extends RichError {\n name = \"WalletSourceRequestConnectionUnknownError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(network: string)\n constructor(par: IRichErrorMessages | string) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `An unknown error occurred while requesting a connection: ${par}`,\n user: \"An unknown error occurred while trying to connect to your wallet - please try again\",\n }\n )\n }\n}\n\nexport class WalletSourceRequestConnectionWalletNotAvailableError extends RichError {\n name = \"WalletSourceRequestConnectionWalletNotAvailableError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(network: string)\n constructor(par: IRichErrorMessages | string) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `The wallet source for ${par} is not available`,\n user: \"An unknown error occurred while trying to connect to your wallet - please try again\",\n }\n )\n }\n}\n\nexport const WalletSourceRequestConnectionErrors: (\n | typeof WalletSourceRequestConnectionRejectedError\n | typeof WalletSourceRequestConnectionUnknownError\n | typeof WalletSourceRequestConnectionWalletNotAvailableError\n)[] = [\n WalletSourceRequestConnectionRejectedError,\n WalletSourceRequestConnectionUnknownError,\n WalletSourceRequestConnectionWalletNotAvailableError,\n]\nexport type WalletSourceRequestConnectionError = RichErrorUnion<\n typeof WalletSourceRequestConnectionErrors\n>\n\nexport class NoWalletConnectedForNetworkError extends RichError {\n name = \"NoWalletConnectedForNetworkError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(network: string)\n constructor(par: IRichErrorMessages | string) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `${par} - No wallet is connected to the client`,\n user: \"A wallet needs to be connected before performing this action\",\n }\n )\n }\n}\n","import { isRichErrorMessages } from \"../utils/rich-error.js\"\nimport { RichError, RichErrorUnion, IRichErrorMessages } from \"./common.js\"\n\nexport class WalletAPIRpcUnknownNetworkError extends RichError {\n name = \"WalletApiRpcHealthError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(network: string)\n constructor(par: IRichErrorMessages | string) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `Could not check rpc health for network: ${par}`,\n user: \"Rpc health check failed\",\n }\n )\n }\n}\n\nexport class WalletAPIInvalidRequestError extends RichError {\n name = \"WalletAPIInvalidRequestError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(\n validationErrors?: Array<{ path: (string | number)[]; message: string }>\n )\n constructor(\n par?:\n | IRichErrorMessages\n | Array<{ path: (string | number)[]; message: string }>\n ) {\n const details = Array.isArray(par)\n ? `\\nValidation errors:\\n${par\n .map(err => ` - ${err.path.join(\".\")}: ${err.message}`)\n .join(\"\\n\")}`\n : \"\"\n\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `Invalid operation request payload.${details}`,\n user: \"Invalid request. Please check your input and try again.\",\n }\n )\n }\n}\n\nexport class WalletAPIFetchError extends RichError {\n name = \"WalletAPIFetchError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(\n url: string,\n statusCode: number,\n attempt: number,\n maxRetries: number\n )\n constructor(\n par: IRichErrorMessages | string,\n statusCode?: number,\n attempt?: number,\n maxRetries?: number\n ) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `Request to ${par} failed (status: ${statusCode}) on attempt ${attempt}/${maxRetries}`,\n user: \"Failed to fetch required data. Please try again later.\",\n }\n )\n }\n}\n\nexport class WalletAPIFetchTimeoutError extends RichError {\n name = \"WalletAPIFetchTimeoutError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(url: string, maxRetries: number, finalError: unknown)\n constructor(\n par: IRichErrorMessages | string,\n maxRetries?: number,\n finalError?: unknown\n ) {\n const errorMessage =\n finalError instanceof Error ? finalError.message : String(finalError)\n\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `Request to ${par} failed after ${maxRetries} retries. Final error: ${errorMessage}`,\n user: \"Service temporarily unavailable. Please try again later.\",\n }\n )\n }\n}\n\nexport class WalletAPIInvalidURLError extends RichError {\n name = \"WalletAPIInvalidURLError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(url: string)\n constructor(par: IRichErrorMessages | string) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `Invalid URL provided: ${par}`,\n user: \"Invalid request URL configuration.\",\n }\n )\n }\n}\n\nexport const WalletAPIErrors: (\n | typeof WalletAPIRpcUnknownNetworkError\n | typeof WalletAPIInvalidRequestError\n | typeof WalletAPIFetchError\n | typeof WalletAPIFetchTimeoutError\n | typeof WalletAPIInvalidURLError\n)[] = [\n WalletAPIRpcUnknownNetworkError,\n WalletAPIInvalidRequestError,\n WalletAPIFetchError,\n WalletAPIFetchTimeoutError,\n WalletAPIInvalidURLError,\n]\nexport type WalletAPIError = RichErrorUnion<typeof WalletAPIErrors>\n","import { TypeOfRichError, isRichErrorMessages } from \"../index.js\"\nimport {\n IRichErrorMessages,\n RichError,\n RichErrorUnion,\n UnexpectedRichErrorMessages,\n} from \"./common.js\"\n\nexport class Web3AuthFrameNotLoading extends RichError {\n name = \"Web3AuthFrameNotLoading\" as const\n\n constructor(url: string, error: string | Event)\n constructor(messages: IRichErrorMessages)\n constructor(par1: string | IRichErrorMessages, error?: string | Event) {\n const _error = error\n ? typeof error === \"string\"\n ? error\n : error.type\n : \"/\"\n super(\n isRichErrorMessages(par1)\n ? par1\n : {\n dev: `Fxhash embedded wallet iframe (at \"${par1}\") could not be loaded. The following error was retured: ${_error}`,\n user: \"Fxhash embedded wallet has not loaded\",\n }\n )\n }\n}\n\nexport class Web3AuthFrameNotResponding extends RichError {\n name = \"Web3AuthFrameNotResponding\" as const\n\n constructor(url: string) {\n super({\n dev: `Fxhash embedded wallet iframe (at \"${url}\") is not responding to requests`,\n user: \"Fxhash embedded wallet is not responding\",\n })\n }\n}\n\nexport class Web3AuthFrameNotInitialized extends RichError {\n name = \"Web3AuthFrameNotInitialized\" as const\n messages = {\n dev: \"Fxhash embedded wallet <iframe> hasn't been initialized while it should have\",\n user: \"Fxhash embedded wallet wasn't initialized\",\n }\n}\n\n// errors related to the initialization of the frame\nexport type Web3AuthFrameInitializationError =\n | Web3AuthFrameNotInitialized\n | Web3AuthFrameNotLoading\n | Web3AuthFrameNotResponding\n\nexport class Web3AuthFrameAuthenticationError extends RichError {\n name = \"Web3AuthFrameAuthenticationError\" as const\n messages = {\n dev: \"An error occurred when attempting to authenticate on Web3Auth\",\n user: \"Authentication error\",\n }\n}\n\nexport class Web3AuthFrameFxhashAuthenticationError extends RichError {\n name = \"Web3AuthFrameFxhashAuthenticationError\" as const\n messages = {\n dev: \"An error occurred when attempting to authenticate on fxhash\",\n user: \"Authentication error\",\n }\n}\n\nexport class Web3AuthFrameLogoutFailedError extends RichError {\n name = \"Web3AuthFrameLogoutFailedError\" as const\n messages = {\n dev: \"Logout failed. This is likely an issue on fxhash end.\",\n user: \"Could not logout your account. Please try again.\",\n }\n}\n\nexport class Web3AuthInitializationFailedError extends RichError {\n name = \"Web3AuthInitializationFailedError\" as const\n messages = {\n dev: \"Web3Auth initialization failed, as such the embedded wallet cannot be constructed and used. If this issue persists, please raise it on Github.\",\n user: \"Could not initialize embedded wallet.\",\n }\n}\n\nexport class Web3AuthFrameUnknownError extends RichError {\n name = \"Web3AuthFrameUnknownError\" as const\n messages: {\n dev: string\n user: string\n } = {\n dev: \"An unexpected error was raised using Web3Auth\",\n user: UnexpectedRichErrorMessages.user,\n }\n}\n\nexport const Web3AuthFrameErrors: {\n init: (typeof Web3AuthInitializationFailedError)[]\n getSessionDetails: (typeof Web3AuthFrameAuthenticationError)[]\n login: (\n | typeof Web3AuthFrameAuthenticationError\n | typeof Web3AuthFrameFxhashAuthenticationError\n | typeof Web3AuthFrameUnknownError\n )[]\n logout: (typeof Web3AuthFrameLogoutFailedError)[]\n} = {\n init: [Web3AuthInitializationFailedError],\n getSessionDetails: [Web3AuthFrameAuthenticationError],\n login: [\n Web3AuthFrameAuthenticationError,\n Web3AuthFrameFxhashAuthenticationError,\n Web3AuthFrameUnknownError,\n ],\n logout: [Web3AuthFrameLogoutFailedError],\n}\n\nexport type Web3AuthFrameError = {\n [K in keyof typeof Web3AuthFrameErrors]: RichErrorUnion<\n (typeof Web3AuthFrameErrors)[K]\n >\n}\n\nexport type AllWeb3AuthFrameError = TypeOfRichError<\n Web3AuthFrameError[keyof Web3AuthFrameError]\n>\nexport const AllWeb3AuthFrameErrors: AllWeb3AuthFrameError[] =\n Array<AllWeb3AuthFrameError>().concat.apply(\n [],\n Object.values(Web3AuthFrameErrors) as any\n )\n"],"mappings":";AAiBO,IAAM,8BAET;AAAA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ACnC;","names":[]}
1
+ {"version":3,"sources":["../src/errors/common.ts","../src/errors/network.ts","../src/errors/graphql/common.ts","../src/errors/graphql/email-otp.ts","../src/utils/rich-error.ts","../src/errors/graphql/oauth.ts","../src/errors/graphql/wallet-linking.ts","../src/errors/core.ts","../src/errors/wallet-api.ts","../src/errors/web3auth.ts"],"sourcesContent":["import type { IEquatableError } from \"@fxhash/utils\"\n\n/**\n * Rich Error Messages are messages with extra data for a better usage of errors\n * passed through the stack. Traditionally, error messages are intended for\n * developers only (and some custom implementation for user error feedback is\n * required for clean UIs).\n */\nexport interface IRichErrorMessages {\n dev?: string\n user?: string\n}\n\n/**\n * Static error messages for \"unexpected\" errors. This payload is reused accross\n * the stack for when error data is missing.\n */\nexport const UnexpectedRichErrorMessages: Readonly<\n Required<IRichErrorMessages>\n> = {\n dev: \"Unexpected error\",\n user: \"Unexpected error\",\n} as const\n\n/**\n * Flatenned Rich Error interface so that Rich Errors can also be passed in a\n * more convenient way. The purpose of this interface is to provide back-\n * compatibility with `Error`, as well as providing an unambiguous `userMessage`\n * property which can be used by front-end applications.\n */\nexport interface IRichError {\n /**\n * Message intended for developers\n */\n message: string\n /**\n * Message intended for users\n */\n userMessage: string\n}\n\n/**\n * An error which provides messages intended for devs & users. This class should\n * be used accross our stack to provide meaningful error objects which can be\n * used for both developers & users. When typed errors are returned, if they all\n * are instances of `RichError`, then client applications can take some simple\n * shortcuts to provide error feedback to both the developer and the user.\n *\n * @example\n *\n * ```ts\n * export class SomeCustomError extends RichError {\n * name = \"SomeCustomError\" as const // `code` will have same value\n * messages = {\n * dev: \"some message for devs\",\n * user: \"some message for users\"\n * }\n * }\n * ```\n *\n * ```ts\n * const res = await something()\n * if (res.isFailure()) {\n * const err = res.error // if this is typed as `RichError`\n * displayErrorOnUI(err.userMessage) // safely display user message\n * }\n * ```\n */\nexport class RichError extends Error implements IRichError, IEquatableError {\n messages: IRichErrorMessages = UnexpectedRichErrorMessages\n messagesOverride: IRichErrorMessages | undefined\n\n constructor(messagesOverride?: IRichErrorMessages) {\n super()\n if (messagesOverride) {\n this.messagesOverride = messagesOverride\n }\n }\n\n private _message(target: \"dev\" | \"user\") {\n return (\n this.messagesOverride?.[target] ||\n this.messages[target] ||\n UnexpectedRichErrorMessages[target]\n )\n }\n\n get message(): string {\n return this._message(\"dev\")\n }\n\n get userMessage(): string {\n return this._message(\"user\")\n }\n\n get code(): string {\n return this.name\n }\n\n public serialize(): IRichErrorSerialized {\n return {\n code: this.code,\n messages: this.messagesOverride || this.messages,\n }\n }\n\n static get code(): string {\n return this.name\n }\n\n /**\n * Instanciates a Rich Error, trying to match the serialized error with the\n * provided Rich Error classes. The `code` property of the serialized payload\n * is matched against `RichError.name`\n *\n * @param serialized A rich error serialized\n * @param expected A list of Rich Error classes which are expected. If the\n * serialized error doesn't match any of these, UnexpectedRichError will be\n * returned.\n *\n * @returns An instance of Rich Error which type matches the `code` property,\n * or {@link UnexpectedRichError} if no match.\n */\n static parse<T extends (typeof RichError)[]>(\n serialized: IRichErrorSerialized,\n expected: T\n ): RichErrorUnion<T> | UnexpectedRichError {\n for (const RichErrorClass of expected) {\n const maybeError = new RichErrorClass(serialized.messages)\n if (maybeError.code === serialized.code) {\n return maybeError as InstanceType<T[number]>\n }\n }\n return new UnexpectedRichError(serialized.messages)\n }\n\n /**\n * Returns a new instance of {@link UnexpectedRichError}\n * @param messagesOverride Optional overrides of default unexpected messages\n */\n static Unexpected(\n messagesOverride?: IRichErrorMessages\n ): UnexpectedRichError {\n return new UnexpectedRichError(messagesOverride)\n }\n}\n\n/**\n * A Rich error serialized,\n */\nexport interface IRichErrorSerialized {\n code: string\n messages?: IRichErrorMessages\n}\n\n/**\n * A general-purpose error which is thrown when no better error could be\n * inferred from the available context.\n */\nexport class UnexpectedRichError extends RichError {\n name = \"UnexpectedRichError\" as const\n messages: typeof UnexpectedRichErrorMessages = UnexpectedRichErrorMessages\n}\n\n/**\n * Creates an Union of Rich Error instance types from an array of Rich Error\n * classes.\n */\nexport type RichErrorUnion<T extends (typeof RichError)[]> = InstanceType<\n T[number]\n>\n","import { RichError } from \"./common.js\"\n\nexport class NetworkRichError extends RichError {\n name = \"NetworkRichError\" as const\n messages = {\n dev: \"An network error occured.\",\n user: \"Network error\",\n }\n}\n","import {\n IRichErrorSerialized,\n RichError,\n RichErrorUnion,\n UnexpectedRichError,\n} from \"../common.js\"\nimport { NetworkRichError } from \"../network.js\"\n\n/**\n * Format of the GraphQL error extensions returned by the GraphQL API.\n */\nexport interface IFxhashGraphQLErrorExtensions {\n version: \"fxhash@0.1.0\"\n richError: IRichErrorSerialized\n}\n\nexport const GraphQLErrors: (\n | typeof UnexpectedRichError\n | typeof NetworkRichError\n)[] = [NetworkRichError, UnexpectedRichError]\n\nexport type WithGqlErrors<T extends RichError> =\n | T\n | RichErrorUnion<typeof GraphQLErrors>\n","import { RichError, RichErrorUnion } from \"../common.js\"\n\nexport class EmailOTPLockedError extends RichError {\n name = \"EmailOTPLockedError\" as const\n messages = {\n dev: \"Email locked 2h because too many attempts\",\n user: \"This email is locked for verification during 2 hours because of too many attempts in a short period of time\",\n }\n}\n\nexport const EmailOTPRequestErrors: (typeof EmailOTPLockedError)[] = [\n EmailOTPLockedError,\n]\nexport type EmailOTPRequestError = RichErrorUnion<typeof EmailOTPRequestErrors>\n\nexport class EmailOTPInvalidError extends RichError {\n name = \"EmailOTPInvalidError\" as const\n messages = {\n dev: \"Email verification failed because OTP is invalid\",\n user: \"The validation code is invalid\",\n }\n}\n\nexport class EmailOTPExpiredError extends RichError {\n name = \"EmailOTPExpiredError\" as const\n messages = {\n dev: \"Email verification failed because OTP has expired. A new OTP request must be initiated\",\n user: \"Verification code has expired. Please make another request.\",\n }\n}\n\nexport const EmailOTPVerificationErrors: (\n | typeof EmailOTPLockedError\n | typeof EmailOTPInvalidError\n | typeof EmailOTPExpiredError\n)[] = [EmailOTPInvalidError, EmailOTPExpiredError, EmailOTPLockedError]\nexport type EmailOTPVerificationError = RichErrorUnion<\n typeof EmailOTPVerificationErrors\n>\n","import type { CombinedError, OperationResult } from \"@urql/core\"\nimport {\n IFxhashGraphQLErrorExtensions,\n IRichErrorMessages,\n NetworkRichError,\n RichError,\n UnexpectedRichError,\n WithGqlErrors,\n} from \"../index.js\"\nimport { IEquatableError, Result, failure, success } from \"@fxhash/utils\"\n\nexport type TypeOfRichError<T extends RichError> = {\n new (): T\n parse: (typeof RichError)[\"parse\"]\n Unexpected: (typeof RichError)[\"Unexpected\"]\n code: (typeof RichError)[\"code\"]\n}\n\n/**\n * Instanciate a new {@link RichError} using a declarative object. This is\n * useful when Rich Error are instanciated programmatically when type is\n * unknown.\n */\nexport function richError(params: {\n name: string\n messages?: IRichErrorMessages\n}) {\n return Object.assign(new RichError(), params) as RichError\n}\n\nexport function isFxhashErrorExtensions(\n ext: any\n): ext is IFxhashGraphQLErrorExtensions {\n return typeof ext === \"object\" && ext.version === \"fxhash@0.1.0\"\n}\n\n/**\n * Test whether a given value is implementing the {@link IRichErrorMessages}\n * interface.\n * @param value Any value\n */\nexport function isRichErrorMessages(value: any): value is IRichErrorMessages {\n if (typeof value !== \"object\") return false\n return typeof value.dev === \"string\" || typeof value.user === \"string\"\n}\n\n/**\n * Parses the GraphQL error object into a RichError. This function detects\n * fxhash error extensions for outputting user error messages returned by\n * the backend.\n *\n * @param error A GraphQL error response\n *\n * @returns An \"untyped\" rich error constructed by parsing the GraphQL error\n */\nexport function richErrorFromGraphQLError(\n error: CombinedError\n): RichError | UnexpectedRichError | NetworkRichError {\n if (error.graphQLErrors.length > 0) {\n const gqlError = error.graphQLErrors[0]\n if (isFxhashErrorExtensions(gqlError.extensions)) {\n return richError({\n name: gqlError.extensions.richError.code,\n messages: gqlError.extensions.richError.messages,\n })\n }\n return new UnexpectedRichError()\n }\n if (error.networkError) {\n return new NetworkRichError()\n }\n return new UnexpectedRichError()\n}\n\n/**\n * Parses the GraphQL error response to find the fxhash GraphQL error extension,\n * which is used to instanciate a Rich Error from a list of provided RichErrors.\n * The `name` constant property of such classes will be compared to the `code`\n * property of the fxhash error extension to find a match.\n *\n * @param graphQLError GraphQL error response\n * @param expectedErrors An array of RichError classes which will be parsed to\n * find matches between the RichError `name` constant and the `code` returned\n * by the GraphQL fxhash error extension.\n *\n * @returns A RichError instance matchin the error code, or\n * {@link NetworkRichError} if a network error occured, else\n * {@link UnexpectedRichError}\n */\nexport function typedRichErrorFromGraphQLError<T extends (typeof RichError)[]>(\n graphQLError: CombinedError,\n expectedErrors: T\n): WithGqlErrors<InstanceType<T[number]>> {\n if (graphQLError.networkError) {\n return new NetworkRichError()\n }\n if (graphQLError.graphQLErrors.length > 0) {\n const gqlError = graphQLError.graphQLErrors[0]\n if (isFxhashErrorExtensions(gqlError.extensions)) {\n return RichError.parse(gqlError.extensions.richError, expectedErrors)\n }\n return new UnexpectedRichError()\n }\n return new UnexpectedRichError()\n}\n\n/**\n * Returns a `Result<Data, TypedRichError>` by parsing a GraphQL response. If\n * the response has an error, {@link typedRichErrorFromGraphQLError} will be\n * called with such error to return a proper error instance based on the error\n * code in the fxhash graphql error extension (or a a generic error if none).\n *\n * @param operationResult A GraphQL response from fxhash hasura endpoint\n * @param getData A function which takes the response and returns the data (if\n * no data is found it should return `null` | `undefined`, in which case it will\n * fail with UnexpectedError)\n * @param potentialErrors An array of Rich Error classes which could be found in\n * the error response.\n *\n * @example\n *\n * ```ts\n * const emailRequestOTP = async (email) => {\n * return richResultFromGraphQLResponse(\n * await gqlWrapper.client().mutation(Mu_Web3AuthEmailRequestOTP, {\n * email,\n * }),\n * res => res.data?.web3auth_email_request_otp,\n * EmailOTPRequestErrors\n * )\n * },\n * ```\n */\nexport function richResultFromGraphQLResponse<\n T extends (typeof RichError)[],\n Data = any,\n ExtractedData = any,\n>(\n operationResult: OperationResult<Data>,\n getData: (result: OperationResult<Data>) => ExtractedData | undefined | null,\n potentialErrors: T\n): Result<ExtractedData, WithGqlErrors<InstanceType<T[number]>>> {\n const res = operationResult\n if (res.error) {\n return failure(typedRichErrorFromGraphQLError(res.error, potentialErrors))\n }\n const data = getData(res)\n return data\n ? success(data)\n : failure(\n new UnexpectedRichError({\n dev: \"Expected data missing from GraphQL response\",\n })\n )\n}\n\n/**\n * Test if an error is of a certain error kind, among a list of [errors] or\n * [list of errors]. This allows testing multiple array of errors, which are\n * defined quite a lot throughout the errors stack.\n *\n * @param error The error which needs to be tested\n * @param kinds List of [errors]/[array of errors]\n *\n * @returns boolean if error is of given kind\n *\n * @example\n *\n * ```ts\n * isErrorOfKind(\n * someErr,\n * UnexpectedRichError,\n * [SuperError, BigError],\n * SimpleError\n * )\n * ```\n */\nexport function isErrorOfKind<\n Errors extends (IEquatableError | IEquatableError[])[],\n>(\n error: IEquatableError,\n ...kinds: Errors\n): error is Instance<Flatten<Errors>> {\n for (const kind of kinds) {\n if (Array.isArray(kind)) {\n if (isErrorOfKind(error, ...kind)) return true\n } else {\n if (error.name === kind.name) return true\n // workaround for nextjs minification issue\n if (error.name === (kind as any).errorType) return true\n }\n }\n return false\n}\n\ntype Flatten<T> = T extends (infer U)[] ? Flatten<U> : T\ntype Instance<T> = T extends abstract new (...args: any) => any\n ? InstanceType<T>\n : T\n","import { isRichErrorMessages } from \"../../utils/rich-error.js\"\nimport { IRichErrorMessages, RichError, RichErrorUnion } from \"../common.js\"\nimport { capitalize } from \"@fxhash/utils\"\n\ntype OAuthProvider = \"google\" | \"discord\"\n\nconst couldntSignIn = (provider: OAuthProvider) =>\n `Couldn't sign in using ${capitalize(provider)}`\n\nexport class OAuthTokenVerificationError extends RichError {\n name = \"OAuthTokenVerificationError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(provider: OAuthProvider)\n constructor(par: IRichErrorMessages | OAuthProvider) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `The provided ${capitalize(par)} OAuth token could not be verified against ${capitalize(par)} services.`,\n user: couldntSignIn(par),\n }\n )\n }\n}\n\nexport class OAuthMissingInfoError extends RichError {\n name = \"OAuthMissingInfoError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(provider: OAuthProvider, missing: string[])\n constructor(par: IRichErrorMessages | OAuthProvider, missing?: string[]) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n 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.`,\n user: couldntSignIn(par),\n }\n )\n }\n}\n\nexport const OAuthErrors: (\n | typeof OAuthTokenVerificationError\n | typeof OAuthMissingInfoError\n)[] = [OAuthTokenVerificationError, OAuthMissingInfoError]\nexport type OAuthError = RichErrorUnion<typeof OAuthErrors>\n","import { isRichErrorMessages } from \"../../utils/rich-error.js\"\nimport { IRichErrorMessages, RichError, RichErrorUnion } from \"../common.js\"\n\nexport class WalletAlreadyOtherAccountMainWalletError extends RichError {\n static readonly errorType = \"WalletAlreadyOtherAccountMainWalletError\"\n name = \"WalletAlreadyOtherAccountMainWalletError\" as const\n messages = {\n dev: \"Wallet is already the main wallet of another account.\",\n 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.\",\n }\n}\n\nexport class WalletAlreadyLinkedError extends RichError {\n static readonly errorType = \"WalletAlreadyLinkedError\"\n name = \"WalletAlreadyLinkedError\" as const\n messages = {\n dev: \"Wallet is already linked to another account (not as the main wallet)\",\n user: \"This wallet is already associated to another account. You must first connect to your other account and unlink this wallet from it.\",\n }\n}\n\nexport class AccountAlreadyLinkedOnNetworkError extends RichError {\n name = \"AccountAlreadyLinkedOnNetworkError\" as const\n constructor(messages: IRichErrorMessages)\n constructor(network: string)\n constructor(par: IRichErrorMessages | string) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `Account already linked to a wallet on ${par.toLowerCase()}. There can only be one wallet per network linked to each account.`,\n user: `Your account is already linked to a wallet on ${par.toLowerCase()}`,\n }\n )\n }\n}\n\nexport const LinkWalletErrors: (\n | typeof WalletAlreadyOtherAccountMainWalletError\n | typeof WalletAlreadyLinkedError\n | typeof AccountAlreadyLinkedOnNetworkError\n)[] = [\n WalletAlreadyOtherAccountMainWalletError,\n WalletAlreadyLinkedError,\n AccountAlreadyLinkedOnNetworkError,\n]\nexport type LinkWalletError = RichErrorUnion<typeof LinkWalletErrors>\n\nexport class WalletNotLinkedToAccountError extends RichError {\n name = \"WalletNotLinkedToAccountError\" as const\n messages = {\n dev: \"Wallet cannot be unlinked because it's not linked to the account currently authenticated\",\n user: \"The wallet cannot be unlinked because it isn't linked to your account.\",\n }\n}\n\nexport class MainWalletCannotBeUnlinkedError extends RichError {\n name = \"MainWalletCannotBeUnlinkedError\" as const\n messages = {\n dev: \"The main wallet of an account cannot be unlinked from the account.\",\n user: \"This wallet is the main one associated with your account, as such it cannot be unlinked.\",\n }\n}\n\nexport const UnlinkWalletErrors: (\n | typeof WalletNotLinkedToAccountError\n | typeof MainWalletCannotBeUnlinkedError\n)[] = [WalletNotLinkedToAccountError, MainWalletCannotBeUnlinkedError]\nexport type UnlinkWalletError = RichErrorUnion<typeof UnlinkWalletErrors>\n","import { isRichErrorMessages } from \"../utils/rich-error.js\"\nimport { IRichErrorMessages, RichError, RichErrorUnion } from \"./common.js\"\n\nexport class WalletSourceRequestConnectionRejectedError extends RichError {\n name = \"WalletSourceRequestConnectionRejectedError\" as const\n messages = {\n dev: \"The connection request was rejected by the user\",\n user: \"It looks like you've rejected the connection request - if you didn't mean to, please try again\",\n }\n}\n\nexport class WalletSourceRequestConnectionUnknownError extends RichError {\n name = \"WalletSourceRequestConnectionUnknownError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(network: string)\n constructor(par: IRichErrorMessages | string) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `An unknown error occurred while requesting a connection: ${par}`,\n user: \"An unknown error occurred while trying to connect to your wallet - please try again\",\n }\n )\n }\n}\n\nexport class WalletSourceRequestConnectionWalletNotAvailableError extends RichError {\n name = \"WalletSourceRequestConnectionWalletNotAvailableError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(network: string)\n constructor(par: IRichErrorMessages | string) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `The wallet source for ${par} is not available`,\n user: \"An unknown error occurred while trying to connect to your wallet - please try again\",\n }\n )\n }\n}\n\nexport const WalletSourceRequestConnectionErrors: (\n | typeof WalletSourceRequestConnectionRejectedError\n | typeof WalletSourceRequestConnectionUnknownError\n | typeof WalletSourceRequestConnectionWalletNotAvailableError\n)[] = [\n WalletSourceRequestConnectionRejectedError,\n WalletSourceRequestConnectionUnknownError,\n WalletSourceRequestConnectionWalletNotAvailableError,\n]\nexport type WalletSourceRequestConnectionError = RichErrorUnion<\n typeof WalletSourceRequestConnectionErrors\n>\n\nexport class NoWalletConnectedForNetworkError extends RichError {\n name = \"NoWalletConnectedForNetworkError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(network: string)\n constructor(par: IRichErrorMessages | string) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `${par} - No wallet is connected to the client`,\n user: \"A wallet needs to be connected before performing this action\",\n }\n )\n }\n}\n","import { isRichErrorMessages } from \"../utils/rich-error.js\"\nimport { RichError, RichErrorUnion, IRichErrorMessages } from \"./common.js\"\n\nexport class WalletAPIRpcUnknownNetworkError extends RichError {\n name = \"WalletApiRpcHealthError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(network: string)\n constructor(par: IRichErrorMessages | string) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `Could not check rpc health for network: ${par}`,\n user: \"Rpc health check failed\",\n }\n )\n }\n}\n\nexport class WalletAPIInvalidRequestError extends RichError {\n name = \"WalletAPIInvalidRequestError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(\n validationErrors?: Array<{ path: (string | number)[]; message: string }>\n )\n constructor(\n par?:\n | IRichErrorMessages\n | Array<{ path: (string | number)[]; message: string }>\n ) {\n const details = Array.isArray(par)\n ? `\\nValidation errors:\\n${par\n .map(err => ` - ${err.path.join(\".\")}: ${err.message}`)\n .join(\"\\n\")}`\n : \"\"\n\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `Invalid operation request payload.${details}`,\n user: \"Invalid request. Please check your input and try again.\",\n }\n )\n }\n}\n\nexport class WalletAPIFetchError extends RichError {\n name = \"WalletAPIFetchError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(\n url: string,\n statusCode: number,\n attempt: number,\n maxRetries: number\n )\n constructor(\n par: IRichErrorMessages | string,\n statusCode?: number,\n attempt?: number,\n maxRetries?: number\n ) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `Request to ${par} failed (status: ${statusCode}) on attempt ${attempt}/${maxRetries}`,\n user: \"Failed to fetch required data. Please try again later.\",\n }\n )\n }\n}\n\nexport class WalletAPIFetchTimeoutError extends RichError {\n name = \"WalletAPIFetchTimeoutError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(url: string, maxRetries: number, finalError: unknown)\n constructor(\n par: IRichErrorMessages | string,\n maxRetries?: number,\n finalError?: unknown\n ) {\n const errorMessage =\n finalError instanceof Error ? finalError.message : String(finalError)\n\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `Request to ${par} failed after ${maxRetries} retries. Final error: ${errorMessage}`,\n user: \"Service temporarily unavailable. Please try again later.\",\n }\n )\n }\n}\n\nexport class WalletAPIInvalidURLError extends RichError {\n name = \"WalletAPIInvalidURLError\" as const\n\n constructor(messages: IRichErrorMessages)\n constructor(url: string)\n constructor(par: IRichErrorMessages | string) {\n super(\n isRichErrorMessages(par)\n ? par\n : {\n dev: `Invalid URL provided: ${par}`,\n user: \"Invalid request URL configuration.\",\n }\n )\n }\n}\n\nexport const WalletAPIErrors: (\n | typeof WalletAPIRpcUnknownNetworkError\n | typeof WalletAPIInvalidRequestError\n | typeof WalletAPIFetchError\n | typeof WalletAPIFetchTimeoutError\n | typeof WalletAPIInvalidURLError\n)[] = [\n WalletAPIRpcUnknownNetworkError,\n WalletAPIInvalidRequestError,\n WalletAPIFetchError,\n WalletAPIFetchTimeoutError,\n WalletAPIInvalidURLError,\n]\nexport type WalletAPIError = RichErrorUnion<typeof WalletAPIErrors>\n","import { TypeOfRichError, isRichErrorMessages } from \"../index.js\"\nimport {\n IRichErrorMessages,\n RichError,\n RichErrorUnion,\n UnexpectedRichErrorMessages,\n} from \"./common.js\"\n\nexport class Web3AuthFrameNotLoading extends RichError {\n name = \"Web3AuthFrameNotLoading\" as const\n\n constructor(url: string, error: string | Event)\n constructor(messages: IRichErrorMessages)\n constructor(par1: string | IRichErrorMessages, error?: string | Event) {\n const _error = error\n ? typeof error === \"string\"\n ? error\n : error.type\n : \"/\"\n super(\n isRichErrorMessages(par1)\n ? par1\n : {\n dev: `Fxhash embedded wallet iframe (at \"${par1}\") could not be loaded. The following error was retured: ${_error}`,\n user: \"Fxhash embedded wallet has not loaded\",\n }\n )\n }\n}\n\nexport class Web3AuthFrameNotResponding extends RichError {\n name = \"Web3AuthFrameNotResponding\" as const\n\n constructor(url: string) {\n super({\n dev: `Fxhash embedded wallet iframe (at \"${url}\") is not responding to requests`,\n user: \"Fxhash embedded wallet is not responding\",\n })\n }\n}\n\nexport class Web3AuthFrameNotInitialized extends RichError {\n name = \"Web3AuthFrameNotInitialized\" as const\n messages = {\n dev: \"Fxhash embedded wallet <iframe> hasn't been initialized while it should have\",\n user: \"Fxhash embedded wallet wasn't initialized\",\n }\n}\n\n// errors related to the initialization of the frame\nexport type Web3AuthFrameInitializationError =\n | Web3AuthFrameNotInitialized\n | Web3AuthFrameNotLoading\n | Web3AuthFrameNotResponding\n\nexport class Web3AuthFrameAuthenticationError extends RichError {\n name = \"Web3AuthFrameAuthenticationError\" as const\n messages = {\n dev: \"An error occurred when attempting to authenticate on Web3Auth\",\n user: \"Authentication error\",\n }\n}\n\nexport class Web3AuthFrameFxhashAuthenticationError extends RichError {\n name = \"Web3AuthFrameFxhashAuthenticationError\" as const\n messages = {\n dev: \"An error occurred when attempting to authenticate on fxhash\",\n user: \"Authentication error\",\n }\n}\n\nexport class Web3AuthFrameLogoutFailedError extends RichError {\n name = \"Web3AuthFrameLogoutFailedError\" as const\n messages = {\n dev: \"Logout failed. This is likely an issue on fxhash end.\",\n user: \"Could not logout your account. Please try again.\",\n }\n}\n\nexport class Web3AuthInitializationFailedError extends RichError {\n name = \"Web3AuthInitializationFailedError\" as const\n messages = {\n dev: \"Web3Auth initialization failed, as such the embedded wallet cannot be constructed and used. If this issue persists, please raise it on Github.\",\n user: \"Could not initialize embedded wallet.\",\n }\n}\n\nexport class Web3AuthFrameUnknownError extends RichError {\n name = \"Web3AuthFrameUnknownError\" as const\n messages: {\n dev: string\n user: string\n } = {\n dev: \"An unexpected error was raised using Web3Auth\",\n user: UnexpectedRichErrorMessages.user,\n }\n}\n\nexport const Web3AuthFrameErrors: {\n init: (typeof Web3AuthInitializationFailedError)[]\n getSessionDetails: (typeof Web3AuthFrameAuthenticationError)[]\n login: (\n | typeof Web3AuthFrameAuthenticationError\n | typeof Web3AuthFrameFxhashAuthenticationError\n | typeof Web3AuthFrameUnknownError\n )[]\n logout: (typeof Web3AuthFrameLogoutFailedError)[]\n} = {\n init: [Web3AuthInitializationFailedError],\n getSessionDetails: [Web3AuthFrameAuthenticationError],\n login: [\n Web3AuthFrameAuthenticationError,\n Web3AuthFrameFxhashAuthenticationError,\n Web3AuthFrameUnknownError,\n ],\n logout: [Web3AuthFrameLogoutFailedError],\n}\n\nexport type Web3AuthFrameError = {\n [K in keyof typeof Web3AuthFrameErrors]: RichErrorUnion<\n (typeof Web3AuthFrameErrors)[K]\n >\n}\n\nexport type AllWeb3AuthFrameError = TypeOfRichError<\n Web3AuthFrameError[keyof Web3AuthFrameError]\n>\nexport const AllWeb3AuthFrameErrors: AllWeb3AuthFrameError[] =\n Array<AllWeb3AuthFrameError>().concat.apply(\n [],\n Object.values(Web3AuthFrameErrors) as any\n )\n"],"mappings":";AAiBO,IAAM,8BAET;AAAA,EACF,KAAK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O,IAAM,yBACX,MAA6B,EAAE,OAAO;AAAA,EACpC,CAAC;AAAA,EACD,OAAO,OAAO,mBAAmB;AACnC;","names":[]}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@fxhash/errors",
3
3
  "description": "Application-wide errors which are exposed and used by different parts of our stack.",
4
- "version": "0.0.10",
4
+ "version": "0.0.12",
5
5
  "author": "fxhash",
6
6
  "dependencies": {
7
7
  "@urql/core": "4.1.4",
8
- "@fxhash/utils": "0.0.3"
8
+ "@fxhash/utils": "0.0.5"
9
9
  },
10
10
  "devDependencies": {
11
11
  "@types/node": "18.7.13",
@@ -13,7 +13,7 @@
13
13
  "tsup": "8.4.0",
14
14
  "typescript": "5.8.2",
15
15
  "unplugin-isolated-decl": "0.13.6",
16
- "@fxhash/tsconfig": "0.0.1"
16
+ "@fxhash/tsconfig": "0.0.3"
17
17
  },
18
18
  "exports": {
19
19
  ".": {