@takentrade/takentrade-libs 0.0.57

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 (164) hide show
  1. package/README.md +216 -0
  2. package/dist/bullmq/bullmq.module.d.ts +2 -0
  3. package/dist/bullmq/bullmq.module.js +16 -0
  4. package/dist/bullmq/bullmq.service.d.ts +2 -0
  5. package/dist/bullmq/bullmq.service.js +16 -0
  6. package/dist/bullmq/config/bull.config.d.ts +22 -0
  7. package/dist/bullmq/config/bull.config.js +28 -0
  8. package/dist/bullmq/index.d.ts +1 -0
  9. package/dist/bullmq/index.js +17 -0
  10. package/dist/cache/cache.interface.d.ts +2 -0
  11. package/dist/cache/cache.interface.js +2 -0
  12. package/dist/cache/cache.module.d.ts +5 -0
  13. package/dist/cache/cache.module.js +27 -0
  14. package/dist/cache/cache.service.d.ts +24 -0
  15. package/dist/cache/cache.service.js +91 -0
  16. package/dist/cache/index.d.ts +2 -0
  17. package/dist/cache/index.js +18 -0
  18. package/dist/common/circuit-breaker/circuit-breaker.module.d.ts +2 -0
  19. package/dist/common/circuit-breaker/circuit-breaker.module.js +20 -0
  20. package/dist/common/circuit-breaker/circuit-breaker.service.d.ts +13 -0
  21. package/dist/common/circuit-breaker/circuit-breaker.service.js +120 -0
  22. package/dist/common/circuit-breaker/circuit-breaker.types.d.ts +19 -0
  23. package/dist/common/circuit-breaker/circuit-breaker.types.js +9 -0
  24. package/dist/common/config/index.d.ts +1 -0
  25. package/dist/common/config/index.js +2 -0
  26. package/dist/common/config/nats.config.d.ts +9 -0
  27. package/dist/common/config/nats.config.js +12 -0
  28. package/dist/common/constants/index.d.ts +2 -0
  29. package/dist/common/constants/index.js +18 -0
  30. package/dist/common/constants/otp.constants.d.ts +15 -0
  31. package/dist/common/constants/otp.constants.js +18 -0
  32. package/dist/common/constants/queues.constants.d.ts +9 -0
  33. package/dist/common/constants/queues.constants.js +12 -0
  34. package/dist/common/dto/index.d.ts +3 -0
  35. package/dist/common/dto/index.js +19 -0
  36. package/dist/common/dto/payment/index.d.ts +1 -0
  37. package/dist/common/dto/payment/index.js +17 -0
  38. package/dist/common/dto/payment/withdrawal.dto.d.ts +19 -0
  39. package/dist/common/dto/payment/withdrawal.dto.js +97 -0
  40. package/dist/common/dto/support/create-message.dto.d.ts +4 -0
  41. package/dist/common/dto/support/create-message.dto.js +25 -0
  42. package/dist/common/dto/support/create-ticket.dto.d.ts +7 -0
  43. package/dist/common/dto/support/create-ticket.dto.js +43 -0
  44. package/dist/common/dto/support/index.d.ts +3 -0
  45. package/dist/common/dto/support/index.js +19 -0
  46. package/dist/common/dto/support/update-ticket.dto.d.ts +6 -0
  47. package/dist/common/dto/support/update-ticket.dto.js +41 -0
  48. package/dist/common/dto/users/index.d.ts +6 -0
  49. package/dist/common/dto/users/index.js +22 -0
  50. package/dist/common/dto/users/login.dto.d.ts +9 -0
  51. package/dist/common/dto/users/login.dto.js +40 -0
  52. package/dist/common/dto/users/passcode.dto.d.ts +12 -0
  53. package/dist/common/dto/users/passcode.dto.js +51 -0
  54. package/dist/common/dto/users/phone.dto.d.ts +4 -0
  55. package/dist/common/dto/users/phone.dto.js +26 -0
  56. package/dist/common/dto/users/register.dto.d.ts +8 -0
  57. package/dist/common/dto/users/register.dto.js +46 -0
  58. package/dist/common/dto/users/request-phone-verification.dto.d.ts +3 -0
  59. package/dist/common/dto/users/request-phone-verification.dto.js +20 -0
  60. package/dist/common/dto/users/verify-phone.dto.d.ts +3 -0
  61. package/dist/common/dto/users/verify-phone.dto.js +20 -0
  62. package/dist/common/enums/index.d.ts +2 -0
  63. package/dist/common/enums/index.js +18 -0
  64. package/dist/common/enums/support-action.enum.d.ts +7 -0
  65. package/dist/common/enums/support-action.enum.js +11 -0
  66. package/dist/common/enums/ticket.enum.d.ts +19 -0
  67. package/dist/common/enums/ticket.enum.js +25 -0
  68. package/dist/common/health/health.controller.d.ts +9 -0
  69. package/dist/common/health/health.controller.js +51 -0
  70. package/dist/common/health/health.module.d.ts +2 -0
  71. package/dist/common/health/health.module.js +22 -0
  72. package/dist/common/index.d.ts +6 -0
  73. package/dist/common/index.js +23 -0
  74. package/dist/common/utils/index.d.ts +3 -0
  75. package/dist/common/utils/index.js +19 -0
  76. package/dist/common/utils/random.utils.d.ts +10 -0
  77. package/dist/common/utils/random.utils.js +27 -0
  78. package/dist/common/utils/reference.utils.d.ts +1 -0
  79. package/dist/common/utils/reference.utils.js +17 -0
  80. package/dist/common/utils/string.utils.d.ts +2 -0
  81. package/dist/common/utils/string.utils.js +17 -0
  82. package/dist/index.d.ts +8 -0
  83. package/dist/index.js +24 -0
  84. package/dist/logger/fake/FakeLogger.service.d.ts +13 -0
  85. package/dist/logger/fake/FakeLogger.service.js +21 -0
  86. package/dist/logger/index.d.ts +2 -0
  87. package/dist/logger/index.js +18 -0
  88. package/dist/logger/logger.module.d.ts +7 -0
  89. package/dist/logger/logger.module.js +69 -0
  90. package/dist/logger/real/pinoLogger.service.d.ts +14 -0
  91. package/dist/logger/real/pinoLogger.service.js +76 -0
  92. package/dist/nats/constants/nats.constants.d.ts +9 -0
  93. package/dist/nats/constants/nats.constants.js +12 -0
  94. package/dist/nats/decorators/nats-event-pattern.decorator.d.ts +2 -0
  95. package/dist/nats/decorators/nats-event-pattern.decorator.js +11 -0
  96. package/dist/nats/dto/nats-message.dto.d.ts +5 -0
  97. package/dist/nats/dto/nats-message.dto.js +27 -0
  98. package/dist/nats/index.d.ts +5 -0
  99. package/dist/nats/index.js +21 -0
  100. package/dist/nats/interceptors/nats-logging.interceptor.d.ts +6 -0
  101. package/dist/nats/interceptors/nats-logging.interceptor.js +33 -0
  102. package/dist/nats/interfaces/nats-options.interface.d.ts +23 -0
  103. package/dist/nats/interfaces/nats-options.interface.js +2 -0
  104. package/dist/prisma/index.d.ts +2 -0
  105. package/dist/prisma/index.js +18 -0
  106. package/dist/prisma/prisma.module.d.ts +2 -0
  107. package/dist/prisma/prisma.module.js +21 -0
  108. package/dist/prisma/prisma.service.d.ts +6 -0
  109. package/dist/prisma/prisma.service.js +25 -0
  110. package/dist/rpc/index.d.ts +50 -0
  111. package/dist/rpc/index.js +131 -0
  112. package/dist/utils/dto/index.d.ts +4 -0
  113. package/dist/utils/dto/index.js +31 -0
  114. package/dist/utils/filters/http-exception.filter.d.ts +6 -0
  115. package/dist/utils/filters/http-exception.filter.js +56 -0
  116. package/dist/utils/filters/index.d.ts +1 -0
  117. package/dist/utils/filters/index.js +17 -0
  118. package/dist/utils/index.d.ts +26 -0
  119. package/dist/utils/index.js +66 -0
  120. package/dist/utils/interceptors/index.d.ts +2 -0
  121. package/dist/utils/interceptors/index.js +18 -0
  122. package/dist/utils/interceptors/pagination.interceptor.d.ts +19 -0
  123. package/dist/utils/interceptors/pagination.interceptor.js +49 -0
  124. package/dist/utils/interceptors/response.interceptor.d.ts +15 -0
  125. package/dist/utils/interceptors/response.interceptor.js +86 -0
  126. package/dist/utils/interfaces/config.interface.d.ts +39 -0
  127. package/dist/utils/interfaces/config.interface.js +2 -0
  128. package/dist/utils/interfaces/general.interface.d.ts +13 -0
  129. package/dist/utils/interfaces/general.interface.js +2 -0
  130. package/dist/utils/interfaces/index.d.ts +6 -0
  131. package/dist/utils/interfaces/index.js +22 -0
  132. package/dist/utils/interfaces/interceptor.interface.d.ts +15 -0
  133. package/dist/utils/interfaces/interceptor.interface.js +2 -0
  134. package/dist/utils/interfaces/multer-file.interface.d.ts +8 -0
  135. package/dist/utils/interfaces/multer-file.interface.js +2 -0
  136. package/dist/utils/interfaces/pagination.interface.d.ts +17 -0
  137. package/dist/utils/interfaces/pagination.interface.js +2 -0
  138. package/dist/utils/interfaces/response.interface.d.ts +21 -0
  139. package/dist/utils/interfaces/response.interface.js +9 -0
  140. package/dist/utils/pipes/file.pipe.d.ts +6 -0
  141. package/dist/utils/pipes/file.pipe.js +44 -0
  142. package/dist/utils/pipes/index.d.ts +3 -0
  143. package/dist/utils/pipes/index.js +19 -0
  144. package/dist/utils/pipes/pagination.pipe.d.ts +7 -0
  145. package/dist/utils/pipes/pagination.pipe.js +24 -0
  146. package/dist/utils/pipes/validation.pipe.d.ts +4 -0
  147. package/dist/utils/pipes/validation.pipe.js +24 -0
  148. package/dist/utils/utils/configuration.d.ts +3 -0
  149. package/dist/utils/utils/configuration.js +87 -0
  150. package/dist/utils/utils/country.utils.d.ts +4 -0
  151. package/dist/utils/utils/country.utils.js +41 -0
  152. package/dist/utils/utils/index.d.ts +5 -0
  153. package/dist/utils/utils/index.js +21 -0
  154. package/dist/utils/utils/otp.d.ts +1 -0
  155. package/dist/utils/utils/otp.js +102 -0
  156. package/dist/utils/utils/response.utils.d.ts +15 -0
  157. package/dist/utils/utils/response.utils.js +39 -0
  158. package/dist/utils/utils/utils.d.ts +4 -0
  159. package/dist/utils/utils/utils.js +40 -0
  160. package/dist/utils/validators/index.d.ts +1 -0
  161. package/dist/utils/validators/index.js +17 -0
  162. package/dist/utils/validators/nats.validator.d.ts +7 -0
  163. package/dist/utils/validators/nats.validator.js +47 -0
  164. package/package.json +65 -0
