@triproject/nestjs-core 1.0.28 → 1.0.30

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 (68) hide show
  1. package/dist/bootstrap.js +39 -1
  2. package/dist/config.js +257 -1
  3. package/dist/controllers/controller.js +53 -1
  4. package/dist/drivers/cache/cache.js +79 -1
  5. package/dist/drivers/cache/cache.module.js +30 -1
  6. package/dist/drivers/cache/index.js +14 -1
  7. package/dist/drivers/cache/redis.js +76 -1
  8. package/dist/drivers/db/db.helper.d.ts +1 -1
  9. package/dist/drivers/db/db.helper.js +276 -1
  10. package/dist/drivers/db/db.module.js +64 -1
  11. package/dist/drivers/db/db.service.js +52 -1
  12. package/dist/drivers/db/index.js +14 -1
  13. package/dist/drivers/db/migration.js +119 -1
  14. package/dist/drivers/db/repository.js +258 -1
  15. package/dist/drivers/encryptions/encryption.js +55 -1
  16. package/dist/drivers/encryptions/encryption.module.js +34 -1
  17. package/dist/drivers/encryptions/index.js +14 -1
  18. package/dist/drivers/encryptions/jwt.js +62 -1
  19. package/dist/drivers/encryptions/password-hash.js +48 -1
  20. package/dist/drivers/encryptions/snap.signature.js +111 -1
  21. package/dist/drivers/logger/app.logger.js +121 -2
  22. package/dist/drivers/logger/cloudwatch.js +73 -1
  23. package/dist/drivers/logger/index.js +12 -1
  24. package/dist/drivers/logger/logger.contract.js +29 -1
  25. package/dist/drivers/logger/logger.driver.js +49 -1
  26. package/dist/drivers/logger/slack.logger.js +42 -1
  27. package/dist/drivers/mail/index.js +14 -1
  28. package/dist/drivers/mail/mail-template.js +39 -6
  29. package/dist/drivers/mail/mail.config.js +10 -1
  30. package/dist/drivers/mail/mail.js +58 -13
  31. package/dist/drivers/mail/mail.module.js +36 -1
  32. package/dist/drivers/mail/mail.queue.js +45 -1
  33. package/dist/drivers/mail/mailer.js +64 -1
  34. package/dist/drivers/message-broker/index.js +14 -1
  35. package/dist/drivers/message-broker/kafka.js +104 -1
  36. package/dist/drivers/message-broker/message-broker.contract.js +24 -1
  37. package/dist/drivers/message-broker/message-broker.module.js +28 -1
  38. package/dist/drivers/message-broker/message.broker.js +67 -1
  39. package/dist/drivers/message-broker/rabbitmq.js +115 -1
  40. package/dist/drivers/notifications/index.js +14 -1
  41. package/dist/drivers/notifications/notification.config.js +10 -1
  42. package/dist/drivers/notifications/notification.module.js +34 -1
  43. package/dist/drivers/notifications/notification.queue.js +45 -1
  44. package/dist/drivers/notifications/push-notification.js +81 -1
  45. package/dist/drivers/notifications/slack.js +74 -1
  46. package/dist/drivers/queues/app.queue.js +77 -1
  47. package/dist/drivers/queues/index.js +14 -1
  48. package/dist/drivers/queues/queue.module.js +51 -1
  49. package/dist/drivers/secret-manager/aws-secret-manager.js +40 -1
  50. package/dist/drivers/secret-manager/index.js +50 -1
  51. package/dist/drivers/storage/csv.storage.js +71 -1
  52. package/dist/drivers/storage/excel.storage.js +57 -1
  53. package/dist/drivers/storage/index.js +14 -1
  54. package/dist/drivers/storage/local.storage.js +94 -1
  55. package/dist/drivers/storage/minio.storage.js +82 -1
  56. package/dist/drivers/storage/s3-storage.js +122 -1
  57. package/dist/drivers/storage/storage.contract.js +31 -1
  58. package/dist/drivers/storage/storage.module.js +32 -1
  59. package/dist/drivers/storage/storage.service.js +59 -1
  60. package/dist/helpers/exception.helper.js +132 -1
  61. package/dist/helpers/http.helper.js +163 -1
  62. package/dist/helpers/swagger.helper.js +474 -1
  63. package/dist/index.js +14 -1
  64. package/dist/types.d.js +4 -1
  65. package/dist/utils/redlock.js +51 -1
  66. package/dist/utils/throttle.js +68 -1
  67. package/dist/utils/totp.js +56 -1
  68. package/package.json +13 -11
