@the-neon/core
v0.2.6
Published
Core utilities for Neon — decorators, errors, and interfaces
Downloads
857
Readme
@the-neon/core
Core decorators, errors, and interfaces for Neon.
Install
npm install @the-neon/coreUsage
import {
Action,
SkipAuthorization,
ErrorPrefix,
ApplicationError,
AuthenticationError,
AuthorizationError,
InputError,
ItemNotFoundError,
IAppContext,
IAuthenticatedUser,
} from "@the-neon/core";Enums
Action
Bitmask for access control:
Action.Read // 1
Action.Write // 2
Action.Delete // 4
Action.Execute // 8
Action.Approve // 16SkipAuthorization
Bypass auth checks:
SkipAuthorization.yes
SkipAuthorization.noErrorPrefix
Error code prefixes for ApplicationError:
ErrorPrefix.Authentication // "AUTH"
ErrorPrefix.Authorization // "AZ"
ErrorPrefix.Custom // "CUS"
ErrorPrefix.ConstraintViolation // "CV"
ErrorPrefix.InputValidation // "IV"
ErrorPrefix.InputValidationInvalidFormat // "IV.IFMT"
ErrorPrefix.InputValidationRequired // "IV.RQ"
ErrorPrefix.InputValidationSmallerThan // "IV.ST"
ErrorPrefix.InputValidationGreaterThan // "IV.GT"
ErrorPrefix.NotSupportedAppVersion // "NSAV"
ErrorPrefix.System // "SYS"Interfaces
IAppContext
Application context for requests:
interface IAppContext {
token?: string;
connectionId?: string;
user?: IAuthenticatedUser;
}IAuthenticatedUser
Authenticated user data:
interface IAuthenticatedUser {
id: string;
tenantId: string;
}Errors
ApplicationError
Base error with prefix, affected fields, and message:
throw new ApplicationError(ErrorPrefix.InputValidation, ["email"], "Invalid email");AuthenticationError
User not authenticated:
throw new AuthenticationError();
throw new AuthenticationError("Custom message");AuthorizationError
User not authorized:
throw new AuthorizationError();InputError
Request input validation failure:
throw new InputError("Validation failed", [new Map([["email", "Invalid email"]])]);ItemNotFoundError
Requested item not found:
throw new ItemNotFoundError();Type Aliases
const integer: number;
const long: number;
const float: number;
const timestamp: Date;