@skillstew/common 1.0.2 → 1.0.3

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.
@@ -0,0 +1,14 @@
1
+ export declare abstract class AppError extends Error {
2
+ readonly message: string;
3
+ readonly code: string;
4
+ readonly context?: Record<string, unknown> | undefined;
5
+ readonly name: string;
6
+ constructor(message: string, code: string, context?: Record<string, unknown> | undefined);
7
+ abstract toJSON(): object;
8
+ }
9
+ export declare abstract class DomainError extends AppError {
10
+ }
11
+ export declare abstract class InfrastructureError extends AppError {
12
+ }
13
+ export declare abstract class ApplicationError extends AppError {
14
+ }
@@ -0,0 +1,24 @@
1
+ import { InfrastructureError } from "./AppError";
2
+ import { JwtErrorCodes } from "./codes/JwtErrorCodes";
3
+ export declare class JwtError extends InfrastructureError {
4
+ constructor(code: keyof typeof JwtErrorCodes);
5
+ toJSON(): object;
6
+ }
7
+ export declare class EmailVerificationJwtVerifyError extends JwtError {
8
+ constructor();
9
+ }
10
+ export declare class RefreshTokenVerifyError extends JwtError {
11
+ constructor();
12
+ }
13
+ export declare class AccessTokenVerifyError extends JwtError {
14
+ constructor();
15
+ }
16
+ export declare class InvalidTokenError extends JwtError {
17
+ constructor();
18
+ }
19
+ export declare class InvalidTokenRoleError extends JwtError {
20
+ constructor();
21
+ }
22
+ export declare class TokenRoleMismatchError extends JwtError {
23
+ constructor();
24
+ }
@@ -0,0 +1,5 @@
1
+ import { ApplicationError } from "./AppError";
2
+ export declare class UnauthenticatedError extends ApplicationError {
3
+ constructor();
4
+ toJSON(): object;
5
+ }
@@ -0,0 +1,8 @@
1
+ export declare enum JwtErrorCodes {
2
+ EMAIL_VERIFICATION_JWT_VERIFY_ERROR = "Invalid email verification jwt",
3
+ REFRESH_TOKEN_VERIFY_ERROR = "Invalid refresh token",
4
+ ACCESS_TOKEN_VERIFY_ERROR = "Invalid access token",
5
+ INVALID_TOKEN_ERROR = "Invalid token",
6
+ INVALID_TOKEN_ROLE_ERROR = "Invalid role identifier",
7
+ TOKEN_ROLE_MISMATCH_ERROR = "Role mismatch between payload and header"
8
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./errors/AppError";
2
+ export * from "./errors/JwtErrors";
3
+ export * from "./errors/UnauthenticatedError";
4
+ export * from "./errors/codes/JwtErrorCodes";
5
+ export * from "./jwt-utils/JwtHelper";
6
+ export * from "./middlewares/authMiddleware";
7
+ export * from "./types/UserRoles";
@@ -0,0 +1,23 @@
1
+ import { UserRoles } from "../types/UserRoles";
2
+ export type tokenBody = {
3
+ userId: string;
4
+ email: string;
5
+ role: Exclude<UserRoles, "ADMIN">;
6
+ } | {
7
+ userId: string;
8
+ username: string;
9
+ role: "ADMIN";
10
+ };
11
+ export type JWTPayload = tokenBody & {
12
+ iat: number;
13
+ exp: number;
14
+ };
15
+ export declare class JwtHelper {
16
+ private _AccessSecrets;
17
+ constructor({ userAccessTokenSecret, expertAccessTokenSecret, adminAccessTokenSecret, }: {
18
+ userAccessTokenSecret: string;
19
+ expertAccessTokenSecret: string;
20
+ adminAccessTokenSecret: string;
21
+ });
22
+ verifyAccessToken: (jwtToken: string) => JWTPayload;
23
+ }
@@ -0,0 +1,6 @@
1
+ import { RequestHandler } from "express";
2
+ export declare class AuthMiddleware {
3
+ private _jwtHelper;
4
+ constructor(userAccessTokenSecret: string, expertAccessTokenSecret: string, adminAccessTokenSecret: string);
5
+ verify: RequestHandler;
6
+ }
@@ -0,0 +1,2 @@
1
+ export declare const USER_ROLES: readonly ["USER", "EXPERT", "ADMIN"];
2
+ export type UserRoles = (typeof USER_ROLES)[number];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skillstew/common",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "scripts": {
package/tsconfig.json CHANGED
@@ -54,7 +54,7 @@
54
54
  // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
55
55
 
56
56
  /* Emit */
57
- // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
57
+ "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
58
58
  // "declarationMap": true, /* Create sourcemaps for d.ts files. */
59
59
  // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
60
60
  // "sourceMap": true, /* Create source map files for emitted JavaScript files. */