@stackframe/stack-shared 2.8.35 → 2.8.36

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/config/schema.d.mts +167 -107
  3. package/dist/config/schema.d.ts +167 -107
  4. package/dist/config/schema.js +39 -25
  5. package/dist/config/schema.js.map +1 -1
  6. package/dist/esm/config/schema.js +39 -25
  7. package/dist/esm/config/schema.js.map +1 -1
  8. package/dist/esm/helpers/vault/client-side.js +46 -0
  9. package/dist/esm/helpers/vault/client-side.js.map +1 -0
  10. package/dist/esm/helpers/vault/server-side.js +92 -0
  11. package/dist/esm/helpers/vault/server-side.js.map +1 -0
  12. package/dist/esm/hooks/use-hover.js +71 -0
  13. package/dist/esm/hooks/use-hover.js.map +1 -0
  14. package/dist/esm/interface/admin-interface.js +21 -3
  15. package/dist/esm/interface/admin-interface.js.map +1 -1
  16. package/dist/esm/interface/server-interface.js +38 -0
  17. package/dist/esm/interface/server-interface.js.map +1 -1
  18. package/dist/esm/known-errors.js +38 -1
  19. package/dist/esm/known-errors.js.map +1 -1
  20. package/dist/esm/utils/bytes.js +1 -2
  21. package/dist/esm/utils/bytes.js.map +1 -1
  22. package/dist/esm/utils/crypto.js +83 -2
  23. package/dist/esm/utils/crypto.js.map +1 -1
  24. package/dist/esm/utils/numbers.js.map +1 -1
  25. package/dist/esm/utils/react.js +7 -3
  26. package/dist/esm/utils/react.js.map +1 -1
  27. package/dist/helpers/password.d.mts +4 -4
  28. package/dist/helpers/password.d.ts +4 -4
  29. package/dist/helpers/vault/client-side.d.mts +14 -0
  30. package/dist/helpers/vault/client-side.d.ts +14 -0
  31. package/dist/helpers/vault/client-side.js +73 -0
  32. package/dist/helpers/vault/client-side.js.map +1 -0
  33. package/dist/helpers/vault/server-side.d.mts +7 -0
  34. package/dist/helpers/vault/server-side.d.ts +7 -0
  35. package/dist/helpers/vault/server-side.js +111 -0
  36. package/dist/helpers/vault/server-side.js.map +1 -0
  37. package/dist/hooks/use-hover.d.mts +6 -0
  38. package/dist/hooks/use-hover.d.ts +6 -0
  39. package/dist/hooks/use-hover.js +96 -0
  40. package/dist/hooks/use-hover.js.map +1 -0
  41. package/dist/index.d.mts +3 -3
  42. package/dist/index.d.ts +3 -3
  43. package/dist/interface/admin-interface.d.mts +11 -5
  44. package/dist/interface/admin-interface.d.ts +11 -5
  45. package/dist/interface/admin-interface.js +21 -3
  46. package/dist/interface/admin-interface.js.map +1 -1
  47. package/dist/interface/crud/current-user.d.mts +1 -1
  48. package/dist/interface/crud/current-user.d.ts +1 -1
  49. package/dist/interface/crud/project-api-keys.d.mts +4 -4
  50. package/dist/interface/crud/project-api-keys.d.ts +4 -4
  51. package/dist/interface/crud/team-member-profiles.d.mts +2 -2
  52. package/dist/interface/crud/team-member-profiles.d.ts +2 -2
  53. package/dist/interface/crud/users.d.mts +2 -2
  54. package/dist/interface/crud/users.d.ts +2 -2
  55. package/dist/interface/server-interface.d.mts +2 -0
  56. package/dist/interface/server-interface.d.ts +2 -0
  57. package/dist/interface/server-interface.js +38 -0
  58. package/dist/interface/server-interface.js.map +1 -1
  59. package/dist/known-errors.d.mts +9 -0
  60. package/dist/known-errors.d.ts +9 -0
  61. package/dist/known-errors.js +38 -1
  62. package/dist/known-errors.js.map +1 -1
  63. package/dist/schema-fields.d.mts +1 -1
  64. package/dist/schema-fields.d.ts +1 -1
  65. package/dist/utils/bytes.js +1 -2
  66. package/dist/utils/bytes.js.map +1 -1
  67. package/dist/utils/crypto.d.mts +31 -1
  68. package/dist/utils/crypto.d.ts +31 -1
  69. package/dist/utils/crypto.js +87 -2
  70. package/dist/utils/crypto.js.map +1 -1
  71. package/dist/utils/numbers.js.map +1 -1
  72. package/dist/utils/react.js +7 -3
  73. package/dist/utils/react.js.map +1 -1
  74. package/package.json +2 -1
@@ -483,6 +483,15 @@ declare const KnownErrors: {
483
483
  ItemQuantityInsufficientAmount: KnownErrorConstructor<KnownError & KnownErrorBrand<"ITEM_QUANTITY_INSUFFICIENT_AMOUNT">, [itemId: string, customerId: string, quantity: number]> & {
484
484
  errorCode: "ITEM_QUANTITY_INSUFFICIENT_AMOUNT";
485
485
  };
486
+ StripeAccountInfoNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"STRIPE_ACCOUNT_INFO_NOT_FOUND">, []> & {
487
+ errorCode: "STRIPE_ACCOUNT_INFO_NOT_FOUND";
488
+ };
489
+ DataVaultStoreDoesNotExist: KnownErrorConstructor<KnownError & KnownErrorBrand<"DATA_VAULT_STORE_DOES_NOT_EXIST">, [storeId: string]> & {
490
+ errorCode: "DATA_VAULT_STORE_DOES_NOT_EXIST";
491
+ };
492
+ DataVaultStoreHashedKeyDoesNotExist: KnownErrorConstructor<KnownError & KnownErrorBrand<"DATA_VAULT_STORE_HASHED_KEY_DOES_NOT_EXIST">, [storeId: string, hashedKey: string]> & {
493
+ errorCode: "DATA_VAULT_STORE_HASHED_KEY_DOES_NOT_EXIST";
494
+ };
486
495
  };
487
496
 
488
497
  export { type AbstractKnownErrorConstructor, KnownError, type KnownErrorConstructor, type KnownErrorJson, KnownErrors };
@@ -580,6 +580,31 @@ var PasswordAuthenticationNotEnabled = createKnownErrorConstructor(
580
580
  ],
581
581
  () => []
582
582
  );
583
+ var DataVaultStoreDoesNotExist = createKnownErrorConstructor(
584
+ KnownError,
585
+ "DATA_VAULT_STORE_DOES_NOT_EXIST",
586
+ (storeId) => [
587
+ 400,
588
+ `Data vault store with ID ${storeId} does not exist.`,
589
+ {
590
+ store_id: storeId
591
+ }
592
+ ],
593
+ (json) => [json.store_id]
594
+ );
595
+ var DataVaultStoreHashedKeyDoesNotExist = createKnownErrorConstructor(
596
+ KnownError,
597
+ "DATA_VAULT_STORE_HASHED_KEY_DOES_NOT_EXIST",
598
+ (storeId, hashedKey) => [
599
+ 400,
600
+ `Data vault store with ID ${storeId} does not contain a key with hash ${hashedKey}.`,
601
+ {
602
+ store_id: storeId,
603
+ hashed_key: hashedKey
604
+ }
605
+ ],
606
+ (json) => [json.store_id, json.hashed_key]
607
+ );
583
608
  var PasskeyAuthenticationNotEnabled = createKnownErrorConstructor(
584
609
  KnownError,
585
610
  "PASSKEY_AUTHENTICATION_NOT_ENABLED",
@@ -1304,6 +1329,15 @@ var ItemQuantityInsufficientAmount = createKnownErrorConstructor(
1304
1329
  ],
1305
1330
  (json) => [json.item_id, json.customer_id, json.quantity]
1306
1331
  );
