@fluyappgocore/commons-backend 1.0.202
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.
- package/build/classes/BacklogManager.d.ts +129 -0
- package/build/classes/BacklogManager.js +417 -0
- package/build/classes/BacklogMonitor.d.ts +102 -0
- package/build/classes/BacklogMonitor.js +222 -0
- package/build/classes/HttpResponse.d.ts +7 -0
- package/build/classes/HttpResponse.js +13 -0
- package/build/classes/index.d.ts +3 -0
- package/build/classes/index.js +15 -0
- package/build/dtos/file.dto.d.ts +5 -0
- package/build/dtos/file.dto.js +25 -0
- package/build/dtos/index.d.ts +1 -0
- package/build/dtos/index.js +13 -0
- package/build/events/BatchEnhancedListener.d.ts +106 -0
- package/build/events/BatchEnhancedListener.js +307 -0
- package/build/events/EnhancedListener.d.ts +75 -0
- package/build/events/EnhancedListener.js +185 -0
- package/build/events/baseListener.d.ts +19 -0
- package/build/events/baseListener.js +90 -0
- package/build/events/basePublisher.d.ts +14 -0
- package/build/events/basePublisher.js +84 -0
- package/build/events/config.d.ts +7 -0
- package/build/events/config.js +14 -0
- package/build/events/createClient.d.ts +38 -0
- package/build/events/createClient.js +416 -0
- package/build/events/index.d.ts +6 -0
- package/build/events/index.js +18 -0
- package/build/events/interfaces/agent.event.d.ts +7 -0
- package/build/events/interfaces/agent.event.js +2 -0
- package/build/events/interfaces/agentCrud.event.d.ts +7 -0
- package/build/events/interfaces/agentCrud.event.js +2 -0
- package/build/events/interfaces/agentTracking.event.d.ts +7 -0
- package/build/events/interfaces/agentTracking.event.js +2 -0
- package/build/events/interfaces/audit.event.d.ts +7 -0
- package/build/events/interfaces/audit.event.js +2 -0
- package/build/events/interfaces/branch.event.d.ts +7 -0
- package/build/events/interfaces/branch.event.js +2 -0
- package/build/events/interfaces/deleteTracking.event.d.ts +7 -0
- package/build/events/interfaces/deleteTracking.event.js +2 -0
- package/build/events/interfaces/department.event.d.ts +7 -0
- package/build/events/interfaces/department.event.js +2 -0
- package/build/events/interfaces/entity.event.d.ts +7 -0
- package/build/events/interfaces/entity.event.js +2 -0
- package/build/events/interfaces/index.d.ts +23 -0
- package/build/events/interfaces/index.js +35 -0
- package/build/events/interfaces/manualMatch.event.d.ts +7 -0
- package/build/events/interfaces/manualMatch.event.js +2 -0
- package/build/events/interfaces/match.event.d.ts +7 -0
- package/build/events/interfaces/match.event.js +2 -0
- package/build/events/interfaces/monitor.event.d.ts +7 -0
- package/build/events/interfaces/monitor.event.js +2 -0
- package/build/events/interfaces/notification.event.d.ts +7 -0
- package/build/events/interfaces/notification.event.js +2 -0
- package/build/events/interfaces/object.event.d.ts +7 -0
- package/build/events/interfaces/object.event.js +2 -0
- package/build/events/interfaces/payments.event.d.ts +7 -0
- package/build/events/interfaces/payments.event.js +2 -0
- package/build/events/interfaces/planning.event.d.ts +7 -0
- package/build/events/interfaces/planning.event.js +2 -0
- package/build/events/interfaces/service.event.d.ts +7 -0
- package/build/events/interfaces/service.event.js +2 -0
- package/build/events/interfaces/subscription.event.d.ts +7 -0
- package/build/events/interfaces/subscription.event.js +2 -0
- package/build/events/interfaces/ticket.event.d.ts +7 -0
- package/build/events/interfaces/ticket.event.js +2 -0
- package/build/events/interfaces/ticketNote.event.d.ts +7 -0
- package/build/events/interfaces/ticketNote.event.js +2 -0
- package/build/events/interfaces/ticketTracking.event.d.ts +7 -0
- package/build/events/interfaces/ticketTracking.event.js +2 -0
- package/build/events/interfaces/ticketxTopics.event.d.ts +7 -0
- package/build/events/interfaces/ticketxTopics.event.js +2 -0
- package/build/events/interfaces/topics.event.d.ts +7 -0
- package/build/events/interfaces/topics.event.js +2 -0
- package/build/events/interfaces/waitingList.event.d.ts +7 -0
- package/build/events/interfaces/waitingList.event.js +2 -0
- package/build/exceptions/AuthenticationTokenMissingException.d.ts +5 -0
- package/build/exceptions/AuthenticationTokenMissingException.js +27 -0
- package/build/exceptions/HttpException.d.ts +5 -0
- package/build/exceptions/HttpException.js +27 -0
- package/build/exceptions/MongoErrorException.d.ts +4 -0
- package/build/exceptions/MongoErrorException.js +27 -0
- package/build/exceptions/MulterException.d.ts +4 -0
- package/build/exceptions/MulterException.js +27 -0
- package/build/exceptions/QwizardException.d.ts +5 -0
- package/build/exceptions/QwizardException.js +27 -0
- package/build/exceptions/RecordingServerException.d.ts +5 -0
- package/build/exceptions/RecordingServerException.js +27 -0
- package/build/exceptions/UserNotFoundException.d.ts +4 -0
- package/build/exceptions/UserNotFoundException.js +27 -0
- package/build/exceptions/UserWithThatEmailAlreadyExistsException.d.ts +4 -0
- package/build/exceptions/UserWithThatEmailAlreadyExistsException.js +27 -0
- package/build/exceptions/WrongAnonymousAuthException.d.ts +5 -0
- package/build/exceptions/WrongAnonymousAuthException.js +27 -0
- package/build/exceptions/WrongAuthenticationTokenException.d.ts +5 -0
- package/build/exceptions/WrongAuthenticationTokenException.js +27 -0
- package/build/exceptions/WrongBusinessAuthException.d.ts +5 -0
- package/build/exceptions/WrongBusinessAuthException.js +27 -0
- package/build/exceptions/WrongCredentialsException.d.ts +4 -0
- package/build/exceptions/WrongCredentialsException.js +27 -0
- package/build/exceptions/WrongRoomException.d.ts +4 -0
- package/build/exceptions/WrongRoomException.js +27 -0
- package/build/exceptions/index.d.ts +16 -0
- package/build/exceptions/index.js +28 -0
- package/build/exceptions/invalidToken.exception.d.ts +4 -0
- package/build/exceptions/invalidToken.exception.js +27 -0
- package/build/exceptions/missingToken.exception.d.ts +4 -0
- package/build/exceptions/missingToken.exception.js +27 -0
- package/build/exceptions/wrongAuth.exception.d.ts +5 -0
- package/build/exceptions/wrongAuth.exception.js +27 -0
- package/build/index.d.ts +12 -0
- package/build/index.js +32 -0
- package/build/interfaces/controller.interface.d.ts +5 -0
- package/build/interfaces/controller.interface.js +2 -0
- package/build/interfaces/index.d.ts +3 -0
- package/build/interfaces/index.js +15 -0
- package/build/interfaces/requesWithUser.interface.d.ts +11 -0
- package/build/interfaces/requesWithUser.interface.js +2 -0
- package/build/interfaces/token.interface.d.ts +12 -0
- package/build/interfaces/token.interface.js +2 -0
- package/build/lib/ensureDatabase.d.ts +11 -0
- package/build/lib/ensureDatabase.js +97 -0
- package/build/lib/functions.d.ts +89 -0
- package/build/lib/functions.js +214 -0
- package/build/lib/helpers.d.ts +29 -0
- package/build/lib/helpers.js +33 -0
- package/build/lib/index.d.ts +4 -0
- package/build/lib/index.js +16 -0
- package/build/lib/logger.d.ts +2 -0
- package/build/lib/logger.js +41 -0
- package/build/middlewares/auth.middleware.d.ts +6 -0
- package/build/middlewares/auth.middleware.js +287 -0
- package/build/middlewares/error.middleware.d.ts +3 -0
- package/build/middlewares/error.middleware.js +14 -0
- package/build/middlewares/index.d.ts +3 -0
- package/build/middlewares/index.js +15 -0
- package/build/middlewares/validation.middleware.d.ts +2 -0
- package/build/middlewares/validation.middleware.js +22 -0
- package/package.json +45 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Response } from "express";
|
|
2
|
+
import { LimitedType } from "./helpers";
|
|
3
|
+
export declare const getMailSubjectFromHTML: (html: string, defaultSubject: string) => Promise<string>;
|
|
4
|
+
/**
|
|
5
|
+
* Extracts rate limiting metadata from HTTP response headers
|
|
6
|
+
*
|
|
7
|
+
* @param res - Express/HTTP Response object containing rate limit headers
|
|
8
|
+
* @returns {RateLimitMetadata} Object containing rate limit information
|
|
9
|
+
* - limit: Maximum number of requests allowed (X-RateLimit-Limit)
|
|
10
|
+
* - remaining: Number of requests remaining (X-RateLimit-Remaining)
|
|
11
|
+
* - reset: Timestamp when the rate limit resets (X-RateLimit-Reset)
|
|
12
|
+
*/
|
|
13
|
+
export declare const getRateLimitMetadata: (res: Response) => {
|
|
14
|
+
limit: string | undefined;
|
|
15
|
+
remaining: string | undefined;
|
|
16
|
+
reset: string | undefined;
|
|
17
|
+
};
|
|
18
|
+
export declare const getClientIP: (req: any) => any;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a rate limiter that restricts requests to a specified maximum within a one-minute window
|
|
21
|
+
* @param maxRequests - Maximum number of requests allowed per minute (defaults to 10)
|
|
22
|
+
* @returns Express middleware rate limiter
|
|
23
|
+
* @example
|
|
24
|
+
* // Allow 20 requests per minute
|
|
25
|
+
* app.use(createOneMinuteLimiter(20));
|
|
26
|
+
*/
|
|
27
|
+
export declare const createOneMinuteLimiter: (maxRequests?: number) => import("express-rate-limit").RateLimitRequestHandler;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a rate limiter that restricts requests to a specified maximum within a ten-minute window
|
|
30
|
+
* @param maxRequests - Maximum number of requests allowed per 10 minutes (defaults to 50)
|
|
31
|
+
* @returns Express middleware rate limiter
|
|
32
|
+
* @example
|
|
33
|
+
* // Allow 100 requests per 10 minutes
|
|
34
|
+
* app.use(createTenMinuteLimiter(100));
|
|
35
|
+
*/
|
|
36
|
+
export declare const createTenMinuteLimiter: (maxRequests?: number) => import("express-rate-limit").RateLimitRequestHandler;
|
|
37
|
+
export declare const oneMinuteLimiter: import("express-rate-limit").RateLimitRequestHandler;
|
|
38
|
+
export declare const tenMinuteLimiter: import("express-rate-limit").RateLimitRequestHandler;
|
|
39
|
+
/**
|
|
40
|
+
* Formats a date according to Spanish (es-ES) locale specifications
|
|
41
|
+
* @param date - Date object to format
|
|
42
|
+
* @returns Formatted date string in the format "DD/MM/YYYY HH:mm:ss"
|
|
43
|
+
* @example
|
|
44
|
+
* // Returns "25/03/2024 14:30:45"
|
|
45
|
+
* formatDateEs(new Date());
|
|
46
|
+
*/
|
|
47
|
+
export declare const formatDateEs: (date: Date) => string;
|
|
48
|
+
/**
|
|
49
|
+
* Sanitizes a text field by removing newlines and trimming whitespace
|
|
50
|
+
* @param field - String to sanitize
|
|
51
|
+
* @returns Sanitized string with newlines replaced by spaces and trimmed
|
|
52
|
+
* @example
|
|
53
|
+
* // Returns "Hello World"
|
|
54
|
+
* sanitizeField("Hello\nWorld");
|
|
55
|
+
*/
|
|
56
|
+
export declare const sanitizeField: (field: string) => string;
|
|
57
|
+
/**
|
|
58
|
+
* Compares two objects and returns an object containing the fields that have changed,
|
|
59
|
+
* along with their old and new values. All values are converted to strings for comparison.
|
|
60
|
+
* Objects are JSON stringified for comparison.
|
|
61
|
+
*
|
|
62
|
+
* @param oldObj - The original object to compare from
|
|
63
|
+
* @param newObj - The new object to compare against
|
|
64
|
+
* @returns An object mapping changed field names to their old and new string values
|
|
65
|
+
* @example
|
|
66
|
+
* const oldUser = { name: "John", age: 30, data: { score: 100 } };
|
|
67
|
+
* const newUser = { name: "John", age: 31, data: { score: 200 } };
|
|
68
|
+
* const changes = getChangedFields(oldUser, newUser);
|
|
69
|
+
* // Returns:
|
|
70
|
+
* // {
|
|
71
|
+
* // age: { oldValue: "30", newValue: "31" },
|
|
72
|
+
* // data: { oldValue: '{"score":100}', newValue: '{"score":200}' }
|
|
73
|
+
* // }
|
|
74
|
+
*/
|
|
75
|
+
export declare const getChangedFields: (oldObj: any, newObj: any) => {
|
|
76
|
+
[key: string]: {
|
|
77
|
+
oldValue: string;
|
|
78
|
+
newValue: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Gets the limit for a specific resource type based on the entity's tier
|
|
83
|
+
* @param entity - Entity object with tierId property
|
|
84
|
+
* @param limit - The type of limit to retrieve (branch, department, service, user, agent, device, ticketsMonthly)
|
|
85
|
+
* @returns The limit value for the specified type, or -1 if tier is unknown or entity has no tierId
|
|
86
|
+
*/
|
|
87
|
+
export declare const getLimitsByTier: (entity: {
|
|
88
|
+
tierId?: number;
|
|
89
|
+
} | null, limit: LimitedType) => number;
|
|
@@ -0,0 +1,214 @@
|
|
|
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.getLimitsByTier = exports.getChangedFields = exports.sanitizeField = exports.formatDateEs = exports.tenMinuteLimiter = exports.oneMinuteLimiter = exports.createTenMinuteLimiter = exports.createOneMinuteLimiter = exports.getClientIP = exports.getRateLimitMetadata = exports.getMailSubjectFromHTML = void 0;
|
|
43
|
+
var express_rate_limit_1 = __importDefault(require("express-rate-limit"));
|
|
44
|
+
var helpers_1 = require("./helpers");
|
|
45
|
+
var getMailSubjectFromHTML = function (html, defaultSubject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
+
var titleRegex, match, pageTitle;
|
|
47
|
+
return __generator(this, function (_a) {
|
|
48
|
+
titleRegex = /<title>(.*?)<\/title>/;
|
|
49
|
+
match = html.match(titleRegex);
|
|
50
|
+
if (match && match[1]) {
|
|
51
|
+
pageTitle = match[1];
|
|
52
|
+
return [2 /*return*/, pageTitle];
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return [2 /*return*/, defaultSubject];
|
|
56
|
+
}
|
|
57
|
+
return [2 /*return*/];
|
|
58
|
+
});
|
|
59
|
+
}); };
|
|
60
|
+
exports.getMailSubjectFromHTML = getMailSubjectFromHTML;
|
|
61
|
+
/**
|
|
62
|
+
* Extracts rate limiting metadata from HTTP response headers
|
|
63
|
+
*
|
|
64
|
+
* @param res - Express/HTTP Response object containing rate limit headers
|
|
65
|
+
* @returns {RateLimitMetadata} Object containing rate limit information
|
|
66
|
+
* - limit: Maximum number of requests allowed (X-RateLimit-Limit)
|
|
67
|
+
* - remaining: Number of requests remaining (X-RateLimit-Remaining)
|
|
68
|
+
* - reset: Timestamp when the rate limit resets (X-RateLimit-Reset)
|
|
69
|
+
*/
|
|
70
|
+
var getRateLimitMetadata = function (res) {
|
|
71
|
+
var _a, _b, _c;
|
|
72
|
+
return {
|
|
73
|
+
limit: ((_a = res.getHeader("X-RateLimit-Limit")) === null || _a === void 0 ? void 0 : _a.toString()) || undefined,
|
|
74
|
+
remaining: ((_b = res.getHeader("X-RateLimit-Remaining")) === null || _b === void 0 ? void 0 : _b.toString()) || undefined,
|
|
75
|
+
reset: ((_c = res.getHeader("X-RateLimit-Reset")) === null || _c === void 0 ? void 0 : _c.toString()) || undefined,
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
exports.getRateLimitMetadata = getRateLimitMetadata;
|
|
79
|
+
var getClientIP = function (req) { return req.ip || req.headers["x-forwarded-for"] || req.connection.remoteAddress; };
|
|
80
|
+
exports.getClientIP = getClientIP;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a rate limiter that restricts requests to a specified maximum within a one-minute window
|
|
83
|
+
* @param maxRequests - Maximum number of requests allowed per minute (defaults to 10)
|
|
84
|
+
* @returns Express middleware rate limiter
|
|
85
|
+
* @example
|
|
86
|
+
* // Allow 20 requests per minute
|
|
87
|
+
* app.use(createOneMinuteLimiter(20));
|
|
88
|
+
*/
|
|
89
|
+
var createOneMinuteLimiter = function (maxRequests) {
|
|
90
|
+
if (maxRequests === void 0) { maxRequests = 10; }
|
|
91
|
+
return express_rate_limit_1.default({
|
|
92
|
+
windowMs: 1 * 60 * 1000,
|
|
93
|
+
max: maxRequests,
|
|
94
|
+
message: "Too many requests in 1 minute (max " + maxRequests + "), please slow down.",
|
|
95
|
+
headers: true,
|
|
96
|
+
keyGenerator: exports.getClientIP,
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
exports.createOneMinuteLimiter = createOneMinuteLimiter;
|
|
100
|
+
/**
|
|
101
|
+
* Creates a rate limiter that restricts requests to a specified maximum within a ten-minute window
|
|
102
|
+
* @param maxRequests - Maximum number of requests allowed per 10 minutes (defaults to 50)
|
|
103
|
+
* @returns Express middleware rate limiter
|
|
104
|
+
* @example
|
|
105
|
+
* // Allow 100 requests per 10 minutes
|
|
106
|
+
* app.use(createTenMinuteLimiter(100));
|
|
107
|
+
*/
|
|
108
|
+
var createTenMinuteLimiter = function (maxRequests) {
|
|
109
|
+
if (maxRequests === void 0) { maxRequests = 50; }
|
|
110
|
+
return express_rate_limit_1.default({
|
|
111
|
+
windowMs: 10 * 60 * 1000,
|
|
112
|
+
max: maxRequests,
|
|
113
|
+
message: "Too many requests in 10 minutes (max " + maxRequests + "), please slow down.",
|
|
114
|
+
headers: true,
|
|
115
|
+
keyGenerator: exports.getClientIP,
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
exports.createTenMinuteLimiter = createTenMinuteLimiter;
|
|
119
|
+
// For backward compatibility
|
|
120
|
+
exports.oneMinuteLimiter = exports.createOneMinuteLimiter();
|
|
121
|
+
exports.tenMinuteLimiter = exports.createTenMinuteLimiter();
|
|
122
|
+
/**
|
|
123
|
+
* Formats a date according to Spanish (es-ES) locale specifications
|
|
124
|
+
* @param date - Date object to format
|
|
125
|
+
* @returns Formatted date string in the format "DD/MM/YYYY HH:mm:ss"
|
|
126
|
+
* @example
|
|
127
|
+
* // Returns "25/03/2024 14:30:45"
|
|
128
|
+
* formatDateEs(new Date());
|
|
129
|
+
*/
|
|
130
|
+
var formatDateEs = function (date) {
|
|
131
|
+
return date
|
|
132
|
+
.toLocaleString("es-ES", {
|
|
133
|
+
year: "numeric",
|
|
134
|
+
month: "2-digit",
|
|
135
|
+
day: "2-digit",
|
|
136
|
+
hour: "2-digit",
|
|
137
|
+
minute: "2-digit",
|
|
138
|
+
second: "2-digit",
|
|
139
|
+
})
|
|
140
|
+
.replace(",", "");
|
|
141
|
+
};
|
|
142
|
+
exports.formatDateEs = formatDateEs;
|
|
143
|
+
/**
|
|
144
|
+
* Sanitizes a text field by removing newlines and trimming whitespace
|
|
145
|
+
* @param field - String to sanitize
|
|
146
|
+
* @returns Sanitized string with newlines replaced by spaces and trimmed
|
|
147
|
+
* @example
|
|
148
|
+
* // Returns "Hello World"
|
|
149
|
+
* sanitizeField("Hello\nWorld");
|
|
150
|
+
*/
|
|
151
|
+
var sanitizeField = function (field) { return (field ? field.replace(/\r?\n|\r/g, " ").trim() : ""); };
|
|
152
|
+
exports.sanitizeField = sanitizeField;
|
|
153
|
+
/**
|
|
154
|
+
* Compares two objects and returns an object containing the fields that have changed,
|
|
155
|
+
* along with their old and new values. All values are converted to strings for comparison.
|
|
156
|
+
* Objects are JSON stringified for comparison.
|
|
157
|
+
*
|
|
158
|
+
* @param oldObj - The original object to compare from
|
|
159
|
+
* @param newObj - The new object to compare against
|
|
160
|
+
* @returns An object mapping changed field names to their old and new string values
|
|
161
|
+
* @example
|
|
162
|
+
* const oldUser = { name: "John", age: 30, data: { score: 100 } };
|
|
163
|
+
* const newUser = { name: "John", age: 31, data: { score: 200 } };
|
|
164
|
+
* const changes = getChangedFields(oldUser, newUser);
|
|
165
|
+
* // Returns:
|
|
166
|
+
* // {
|
|
167
|
+
* // age: { oldValue: "30", newValue: "31" },
|
|
168
|
+
* // data: { oldValue: '{"score":100}', newValue: '{"score":200}' }
|
|
169
|
+
* // }
|
|
170
|
+
*/
|
|
171
|
+
var getChangedFields = function (oldObj, newObj) {
|
|
172
|
+
var changes = {};
|
|
173
|
+
Object.keys(newObj).forEach(function (key) {
|
|
174
|
+
var oldValue = oldObj[key];
|
|
175
|
+
var newValue = newObj[key];
|
|
176
|
+
// Skip if values are the same
|
|
177
|
+
if (oldValue === newValue)
|
|
178
|
+
return;
|
|
179
|
+
// Convert values to strings for comparison and storage
|
|
180
|
+
var oldStringified = typeof oldValue === "object" && oldValue !== null ? JSON.stringify(oldValue) : String(oldValue !== null && oldValue !== void 0 ? oldValue : "");
|
|
181
|
+
var newStringified = typeof newValue === "object" && newValue !== null ? JSON.stringify(newValue) : String(newValue);
|
|
182
|
+
// Only add if values are actually different when compared as strings
|
|
183
|
+
if (oldStringified !== newStringified) {
|
|
184
|
+
changes[key] = {
|
|
185
|
+
oldValue: oldStringified,
|
|
186
|
+
newValue: newStringified,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return changes;
|
|
191
|
+
};
|
|
192
|
+
exports.getChangedFields = getChangedFields;
|
|
193
|
+
/**
|
|
194
|
+
* Gets the limit for a specific resource type based on the entity's tier
|
|
195
|
+
* @param entity - Entity object with tierId property
|
|
196
|
+
* @param limit - The type of limit to retrieve (branch, department, service, user, agent, device, ticketsMonthly)
|
|
197
|
+
* @returns The limit value for the specified type, or -1 if tier is unknown or entity has no tierId
|
|
198
|
+
*/
|
|
199
|
+
var getLimitsByTier = function (entity, limit) {
|
|
200
|
+
if (entity === null || entity === void 0 ? void 0 : entity.tierId) {
|
|
201
|
+
var tier = entity.tierId;
|
|
202
|
+
if (tier === 1) {
|
|
203
|
+
return helpers_1.TierLimits.free[limit];
|
|
204
|
+
}
|
|
205
|
+
else if (tier === 2) {
|
|
206
|
+
return helpers_1.TierLimits.starter[limit];
|
|
207
|
+
}
|
|
208
|
+
return -1; // Default for unknown tiers
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
return -1;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
exports.getLimitsByTier = getLimitsByTier;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare enum LimitedType {
|
|
2
|
+
branch = "branch",
|
|
3
|
+
department = "department",
|
|
4
|
+
service = "service",
|
|
5
|
+
user = "user",
|
|
6
|
+
agent = "agent",
|
|
7
|
+
device = "device",
|
|
8
|
+
ticketsMonthly = "ticketsMonthly"
|
|
9
|
+
}
|
|
10
|
+
export declare const TierLimits: {
|
|
11
|
+
free: {
|
|
12
|
+
branch: number;
|
|
13
|
+
department: number;
|
|
14
|
+
service: number;
|
|
15
|
+
user: number;
|
|
16
|
+
agent: number;
|
|
17
|
+
device: number;
|
|
18
|
+
ticketsMonthly: number;
|
|
19
|
+
};
|
|
20
|
+
starter: {
|
|
21
|
+
branch: number;
|
|
22
|
+
department: number;
|
|
23
|
+
service: number;
|
|
24
|
+
user: number;
|
|
25
|
+
agent: number;
|
|
26
|
+
device: number;
|
|
27
|
+
ticketsMonthly: number;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TierLimits = exports.LimitedType = void 0;
|
|
4
|
+
var LimitedType;
|
|
5
|
+
(function (LimitedType) {
|
|
6
|
+
LimitedType["branch"] = "branch";
|
|
7
|
+
LimitedType["department"] = "department";
|
|
8
|
+
LimitedType["service"] = "service";
|
|
9
|
+
LimitedType["user"] = "user";
|
|
10
|
+
LimitedType["agent"] = "agent";
|
|
11
|
+
LimitedType["device"] = "device";
|
|
12
|
+
LimitedType["ticketsMonthly"] = "ticketsMonthly";
|
|
13
|
+
})(LimitedType = exports.LimitedType || (exports.LimitedType = {}));
|
|
14
|
+
exports.TierLimits = {
|
|
15
|
+
free: {
|
|
16
|
+
branch: 1,
|
|
17
|
+
department: 1,
|
|
18
|
+
service: 5,
|
|
19
|
+
user: 4,
|
|
20
|
+
agent: 3,
|
|
21
|
+
device: 0,
|
|
22
|
+
ticketsMonthly: 200,
|
|
23
|
+
},
|
|
24
|
+
starter: {
|
|
25
|
+
branch: 3,
|
|
26
|
+
department: 3,
|
|
27
|
+
service: 20,
|
|
28
|
+
user: 6,
|
|
29
|
+
agent: 5,
|
|
30
|
+
device: 3,
|
|
31
|
+
ticketsMonthly: 5000,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./functions"), exports);
|
|
14
|
+
__exportStar(require("./helpers"), exports);
|
|
15
|
+
__exportStar(require("./logger"), exports);
|
|
16
|
+
__exportStar(require("./ensureDatabase"), exports);
|
|
@@ -0,0 +1,41 @@
|
|
|
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.logger = void 0;
|
|
7
|
+
var pino_1 = __importDefault(require("pino"));
|
|
8
|
+
exports.logger = pino_1.default({
|
|
9
|
+
level: process.env.LOG_LEVEL || 'info',
|
|
10
|
+
transport: {
|
|
11
|
+
target: 'pino-pretty',
|
|
12
|
+
options: {
|
|
13
|
+
colorize: true,
|
|
14
|
+
levelFirst: true,
|
|
15
|
+
translateTime: 'SYS:standard',
|
|
16
|
+
ignore: 'pid,hostname',
|
|
17
|
+
messageFormat: '{msg} {context}',
|
|
18
|
+
customLevels: {
|
|
19
|
+
error: 50,
|
|
20
|
+
warn: 40,
|
|
21
|
+
info: 30,
|
|
22
|
+
debug: 20,
|
|
23
|
+
trace: 10
|
|
24
|
+
},
|
|
25
|
+
customColors: 'error:red,warn:yellow,info:blue,debug:green,trace:gray'
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
base: {
|
|
29
|
+
env: process.env.NODE_ENV,
|
|
30
|
+
},
|
|
31
|
+
timestamp: function () { return ",\"time\":\"" + new Date(Date.now()).toISOString() + "\""; },
|
|
32
|
+
formatters: {
|
|
33
|
+
level: function (label) {
|
|
34
|
+
return { level: label.toUpperCase() };
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
redact: {
|
|
38
|
+
paths: ['password', 'secret', 'token', '*.password', '*.secret', '*.token'],
|
|
39
|
+
censor: '**REDACTED**'
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NextFunction, Response, Request } from "express";
|
|
2
|
+
import { RequestWithUser, RequestWithUserFB } from "../interfaces";
|
|
3
|
+
export declare function authFBMiddleware(request: RequestWithUserFB, response: Response, next: NextFunction): Promise<void>;
|
|
4
|
+
export declare function authMiddleware(request: RequestWithUser, response: Response, next: NextFunction): Promise<void>;
|
|
5
|
+
export declare function midAuthMiddleware(request: RequestWithUser, response: Response, next: NextFunction): Promise<void>;
|
|
6
|
+
export declare function authTokenMiddleware(request: Request, response: Response, next: NextFunction): Promise<void>;
|