@triproject/nestjs-core 1.0.29 → 1.0.31
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/dist/bootstrap.js +39 -1
- package/dist/config.js +257 -1
- package/dist/controllers/controller.js +53 -1
- package/dist/drivers/cache/cache.js +79 -1
- package/dist/drivers/cache/cache.module.js +30 -1
- package/dist/drivers/cache/index.js +14 -1
- package/dist/drivers/cache/redis.js +76 -1
- package/dist/drivers/db/db.helper.d.ts +1 -1
- package/dist/drivers/db/db.helper.js +276 -1
- package/dist/drivers/db/db.module.js +64 -1
- package/dist/drivers/db/db.service.js +52 -1
- package/dist/drivers/db/index.js +14 -1
- package/dist/drivers/db/migration.js +119 -1
- package/dist/drivers/db/repository.js +258 -1
- package/dist/drivers/encryptions/encryption.js +55 -1
- package/dist/drivers/encryptions/encryption.module.js +34 -1
- package/dist/drivers/encryptions/index.js +14 -1
- package/dist/drivers/encryptions/jwt.js +62 -1
- package/dist/drivers/encryptions/password-hash.js +48 -1
- package/dist/drivers/encryptions/snap.signature.js +111 -1
- package/dist/drivers/logger/app.logger.js +121 -2
- package/dist/drivers/logger/cloudwatch.js +73 -1
- package/dist/drivers/logger/index.js +12 -1
- package/dist/drivers/logger/logger.contract.js +29 -1
- package/dist/drivers/logger/logger.driver.js +49 -1
- package/dist/drivers/logger/slack.logger.js +42 -1
- package/dist/drivers/mail/index.js +14 -1
- package/dist/drivers/mail/mail-template.js +39 -6
- package/dist/drivers/mail/mail.config.js +10 -1
- package/dist/drivers/mail/mail.js +58 -13
- package/dist/drivers/mail/mail.module.js +36 -1
- package/dist/drivers/mail/mail.queue.js +45 -1
- package/dist/drivers/mail/mailer.js +64 -1
- package/dist/drivers/message-broker/index.js +14 -1
- package/dist/drivers/message-broker/kafka.js +104 -1
- package/dist/drivers/message-broker/message-broker.contract.js +24 -1
- package/dist/drivers/message-broker/message-broker.module.js +28 -1
- package/dist/drivers/message-broker/message.broker.js +67 -1
- package/dist/drivers/message-broker/rabbitmq.js +115 -1
- package/dist/drivers/notifications/index.js +14 -1
- package/dist/drivers/notifications/notification.config.js +10 -1
- package/dist/drivers/notifications/notification.module.js +34 -1
- package/dist/drivers/notifications/notification.queue.js +45 -1
- package/dist/drivers/notifications/push-notification.js +81 -1
- package/dist/drivers/notifications/slack.js +74 -1
- package/dist/drivers/queues/app.queue.js +77 -1
- package/dist/drivers/queues/index.js +14 -1
- package/dist/drivers/queues/queue.module.js +51 -1
- package/dist/drivers/secret-manager/aws-secret-manager.js +40 -1
- package/dist/drivers/secret-manager/index.js +50 -1
- package/dist/drivers/storage/csv.storage.js +71 -1
- package/dist/drivers/storage/excel.storage.js +57 -1
- package/dist/drivers/storage/index.js +14 -1
- package/dist/drivers/storage/local.storage.js +94 -1
- package/dist/drivers/storage/minio.storage.js +82 -1
- package/dist/drivers/storage/s3-storage.js +122 -1
- package/dist/drivers/storage/storage.contract.js +31 -1
- package/dist/drivers/storage/storage.module.js +32 -1
- package/dist/drivers/storage/storage.service.js +59 -1
- package/dist/helpers/exception.helper.js +132 -1
- package/dist/helpers/http.helper.js +163 -1
- package/dist/helpers/swagger.helper.js +474 -1
- package/dist/index.js +14 -1
- package/dist/types.d.js +4 -1
- package/dist/utils/redlock.js +51 -1
- package/dist/utils/throttle.js +68 -1
- package/dist/utils/totp.js +56 -1
- package/package.json +32 -29
|
@@ -1 +1,81 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var decorator, obj;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), Object.defineProperty(exports, "PushNotification", {
|
|
6
|
+
enumerable: !0,
|
|
7
|
+
get: function() {
|
|
8
|
+
return PushNotification;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
let _bull = require("@nestjs/bull"), _common = require("@nestjs/common"), _helpers = require("@triproject/helpers"), _axios = (obj = require("axios")) && obj.__esModule ? obj : {
|
|
12
|
+
default: obj
|
|
13
|
+
}, _bullmq = require("bullmq"), _exceptionhelper = require("../../helpers/exception.helper"), _secretmanager = require("../secret-manager"), _notificationconfig = require("./notification.config");
|
|
14
|
+
function _ts_metadata(k, v) {
|
|
15
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
16
|
+
}
|
|
17
|
+
let PushNotification = class PushNotification {
|
|
18
|
+
notificationQueue;
|
|
19
|
+
APP_ID;
|
|
20
|
+
client;
|
|
21
|
+
constructor(notificationQueue){
|
|
22
|
+
this.notificationQueue = notificationQueue, (0, _secretmanager.getSecret)().then((secret)=>{
|
|
23
|
+
this.APP_ID = secret.ONESIGNAL_APP_ID, this.client = _axios.default.create({
|
|
24
|
+
baseURL: 'https://api.onesignal.com',
|
|
25
|
+
timeout: 100,
|
|
26
|
+
headers: {
|
|
27
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
28
|
+
Authorization: `Key ${secret.ONESIGNAL_REST_API_KEY}`
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async send(params, shouldQueue = !0) {
|
|
34
|
+
if (!this.client) throw new _exceptionhelper.AppInternalServerErrorException('PushNotification client not initialized yet');
|
|
35
|
+
if (shouldQueue) return this.notificationQueue.add(_notificationconfig.notificationQueue, params, {
|
|
36
|
+
jobId: (0, _helpers.generateId)()
|
|
37
|
+
});
|
|
38
|
+
let { userId, type, title, message, data } = params;
|
|
39
|
+
return await this.client.post('notifications', {
|
|
40
|
+
app_id: this.APP_ID,
|
|
41
|
+
target_channel: 'push',
|
|
42
|
+
name: type,
|
|
43
|
+
headings: {
|
|
44
|
+
en: title
|
|
45
|
+
},
|
|
46
|
+
contents: {
|
|
47
|
+
en: message
|
|
48
|
+
},
|
|
49
|
+
data,
|
|
50
|
+
included_segments: [
|
|
51
|
+
userId
|
|
52
|
+
].filter((d)=>d)
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
broadcast(params, shouldQueue = !0) {
|
|
56
|
+
if (!this.client) throw new _exceptionhelper.AppInternalServerErrorException('PushNotification client not initialized yet');
|
|
57
|
+
let { title, message, data } = params;
|
|
58
|
+
return this.send({
|
|
59
|
+
userId: 'All',
|
|
60
|
+
type: 'broadcast',
|
|
61
|
+
title,
|
|
62
|
+
message,
|
|
63
|
+
data
|
|
64
|
+
}, shouldQueue);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
PushNotification = function(decorators, target, key, desc) {
|
|
68
|
+
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
69
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
70
|
+
else for(var i = decorators.length - 1; i >= 0; i--)(d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
|
|
71
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
72
|
+
}([
|
|
73
|
+
(0, _common.Injectable)(),
|
|
74
|
+
(decorator = (0, _bull.InjectQueue)(_notificationconfig.notificationQueue), function(target, key) {
|
|
75
|
+
decorator(target, key, 0);
|
|
76
|
+
}),
|
|
77
|
+
_ts_metadata("design:type", Function),
|
|
78
|
+
_ts_metadata("design:paramtypes", [
|
|
79
|
+
void 0 === _bullmq.Queue ? Object : _bullmq.Queue
|
|
80
|
+
])
|
|
81
|
+
], PushNotification);
|
|
@@ -1 +1,74 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var obj;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), Object.defineProperty(exports, "Slack", {
|
|
6
|
+
enumerable: !0,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Slack;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
let _axios = (obj = require("axios")) && obj.__esModule ? obj : {
|
|
12
|
+
default: obj
|
|
13
|
+
};
|
|
14
|
+
let Slack = class Slack {
|
|
15
|
+
logger = console;
|
|
16
|
+
client;
|
|
17
|
+
status = {
|
|
18
|
+
blocked: !1,
|
|
19
|
+
lastUpdateAt: new Date()
|
|
20
|
+
};
|
|
21
|
+
constructor(config){
|
|
22
|
+
config.logger && (this.logger = config.logger), config.webhookUrl.startsWith('https') && (this.client = _axios.default.create({
|
|
23
|
+
baseURL: config.webhookUrl,
|
|
24
|
+
timeout: 500,
|
|
25
|
+
headers: {
|
|
26
|
+
'Content-Type': 'application/json'
|
|
27
|
+
}
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
_toggleBlocked() {
|
|
31
|
+
this.status = {
|
|
32
|
+
blocked: !this.status.blocked,
|
|
33
|
+
lastUpdateAt: new Date()
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
_format(...messages) {
|
|
37
|
+
let blocks = [];
|
|
38
|
+
if (0 === messages.length) return blocks;
|
|
39
|
+
if (messages.length > 0 && 'string' == typeof messages[0]) return blocks.push({
|
|
40
|
+
type: 'header',
|
|
41
|
+
text: {
|
|
42
|
+
type: 'plain_text',
|
|
43
|
+
text: messages[0]
|
|
44
|
+
}
|
|
45
|
+
}), blocks;
|
|
46
|
+
for (let msg of messages)msg && (msg instanceof Error ? blocks.push({
|
|
47
|
+
type: 'section',
|
|
48
|
+
text: {
|
|
49
|
+
type: 'mrkdwn',
|
|
50
|
+
text: '<font color="red">```**' + msg.name + '**: ' + msg.message + '\n ' + msg?.stack?.split('\n').join('\n ') + '</font>```'
|
|
51
|
+
}
|
|
52
|
+
}) : 'object' == typeof msg ? blocks.push({
|
|
53
|
+
type: 'section',
|
|
54
|
+
text: {
|
|
55
|
+
type: 'mrkdwn',
|
|
56
|
+
text: '```json' + JSON.stringify(msg, null, 2) + '```'
|
|
57
|
+
}
|
|
58
|
+
}) : blocks.push({
|
|
59
|
+
type: 'section',
|
|
60
|
+
text: {
|
|
61
|
+
type: 'plain_text',
|
|
62
|
+
text: msg?.toString()
|
|
63
|
+
}
|
|
64
|
+
}));
|
|
65
|
+
return blocks;
|
|
66
|
+
}
|
|
67
|
+
async send(...messages) {
|
|
68
|
+
if (this.client && !(this.status.blocked && new Date().getTime() - this.status.lastUpdateAt.getTime() < 10800000)) return await this.client.post('', {
|
|
69
|
+
blocks: this._format(...messages)
|
|
70
|
+
}).then((data)=>(this.status.blocked && this._toggleBlocked(), data)).catch((error)=>{
|
|
71
|
+
this?.logger.error('Failed to send slack notification', error), this.status.blocked || this._toggleBlocked();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
@@ -1 +1,77 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: !0
|
|
4
|
+
}), Object.defineProperty(exports, "AppQueue", {
|
|
5
|
+
enumerable: !0,
|
|
6
|
+
get: function() {
|
|
7
|
+
return AppQueue;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
let _bull = require("@nestjs/bull"), _applogger = require("../logger/app.logger");
|
|
11
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
12
|
+
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
13
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
14
|
+
else for(var i = decorators.length - 1; i >= 0; i--)(d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
|
|
15
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
16
|
+
}
|
|
17
|
+
function _ts_metadata(k, v) {
|
|
18
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
19
|
+
}
|
|
20
|
+
let AppQueue = class AppQueue {
|
|
21
|
+
logger = new _applogger.AppLogger(this.constructor.name);
|
|
22
|
+
constructor(){
|
|
23
|
+
this.logger.log(this.constructor.name + ' is ready');
|
|
24
|
+
}
|
|
25
|
+
onProgress(job) {
|
|
26
|
+
this.logger.log(`Job ${job.id} in ${job.name} is active`, job.data);
|
|
27
|
+
}
|
|
28
|
+
onCompleted(job) {
|
|
29
|
+
this.logger.log(`Job ${job.id} in ${job.name} is completed`, job.data);
|
|
30
|
+
}
|
|
31
|
+
onStalled(job) {
|
|
32
|
+
this.logger.error(`Job ${job.id} in ${job.name} is stalled`, job.data);
|
|
33
|
+
}
|
|
34
|
+
onError(job) {
|
|
35
|
+
this.logger.error(`Job ${job.id} in ${job.name} is error`, job.data);
|
|
36
|
+
}
|
|
37
|
+
onFailed(job, error) {
|
|
38
|
+
this.logger.error(`Job ${job.id} in ${job.name} is failed`, job.data, error);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
_ts_decorate([
|
|
42
|
+
(0, _bull.OnQueueProgress)(),
|
|
43
|
+
_ts_metadata("design:type", Function),
|
|
44
|
+
_ts_metadata("design:paramtypes", [
|
|
45
|
+
"u" < typeof Job ? Object : Job
|
|
46
|
+
]),
|
|
47
|
+
_ts_metadata("design:returntype", void 0)
|
|
48
|
+
], AppQueue.prototype, "onProgress", null), _ts_decorate([
|
|
49
|
+
(0, _bull.OnQueueCompleted)(),
|
|
50
|
+
_ts_metadata("design:type", Function),
|
|
51
|
+
_ts_metadata("design:paramtypes", [
|
|
52
|
+
"u" < typeof Job ? Object : Job
|
|
53
|
+
]),
|
|
54
|
+
_ts_metadata("design:returntype", void 0)
|
|
55
|
+
], AppQueue.prototype, "onCompleted", null), _ts_decorate([
|
|
56
|
+
(0, _bull.OnQueueStalled)(),
|
|
57
|
+
_ts_metadata("design:type", Function),
|
|
58
|
+
_ts_metadata("design:paramtypes", [
|
|
59
|
+
"u" < typeof Job ? Object : Job
|
|
60
|
+
]),
|
|
61
|
+
_ts_metadata("design:returntype", void 0)
|
|
62
|
+
], AppQueue.prototype, "onStalled", null), _ts_decorate([
|
|
63
|
+
(0, _bull.OnQueueError)(),
|
|
64
|
+
_ts_metadata("design:type", Function),
|
|
65
|
+
_ts_metadata("design:paramtypes", [
|
|
66
|
+
"u" < typeof Job ? Object : Job
|
|
67
|
+
]),
|
|
68
|
+
_ts_metadata("design:returntype", void 0)
|
|
69
|
+
], AppQueue.prototype, "onError", null), _ts_decorate([
|
|
70
|
+
(0, _bull.OnQueueFailed)(),
|
|
71
|
+
_ts_metadata("design:type", Function),
|
|
72
|
+
_ts_metadata("design:paramtypes", [
|
|
73
|
+
"u" < typeof Job ? Object : Job,
|
|
74
|
+
Object
|
|
75
|
+
]),
|
|
76
|
+
_ts_metadata("design:returntype", void 0)
|
|
77
|
+
], AppQueue.prototype, "onFailed", null);
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
function _export_star(from, to) {
|
|
3
|
+
return Object.keys(from).forEach(function(k) {
|
|
4
|
+
"default" === k || Object.prototype.hasOwnProperty.call(to, k) || Object.defineProperty(to, k, {
|
|
5
|
+
enumerable: !0,
|
|
6
|
+
get: function() {
|
|
7
|
+
return from[k];
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
}), from;
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(exports, "__esModule", {
|
|
13
|
+
value: !0
|
|
14
|
+
}), _export_star(require("./app.queue"), exports), _export_star(require("./queue.module"), exports);
|
|
@@ -1 +1,51 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: !0
|
|
4
|
+
}), Object.defineProperty(exports, "QueueModule", {
|
|
5
|
+
enumerable: !0,
|
|
6
|
+
get: function() {
|
|
7
|
+
return QueueModule;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
let _bullmq = require("@nestjs/bullmq"), _common = require("@nestjs/common"), _secretmanager = require("../secret-manager");
|
|
11
|
+
let QueueModule = class QueueModule {
|
|
12
|
+
};
|
|
13
|
+
QueueModule = function(decorators, target, key, desc) {
|
|
14
|
+
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
15
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
16
|
+
else for(var i = decorators.length - 1; i >= 0; i--)(d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
|
|
17
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
18
|
+
}([
|
|
19
|
+
(0, _common.Global)(),
|
|
20
|
+
(0, _common.Module)({
|
|
21
|
+
imports: [
|
|
22
|
+
_bullmq.BullModule.forRootAsync({
|
|
23
|
+
useFactory: async ()=>{
|
|
24
|
+
let secret = await (0, _secretmanager.getSecret)();
|
|
25
|
+
return {
|
|
26
|
+
prefix: secret.APP_KEY + ':JOBS:',
|
|
27
|
+
defaultJobOptions: {
|
|
28
|
+
delay: 0,
|
|
29
|
+
removeOnComplete: !0,
|
|
30
|
+
removeOnFail: !1,
|
|
31
|
+
backoff: {
|
|
32
|
+
type: 'exponential',
|
|
33
|
+
delay: 10
|
|
34
|
+
},
|
|
35
|
+
attempts: 2
|
|
36
|
+
},
|
|
37
|
+
connection: {
|
|
38
|
+
host: secret.REDIS_HOST,
|
|
39
|
+
port: secret.REDIS_PORT,
|
|
40
|
+
db: secret.REDIS_DB,
|
|
41
|
+
password: secret.REDIS_PASSWORD,
|
|
42
|
+
tls: secret.REDIS_TLS ? {
|
|
43
|
+
ca: ''
|
|
44
|
+
} : void 0
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
]
|
|
50
|
+
})
|
|
51
|
+
], QueueModule);
|
|
@@ -1 +1,40 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: !0
|
|
4
|
+
}), Object.defineProperty(exports, "AWSSecretManager", {
|
|
5
|
+
enumerable: !0,
|
|
6
|
+
get: function() {
|
|
7
|
+
return AWSSecretManager;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
let _clientsecretsmanager = require("@aws-sdk/client-secrets-manager"), _common = require("@nestjs/common"), _logger = require("@triproject/nestjs-core/logger"), _config = require("../../config");
|
|
11
|
+
let AWSSecretManager = class AWSSecretManager {
|
|
12
|
+
logger = new _logger.AppLogger(AWSSecretManager.name);
|
|
13
|
+
secretManagerClient;
|
|
14
|
+
secretData;
|
|
15
|
+
constructor(){
|
|
16
|
+
_config.AWS_SECRETS_MANAGER_ENABLED && _config.AWS_SECRETS_MANAGER_REGION && _config.AWS_SECRETS_MANAGER_VERSION_STAGE && (this.secretManagerClient = new _clientsecretsmanager.SecretsManagerClient({
|
|
17
|
+
region: _config.AWS_SECRETS_MANAGER_REGION,
|
|
18
|
+
credentials: {
|
|
19
|
+
accessKeyId: _config.AWS_SECRETS_MANAGER_ACCESS_KEY_ID,
|
|
20
|
+
secretAccessKey: _config.AWS_SECRETS_MANAGER_SECRET_ACCESS_KEY
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
async get() {
|
|
25
|
+
if (!this.secretManagerClient) return {};
|
|
26
|
+
try {
|
|
27
|
+
if (this.secretData) return this.secretData;
|
|
28
|
+
let responseData = await this.secretManagerClient.send(new _clientsecretsmanager.GetSecretValueCommand({
|
|
29
|
+
SecretId: _config.AWS_SECRETS_MANAGER_SECRET_NAME,
|
|
30
|
+
VersionStage: _config.AWS_SECRETS_MANAGER_VERSION_STAGE
|
|
31
|
+
}));
|
|
32
|
+
return this.secretData = JSON.parse(responseData.SecretString), this.secretData;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
throw this.logger.error('Failed get secret data', {
|
|
35
|
+
SecretId: _config.AWS_SECRETS_MANAGER_SECRET_NAME,
|
|
36
|
+
VersionStage: _config.AWS_SECRETS_MANAGER_VERSION_STAGE
|
|
37
|
+
}, error), new _common.InternalServerErrorException('Failed get secret data from AWS Secret Manager');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -1 +1,50 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: !0
|
|
4
|
+
}), Object.defineProperty(exports, "getSecret", {
|
|
5
|
+
enumerable: !0,
|
|
6
|
+
get: function() {
|
|
7
|
+
return getSecret;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
let _config = /*#__PURE__*/ function(obj, nodeInterop) {
|
|
11
|
+
if (obj && obj.__esModule) return obj;
|
|
12
|
+
if (null === obj || "object" != typeof obj && "function" != typeof obj) return {
|
|
13
|
+
default: obj
|
|
14
|
+
};
|
|
15
|
+
var cache = _getRequireWildcardCache(void 0);
|
|
16
|
+
if (cache && cache.has(obj)) return cache.get(obj);
|
|
17
|
+
var newObj = {
|
|
18
|
+
__proto__: null
|
|
19
|
+
}, hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
20
|
+
for(var key in obj)if ("default" !== key && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
21
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
22
|
+
desc && (desc.get || desc.set) ? Object.defineProperty(newObj, key, desc) : newObj[key] = obj[key];
|
|
23
|
+
}
|
|
24
|
+
return newObj.default = obj, cache && cache.set(obj, newObj), newObj;
|
|
25
|
+
}(require("../../config"));
|
|
26
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
27
|
+
if ("function" != typeof WeakMap) return null;
|
|
28
|
+
var cacheBabelInterop = new WeakMap(), cacheNodeInterop = new WeakMap();
|
|
29
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
30
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
31
|
+
})(nodeInterop);
|
|
32
|
+
}
|
|
33
|
+
let getSecret = async (env)=>{
|
|
34
|
+
env = {
|
|
35
|
+
..._config,
|
|
36
|
+
...env ?? {}
|
|
37
|
+
};
|
|
38
|
+
try {
|
|
39
|
+
if (!_config.AWS_SECRETS_MANAGER_ENABLED) {
|
|
40
|
+
let awsSecretManager = require('./aws-secret-manager');
|
|
41
|
+
env = {
|
|
42
|
+
...env,
|
|
43
|
+
...await new awsSecretManager.AWSSecretManager().get()
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return env;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
return env;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
@@ -1 +1,71 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: !0
|
|
4
|
+
}), Object.defineProperty(exports, "CsvStorage", {
|
|
5
|
+
enumerable: !0,
|
|
6
|
+
get: function() {
|
|
7
|
+
return CsvStorage;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
let _common = require("@nestjs/common"), _exceptionhelper = require("../../helpers/exception.helper"), _storageservice = require("./storage.service");
|
|
11
|
+
function _ts_metadata(k, v) {
|
|
12
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
13
|
+
}
|
|
14
|
+
let CsvStorage = class CsvStorage {
|
|
15
|
+
storageService;
|
|
16
|
+
EXPIRES_IN = 1800;
|
|
17
|
+
constructor(storageService){
|
|
18
|
+
this.storageService = storageService;
|
|
19
|
+
}
|
|
20
|
+
async create({ header, body, delimiter = ',' }) {
|
|
21
|
+
let result = [
|
|
22
|
+
header
|
|
23
|
+
];
|
|
24
|
+
for (let b of body)result.push(b);
|
|
25
|
+
return result.map((d)=>d.map((o)=>(o ?? '').includes(delimiter) ? `"${o}"` : o).join(delimiter)).join('\n');
|
|
26
|
+
}
|
|
27
|
+
async upload(params) {
|
|
28
|
+
let file = await this.create(params);
|
|
29
|
+
return await this.storageService.upload(params.path + '.csv', file, this.EXPIRES_IN), await this.storageService.get(params.path + '.csv');
|
|
30
|
+
}
|
|
31
|
+
async read(buffer, delimiter = ',') {
|
|
32
|
+
let { rows } = this._parseCsvBuffer(buffer, delimiter);
|
|
33
|
+
return rows.map((row)=>row.split(delimiter).map((value)=>value.trim()));
|
|
34
|
+
}
|
|
35
|
+
async readWithHeaders(buffer, dtoClass, delimiter = ',') {
|
|
36
|
+
let { headers, rows } = this._parseCsvBuffer(buffer, delimiter);
|
|
37
|
+
return this._validateCsvHeaders(headers, dtoClass), this._mapRowsToObjects(headers, rows, delimiter);
|
|
38
|
+
}
|
|
39
|
+
_parseCsvBuffer(buffer, delimiter) {
|
|
40
|
+
let [headerRow, ...rows] = buffer.toString('utf-8').split('\n').filter(Boolean);
|
|
41
|
+
return {
|
|
42
|
+
headers: headerRow.split(delimiter).map((value)=>value.trim()),
|
|
43
|
+
rows
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
_validateCsvHeaders(headers, dtoClass) {
|
|
47
|
+
let expectedHeaders = dtoClass.csvHeader(), missingHeaders = expectedHeaders.filter((field)=>!headers.includes(field)), unexpectedHeaders = headers.filter((header)=>!expectedHeaders.includes(header));
|
|
48
|
+
if (missingHeaders.length || unexpectedHeaders.length) {
|
|
49
|
+
let parts = [];
|
|
50
|
+
throw missingHeaders.length && parts.push(`Missing headers: ${missingHeaders.join(', ')}`), unexpectedHeaders.length && parts.push(`Unexpected headers: ${unexpectedHeaders.join(', ')}`), new _exceptionhelper.AppBadRequestException(parts.join('; '));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
_mapRowsToObjects(headers, rows, delimiter) {
|
|
54
|
+
return rows.map((row)=>row.split(delimiter).reduce((acc, value, index)=>{
|
|
55
|
+
let key = headers[index];
|
|
56
|
+
return void 0 !== key && (acc[key] = value.trim()), acc;
|
|
57
|
+
}, {}));
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
CsvStorage = function(decorators, target, key, desc) {
|
|
61
|
+
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
62
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
63
|
+
else for(var i = decorators.length - 1; i >= 0; i--)(d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
|
|
64
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
65
|
+
}([
|
|
66
|
+
(0, _common.Injectable)(),
|
|
67
|
+
_ts_metadata("design:type", Function),
|
|
68
|
+
_ts_metadata("design:paramtypes", [
|
|
69
|
+
void 0 === _storageservice.StorageService ? Object : _storageservice.StorageService
|
|
70
|
+
])
|
|
71
|
+
], CsvStorage);
|
|
@@ -1 +1,57 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: !0
|
|
4
|
+
}), Object.defineProperty(exports, "ExcelService", {
|
|
5
|
+
enumerable: !0,
|
|
6
|
+
get: function() {
|
|
7
|
+
return ExcelService;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
let _common = require("@nestjs/common"), _exceljs = require("exceljs"), _storageservice = require("./storage.service");
|
|
11
|
+
function _ts_metadata(k, v) {
|
|
12
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
13
|
+
}
|
|
14
|
+
let ExcelService = class ExcelService {
|
|
15
|
+
storageService;
|
|
16
|
+
constructor(storageService){
|
|
17
|
+
this.storageService = storageService;
|
|
18
|
+
}
|
|
19
|
+
static validate(maxSize = 1_024_000) {
|
|
20
|
+
return new _common.ParseFilePipeBuilder().addFileTypeValidator({
|
|
21
|
+
fileType: '.(vnd.openxmlformats-officedocument.spreadsheetml.sheet|xlsx)',
|
|
22
|
+
skipMagicNumbersValidation: !0
|
|
23
|
+
}).addMaxSizeValidator({
|
|
24
|
+
maxSize,
|
|
25
|
+
message: (max)=>`Max file size is ${Math.ceil(max / 1024)} MB`
|
|
26
|
+
}).build({
|
|
27
|
+
errorHttpStatusCode: _common.HttpStatus.BAD_REQUEST
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async read(file) {
|
|
31
|
+
try {
|
|
32
|
+
return await new _exceljs.Workbook().xlsx.load(file.buffer);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
throw new _common.UnsupportedMediaTypeException('File is not valid .xlsx');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async create({ title, header, body }) {
|
|
38
|
+
let wb = new _exceljs.Workbook(), ws = wb.addWorksheet(title);
|
|
39
|
+
return ws.addRow(header), body.length > 0 && ws.addRows(body), await wb.xlsx.writeBuffer();
|
|
40
|
+
}
|
|
41
|
+
async upload(path, params) {
|
|
42
|
+
let file = await this.create(params);
|
|
43
|
+
return await this.storageService.upload(path + '.xlsx', file);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
ExcelService = function(decorators, target, key, desc) {
|
|
47
|
+
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
48
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
49
|
+
else for(var i = decorators.length - 1; i >= 0; i--)(d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
|
|
50
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
51
|
+
}([
|
|
52
|
+
(0, _common.Injectable)(),
|
|
53
|
+
_ts_metadata("design:type", Function),
|
|
54
|
+
_ts_metadata("design:paramtypes", [
|
|
55
|
+
void 0 === _storageservice.StorageService ? Object : _storageservice.StorageService
|
|
56
|
+
])
|
|
57
|
+
], ExcelService);
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
function _export_star(from, to) {
|
|
3
|
+
return Object.keys(from).forEach(function(k) {
|
|
4
|
+
"default" === k || Object.prototype.hasOwnProperty.call(to, k) || Object.defineProperty(to, k, {
|
|
5
|
+
enumerable: !0,
|
|
6
|
+
get: function() {
|
|
7
|
+
return from[k];
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
}), from;
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(exports, "__esModule", {
|
|
13
|
+
value: !0
|
|
14
|
+
}), _export_star(require("./storage.contract"), exports), _export_star(require("./storage.module"), exports), _export_star(require("./storage.service"), exports);
|