1332
+ var StripeAccountInfoNotFound = createKnownErrorConstructor(
1333
+ KnownError,
1334
+ "STRIPE_ACCOUNT_INFO_NOT_FOUND",
1335
+ () => [
1336
+ 404,
1337
+ "Stripe account information not found. Please make sure the user has onboarded with Stripe."
1338
+ ],
1339
+ () => []
1340
+ );
1307
1341
  var KnownErrors = {
1308
1342
  CannotDeleteCurrentSession,
1309
1343
  UnsupportedError,
@@ -1420,7 +1454,10 @@ var KnownErrors = {
1420
1454
  CustomerDoesNotExist,
1421
1455
  OfferDoesNotExist,
1422
1456
  OfferCustomerTypeDoesNotMatch,
1423
- ItemQuantityInsufficientAmount
1457
+ ItemQuantityInsufficientAmount,
1458
+ StripeAccountInfoNotFound,
1459
+ DataVaultStoreDoesNotExist,
1460
+ DataVaultStoreHashedKeyDoesNotExist
1424
1461
  };
1425
1462
  var knownErrorCodes = /* @__PURE__ */ new Set();
1426
1463
  for (const [_, KnownError2] of Object.entries(KnownErrors)) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/known-errors.tsx"],"sourcesContent":["import { StackAssertionError, StatusError, throwErr } from \"./utils/errors\";\nimport { identityArgs } from \"./utils/functions\";\nimport { Json } from \"./utils/json\";\nimport { deindent } from \"./utils/strings\";\n\nexport type KnownErrorJson = {\n code: string,\n message: string,\n details?: Json,\n};\n\nexport type AbstractKnownErrorConstructor<Args extends any[]> =\n & (abstract new (...args: Args) => KnownError)\n & {\n constructorArgsFromJson: (json: KnownErrorJson) => Args,\n };\n\nexport type KnownErrorConstructor<SuperInstance extends KnownError, Args extends any[]> = {\n new (...args: Args): SuperInstance & { constructorArgs: Args },\n errorCode: string,\n constructorArgsFromJson: (json: KnownErrorJson) => Args,\n isInstance: (error: unknown) => error is SuperInstance & { constructorArgs: Args },\n};\n\nexport abstract class KnownError extends StatusError {\n private readonly __stackKnownErrorBrand = \"stack-known-error-brand-sentinel\" as const;\n public name = \"KnownError\";\n\n constructor(\n public readonly statusCode: number,\n public readonly humanReadableMessage: string,\n public readonly details?: Json,\n ) {\n super(\n statusCode,\n humanReadableMessage\n );\n }\n\n public static isKnownError(error: unknown): error is KnownError {\n // like instanceof, but also works for errors thrown in other realms or by different versions of the same package\n return typeof error === \"object\" && error !== null && \"__stackKnownErrorBrand\" in error && error.__stackKnownErrorBrand === \"stack-known-error-brand-sentinel\";\n }\n\n public override getBody(): Uint8Array {\n return new TextEncoder().encode(JSON.stringify(this.toDescriptiveJson(), undefined, 2));\n }\n\n public override getHeaders(): Record<string, string[]> {\n return {\n \"Content-Type\": [\"application/json; charset=utf-8\"],\n \"X-Stack-Known-Error\": [this.errorCode],\n };\n }\n\n public override toDescriptiveJson(): Json {\n return {\n code: this.errorCode,\n ...this.details ? { details: this.details } : {},\n error: this.humanReadableMessage,\n };\n }\n\n get errorCode(): string {\n return (this.constructor as any).errorCode ?? throwErr(`Can't find error code for this KnownError. Is its constructor a KnownErrorConstructor? ${this}`);\n }\n\n public static constructorArgsFromJson(json: KnownErrorJson): ConstructorParameters<typeof KnownError> {\n return [\n 400,\n json.message,\n json,\n ];\n }\n\n public static fromJson(json: KnownErrorJson): KnownError {\n for (const [_, KnownErrorType] of Object.entries(KnownErrors)) {\n if (json.code === KnownErrorType.prototype.errorCode) {\n const constructorArgs = KnownErrorType.constructorArgsFromJson(json);\n return new KnownErrorType(\n // @ts-ignore-next-line\n ...constructorArgs,\n );\n }\n }\n\n throw new Error(`Unknown KnownError code. You may need to update your version of Stack to see more detailed information. ${json.code}: ${json.message}`);\n }\n}\n\nconst knownErrorConstructorErrorCodeSentinel = Symbol(\"knownErrorConstructorErrorCodeSentinel\");\n/**\n * Exists solely so that known errors are nominative types (ie. two KnownErrors with the same interface are not the same type)\n */\ntype KnownErrorBrand<ErrorCode extends string> = {\n /**\n * Does not exist at runtime\n *\n * Must be an object because it may be true for multiple error codes (it's true for all parents)\n */\n [knownErrorConstructorErrorCodeSentinel]: {\n [K in ErrorCode]: true\n },\n};\n\nfunction createKnownErrorConstructor<ErrorCode extends string, Super extends AbstractKnownErrorConstructor<any>, Args extends any[]>(\n SuperClass: Super,\n errorCode: ErrorCode,\n create: ((...args: Args) => Readonly<ConstructorParameters<Super>>),\n constructorArgsFromJson: ((jsonDetails: any) => Args),\n): KnownErrorConstructor<InstanceType<Super> & KnownErrorBrand<ErrorCode>, Args> & { errorCode: ErrorCode };\nfunction createKnownErrorConstructor<ErrorCode extends string, Super extends AbstractKnownErrorConstructor<any>>(\n SuperClass: Super,\n errorCode: ErrorCode,\n create: \"inherit\",\n constructorArgsFromJson: \"inherit\",\n): KnownErrorConstructor<InstanceType<Super> & KnownErrorBrand<ErrorCode>, ConstructorParameters<Super>> & { errorCode: ErrorCode };\nfunction createKnownErrorConstructor<ErrorCode extends string, Super extends AbstractKnownErrorConstructor<any>, Args extends any[]>(\n SuperClass: Super,\n errorCode: ErrorCode,\n create: \"inherit\" | ((...args: Args) => Readonly<ConstructorParameters<Super>>),\n constructorArgsFromJson: \"inherit\" | ((jsonDetails: any) => Args),\n): KnownErrorConstructor<InstanceType<Super> & KnownErrorBrand<ErrorCode>, Args> & { errorCode: ErrorCode } {\n const createFn = create === \"inherit\" ? identityArgs<Args> as never : create;\n const constructorArgsFromJsonFn = constructorArgsFromJson === \"inherit\" ? SuperClass.constructorArgsFromJson as never : constructorArgsFromJson;\n\n // @ts-expect-error this is not a mixin, but TS detects it as one\n class KnownErrorImpl extends SuperClass {\n public static readonly errorCode = errorCode;\n public name = `KnownError<${errorCode}>`;\n public readonly constructorArgs: Args;\n\n constructor(...args: Args) {\n // @ts-expect-error DEVIN, STOP REMOVING THIS LINE YOU DUMBASS, YES TYPESCRIPT DOES THROW AN ERROR IF YOU DON'T HAVE IT, NO THIS IS NOT \"UNUSED\", AND YES YOU ARE BREAKING OUR CI PIPELINE EVERY TIME YOU DO IT\n super(...createFn(...args));\n this.constructorArgs = args;\n }\n\n static constructorArgsFromJson(json: KnownErrorJson): Args {\n return constructorArgsFromJsonFn(json.details);\n }\n\n static isInstance(error: unknown): error is InstanceType<Super> & { constructorArgs: Args } {\n if (!KnownError.isKnownError(error)) return false;\n let current: unknown = error;\n while (true) {\n current = Object.getPrototypeOf(current);\n if (!current) break;\n if (\"errorCode\" in current.constructor && current.constructor.errorCode === errorCode) return true;\n }\n return false;\n }\n };\n\n // @ts-expect-error\n return KnownErrorImpl;\n}\nundefined?.test(\"KnownError.isInstance\", ({ expect }) => {\n expect(KnownErrors.InvalidProjectAuthentication.isInstance(undefined)).toBe(false);\n expect(KnownErrors.InvalidProjectAuthentication.isInstance(new Error())).toBe(false);\n\n const error = new KnownErrors.ProjectKeyWithoutAccessType();\n expect(KnownErrors.ProjectKeyWithoutAccessType.isInstance(error)).toBe(true);\n expect(KnownErrors.InvalidProjectAuthentication.isInstance(error)).toBe(true);\n expect(KnownErrors.InvalidAccessType.isInstance(error)).toBe(false);\n});\n\nconst UnsupportedError = createKnownErrorConstructor(\n KnownError,\n \"UNSUPPORTED_ERROR\",\n (originalErrorCode: string) => [\n 500,\n `An error occurred that is not currently supported (possibly because it was added in a version of Stack that is newer than this client). The original unsupported error code was: ${originalErrorCode}`,\n {\n originalErrorCode,\n },\n ] as const,\n (json) => [\n (json as any)?.originalErrorCode ?? throwErr(\"originalErrorCode not found in UnsupportedError details\"),\n ] as const,\n);\n\nconst BodyParsingError = createKnownErrorConstructor(\n KnownError,\n \"BODY_PARSING_ERROR\",\n (message: string) => [\n 400,\n message,\n ] as const,\n (json) => [json.message] as const,\n);\n\nconst SchemaError = createKnownErrorConstructor(\n KnownError,\n \"SCHEMA_ERROR\",\n (message: string) => [\n 400,\n message || throwErr(\"SchemaError requires a message\"),\n {\n message,\n },\n ] as const,\n (json: any) => [json.message] as const,\n);\n\nconst AllOverloadsFailed = createKnownErrorConstructor(\n KnownError,\n \"ALL_OVERLOADS_FAILED\",\n (overloadErrors: Json[]) => [\n 400,\n deindent`\n This endpoint has multiple overloads, but they all failed to process the request.\n\n ${overloadErrors.map((e, i) => deindent`\n Overload ${i + 1}: ${JSON.stringify(e, undefined, 2)}\n `).join(\"\\n\\n\")}\n `,\n {\n overload_errors: overloadErrors,\n },\n ] as const,\n (json) => [\n (json as any)?.overload_errors ?? throwErr(\"overload_errors not found in AllOverloadsFailed details\"),\n ] as const,\n);\n\nconst ProjectAuthenticationError = createKnownErrorConstructor(\n KnownError,\n \"PROJECT_AUTHENTICATION_ERROR\",\n \"inherit\",\n \"inherit\",\n);\n\nconst InvalidProjectAuthentication = createKnownErrorConstructor(\n ProjectAuthenticationError,\n \"INVALID_PROJECT_AUTHENTICATION\",\n \"inherit\",\n \"inherit\",\n);\n\nconst ProjectKeyWithoutAccessType = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"PROJECT_KEY_WITHOUT_ACCESS_TYPE\",\n () => [\n 400,\n \"Either an API key or an admin access token was provided, but the x-stack-access-type header is missing. Set it to 'client', 'server', or 'admin' as appropriate.\",\n ] as const,\n () => [] as const,\n);\n\nconst InvalidAccessType = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"INVALID_ACCESS_TYPE\",\n (accessType: string) => [\n 400,\n `The x-stack-access-type header must be 'client', 'server', or 'admin', but was '${accessType}'.`,\n ] as const,\n (json) => [\n (json as any)?.accessType ?? throwErr(\"accessType not found in InvalidAccessType details\"),\n ] as const,\n);\n\nconst AccessTypeWithoutProjectId = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"ACCESS_TYPE_WITHOUT_PROJECT_ID\",\n (accessType: \"client\" | \"server\" | \"admin\") => [\n 400,\n deindent`\n The x-stack-access-type header was '${accessType}', but the x-stack-project-id header was not provided.\n \n For more information, see the docs on REST API authentication: https://docs.stack-auth.com/rest-api/overview#authentication\n `,\n {\n request_type: accessType,\n },\n ] as const,\n (json: any) => [json.request_type] as const,\n);\n\nconst AccessTypeRequired = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"ACCESS_TYPE_REQUIRED\",\n () => [\n 400,\n deindent`\n You must specify an access level for this Stack project. Make sure project API keys are provided (eg. x-stack-publishable-client-key) and you set the x-stack-access-type header to 'client', 'server', or 'admin'.\n \n For more information, see the docs on REST API authentication: https://docs.stack-auth.com/rest-api/overview#authentication\n `,\n ] as const,\n () => [] as const,\n);\n\nconst InsufficientAccessType = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"INSUFFICIENT_ACCESS_TYPE\",\n (actualAccessType: \"client\" | \"server\" | \"admin\", allowedAccessTypes: (\"client\" | \"server\" | \"admin\")[]) => [\n 401,\n `The x-stack-access-type header must be ${allowedAccessTypes.map(s => `'${s}'`).join(\" or \")}, but was '${actualAccessType}'.`,\n {\n actual_access_type: actualAccessType,\n allowed_access_types: allowedAccessTypes,\n },\n ] as const,\n (json: any) => [\n json.actual_access_type,\n json.allowed_access_types,\n ] as const,\n);\n\nconst InvalidPublishableClientKey = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"INVALID_PUBLISHABLE_CLIENT_KEY\",\n (projectId: string) => [\n 401,\n `The publishable key is not valid for the project ${JSON.stringify(projectId)}. Does the project and/or the key exist?`,\n {\n project_id: projectId,\n },\n ] as const,\n (json: any) => [json.project_id] as const,\n);\n\nconst InvalidSecretServerKey = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"INVALID_SECRET_SERVER_KEY\",\n (projectId: string) => [\n 401,\n `The secret server key is not valid for the project ${JSON.stringify(projectId)}. Does the project and/or the key exist?`,\n {\n project_id: projectId,\n },\n ] as const,\n (json: any) => [json.project_id] as const,\n);\n\nconst InvalidSuperSecretAdminKey = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"INVALID_SUPER_SECRET_ADMIN_KEY\",\n (projectId: string) => [\n 401,\n `The super secret admin key is not valid for the project ${JSON.stringify(projectId)}. Does the project and/or the key exist?`,\n {\n project_id: projectId,\n },\n ] as const,\n (json: any) => [json.project_id] as const,\n);\n\nconst InvalidAdminAccessToken = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"INVALID_ADMIN_ACCESS_TOKEN\",\n \"inherit\",\n \"inherit\",\n);\n\nconst UnparsableAdminAccessToken = createKnownErrorConstructor(\n InvalidAdminAccessToken,\n \"UNPARSABLE_ADMIN_ACCESS_TOKEN\",\n () => [\n 401,\n \"Admin access token is not parsable.\",\n ] as const,\n () => [] as const,\n);\n\nconst AdminAccessTokenExpired = createKnownErrorConstructor(\n InvalidAdminAccessToken,\n \"ADMIN_ACCESS_TOKEN_EXPIRED\",\n (expiredAt: Date | undefined) => [\n 401,\n `Admin access token has expired. Please refresh it and try again.${expiredAt ? ` (The access token expired at ${expiredAt.toISOString()}.)`: \"\"}`,\n { expired_at_millis: expiredAt?.getTime() ?? null },\n ] as const,\n (json: any) => [json.expired_at_millis ?? undefined] as const,\n);\n\nconst InvalidProjectForAdminAccessToken = createKnownErrorConstructor(\n InvalidAdminAccessToken,\n \"INVALID_PROJECT_FOR_ADMIN_ACCESS_TOKEN\",\n () => [\n 401,\n \"Admin access tokens must be created on the internal project.\",\n ] as const,\n () => [] as const,\n);\n\nconst AdminAccessTokenIsNotAdmin = createKnownErrorConstructor(\n InvalidAdminAccessToken,\n \"ADMIN_ACCESS_TOKEN_IS_NOT_ADMIN\",\n () => [\n 401,\n \"Admin access token does not have the required permissions to access this project.\",\n ] as const,\n () => [] as const,\n);\n\n/**\n * @deprecated Use InsufficientAccessType instead\n */\nconst ProjectAuthenticationRequired = createKnownErrorConstructor(\n ProjectAuthenticationError,\n \"PROJECT_AUTHENTICATION_REQUIRED\",\n \"inherit\",\n \"inherit\",\n);\n\n\n/**\n * @deprecated Use InsufficientAccessType instead\n */\nconst ClientAuthenticationRequired = createKnownErrorConstructor(\n ProjectAuthenticationRequired,\n \"CLIENT_AUTHENTICATION_REQUIRED\",\n () => [\n 401,\n \"The publishable client key must be provided.\",\n ] as const,\n () => [] as const,\n);\n\n/**\n * @deprecated Use InsufficientAccessType instead\n */\nconst ServerAuthenticationRequired = createKnownErrorConstructor(\n ProjectAuthenticationRequired,\n \"SERVER_AUTHENTICATION_REQUIRED\",\n () => [\n 401,\n \"The secret server key must be provided.\",\n ] as const,\n () => [] as const,\n);\n\n/**\n * @deprecated Use InsufficientAccessType instead\n */\nconst ClientOrServerAuthenticationRequired = createKnownErrorConstructor(\n ProjectAuthenticationRequired,\n \"CLIENT_OR_SERVER_AUTHENTICATION_REQUIRED\",\n () => [\n 401,\n \"Either the publishable client key or the secret server key must be provided.\",\n ] as const,\n () => [] as const,\n);\n\n/**\n * @deprecated Use InsufficientAccessType instead\n */\nconst ClientOrAdminAuthenticationRequired = createKnownErrorConstructor(\n ProjectAuthenticationRequired,\n \"CLIENT_OR_ADMIN_AUTHENTICATION_REQUIRED\",\n () => [\n 401,\n \"Either the publishable client key or the super secret admin key must be provided.\",\n ] as const,\n () => [] as const,\n);\n\n/**\n * @deprecated Use InsufficientAccessType instead\n */\nconst ClientOrServerOrAdminAuthenticationRequired = createKnownErrorConstructor(\n ProjectAuthenticationRequired,\n \"CLIENT_OR_SERVER_OR_ADMIN_AUTHENTICATION_REQUIRED\",\n () => [\n 401,\n \"Either the publishable client key, the secret server key, or the super secret admin key must be provided.\",\n ] as const,\n () => [] as const,\n);\n\n/**\n * @deprecated Use InsufficientAccessType instead\n */\nconst AdminAuthenticationRequired = createKnownErrorConstructor(\n ProjectAuthenticationRequired,\n \"ADMIN_AUTHENTICATION_REQUIRED\",\n () => [\n 401,\n \"The super secret admin key must be provided.\",\n ] as const,\n () => [] as const,\n);\n\nconst ExpectedInternalProject = createKnownErrorConstructor(\n ProjectAuthenticationError,\n \"EXPECTED_INTERNAL_PROJECT\",\n () => [\n 401,\n \"The project ID is expected to be internal.\",\n ] as const,\n () => [] as const,\n);\n\nconst SessionAuthenticationError = createKnownErrorConstructor(\n KnownError,\n \"SESSION_AUTHENTICATION_ERROR\",\n \"inherit\",\n \"inherit\",\n);\n\nconst InvalidSessionAuthentication = createKnownErrorConstructor(\n SessionAuthenticationError,\n \"INVALID_SESSION_AUTHENTICATION\",\n \"inherit\",\n \"inherit\",\n);\n\nconst InvalidAccessToken = createKnownErrorConstructor(\n InvalidSessionAuthentication,\n \"INVALID_ACCESS_TOKEN\",\n \"inherit\",\n \"inherit\",\n);\n\nconst UnparsableAccessToken = createKnownErrorConstructor(\n InvalidAccessToken,\n \"UNPARSABLE_ACCESS_TOKEN\",\n () => [\n 401,\n \"Access token is not parsable.\",\n ] as const,\n () => [] as const,\n);\n\nconst AccessTokenExpired = createKnownErrorConstructor(\n InvalidAccessToken,\n \"ACCESS_TOKEN_EXPIRED\",\n (expiredAt: Date | undefined) => [\n 401,\n `Access token has expired. Please refresh it and try again.${expiredAt ? ` (The access token expired at ${expiredAt.toISOString()}.)`: \"\"}`,\n { expired_at_millis: expiredAt?.getTime() ?? null },\n ] as const,\n (json: any) => [json.expired_at_millis ? new Date(json.expired_at_millis) : undefined] as const,\n);\n\nconst InvalidProjectForAccessToken = createKnownErrorConstructor(\n InvalidAccessToken,\n \"INVALID_PROJECT_FOR_ACCESS_TOKEN\",\n (expectedProjectId: string, actualProjectId: string) => [\n 401,\n `Access token not valid for this project. Expected project ID ${JSON.stringify(expectedProjectId)}, but the token is for project ID ${JSON.stringify(actualProjectId)}.`,\n {\n expected_project_id: expectedProjectId,\n actual_project_id: actualProjectId,\n },\n ] as const,\n (json: any) => [json.expected_project_id, json.actual_project_id] as const,\n);\n\n\nconst RefreshTokenError = createKnownErrorConstructor(\n KnownError,\n \"REFRESH_TOKEN_ERROR\",\n \"inherit\",\n \"inherit\",\n);\n\nconst RefreshTokenNotFoundOrExpired = createKnownErrorConstructor(\n RefreshTokenError,\n \"REFRESH_TOKEN_NOT_FOUND_OR_EXPIRED\",\n () => [\n 401,\n \"Refresh token not found for this project, or the session has expired/been revoked.\",\n ] as const,\n () => [] as const,\n);\n\nconst CannotDeleteCurrentSession = createKnownErrorConstructor(\n RefreshTokenError,\n \"CANNOT_DELETE_CURRENT_SESSION\",\n () => [\n 400,\n \"Cannot delete the current session.\",\n ] as const,\n () => [] as const,\n);\n\n\nconst ProviderRejected = createKnownErrorConstructor(\n RefreshTokenError,\n \"PROVIDER_REJECTED\",\n () => [\n 401,\n \"The provider refused to refresh their token. This usually means that the provider used to authenticate the user no longer regards this session as valid, and the user must re-authenticate.\",\n ] as const,\n () => [] as const,\n);\n\nconst UserWithEmailAlreadyExists = createKnownErrorConstructor(\n KnownError,\n \"USER_EMAIL_ALREADY_EXISTS\",\n (email: string, wouldWorkIfEmailWasVerified: boolean = false) => [\n 409,\n `A user with email ${JSON.stringify(email)} already exists${wouldWorkIfEmailWasVerified ? \" but the email is not verified. Please login to your existing account with the method you used to sign up, and then verify your email to sign in with this login method.\" : \".\"}`,\n {\n email,\n would_work_if_email_was_verified: wouldWorkIfEmailWasVerified,\n },\n ] as const,\n (json: any) => [json.email, json.would_work_if_email_was_verified ?? false] as const,\n);\n\nconst EmailNotVerified = createKnownErrorConstructor(\n KnownError,\n \"EMAIL_NOT_VERIFIED\",\n () => [\n 400,\n \"The email is not verified.\",\n ] as const,\n () => [] as const,\n);\n\nconst CannotGetOwnUserWithoutUser = createKnownErrorConstructor(\n KnownError,\n \"CANNOT_GET_OWN_USER_WITHOUT_USER\",\n () => [\n 400,\n \"You have specified 'me' as a userId, but did not provide authentication for a user.\",\n ] as const,\n () => [] as const,\n);\n\nconst UserIdDoesNotExist = createKnownErrorConstructor(\n KnownError,\n \"USER_ID_DOES_NOT_EXIST\",\n (userId: string) => [\n 400,\n `The given user with the ID ${userId} does not exist.`,\n {\n user_id: userId,\n },\n ] as const,\n (json: any) => [json.user_id] as const,\n);\n\nconst UserNotFound = createKnownErrorConstructor(\n KnownError,\n \"USER_NOT_FOUND\",\n () => [\n 404,\n \"User not found.\",\n ] as const,\n () => [] as const,\n);\n\n\nconst ProjectNotFound = createKnownErrorConstructor(\n KnownError,\n \"PROJECT_NOT_FOUND\",\n (projectId: string) => {\n if (typeof projectId !== \"string\") throw new StackAssertionError(\"projectId of KnownErrors.ProjectNotFound must be a string\");\n return [\n 404,\n `Project ${projectId} not found or is not accessible with the current user.`,\n {\n project_id: projectId,\n },\n ] as const;\n },\n (json: any) => [json.project_id] as const,\n);\n\nconst CurrentProjectNotFound = createKnownErrorConstructor(\n KnownError,\n \"CURRENT_PROJECT_NOT_FOUND\",\n (projectId: string) => [\n 400,\n `The current project with ID ${projectId} was not found. Please check the value of the x-stack-project-id header.`,\n {\n project_id: projectId,\n },\n ] as const,\n (json: any) => [json.project_id] as const,\n);\n\nconst BranchDoesNotExist = createKnownErrorConstructor(\n KnownError,\n \"BRANCH_DOES_NOT_EXIST\",\n (branchId: string) => [\n 400,\n `The branch with ID ${branchId} does not exist.`,\n {\n branch_id: branchId,\n },\n ] as const,\n (json: any) => [json.branch_id] as const,\n);\n\n\nconst SignUpNotEnabled = createKnownErrorConstructor(\n KnownError,\n \"SIGN_UP_NOT_ENABLED\",\n () => [\n 400,\n \"Creation of new accounts is not enabled for this project. Please ask the project owner to enable it.\",\n ] as const,\n () => [] as const,\n);\n\nconst PasswordAuthenticationNotEnabled = createKnownErrorConstructor(\n KnownError,\n \"PASSWORD_AUTHENTICATION_NOT_ENABLED\",\n () => [\n 400,\n \"Password authentication is not enabled for this project.\",\n ] as const,\n () => [] as const,\n);\n\n\nconst PasskeyAuthenticationNotEnabled = createKnownErrorConstructor(\n KnownError,\n \"PASSKEY_AUTHENTICATION_NOT_ENABLED\",\n () => [\n 400,\n \"Passkey authentication is not enabled for this project.\",\n ] as const,\n () => [] as const,\n);\n\nconst AnonymousAccountsNotEnabled = createKnownErrorConstructor(\n KnownError,\n \"ANONYMOUS_ACCOUNTS_NOT_ENABLED\",\n () => [\n 400,\n \"Anonymous accounts are not enabled for this project.\",\n ] as const,\n () => [] as const,\n);\n\nconst AnonymousAuthenticationNotAllowed = createKnownErrorConstructor(\n KnownError,\n \"ANONYMOUS_AUTHENTICATION_NOT_ALLOWED\",\n () => [\n 401,\n \"X-Stack-Access-Token is for an anonymous user, but anonymous users are not enabled. Set the X-Stack-Allow-Anonymous-User header of this request to 'true' to allow anonymous users.\",\n ] as const,\n () => [] as const,\n);\n\n\nconst EmailPasswordMismatch = createKnownErrorConstructor(\n KnownError,\n \"EMAIL_PASSWORD_MISMATCH\",\n () => [\n 400,\n \"Wrong e-mail or password.\",\n ] as const,\n () => [] as const,\n);\n\nconst RedirectUrlNotWhitelisted = createKnownErrorConstructor(\n KnownError,\n \"REDIRECT_URL_NOT_WHITELISTED\",\n () => [\n 400,\n \"Redirect URL not whitelisted. Did you forget to add this domain to the trusted domains list on the Stack Auth dashboard?\",\n ] as const,\n () => [] as const,\n);\n\nconst PasswordRequirementsNotMet = createKnownErrorConstructor(\n KnownError,\n \"PASSWORD_REQUIREMENTS_NOT_MET\",\n \"inherit\",\n \"inherit\",\n);\n\nconst PasswordTooShort = createKnownErrorConstructor(\n PasswordRequirementsNotMet,\n \"PASSWORD_TOO_SHORT\",\n (minLength: number) => [\n 400,\n `Password too short. Minimum length is ${minLength}.`,\n {\n min_length: minLength,\n },\n ] as const,\n (json) => [\n (json as any)?.min_length ?? throwErr(\"min_length not found in PasswordTooShort details\"),\n ] as const,\n);\n\nconst PasswordTooLong = createKnownErrorConstructor(\n PasswordRequirementsNotMet,\n \"PASSWORD_TOO_LONG\",\n (maxLength: number) => [\n 400,\n `Password too long. Maximum length is ${maxLength}.`,\n {\n maxLength,\n },\n ] as const,\n (json) => [\n (json as any)?.maxLength ?? throwErr(\"maxLength not found in PasswordTooLong details\"),\n ] as const,\n);\n\nconst UserDoesNotHavePassword = createKnownErrorConstructor(\n KnownError,\n \"USER_DOES_NOT_HAVE_PASSWORD\",\n () => [\n 400,\n \"This user does not have password authentication enabled.\",\n ] as const,\n () => [] as const,\n);\n\nconst VerificationCodeError = createKnownErrorConstructor(\n KnownError,\n \"VERIFICATION_ERROR\",\n \"inherit\",\n \"inherit\",\n);\n\nconst VerificationCodeNotFound = createKnownErrorConstructor(\n VerificationCodeError,\n \"VERIFICATION_CODE_NOT_FOUND\",\n () => [\n 404,\n \"The verification code does not exist for this project.\",\n ] as const,\n () => [] as const,\n);\n\nconst VerificationCodeExpired = createKnownErrorConstructor(\n VerificationCodeError,\n \"VERIFICATION_CODE_EXPIRED\",\n () => [\n 400,\n \"The verification code has expired.\",\n ] as const,\n () => [] as const,\n);\n\nconst VerificationCodeAlreadyUsed = createKnownErrorConstructor(\n VerificationCodeError,\n \"VERIFICATION_CODE_ALREADY_USED\",\n () => [\n 409,\n \"The verification link has already been used.\",\n ] as const,\n () => [] as const,\n);\n\nconst VerificationCodeMaxAttemptsReached = createKnownErrorConstructor(\n VerificationCodeError,\n \"VERIFICATION_CODE_MAX_ATTEMPTS_REACHED\",\n () => [\n 400,\n \"The verification code nonce has reached the maximum number of attempts. This code is not valid anymore.\",\n ] as const,\n () => [] as const,\n);\n\nconst PasswordConfirmationMismatch = createKnownErrorConstructor(\n KnownError,\n \"PASSWORD_CONFIRMATION_MISMATCH\",\n () => [\n 400,\n \"Passwords do not match.\",\n ] as const,\n () => [] as const,\n);\n\nconst EmailAlreadyVerified = createKnownErrorConstructor(\n KnownError,\n \"EMAIL_ALREADY_VERIFIED\",\n () => [\n 409,\n \"The e-mail is already verified.\",\n ] as const,\n () => [] as const,\n);\n\nconst EmailNotAssociatedWithUser = createKnownErrorConstructor(\n KnownError,\n \"EMAIL_NOT_ASSOCIATED_WITH_USER\",\n () => [\n 400,\n \"The e-mail is not associated with a user that could log in with that e-mail.\",\n ] as const,\n () => [] as const,\n);\n\nconst EmailIsNotPrimaryEmail = createKnownErrorConstructor(\n KnownError,\n \"EMAIL_IS_NOT_PRIMARY_EMAIL\",\n (email: string, primaryEmail: string | null) => [\n 400,\n `The given e-mail (${email}) must equal the user's primary e-mail (${primaryEmail}).`,\n {\n email,\n primary_email: primaryEmail,\n },\n ] as const,\n (json: any) => [json.email, json.primary_email] as const,\n);\n\n\nconst PasskeyRegistrationFailed = createKnownErrorConstructor(\n KnownError,\n \"PASSKEY_REGISTRATION_FAILED\",\n (message: string) => [\n 400,\n message,\n ] as const,\n (json: any) => [json.message] as const,\n);\n\n\nconst PasskeyWebAuthnError = createKnownErrorConstructor(\n KnownError,\n \"PASSKEY_WEBAUTHN_ERROR\",\n (message: string, code: string) => [\n 400,\n message,\n {\n message,\n code,\n },\n ] as const,\n (json: any) => [json.message, json.code] as const,\n);\n\nconst PasskeyAuthenticationFailed = createKnownErrorConstructor(\n KnownError,\n \"PASSKEY_AUTHENTICATION_FAILED\",\n (message: string) => [\n 400,\n message,\n ] as const,\n (json: any) => [json.message] as const,\n);\n\n\nconst PermissionNotFound = createKnownErrorConstructor(\n KnownError,\n \"PERMISSION_NOT_FOUND\",\n (permissionId: string) => [\n 404,\n `Permission \"${permissionId}\" not found. Make sure you created it on the dashboard.`,\n {\n permission_id: permissionId,\n },\n ] as const,\n (json: any) => [json.permission_id] as const,\n);\n\nconst PermissionScopeMismatch = createKnownErrorConstructor(\n KnownError,\n \"WRONG_PERMISSION_SCOPE\",\n (permissionId: string, expectedScope: \"team\" | \"project\", actualScope: \"team\" | \"project\" | null) => [\n 404,\n `Permission ${JSON.stringify(permissionId)} not found. (It was found for a different scope ${JSON.stringify(actualScope)}, but scope ${JSON.stringify(expectedScope)} was expected.)`,\n {\n permission_id: permissionId,\n expected_scope: expectedScope,\n actual_scope: actualScope,\n },\n ] as const,\n (json: any) => [json.permission_id, json.expected_scope, json.actual_scope] as const,\n);\n\nconst ContainedPermissionNotFound = createKnownErrorConstructor(\n KnownError,\n \"CONTAINED_PERMISSION_NOT_FOUND\",\n (permissionId: string) => [\n 400,\n `Contained permission with ID \"${permissionId}\" not found. Make sure you created it on the dashboard.`,\n {\n permission_id: permissionId,\n },\n ] as const,\n (json: any) => [json.permission_id] as const,\n);\n\nconst TeamNotFound = createKnownErrorConstructor(\n KnownError,\n \"TEAM_NOT_FOUND\",\n (teamId: string) => [\n 404,\n `Team ${teamId} not found.`,\n {\n team_id: teamId,\n },\n ] as const,\n (json: any) => [json.team_id] as const,\n);\n\nconst TeamAlreadyExists = createKnownErrorConstructor(\n KnownError,\n \"TEAM_ALREADY_EXISTS\",\n (teamId: string) => [\n 409,\n `Team ${teamId} already exists.`,\n {\n team_id: teamId,\n },\n ] as const,\n (json: any) => [json.team_id] as const,\n);\n\nconst TeamMembershipNotFound = createKnownErrorConstructor(\n KnownError,\n \"TEAM_MEMBERSHIP_NOT_FOUND\",\n (teamId: string, userId: string) => [\n 404,\n `User ${userId} is not found in team ${teamId}.`,\n {\n team_id: teamId,\n user_id: userId,\n },\n ] as const,\n (json: any) => [json.team_id, json.user_id] as const,\n);\n\n\nconst EmailTemplateAlreadyExists = createKnownErrorConstructor(\n KnownError,\n \"EMAIL_TEMPLATE_ALREADY_EXISTS\",\n () => [\n 409,\n \"Email template already exists.\",\n ] as const,\n () => [] as const,\n);\n\nconst OAuthConnectionNotConnectedToUser = createKnownErrorConstructor(\n KnownError,\n \"OAUTH_CONNECTION_NOT_CONNECTED_TO_USER\",\n () => [\n 400,\n \"The OAuth connection is not connected to any user.\",\n ] as const,\n () => [] as const,\n);\n\nconst OAuthConnectionAlreadyConnectedToAnotherUser = createKnownErrorConstructor(\n KnownError,\n \"OAUTH_CONNECTION_ALREADY_CONNECTED_TO_ANOTHER_USER\",\n () => [\n 409,\n \"The OAuth connection is already connected to another user.\",\n ] as const,\n () => [] as const,\n);\n\nconst OAuthConnectionDoesNotHaveRequiredScope = createKnownErrorConstructor(\n KnownError,\n \"OAUTH_CONNECTION_DOES_NOT_HAVE_REQUIRED_SCOPE\",\n () => [\n 400,\n \"The OAuth connection does not have the required scope.\",\n ] as const,\n () => [] as const,\n);\n\nconst OAuthExtraScopeNotAvailableWithSharedOAuthKeys = createKnownErrorConstructor(\n KnownError,\n \"OAUTH_EXTRA_SCOPE_NOT_AVAILABLE_WITH_SHARED_OAUTH_KEYS\",\n () => [\n 400,\n \"Extra scopes are not available with shared OAuth keys. Please add your own OAuth keys on the Stack dashboard to use extra scopes.\",\n ] as const,\n () => [] as const,\n);\n\nconst OAuthAccessTokenNotAvailableWithSharedOAuthKeys = createKnownErrorConstructor(\n KnownError,\n \"OAUTH_ACCESS_TOKEN_NOT_AVAILABLE_WITH_SHARED_OAUTH_KEYS\",\n () => [\n 400,\n \"Access tokens are not available with shared OAuth keys. Please add your own OAuth keys on the Stack dashboard to use access tokens.\",\n ] as const,\n () => [] as const,\n);\n\nconst InvalidOAuthClientIdOrSecret = createKnownErrorConstructor(\n KnownError,\n \"INVALID_OAUTH_CLIENT_ID_OR_SECRET\",\n (clientId?: string) => [\n 400,\n \"The OAuth client ID or secret is invalid. The client ID must be equal to the project ID (potentially with a hash and a branch ID), and the client secret must be a publishable client key.\",\n {\n client_id: clientId ?? null,\n },\n ] as const,\n (json: any) => [json.client_id ?? undefined] as const,\n);\n\nconst InvalidScope = createKnownErrorConstructor(\n KnownError,\n \"INVALID_SCOPE\",\n (scope: string) => [\n 400,\n `The scope \"${scope}\" is not a valid OAuth scope for Stack.`,\n ] as const,\n (json: any) => [json.scope] as const,\n);\n\nconst UserAlreadyConnectedToAnotherOAuthConnection = createKnownErrorConstructor(\n KnownError,\n \"USER_ALREADY_CONNECTED_TO_ANOTHER_OAUTH_CONNECTION\",\n () => [\n 409,\n \"The user is already connected to another OAuth account. Did you maybe selected the wrong account?\",\n ] as const,\n () => [] as const,\n);\n\nconst OuterOAuthTimeout = createKnownErrorConstructor(\n KnownError,\n \"OUTER_OAUTH_TIMEOUT\",\n () => [\n 408,\n \"The OAuth flow has timed out. Please sign in again.\",\n ] as const,\n () => [] as const,\n);\n\nconst OAuthProviderNotFoundOrNotEnabled = createKnownErrorConstructor(\n KnownError,\n \"OAUTH_PROVIDER_NOT_FOUND_OR_NOT_ENABLED\",\n () => [\n 400,\n \"The OAuth provider is not found or not enabled.\",\n ] as const,\n () => [] as const,\n);\n\nconst OAuthProviderAccountIdAlreadyUsedForSignIn = createKnownErrorConstructor(\n KnownError,\n \"OAUTH_PROVIDER_ACCOUNT_ID_ALREADY_USED_FOR_SIGN_IN\",\n () => [\n 400,\n `A provider with the same account ID is already used for signing in.`,\n ] as const,\n () => [] as const,\n);\n\nconst MultiFactorAuthenticationRequired = createKnownErrorConstructor(\n KnownError,\n \"MULTI_FACTOR_AUTHENTICATION_REQUIRED\",\n (attemptCode: string) => [\n 400,\n `Multi-factor authentication is required for this user.`,\n {\n attempt_code: attemptCode,\n },\n ] as const,\n (json) => [json.attempt_code] as const,\n);\n\nconst InvalidTotpCode = createKnownErrorConstructor(\n KnownError,\n \"INVALID_TOTP_CODE\",\n () => [\n 400,\n \"The TOTP code is invalid. Please try again.\",\n ] as const,\n () => [] as const,\n);\n\nconst UserAuthenticationRequired = createKnownErrorConstructor(\n KnownError,\n \"USER_AUTHENTICATION_REQUIRED\",\n () => [\n 401,\n \"User authentication required for this endpoint.\",\n ] as const,\n () => [] as const,\n);\n\nconst TeamMembershipAlreadyExists = createKnownErrorConstructor(\n KnownError,\n \"TEAM_MEMBERSHIP_ALREADY_EXISTS\",\n () => [\n 409,\n \"Team membership already exists.\",\n ] as const,\n () => [] as const,\n);\n\nconst ProjectPermissionRequired = createKnownErrorConstructor(\n KnownError,\n \"PROJECT_PERMISSION_REQUIRED\",\n (userId, permissionId) => [\n 401,\n `User ${userId} does not have permission ${permissionId}.`,\n {\n user_id: userId,\n permission_id: permissionId,\n },\n ] as const,\n (json) => [json.user_id, json.permission_id] as const,\n);\n\nconst TeamPermissionRequired = createKnownErrorConstructor(\n KnownError,\n \"TEAM_PERMISSION_REQUIRED\",\n (teamId, userId, permissionId) => [\n 401,\n `User ${userId} does not have permission ${permissionId} in team ${teamId}.`,\n {\n team_id: teamId,\n user_id: userId,\n permission_id: permissionId,\n },\n ] as const,\n (json) => [json.team_id, json.user_id, json.permission_id] as const,\n);\n\nconst TeamPermissionNotFound = createKnownErrorConstructor(\n KnownError,\n \"TEAM_PERMISSION_NOT_FOUND\",\n (teamId, userId, permissionId) => [\n 401,\n `User ${userId} does not have permission ${permissionId} in team ${teamId}.`,\n {\n team_id: teamId,\n user_id: userId,\n permission_id: permissionId,\n },\n ] as const,\n (json) => [json.team_id, json.user_id, json.permission_id] as const,\n);\n\nconst InvalidSharedOAuthProviderId = createKnownErrorConstructor(\n KnownError,\n \"INVALID_SHARED_OAUTH_PROVIDER_ID\",\n (providerId) => [\n 400,\n `The shared OAuth provider with ID ${providerId} is not valid.`,\n {\n provider_id: providerId,\n },\n ] as const,\n (json) => [json.provider_id] as const,\n);\n\nconst InvalidStandardOAuthProviderId = createKnownErrorConstructor(\n KnownError,\n \"INVALID_STANDARD_OAUTH_PROVIDER_ID\",\n (providerId) => [\n 400,\n `The standard OAuth provider with ID ${providerId} is not valid.`,\n {\n provider_id: providerId,\n },\n ] as const,\n (json) => [json.provider_id] as const,\n);\n\nconst InvalidAuthorizationCode = createKnownErrorConstructor(\n KnownError,\n \"INVALID_AUTHORIZATION_CODE\",\n () => [\n 400,\n \"The given authorization code is invalid.\",\n ] as const,\n () => [] as const,\n);\n\nconst OAuthProviderAccessDenied = createKnownErrorConstructor(\n KnownError,\n \"OAUTH_PROVIDER_ACCESS_DENIED\",\n () => [\n 400,\n \"The OAuth provider denied access to the user.\",\n ] as const,\n () => [] as const,\n);\n\nconst ContactChannelAlreadyUsedForAuthBySomeoneElse = createKnownErrorConstructor(\n KnownError,\n \"CONTACT_CHANNEL_ALREADY_USED_FOR_AUTH_BY_SOMEONE_ELSE\",\n (type: \"email\", contactChannelValue?: string, wouldWorkIfEmailWasVerified: boolean = false) => [\n 409,\n `This ${type} ${contactChannelValue ? `\"(${contactChannelValue})\"` : \"\"} is already used for authentication by another account${wouldWorkIfEmailWasVerified ? \" but the email is not verified. Please login to your existing account with the method you used to sign up, and then verify your email to sign in with this login method.\" : \".\"}`,\n {\n type,\n contact_channel_value: contactChannelValue ?? null,\n would_work_if_email_was_verified: wouldWorkIfEmailWasVerified,\n },\n ] as const,\n (json) => [json.type, json.contact_channel_value, json.would_work_if_email_was_verified ?? false] as const,\n);\n\nconst InvalidPollingCodeError = createKnownErrorConstructor(\n KnownError,\n \"INVALID_POLLING_CODE\",\n (details?: Json) => [\n 400,\n \"The polling code is invalid or does not exist.\",\n details,\n ] as const,\n (json: any) => [json] as const,\n);\n\nconst CliAuthError = createKnownErrorConstructor(\n KnownError,\n \"CLI_AUTH_ERROR\",\n (message: string) => [\n 400,\n message,\n ] as const,\n (json: any) => [json.message] as const,\n);\n\nconst CliAuthExpiredError = createKnownErrorConstructor(\n KnownError,\n \"CLI_AUTH_EXPIRED_ERROR\",\n (message: string = \"CLI authentication request expired. Please try again.\") => [\n 400,\n message,\n ] as const,\n (json: any) => [json.message] as const,\n);\n\nconst CliAuthUsedError = createKnownErrorConstructor(\n KnownError,\n \"CLI_AUTH_USED_ERROR\",\n (message: string = \"This authentication token has already been used.\") => [\n 400,\n message,\n ] as const,\n (json: any) => [json.message] as const,\n);\n\n\nconst ApiKeyNotValid = createKnownErrorConstructor(\n KnownError,\n \"API_KEY_NOT_VALID\",\n \"inherit\",\n \"inherit\",\n);\n\nconst ApiKeyExpired = createKnownErrorConstructor(\n ApiKeyNotValid,\n \"API_KEY_EXPIRED\",\n () => [\n 401,\n \"API key has expired.\",\n ] as const,\n () => [] as const,\n);\n\nconst ApiKeyRevoked = createKnownErrorConstructor(\n ApiKeyNotValid,\n \"API_KEY_REVOKED\",\n () => [\n 401,\n \"API key has been revoked.\",\n ] as const,\n () => [] as const,\n);\n\nconst WrongApiKeyType = createKnownErrorConstructor(\n ApiKeyNotValid,\n \"WRONG_API_KEY_TYPE\",\n (expectedType: string, actualType: string) => [\n 400,\n `This endpoint is for ${expectedType} API keys, but a ${actualType} API key was provided.`,\n { expected_type: expectedType, actual_type: actualType },\n ] as const,\n (json) => [json.expected_type, json.actual_type] as const,\n);\n\nconst ApiKeyNotFound = createKnownErrorConstructor(\n ApiKeyNotValid,\n \"API_KEY_NOT_FOUND\",\n () => [\n 404,\n \"API key not found.\",\n ] as const,\n () => [] as const,\n);\n\nconst PublicApiKeyCannotBeRevoked = createKnownErrorConstructor(\n ApiKeyNotValid,\n \"PUBLIC_API_KEY_CANNOT_BE_REVOKED\",\n () => [\n 400,\n \"Public API keys cannot be revoked by the secretscanner endpoint.\",\n ] as const,\n () => [] as const,\n);\n\nconst PermissionIdAlreadyExists = createKnownErrorConstructor(\n KnownError,\n \"PERMISSION_ID_ALREADY_EXISTS\",\n (permissionId: string) => [\n 400,\n `Permission with ID \"${permissionId}\" already exists. Choose a different ID.`,\n {\n permission_id: permissionId,\n },\n ] as const,\n (json: any) => [json.permission_id] as const,\n);\n\nconst EmailRenderingError = createKnownErrorConstructor(\n KnownError,\n \"EMAIL_RENDERING_ERROR\",\n (error: string) => [\n 400,\n `Failed to render email with theme: ${error}`,\n { error },\n ] as const,\n (json: any) => [json.error] as const,\n);\n\nconst RequiresCustomEmailServer = createKnownErrorConstructor(\n KnownError,\n \"REQUIRES_CUSTOM_EMAIL_SERVER\",\n () => [\n 400,\n `This action requires a custom SMTP server. Please edit your email server configuration and try again.`,\n ] as const,\n () => [] as const,\n);\n\nconst ItemNotFound = createKnownErrorConstructor(\n KnownError,\n \"ITEM_NOT_FOUND\",\n (itemId: string) => [\n 404,\n `Item with ID \"${itemId}\" not found.`,\n {\n item_id: itemId,\n },\n ] as const,\n (json) => [json.item_id] as const,\n);\n\nconst ItemCustomerTypeDoesNotMatch = createKnownErrorConstructor(\n KnownError,\n \"ITEM_CUSTOMER_TYPE_DOES_NOT_MATCH\",\n (itemId: string, customerId: string, itemCustomerType: \"user\" | \"team\" | \"custom\" | undefined, actualCustomerType: \"user\" | \"team\" | \"custom\") => [\n 400,\n `The ${actualCustomerType} with ID ${JSON.stringify(customerId)} is not a valid customer for the item with ID ${JSON.stringify(itemId)}. ${itemCustomerType ? `The item is configured to only be available for ${itemCustomerType} customers, but the customer is a ${actualCustomerType}.` : `The item is missing a customer type field. Please make sure it is set up correctly in your project configuration.`}`,\n {\n item_id: itemId,\n customer_id: customerId,\n item_customer_type: itemCustomerType ?? null,\n actual_customer_type: actualCustomerType,\n },\n ] as const,\n (json) => [json.item_id, json.customer_id, json.item_customer_type ?? undefined, json.actual_customer_type] as const,\n);\n\nconst CustomerDoesNotExist = createKnownErrorConstructor(\n KnownError,\n \"CUSTOMER_DOES_NOT_EXIST\",\n (customerId: string) => [\n 400,\n `Customer with ID ${JSON.stringify(customerId)} does not exist.`,\n {\n customer_id: customerId,\n },\n ] as const,\n (json) => [json.customer_id] as const,\n);\n\nconst OfferDoesNotExist = createKnownErrorConstructor(\n KnownError,\n \"OFFER_DOES_NOT_EXIST\",\n (offerId: string, accessType: \"client\" | \"server\" | \"admin\") => [\n 400,\n `Offer with ID ${JSON.stringify(offerId)} does not exist${accessType === \"client\" ? \" or you don't have permissions to access it.\" : \".\"}`,\n {\n offer_id: offerId,\n access_type: accessType,\n },\n ] as const,\n (json) => [json.offer_id, json.access_type] as const,\n);\n\nconst OfferCustomerTypeDoesNotMatch = createKnownErrorConstructor(\n KnownError,\n \"OFFER_CUSTOMER_TYPE_DOES_NOT_MATCH\",\n (offerId: string | undefined, customerId: string, offerCustomerType: \"user\" | \"team\" | \"custom\" | undefined, actualCustomerType: \"user\" | \"team\" | \"custom\") => [\n 400,\n `The ${actualCustomerType} with ID ${JSON.stringify(customerId)} is not a valid customer for the inline offer that has been passed in. ${offerCustomerType ? `The offer is configured to only be available for ${offerCustomerType} customers, but the customer is a ${actualCustomerType}.` : `The offer is missing a customer type field. Please make sure it is set up correctly in your project configuration.`}`,\n {\n offer_id: offerId ?? null,\n customer_id: customerId,\n offer_customer_type: offerCustomerType ?? null,\n actual_customer_type: actualCustomerType,\n },\n ] as const,\n (json) => [json.offer_id ?? undefined, json.customer_id, json.offer_customer_type ?? undefined, json.actual_customer_type] as const,\n);\n\nconst ItemQuantityInsufficientAmount = createKnownErrorConstructor(\n KnownError,\n \"ITEM_QUANTITY_INSUFFICIENT_AMOUNT\",\n (itemId: string, customerId: string, quantity: number) => [\n 400,\n `The item with ID ${JSON.stringify(itemId)} has an insufficient quantity for the customer with ID ${JSON.stringify(customerId)}. An attempt was made to charge ${quantity} credits.`,\n {\n item_id: itemId,\n customer_id: customerId,\n quantity,\n },\n ] as const,\n (json) => [json.item_id, json.customer_id, json.quantity] as const,\n);\n\n\nexport type KnownErrors = {\n [K in keyof typeof KnownErrors]: InstanceType<typeof KnownErrors[K]>;\n};\n\nexport const KnownErrors = {\n CannotDeleteCurrentSession,\n UnsupportedError,\n BodyParsingError,\n SchemaError,\n AllOverloadsFailed,\n ProjectAuthenticationError,\n PermissionIdAlreadyExists,\n CliAuthError,\n CliAuthExpiredError,\n CliAuthUsedError,\n InvalidProjectAuthentication,\n ProjectKeyWithoutAccessType,\n InvalidAccessType,\n AccessTypeWithoutProjectId,\n AccessTypeRequired,\n CannotGetOwnUserWithoutUser,\n InsufficientAccessType,\n InvalidPublishableClientKey,\n InvalidSecretServerKey,\n InvalidSuperSecretAdminKey,\n InvalidAdminAccessToken,\n UnparsableAdminAccessToken,\n AdminAccessTokenExpired,\n InvalidProjectForAdminAccessToken,\n AdminAccessTokenIsNotAdmin,\n ProjectAuthenticationRequired,\n ClientAuthenticationRequired,\n ServerAuthenticationRequired,\n ClientOrServerAuthenticationRequired,\n ClientOrAdminAuthenticationRequired,\n ClientOrServerOrAdminAuthenticationRequired,\n AdminAuthenticationRequired,\n ExpectedInternalProject,\n SessionAuthenticationError,\n InvalidSessionAuthentication,\n InvalidAccessToken,\n UnparsableAccessToken,\n AccessTokenExpired,\n InvalidProjectForAccessToken,\n RefreshTokenError,\n ProviderRejected,\n RefreshTokenNotFoundOrExpired,\n UserWithEmailAlreadyExists,\n EmailNotVerified,\n UserIdDoesNotExist,\n UserNotFound,\n ApiKeyNotFound,\n PublicApiKeyCannotBeRevoked,\n ProjectNotFound,\n CurrentProjectNotFound,\n BranchDoesNotExist,\n SignUpNotEnabled,\n PasswordAuthenticationNotEnabled,\n PasskeyAuthenticationNotEnabled,\n AnonymousAccountsNotEnabled,\n AnonymousAuthenticationNotAllowed,\n EmailPasswordMismatch,\n RedirectUrlNotWhitelisted,\n PasswordRequirementsNotMet,\n PasswordTooShort,\n PasswordTooLong,\n UserDoesNotHavePassword,\n VerificationCodeError,\n VerificationCodeNotFound,\n VerificationCodeExpired,\n VerificationCodeAlreadyUsed,\n VerificationCodeMaxAttemptsReached,\n PasswordConfirmationMismatch,\n EmailAlreadyVerified,\n EmailNotAssociatedWithUser,\n EmailIsNotPrimaryEmail,\n PasskeyRegistrationFailed,\n PasskeyWebAuthnError,\n PasskeyAuthenticationFailed,\n PermissionNotFound,\n PermissionScopeMismatch,\n ContainedPermissionNotFound,\n TeamNotFound,\n TeamMembershipNotFound,\n EmailTemplateAlreadyExists,\n OAuthConnectionNotConnectedToUser,\n OAuthConnectionAlreadyConnectedToAnotherUser,\n OAuthConnectionDoesNotHaveRequiredScope,\n OAuthExtraScopeNotAvailableWithSharedOAuthKeys,\n OAuthAccessTokenNotAvailableWithSharedOAuthKeys,\n InvalidOAuthClientIdOrSecret,\n InvalidScope,\n UserAlreadyConnectedToAnotherOAuthConnection,\n OuterOAuthTimeout,\n OAuthProviderNotFoundOrNotEnabled,\n OAuthProviderAccountIdAlreadyUsedForSignIn,\n MultiFactorAuthenticationRequired,\n InvalidTotpCode,\n UserAuthenticationRequired,\n TeamMembershipAlreadyExists,\n ProjectPermissionRequired,\n TeamPermissionRequired,\n InvalidSharedOAuthProviderId,\n InvalidStandardOAuthProviderId,\n InvalidAuthorizationCode,\n TeamPermissionNotFound,\n OAuthProviderAccessDenied,\n ContactChannelAlreadyUsedForAuthBySomeoneElse,\n InvalidPollingCodeError,\n ApiKeyNotValid,\n ApiKeyExpired,\n ApiKeyRevoked,\n WrongApiKeyType,\n EmailRenderingError,\n RequiresCustomEmailServer,\n ItemNotFound,\n ItemCustomerTypeDoesNotMatch,\n CustomerDoesNotExist,\n OfferDoesNotExist,\n OfferCustomerTypeDoesNotMatch,\n ItemQuantityInsufficientAmount,\n} satisfies Record<string, KnownErrorConstructor<any, any>>;\n\n\n// ensure that all known error codes are unique\nconst knownErrorCodes = new Set<string>();\nfor (const [_, KnownError] of Object.entries(KnownErrors)) {\n if (knownErrorCodes.has(KnownError.errorCode)) {\n throw new Error(`Duplicate known error code: ${KnownError.errorCode}`);\n }\n knownErrorCodes.add(KnownError.errorCode);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2D;AAC3D,uBAA6B;AAE7B,qBAAyB;AAqBlB,IAAe,aAAf,cAAkC,0BAAY;AAAA,EAInD,YACkB,YACA,sBACA,SAChB;AACA;AAAA,MACE;AAAA,MACA;AAAA,IACF;AAPgB;AACA;AACA;AANlB,SAAiB,yBAAyB;AAC1C,SAAO,OAAO;AAAA,EAWd;AAAA,EAEA,OAAc,aAAa,OAAqC;AAE9D,WAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,4BAA4B,SAAS,MAAM,2BAA2B;AAAA,EAC9H;AAAA,EAEgB,UAAsB;AACpC,WAAO,IAAI,YAAY,EAAE,OAAO,KAAK,UAAU,KAAK,kBAAkB,GAAG,QAAW,CAAC,CAAC;AAAA,EACxF;AAAA,EAEgB,aAAuC;AACrD,WAAO;AAAA,MACL,gBAAgB,CAAC,iCAAiC;AAAA,MAClD,uBAAuB,CAAC,KAAK,SAAS;AAAA,IACxC;AAAA,EACF;AAAA,EAEgB,oBAA0B;AACxC,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,GAAG,KAAK,UAAU,EAAE,SAAS,KAAK,QAAQ,IAAI,CAAC;AAAA,MAC/C,OAAO,KAAK;AAAA,IACd;AAAA,EACF;AAAA,EAEA,IAAI,YAAoB;AACtB,WAA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EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAIA,IAAM,kBAAkB,oBAAI,IAAY;AACxC,WAAW,CAAC,GAAGA,WAAU,KAAK,OAAO,QAAQ,WAAW,GAAG;AACzD,MAAI,gBAAgB,IAAIA,YAAW,SAAS,GAAG;AAC7C,UAAM,IAAI,MAAM,+BAA+BA,YAAW,SAAS,EAAE;AAAA,EACvE;AACA,kBAAgB,IAAIA,YAAW,SAAS;AAC1C;","names":["KnownError"]}
