@hastehaul/common 1.0.5 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- package/build/connections-wrappers/index.d.ts +2 -0
- package/build/connections-wrappers/index.js +18 -0
- package/build/connections-wrappers/redis-connection-wrapper.d.ts +9 -0
- package/build/connections-wrappers/redis-connection-wrapper.js +29 -0
- package/build/connections-wrappers/socket-connection-wrapper.d.ts +9 -0
- package/build/connections-wrappers/socket-connection-wrapper.js +25 -0
- package/build/errors/bad-request-error.d.ts +10 -0
- package/build/errors/bad-request-error.js +17 -0
- package/build/errors/custom-error.d.ts +8 -0
- package/build/errors/custom-error.js +10 -0
- package/build/errors/database-error.d.ts +9 -0
- package/build/errors/database-error.js +14 -0
- package/build/errors/index.d.ts +5 -0
- package/build/errors/index.js +21 -0
- package/build/errors/not-found-error.d.ts +9 -0
- package/build/errors/not-found-error.js +14 -0
- package/build/errors/system-error.d.ts +9 -0
- package/build/errors/system-error.js +14 -0
- package/build/index.d.ts +4 -5
- package/build/index.js +18 -4
- package/build/middlewares/current-user.d.ts +2 -0
- package/build/middlewares/current-user.js +59 -0
- package/build/middlewares/error-handler.d.ts +2 -0
- package/build/middlewares/error-handler.js +14 -0
- package/build/middlewares/index.d.ts +2 -0
- package/build/middlewares/index.js +18 -0
- package/build/utils/base_classes/index.d.ts +3 -0
- package/build/utils/base_classes/index.js +19 -0
- package/build/utils/base_classes/jobs/base-producers.d.ts +7 -0
- package/build/utils/base_classes/jobs/base-producers.js +12 -0
- package/build/utils/base_classes/jobs/base-worker.d.ts +6 -0
- package/build/utils/base_classes/jobs/base-worker.js +19 -0
- package/build/utils/base_classes/listeners/base-namespace.d.ts +4 -0
- package/build/utils/base_classes/listeners/base-namespace.js +6 -0
- package/build/utils/enums.d.ts +75 -0
- package/build/utils/enums.js +81 -0
- package/build/utils/index.d.ts +3 -0
- package/build/utils/index.js +19 -0
- package/build/utils/read-dir.d.ts +7 -0
- package/build/utils/read-dir.js +51 -0
- package/package.json +11 -1
@@ -0,0 +1,18 @@
|
|
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("./redis-connection-wrapper"), exports);
|
18
|
+
__exportStar(require("./socket-connection-wrapper"), exports);
|
@@ -0,0 +1,29 @@
|
|
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.redisWrapper = exports.RedisWrapper = void 0;
|
7
|
+
const ioredis_1 = __importDefault(require("ioredis"));
|
8
|
+
class RedisWrapper {
|
9
|
+
constructor() {
|
10
|
+
this.host = "customer-redis-srv";
|
11
|
+
this.port = 6379;
|
12
|
+
}
|
13
|
+
get client() {
|
14
|
+
if (!this._redisClient)
|
15
|
+
throw new Error("Cannot access Redis Client before connecting");
|
16
|
+
return this._redisClient;
|
17
|
+
}
|
18
|
+
connect() {
|
19
|
+
this._redisClient = new ioredis_1.default({ host: this.host, port: this.port, maxRetriesPerRequest: null });
|
20
|
+
this._redisClient.on("connect", function () {
|
21
|
+
console.info("Redis Server Connected!");
|
22
|
+
});
|
23
|
+
this._redisClient.on("error", function (error) {
|
24
|
+
console.error("Error in Redis", error);
|
25
|
+
});
|
26
|
+
}
|
27
|
+
}
|
28
|
+
exports.RedisWrapper = RedisWrapper;
|
29
|
+
exports.redisWrapper = new RedisWrapper();
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import http from "http";
|
3
|
+
import { Server } from 'socket.io';
|
4
|
+
export declare class SocketWrapper {
|
5
|
+
protected _io?: Server;
|
6
|
+
get io(): Server<import("socket.io/dist/typed-events").DefaultEventsMap, import("socket.io/dist/typed-events").DefaultEventsMap, import("socket.io/dist/typed-events").DefaultEventsMap, any>;
|
7
|
+
connect(httpServer: http.Server): void;
|
8
|
+
}
|
9
|
+
export declare const socketWrapper: SocketWrapper;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.socketWrapper = exports.SocketWrapper = void 0;
|
4
|
+
const socket_io_1 = require("socket.io");
|
5
|
+
class SocketWrapper {
|
6
|
+
get io() {
|
7
|
+
if (!this._io)
|
8
|
+
throw new Error("Cannot access IO Client before connecting");
|
9
|
+
return this._io;
|
10
|
+
}
|
11
|
+
connect(httpServer) {
|
12
|
+
this._io = new socket_io_1.Server(httpServer, {
|
13
|
+
path: "/socket/",
|
14
|
+
pingTimeout: 30000,
|
15
|
+
pingInterval: 25000,
|
16
|
+
cors: {
|
17
|
+
origin: "*",
|
18
|
+
methods: ["GET", "POST"],
|
19
|
+
// credentials: true,
|
20
|
+
},
|
21
|
+
});
|
22
|
+
}
|
23
|
+
}
|
24
|
+
exports.SocketWrapper = SocketWrapper;
|
25
|
+
exports.socketWrapper = new SocketWrapper();
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { StatusCodes } from "../utils/enums";
|
2
|
+
import { CustomError } from "./custom-error";
|
3
|
+
export declare class BadRequestError extends CustomError {
|
4
|
+
message: string;
|
5
|
+
statusCode: StatusCodes;
|
6
|
+
constructor(message: string);
|
7
|
+
serializeErrors(): {
|
8
|
+
message: string;
|
9
|
+
}[];
|
10
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.BadRequestError = void 0;
|
4
|
+
const enums_1 = require("../utils/enums");
|
5
|
+
const custom_error_1 = require("./custom-error");
|
6
|
+
class BadRequestError extends custom_error_1.CustomError {
|
7
|
+
constructor(message) {
|
8
|
+
super(message);
|
9
|
+
this.message = message;
|
10
|
+
this.statusCode = enums_1.StatusCodes.BAD_REQUEST;
|
11
|
+
Object.setPrototypeOf(this, BadRequestError.prototype);
|
12
|
+
}
|
13
|
+
serializeErrors() {
|
14
|
+
return [{ message: this.message }];
|
15
|
+
}
|
16
|
+
}
|
17
|
+
exports.BadRequestError = BadRequestError;
|
@@ -0,0 +1,10 @@
|
|
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
|
+
Object.setPrototypeOf(this, CustomError.prototype);
|
8
|
+
}
|
9
|
+
}
|
10
|
+
exports.CustomError = CustomError;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { StatusCodes } from '../utils/enums';
|
2
|
+
import { CustomError } from './custom-error';
|
3
|
+
export declare class DatabaseError extends CustomError {
|
4
|
+
statusCode: StatusCodes;
|
5
|
+
constructor(message?: string);
|
6
|
+
serializeErrors: () => {
|
7
|
+
message: string;
|
8
|
+
}[];
|
9
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.DatabaseError = void 0;
|
4
|
+
const enums_1 = require("../utils/enums");
|
5
|
+
const custom_error_1 = require("./custom-error");
|
6
|
+
class DatabaseError extends custom_error_1.CustomError {
|
7
|
+
constructor(message = "Error connecting to database") {
|
8
|
+
super(message);
|
9
|
+
this.statusCode = enums_1.StatusCodes.INTERNALE_SERVER_ERROR;
|
10
|
+
this.serializeErrors = () => [{ message: this.message }];
|
11
|
+
Object.setPrototypeOf(this, DatabaseError.prototype);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
exports.DatabaseError = DatabaseError;
|
@@ -0,0 +1,21 @@
|
|
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("./bad-request-error"), exports);
|
18
|
+
__exportStar(require("./custom-error"), exports);
|
19
|
+
__exportStar(require("./database-error"), exports);
|
20
|
+
__exportStar(require("./not-found-error"), exports);
|
21
|
+
__exportStar(require("./system-error"), exports);
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { StatusCodes } from "../utils/enums";
|
2
|
+
import { CustomError } from "./custom-error";
|
3
|
+
export declare class NotFoundError extends CustomError {
|
4
|
+
statusCode: StatusCodes;
|
5
|
+
constructor(message: string);
|
6
|
+
serializeErrors: () => {
|
7
|
+
message: string;
|
8
|
+
}[];
|
9
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.NotFoundError = void 0;
|
4
|
+
const enums_1 = require("../utils/enums");
|
5
|
+
const custom_error_1 = require("./custom-error");
|
6
|
+
class NotFoundError extends custom_error_1.CustomError {
|
7
|
+
constructor(message) {
|
8
|
+
super(message);
|
9
|
+
this.statusCode = enums_1.StatusCodes.NOT_FOUND;
|
10
|
+
this.serializeErrors = () => [{ message: this.message }];
|
11
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
exports.NotFoundError = NotFoundError;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { StatusCodes } from "../utils/enums";
|
2
|
+
import { CustomError } from "./custom-error";
|
3
|
+
export declare class SystemError extends CustomError {
|
4
|
+
statusCode: StatusCodes;
|
5
|
+
constructor(message?: string);
|
6
|
+
serializeErrors: () => {
|
7
|
+
message: string;
|
8
|
+
}[];
|
9
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.SystemError = void 0;
|
4
|
+
const enums_1 = require("../utils/enums");
|
5
|
+
const custom_error_1 = require("./custom-error");
|
6
|
+
class SystemError extends custom_error_1.CustomError {
|
7
|
+
constructor(message = "Something went wrong") {
|
8
|
+
super(message);
|
9
|
+
this.statusCode = enums_1.StatusCodes.INTERNALE_SERVER_ERROR;
|
10
|
+
this.serializeErrors = () => [{ message: this.message }];
|
11
|
+
Object.setPrototypeOf(this, SystemError.prototype);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
exports.SystemError = SystemError;
|
package/build/index.d.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
declare const color: Color;
|
1
|
+
export * from "./connections-wrappers";
|
2
|
+
export * from "./errors";
|
3
|
+
export * from "./middlewares";
|
4
|
+
export * from "./utils";
|
package/build/index.js
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
|
4
|
-
|
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);
|
5
15
|
};
|
6
|
-
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./connections-wrappers"), exports);
|
18
|
+
__exportStar(require("./errors"), exports);
|
19
|
+
__exportStar(require("./middlewares"), exports);
|
20
|
+
__exportStar(require("./utils"), exports);
|
@@ -0,0 +1,59 @@
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
32
|
+
});
|
33
|
+
};
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
35
|
+
exports.currentUser = void 0;
|
36
|
+
const jsonwebtoken_1 = __importStar(require("jsonwebtoken"));
|
37
|
+
const currentUser = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
38
|
+
let result = null;
|
39
|
+
try {
|
40
|
+
const bearerToken = req.headers["authorization"];
|
41
|
+
if (typeof bearerToken !== "undefined" && bearerToken) {
|
42
|
+
const token = bearerToken.split(" ")[1];
|
43
|
+
if (token) {
|
44
|
+
result = jsonwebtoken_1.default.verify(token, process.env.JWT_KEY.split("-").join(""));
|
45
|
+
}
|
46
|
+
}
|
47
|
+
req.currentUser = result;
|
48
|
+
}
|
49
|
+
catch (err) {
|
50
|
+
if (err instanceof jsonwebtoken_1.TokenExpiredError) {
|
51
|
+
// await AuthController.refreshToken(req, res)
|
52
|
+
}
|
53
|
+
else {
|
54
|
+
req.currentUser = null;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
next();
|
58
|
+
});
|
59
|
+
exports.currentUser = currentUser;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.errorHandler = void 0;
|
4
|
+
const custom_error_1 = require("../errors/custom-error");
|
5
|
+
const enums_1 = require("../utils/enums");
|
6
|
+
const errorHandler = (err, req, res, next) => {
|
7
|
+
if (err instanceof custom_error_1.CustomError) {
|
8
|
+
return res.status(err.statusCode).send({ errors: err.serializeErrors() });
|
9
|
+
}
|
10
|
+
res
|
11
|
+
.status(enums_1.StatusCodes.BAD_REQUEST)
|
12
|
+
.send({ errors: [{ message: "Something went wrong" }] });
|
13
|
+
};
|
14
|
+
exports.errorHandler = errorHandler;
|
@@ -0,0 +1,18 @@
|
|
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("./current-user"), exports);
|
18
|
+
__exportStar(require("./error-handler"), exports);
|
@@ -0,0 +1,19 @@
|
|
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("./jobs/base-producers"), exports);
|
18
|
+
__exportStar(require("./jobs/base-worker"), exports);
|
19
|
+
__exportStar(require("./listeners/base-namespace"), exports);
|
@@ -0,0 +1,12 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.AbstractJobQueue = void 0;
|
4
|
+
const bullmq_1 = require("bullmq");
|
5
|
+
const redis_connection_wrapper_1 = require("../../../connections-wrappers/redis-connection-wrapper");
|
6
|
+
// Define the abstract class
|
7
|
+
class AbstractJobQueue {
|
8
|
+
constructor(queueName) {
|
9
|
+
this.que = new bullmq_1.Queue(queueName, { connection: redis_connection_wrapper_1.redisWrapper.client });
|
10
|
+
}
|
11
|
+
}
|
12
|
+
exports.AbstractJobQueue = AbstractJobQueue;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.AbstractWorker = void 0;
|
4
|
+
const bullmq_1 = require("bullmq");
|
5
|
+
const redis_connection_wrapper_1 = require("../../../connections-wrappers/redis-connection-wrapper");
|
6
|
+
class AbstractWorker {
|
7
|
+
constructor(queueName) {
|
8
|
+
this.worker = new bullmq_1.Worker(queueName, this.process.bind(this), {
|
9
|
+
connection: redis_connection_wrapper_1.redisWrapper.client,
|
10
|
+
autorun: false,
|
11
|
+
});
|
12
|
+
this.worker.on("error", (err) => {
|
13
|
+
console.error(`${queueName} Error: `, err);
|
14
|
+
});
|
15
|
+
console.log(" --- WORKER STARTED --- ", queueName);
|
16
|
+
this.worker.run();
|
17
|
+
}
|
18
|
+
}
|
19
|
+
exports.AbstractWorker = AbstractWorker;
|
@@ -0,0 +1,75 @@
|
|
1
|
+
export declare enum Events {
|
2
|
+
CHARGE_SUCCESS = "charge.success",
|
3
|
+
TRANSFER_SUCCESS = "transfer.success",
|
4
|
+
TRANSFER_FAILED = "transfer.failed",
|
5
|
+
TRANSFER_REVERSED = "transfer.reversed",
|
6
|
+
PAYMENT_REQUEST_PENDING = "paymentrequest.pending",
|
7
|
+
PAYMENT_REQUEST_SUCCESS = "paymentrequest.success"
|
8
|
+
}
|
9
|
+
export declare enum Status {
|
10
|
+
NEW = "new",
|
11
|
+
PENDING = "pending",
|
12
|
+
SUCCESS = "success",
|
13
|
+
ACTIVE = "active",
|
14
|
+
DELETED = "deleted",
|
15
|
+
EXPIRED = "expired",
|
16
|
+
BLOCKED = "blocked",
|
17
|
+
SUSPENDED = "suspended",
|
18
|
+
VACATION = "vacation"
|
19
|
+
}
|
20
|
+
export declare enum StatusCodes {
|
21
|
+
CONTINUE = 100,
|
22
|
+
SWITCHING_PROTOCOL = 101,
|
23
|
+
EARLY_HINT = 103,
|
24
|
+
OK = 200,
|
25
|
+
CREATED = 201,
|
26
|
+
ACCEPTED = 202,
|
27
|
+
NON_AUTHORTATIVE_INFORMATION = 203,
|
28
|
+
NO_CONTENT = 204,
|
29
|
+
RESET_CONTENT = 205,
|
30
|
+
PARTIAL_CONTENT = 206,
|
31
|
+
MULTIPLE_CHOISES = 300,
|
32
|
+
MOVED_PERMANEETLY = 301,
|
33
|
+
FOUND = 302,
|
34
|
+
SEE_OTHERS = 303,
|
35
|
+
NOT_MODIFIED = 304,
|
36
|
+
TEMPORAL_REDIRECT = 307,
|
37
|
+
PERMANENT_REDIRECT = 308,
|
38
|
+
BAD_REQUEST = 400,
|
39
|
+
UNAUTHORIZED = 401,
|
40
|
+
PAYMENT_REQUIRED = 402,
|
41
|
+
FORBIDDEN = 403,
|
42
|
+
NOT_FOUND = 404,
|
43
|
+
METHOD_NOT_ALLOED = 405,
|
44
|
+
NOT_ACCEPTABLE = 406,
|
45
|
+
PROXY_AUTHENTICATION_REQUIRED = 407,
|
46
|
+
REQUEST_TIMEOUT = 408,
|
47
|
+
CONFLIT = 409,
|
48
|
+
GONE = 410,
|
49
|
+
LENGTH_REQUIRED = 411,
|
50
|
+
PRECONDITION_FAILED = 412,
|
51
|
+
PAYLOAD_TOO_LARGE = 413,
|
52
|
+
URI_TOOL_LONG = 414,
|
53
|
+
UNSUPPORTED_MEDIA_TYPE = 415,
|
54
|
+
RANGE_NOT_SATISFIABLE = 416,
|
55
|
+
EXPECTATION_FAILED = 417,
|
56
|
+
IM_A_TEAPOT = 418,
|
57
|
+
UNPROCESSABLE_ENTITY = 422,
|
58
|
+
TOO_EARLY = 425,
|
59
|
+
UPGRADE_REQUIRED = 426,
|
60
|
+
PRECONDITION_REQUIRED = 428,
|
61
|
+
TOO_MANY_REQUEST = 429,
|
62
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
|
63
|
+
UNAVAILABLE_FOR_LEGAL_REASONS = 451,
|
64
|
+
INTERNALE_SERVER_ERROR = 500,
|
65
|
+
NOT_IMPLEMENTED = 501,
|
66
|
+
BAD_GATEWAY = 502,
|
67
|
+
SERVICE_UNAVAILABLE = 503,
|
68
|
+
GATEWAY_TIMEOUT = 504,
|
69
|
+
HTTP_VERSION_NOT_SUPPORTED = 505,
|
70
|
+
VARIANT_ALSO_NEGOTIATES = 506,
|
71
|
+
INSUFFICIENT_STORAGE = 507,
|
72
|
+
LOOP_DETECTED = 508,
|
73
|
+
NOT_EXTENDED = 510,
|
74
|
+
NETWORK_AUTHENTICATION_REQUIRED = 511
|
75
|
+
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.StatusCodes = exports.Status = exports.Events = void 0;
|
4
|
+
var Events;
|
5
|
+
(function (Events) {
|
6
|
+
Events["CHARGE_SUCCESS"] = "charge.success";
|
7
|
+
Events["TRANSFER_SUCCESS"] = "transfer.success";
|
8
|
+
Events["TRANSFER_FAILED"] = "transfer.failed";
|
9
|
+
Events["TRANSFER_REVERSED"] = "transfer.reversed";
|
10
|
+
Events["PAYMENT_REQUEST_PENDING"] = "paymentrequest.pending";
|
11
|
+
Events["PAYMENT_REQUEST_SUCCESS"] = "paymentrequest.success";
|
12
|
+
})(Events || (exports.Events = Events = {}));
|
13
|
+
var Status;
|
14
|
+
(function (Status) {
|
15
|
+
Status["NEW"] = "new";
|
16
|
+
Status["PENDING"] = "pending";
|
17
|
+
Status["SUCCESS"] = "success";
|
18
|
+
Status["ACTIVE"] = "active";
|
19
|
+
Status["DELETED"] = "deleted";
|
20
|
+
Status["EXPIRED"] = "expired";
|
21
|
+
Status["BLOCKED"] = "blocked";
|
22
|
+
Status["SUSPENDED"] = "suspended";
|
23
|
+
Status["VACATION"] = "vacation";
|
24
|
+
})(Status || (exports.Status = Status = {}));
|
25
|
+
var StatusCodes;
|
26
|
+
(function (StatusCodes) {
|
27
|
+
StatusCodes[StatusCodes["CONTINUE"] = 100] = "CONTINUE";
|
28
|
+
StatusCodes[StatusCodes["SWITCHING_PROTOCOL"] = 101] = "SWITCHING_PROTOCOL";
|
29
|
+
StatusCodes[StatusCodes["EARLY_HINT"] = 103] = "EARLY_HINT";
|
30
|
+
StatusCodes[StatusCodes["OK"] = 200] = "OK";
|
31
|
+
StatusCodes[StatusCodes["CREATED"] = 201] = "CREATED";
|
32
|
+
StatusCodes[StatusCodes["ACCEPTED"] = 202] = "ACCEPTED";
|
33
|
+
StatusCodes[StatusCodes["NON_AUTHORTATIVE_INFORMATION"] = 203] = "NON_AUTHORTATIVE_INFORMATION";
|
34
|
+
StatusCodes[StatusCodes["NO_CONTENT"] = 204] = "NO_CONTENT";
|
35
|
+
StatusCodes[StatusCodes["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
36
|
+
StatusCodes[StatusCodes["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
37
|
+
StatusCodes[StatusCodes["MULTIPLE_CHOISES"] = 300] = "MULTIPLE_CHOISES";
|
38
|
+
StatusCodes[StatusCodes["MOVED_PERMANEETLY"] = 301] = "MOVED_PERMANEETLY";
|
39
|
+
StatusCodes[StatusCodes["FOUND"] = 302] = "FOUND";
|
40
|
+
StatusCodes[StatusCodes["SEE_OTHERS"] = 303] = "SEE_OTHERS";
|
41
|
+
StatusCodes[StatusCodes["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
42
|
+
StatusCodes[StatusCodes["TEMPORAL_REDIRECT"] = 307] = "TEMPORAL_REDIRECT";
|
43
|
+
StatusCodes[StatusCodes["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
44
|
+
StatusCodes[StatusCodes["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
45
|
+
StatusCodes[StatusCodes["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
46
|
+
StatusCodes[StatusCodes["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
47
|
+
StatusCodes[StatusCodes["FORBIDDEN"] = 403] = "FORBIDDEN";
|
48
|
+
StatusCodes[StatusCodes["NOT_FOUND"] = 404] = "NOT_FOUND";
|
49
|
+
StatusCodes[StatusCodes["METHOD_NOT_ALLOED"] = 405] = "METHOD_NOT_ALLOED";
|
50
|
+
StatusCodes[StatusCodes["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
51
|
+
StatusCodes[StatusCodes["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
52
|
+
StatusCodes[StatusCodes["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
53
|
+
StatusCodes[StatusCodes["CONFLIT"] = 409] = "CONFLIT";
|
54
|
+
StatusCodes[StatusCodes["GONE"] = 410] = "GONE";
|
55
|
+
StatusCodes[StatusCodes["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
56
|
+
StatusCodes[StatusCodes["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
57
|
+
StatusCodes[StatusCodes["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
|
58
|
+
StatusCodes[StatusCodes["URI_TOOL_LONG"] = 414] = "URI_TOOL_LONG";
|
59
|
+
StatusCodes[StatusCodes["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
60
|
+
StatusCodes[StatusCodes["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
|
61
|
+
StatusCodes[StatusCodes["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
62
|
+
StatusCodes[StatusCodes["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT";
|
63
|
+
StatusCodes[StatusCodes["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
64
|
+
StatusCodes[StatusCodes["TOO_EARLY"] = 425] = "TOO_EARLY";
|
65
|
+
StatusCodes[StatusCodes["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
|
66
|
+
StatusCodes[StatusCodes["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
67
|
+
StatusCodes[StatusCodes["TOO_MANY_REQUEST"] = 429] = "TOO_MANY_REQUEST";
|
68
|
+
StatusCodes[StatusCodes["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
|
69
|
+
StatusCodes[StatusCodes["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
|
70
|
+
StatusCodes[StatusCodes["INTERNALE_SERVER_ERROR"] = 500] = "INTERNALE_SERVER_ERROR";
|
71
|
+
StatusCodes[StatusCodes["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
72
|
+
StatusCodes[StatusCodes["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
73
|
+
StatusCodes[StatusCodes["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
74
|
+
StatusCodes[StatusCodes["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
75
|
+
StatusCodes[StatusCodes["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
76
|
+
StatusCodes[StatusCodes["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
|
77
|
+
StatusCodes[StatusCodes["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
|
78
|
+
StatusCodes[StatusCodes["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
|
79
|
+
StatusCodes[StatusCodes["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
|
80
|
+
StatusCodes[StatusCodes["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
81
|
+
})(StatusCodes || (exports.StatusCodes = StatusCodes = {}));
|
@@ -0,0 +1,19 @@
|
|
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("./enums"), exports);
|
18
|
+
__exportStar(require("./base_classes"), exports);
|
19
|
+
__exportStar(require("./read-dir"), exports);
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/**
|
2
|
+
* Recursively read directories with subdirectories and files.
|
3
|
+
* @param dirPath The path of the directory to read.
|
4
|
+
* @param filter A callback function to filter specific files (optional).
|
5
|
+
* @returns A Promise that resolves to an array of file paths matching the filter (if provided).
|
6
|
+
*/
|
7
|
+
export declare function readDirectoryRecursive(dirPath: string, filter?: (filePath: string) => boolean): Promise<string[]>;
|
@@ -0,0 +1,51 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.readDirectoryRecursive = void 0;
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
17
|
+
const path_1 = __importDefault(require("path"));
|
18
|
+
/**
|
19
|
+
* Recursively read directories with subdirectories and files.
|
20
|
+
* @param dirPath The path of the directory to read.
|
21
|
+
* @param filter A callback function to filter specific files (optional).
|
22
|
+
* @returns A Promise that resolves to an array of file paths matching the filter (if provided).
|
23
|
+
*/
|
24
|
+
function readDirectoryRecursive(dirPath, filter) {
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
26
|
+
const files = [];
|
27
|
+
const entries = yield fs_1.default.promises.readdir(dirPath);
|
28
|
+
yield Promise.all(entries.map((entry) => __awaiter(this, void 0, void 0, function* () {
|
29
|
+
const fullPath = path_1.default.join(dirPath, entry);
|
30
|
+
const stats = yield fs_1.default.promises.stat(fullPath);
|
31
|
+
if (stats.isDirectory()) {
|
32
|
+
files.push(...yield readDirectoryRecursive(fullPath, filter));
|
33
|
+
}
|
34
|
+
else if (stats.isFile() && (!filter || (filter && filter(fullPath)))) {
|
35
|
+
files.push(fullPath);
|
36
|
+
}
|
37
|
+
})));
|
38
|
+
return files;
|
39
|
+
});
|
40
|
+
}
|
41
|
+
exports.readDirectoryRecursive = readDirectoryRecursive;
|
42
|
+
// // Example usage:
|
43
|
+
// const directoryPath = '/path/to/your/directory';
|
44
|
+
// (async () => {
|
45
|
+
// try {
|
46
|
+
// const filteredFiles = await readDirectoryRecursive(directoryPath, (filePath) => filePath.endsWith('.txt'));
|
47
|
+
// console.log(filteredFiles);
|
48
|
+
// } catch (err) {
|
49
|
+
// console.error('Error occurred:', err);
|
50
|
+
// }
|
51
|
+
// })();
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hastehaul/common",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.8",
|
4
4
|
"description": "",
|
5
5
|
"main": "./build/index.js",
|
6
6
|
"types": "./build/index.d.ts",
|
@@ -16,7 +16,17 @@
|
|
16
16
|
"author": "",
|
17
17
|
"license": "ISC",
|
18
18
|
"devDependencies": {
|
19
|
+
"@types/express": "^4.17.17",
|
20
|
+
"@types/jsonwebtoken": "^9.0.2",
|
21
|
+
"@types/node": "^20.4.6",
|
19
22
|
"del-cli": "^5.0.0",
|
20
23
|
"typescript": "^5.1.6"
|
24
|
+
},
|
25
|
+
"dependencies": {
|
26
|
+
"bullmq": "^4.6.3",
|
27
|
+
"express": "^4.18.2",
|
28
|
+
"ioredis": "^5.3.2",
|
29
|
+
"jsonwebtoken": "^9.0.1",
|
30
|
+
"socket.io": "^4.7.1"
|
21
31
|
}
|
22
32
|
}
|