@xrystal/core 3.2.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.
Files changed (76) hide show
  1. package/README.md +1 -0
  2. package/bin/constants/index.mjs +14 -0
  3. package/bin/helpers/index.mjs +83 -0
  4. package/bin/main-cli.js +179 -0
  5. package/package.json +113 -0
  6. package/source/index.d.ts +2 -0
  7. package/source/index.js +8 -0
  8. package/source/loader/configs/index.d.ts +13 -0
  9. package/source/loader/configs/index.js +17 -0
  10. package/source/loader/events/index.d.ts +6 -0
  11. package/source/loader/events/index.js +25 -0
  12. package/source/loader/index.d.ts +6 -0
  13. package/source/loader/index.js +6 -0
  14. package/source/loader/localizations/index.d.ts +14 -0
  15. package/source/loader/localizations/index.js +32 -0
  16. package/source/loader/logger/index.d.ts +22 -0
  17. package/source/loader/logger/index.js +130 -0
  18. package/source/loader/system/index.d.ts +8 -0
  19. package/source/loader/system/index.js +14 -0
  20. package/source/project/index.d.ts +7 -0
  21. package/source/project/index.js +94 -0
  22. package/source/utils/constants/index.d.ts +8 -0
  23. package/source/utils/constants/index.js +10 -0
  24. package/source/utils/helpers/date/index.d.ts +16 -0
  25. package/source/utils/helpers/date/index.js +48 -0
  26. package/source/utils/helpers/filters/index.d.ts +17 -0
  27. package/source/utils/helpers/filters/index.js +44 -0
  28. package/source/utils/helpers/hash/crypto.d.ts +3 -0
  29. package/source/utils/helpers/hash/crypto.js +22 -0
  30. package/source/utils/helpers/id/index.d.ts +13 -0
  31. package/source/utils/helpers/id/index.js +24 -0
  32. package/source/utils/helpers/index.d.ts +16 -0
  33. package/source/utils/helpers/index.js +16 -0
  34. package/source/utils/helpers/ip/index.d.ts +1 -0
  35. package/source/utils/helpers/ip/index.js +3 -0
  36. package/source/utils/helpers/is/index.d.ts +11 -0
  37. package/source/utils/helpers/is/index.js +35 -0
  38. package/source/utils/helpers/locales/index.d.ts +52 -0
  39. package/source/utils/helpers/locales/index.js +161 -0
  40. package/source/utils/helpers/locales copy/index.d.ts +52 -0
  41. package/source/utils/helpers/locales copy/index.js +161 -0
  42. package/source/utils/helpers/math/index.d.ts +2 -0
  43. package/source/utils/helpers/math/index.js +14 -0
  44. package/source/utils/helpers/objects/index.d.ts +1 -0
  45. package/source/utils/helpers/objects/index.js +55 -0
  46. package/source/utils/helpers/path/index.d.ts +2 -0
  47. package/source/utils/helpers/path/index.js +4 -0
  48. package/source/utils/helpers/regex/checkSpecialRegexControl.d.ts +1 -0
  49. package/source/utils/helpers/regex/checkSpecialRegexControl.js +3 -0
  50. package/source/utils/helpers/string/index.d.ts +1 -0
  51. package/source/utils/helpers/string/index.js +9 -0
  52. package/source/utils/helpers/timer/index.d.ts +3 -0
  53. package/source/utils/helpers/timer/index.js +5 -0
  54. package/source/utils/helpers/tmp/index.d.ts +8 -0
  55. package/source/utils/helpers/tmp/index.js +109 -0
  56. package/source/utils/helpers/validates/index.d.ts +5 -0
  57. package/source/utils/helpers/validates/index.js +20 -0
  58. package/source/utils/index.d.ts +3 -0
  59. package/source/utils/index.js +3 -0
  60. package/source/utils/models/classes/class.controller.d.ts +121 -0
  61. package/source/utils/models/classes/class.controller.js +421 -0
  62. package/source/utils/models/classes/class.response.d.ts +17 -0
  63. package/source/utils/models/classes/class.response.js +37 -0
  64. package/source/utils/models/classes/class.services.d.ts +129 -0
  65. package/source/utils/models/classes/class.services.js +344 -0
  66. package/source/utils/models/classes/class.tmp-file-loader.d.ts +11 -0
  67. package/source/utils/models/classes/class.tmp-file-loader.js +38 -0
  68. package/source/utils/models/classes/class.x.d.ts +12 -0
  69. package/source/utils/models/classes/class.x.js +16 -0
  70. package/source/utils/models/enums/index.d.ts +116 -0
  71. package/source/utils/models/enums/index.js +132 -0
  72. package/source/utils/models/index.d.ts +8 -0
  73. package/source/utils/models/index.js +8 -0
  74. package/source/utils/models/types/index.d.ts +3 -0
  75. package/source/utils/models/types/index.js +2 -0
  76. package/x/tmp.yml +26 -0