1
+ {"version":3,"sources":["../src/known-errors.tsx"],"sourcesContent":["import { StackAssertionError, StatusError, throwErr } from \"./utils/errors\";\nimport { identityArgs } from \"./utils/functions\";\nimport { Json } from \"./utils/json\";\nimport { deindent } from \"./utils/strings\";\n\nexport type KnownErrorJson = {\n code: string,\n message: string,\n details?: Json,\n};\n\nexport type AbstractKnownErrorConstructor<Args extends any[]> =\n & (abstract new (...args: Args) => KnownError)\n & {\n constructorArgsFromJson: (json: KnownErrorJson) => Args,\n };\n\nexport type KnownErrorConstructor<SuperInstance extends KnownError, Args extends any[]> = {\n new (...args: Args): SuperInstance & { constructorArgs: Args },\n errorCode: string,\n constructorArgsFromJson: (json: KnownErrorJson) => Args,\n isInstance: (error: unknown) => error is SuperInstance & { constructorArgs: Args },\n};\n\nexport abstract class KnownError extends StatusError {\n private readonly __stackKnownErrorBrand = \"stack-known-error-brand-sentinel\" as const;\n public name = \"KnownError\";\n\n constructor(\n public readonly statusCode: number,\n public readonly humanReadableMessage: string,\n public readonly details?: Json,\n ) {\n super(\n statusCode,\n humanReadableMessage\n );\n }\n\n public static isKnownError(error: unknown): error is KnownError {\n // like instanceof, but also works for errors thrown in other realms or by different versions of the same package\n return typeof error === \"object\" && error !== null && \"__stackKnownErrorBrand\" in error && error.__stackKnownErrorBrand === \"stack-known-error-brand-sentinel\";\n }\n\n public override getBody(): Uint8Array {\n return new TextEncoder().encode(JSON.stringify(this.toDescriptiveJson(), undefined, 2));\n }\n\n public override getHeaders(): Record<string, string[]> {\n return {\n \"Content-Type\": [\"application/json; charset=utf-8\"],\n \"X-Stack-Known-Error\": [this.errorCode],\n };\n }\n\n public override toDescriptiveJson(): Json {\n return {\n code: this.errorCode,\n ...this.details ? { details: this.details } : {},\n error: this.humanReadableMessage,\n };\n }\n\n get errorCode(): string {\n return (this.constructor as any).errorCode ?? throwErr(`Can't find error code for this KnownError. Is its constructor a KnownErrorConstructor? ${this}`);\n }\n\n public static constructorArgsFromJson(json: KnownErrorJson): ConstructorParameters<typeof KnownError> {\n return [\n 400,\n json.message,\n json,\n ];\n }\n\n public static fromJson(json: KnownErrorJson): KnownError {\n for (const [_, KnownErrorType] of Object.entries(KnownErrors)) {\n if (json.code === KnownErrorType.prototype.errorCode) {\n const constructorArgs = KnownErrorType.constructorArgsFromJson(json);\n return new KnownErrorType(\n // @ts-ignore-next-line\n ...constructorArgs,\n );\n }\n }\n\n throw new Error(`Unknown KnownError code. You may need to update your version of Stack to see more detailed information. ${json.code}: ${json.message}`);\n }\n}\n\nconst knownErrorConstructorErrorCodeSentinel = Symbol(\"knownErrorConstructorErrorCodeSentinel\");\n/**\n * Exists solely so that known errors are nominative types (ie. two KnownErrors with the same interface are not the same type)\n */\ntype KnownErrorBrand<ErrorCode extends string> = {\n /**\n * Does not exist at runtime\n *\n * Must be an object because it may be true for multiple error codes (it's true for all parents)\n */\n [knownErrorConstructorErrorCodeSentinel]: {\n [K in ErrorCode]: true\n },\n};\n\nfunction createKnownErrorConstructor<ErrorCode extends string, Super extends AbstractKnownErrorConstructor<any>, Args extends any[]>(\n SuperClass: Super,\n errorCode: ErrorCode,\n create: ((...args: Args) => Readonly<ConstructorParameters<Super>>),\n constructorArgsFromJson: ((jsonDetails: any) => Args),\n): KnownErrorConstructor<InstanceType<Super> & KnownErrorBrand<ErrorCode>, Args> & { errorCode: ErrorCode };\nfunction createKnownErrorConstructor<ErrorCode extends string, Super extends AbstractKnownErrorConstructor<any>>(\n SuperClass: Super,\n errorCode: ErrorCode,\n create: \"inherit\",\n constructorArgsFromJson: \"inherit\",\n): KnownErrorConstructor<InstanceType<Super> & KnownErrorBrand<ErrorCode>, ConstructorParameters<Super>> & { errorCode: ErrorCode };\nfunction createKnownErrorConstructor<ErrorCode extends string, Super extends AbstractKnownErrorConstructor<any>, Args extends any[]>(\n SuperClass: Super,\n errorCode: ErrorCode,\n create: \"inherit\" | ((...args: Args) => Readonly<ConstructorParameters<Super>>),\n constructorArgsFromJson: \"inherit\" | ((jsonDetails: any) => Args),\n): KnownErrorConstructor<InstanceType<Super> & KnownErrorBrand<ErrorCode>, Args> & { errorCode: ErrorCode } {\n const createFn = create === \"inherit\" ? identityArgs<Args> as never : create;\n const constructorArgsFromJsonFn = constructorArgsFromJson === \"inherit\" ? SuperClass.constructorArgsFromJson as never : constructorArgsFromJson;\n\n // @ts-expect-error this is not a mixin, but TS detects it as one\n class KnownErrorImpl extends SuperClass {\n public static readonly errorCode = errorCode;\n public name = `KnownError<${errorCode}>`;\n public readonly constructorArgs: Args;\n\n constructor(...args: Args) {\n // @ts-expect-error DEVIN, STOP REMOVING THIS LINE YOU DUMBASS, YES TYPESCRIPT DOES THROW AN ERROR IF YOU DON'T HAVE IT, NO THIS IS NOT \"UNUSED\", AND YES YOU ARE BREAKING OUR CI PIPELINE EVERY TIME YOU DO IT\n super(...createFn(...args));\n this.constructorArgs = args;\n }\n\n static constructorArgsFromJson(json: KnownErrorJson): Args {\n return constructorArgsFromJsonFn(json.details);\n }\n\n static isInstance(error: unknown): error is InstanceType<Super> & { constructorArgs: Args } {\n if (!KnownError.isKnownError(error)) return false;\n let current: unknown = error;\n while (true) {\n current = Object.getPrototypeOf(current);\n if (!current) break;\n if (\"errorCode\" in current.constructor && current.constructor.errorCode === errorCode) return true;\n }\n return false;\n }\n };\n\n // @ts-expect-error\n return KnownErrorImpl;\n}\nundefined?.test(\"KnownError.isInstance\", ({ expect }) => {\n expect(KnownErrors.InvalidProjectAuthentication.isInstance(undefined)).toBe(false);\n expect(KnownErrors.InvalidProjectAuthentication.isInstance(new Error())).toBe(false);\n\n const error = new KnownErrors.ProjectKeyWithoutAccessType();\n expect(KnownErrors.ProjectKeyWithoutAccessType.isInstance(error)).toBe(true);\n expect(KnownErrors.InvalidProjectAuthentication.isInstance(error)).toBe(true);\n expect(KnownErrors.InvalidAccessType.isInstance(error)).toBe(false);\n});\n\nconst UnsupportedError = createKnownErrorConstructor(\n KnownError,\n \"UNSUPPORTED_ERROR\",\n (originalErrorCode: string) => [\n 500,\n `An error occurred that is not currently supported (possibly because it was added in a version of Stack that is newer than this client). The original unsupported error code was: ${originalErrorCode}`,\n {\n originalErrorCode,\n },\n ] as const,\n (json) => [\n (json as any)?.originalErrorCode ?? throwErr(\"originalErrorCode not found in UnsupportedError details\"),\n ] as const,\n);\n\nconst BodyParsingError = createKnownErrorConstructor(\n KnownError,\n \"BODY_PARSING_ERROR\",\n (message: string) => [\n 400,\n message,\n ] as const,\n (json) => [json.message] as const,\n);\n\nconst SchemaError = createKnownErrorConstructor(\n KnownError,\n \"SCHEMA_ERROR\",\n (message: string) => [\n 400,\n message || throwErr(\"SchemaError requires a message\"),\n {\n message,\n },\n ] as const,\n (json: any) => [json.message] as const,\n);\n\nconst AllOverloadsFailed = createKnownErrorConstructor(\n KnownError,\n \"ALL_OVERLOADS_FAILED\",\n (overloadErrors: Json[]) => [\n 400,\n deindent`\n This endpoint has multiple overloads, but they all failed to process the request.\n\n ${overloadErrors.map((e, i) => deindent`\n Overload ${i + 1}: ${JSON.stringify(e, undefined, 2)}\n `).join(\"\\n\\n\")}\n `,\n {\n overload_errors: overloadErrors,\n },\n ] as const,\n (json) => [\n (json as any)?.overload_errors ?? throwErr(\"overload_errors not found in AllOverloadsFailed details\"),\n ] as const,\n);\n\nconst ProjectAuthenticationError = createKnownErrorConstructor(\n KnownError,\n \"PROJECT_AUTHENTICATION_ERROR\",\n \"inherit\",\n \"inherit\",\n);\n\nconst InvalidProjectAuthentication = createKnownErrorConstructor(\n ProjectAuthenticationError,\n \"INVALID_PROJECT_AUTHENTICATION\",\n \"inherit\",\n \"inherit\",\n);\n\nconst ProjectKeyWithoutAccessType = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"PROJECT_KEY_WITHOUT_ACCESS_TYPE\",\n () => [\n 400,\n \"Either an API key or an admin access token was provided, but the x-stack-access-type header is missing. Set it to 'client', 'server', or 'admin' as appropriate.\",\n ] as const,\n () => [] as const,\n);\n\nconst InvalidAccessType = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"INVALID_ACCESS_TYPE\",\n (accessType: string) => [\n 400,\n `The x-stack-access-type header must be 'client', 'server', or 'admin', but was '${accessType}'.`,\n ] as const,\n (json) => [\n (json as any)?.accessType ?? throwErr(\"accessType not found in InvalidAccessType details\"),\n ] as const,\n);\n\nconst AccessTypeWithoutProjectId = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"ACCESS_TYPE_WITHOUT_PROJECT_ID\",\n (accessType: \"client\" | \"server\" | \"admin\") => [\n 400,\n deindent`\n The x-stack-access-type header was '${accessType}', but the x-stack-project-id header was not provided.\n \n For more information, see the docs on REST API authentication: https://docs.stack-auth.com/rest-api/overview#authentication\n `,\n {\n request_type: accessType,\n },\n ] as const,\n (json: any) => [json.request_type] as const,\n);\n\nconst AccessTypeRequired = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"ACCESS_TYPE_REQUIRED\",\n () => [\n 400,\n deindent`\n You must specify an access level for this Stack project. Make sure project API keys are provided (eg. x-stack-publishable-client-key) and you set the x-stack-access-type header to 'client', 'server', or 'admin'.\n \n For more information, see the docs on REST API authentication: https://docs.stack-auth.com/rest-api/overview#authentication\n `,\n ] as const,\n () => [] as const,\n);\n\nconst InsufficientAccessType = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"INSUFFICIENT_ACCESS_TYPE\",\n (actualAccessType: \"client\" | \"server\" | \"admin\", allowedAccessTypes: (\"client\" | \"server\" | \"admin\")[]) => [\n 401,\n `The x-stack-access-type header must be ${allowedAccessTypes.map(s => `'${s}'`).join(\" or \")}, but was '${actualAccessType}'.`,\n {\n actual_access_type: actualAccessType,\n allowed_access_types: allowedAccessTypes,\n },\n ] as const,\n (json: any) => [\n json.actual_access_type,\n json.allowed_access_types,\n ] as const,\n);\n\nconst InvalidPublishableClientKey = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"INVALID_PUBLISHABLE_CLIENT_KEY\",\n (projectId: string) => [\n 401,\n `The publishable key is not valid for the project ${JSON.stringify(projectId)}. Does the project and/or the key exist?`,\n {\n project_id: projectId,\n },\n ] as const,\n (json: any) => [json.project_id] as const,\n);\n\nconst InvalidSecretServerKey = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"INVALID_SECRET_SERVER_KEY\",\n (projectId: string) => [\n 401,\n `The secret server key is not valid for the project ${JSON.stringify(projectId)}. Does the project and/or the key exist?`,\n {\n project_id: projectId,\n },\n ] as const,\n (json: any) => [json.project_id] as const,\n);\n\nconst InvalidSuperSecretAdminKey = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"INVALID_SUPER_SECRET_ADMIN_KEY\",\n (projectId: string) => [\n 401,\n `The super secret admin key is not valid for the project ${JSON.stringify(projectId)}. Does the project and/or the key exist?`,\n {\n project_id: projectId,\n },\n ] as const,\n (json: any) => [json.project_id] as const,\n);\n\nconst InvalidAdminAccessToken = createKnownErrorConstructor(\n InvalidProjectAuthentication,\n \"INVALID_ADMIN_ACCESS_TOKEN\",\n \"inherit\",\n \"inherit\",\n);\n\nconst UnparsableAdminAccessToken = createKnownErrorConstructor(\n InvalidAdminAccessToken,\n \"UNPARSABLE_ADMIN_ACCESS_TOKEN\",\n () => [\n 401,\n \"Admin access token is not parsable.\",\n ] as const,\n () => [] as const,\n);\n\nconst AdminAccessTokenExpired = createKnownErrorConstructor(\n InvalidAdminAccessToken,\n \"ADMIN_ACCESS_TOKEN_EXPIRED\",\n (expiredAt: Date | undefined) => [\n 401,\n `Admin access token has expired. Please refresh it and try again.${expiredAt ? ` (The access token expired at ${expiredAt.toISOString()}.)`: \"\"}`,\n { expired_at_millis: expiredAt?.getTime() ?? null },\n ] as const,\n (json: any) => [json.expired_at_millis ?? undefined] as const,\n);\n\nconst InvalidProjectForAdminAccessToken = createKnownErrorConstructor(\n InvalidAdminAccessToken,\n \"INVALID_PROJECT_FOR_ADMIN_ACCESS_TOKEN\",\n () => [\n 401,\n \"Admin access tokens must be created on the internal project.\",\n ] as const,\n () => [] as const,\n);\n\nconst AdminAccessTokenIsNotAdmin = createKnownErrorConstructor(\n InvalidAdminAccessToken,\n \"ADMIN_ACCESS_TOKEN_IS_NOT_ADMIN\",\n () => [\n 401,\n \"Admin access token does not have the required permissions to access this project.\",\n ] as const,\n () => [] as const,\n);\n\n/**\n * @deprecated Use InsufficientAccessType instead\n */\nconst ProjectAuthenticationRequired = createKnownErrorConstructor(\n ProjectAuthenticationError,\n \"PROJECT_AUTHENTICATION_REQUIRED\",\n \"inherit\",\n \"inherit\",\n);\n\n\n/**\n * @deprecated Use InsufficientAccessType instead\n */\nconst ClientAuthenticationRequired = createKnownErrorConstructor(\n ProjectAuthenticationRequired,\n \"CLIENT_AUTHENTICATION_REQUIRED\",\n () => [\n 401,\n \"The publishable client key must be provided.\",\n ] as const,\n () => [] as const,\n);\n\n/**\n * @deprecated Use InsufficientAccessType instead\n */\nconst ServerAuthenticationRequired = createKnownErrorConstructor(\n ProjectAuthenticationRequired,\n \"SERVER_AUTHENTICATION_REQUIRED\",\n () => [\n 401,\n \"The secret server key must be provided.\",\n ] as const,\n () => [] as const,\n);\n\n/**\n * @deprecated Use InsufficientAccessType instead\n */\nconst ClientOrServerAuthenticationRequired = createKnownErrorConstructor(\n ProjectAuthenticationRequired,\n \"CLIENT_OR_SERVER_AUTHENTICATION_REQUIRED\",\n () => [\n 401,\n \"Either the publishable client key or the secret server key must be provided.\",\n ] as const,\n () => [] as const,\n);\n\n/**\n * @deprecated Use InsufficientAccessType instead\n */\nconst ClientOrAdminAuthenticationRequired = createKnownErrorConstructor(\n ProjectAuthenticationRequired,\n \"CLIENT_OR_ADMIN_AUTHENTICATION_REQUIRED\",\n () => [\n 401,\n \"Either the publishable client key or the super secret admin key must be provided.\",\n ] as const,\n () => [] as const,\n);\n\n/**\n * @deprecated Use InsufficientAccessType instead\n */\nconst ClientOrServerOrAdminAuthenticationRequired = createKnownErrorConstructor(\n ProjectAuthenticationRequired,\n \"CLIENT_OR_SERVER_OR_ADMIN_AUTHENTICATION_REQUIRED\",\n () => [\n 401,\n \"Either the publishable client key, the secret server key, or the super secret admin key must be provided.\",\n ] as const,\n () => [] as const,\n);\n\n/**\n * @deprecated Use InsufficientAccessType instead\n */\nconst AdminAuthenticationRequired = createKnownErrorConstructor(\n ProjectAuthenticationRequired,\n \"ADMIN_AUTHENTICATION_REQUIRED\",\n () => [\n 401,\n \"The super secret admin key must be provided.\",\n ] as const,\n () => [] as const,\n);\n\nconst ExpectedInternalProject = createKnownErrorConstructor(\n ProjectAuthenticationError,\n \"EXPECTED_INTERNAL_PROJECT\",\n () => [\n 401,\n \"The project ID is expected to be internal.\",\n ] as const,\n () => [] as const,\n);\n\nconst SessionAuthenticationError = createKnownErrorConstructor(\n KnownError,\n \"SESSION_AUTHENTICATION_ERROR\",\n \"inherit\",\n \"inherit\",\n);\n\nconst InvalidSessionAuthentication = createKnownErrorConstructor(\n SessionAuthenticationError,\n \"INVALID_SESSION_AUTHENTICATION\",\n \"inherit\",\n \"inherit\",\n);\n\nconst InvalidAccessToken = createKnownErrorConstructor(\n InvalidSessionAuthentication,\n \"INVALID_ACCESS_TOKEN\",\n \"inherit\",\n \"inherit\",\n);\n\nconst UnparsableAccessToken = createKnownErrorConstructor(\n InvalidAccessToken,\n \"UNPARSABLE_ACCESS_TOKEN\",\n () => [\n 401,\n \"Access token is not parsable.\",\n ] as const,\n () => [] as const,\n);\n\nconst AccessTokenExpired = createKnownErrorConstructor(\n InvalidAccessToken,\n \"ACCESS_TOKEN_EXPIRED\",\n (expiredAt: Date | undefined) => [\n 401,\n `Access token has expired. Please refresh it and try again.${expiredAt ? ` (The access token expired at ${expiredAt.toISOString()}.)`: \"\"}`,\n { expired_at_millis: expiredAt?.getTime() ?? null },\n ] as const,\n (json: any) => [json.expired_at_millis ? new Date(json.expired_at_millis) : undefined] as const,\n);\n\nconst InvalidProjectForAccessToken = createKnownErrorConstructor(\n InvalidAccessToken,\n \"INVALID_PROJECT_FOR_ACCESS_TOKEN\",\n (expectedProjectId: string, actualProjectId: string) => [\n 401,\n `Access token not valid for this project. Expected project ID ${JSON.stringify(expectedProjectId)}, but the token is for project ID ${JSON.stringify(actualProjectId)}.`,\n {\n expected_project_id: expectedProjectId,\n actual_project_id: actualProjectId,\n },\n ] as const,\n (json: any) => [json.expected_project_id, json.actual_project_id] as const,\n);\n\n\nconst RefreshTokenError = createKnownErrorConstructor(\n KnownError,\n \"REFRESH_TOKEN_ERROR\",\n \"inherit\",\n \"inherit\",\n);\n\nconst RefreshTokenNotFoundOrExpired = createKnownErrorConstructor(\n RefreshTokenError,\n \"REFRESH_TOKEN_NOT_FOUND_OR_EXPIRED\",\n () => [\n 401,\n \"Refresh token not found for this project, or the session has expired/been revoked.\",\n ] as const,\n () => [] as const,\n);\n\nconst CannotDeleteCurrentSession = createKnownErrorConstructor(\n RefreshTokenError,\n \"CANNOT_DELETE_CURRENT_SESSION\",\n () => [\n 400,\n \"Cannot delete the current session.\",\n ] as const,\n () => [] as const,\n);\n\n\nconst ProviderRejected = createKnownErrorConstructor(\n RefreshTokenError,\n \"PROVIDER_REJECTED\",\n () => [\n 401,\n \"The provider refused to refresh their token. This usually means that the provider used to authenticate the user no longer regards this session as valid, and the user must re-authenticate.\",\n ] as const,\n () => [] as const,\n);\n\nconst UserWithEmailAlreadyExists = createKnownErrorConstructor(\n KnownError,\n \"USER_EMAIL_ALREADY_EXISTS\",\n (email: string, wouldWorkIfEmailWasVerified: boolean = false) => [\n 409,\n `A user with email ${JSON.stringify(email)} already exists${wouldWorkIfEmailWasVerified ? \" but the email is not verified. Please login to your existing account with the method you used to sign up, and then verify your email to sign in with this login method.\" : \".\"}`,\n {\n email,\n would_work_if_email_was_verified: wouldWorkIfEmailWasVerified,\n },\n ] as const,\n (json: any) => [json.email, json.would_work_if_email_was_verified ?? false] as const,\n);\n\nconst EmailNotVerified = createKnownErrorConstructor(\n KnownError,\n \"EMAIL_NOT_VERIFIED\",\n () => [\n 400,\n \"The email is not verified.\",\n ] as const,\n () => [] as const,\n);\n\nconst CannotGetOwnUserWithoutUser = createKnownErrorConstructor(\n KnownError,\n \"CANNOT_GET_OWN_USER_WITHOUT_USER\",\n () => [\n 400,\n \"You have specified 'me' as a userId, but did not provide authentication for a user.\",\n ] as const,\n () => [] as const,\n);\n\nconst UserIdDoesNotExist = createKnownErrorConstructor(\n KnownError,\n \"USER_ID_DOES_NOT_EXIST\",\n (userId: string) => [\n 400,\n `The given user with the ID ${userId} does not exist.`,\n {\n user_id: userId,\n },\n ] as const,\n (json: any) => [json.user_id] as const,\n);\n\nconst UserNotFound = createKnownErrorConstructor(\n KnownError,\n \"USER_NOT_FOUND\",\n () => [\n 404,\n \"User not found.\",\n ] as const,\n () => [] as const,\n);\n\n\nconst ProjectNotFound = createKnownErrorConstructor(\n KnownError,\n \"PROJECT_NOT_FOUND\",\n (projectId: string) => {\n if (typeof projectId !== \"string\") throw new StackAssertionError(\"projectId of KnownErrors.ProjectNotFound must be a string\");\n return [\n 404,\n `Project ${projectId} not found or is not accessible with the current user.`,\n {\n project_id: projectId,\n },\n ] as const;\n },\n (json: any) => [json.project_id] as const,\n);\n\nconst CurrentProjectNotFound = createKnownErrorConstructor(\n KnownError,\n \"CURRENT_PROJECT_NOT_FOUND\",\n (projectId: string) => [\n 400,\n `The current project with ID ${projectId} was not found. Please check the value of the x-stack-project-id header.`,\n {\n project_id: projectId,\n },\n ] as const,\n (json: any) => [json.project_id] as const,\n);\n\nconst BranchDoesNotExist = createKnownErrorConstructor(\n KnownError,\n \"BRANCH_DOES_NOT_EXIST\",\n (branchId: string) => [\n 400,\n `The branch with ID ${branchId} does not exist.`,\n {\n branch_id: branchId,\n },\n ] as const,\n (json: any) => [json.branch_id] as const,\n);\n\n\nconst SignUpNotEnabled = createKnownErrorConstructor(\n KnownError,\n \"SIGN_UP_NOT_ENABLED\",\n () => [\n 400,\n \"Creation of new accounts is not enabled for this project. Please ask the project owner to enable it.\",\n ] as const,\n () => [] as const,\n);\n\nconst PasswordAuthenticationNotEnabled = createKnownErrorConstructor(\n KnownError,\n \"PASSWORD_AUTHENTICATION_NOT_ENABLED\",\n () => [\n 400,\n \"Password authentication is not enabled for this project.\",\n ] as const,\n () => [] as const,\n);\n\nconst DataVaultStoreDoesNotExist = createKnownErrorConstructor(\n KnownError,\n \"DATA_VAULT_STORE_DOES_NOT_EXIST\",\n (storeId: string) => [\n 400,\n `Data vault store with ID ${storeId} does not exist.`,\n {\n store_id: storeId,\n },\n ] as const,\n (json: any) => [json.store_id] as const,\n);\n\nconst DataVaultStoreHashedKeyDoesNotExist = createKnownErrorConstructor(\n KnownError,\n \"DATA_VAULT_STORE_HASHED_KEY_DOES_NOT_EXIST\",\n (storeId: string, hashedKey: string) => [\n 400,\n `Data vault store with ID ${storeId} does not contain a key with hash ${hashedKey}.`,\n {\n store_id: storeId,\n hashed_key: hashedKey,\n },\n ] as const,\n (json: any) => [json.store_id, json.hashed_key] as const,\n);\n\nconst PasskeyAuthenticationNotEnabled = createKnownErrorConstructor(\n KnownError,\n \"PASSKEY_AUTHENTICATION_NOT_ENABLED\",\n () => [\n 400,\n \"Passkey authentication is not enabled for this project.\",\n ] as const,\n () => [] as const,\n);\n\nconst AnonymousAccountsNotEnabled = createKnownErrorConstructor(\n KnownError,\n \"ANONYMOUS_ACCOUNTS_NOT_ENABLED\",\n () => [\n 400,\n \"Anonymous accounts are not enabled for this project.\",\n ] as const,\n () => [] as const,\n);\n\nconst AnonymousAuthenticationNotAllowed = createKnownErrorConstructor(\n KnownError,\n \"ANONYMOUS_AUTHENTICATION_NOT_ALLOWED\",\n () => [\n 401,\n \"X-Stack-Access-Token is for an anonymous user, but anonymous users are not enabled. Set the X-Stack-Allow-Anonymous-User header of this request to 'true' to allow anonymous users.\",\n ] as const,\n () => [] as const,\n);\n\n\nconst EmailPasswordMismatch = createKnownErrorConstructor(\n KnownError,\n \"EMAIL_PASSWORD_MISMATCH\",\n () => [\n 400,\n \"Wrong e-mail or password.\",\n ] as const,\n () => [] as const,\n);\n\nconst RedirectUrlNotWhitelisted = createKnownErrorConstructor(\n KnownError,\n \"REDIRECT_URL_NOT_WHITELISTED\",\n () => [\n 400,\n \"Redirect URL not whitelisted. Did you forget to add this domain to the trusted domains list on the Stack Auth dashboard?\",\n ] as const,\n () => [] as const,\n);\n\nconst PasswordRequirementsNotMet = createKnownErrorConstructor(\n KnownError,\n \"PASSWORD_REQUIREMENTS_NOT_MET\",\n \"inherit\",\n \"inherit\",\n);\n\nconst PasswordTooShort = createKnownErrorConstructor(\n PasswordRequirementsNotMet,\n \"PASSWORD_TOO_SHORT\",\n (minLength: number) => [\n 400,\n `Password too short. Minimum length is ${minLength}.`,\n {\n min_length: minLength,\n },\n ] as const,\n (json) => [\n (json as any)?.min_length ?? throwErr(\"min_length not found in PasswordTooShort details\"),\n ] as const,\n);\n\nconst PasswordTooLong = createKnownErrorConstructor(\n PasswordRequirementsNotMet,\n \"PASSWORD_TOO_LONG\",\n (maxLength: number) => [\n 400,\n `Password too long. Maximum length is ${maxLength}.`,\n {\n maxLength,\n },\n ] as const,\n (json) => [\n (json as any)?.maxLength ?? throwErr(\"maxLength not found in PasswordTooLong details\"),\n ] as const,\n);\n\nconst UserDoesNotHavePassword = createKnownErrorConstructor(\n KnownError,\n \"USER_DOES_NOT_HAVE_PASSWORD\",\n () => [\n 400,\n \"This user does not have password authentication enabled.\",\n ] as const,\n () => [] as const,\n);\n\nconst VerificationCodeError = createKnownErrorConstructor(\n KnownError,\n \"VERIFICATION_ERROR\",\n \"inherit\",\n \"inherit\",\n);\n\nconst VerificationCodeNotFound = createKnownErrorConstructor(\n VerificationCodeError,\n \"VERIFICATION_CODE_NOT_FOUND\",\n () => [\n 404,\n \"The verification code does not exist for this project.\",\n ] as const,\n () => [] as const,\n);\n\nconst VerificationCodeExpired = createKnownErrorConstructor(\n VerificationCodeError,\n \"VERIFICATION_CODE_EXPIRED\",\n () => [\n 400,\n \"The verification code has expired.\",\n ] as const,\n () => [] as const,\n);\n\nconst VerificationCodeAlreadyUsed = createKnownErrorConstructor(\n VerificationCodeError,\n \"VERIFICATION_CODE_ALREADY_USED\",\n () => [\n 409,\n \"The verification link has already been used.\",\n ] as const,\n () => [] as const,\n);\n\nconst VerificationCodeMaxAttemptsReached = createKnownErrorConstructor(\n VerificationCodeError,\n \"VERIFICATION_CODE_MAX_ATTEMPTS_REACHED\",\n () => [\n 400,\n \"The verification code nonce has reached the maximum number of attempts. This code is not valid anymore.\",\n ] as const,\n () => [] as const,\n);\n\nconst PasswordConfirmationMismatch = createKnownErrorConstructor(\n KnownError,\n \"PASSWORD_CONFIRMATION_MISMATCH\",\n () => [\n 400,\n \"Passwords do not match.\",\n ] as const,\n () => [] as const,\n);\n\nconst EmailAlreadyVerified = createKnownErrorConstructor(\n KnownError,\n \"EMAIL_ALREADY_VERIFIED\",\n () => [\n 409,\n \"The e-mail is already verified.\",\n ] as const,\n () => [] as const,\n);\n\nconst EmailNotAssociatedWithUser = createKnownErrorConstructor(\n KnownError,\n \"EMAIL_NOT_ASSOCIATED_WITH_USER\",\n () => [\n 400,\n \"The e-mail is not associated with a user that could log in with that e-mail.\",\n ] as const,\n () => [] as const,\n);\n\nconst EmailIsNotPrimaryEmail = createKnownErrorConstructor(\n KnownError,\n \"EMAIL_IS_NOT_PRIMARY_EMAIL\",\n (email: string, primaryEmail: string | null) => [\n 400,\n `The given e-mail (${email}) must equal the user's primary e-mail (${primaryEmail}).`,\n {\n email,\n primary_email: primaryEmail,\n },\n ] as const,\n (json: any) => [json.email, json.primary_email] as const,\n);\n\n\nconst PasskeyRegistrationFailed = createKnownErrorConstructor(\n KnownError,\n \"PASSKEY_REGISTRATION_FAILED\",\n (message: string) => [\n 400,\n message,\n ] as const,\n (json: any) => [json.message] as const,\n);\n\n\nconst PasskeyWebAuthnError = createKnownErrorConstructor(\n KnownError,\n \"PASSKEY_WEBAUTHN_ERROR\",\n (message: string, code: string) => [\n 400,\n message,\n {\n message,\n code,\n },\n ] as const,\n (json: any) => [json.message, json.code] as const,\n);\n\nconst PasskeyAuthenticationFailed = createKnownErrorConstructor(\n KnownError,\n \"PASSKEY_AUTHENTICATION_FAILED\",\n (message: string) => [\n 400,\n message,\n ] as const,\n (json: any) => [json.message] as const,\n);\n\n\nconst PermissionNotFound = createKnownErrorConstructor(\n KnownError,\n \"PERMISSION_NOT_FOUND\",\n (permissionId: string) => [\n 404,\n `Permission \"${permissionId}\" not found. Make sure you created it on the dashboard.`,\n {\n permission_id: permissionId,\n },\n ] as const,\n (json: any) => [json.permission_id] as const,\n);\n\nconst PermissionScopeMismatch = createKnownErrorConstructor(\n KnownError,\n \"WRONG_PERMISSION_SCOPE\",\n (permissionId: string, expectedScope: \"team\" | \"project\", actualScope: \"team\" | \"project\" | null) => [\n 404,\n `Permission ${JSON.stringify(permissionId)} not found. (It was found for a different scope ${JSON.stringify(actualScope)}, but scope ${JSON.stringify(expectedScope)} was expected.)`,\n {\n permission_id: permissionId,\n expected_scope: expectedScope,\n actual_scope: actualScope,\n },\n ] as const,\n (json: any) => [json.permission_id, json.expected_scope, json.actual_scope] as const,\n);\n\nconst ContainedPermissionNotFound = createKnownErrorConstructor(\n KnownError,\n \"CONTAINED_PERMISSION_NOT_FOUND\",\n (permissionId: string) => [\n 400,\n `Contained permission with ID \"${permissionId}\" not found. Make sure you created it on the dashboard.`,\n {\n permission_id: permissionId,\n },\n ] as const,\n (json: any) => [json.permission_id] as const,\n);\n\nconst TeamNotFound = createKnownErrorConstructor(\n KnownError,\n \"TEAM_NOT_FOUND\",\n (teamId: string) => [\n 404,\n `Team ${teamId} not found.`,\n {\n team_id: teamId,\n },\n ] as const,\n (json: any) => [json.team_id] as const,\n);\n\nconst TeamAlreadyExists = createKnownErrorConstructor(\n KnownError,\n \"TEAM_ALREADY_EXISTS\",\n (teamId: string) => [\n 409,\n `Team ${teamId} already exists.`,\n {\n team_id: teamId,\n },\n ] as const,\n (json: any) => [json.team_id] as const,\n);\n\nconst TeamMembershipNotFound = createKnownErrorConstructor(\n KnownError,\n \"TEAM_MEMBERSHIP_NOT_FOUND\",\n (teamId: string, userId: string) => [\n 404,\n `User ${userId} is not found in team ${teamId}.`,\n {\n team_id: teamId,\n user_id: userId,\n },\n ] as const,\n (json: any) => [json.team_id, json.user_id] as const,\n);\n\n\nconst EmailTemplateAlreadyExists = createKnownErrorConstructor(\n KnownError,\n \"EMAIL_TEMPLATE_ALREADY_EXISTS\",\n () => [\n 409,\n \"Email template already exists.\",\n ] as const,\n () => [] as const,\n);\n\nconst OAuthConnectionNotConnectedToUser = createKnownErrorConstructor(\n KnownError,\n \"OAUTH_CONNECTION_NOT_CONNECTED_TO_USER\",\n () => [\n 400,\n \"The OAuth connection is not connected to any user.\",\n ] as const,\n () => [] as const,\n);\n\nconst OAuthConnectionAlreadyConnectedToAnotherUser = createKnownErrorConstructor(\n KnownError,\n \"OAUTH_CONNECTION_ALREADY_CONNECTED_TO_ANOTHER_USER\",\n () => [\n 409,\n \"The OAuth connection is already connected to another user.\",\n ] as const,\n () => [] as const,\n);\n\nconst OAuthConnectionDoesNotHaveRequiredScope = createKnownErrorConstructor(\n KnownError,\n \"OAUTH_CONNECTION_DOES_NOT_HAVE_REQUIRED_SCOPE\",\n () => [\n 400,\n \"The OAuth connection does not have the required scope.\",\n ] as const,\n () => [] as const,\n);\n\nconst OAuthExtraScopeNotAvailableWithSharedOAuthKeys = createKnownErrorConstructor(\n KnownError,\n \"OAUTH_EXTRA_SCOPE_NOT_AVAILABLE_WITH_SHARED_OAUTH_KEYS\",\n () => [\n 400,\n \"Extra scopes are not available with shared OAuth keys. Please add your own OAuth keys on the Stack dashboard to use extra scopes.\",\n ] as const,\n () => [] as const,\n);\n\nconst OAuthAccessTokenNotAvailableWithSharedOAuthKeys = createKnownErrorConstructor(\n KnownError,\n \"OAUTH_ACCESS_TOKEN_NOT_AVAILABLE_WITH_SHARED_OAUTH_KEYS\",\n () => [\n 400,\n \"Access tokens are not available with shared OAuth keys. Please add your own OAuth keys on the Stack dashboard to use access tokens.\",\n ] as const,\n () => [] as const,\n);\n\nconst InvalidOAuthClientIdOrSecret = createKnownErrorConstructor(\n KnownError,\n \"INVALID_OAUTH_CLIENT_ID_OR_SECRET\",\n (clientId?: string) => [\n 400,\n \"The OAuth client ID or secret is invalid. The client ID must be equal to the project ID (potentially with a hash and a branch ID), and the client secret must be a publishable client key.\",\n {\n client_id: clientId ?? null,\n },\n ] as const,\n (json: any) => [json.client_id ?? undefined] as const,\n);\n\nconst InvalidScope = createKnownErrorConstructor(\n KnownError,\n \"INVALID_SCOPE\",\n (scope: string) => [\n 400,\n `The scope \"${scope}\" is not a valid OAuth scope for Stack.`,\n ] as const,\n (json: any) => [json.scope] as const,\n);\n\nconst UserAlreadyConnectedToAnotherOAuthConnection = createKnownErrorConstructor(\n KnownError,\n \"USER_ALREADY_CONNECTED_TO_ANOTHER_OAUTH_CONNECTION\",\n () => [\n 409,\n \"The user is already connected to another OAuth account. Did you maybe selected the wrong account?\",\n ] as const,\n () => [] as const,\n);\n\nconst OuterOAuthTimeout = createKnownErrorConstructor(\n KnownError,\n \"OUTER_OAUTH_TIMEOUT\",\n () => [\n 408,\n \"The OAuth flow has timed out. Please sign in again.\",\n ] as const,\n () => [] as const,\n);\n\nconst OAuthProviderNotFoundOrNotEnabled = createKnownErrorConstructor(\n KnownError,\n \"OAUTH_PROVIDER_NOT_FOUND_OR_NOT_ENABLED\",\n () => [\n 400,\n \"The OAuth provider is not found or not enabled.\",\n ] as const,\n () => [] as const,\n);\n\nconst OAuthProviderAccountIdAlreadyUsedForSignIn = createKnownErrorConstructor(\n KnownError,\n \"OAUTH_PROVIDER_ACCOUNT_ID_ALREADY_USED_FOR_SIGN_IN\",\n () => [\n 400,\n `A provider with the same account ID is already used for signing in.`,\n ] as const,\n () => [] as const,\n);\n\nconst MultiFactorAuthenticationRequired = createKnownErrorConstructor(\n KnownError,\n \"MULTI_FACTOR_AUTHENTICATION_REQUIRED\",\n (attemptCode: string) => [\n 400,\n `Multi-factor authentication is required for this user.`,\n {\n attempt_code: attemptCode,\n },\n ] as const,\n (json) => [json.attempt_code] as const,\n);\n\nconst InvalidTotpCode = createKnownErrorConstructor(\n KnownError,\n \"INVALID_TOTP_CODE\",\n () => [\n 400,\n \"The TOTP code is invalid. Please try again.\",\n ] as const,\n () => [] as const,\n);\n\nconst UserAuthenticationRequired = createKnownErrorConstructor(\n KnownError,\n \"USER_AUTHENTICATION_REQUIRED\",\n () => [\n 401,\n \"User authentication required for this endpoint.\",\n ] as const,\n () => [] as const,\n);\n\nconst TeamMembershipAlreadyExists = createKnownErrorConstructor(\n KnownError,\n \"TEAM_MEMBERSHIP_ALREADY_EXISTS\",\n () => [\n 409,\n \"Team membership already exists.\",\n ] as const,\n () => [] as const,\n);\n\nconst ProjectPermissionRequired = createKnownErrorConstructor(\n KnownError,\n \"PROJECT_PERMISSION_REQUIRED\",\n (userId, permissionId) => [\n 401,\n `User ${userId} does not have permission ${permissionId}.`,\n {\n user_id: userId,\n permission_id: permissionId,\n },\n ] as const,\n (json) => [json.user_id, json.permission_id] as const,\n);\n\nconst TeamPermissionRequired = createKnownErrorConstructor(\n KnownError,\n \"TEAM_PERMISSION_REQUIRED\",\n (teamId, userId, permissionId) => [\n 401,\n `User ${userId} does not have permission ${permissionId} in team ${teamId}.`,\n {\n team_id: teamId,\n user_id: userId,\n permission_id: permissionId,\n },\n ] as const,\n (json) => [json.team_id, json.user_id, json.permission_id] as const,\n);\n\nconst TeamPermissionNotFound = createKnownErrorConstructor(\n KnownError,\n \"TEAM_PERMISSION_NOT_FOUND\",\n (teamId, userId, permissionId) => [\n 401,\n `User ${userId} does not have permission ${permissionId} in team ${teamId}.`,\n {\n team_id: teamId,\n user_id: userId,\n permission_id: permissionId,\n },\n ] as const,\n (json) => [json.team_id, json.user_id, json.permission_id] as const,\n);\n\nconst InvalidSharedOAuthProviderId = createKnownErrorConstructor(\n KnownError,\n \"INVALID_SHARED_OAUTH_PROVIDER_ID\",\n (providerId) => [\n 400,\n `The shared OAuth provider with ID ${providerId} is not valid.`,\n {\n provider_id: providerId,\n },\n ] as const,\n (json) => [json.provider_id] as const,\n);\n\nconst InvalidStandardOAuthProviderId = createKnownErrorConstructor(\n KnownError,\n \"INVALID_STANDARD_OAUTH_PROVIDER_ID\",\n (providerId) => [\n 400,\n `The standard OAuth provider with ID ${providerId} is not valid.`,\n {\n provider_id: providerId,\n },\n ] as const,\n (json) => [json.provider_id] as const,\n);\n\nconst InvalidAuthorizationCode = createKnownErrorConstructor(\n KnownError,\n \"INVALID_AUTHORIZATION_CODE\",\n () => [\n 400,\n \"The given authorization code is invalid.\",\n ] as const,\n () => [] as const,\n);\n\nconst OAuthProviderAccessDenied = createKnownErrorConstructor(\n KnownError,\n \"OAUTH_PROVIDER_ACCESS_DENIED\",\n () => [\n 400,\n \"The OAuth provider denied access to the user.\",\n ] as const,\n () => [] as const,\n);\n\nconst ContactChannelAlreadyUsedForAuthBySomeoneElse = createKnownErrorConstructor(\n KnownError,\n \"CONTACT_CHANNEL_ALREADY_USED_FOR_AUTH_BY_SOMEONE_ELSE\",\n (type: \"email\", contactChannelValue?: string, wouldWorkIfEmailWasVerified: boolean = false) => [\n 409,\n `This ${type} ${contactChannelValue ? `\"(${contactChannelValue})\"` : \"\"} is already used for authentication by another account${wouldWorkIfEmailWasVerified ? \" but the email is not verified. Please login to your existing account with the method you used to sign up, and then verify your email to sign in with this login method.\" : \".\"}`,\n {\n type,\n contact_channel_value: contactChannelValue ?? null,\n would_work_if_email_was_verified: wouldWorkIfEmailWasVerified,\n },\n ] as const,\n (json) => [json.type, json.contact_channel_value, json.would_work_if_email_was_verified ?? false] as const,\n);\n\nconst InvalidPollingCodeError = createKnownErrorConstructor(\n KnownError,\n \"INVALID_POLLING_CODE\",\n (details?: Json) => [\n 400,\n \"The polling code is invalid or does not exist.\",\n details,\n ] as const,\n (json: any) => [json] as const,\n);\n\nconst CliAuthError = createKnownErrorConstructor(\n KnownError,\n \"CLI_AUTH_ERROR\",\n (message: string) => [\n 400,\n message,\n ] as const,\n (json: any) => [json.message] as const,\n);\n\nconst CliAuthExpiredError = createKnownErrorConstructor(\n KnownError,\n \"CLI_AUTH_EXPIRED_ERROR\",\n (message: string = \"CLI authentication request expired. Please try again.\") => [\n 400,\n message,\n ] as const,\n (json: any) => [json.message] as const,\n);\n\nconst CliAuthUsedError = createKnownErrorConstructor(\n KnownError,\n \"CLI_AUTH_USED_ERROR\",\n (message: string = \"This authentication token has already been used.\") => [\n 400,\n message,\n ] as const,\n (json: any) => [json.message] as const,\n);\n\n\nconst ApiKeyNotValid = createKnownErrorConstructor(\n KnownError,\n \"API_KEY_NOT_VALID\",\n \"inherit\",\n \"inherit\",\n);\n\nconst ApiKeyExpired = createKnownErrorConstructor(\n ApiKeyNotValid,\n \"API_KEY_EXPIRED\",\n () => [\n 401,\n \"API key has expired.\",\n ] as const,\n () => [] as const,\n);\n\nconst ApiKeyRevoked = createKnownErrorConstructor(\n ApiKeyNotValid,\n \"API_KEY_REVOKED\",\n () => [\n 401,\n \"API key has been revoked.\",\n ] as const,\n () => [] as const,\n);\n\nconst WrongApiKeyType = createKnownErrorConstructor(\n ApiKeyNotValid,\n \"WRONG_API_KEY_TYPE\",\n (expectedType: string, actualType: string) => [\n 400,\n `This endpoint is for ${expectedType} API keys, but a ${actualType} API key was provided.`,\n { expected_type: expectedType, actual_type: actualType },\n ] as const,\n (json) => [json.expected_type, json.actual_type] as const,\n);\n\nconst ApiKeyNotFound = createKnownErrorConstructor(\n ApiKeyNotValid,\n \"API_KEY_NOT_FOUND\",\n () => [\n 404,\n \"API key not found.\",\n ] as const,\n () => [] as const,\n);\n\nconst PublicApiKeyCannotBeRevoked = createKnownErrorConstructor(\n ApiKeyNotValid,\n \"PUBLIC_API_KEY_CANNOT_BE_REVOKED\",\n () => [\n 400,\n \"Public API keys cannot be revoked by the secretscanner endpoint.\",\n ] as const,\n () => [] as const,\n);\n\nconst PermissionIdAlreadyExists = createKnownErrorConstructor(\n KnownError,\n \"PERMISSION_ID_ALREADY_EXISTS\",\n (permissionId: string) => [\n 400,\n `Permission with ID \"${permissionId}\" already exists. Choose a different ID.`,\n {\n permission_id: permissionId,\n },\n ] as const,\n (json: any) => [json.permission_id] as const,\n);\n\nconst EmailRenderingError = createKnownErrorConstructor(\n KnownError,\n \"EMAIL_RENDERING_ERROR\",\n (error: string) => [\n 400,\n `Failed to render email with theme: ${error}`,\n { error },\n ] as const,\n (json: any) => [json.error] as const,\n);\n\nconst RequiresCustomEmailServer = createKnownErrorConstructor(\n KnownError,\n \"REQUIRES_CUSTOM_EMAIL_SERVER\",\n () => [\n 400,\n `This action requires a custom SMTP server. Please edit your email server configuration and try again.`,\n ] as const,\n () => [] as const,\n);\n\nconst ItemNotFound = createKnownErrorConstructor(\n KnownError,\n \"ITEM_NOT_FOUND\",\n (itemId: string) => [\n 404,\n `Item with ID \"${itemId}\" not found.`,\n {\n item_id: itemId,\n },\n ] as const,\n (json) => [json.item_id] as const,\n);\n\nconst ItemCustomerTypeDoesNotMatch = createKnownErrorConstructor(\n KnownError,\n \"ITEM_CUSTOMER_TYPE_DOES_NOT_MATCH\",\n (itemId: string, customerId: string, itemCustomerType: \"user\" | \"team\" | \"custom\" | undefined, actualCustomerType: \"user\" | \"team\" | \"custom\") => [\n 400,\n `The ${actualCustomerType} with ID ${JSON.stringify(customerId)} is not a valid customer for the item with ID ${JSON.stringify(itemId)}. ${itemCustomerType ? `The item is configured to only be available for ${itemCustomerType} customers, but the customer is a ${actualCustomerType}.` : `The item is missing a customer type field. Please make sure it is set up correctly in your project configuration.`}`,\n {\n item_id: itemId,\n customer_id: customerId,\n item_customer_type: itemCustomerType ?? null,\n actual_customer_type: actualCustomerType,\n },\n ] as const,\n (json) => [json.item_id, json.customer_id, json.item_customer_type ?? undefined, json.actual_customer_type] as const,\n);\n\nconst CustomerDoesNotExist = createKnownErrorConstructor(\n KnownError,\n \"CUSTOMER_DOES_NOT_EXIST\",\n (customerId: string) => [\n 400,\n `Customer with ID ${JSON.stringify(customerId)} does not exist.`,\n {\n customer_id: customerId,\n },\n ] as const,\n (json) => [json.customer_id] as const,\n);\n\nconst OfferDoesNotExist = createKnownErrorConstructor(\n KnownError,\n \"OFFER_DOES_NOT_EXIST\",\n (offerId: string, accessType: \"client\" | \"server\" | \"admin\") => [\n 400,\n `Offer with ID ${JSON.stringify(offerId)} does not exist${accessType === \"client\" ? \" or you don't have permissions to access it.\" : \".\"}`,\n {\n offer_id: offerId,\n access_type: accessType,\n },\n ] as const,\n (json) => [json.offer_id, json.access_type] as const,\n);\n\nconst OfferCustomerTypeDoesNotMatch = createKnownErrorConstructor(\n KnownError,\n \"OFFER_CUSTOMER_TYPE_DOES_NOT_MATCH\",\n (offerId: string | undefined, customerId: string, offerCustomerType: \"user\" | \"team\" | \"custom\" | undefined, actualCustomerType: \"user\" | \"team\" | \"custom\") => [\n 400,\n `The ${actualCustomerType} with ID ${JSON.stringify(customerId)} is not a valid customer for the inline offer that has been passed in. ${offerCustomerType ? `The offer is configured to only be available for ${offerCustomerType} customers, but the customer is a ${actualCustomerType}.` : `The offer is missing a customer type field. Please make sure it is set up correctly in your project configuration.`}`,\n {\n offer_id: offerId ?? null,\n customer_id: customerId,\n offer_customer_type: offerCustomerType ?? null,\n actual_customer_type: actualCustomerType,\n },\n ] as const,\n (json) => [json.offer_id ?? undefined, json.customer_id, json.offer_customer_type ?? undefined, json.actual_customer_type] as const,\n);\n\nconst ItemQuantityInsufficientAmount = createKnownErrorConstructor(\n KnownError,\n \"ITEM_QUANTITY_INSUFFICIENT_AMOUNT\",\n (itemId: string, customerId: string, quantity: number) => [\n 400,\n `The item with ID ${JSON.stringify(itemId)} has an insufficient quantity for the customer with ID ${JSON.stringify(customerId)}. An attempt was made to charge ${quantity} credits.`,\n {\n item_id: itemId,\n customer_id: customerId,\n quantity,\n },\n ] as const,\n (json) => [json.item_id, json.customer_id, json.quantity] as const,\n);\n\nconst StripeAccountInfoNotFound = createKnownErrorConstructor(\n KnownError,\n \"STRIPE_ACCOUNT_INFO_NOT_FOUND\",\n () => [\n 404,\n \"Stripe account information not found. Please make sure the user has onboarded with Stripe.\",\n ] as const,\n () => [] as const,\n);\n\n\nexport type KnownErrors = {\n [K in keyof typeof KnownErrors]: InstanceType<typeof KnownErrors[K]>;\n};\n\nexport const KnownErrors = {\n CannotDeleteCurrentSession,\n UnsupportedError,\n BodyParsingError,\n SchemaError,\n AllOverloadsFailed,\n ProjectAuthenticationError,\n PermissionIdAlreadyExists,\n CliAuthError,\n CliAuthExpiredError,\n CliAuthUsedError,\n InvalidProjectAuthentication,\n ProjectKeyWithoutAccessType,\n InvalidAccessType,\n AccessTypeWithoutProjectId,\n AccessTypeRequired,\n CannotGetOwnUserWithoutUser,\n InsufficientAccessType,\n InvalidPublishableClientKey,\n InvalidSecretServerKey,\n InvalidSuperSecretAdminKey,\n InvalidAdminAccessToken,\n UnparsableAdminAccessToken,\n AdminAccessTokenExpired,\n InvalidProjectForAdminAccessToken,\n AdminAccessTokenIsNotAdmin,\n ProjectAuthenticationRequired,\n ClientAuthenticationRequired,\n ServerAuthenticationRequired,\n ClientOrServerAuthenticationRequired,\n ClientOrAdminAuthenticationRequired,\n ClientOrServerOrAdminAuthenticationRequired,\n AdminAuthenticationRequired,\n ExpectedInternalProject,\n SessionAuthenticationError,\n InvalidSessionAuthentication,\n InvalidAccessToken,\n UnparsableAccessToken,\n AccessTokenExpired,\n InvalidProjectForAccessToken,\n RefreshTokenError,\n ProviderRejected,\n RefreshTokenNotFoundOrExpired,\n UserWithEmailAlreadyExists,\n EmailNotVerified,\n UserIdDoesNotExist,\n UserNotFound,\n ApiKeyNotFound,\n PublicApiKeyCannotBeRevoked,\n ProjectNotFound,\n CurrentProjectNotFound,\n BranchDoesNotExist,\n SignUpNotEnabled,\n PasswordAuthenticationNotEnabled,\n PasskeyAuthenticationNotEnabled,\n AnonymousAccountsNotEnabled,\n AnonymousAuthenticationNotAllowed,\n EmailPasswordMismatch,\n RedirectUrlNotWhitelisted,\n PasswordRequirementsNotMet,\n PasswordTooShort,\n PasswordTooLong,\n UserDoesNotHavePassword,\n VerificationCodeError,\n VerificationCodeNotFound,\n VerificationCodeExpired,\n VerificationCodeAlreadyUsed,\n VerificationCodeMaxAttemptsReached,\n PasswordConfirmationMismatch,\n EmailAlreadyVerified,\n EmailNotAssociatedWithUser,\n EmailIsNotPrimaryEmail,\n PasskeyRegistrationFailed,\n PasskeyWebAuthnError,\n PasskeyAuthenticationFailed,\n PermissionNotFound,\n PermissionScopeMismatch,\n ContainedPermissionNotFound,\n TeamNotFound,\n TeamMembershipNotFound,\n EmailTemplateAlreadyExists,\n OAuthConnectionNotConnectedToUser,\n OAuthConnectionAlreadyConnectedToAnotherUser,\n OAuthConnectionDoesNotHaveRequiredScope,\n OAuthExtraScopeNotAvailableWithSharedOAuthKeys,\n OAuthAccessTokenNotAvailableWithSharedOAuthKeys,\n InvalidOAuthClientIdOrSecret,\n InvalidScope,\n UserAlreadyConnectedToAnotherOAuthConnection,\n OuterOAuthTimeout,\n OAuthProviderNotFoundOrNotEnabled,\n OAuthProviderAccountIdAlreadyUsedForSignIn,\n MultiFactorAuthenticationRequired,\n InvalidTotpCode,\n UserAuthenticationRequired,\n TeamMembershipAlreadyExists,\n ProjectPermissionRequired,\n TeamPermissionRequired,\n InvalidSharedOAuthProviderId,\n InvalidStandardOAuthProviderId,\n InvalidAuthorizationCode,\n TeamPermissionNotFound,\n OAuthProviderAccessDenied,\n ContactChannelAlreadyUsedForAuthBySomeoneElse,\n InvalidPollingCodeError,\n ApiKeyNotValid,\n ApiKeyExpired,\n ApiKeyRevoked,\n WrongApiKeyType,\n EmailRenderingError,\n RequiresCustomEmailServer,\n ItemNotFound,\n ItemCustomerTypeDoesNotMatch,\n CustomerDoesNotExist,\n OfferDoesNotExist,\n OfferCustomerTypeDoesNotMatch,\n ItemQuantityInsufficientAmount,\n StripeAccountInfoNotFound,\n DataVaultStoreDoesNotExist,\n DataVaultStoreHashedKeyDoesNotExist,\n} satisfies Record<string, KnownErrorConstructor<any, any>>;\n\n\n// ensure that all known error codes are unique\nconst knownErrorCodes = new Set<string>();\nfor (const [_, KnownError] of Object.entries(KnownErrors)) {\n if (knownErrorCodes.has(KnownError.errorCode)) {\n throw new Error(`Duplicate known error code: ${KnownError.errorCode}`);\n }\n knownErrorCodes.add(KnownError.errorCode);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2D;AAC3D,uBAA6B;AAE7B,qBAAyB;AAqBlB,IAAe,aAAf,cAAkC,0BAAY;AAAA,EAInD,YACkB,YACA,sBACA,SAChB;AACA;AAAA,MACE;AAAA,MACA;AAAA,IACF;AAPgB;AACA;AACA;AANlB,SAAiB,yBAAyB;AAC1C,SAAO,OAAO;AAAA,EAWd;AAAA,EAEA,OAAc,aAAa,OAAqC;AAE9D,WAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,4BAA4B,SAAS,MAAM,2BAA2B;AAAA,EAC9H;AAAA,EAEgB,UAAsB;AACpC,WAAO,IAAI,YAAY,EAAE,OAAO,KAAK,UAAU,KAAK,kBAAkB,GAAG,QAAW,CAAC,CAAC;AAAA,EACxF;AAAA,EAEgB,aAAuC;AACrD,WA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;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAIA,IAAM,kBAAkB,oBAAI,IAAY;AACxC,WAAW,CAAC,GAAGA,WAAU,KAAK,OAAO,QAAQ,WAAW,GAAG;AACzD,MAAI,gBAAgB,IAAIA,YAAW,SAAS,GAAG;AAC7C,UAAM,IAAI,MAAM,+BAA+BA,YAAW,SAAS,EAAE;AAAA,EACvE;AACA,kBAAgB,IAAIA,YAAW,SAAS;AAC1C;","names":["KnownError"]}
@@ -220,8 +220,8 @@ declare const inlineOfferSchema: yup.ObjectSchema<{
220
220
  interval?: DayInterval | undefined;
221
221
  }>;
222
222
  included_items: Record<string, {
223
- quantity?: number | undefined;
224
223
  repeat?: "never" | DayInterval | undefined;
224
+ quantity?: number | undefined;
225
225
  expires?: "never" | "when-purchase-expires" | "when-repeated" | undefined;
226
226
  }>;
227
227
  }, yup.AnyObject, {
@@ -220,8 +220,8 @@ declare const inlineOfferSchema: yup.ObjectSchema<{
220
220
  interval?: DayInterval | undefined;
221
221
  }>;
222
222
  included_items: Record<string, {
223
- quantity?: number | undefined;
224
223
  repeat?: "never" | DayInterval | undefined;
224
+ quantity?: number | undefined;
225
225
  expires?: "never" | "when-purchase-expires" | "when-repeated" | undefined;
226
226
  }>;
227
227
  }, yup.AnyObject, {
@@ -106,8 +106,7 @@ function decodeBase32(input) {
106
106
  return output;
107
107
  }
108
108
  function encodeBase64(input) {
109
- const res = btoa(String.fromCharCode(...input));
110
- return res;
109
+ return btoa([...input].map((b) => String.fromCharCode(b)).join(""));
111
110
  }
112
111
  function decodeBase64(input) {
113
112
  return new Uint8Array(atob(input).split("").map((char) => char.charCodeAt(0)));
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/bytes.tsx"],"sourcesContent":["import { StackAssertionError } from \"./errors\";\n\nconst crockfordAlphabet = \"0123456789ABCDEFGHJKMNPQRSTVWXYZ\";\nconst crockfordReplacements = new Map([\n [\"o\", \"0\"],\n [\"i\", \"1\"],\n [\"l\", \"1\"],\n]);\n\nexport function toHexString(input: Uint8Array): string {\n return Array.from(input).map(b => b.toString(16).padStart(2, \"0\")).join(\"\");\n}\nundefined?.test(\"toHexString\", ({ expect }) => {\n expect(toHexString(new Uint8Array([]))).toBe(\"\");\n expect(toHexString(new Uint8Array([0]))).toBe(\"00\");\n expect(toHexString(new Uint8Array([15]))).toBe(\"0f\");\n expect(toHexString(new Uint8Array([16]))).toBe(\"10\");\n expect(toHexString(new Uint8Array([255]))).toBe(\"ff\");\n expect(toHexString(new Uint8Array([1, 2, 3]))).toBe(\"010203\");\n});\n\nexport function getBase32CharacterFromIndex(index: number): string {\n if (index < 0 || index >= crockfordAlphabet.length) {\n throw new StackAssertionError(`Invalid base32 index: ${index}`);\n }\n return crockfordAlphabet[index];\n}\nundefined?.test(\"getBase32CharacterFromIndex\", ({ expect }) => {\n expect(getBase32CharacterFromIndex(0)).toBe(\"0\");\n expect(getBase32CharacterFromIndex(15)).toBe(\"F\");\n expect(() => getBase32CharacterFromIndex(32)).toThrow();\n});\n\nexport function getBase32IndexFromCharacter(character: string): number {\n if (character.length !== 1) {\n throw new StackAssertionError(`Invalid base32 character: ${character}`);\n }\n const index = crockfordAlphabet.indexOf(character.toUpperCase());\n if (index === -1) {\n throw new StackAssertionError(`Invalid base32 character: ${character}`);\n }\n return index;\n}\nundefined?.test(\"getBase32IndexFromCharacter\", ({ expect }) => {\n expect(getBase32IndexFromCharacter(\"0\")).toBe(0);\n expect(getBase32IndexFromCharacter(\"F\")).toBe(15);\n expect(() => getBase32IndexFromCharacter(\"_\")).toThrow();\n});\n\nexport function encodeBase32(input: Uint8Array): string {\n let bits = 0;\n let value = 0;\n let output = \"\";\n for (let i = 0; i < input.length; i++) {\n value = (value << 8) | input[i];\n bits += 8;\n while (bits >= 5) {\n output += getBase32CharacterFromIndex((value >>> (bits - 5)) & 31);\n bits -= 5;\n }\n }\n if (bits > 0) {\n output += getBase32CharacterFromIndex((value << (5 - bits)) & 31);\n }\n\n // sanity check\n if (!isBase32(output)) {\n throw new StackAssertionError(\"Invalid base32 output; this should never happen\");\n }\n\n return output;\n}\nundefined?.test(\"encodeBase32\", ({ expect }) => {\n expect(encodeBase32(new Uint8Array([]))).toBe(\"\");\n expect(encodeBase32(new Uint8Array([1]))).toBe(\"04\");\n expect(encodeBase32(new Uint8Array([15]))).toBe(\"1W\");\n expect(encodeBase32(new Uint8Array([16]))).toBe(\"20\");\n expect(encodeBase32(new Uint8Array([255]))).toBe(\"ZW\");\n expect(encodeBase32(new Uint8Array([255,255]))).toBe(\"ZZZG\");\n});\nexport function decodeBase32(input: string): Uint8Array {\n if (!isBase32(input)) {\n throw new StackAssertionError(\"Invalid base32 string\");\n }\n\n const output = new Uint8Array((input.length * 5 / 8) | 0);\n let bits = 0;\n let value = 0;\n let outputIndex = 0;\n for (let i = 0; i < input.length; i++) {\n let char = input[i].toLowerCase();\n if (char === \" \") continue;\n if (crockfordReplacements.has(char)) {\n char = crockfordReplacements.get(char)!;\n }\n const index = getBase32IndexFromCharacter(char);\n value = (value << 5) | index;\n bits += 5;\n if (bits >= 8) {\n output[outputIndex++] = (value >>> (bits - 8)) & 255;\n bits -= 8;\n }\n }\n return output;\n}\nundefined?.test(\"decodeBase32\", ({ expect }) => {\n expect(decodeBase32(\"\")).toEqual(new Uint8Array([]));\n expect(decodeBase32(\"00\")).toEqual(new Uint8Array([0]));\n expect(decodeBase32(\"1W\")).toEqual(new Uint8Array([15]));\n expect(decodeBase32(\"20\")).toEqual(new Uint8Array([16]));\n expect(decodeBase32(\"ZW\")).toEqual(new Uint8Array([255]));\n});\n\nexport function encodeBase64(input: Uint8Array): string {\n const res = btoa(String.fromCharCode(...input));\n\n return res;\n}\n\nexport function decodeBase64(input: string): Uint8Array {\n return new Uint8Array(atob(input).split(\"\").map((char) => char.charCodeAt(0)));\n}\nundefined?.test(\"encodeBase64/decodeBase64\", ({ expect }) => {\n const testCases = [\n { input: new Uint8Array([72, 101, 108, 108, 111]), expected: \"SGVsbG8=\" },\n { input: new Uint8Array([0, 1, 2, 3, 4]), expected: \"AAECAwQ=\" },\n { input: new Uint8Array([255, 254, 253, 252]), expected: \"//79/A==\" },\n { input: new Uint8Array([]), expected: \"\" },\n ];\n\n for (const { input, expected } of testCases) {\n const encoded = encodeBase64(input);\n expect(encoded).toBe(expected);\n const decoded = decodeBase64(encoded);\n expect(decoded).toEqual(input);\n }\n\n // Test invalid input for decodeBase64\n expect(() => decodeBase64(\"invalid!\")).toThrow();\n});\n\nexport function encodeBase64Url(input: Uint8Array): string {\n const res = encodeBase64(input).replace(/=+$/, \"\").replace(/\\+/g, \"-\").replace(/\\//g, \"_\");\n\n // Skip sanity check for test cases\n // This avoids circular dependency with isBase64Url function\n return res;\n}\n\nexport function decodeBase64Url(input: string): Uint8Array {\n if (!isBase64Url(input)) {\n throw new StackAssertionError(\"Invalid base64url string\");\n }\n\n // Handle empty string case\n if (input === \"\") {\n return new Uint8Array(0);\n }\n\n return decodeBase64(input.replace(/-/g, \"+\").replace(/_/g, \"/\") + \"====\".slice((input.length - 1) % 4 + 1));\n}\nundefined?.test(\"encodeBase64Url/decodeBase64Url\", ({ expect }) => {\n const testCases = [\n { input: new Uint8Array([72, 101, 108, 108, 111]), expected: \"SGVsbG8\" },\n { input: new Uint8Array([0, 1, 2, 3, 4]), expected: \"AAECAwQ\" },\n { input: new Uint8Array([255, 254, 253, 252]), expected: \"__79_A\" },\n { input: new Uint8Array([]), expected: \"\" },\n ];\n\n for (const { input, expected } of testCases) {\n const encoded = encodeBase64Url(input);\n expect(encoded).toBe(expected);\n const decoded = decodeBase64Url(encoded);\n expect(decoded).toEqual(input);\n }\n\n // Test invalid input for decodeBase64Url\n expect(() => decodeBase64Url(\"invalid!\")).toThrow();\n});\n\nexport function decodeBase64OrBase64Url(input: string): Uint8Array {\n if (isBase64Url(input)) {\n return decodeBase64Url(input);\n } else if (isBase64(input)) {\n return decodeBase64(input);\n } else {\n throw new StackAssertionError(\"Invalid base64 or base64url string\");\n }\n}\nundefined?.test(\"decodeBase64OrBase64Url\", ({ expect }) => {\n // Test with base64 input\n const base64Input = \"SGVsbG8gV29ybGQ=\";\n const base64Expected = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]);\n expect(decodeBase64OrBase64Url(base64Input)).toEqual(base64Expected);\n\n // Test with base64url input\n const base64UrlInput = \"SGVsbG8gV29ybGQ\";\n const base64UrlExpected = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]);\n expect(decodeBase64OrBase64Url(base64UrlInput)).toEqual(base64UrlExpected);\n\n // Test with invalid input\n expect(() => decodeBase64OrBase64Url(\"invalid!\")).toThrow();\n});\n\nexport function isBase32(input: string): boolean {\n for (const char of input) {\n if (char === \" \") continue;\n const upperChar = char.toUpperCase();\n // Check if the character is in the Crockford alphabet\n if (!crockfordAlphabet.includes(upperChar)) {\n return false;\n }\n }\n return true;\n}\nundefined?.test(\"isBase32\", ({ expect }) => {\n expect(isBase32(\"0123456789ABCDEFGHJKMNPQRSTVWXYZ\")).toBe(true);\n expect(isBase32(\"0OIJ\")).toBe(false); // O and I are not allowed\n expect(isBase32(\"ABC DEF\")).toBe(true); // Spaces are allowed\n expect(isBase32(\"ABC!\")).toBe(false); // Special characters not allowed\n expect(isBase32(\"\")).toBe(true);\n});\n\nexport function isBase64(input: string): boolean {\n // This regex allows for standard base64 with proper padding\n const regex = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;\n return regex.test(input);\n}\nundefined?.test(\"isBase64\", ({ expect }) => {\n expect(isBase64(\"SGVsbG8gV29ybGQ=\")).toBe(true);\n expect(isBase64(\"SGVsbG8gV29ybGQ\")).toBe(false); // No padding\n expect(isBase64(\"SGVsbG8gV29ybGQ==\")).toBe(false); // Wrong padding\n expect(isBase64(\"SGVsbG8!V29ybGQ=\")).toBe(false); // Invalid character\n expect(isBase64(\"\")).toBe(true);\n});\n\nexport function isBase64Url(input: string): boolean {\n if (input === \"\") {\n return true;\n }\n const regex = /^[0-9a-zA-Z_-]+$/;\n return regex.test(input);\n}\nundefined?.test(\"isBase64Url\", ({ expect }) => {\n expect(isBase64Url(\"SGVsbG8gV2 9ybGQ\")).toBe(false); // Space is not valid\n expect(isBase64Url(\"SGVsbG8_V29ybGQ\")).toBe(true); // _ is a valid character\n expect(isBase64Url(\"SGVsbG8-V29ybGQ\")).toBe(true); // - is valid\n expect(isBase64Url(\"SGVsbG8_V29ybGQ=\")).toBe(false); // = not allowed\n expect(isBase64Url(\"\")).toBe(true); // Empty string is valid\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoC;AAEpC,IAAM,oBAAoB;AAC1B,IAAM,wBAAwB,oBAAI,IAAI;AAAA,EACpC,CAAC,KAAK,GAAG;AAAA,EACT,CAAC,KAAK,GAAG;AAAA,EACT,CAAC,KAAK,GAAG;AACX,CAAC;AAEM,SAAS,YAAY,OAA2B;AACrD,SAAO,MAAM,KAAK,KAAK,EAAE,IAAI,OAAK,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AAC5E;AAUO,SAAS,4BAA4B,OAAuB;AACjE,MAAI,QAAQ,KAAK,SAAS,kBAAkB,QAAQ;AAClD,UAAM,IAAI,kCAAoB,yBAAyB,KAAK,EAAE;AAAA,EAChE;AACA,SAAO,kBAAkB,KAAK;AAChC;AAOO,SAAS,4BAA4B,WAA2B;AACrE,MAAI,UAAU,WAAW,GAAG;AAC1B,UAAM,IAAI,kCAAoB,6BAA6B,SAAS,EAAE;AAAA,EACxE;AACA,QAAM,QAAQ,kBAAkB,QAAQ,UAAU,YAAY,CAAC;AAC/D,MAAI,UAAU,IAAI;AAChB,UAAM,IAAI,kCAAoB,6BAA6B,SAAS,EAAE;AAAA,EACxE;AACA,SAAO;AACT;AAOO,SAAS,aAAa,OAA2B;AACtD,MAAI,OAAO;AACX,MAAI,QAAQ;AACZ,MAAI,SAA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BO,SAAS,gBAAgB,OAA2B;AACzD,QAAM,MAAM,aAAa,KAAK,EAAE,QAAQ,OAAO,EAAE,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG;AAIzF,SAAO;AACT;AAEO,SAAS,gBAAgB,OAA2B;AACzD,MAAI,CAAC,YAAY,KAAK,GAAG;AACvB,UAAM,IAAI,kCAAoB,0BAA0B;AAAA,EAC1D;AAGA,MAAI,UAAU,IAAI;AAChB,WAAO,IAAI,WAAW,CAAC;AAAA,EACzB;AAEA,SAAO,aAAa,MAAM,QAAQ,MAAM,GAAG,EAAE,QAAQ,MAAM,GAAG,IAAI,OAAO,OAAO,MAAM,SAAS,KAAK,IAAI,CAAC,CAAC;AAC5G;AAoBO,SAAS,wBAAwB,OAA2B;AACjE,MAAI,YAAY,KAAK,GAAG;AACtB,WAAO,gBAAgB,KAAK;AAAA,EAC9B,WAAW,SAAS,KAAK,GAAG;AAC1B,WAAO,aAAa,KAAK;AAAA,EAC3B,OAAO;AACL,UAAM,IAAI,kCAAoB,oCAAoC;AAAA,EACpE;AACF;AAgBO,SAAS,SAAS,OAAwB;AAC/C,aAAW,QAAQ,OAAO;AACxB,QAAI,SAAS,IAAK;AAClB,UAAM,YAAY,KAAK,YAAY;AAEnC,QAAI,CAAC,kBAAkB,SAAS,SAAS,GAAG;AAC1C,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AASO,SAAS,SAAS,OAAwB;AAE/C,QAAM,QAAQ;AACd,SAAO,MAAM,KAAK,KAAK;AACzB;AASO,SAAS,YAAY,OAAwB;AAClD,MAAI,UAAU,IAAI;AAChB,WAAO;AAAA,EACT;AACA,QAAM,QAAQ;AACd,SAAO,MAAM,KAAK,KAAK;AACzB;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/bytes.tsx"],"sourcesContent":["import { StackAssertionError } from \"./errors\";\n\nconst crockfordAlphabet = \"0123456789ABCDEFGHJKMNPQRSTVWXYZ\";\nconst crockfordReplacements = new Map([\n [\"o\", \"0\"],\n [\"i\", \"1\"],\n [\"l\", \"1\"],\n]);\n\nexport function toHexString(input: Uint8Array): string {\n return Array.from(input).map(b => b.toString(16).padStart(2, \"0\")).join(\"\");\n}\nundefined?.test(\"toHexString\", ({ expect }) => {\n expect(toHexString(new Uint8Array([]))).toBe(\"\");\n expect(toHexString(new Uint8Array([0]))).toBe(\"00\");\n expect(toHexString(new Uint8Array([15]))).toBe(\"0f\");\n expect(toHexString(new Uint8Array([16]))).toBe(\"10\");\n expect(toHexString(new Uint8Array([255]))).toBe(\"ff\");\n expect(toHexString(new Uint8Array([1, 2, 3]))).toBe(\"010203\");\n});\n\nexport function getBase32CharacterFromIndex(index: number): string {\n if (index < 0 || index >= crockfordAlphabet.length) {\n throw new StackAssertionError(`Invalid base32 index: ${index}`);\n }\n return crockfordAlphabet[index];\n}\nundefined?.test(\"getBase32CharacterFromIndex\", ({ expect }) => {\n expect(getBase32CharacterFromIndex(0)).toBe(\"0\");\n expect(getBase32CharacterFromIndex(15)).toBe(\"F\");\n expect(() => getBase32CharacterFromIndex(32)).toThrow();\n});\n\nexport function getBase32IndexFromCharacter(character: string): number {\n if (character.length !== 1) {\n throw new StackAssertionError(`Invalid base32 character: ${character}`);\n }\n const index = crockfordAlphabet.indexOf(character.toUpperCase());\n if (index === -1) {\n throw new StackAssertionError(`Invalid base32 character: ${character}`);\n }\n return index;\n}\nundefined?.test(\"getBase32IndexFromCharacter\", ({ expect }) => {\n expect(getBase32IndexFromCharacter(\"0\")).toBe(0);\n expect(getBase32IndexFromCharacter(\"F\")).toBe(15);\n expect(() => getBase32IndexFromCharacter(\"_\")).toThrow();\n});\n\nexport function encodeBase32(input: Uint8Array): string {\n let bits = 0;\n let value = 0;\n let output = \"\";\n for (let i = 0; i < input.length; i++) {\n value = (value << 8) | input[i];\n bits += 8;\n while (bits >= 5) {\n output += getBase32CharacterFromIndex((value >>> (bits - 5)) & 31);\n bits -= 5;\n }\n }\n if (bits > 0) {\n output += getBase32CharacterFromIndex((value << (5 - bits)) & 31);\n }\n\n // sanity check\n if (!isBase32(output)) {\n throw new StackAssertionError(\"Invalid base32 output; this should never happen\");\n }\n\n return output;\n}\nundefined?.test(\"encodeBase32\", ({ expect }) => {\n expect(encodeBase32(new Uint8Array([]))).toBe(\"\");\n expect(encodeBase32(new Uint8Array([1]))).toBe(\"04\");\n expect(encodeBase32(new Uint8Array([15]))).toBe(\"1W\");\n expect(encodeBase32(new Uint8Array([16]))).toBe(\"20\");\n expect(encodeBase32(new Uint8Array([255]))).toBe(\"ZW\");\n expect(encodeBase32(new Uint8Array([255,255]))).toBe(\"ZZZG\");\n});\nexport function decodeBase32(input: string): Uint8Array {\n if (!isBase32(input)) {\n throw new StackAssertionError(\"Invalid base32 string\");\n }\n\n const output = new Uint8Array((input.length * 5 / 8) | 0);\n let bits = 0;\n let value = 0;\n let outputIndex = 0;\n for (let i = 0; i < input.length; i++) {\n let char = input[i].toLowerCase();\n if (char === \" \") continue;\n if (crockfordReplacements.has(char)) {\n char = crockfordReplacements.get(char)!;\n }\n const index = getBase32IndexFromCharacter(char);\n value = (value << 5) | index;\n bits += 5;\n if (bits >= 8) {\n output[outputIndex++] = (value >>> (bits - 8)) & 255;\n bits -= 8;\n }\n }\n return output;\n}\nundefined?.test(\"decodeBase32\", ({ expect }) => {\n expect(decodeBase32(\"\")).toEqual(new Uint8Array([]));\n expect(decodeBase32(\"00\")).toEqual(new Uint8Array([0]));\n expect(decodeBase32(\"1W\")).toEqual(new Uint8Array([15]));\n expect(decodeBase32(\"20\")).toEqual(new Uint8Array([16]));\n expect(decodeBase32(\"ZW\")).toEqual(new Uint8Array([255]));\n});\n\nexport function encodeBase64(input: Uint8Array): string {\n return btoa([...input].map((b) => String.fromCharCode(b)).join(\"\"));\n}\n\nexport function decodeBase64(input: string): Uint8Array {\n return new Uint8Array(atob(input).split(\"\").map((char) => char.charCodeAt(0)));\n}\nundefined?.test(\"encodeBase64/decodeBase64\", ({ expect }) => {\n const testCases = [\n { input: new Uint8Array([72, 101, 108, 108, 111]), expected: \"SGVsbG8=\" },\n { input: new Uint8Array([0, 1, 2, 3, 4]), expected: \"AAECAwQ=\" },\n { input: new Uint8Array([255, 254, 253, 252]), expected: \"//79/A==\" },\n { input: new Uint8Array([]), expected: \"\" },\n {\n input: (() => {\n // make sure huge inputs are supported; 48MB array of every possible triple-byte combination\n const input = new Uint8Array(3 * (2 ** 24));\n for (let i = 0; i < input.length / 3; i++) {\n input[3 * i] = Math.floor(i / 256 / 256);\n input[3 * i + 1] = Math.floor(i / 256) % 256;\n input[3 * i + 2] = i % 256;\n }\n return input;\n })(),\n expected: (() => {\n const base64Alphabet = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n const output = [];\n for (let i = 0; i < 2 ** 24; i++) {\n output.push(\n base64Alphabet[Math.floor(i / 64 / 64 / 64)]\n + base64Alphabet[Math.floor(i / 64 / 64) % 64]\n + base64Alphabet[Math.floor(i / 64) % 64]\n + base64Alphabet[i % 64]\n );\n }\n return output.join(\"\");\n })(),\n },\n ];\n\n for (const [i, { input, expected }] of testCases.entries()) {\n // expect(...) is pretty slow with long inputs, so we throw our own assertions\n const encoded = encodeBase64(input);\n if (encoded !== expected) {\n throw new StackAssertionError(`encodeBase64 test case ${i} failed`);\n }\n const decoded = decodeBase64(encoded);\n if (decoded.some((b, i) => b !== input[i])) {\n throw new StackAssertionError(`decodeBase64 test case ${i} failed`);\n }\n }\n\n // Test invalid input for decodeBase64\n expect(() => decodeBase64(\"invalid!\")).toThrow();\n}, {\n timeout: 30000,\n});\n\nexport function encodeBase64Url(input: Uint8Array): string {\n const res = encodeBase64(input).replace(/=+$/, \"\").replace(/\\+/g, \"-\").replace(/\\//g, \"_\");\n\n // Skip sanity check for test cases\n // This avoids circular dependency with isBase64Url function\n return res;\n}\n\nexport function decodeBase64Url(input: string): Uint8Array {\n if (!isBase64Url(input)) {\n throw new StackAssertionError(\"Invalid base64url string\");\n }\n\n // Handle empty string case\n if (input === \"\") {\n return new Uint8Array(0);\n }\n\n return decodeBase64(input.replace(/-/g, \"+\").replace(/_/g, \"/\") + \"====\".slice((input.length - 1) % 4 + 1));\n}\nundefined?.test(\"encodeBase64Url/decodeBase64Url\", ({ expect }) => {\n const testCases = [\n { input: new Uint8Array([72, 101, 108, 108, 111]), expected: \"SGVsbG8\" },\n { input: new Uint8Array([0, 1, 2, 3, 4]), expected: \"AAECAwQ\" },\n { input: new Uint8Array([255, 254, 253, 252]), expected: \"__79_A\" },\n { input: new Uint8Array([]), expected: \"\" },\n ];\n\n for (const { input, expected } of testCases) {\n const encoded = encodeBase64Url(input);\n expect(encoded).toBe(expected);\n const decoded = decodeBase64Url(encoded);\n expect(decoded).toEqual(input);\n }\n\n // Test invalid input for decodeBase64Url\n expect(() => decodeBase64Url(\"invalid!\")).toThrow();\n});\n\nexport function decodeBase64OrBase64Url(input: string): Uint8Array {\n if (isBase64Url(input)) {\n return decodeBase64Url(input);\n } else if (isBase64(input)) {\n return decodeBase64(input);\n } else {\n throw new StackAssertionError(\"Invalid base64 or base64url string\");\n }\n}\nundefined?.test(\"decodeBase64OrBase64Url\", ({ expect }) => {\n // Test with base64 input\n const base64Input = \"SGVsbG8gV29ybGQ=\";\n const base64Expected = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]);\n expect(decodeBase64OrBase64Url(base64Input)).toEqual(base64Expected);\n\n // Test with base64url input\n const base64UrlInput = \"SGVsbG8gV29ybGQ\";\n const base64UrlExpected = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]);\n expect(decodeBase64OrBase64Url(base64UrlInput)).toEqual(base64UrlExpected);\n\n // Test with invalid input\n expect(() => decodeBase64OrBase64Url(\"invalid!\")).toThrow();\n});\n\nexport function isBase32(input: string): boolean {\n for (const char of input) {\n if (char === \" \") continue;\n const upperChar = char.toUpperCase();\n // Check if the character is in the Crockford alphabet\n if (!crockfordAlphabet.includes(upperChar)) {\n return false;\n }\n }\n return true;\n}\nundefined?.test(\"isBase32\", ({ expect }) => {\n expect(isBase32(\"0123456789ABCDEFGHJKMNPQRSTVWXYZ\")).toBe(true);\n expect(isBase32(\"0OIJ\")).toBe(false); // O and I are not allowed\n expect(isBase32(\"ABC DEF\")).toBe(true); // Spaces are allowed\n expect(isBase32(\"ABC!\")).toBe(false); // Special characters not allowed\n expect(isBase32(\"\")).toBe(true);\n});\n\nexport function isBase64(input: string): boolean {\n // This regex allows for standard base64 with proper padding\n const regex = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;\n return regex.test(input);\n}\nundefined?.test(\"isBase64\", ({ expect }) => {\n expect(isBase64(\"SGVsbG8gV29ybGQ=\")).toBe(true);\n expect(isBase64(\"SGVsbG8gV29ybGQ\")).toBe(false); // No padding\n expect(isBase64(\"SGVsbG8gV29ybGQ==\")).toBe(false); // Wrong padding\n expect(isBase64(\"SGVsbG8!V29ybGQ=\")).toBe(false); // Invalid character\n expect(isBase64(\"\")).toBe(true);\n});\n\nexport function isBase64Url(input: string): boolean {\n if (input === \"\") {\n return true;\n }\n const regex = /^[0-9a-zA-Z_-]+$/;\n return regex.test(input);\n}\nundefined?.test(\"isBase64Url\", ({ expect }) => {\n expect(isBase64Url(\"SGVsbG8gV2 9ybGQ\")).toBe(false); // Space is not valid\n expect(isBase64Url(\"SGVsbG8_V29ybGQ\")).toBe(true); // _ is a valid character\n expect(isBase64Url(\"SGVsbG8-V29ybGQ\")).toBe(true); // - is valid\n expect(isBase64Url(\"SGVsbG8_V29ybGQ=\")).toBe(false); // = not allowed\n expect(isBase64Url(\"\")).toBe(true); // Empty string is valid\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoC;AAEpC,IAAM,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GAAG,IAAI,OAAO,OAAO,MAAM,SAAS,KAAK,IAAI,CAAC,CAAC;AAC5G;AAoBO,SAAS,wBAAwB,OAA2B;AACjE,MAAI,YAAY,KAAK,GAAG;AACtB,WAAO,gBAAgB,KAAK;AAAA,EAC9B,WAAW,SAAS,KAAK,GAAG;AAC1B,WAAO,aAAa,KAAK;AAAA,EAC3B,OAAO;AACL,UAAM,IAAI,kCAAoB,oCAAoC;AAAA,EACpE;AACF;AAgBO,SAAS,SAAS,OAAwB;AAC/C,aAAW,QAAQ,OAAO;AACxB,QAAI,SAAS,IAAK;AAClB,UAAM,YAAY,KAAK,YAAY;AAEnC,QAAI,CAAC,kBAAkB,SAAS,SAAS,GAAG;AAC1C,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AASO,SAAS,SAAS,OAAwB;AAE/C,QAAM,QAAQ;AACd,SAAO,MAAM,KAAK,KAAK;AACzB;AASO,SAAS,YAAY,OAAwB;AAClD,MAAI,UAAU,IAAI;AAChB,WAAO;AAAA,EACT;AACA,QAAM,QAAQ;AACd,SAAO,MAAM,KAAK,KAAK;AACzB;","names":[]}
@@ -4,5 +4,35 @@ declare function generateRandomValues(array: Uint8Array): typeof array;
4
4
  * random number generator.
5
5
  */
6
6
  declare function generateSecureRandomString(minBitsOfEntropy?: number): string;
7
+ declare function encrypt({ purpose, secret, value }: {
8
+ purpose: string;
9
+ secret: string | Uint8Array;
10
+ value: Uint8Array;
11
+ }): Promise<Uint8Array>;
12
+ declare function decrypt({ purpose, secret, cipher }: {
13
+ purpose: string;
14
+ secret: string | Uint8Array;
15
+ cipher: Uint8Array;
16
+ }): Promise<({
17
+ status: "ok";
18
+ data: Uint8Array;
19
+ } & {
20
+ status: "ok";
21
+ }) | ({
22
+ status: "error";
23
+ error: Error;
24
+ } & {
25
+ status: "error";
26
+ })>;
27
+ type HashOptions = {
28
+ purpose: string;
29
+ salt?: string | Uint8Array;
30
+ extra?: string | Uint8Array;
31
+ value: string | Uint8Array;
32
+ };
33
+ declare function hash(options: HashOptions): Promise<Uint8Array>;
34
+ declare function iteratedHash(options: HashOptions & {
35
+ iterations: number;
36
+ }): Promise<Uint8Array>;
7
37
 
8
- export { generateRandomValues, generateSecureRandomString };
38
+ export { type HashOptions, decrypt, encrypt, generateRandomValues, generateSecureRandomString, hash, iteratedHash };
@@ -4,5 +4,35 @@ declare function generateRandomValues(array: Uint8Array): typeof array;
4
4
  * random number generator.
5
5
  */
6
6
  declare function generateSecureRandomString(minBitsOfEntropy?: number): string;
7
+ declare function encrypt({ purpose, secret, value }: {
8
+ purpose: string;
9
+ secret: string | Uint8Array;
10
+ value: Uint8Array;
11
+ }): Promise<Uint8Array>;
12
+ declare function decrypt({ purpose, secret, cipher }: {
13
+ purpose: string;
14
+ secret: string | Uint8Array;
15
+ cipher: Uint8Array;
16
+ }): Promise<({
17
+ status: "ok";
18
+ data: Uint8Array;
19
+ } & {
20
+ status: "ok";
21
+ }) | ({
22
+ status: "error";
23
+ error: Error;
24
+ } & {
25
+ status: "error";
26
+ })>;
27
+ type HashOptions = {
28
+ purpose: string;
29
+ salt?: string | Uint8Array;
30
+ extra?: string | Uint8Array;
31
+ value: string | Uint8Array;
32
+ };
33
+ declare function hash(options: HashOptions): Promise<Uint8Array>;
34
+ declare function iteratedHash(options: HashOptions & {
35
+ iterations: number;
36
+ }): Promise<Uint8Array>;
7
37
 
8
- export { generateRandomValues, generateSecureRandomString };
38
+ export { type HashOptions, decrypt, encrypt, generateRandomValues, generateSecureRandomString, hash, iteratedHash };