@takentrade/takentrade-libs 3.0.0 → 3.1.0
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/README.md +1 -0
- package/dist/auth/auth.interface.d.ts +8 -0
- package/dist/auth/auth.interface.js +2 -0
- package/dist/auth/decorators/get-user.decorator.d.ts +2 -0
- package/dist/auth/decorators/get-user.decorator.js +26 -0
- package/dist/auth/decorators/index.d.ts +1 -0
- package/dist/auth/decorators/index.js +1 -0
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/metrics/metrics.interface.d.ts +0 -53
- package/dist/metrics/metrics.interface.js +0 -12
- package/dist/monitoring/alerting.service.d.ts +82 -0
- package/dist/monitoring/alerting.service.js +290 -0
- package/dist/monitoring/index.d.ts +5 -0
- package/dist/monitoring/index.js +21 -0
- package/dist/monitoring/monitoring.interface.d.ts +102 -0
- package/dist/monitoring/monitoring.interface.js +10 -0
- package/dist/monitoring/monitoring.module.d.ts +8 -0
- package/dist/monitoring/monitoring.module.js +44 -0
- package/dist/monitoring/sentry.service.d.ts +65 -0
- package/dist/monitoring/sentry.service.js +218 -0
- package/dist/monitoring/uptime.service.d.ts +59 -0
- package/dist/monitoring/uptime.service.js +213 -0
- package/dist/resilience/circuit-breaker.interface.d.ts +0 -75
- package/dist/resilience/circuit-breaker.interface.js +0 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/helpers/date.util.d.ts +8 -0
- package/dist/utils/helpers/date.util.js +30 -0
- package/dist/utils/helpers/decimal.util.d.ts +9 -0
- package/dist/utils/helpers/decimal.util.js +31 -0
- package/dist/utils/helpers/referral.util.d.ts +4 -0
- package/dist/utils/helpers/referral.util.js +53 -0
- package/dist/utils/helpers/role.util.d.ts +8 -0
- package/dist/utils/helpers/role.util.js +18 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +4 -0
- package/package.json +4 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isToday = exports.calculateNextDate = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Calculate next date based on frequency
|
|
6
|
+
*/
|
|
7
|
+
const calculateNextDate = (frequency, lastDate) => {
|
|
8
|
+
const nextDate = new Date(lastDate);
|
|
9
|
+
const frequencyMap = {
|
|
10
|
+
DAILY: () => nextDate.setDate(nextDate.getDate() + 1),
|
|
11
|
+
WEEKLY: () => nextDate.setDate(nextDate.getDate() + 7),
|
|
12
|
+
MONTHLY: () => nextDate.setMonth(nextDate.getMonth() + 1),
|
|
13
|
+
};
|
|
14
|
+
const calculateFn = frequencyMap[frequency];
|
|
15
|
+
if (!calculateFn)
|
|
16
|
+
throw new Error('Invalid frequency');
|
|
17
|
+
calculateFn();
|
|
18
|
+
return nextDate;
|
|
19
|
+
};
|
|
20
|
+
exports.calculateNextDate = calculateNextDate;
|
|
21
|
+
/**
|
|
22
|
+
* Check if a given date is today
|
|
23
|
+
*/
|
|
24
|
+
const isToday = (date) => {
|
|
25
|
+
const today = new Date();
|
|
26
|
+
return (date.getDate() === today.getDate() &&
|
|
27
|
+
date.getMonth() === today.getMonth() &&
|
|
28
|
+
date.getFullYear() === today.getFullYear());
|
|
29
|
+
};
|
|
30
|
+
exports.isToday = isToday;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Decimal from 'decimal.js';
|
|
2
|
+
/**
|
|
3
|
+
* Convert a value to Decimal
|
|
4
|
+
*/
|
|
5
|
+
export declare const toDecimal: (value: number | string | Decimal) => Decimal;
|
|
6
|
+
/**
|
|
7
|
+
* Convert Decimal to Prisma-compatible number
|
|
8
|
+
*/
|
|
9
|
+
export declare const toPrismaDecimal: (value: Decimal) => number;
|
|
@@ -0,0 +1,31 @@
|
|
|
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.toPrismaDecimal = exports.toDecimal = void 0;
|
|
7
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
|
+
const DEFAULT_DECIMAL_PLACES = 4;
|
|
9
|
+
decimal_js_1.default.set({ precision: 20, rounding: decimal_js_1.default.ROUND_HALF_UP });
|
|
10
|
+
/**
|
|
11
|
+
* Convert a value to Decimal
|
|
12
|
+
*/
|
|
13
|
+
const toDecimal = (value) => {
|
|
14
|
+
try {
|
|
15
|
+
return new decimal_js_1.default(value);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
throw new Error(`Invalid decimal value: ${value}`);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.toDecimal = toDecimal;
|
|
22
|
+
/**
|
|
23
|
+
* Convert Decimal to Prisma-compatible number
|
|
24
|
+
*/
|
|
25
|
+
const toPrismaDecimal = (value) => {
|
|
26
|
+
if (!decimal_js_1.default.isDecimal(value)) {
|
|
27
|
+
throw new Error('Value must be a Decimal instance');
|
|
28
|
+
}
|
|
29
|
+
return value.toDecimalPlaces(DEFAULT_DECIMAL_PLACES).toNumber();
|
|
30
|
+
};
|
|
31
|
+
exports.toPrismaDecimal = toPrismaDecimal;
|
|
@@ -0,0 +1,53 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.generateReferralCode = void 0;
|
|
37
|
+
const crypto = __importStar(require("crypto"));
|
|
38
|
+
/**
|
|
39
|
+
* Generate a unique referral code in format TNT-XXXX-XXXX
|
|
40
|
+
*/
|
|
41
|
+
const generateReferralCode = () => {
|
|
42
|
+
const chars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
|
|
43
|
+
const generateRandomPart = (length) => {
|
|
44
|
+
const randomBytes = crypto.randomBytes(length);
|
|
45
|
+
return Array.from(randomBytes)
|
|
46
|
+
.map((x) => chars[x % chars.length])
|
|
47
|
+
.join('');
|
|
48
|
+
};
|
|
49
|
+
const firstPart = generateRandomPart(4);
|
|
50
|
+
const secondPart = generateRandomPart(4);
|
|
51
|
+
return `TNT-${firstPart}-${secondPart}`;
|
|
52
|
+
};
|
|
53
|
+
exports.generateReferralCode = generateReferralCode;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBaseRole = exports.isAdminRole = void 0;
|
|
4
|
+
const BASE_ROLE = 'USER';
|
|
5
|
+
/**
|
|
6
|
+
* Check if role is an admin role
|
|
7
|
+
*/
|
|
8
|
+
const isAdminRole = (roleName) => {
|
|
9
|
+
return roleName !== BASE_ROLE;
|
|
10
|
+
};
|
|
11
|
+
exports.isAdminRole = isAdminRole;
|
|
12
|
+
/**
|
|
13
|
+
* Get base role
|
|
14
|
+
*/
|
|
15
|
+
const getBaseRole = () => {
|
|
16
|
+
return BASE_ROLE;
|
|
17
|
+
};
|
|
18
|
+
exports.getBaseRole = getBaseRole;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -14,6 +14,10 @@ export * from './utils';
|
|
|
14
14
|
export * from './interfaces';
|
|
15
15
|
export * from './dto';
|
|
16
16
|
export * from './enums';
|
|
17
|
+
export * from './helpers/decimal.util';
|
|
18
|
+
export * from './helpers/date.util';
|
|
19
|
+
export * from './helpers/role.util';
|
|
20
|
+
export * from './helpers/referral.util';
|
|
17
21
|
/**
|
|
18
22
|
* A set of shared utilities across the application.
|
|
19
23
|
*/
|
package/dist/utils/index.js
CHANGED
|
@@ -54,6 +54,10 @@ __exportStar(require("./utils"), exports);
|
|
|
54
54
|
__exportStar(require("./interfaces"), exports);
|
|
55
55
|
__exportStar(require("./dto"), exports);
|
|
56
56
|
__exportStar(require("./enums"), exports);
|
|
57
|
+
__exportStar(require("./helpers/decimal.util"), exports);
|
|
58
|
+
__exportStar(require("./helpers/date.util"), exports);
|
|
59
|
+
__exportStar(require("./helpers/role.util"), exports);
|
|
60
|
+
__exportStar(require("./helpers/referral.util"), exports);
|
|
57
61
|
/**
|
|
58
62
|
* A set of shared utilities across the application.
|
|
59
63
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takentrade/takentrade-libs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "TakeNTrade shared libraries",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -37,11 +37,14 @@
|
|
|
37
37
|
"@nestjs/microservices": "^11.1.9",
|
|
38
38
|
"@nestjs/passport": "^11.0.5",
|
|
39
39
|
"@nestjs/terminus": "^11.0.0",
|
|
40
|
+
"@sentry/node": "^10.27.0",
|
|
41
|
+
"@sentry/tracing": "^7.120.4",
|
|
40
42
|
"class-transformer": "^0.5.1",
|
|
41
43
|
"class-validator": "^0.14.3",
|
|
42
44
|
"cloudinary": "^2.8.0",
|
|
43
45
|
"cockatiel": "^3.2.1",
|
|
44
46
|
"country-codes-list": "^2.0.0",
|
|
47
|
+
"decimal.js": "^10.6.0",
|
|
45
48
|
"ioredis": "^5.8.2",
|
|
46
49
|
"joi": "^18.0.2",
|
|
47
50
|
"jsonwebtoken": "^9.0.2",
|