firebase-auth-cloudflare-workers
Version:
Zero-dependencies firebase auth library for Cloudflare Workers.
215 lines (214 loc) • 6.31 kB
TypeScript
/**
* Jwt error code structure.
*
* @param code - The error code.
* @param message - The error message.
* @constructor
*/
export declare class JwtError extends Error {
readonly code: JwtErrorCode;
readonly message: string;
constructor(code: JwtErrorCode, message: string);
}
/**
* JWT error codes.
*/
export declare enum JwtErrorCode {
INVALID_ARGUMENT = "invalid-argument",
INVALID_CREDENTIAL = "invalid-credential",
TOKEN_EXPIRED = "token-expired",
INVALID_SIGNATURE = "invalid-token",
NO_MATCHING_KID = "no-matching-kid-error",
NO_KID_IN_HEADER = "no-kid-error",
KEY_FETCH_ERROR = "key-fetch-error"
}
/**
* App client error codes and their default messages.
*/
export declare class AppErrorCodes {
static INVALID_CREDENTIAL: string;
static INTERNAL_ERROR: string;
static NETWORK_ERROR: string;
static NETWORK_TIMEOUT: string;
static UNABLE_TO_PARSE_RESPONSE: string;
}
/**
* Auth client error codes and their default messages.
*/
export declare class AuthClientErrorCode {
static INVALID_ARGUMENT: {
code: string;
message: string;
};
static INVALID_CREDENTIAL: {
code: string;
message: string;
};
static ID_TOKEN_EXPIRED: {
code: string;
message: string;
};
static INVALID_ID_TOKEN: {
code: string;
message: string;
};
static ID_TOKEN_REVOKED: {
code: string;
message: string;
};
static INTERNAL_ERROR: {
code: string;
message: string;
};
static USER_NOT_FOUND: {
code: string;
message: string;
};
static USER_DISABLED: {
code: string;
message: string;
};
static SESSION_COOKIE_EXPIRED: {
code: string;
message: string;
};
static SESSION_COOKIE_REVOKED: {
code: string;
message: string;
};
static INVALID_SESSION_COOKIE_DURATION: {
code: string;
message: string;
};
static INVALID_UID: {
code: string;
message: string;
};
static INVALID_TOKENS_VALID_AFTER_TIME: {
code: string;
message: string;
};
static FORBIDDEN_CLAIM: {
code: string;
message: string;
};
static INVALID_CLAIMS: {
code: string;
message: string;
};
static CLAIMS_TOO_LARGE: {
code: string;
message: string;
};
}
/**
* `FirebaseErrorInterface` is a subclass of the standard JavaScript `Error` object. In
* addition to a message string and stack trace, it contains a string code.
*/
export interface FirebaseErrorInterface {
/**
* Error codes are strings using the following format: `"service/string-code"`.
* Some examples include `"auth/invalid-uid"` and
* `"messaging/invalid-recipient"`.
*
* While the message for a given error can change, the code will remain the same
* between backward-compatible versions of the Firebase SDK.
*/
code: string;
/**
* An explanatory message for the error that just occurred.
*
* This message is designed to be helpful to you, the developer. Because
* it generally does not convey meaningful information to end users,
* this message should not be displayed in your application.
*/
message: string;
/**
* A string value containing the execution backtrace when the error originally
* occurred.
*
* This information can be useful for troubleshooting the cause of the error with
* {@link https://firebase.google.com/support | Firebase Support}.
*/
stack?: string;
/**
* Returns a JSON-serializable object representation of this error.
*
* @returns A JSON-serializable representation of this object.
*/
toJSON(): object;
}
/**
* Firebase error code structure. This extends Error.
*
* @param errorInfo - The error information (code and message).
* @constructor
*/
export declare class FirebaseError extends Error implements FirebaseErrorInterface {
private errorInfo;
constructor(errorInfo: ErrorInfo);
/** @returns The error code. */
get code(): string;
/** @returns The error message. */
get message(): string;
/** @returns The object representation of the error. */
toJSON(): object;
}
/**
* Defines error info type. This includes a code and message string.
*/
export interface ErrorInfo {
code: string;
message: string;
}
/**
* A FirebaseError with a prefix in front of the error code.
*
* @param codePrefix - The prefix to apply to the error code.
* @param code - The error code.
* @param message - The error message.
* @constructor
*/
export declare class PrefixedFirebaseError extends FirebaseError {
private codePrefix;
constructor(codePrefix: string, code: string, message: string);
/**
* Allows the error type to be checked without needing to know implementation details
* of the code prefixing.
*
* @param code - The non-prefixed error code to test against.
* @returns True if the code matches, false otherwise.
*/
hasCode(code: string): boolean;
}
/**
* Firebase Auth error code structure. This extends PrefixedFirebaseError.
*
* @param info - The error code info.
* @param [message] The error message. This will override the default
* message if provided.
* @constructor
*/
export declare class FirebaseAuthError extends PrefixedFirebaseError {
constructor(info: ErrorInfo, message?: string);
/**
* Creates the developer-facing error corresponding to the backend error code.
*
* @param serverErrorCode - The server error code.
* @param [message] The error message. The default message is used
* if not provided.
* @param [rawServerResponse] The error's raw server response.
* @returns The corresponding developer-facing error.
*/
static fromServerError(serverErrorCode: string, rawServerResponse?: object): FirebaseAuthError;
}
/**
* Firebase App error code structure. This extends PrefixedFirebaseError.
*
* @param code - The error code.
* @param message - The error message.
* @constructor
*/
export declare class FirebaseAppError extends PrefixedFirebaseError {
constructor(code: string, message: string);
}