@resolveio/server-lib 20.7.8 → 20.7.10

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 (50) hide show
  1. package/collections/cron-job.collection.js.map +1 -1
  2. package/collections/email-history.collection.js.map +1 -1
  3. package/collections/email-verified.collection.js.map +1 -1
  4. package/collections/file.collection.js.map +1 -1
  5. package/collections/flag-update.collection.js.map +1 -1
  6. package/collections/flag.collection.js.map +1 -1
  7. package/collections/log-method-latency.collection.js.map +1 -1
  8. package/collections/log-subscription.collection.js.map +1 -1
  9. package/collections/log.collection.js.map +1 -1
  10. package/collections/logged-in-users.collection.js.map +1 -1
  11. package/collections/method-response.collection.js.map +1 -1
  12. package/collections/monitor-cpu.collection.js.map +1 -1
  13. package/collections/monitor-function.collection.js.map +1 -1
  14. package/collections/monitor-memory.collection.js.map +1 -1
  15. package/collections/monitor-mongo.collection.js.map +1 -1
  16. package/collections/notification.collection.js.map +1 -1
  17. package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
  18. package/collections/report-builder-library.collection.js.map +1 -1
  19. package/collections/report-builder-report.collection.js.map +1 -1
  20. package/collections/user-group.collection.js.map +1 -1
  21. package/collections/user.collection.js.map +1 -1
  22. package/cron/cron.d.ts +1 -1
  23. package/cron/cron.js +1 -1
  24. package/cron/cron.js.map +1 -1
  25. package/http/auth.js.map +1 -1
  26. package/http/health.d.ts +1 -1
  27. package/http/health.js +1 -1
  28. package/http/health.js.map +1 -1
  29. package/managers/method.manager.js +1 -1
  30. package/managers/method.manager.js.map +1 -1
  31. package/managers/mongo.manager.d.ts +3 -2
  32. package/managers/mongo.manager.js +1 -1
  33. package/managers/mongo.manager.js.map +1 -1
  34. package/managers/monitor.manager.js.map +1 -1
  35. package/managers/subscription.manager.js.map +1 -1
  36. package/methods/aws.js.map +1 -1
  37. package/methods/cron-jobs.js +1 -1
  38. package/methods/cron-jobs.js.map +1 -1
  39. package/methods/monitor.js.map +1 -1
  40. package/methods/support.js.map +1 -1
  41. package/package.json +1 -1
  42. package/public_api.d.ts +4 -4
  43. package/public_api.js +1 -1
  44. package/public_api.js.map +1 -1
  45. package/publications/cron-jobs.js.map +1 -1
  46. package/publications/files.js.map +1 -1
  47. package/publications/report-builder-reports.js.map +1 -1
  48. package/server-app.js +1 -1
  49. package/server-app.js.map +1 -1
  50. package/util/schema-report-builder.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/methods/aws.ts"],"names":["client_s3_1","require","s3_request_presigner_1","axios_1","simpl_schema_1","file_collection_1","resolveio_server_app_1","common_1","fs","pdfCnt","loadAWSMethods","methodManager","methods","uploadFileAndSave","check","default","fileName","type","String","fileData","fileSize","Number","fileOrder","fileType","compress","Boolean","function","Error","key","Date","now","s3","this","getAWS","maxRetries","attempt","putObject","Bucket","process","env","AWS_S3_BUCKET","Key","Body","Buffer","from","replace","split","ACL","ContentType","ContentDisposition","_b","sent","Files","create","_id","objectIdHexString","__v","name","size","order","backoff_1","Math","pow","console","warn","concat","Promise","resolve","setTimeout","err_1","message","uploadNonPDFFileAndSave","_a","mesage","err_2","uploadNonPDFBufferAndSave","fileDataBuffer","err_3","uploadNonPDFStreamAndSave","createReadStream","err_4","deleteFiles","keys","Array","keys.$","find","$in","files","deleteCnt","length","files_1","__values","files_1_1","next","file","value","deleteOne","deleteObject","err_5","deleteFile","findOne","err_6","err_7","deleteFileWithId","id_file","err_8","err_9","getSignedUrlsAndFilesWithId","ids","ids.$","expires","res","_c","i","getCommand","GetObjectCommand","push","getSignedUrl","expiresIn","apply","fileArray","map","a","getSignedUrlWithId","getSignedUrlUSEast1BucketAndKey","bucket","s3USEast1","getSignedUrls","getDataURIfromURL","url","get","responseType","response","status","contentType","headers","dataBase64","data","toString","emailFile","email","additional_message","findById","callMethod","resPDF","emailMessage","sendEmail","ResolveIOServer","getClientName","filename","path","err_10","exports"],"mappings":"wwDAAAA,a,qFAAAC,QAAA,oBAAA,GACAC,uBAAAD,QAAA,+BA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Q,SAAU,SAAe8E,EAAiBoC,EAAeC,G,sHAC7C,MAAA,CAAA,EAAMxI,kBAAA+C,MAAM0F,SAAStC,CAAO,G,OAEvC,GAAI,EAFAV,EAAOtB,EAAArB,KAAA,GAGV,MAAM,IAAIxB,MAAM,8CAA8C,E,iBAIjD,O,wBAAA,CAAA,EAAMK,KAAK+G,WAAW,eAAgBjD,EAAKlE,IAAK,MAAM,G,cAA/DoH,EAASxE,EAAArB,KAAA,GAGR2C,EAAKpC,KAAO,KACXuF,EAAe,+CAAwE,KAAvBJ,EAA4B,0BAA4BA,EAAqB,KAAO,IAExJ,CAAA,EAAM7G,KAAKkH,UAAUN,EAAOtI,uBAAA6I,gBAAgBC,cAAa,EAAK,WAAatD,EAAKrC,KAAMwF,EAAc,GAAI,CAAC,CACxGI,SAAUvD,EAAKrC,KACf6F,KAAMN,C,GACH,KAAM,EAAE,IANT,CAAA,EAAA,GADD,CAAA,EAAA,G,cAIFxE,EAAArB,KAAA,E,aAQA,OAFI8F,EAAe,kDAA2E,KAAvBJ,EAA4B,0BAA4BA,EAAqB,KAAO,IAE3J,CAAA,EAAM7G,KAAKkH,UAAUN,EAAOtI,uBAAA6I,gBAAgBC,cAAa,EAAK,WAAatD,EAAKrC,KAAMwF,EAAeD,EAAQ,GAAI,KAAM,KAAM,EAAE,G,OAA/HxE,EAAArB,KAAA,E,iBAGD,MAAA,CAAA,EAAO,CAAA,G,OAGP,MAAM,IAAIxB,MAAM,iDAAiD,E,4BAKlE,M,YADI8C,OAAS,4BAA8B8E,EAAI9E,OACzC8E,E,yBAIT,CACF,CA/gBAC,QAAA9I,eAAAA","file":"aws.js","sourcesContent":["import { GetObjectCommand } from '@aws-sdk/client-s3';\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner';\nimport axios from 'axios';\nimport SimpleSchema from 'simpl-schema';\nimport { Files } from '../collections/file.collection';\nimport { AWS, MethodManager } from '../managers/method.manager';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { objectIdHexString } from '../util/common';\nlet fs = require('fs');\nlet pdfCnt = 1000000;\n\nexport function loadAWSMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tuploadFileAndSave: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tfileName: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tfileData: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tfileSize: {\n\t\t\t\t\ttype: Number\n\t\t\t\t},\n\t\t\t\tfileOrder: {\n\t\t\t\t\ttype: Number\n\t\t\t\t},\n\t\t\t\tfileType: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tcompress: {\n\t\t\t\t\ttype: Boolean\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(fileName: string, fileData: string, fileSize: number, fileOrder: number, fileType: string, compress: Boolean) {\n\t\t\t\tif (!fileName) {\n\t\t\t\t\tthrow new Error(\"Invalid File Name provided\");\n\t\t\t\t}\n\n\t\t\t\tlet key = 'uploads/' + Date.now() + '-' + (pdfCnt++) + '-' + fileName;\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\tconst maxRetries = 3;\n\t\t\t\tlet attempt = 0;\n\n\t\t\t\twhile (attempt <= maxRetries) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlet res = await s3.putObject({\n\t\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET,\n\t\t\t\t\t\t\tKey: key,\n\t\t\t\t\t\t\tBody: Buffer.from(fileData.replace('data:' + fileData.split(',')[0].split(':')[1].split(';')[0] + ';base64,', ''), 'base64'), \n\t\t\t\t\t\t\tACL: 'private', \n\t\t\t\t\t\t\tContentType: fileData.split(',')[0].split(':')[1].split(';')[0], \n\t\t\t\t\t\t\tContentDisposition: 'inline'\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (res) {\n\t\t\t\t\t\t\treturn Files.create({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(), __v: 0, name: fileName, size: fileSize, key: key, order: fileOrder, type: fileType\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\tattempt++;\n\t\t\t\t\t\tif (attempt <= maxRetries) {\n\t\t\t\t\t\t\tconst backoff = Math.pow(2, attempt) * 1000;\n\t\t\t\t\t\t\tconsole.warn(`Attempt ${attempt} failed. Retrying in ${backoff / 1000} seconds...`);\n\t\t\t\t\t\t\t// eslint-disable-next-line no-restricted-syntax\n\t\t\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, backoff));\n\t\t\t\t\t\t} \n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthrow new Error(`Error in AWS Upload File And Save: Failed to upload after ${maxRetries} attempts: ${err.message}`);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn null;\n\t\t\t}\n\t\t},\n\t\tuploadNonPDFFileAndSave: {\n\t\t\tcheck: new SimpleSchema({\t\n\t\t\t\tfileName: {\t\n\t\t\t\t\ttype: String\t\n\t\t\t\t},\t\n\t\t\t\tfileData: {\t\n\t\t\t\t\ttype: String\t\n\t\t\t\t},\t\n\t\t\t\tfileSize: {\t\n\t\t\t\t\ttype: Number\t\n\t\t\t\t},\t\n\t\t\t\tfileOrder: {\t\n\t\t\t\t\ttype: Number\t\n\t\t\t\t},\t\n\t\t\t\tfileType: {\t\n\t\t\t\t\ttype: String\t\n\t\t\t\t}\t\n\t\t\t}),\t\n\t\t\tfunction: async function(fileName: string, fileData: string, fileSize: number, fileOrder: number, fileType: string) {\t\n\t\t\t\tif (!fileName) {\n\t\t\t\t\tthrow new Error(\"Invalid File Name provided\");\n\t\t\t\t}\n\n\t\t\t\tlet key = 'uploads/' + Date.now() + '-' + fileName;\t\n\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tlet res = await s3.putObject({\n\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET, \n\t\t\t\t\t\tKey: key, \n\t\t\t\t\t\tBody: Buffer.from(fileData), \n\t\t\t\t\t\tACL: 'private', \n\t\t\t\t\t\tContentType: 'application/gzip', \n\t\t\t\t\t\tContentDisposition: 'inline'\n\t\t\t\t\t});\n\n\t\t\t\t\tif (res) {\n\t\t\t\t\t\treturn Files.create({\t\n\t\t\t\t\t\t\t_id: objectIdHexString(), __v: 0, name: fileName, size: fileSize, key: key, order: fileOrder, type: fileType\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.mesage = 'Error In AWS Upload Non PDF File And Save: ' + err.mesage;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\t\n\t\t},\n\t\tuploadNonPDFBufferAndSave: {\n\t\t\tcheck: new SimpleSchema({\t\n\t\t\t\tfileName: {\t\n\t\t\t\t\ttype: String\t\n\t\t\t\t},\t\n\t\t\t\tfileDataBuffer: {\t\n\t\t\t\t\ttype: Buffer\n\t\t\t\t},\t\n\t\t\t\tfileSize: {\t\n\t\t\t\t\ttype: Number\t\n\t\t\t\t},\t\n\t\t\t\tfileOrder: {\t\n\t\t\t\t\ttype: Number\t\n\t\t\t\t},\t\n\t\t\t\tfileType: {\t\n\t\t\t\t\ttype: String\t\n\t\t\t\t}\t\n\t\t\t}),\t\n\t\t\tfunction: async function(fileName: string, fileDataBuffer, fileSize: number, fileOrder: number, fileType: string) {\t\n\t\t\t\tif (!fileName) {\n\t\t\t\t\tthrow new Error(\"Invalid File Name provided\");\n\t\t\t\t}\n\n\t\t\t\tlet key = 'uploads/' + Date.now() + '-' + fileName;\t\n\t\t\t\t\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\n\t\t\t\ttry {\n\t\t\t\t\tlet res = await s3.putObject({\n\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET, \n\t\t\t\t\t\tKey: key, \n\t\t\t\t\t\tBody: fileDataBuffer, \n\t\t\t\t\t\tACL: 'private', \n\t\t\t\t\t\tContentType: 'application/gzip', \n\t\t\t\t\t\tContentDisposition: 'inline'\n\t\t\t\t\t});\n\n\t\t\t\t\tif (res) {\n\t\t\t\t\t\treturn Files.create({\t\n\t\t\t\t\t\t\t_id: objectIdHexString(), __v: 0, name: fileName, size: fileSize, key: key, order: fileOrder, type: fileType\n\t\t\t\t\t\t});\n\t\t\t\t\t}\t\n\t\t\t\t\telse {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.mesage = 'Error In AWS Upload Non PDF Buffer And Save: ' + err.mesage;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\t\n\t\t},\n\t\tuploadNonPDFStreamAndSave: {\n\t\t\tcheck: new SimpleSchema({\t\n\t\t\t\tfileName: {\t\n\t\t\t\t\ttype: String\t\n\t\t\t\t},\t\n\t\t\t\tfileData: {\t\n\t\t\t\t\ttype: String\t\n\t\t\t\t},\t\n\t\t\t\tfileOrder: {\t\n\t\t\t\t\ttype: Number\t\n\t\t\t\t},\t\n\t\t\t\tfileType: {\t\n\t\t\t\t\ttype: String\t\n\t\t\t\t}\t\n\t\t\t}),\t\n\t\t\tfunction: async function(fileName: string, fileData: string, fileOrder: number, fileType: string) {\t\n\t\t\t\tif (!fileName) {\n\t\t\t\t\tthrow new Error(\"Invalid File Name provided\");\n\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\tlet key = 'uploads/' + Date.now() + '-' + fileName;\t\n\t\t\t\t\t\t\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tlet res = await s3.putObject({\n\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET, \n\t\t\t\t\t\tKey: key, \n\t\t\t\t\t\tBody: fs.createReadStream(fileData), \n\t\t\t\t\t\tACL: 'private', \n\t\t\t\t\t\tContentType: 'application/gzip', \n\t\t\t\t\t\tContentDisposition: 'inline'\n\t\t\t\t\t});\n\n\t\t\t\t\tif (res) {\n\t\t\t\t\t\treturn Files.create({\t\n\t\t\t\t\t\t\t_id: objectIdHexString(), __v: 0, name: fileName, size: 1, key: key, order: fileOrder, type: fileType\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.mesage = 'Error In AWS Upload Non PDF Stream And Save: ' + err.mesage;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\t\n\t\t},\n\t\tdeleteFiles: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tkeys: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'keys.$': {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(keys: string[]) {\t\n\t\t\t\tlet files = await Files.find({key: {$in: keys}});\n\t\n\t\t\t\tlet deleteCnt = files.length;\n\t\n\t\t\t\tfor (let file of files) {\n\t\t\t\t\tawait Files.deleteOne({_id: file._id});\n\t\t\t\t\t\n\t\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\t\t\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlet res = await s3.deleteObject({\n\t\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET, \n\t\t\t\t\t\t\tKey: file.key\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (res) {\n\t\t\t\t\t\t\tdeleteCnt--;\n\t\t\t\t\t\t\tif (!deleteCnt) {\n\t\t\t\t\t\t\t\treturn files.length;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\terr.mesage = 'Error In AWS Delete Files: ' + err.mesage;\n\t\t\t\t\t\tthrow err;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t},\n\t\tdeleteFile: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tkey: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(key: string) {\t\t\n\t\t\t\tlet file = await Files.findOne({key: key});\n\t\n\t\t\t\tif (file) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait Files.deleteOne({_id: file._id});\n\t\t\t\t\t}\n\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\terr.mesage = 'Error In AWS Delete File (Resolve Side): ' + err.mesage;\n\t\t\t\t\t\tthrow err;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tlet res = await s3.deleteObject({\n\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET,\n\t\t\t\t\t\tKey: key\n\t\t\t\t\t});\n\t\t\t\t\t\n\t\t\t\t\treturn res;\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.mesage = 'Error In AWS Delete File (AWS Side): ' + err.mesage;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tdeleteFileWithId: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_file: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(id_file: string) {\n\t\t\t\tlet file = await Files.findOne({_id: id_file});\n\t\n\t\t\t\tif (!file) {\n\t\t\t\t\tthrow new Error('Error in AWS Delete File With ID: Could not find file');\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tawait Files.deleteOne({_id: file._id});\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.mesage = 'Error In AWS Delete File With ID (Resolve Side): ' + err.mesage;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tlet res = await s3.deleteObject({\n\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET,\n\t\t\t\t\t\tKey: file.key\n\t\t\t\t\t});\n\n\t\t\t\t\treturn res;\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.mesage = 'Error In AWS Delete File With ID (AWS Side): ' + err.mesage;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tgetSignedUrlsAndFilesWithId: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tids: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'ids.$': {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\texpires: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(ids: string[], expires: number) {\n\t\t\t\tlet res = [];\n\n\t\t\t\tlet files = await Files.find({_id: {$in: ids}});\n\t\t\t\t\n\t\t\t\tfor (let i = 0; i < files.length; i++) {\n\t\t\t\t\tlet file = files[i];\n\t\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\t\tlet getCommand = new GetObjectCommand({\n\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET, \n\t\t\t\t\t\tKey: file.key\n\t\t\t\t\t});\n\t\t\t\t\tres.push(await getSignedUrl(s3, getCommand, {expiresIn: expires}));\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn {res: res, fileArray: files.map(a => a.name)};\n\t\t\t}\n\t\t},\n\t\tgetSignedUrlWithId: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_file: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\texpires: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(id_file: string, expires: number) {\n\t\t\t\tlet file = await Files.findOne({_id: id_file});\n\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\tlet getCommand = new GetObjectCommand({\n\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET, \n\t\t\t\t\tKey: file.key\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\treturn getSignedUrl(s3, getCommand, {expiresIn: expires});\n\t\t\t}\n\t\t},\n\t\tgetSignedUrlUSEast1BucketAndKey: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tbucket: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tkey: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\texpires: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(bucket: string, key: string, expires: number) {\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3USEast1();\n\t\t\t\tlet getCommand = new GetObjectCommand({\n\t\t\t\t\tBucket: bucket, \n\t\t\t\t\tKey: key\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\treturn getSignedUrl(s3, getCommand, {expiresIn: expires});\n\t\t\t}\n\t\t},\n\t\tgetSignedUrl: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tkey: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\texpires: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(key: string, expires: number) {\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\tlet getCommand = new GetObjectCommand({\n\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET, \n\t\t\t\t\tKey: key\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\treturn getSignedUrl(s3, getCommand, {expiresIn: expires});\n\t\t\t}\n\t\t},\n\t\tgetSignedUrls: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tkeys: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'keys.$': {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\texpires: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(keys: string[], expires: number) {\n\t\t\t\tlet res = [];\n\n\t\t\t\tfor (let i = 0; i < keys.length; i++) {\n\t\t\t\t\tlet key = keys[i];\n\t\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\t\tlet getCommand = new GetObjectCommand({\n\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET, \n\t\t\t\t\t\tKey: key\n\t\t\t\t\t});\n\n\t\t\t\t\tres.push(await getSignedUrl(s3, getCommand, {expiresIn: expires}));\n\t\t\t\t}\n\n\t\t\t\treturn res;\n\t\t\t}\n\t\t},\n\t\tgetDataURIfromURL: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\turl: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(url: string) {\n\t\t\t\tconst response = await axios.get(url, {\n\t\t\t\t\tresponseType: 'arraybuffer'\n\t\t\t\t});\n\t\t\t\n\t\t\t\tif (response.status !== 200) {\n\t\t\t\t\tthrow new Error(`Error in Get Data URI From URL: Failed to fetch URL, status: ${response.status}`);\n\t\t\t\t}\n\t\t\t\n\t\t\t\tconst contentType = response.headers['content-type'];\n\t\t\t\tconst dataBase64 = Buffer.from(response.data).toString('base64');\n\t\t\t\treturn `data:${contentType};base64,${dataBase64}`;\n\t\t\t}\n\t\t},\n\t\temailFile: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_file: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\temail: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n additional_message: {\n type: String\n }\n\t\t\t}),\n\t\t\tfunction: async function(id_file: string, email: string, additional_message) {\n\t\t\t\tlet file = await Files.findById(id_file);\n\n\t\t\t\tif (!file) {\n\t\t\t\t\tthrow new Error('Error in AWS Email File: Could not find file');\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tlet resPDF = await this.callMethod('getSignedUrl', file.key, 259200);\n\t\t\t\t\t\n\t\t\t\t\tif (resPDF) {\n\t\t\t\t\t\tif (file.size < 5000000) {\n\t\t\t\t\t\t\tlet emailMessage = 'Attached is the file requested for email.\\n' + (additional_message !== '' ? '\\nAdditional Message:\\n' + additional_message + '\\n' : '') ;\n\n\t\t\t\t\t\t\tawait this.sendEmail(email, ResolveIOServer.getClientName() + ' File - ' + file.name, emailMessage, '', [{\n\t\t\t\t\t\t\t\tfilename: file.name,\n\t\t\t\t\t\t\t\tpath: resPDF\n\t\t\t\t\t\t\t}], null, '');\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tlet emailMessage = 'Please click the link to the requested file.\\n' + (additional_message !== '' ? '\\nAdditional Message:\\n' + additional_message + '\\n' : '') ;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tawait this.sendEmail(email, ResolveIOServer.getClientName() + ' File - ' + file.name, emailMessage + resPDF, '', null, null, '');\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new Error('Error in AWS Email File: Could not get file URL');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.mesage = 'Error In AWS Email File: ' + err.mesage;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t});\n}"]}
