@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.
- package/README.md +216 -0
- package/dist/bullmq/bullmq.module.d.ts +2 -0
- package/dist/bullmq/bullmq.module.js +16 -0
- package/dist/bullmq/bullmq.service.d.ts +2 -0
- package/dist/bullmq/bullmq.service.js +16 -0
- package/dist/bullmq/config/bull.config.d.ts +22 -0
- package/dist/bullmq/config/bull.config.js +28 -0
- package/dist/bullmq/index.d.ts +1 -0
- package/dist/bullmq/index.js +17 -0
- package/dist/cache/cache.interface.d.ts +2 -0
- package/dist/cache/cache.interface.js +2 -0
- package/dist/cache/cache.module.d.ts +5 -0
- package/dist/cache/cache.module.js +27 -0
- package/dist/cache/cache.service.d.ts +24 -0
- package/dist/cache/cache.service.js +91 -0
- package/dist/cache/index.d.ts +2 -0
- package/dist/cache/index.js +18 -0
- package/dist/common/circuit-breaker/circuit-breaker.module.d.ts +2 -0
- package/dist/common/circuit-breaker/circuit-breaker.module.js +20 -0
- package/dist/common/circuit-breaker/circuit-breaker.service.d.ts +13 -0
- package/dist/common/circuit-breaker/circuit-breaker.service.js +120 -0
- package/dist/common/circuit-breaker/circuit-breaker.types.d.ts +19 -0
- package/dist/common/circuit-breaker/circuit-breaker.types.js +9 -0
- package/dist/common/config/index.d.ts +1 -0
- package/dist/common/config/index.js +2 -0
- package/dist/common/config/nats.config.d.ts +9 -0
- package/dist/common/config/nats.config.js +12 -0
- package/dist/common/constants/index.d.ts +2 -0
- package/dist/common/constants/index.js +18 -0
- package/dist/common/constants/otp.constants.d.ts +15 -0
- package/dist/common/constants/otp.constants.js +18 -0
- package/dist/common/constants/queues.constants.d.ts +9 -0
- package/dist/common/constants/queues.constants.js +12 -0
- package/dist/common/dto/index.d.ts +3 -0
- package/dist/common/dto/index.js +19 -0
- package/dist/common/dto/payment/index.d.ts +1 -0
- package/dist/common/dto/payment/index.js +17 -0
- package/dist/common/dto/payment/withdrawal.dto.d.ts +19 -0
- package/dist/common/dto/payment/withdrawal.dto.js +97 -0
- package/dist/common/dto/support/create-message.dto.d.ts +4 -0
- package/dist/common/dto/support/create-message.dto.js +25 -0
- package/dist/common/dto/support/create-ticket.dto.d.ts +7 -0
- package/dist/common/dto/support/create-ticket.dto.js +43 -0
- package/dist/common/dto/support/index.d.ts +3 -0
- package/dist/common/dto/support/index.js +19 -0
- package/dist/common/dto/support/update-ticket.dto.d.ts +6 -0
- package/dist/common/dto/support/update-ticket.dto.js +41 -0
- package/dist/common/dto/users/index.d.ts +6 -0
- package/dist/common/dto/users/index.js +22 -0
- package/dist/common/dto/users/login.dto.d.ts +9 -0
- package/dist/common/dto/users/login.dto.js +40 -0
- package/dist/common/dto/users/passcode.dto.d.ts +12 -0
- package/dist/common/dto/users/passcode.dto.js +51 -0
- package/dist/common/dto/users/phone.dto.d.ts +4 -0
- package/dist/common/dto/users/phone.dto.js +26 -0
- package/dist/common/dto/users/register.dto.d.ts +8 -0
- package/dist/common/dto/users/register.dto.js +46 -0
- package/dist/common/dto/users/request-phone-verification.dto.d.ts +3 -0
- package/dist/common/dto/users/request-phone-verification.dto.js +20 -0
- package/dist/common/dto/users/verify-phone.dto.d.ts +3 -0
- package/dist/common/dto/users/verify-phone.dto.js +20 -0
- package/dist/common/enums/index.d.ts +2 -0
- package/dist/common/enums/index.js +18 -0
- package/dist/common/enums/support-action.enum.d.ts +7 -0
- package/dist/common/enums/support-action.enum.js +11 -0
- package/dist/common/enums/ticket.enum.d.ts +19 -0
- package/dist/common/enums/ticket.enum.js +25 -0
- package/dist/common/health/health.controller.d.ts +9 -0
- package/dist/common/health/health.controller.js +51 -0
- package/dist/common/health/health.module.d.ts +2 -0
- package/dist/common/health/health.module.js +22 -0
- package/dist/common/index.d.ts +6 -0
- package/dist/common/index.js +23 -0
- package/dist/common/utils/index.d.ts +3 -0
- package/dist/common/utils/index.js +19 -0
- package/dist/common/utils/random.utils.d.ts +10 -0
- package/dist/common/utils/random.utils.js +27 -0
- package/dist/common/utils/reference.utils.d.ts +1 -0
- package/dist/common/utils/reference.utils.js +17 -0
- package/dist/common/utils/string.utils.d.ts +2 -0
- package/dist/common/utils/string.utils.js +17 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +24 -0
- package/dist/logger/fake/FakeLogger.service.d.ts +13 -0
- package/dist/logger/fake/FakeLogger.service.js +21 -0
- package/dist/logger/index.d.ts +2 -0
- package/dist/logger/index.js +18 -0
- package/dist/logger/logger.module.d.ts +7 -0
- package/dist/logger/logger.module.js +69 -0
- package/dist/logger/real/pinoLogger.service.d.ts +14 -0
- package/dist/logger/real/pinoLogger.service.js +76 -0
- package/dist/nats/constants/nats.constants.d.ts +9 -0
- package/dist/nats/constants/nats.constants.js +12 -0
- package/dist/nats/decorators/nats-event-pattern.decorator.d.ts +2 -0
- package/dist/nats/decorators/nats-event-pattern.decorator.js +11 -0
- package/dist/nats/dto/nats-message.dto.d.ts +5 -0
- package/dist/nats/dto/nats-message.dto.js +27 -0
- package/dist/nats/index.d.ts +5 -0
- package/dist/nats/index.js +21 -0
- package/dist/nats/interceptors/nats-logging.interceptor.d.ts +6 -0
- package/dist/nats/interceptors/nats-logging.interceptor.js +33 -0
- package/dist/nats/interfaces/nats-options.interface.d.ts +23 -0
- package/dist/nats/interfaces/nats-options.interface.js +2 -0
- package/dist/prisma/index.d.ts +2 -0
- package/dist/prisma/index.js +18 -0
- package/dist/prisma/prisma.module.d.ts +2 -0
- package/dist/prisma/prisma.module.js +21 -0
- package/dist/prisma/prisma.service.d.ts +6 -0
- package/dist/prisma/prisma.service.js +25 -0
- package/dist/rpc/index.d.ts +50 -0
- package/dist/rpc/index.js +131 -0
- package/dist/utils/dto/index.d.ts +4 -0
- package/dist/utils/dto/index.js +31 -0
- package/dist/utils/filters/http-exception.filter.d.ts +6 -0
- package/dist/utils/filters/http-exception.filter.js +56 -0
- package/dist/utils/filters/index.d.ts +1 -0
- package/dist/utils/filters/index.js +17 -0
- package/dist/utils/index.d.ts +26 -0
- package/dist/utils/index.js +66 -0
- package/dist/utils/interceptors/index.d.ts +2 -0
- package/dist/utils/interceptors/index.js +18 -0
- package/dist/utils/interceptors/pagination.interceptor.d.ts +19 -0
- package/dist/utils/interceptors/pagination.interceptor.js +49 -0
- package/dist/utils/interceptors/response.interceptor.d.ts +15 -0
- package/dist/utils/interceptors/response.interceptor.js +86 -0
- package/dist/utils/interfaces/config.interface.d.ts +39 -0
- package/dist/utils/interfaces/config.interface.js +2 -0
- package/dist/utils/interfaces/general.interface.d.ts +13 -0
- package/dist/utils/interfaces/general.interface.js +2 -0
- package/dist/utils/interfaces/index.d.ts +6 -0
- package/dist/utils/interfaces/index.js +22 -0
- package/dist/utils/interfaces/interceptor.interface.d.ts +15 -0
- package/dist/utils/interfaces/interceptor.interface.js +2 -0
- package/dist/utils/interfaces/multer-file.interface.d.ts +8 -0
- package/dist/utils/interfaces/multer-file.interface.js +2 -0
- package/dist/utils/interfaces/pagination.interface.d.ts +17 -0
- package/dist/utils/interfaces/pagination.interface.js +2 -0
- package/dist/utils/interfaces/response.interface.d.ts +21 -0
- package/dist/utils/interfaces/response.interface.js +9 -0
- package/dist/utils/pipes/file.pipe.d.ts +6 -0
- package/dist/utils/pipes/file.pipe.js +44 -0
- package/dist/utils/pipes/index.d.ts +3 -0
- package/dist/utils/pipes/index.js +19 -0
- package/dist/utils/pipes/pagination.pipe.d.ts +7 -0
- package/dist/utils/pipes/pagination.pipe.js +24 -0
- package/dist/utils/pipes/validation.pipe.d.ts +4 -0
- package/dist/utils/pipes/validation.pipe.js +24 -0
- package/dist/utils/utils/configuration.d.ts +3 -0
- package/dist/utils/utils/configuration.js +87 -0
- package/dist/utils/utils/country.utils.d.ts +4 -0
- package/dist/utils/utils/country.utils.js +41 -0
- package/dist/utils/utils/index.d.ts +5 -0
- package/dist/utils/utils/index.js +21 -0
- package/dist/utils/utils/otp.d.ts +1 -0
- package/dist/utils/utils/otp.js +102 -0
- package/dist/utils/utils/response.utils.d.ts +15 -0
- package/dist/utils/utils/response.utils.js +39 -0
- package/dist/utils/utils/utils.d.ts +4 -0
- package/dist/utils/utils/utils.js +40 -0
- package/dist/utils/validators/index.d.ts +1 -0
- package/dist/utils/validators/index.js +17 -0
- package/dist/utils/validators/nats.validator.d.ts +7 -0
- package/dist/utils/validators/nats.validator.js +47 -0
- package/package.json +65 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as validators from './validators';
|
|
2
|
+
import * as filters from './filters';
|
|
3
|
+
import * as interceptors from './interceptors';
|
|
4
|
+
import * as interfaces from './interfaces';
|
|
5
|
+
import * as pipes from './pipes';
|
|
6
|
+
import * as utils from './utils';
|
|
7
|
+
export * as dto from './dto';
|
|
8
|
+
export * as interfaces from './interfaces';
|
|
9
|
+
export * from './validators';
|
|
10
|
+
export * from './filters';
|
|
11
|
+
export * from './interceptors';
|
|
12
|
+
export * from './pipes';
|
|
13
|
+
export * from './utils';
|
|
14
|
+
export * from './interfaces';
|
|
15
|
+
export * from './dto';
|
|
16
|
+
/**
|
|
17
|
+
* A set of shared utilities across the application.
|
|
18
|
+
*/
|
|
19
|
+
export declare const TakeNTradeUtils: {
|
|
20
|
+
validators: typeof validators;
|
|
21
|
+
filters: typeof filters;
|
|
22
|
+
interceptors: typeof interceptors;
|
|
23
|
+
pipes: typeof pipes;
|
|
24
|
+
utils: typeof utils;
|
|
25
|
+
interfaces: typeof interfaces;
|
|
26
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.TakeNTradeUtils = exports.interfaces = exports.dto = void 0;
|
|
40
|
+
const validators = __importStar(require("./validators"));
|
|
41
|
+
const filters = __importStar(require("./filters"));
|
|
42
|
+
const interceptors = __importStar(require("./interceptors"));
|
|
43
|
+
const interfaces = __importStar(require("./interfaces"));
|
|
44
|
+
const pipes = __importStar(require("./pipes"));
|
|
45
|
+
const utils = __importStar(require("./utils"));
|
|
46
|
+
// Exports:
|
|
47
|
+
exports.dto = __importStar(require("./dto"));
|
|
48
|
+
exports.interfaces = __importStar(require("./interfaces"));
|
|
49
|
+
__exportStar(require("./validators"), exports);
|
|
50
|
+
__exportStar(require("./filters"), exports);
|
|
51
|
+
__exportStar(require("./interceptors"), exports);
|
|
52
|
+
__exportStar(require("./pipes"), exports);
|
|
53
|
+
__exportStar(require("./utils"), exports);
|
|
54
|
+
__exportStar(require("./interfaces"), exports);
|
|
55
|
+
__exportStar(require("./dto"), exports);
|
|
56
|
+
/**
|
|
57
|
+
* A set of shared utilities across the application.
|
|
58
|
+
*/
|
|
59
|
+
exports.TakeNTradeUtils = {
|
|
60
|
+
validators,
|
|
61
|
+
filters,
|
|
62
|
+
interceptors,
|
|
63
|
+
pipes,
|
|
64
|
+
utils,
|
|
65
|
+
interfaces,
|
|
66
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./pagination.interceptor"), exports);
|
|
18
|
+
__exportStar(require("./response.interceptor"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
/**
|
|
4
|
+
* This is intended to intercept incoming requests for routes that intend to use pagination.
|
|
5
|
+
* It attaches a `Pagination` object named `pagination` to the request object.
|
|
6
|
+
*
|
|
7
|
+
* This new `pagination` property on the request body uses the `page` and `limit` properties on
|
|
8
|
+
* the request's query object if they exist. If no `page` or `limit` property is provided by
|
|
9
|
+
* the request client, this interceptor sets defaults.
|
|
10
|
+
*
|
|
11
|
+
* Defaults:
|
|
12
|
+
*
|
|
13
|
+
* `page` = 1 and;
|
|
14
|
+
*
|
|
15
|
+
* `limit` = 10
|
|
16
|
+
*/
|
|
17
|
+
export declare class PaginationInterceptor implements NestInterceptor {
|
|
18
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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.PaginationInterceptor = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
/**
|
|
12
|
+
* This is intended to intercept incoming requests for routes that intend to use pagination.
|
|
13
|
+
* It attaches a `Pagination` object named `pagination` to the request object.
|
|
14
|
+
*
|
|
15
|
+
* This new `pagination` property on the request body uses the `page` and `limit` properties on
|
|
16
|
+
* the request's query object if they exist. If no `page` or `limit` property is provided by
|
|
17
|
+
* the request client, this interceptor sets defaults.
|
|
18
|
+
*
|
|
19
|
+
* Defaults:
|
|
20
|
+
*
|
|
21
|
+
* `page` = 1 and;
|
|
22
|
+
*
|
|
23
|
+
* `limit` = 10
|
|
24
|
+
*/
|
|
25
|
+
let PaginationInterceptor = class PaginationInterceptor {
|
|
26
|
+
intercept(context, next) {
|
|
27
|
+
const request = context.switchToHttp().getRequest();
|
|
28
|
+
let page = Number.parseInt(request.query.page);
|
|
29
|
+
let limit = Number.parseInt(request.query.limit);
|
|
30
|
+
// check validity and set defaults where necessary
|
|
31
|
+
page = page.toString() === Number.NaN.toString() ? 1 : page;
|
|
32
|
+
limit = limit.toString() === Number.NaN.toString() ? 10 : limit;
|
|
33
|
+
// set boundaries
|
|
34
|
+
page = page <= 0 ? 1 : page;
|
|
35
|
+
limit = limit > 100 ? 100 : limit;
|
|
36
|
+
const pagination = {
|
|
37
|
+
offset: page * limit - limit,
|
|
38
|
+
skip: (page - 1) * limit,
|
|
39
|
+
limit,
|
|
40
|
+
page,
|
|
41
|
+
};
|
|
42
|
+
request.pagination = pagination;
|
|
43
|
+
return next.handle();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.PaginationInterceptor = PaginationInterceptor;
|
|
47
|
+
exports.PaginationInterceptor = PaginationInterceptor = __decorate([
|
|
48
|
+
(0, common_1.Injectable)()
|
|
49
|
+
], PaginationInterceptor);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { IAppResponse } from '../interfaces/response.interface';
|
|
4
|
+
import { IResponseInterceptor, IInterceptorConfig } from '../interfaces/interceptor.interface';
|
|
5
|
+
export declare class ResponseInterceptor<T> implements NestInterceptor<T, IAppResponse<T>>, IResponseInterceptor<T> {
|
|
6
|
+
private readonly logger;
|
|
7
|
+
private readonly config;
|
|
8
|
+
constructor(config?: IInterceptorConfig);
|
|
9
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<IAppResponse<T>>;
|
|
10
|
+
private buildMetadata;
|
|
11
|
+
private enhanceExistingResponse;
|
|
12
|
+
private createSuccessResponse;
|
|
13
|
+
private extractRequestId;
|
|
14
|
+
private generateRequestId;
|
|
15
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
var ResponseInterceptor_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ResponseInterceptor = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const operators_1 = require("rxjs/operators");
|
|
13
|
+
const utils_1 = require("../utils");
|
|
14
|
+
let ResponseInterceptor = ResponseInterceptor_1 = class ResponseInterceptor {
|
|
15
|
+
logger = new common_1.Logger(ResponseInterceptor_1.name);
|
|
16
|
+
config;
|
|
17
|
+
constructor(config = {}) {
|
|
18
|
+
this.config = {
|
|
19
|
+
includeTimestamp: true,
|
|
20
|
+
includePath: true,
|
|
21
|
+
includeRequestId: true,
|
|
22
|
+
includeVersion: false,
|
|
23
|
+
includeExecutionTime: true,
|
|
24
|
+
defaultSuccessMessage: 'Request successful',
|
|
25
|
+
...config,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
intercept(context, next) {
|
|
29
|
+
const startTime = Date.now();
|
|
30
|
+
const request = context.switchToHttp().getRequest();
|
|
31
|
+
const metadata = this.buildMetadata(request, startTime);
|
|
32
|
+
return next.handle().pipe((0, operators_1.tap)(() => {
|
|
33
|
+
this.logger.log(`${request.method} ${request.url} - ${Date.now() - startTime}ms`);
|
|
34
|
+
}), (0, operators_1.map)((data) => {
|
|
35
|
+
if (data instanceof utils_1.AppResponse) {
|
|
36
|
+
return this.enhanceExistingResponse(data, metadata, startTime);
|
|
37
|
+
}
|
|
38
|
+
return this.createSuccessResponse(data, metadata, startTime);
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
buildMetadata(request, startTime) {
|
|
42
|
+
const metadata = {};
|
|
43
|
+
if (this.config.includeTimestamp) {
|
|
44
|
+
metadata.timestamp = new Date().toISOString();
|
|
45
|
+
}
|
|
46
|
+
if (this.config.includePath) {
|
|
47
|
+
metadata.path = `${request.method} ${request.url}`;
|
|
48
|
+
}
|
|
49
|
+
if (this.config.includeRequestId) {
|
|
50
|
+
metadata.requestId = this.extractRequestId(request);
|
|
51
|
+
}
|
|
52
|
+
if (this.config.includeVersion && this.config.version) {
|
|
53
|
+
metadata.version = this.config.version;
|
|
54
|
+
}
|
|
55
|
+
return metadata;
|
|
56
|
+
}
|
|
57
|
+
enhanceExistingResponse(response, metadata, startTime) {
|
|
58
|
+
if (this.config.includeExecutionTime) {
|
|
59
|
+
response.executionTime = Date.now() - startTime;
|
|
60
|
+
}
|
|
61
|
+
response.timestamp = response.timestamp || metadata.timestamp;
|
|
62
|
+
response.path = response.path || metadata.path;
|
|
63
|
+
response.requestId = response.requestId || metadata.requestId;
|
|
64
|
+
response.version = response.version || metadata.version;
|
|
65
|
+
return response;
|
|
66
|
+
}
|
|
67
|
+
createSuccessResponse(data, metadata, startTime) {
|
|
68
|
+
if (this.config.includeExecutionTime) {
|
|
69
|
+
metadata.executionTime = Date.now() - startTime;
|
|
70
|
+
}
|
|
71
|
+
return utils_1.AppResponse.success(this.config.defaultSuccessMessage, data, metadata);
|
|
72
|
+
}
|
|
73
|
+
extractRequestId(request) {
|
|
74
|
+
return ((request.headers && request.headers['x-request-id']) ||
|
|
75
|
+
(request.headers && request.headers['x-correlation-id']) ||
|
|
76
|
+
(request.headers && request.headers['x-trace-id']) ||
|
|
77
|
+
this.generateRequestId());
|
|
78
|
+
}
|
|
79
|
+
generateRequestId() {
|
|
80
|
+
return `req_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
exports.ResponseInterceptor = ResponseInterceptor;
|
|
84
|
+
exports.ResponseInterceptor = ResponseInterceptor = ResponseInterceptor_1 = __decorate([
|
|
85
|
+
(0, common_1.Injectable)()
|
|
86
|
+
], ResponseInterceptor);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface Configuration {
|
|
2
|
+
PORT: number;
|
|
3
|
+
HOST: string;
|
|
4
|
+
DATABASE_URL: string;
|
|
5
|
+
JWT_ACCESS_TOKEN_SECRET: string;
|
|
6
|
+
JWT_ACCESS_TOKEN_EXPIRES_IN: string;
|
|
7
|
+
JWT_REFRESH_TOKEN_SECRET: string;
|
|
8
|
+
JWT_REFRESH_TOKEN_EXPIRES_IN: string;
|
|
9
|
+
REDIS_URL: string;
|
|
10
|
+
CACHE_TTL: number;
|
|
11
|
+
CACHE_MAX_ITEMS: number;
|
|
12
|
+
MAIL_HOST: string;
|
|
13
|
+
MAIL_USER: string;
|
|
14
|
+
MAIL_PASS: string;
|
|
15
|
+
PROVIDUS_BASE_URL: string;
|
|
16
|
+
PROVIDUS_SECRET_KEY: string;
|
|
17
|
+
PROVIDUS_PUBLIC_KEY: string;
|
|
18
|
+
VTPASS_BASE_URL: string;
|
|
19
|
+
VTPASS_API_KEY: string;
|
|
20
|
+
VTPASS_PUBLIC_KEY: string;
|
|
21
|
+
VTPASS_SECRET_KEY: string;
|
|
22
|
+
CREDITSWITCH_BASE_URL: string;
|
|
23
|
+
CREDITSWITCH_CLIENT_ID: string;
|
|
24
|
+
CREDITSWITCH_CLIENT_SECRET: string;
|
|
25
|
+
CREDITSWITCH_USERNAME: string;
|
|
26
|
+
CREDITSWITCH_PASSWORD: string;
|
|
27
|
+
RELOADLY_BASE_URL: string;
|
|
28
|
+
RELOADLY_CLIENT_ID: string;
|
|
29
|
+
RELOADLY_CLIENT_SECRET: string;
|
|
30
|
+
RELOADLY_AUDIENCE: string;
|
|
31
|
+
RELOADLY_SANDBOX: boolean;
|
|
32
|
+
CLOUDINARY_CLOUD_NAME: string;
|
|
33
|
+
CLOUDINARY_API_KEY: string;
|
|
34
|
+
CLOUDINARY_API_SECRET: string;
|
|
35
|
+
NATS_URL: string;
|
|
36
|
+
CORS_ORIGIN: string;
|
|
37
|
+
EXPO_ACCESS_TOKEN: string;
|
|
38
|
+
AFRICASTALKING_API_KEY: string;
|
|
39
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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("./multer-file.interface"), exports);
|
|
18
|
+
__exportStar(require("./general.interface"), exports);
|
|
19
|
+
__exportStar(require("./pagination.interface"), exports);
|
|
20
|
+
__exportStar(require("./response.interface"), exports);
|
|
21
|
+
__exportStar(require("./interceptor.interface"), exports);
|
|
22
|
+
__exportStar(require("./config.interface"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { IAppResponse } from './response.interface';
|
|
4
|
+
export interface IResponseInterceptor<T> {
|
|
5
|
+
intercept(context: ExecutionContext, next: any): Observable<IAppResponse<T>>;
|
|
6
|
+
}
|
|
7
|
+
export interface IInterceptorConfig {
|
|
8
|
+
includeTimestamp?: boolean;
|
|
9
|
+
includePath?: boolean;
|
|
10
|
+
includeRequestId?: boolean;
|
|
11
|
+
includeVersion?: boolean;
|
|
12
|
+
includeExecutionTime?: boolean;
|
|
13
|
+
defaultSuccessMessage?: string;
|
|
14
|
+
version?: string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface PaginationOptions {
|
|
2
|
+
/** The page value from the client. It is used to evaluate the value of `offset` and `skip`. Defaults to 1. */
|
|
3
|
+
page?: number;
|
|
4
|
+
/** The number of rows to take */
|
|
5
|
+
limit?: number;
|
|
6
|
+
/** The number of rows to skip */
|
|
7
|
+
offset?: number;
|
|
8
|
+
/** Logically same as offset. */
|
|
9
|
+
skip?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface PaginatedResult<R = unknown> {
|
|
12
|
+
records: R[];
|
|
13
|
+
/** The total number of records matched across all pages */
|
|
14
|
+
count: number;
|
|
15
|
+
limit: number;
|
|
16
|
+
page: number;
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface IAppResponse<T = any> {
|
|
2
|
+
status: ResponseStatus;
|
|
3
|
+
message: string;
|
|
4
|
+
data: T;
|
|
5
|
+
timestamp?: string;
|
|
6
|
+
path?: string;
|
|
7
|
+
requestId?: string;
|
|
8
|
+
version?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface IResponseMetadata {
|
|
11
|
+
timestamp: string;
|
|
12
|
+
path: string;
|
|
13
|
+
requestId?: string;
|
|
14
|
+
version?: string;
|
|
15
|
+
executionTime?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare enum ResponseStatus {
|
|
18
|
+
SUCCESS = "success",
|
|
19
|
+
ERROR = "error",
|
|
20
|
+
WARNING = "warning"
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseStatus = void 0;
|
|
4
|
+
var ResponseStatus;
|
|
5
|
+
(function (ResponseStatus) {
|
|
6
|
+
ResponseStatus["SUCCESS"] = "success";
|
|
7
|
+
ResponseStatus["ERROR"] = "error";
|
|
8
|
+
ResponseStatus["WARNING"] = "warning";
|
|
9
|
+
})(ResponseStatus || (exports.ResponseStatus = ResponseStatus = {}));
|
|
@@ -0,0 +1,44 @@
|
|
|
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.FileValidationPipe = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
let FileValidationPipe = class FileValidationPipe {
|
|
12
|
+
transform(value) {
|
|
13
|
+
if (!value) {
|
|
14
|
+
throw new common_1.BadRequestException('No files uploaded');
|
|
15
|
+
}
|
|
16
|
+
this.validateFileType(value);
|
|
17
|
+
this.validateFileSize(value);
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
validateFileType(files) {
|
|
21
|
+
const allowedMimeTypes = ['image/jpeg', 'image/png', 'image/jpg'];
|
|
22
|
+
if (files.frontImage?.[0] &&
|
|
23
|
+
!allowedMimeTypes.includes(files.frontImage[0].mimetype)) {
|
|
24
|
+
throw new common_1.BadRequestException('Front image must be a jpeg, jpg, or png file');
|
|
25
|
+
}
|
|
26
|
+
if (files.backImage?.[0] &&
|
|
27
|
+
!allowedMimeTypes.includes(files.backImage[0].mimetype)) {
|
|
28
|
+
throw new common_1.BadRequestException('Back image must be a jpeg, jpg, or png file');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
validateFileSize(files) {
|
|
32
|
+
const maxSize = 5 * 1024 * 1024; // 5MB
|
|
33
|
+
if (files.frontImage?.[0] && files.frontImage[0].size > maxSize) {
|
|
34
|
+
throw new common_1.BadRequestException('Front image size should not exceed 5MB');
|
|
35
|
+
}
|
|
36
|
+
if (files.backImage?.[0] && files.backImage[0].size > maxSize) {
|
|
37
|
+
throw new common_1.BadRequestException('Back image size should not exceed 5MB');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.FileValidationPipe = FileValidationPipe;
|
|
42
|
+
exports.FileValidationPipe = FileValidationPipe = __decorate([
|
|
43
|
+
(0, common_1.Injectable)()
|
|
44
|
+
], FileValidationPipe);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./validation.pipe"), exports);
|
|
18
|
+
__exportStar(require("./pagination.pipe"), exports);
|
|
19
|
+
__exportStar(require("./file.pipe"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ArgumentMetadata, PipeTransform } from '@nestjs/common';
|
|
2
|
+
/**
|
|
3
|
+
* Removes the `page` and `limit` fields on the query object returned by the NestJS @Query argument decorator.
|
|
4
|
+
*/
|
|
5
|
+
export declare class PaginationQueryCleanerPipe implements PipeTransform {
|
|
6
|
+
transform(value: any, metadata: ArgumentMetadata): any;
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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.PaginationQueryCleanerPipe = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
/**
|
|
12
|
+
* Removes the `page` and `limit` fields on the query object returned by the NestJS @Query argument decorator.
|
|
13
|
+
*/
|
|
14
|
+
let PaginationQueryCleanerPipe = class PaginationQueryCleanerPipe {
|
|
15
|
+
transform(value, metadata) {
|
|
16
|
+
delete value.page;
|
|
17
|
+
delete value.limit;
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.PaginationQueryCleanerPipe = PaginationQueryCleanerPipe;
|
|
22
|
+
exports.PaginationQueryCleanerPipe = PaginationQueryCleanerPipe = __decorate([
|
|
23
|
+
(0, common_1.Injectable)()
|
|
24
|
+
], PaginationQueryCleanerPipe);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TNTValidationPipe = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
class TNTValidationPipe extends common_1.ValidationPipe {
|
|
6
|
+
async transform(value, metadata) {
|
|
7
|
+
try {
|
|
8
|
+
return await super.transform(value, metadata);
|
|
9
|
+
}
|
|
10
|
+
catch (e) {
|
|
11
|
+
if (e instanceof common_1.BadRequestException) {
|
|
12
|
+
console.log(e.getResponse());
|
|
13
|
+
const errorResponse = e.getResponse();
|
|
14
|
+
if (Array.isArray(errorResponse.message)) {
|
|
15
|
+
errorResponse.errors = errorResponse.message;
|
|
16
|
+
errorResponse.message = 'Invalid Data';
|
|
17
|
+
delete errorResponse.error;
|
|
18
|
+
throw new common_1.BadRequestException(errorResponse);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.TNTValidationPipe = TNTValidationPipe;
|