@@ -0,0 +1,87 @@
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.config = void 0;
37
+ const Joi = __importStar(require("joi"));
38
+ exports.config = Joi.object({
39
+ // Environment
40
+ PORT: Joi.number().default(3000),
41
+ HOST: Joi.string().default('localhost'),
42
+ // Database
43
+ DATABASE_URL: Joi.string().uri().required(),
44
+ // JWT
45
+ JWT_ACCESS_TOKEN_SECRET: Joi.string().required(),
46
+ JWT_ACCESS_TOKEN_EXPIRES_IN: Joi.string().default('90d'),
47
+ JWT_REFRESH_TOKEN_SECRET: Joi.string().required(),
48
+ JWT_REFRESH_TOKEN_EXPIRES_IN: Joi.string().default('30d'),
49
+ // Redis
50
+ REDIS_URL: Joi.string().uri().required(),
51
+ CACHE_TTL: Joi.number().default(60),
52
+ CACHE_MAX_ITEMS: Joi.number().default(100),
53
+ // Mail Settings
54
+ MAIL_HOST: Joi.string().required(),
55
+ MAIL_USER: Joi.string().required(),
56
+ MAIL_PASS: Joi.string().required(),
57
+ // Providus Bank
58
+ PROVIDUS_BASE_URL: Joi.string().uri().required(),
59
+ PROVIDUS_SECRET_KEY: Joi.string().required(),
60
+ PROVIDUS_PUBLIC_KEY: Joi.string().required(),
61
+ // VTpass
62
+ VTPASS_BASE_URL: Joi.string().uri().required(),
63
+ VTPASS_API_KEY: Joi.string().required(),
64
+ VTPASS_PUBLIC_KEY: Joi.string().required(),
65
+ VTPASS_SECRET_KEY: Joi.string().required(),
66
+ // CreditSwitch
67
+ CREDITSWITCH_BASE_URL: Joi.string().uri().required(),
68
+ CREDITSWITCH_CLIENT_ID: Joi.string().required(),
69
+ CREDITSWITCH_CLIENT_SECRET: Joi.string().required(),
70
+ CREDITSWITCH_USERNAME: Joi.string().required(),
71
+ CREDITSWITCH_PASSWORD: Joi.string().required(),
72
+ // Reloadly
73
+ RELOADLY_BASE_URL: Joi.string().uri().required(),
74
+ RELOADLY_CLIENT_ID: Joi.string().required(),
75
+ RELOADLY_CLIENT_SECRET: Joi.string().required(),
76
+ RELOADLY_AUDIENCE: Joi.string().uri().required(),
77
+ RELOADLY_SANDBOX: Joi.boolean().default(true),
78
+ // Cloudinary
79
+ CLOUDINARY_CLOUD_NAME: Joi.string().required(),
80
+ CLOUDINARY_API_KEY: Joi.string().required(),
81
+ CLOUDINARY_API_SECRET: Joi.string().required(),
82
+ // Others
83
+ NATS_URL: Joi.string().uri().default('nats://localhost:4222'),
84
+ CORS_ORIGIN: Joi.string().default('*'),
85
+ EXPO_ACCESS_TOKEN: Joi.string().required(),
86
+ AFRICASTALKING_API_KEY: Joi.string().required(),
87
+ });
@@ -0,0 +1,4 @@
1
+ /**
2
+ * An array of country dial codes
3
+ */
4
+ export declare const CountryDialCodes: string[];
@@ -0,0 +1,41 @@
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.CountryDialCodes = void 0;
37
+ const CountryCodeList = __importStar(require("country-codes-list"));
38
+ /**
39
+ * An array of country dial codes
40
+ */
41
+ exports.CountryDialCodes = Object.keys(CountryCodeList.customList('countryCallingCode')).map((code) => `+${code}`);
@@ -0,0 +1,5 @@
1
+ export * from './otp';
2
+ export * from './response.utils';
3
+ export * from './country.utils';
4
+ export * from './utils';
5
+ export * from './configuration';
@@ -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("./otp"), exports);
18
+ __exportStar(require("./response.utils"), exports);
19
+ __exportStar(require("./country.utils"), exports);
20
+ __exportStar(require("./utils"), exports);
21
+ __exportStar(require("./configuration"), exports);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ // import { Schema, model, Document } from 'mongoose';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ // export interface IOTP extends Document {
5
+ // key: string;
6
+ // otp: string;
7
+ // action: string;
8
+ // user_agent: string;
9
+ // ip_address: string;
10
+ // verify: boolean;
11
+ // created_date: Date;
12
+ // }
13
+ // const OTPSchema = new Schema<IOTP>({
14
+ // key: { type: String, required: true },
15
+ // otp: { type: String, required: true },
16
+ // action: { type: String, required: true },
17
+ // user_agent: { type: String },
18
+ // ip_address: { type: String },
19
+ // verify: { type: Boolean, default: false },
20
+ // created_date: { type: Date, default: Date.now },
21
+ // });
22
+ // const OTPManager = model<IOTP>('OTPManager', OTPSchema);
23
+ // export default OTPManager;
24
+ // import * as base64 from 'base64-js';
25
+ // import { decrypt, encrypt } from './utils';
26
+ // function generateKey(key: string): string {
27
+ // const keyString: string = key + process.env.SECRETKEY;
28
+ // const encodedKey: string = base64.fromByteArray(
29
+ // Buffer.from(keyString, 'utf-8'),
30
+ // );
31
+ // return encodedKey;
32
+ // }
33
+ // async function generateOTP(
34
+ // credential: string,
35
+ // action: string,
36
+ // ip_address: string,
37
+ // user_agent: string,
38
+ // ): Promise<{ otp: string | null; countdown: number }> {
39
+ // const key: string = generateKey(
40
+ // credential + ip_address + user_agent + action,
41
+ // );
42
+ // try {
43
+ // const existingOTP = await OTPManager.findOne({
44
+ // key,
45
+ // created_date: { $gte: new Date(Date.now() - 30 * 1000) },
46
+ // });
47
+ // if (existingOTP) {
48
+ // const countdown = Math.round(
49
+ // (existingOTP.created_date.getTime() + 30 * 1000 - Date.now()) / 1000,
50
+ // );
51
+ // return { otp: null, countdown };
52
+ // }
53
+ // const otpCode: string = Math.random().toString().slice(2, 8);
54
+ // await OTPManager.deleteMany({ key });
55
+ // await OTPManager.create({
56
+ // key,
57
+ // otp: encrypt(otpCode, ''),
58
+ // action,
59
+ // ip_address,
60
+ // user_agent,
61
+ // });
62
+ // return { otp: otpCode, countdown: 0 };
63
+ // } catch (error) {
64
+ // console.error('Error generating OTP:', error);
65
+ // return { otp: null, countdown: 0 };
66
+ // }
67
+ // }
68
+ // async function verifyOTP(
69
+ // otp: string,
70
+ // credential: string,
71
+ // user_agent: string,
72
+ // ip_address: string,
73
+ // action: string,
74
+ // ): Promise<{ isVerify: boolean; message: string }> {
75
+ // const key: string = generateKey(
76
+ // credential + ip_address + user_agent + action,
77
+ // );
78
+ // try {
79
+ // const otpModel: IOTP | null = await OTPManager.findOne({ key });
80
+ // if (!otpModel) {
81
+ // return { isVerify: false, message: 'INVALID_OTP' };
82
+ // }
83
+ // const expireTime: Date = new Date(
84
+ // otpModel.created_date.getTime() + 5 * 60 * 1000,
85
+ // ); // Adding 5 minutes to the created date
86
+ // const currentTime: Date = new Date();
87
+ // if (expireTime < currentTime) {
88
+ // await OTPManager.deleteMany({ key });
89
+ // return { isVerify: false, message: 'INVALID_OR_EXPIRED_OTP' };
90
+ // }
91
+ // if (otp === decrypt(otpModel.otp, '')) {
92
+ // await OTPManager.deleteMany({ key });
93
+ // return { isVerify: true, message: 'OTP_VERIFIED' };
94
+ // } else {
95
+ // return { isVerify: false, message: 'INVALID_OTP' };
96
+ // }
97
+ // } catch (error) {
98
+ // console.log(` verify error error ` + error);
99
+ // return { isVerify: false, message: 'ERROR_OCCURED' };
100
+ // }
101
+ // }
102
+ // export { generateOTP, verifyOTP };
@@ -0,0 +1,15 @@
1
+ import { IAppResponse, ResponseStatus, IResponseMetadata } from '../interfaces';
2
+ export declare class AppResponse<T = any> implements IAppResponse<T> {
3
+ status: ResponseStatus;
4
+ message: string;
5
+ data: T;
6
+ timestamp?: string;
7
+ path?: string;
8
+ requestId?: string;
9
+ version?: string;
10
+ executionTime?: number;
11
+ constructor(status: ResponseStatus, message: string, data: T, metadata?: Partial<IResponseMetadata>);
12
+ static success<T>(message: string, data: T, metadata?: Partial<IResponseMetadata>): AppResponse<T>;
13
+ static error<T = null>(message: string, data?: T | null, metadata?: Partial<IResponseMetadata>): AppResponse<T | null>;
14
+ static warning<T = null>(message: string, data?: T | null, metadata?: Partial<IResponseMetadata>): AppResponse<T | null>;
15
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppResponse = void 0;
4
+ const interfaces_1 = require("../interfaces");
5
+ class AppResponse {
6
+ status;
7
+ message;
8
+ data;
9
+ timestamp;
10
+ path;
11
+ requestId;
12
+ version;
13
+ executionTime;
14
+ constructor(status, message, data, metadata) {
15
+ this.status = status;
16
+ this.message = message;
17
+ this.data = data;
18
+ if (metadata?.timestamp)
19
+ this.timestamp = metadata.timestamp;
20
+ if (metadata?.path)
21
+ this.path = metadata.path;
22
+ if (metadata?.requestId)
23
+ this.requestId = metadata.requestId;
24
+ if (metadata?.version)
25
+ this.version = metadata.version;
26
+ if (metadata?.executionTime)
27
+ this.executionTime = metadata.executionTime;
28
+ }
29
+ static success(message, data, metadata) {
30
+ return new AppResponse(interfaces_1.ResponseStatus.SUCCESS, message, data, metadata);
31
+ }
32
+ static error(message, data = null, metadata) {
33
+ return new AppResponse(interfaces_1.ResponseStatus.ERROR, message, data, metadata);
34
+ }
35
+ static warning(message, data = null, metadata) {
36
+ return new AppResponse(interfaces_1.ResponseStatus.WARNING, message, data, metadata);
37
+ }
38
+ }
39
+ exports.AppResponse = AppResponse;
@@ -0,0 +1,4 @@
1
+ export declare const getPhoneCode: (phoneNumber: string, countryCode: string) => string;
2
+ export declare const encrypt: (text: string, key: string) => string;
3
+ export declare const decrypt: (text: string, key: string) => string;
4
+ export declare const phoneValidation: (S: any) => any;
@@ -0,0 +1,40 @@
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.phoneValidation = exports.decrypt = exports.encrypt = exports.getPhoneCode = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ const getPhoneCode = (phoneNumber, countryCode) => {
9
+ const normalizedNumber = phoneNumber.startsWith('0')
10
+ ? phoneNumber.slice(1)
11
+ : phoneNumber;
12
+ return countryCode + normalizedNumber;
13
+ };
14
+ exports.getPhoneCode = getPhoneCode;
15
+ // Encrypt
16
+ const encrypt = (text, key) => {
17
+ const iv = crypto_1.default.randomBytes(16);
18
+ const cipher = crypto_1.default.createCipheriv('aes-256-cbc', Buffer.from(key), iv);
19
+ let encrypted = cipher.update(text);
20
+ encrypted = Buffer.concat([encrypted, cipher.final()]);
21
+ return `${iv.toString('hex')}:${encrypted.toString('hex')}`;
22
+ };
23
+ exports.encrypt = encrypt;
24
+ // Decryption
25
+ const decrypt = (text, key) => {
26
+ const textParts = text.split(':');
27
+ const iv = Buffer.from(textParts.shift(), 'hex');
28
+ const encryptedText = Buffer.from(textParts.join(':'), 'hex');
29
+ const decipher = crypto_1.default.createDecipheriv('aes-256-cbc', Buffer.from(key), iv);
30
+ let decrypted = decipher.update(encryptedText);
31
+ decrypted = Buffer.concat([decrypted, decipher.final()]);
32
+ return decrypted.toString();
33
+ };
34
+ exports.decrypt = decrypt;
35
+ const phoneValidation = (S) => {
36
+ return S.string()
37
+ .pattern(/^234[7-9]{1}([0|1]{1})([0-9]{8})$/)
38
+ .required();
39
+ };
40
+ exports.phoneValidation = phoneValidation;
@@ -0,0 +1 @@
1
+ export * from './nats.validator';
@@ -0,0 +1,17 @@
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("./nats.validator"), exports);
@@ -0,0 +1,7 @@
1
+ import { PipeTransform, ArgumentMetadata } from '@nestjs/common';
2
+ import { ClassConstructor } from 'class-transformer';
3
+ export declare const validateNatsMessage: (dto: ClassConstructor<object>, data: unknown) => Promise<object>;
4
+ export declare class ValidateNatsMessagePipe implements PipeTransform {
5
+ transform(value: any, metadata: ArgumentMetadata): Promise<any>;
6
+ private toValidate;
7
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.ValidateNatsMessagePipe = exports.validateNatsMessage = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const class_validator_1 = require("class-validator");
12
+ const class_transformer_1 = require("class-transformer");
13
+ const microservices_1 = require("@nestjs/microservices");
14
+ const validateNatsMessage = async (dto, data) => {
15
+ const instance = (0, class_transformer_1.plainToInstance)(dto, data);
16
+ const errors = await (0, class_validator_1.validate)(instance);
17
+ if (errors.length > 0) {
18
+ console.error('Validation errors:', errors);
19
+ throw new microservices_1.RpcException(new common_1.BadRequestException(errors));
20
+ }
21
+ return instance;
22
+ };
23
+ exports.validateNatsMessage = validateNatsMessage;
24
+ let ValidateNatsMessagePipe = class ValidateNatsMessagePipe {
25
+ async transform(value, metadata) {
26
+ const { metatype } = metadata;
27
+ if (!metatype || !this.toValidate(metatype)) {
28
+ return value;
29
+ }
30
+ const object = (0, class_transformer_1.plainToInstance)(metatype, value);
31
+ const errors = await (0, class_validator_1.validate)(object);
32
+ if (errors.length > 0) {
33
+ throw new microservices_1.RpcException(new common_1.BadRequestException(errors
34
+ .map((err) => Object.values(err.constraints))
35
+ .join(', ')));
36
+ }
37
+ return object;
38
+ }
39
+ toValidate(metatype) {
40
+ const types = [String, Boolean, Number, Array, Object];
41
+ return !types.includes(metatype);
42
+ }
43
+ };
44
+ exports.ValidateNatsMessagePipe = ValidateNatsMessagePipe;
45
+ exports.ValidateNatsMessagePipe = ValidateNatsMessagePipe = __decorate([
46
+ (0, common_1.Injectable)()
47
+ ], ValidateNatsMessagePipe);
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@takentrade/takentrade-libs",
3
+ "version": "0.0.57",
4
+ "description": "TakeNTrade shared libraries",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist/"
10
+ ],
11
+ "scripts": {
12
+ "test": "echo \"Error: no test specified\" && exit 1",
13
+ "build": "rm -rf dist && tsc",
14
+ "prettier": "prettier --write .",
15
+ "prettier:check": "prettier --check ."
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/TakeNTrade/takentrade-libs.git"
20
+ },
21
+ "keywords": [
22
+ "takentrade",
23
+ "takentrade-libs",
24
+ "libs"
25
+ ],
26
+ "author": "TakeNTrade",
27
+ "license": "MIT",
28
+ "dependencies": {
29
+ "@nestjs/axios": "^4.0.1",
30
+ "@nestjs/bullmq": "^11.0.2",
31
+ "@nestjs/common": "^11.1.5",
32
+ "@nestjs/config": "^4.0.2",
33
+ "@nestjs/jwt": "^11.0.0",
34
+ "@nestjs/microservices": "^11.1.5",
35
+ "@nestjs/swagger": "^11.2.0",
36
+ "@nestjs/terminus": "^11.0.0",
37
+ "@prisma/client": "^6.12.0",
38
+ "class-transformer": "^0.5.1",
39
+ "class-validator": "^0.14.2",
40
+ "country-codes-list": "^2.0.0",
41
+ "ioredis": "^5.6.1",
42
+ "joi": "^17.13.3",
43
+ "jsonwebtoken": "^9.0.2",
44
+ "nestjs-pino": "^4.4.0",
45
+ "object-hash": "^3.0.0",
46
+ "pino": "^9.7.0",
47
+ "rxjs": "^7.8.2",
48
+ "tsup": "^8.5.0",
49
+ "typescript": "^5.8.3",
50
+ "uuid": "^11.1.0"
51
+ },
52
+ "devDependencies": {
53
+ "@types/node": "^24.0.15",
54
+ "@types/object-hash": "^3.0.6",
55
+ "prettier": "^3.6.2"
56
+ },
57
+ "exports": {
58
+ ".": "./dist/index.js",
59
+ "./auth": "./dist/auth/index.js",
60
+ "./bullmq": "./dist/bullmq/index.js",
61
+ "./cache": "./dist/cache/index.js",
62
+ "./common": "./dist/common/index.js",
63
+ "./nats": "./dist/nats/index.js"
64
+ }
65
+ }