@resolveio/server-lib 20.7.6 → 20.7.8

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 (112) hide show
  1. package/client-server-app.js +1 -1
  2. package/client-server-app.js.map +1 -1
  3. package/collections/app-status.collection.js +1 -1
  4. package/collections/app-status.collection.js.map +1 -1
  5. package/collections/counter.collection.js +1 -1
  6. package/collections/counter.collection.js.map +1 -1
  7. package/collections/cron-job-history.collection.js +1 -1
  8. package/collections/cron-job-history.collection.js.map +1 -1
  9. package/collections/cron-job.collection.js +1 -1
  10. package/collections/cron-job.collection.js.map +1 -1
  11. package/collections/email-history.collection.js +1 -1
  12. package/collections/email-history.collection.js.map +1 -1
  13. package/collections/email-verified.collection.js +1 -1
  14. package/collections/email-verified.collection.js.map +1 -1
  15. package/collections/file.collection.js +1 -1
  16. package/collections/file.collection.js.map +1 -1
  17. package/collections/flag-update.collection.js +1 -1
  18. package/collections/flag-update.collection.js.map +1 -1
  19. package/collections/flag.collection.js +1 -1
  20. package/collections/flag.collection.js.map +1 -1
  21. package/collections/log-method-latency.collection.js +1 -1
  22. package/collections/log-method-latency.collection.js.map +1 -1
  23. package/collections/log-subscription.collection.js +1 -1
  24. package/collections/log-subscription.collection.js.map +1 -1
  25. package/collections/log.collection.js +1 -1
  26. package/collections/log.collection.js.map +1 -1
  27. package/collections/logged-in-users.collection.js +1 -1
  28. package/collections/logged-in-users.collection.js.map +1 -1
  29. package/collections/method-response.collection.js +1 -1
  30. package/collections/method-response.collection.js.map +1 -1
  31. package/collections/monitor-cpu.collection.js +1 -1
  32. package/collections/monitor-cpu.collection.js.map +1 -1
  33. package/collections/monitor-function.collection.js +1 -1
  34. package/collections/monitor-function.collection.js.map +1 -1
  35. package/collections/monitor-memory.collection.js +1 -1
  36. package/collections/monitor-memory.collection.js.map +1 -1
  37. package/collections/monitor-mongo.collection.js +1 -1
  38. package/collections/monitor-mongo.collection.js.map +1 -1
  39. package/collections/notification.collection.js +1 -1
  40. package/collections/notification.collection.js.map +1 -1
  41. package/collections/report-builder-dashboard-builder.collection.js +1 -1
  42. package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
  43. package/collections/report-builder-library.collection.js +1 -1
  44. package/collections/report-builder-library.collection.js.map +1 -1
  45. package/collections/report-builder-report.collection.js +1 -1
  46. package/collections/report-builder-report.collection.js.map +1 -1
  47. package/collections/user-group.collection.js +1 -1
  48. package/collections/user-group.collection.js.map +1 -1
  49. package/collections/user-guide.collection.js +1 -1
  50. package/collections/user-guide.collection.js.map +1 -1
  51. package/collections/user.collection.js +1 -1
  52. package/collections/user.collection.js.map +1 -1
  53. package/fixtures/cron-jobs.js +1 -1
  54. package/fixtures/cron-jobs.js.map +1 -1
  55. package/fixtures/init.js +1 -1
  56. package/fixtures/init.js.map +1 -1
  57. package/http/auth.d.ts +2 -1
  58. package/http/auth.js +1 -1
  59. package/http/auth.js.map +1 -1
  60. package/http/home.js +1 -1
  61. package/http/home.js.map +1 -1
  62. package/managers/cron.manager.d.ts +3 -1
  63. package/managers/cron.manager.js +1 -1
  64. package/managers/cron.manager.js.map +1 -1
  65. package/managers/local-log.manager.d.ts +3 -1
  66. package/managers/local-log.manager.js +1 -1
  67. package/managers/local-log.manager.js.map +1 -1
  68. package/managers/method.manager.d.ts +12 -7
  69. package/managers/method.manager.js +1 -1
  70. package/managers/method.manager.js.map +1 -1
  71. package/managers/mongo.manager.d.ts +17 -12
  72. package/managers/mongo.manager.js +1 -1
  73. package/managers/mongo.manager.js.map +1 -1
  74. package/managers/monitor.manager.d.ts +15 -7
  75. package/managers/monitor.manager.js +1 -1
  76. package/managers/monitor.manager.js.map +1 -1
  77. package/managers/subscription.manager.d.ts +5 -3
  78. package/managers/subscription.manager.js +1 -1
  79. package/managers/subscription.manager.js.map +1 -1
  80. package/managers/websocket.manager.d.ts +3 -1
  81. package/managers/websocket.manager.js +1 -1
  82. package/managers/websocket.manager.js.map +1 -1
  83. package/methods/accounts.js +1 -1
  84. package/methods/accounts.js.map +1 -1
  85. package/methods/aws.js +1 -1
  86. package/methods/aws.js.map +1 -1
  87. package/methods/collections.js +1 -1
  88. package/methods/collections.js.map +1 -1
  89. package/methods/counters.js +1 -1
  90. package/methods/counters.js.map +1 -1
  91. package/methods/cron-jobs.js +1 -1
  92. package/methods/cron-jobs.js.map +1 -1
  93. package/methods/logs.js +1 -1
  94. package/methods/logs.js.map +1 -1
  95. package/methods/monitor.js +1 -1
  96. package/methods/monitor.js.map +1 -1
  97. package/methods/pdf.js +1 -1
  98. package/methods/pdf.js.map +1 -1
  99. package/methods/report-builder.js +1 -1
  100. package/methods/report-builder.js.map +1 -1
  101. package/methods/support.js +1 -1
  102. package/methods/support.js.map +1 -1
  103. package/models/method.model.d.ts +6 -1
  104. package/package.json +5 -4
  105. package/publications/logs.js +1 -1
  106. package/publications/logs.js.map +1 -1
  107. package/resolveio-server-app.d.ts +14 -10
  108. package/resolveio-server-app.js +1 -1
  109. package/resolveio-server-app.js.map +1 -1
  110. package/server-app.d.ts +5 -4
  111. package/server-app.js +1 -1
  112. package/server-app.js.map +1 -1
