UNPKG

@withstudiocms/auth-kit

Version:

Utilities for managing authentication

159 lines (158 loc) 7.68 kB
import { Effect } from '@withstudiocms/effect'; declare const EncryptionError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & { readonly _tag: "EncryptionError"; } & Readonly<A>; /** * Represents an error that occurs during encryption operations. * * @extends Data.TaggedError<'EncryptionError'> * @template { cause: unknown } - The shape of the error details. * * @property {unknown} cause - The underlying cause of the encryption error. */ export declare class EncryptionError extends EncryptionError_base<{ cause: unknown; }> { } declare const DecryptionError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & { readonly _tag: "DecryptionError"; } & Readonly<A>; /** * Represents an error that occurs during the decryption process. * * @extends Data.TaggedError * @tag DecryptionError * @property {unknown} cause - The underlying cause of the decryption failure. */ export declare class DecryptionError extends DecryptionError_base<{ cause: unknown; }> { } declare const PasswordError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & { readonly _tag: "PasswordError"; } & Readonly<A>; /** * PasswordError is a custom error class for handling password-related errors. * It extends the TaggedError class from the Data module, allowing for structured error handling. */ export declare class PasswordError extends PasswordError_base<{ cause?: unknown; message?: string; }> { } declare const CheckIfUnsafeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & { readonly _tag: "CheckIfUnsafeError"; } & Readonly<A>; /** * Error thrown when a safety check fails, indicating an unsafe condition. * * @extends Data.TaggedError * @template {object} T - The shape of the error data. * @property {string} message - A descriptive message explaining why the error was thrown. */ export declare class CheckIfUnsafeError extends CheckIfUnsafeError_base<{ message: string; }> { } declare const SessionError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & { readonly _tag: "SessionError"; } & Readonly<A>; /** * Represents an error related to session handling within the authentication kit. * * @extends {Data.TaggedError<'SessionError', { cause: unknown }>} * * @example * throw new SessionError({ cause: someError }); * * @property {unknown} cause - The underlying cause of the session error. */ export declare class SessionError extends SessionError_base<{ cause: unknown; }> { } declare const UserError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & { readonly _tag: "UserError"; } & Readonly<A>; /** * Represents an error related to user operations within the authentication kit. * * @extends Data.TaggedError * @template { cause: unknown } - The shape of the error details. * * @example * throw new UserError({ cause: someError }); */ export declare class UserError extends UserError_base<{ cause: unknown; }> { } /** * Executes a function within an Effect context, capturing any thrown errors as an `EncryptionError`. * * @template A - The return type of the function to execute. * @param _try - A function that may throw an error. * @returns An `Effect` that yields the result of the function or an `EncryptionError` if an exception is thrown. */ export declare const useEncryptionError: <A>(_try: () => A) => Effect.Effect<A, EncryptionError>; /** * Executes the provided function within an Effect context, mapping any thrown error * to a `DecryptionError`. * * @typeParam A - The type of the value returned by the function. * @param _try - A function that may throw an error during execution. * @returns An `Effect` that yields the result of the function or a `DecryptionError` if an error is thrown. */ export declare const useDecryptionError: <A>(_try: () => A) => Effect.Effect<A, DecryptionError>; /** * Executes a function that may throw and wraps any thrown error in a `PasswordError`. * * @template A - The return type of the function to execute. * @param _try - A function that may throw an error. * @returns An `Effect` that yields the result of the function or a `PasswordError` if an error is thrown. */ export declare const usePasswordError: <A>(_try: () => A) => Effect.Effect<A, PasswordError>; /** * Executes a function within an Effect, mapping any thrown error to a `SessionError`. * * @template A - The return type of the function to execute. * @param _try - A function that returns a value of type `A`. If this function throws, the error is caught and wrapped in a `SessionError`. * @returns An `Effect` that yields the result of `_try` or fails with a `SessionError` if an error is thrown. */ export declare const useSessionError: <A>(_try: () => A) => Effect.Effect<A, SessionError>; /** * Wraps an asynchronous function in an Effect that captures any thrown errors * and converts them into a `SessionError`. * * @template A The type of the resolved value from the promise. * @param _try - A function that returns a promise to be executed. * @returns An `Effect` that resolves with the value of the promise or fails with a `SessionError`. */ export declare const useSessionErrorPromise: <A>(_try: () => Promise<A>) => Effect.Effect<A, SessionError>; /** * Executes a provided function within an Effect, catching any thrown errors and wrapping them * in a `CheckIfUnsafeError` with a prefixed message. * * @template A - The return type of the function to execute. * @param _try - A function to execute that may throw an error. * @param prefix - A string to prefix to the error message if an error is caught. * @returns An Effect that yields the result of the function or a `CheckIfUnsafeError` if an error occurs. */ export declare const useUnsafeCheckError: <A>(_try: () => A, prefix: string) => Effect.Effect<A, CheckIfUnsafeError>; /** * Executes a function within an Effect, mapping any thrown error to a `UserError`. * * @typeParam A - The return type of the function to execute. * @param _try - A function to execute that may throw an error. * @returns An `Effect` that yields the result of the function or a `UserError` if an error is thrown. */ export declare const useUserError: <A>(_try: () => A) => Effect.Effect<A, UserError>; /** * Wraps a promise-returning function in an Effect, mapping any thrown error to a `UserError`. * * @template A The type of the resolved value from the promise. * @param _try - A function that returns a promise of type `A`. * @returns An `Effect` that resolves with the value of type `A` or fails with a `UserError`. */ export declare const useUserErrorPromise: <A>(_try: () => Promise<A>) => Effect.Effect<A, UserError>; export {};