@ccgtickets/common 1.0.12 → 1.0.15

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.
Files changed (46) hide show
  1. package/build/cjs/errors/bad-request-error.d.ts +10 -0
  2. package/build/cjs/errors/bad-request-error.js +17 -0
  3. package/build/cjs/errors/custom-error.d.ts +8 -0
  4. package/build/cjs/errors/custom-error.js +11 -0
  5. package/build/cjs/errors/database-connection-error.d.ts +13 -0
  6. package/build/cjs/errors/database-connection-error.js +22 -0
  7. package/build/cjs/errors/not-authorized-error.d.ts +8 -0
  8. package/build/cjs/errors/not-authorized-error.js +17 -0
  9. package/build/cjs/errors/not-found-error.d.ts +9 -0
  10. package/build/cjs/errors/not-found-error.js +15 -0
  11. package/build/cjs/errors/request-validation-error.d.ts +14 -0
  12. package/build/cjs/errors/request-validation-error.js +22 -0
  13. package/build/cjs/index.d.ts +10 -0
  14. package/build/cjs/index.js +26 -0
  15. package/build/cjs/middlewares/current-user.d.ts +14 -0
  16. package/build/cjs/middlewares/current-user.js +20 -0
  17. package/build/cjs/middlewares/error-handler.d.ts +2 -0
  18. package/build/cjs/middlewares/error-handler.js +13 -0
  19. package/build/cjs/middlewares/require-auth.d.ts +2 -0
  20. package/build/cjs/middlewares/require-auth.js +12 -0
  21. package/build/cjs/middlewares/validate-request.d.ts +2 -0
  22. package/build/cjs/middlewares/validate-request.js +13 -0
  23. package/build/cjs/package.json +3 -0
  24. package/build/esm/errors/bad-request-error.d.ts +10 -0
  25. package/build/esm/errors/bad-request-error.js +14 -0
  26. package/build/esm/errors/custom-error.d.ts +8 -0
  27. package/build/esm/errors/custom-error.js +7 -0
  28. package/build/esm/errors/database-connection-error.d.ts +13 -0
  29. package/build/esm/errors/database-connection-error.js +18 -0
  30. package/build/esm/errors/not-authorized-error.d.ts +8 -0
  31. package/build/esm/errors/not-authorized-error.js +13 -0
  32. package/build/esm/errors/not-found-error.d.ts +9 -0
  33. package/build/esm/errors/not-found-error.js +11 -0
  34. package/build/esm/errors/request-validation-error.d.ts +14 -0
  35. package/build/esm/errors/request-validation-error.js +19 -0
  36. package/build/esm/index.d.ts +10 -0
  37. package/build/esm/index.js +10 -0
  38. package/build/esm/middlewares/current-user.d.ts +14 -0
  39. package/build/esm/middlewares/current-user.js +12 -0
  40. package/build/esm/middlewares/error-handler.d.ts +2 -0
  41. package/build/esm/middlewares/error-handler.js +9 -0
  42. package/build/esm/middlewares/require-auth.d.ts +2 -0
  43. package/build/esm/middlewares/require-auth.js +8 -0
  44. package/build/esm/middlewares/validate-request.d.ts +2 -0
  45. package/build/esm/middlewares/validate-request.js +9 -0
  46. package/package.json +22 -8