package/http/auth.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/http/auth.ts"],"names":["user_collection_1","require","jwt","handlebars","resolveio_server_app_1","simpl_schema_1","bodyParser","jwt_decode_1","common_1","setupAuthRoutes","mainServer","app","serverConfig","_this","this","post","json","request","response","__awaiter","headers","origin","send","JSON","stringify","error","result","body","schema","default","id_token","type","String","validate","errors","console","Date","ResolveIOServer","getMainServer","getMethodManager","sendEmail","getClientName","tokenData","split","token","decodedJWT","Users","findOne","other.ms_oid","user","_a","sent","email","toLowerCase","updateOne","_id","$set","objectIdHexString","__v","roles","super_admin","approvals","groups","notifications","miscs","username","fullname","active","phonenumber","readonly","other","ms_oid","attempts","salt","sign","now","toString","expiresIn","hash","last","settings","services","is_customer","create","update","id_user","log","password","user_1","authenticate","resAuth","emailData_1","userToChangePassword","userWhoResetPassword","url","encodeURIComponent","then","resUp","readFile","html","template","compile","registerHelper","a","b","errEmail","errUp","emailData_2","err","resetAttempts","refreshToken","verify","decoded","findById","body_1","enrollmentToken","$and","services.enrollment","projection","body_2","setPassword","body_3","forgotPasswordToken","services.forgot_password","body_4","callMethod","call","exports"],"mappings":"k8CAAAA,mB,sFAAAC,QAAA,gCAAA,GACAC,IAAAD,QAAA,cAAA,EACAE,WAAAF,QAAA,YAAA,EACAG,uBAAAH,QAAA,yBAAA,EAEAI,eAAAJ,QAAA,cAAA,EACAK,WAAAL,QAAA,aAAA,EACAM,aAAAN,QAAA,YAAA,EACAO,SAAAP,QAAA,gBAAA,EAEA,SAAgBQ,gBAAgBC,EAAYC,EAAKC,GAAjD,IAAAC,EAAAC,KACCH,EAAII,KAAK,YAAaT,WAAWU,KAAI,EAAI,SAAOC,EAASC,GAAQ,OAAAC,UAAAN,EAAA,KAAA,EAAA,KAAA,EAAA,W,gFAC5DI,EAAQG,QAAQC,SAAWT,EAAuB,UAAKK,EAAQG,QAAQC,SAAWT,EAA2B,aAA7G,CAAA,EAAA,IACHM,EAASI,KAAKC,KAAKC,UAAU,CAC5BC,MAAO,CAAA,EACPC,OAAQ,gB,CACR,CAAC,E,eAGEC,EAAOV,EAAQU,KAEfC,EAAS,IAAIvB,eAAAwB,QAAa,CAC7BC,SAAU,CACTC,KAAMC,M,EAEP,EAED,IACCJ,EAAOK,SAASN,CAAI,C,CAErB,MAAOO,GACN,GAAIA,EAUH,OATAC,QAAQV,MAAM,IAAIW,KAAQ,+BAAgCF,CAAM,EAEhE9B,uBAAAiC,gBAAgBC,cAAa,EAAGC,iBAAgB,EAAGC,UAAU,oBAAqBpC,uBAAAiC,gBAAgBI,cAAa,EAAK,wBAAyB,wDAAoElB,KAAKC,UAAUG,EAAM,KAAM,CAAC,EAAI,eAAiBJ,KAAKC,UAAUU,EAAQ,KAAM,CAAC,CAAC,EAEjShB,EAASI,KAAKC,KAAKC,UAAU,CAC5BC,MAAO,CAAA,EACPC,OAAQ,oB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,EAAA,IACHM,EAASI,KAAKC,KAAKC,UAAU,CAC5BC,MAAO,CAAA,EACPC,OAAQ,gB,CACR,CAAC,E,cAGEC,EAAOV,EAAQU,KAEfC,EAAS,IAAIvB,eAAAwB,QAAa,CAC7BoC,SAAU,CACTlC,KAAMC,M,EAEP,EAED,IACCJ,EAAOK,SAASN,CAAI,C,CAErB,MAAOO,GACN,GAAIA,EAUH,OATAC,QAAQV,MAAM,IAAIW,KAAQ,uCAAwCF,CAAM,EAExE9B,uBAAAiC,gBAAgBC,cAAa,EAAGC,iBAAgB,EAAGC,UAAU,oBAAqBpC,uBAAAiC,gBAAgBI,cAAa,EAAK,wBAAyB,6DAAyElB,KAAKC,UAAUG,EAAM,KAAM,CAAC,EAAI,eAAiBJ,KAAKC,UAAUU,EAAQ,KAAM,CAAC,CAAC,EAEtShB,EAASI,KAAKC,KAAKC,UAAU,CAC5BC,MAAO,CAAA,EACPC,OAAQ,oB,CACR,CAAC,EAEF,CAAA,E,CAIS,MAAA,CAAA,EAAM1B,kBAAA8C,MAAMC,QAAQ,CAACoB,OAAQ,CAAA,EAAMF,SAAUtC,EAAKsC,QAAQ,CAAC,G,cAAlEhB,EAAOC,EAAAC,KAAA,GAEP,CAAA,EAAA,GACI,CAAA,EAAMnD,kBAAA8C,MAAMC,QAAQ,CAACoB,OAAQ,CAAA,EAAMf,MAAOzB,EAAKsC,QAAQ,CAAC,G,OAA/DhB,EAAOC,EAAAC,KAAA,E,iBAGJF,GACHvC,EAAW6B,iBAAgB,EAAGsF,WAAWC,KAAKpH,EAAW6B,iBAAgB,EAAI,oBAAqBU,EAAKM,GAAG,EAG3GrC,EAASI,KAAKC,KAAKC,UAAU,CAC5BC,MAAO,CAAA,EACPC,OAAQ,E,CACR,CAAC,E,gCAEH,CACF,CAjtBAqG,QAAAtH,gBAAAA","file":"auth.js","sourcesContent":["import { Users } from '../collections/user.collection';\nimport * as jwt from 'jsonwebtoken';\nimport * as handlebars from 'handlebars';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { UserModel } from '../models/user.model';\nimport SimpleSchema from 'simpl-schema';\nimport * as bodyParser from 'body-parser';\nimport jwt_decode from 'jwt-decode';\nimport { objectIdHexString } from '../util/common';\n\nexport function setupAuthRoutes(mainServer, app, serverConfig) {\n\tapp.post('/login365', bodyParser.json(), async (request, response) => {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\tid_token: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/login)', errors);\n\t\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/login365' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet tokenData = body.id_token.split('&');\n\t\t\tlet token = tokenData[0].split('=')[1];\n\t\t\tlet decodedJWT = jwt_decode(token);\n\n\t\t\tif (decodedJWT && decodedJWT['name'] && decodedJWT['preferred_username'] && decodedJWT['oid']) {\n\t\t\t\tlet user = await Users.findOne({'other.ms_oid': decodedJWT['oid']});\n\n\t\t\t\tif (!user) {\n\t\t\t\t\tuser = await Users.findOne({email: decodedJWT['preferred_username'].toLowerCase()});\n\n\t\t\t\t\tif (user) {\n\t\t\t\t\t\tawait Users.updateOne({_id: user._id}, {$set: {'other.ms_oid': decodedJWT['oid']}});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!user) {\n\t\t\t\t\tuser = {\n\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\troles: {\n\t\t\t\t\t\t\tsuper_admin: false,\n\t\t\t\t\t\t\tapprovals: [],\n\t\t\t\t\t\t\tgroups: [],\n\t\t\t\t\t\t\tnotifications: [],\n\t\t\t\t\t\t\tmiscs: []\n\t\t\t\t\t\t},\n\t\t\t\t\t\tusername: decodedJWT['preferred_username'].toLowerCase(),\n\t\t\t\t\t\temail: decodedJWT['preferred_username'].toLowerCase(),\n\t\t\t\t\t\tfullname: decodedJWT['name'],\n\t\t\t\t\t\tactive: true,\n\t\t\t\t\t\tphonenumber: '',\n\t\t\t\t\t\treadonly: false,\n\t\t\t\t\t\tother: {\n\t\t\t\t\t\t\tms_oid: decodedJWT['oid']\n\t\t\t\t\t\t},\n\t\t\t\t\t\tattempts: 0,\n\t\t\t\t\t\tsalt: jwt.sign({now: (Date.now() - 1000).toString()}, serverConfig['JWT_SECRET'], {\n\t\t\t\t\t\t\texpiresIn : 90 * 24 * 60 * 60 * 1000 // 90 days\n\t\t\t\t\t\t}),\n\t\t\t\t\t\thash: jwt.sign({now: (Date.now() + 1000).toString()}, serverConfig['JWT_SECRET'], {\n\t\t\t\t\t\t\texpiresIn : 90 * 24 * 60 * 60 * 1000 // 90 days\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tlast: new Date(),\n\t\t\t\t\t\tsettings: null,\n\t\t\t\t\t\tservices: null,\n\t\t\t\t\t\tis_customer: false\n\t\t\t\t\t};\n\t\t\t\t\t\n\t\t\t\t\tawait Users.create(user);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet update = false;\n\n\t\t\t\t\tif (user.email !== decodedJWT['preferred_username'].toLowerCase()) {\n\t\t\t\t\t\tuser.email = decodedJWT['preferred_username'].toLowerCase();\n\t\t\t\t\t\tupdate = true;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (user.fullname !== decodedJWT['name']) {\n\t\t\t\t\t\tuser.fullname = decodedJWT['name'];\n\t\t\t\t\t\tupdate = true;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (update) {\n\t\t\t\t\t\tawait Users.updateOne({_id: user._id}, {$set: {email: user.email, fullname: user.fullname}});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\terror: false,\n\t\t\t\t\tresult: {\n\t\t\t\t\t\ttoken: jwt.sign({id_user: user._id}, serverConfig['JWT_SECRET'], {\n\t\t\t\t\t\t\texpiresIn : 90 * 24 * 60 * 60 * 1000 // 90 days\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tconsole.log('ERROR - 1', tokenData, token, decodedJWT);\n\n\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\terror: true,\n\t\t\t\t\tresult: 'Invalid Azure Token'\n\t\t\t\t}));\n\t\t\t}\n\t\t}\n\t});\n\n\t// Login via HTTP, return refresh token if authenticated\n\tapp.post('/login', bodyParser.json(), async (request, response) => {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\tusername: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/login)', errors);\n\t\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/login' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet user = await Users.findOne({active: true, username: body.username});\n\n\t\t\tif (!user) {\n\t\t\t\tuser = await Users.findOne({active: true, email: body.username});\n\t\t\t}\n\t\t\t\n\t\t\tif (!user) {\n\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\terror: true,\n\t\t\t\t\tresult: 'Invalid Username And Password'\n\t\t\t\t}));\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet resAuth = await Users.authenticate(user, body.password);\n\n\t\t\tif (resAuth['error']) {\n\t\t\t\tif (resAuth['error'] === 'Too Many Attempts') {\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: resAuth['error'] + '. A password reset link has been sent to your email, please reset your password.'\n\t\t\t\t\t}));\n\n\t\t\t\t\tif (!user.services) {\n\t\t\t\t\t\tuser.services = {};\n\t\t\t\t\t}\n\n\t\t\t\t\tuser.services['forgot_password'] = jwt.sign({id_user: user._id}, serverConfig['JWT_SECRET']);\n\n\t\t\t\t\tlet emailData = {\n\t\t\t\t\t\tuserToChangePassword: user.fullname,\n\t\t\t\t\t\tuserWhoResetPassword: ResolveIOServer.getClientName() + ' System',\n\t\t\t\t\t\turl: (serverConfig['ROOT_URL'] + '/forgot-password?' + encodeURIComponent(serverConfig['SERVER_URL']) + '&' + user.services['forgot_password'])\n\t\t\t\t\t};\n\n\t\t\t\t\tUsers.updateOne({_id: user._id}, {$set: {services: user.services}}).then(resUp => {\n\t\t\t\t\t\tmainServer.getMethodManager().readFile('email-templates/forgot-password.html').then(html => {\n\t\t\t\t\t\t\tlet template = handlebars.compile(html);\n\t\t\t\t\t\t\thandlebars.registerHelper('equals', (a, b) => {\n\t\t\t\t\t\t\t\treturn a === b;\n\t\t\t\t\t\t\t});\n\t\t\n\t\t\t\t\t\t\tmainServer.getMethodManager().sendEmail(user.email, 'ResolveIO (' + ResolveIOServer.getClientName() + ') - Forgot Password', '', template(emailData), null, null, '');\n\t\t\t\t\t\t}, errEmail => console.log(errEmail));\n\t\t\t\t\t}, errUp => {});\n\t\t\t\t}\n\t\t\t\telse if (resAuth['error'] === 'No Salt Value Stored') {\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'A password reset link has been sent to your email, please reset your password.'\n\t\t\t\t\t}));\n\n\t\t\t\t\tif (!user.services) {\n\t\t\t\t\t\tuser.services = {};\n\t\t\t\t\t}\n\n\t\t\t\t\tuser.services['forgot_password'] = jwt.sign({id_user: user._id}, serverConfig['JWT_SECRET']);\n\n\t\t\t\t\tlet emailData = {\n\t\t\t\t\t\tuserToChangePassword: user.fullname,\n\t\t\t\t\t\tuserWhoResetPassword: ResolveIOServer.getClientName() + ' System',\n\t\t\t\t\t\turl: (serverConfig['ROOT_URL'] + '/forgot-password?' + encodeURIComponent(serverConfig['SERVER_URL']) + '&' + user.services['forgot_password'])\n\t\t\t\t\t};\n\n\t\t\t\t\tUsers.updateOne({_id: user._id}, {$set: {services: user.services}}).then(resUp => {\n\t\t\t\t\t\tmainServer.getMethodManager().readFile('email-templates/forgot-password.html').then(html => {\n\t\t\t\t\t\t\tlet template = handlebars.compile(html);\n\t\t\t\t\t\t\thandlebars.registerHelper('equals', (a, b) => {\n\t\t\t\t\t\t\t\treturn a === b;\n\t\t\t\t\t\t\t});\n\t\t\n\t\t\t\t\t\t\tmainServer.getMethodManager().sendEmail(user.email, 'ResolveIO (' + ResolveIOServer.getClientName() + ') - Forgot Password', '', template(emailData), null, null, '');\n\t\t\t\t\t\t}, errEmail => console.log(errEmail));\n\t\t\t\t\t}, err => {});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: resAuth['error']\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (resAuth && resAuth['data'] && resAuth['data'].active) {\n\t\t\t\t\tawait Users.resetAttempts(resAuth['data']);\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: false,\n\t\t\t\t\t\tresult: {\n\t\t\t\t\t\t\ttoken: jwt.sign({id_user: resAuth['data']._id}, serverConfig['JWT_SECRET'], {\n\t\t\t\t\t\t\t\texpiresIn : 90 * 24 * 60 * 60 * 1000 // 90 days\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}\n\t\t\t}\n\t\t}\n\t});\n\n\tapp.post('/accessToken', bodyParser.json(), async function (request, response) {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_SECONDARY_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\trefreshToken: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/accessToken)', errors);\n\t\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/accessToken' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tjwt.verify(body.refreshToken, serverConfig['JWT_SECRET'], (err, decoded) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Token'\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tUsers.findById(decoded['id_user']).then(async (user: UserModel) => {\n\t\t\t\t\t\tif (user) {\n\t\t\t\t\t\t\tif (user.active) {\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: false,\n\t\t\t\t\t\t\t\t\tresult: {\n\t\t\t\t\t\t\t\t\t\ttoken: jwt.sign({id_user: user._id}, serverConfig['JWT_SECRET'], {\n\t\t\t\t\t\t\t\t\t\t\texpiresIn : 3 * 24 * 60 * 60 * 1000 // 3 days\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\tuser: user\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\t\tresult: 'Account is Disabled'\n\t\t\t\t\t\t\t\t}));\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\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\tresult: 'Invalid User'\n\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t}\n\t\t\t\t\t}, error => {\n\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\tresult: 'Invalid Mongo Get User'\n\t\t\t\t\t\t}));\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t});\n\n\tapp.post('/userWithEnrollmentToken', bodyParser.json(), function (request, response) {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_SECONDARY_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\tenrollmentToken: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/userWithEnrollmentToken)', errors);\n\t\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/userWithEnrollmentToken' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tjwt.verify(body.enrollmentToken, serverConfig['JWT_SECRET'], (err, decoded) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Token'\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tUsers.findOne({\n\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t{_id: decoded['id_user']},\n\t\t\t\t\t\t\t{'services.enrollment': body.enrollmentToken}\n\t\t\t\t\t\t]\n\t\t\t\t\t}, {projection: {_id: 1, __v: 1, username: 1, active: 1}}).then((user) => {\n\t\t\t\t\t\tif (user) {\n\t\t\t\t\t\t\tif (user.active) {\n\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: false,\n\t\t\t\t\t\t\t\t\tresult: {\n\t\t\t\t\t\t\t\t\t\tuser: user\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\t\tresult: 'Account is Disabled'\n\t\t\t\t\t\t\t\t}));\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\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\tresult: 'Invalid User'\n\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t}\n\t\t\t\t\t}, error => {\n\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\tresult: 'Invalid Mongo Get User'\n\t\t\t\t\t\t}));\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t});\n\n\tapp.post('/setUserWithEnrollmentToken', bodyParser.json(), function (request, response) {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_SECONDARY_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\tenrollmentToken: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/setUserWithEnrollmentToken)', errors);\n\t\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/setUserWithEnrollmentToken' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tjwt.verify(body.enrollmentToken, serverConfig['JWT_SECRET'], async (err, decoded) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Token'\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tUsers.findOne({\n\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t{_id: decoded['id_user']},\n\t\t\t\t\t\t\t{'services.enrollment': body.enrollmentToken}\n\t\t\t\t\t\t]\n\t\t\t\t\t}).then(async (user: UserModel) => {\n\t\t\t\t\t\tif (user) {\n\t\t\t\t\t\t\tif (user.active) {\n\t\t\t\t\t\t\t\tawait Users.setPassword(user, body.password);\n\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: false,\n\t\t\t\t\t\t\t\t\tresult: true\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\t\tresult: 'Account is Disabled'\n\t\t\t\t\t\t\t\t}));\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\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\tresult: 'Invalid User'\n\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t}\n\t\t\t\t\t}, error => {\n\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\tresult: 'Invalid Mongo Get User'\n\t\t\t\t\t\t}));\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t});\n\n\tapp.post('/userWithForgotPasswordToken', bodyParser.json(), function (request, response) {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_SECONDARY_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\tforgotPasswordToken: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/userWithForgotPasswordToken)', errors);\n\t\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/userWithForgotPasswordToken' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tjwt.verify(body.forgotPasswordToken, serverConfig['JWT_SECRET'], (err, decoded) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Token'\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tUsers.findOne({\n\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t{_id: decoded['id_user']},\n\t\t\t\t\t\t\t{'services.forgot_password': body.forgotPasswordToken}\n\t\t\t\t\t\t]\n\t\t\t\t\t}, {projection: {_id: 1, __v: 1, username: 1, active: 1}}).then((user) => {\n\t\t\t\t\t\tif (user) {\n\t\t\t\t\t\t\tif (user.active) {\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: false,\n\t\t\t\t\t\t\t\t\tresult: {\n\t\t\t\t\t\t\t\t\t\tuser: user\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\t\tresult: 'Account is Disabled'\n\t\t\t\t\t\t\t\t}));\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\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\tresult: 'Invalid Token'\n\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t}\n\t\t\t\t\t}, error => {\n\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\tresult: 'Invalid Mongo Get User'\n\t\t\t\t\t\t}));\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t});\n\n\tapp.post('/setUserWithForgotPasswordToken', bodyParser.json(), function (request, response) {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_SECONDARY_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\tforgotPasswordToken: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/setUserWithForgotPasswordToken)', errors);\n\t\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/setUserWithForgotPasswordToken' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tjwt.verify(body.forgotPasswordToken, serverConfig['JWT_SECRET'], async (err, decoded) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Token'\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tUsers.findOne({\n\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t{_id: decoded['id_user']},\n\t\t\t\t\t\t\t{'services.forgot_password': body.forgotPasswordToken}\n\t\t\t\t\t\t]\n\t\t\t\t\t}).then(async (user: UserModel) => {\n\t\t\t\t\t\tif (user) {\n\t\t\t\t\t\t\tif (user.active) {\n\t\t\t\t\t\t\t\tawait Users.setPassword(user, body.password);\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: false,\n\t\t\t\t\t\t\t\t\tresult: true\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\t\tresult: 'Account is Disabled'\n\t\t\t\t\t\t\t\t}));\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\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\tresult: 'Invalid User'\n\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t}\n\t\t\t\t\t}, error => {\n\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\tresult: 'Invalid Mongo Get User'\n\t\t\t\t\t\t}));\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t});\n\n\tapp.post('/resetPassword', bodyParser.json(), async (request, response) => {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\tusername: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/resetPassword)', errors);\n\t\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/resetPassword' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet user = await Users.findOne({active: true, username: body.username});\n\n\t\t\tif (!user) {\n\t\t\t\tuser = await Users.findOne({active: true, email: body.username});\n\t\t\t}\n\t\t\t\n\t\t\tif (user) {\n\t\t\t\tmainServer.getMethodManager().callMethod.call(mainServer.getMethodManager(), 'resetUserPassword', user._id);\n\t\t\t}\n\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: false,\n\t\t\t\tresult: ''\n\t\t\t}));\n\t\t}\n\t});\n}"]}
1
+ {"version":3,"sources":["../../src/http/auth.ts"],"names":["bodyParser","require","handlebars","jwt","jwt_decode_1","simpl_schema_1","user_collection_1","resolveio_server_app_1","common_1","setupAuthRoutes","mainServer","app","serverConfig","_this","this","post","json","request","response","__awaiter","headers","origin","send","JSON","stringify","error","result","body","schema","default","id_token","type","String","validate","console","Date","errors_1","ResolveIOServer","getMainServer","getMethodManager","sendEmail","getClientName","_a","sent","tokenData","split","token","decodedJWT","Users","findOne","other.ms_oid","user","email","toLowerCase","updateOne","_id","$set","objectIdHexString","__v","roles","super_admin","approvals","groups","notifications","miscs","username","fullname","active","phonenumber","readonly","other","ms_oid","attempts","salt","sign","now","toString","expiresIn","hash","last","settings","services","is_customer","create","update","id_user","log","password","errors_2","authenticate","resAuth","emailData","userToChangePassword","userWhoResetPassword","url","encodeURIComponent","html","readFile","template","compile","registerHelper","a","b","resetAttempts","refreshToken","errors_3","verify","err","decoded","findById","_b","body_1","enrollmentToken","errors_4","$and","services.enrollment","projection","body_2","errors_5","setPassword","body_3","forgotPasswordToken","errors_6","services.forgot_password","body_4","errors_7","errors_8","callMethod","call","exports"],"mappings":"k8CAAAA,Y,sFAAAC,QAAA,aAAA,GACAC,WAAAD,QAAA,YAAA,EACAE,IAAAF,QAAA,cAAA,EACAG,aAAAH,QAAA,YAAA,EACAI,eAAAJ,QAAA,cAAA,EACAK,kBAAAL,QAAA,gCAAA,EACAM,uBAAAN,QAAA,yBAAA,EAEAO,SAAAP,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BY,EAAKI,GAAG,EAG3GrC,EAASI,KAAKC,KAAKC,UAAU,CAC5BC,MAAO,CAAA,EACPC,OAAQ,E,CACR,CAAC,E,kCAEH,CACF,CAztBAuG,QAAAxH,gBAAAA","file":"auth.js","sourcesContent":["import * as bodyParser from 'body-parser';\nimport * as handlebars from 'handlebars';\nimport * as jwt from 'jsonwebtoken';\nimport jwt_decode from 'jwt-decode';\nimport SimpleSchema from 'simpl-schema';\nimport { Users } from '../collections/user.collection';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { ResolveIOMainServer } from '../server-app';\nimport { objectIdHexString } from '../util/common';\n\nexport function setupAuthRoutes(mainServer: ResolveIOMainServer, app, serverConfig) {\n\tapp.post('/login365', bodyParser.json(), async (request, response) => {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\tid_token: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/login)', errors);\n\t\n\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/login365' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet tokenData = body.id_token.split('&');\n\t\t\tlet token = tokenData[0].split('=')[1];\n\t\t\tlet decodedJWT = jwt_decode(token);\n\n\t\t\tif (decodedJWT && decodedJWT['name'] && decodedJWT['preferred_username'] && decodedJWT['oid']) {\n\t\t\t\tlet user = await Users.findOne({'other.ms_oid': decodedJWT['oid']});\n\n\t\t\t\tif (!user) {\n\t\t\t\t\tuser = await Users.findOne({email: decodedJWT['preferred_username'].toLowerCase()});\n\n\t\t\t\t\tif (user) {\n\t\t\t\t\t\tawait Users.updateOne({_id: user._id}, {$set: {'other.ms_oid': decodedJWT['oid']}});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!user) {\n\t\t\t\t\tuser = {\n\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\troles: {\n\t\t\t\t\t\t\tsuper_admin: false,\n\t\t\t\t\t\t\tapprovals: [],\n\t\t\t\t\t\t\tgroups: [],\n\t\t\t\t\t\t\tnotifications: [],\n\t\t\t\t\t\t\tmiscs: []\n\t\t\t\t\t\t},\n\t\t\t\t\t\tusername: decodedJWT['preferred_username'].toLowerCase(),\n\t\t\t\t\t\temail: decodedJWT['preferred_username'].toLowerCase(),\n\t\t\t\t\t\tfullname: decodedJWT['name'],\n\t\t\t\t\t\tactive: true,\n\t\t\t\t\t\tphonenumber: '',\n\t\t\t\t\t\treadonly: false,\n\t\t\t\t\t\tother: {\n\t\t\t\t\t\t\tms_oid: decodedJWT['oid']\n\t\t\t\t\t\t},\n\t\t\t\t\t\tattempts: 0,\n\t\t\t\t\t\tsalt: jwt.sign({now: (Date.now() - 1000).toString()}, serverConfig['JWT_SECRET'], {\n\t\t\t\t\t\t\texpiresIn : 90 * 24 * 60 * 60 * 1000 // 90 days\n\t\t\t\t\t\t}),\n\t\t\t\t\t\thash: jwt.sign({now: (Date.now() + 1000).toString()}, serverConfig['JWT_SECRET'], {\n\t\t\t\t\t\t\texpiresIn : 90 * 24 * 60 * 60 * 1000 // 90 days\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tlast: new Date(),\n\t\t\t\t\t\tsettings: null,\n\t\t\t\t\t\tservices: null,\n\t\t\t\t\t\tis_customer: false\n\t\t\t\t\t};\n\t\t\t\t\t\n\t\t\t\t\tawait Users.create(user);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet update = false;\n\n\t\t\t\t\tif (user.email !== decodedJWT['preferred_username'].toLowerCase()) {\n\t\t\t\t\t\tuser.email = decodedJWT['preferred_username'].toLowerCase();\n\t\t\t\t\t\tupdate = true;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (user.fullname !== decodedJWT['name']) {\n\t\t\t\t\t\tuser.fullname = decodedJWT['name'];\n\t\t\t\t\t\tupdate = true;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (update) {\n\t\t\t\t\t\tawait Users.updateOne({_id: user._id}, {$set: {email: user.email, fullname: user.fullname}});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\terror: false,\n\t\t\t\t\tresult: {\n\t\t\t\t\t\ttoken: jwt.sign({id_user: user._id}, serverConfig['JWT_SECRET'], {\n\t\t\t\t\t\t\texpiresIn : 90 * 24 * 60 * 60 * 1000 // 90 days\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tconsole.log('ERROR - 1', tokenData, token, decodedJWT);\n\n\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\terror: true,\n\t\t\t\t\tresult: 'Invalid Azure Token'\n\t\t\t\t}));\n\t\t\t}\n\t\t}\n\t});\n\n\t// Login via HTTP, return refresh token if authenticated\n\tapp.post('/login', bodyParser.json(), async (request, response) => {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\tusername: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/login)', errors);\n\t\n\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/login' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet user = await Users.findOne({active: true, username: body.username});\n\n\t\t\tif (!user) {\n\t\t\t\tuser = await Users.findOne({active: true, email: body.username});\n\t\t\t}\n\t\t\t\n\t\t\tif (!user) {\n\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\terror: true,\n\t\t\t\t\tresult: 'Invalid Username And Password'\n\t\t\t\t}));\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet resAuth = await Users.authenticate(user, body.password);\n\n\t\t\tif (resAuth['error']) {\n\t\t\t\tif (resAuth['error'] === 'Too Many Attempts') {\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: resAuth['error'] + '. A password reset link has been sent to your email, please reset your password.'\n\t\t\t\t\t}));\n\n\t\t\t\t\tif (!user.services) {\n\t\t\t\t\t\tuser.services = {};\n\t\t\t\t\t}\n\n\t\t\t\t\tuser.services['forgot_password'] = jwt.sign({id_user: user._id}, serverConfig['JWT_SECRET']);\n\n\t\t\t\t\tlet emailData = {\n\t\t\t\t\t\tuserToChangePassword: user.fullname,\n\t\t\t\t\t\tuserWhoResetPassword: ResolveIOServer.getClientName() + ' System',\n\t\t\t\t\t\turl: (serverConfig['ROOT_URL'] + '/forgot-password?' + encodeURIComponent(serverConfig['SERVER_URL']) + '&' + user.services['forgot_password'])\n\t\t\t\t\t};\n\n\t\t\t\t\tlet resUp = await Users.updateOne({_id: user._id}, {$set: {services: user.services}});\n\t\t\t\t\tlet html = mainServer.getMethodManager().readFile('email-templates/forgot-password.html');\n\t\t\t\t\tlet template = handlebars.compile(html);\n\t\t\t\t\thandlebars.registerHelper('equals', (a, b) => {\n\t\t\t\t\t\treturn a === b;\n\t\t\t\t\t});\n\t\n\t\t\t\t\tawait mainServer.getMethodManager().sendEmail(user.email, 'ResolveIO (' + ResolveIOServer.getClientName() + ') - Forgot Password', '', template(emailData), null, null, '');\n\t\t\t\t}\n\t\t\t\telse if (resAuth['error'] === 'No Salt Value Stored') {\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'A password reset link has been sent to your email, please reset your password.'\n\t\t\t\t\t}));\n\n\t\t\t\t\tif (!user.services) {\n\t\t\t\t\t\tuser.services = {};\n\t\t\t\t\t}\n\n\t\t\t\t\tuser.services['forgot_password'] = jwt.sign({id_user: user._id}, serverConfig['JWT_SECRET']);\n\n\t\t\t\t\tlet emailData = {\n\t\t\t\t\t\tuserToChangePassword: user.fullname,\n\t\t\t\t\t\tuserWhoResetPassword: ResolveIOServer.getClientName() + ' System',\n\t\t\t\t\t\turl: (serverConfig['ROOT_URL'] + '/forgot-password?' + encodeURIComponent(serverConfig['SERVER_URL']) + '&' + user.services['forgot_password'])\n\t\t\t\t\t};\n\n\t\t\t\t\tlet resUp = await Users.updateOne({_id: user._id}, {$set: {services: user.services}});\n\t\t\t\t\tlet html = mainServer.getMethodManager().readFile('email-templates/forgot-password.html');\n\t\t\t\t\tlet template = handlebars.compile(html);\n\t\t\t\t\thandlebars.registerHelper('equals', (a, b) => {\n\t\t\t\t\t\treturn a === b;\n\t\t\t\t\t});\n\n\t\t\t\t\tawait mainServer.getMethodManager().sendEmail(user.email, 'ResolveIO (' + ResolveIOServer.getClientName() + ') - Forgot Password', '', template(emailData), null, null, '');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: resAuth['error']\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (resAuth && resAuth['data'] && resAuth['data'].active) {\n\t\t\t\t\tawait Users.resetAttempts(resAuth['data']);\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: false,\n\t\t\t\t\t\tresult: {\n\t\t\t\t\t\t\ttoken: jwt.sign({id_user: resAuth['data']._id}, serverConfig['JWT_SECRET'], {\n\t\t\t\t\t\t\t\texpiresIn : 90 * 24 * 60 * 60 * 1000 // 90 days\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}\n\t\t\t}\n\t\t}\n\t});\n\n\tapp.post('/accessToken', bodyParser.json(), async (request, response) => {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_SECONDARY_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\trefreshToken: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/accessToken)', errors);\n\t\n\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/accessToken' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tjwt.verify(body.refreshToken, serverConfig['JWT_SECRET'], async (err, decoded) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Token'\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlet user = await Users.findById(decoded['id_user']);\n\t\t\t\t\t\tif (user) {\n\t\t\t\t\t\t\tif (user.active) {\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: false,\n\t\t\t\t\t\t\t\t\tresult: {\n\t\t\t\t\t\t\t\t\t\ttoken: jwt.sign({id_user: user._id}, serverConfig['JWT_SECRET'], {\n\t\t\t\t\t\t\t\t\t\t\texpiresIn : 3 * 24 * 60 * 60 * 1000 // 3 days\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\tuser: user\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\t\tresult: 'Account is Disabled'\n\t\t\t\t\t\t\t\t}));\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\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\tresult: 'Invalid User'\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 {\n\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\tresult: 'Invalid Mongo Get User'\n\t\t\t\t\t\t}));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t});\n\n\tapp.post('/userWithEnrollmentToken', bodyParser.json(), async (request, response) => {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_SECONDARY_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\tenrollmentToken: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/userWithEnrollmentToken)', errors);\n\t\n\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/userWithEnrollmentToken' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tjwt.verify(body.enrollmentToken, serverConfig['JWT_SECRET'], async (err, decoded) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Token'\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlet user = await Users.findOne({\n\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t{_id: decoded['id_user']},\n\t\t\t\t\t\t\t\t{'services.enrollment': body.enrollmentToken}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}, {projection: {_id: 1, __v: 1, username: 1, active: 1}});\n\t\t\t\t\t\tif (user) {\n\t\t\t\t\t\t\tif (user.active) {\n\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: false,\n\t\t\t\t\t\t\t\t\tresult: {\n\t\t\t\t\t\t\t\t\t\tuser: user\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\t\tresult: 'Account is Disabled'\n\t\t\t\t\t\t\t\t}));\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\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\tresult: 'Invalid User'\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 {\n\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\tresult: 'Invalid Mongo Get User'\n\t\t\t\t\t\t}));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t});\n\n\tapp.post('/setUserWithEnrollmentToken', bodyParser.json(), async (request, response) => {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_SECONDARY_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\tenrollmentToken: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/setUserWithEnrollmentToken)', errors);\n\t\n\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/setUserWithEnrollmentToken' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tjwt.verify(body.enrollmentToken, serverConfig['JWT_SECRET'], async (err, decoded) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Token'\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlet user = await Users.findOne({\n\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t{_id: decoded['id_user']},\n\t\t\t\t\t\t\t\t{'services.enrollment': body.enrollmentToken}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (user) {\n\t\t\t\t\t\t\tif (user.active) {\n\t\t\t\t\t\t\t\tawait Users.setPassword(user, body.password);\n\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: false,\n\t\t\t\t\t\t\t\t\tresult: true\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\t\tresult: 'Account is Disabled'\n\t\t\t\t\t\t\t\t}));\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\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\tresult: 'Invalid User'\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 {\n\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\tresult: 'Invalid Mongo Get User'\n\t\t\t\t\t\t}));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t});\n\n\tapp.post('/userWithForgotPasswordToken', bodyParser.json(), async (request, response) => {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_SECONDARY_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\tforgotPasswordToken: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/userWithForgotPasswordToken)', errors);\n\t\n\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/userWithForgotPasswordToken' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tjwt.verify(body.forgotPasswordToken, serverConfig['JWT_SECRET'], async (err, decoded) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Token'\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlet user = await Users.findOne({\n\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t{_id: decoded['id_user']},\n\t\t\t\t\t\t\t\t{'services.forgot_password': body.forgotPasswordToken}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}, {projection: {_id: 1, __v: 1, username: 1, active: 1}});\n\t\t\t\t\t\t\t\n\t\t\t\t\t\tif (user) {\n\t\t\t\t\t\t\tif (user.active) {\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: false,\n\t\t\t\t\t\t\t\t\tresult: {\n\t\t\t\t\t\t\t\t\t\tuser: user\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\t\tresult: 'Account is Disabled'\n\t\t\t\t\t\t\t\t}));\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\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\tresult: 'Invalid Token'\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 {\n\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\tresult: 'Invalid Mongo Get User'\n\t\t\t\t\t\t}));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t});\n\n\tapp.post('/setUserWithForgotPasswordToken', bodyParser.json(), async (request, response) => {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_SECONDARY_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\tforgotPasswordToken: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/setUserWithForgotPasswordToken)', errors);\n\t\n\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/setUserWithForgotPasswordToken' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tjwt.verify(body.forgotPasswordToken, serverConfig['JWT_SECRET'], async (err, decoded) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Token'\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlet user = await Users.findOne({\n\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t{_id: decoded['id_user']},\n\t\t\t\t\t\t\t\t{'services.forgot_password': body.forgotPasswordToken}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\n\t\t\t\t\t\tif (user) {\n\t\t\t\t\t\t\tif (user.active) {\n\t\t\t\t\t\t\t\tawait Users.setPassword(user, body.password);\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: false,\n\t\t\t\t\t\t\t\t\tresult: true\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\t\tresult: 'Account is Disabled'\n\t\t\t\t\t\t\t\t}));\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\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\t\tresult: 'Invalid User'\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 {\n\t\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\tresult: 'Invalid Mongo Get User'\n\t\t\t\t\t\t}));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t});\n\n\tapp.post('/resetPassword', bodyParser.json(), async (request, response) => {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\tusername: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/resetPassword)', errors);\n\t\n\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/resetPassword' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet user = await Users.findOne({active: true, username: body.username});\n\n\t\t\tif (!user) {\n\t\t\t\tuser = await Users.findOne({active: true, email: body.username});\n\t\t\t}\n\t\t\t\n\t\t\tif (user) {\n\t\t\t\tmainServer.getMethodManager().callMethod.call(mainServer.getMethodManager(), 'resetUserPassword', user._id);\n\t\t\t}\n\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: false,\n\t\t\t\tresult: ''\n\t\t\t}));\n\t\t}\n\t});\n}"]}
package/http/home.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.setupHomeRoutes=void 0;var simpl_schema_1=require("simpl-schema"),resolveio_server_app_1=require("../resolveio-server-app"),bodyParser=require("body-parser");function setupHomeRoutes(t,e,i){e.post("/resolveioContactUs",bodyParser.json(),function(e,r){if(e.headers.origin!==i.ROOT_URL&&e.headers.origin!==i.SEC_ROOT_URL)r.send(JSON.stringify({error:!0,result:"Invalid header"}));else{var o=e.body,s=new simpl_schema_1.default({form:{type:Object},"form.name":{type:String},"form.email":{type:String},"form.phone":{type:String},"form.subject":{type:String},"form.message":{type:String}});try{s.validate(o)}catch(e){if(e)return console.error(new Date,"Error in HTTP Check (/resolveioContactUs)",e),resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().sendEmail("dev@resolveio.com",resolveio_server_app_1.ResolveIOServer.getClientName()+"HTTP - Error Detected","Match Error On HTTP /resolveioContactUs\n\nData Being Checked\n"+JSON.stringify(o,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2)),void r.send(JSON.stringify({error:!0,result:"Invalid Parameters"}))}s=e.body.form;t.getMethodManager().sendEmail("dustin@resolveio.com","ResolveIO - Contact Us","","Name: "+s.name+"<br>Email: "+s.email+"<br>Phone: "+s.phone+"<br>Subject: "+s.subject+"<br>Message: "+s.message+"<br>"),r.send(JSON.stringify({error:!1,result:null}))}})}exports.setupHomeRoutes=setupHomeRoutes;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,n,o,s){return new(o=o||Promise)(function(t,r){function fulfilled(e){try{step(s.next(e))}catch(e){r(e)}}function rejected(e){try{step(s.throw(e))}catch(e){r(e)}}function step(e){var r;e.done?t(e.value):((r=e.value)instanceof o?r:new o(function(e){e(r)})).then(fulfilled,rejected)}step((s=s.apply(e,n||[])).next())})},__generator=this&&this.__generator||function(n,o){var s,a,i,l={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},u={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function verb(t){return function(e){var r=[t,e];if(s)throw new TypeError("Generator is already executing.");for(;l=u&&r[u=0]?0:l;)try{if(s=1,a&&(i=2&r[0]?a.return:r[0]?a.throw||((i=a.return)&&i.call(a),0):a.next)&&!(i=i.call(a,r[1])).done)return i;switch(a=0,(r=i?[2&r[0],i.value]:r)[0]){case 0:case 1:i=r;break;case 4:return l.label++,{value:r[1],done:!1};case 5:l.label++,a=r[1],r=[0];continue;case 7:r=l.ops.pop(),l.trys.pop();continue;default:if(!(i=0<(i=l.trys).length&&i[i.length-1])&&(6===r[0]||2===r[0])){l=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3]))l.label=r[1];else if(6===r[0]&&l.label<i[1])l.label=i[1],i=r;else{if(!(i&&l.label<i[2])){i[2]&&l.ops.pop(),l.trys.pop();continue}l.label=i[2],l.ops.push(r)}}r=o.call(n,l)}catch(e){r=[6,e],a=0}finally{s=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}}},bodyParser=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.setupHomeRoutes=void 0,require("body-parser")),simpl_schema_1=require("simpl-schema"),resolveio_server_app_1=require("../resolveio-server-app");function setupHomeRoutes(a,e,i){var r=this;e.post("/resolveioContactUs",bodyParser.json(),function(o,s){return __awaiter(r,void 0,void 0,function(){var r,t,n;return __generator(this,function(e){switch(e.label){case 0:return o.headers.origin===i.ROOT_URL||o.headers.origin===i.SEC_ROOT_URL?[3,1]:(s.send(JSON.stringify({error:!0,result:"Invalid header"})),[3,7]);case 1:r=o.body,t=new simpl_schema_1.default({form:{type:Object},"form.name":{type:String},"form.email":{type:String},"form.phone":{type:String},"form.subject":{type:String},"form.message":{type:String}}),e.label=2;case 2:return e.trys.push([2,3,,6]),t.validate(r),[3,6];case 3:return(n=e.sent())?(console.error(new Date,"Error in HTTP Check (/resolveioContactUs)",n),[4,resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().sendEmail("dev@resolveio.com",resolveio_server_app_1.ResolveIOServer.getClientName()+"HTTP - Error Detected","Match Error On HTTP /resolveioContactUs\n\nData Being Checked\n"+JSON.stringify(r,null,2)+"\n\nErrors\n"+JSON.stringify(n,null,2))]):[3,5];case 4:return e.sent(),s.send(JSON.stringify({error:!0,result:"Invalid Parameters"})),[2];case 5:return[3,6];case 6:n=o.body.form,a.getMethodManager().sendEmail("dustin@resolveio.com","ResolveIO - Contact Us","","Name: "+n.name+"<br>Email: "+n.email+"<br>Phone: "+n.phone+"<br>Subject: "+n.subject+"<br>Message: "+n.message+"<br>"),s.send(JSON.stringify({error:!1,result:null})),e.label=7;case 7:return[2]}})})})}exports.setupHomeRoutes=setupHomeRoutes;
2
2
  //# sourceMappingURL=home.js.map
package/http/home.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/http/home.ts"],"names":["simpl_schema_1","require","resolveio_server_app_1","bodyParser","setupHomeRoutes","mainServer","app","serverConfig","post","json","request","response","headers","origin","send","JSON","stringify","error","result","body","schema","default","form","type","Object","form.name","String","form.email","form.phone","form.subject","form.message","validate","errors","console","Date","ResolveIOServer","getMainServer","getMethodManager","sendEmail","getClientName","name","email","phone","subject","message","exports"],"mappings":"mGAAA,IAAAA,eAAAC,QAAA,cAAA,EACAC,uBAAAD,QAAA,yBAAA,EACAE,WAAAF,QAAA,aAAA,EAEA,SAAgBG,gBAAgBC,EAAYC,EAAKC,GAChDD,EAAIE,KAAK,sBAAuBL,WAAWM,KAAI,EAAI,SAAUC,EAASC,GACrE,GAAID,EAAQE,QAAQC,SAAWN,EAAuB,UAAKG,EAAQE,QAAQC,SAAWN,EAA2B,aAChHI,EAASG,KAAKC,KAAKC,UAAU,CAC5BC,MAAO,CAAA,EACPC,OAAQ,gB,CACR,CAAC,MAEE,CACJ,IAAIC,EAAOT,EAAQS,KAEfC,EAAS,IAAIpB,eAAAqB,QAAa,CAC7BC,KAAM,CACLC,KAAMC,M,EAEPC,YAAa,CACZF,KAAMG,M,EAEPC,aAAc,CACbJ,KAAMG,M,EAEPE,aAAc,CACbL,KAAMG,M,EAEPG,eAAgB,CACfN,KAAMG,M,EAEPI,eAAgB,CACfP,KAAMG,M,EAEP,EAED,IACCN,EAAOW,SAASZ,CAAI,C,CAErB,MAAOa,GACN,GAAIA,EAUH,OATAC,QAAQhB,MAAM,IAAIiB,KAAQ,4CAA6CF,CAAM,EAE7E9B,uBAAAiC,gBAAgBC,cAAa,EAAGC,iBAAgB,EAAGC,UAAU,oBAAqBpC,uBAAAiC,gBAAgBI,cAAa,EAAK,wBAAyB,kEAA8ExB,KAAKC,UAAUG,EAAM,KAAM,CAAC,EAAI,eAAiBJ,KAAKC,UAAUgB,EAAQ,KAAM,CAAC,CAAC,EAF3SC,KAIAtB,EAASG,KAAKC,KAAKC,UAAU,CAC5BC,MAAO,CAAA,EACPC,OAAQ,oB,CACR,CAAC,C,CAMSI,EAAOZ,EAAQS,KAAKG,KAExBjB,EAAWgC,iBAAgB,EAAGC,UAAU,uBAAwB,yBAA0B,GAC1F,SAAWhB,EAAKkB,KAChB,cAAYlB,EAAKmB,MACjB,cAAYnB,EAAKoB,MACjB,gBAAcpB,EAAKqB,QACnB,gBAAcrB,EAAKsB,QAAU,MAAM,EAEnCjC,EAASG,KAAKC,KAAKC,UAAU,CACrCC,MAAO,CAAA,EACPC,OAAQ,I,CACR,CAAC,C,CAEJ,CAAC,CACF,CAjEA2B,QAAAzC,gBAAAA","file":"home.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport * as bodyParser from 'body-parser';\n\nexport function setupHomeRoutes(mainServer, app, serverConfig) {\n\tapp.post('/resolveioContactUs', bodyParser.json(), function (request, response) {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\tform: {\n\t\t\t\t\ttype: Object\n\t\t\t\t},\n\t\t\t\t'form.name': {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\t'form.email': {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\t'form.phone': {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\t'form.subject': {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\t'form.message': {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/resolveioContactUs)', errors);\n\t\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/resolveioContactUs' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n let form = request.body.form;\n \n mainServer.getMethodManager().sendEmail('dustin@resolveio.com', 'ResolveIO - Contact Us', '', \n 'Name: ' + form.name + '<br>' + \n 'Email: ' + form.email + '<br>' + \n 'Phone: ' + form.phone + '<br>' + \n 'Subject: ' + form.subject + '<br>' + \n 'Message: ' + form.message + '<br>');\n\n response.send(JSON.stringify({\n\t\t\t\terror: false,\n\t\t\t\tresult: null\n\t\t\t}));\n\t\t}\n\t});\n}"]}
1
+ {"version":3,"sources":["../../src/http/home.ts"],"names":["bodyParser","require","simpl_schema_1","resolveio_server_app_1","setupHomeRoutes","mainServer","app","serverConfig","_this","this","post","json","request","response","__awaiter","headers","origin","send","JSON","stringify","error","result","body","schema","default","form","type","Object","form.name","String","form.email","form.phone","form.subject","form.message","validate","console","Date","errors_1","ResolveIOServer","getMainServer","getMethodManager","sendEmail","getClientName","_a","sent","name","email","phone","subject","message","exports"],"mappings":"k8CAAAA,Y,sFAAAC,QAAA,aAAA,GACAC,eAAAD,QAAA,cAAA,EACAE,uBAAAF,QAAA,yBAAA,EAEA,SAAgBG,gBAAgBC,EAAYC,EAAKC,GAAjD,IAAAC,EAAAC,KACCH,EAAII,KAAK,sBAAuBV,WAAWW,KAAI,EAAI,SAAOC,EAASC,GAAQ,OAAAC,UAAAN,EAAA,KAAA,EAAA,KAAA,EAAA,W,4EACtEI,EAAQG,QAAQC,SAAW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chema from 'simpl-schema';\nimport { ResolveIOServer } from '../resolveio-server-app';\n\nexport function setupHomeRoutes(mainServer, app, serverConfig) {\n\tapp.post('/resolveioContactUs', bodyParser.json(), async (request, response) => {\n\t\tif (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL']) {\n\t\t\tresponse.send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Invalid header'\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\tlet body = request.body;\n\n\t\t\tlet schema = new SimpleSchema({\n\t\t\t\tform: {\n\t\t\t\t\ttype: Object\n\t\t\t\t},\n\t\t\t\t'form.name': {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\t'form.email': {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\t'form.phone': {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\t'form.subject': {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\t'form.message': {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\ttry {\n\t\t\t\tschema.validate(body);\n\t\t\t}\n\t\t\tcatch (errors) {\n\t\t\t\tif (errors) {\n\t\t\t\t\tconsole.error(new Date(), 'Error in HTTP Check (/resolveioContactUs)', errors);\n\t\n\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/resolveioContactUs' + '\\n\\nData Being Checked\\n' + JSON.stringify(body, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(errors, null, 2));\n\t\n\t\t\t\t\tresponse.send(JSON.stringify({\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\tresult: 'Invalid Parameters'\n\t\t\t\t\t}));\n\t\t\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n let form = request.body.form;\n \n mainServer.getMethodManager().sendEmail('dustin@resolveio.com', 'ResolveIO - Contact Us', '', \n 'Name: ' + form.name + '<br>' + \n 'Email: ' + form.email + '<br>' + \n 'Phone: ' + form.phone + '<br>' + \n 'Subject: ' + form.subject + '<br>' + \n 'Message: ' + form.message + '<br>');\n\n response.send(JSON.stringify({\n\t\t\t\terror: false,\n\t\t\t\tresult: null\n\t\t\t}));\n\t\t}\n\t});\n}"]}
@@ -3,7 +3,9 @@ export declare class CronManager {
3
3
  private _watchCrons$;
4
4
  private _jobs;
5
5
  constructor();
6
- watchCrons(): Promise<void>;
6
+ static create(): CronManager;
7
+ private initialize;
8
+ private watchCrons;
7
9
  private doesCronJobExist;
8
10
  private doesCronJobNameExist;
9
11
  private addCronJob;
@@ -1,2 +1,2 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,o,r,i){return new(r=r||Promise)(function(t,n){function fulfilled(e){try{step(i.next(e))}catch(e){n(e)}}function rejected(e){try{step(i.throw(e))}catch(e){n(e)}}function step(e){var n;e.done?t(e.value):((n=e.value)instanceof r?n:new r(function(e){e(n)})).then(fulfilled,rejected)}step((i=i.apply(e,o||[])).next())})},__generator=this&&this.__generator||function(o,r){var i,a,s,c={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},_={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(_[Symbol.iterator]=function(){return this}),_;function verb(t){return function(e){var n=[t,e];if(i)throw new TypeError("Generator is already executing.");for(;c=_&&n[_=0]?0:c;)try{if(i=1,a&&(s=2&n[0]?a.return:n[0]?a.throw||((s=a.return)&&s.call(a),0):a.next)&&!(s=s.call(a,n[1])).done)return s;switch(a=0,(n=s?[2&n[0],s.value]:n)[0]){case 0:case 1:s=n;break;case 4:return c.label++,{value:n[1],done:!1};case 5:c.label++,a=n[1],n=[0];continue;case 7:n=c.ops.pop(),c.trys.pop();continue;default:if(!(s=0<(s=c.trys).length&&s[s.length-1])&&(6===n[0]||2===n[0])){c=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]<s[3]))c.label=n[1];else if(6===n[0]&&c.label<s[1])c.label=s[1],s=n;else{if(!(s&&c.label<s[2])){s[2]&&c.ops.pop(),c.trys.pop();continue}c.label=s[2],c.ops.push(n)}}n=r.call(o,c)}catch(e){n=[6,e],a=0}finally{i=s=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}}},cron_job_collection_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.CronManager=void 0,require("../collections/cron-job.collection")),cron_1=require("../cron/cron"),cron_job_history_collection_1=require("../collections/cron-job-history.collection"),resolveio_server_app_1=require("../resolveio-server-app"),common_1=require("../util/common"),CronManager=function(){function CronManager(){this._jobs=[],this._cronManager=new cron_1.CronJobManager,this.watchCrons()}return CronManager.prototype.watchCrons=function(){return __awaiter(this,void 0,void 0,function(){var n=this;return __generator(this,function(e){switch(e.label){case 0:return this._watchCrons$&&!this._watchCrons$.closed&&(this._watchCrons$.removeAllListeners(),this._watchCrons$.close(),this._watchCrons$=null),[4,new Promise(function(e){return setTimeout(e,1e3)})];case 1:return e.sent(),this._watchCrons$&&!this._watchCrons$.closed||(cron_job_collection_1.CronJobs.find().then(function(e){n._jobs=e,n._jobs.forEach(function(e){n.addCronJob(e),e.running&&cron_job_collection_1.CronJobs.updateOne({_id:e._id},{$set:{running:!1}})})}),this._watchCrons$=cron_job_collection_1.CronJobs.watchCollection([],{fullDocument:"updateLookup"}),this._watchCrons$.on("change",function(o){return __awaiter(n,void 0,void 0,function(){var n,t;return __generator(this,function(e){return"insert"===o.operationType?o.fullDocument&&(this._jobs.some(function(e){return e._id===o.documentKey._id})||this._jobs.push(o.fullDocument),this.addCronJob(o.fullDocument)):"replace"===o.operationType||"update"===o.operationType?o.fullDocument?(n=this._jobs.find(function(e){return e._id===o.documentKey._id}))?(this._jobs.splice(this._jobs.map(function(e){return e._id}).indexOf(o.documentKey._id),1,o.fullDocument),n.name!==o.fullDocument.name?(this.removeCronJob(n.name),this.addCronJob(o.fullDocument)):(typeof n.time_to_run!=typeof o.fullDocument.time_to_run||"string"==typeof n.time_to_run&&n.time_to_run!==o.fullDocument.time_to_run||n.time_to_run instanceof Date&&n.time_to_run.getTime()!==o.fullDocument.time_to_run.getTime()||n.timezone!==o.fullDocument.timezone)&&this.updateCronJob(o.fullDocument)):(this._jobs.push(o.fullDocument),this.addCronJob(o.fullDocument)):this._jobs.some(function(e){return e._id===o.documentKey._id})&&(t=this._jobs.find(function(e){return e._id===o.documentKey._id}),this.removeCronJob(t.name),this._jobs.splice(this._jobs.map(function(e){return e._id}).indexOf(o.documentKey._id),1)):"delete"===o.operationType&&this._jobs.some(function(e){return e._id===o.documentKey._id})&&(t=this._jobs.find(function(e){return e._id===o.documentKey._id}),this.removeCronJob(t.name),this._jobs.splice(this._jobs.map(function(e){return e._id}).indexOf(o.documentKey._id),1)),[2]})})}).on("error",function(e){n._watchCrons$.removeAllListeners(),n._watchCrons$.close(),n._watchCrons$=null,n.watchCrons()}).on("end",function(){n._watchCrons$.removeAllListeners(),n._watchCrons$.close(),n._watchCrons$=null,n.watchCrons()}).on("close",function(){n._watchCrons$.removeAllListeners(),n._watchCrons$=null,n.watchCrons()})),[2]}})})},CronManager.prototype.doesCronJobExist=function(e){return this._cronManager.exists(e.name)},CronManager.prototype.doesCronJobNameExist=function(e){return this._cronManager.exists(e)},CronManager.prototype.addCronJob=function(n){var e=this;if(!this.doesCronJobExist(n))try{this._cronManager.add(n.name,n.time_to_run,function(){return e.runCronJob(n)},null,!0,n.timezone,null,!1);var t=new Date(this._cronManager.getJob(n.name).nextDate().ts);(n.running||t&&!n.next_run||t.getTime()!==n.next_run.getTime())&&cron_job_collection_1.CronJobs.updateOne({_id:n._id},{$set:{running:!1,next_run:t||null}})}catch(e){console.log("Cron error",e),n.time_to_run instanceof Date&&this.runCronJob(n)}},CronManager.prototype.updateCronJob=function(e){var n,t=this;this.doesCronJobExist(e)&&(this._cronManager.update(e.name,e.time_to_run,function(){return t.runCronJob(e)},null,!0,e.timezone),!(n=new Date(this._cronManager.getJob(e.name).nextDate().ts))||e.next_run&&n.getTime()===e.next_run.getTime()||cron_job_collection_1.CronJobs.updateOne({_id:e._id},{$set:{next_run:n}}))},CronManager.prototype.removeCronJob=function(e){this.doesCronJobNameExist(e)&&this._cronManager.delete(e)},CronManager.prototype.startCronJob=function(e){this.doesCronJobExist(e)&&this._cronManager.start(e.name)},CronManager.prototype.stopCronJob=function(e){this.doesCronJobExist(e)&&this._cronManager.stop(e.name)},CronManager.prototype.stopAllCronJobs=function(){this._cronManager.stopAll()},CronManager.prototype.runCronJob=function(s){var e=this,n=new Date;cron_job_collection_1.CronJobs.findOneAndUpdate({$and:[{_id:s._id},{running:!1},{$or:[{next_run:{$exists:!1}},{next_run:null},{next_run:{$lte:n}}]}]},{$set:{running:!0}}).then(function(a){return __awaiter(e,void 0,void 0,function(){var t,n,o,r,i=this;return __generator(this,function(e){switch(e.label){case 0:return a?(t={_id:(0,common_1.objectIdHexString)(),name:a.name,reoccuring:a.repeat,time_to_run:a.time_to_run,method_name:a.method_run,id_cronjob:a._id,server_restart:!0,passed:!0,error:"",date_scheduled:a.next_run,date_start:new Date,date_end:null,date_next:null},[4,cron_job_history_collection_1.CronJobHistories.create(t)]):[3,14];case 1:e.sent(),n=setTimeout(function(){return __awaiter(i,void 0,void 0,function(){var n;return __generator(this,function(e){return console.log(new Date,"Cron Timeout",JSON.stringify(s,null,2)),a.repeat?(n=new Date(this._cronManager.getJob(a.name).nextDate().ts),t.date_next=n,cron_job_collection_1.CronJobs.updateOne({_id:a._id},{$set:{running:!1,next_run:n}})):cron_job_collection_1.CronJobs.deleteOne({_id:a._id}),[2]})})},3e5),e.label=2;case 2:return(e.trys.push([2,11,12,13]),a.method_run_data)?[4,resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethodCron(a.method_run,a.method_run_data)]:[3,4];case 3:return e.sent(),[3,6];case 4:return[4,resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethodCron(a.method_run)];case 5:e.sent(),e.label=6;case 6:return a.method_complete?a.method_complete_data?[4,resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethodCron(a.method_complete,a.method_complete_data)]:[3,8]:[3,10];case 7:return e.sent(),[3,10];case 8:return[4,resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethodCron(a.method_complete)];case 9:e.sent(),e.label=10;case 10:return[3,13];case 11:return o=e.sent(),console.log(new Date,"Cron Error",JSON.stringify(o,null,2)),t.error=JSON.stringify(o,null,2),t.passed=!1,a.repeat?(r=new Date(this._cronManager.getJob(a.name).nextDate().ts),t.date_next=r,cron_job_collection_1.CronJobs.updateOne({_id:a._id},{$set:{running:!1,next_run:r}})):cron_job_collection_1.CronJobs.deleteOne({_id:a._id}),[3,13];case 12:return clearTimeout(n),[7];case 13:a.repeat?(r=new Date(this._cronManager.getJob(a.name).nextDate().ts),t.date_next=r,cron_job_collection_1.CronJobs.updateOne({_id:a._id},{$set:{running:!1,next_run:r}})):cron_job_collection_1.CronJobs.deleteOne({_id:a._id}),cron_job_history_collection_1.CronJobHistories.updateOne({_id:t._id},{$set:{server_restart:!1,passed:t.passed,error:t.error,date_end:new Date,date_next:t.date_next}}),e.label=14;case 14:return[2]}})})},function(){})},CronManager}();exports.CronManager=CronManager;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,r,o,a){return new(o=o||Promise)(function(t,n){function fulfilled(e){try{step(a.next(e))}catch(e){n(e)}}function rejected(e){try{step(a.throw(e))}catch(e){n(e)}}function step(e){var n;e.done?t(e.value):((n=e.value)instanceof o?n:new o(function(e){e(n)})).then(fulfilled,rejected)}step((a=a.apply(e,r||[])).next())})},__generator=this&&this.__generator||function(r,o){var a,i,s,c={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},u={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function verb(t){return function(e){var n=[t,e];if(a)throw new TypeError("Generator is already executing.");for(;c=u&&n[u=0]?0:c;)try{if(a=1,i&&(s=2&n[0]?i.return:n[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,n[1])).done)return s;switch(i=0,(n=s?[2&n[0],s.value]:n)[0]){case 0:case 1:s=n;break;case 4:return c.label++,{value:n[1],done:!1};case 5:c.label++,i=n[1],n=[0];continue;case 7:n=c.ops.pop(),c.trys.pop();continue;default:if(!(s=0<(s=c.trys).length&&s[s.length-1])&&(6===n[0]||2===n[0])){c=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]<s[3]))c.label=n[1];else if(6===n[0]&&c.label<s[1])c.label=s[1],s=n;else{if(!(s&&c.label<s[2])){s[2]&&c.ops.pop(),c.trys.pop();continue}c.label=s[2],c.ops.push(n)}}n=o.call(r,c)}catch(e){n=[6,e],i=0}finally{a=s=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}}},__values=this&&this.__values||function(e){var n="function"==typeof Symbol&&Symbol.iterator,t=n&&e[n],r=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return{value:(e=e&&r>=e.length?void 0:e)&&e[r++],done:!e}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},cron_job_history_collection_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.CronManager=void 0,require("../collections/cron-job-history.collection")),cron_job_collection_1=require("../collections/cron-job.collection"),cron_1=require("../cron/cron"),resolveio_server_app_1=require("../resolveio-server-app"),common_1=require("../util/common"),CronManager=function(){function CronManager(){this._jobs=[]}return CronManager.create=function(){var e=this,n=new CronManager;return setImmediate(function(){return __awaiter(e,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return[4,n.initialize()];case 1:return[2,e.sent()]}})})}),n},CronManager.prototype.initialize=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._cronManager=new cron_1.CronJobManager,[4,this.watchCrons()];case 1:return e.sent(),[2]}})})},CronManager.prototype.watchCrons=function(){return __awaiter(this,void 0,void 0,function(){var n,t,r,o,a,i,s=this;return __generator(this,function(e){switch(e.label){case 0:return!this._watchCrons$||this._watchCrons$.closed?[3,2]:(this._watchCrons$.removeAllListeners(),[4,this._watchCrons$.close()]);case 1:e.sent(),this._watchCrons$=null,e.label=2;case 2:return[4,new Promise(function(e){return setTimeout(e,1e3)})];case 3:return e.sent(),this._watchCrons$&&!this._watchCrons$.closed?[3,14]:[4,cron_job_collection_1.CronJobs.find()];case 4:o=e.sent(),this._jobs=o,e.label=5;case 5:e.trys.push([5,11,12,13]),n=__values(this._jobs),t=n.next(),e.label=6;case 6:return t.done?[3,10]:(r=t.value,[4,this.addCronJob(r)]);case 7:return(e.sent(),r.running)?[4,cron_job_collection_1.CronJobs.updateOne({_id:r._id},{$set:{running:!1}})]:[3,9];case 8:e.sent(),e.label=9;case 9:return t=n.next(),[3,6];case 10:return[3,13];case 11:return o=e.sent(),a={error:o},[3,13];case 12:try{t&&!t.done&&(i=n.return)&&i.call(n)}finally{if(a)throw a.error}return[7];case 13:this._watchCrons$=cron_job_collection_1.CronJobs.watchCollection([],{fullDocument:"updateLookup"}),this._watchCrons$.on("change",function(r){return __awaiter(s,void 0,void 0,function(){var n,t;return __generator(this,function(e){switch(e.label){case 0:return"insert"!==r.operationType?[3,3]:r.fullDocument?(this._jobs.some(function(e){return e._id===r.documentKey._id})||this._jobs.push(r.fullDocument),[4,this.addCronJob(r.fullDocument)]):[3,2];case 1:e.sent(),e.label=2;case 2:return[3,14];case 3:return"replace"!==r.operationType&&"update"!==r.operationType?[3,13]:r.fullDocument?(n=this._jobs.find(function(e){return e._id===r.documentKey._id}))?(this._jobs.splice(this._jobs.map(function(e){return e._id}).indexOf(r.documentKey._id),1,r.fullDocument),n.name===r.fullDocument.name?[3,5]:(this.removeCronJob(n.name),[4,this.addCronJob(r.fullDocument)])):[3,8]:[3,11];case 4:return e.sent(),[3,7];case 5:return typeof n.time_to_run!=typeof r.fullDocument.time_to_run||"string"==typeof n.time_to_run&&n.time_to_run!==r.fullDocument.time_to_run||n.time_to_run instanceof Date&&n.time_to_run.getTime()!==r.fullDocument.time_to_run.getTime()||n.timezone!==r.fullDocument.timezone?[4,this.updateCronJob(r.fullDocument)]:[3,7];case 6:e.sent(),e.label=7;case 7:return[3,10];case 8:return this._jobs.push(r.fullDocument),[4,this.addCronJob(r.fullDocument)];case 9:e.sent(),e.label=10;case 10:return[3,12];case 11:this._jobs.some(function(e){return e._id===r.documentKey._id})&&(t=this._jobs.find(function(e){return e._id===r.documentKey._id}),this.removeCronJob(t.name),this._jobs.splice(this._jobs.map(function(e){return e._id}).indexOf(r.documentKey._id),1)),e.label=12;case 12:return[3,14];case 13:"delete"===r.operationType&&this._jobs.some(function(e){return e._id===r.documentKey._id})&&(t=this._jobs.find(function(e){return e._id===r.documentKey._id}),this.removeCronJob(t.name),this._jobs.splice(this._jobs.map(function(e){return e._id}).indexOf(r.documentKey._id),1)),e.label=14;case 14:return[2]}})})}).on("error",function(){return __awaiter(s,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return[4,this._watchCrons$.close()];case 1:return e.sent(),[2]}})})}).on("end",function(){return __awaiter(s,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return[4,this._watchCrons$.close()];case 1:return e.sent(),[2]}})})}).on("close",function(){return __awaiter(s,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._watchCrons$.removeAllListeners(),this._watchCrons$=null,[4,this.watchCrons()];case 1:return e.sent(),[2]}})})}),e.label=14;case 14:return[2]}})})},CronManager.prototype.doesCronJobExist=function(e){return this._cronManager.exists(e.name)},CronManager.prototype.doesCronJobNameExist=function(e){return this._cronManager.exists(e)},CronManager.prototype.addCronJob=function(r){return __awaiter(this,void 0,void 0,function(){var n,t=this;return __generator(this,function(e){switch(e.label){case 0:if(this.doesCronJobExist(r))return[3,7];e.label=1;case 1:return(e.trys.push([1,4,,7]),this._cronManager.add(r.name,r.time_to_run,function(){return t.runCronJob(r)},null,!0,r.timezone,null,!1),n=new Date(this._cronManager.getJob(r.name).nextDate().ts),r.running||n&&!r.next_run||n.getTime()!==r.next_run.getTime())?[4,cron_job_collection_1.CronJobs.updateOne({_id:r._id},{$set:{running:!1,next_run:n||null}})]:[3,3];case 2:e.sent(),e.label=3;case 3:return[3,7];case 4:return(n=e.sent(),console.log("Cron error",n),r.time_to_run instanceof Date)?[4,this.runCronJob(r)]:[3,6];case 5:e.sent(),e.label=6;case 6:return[3,7];case 7:return[2]}})})},CronManager.prototype.updateCronJob=function(r){return __awaiter(this,void 0,void 0,function(){var n,t=this;return __generator(this,function(e){switch(e.label){case 0:return this.doesCronJobExist(r)?(this._cronManager.update(r.name,r.time_to_run,function(){return t.runCronJob(r)},null,!0,r.timezone),!(n=new Date(this._cronManager.getJob(r.name).nextDate().ts))||r.next_run&&n.getTime()===r.next_run.getTime()?[3,2]:[4,cron_job_collection_1.CronJobs.updateOne({_id:r._id},{$set:{next_run:n}})]):[3,2];case 1:e.sent(),e.label=2;case 2:return[2]}})})},CronManager.prototype.removeCronJob=function(e){this.doesCronJobNameExist(e)&&this._cronManager.delete(e)},CronManager.prototype.startCronJob=function(e){this.doesCronJobExist(e)&&this._cronManager.start(e.name)},CronManager.prototype.stopCronJob=function(e){this.doesCronJobExist(e)&&this._cronManager.stop(e.name)},CronManager.prototype.stopAllCronJobs=function(){this._cronManager.stopAll()},CronManager.prototype.runCronJob=function(s){return __awaiter(this,void 0,void 0,function(){var t,r,n,o,a,i=this;return __generator(this,function(e){switch(e.label){case 0:return o=new Date,[4,cron_job_collection_1.CronJobs.findOneAndUpdate({$and:[{_id:s._id},{running:!1},{$or:[{next_run:{$exists:!1}},{next_run:null},{next_run:{$lte:o}}]}]},{$set:{running:!0}})];case 1:return(t=e.sent())?(r={_id:(0,common_1.objectIdHexString)(),name:t.name,reoccuring:t.repeat,time_to_run:t.time_to_run,method_name:t.method_run,id_cronjob:t._id,server_restart:!0,passed:!0,error:"",date_scheduled:t.next_run,date_start:new Date,date_end:null,date_next:null},[4,cron_job_history_collection_1.CronJobHistories.create(r)]):[3,24];case 2:e.sent(),n=setTimeout(function(){return __awaiter(i,void 0,void 0,function(){var n;return __generator(this,function(e){switch(e.label){case 0:return(console.log(new Date,"Cron Timeout",JSON.stringify(s,null,2)),t.repeat)?(n=new Date(this._cronManager.getJob(t.name).nextDate().ts),r.date_next=n,[4,cron_job_collection_1.CronJobs.updateOne({_id:t._id},{$set:{running:!1,next_run:n}})]):[3,2];case 1:return e.sent(),[3,4];case 2:return[4,cron_job_collection_1.CronJobs.deleteOne({_id:t._id})];case 3:e.sent(),e.label=4;case 4:return[2]}})})},3e5),e.label=3;case 3:return(e.trys.push([3,12,17,18]),t.method_run_data)?[4,resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethodCron(t.method_run,t.method_run_data)]:[3,5];case 4:return e.sent(),[3,7];case 5:return[4,resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethodCron(t.method_run)];case 6:e.sent(),e.label=7;case 7:return t.method_complete?t.method_complete_data?[4,resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethodCron(t.method_complete,t.method_complete_data)]:[3,9]:[3,11];case 8:return e.sent(),[3,11];case 9:return[4,resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethodCron(t.method_complete)];case 10:e.sent(),e.label=11;case 11:return[3,18];case 12:return(o=e.sent(),console.log(new Date,"Cron Error",JSON.stringify(o,null,2)),r.error=JSON.stringify(o,null,2),r.passed=!1,t.repeat)?(a=new Date(this._cronManager.getJob(t.name).nextDate().ts),r.date_next=a,[4,cron_job_collection_1.CronJobs.updateOne({_id:t._id},{$set:{running:!1,next_run:a}})]):[3,14];case 13:return e.sent(),[3,16];case 14:return[4,cron_job_collection_1.CronJobs.deleteOne({_id:t._id})];case 15:e.sent(),e.label=16;case 16:return[3,18];case 17:return clearTimeout(n),[7];case 18:return t.repeat?(a=new Date(this._cronManager.getJob(t.name).nextDate().ts),r.date_next=a,[4,cron_job_collection_1.CronJobs.updateOne({_id:t._id},{$set:{running:!1,next_run:a}})]):[3,20];case 19:return e.sent(),[3,22];case 20:return[4,cron_job_collection_1.CronJobs.deleteOne({_id:t._id})];case 21:e.sent(),e.label=22;case 22:return[4,cron_job_history_collection_1.CronJobHistories.updateOne({_id:r._id},{$set:{server_restart:!1,passed:r.passed,error:r.error,date_end:new Date,date_next:r.date_next}})];case 23:e.sent(),e.label=24;case 24:return[2]}})})},CronManager}();exports.CronManager=CronManager;
2
2
  //# sourceMappingURL=cron.manager.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/managers/cron.manager.ts"],"names":["cron_job_collection_1","require","cron_1","cron_job_history_collection_1","resolveio_server_app_1","common_1","CronManager","this","_jobs","_cronManager","CronJobManager","watchCrons","prototype","_watchCrons$","closed","removeAllListeners","close","Promise","resolve","setTimeout","_a","sent","CronJobs","find","then","res","_this","forEach","job","addCronJob","running","updateOne","_id","$set","watchCollection","fullDocument","on","doc","__awaiter","operationType","some","a","documentKey","push","oldDoc","splice","map","indexOf","name","removeCronJob","time_to_run","Date","getTime","timezone","updateCronJob","err","doesCronJobExist","cron","exists","doesCronJobNameExist","cron_name","add","runCronJob","nextDate","getJob","next_run","e","console","log","update","delete","startCronJob","start","stopCronJob","stop","stopAllCronJobs","stopAll","now","findOneAndUpdate","$and","$or","$exists","$lte","cronHistory_1","objectIdHexString","reoccuring","repeat","method_name","method_run","id_cronjob","server_restart","passed","error","date_scheduled","date_start","date_end","date_next","CronJobHistories","create","timeoutHandle","JSON","stringify","deleteOne","method_run_data","ResolveIOServer","getMainServer","getMethodManager","callMethodCron","method_complete","method_complete_data","err_1","clearTimeout","exports"],"mappings":"k8CACAA,uB,kFAAAC,QAAA,oCAAA,GACAC,OAAAD,QAAA,cAAA,EAEAE,8BAAAF,QAAA,4CAAA,EAEAG,uBAAAH,QAAA,yBAAA,EACAI,SAAAJ,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IAAKP,EAAIO,GAAG,CAAC,E,sBAKlC+E,aAAaZ,CAAa,E,YAGvB1E,EAAI6D,QACHvB,EAAW,IAAIZ,KAAK5C,KAAKE,aAAauD,OAAOvC,EAAIuB,IAAI,EAAEe,SAAQ,EAAO,EAAC,EAC3EoB,EAAYa,UAAYjC,EACxB/D,sBAAAsB,SAASS,UAAU,CAACC,IAAKP,EAAIO,GAAG,EAAG,CAACC,KAAM,CAACH,QAAS,CAAA,EAAOmC,SAAUF,CAAQ,CAAC,CAAC,GAG/E/D,sBAAAsB,SAASgF,UAAU,CAACtE,IAAKP,EAAIO,GAAG,CAAC,EAGlC7B,8BAAA8F,iBAAiBlE,UAAU,CAACC,IAAKmD,EAAYnD,GAAG,EAAG,CAACC,KAAM,CACzDyD,eAAgB,CAAA,EAChBC,OAAQR,EAAYQ,OACpBC,MAAOT,EAAYS,MACnBG,SAAU,IAAI5C,KACd6C,UAAWb,EAAYa,S,CACvB,CAAC,E,mCAED,YAAQ,CACZ,EACD1F,WAAA,EAAC,EArRY0G,QAAA1G,YAAAA","file":"cron.manager.js","sourcesContent":["import { CronJobModel } from '../models/cron-job.model';\nimport { CronJobs } from '../collections/cron-job.collection';\nimport { CronJobManager } from '../cron/cron';\nimport { ChangeStream, ChangeStreamDocument } from 'mongodb';\nimport { CronJobHistories } from '../collections/cron-job-history.collection';\nimport { CronJobHistoryModel } from '../models/cron-job-history.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { objectIdHexString } from '../util/common';\n\nexport class CronManager {\n\tprivate _cronManager: CronJobManager;\n\tprivate _watchCrons$: ChangeStream;\n\tprivate _jobs: CronJobModel[] = [];\n\n\tconstructor() {\n\t\tthis._cronManager = new CronJobManager();\n\t\tthis.watchCrons();\n\t}\n\n\tpublic async watchCrons() {\n\t\tif (this._watchCrons$ && !this._watchCrons$.closed) {\n\t\t\tthis._watchCrons$.removeAllListeners();\n\t\t\tthis._watchCrons$.close();\n\t\t\tthis._watchCrons$ = null;\n\t\t}\n\t\n\t\tawait new Promise(resolve => setTimeout(resolve, 1000));\n\t\n\t\tif (!this._watchCrons$ || this._watchCrons$.closed) {\t\t\t\n\t\t\tCronJobs.find().then(res => {\n\t\t\t\tthis._jobs = res;\n\n\t\t\t\tthis._jobs.forEach(job => {\n\t\t\t\t\tthis.addCronJob(job);\n\t\t\t\t\tif (job.running) {\n\t\t\t\t\t\tCronJobs.updateOne({_id: job._id}, {$set: {running: false}});\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tthis._watchCrons$ = CronJobs.watchCollection([], {fullDocument: 'updateLookup'});\n\n\t\t\tthis._watchCrons$.on('change', async (doc: ChangeStreamDocument<CronJobModel>) => {\n\t\t\t\tif (doc.operationType === 'insert') {\n\t\t\t\t\tif (doc.fullDocument) {\n\t\t\t\t\t\tif (!this._jobs.some(a => a._id === <any>doc.documentKey['_id'])) {\n\t\t\t\t\t\t\tthis._jobs.push(doc.fullDocument);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis.addCronJob(doc.fullDocument);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (doc.operationType === 'replace' || doc.operationType === 'update') {\n\t\t\t\t\tif (doc.fullDocument) {\n\t\t\t\t\t\tlet oldDoc = this._jobs.find(a => a._id === <any>doc.documentKey['_id']);\n\t\t\t\t\t\tif (oldDoc) {\n\t\t\t\t\t\t\tthis._jobs.splice(this._jobs.map(a => a._id).indexOf(<any>doc.documentKey['_id']), 1, doc.fullDocument);\n\n\t\t\t\t\t\t\tif (oldDoc.name !== doc.fullDocument.name) {\n\t\t\t\t\t\t\t\tthis.removeCronJob(oldDoc.name);\n\t\t\t\t\t\t\t\tthis.addCronJob(doc.fullDocument);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if (typeof oldDoc.time_to_run !== typeof doc.fullDocument.time_to_run || (typeof oldDoc.time_to_run === 'string' && oldDoc.time_to_run !== doc.fullDocument.time_to_run) ||\n\t\t\t\t\t\t\t\t(oldDoc.time_to_run instanceof Date && oldDoc.time_to_run.getTime() !== (<Date>doc.fullDocument.time_to_run).getTime()) || \n\t\t\t\t\t\t\t\toldDoc.timezone !== doc.fullDocument.timezone\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tthis.updateCronJob(doc.fullDocument);\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\tthis._jobs.push(doc.fullDocument);\n\t\t\t\t\t\t\tthis.addCronJob(doc.fullDocument);\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\tif (this._jobs.some(a => a._id === <any>doc.documentKey['_id'])) {\n\t\t\t\t\t\t\tlet job = this._jobs.find(a => a._id === <any>doc.documentKey['_id']);\n\t\t\t\t\t\t\tthis.removeCronJob(job.name);\n\t\t\t\t\t\t\tthis._jobs.splice(this._jobs.map(a => a._id).indexOf(<any>doc.documentKey['_id']), 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (doc.operationType === 'delete') {\n\t\t\t\t\tif (this._jobs.some(a => a._id === (<any>doc).documentKey['_id'])) {\n\t\t\t\t\t\tlet job = this._jobs.find(a => a._id === <any>doc.documentKey['_id']);\n\t\t\t\t\t\tthis.removeCronJob(job.name);\n\t\t\t\t\t\tthis._jobs.splice(this._jobs.map(a => a._id).indexOf(<any>doc.documentKey['_id']), 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\t\t\t.on('error', (err) => {\n\t\t\t\tthis._watchCrons$.removeAllListeners();\n\t\t\t\tthis._watchCrons$.close();\n\t\t\t\tthis._watchCrons$ = null;\n\t\t\t\tthis.watchCrons();\n\t\t\t})\n\t\t\t.on('end', () => {\n\t\t\t\tthis._watchCrons$.removeAllListeners();\n\t\t\t\tthis._watchCrons$.close();\n\t\t\t\tthis._watchCrons$ = null;\n\t\t\t\tthis.watchCrons();\n\t\t\t})\n\t\t\t.on('close', () => {\n\t\t\t\tthis._watchCrons$.removeAllListeners();\n\t\t\t\tthis._watchCrons$ = null;\n\t\t\t\tthis.watchCrons();\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate doesCronJobExist(cron: CronJobModel) {\n\t\treturn this._cronManager.exists(cron.name);\n\t}\n\n\tprivate doesCronJobNameExist(cron_name: string) {\n\t\treturn this._cronManager.exists(cron_name);\n\t}\n\n\tprivate addCronJob(cron: CronJobModel) {\n\t\tif (!this.doesCronJobExist(cron)) {\n\t\t\ttry {\n\t\t\t\tthis._cronManager.add(\n\t\t\t\t\tcron.name,\n\t\t\t\t\tcron.time_to_run,\n\t\t\t\t\t() => this.runCronJob(cron),\n\t\t\t\t\tnull,\n\t\t\t\t\ttrue,\n\t\t\t\t\tcron.timezone,\n\t\t\t\t\tnull, \n\t\t\t\t\tfalse\n\t\t\t\t);\n\n\t\t\t\tlet nextDate = new Date(this._cronManager.getJob(cron.name).nextDate()['ts']);\n\n\t\t\t\tif (cron.running || (nextDate && !cron.next_run || nextDate.getTime() !== cron.next_run.getTime())) {\n\t\t\t\t\tCronJobs.updateOne({_id: cron._id}, {$set: {running: false, next_run: nextDate || null}});\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch(e) {\n\t\t\t\tconsole.log('Cron error', e);\n\n\t\t\t\tif (cron.time_to_run instanceof Date) {\n\t\t\t\t\tthis.runCronJob(cron);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.update(cron.name, cron.time_to_run, () => this.runCronJob(cron), null, true, cron.timezone);\n\n\t\t\tlet nextDate = new Date(this._cronManager.getJob(cron.name).nextDate()['ts']);\n\n\t\t\tif (nextDate && (!cron.next_run || nextDate.getTime() !== cron.next_run.getTime())) {\n\t\t\t\tCronJobs.updateOne({_id: cron._id}, {$set: {next_run: nextDate}});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate removeCronJob(cron_name: string) {\n\t\tif (this.doesCronJobNameExist(cron_name)) {\n\t\t\tthis._cronManager.delete(cron_name);\n\t\t}\n\t}\n\n\tprivate startCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.start(cron.name);\n\t\t}\n\t}\n\n\tprivate stopCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.stop(cron.name);\n\t\t}\n\t}\n\n\tprivate stopAllCronJobs() {\n\t\tthis._cronManager.stopAll();\n\t}\n\n\tprivate runCronJob(cron: CronJobModel) {\n\t\tlet now = new Date();\n\n\t\tCronJobs.findOneAndUpdate({\n\t\t\t$and: [\n\t\t\t\t{_id: cron._id},\n\t\t\t\t{running: false},\n\t\t\t\t{\n\t\t\t\t\t$or: [\n\t\t\t\t\t\t{next_run: {$exists: false}},\n\t\t\t\t\t\t{next_run: null},\n\t\t\t\t\t\t{next_run: {$lte: now}}\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t]\n\t\t}, {$set: {running: true}}).then(async res => {\n\t\t\tif (res) {\n\t\t\t\tlet cronHistory: CronJobHistoryModel = {\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\tname: res.name,\n\t\t\t\t\treoccuring: res.repeat,\n\t\t\t\t\ttime_to_run: res.time_to_run,\n\t\t\t\t\tmethod_name: res.method_run,\n\t\t\t\t\tid_cronjob: res._id,\n\t\t\t\t\tserver_restart: true,\n\t\t\t\t\tpassed: true,\n\t\t\t\t\terror: '',\n\t\t\t\t\tdate_scheduled: res.next_run,\n\t\t\t\t\tdate_start: new Date(),\n\t\t\t\t\tdate_end: null,\n\t\t\t\t\tdate_next: null\n\t\t\t\t};\n\t\t\t\t\n\t\t\t\tawait CronJobHistories.create(cronHistory);\n\n\t\t\t\tlet timeoutHandle = setTimeout(async () => {\n\t\t\t\t\tconsole.log(new Date(), 'Cron Timeout', JSON.stringify(cron, null, 2));\n\n\t\t\t\t\tif (res.repeat) {\n\t\t\t\t\t\tlet nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);\n\t\t\t\t\t\tcronHistory.date_next = nextDate;\n\t\t\t\t\t\tCronJobs.updateOne({_id: res._id}, {$set: {running: false, next_run: nextDate}});\n\t\t\t\t\t} \n\t\t\t\t\telse {\n\t\t\t\t\t\tCronJobs.deleteOne({_id: res._id});\n\t\t\t\t\t}\n\t\t\t\t}, 5 * 60 * 1000); // 5 minutes in milliseconds\n\n\t\t\t\ttry {\n\t\t\t\t\tif (res.method_run_data) {\n\t\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_run, res.method_run_data);\t\n\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_run);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (res.method_complete) {\n\t\t\t\t\t\tif (res.method_complete_data) {\n\t\t\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_complete, res.method_complete_data);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_complete);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\tconsole.log(new Date(), 'Cron Error', JSON.stringify(err, null, 2));\n\t\t\t\t\tcronHistory.error = JSON.stringify(err, null, 2);\n\t\t\t\t\tcronHistory.passed = false;\n\n\t\t\t\t\tif (res.repeat) {\n\t\t\t\t\t\tlet nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);\n\t\t\t\t\t\tcronHistory.date_next = nextDate;\n\t\t\t\t\t\tCronJobs.updateOne({_id: res._id}, {$set: {running: false, next_run: nextDate}});\n\t\t\t\t\t} \n\t\t\t\t\telse {\n\t\t\t\t\t\tCronJobs.deleteOne({_id: res._id});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfinally {\n\t\t\t\t\t// Clear the timeout if the job completes or fails before the timeout\n\t\t\t\t\tclearTimeout(timeoutHandle);\n\t\t\t\t}\n\n\t\t\t\tif (res.repeat) {\n\t\t\t\t\tlet nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);\n\t\t\t\t\tcronHistory.date_next = nextDate;\n\t\t\t\t\tCronJobs.updateOne({_id: res._id}, {$set: {running: false, next_run: nextDate}});\n\t\t\t\t} \n\t\t\t\telse {\n\t\t\t\t\tCronJobs.deleteOne({_id: res._id});\n\t\t\t\t}\n\n\t\t\t\tCronJobHistories.updateOne({_id: cronHistory._id}, {$set: {\n\t\t\t\t\tserver_restart: false,\n\t\t\t\t\tpassed: cronHistory.passed,\n\t\t\t\t\terror: cronHistory.error,\n\t\t\t\t\tdate_end: new Date(),\n\t\t\t\t\tdate_next: cronHistory.date_next\n\t\t\t\t}});\n\t\t\t}\n\t\t}, () => {});\n\t}\n}"]}