@@ -1 +1,94 @@
1
- "use strict";var obj;Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"LocalStorageService",{enumerable:!0,get:function(){return LocalStorageService}});let _helpers=require("@triproject/helpers"),_fs=require("fs"),_path=(obj=require("path"))&&obj.__esModule?obj:{default:obj},_exceptionhelper=require("../../helpers/exception.helper"),_secretmanager=require("../secret-manager");let LocalStorageService=class LocalStorageService{expiresIn=3600;BUCKET;constructor(){(0,_secretmanager.getSecret)().then(conf=>{this.BUCKET=conf.S3_BUCKET})}_getPath(relativePath){return _path.default.join(this.BUCKET,relativePath)}async get(path){return{url:this._getPath(path),fileName:(0,_helpers.getFileName)(path)}}async upload(filePath,file){let fullFilePath=this._getPath(filePath);return(0,_fs.mkdirSync)(_path.default.dirname(fullFilePath),{recursive:!0}),(0,_fs.writeFileSync)(fullFilePath,file),this.get(filePath)}async move(oldPath,newPath){let oldFullPath=this._getPath(oldPath),newFullPath=this._getPath(newPath);try{if(await this.isExists(oldFullPath))return(0,_fs.mkdirSync)(_path.default.dirname(newFullPath),{recursive:!0}),(0,_fs.renameSync)(oldFullPath,newFullPath),!0;return!1}catch(error){throw new _exceptionhelper.AppUnprocessableEntityException(`Failed to rename file from ${oldPath} to ${newPath}: ${error?.message}`)}}delete(path){let fullFilePath=this._getPath(path);this._assertFileExists(fullFilePath);try{return(0,_fs.unlinkSync)(fullFilePath),Promise.resolve()}catch(error){throw new _exceptionhelper.AppUnprocessableEntityException(`Failed to delete file ${path}: ${error?.message}`)}}async getBase64(filePath){let fullFilePath=this._getPath(filePath);this._assertFileExists(fullFilePath);try{let base64=(0,_fs.readFileSync)(fullFilePath).toString("base64"),mimeType=this._getMimeType(filePath);return`data:${mimeType};base64,${base64}`}catch(error){throw new _exceptionhelper.AppUnprocessableEntityException(`Failed to get base64 for ${filePath}: ${error?.message}`)}}_getMimeType(filePath){let fullFilePath=this._getPath(filePath);this._assertFileExists(fullFilePath);try{switch(_path.default.extname(filePath).toLowerCase()){case".png":return"image/png";case".jpg":case".jpeg":return"image/jpeg";default:return"application/octet-stream"}}catch(error){throw new _exceptionhelper.AppUnprocessableEntityException(`Failed to get MIME type for ${filePath}: ${error?.message}`)}}async isExists(filePath){try{return(0,_fs.accessSync)(this._getPath(filePath)),!0}catch{return!1}}_assertFileExists(filePath){if(!this.isExists(filePath))throw new _exceptionhelper.AppUnprocessableEntityException(`File not found: ${filePath}`)}};
1
+ "use strict";
2
+ var obj;
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), Object.defineProperty(exports, "LocalStorageService", {
6
+ enumerable: !0,
7
+ get: function() {
8
+ return LocalStorageService;
9
+ }
10
+ });
11
+ let _helpers = require("@triproject/helpers"), _fs = require("fs"), _path = (obj = require("path")) && obj.__esModule ? obj : {
12
+ default: obj
13
+ }, _exceptionhelper = require("../../helpers/exception.helper"), _secretmanager = require("../secret-manager");
14
+ let LocalStorageService = class LocalStorageService {
15
+ expiresIn = 3600;
16
+ BUCKET;
17
+ constructor(){
18
+ (0, _secretmanager.getSecret)().then((conf)=>{
19
+ this.BUCKET = conf.S3_BUCKET;
20
+ });
21
+ }
22
+ _getPath(relativePath) {
23
+ return _path.default.join(this.BUCKET, relativePath);
24
+ }
25
+ async get(path) {
26
+ return {
27
+ url: this._getPath(path),
28
+ fileName: (0, _helpers.getFileName)(path)
29
+ };
30
+ }
31
+ async upload(filePath, file) {
32
+ let fullFilePath = this._getPath(filePath);
33
+ return (0, _fs.mkdirSync)(_path.default.dirname(fullFilePath), {
34
+ recursive: !0
35
+ }), (0, _fs.writeFileSync)(fullFilePath, file), this.get(filePath);
36
+ }
37
+ async move(oldPath, newPath) {
38
+ let oldFullPath = this._getPath(oldPath), newFullPath = this._getPath(newPath);
39
+ try {
40
+ if (await this.isExists(oldFullPath)) return (0, _fs.mkdirSync)(_path.default.dirname(newFullPath), {
41
+ recursive: !0
42
+ }), (0, _fs.renameSync)(oldFullPath, newFullPath), !0;
43
+ return !1;
44
+ } catch (error) {
45
+ throw new _exceptionhelper.AppUnprocessableEntityException(`Failed to rename file from ${oldPath} to ${newPath}: ${error?.message}`);
46
+ }
47
+ }
48
+ delete(path) {
49
+ let fullFilePath = this._getPath(path);
50
+ this._assertFileExists(fullFilePath);
51
+ try {
52
+ return (0, _fs.unlinkSync)(fullFilePath), Promise.resolve();
53
+ } catch (error) {
54
+ throw new _exceptionhelper.AppUnprocessableEntityException(`Failed to delete file ${path}: ${error?.message}`);
55
+ }
56
+ }
57
+ async getBase64(filePath) {
58
+ let fullFilePath = this._getPath(filePath);
59
+ this._assertFileExists(fullFilePath);
60
+ try {
61
+ let base64 = (0, _fs.readFileSync)(fullFilePath).toString('base64'), mimeType = this._getMimeType(filePath);
62
+ return `data:${mimeType};base64,${base64}`;
63
+ } catch (error) {
64
+ throw new _exceptionhelper.AppUnprocessableEntityException(`Failed to get base64 for ${filePath}: ${error?.message}`);
65
+ }
66
+ }
67
+ _getMimeType(filePath) {
68
+ let fullFilePath = this._getPath(filePath);
69
+ this._assertFileExists(fullFilePath);
70
+ try {
71
+ switch(_path.default.extname(filePath).toLowerCase()){
72
+ case '.png':
73
+ return 'image/png';
74
+ case '.jpg':
75
+ case '.jpeg':
76
+ return 'image/jpeg';
77
+ default:
78
+ return 'application/octet-stream';
79
+ }
80
+ } catch (error) {
81
+ throw new _exceptionhelper.AppUnprocessableEntityException(`Failed to get MIME type for ${filePath}: ${error?.message}`);
82
+ }
83
+ }
84
+ async isExists(filePath) {
85
+ try {
86
+ return (0, _fs.accessSync)(this._getPath(filePath)), !0;
87
+ } catch {
88
+ return !1;
89
+ }
90
+ }
91
+ _assertFileExists(filePath) {
92
+ if (!this.isExists(filePath)) throw new _exceptionhelper.AppUnprocessableEntityException(`File not found: ${filePath}`);
93
+ }
94
+ };
@@ -1 +1,82 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"MinioStorage",{enumerable:!0,get:function(){return MinioStorage}});let _helpers=require("@triproject/helpers"),_minio=require("minio"),_exceptionhelper=require("../../helpers/exception.helper"),_secretmanager=require("../secret-manager");let MinioStorage=class MinioStorage{expiresIn;client;BUCKET;constructor(){(0,_secretmanager.getSecret)().then(secret=>{if(!secret.MINIO_HOST)throw new _exceptionhelper.AppUnprocessableEntityException("MINIO_HOST is not defined in secret manager.");this.BUCKET=this.BUCKET,this.client=new _minio.Client({endPoint:secret.MINIO_HOST,port:+secret.MINIO_PORT,useSSL:secret.MINIO_USE_SSL,accessKey:secret.S3_ACCESS_KEY_ID,secretKey:secret.S3_SECRET_ACCESS_KEY})})}async get(fileName,expiresIn=86400){if(!fileName)throw new _exceptionhelper.AppUnprocessableEntityException("File name is required to get URL.");let ext=(0,_helpers.getFileExtension)(fileName),isImage=["png","jpg","jpeg","gif","webp","svg","ico","jpeg","bmp"].includes(ext);return{url:await this.client.presignedUrl("GET",this.BUCKET,fileName,expiresIn,(0,_helpers.removeEmptyValues)({"Content-Type":isImage?"image":void 0,"Content-Disposition":isImage?`inline; filename="${fileName}"`:void 0,"response-content-type":isImage?"image/"+ext:void 0})).catch(()=>""),fileName:(0,_helpers.getFileName)(fileName)}}async upload(fileName,file,expiresIn){return await this.client.putObject(this.BUCKET,fileName,file),expiresIn&&await this.client.presignedPutObject(this.BUCKET,fileName,expiresIn),await this.get(fileName,expiresIn)}async delete(path){return await this.client.removeObject(this.BUCKET,path)}async isExists(fileName){return await this.client.getObject(this.BUCKET,fileName).then(()=>!0).catch(()=>!1)}async move(oldPath,newPath){let copyConditions=new _minio.CopyConditions;try{return await this.client.copyObject(this.BUCKET,newPath,`${this.BUCKET}/${oldPath}`,copyConditions),await this.client.removeObject(this.BUCKET,oldPath),!0}catch(error){return!1}}async getBase64(fileName){return this.stream(fileName,buffer=>`${buffer.toString("base64")}`)}async stream(fileName,processFn){try{let stream=await this.client.getObject(this.BUCKET,fileName),chunks=[],mimeType="application/octet-stream";return new Promise((resolve,reject)=>{stream.on("data",chunk=>chunks.push(chunk)),stream.on("end",()=>{let buffer=Buffer.concat(chunks);mimeType=stream.headers?.["content-type"]||mimeType,resolve(processFn(buffer,mimeType))}),stream.on("error",err=>reject(err))})}catch(error){throw Error(`Failed to process file ${fileName}: ${error.message}`)}}};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: !0
4
+ }), Object.defineProperty(exports, "MinioStorage", {
5
+ enumerable: !0,
6
+ get: function() {
7
+ return MinioStorage;
8
+ }
9
+ });
10
+ let _helpers = require("@triproject/helpers"), _minio = require("minio"), _exceptionhelper = require("../../helpers/exception.helper"), _secretmanager = require("../secret-manager");
11
+ let MinioStorage = class MinioStorage {
12
+ expiresIn;
13
+ client;
14
+ BUCKET;
15
+ constructor(){
16
+ (0, _secretmanager.getSecret)().then((secret)=>{
17
+ if (!secret.MINIO_HOST) throw new _exceptionhelper.AppUnprocessableEntityException('MINIO_HOST is not defined in secret manager.');
18
+ this.BUCKET = this.BUCKET, this.client = new _minio.Client({
19
+ endPoint: secret.MINIO_HOST,
20
+ port: +secret.MINIO_PORT,
21
+ useSSL: secret.MINIO_USE_SSL,
22
+ accessKey: secret.S3_ACCESS_KEY_ID,
23
+ secretKey: secret.S3_SECRET_ACCESS_KEY
24
+ });
25
+ });
26
+ }
27
+ async get(fileName, expiresIn = 86400) {
28
+ if (!fileName) throw new _exceptionhelper.AppUnprocessableEntityException('File name is required to get URL.');
29
+ let ext = (0, _helpers.getFileExtension)(fileName), isImage = [
30
+ 'png',
31
+ 'jpg',
32
+ 'jpeg',
33
+ 'gif',
34
+ 'webp',
35
+ 'svg',
36
+ 'ico',
37
+ 'jpeg',
38
+ 'bmp'
39
+ ].includes(ext);
40
+ return {
41
+ url: await this.client.presignedUrl('GET', this.BUCKET, fileName, expiresIn, (0, _helpers.removeEmptyValues)({
42
+ 'Content-Type': isImage ? 'image' : void 0,
43
+ 'Content-Disposition': isImage ? `inline; filename="${fileName}"` : void 0,
44
+ 'response-content-type': isImage ? 'image/' + ext : void 0
45
+ })).catch(()=>''),
46
+ fileName: (0, _helpers.getFileName)(fileName)
47
+ };
48
+ }
49
+ async upload(fileName, file, expiresIn) {
50
+ return await this.client.putObject(this.BUCKET, fileName, file), expiresIn && await this.client.presignedPutObject(this.BUCKET, fileName, expiresIn), await this.get(fileName, expiresIn);
51
+ }
52
+ async delete(path) {
53
+ return await this.client.removeObject(this.BUCKET, path);
54
+ }
55
+ async isExists(fileName) {
56
+ return await this.client.getObject(this.BUCKET, fileName).then(()=>!0).catch(()=>!1);
57
+ }
58
+ async move(oldPath, newPath) {
59
+ let copyConditions = new _minio.CopyConditions();
60
+ try {
61
+ return await this.client.copyObject(this.BUCKET, newPath, `${this.BUCKET}/${oldPath}`, copyConditions), await this.client.removeObject(this.BUCKET, oldPath), !0;
62
+ } catch (error) {
63
+ return !1;
64
+ }
65
+ }
66
+ async getBase64(fileName) {
67
+ return this.stream(fileName, (buffer)=>`${buffer.toString('base64')}`);
68
+ }
69
+ async stream(fileName, processFn) {
70
+ try {
71
+ let stream = await this.client.getObject(this.BUCKET, fileName), chunks = [], mimeType = 'application/octet-stream';
72
+ return new Promise((resolve, reject)=>{
73
+ stream.on('data', (chunk)=>chunks.push(chunk)), stream.on('end', ()=>{
74
+ let buffer = Buffer.concat(chunks);
75
+ mimeType = stream.headers?.['content-type'] || mimeType, resolve(processFn(buffer, mimeType));
76
+ }), stream.on('error', (err)=>reject(err));
77
+ });
78
+ } catch (error) {
79
+ throw Error(`Failed to process file ${fileName}: ${error.message}`);
80
+ }
81
+ }
82
+ };
@@ -1 +1,122 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"S3Storage",{enumerable:!0,get:function(){return S3Storage}});let _clients3=require("@aws-sdk/client-s3"),_s3requestpresigner=require("@aws-sdk/s3-request-presigner"),_helpers=require("@triproject/helpers"),_exceptionhelper=require("../../helpers/exception.helper"),_secretmanager=require("../secret-manager");let S3Storage=class S3Storage{client;BUCKET;expiresIn=3600;constructor(){(0,_secretmanager.getSecret)().then(secret=>{"s3"===secret.STORAGE_DRIVER&&(this.BUCKET=secret.S3_BUCKET,this.client=new _clients3.S3Client({region:secret.S3_REGION,credentials:{accessKeyId:secret.S3_ACCESS_KEY_ID,secretAccessKey:secret.S3_SECRET_ACCESS_KEY}}))})}async get(path,ttl=this.expiresIn){if(!this.client)throw new _exceptionhelper.AppUnprocessableEntityException("S3 Client is not initialized yet");let ext=(0,_helpers.getFileExtension)(path),isImage=["png","jpg","jpeg","gif","webp","svg","ico","jpeg"].includes(ext),command=new _clients3.GetObjectCommand((0,_helpers.removeEmptyValues)({Bucket:this.BUCKET,Key:path,ResponseContentType:isImage?"image/"+ext:void 0}));return{url:await (0,_s3requestpresigner.getSignedUrl)(this.client,command,{expiresIn:ttl??this.expiresIn}),fileName:(0,_helpers.getFileName)(path)}}async upload(path,file,expiresIn){if(!this.client)throw new _exceptionhelper.AppUnprocessableEntityException("S3 Client is not initialized yet");return new _clients3.PutObjectCommand({Bucket:this.BUCKET,Key:path,Body:file,Expires:expiresIn?new Date(Date.now()+1e3*expiresIn):void 0}),await this.get(path)}async delete(path){if(!this.client)throw new _exceptionhelper.AppUnprocessableEntityException("S3 Client is not initialized yet");try{this.client.send(new _clients3.DeleteObjectCommand({Bucket:this.BUCKET,Key:path}))}catch(error){throw new _exceptionhelper.AppUnprocessableEntityException(`Failed to delete file ${path}: ${error?.message}`)}}async isExists(path){if(!this.client)throw new _exceptionhelper.AppUnprocessableEntityException("S3 Client is not initialized yet");let command=new _clients3.GetObjectCommand({Bucket:this.BUCKET,Key:path});try{return await this.client.send(command),!0}catch(error){if(error?.name==="NoSuchKey")return!1;throw new _exceptionhelper.AppUnprocessableEntityException(`Failed to check if file exists ${path}: ${error?.message}`)}}async move(oldPath,newPath){if(!this.client)throw new _exceptionhelper.AppUnprocessableEntityException("S3 Client is not initialized yet");try{return await this.client.send(new _clients3.CopyObjectCommand({Bucket:this.BUCKET,CopySource:`${this.BUCKET}/${oldPath}`,Key:newPath})),await this.client.send(new _clients3.DeleteObjectCommand({Bucket:this.BUCKET,Key:oldPath})),!0}catch(error){return!1}}async _getObjectStream(path){if(!this.client)throw new _exceptionhelper.AppUnprocessableEntityException("S3 Client is not initialized yet");let command=new _clients3.GetObjectCommand({Bucket:this.BUCKET,Key:path}),response=await this.client.send(command);return{stream:response.Body,mimeType:response.ContentType||"application/octet-stream"}}async getBase64(path){if(!this.client)throw new _exceptionhelper.AppUnprocessableEntityException("S3 Client is not initialized yet");try{let{stream,mimeType}=await this._getObjectStream(path),chunks=[];return new Promise((resolve,reject)=>{stream.on("data",chunk=>chunks.push(chunk)),stream.on("end",()=>{let base64=Buffer.concat(chunks).toString("base64");resolve(`data:${mimeType};base64,${base64}`)}),stream.on("error",reject)})}catch(error){throw new _exceptionhelper.AppUnprocessableEntityException(`Failed to get base64 for ${path}: ${error?.message}`)}}};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: !0
4
+ }), Object.defineProperty(exports, "S3Storage", {
5
+ enumerable: !0,
6
+ get: function() {
7
+ return S3Storage;
8
+ }
9
+ });
10
+ let _clients3 = require("@aws-sdk/client-s3"), _s3requestpresigner = require("@aws-sdk/s3-request-presigner"), _helpers = require("@triproject/helpers"), _exceptionhelper = require("../../helpers/exception.helper"), _secretmanager = require("../secret-manager");
11
+ let S3Storage = class S3Storage {
12
+ client;
13
+ BUCKET;
14
+ expiresIn = 3600;
15
+ constructor(){
16
+ (0, _secretmanager.getSecret)().then((secret)=>{
17
+ 's3' === secret.STORAGE_DRIVER && (this.BUCKET = secret.S3_BUCKET, this.client = new _clients3.S3Client({
18
+ region: secret.S3_REGION,
19
+ credentials: {
20
+ accessKeyId: secret.S3_ACCESS_KEY_ID,
21
+ secretAccessKey: secret.S3_SECRET_ACCESS_KEY
22
+ }
23
+ }));
24
+ });
25
+ }
26
+ async get(path, ttl = this.expiresIn) {
27
+ if (!this.client) throw new _exceptionhelper.AppUnprocessableEntityException('S3 Client is not initialized yet');
28
+ let ext = (0, _helpers.getFileExtension)(path), isImage = [
29
+ 'png',
30
+ 'jpg',
31
+ 'jpeg',
32
+ 'gif',
33
+ 'webp',
34
+ 'svg',
35
+ 'ico',
36
+ 'jpeg'
37
+ ].includes(ext), command = new _clients3.GetObjectCommand((0, _helpers.removeEmptyValues)({
38
+ Bucket: this.BUCKET,
39
+ Key: path,
40
+ ResponseContentType: isImage ? 'image/' + ext : void 0
41
+ }));
42
+ return {
43
+ url: await (0, _s3requestpresigner.getSignedUrl)(this.client, command, {
44
+ expiresIn: ttl ?? this.expiresIn
45
+ }),
46
+ fileName: (0, _helpers.getFileName)(path)
47
+ };
48
+ }
49
+ async upload(path, file, expiresIn) {
50
+ if (!this.client) throw new _exceptionhelper.AppUnprocessableEntityException('S3 Client is not initialized yet');
51
+ return new _clients3.PutObjectCommand({
52
+ Bucket: this.BUCKET,
53
+ Key: path,
54
+ Body: file,
55
+ Expires: expiresIn ? new Date(Date.now() + 1000 * expiresIn) : void 0
56
+ }), await this.get(path);
57
+ }
58
+ async delete(path) {
59
+ if (!this.client) throw new _exceptionhelper.AppUnprocessableEntityException('S3 Client is not initialized yet');
60
+ try {
61
+ this.client.send(new _clients3.DeleteObjectCommand({
62
+ Bucket: this.BUCKET,
63
+ Key: path
64
+ }));
65
+ } catch (error) {
66
+ throw new _exceptionhelper.AppUnprocessableEntityException(`Failed to delete file ${path}: ${error?.message}`);
67
+ }
68
+ }
69
+ async isExists(path) {
70
+ if (!this.client) throw new _exceptionhelper.AppUnprocessableEntityException('S3 Client is not initialized yet');
71
+ let command = new _clients3.GetObjectCommand({
72
+ Bucket: this.BUCKET,
73
+ Key: path
74
+ });
75
+ try {
76
+ return await this.client.send(command), !0;
77
+ } catch (error) {
78
+ if (error?.name === 'NoSuchKey') return !1;
79
+ throw new _exceptionhelper.AppUnprocessableEntityException(`Failed to check if file exists ${path}: ${error?.message}`);
80
+ }
81
+ }
82
+ async move(oldPath, newPath) {
83
+ if (!this.client) throw new _exceptionhelper.AppUnprocessableEntityException('S3 Client is not initialized yet');
84
+ try {
85
+ return await this.client.send(new _clients3.CopyObjectCommand({
86
+ Bucket: this.BUCKET,
87
+ CopySource: `${this.BUCKET}/${oldPath}`,
88
+ Key: newPath
89
+ })), await this.client.send(new _clients3.DeleteObjectCommand({
90
+ Bucket: this.BUCKET,
91
+ Key: oldPath
92
+ })), !0;
93
+ } catch (error) {
94
+ return !1;
95
+ }
96
+ }
97
+ async _getObjectStream(path) {
98
+ if (!this.client) throw new _exceptionhelper.AppUnprocessableEntityException('S3 Client is not initialized yet');
99
+ let command = new _clients3.GetObjectCommand({
100
+ Bucket: this.BUCKET,
101
+ Key: path
102
+ }), response = await this.client.send(command);
103
+ return {
104
+ stream: response.Body,
105
+ mimeType: response.ContentType || 'application/octet-stream'
106
+ };
107
+ }
108
+ async getBase64(path) {
109
+ if (!this.client) throw new _exceptionhelper.AppUnprocessableEntityException('S3 Client is not initialized yet');
110
+ try {
111
+ let { stream, mimeType } = await this._getObjectStream(path), chunks = [];
112
+ return new Promise((resolve, reject)=>{
113
+ stream.on('data', (chunk)=>chunks.push(chunk)), stream.on('end', ()=>{
114
+ let base64 = Buffer.concat(chunks).toString('base64');
115
+ resolve(`data:${mimeType};base64,${base64}`);
116
+ }), stream.on('error', reject);
117
+ });
118
+ } catch (error) {
119
+ throw new _exceptionhelper.AppUnprocessableEntityException(`Failed to get base64 for ${path}: ${error?.message}`);
120
+ }
121
+ }
122
+ };
@@ -1 +1,31 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"StorageContract",{enumerable:!0,get:function(){return StorageContract}});let _exceptionhelper=require("../../helpers/exception.helper");let StorageContract=class StorageContract{expiresIn;upload(path,file,expiresIn){throw new _exceptionhelper.AppUnprocessableEntityException("Method not implemented.")}get(path,ttl){throw new _exceptionhelper.AppUnprocessableEntityException("Method not implemented.")}isExists(path){throw new _exceptionhelper.AppUnprocessableEntityException("Method not implemented.")}move(oldPath,newPath){throw new _exceptionhelper.AppUnprocessableEntityException("Method not implemented.")}delete(path){throw new _exceptionhelper.AppUnprocessableEntityException("Method not implemented.")}getBase64(path){throw new _exceptionhelper.AppUnprocessableEntityException("Method not implemented.")}};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: !0
4
+ }), Object.defineProperty(exports, "StorageContract", {
5
+ enumerable: !0,
6
+ get: function() {
7
+ return StorageContract;
8
+ }
9
+ });
10
+ let _exceptionhelper = require("../../helpers/exception.helper");
11
+ let StorageContract = class StorageContract {
12
+ expiresIn;
13
+ upload(path, file, expiresIn) {
14
+ throw new _exceptionhelper.AppUnprocessableEntityException('Method not implemented.');
15
+ }
16
+ get(path, ttl) {
17
+ throw new _exceptionhelper.AppUnprocessableEntityException('Method not implemented.');
18
+ }
19
+ isExists(path) {
20
+ throw new _exceptionhelper.AppUnprocessableEntityException('Method not implemented.');
21
+ }
22
+ move(oldPath, newPath) {
23
+ throw new _exceptionhelper.AppUnprocessableEntityException('Method not implemented.');
24
+ }
25
+ delete(path) {
26
+ throw new _exceptionhelper.AppUnprocessableEntityException('Method not implemented.');
27
+ }
28
+ getBase64(path) {
29
+ throw new _exceptionhelper.AppUnprocessableEntityException('Method not implemented.');
30
+ }
31
+ };
@@ -1 +1,32 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"StorageModule",{enumerable:!0,get:function(){return StorageModule}});let _common=require("@nestjs/common"),_csvstorage=require("./csv.storage"),_excelstorage=require("./excel.storage"),_storageservice=require("./storage.service");let StorageModule=class StorageModule{};StorageModule=function(decorators,target,key,desc){var d,c=arguments.length,r=c<3?target:null===desc?desc=Object.getOwnPropertyDescriptor(target,key):desc;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(decorators,target,key,desc);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);return c>3&&r&&Object.defineProperty(target,key,r),r}([(0,_common.Global)(),(0,_common.Module)({providers:[_storageservice.StorageService,_csvstorage.CsvStorage,_excelstorage.ExcelService],exports:[_storageservice.StorageService,_csvstorage.CsvStorage,_excelstorage.ExcelService]})],StorageModule);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: !0
4
+ }), Object.defineProperty(exports, "StorageModule", {
5
+ enumerable: !0,
6
+ get: function() {
7
+ return StorageModule;
8
+ }
9
+ });
10
+ let _common = require("@nestjs/common"), _csvstorage = require("./csv.storage"), _excelstorage = require("./excel.storage"), _storageservice = require("./storage.service");
11
+ let StorageModule = class StorageModule {
12
+ };
13
+ StorageModule = 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
+ providers: [
22
+ _storageservice.StorageService,
23
+ _csvstorage.CsvStorage,
24
+ _excelstorage.ExcelService
25
+ ],
26
+ exports: [
27
+ _storageservice.StorageService,
28
+ _csvstorage.CsvStorage,
29
+ _excelstorage.ExcelService
30
+ ]
31
+ })
32
+ ], StorageModule);
@@ -1 +1,59 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"StorageService",{enumerable:!0,get:function(){return StorageService}});let _common=require("@nestjs/common"),_secretmanager=require("../secret-manager");function _ts_metadata(k,v){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(k,v)}let StorageService=class StorageService{expiresIn;driver;constructor(){(0,_secretmanager.getSecret)().then(secret=>{if("s3"===secret.STORAGE_DRIVER){let{S3Storage}=require("./s3-storage");this.driver=new S3Storage}else if("minio"===secret.STORAGE_DRIVER){let{MinioStorage}=require("./minio.storage");this.driver=new MinioStorage}else{let{LocalStorageService}=require("./local.storage");this.driver=new LocalStorageService}})}upload(path,file,expiresIn){return this.driver.upload(path,file,expiresIn)}get(path,ttl){return this.driver.get(path,ttl)}delete(path){return this.driver.delete(path)}isExists(path){return this.driver.isExists(path)}getBase64(path){return this.driver.getBase64(path)}move(oldPath,newPath){return this.driver.move(oldPath,newPath)}};StorageService=function(decorators,target,key,desc){var d,c=arguments.length,r=c<3?target:null===desc?desc=Object.getOwnPropertyDescriptor(target,key):desc;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(decorators,target,key,desc);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);return c>3&&r&&Object.defineProperty(target,key,r),r}([(0,_common.Injectable)(),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[])],StorageService);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: !0
4
+ }), Object.defineProperty(exports, "StorageService", {
5
+ enumerable: !0,
6
+ get: function() {
7
+ return StorageService;
8
+ }
9
+ });
10
+ let _common = require("@nestjs/common"), _secretmanager = require("../secret-manager");
11
+ function _ts_metadata(k, v) {
12
+ if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
13
+ }
14
+ let StorageService = class StorageService {
15
+ expiresIn;
16
+ driver;
17
+ constructor(){
18
+ (0, _secretmanager.getSecret)().then((secret)=>{
19
+ if ('s3' === secret.STORAGE_DRIVER) {
20
+ let { S3Storage } = require('./s3-storage');
21
+ this.driver = new S3Storage();
22
+ } else if ('minio' === secret.STORAGE_DRIVER) {
23
+ let { MinioStorage } = require('./minio.storage');
24
+ this.driver = new MinioStorage();
25
+ } else {
26
+ let { LocalStorageService } = require('./local.storage');
27
+ this.driver = new LocalStorageService();
28
+ }
29
+ });
30
+ }
31
+ upload(path, file, expiresIn) {
32
+ return this.driver.upload(path, file, expiresIn);
33
+ }
34
+ get(path, ttl) {
35
+ return this.driver.get(path, ttl);
36
+ }
37
+ delete(path) {
38
+ return this.driver.delete(path);
39
+ }
40
+ isExists(path) {
41
+ return this.driver.isExists(path);
42
+ }
43
+ getBase64(path) {
44
+ return this.driver.getBase64(path);
45
+ }
46
+ move(oldPath, newPath) {
47
+ return this.driver.move(oldPath, newPath);
48
+ }
49
+ };
50
+ StorageService = function(decorators, target, key, desc) {
51
+ var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
52
+ if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
53
+ 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);
54
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
55
+ }([
56
+ (0, _common.Injectable)(),
57
+ _ts_metadata("design:type", Function),
58
+ _ts_metadata("design:paramtypes", [])
59
+ ], StorageService);
@@ -1 +1,132 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var target=exports,all={get AppBadGatewayException(){return AppBadGatewayException},get AppBadRequestException(){return AppBadRequestException},get AppConflictException(){return AppConflictException},get AppForbiddenException(){return AppForbiddenException},get AppGatewayTimeoutException(){return AppGatewayTimeoutException},get AppInternalServerErrorException(){return AppInternalServerErrorException},get AppNotFoundException(){return AppNotFoundException},get AppServiceUnavailableException(){return AppServiceUnavailableException},get AppUnauthorizedException(){return AppUnauthorizedException},get AppUnprocessableEntityException(){return AppUnprocessableEntityException}};for(var name in all)Object.defineProperty(target,name,{enumerable:!0,get:Object.getOwnPropertyDescriptor(all,name).get});let _common=require("@nestjs/common");let AppBadRequestException=class AppBadRequestException extends _common.BadRequestException{constructor(err){super({statusCode:400,message:"Bad request",errors:"string"==typeof err?{error:err}:Object.entries(err).reduce((acc,[key,value])=>({...acc,[key]:value}),{})}),this.message=("string"==typeof err?[err]:Object.values(err).flat()).join(", ")}has(str){return this.message.includes(str)}};let AppUnprocessableEntityException=class AppUnprocessableEntityException extends _common.UnprocessableEntityException{constructor(message){super({statusCode:422,message:message||"Unprocessable entity"})}};let AppNotFoundException=class AppNotFoundException extends _common.NotFoundException{constructor(message){super({statusCode:404,message:message||"Not found"})}};let AppForbiddenException=class AppForbiddenException extends _common.ForbiddenException{constructor(message){super({statusCode:403,message:message||"Forbidden"})}};let AppUnauthorizedException=class AppUnauthorizedException extends _common.UnauthorizedException{constructor(message){super({statusCode:401,message:message||"Unauthorized"})}};let AppConflictException=class AppConflictException extends _common.ConflictException{constructor(message){super({statusCode:409,message:message||"Conflict"})}};let AppBadGatewayException=class AppBadGatewayException extends _common.BadGatewayException{constructor(message){super({statusCode:502,message:message||"Bad gateway"})}};let AppGatewayTimeoutException=class AppGatewayTimeoutException extends _common.GatewayTimeoutException{constructor(message){super({statusCode:504,message:message||"Gateway timeout"})}};let AppInternalServerErrorException=class AppInternalServerErrorException extends _common.InternalServerErrorException{constructor(message){super({statusCode:500,message:message||"Internal server error"})}};let AppServiceUnavailableException=class AppServiceUnavailableException extends _common.ServiceUnavailableException{constructor(message){super({statusCode:503,message:message||"Service unavailable"})}};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: !0
4
+ });
5
+ var target = exports, all = {
6
+ get AppBadGatewayException () {
7
+ return AppBadGatewayException;
8
+ },
9
+ get AppBadRequestException () {
10
+ return AppBadRequestException;
11
+ },
12
+ get AppConflictException () {
13
+ return AppConflictException;
14
+ },
15
+ get AppForbiddenException () {
16
+ return AppForbiddenException;
17
+ },
18
+ get AppGatewayTimeoutException () {
19
+ return AppGatewayTimeoutException;
20
+ },
21
+ get AppInternalServerErrorException () {
22
+ return AppInternalServerErrorException;
23
+ },
24
+ get AppNotFoundException () {
25
+ return AppNotFoundException;
26
+ },
27
+ get AppServiceUnavailableException () {
28
+ return AppServiceUnavailableException;
29
+ },
30
+ get AppUnauthorizedException () {
31
+ return AppUnauthorizedException;
32
+ },
33
+ get AppUnprocessableEntityException () {
34
+ return AppUnprocessableEntityException;
35
+ }
36
+ };
37
+ for(var name in all)Object.defineProperty(target, name, {
38
+ enumerable: !0,
39
+ get: Object.getOwnPropertyDescriptor(all, name).get
40
+ });
41
+ let _common = require("@nestjs/common");
42
+ let AppBadRequestException = class AppBadRequestException extends _common.BadRequestException {
43
+ constructor(err){
44
+ super({
45
+ statusCode: 400,
46
+ message: 'Bad request',
47
+ errors: 'string' == typeof err ? {
48
+ error: err
49
+ } : Object.entries(err).reduce((acc, [key, value])=>({
50
+ ...acc,
51
+ [key]: value
52
+ }), {})
53
+ }), this.message = ('string' == typeof err ? [
54
+ err
55
+ ] : Object.values(err).flat()).join(', ');
56
+ }
57
+ has(str) {
58
+ return this.message.includes(str);
59
+ }
60
+ };
61
+ let AppUnprocessableEntityException = class AppUnprocessableEntityException extends _common.UnprocessableEntityException {
62
+ constructor(message){
63
+ super({
64
+ statusCode: 422,
65
+ message: message || 'Unprocessable entity'
66
+ });
67
+ }
68
+ };
69
+ let AppNotFoundException = class AppNotFoundException extends _common.NotFoundException {
70
+ constructor(message){
71
+ super({
72
+ statusCode: 404,
73
+ message: message || 'Not found'
74
+ });
75
+ }
76
+ };
77
+ let AppForbiddenException = class AppForbiddenException extends _common.ForbiddenException {
78
+ constructor(message){
79
+ super({
80
+ statusCode: 403,
81
+ message: message || 'Forbidden'
82
+ });
83
+ }
84
+ };
85
+ let AppUnauthorizedException = class AppUnauthorizedException extends _common.UnauthorizedException {
86
+ constructor(message){
87
+ super({
88
+ statusCode: 401,
89
+ message: message || 'Unauthorized'
90
+ });
91
+ }
92
+ };
93
+ let AppConflictException = class AppConflictException extends _common.ConflictException {
94
+ constructor(message){
95
+ super({
96
+ statusCode: 409,
97
+ message: message || 'Conflict'
98
+ });
99
+ }
100
+ };
101
+ let AppBadGatewayException = class AppBadGatewayException extends _common.BadGatewayException {
102
+ constructor(message){
103
+ super({
104
+ statusCode: 502,
105
+ message: message || 'Bad gateway'
106
+ });
107
+ }
108
+ };
109
+ let AppGatewayTimeoutException = class AppGatewayTimeoutException extends _common.GatewayTimeoutException {
110
+ constructor(message){
111
+ super({
112
+ statusCode: 504,
113
+ message: message || 'Gateway timeout'
114
+ });
115
+ }
116
+ };
117
+ let AppInternalServerErrorException = class AppInternalServerErrorException extends _common.InternalServerErrorException {
118
+ constructor(message){
119
+ super({
120
+ statusCode: 500,
121
+ message: message || 'Internal server error'
122
+ });
123
+ }
124
+ };
125
+ let AppServiceUnavailableException = class AppServiceUnavailableException extends _common.ServiceUnavailableException {
126
+ constructor(message){
127
+ super({
128
+ statusCode: 503,
129
+ message: message || 'Service unavailable'
130
+ });
131
+ }
132
+ };