@@ -0,0 +1,10 @@
1
+ import { CustomError } from "./custom-error.js";
2
+ export declare class BadRequestError extends CustomError {
3
+ message: string;
4
+ statusCode: number;
5
+ constructor(message: string);
6
+ serializeErrors(): {
7
+ message: string;
8
+ field?: string;
9
+ }[];
10
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BadRequestError = void 0;
4
+ const custom_error_js_1 = require("./custom-error.js");
5
+ class BadRequestError extends custom_error_js_1.CustomError {
6
+ constructor(message) {
7
+ super(message);
8
+ this.message = message;
9
+ this.statusCode = 400;
10
+ // Only because extending built-in Class
11
+ Object.setPrototypeOf(this, BadRequestError.prototype);
12
+ }
13
+ serializeErrors() {
14
+ return [{ message: "" }];
15
+ }
16
+ }
17
+ exports.BadRequestError = BadRequestError;
@@ -0,0 +1,8 @@
1
+ export declare abstract class CustomError extends Error {
2
+ abstract statusCode: number;
3
+ constructor(message: string);
4
+ abstract serializeErrors(): {
5
+ message: string;
6
+ field?: string;
7
+ }[];
8
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomError = void 0;
4
+ class CustomError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ // Only because extending built-in Class
8
+ Object.setPrototypeOf(this, CustomError.prototype);
9
+ }
10
+ }
11
+ exports.CustomError = CustomError;
@@ -0,0 +1,13 @@
1
+ import { CustomError } from "./custom-error.js";
2
+ export declare class DatabaseConnectionError extends CustomError {
3
+ serialzeErrors(): {
4
+ message: string;
5
+ field?: string;
6
+ }[];
7
+ statusCode: number;
8
+ reason: string;
9
+ constructor();
10
+ serializeErrors(): {
11
+ message: string;
12
+ }[];
13
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DatabaseConnectionError = void 0;
4
+ const custom_error_js_1 = require("./custom-error.js");
5
+ class DatabaseConnectionError extends custom_error_js_1.CustomError {
6
+ serialzeErrors() {
7
+ throw new Error("Method not implemented.");
8
+ }
9
+ constructor() {
10
+ super("Error Connecting to Database.");
11
+ this.statusCode = 500;
12
+ this.reason = "Error Connecting to Database.";
13
+ // Only because extending built-in Class
14
+ Object.setPrototypeOf(this, DatabaseConnectionError.prototype);
15
+ }
16
+ serializeErrors() {
17
+ return [
18
+ { message: this.reason }
19
+ ];
20
+ }
21
+ }
22
+ exports.DatabaseConnectionError = DatabaseConnectionError;
@@ -0,0 +1,8 @@
1
+ import { CustomError } from "./custom-error.js";
2
+ export declare class NotAuthorizedError extends CustomError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeErrors(): {
6
+ message: string;
7
+ }[];
8
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotAuthorizedError = void 0;
4
+ const custom_error_js_1 = require("./custom-error.js");
5
+ class NotAuthorizedError extends custom_error_js_1.CustomError {
6
+ constructor() {
7
+ super("Not authorized");
8
+ this.statusCode = 401;
9
+ // Only because extending built-in Class
10
+ Object.setPrototypeOf(this, NotAuthorizedError.prototype);
11
+ }
12
+ ;
13
+ serializeErrors() {
14
+ return [{ message: "Not authorized" }];
15
+ }
16
+ }
17
+ exports.NotAuthorizedError = NotAuthorizedError;
@@ -0,0 +1,9 @@
1
+ import { CustomError } from "./custom-error.js";
2
+ export declare class NotFoundError extends CustomError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeErrors(): {
6
+ message: string;
7
+ field?: string;
8
+ }[];
9
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotFoundError = void 0;
4
+ const custom_error_js_1 = require("./custom-error.js");
5
+ class NotFoundError extends custom_error_js_1.CustomError {
6
+ constructor() {
7
+ super("Route not found");
8
+ this.statusCode = 404;
9
+ Object.setPrototypeOf(this, NotFoundError.prototype);
10
+ }
11
+ serializeErrors() {
12
+ return [{ message: "Not Found" }];
13
+ }
14
+ }
15
+ exports.NotFoundError = NotFoundError;
@@ -0,0 +1,14 @@
1
+ import type { ValidationError } from "express-validator";
2
+ import { CustomError } from "./custom-error.js";
3
+ export declare class RequestValidationError extends CustomError {
4
+ errors: ValidationError[];
5
+ statusCode: number;
6
+ constructor(errors: ValidationError[]);
7
+ serializeErrors(): ({
8
+ message: any;
9
+ field: string;
10
+ } | {
11
+ message: any;
12
+ field?: never;
13
+ })[];
14
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RequestValidationError = void 0;
4
+ const custom_error_js_1 = require("./custom-error.js");
5
+ class RequestValidationError extends custom_error_js_1.CustomError {
6
+ constructor(errors) {
7
+ super("Invalid request parameters.");
8
+ this.errors = errors;
9
+ this.statusCode = 400;
10
+ // Only because extending built-in Class
11
+ Object.setPrototypeOf(this, RequestValidationError.prototype);
12
+ }
13
+ serializeErrors() {
14
+ return this.errors.map((err) => {
15
+ if (err.type === 'field') {
16
+ return { message: err.msg, field: err.path };
17
+ }
18
+ return { message: err.msg };
19
+ });
20
+ }
21
+ }
22
+ exports.RequestValidationError = RequestValidationError;
@@ -0,0 +1,10 @@
1
+ export * from "./errors/bad-request-error.js";
2
+ export * from "./errors/custom-error.js";
3
+ export * from "./errors/database-connection-error.js";
4
+ export * from "./errors/not-authorized-error.js";
5
+ export * from "./errors/not-found-error.js";
6
+ export * from "./errors/request-validation-error.js";
7
+ export * from "./middlewares/current-user.js";
8
+ export * from "./middlewares/error-handler.js";
9
+ export * from "./middlewares/require-auth.js";
10
+ export * from "./middlewares/validate-request.js";
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./errors/bad-request-error.js"), exports);
18
+ __exportStar(require("./errors/custom-error.js"), exports);
19
+ __exportStar(require("./errors/database-connection-error.js"), exports);
20
+ __exportStar(require("./errors/not-authorized-error.js"), exports);
21
+ __exportStar(require("./errors/not-found-error.js"), exports);
22
+ __exportStar(require("./errors/request-validation-error.js"), exports);
23
+ __exportStar(require("./middlewares/current-user.js"), exports);
24
+ __exportStar(require("./middlewares/error-handler.js"), exports);
25
+ __exportStar(require("./middlewares/require-auth.js"), exports);
26
+ __exportStar(require("./middlewares/validate-request.js"), exports);
@@ -0,0 +1,14 @@
1
+ import type { Request, Response, NextFunction } from "express";
2
+ interface UserPayload {
3
+ id: string;
4
+ email: string;
5
+ }
6
+ declare global {
7
+ namespace Express {
8
+ interface Request {
9
+ currentUser?: UserPayload;
10
+ }
11
+ }
12
+ }
13
+ export declare const currentUser: (req: Request, res: Response, next: NextFunction) => void;
14
+ export {};
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.currentUser = void 0;
7
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ const currentUser = (req, res, next) => {
9
+ var _a;
10
+ if (!((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt)) {
11
+ return next();
12
+ }
13
+ try {
14
+ const payload = jsonwebtoken_1.default.verify(req.session.jwt, process.env.JWT_KEY);
15
+ req.currentUser = payload;
16
+ }
17
+ catch (err) { }
18
+ next();
19
+ };
20
+ exports.currentUser = currentUser;
@@ -0,0 +1,2 @@
1
+ import type { Request, Response, NextFunction } from "express";
2
+ export declare const errorHandler: (err: Error, req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.errorHandler = void 0;
4
+ const custom_error_js_1 = require("../errors/custom-error.js");
5
+ const errorHandler = (err, req, res, next) => {
6
+ if (err instanceof custom_error_js_1.CustomError) {
7
+ return res.status(400).send({ errors: err.serializeErrors() });
8
+ }
9
+ res.status(400).send({
10
+ errors: [{ message: "Something Went Wrong!!" }]
11
+ });
12
+ };
13
+ exports.errorHandler = errorHandler;
@@ -0,0 +1,2 @@
1
+ import type { Request, Response, NextFunction } from "express";
2
+ export declare const requireAuth: (req: Request, res: Response, next: NextFunction) => void;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requireAuth = void 0;
4
+ const not_authorized_error_js_1 = require("../errors/not-authorized-error.js");
5
+ const requireAuth = (req, res, next) => {
6
+ //@ts-ignore
7
+ if (!req.currentUser) {
8
+ throw new not_authorized_error_js_1.NotAuthorizedError();
9
+ }
10
+ next();
11
+ };
12
+ exports.requireAuth = requireAuth;
@@ -0,0 +1,2 @@
1
+ import type { Request, Response, NextFunction } from "express";
2
+ export declare const validateRequest: (req: Request, res: Response, next: NextFunction) => void;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateRequest = void 0;
4
+ const express_validator_1 = require("express-validator");
5
+ const request_validation_error_js_1 = require("../errors/request-validation-error.js");
6
+ const validateRequest = (req, res, next) => {
7
+ const errors = (0, express_validator_1.validationResult)(req);
8
+ if (!errors.isEmpty()) {
9
+ throw new request_validation_error_js_1.RequestValidationError(errors.array());
10
+ }
11
+ next();
12
+ };
13
+ exports.validateRequest = validateRequest;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,10 @@
1
+ import { CustomError } from "./custom-error.js";
2
+ export declare class BadRequestError extends CustomError {
3
+ message: string;
4
+ statusCode: number;
5
+ constructor(message: string);
6
+ serializeErrors(): {
7
+ message: string;
8
+ field?: string;
9
+ }[];
10
+ }
@@ -0,0 +1,14 @@
1
+ import { CustomError } from "./custom-error.js";
2
+ export class BadRequestError extends CustomError {
3
+ message;
4
+ statusCode = 400;
5
+ constructor(message) {
6
+ super(message);
7
+ this.message = message;
8
+ // Only because extending built-in Class
9
+ Object.setPrototypeOf(this, BadRequestError.prototype);
10
+ }
11
+ serializeErrors() {
12
+ return [{ message: "" }];
13
+ }
14
+ }
@@ -0,0 +1,8 @@
1
+ export declare abstract class CustomError extends Error {
2
+ abstract statusCode: number;
3
+ constructor(message: string);
4
+ abstract serializeErrors(): {
5
+ message: string;
6
+ field?: string;
7
+ }[];
8
+ }
@@ -0,0 +1,7 @@
1
+ export class CustomError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ // Only because extending built-in Class
5
+ Object.setPrototypeOf(this, CustomError.prototype);
6
+ }
7
+ }
@@ -0,0 +1,13 @@
1
+ import { CustomError } from "./custom-error.js";
2
+ export declare class DatabaseConnectionError extends CustomError {
3
+ serialzeErrors(): {
4
+ message: string;
5
+ field?: string;
6
+ }[];
7
+ statusCode: number;
8
+ reason: string;
9
+ constructor();
10
+ serializeErrors(): {
11
+ message: string;
12
+ }[];
13
+ }
@@ -0,0 +1,18 @@
1
+ import { CustomError } from "./custom-error.js";
2
+ export class DatabaseConnectionError extends CustomError {
3
+ serialzeErrors() {
4
+ throw new Error("Method not implemented.");
5
+ }
6
+ statusCode = 500;
7
+ reason = "Error Connecting to Database.";
8
+ constructor() {
9
+ super("Error Connecting to Database.");
10
+ // Only because extending built-in Class
11
+ Object.setPrototypeOf(this, DatabaseConnectionError.prototype);
12
+ }
13
+ serializeErrors() {
14
+ return [
15
+ { message: this.reason }
16
+ ];
17
+ }
18
+ }
@@ -0,0 +1,8 @@
1
+ import { CustomError } from "./custom-error.js";
2
+ export declare class NotAuthorizedError extends CustomError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeErrors(): {
6
+ message: string;
7
+ }[];
8
+ }
@@ -0,0 +1,13 @@
1
+ import { CustomError } from "./custom-error.js";
2
+ export class NotAuthorizedError extends CustomError {
3
+ statusCode = 401;
4
+ constructor() {
5
+ super("Not authorized");
6
+ // Only because extending built-in Class
7
+ Object.setPrototypeOf(this, NotAuthorizedError.prototype);
8
+ }
9
+ ;
10
+ serializeErrors() {
11
+ return [{ message: "Not authorized" }];
12
+ }
13
+ }
@@ -0,0 +1,9 @@
1
+ import { CustomError } from "./custom-error.js";
2
+ export declare class NotFoundError extends CustomError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeErrors(): {
6
+ message: string;
7
+ field?: string;
8
+ }[];
9
+ }
@@ -0,0 +1,11 @@
1
+ import { CustomError } from "./custom-error.js";
2
+ export class NotFoundError extends CustomError {
3
+ statusCode = 404;
4
+ constructor() {
5
+ super("Route not found");
6
+ Object.setPrototypeOf(this, NotFoundError.prototype);
7
+ }
8
+ serializeErrors() {
9
+ return [{ message: "Not Found" }];
10
+ }
11
+ }
@@ -0,0 +1,14 @@
1
+ import type { ValidationError } from "express-validator";
2
+ import { CustomError } from "./custom-error.js";
3
+ export declare class RequestValidationError extends CustomError {
4
+ errors: ValidationError[];
5
+ statusCode: number;
6
+ constructor(errors: ValidationError[]);
7
+ serializeErrors(): ({
8
+ message: any;
9
+ field: string;
10
+ } | {
11
+ message: any;
12
+ field?: never;
13
+ })[];
14
+ }
@@ -0,0 +1,19 @@
1
+ import { CustomError } from "./custom-error.js";
2
+ export class RequestValidationError extends CustomError {
3
+ errors;
4
+ statusCode = 400;
5
+ constructor(errors) {
6
+ super("Invalid request parameters.");
7
+ this.errors = errors;
8
+ // Only because extending built-in Class
9
+ Object.setPrototypeOf(this, RequestValidationError.prototype);
10
+ }
11
+ serializeErrors() {
12
+ return this.errors.map((err) => {
13
+ if (err.type === 'field') {
14
+ return { message: err.msg, field: err.path };
15
+ }
16
+ return { message: err.msg };
17
+ });
18
+ }
19
+ }
@@ -0,0 +1,10 @@
1
+ export * from "./errors/bad-request-error.js";
2
+ export * from "./errors/custom-error.js";
3
+ export * from "./errors/database-connection-error.js";
4
+ export * from "./errors/not-authorized-error.js";
5
+ export * from "./errors/not-found-error.js";
6
+ export * from "./errors/request-validation-error.js";
7
+ export * from "./middlewares/current-user.js";
8
+ export * from "./middlewares/error-handler.js";
9
+ export * from "./middlewares/require-auth.js";
10
+ export * from "./middlewares/validate-request.js";
@@ -0,0 +1,10 @@
1
+ export * from "./errors/bad-request-error.js";
2
+ export * from "./errors/custom-error.js";
3
+ export * from "./errors/database-connection-error.js";
4
+ export * from "./errors/not-authorized-error.js";
5
+ export * from "./errors/not-found-error.js";
6
+ export * from "./errors/request-validation-error.js";
7
+ export * from "./middlewares/current-user.js";
8
+ export * from "./middlewares/error-handler.js";
9
+ export * from "./middlewares/require-auth.js";
10
+ export * from "./middlewares/validate-request.js";
@@ -0,0 +1,14 @@
1
+ import type { Request, Response, NextFunction } from "express";
2
+ interface UserPayload {
3
+ id: string;
4
+ email: string;
5
+ }
6
+ declare global {
7
+ namespace Express {
8
+ interface Request {
9
+ currentUser?: UserPayload;
10
+ }
11
+ }
12
+ }
13
+ export declare const currentUser: (req: Request, res: Response, next: NextFunction) => void;
14
+ export {};
@@ -0,0 +1,12 @@
1
+ import jwt from "jsonwebtoken";
2
+ export const currentUser = (req, res, next) => {
3
+ if (!req.session?.jwt) {
4
+ return next();
5
+ }
6
+ try {
7
+ const payload = jwt.verify(req.session.jwt, process.env.JWT_KEY);
8
+ req.currentUser = payload;
9
+ }
10
+ catch (err) { }
11
+ next();
12
+ };
@@ -0,0 +1,2 @@
1
+ import type { Request, Response, NextFunction } from "express";
2
+ export declare const errorHandler: (err: Error, req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
@@ -0,0 +1,9 @@
1
+ import { CustomError } from "../errors/custom-error.js";
2
+ export const errorHandler = (err, req, res, next) => {
3
+ if (err instanceof CustomError) {
4
+ return res.status(400).send({ errors: err.serializeErrors() });
5
+ }
6
+ res.status(400).send({
7
+ errors: [{ message: "Something Went Wrong!!" }]
8
+ });
9
+ };
@@ -0,0 +1,2 @@
1
+ import type { Request, Response, NextFunction } from "express";
2
+ export declare const requireAuth: (req: Request, res: Response, next: NextFunction) => void;
@@ -0,0 +1,8 @@
1
+ import { NotAuthorizedError } from "../errors/not-authorized-error.js";
2
+ export const requireAuth = (req, res, next) => {
3
+ //@ts-ignore
4
+ if (!req.currentUser) {
5
+ throw new NotAuthorizedError();
6
+ }
7
+ next();
8
+ };
@@ -0,0 +1,2 @@
1
+ import type { Request, Response, NextFunction } from "express";
2
+ export declare const validateRequest: (req: Request, res: Response, next: NextFunction) => void;
@@ -0,0 +1,9 @@
1
+ import { validationResult } from "express-validator";
2
+ import { RequestValidationError } from "../errors/request-validation-error.js";
3
+ export const validateRequest = (req, res, next) => {
4
+ const errors = validationResult(req);
5
+ if (!errors.isEmpty()) {
6
+ throw new RequestValidationError(errors.array());
7
+ }
8
+ next();
9
+ };
package/package.json CHANGED
@@ -1,21 +1,35 @@
1
1
  {
2
2
  "name": "@ccgtickets/common",
3
- "version": "1.0.12",
3
+ "version": "1.0.15",
4
4
  "description": "",
5
- "main": "./build/index.js",
6
- "types": "./build/index.d.ts",
5
+ "type": "module",
7
6
  "files": [
8
- "dist"
7
+ "build/**/*"
9
8
  ],
9
+ "main": "./build/cjs/index.js",
10
+ "module": "./build/esm/index.js",
11
+ "types": "./build/esm/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./build/esm/index.d.ts",
15
+ "import": "./build/esm/index.js",
16
+ "require": "./build/cjs/index.js"
17
+ }
18
+ },
10
19
  "scripts": {
11
- "clean": "del-cli ./dist/*",
12
- "build": "npm run clean && tsc",
13
- "pub": "git add . && git commit -m\"Updates\" && npm version patch && npm run build && npm publish --access public"
20
+ "clean": "del-cli ./build/*",
21
+ "build:esm": "tsc -p tsconfig.esm.json",
22
+ "build:cjs": "tsc -p tsconfig.cjs.json",
23
+ "postbuild:cjs": "node ./scripts/write-cjs-package.mjs",
24
+ "build": "npm run clean && npm run build:esm && npm run build:cjs && npm run smoke",
25
+ "smoke:cjs": "node -e \"require('./build/cjs/index.js'); console.log('cjs ok')\"",
26
+ "smoke:esm": "node -e \"import('./build/esm/index.js').then(()=>console.log('esm ok'))\"",
27
+ "smoke": "npm run smoke:cjs && npm run smoke:esm",
28
+ "pub": "git add . && git commit -m \"Updates\" && npm version patch && npm run build && npm publish --access public"
14
29
  },
15
30
  "keywords": [],
16
31
  "author": "",
17
32
  "license": "ISC",
18
- "type": "module",
19
33
  "devDependencies": {
20
34
  "del-cli": "^7.0.0",
21
35
  "typescript": "^5.9.3"