@foxy.io/sdk
Version:
Universal SDK for a full server-side and a limited in-browser access to Foxy hAPI.
41 lines (40 loc) • 2.25 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthError = void 0;
const v8n_1 = __importDefault(require("v8n"));
/**
* Base error class for all authentication-related errors in
* the APIs that can be used both server and client-side. If you're
* building your own API client with our SDK, you should consider using
* this class for similar purposes.
*/
class AuthError extends Error {
constructor(params) {
AuthError.v8n.constructor.check(params);
super(`authentication failed with code ${params.code}`);
this.originalError = params.originalError;
this.code = params.code;
}
}
exports.AuthError = AuthError;
/** Credentials are valid, but the session can be created only after changing the current password. This usually happens after a server-side password reset has been initiated for security reasons. */
AuthError.NEW_PASSWORD_REQUIRED = 'NEW_PASSWORD_REQUIRED';
/** Credentials are valid, but the new password provided in response to the `NEW_PASSWORD_REQUIRED` error doesn't meet the security requirements. */
AuthError.INVALID_NEW_PASSWORD = 'INVALID_NEW_PASSWORD';
/** Credentials are invalid. That could mean empty or invalid email or password or otherwise incorrect auth data. */
AuthError.UNAUTHORIZED = 'UNAUTHORIZED';
/** Provided form data is invalid, e.g. email is too long or captcha is expired. */
AuthError.INVALID_FORM = 'INVALID_FORM';
/** Provided email is already taken. Applies to customer registration only. */
AuthError.UNAVAILABLE = 'UNAVAILABLE';
/** Any other or internal error that interrupted authentication. */
AuthError.UNKNOWN = 'UNKNOWN';
/** Available class member validators. */
AuthError.v8n = {
constructor: v8n_1.default().schema({
code: v8n_1.default().passesAnyOf(v8n_1.default().exact(AuthError.NEW_PASSWORD_REQUIRED), v8n_1.default().exact(AuthError.INVALID_NEW_PASSWORD), v8n_1.default().exact(AuthError.UNAUTHORIZED), v8n_1.default().exact(AuthError.INVALID_FORM), v8n_1.default().exact(AuthError.UNAVAILABLE), v8n_1.default().exact(AuthError.UNKNOWN)),
}),
};