@@ -0,0 +1,130 @@
1
+ import winston, { format } from 'winston';
2
+ import 'winston-daily-rotate-file';
3
+ import path from 'path';
4
+ import { Kafka, Partitioners } from 'kafkajs';
5
+ import { LoggerLayerEnum } from '../../utils';
6
+ const customLevels = {
7
+ critical: LoggerLayerEnum.CRITICAL, // 0
8
+ error: LoggerLayerEnum.ERROR, // 1
9
+ info: LoggerLayerEnum.INFO, // 2
10
+ debug: LoggerLayerEnum.DEBUG // 3
11
+ };
12
+ const customColors = {
13
+ critical: 'red',
14
+ error: 'magenta',
15
+ warn: 'yellow',
16
+ info: 'green',
17
+ http: 'cyan',
18
+ debug: 'blue'
19
+ };
20
+ export default class LoggerService {
21
+ serviceName = "";
22
+ environment = "";
23
+ kafkaProducer = null;
24
+ kafkaTopic = "";
25
+ isKafkaReady = false;
26
+ getConsoleFormat() {
27
+ return format.combine(format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), format.colorize({ all: true }), format.printf((info) => {
28
+ const msg = typeof info.message === 'object' ? JSON.stringify(info.message) : info.message;
29
+ return `${info.timestamp} [${this.serviceName}] ${info.level}: ${msg}`;
30
+ }));
31
+ }
32
+ winston = winston.createLogger({
33
+ level: 'debug',
34
+ levels: customLevels,
35
+ transports: [
36
+ new winston.transports.Console({
37
+ format: this.getConsoleFormat()
38
+ })
39
+ ]
40
+ });
41
+ constructor() {
42
+ winston.addColors(customColors);
43
+ }
44
+ load = async (config) => {
45
+ this.serviceName = config.serviceName;
46
+ this.environment = config.env;
47
+ this.kafkaTopic = config.kafkaTopic;
48
+ this.winstonLoader({
49
+ loadPath: config.loadPath,
50
+ loggerLevel: config.loggerLevel
51
+ });
52
+ const brokers = config.kafkaBrokers ? config.kafkaBrokers.split(',').map((b) => b.trim()) : [];
53
+ if (brokers.length > 0) {
54
+ try {
55
+ const kafka = new Kafka({
56
+ clientId: config.serviceName,
57
+ brokers: brokers,
58
+ retry: {
59
+ initialRetryTime: 100,
60
+ retries: 3
61
+ }
62
+ });
63
+ this.kafkaProducer = kafka.producer({ createPartitioner: Partitioners.LegacyPartitioner });
64
+ await this.kafkaProducer.connect();
65
+ this.isKafkaReady = true;
66
+ this.winston.info('Logger connected to Kafka successfully');
67
+ }
68
+ catch (err) {
69
+ console.error(`[LoggerService] Kafka connection failed: ${err.message}. Logging will continue only to files/console.`);
70
+ this.isKafkaReady = false;
71
+ this.kafkaProducer = null;
72
+ }
73
+ }
74
+ };
75
+ winstonLoader = ({ loadPath, loggerLevel }) => {
76
+ const { combine, timestamp, json, errors } = format;
77
+ const jsonFileFormat = combine(timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), errors({ stack: true }), json());
78
+ const winstonLogger = winston.createLogger({
79
+ level: loggerLevel,
80
+ levels: customLevels,
81
+ transports: [
82
+ new winston.transports.Console({
83
+ format: this.getConsoleFormat()
84
+ }),
85
+ new winston.transports.DailyRotateFile({
86
+ filename: path.resolve(loadPath, 'error', '%DATE%_error.log'),
87
+ level: 'error',
88
+ format: jsonFileFormat,
89
+ maxSize: '2mb',
90
+ maxFiles: '7d'
91
+ }),
92
+ new winston.transports.DailyRotateFile({
93
+ filename: path.resolve(loadPath, 'critical', '%DATE%_critical.log'),
94
+ level: 'critical',
95
+ format: jsonFileFormat,
96
+ maxSize: '2mb',
97
+ maxFiles: '14d'
98
+ })
99
+ ]
100
+ });
101
+ winstonLogger.on('data', (info) => {
102
+ if (this.isKafkaReady) {
103
+ this.logToKafka(info);
104
+ }
105
+ });
106
+ this.winston = winstonLogger;
107
+ return winstonLogger;
108
+ };
109
+ async logToKafka(info) {
110
+ if (!this.kafkaProducer || !this.isKafkaReady)
111
+ return;
112
+ try {
113
+ await this.kafkaProducer.send({
114
+ topic: this.kafkaTopic,
115
+ messages: [{
116
+ value: JSON.stringify({
117
+ ...info,
118
+ service: this.serviceName,
119
+ env: this.environment,
120
+ timestamp: new Date().toISOString()
121
+ })
122
+ }]
123
+ });
124
+ }
125
+ catch (err) {
126
+ this.isKafkaReady = false;
127
+ console.error('Kafka send error, disabling Kafka logging temporarily:', err);
128
+ }
129
+ }
130
+ }
@@ -0,0 +1,8 @@
1
+ export default class SystemService {
2
+ private static _tmp;
3
+ load: ({ tmp, }: {
4
+ tmp: any;
5
+ }) => Promise<void>;
6
+ private _systemLoader;
7
+ static get tmp(): any;
8
+ }
@@ -0,0 +1,14 @@
1
+ export default class SystemService {
2
+ static _tmp;
3
+ load = async ({ tmp, }) => {
4
+ SystemService._tmp = tmp;
5
+ await this._systemLoader({});
6
+ };
7
+ _systemLoader = async ({}) => {
8
+ //console.log(this._tmp)
9
+ };
10
+ // => getters
11
+ static get tmp() {
12
+ return SystemService._tmp;
13
+ }
14
+ }
@@ -0,0 +1,7 @@
1
+ import webpack from 'webpack';
2
+ import * as webpackMerge from 'webpack-merge';
3
+ import nodeExternals from 'webpack-node-externals';
4
+ import MiniCssExtractPlugin from 'mini-css-extract-plugin';
5
+ declare const coreLoader: any;
6
+ export { webpack, webpackMerge, nodeExternals, MiniCssExtractPlugin };
7
+ export default coreLoader;
@@ -0,0 +1,94 @@
1
+ // => import dependencies
2
+ import path from 'path';
3
+ import webpack from 'webpack';
4
+ import * as webpackMerge from 'webpack-merge';
5
+ import nodeExternals from 'webpack-node-externals';
6
+ import MiniCssExtractPlugin from 'mini-css-extract-plugin';
7
+ import { SystemService, ConfigsService, LoggerService, EventsService, LocalizationsService } from '../loader/index';
8
+ import { packageName, tmpFileDefaultName, tmpFileDefaultExt, findFileRecursively, TmpFileLoader, x, kafkaBrokers, systemLoggerLayer, } from '../utils/index';
9
+ //
10
+ let coreHasRun = false;
11
+ const coreLoader = async () => {
12
+ let response = {};
13
+ let r = {};
14
+ let rootFolderPath = '';
15
+ let ownerTmpFilePath = null;
16
+ let resolvedTmpFileJson = null;
17
+ if (coreHasRun) {
18
+ return response;
19
+ }
20
+ try {
21
+ ownerTmpFilePath = findFileRecursively('.', tmpFileDefaultName, tmpFileDefaultExt);
22
+ if (!ownerTmpFilePath) {
23
+ console.error(`${tmpFileDefaultName} file not found.`);
24
+ }
25
+ const tmpFileObject = new TmpFileLoader({
26
+ filePath: ownerTmpFilePath
27
+ });
28
+ resolvedTmpFileJson = tmpFileObject.getResolvedTmpFile();
29
+ r = resolvedTmpFileJson;
30
+ response = {
31
+ _: r
32
+ };
33
+ rootFolderPath = resolvedTmpFileJson.configs.rootFolderPath;
34
+ // => LOADER
35
+ const serviceName = r.configs.service;
36
+ const nodeEnv = process.env.NODE_ENV;
37
+ try {
38
+ x.set({
39
+ service: SystemService,
40
+ reference: SystemService
41
+ });
42
+ x.set({
43
+ service: ConfigsService,
44
+ reference: ConfigsService
45
+ });
46
+ x.set({
47
+ service: LoggerService,
48
+ reference: LoggerService
49
+ });
50
+ x.set({
51
+ service: EventsService,
52
+ reference: EventsService
53
+ });
54
+ x.set({
55
+ service: LocalizationsService,
56
+ reference: LocalizationsService
57
+ });
58
+ await x.get(SystemService).load({
59
+ tmp: response
60
+ });
61
+ await x.get(ConfigsService).load({
62
+ tmpFolderPath: rootFolderPath,
63
+ systemService: x.get(SystemService),
64
+ envLoadPath: `${rootFolderPath}/${r.configs.loaders.configs.envLoadPath}`,
65
+ ...(r.configs.loaders.configs.globalEnvFileName ? { globalEnvFileName: r.configs.loaders.configs.globalEnvFileName } : null)
66
+ });
67
+ await x.get(LoggerService).load({
68
+ loadPath: `${rootFolderPath}/${r.configs.loaders.loggers.loadPath}`,
69
+ loggerLevel: systemLoggerLayer || r.configs.loaders.loggers.logLevel,
70
+ serviceName,
71
+ env: nodeEnv,
72
+ kafkaBrokers: kafkaBrokers || '',
73
+ kafkaTopic: r.configs.loaders.loggers.topic
74
+ });
75
+ await x.get(EventsService).load({});
76
+ await x.get(LocalizationsService).load({
77
+ loadPath: path.resolve(`${rootFolderPath}/${r.configs.loaders.localization.loadPath}`),
78
+ fallbackLang: r.configs.loaders.localization.fallbackLang,
79
+ preloadLang: r.configs.loaders.localization.preloadLangs,
80
+ });
81
+ }
82
+ catch (error) {
83
+ console.log(`x:${error}`);
84
+ }
85
+ //
86
+ coreHasRun = true;
87
+ return response;
88
+ }
89
+ catch (error) {
90
+ console.error(`${packageName} x:`, error?.message);
91
+ }
92
+ };
93
+ export { webpack, webpackMerge, nodeExternals, MiniCssExtractPlugin };
94
+ export default coreLoader;
@@ -0,0 +1,8 @@
1
+ export declare const packageName: string;
2
+ export declare const tmpFileDefaultMainFolderName: string;
3
+ export declare const tmpFileDefaultName: string;
4
+ export declare const tmpFileDefaultExt = ".yml";
5
+ export declare const defaultTmpFilePath: string;
6
+ export declare const defaultOwnerTmpFilePath: string;
7
+ export declare const systemLoggerLayer: string;
8
+ export declare const kafkaBrokers: string;
@@ -0,0 +1,10 @@
1
+ import path from 'path';
2
+ import { __dirname } from '../helpers/path';
3
+ export const packageName = 'tmp-project-tool';
4
+ export const tmpFileDefaultMainFolderName = 'x';
5
+ export const tmpFileDefaultName = 'tmp';
6
+ export const tmpFileDefaultExt = '.yml';
7
+ export const defaultTmpFilePath = path.resolve(__dirname(import.meta.url), `../../${tmpFileDefaultMainFolderName}/${tmpFileDefaultName}.yml`);
8
+ export const defaultOwnerTmpFilePath = path.resolve(`./${tmpFileDefaultMainFolderName}/${tmpFileDefaultName}.yml`);
9
+ export const systemLoggerLayer = process.env.SYSTEM_LOGGER_LAYER;
10
+ export const kafkaBrokers = process.env.KAFKA_BROKERS;
@@ -0,0 +1,16 @@
1
+ import { PolarityTypeEnum } from "../../models";
2
+ export declare function dateZoneConverter({ polarity, date, zone, factor }: {
3
+ polarity: PolarityTypeEnum;
4
+ date: Date;
5
+ zone: number;
6
+ factor?: number;
7
+ }): string;
8
+ export declare function convertDate(date: string, splitCharacter?: string, replaceCharacter?: string): string[];
9
+ export declare function convertTime(time: string, splitCharacter?: string, replaceCharacter?: string): string[];
10
+ export declare function getDateAndTime({ getDate, getTime, dateCharacter, timeCharacter, separatorCharacter }: {
11
+ getDate: boolean;
12
+ getTime: boolean;
13
+ dateCharacter: string;
14
+ timeCharacter: string;
15
+ separatorCharacter: string;
16
+ }): string;
@@ -0,0 +1,48 @@
1
+ import { PolarityTypeEnum } from "../../models";
2
+ export function dateZoneConverter({ polarity, date, zone, factor = 1000 }) {
3
+ let convertedZoneTime = null;
4
+ if (polarity === PolarityTypeEnum.NEGATIVE) {
5
+ convertedZoneTime = date.getTime() - factor * zone;
6
+ }
7
+ else {
8
+ convertedZoneTime = date.getTime() + factor * zone;
9
+ }
10
+ return new Date(convertedZoneTime).toISOString();
11
+ }
12
+ export function convertDate(date, splitCharacter = '/', replaceCharacter = '-') {
13
+ const convertDate = date.split(splitCharacter).map((value, index) => index !== 2 ? replaceCharacter : value);
14
+ return convertDate;
15
+ }
16
+ export function convertTime(time, splitCharacter = ':', replaceCharacter = '-') {
17
+ const convertDate = time.split(splitCharacter).map((value, index) => index !== 2 ? replaceCharacter : value);
18
+ return convertDate;
19
+ }
20
+ export function getDateAndTime({ getDate = true, getTime = true, dateCharacter = '-', timeCharacter = ':', separatorCharacter = '&' }) {
21
+ const date = new Date();
22
+ let formattedDate = '';
23
+ if (!getDate && !getTime) {
24
+ throw new Error("Invalid options! Required one true value");
25
+ }
26
+ if (getDate) {
27
+ const day = date.getDate().toString().padStart(2, '0');
28
+ const month = (date.getMonth() + 1).toString().padStart(2, '0');
29
+ const year = date.getFullYear();
30
+ formattedDate = `${year}${dateCharacter}${month}${dateCharacter}${day}`;
31
+ }
32
+ if (getTime) {
33
+ const hours = date.getHours().toString().padStart(2, '0');
34
+ const minutes = date.getMinutes().toString().padStart(2, '0');
35
+ const seconds = date.getSeconds().toString().padStart(2, '0');
36
+ formattedDate = `${hours}${timeCharacter}${minutes}${timeCharacter}${seconds}`;
37
+ }
38
+ if (getDate && getTime) {
39
+ const day = date.getDate().toString().padStart(2, '0');
40
+ const month = (date.getMonth() + 1).toString().padStart(2, '0');
41
+ const year = date.getFullYear();
42
+ const hours = date.getHours().toString().padStart(2, '0');
43
+ const minutes = date.getMinutes().toString().padStart(2, '0');
44
+ const seconds = date.getSeconds().toString().padStart(2, '0');
45
+ formattedDate = `${year}${dateCharacter}${month}${dateCharacter}${day}${separatorCharacter}${hours}${timeCharacter}${minutes}${timeCharacter}${seconds}`;
46
+ }
47
+ return formattedDate;
48
+ }
@@ -0,0 +1,17 @@
1
+ declare function mongoFilter(start: any, end: any, objPath: string): any;
2
+ declare function filterUniqueOnce<T extends Record<string, any>>({ arr, key, uniqueOnceValues }: {
3
+ arr: T[];
4
+ key: keyof T;
5
+ uniqueOnceValues: (T[keyof T])[];
6
+ }): T[];
7
+ declare function filterSortByPropOrder<T extends Record<string, any>>({ arr, key, desiredOrder }: {
8
+ arr: T[];
9
+ key: keyof T;
10
+ desiredOrder: T[keyof T][];
11
+ }): T[];
12
+ declare function filterRemoveItemsByProps<T extends Record<string, any>>({ arr, key, valuesToRemove }: {
13
+ arr: T[];
14
+ key: keyof T;
15
+ valuesToRemove: (T[keyof T])[];
16
+ }): T[];
17
+ export { mongoFilter, filterUniqueOnce, filterSortByPropOrder, filterRemoveItemsByProps };
@@ -0,0 +1,44 @@
1
+ function mongoFilter(start, end, objPath) {
2
+ const filter = {};
3
+ if (!objPath) {
4
+ throw new Error('MongoFilter helper property is required.');
5
+ }
6
+ filter[objPath] = filter[objPath] || {};
7
+ if (start && end) {
8
+ filter[objPath].$gte = start;
9
+ filter[objPath].$lte = end;
10
+ }
11
+ else if (start) {
12
+ filter[objPath].$gte = start;
13
+ }
14
+ else if (end) {
15
+ filter[objPath].$lte = end;
16
+ }
17
+ return filter;
18
+ }
19
+ function filterUniqueOnce({ arr, key, uniqueOnceValues }) {
20
+ const seen = new Set();
21
+ return arr.filter(item => {
22
+ const val = item[key];
23
+ if (uniqueOnceValues.includes(val)) {
24
+ if (seen.has(val))
25
+ return false;
26
+ seen.add(val);
27
+ return true;
28
+ }
29
+ return true;
30
+ });
31
+ }
32
+ function filterSortByPropOrder({ arr, key, desiredOrder }) {
33
+ const orderMap = new Map();
34
+ desiredOrder.forEach((value, index) => orderMap.set(value, index));
35
+ return [...arr].sort((a, b) => {
36
+ const aIndex = orderMap.get(a[key]) ?? Infinity;
37
+ const bIndex = orderMap.get(b[key]) ?? Infinity;
38
+ return aIndex - bIndex;
39
+ });
40
+ }
41
+ function filterRemoveItemsByProps({ arr, key, valuesToRemove }) {
42
+ return arr.filter(item => !valuesToRemove.includes(item[key]));
43
+ }
44
+ export { mongoFilter, filterUniqueOnce, filterSortByPropOrder, filterRemoveItemsByProps };
@@ -0,0 +1,3 @@
1
+ export declare function generateSHA256Hash(secret: any, payload?: any): string;
2
+ export declare function generateNumberAndLetter(length?: number): string;
3
+ export declare function generateCodeChallenge(codeVerifier: string): string;
@@ -0,0 +1,22 @@
1
+ import crypto from 'crypto';
2
+ export function generateSHA256Hash(secret, payload) {
3
+ return crypto
4
+ .createHmac('sha256', secret)
5
+ .update(payload ? payload : '')
6
+ .digest('hex');
7
+ }
8
+ export function generateNumberAndLetter(length = 8) {
9
+ const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
10
+ const array = new Uint8Array(length);
11
+ crypto.getRandomValues(array);
12
+ return Array.from(array, byte => charset[byte % charset.length]).join('');
13
+ }
14
+ export function generateCodeChallenge(codeVerifier) {
15
+ return crypto
16
+ .createHash('sha256')
17
+ .update(codeVerifier)
18
+ .digest('base64')
19
+ .replace(/\+/g, '-')
20
+ .replace(/\//g, '_')
21
+ .replace(/=+$/, '');
22
+ }
@@ -0,0 +1,13 @@
1
+ export declare const serverIdNameGenerator: ({ prefix, payload, suffix }: {
2
+ prefix?: string;
3
+ payload: any;
4
+ suffix?: string;
5
+ }) => string;
6
+ export declare function generateRandomKey(options: {
7
+ length?: number;
8
+ format?: 'hex' | 'base64';
9
+ prefix?: string;
10
+ suffix?: string;
11
+ separator?: string;
12
+ }): string;
13
+ export declare function generateReferenceCode(length: number, prefix?: string, middle?: string, suffix?: string): string;
@@ -0,0 +1,24 @@
1
+ import crypto from 'crypto';
2
+ export const serverIdNameGenerator = ({ prefix, payload, suffix }) => {
3
+ return `${prefix}-${payload.toString()}-${suffix}`;
4
+ };
5
+ export function generateRandomKey(options) {
6
+ const { length = 48, format = 'hex', prefix = '', suffix = '', separator = '-', } = options;
7
+ const randomPart = crypto.randomBytes(length).toString(format);
8
+ const parts = [prefix, randomPart, suffix].filter(Boolean);
9
+ return parts.join(separator);
10
+ }
11
+ export function generateReferenceCode(length, prefix = "", middle = "", suffix = "") {
12
+ const totalLength = prefix.length + length + middle.length + suffix.length;
13
+ if (totalLength <= 0) {
14
+ throw new Error("The total length (including prefix, middle, and suffix) must be greater than 0.");
15
+ }
16
+ let referenceCode = "";
17
+ for (let i = 0; i < length; i++) {
18
+ const randomDigit = Math.floor(Math.random() * 10);
19
+ referenceCode += randomDigit.toString();
20
+ }
21
+ const middleIndex = Math.floor(referenceCode.length / 2);
22
+ const referenceWithMiddle = referenceCode.slice(0, middleIndex) + middle + referenceCode.slice(middleIndex);
23
+ return `${prefix}${referenceWithMiddle}${suffix}`;
24
+ }
@@ -0,0 +1,16 @@
1
+ export * from './tmp/index';
2
+ export * from './path/index';
3
+ export * from './is/index';
4
+ export * from './id/index';
5
+ export * from './validates/index';
6
+ export * from './ip/index';
7
+ export * from './hash/crypto';
8
+ export * from './string/index';
9
+ export * from './objects/index';
10
+ export * from './locales/index';
11
+ export * from './timer/index';
12
+ export * from './date/index';
13
+ export * from './math/index';
14
+ export * from './regex/checkSpecialRegexControl';
15
+ export * from './filters/index';
16
+ export * from './locales/index';
@@ -0,0 +1,16 @@
1
+ export * from './tmp/index';
2
+ export * from './path/index';
3
+ export * from './is/index';
4
+ export * from './id/index';
5
+ export * from './validates/index';
6
+ export * from './ip/index';
7
+ export * from './hash/crypto';
8
+ export * from './string/index';
9
+ export * from './objects/index';
10
+ export * from './locales/index';
11
+ export * from './timer/index';
12
+ export * from './date/index';
13
+ export * from './math/index';
14
+ export * from './regex/checkSpecialRegexControl';
15
+ export * from './filters/index';
16
+ export * from './locales/index';
@@ -0,0 +1 @@
1
+ export declare const getClientIp: (req: any) => any;
@@ -0,0 +1,3 @@
1
+ export const getClientIp = (req) => {
2
+ return req.headers["x-forwarded-for"]?.split(",")[0] || req.socket.remoteAddress;
3
+ };
@@ -0,0 +1,11 @@
1
+ export declare function isFalsy(value: unknown, options: {
2
+ ignoreFalse?: boolean;
3
+ ignoreZero?: boolean;
4
+ ignoreEmptyString?: boolean;
5
+ ignoreNull?: boolean;
6
+ ignoreUndefined?: boolean;
7
+ ignoreNaN?: boolean;
8
+ }): boolean;
9
+ export declare function isType(data: any, type: any): boolean;
10
+ export declare function isInstance(data: any, type: any): boolean;
11
+ export declare function isBcryptHash(value: string): boolean;
@@ -0,0 +1,35 @@
1
+ export function isFalsy(value, options) {
2
+ if (!options.ignoreFalse && value === false)
3
+ return true;
4
+ if (!options.ignoreZero && value === 0)
5
+ return true;
6
+ if (!options.ignoreEmptyString && value === '')
7
+ return true;
8
+ if (!options.ignoreNull && value === null)
9
+ return true;
10
+ if (!options.ignoreUndefined && value === undefined)
11
+ return true;
12
+ if (!options.ignoreNaN && typeof value === 'number' && isNaN(value))
13
+ return true;
14
+ return false;
15
+ }
16
+ export function isType(data, type) {
17
+ if (typeof data === type) {
18
+ return true;
19
+ }
20
+ else {
21
+ return false;
22
+ }
23
+ }
24
+ export function isInstance(data, type) {
25
+ if (data instanceof type) {
26
+ return true;
27
+ }
28
+ else {
29
+ return false;
30
+ }
31
+ }
32
+ export function isBcryptHash(value) {
33
+ const bcryptRegex = /^\$2[aby]\$\d{2}\$.{53}$/;
34
+ return bcryptRegex.test(value);
35
+ }
@@ -0,0 +1,52 @@
1
+ export declare const responseMessageHelper: {
2
+ successFully: (process?: string, event?: string, t?: any) => string;
3
+ unsuccessful: (process?: string, event?: string, t?: any) => string;
4
+ notFound: (process?: string, event?: string, t?: any) => string;
5
+ notMatch: (process?: string, event?: string, t?: any) => string;
6
+ notUse: (process?: string, event?: string, t?: any) => string;
7
+ invalid: (process?: string, event?: string, t?: any) => string;
8
+ checked: (process?: string, event?: string, t?: any) => string;
9
+ process: (process?: string, event?: string, t?: any) => string;
10
+ missingData: (process?: string, event?: string, t?: any) => string;
11
+ allreadyHave: (process?: string, event?: string, t?: any) => string;
12
+ wrongFormat: (process?: string, event?: string, t?: any) => string;
13
+ externalApiError: (process?: string, event?: string, t?: any) => string;
14
+ unauthorizedUrl: (process?: string, event?: string, t?: any) => string;
15
+ endpointNotWorking: (endpoint?: string, t?: any) => string;
16
+ schemaMissingDataChecks: (t?: any) => string;
17
+ schemaInvalidDataChecks: (t?: any) => string;
18
+ schemaUnknowErrorChecks: (a: any, b: any, t?: any) => string;
19
+ schemaUnknowErrorLogic: (a: any, b: any, t?: any) => string;
20
+ schemaUnknowErrorResponse: (a: any, b: any, t?: any) => string;
21
+ schemaUnknowErrorMain: (a: any, b: any, t?: any) => string;
22
+ dbQueryError: (process?: string, event?: string, t?: any) => string;
23
+ unknowError: (process?: string, event?: string, t?: any) => string;
24
+ serverError: (process?: string, event?: string, t?: any) => string;
25
+ emailWelcomeTemplateTitle: (t?: any) => string;
26
+ emailWelcomeTemplateExplanation: (t?: any) => string;
27
+ emailForgotPasswordTemplateTitle: (t?: any) => string;
28
+ emailForgotPasswordTemplateExplanation: (t?: any) => string;
29
+ allRightsReserved: (extra1?: string, extra2?: string, t?: any) => string;
30
+ emailButtonText: (t?: any) => string;
31
+ emailIgnoreText: (t?: any) => string;
32
+ welcomeMessage: (username?: string, t?: any) => string;
33
+ userIsBlocked: (extra1?: string, t?: any) => string;
34
+ passwordChangeCode: (username?: string, t?: any) => string;
35
+ notEnoughWalletBalance: (money?: string, currency?: string, t?: any) => string;
36
+ openAuthConsumerOverhang: (param1?: string, param2?: string, t?: any) => string;
37
+ thirdPartySystemOverhang: (param1?: string, param2?: string, t?: any) => string;
38
+ deviceOverhang: (param1?: string, param2?: string, t?: any) => string;
39
+ provisionOverhang: (money?: string, currency?: string, t?: any) => string;
40
+ balanceOverhang: (money?: string, currency?: string, t?: any) => string;
41
+ debtOverhang: (money?: string, currency?: string, t?: any) => string;
42
+ shipmentNotAccepted: (value1?: string, value2?: string, t?: any) => string;
43
+ optionsMethod: (methods?: string, t?: any) => string;
44
+ notAllowedCORS: (methods?: string, t?: any) => string;
45
+ missingCRSFToken: (t?: any) => string;
46
+ invalidCRSFToken: (t?: any) => string;
47
+ tooManyRequest: (t?: any) => string;
48
+ endpointNotFound: (t?: any) => string;
49
+ roleAccess: (error?: string, t?: any) => string;
50
+ authenticationRequiredTokenExpired: (t?: any) => string;
51
+ authenticationRequired: (t?: any) => string;
52
+ };