1
+ {"version":3,"sources":["../../src/managers/cron.manager.ts"],"names":["cron_job_history_collection_1","require","cron_job_collection_1","cron_1","resolveio_server_app_1","common_1","CronManager","this","_jobs","create","_this","cronManager","setImmediate","__awaiter","__generator","_a","initialize","sent","prototype","_cronManager","CronJobManager","watchCrons","_watchCrons$","closed","removeAllListeners","close","_d","Promise","resolve","setTimeout","CronJobs","find","res","__values","_b","next","job","value","addCronJob","running","updateOne","_id","$set","watchCollection","fullDocument","on","doc","operationType","some","a","documentKey","push","oldDoc","splice","map","indexOf","name","removeCronJob","time_to_run","Date","getTime","timezone","updateCronJob","doesCronJobExist","cron","exists","doesCronJobNameExist","cron_name","add","runCronJob","nextDate","getJob","next_run","console","log","e_2","update","delete","startCronJob","start","stopCronJob","stop","stopAllCronJobs","stopAll","now","findOneAndUpdate","$and","$or","$exists","$lte","cronHistory_1","objectIdHexString","reoccuring","repeat","method_name","method_run","id_cronjob","server_restart","passed","error","date_scheduled","date_start","date_end","date_next","CronJobHistories","timeoutHandle","JSON","stringify","deleteOne","method_run_data","ResolveIOServer","getMainServer","getMethodManager","callMethodCron","method_complete","method_complete_data","err_1","clearTimeout","exports"],"mappings":"wwDACAA,+B,kFAAAC,QAAA,4CAAA,GACAC,sBAAAD,QAAA,oCAAA,EACAE,OAAAF,QAAA,cAAA,EAGAG,uBAAAH,QAAA,yBAAA,EACAI,SAAAJ,QAAA,gBAAA,EAEAK,YAAA,WAKC,SAAAA,cAFQC,KAAAC,MAAwB,EAEjB,CAkRhB,OAhRQF,YAAAG,OAAP,WAAA,IAAAC,EAAAH,KACOI,EAAc,IAAIL,YAExB,OADAM,aAAa,WAAA,OAAAC,UAAAH,EAAA,KAAA,EAAA,KAAA,EAAA,WAAA,OAAAI,YAAAP,KAAA,SAAAQ,G,uBAAY,MAAA,CAAA,EAAMJ,EAAYK,WAAU,G,OAA5B,MAAA,CAAA,EAAAD,EAAAE,KAAA,E,MAA8B,EAChDN,CACR,EAEcL,YAAAY,UAAAF,WAAd,W,0GAEC,OADAT,KAAKY,aAAe,IAAIhB,OAAAiB,eACxB,CAAA,EAAMb,KAAKc,WAAU,G,cAArBN,EAAAE,KAAA,E,UAGaX,YAAAY,UAAAG,WAAd,W,uIACKd,CAAAA,KAAKe,cAAiBf,KAAKe,aAAaC,OAAxC,CAAA,EAAA,IACHhB,KAAKe,aAAaE,mBAAkB,EACpC,CAAA,EAAMjB,KAAKe,aAAaG,MAAK,I,OAA7BC,EAAAT,KAAA,EACAV,KAAKe,aAAe,K,iBAIrB,MAAA,CAAA,EAAM,IAAIK,QAAQ,SAAAC,GAAW,OAAAC,WAAWD,EAAS,GAAI,CAAxB,CAAyB,G,cAAtDF,EAAAT,KAAA,EAEKV,KAAKe,cAAgBf,CAAAA,KAAKe,aAAaC,OAAxC,CAAA,EAAA,IACO,CAAA,EAAMrB,sBAAA4B,SAASC,KAAI,G,OAAzBC,EAAMN,EAAAT,KAAA,EACVV,KAAKC,MAAQwB,E,2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EAAO,EAAC,EAC3EoB,EAAYa,UAAYjC,EACxB,CAAA,EAAMpE,sBAAA4B,SAASU,UAAU,CAACC,IAAKT,EAAIS,GAAG,EAAG,CAACC,KAAM,CAACH,QAAS,CAAA,EAAOiC,SAAUF,CAAQ,CAAC,CAAC,IAHlF,CAAA,EAAA,I,eAGHvD,EAAAE,KAAA,E,eAGA,MAAA,CAAA,EAAMf,sBAAA4B,SAAS8E,UAAU,CAACnE,IAAKT,EAAIS,GAAG,CAAC,G,QAAvC1B,EAAAE,KAAA,E,+CAKDoG,aAAaZ,CAAa,E,mBAGvBzE,EAAI6D,QACHvB,EAAW,IAAIX,KAAKpD,KAAKY,aAAaoD,OAAOvC,EAAIwB,IAAI,EAAEc,SAAQ,EAAO,EAAC,EAC3EoB,EAAYa,UAAYjC,EACxB,CAAA,EAAMpE,sBAAA4B,SAASU,UAAU,CAACC,IAAKT,EAAIS,GAAG,EAAG,CAACC,KAAM,CAACH,QAAS,CAAA,EAAOiC,SAAUF,CAAQ,CAAC,CAAC,IAHlF,CAAA,EAAA,I,eAGHvD,EAAAE,KAAA,E,eAGA,MAAA,CAAA,EAAMf,sBAAA4B,SAAS8E,UAAU,CAACnE,IAAKT,EAAIS,GAAG,CAAC,G,QAAvC1B,EAAAE,KAAA,E,mBAGD,MAAA,CAAA,EAAMjB,8BAAAwG,iBAAiBhE,UAAU,CAACC,IAAKiD,EAAYjD,GAAG,EAAG,CAACC,KAAM,CAC/DuD,eAAgB,CAAA,EAChBC,OAAQR,EAAYQ,OACpBC,MAAOT,EAAYS,MACnBG,SAAU,IAAI3C,KACd4C,UAAWb,EAAYa,S,CACvB,CAAC,G,QANFxF,EAAAE,KAAA,E,mCASHX,WAAA,EAAC,EAvRYgH,QAAAhH,YAAAA","file":"cron.manager.js","sourcesContent":["import { ChangeStream, ChangeStreamDocument } from 'mongodb';\nimport { CronJobHistories } from '../collections/cron-job-history.collection';\nimport { CronJobs } from '../collections/cron-job.collection';\nimport { CronJobManager } from '../cron/cron';\nimport { CronJobHistoryModel } from '../models/cron-job-history.model';\nimport { CronJobModel } from '../models/cron-job.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { objectIdHexString } from '../util/common';\n\nexport class CronManager {\n\tprivate _cronManager: CronJobManager;\n\tprivate _watchCrons$: ChangeStream;\n\tprivate _jobs: CronJobModel[] = [];\n\n\tconstructor() {}\n\n\tstatic create() {\n\t\tconst cronManager = new CronManager();\n\t\tsetImmediate(async () => await cronManager.initialize());\n\t\treturn cronManager;\n\t}\n\n\tprivate async initialize() {\n\t\tthis._cronManager = new CronJobManager();\n\t\tawait this.watchCrons();\n\t}\n\n\tprivate async watchCrons() {\n\t\tif (this._watchCrons$ && !this._watchCrons$.closed) {\n\t\t\tthis._watchCrons$.removeAllListeners();\n\t\t\tawait this._watchCrons$.close();\n\t\t\tthis._watchCrons$ = null;\n\t\t}\n\t\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\tawait new Promise(resolve => setTimeout(resolve, 1000));\n\t\n\t\tif (!this._watchCrons$ || this._watchCrons$.closed) {\t\t\t\n\t\t\tlet res = await CronJobs.find();\n\t\t\tthis._jobs = res;\n\n\t\t\tfor (let job of this._jobs) {\n\t\t\t\tawait this.addCronJob(job);\n\t\t\t\tif (job.running) {\n\t\t\t\t\tawait CronJobs.updateOne({_id: job._id}, {$set: {running: false}});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis._watchCrons$ = CronJobs.watchCollection([], {fullDocument: 'updateLookup'});\n\n\t\t\tthis._watchCrons$.on('change', async (doc: ChangeStreamDocument<CronJobModel>) => {\n\t\t\t\tif (doc.operationType === 'insert') {\n\t\t\t\t\tif (doc.fullDocument) {\n\t\t\t\t\t\tif (!this._jobs.some(a => a._id === <any>doc.documentKey['_id'])) {\n\t\t\t\t\t\t\tthis._jobs.push(doc.fullDocument);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait this.addCronJob(doc.fullDocument);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (doc.operationType === 'replace' || doc.operationType === 'update') {\n\t\t\t\t\tif (doc.fullDocument) {\n\t\t\t\t\t\tlet oldDoc = this._jobs.find(a => a._id === <any>doc.documentKey['_id']);\n\t\t\t\t\t\tif (oldDoc) {\n\t\t\t\t\t\t\tthis._jobs.splice(this._jobs.map(a => a._id).indexOf(<any>doc.documentKey['_id']), 1, doc.fullDocument);\n\n\t\t\t\t\t\t\tif (oldDoc.name !== doc.fullDocument.name) {\n\t\t\t\t\t\t\t\tthis.removeCronJob(oldDoc.name);\n\t\t\t\t\t\t\t\tawait this.addCronJob(doc.fullDocument);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if (typeof oldDoc.time_to_run !== typeof doc.fullDocument.time_to_run || (typeof oldDoc.time_to_run === 'string' && oldDoc.time_to_run !== doc.fullDocument.time_to_run) ||\n\t\t\t\t\t\t\t\t(oldDoc.time_to_run instanceof Date && oldDoc.time_to_run.getTime() !== (<Date>doc.fullDocument.time_to_run).getTime()) || \n\t\t\t\t\t\t\t\toldDoc.timezone !== doc.fullDocument.timezone\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tawait this.updateCronJob(doc.fullDocument);\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\tthis._jobs.push(doc.fullDocument);\n\t\t\t\t\t\t\tawait this.addCronJob(doc.fullDocument);\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\tif (this._jobs.some(a => a._id === <any>doc.documentKey['_id'])) {\n\t\t\t\t\t\t\tlet job = this._jobs.find(a => a._id === <any>doc.documentKey['_id']);\n\t\t\t\t\t\t\tthis.removeCronJob(job.name);\n\t\t\t\t\t\t\tthis._jobs.splice(this._jobs.map(a => a._id).indexOf(<any>doc.documentKey['_id']), 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (doc.operationType === 'delete') {\n\t\t\t\t\tif (this._jobs.some(a => a._id === (<any>doc).documentKey['_id'])) {\n\t\t\t\t\t\tlet job = this._jobs.find(a => a._id === <any>doc.documentKey['_id']);\n\t\t\t\t\t\tthis.removeCronJob(job.name);\n\t\t\t\t\t\tthis._jobs.splice(this._jobs.map(a => a._id).indexOf(<any>doc.documentKey['_id']), 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\t\t\t.on('error', async () => {\n\t\t\t\tawait this._watchCrons$.close();\n\t\t\t})\n\t\t\t.on('end', async () => {\n\t\t\t\tawait this._watchCrons$.close();\n\t\t\t})\n\t\t\t.on('close', async () => {\n\t\t\t\tthis._watchCrons$.removeAllListeners();\n\t\t\t\tthis._watchCrons$ = null;\n\t\t\t\tawait this.watchCrons();\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate doesCronJobExist(cron: CronJobModel) {\n\t\treturn this._cronManager.exists(cron.name);\n\t}\n\n\tprivate doesCronJobNameExist(cron_name: string) {\n\t\treturn this._cronManager.exists(cron_name);\n\t}\n\n\tprivate async addCronJob(cron: CronJobModel) {\n\t\tif (!this.doesCronJobExist(cron)) {\n\t\t\ttry {\n\t\t\t\tthis._cronManager.add(\n\t\t\t\t\tcron.name,\n\t\t\t\t\tcron.time_to_run,\n\t\t\t\t\t() => this.runCronJob(cron),\n\t\t\t\t\tnull,\n\t\t\t\t\ttrue,\n\t\t\t\t\tcron.timezone,\n\t\t\t\t\tnull, \n\t\t\t\t\tfalse\n\t\t\t\t);\n\n\t\t\t\tlet nextDate = new Date(this._cronManager.getJob(cron.name).nextDate()['ts']);\n\n\t\t\t\tif (cron.running || (nextDate && !cron.next_run || nextDate.getTime() !== cron.next_run.getTime())) {\n\t\t\t\t\tawait CronJobs.updateOne({_id: cron._id}, {$set: {running: false, next_run: nextDate || null}});\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch(e) {\n\t\t\t\tconsole.log('Cron error', e);\n\n\t\t\t\tif (cron.time_to_run instanceof Date) {\n\t\t\t\t\tawait this.runCronJob(cron);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async updateCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.update(cron.name, cron.time_to_run, () => this.runCronJob(cron), null, true, cron.timezone);\n\n\t\t\tlet nextDate = new Date(this._cronManager.getJob(cron.name).nextDate()['ts']);\n\n\t\t\tif (nextDate && (!cron.next_run || nextDate.getTime() !== cron.next_run.getTime())) {\n\t\t\t\tawait CronJobs.updateOne({_id: cron._id}, {$set: {next_run: nextDate}});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate removeCronJob(cron_name: string) {\n\t\tif (this.doesCronJobNameExist(cron_name)) {\n\t\t\tthis._cronManager.delete(cron_name);\n\t\t}\n\t}\n\n\tprivate startCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.start(cron.name);\n\t\t}\n\t}\n\n\tprivate stopCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.stop(cron.name);\n\t\t}\n\t}\n\n\tprivate stopAllCronJobs() {\n\t\tthis._cronManager.stopAll();\n\t}\n\n\tprivate async runCronJob(cron: CronJobModel) {\n\t\tlet now = new Date();\n\n\t\tlet res = await CronJobs.findOneAndUpdate({\n\t\t\t$and: [\n\t\t\t\t{_id: cron._id},\n\t\t\t\t{running: false},\n\t\t\t\t{\n\t\t\t\t\t$or: [\n\t\t\t\t\t\t{next_run: {$exists: false}},\n\t\t\t\t\t\t{next_run: null},\n\t\t\t\t\t\t{next_run: {$lte: now}}\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t]\n\t\t}, {$set: {running: true}});\n\t\t\t\n\t\tif (res) {\n\t\t\tlet cronHistory: CronJobHistoryModel = {\n\t\t\t\t_id: objectIdHexString(),\n\t\t\t\tname: res.name,\n\t\t\t\treoccuring: res.repeat,\n\t\t\t\ttime_to_run: res.time_to_run,\n\t\t\t\tmethod_name: res.method_run,\n\t\t\t\tid_cronjob: res._id,\n\t\t\t\tserver_restart: true,\n\t\t\t\tpassed: true,\n\t\t\t\terror: '',\n\t\t\t\tdate_scheduled: res.next_run,\n\t\t\t\tdate_start: new Date(),\n\t\t\t\tdate_end: null,\n\t\t\t\tdate_next: null\n\t\t\t};\n\t\t\t\n\t\t\tawait CronJobHistories.create(cronHistory);\n\n\t\t\tlet timeoutHandle = setTimeout(async () => {\n\t\t\t\tconsole.log(new Date(), 'Cron Timeout', JSON.stringify(cron, null, 2));\n\n\t\t\t\tif (res.repeat) {\n\t\t\t\t\tlet nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);\n\t\t\t\t\tcronHistory.date_next = nextDate;\n\t\t\t\t\tawait CronJobs.updateOne({_id: res._id}, {$set: {running: false, next_run: nextDate}});\n\t\t\t\t} \n\t\t\t\telse {\n\t\t\t\t\tawait CronJobs.deleteOne({_id: res._id});\n\t\t\t\t}\n\t\t\t}, 5 * 60 * 1000); // 5 minutes in milliseconds\n\n\t\t\ttry {\n\t\t\t\tif (res.method_run_data) {\n\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_run, res.method_run_data);\t\n\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_run);\n\t\t\t\t}\n\n\t\t\t\tif (res.method_complete) {\n\t\t\t\t\tif (res.method_complete_data) {\n\t\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_complete, res.method_complete_data);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_complete);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\tconsole.log(new Date(), 'Cron Error', JSON.stringify(err, null, 2));\n\t\t\t\tcronHistory.error = JSON.stringify(err, null, 2);\n\t\t\t\tcronHistory.passed = false;\n\n\t\t\t\tif (res.repeat) {\n\t\t\t\t\tlet nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);\n\t\t\t\t\tcronHistory.date_next = nextDate;\n\t\t\t\t\tawait CronJobs.updateOne({_id: res._id}, {$set: {running: false, next_run: nextDate}});\n\t\t\t\t} \n\t\t\t\telse {\n\t\t\t\t\tawait CronJobs.deleteOne({_id: res._id});\n\t\t\t\t}\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\t// Clear the timeout if the job completes or fails before the timeout\n\t\t\t\tclearTimeout(timeoutHandle);\n\t\t\t}\n\n\t\t\tif (res.repeat) {\n\t\t\t\tlet nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);\n\t\t\t\tcronHistory.date_next = nextDate;\n\t\t\t\tawait CronJobs.updateOne({_id: res._id}, {$set: {running: false, next_run: nextDate}});\n\t\t\t} \n\t\t\telse {\n\t\t\t\tawait CronJobs.deleteOne({_id: res._id});\n\t\t\t}\n\n\t\t\tawait CronJobHistories.updateOne({_id: cronHistory._id}, {$set: {\n\t\t\t\tserver_restart: false,\n\t\t\t\tpassed: cronHistory.passed,\n\t\t\t\terror: cronHistory.error,\n\t\t\t\tdate_end: new Date(),\n\t\t\t\tdate_next: cronHistory.date_next\n\t\t\t}});\n\t\t}\n\t}\n}"]}
@@ -1,4 +1,4 @@
1
- export type LocalLogType = 'monitor-mongo' | 'monitor-memory' | 'monitor-cpu' | 'monitor-function' | 'log';
1
+ export type LocalLogType = 'monitor-mongo' | 'monitor-memory' | 'monitor-cpu' | 'monitor-function' | 'log' | 'log-subscription' | 'log-method-latency';
2
2
  export interface LocalLogModel {
3
3
  type: LocalLogType;
4
4
  data: any;
@@ -7,6 +7,8 @@ export interface LocalLogModel {
7
7
  export declare class LocalLogManager {
8
8
  private _logFilePath;
9
9
  constructor();
10
+ static create(): LocalLogManager;
11
+ private initialize;
10
12
  writeLog(logEntry: LocalLogModel): void;
11
13
  writeLogs(logEntries: LocalLogModel[]): void;
12
14
  /**
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LocalLogManager=void 0;var fs=require("fs"),resolveio_server_app_1=require("../resolveio-server-app"),LocalLogManager=function(){function LocalLogManager(){"https://resolveio.com"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||"http://localhost:4200"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||fs.existsSync("/home/ubuntu/resolveio/logs")||fs.mkdirSync("/home/ubuntu/resolveio/logs"),this._logFilePath="/home/ubuntu/resolveio/logs/local-logs.jsonl"}return LocalLogManager.prototype.writeLog=function(e){try{e.instance_index=process.env.NODE_APP_INSTANCE||"";var o=JSON.stringify(e)+"\n";fs.appendFileSync(this._logFilePath,o,{encoding:"utf8"})}catch(e){console.error(new Date,"LocalLogManager","Failed to write log to file:",e)}},LocalLogManager.prototype.writeLogs=function(e){if(e&&0!==e.length)try{var o=e.map(function(e){return e.instance_index=process.env.NODE_APP_INSTANCE||"",JSON.stringify(e)}).join("\n")+"\n";fs.appendFileSync(this._logFilePath,o,{encoding:"utf8"})}catch(e){console.error(new Date,"LocalLogManager","Failed to write logs batch:",e)}},LocalLogManager.prototype.offloadLogs=function(){var e=[];try{if(!fs.existsSync(this._logFilePath))return e;var o=fs.readFileSync(this._logFilePath,"utf8");if(0===o.trim().length)return e;e=o.split("\n").filter(function(e){return""!==e.trim()}),fs.writeFileSync(this._logFilePath,"")}catch(e){console.error(new Date,"LocalLogManager","Failed to offload logs:",e)}return e},LocalLogManager}();exports.LocalLogManager=LocalLogManager;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LocalLogManager=void 0;var fs=require("fs"),resolveio_server_app_1=require("../resolveio-server-app"),LocalLogManager=function(){function LocalLogManager(){}return LocalLogManager.create=function(){var e=new LocalLogManager;return e.initialize(),e},LocalLogManager.prototype.initialize=function(){"https://resolveio.com"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||"http://localhost:4200"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||fs.existsSync("/home/ubuntu/resolveio/logs")||fs.mkdirSync("/home/ubuntu/resolveio/logs"),this._logFilePath="/home/ubuntu/resolveio/logs/local-logs.jsonl"},LocalLogManager.prototype.writeLog=function(e){try{e.instance_index=process.env.NODE_APP_INSTANCE||"";var o=JSON.stringify(e)+"\n";fs.appendFileSync(this._logFilePath,o,{encoding:"utf8"})}catch(e){console.error(new Date,"LocalLogManager","Failed to write log to file:",e)}},LocalLogManager.prototype.writeLogs=function(e){if(e&&0!==e.length)try{var o=e.map(function(e){return e.instance_index=process.env.NODE_APP_INSTANCE||"",JSON.stringify(e)}).join("\n")+"\n";fs.appendFileSync(this._logFilePath,o,{encoding:"utf8"})}catch(e){console.error(new Date,"LocalLogManager","Failed to write logs batch:",e)}},LocalLogManager.prototype.offloadLogs=function(){var e=[];try{if(!fs.existsSync(this._logFilePath))return e;var o=fs.readFileSync(this._logFilePath,"utf8");if(0===o.trim().length)return e;e=o.split("\n").filter(function(e){return""!==e.trim()}),fs.writeFileSync(this._logFilePath,"")}catch(e){console.error(new Date,"LocalLogManager","Failed to offload logs:",e)}return e},LocalLogManager}();exports.LocalLogManager=LocalLogManager;
2
2
  //# sourceMappingURL=local-log.manager.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/managers/local-log.manager.ts"],"names":["fs","require","resolveio_server_app_1","LocalLogManager","ResolveIOServer","getServerConfig","existsSync","mkdirSync","this","_logFilePath","prototype","writeLog","logEntry","instance_index","process","env","NODE_APP_INSTANCE","log","JSON","stringify","appendFileSync","encoding","err","console","error","Date","writeLogs","logEntries","length","logs","map","join","offloadLogs","result","fileData","readFileSync","trim","split","filter","l","writeFileSync","exports"],"mappings":"mGAGA,IAAAA,GAAAC,QAAA,IAAA,EACAC,uBAAAD,QAAA,yBAAA,EAcAE,gBAAA,WAGC,SAAAA,kBA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KC,aAAc,EAAE,C,CAEvC,MAAMa,GACLC,QAAQC,MAAM,IAAIC,KAAQ,kBAAmB,0BAA2BH,CAAG,C,CAG5E,OAAOW,CACR,EACD9B,eAAA,EAAC,EA3EYsC,QAAAtC,gBAAAA","file":"local-log.manager.js","sourcesContent":["/***************\nlocal-logs.manager.ts\n****************/\nimport * as fs from 'fs';\nimport { ResolveIOServer } from '../resolveio-server-app';\n\nexport type LocalLogType = 'monitor-mongo' \n\t| 'monitor-memory'\n\t| 'monitor-cpu'\n\t| 'monitor-function'\n\t| 'log'\n\nexport interface LocalLogModel {\n\ttype: LocalLogType;\n\tdata: any;\n\tinstance_index?: string;\n}\n\nexport class LocalLogManager {\n\tprivate _logFilePath: string;\n\n\tconstructor() {\n\t\tif (\n\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] !== 'https://resolveio.com'\n\t\t\t&& ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200'\n\t\t) {\n\t\t\tif (!fs.existsSync('/home/ubuntu/resolveio/logs')) {\n\t\t\t\tfs.mkdirSync('/home/ubuntu/resolveio/logs');\n\t\t\t}\n\t\t}\n\t\t\n\t\tthis._logFilePath = '/home/ubuntu/resolveio/logs/local-logs.jsonl';\n\t}\n\n\t// Internal method to append a JSON line to the file\n\tpublic writeLog(logEntry: LocalLogModel): void {\n\t\ttry {\n\t\t\tlogEntry.instance_index = process.env.NODE_APP_INSTANCE || '';\n\n\t\t\tlet log = JSON.stringify(logEntry) + '\\n';\n\t\t\tfs.appendFileSync(this._logFilePath, log, { encoding: 'utf8' });\n\t\t}\n\t\tcatch(err) {\n\t\t\t// If there's an error writing logs, you might want to handle it or queue it\n\t\t\tconsole.error(new Date(), 'LocalLogManager', 'Failed to write log to file:', err);\n\t\t}\n\t}\n\n\tpublic writeLogs(logEntries: LocalLogModel[]): void {\n\t\tif (!logEntries || logEntries.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\t// Convert each item to a JSON string, add newline\n\t\t\tlet logs = logEntries.map(logEntry => {\n\t\t\t\tlogEntry.instance_index = process.env.NODE_APP_INSTANCE || '';\n\t\t\t\treturn JSON.stringify(logEntry);\n\t\t\t}).join('\\n') + '\\n';\n\t\t\tfs.appendFileSync(this._logFilePath, logs, { encoding: 'utf8' });\n\t\t}\n\t\tcatch (err) {\n\t\t\tconsole.error(new Date(), 'LocalLogManager', 'Failed to write logs batch:', err);\n\t\t}\n\t}\n\n\t/**\n\t * Reads all logs from disk, then empties the file.\n\t */\n\tpublic offloadLogs(): any[] {\n\t\tlet result = [];\n\n\t\ttry {\n\t\t\tif (!fs.existsSync(this._logFilePath)) {\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tlet fileData = fs.readFileSync(this._logFilePath, 'utf8');\n\t\t\tif (fileData.trim().length === 0) {\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tresult = fileData.split('\\n').filter(l => l.trim() !== '');\n\n\t\t\t// Truncate the file so we don't send logs more than once\n\t\t\tfs.writeFileSync(this._logFilePath, '');\n\t\t}\n\t\tcatch(err) {\n\t\t\tconsole.error(new Date(), 'LocalLogManager', 'Failed to offload logs:', err);\n\t\t}\n\n\t\treturn result;\n\t}\n}"]}
1
+ {"version":3,"sources":["../../src/managers/local-log.manager.ts"],"names":["fs","require","resolveio_server_app_1","LocalLogManager","create","localLogManager","initialize","prototype","ResolveIOServer","getServerConfig","existsSync","mkdirSync","this","_logFilePath","writeLog","logEntry","instance_index","process","env","NODE_APP_INSTANCE","log","JSON","stringify","appendFileSync","encoding","err","console","error","Date","writeLogs","logEntries","length","logs","map","join","offloadLogs","result","fileData","readFileSync","trim","split","filter","l","writeFileSync","exports"],"mappings":"mGAGA,IAAAA,GAAAC,QAAA,IAAA,EACAC,uBAAAD,QAAA,yBAAA,EAgBAE,gBAAA,WAGC,SAAAA,mBAgFD,OA9EQA,gBAAAC,OAAP,WACC,IAAMC,EAAkB,IAAIF,gBAE5B,OADAE,EAAgBC,WAAU,EAC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EAGzDvC,GAAG2C,cAAc/B,KAAKC,aAAc,EAAE,C,CAEvC,MAAMY,GACLC,QAAQC,MAAM,IAAIC,KAAQ,kBAAmB,0BAA2BH,CAAG,C,CAG5E,OAAOW,CACR,EACDjC,eAAA,EAAC,EAnFYyC,QAAAzC,gBAAAA","file":"local-log.manager.js","sourcesContent":["/***************\nlocal-logs.manager.ts\n****************/\nimport * as fs from 'fs';\nimport { ResolveIOServer } from '../resolveio-server-app';\n\nexport type LocalLogType = 'monitor-mongo' \n\t| 'monitor-memory'\n\t| 'monitor-cpu'\n\t| 'monitor-function'\n\t| 'log'\n\t| 'log-subscription'\n\t| 'log-method-latency';\n\nexport interface LocalLogModel {\n\ttype: LocalLogType;\n\tdata: any;\n\tinstance_index?: string;\n}\n\nexport class LocalLogManager {\n\tprivate _logFilePath: string;\n\n\tconstructor() {}\n\n\tstatic create() {\n\t\tconst localLogManager = new LocalLogManager();\n\t\tlocalLogManager.initialize();\n\t\treturn localLogManager;\n\t}\n\n\tprivate initialize() {\n\t\tif (\n\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] !== 'https://resolveio.com'\n\t\t\t&& ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200'\n\t\t) {\n\t\t\tif (!fs.existsSync('/home/ubuntu/resolveio/logs')) {\n\t\t\t\tfs.mkdirSync('/home/ubuntu/resolveio/logs');\n\t\t\t}\n\t\t}\n\t\t\n\t\tthis._logFilePath = '/home/ubuntu/resolveio/logs/local-logs.jsonl';\n\t}\n\n\t// Internal method to append a JSON line to the file\n\tpublic writeLog(logEntry: LocalLogModel): void {\n\t\ttry {\n\t\t\tlogEntry.instance_index = process.env.NODE_APP_INSTANCE || '';\n\n\t\t\tlet log = JSON.stringify(logEntry) + '\\n';\n\t\t\tfs.appendFileSync(this._logFilePath, log, { encoding: 'utf8' });\n\t\t}\n\t\tcatch(err) {\n\t\t\t// If there's an error writing logs, you might want to handle it or queue it\n\t\t\tconsole.error(new Date(), 'LocalLogManager', 'Failed to write log to file:', err);\n\t\t}\n\t}\n\n\tpublic writeLogs(logEntries: LocalLogModel[]): void {\n\t\tif (!logEntries || logEntries.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\t// Convert each item to a JSON string, add newline\n\t\t\tlet logs = logEntries.map(logEntry => {\n\t\t\t\tlogEntry.instance_index = process.env.NODE_APP_INSTANCE || '';\n\t\t\t\treturn JSON.stringify(logEntry);\n\t\t\t}).join('\\n') + '\\n';\n\t\t\tfs.appendFileSync(this._logFilePath, logs, { encoding: 'utf8' });\n\t\t}\n\t\tcatch (err) {\n\t\t\tconsole.error(new Date(), 'LocalLogManager', 'Failed to write logs batch:', err);\n\t\t}\n\t}\n\n\t/**\n\t * Reads all logs from disk, then empties the file.\n\t */\n\tpublic offloadLogs(): any[] {\n\t\tlet result = [];\n\n\t\ttry {\n\t\t\tif (!fs.existsSync(this._logFilePath)) {\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tlet fileData = fs.readFileSync(this._logFilePath, 'utf8');\n\t\t\tif (fileData.trim().length === 0) {\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tresult = fileData.split('\\n').filter(l => l.trim() !== '');\n\n\t\t\t// Truncate the file so we don't send logs more than once\n\t\t\tfs.writeFileSync(this._logFilePath, '');\n\t\t}\n\t\tcatch(err) {\n\t\t\tconsole.error(new Date(), 'LocalLogManager', 'Failed to offload logs:', err);\n\t\t}\n\n\t\treturn result;\n\t}\n}"]}
@@ -1,10 +1,14 @@
1
+ import { S3 } from '@aws-sdk/client-s3';
2
+ import { EmailHistoryModel } from '../models/email-history.model';
1
3
  import { MethodModel } from '../models/method.model';
2
4
  import { MonitorManagerFunction } from './monitor.manager';
3
- import { S3 } from '@aws-sdk/client-s3';
5
+ import { WebSocketManager } from './websocket.manager';
4
6
  export declare class AWS {
5
7
  private _s3;
6
8
  private _s3USEast1;
7
9
  constructor();
10
+ create(): AWS;
11
+ private initialize;
8
12
  s3(): S3;
9
13
  s3USEast1(): S3;
10
14
  }
@@ -24,18 +28,19 @@ export declare class MethodManager {
24
28
  private _debugSendQueueHits;
25
29
  clientDir: string;
26
30
  serverConfig: string;
27
- constructor(monitorManagerFunction: MonitorManagerFunction, isWorkersEnabled: any, isWorkerInstance: any);
31
+ constructor();
32
+ static create(websocketManager: WebSocketManager, monitorManagerFunction: MonitorManagerFunction, isWorkersEnabled: any, isWorkerInstance: any): MethodManager;
33
+ private initialize;
28
34
  methods(method: MethodModel): void;
29
- callMethodCron(method: string, ...methodData: any[]): any;
35
+ callMethodCron(method: string, ...methodData: any[]): Promise<any>;
30
36
  callMethod(method: string, ...methodData: any[]): Promise<any>;
31
- private sendWS;
32
37
  setupEmailWatcher(): Promise<void>;
33
38
  loadPendingEmails(): Promise<void>;
34
39
  tryProcessEmail(): Promise<void>;
35
40
  safeStringify(obj: any): string;
36
41
  getCircularReplacer(): (key: any, value: any) => any;
37
- sendEmail(sendTo: string, subject: string, text?: string, html?: string, attachments?: any[], send_from?: string, reply_to?: string, local_override?: boolean): Promise<unknown>;
42
+ sendEmail(sendTo: string, subject: string, text?: string, html?: string, attachments?: any[], send_from?: string, reply_to?: string, local_override?: boolean): Promise<true | EmailHistoryModel>;
38
43
  getAWS(): AWS;
39
- readFile(fileName: any): Promise<unknown>;
40
- readImage(fileName: any): Promise<unknown>;
44
+ readFile(fileName: any): void;
45
+ readImage(fileName: any): void;
41
46
  }