1
+ {"version":3,"sources":["../../src/methods/aws.ts"],"names":["client_s3_1","require","s3_request_presigner_1","axios_1","simpl_schema_1","file_collection_1","resolveio_server_app_1","common_1","fs","pdfCnt","loadAWSMethods","methodManager","methods","uploadFileAndSave","check","default","fileName","type","String","fileData","fileSize","Number","fileOrder","fileType","compress","Boolean","function","Error","key","Date","now","s3","this","getAWS","maxRetries","attempt","putObject","Bucket","process","env","AWS_S3_BUCKET","Key","Body","Buffer","from","replace","split","ACL","ContentType","ContentDisposition","_b","sent","Files","create","_id","objectIdHexString","__v","name","size","order","backoff_1","Math","pow","console","warn","concat","Promise","resolve","setTimeout","err_1","message","uploadNonPDFFileAndSave","_a","mesage","err_2","uploadNonPDFBufferAndSave","fileDataBuffer","err_3","uploadNonPDFStreamAndSave","createReadStream","err_4","deleteFiles","keys","Array","keys.$","find","$in","files","deleteCnt","length","files_1","__values","files_1_1","next","file","value","deleteOne","deleteObject","err_5","deleteFile","findOne","err_6","err_7","deleteFileWithId","id_file","err_8","err_9","getSignedUrlsAndFilesWithId","ids","ids.$","expires","res","_c","i","getCommand","GetObjectCommand","push","getSignedUrl","expiresIn","apply","fileArray","map","a","getSignedUrlWithId","getSignedUrlUSEast1BucketAndKey","bucket","s3USEast1","getSignedUrls","getDataURIfromURL","url","get","responseType","response","status","contentType","headers","dataBase64","data","toString","emailFile","email","additional_message","findById","callMethod","resPDF","emailMessage","sendEmail","ResolveIOServer","getClientName","filename","path","err_10","exports"],"mappings":"wwDAAAA,a,qFAAAC,QAAA,oBAAA,GACAC,uBAAAD,QAAA,+BAAA,EACAE,QAAAF,QAAA,OAAA,EACAG,eAAAH,QAAA,cAAA,EACAI,kBAAAJ,QAAA,gCAAA,EAEAK,uBAAAL,QAAA,yBAAA,EACAM,SAAAN,QAAA,gBAAA,EACIO,GAAKP,QAAQ,IAAI,EACjBQ,OAAS,IAEb,SAAgBC,eAAeC,GAC9BA,EAAcC,QAAQ,CACrBC,kBAAmB,CAClBC,MAAO,IAAIV,eAAAW,QAAa,CACvBC,SAAU,CACTC,KAAMC,M,EAEPC,SAAU,CACTF,KAAMC,M,EAEPE,SAAU,CACTH,KAAMI,M,EAEPC,UAAW,CACVL,KAAMI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,EAAM7G,KAAKkH,UAAUN,EAAOtI,uBAAA6I,gBAAgBC,cAAa,EAAK,WAAatD,EAAKrC,KAAMwF,EAAc,GAAI,CAAC,CACxGI,SAAUvD,EAAKrC,KACf6F,KAAMN,C,GACH,KAAM,EAAE,IANT,CAAA,EAAA,GADD,CAAA,EAAA,G,cAIFxE,EAAArB,KAAA,E,aAQA,OAFI8F,EAAe,kDAA2E,KAAvBJ,EAA4B,0BAA4BA,EAAqB,KAAO,IAE3J,CAAA,EAAM7G,KAAKkH,UAAUN,EAAOtI,uBAAA6I,gBAAgBC,cAAa,EAAK,WAAatD,EAAKrC,KAAMwF,EAAeD,EAAQ,GAAI,KAAM,KAAM,EAAE,G,OAA/HxE,EAAArB,KAAA,E,iBAGD,MAAA,CAAA,EAAO,CAAA,G,OAGP,MAAM,IAAIxB,MAAM,iDAAiD,E,4BAKlE,M,YADI8C,OAAS,4BAA8B8E,EAAI9E,OACzC8E,E,yBAIT,CACF,CAhhBAC,QAAA9I,eAAAA","file":"aws.js","sourcesContent":["import { GetObjectCommand } from '@aws-sdk/client-s3';\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner';\nimport axios from 'axios';\nimport SimpleSchema from 'simpl-schema';\nimport { Files } from '../collections/file.collection';\nimport { AWS, MethodManager } from '../managers/method.manager';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { objectIdHexString } from '../util/common';\nlet fs = require('fs');\nlet pdfCnt = 1000000;\n\nexport function loadAWSMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tuploadFileAndSave: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tfileName: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tfileData: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tfileSize: {\n\t\t\t\t\ttype: Number\n\t\t\t\t},\n\t\t\t\tfileOrder: {\n\t\t\t\t\ttype: Number\n\t\t\t\t},\n\t\t\t\tfileType: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tcompress: {\n\t\t\t\t\ttype: Boolean\n\t\t\t\t}\n\t\t\t}),\n\t\t\t// eslint-disable-next-line no-unused-vars\n\t\t\tfunction: async function(fileName: string, fileData: string, fileSize: number, fileOrder: number, fileType: string, compress: Boolean) {\n\t\t\t\tif (!fileName) {\n\t\t\t\t\tthrow new Error(\"Invalid File Name provided\");\n\t\t\t\t}\n\n\t\t\t\tlet key = 'uploads/' + Date.now() + '-' + (pdfCnt++) + '-' + fileName;\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\tconst maxRetries = 3;\n\t\t\t\tlet attempt = 0;\n\n\t\t\t\twhile (attempt <= maxRetries) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlet res = await s3.putObject({\n\t\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET,\n\t\t\t\t\t\t\tKey: key,\n\t\t\t\t\t\t\tBody: Buffer.from(fileData.replace('data:' + fileData.split(',')[0].split(':')[1].split(';')[0] + ';base64,', ''), 'base64'), \n\t\t\t\t\t\t\tACL: 'private', \n\t\t\t\t\t\t\tContentType: fileData.split(',')[0].split(':')[1].split(';')[0], \n\t\t\t\t\t\t\tContentDisposition: 'inline'\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (res) {\n\t\t\t\t\t\t\treturn Files.create({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(), __v: 0, name: fileName, size: fileSize, key: key, order: fileOrder, type: fileType\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\tattempt++;\n\t\t\t\t\t\tif (attempt <= maxRetries) {\n\t\t\t\t\t\t\tconst backoff = Math.pow(2, attempt) * 1000;\n\t\t\t\t\t\t\tconsole.warn(`Attempt ${attempt} failed. Retrying in ${backoff / 1000} seconds...`);\n\t\t\t\t\t\t\t// eslint-disable-next-line no-restricted-syntax\n\t\t\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, backoff));\n\t\t\t\t\t\t} \n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthrow new Error(`Error in AWS Upload File And Save: Failed to upload after ${maxRetries} attempts: ${err.message}`);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn null;\n\t\t\t}\n\t\t},\n\t\tuploadNonPDFFileAndSave: {\n\t\t\tcheck: new SimpleSchema({\t\n\t\t\t\tfileName: {\t\n\t\t\t\t\ttype: String\t\n\t\t\t\t},\t\n\t\t\t\tfileData: {\t\n\t\t\t\t\ttype: String\t\n\t\t\t\t},\t\n\t\t\t\tfileSize: {\t\n\t\t\t\t\ttype: Number\t\n\t\t\t\t},\t\n\t\t\t\tfileOrder: {\t\n\t\t\t\t\ttype: Number\t\n\t\t\t\t},\t\n\t\t\t\tfileType: {\t\n\t\t\t\t\ttype: String\t\n\t\t\t\t}\t\n\t\t\t}),\t\n\t\t\tfunction: async function(fileName: string, fileData: string, fileSize: number, fileOrder: number, fileType: string) {\t\n\t\t\t\tif (!fileName) {\n\t\t\t\t\tthrow new Error(\"Invalid File Name provided\");\n\t\t\t\t}\n\n\t\t\t\tlet key = 'uploads/' + Date.now() + '-' + fileName;\t\n\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tlet res = await s3.putObject({\n\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET, \n\t\t\t\t\t\tKey: key, \n\t\t\t\t\t\tBody: Buffer.from(fileData), \n\t\t\t\t\t\tACL: 'private', \n\t\t\t\t\t\tContentType: 'application/gzip', \n\t\t\t\t\t\tContentDisposition: 'inline'\n\t\t\t\t\t});\n\n\t\t\t\t\tif (res) {\n\t\t\t\t\t\treturn Files.create({\t\n\t\t\t\t\t\t\t_id: objectIdHexString(), __v: 0, name: fileName, size: fileSize, key: key, order: fileOrder, type: fileType\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.mesage = 'Error In AWS Upload Non PDF File And Save: ' + err.mesage;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\t\n\t\t},\n\t\tuploadNonPDFBufferAndSave: {\n\t\t\tcheck: new SimpleSchema({\t\n\t\t\t\tfileName: {\t\n\t\t\t\t\ttype: String\t\n\t\t\t\t},\t\n\t\t\t\tfileDataBuffer: {\t\n\t\t\t\t\ttype: Buffer\n\t\t\t\t},\t\n\t\t\t\tfileSize: {\t\n\t\t\t\t\ttype: Number\t\n\t\t\t\t},\t\n\t\t\t\tfileOrder: {\t\n\t\t\t\t\ttype: Number\t\n\t\t\t\t},\t\n\t\t\t\tfileType: {\t\n\t\t\t\t\ttype: String\t\n\t\t\t\t}\t\n\t\t\t}),\t\n\t\t\tfunction: async function(fileName: string, fileDataBuffer, fileSize: number, fileOrder: number, fileType: string) {\t\n\t\t\t\tif (!fileName) {\n\t\t\t\t\tthrow new Error(\"Invalid File Name provided\");\n\t\t\t\t}\n\n\t\t\t\tlet key = 'uploads/' + Date.now() + '-' + fileName;\t\n\t\t\t\t\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\n\t\t\t\ttry {\n\t\t\t\t\tlet res = await s3.putObject({\n\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET, \n\t\t\t\t\t\tKey: key, \n\t\t\t\t\t\tBody: fileDataBuffer, \n\t\t\t\t\t\tACL: 'private', \n\t\t\t\t\t\tContentType: 'application/gzip', \n\t\t\t\t\t\tContentDisposition: 'inline'\n\t\t\t\t\t});\n\n\t\t\t\t\tif (res) {\n\t\t\t\t\t\treturn Files.create({\t\n\t\t\t\t\t\t\t_id: objectIdHexString(), __v: 0, name: fileName, size: fileSize, key: key, order: fileOrder, type: fileType\n\t\t\t\t\t\t});\n\t\t\t\t\t}\t\n\t\t\t\t\telse {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.mesage = 'Error In AWS Upload Non PDF Buffer And Save: ' + err.mesage;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\t\n\t\t},\n\t\tuploadNonPDFStreamAndSave: {\n\t\t\tcheck: new SimpleSchema({\t\n\t\t\t\tfileName: {\t\n\t\t\t\t\ttype: String\t\n\t\t\t\t},\t\n\t\t\t\tfileData: {\t\n\t\t\t\t\ttype: String\t\n\t\t\t\t},\t\n\t\t\t\tfileOrder: {\t\n\t\t\t\t\ttype: Number\t\n\t\t\t\t},\t\n\t\t\t\tfileType: {\t\n\t\t\t\t\ttype: String\t\n\t\t\t\t}\t\n\t\t\t}),\t\n\t\t\tfunction: async function(fileName: string, fileData: string, fileOrder: number, fileType: string) {\t\n\t\t\t\tif (!fileName) {\n\t\t\t\t\tthrow new Error(\"Invalid File Name provided\");\n\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\tlet key = 'uploads/' + Date.now() + '-' + fileName;\t\n\t\t\t\t\t\t\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tlet res = await s3.putObject({\n\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET, \n\t\t\t\t\t\tKey: key, \n\t\t\t\t\t\tBody: fs.createReadStream(fileData), \n\t\t\t\t\t\tACL: 'private', \n\t\t\t\t\t\tContentType: 'application/gzip', \n\t\t\t\t\t\tContentDisposition: 'inline'\n\t\t\t\t\t});\n\n\t\t\t\t\tif (res) {\n\t\t\t\t\t\treturn Files.create({\t\n\t\t\t\t\t\t\t_id: objectIdHexString(), __v: 0, name: fileName, size: 1, key: key, order: fileOrder, type: fileType\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.mesage = 'Error In AWS Upload Non PDF Stream And Save: ' + err.mesage;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\t\n\t\t},\n\t\tdeleteFiles: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tkeys: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'keys.$': {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(keys: string[]) {\t\n\t\t\t\tlet files = await Files.find({key: {$in: keys}});\n\t\n\t\t\t\tlet deleteCnt = files.length;\n\t\n\t\t\t\tfor (let file of files) {\n\t\t\t\t\tawait Files.deleteOne({_id: file._id});\n\t\t\t\t\t\n\t\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\t\t\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlet res = await s3.deleteObject({\n\t\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET, \n\t\t\t\t\t\t\tKey: file.key\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (res) {\n\t\t\t\t\t\t\tdeleteCnt--;\n\t\t\t\t\t\t\tif (!deleteCnt) {\n\t\t\t\t\t\t\t\treturn files.length;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\terr.mesage = 'Error In AWS Delete Files: ' + err.mesage;\n\t\t\t\t\t\tthrow err;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t},\n\t\tdeleteFile: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tkey: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(key: string) {\t\t\n\t\t\t\tlet file = await Files.findOne({key: key});\n\t\n\t\t\t\tif (file) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait Files.deleteOne({_id: file._id});\n\t\t\t\t\t}\n\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\terr.mesage = 'Error In AWS Delete File (Resolve Side): ' + err.mesage;\n\t\t\t\t\t\tthrow err;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tlet res = await s3.deleteObject({\n\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET,\n\t\t\t\t\t\tKey: key\n\t\t\t\t\t});\n\t\t\t\t\t\n\t\t\t\t\treturn res;\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.mesage = 'Error In AWS Delete File (AWS Side): ' + err.mesage;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tdeleteFileWithId: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_file: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(id_file: string) {\n\t\t\t\tlet file = await Files.findOne({_id: id_file});\n\t\n\t\t\t\tif (!file) {\n\t\t\t\t\tthrow new Error('Error in AWS Delete File With ID: Could not find file');\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tawait Files.deleteOne({_id: file._id});\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.mesage = 'Error In AWS Delete File With ID (Resolve Side): ' + err.mesage;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tlet res = await s3.deleteObject({\n\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET,\n\t\t\t\t\t\tKey: file.key\n\t\t\t\t\t});\n\n\t\t\t\t\treturn res;\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.mesage = 'Error In AWS Delete File With ID (AWS Side): ' + err.mesage;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tgetSignedUrlsAndFilesWithId: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tids: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'ids.$': {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\texpires: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(ids: string[], expires: number) {\n\t\t\t\tlet res = [];\n\n\t\t\t\tlet files = await Files.find({_id: {$in: ids}});\n\t\t\t\t\n\t\t\t\tfor (let i = 0; i < files.length; i++) {\n\t\t\t\t\tlet file = files[i];\n\t\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\t\tlet getCommand = new GetObjectCommand({\n\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET, \n\t\t\t\t\t\tKey: file.key\n\t\t\t\t\t});\n\t\t\t\t\tres.push(await getSignedUrl(s3, getCommand, {expiresIn: expires}));\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn {res: res, fileArray: files.map(a => a.name)};\n\t\t\t}\n\t\t},\n\t\tgetSignedUrlWithId: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_file: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\texpires: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(id_file: string, expires: number) {\n\t\t\t\tlet file = await Files.findOne({_id: id_file});\n\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\tlet getCommand = new GetObjectCommand({\n\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET, \n\t\t\t\t\tKey: file.key\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\treturn getSignedUrl(s3, getCommand, {expiresIn: expires});\n\t\t\t}\n\t\t},\n\t\tgetSignedUrlUSEast1BucketAndKey: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tbucket: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tkey: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\texpires: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(bucket: string, key: string, expires: number) {\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3USEast1();\n\t\t\t\tlet getCommand = new GetObjectCommand({\n\t\t\t\t\tBucket: bucket, \n\t\t\t\t\tKey: key\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\treturn getSignedUrl(s3, getCommand, {expiresIn: expires});\n\t\t\t}\n\t\t},\n\t\tgetSignedUrl: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tkey: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\texpires: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(key: string, expires: number) {\n\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\tlet getCommand = new GetObjectCommand({\n\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET, \n\t\t\t\t\tKey: key\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\treturn getSignedUrl(s3, getCommand, {expiresIn: expires});\n\t\t\t}\n\t\t},\n\t\tgetSignedUrls: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tkeys: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'keys.$': {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\texpires: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(keys: string[], expires: number) {\n\t\t\t\tlet res = [];\n\n\t\t\t\tfor (let i = 0; i < keys.length; i++) {\n\t\t\t\t\tlet key = keys[i];\n\t\t\t\t\tlet s3 = (<AWS>this.getAWS()).s3();\n\t\t\t\t\tlet getCommand = new GetObjectCommand({\n\t\t\t\t\t\tBucket: process.env.AWS_S3_BUCKET, \n\t\t\t\t\t\tKey: key\n\t\t\t\t\t});\n\n\t\t\t\t\tres.push(await getSignedUrl(s3, getCommand, {expiresIn: expires}));\n\t\t\t\t}\n\n\t\t\t\treturn res;\n\t\t\t}\n\t\t},\n\t\tgetDataURIfromURL: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\turl: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(url: string) {\n\t\t\t\tconst response = await axios.get(url, {\n\t\t\t\t\tresponseType: 'arraybuffer'\n\t\t\t\t});\n\t\t\t\n\t\t\t\tif (response.status !== 200) {\n\t\t\t\t\tthrow new Error(`Error in Get Data URI From URL: Failed to fetch URL, status: ${response.status}`);\n\t\t\t\t}\n\t\t\t\n\t\t\t\tconst contentType = response.headers['content-type'];\n\t\t\t\tconst dataBase64 = Buffer.from(response.data).toString('base64');\n\t\t\t\treturn `data:${contentType};base64,${dataBase64}`;\n\t\t\t}\n\t\t},\n\t\temailFile: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_file: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\temail: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n additional_message: {\n type: String\n }\n\t\t\t}),\n\t\t\tfunction: async function(id_file: string, email: string, additional_message) {\n\t\t\t\tlet file = await Files.findById(id_file);\n\n\t\t\t\tif (!file) {\n\t\t\t\t\tthrow new Error('Error in AWS Email File: Could not find file');\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tlet resPDF = await this.callMethod('getSignedUrl', file.key, 259200);\n\t\t\t\t\t\n\t\t\t\t\tif (resPDF) {\n\t\t\t\t\t\tif (file.size < 5000000) {\n\t\t\t\t\t\t\tlet emailMessage = 'Attached is the file requested for email.\\n' + (additional_message !== '' ? '\\nAdditional Message:\\n' + additional_message + '\\n' : '') ;\n\n\t\t\t\t\t\t\tawait this.sendEmail(email, ResolveIOServer.getClientName() + ' File - ' + file.name, emailMessage, '', [{\n\t\t\t\t\t\t\t\tfilename: file.name,\n\t\t\t\t\t\t\t\tpath: resPDF\n\t\t\t\t\t\t\t}], null, '');\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tlet emailMessage = 'Please click the link to the requested file.\\n' + (additional_message !== '' ? '\\nAdditional Message:\\n' + additional_message + '\\n' : '') ;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tawait this.sendEmail(email, ResolveIOServer.getClientName() + ' File - ' + file.name, emailMessage + resPDF, '', null, null, '');\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new Error('Error in AWS Email File: Could not get file URL');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\terr.mesage = 'Error In AWS Email File: ' + err.mesage;\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t});\n}"]}
@@ -1,2 +1,2 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,n,o,l){return new(o=o||Promise)(function(r,t){function fulfilled(e){try{step(l.next(e))}catch(e){t(e)}}function rejected(e){try{step(l.throw(e))}catch(e){t(e)}}function step(e){var t;e.done?r(e.value):((t=e.value)instanceof o?t:new o(function(e){e(t)})).then(fulfilled,rejected)}step((l=l.apply(e,n||[])).next())})},__generator=this&&this.__generator||function(n,o){var l,a,i,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function verb(r){return function(e){var t=[r,e];if(l)throw new TypeError("Generator is already executing.");for(;u=s&&t[s=0]?0:u;)try{if(l=1,a&&(i=2&t[0]?a.return:t[0]?a.throw||((i=a.return)&&i.call(a),0):a.next)&&!(i=i.call(a,t[1])).done)return i;switch(a=0,(t=i?[2&t[0],i.value]:t)[0]){case 0:case 1:i=t;break;case 4:return u.label++,{value:t[1],done:!1};case 5:u.label++,a=t[1],t=[0];continue;case 7:t=u.ops.pop(),u.trys.pop();continue;default:if(!(i=0<(i=u.trys).length&&i[i.length-1])&&(6===t[0]||2===t[0])){u=0;continue}if(3===t[0]&&(!i||t[1]>i[0]&&t[1]<i[3]))u.label=t[1];else if(6===t[0]&&u.label<i[1])u.label=i[1],i=t;else{if(!(i&&u.label<i[2])){i[2]&&u.ops.pop(),u.trys.pop();continue}u.label=i[2],u.ops.push(t)}}t=o.call(n,u)}catch(e){t=[6,e],a=0}finally{l=i=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}},__values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return{value:(e=e&&n>=e.length?void 0:e)&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},Excel=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.loadCronJobMethods=void 0,require("exceljs")),moment=require("moment-timezone"),simpl_schema_1=require("simpl-schema"),XLSX=require("xlsx"),cron_job_collection_1=require("../collections/cron-job.collection"),file_collection_1=require("../collections/file.collection"),report_builder_report_collection_1=require("../collections/report-builder-report.collection"),common_1=require("../util/common");function loadCronJobMethods(e){e.methods({cronEmailMergedDocsCleanUp:{function:function(){return __awaiter(this,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return[4,file_collection_1.Files.find({$and:[{type:"Email Merged Docs"},{createdAt:{$lte:moment().subtract(1,"day").toDate()}}]})];case 1:return(t=e.sent()).length?[4,this.callMethod("deleteFiles")]:[3,4];case 2:return e.sent(),[4,file_collection_1.Files.deleteMany({_id:{$in:t.map(function(e){return e._id})}})];case 3:e.sent(),e.label=4;case 4:return[2,!0]}})})}},stuckCronJob:{function:function(){return __awaiter(this,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return t=moment().subtract(5,"minutes").toDate(),[4,cron_job_collection_1.CronJobs.find({running:!0,updatedAt:{$lte:t}})];case 1:return(t=e.sent()).length?[4,cron_job_collection_1.CronJobs.updateMany({_id:{$in:t.map(function(e){return e._id})}},{$set:{running:!1}})]:[3,3];case 2:e.sent(),e.label=3;case 3:return[2,!0]}})})}},reportbuilderCronJob:{check:new simpl_schema_1.default({data:{type:Object,blackbox:!0}}),function:function(V){return __awaiter(this,void 0,void 0,function(){var i,r,n,t,Y,o,u,s,f,l,c,a,d,q,m,h,y,g,_,j,p,b,v,C,D,z,I,B,W,E,T,w,O,L,P,A,J,N,Q,$,k,M,S,F,R,G,H,x,X,Z,U;return __generator(this,function(e){switch(e.label){case 0:return[4,report_builder_report_collection_1.ReportBuilderReports.findById(V.id_report)];case 1:if((i=e.sent()).fields_selected.forEach(function(e){var t,r=e.fieldPath.replace(/\.\$/g,"").split(".");e.fieldPathObj=null;for(var n=r.length-1;0<=n;n--)e.fieldPathObj?e.fieldPathObj=((t={})[r[n]]=e.fieldPathObj,t):e.fieldPathObj=((t={})[r[n]]=1,t)}),!(i.fields_selected&&i.fields_selected.length||i.groups_row&&i.groups_row.length))return[3,44];r={},n=0,i.fields_selected.forEach(function(t){t.collection_name===i.collection_root&&(r=(0,common_1.mergeDeep)(r,t.fieldPathObj));var e=i.fields_sort.findIndex(function(e){return e.field===t.id});0<=e&&(i.fields_sort[e].field="f_"+n),t.id="f_"+n,n+=1}),t={},i.fields_sort.length?i.fields_sort.forEach(function(e){e.field.startsWith("gr_")?t["_id."+e.field]="asc"===e.order?1:-1:t[e.field]="asc"===e.order?1:-1}):t=null,Y={limit:0,skip:0,fields:r,sort:t},o=[],i.fields_filter.forEach(function(e){var a=[];e.ors.filter(function(e){return!e.field.includes(".$.")}).forEach(function(n){var e,t,r,o,l;n.condition&&n.field&&(null!==n.value&&(!Array.isArray(n.value)||n.value.length)||"null"===n.condition||"nnull"===n.condition)&&("bw"===n.condition?"Date"===n.fieldType&&n.is_rolling?(t=r=null,"Q1"===n.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().startOf("year").quarter(2).subtract(1,"days").toDate()):"Q2"===n.rolling_interval?(r=moment().startOf("year").quarter(2).toDate(),t=moment().startOf("year").quarter(3).subtract(1,"days").toDate()):"Q3"===n.rolling_interval?(r=moment().startOf("year").quarter(3).toDate(),t=moment().startOf("year").quarter(4).subtract(1,"days").toDate()):"Q4"===n.rolling_interval?(r=moment().startOf("year").quarter(4).toDate(),t=moment().endOf("year").toDate()):"Today"===n.rolling_interval?(r=moment().startOf("day").toDate(),t=moment().endOf("day").toDate()):"Yesterday"===n.rolling_interval?(r=moment().subtract(1,"days").startOf("day").toDate(),t=moment().subtract(1,"days").endOf("day").toDate()):"Week"===n.rolling_interval?(r=moment().startOf("isoWeek").toDate(),t=moment().endOf("day").toDate()):"Last Week"===n.rolling_interval?(t=moment().startOf("isoWeek").subtract(1,"days").toDate(),r=moment(t).startOf("isoWeek").toDate()):"Month"===n.rolling_interval?(r=moment().startOf("month").toDate(),t=moment().endOf("day").toDate()):"Last Month"===n.rolling_interval?(t=moment().startOf("month").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("month").toDate()):"Last 30 Days"===n.rolling_interval?(t=moment().endOf("day").toDate(),r=moment().subtract(30,"days").startOf("day").toDate()):"Quarter"===n.rolling_interval?(r=moment().startOf("year").quarter(moment().quarter()).toDate(),t=moment().endOf("day").toDate()):"Last Quarter"===n.rolling_interval?(t=moment().startOf("year").quarter(moment().quarter()).subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("quarter").toDate()):"Year"===n.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().endOf("day").toDate()):"Last Year"===n.rolling_interval?(t=moment().startOf("year").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("year").toDate()):"All"===n.rolling_interval&&(r=new Date(2017,0,1,0,0,0,0),t=moment().endOf("day").toDate()),t.setHours(23),t.setMinutes(59),t.setSeconds(59),t.setMilliseconds(999),a.push({$and:[((e={})[n.field]={$gte:r},e),((r={})[n.field]={$lte:t},r)]})):a.push({$and:[((e={})[n.field]={$gte:n.value},e),((t={})[n.field]={$lte:n.highValue},t)]}):"nnull"===n.condition?((r=[]).push(((e={})[n.field]={$exists:!0},e)),r.push(((t={})[n.field]={$ne:null},t)),"String"===n.fieldType&&r.push(((e={})[n.field]={$ne:""},e)),a.push({$and:r})):"null"===n.condition?a.push(((t={})[n.field]={$eq:null},t)):Array.isArray(n.value)?"ne"===n.condition?(o=[],n.value.forEach(function(e){var t,r;o.push(((t={})[n.field]=((r={})["$"+n.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<o.length?{$and:o}:o[0])):(l=[],n.value.forEach(function(e){var t,r;l.push(((t={})[n.field]=((r={})["$"+n.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<l.length?{$or:l}:l[0])):a.push(((e={})[n.field]=((r={})["$"+n.condition]=n.value,r),e)))}),a.length&&o.push({$or:a})}),e.label=2;case 2:return e.trys.push([2,43,,44]),[4,this.callMethod("reportBuilderBuildTree",i.collection_root)];case 3:if(!(y=e.sent()))return[3,42];y.layers=[y],l=[],u=[],getTreeLeaves(y.children,l),getTreeLeaves(y.children,u,!0),s=[],f=[],i.fields_filter.forEach(function(e){var a=[];e.ors.filter(function(e){return e.field.includes(".$.")}).forEach(function(n){var e,t,o,l,r=u.find(function(e){return e.fieldPath===n.field});r&&s.push(r),n.condition&&n.field&&(null!==n.value&&(!Array.isArray(n.value)||n.value.length)||"null"===n.condition||"nnull"===n.condition)&&("bw"===n.condition?"Date"===n.fieldType&&n.is_rolling?(t=r=null,"Q1"===n.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().startOf("year").quarter(2).subtract(1,"days").toDate()):"Q2"===n.rolling_interval?(r=moment().startOf("year").quarter(2).toDate(),t=moment().startOf("year").quarter(3).subtract(1,"days").toDate()):"Q3"===n.rolling_interval?(r=moment().startOf("year").quarter(3).toDate(),t=moment().startOf("year").quarter(4).subtract(1,"days").toDate()):"Q4"===n.rolling_interval?(r=moment().startOf("year").quarter(4).toDate(),t=moment().endOf("year").toDate()):"Today"===n.rolling_interval?(r=moment().startOf("day").toDate(),t=moment().endOf("day").toDate()):"Yesterday"===n.rolling_interval?(r=moment().subtract(1,"days").startOf("day").toDate(),t=moment().subtract(1,"days").endOf("day").toDate()):"Week"===n.rolling_interval?(r=moment().startOf("isoWeek").toDate(),t=moment().endOf("day").toDate()):"Last Week"===n.rolling_interval?(t=moment().startOf("isoWeek").subtract(1,"days").toDate(),r=moment(t).startOf("isoWeek").toDate()):"Month"===n.rolling_interval?(r=moment().startOf("month").toDate(),t=moment().endOf("day").toDate()):"Last Month"===n.rolling_interval?(t=moment().startOf("month").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("month").toDate()):"Last 30 Days"===n.rolling_interval?(t=moment().endOf("day").toDate(),r=moment().subtract(30,"days").startOf("day").toDate()):"Quarter"===n.rolling_interval?(r=moment().startOf("year").quarter(moment().quarter()).toDate(),t=moment().endOf("day").toDate()):"Last Quarter"===n.rolling_interval?(t=moment().startOf("year").quarter(moment().quarter()).subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("quarter").toDate()):"Year"===n.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().endOf("day").toDate()):"Last Year"===n.rolling_interval?(t=moment().startOf("year").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("year").toDate()):"All"===n.rolling_interval&&(r=new Date(2017,0,1,0,0,0,0),t=moment().endOf("day").toDate()),t.setHours(23),t.setMinutes(59),t.setSeconds(59),t.setMilliseconds(999),a.push({$and:[((e={})[n.field.replace(/\.\$/g,"")]={$gte:r},e),((r={})[n.field.replace(/\.\$/g,"")]={$lte:t},r)]})):f.push({$and:[((e={})[n.field.replace(/\.\$/g,"")]={$gte:n.value},e),((t={})[n.field.replace(/\.\$/g,"")]={$lte:n.highValue},t)]}):"nnull"===n.condition?((r=[]).push(((e={})[n.field.replace(/\.\$/g,"")]={$exists:!0},e)),r.push(((t={})[n.field.replace(/\.\$/g,"")]={$ne:null},t)),"String"===n.fieldType&&r.push(((e={})[n.field.replace(/\.\$/g,"")]={$ne:""},e)),a.push({$and:r})):"null"===n.condition?a.push(((t={})[n.field.replace(/\.\$/g,"")]={$eq:null},t)):Array.isArray(n.value)?"ne"===n.condition?(o=[],n.value.forEach(function(e){var t,r;o.push(((t={})[n.field.replace(/\.\$/g,"")]=((r={})["$"+n.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<o.length?{$and:o}:o[0])):(l=[],n.value.forEach(function(e){var t,r;l.push(((t={})[n.field.replace(/\.\$/g,"")]=((r={})["$"+n.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<l.length?{$or:l}:l[0])):a.push(((e={})[n.field.replace(/\.\$/g,"")]=((r={})["$"+n.condition]=n.value,r),e)))}),a.length&&f.push({$or:a})}),e.label=4;case 4:return e.trys.push([4,41,,42]),[4,this.callMethod("reportBuilderGetResults",i.type,i.collection_root,Y,o,f,s,i.fields_selected,i.fields_custom,i.groups_row,i.fields_total,i.fields_link,i.id_date_field||null,i.date_interval||null,i.group_type)];case 5:if(!(l=e.sent())||!l[0])return[3,40];if(c=l[0].results,a=l[0].totals,"List"!==i.type)return[3,14];i.fields_selected.filter(function(e){return e.show}).forEach(function(t){"Number"!==t.fieldType&&"Count"!==t.leafValueType||"Number"!==t.leafFormatType?"Number"!==t.fieldType&&"Count"!==t.leafValueType||"String"!==t.leafFormatType?"Number"!==t.fieldType&&"Count"!==t.leafValueType||"Currency"!==t.leafFormatType?"Boolean"!==t.fieldType||t.leafFormatType&&"Boolean"!==t.leafFormatType?"Boolean"===t.fieldType&&"String"===t.leafFormatType?c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=!0===e[t.id]?"Yes":"No"}):"Boolean"===t.fieldType&&"Boolean_Number"===t.leafFormatType?c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=!0===e[t.id]?1:0}):"Date"===t.fieldType&&"Date"===t.leafFormatType?c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("L")}):"Date"===t.fieldType&&"Time"===t.leafFormatType?c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("LT")}):"Date"===t.fieldType&&"DateTime"===t.leafFormatType?c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("MM/DD/YYYY h:mm A")}):"Date"===t.fieldType&&"Date_long"===t.leafFormatType?c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("LL")}):"Date"===t.fieldType&&"DateTime_long"===t.leafFormatType?c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("LLL")}):"Date"===t.fieldType&&"Timestamp"===t.leafFormatType&&c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).toDate().getTime()}):c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=!0===e[t.id]?"True":"False"}):c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=(0,common_1.round)(e[t.id],2).toLocaleString("en-US",{style:"currency",currency:"USD"})}):c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=e[t.id].toLocaleString("en-US",{style:"currency",currency:"USD"})}):c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=e[t.id].toLocaleString()})}),d=[],i.groups_row.forEach(function(e){e.id,e.columnName}),i.fields_selected.filter(function(e){return e.show}).forEach(function(e){e.columnName,e.columnName}),E=XLSX.utils.book_new(),c.forEach(function(t){var r={};i.groups_row.forEach(function(e){Array.isArray(t._id[e.id])?r[e.columnName]=t._id[e.id].join(","):"Number"===e.treeItem.fieldType?r[e.columnName]=t._id[e.id]?"string"==typeof t._id[e.id]?parseFloat(t._id[e.id].replace(/,/g,"").replace(/\$/g,"")):t._id[e.id]:"":r[e.columnName]=t._id[e.id]||""}),i.fields_selected.filter(function(e){return e.show}).forEach(function(e){Array.isArray(t[e.id])?r[e.columnName]=t[e.id].join(","):"Number"===e.fieldType||"Count"===e.leafValueType?r[e.columnName]=t[e.id]?"string"==typeof t[e.id]?parseFloat(t[e.id].replace(/,/g,"").replace(/\$/g,"")):t[e.id]:"":r[e.columnName]=t[e.id]||""}),d.push(r)}),T=XLSX.utils.json_to_sheet(d),XLSX.utils.book_append_sheet(E,T,"RB Data"),q=XLSX.write(E,{bookType:"xlsx",type:"base64"}),e.label=6;case 6:e.trys.push([6,11,12,13]),m=__values(V.emails),h=m.next(),e.label=7;case 7:return h.done?[3,10]:(S=h.value,[4,this.sendEmail(S,this.serverConfig.CLIENT_NAME+" Scheduled Report - "+i.report_name,"","\n\t\t\t\t\t\t\t\t\t\t\t\t<b>"+this.serverConfig.CLIENT_NAME+" Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>"+i.report_name+"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>"+V.user+"<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>",[{filename:i.report_name+"-"+moment().format("MM-DD-YYYY-hh-mm-A")+".xlsx",content:q,encoding:"base64"}],this.serverConfig.MAIL_FROM_REPORTS,"")]);case 8:e.sent(),e.label=9;case 9:return h=m.next(),[3,7];case 10:return[3,13];case 11:return y=e.sent(),G={error:y},[3,13];case 12:try{h&&!h.done&&(H=m.return)&&H.call(m)}finally{if(G)throw G.error}return[7];case 13:return[3,40];case 14:if("Group"!==i.type)return[3,27];for(i.fields_selected.filter(function(e){return e.show}).forEach(function(t){c.forEach(function(e){modifyDataTypeField(i,e,t,1)})}),E=new Excel.Workbook,g=E.addWorksheet("RB_1",{views:[{showGridLines:!1}]}),E.properties.date1904=!1,E.calcProperties.fullCalcOnLoad=!0,_=1,(p=g.getRow(_)).getCell(2).font={name:"Arial",bold:!0,size:14},p.getCell(4).font={name:"Arial",size:14},p.getCell(2).value="Report Name:",p.getCell(4).value=i.report_name,_+=1,(p=g.getRow(_)).getCell(2).font={name:"Arial",bold:!0,size:14},p.getCell(4).font={name:"Arial",size:14},p.getCell(2).value="Run Date:",p.getCell(4).value=moment().format("LLL"),_+=2,p=(0,common_1.deepCopy)(c),j=[],p.forEach(function(e){_=tabGroupExcelRecursive(i,g,_,1,e),tabGroupExcelWidthRecursive(i,1,e,j)}),A=1;A<g.columns.length;A++)g.columns[A].width=j[A-1];p=new Date,e.label=15;case 15:return e.trys.push([15,25,,26]),[4,E.xlsx.writeBuffer()];case 16:$=e.sent(),e.label=17;case 17:e.trys.push([17,22,23,24]),b=__values(V.emails),v=b.next(),e.label=18;case 18:return v.done?[3,21]:(S=v.value,[4,this.sendEmail(S,this.serverConfig.CLIENT_NAME+" Scheduled Report - "+i.report_name,"","\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>"+this.serverConfig.CLIENT_NAME+" Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>"+i.report_name+"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>"+V.user+"<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tHave a great day!<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>",[{filename:"Group_Report_"+i.report_name+"_"+p.getFullYear()+"_"+(p.getMonth()+1)+"_"+p.getDate()+".xlsx",content:$}],this.serverConfig.MAIL_FROM_REPORTS,"")]);case 19:e.sent(),e.label=20;case 20:return v=b.next(),[3,18];case 21:return[3,24];case 22:return x=e.sent(),x={error:x},[3,24];case 23:try{v&&!v.done&&(X=b.return)&&X.call(b)}finally{if(x)throw x.error}return[7];case 24:return[3,26];case 25:return F=e.sent(),console.log("Error writing excel export",F),[3,26];case 26:return[3,40];case 27:if("Dated"!==i.type)return[3,40];if(C=[],D=[],z=[],I=[],B=[],"Quarterly"===i.date_interval)for(c.forEach(function(e){e._id.month<4?e._id.quarter=1:e._id.month<7?e._id.quarter=2:e._id.month<10?e._id.quarter=3:e._id.quarter=4,delete e._id.month}),W=function(e){var t,r=c[e];1<c.filter(function(e){return JSON.stringify(e._id)===JSON.stringify(r._id)}).length&&(t=c.find(function(e){return JSON.stringify(e._id)===JSON.stringify(r._id)}),Object.keys(t).filter(function(e){return"_id"!==e}).forEach(function(e){t[e]+=r[e]}),c.splice(e,1))},A=c.length-1;1<=A;A--)W(A);for((0,common_1.deepCopy)(c).forEach(function(t){delete t._id.day,delete t._id.week,delete t._id.month,delete t._id.quarter,delete t._id.year;var r={};Object.keys(t._id).forEach(function(e){r[e]=t._id[e]}),D.find(function(e){return JSON.stringify(e)===JSON.stringify(r)})||D.push(r)}),(0,common_1.deepCopy)(c).forEach(function(t){Object.keys(t._id).filter(function(e){return"second"!==e&&"hour"!==e&&"minute"!==e&&"day"!==e&&"week"!==e&&"month"!==e&&"quarter"!==e&&"year"!==e}).forEach(function(e){delete t._id[e]});var r={};Object.keys(t._id).forEach(function(e){r[e]=t._id[e]}),C.find(function(e){return JSON.stringify(e)===JSON.stringify(r)})||C.push(r)}),C.forEach(function(e){e.year?"Seconds"===i.date_interval?(e.date=moment.tz({year:e.year,month:e.month-1,day:e.day,hour:e.hour,minute:e.minute,second:e.second},process.env.TZ_CLIENT||"America/Chicago").toDate(),e.dateString=moment(e.date).format("MMM DD YYYY HH:mm:ss")):"Minutes"===i.date_interval?(e.date=moment.tz({year:e.year,month:e.month-1,day:e.day,hour:e.hour,minute:e.minute},process.env.TZ_CLIENT||"America/Chicago").toDate(),e.dateString=moment(e.date).format("MMM DD YYYY HH:mm")):"Hours"===i.date_interval?(e.date=moment.tz({year:e.year,month:e.month-1,day:e.day,hour:e.hour},process.env.TZ_CLIENT||"America/Chicago").toDate(),e.dateString=moment(e.date).format("MMM DD YYYY HH")):"Daily"===i.date_interval?(e.date=moment.tz({year:e.year,month:e.month-1,day:e.day},process.env.TZ_CLIENT||"America/Chicago").toDate(),e.dateString=moment(e.date).format("MMM DD YYYY")):"Weekly"===i.date_interval?(e.date=moment.tz({year:e.year,week:e.week},process.env.TZ_CLIENT||"America/Chicago").day("Monday").toDate(),e.dateLast=moment.tz({year:e.year,week:e.week},process.env.TZ_CLIENT||"America/Chicago").day("Sunday").toDate(),e.dateString="Week #"+e.week+" "+e.year+" ("+moment(e.date).format("MM/DD/YY")+" - "+moment(e.dateLast).format("MM/DD/YY")+")"):"Monthly"===i.date_interval?(e.date=moment.tz({year:e.year,month:e.month-1},process.env.TZ_CLIENT||"America/Chicago").toDate(),e.dateString=moment(e.date).format("MMM YYYY")):"Quarterly"===i.date_interval?(e.date=moment.tz({year:e.year},process.env.TZ_CLIENT||"America/Chicago").quarter(e.quarter).toDate(),e.dateString="Q"+e.quarter+" "+e.year):"Yearly"===i.date_interval&&(e.date=moment.tz({year:e.year},process.env.TZ_CLIENT||"America/Chicago").toDate(),e.dateString=e.year.toString()):e.dateString="No Date"}),(C=C.filter(function(e){return!e.date}).concat(C.filter(function(e){return e.date}).sort(function(e,t){return e.date.getTime()-t.date.getTime()}))).forEach(function(o){var t=[],r={},l={},a={};D.forEach(function(n){var e=c.find(function(t){var r=!0;return Object.keys(n).forEach(function(e){t._id[e]!==n[e]&&(r=!1)}),Object.keys(o).filter(function(e){return"date"!==e&&"dateLast"!==e&&"dateString"!==e}).forEach(function(e){t._id[e]!==o[e]&&(r=!1)}),r});e?(t.push(e),Object.keys(e._id).filter(function(e){return e}).forEach(function(t){i.fields_total.filter(function(e){return e.fields.includes(t)}).length&&(r[t]?r[t]+=e._id[t]:r[t]=e._id[t],l[t]?l[t]+=1:l[t]=1,a[t]=i.fields_total.find(function(e){return e.fields.includes(t)}).type)}),Object.keys(e).filter(function(e){return e&&"_id"!==e}).forEach(function(t){i.fields_total.filter(function(e){return e.fields.includes(t)}).length&&(r[t]?r[t]+=e[t]:r[t]=e[t],l[t]?l[t]+=1:l[t]=1,a[t]=i.fields_total.find(function(e){return e.fields.includes(t)}).type)})):t.push(null)}),Object.keys(a).forEach(function(e){"avg"===a[e]&&(r[e]=r[e]/l[e]),r[e]=(0,common_1.round)(r[e],2)}),B.push(r),z.push(t)}),D.forEach(function(n){var r={},o=c.filter(function(t){var r=!(!Object.keys(n).length||null===n._id);return Object.keys(n).filter(function(e){return"date"!==e&&"dateLast"!==e&&"dateString"!==e&&"second"!==e&&"minute"!==e&&"hour"!==e&&"day"!==e&&"week"!==e&&"month"!==e&&"quarter"!==e&&"year"!==e}).forEach(function(e){t._id[e]!==n[e]&&(r=!1)}),r});i.fields_total.forEach(function(e){e.fields.forEach(function(t){o.length?(r[t]=o.filter(function(e){return e&&e[t]}).map(function(e){return e[t]}).reduce(function(e,t){return e+t},0),"avg"===e.type&&(r[t]=(0,common_1.round)(r[t]/o.length,2))):r[t]=0})}),I.push(r)}),E=new Excel.Workbook,T=E.addWorksheet("Dated_Report",{views:[{showGridLines:!0}]}),E.properties.date1904=!1,E.calcProperties.fullCalcOnLoad=!0,O=w=1,(L=T.getRow(w)).getCell(2).font={name:"Arial",bold:!0,size:14},L.getCell(4).font={name:"Arial",size:14},L.getCell(2).value="Report Name:",L.getCell(4).value=i.report_name,w+=1,(L=T.getRow(w)).getCell(2).font={name:"Arial",bold:!0,size:14},L.getCell(4).font={name:"Arial",size:14},L.getCell(2).value="Run Date:",L.getCell(4).value=moment().format("LLL"),w+=2,L=T.getRow(w),i.groups_row.forEach(function(e){L.getCell(O).value=e.columnName,O++}),i.fields_selected.filter(function(e){return e.show}).forEach(function(e){O++}),i.fields_selected.filter(function(e){return e.show}).forEach(function(){C.forEach(function(e){L.getCell(O).value=e.dateString,O++})}),i.fields_total.forEach(function(e){L.getCell(O).value="Totals - "+(0,common_1.toTitleCase)(e.type),O++}),w+=O=1,L=T.getRow(w),P=function(o){for(var l=D[o],e=0;e<i.fields_selected.filter(function(e){return e.show}).length;e++)!function(t){var e=i.fields_selected.filter(function(e){return e.show})[t];O=1,L=T.getRow(w),i.groups_row.forEach(function(e){L.getCell(O).value=0===t?l[e.id]:"",O++}),L.getCell(O).value=e.columnName,O++;for(var r=0;r<C.length;r++){var n=z[r];n[o]?L.getCell(O).value=n[o][e.id]||"":L.getCell(O).value="",O++}for(r=0;r<i.fields_total.length;r++){i.fields_total[r];L.getCell(O).value=I[o][e.id]||"",O++}w++}(e)},A=0;A<D.length;A++)P(A);if(a)for(A=0;A<i.fields_total.length;A++){for(J=i.fields_total[A],L=T.getRow(w),O=1,L.getCell(O).value=(0,common_1.toTitleCase)(J.type)+" Totals",O+=i.groups_row.length,i.fields_selected.filter(function(e){return e.show}).forEach(function(){O+=1}),C.forEach(function(){O++}),N=0;N<i.fields_selected.filter(function(e){return e.show}).length;N++)Q=i.fields_selected.filter(function(e){return e.show})[N],L.getCell(O).value=a[J.id+"_"+Q.id]||"",O++;w++}e.label=28;case 28:return e.trys.push([28,38,,39]),[4,E.xlsx.writeBuffer()];case 29:$=e.sent(),e.label=30;case 30:e.trys.push([30,35,36,37]),k=__values(V.emails),M=k.next(),e.label=31;case 31:return M.done?[3,34]:(S=M.value,[4,this.sendEmail(S,this.serverConfig.CLIENT_NAME+" Scheduled Report - "+i.report_name,"","\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>".concat(this.serverConfig.CLIENT_NAME," Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>").concat(i.report_name,"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>").concat(V.user,"<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>"),[{filename:i.report_name+"-"+moment().format("MM-DD-YYYY-hh-mm-A")+".xlsx",content:$}],this.serverConfig.MAIL_FROM_REPORTS,"")]);case 32:e.sent(),e.label=33;case 33:return M=k.next(),[3,31];case 34:return[3,37];case 35:return F=e.sent(),Z={error:F},[3,37];case 36:try{M&&!M.done&&(U=k.return)&&U.call(k)}finally{if(Z)throw Z.error}return[7];case 37:return[3,39];case 38:return R=e.sent(),console.log("Error writing excel export",R),[3,39];case 39:return[2,!0];case 40:return[3,42];case 41:throw e.sent();case 42:return[3,44];case 43:throw(R=e.sent()).message="Error in Report Builder Cron Job - Report Builder Build Tree: ".concat(R.message),R;case 44:return[2,!0]}})})}}})}function getTreeLeaves(e,t,r){void 0===r&&(r=!1),e.forEach(function(e){e.isLeaf?t.push(e):e.lookup_collection&&!r||getTreeLeaves(e.children,t,r)})}function modifyDataTypeField(t,e,r,n){function pc(e,t){if(null==e)return"";if("Boolean"===t.fieldType){if(!t.leafFormatType||"Boolean"===t.leafFormatType)return!0===e?"True":"False";if("String"===t.leafFormatType)return!0===e?"Yes":"No";if("Boolean_Number"===t.leafFormatType)return!0===e?1:0}else if("Number"===t.fieldType||"Count"===t.leafValueType){if("Number"===t.leafFormatType)return e.toLocaleString();if("String"===t.leafFormatType)return e.toString();if("Currency"===t.leafFormatType)return(0,common_1.round)(e,2).toLocaleString("en-US",{style:"currency",currency:"USD"})}else if("Date"===t.fieldType)switch(t.leafFormatType){case"Date":return moment(e).format("L");case"Time":return moment(e).format("LT");case"DateTime":return moment(e).format("MM/DD/YYYY h:mm A");case"Date_long":return moment(e).format("LL");case"DateTime_long":return moment(e).format("LLL");case"Timestamp":return moment(e).toDate().getTime();default:return e}return e}var o,l;n<t.groups_row.length?e[o="gr_"+(n+1)]&&e[o].forEach(function(e){modifyDataTypeField(t,e,r,n+1)}):Array.isArray(e[r.id])?e[r.id]=(o=e[r.id],l=r,o.map(function(e){return pc(e,l)})):e[r.id]=pc(e[r.id],r)}function tabGroupExcelRecursive(n,o,l,r,a){var i=o.getRow(l);return r<n.groups_row.length?(i.getCell(2).fill={fgColor:{argb:n.groups_row[r-1].fill_color?n.groups_row[r-1].fill_color.replace("#",""):"ffffff"},type:"pattern",pattern:"solid"},i.getCell(2).font={color:{argb:n.groups_row[r-1].font_color?n.groups_row[r-1].font_color.replace("#",""):"000000"},name:"Arial",bold:!0,size:14},i.getCell(2).value=n.groups_row[r-1].columnName+": "+a._id["gr_"+r],o.mergeCells(i.getCell(2).$col$row+":"+i.getCell(n.fields_selected.filter(function(e){return e.show}).length+1).$col$row),i.getCell(2).border={top:{style:"thick"},left:{style:"thick"},right:{style:"thick"}},n.fields_total.length&&n.fields_total.forEach(function(r){l+=1,i=o.getRow(l),n.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(i.getCell(t+2).value=e.columnName,i.getCell(t+2).font={name:"Arial",bold:!0,size:10}),"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0"),0===t?i.getCell(t+2).border={left:{style:"thick"}}:t===n.fields_selected.filter(function(e){return e.show}).length-1&&(i.getCell(t+2).border={right:{style:"thick"}})})}),n.fields_total.forEach(function(r){l+=1,i=o.getRow(l),n.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(i.getCell(t+2).value=a[r.id+"_"+e.id],i.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0")),0===t?i.getCell(t+2).border={top:{style:"thin"},left:{style:"thick"},bottom:{style:"thick"}}:t===n.fields_selected.filter(function(e){return e.show}).length-1?i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"},right:{style:"thick"}}:i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"}}})}),l+=1,(a=a["gr_"+(r+1)]).forEach(function(e,t){l=tabGroupExcelRecursive(n,o,l,r+1,e)})):(i.getCell(2).fill={fgColor:{argb:n.groups_row[r-1].fill_color?n.groups_row[r-1].fill_color.replace("#",""):"ffffff"},type:"pattern",pattern:"solid"},i.getCell(2).font={color:{argb:n.groups_row[r-1].font_color?n.groups_row[r-1].font_color.replace("#",""):"000000"},name:"Arial",bold:!0,size:12},i.getCell(2).value=n.groups_row[r-1].columnName+": "+a._id["gr_"+r],o.mergeCells(i.getCell(2).$col$row+":"+i.getCell(n.fields_selected.filter(function(e){return e.show}).length+1).$col$row),i.getCell(2).border={top:{style:"thick"},left:{style:"thick"},right:{style:"thick"}},l+=1,i=o.getRow(l),n.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){i.getCell(t+2).value=e.columnName,i.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0"),0===t?i.getCell(t+2).border={left:{style:"thick"}}:t===n.fields_selected.filter(function(e){return e.show}).length-1&&(i.getCell(t+2).border={right:{style:"thick"}})}),a.f_0.forEach(function(e,r){l+=1,i=o.getRow(l),n.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){"Number"===e.fieldType&&"string"==typeof a[e.id][r]&&a[e.id][r]?i.getCell(t+2).value=parseFloat(a[e.id][r].replace(new RegExp(/\,/g),"").replace(new RegExp(/\$/g),"")):i.getCell(t+2).value=a[e.id][r],"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0"),i.getCell(t+2).font={name:"Arial",size:10},0===t?i.getCell(t+2).border={left:{style:"thick"}}:t===n.fields_selected.filter(function(e){return e.show}).length-1&&(i.getCell(t+2).border={right:{style:"thick"}})})}),n.fields_total.forEach(function(r){l+=1,i=o.getRow(l),n.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(i.getCell(t+2).value=a[r.id+"_"+e.id],i.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0")),0===t?i.getCell(t+2).border={top:{style:"thin"},left:{style:"thick"},bottom:{style:"thick"}}:t===n.fields_selected.filter(function(e){return e.show}).length-1?i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"},right:{style:"thick"}}:i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"}}})})),l+1}function tabGroupExcelWidthRecursive(r,n,t,o){return n<r.groups_row.length?(t=t["gr_"+(n+1)]).forEach(function(e,t){o=tabGroupExcelWidthRecursive(r,n+1,e,o)}):r.fields_selected.filter(function(e){return e.show}).forEach(function(r,n){var e;Array.isArray(t[r.id])?t[r.id].forEach(function(e){var t=10;e&&(t=e.length+3),o[n]||(o[n]=Math.max(10,r.columnName.length)),t>o[n]&&(o[n]=t)}):((e=t[r.id])&&(length=e.length+3),o[n]||(o[n]=Math.max(10,r.columnName.length)),length>o[n]&&(o[n]=length))}),o}exports.loadCronJobMethods=loadCronJobMethods;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,n,o,l){return new(o=o||Promise)(function(r,t){function fulfilled(e){try{step(l.next(e))}catch(e){t(e)}}function rejected(e){try{step(l.throw(e))}catch(e){t(e)}}function step(e){var t;e.done?r(e.value):((t=e.value)instanceof o?t:new o(function(e){e(t)})).then(fulfilled,rejected)}step((l=l.apply(e,n||[])).next())})},__generator=this&&this.__generator||function(n,o){var l,a,i,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function verb(r){return function(e){var t=[r,e];if(l)throw new TypeError("Generator is already executing.");for(;u=s&&t[s=0]?0:u;)try{if(l=1,a&&(i=2&t[0]?a.return:t[0]?a.throw||((i=a.return)&&i.call(a),0):a.next)&&!(i=i.call(a,t[1])).done)return i;switch(a=0,(t=i?[2&t[0],i.value]:t)[0]){case 0:case 1:i=t;break;case 4:return u.label++,{value:t[1],done:!1};case 5:u.label++,a=t[1],t=[0];continue;case 7:t=u.ops.pop(),u.trys.pop();continue;default:if(!(i=0<(i=u.trys).length&&i[i.length-1])&&(6===t[0]||2===t[0])){u=0;continue}if(3===t[0]&&(!i||t[1]>i[0]&&t[1]<i[3]))u.label=t[1];else if(6===t[0]&&u.label<i[1])u.label=i[1],i=t;else{if(!(i&&u.label<i[2])){i[2]&&u.ops.pop(),u.trys.pop();continue}u.label=i[2],u.ops.push(t)}}t=o.call(n,u)}catch(e){t=[6,e],a=0}finally{l=i=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}},__values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return{value:(e=e&&n>=e.length?void 0:e)&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},Excel=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.loadCronJobMethods=void 0,require("exceljs")),moment=require("moment-timezone"),simpl_schema_1=require("simpl-schema"),XLSX=require("xlsx"),cron_job_collection_1=require("../collections/cron-job.collection"),file_collection_1=require("../collections/file.collection"),report_builder_report_collection_1=require("../collections/report-builder-report.collection"),common_1=require("../util/common");function loadCronJobMethods(e){e.methods({cronEmailMergedDocsCleanUp:{function:function(){return __awaiter(this,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return[4,file_collection_1.Files.find({$and:[{type:"Email Merged Docs"},{createdAt:{$lte:moment().subtract(1,"day").toDate()}}]})];case 1:return(t=e.sent()).length?[4,this.callMethod("deleteFiles")]:[3,4];case 2:return e.sent(),[4,file_collection_1.Files.deleteMany({_id:{$in:t.map(function(e){return e._id})}})];case 3:e.sent(),e.label=4;case 4:return[2,!0]}})})}},stuckCronJob:{function:function(){return __awaiter(this,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return t=moment().subtract(5,"minutes").toDate(),[4,cron_job_collection_1.CronJobs.find({running:!0,updatedAt:{$lte:t}})];case 1:return(t=e.sent()).length?[4,cron_job_collection_1.CronJobs.updateMany({_id:{$in:t.map(function(e){return e._id})}},{$set:{running:!1}})]:[3,3];case 2:e.sent(),e.label=3;case 3:return[2,!0]}})})}},reportbuilderCronJob:{check:new simpl_schema_1.default({data:{type:Object,blackbox:!0}}),function:function(V){return __awaiter(this,void 0,void 0,function(){var i,r,n,t,Y,o,u,s,f,l,c,a,d,q,m,h,y,g,_,j,p,b,v,C,D,z,I,B,W,T,w,E,O,L,P,A,J,N,Q,$,k,M,S,F,R,G,H,x,X,Z,U;return __generator(this,function(e){switch(e.label){case 0:return[4,report_builder_report_collection_1.ReportBuilderReports.findById(V.id_report)];case 1:if((i=e.sent()).fields_selected.forEach(function(e){var t,r=e.fieldPath.replace(/\.\$/g,"").split(".");e.fieldPathObj=null;for(var n=r.length-1;0<=n;n--)e.fieldPathObj?e.fieldPathObj=((t={})[r[n]]=e.fieldPathObj,t):e.fieldPathObj=((t={})[r[n]]=1,t)}),!(i.fields_selected&&i.fields_selected.length||i.groups_row&&i.groups_row.length))return[3,44];r={},n=0,i.fields_selected.forEach(function(t){t.collection_name===i.collection_root&&(r=(0,common_1.mergeDeep)(r,t.fieldPathObj));var e=i.fields_sort.findIndex(function(e){return e.field===t.id});0<=e&&(i.fields_sort[e].field="f_"+n),t.id="f_"+n,n+=1}),t={},i.fields_sort.length?i.fields_sort.forEach(function(e){e.field.startsWith("gr_")?t["_id."+e.field]="asc"===e.order?1:-1:t[e.field]="asc"===e.order?1:-1}):t=null,Y={limit:0,skip:0,fields:r,sort:t},o=[],i.fields_filter.forEach(function(e){var a=[];e.ors.filter(function(e){return!e.field.includes(".$.")}).forEach(function(n){var e,t,r,o,l;n.condition&&n.field&&(null!==n.value&&(!Array.isArray(n.value)||n.value.length)||"null"===n.condition||"nnull"===n.condition)&&("bw"===n.condition?"Date"===n.fieldType&&n.is_rolling?(t=r=null,"Q1"===n.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().startOf("year").quarter(2).subtract(1,"days").toDate()):"Q2"===n.rolling_interval?(r=moment().startOf("year").quarter(2).toDate(),t=moment().startOf("year").quarter(3).subtract(1,"days").toDate()):"Q3"===n.rolling_interval?(r=moment().startOf("year").quarter(3).toDate(),t=moment().startOf("year").quarter(4).subtract(1,"days").toDate()):"Q4"===n.rolling_interval?(r=moment().startOf("year").quarter(4).toDate(),t=moment().endOf("year").toDate()):"Today"===n.rolling_interval?(r=moment().startOf("day").toDate(),t=moment().endOf("day").toDate()):"Yesterday"===n.rolling_interval?(r=moment().subtract(1,"days").startOf("day").toDate(),t=moment().subtract(1,"days").endOf("day").toDate()):"Week"===n.rolling_interval?(r=moment().startOf("isoWeek").toDate(),t=moment().endOf("day").toDate()):"Last Week"===n.rolling_interval?(t=moment().startOf("isoWeek").subtract(1,"days").toDate(),r=moment(t).startOf("isoWeek").toDate()):"Month"===n.rolling_interval?(r=moment().startOf("month").toDate(),t=moment().endOf("day").toDate()):"Last Month"===n.rolling_interval?(t=moment().startOf("month").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("month").toDate()):"Last 30 Days"===n.rolling_interval?(t=moment().endOf("day").toDate(),r=moment().subtract(30,"days").startOf("day").toDate()):"Quarter"===n.rolling_interval?(r=moment().startOf("year").quarter(moment().quarter()).toDate(),t=moment().endOf("day").toDate()):"Last Quarter"===n.rolling_interval?(t=moment().startOf("year").quarter(moment().quarter()).subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("quarter").toDate()):"Year"===n.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().endOf("day").toDate()):"Last Year"===n.rolling_interval?(t=moment().startOf("year").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("year").toDate()):"All"===n.rolling_interval&&(r=new Date(2017,0,1,0,0,0,0),t=moment().endOf("day").toDate()),t.setHours(23),t.setMinutes(59),t.setSeconds(59),t.setMilliseconds(999),a.push({$and:[((e={})[n.field]={$gte:r},e),((r={})[n.field]={$lte:t},r)]})):a.push({$and:[((e={})[n.field]={$gte:n.value},e),((t={})[n.field]={$lte:n.highValue},t)]}):"nnull"===n.condition?((r=[]).push(((e={})[n.field]={$exists:!0},e)),r.push(((t={})[n.field]={$ne:null},t)),"String"===n.fieldType&&r.push(((e={})[n.field]={$ne:""},e)),a.push({$and:r})):"null"===n.condition?a.push(((t={})[n.field]={$eq:null},t)):Array.isArray(n.value)?"ne"===n.condition?(o=[],n.value.forEach(function(e){var t,r;o.push(((t={})[n.field]=((r={})["$"+n.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<o.length?{$and:o}:o[0])):(l=[],n.value.forEach(function(e){var t,r;l.push(((t={})[n.field]=((r={})["$"+n.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<l.length?{$or:l}:l[0])):a.push(((e={})[n.field]=((r={})["$"+n.condition]=n.value,r),e)))}),a.length&&o.push({$or:a})}),e.label=2;case 2:return e.trys.push([2,43,,44]),[4,this.callMethod("reportBuilderBuildTree",i.collection_root)];case 3:if(!(y=e.sent()))return[3,42];y.layers=[y],l=[],u=[],getTreeLeaves(y.children,l),getTreeLeaves(y.children,u,!0),s=[],f=[],i.fields_filter.forEach(function(e){var a=[];e.ors.filter(function(e){return e.field.includes(".$.")}).forEach(function(n){var e,t,o,l,r=u.find(function(e){return e.fieldPath===n.field});r&&s.push(r),n.condition&&n.field&&(null!==n.value&&(!Array.isArray(n.value)||n.value.length)||"null"===n.condition||"nnull"===n.condition)&&("bw"===n.condition?"Date"===n.fieldType&&n.is_rolling?(t=r=null,"Q1"===n.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().startOf("year").quarter(2).subtract(1,"days").toDate()):"Q2"===n.rolling_interval?(r=moment().startOf("year").quarter(2).toDate(),t=moment().startOf("year").quarter(3).subtract(1,"days").toDate()):"Q3"===n.rolling_interval?(r=moment().startOf("year").quarter(3).toDate(),t=moment().startOf("year").quarter(4).subtract(1,"days").toDate()):"Q4"===n.rolling_interval?(r=moment().startOf("year").quarter(4).toDate(),t=moment().endOf("year").toDate()):"Today"===n.rolling_interval?(r=moment().startOf("day").toDate(),t=moment().endOf("day").toDate()):"Yesterday"===n.rolling_interval?(r=moment().subtract(1,"days").startOf("day").toDate(),t=moment().subtract(1,"days").endOf("day").toDate()):"Week"===n.rolling_interval?(r=moment().startOf("isoWeek").toDate(),t=moment().endOf("day").toDate()):"Last Week"===n.rolling_interval?(t=moment().startOf("isoWeek").subtract(1,"days").toDate(),r=moment(t).startOf("isoWeek").toDate()):"Month"===n.rolling_interval?(r=moment().startOf("month").toDate(),t=moment().endOf("day").toDate()):"Last Month"===n.rolling_interval?(t=moment().startOf("month").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("month").toDate()):"Last 30 Days"===n.rolling_interval?(t=moment().endOf("day").toDate(),r=moment().subtract(30,"days").startOf("day").toDate()):"Quarter"===n.rolling_interval?(r=moment().startOf("year").quarter(moment().quarter()).toDate(),t=moment().endOf("day").toDate()):"Last Quarter"===n.rolling_interval?(t=moment().startOf("year").quarter(moment().quarter()).subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("quarter").toDate()):"Year"===n.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().endOf("day").toDate()):"Last Year"===n.rolling_interval?(t=moment().startOf("year").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("year").toDate()):"All"===n.rolling_interval&&(r=new Date(2017,0,1,0,0,0,0),t=moment().endOf("day").toDate()),t.setHours(23),t.setMinutes(59),t.setSeconds(59),t.setMilliseconds(999),a.push({$and:[((e={})[n.field.replace(/\.\$/g,"")]={$gte:r},e),((r={})[n.field.replace(/\.\$/g,"")]={$lte:t},r)]})):f.push({$and:[((e={})[n.field.replace(/\.\$/g,"")]={$gte:n.value},e),((t={})[n.field.replace(/\.\$/g,"")]={$lte:n.highValue},t)]}):"nnull"===n.condition?((r=[]).push(((e={})[n.field.replace(/\.\$/g,"")]={$exists:!0},e)),r.push(((t={})[n.field.replace(/\.\$/g,"")]={$ne:null},t)),"String"===n.fieldType&&r.push(((e={})[n.field.replace(/\.\$/g,"")]={$ne:""},e)),a.push({$and:r})):"null"===n.condition?a.push(((t={})[n.field.replace(/\.\$/g,"")]={$eq:null},t)):Array.isArray(n.value)?"ne"===n.condition?(o=[],n.value.forEach(function(e){var t,r;o.push(((t={})[n.field.replace(/\.\$/g,"")]=((r={})["$"+n.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<o.length?{$and:o}:o[0])):(l=[],n.value.forEach(function(e){var t,r;l.push(((t={})[n.field.replace(/\.\$/g,"")]=((r={})["$"+n.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<l.length?{$or:l}:l[0])):a.push(((e={})[n.field.replace(/\.\$/g,"")]=((r={})["$"+n.condition]=n.value,r),e)))}),a.length&&f.push({$or:a})}),e.label=4;case 4:return e.trys.push([4,41,,42]),[4,this.callMethod("reportBuilderGetResults",i.type,i.collection_root,Y,o,f,s,i.fields_selected,i.fields_custom,i.groups_row,i.fields_total,i.fields_link,i.id_date_field||null,i.date_interval||null,i.group_type)];case 5:if(!(l=e.sent())||!l[0])return[3,40];if(c=l[0].results,a=l[0].totals,"List"!==i.type)return[3,14];i.fields_selected.filter(function(e){return e.show}).forEach(function(t){"Number"!==t.fieldType&&"Count"!==t.leafValueType||"Number"!==t.leafFormatType?"Number"!==t.fieldType&&"Count"!==t.leafValueType||"String"!==t.leafFormatType?"Number"!==t.fieldType&&"Count"!==t.leafValueType||"Currency"!==t.leafFormatType?"Boolean"!==t.fieldType||t.leafFormatType&&"Boolean"!==t.leafFormatType?"Boolean"===t.fieldType&&"String"===t.leafFormatType?c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=!0===e[t.id]?"Yes":"No"}):"Boolean"===t.fieldType&&"Boolean_Number"===t.leafFormatType?c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=!0===e[t.id]?1:0}):"Date"===t.fieldType&&"Date"===t.leafFormatType?c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("L")}):"Date"===t.fieldType&&"Time"===t.leafFormatType?c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("LT")}):"Date"===t.fieldType&&"DateTime"===t.leafFormatType?c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("MM/DD/YYYY h:mm A")}):"Date"===t.fieldType&&"Date_long"===t.leafFormatType?c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("LL")}):"Date"===t.fieldType&&"DateTime_long"===t.leafFormatType?c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("LLL")}):"Date"===t.fieldType&&"Timestamp"===t.leafFormatType&&c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).toDate().getTime()}):c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=!0===e[t.id]?"True":"False"}):c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=(0,common_1.round)(e[t.id],2).toLocaleString("en-US",{style:"currency",currency:"USD"})}):c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=e[t.id].toLocaleString("en-US",{style:"currency",currency:"USD"})}):c.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=e[t.id].toLocaleString()})}),d=[],i.groups_row.forEach(function(e){e.id,e.columnName}),i.fields_selected.filter(function(e){return e.show}).forEach(function(e){e.columnName,e.columnName}),T=XLSX.utils.book_new(),c.forEach(function(t){var r={};i.groups_row.forEach(function(e){Array.isArray(t._id[e.id])?r[e.columnName]=t._id[e.id].join(","):"Number"===e.treeItem.fieldType?r[e.columnName]=t._id[e.id]?"string"==typeof t._id[e.id]?parseFloat(t._id[e.id].replace(/,/g,"").replace(/\$/g,"")):t._id[e.id]:"":r[e.columnName]=t._id[e.id]||""}),i.fields_selected.filter(function(e){return e.show}).forEach(function(e){Array.isArray(t[e.id])?r[e.columnName]=t[e.id].join(","):"Number"===e.fieldType||"Count"===e.leafValueType?r[e.columnName]=t[e.id]?"string"==typeof t[e.id]?parseFloat(t[e.id].replace(/,/g,"").replace(/\$/g,"")):t[e.id]:"":r[e.columnName]=t[e.id]||""}),d.push(r)}),w=XLSX.utils.json_to_sheet(d),XLSX.utils.book_append_sheet(T,w,"RB Data"),q=XLSX.write(T,{bookType:"xlsx",type:"base64"}),e.label=6;case 6:e.trys.push([6,11,12,13]),m=__values(V.emails),h=m.next(),e.label=7;case 7:return h.done?[3,10]:(S=h.value,[4,this.sendEmail(S,this.serverConfig.CLIENT_NAME+" Scheduled Report - "+i.report_name,"","\n\t\t\t\t\t\t\t\t\t\t\t\t<b>"+this.serverConfig.CLIENT_NAME+" Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>"+i.report_name+"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>"+V.user+"<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>",[{filename:i.report_name+"-"+moment().format("MM-DD-YYYY-hh-mm-A")+".xlsx",content:q,encoding:"base64"}],this.serverConfig.MAIL_FROM_REPORTS,"")]);case 8:e.sent(),e.label=9;case 9:return h=m.next(),[3,7];case 10:return[3,13];case 11:return y=e.sent(),G={error:y},[3,13];case 12:try{h&&!h.done&&(H=m.return)&&H.call(m)}finally{if(G)throw G.error}return[7];case 13:return[3,40];case 14:if("Group"!==i.type)return[3,27];for(i.fields_selected.filter(function(e){return e.show}).forEach(function(t){c.forEach(function(e){modifyDataTypeField(i,e,t,1)})}),T=new Excel.Workbook,g=T.addWorksheet("RB_1",{views:[{showGridLines:!1}]}),T.properties.date1904=!1,T.calcProperties.fullCalcOnLoad=!0,_=1,(p=g.getRow(_)).getCell(2).font={name:"Arial",bold:!0,size:14},p.getCell(4).font={name:"Arial",size:14},p.getCell(2).value="Report Name:",p.getCell(4).value=i.report_name,_+=1,(p=g.getRow(_)).getCell(2).font={name:"Arial",bold:!0,size:14},p.getCell(4).font={name:"Arial",size:14},p.getCell(2).value="Run Date:",p.getCell(4).value=moment().format("LLL"),_+=2,p=(0,common_1.deepCopy)(c),j=[],p.forEach(function(e){_=tabGroupExcelRecursive(i,g,_,1,e),tabGroupExcelWidthRecursive(i,1,e,j)}),A=1;A<g.columns.length;A++)g.columns[A].width=j[A-1];p=new Date,e.label=15;case 15:return e.trys.push([15,25,,26]),[4,T.xlsx.writeBuffer()];case 16:$=e.sent(),e.label=17;case 17:e.trys.push([17,22,23,24]),b=__values(V.emails),v=b.next(),e.label=18;case 18:return v.done?[3,21]:(S=v.value,[4,this.sendEmail(S,this.serverConfig.CLIENT_NAME+" Scheduled Report - "+i.report_name,"","\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>"+this.serverConfig.CLIENT_NAME+" Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>"+i.report_name+"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>"+V.user+"<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tHave a great day!<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>",[{filename:"Group_Report_"+i.report_name+"_"+p.getFullYear()+"_"+(p.getMonth()+1)+"_"+p.getDate()+".xlsx",content:$}],this.serverConfig.MAIL_FROM_REPORTS,"")]);case 19:e.sent(),e.label=20;case 20:return v=b.next(),[3,18];case 21:return[3,24];case 22:return x=e.sent(),x={error:x},[3,24];case 23:try{v&&!v.done&&(X=b.return)&&X.call(b)}finally{if(x)throw x.error}return[7];case 24:return[3,26];case 25:return F=e.sent(),console.log("Error writing excel export",F),[3,26];case 26:return[3,40];case 27:if("Dated"!==i.type)return[3,40];if(C=[],D=[],z=[],I=[],B=[],"Quarterly"===i.date_interval)for(c.forEach(function(e){e._id.month<4?e._id.quarter=1:e._id.month<7?e._id.quarter=2:e._id.month<10?e._id.quarter=3:e._id.quarter=4,delete e._id.month}),W=function(e){var t,r=c[e];1<c.filter(function(e){return JSON.stringify(e._id)===JSON.stringify(r._id)}).length&&(t=c.find(function(e){return JSON.stringify(e._id)===JSON.stringify(r._id)}),Object.keys(t).filter(function(e){return"_id"!==e}).forEach(function(e){t[e]+=r[e]}),c.splice(e,1))},A=c.length-1;1<=A;A--)W(A);for((0,common_1.deepCopy)(c).forEach(function(t){delete t._id.day,delete t._id.week,delete t._id.month,delete t._id.quarter,delete t._id.year;var r={};Object.keys(t._id).forEach(function(e){r[e]=t._id[e]}),D.find(function(e){return JSON.stringify(e)===JSON.stringify(r)})||D.push(r)}),(0,common_1.deepCopy)(c).forEach(function(t){Object.keys(t._id).filter(function(e){return"second"!==e&&"hour"!==e&&"minute"!==e&&"day"!==e&&"week"!==e&&"month"!==e&&"quarter"!==e&&"year"!==e}).forEach(function(e){delete t._id[e]});var r={};Object.keys(t._id).forEach(function(e){r[e]=t._id[e]}),C.find(function(e){return JSON.stringify(e)===JSON.stringify(r)})||C.push(r)}),C.forEach(function(e){e.year?"Seconds"===i.date_interval?(e.date=moment.tz({year:e.year,month:e.month-1,day:e.day,hour:e.hour,minute:e.minute,second:e.second},process.env.TZ_CLIENT||"America/Chicago").toDate(),e.dateString=moment(e.date).format("MMM DD YYYY HH:mm:ss")):"Minutes"===i.date_interval?(e.date=moment.tz({year:e.year,month:e.month-1,day:e.day,hour:e.hour,minute:e.minute},process.env.TZ_CLIENT||"America/Chicago").toDate(),e.dateString=moment(e.date).format("MMM DD YYYY HH:mm")):"Hours"===i.date_interval?(e.date=moment.tz({year:e.year,month:e.month-1,day:e.day,hour:e.hour},process.env.TZ_CLIENT||"America/Chicago").toDate(),e.dateString=moment(e.date).format("MMM DD YYYY HH")):"Daily"===i.date_interval?(e.date=moment.tz({year:e.year,month:e.month-1,day:e.day},process.env.TZ_CLIENT||"America/Chicago").toDate(),e.dateString=moment(e.date).format("MMM DD YYYY")):"Weekly"===i.date_interval?(e.date=moment.tz({year:e.year,week:e.week},process.env.TZ_CLIENT||"America/Chicago").day("Monday").toDate(),e.dateLast=moment.tz({year:e.year,week:e.week},process.env.TZ_CLIENT||"America/Chicago").day("Sunday").toDate(),e.dateString="Week #"+e.week+" "+e.year+" ("+moment(e.date).format("MM/DD/YY")+" - "+moment(e.dateLast).format("MM/DD/YY")+")"):"Monthly"===i.date_interval?(e.date=moment.tz({year:e.year,month:e.month-1},process.env.TZ_CLIENT||"America/Chicago").toDate(),e.dateString=moment(e.date).format("MMM YYYY")):"Quarterly"===i.date_interval?(e.date=moment.tz({year:e.year},process.env.TZ_CLIENT||"America/Chicago").quarter(e.quarter).toDate(),e.dateString="Q"+e.quarter+" "+e.year):"Yearly"===i.date_interval&&(e.date=moment.tz({year:e.year},process.env.TZ_CLIENT||"America/Chicago").toDate(),e.dateString=e.year.toString()):e.dateString="No Date"}),(C=C.filter(function(e){return!e.date}).concat(C.filter(function(e){return e.date}).sort(function(e,t){return e.date.getTime()-t.date.getTime()}))).forEach(function(o){var t=[],r={},l={},a={};D.forEach(function(n){var e=c.find(function(t){var r=!0;return Object.keys(n).forEach(function(e){t._id[e]!==n[e]&&(r=!1)}),Object.keys(o).filter(function(e){return"date"!==e&&"dateLast"!==e&&"dateString"!==e}).forEach(function(e){t._id[e]!==o[e]&&(r=!1)}),r});e?(t.push(e),Object.keys(e._id).filter(function(e){return e}).forEach(function(t){i.fields_total.filter(function(e){return e.fields.includes(t)}).length&&(r[t]?r[t]+=e._id[t]:r[t]=e._id[t],l[t]?l[t]+=1:l[t]=1,a[t]=i.fields_total.find(function(e){return e.fields.includes(t)}).type)}),Object.keys(e).filter(function(e){return e&&"_id"!==e}).forEach(function(t){i.fields_total.filter(function(e){return e.fields.includes(t)}).length&&(r[t]?r[t]+=e[t]:r[t]=e[t],l[t]?l[t]+=1:l[t]=1,a[t]=i.fields_total.find(function(e){return e.fields.includes(t)}).type)})):t.push(null)}),Object.keys(a).forEach(function(e){"avg"===a[e]&&(r[e]=r[e]/l[e]),r[e]=(0,common_1.round)(r[e],2)}),B.push(r),z.push(t)}),D.forEach(function(n){var r={},o=c.filter(function(t){var r=!(!Object.keys(n).length||null===n._id);return Object.keys(n).filter(function(e){return"date"!==e&&"dateLast"!==e&&"dateString"!==e&&"second"!==e&&"minute"!==e&&"hour"!==e&&"day"!==e&&"week"!==e&&"month"!==e&&"quarter"!==e&&"year"!==e}).forEach(function(e){t._id[e]!==n[e]&&(r=!1)}),r});i.fields_total.forEach(function(e){e.fields.forEach(function(t){o.length?(r[t]=o.filter(function(e){return e&&e[t]}).map(function(e){return e[t]}).reduce(function(e,t){return e+t},0),"avg"===e.type&&(r[t]=(0,common_1.round)(r[t]/o.length,2))):r[t]=0})}),I.push(r)}),T=new Excel.Workbook,w=T.addWorksheet("Dated_Report",{views:[{showGridLines:!0}]}),T.properties.date1904=!1,T.calcProperties.fullCalcOnLoad=!0,O=E=1,(L=w.getRow(E)).getCell(2).font={name:"Arial",bold:!0,size:14},L.getCell(4).font={name:"Arial",size:14},L.getCell(2).value="Report Name:",L.getCell(4).value=i.report_name,E+=1,(L=w.getRow(E)).getCell(2).font={name:"Arial",bold:!0,size:14},L.getCell(4).font={name:"Arial",size:14},L.getCell(2).value="Run Date:",L.getCell(4).value=moment().format("LLL"),E+=2,L=w.getRow(E),i.groups_row.forEach(function(e){L.getCell(O).value=e.columnName,O++}),O+=i.fields_selected.filter(function(e){return e.show}).length,i.fields_selected.filter(function(e){return e.show}).forEach(function(){C.forEach(function(e){L.getCell(O).value=e.dateString,O++})}),i.fields_total.forEach(function(e){L.getCell(O).value="Totals - "+(0,common_1.toTitleCase)(e.type),O++}),E+=O=1,L=w.getRow(E),P=function(o){for(var l=D[o],e=0;e<i.fields_selected.filter(function(e){return e.show}).length;e++)!function(t){var e=i.fields_selected.filter(function(e){return e.show})[t];O=1,L=w.getRow(E),i.groups_row.forEach(function(e){L.getCell(O).value=0===t?l[e.id]:"",O++}),L.getCell(O).value=e.columnName,O++;for(var r=0;r<C.length;r++){var n=z[r];n[o]?L.getCell(O).value=n[o][e.id]||"":L.getCell(O).value="",O++}for(r=0;r<i.fields_total.length;r++)L.getCell(O).value=I[o][e.id]||"",O++;E++}(e)},A=0;A<D.length;A++)P(A);if(a)for(A=0;A<i.fields_total.length;A++){for(J=i.fields_total[A],L=w.getRow(E),O=1,L.getCell(O).value=(0,common_1.toTitleCase)(J.type)+" Totals",O+=i.groups_row.length,i.fields_selected.filter(function(e){return e.show}).forEach(function(){O+=1}),C.forEach(function(){O++}),N=0;N<i.fields_selected.filter(function(e){return e.show}).length;N++)Q=i.fields_selected.filter(function(e){return e.show})[N],L.getCell(O).value=a[J.id+"_"+Q.id]||"",O++;E++}e.label=28;case 28:return e.trys.push([28,38,,39]),[4,T.xlsx.writeBuffer()];case 29:$=e.sent(),e.label=30;case 30:e.trys.push([30,35,36,37]),k=__values(V.emails),M=k.next(),e.label=31;case 31:return M.done?[3,34]:(S=M.value,[4,this.sendEmail(S,this.serverConfig.CLIENT_NAME+" Scheduled Report - "+i.report_name,"","\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>".concat(this.serverConfig.CLIENT_NAME," Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>").concat(i.report_name,"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>").concat(V.user,"<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>"),[{filename:i.report_name+"-"+moment().format("MM-DD-YYYY-hh-mm-A")+".xlsx",content:$}],this.serverConfig.MAIL_FROM_REPORTS,"")]);case 32:e.sent(),e.label=33;case 33:return M=k.next(),[3,31];case 34:return[3,37];case 35:return F=e.sent(),Z={error:F},[3,37];case 36:try{M&&!M.done&&(U=k.return)&&U.call(k)}finally{if(Z)throw Z.error}return[7];case 37:return[3,39];case 38:return R=e.sent(),console.log("Error writing excel export",R),[3,39];case 39:return[2,!0];case 40:return[3,42];case 41:throw e.sent();case 42:return[3,44];case 43:throw(R=e.sent()).message="Error in Report Builder Cron Job - Report Builder Build Tree: ".concat(R.message),R;case 44:return[2,!0]}})})}}})}function getTreeLeaves(e,t,r){void 0===r&&(r=!1),e.forEach(function(e){e.isLeaf?t.push(e):e.lookup_collection&&!r||getTreeLeaves(e.children,t,r)})}function modifyDataTypeField(t,e,r,n){function nc(e,t){if(null==e)return"";if("Boolean"===t.fieldType){if(!t.leafFormatType||"Boolean"===t.leafFormatType)return!0===e?"True":"False";if("String"===t.leafFormatType)return!0===e?"Yes":"No";if("Boolean_Number"===t.leafFormatType)return!0===e?1:0}else if("Number"===t.fieldType||"Count"===t.leafValueType){if("Number"===t.leafFormatType)return e.toLocaleString();if("String"===t.leafFormatType)return e.toString();if("Currency"===t.leafFormatType)return(0,common_1.round)(e,2).toLocaleString("en-US",{style:"currency",currency:"USD"})}else if("Date"===t.fieldType)switch(t.leafFormatType){case"Date":return moment(e).format("L");case"Time":return moment(e).format("LT");case"DateTime":return moment(e).format("MM/DD/YYYY h:mm A");case"Date_long":return moment(e).format("LL");case"DateTime_long":return moment(e).format("LLL");case"Timestamp":return moment(e).toDate().getTime();default:return e}return e}var o,l;n<t.groups_row.length?e[o="gr_"+(n+1)]&&e[o].forEach(function(e){modifyDataTypeField(t,e,r,n+1)}):Array.isArray(e[r.id])?e[r.id]=(o=e[r.id],l=r,o.map(function(e){return nc(e,l)})):e[r.id]=nc(e[r.id],r)}function tabGroupExcelRecursive(n,t,o,r,l){var a=t.getRow(o);return r<n.groups_row.length?(a.getCell(2).fill={fgColor:{argb:n.groups_row[r-1].fill_color?n.groups_row[r-1].fill_color.replace("#",""):"ffffff"},type:"pattern",pattern:"solid"},a.getCell(2).font={color:{argb:n.groups_row[r-1].font_color?n.groups_row[r-1].font_color.replace("#",""):"000000"},name:"Arial",bold:!0,size:14},a.getCell(2).value=n.groups_row[r-1].columnName+": "+l._id["gr_"+r],t.mergeCells(a.getCell(2).$col$row+":"+a.getCell(n.fields_selected.filter(function(e){return e.show}).length+1).$col$row),a.getCell(2).border={top:{style:"thick"},left:{style:"thick"},right:{style:"thick"}},n.fields_total.length&&n.fields_total.forEach(function(r){o+=1,a=t.getRow(o),n.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(a.getCell(t+2).value=e.columnName,a.getCell(t+2).font={name:"Arial",bold:!0,size:10}),"Currency"===e.leafFormatType?a.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(a.getCell(t+2).numFmt="#,##0"),0===t?a.getCell(t+2).border={left:{style:"thick"}}:t===n.fields_selected.filter(function(e){return e.show}).length-1&&(a.getCell(t+2).border={right:{style:"thick"}})})}),n.fields_total.forEach(function(r){o+=1,a=t.getRow(o),n.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(a.getCell(t+2).value=l[r.id+"_"+e.id],a.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?a.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(a.getCell(t+2).numFmt="#,##0")),0===t?a.getCell(t+2).border={top:{style:"thin"},left:{style:"thick"},bottom:{style:"thick"}}:t===n.fields_selected.filter(function(e){return e.show}).length-1?a.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"},right:{style:"thick"}}:a.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"}}})}),o+=1,(l=l["gr_"+(r+1)]).forEach(function(e){o=tabGroupExcelRecursive(n,t,o,r+1,e)})):(a.getCell(2).fill={fgColor:{argb:n.groups_row[r-1].fill_color?n.groups_row[r-1].fill_color.replace("#",""):"ffffff"},type:"pattern",pattern:"solid"},a.getCell(2).font={color:{argb:n.groups_row[r-1].font_color?n.groups_row[r-1].font_color.replace("#",""):"000000"},name:"Arial",bold:!0,size:12},a.getCell(2).value=n.groups_row[r-1].columnName+": "+l._id["gr_"+r],t.mergeCells(a.getCell(2).$col$row+":"+a.getCell(n.fields_selected.filter(function(e){return e.show}).length+1).$col$row),a.getCell(2).border={top:{style:"thick"},left:{style:"thick"},right:{style:"thick"}},o+=1,a=t.getRow(o),n.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){a.getCell(t+2).value=e.columnName,a.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?a.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(a.getCell(t+2).numFmt="#,##0"),0===t?a.getCell(t+2).border={left:{style:"thick"}}:t===n.fields_selected.filter(function(e){return e.show}).length-1&&(a.getCell(t+2).border={right:{style:"thick"}})}),l.f_0.forEach(function(e,r){o+=1,a=t.getRow(o),n.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){"Number"===e.fieldType&&"string"==typeof l[e.id][r]&&l[e.id][r]?a.getCell(t+2).value=parseFloat(l[e.id][r].replace(new RegExp(/\,/g),"").replace(new RegExp(/\$/g),"")):a.getCell(t+2).value=l[e.id][r],"Currency"===e.leafFormatType?a.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(a.getCell(t+2).numFmt="#,##0"),a.getCell(t+2).font={name:"Arial",size:10},0===t?a.getCell(t+2).border={left:{style:"thick"}}:t===n.fields_selected.filter(function(e){return e.show}).length-1&&(a.getCell(t+2).border={right:{style:"thick"}})})}),n.fields_total.forEach(function(r){o+=1,a=t.getRow(o),n.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(a.getCell(t+2).value=l[r.id+"_"+e.id],a.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?a.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(a.getCell(t+2).numFmt="#,##0")),0===t?a.getCell(t+2).border={top:{style:"thin"},left:{style:"thick"},bottom:{style:"thick"}}:t===n.fields_selected.filter(function(e){return e.show}).length-1?a.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"},right:{style:"thick"}}:a.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"}}})})),o+1}function tabGroupExcelWidthRecursive(t,r,o,l){return r<t.groups_row.length?(o=o["gr_"+(r+1)]).forEach(function(e){l=tabGroupExcelWidthRecursive(t,r+1,e,l)}):t.fields_selected.filter(function(e){return e.show}).forEach(function(r,n){var e;Array.isArray(o[r.id])?o[r.id].forEach(function(e){var t=10;e&&(t=e.length+3),l[n]||(l[n]=Math.max(10,r.columnName.length)),t>l[n]&&(l[n]=t)}):((e=o[r.id])&&(length=e.length+3),l[n]||(l[n]=Math.max(10,r.columnName.length)),length>l[n]&&(l[n]=length))}),l}exports.loadCronJobMethods=loadCronJobMethods;
2
2
  //# sourceMappingURL=cron-jobs.js.map