@resolveio/server-lib 20.5.0 → 20.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/collections/app-status.collection.js +1 -1
- package/collections/app-status.collection.js.map +1 -1
- package/collections/counter.collection.js +1 -1
- package/collections/counter.collection.js.map +1 -1
- package/collections/cron-job-history.collection.js +1 -1
- package/collections/cron-job-history.collection.js.map +1 -1
- package/collections/cron-job.collection.js +1 -1
- package/collections/cron-job.collection.js.map +1 -1
- package/collections/email-history.collection.js +1 -1
- package/collections/email-history.collection.js.map +1 -1
- package/collections/email-verified.collection.js +1 -1
- package/collections/email-verified.collection.js.map +1 -1
- package/collections/file.collection.js +1 -1
- package/collections/file.collection.js.map +1 -1
- package/collections/flag-update.collection.js +1 -1
- package/collections/flag-update.collection.js.map +1 -1
- package/collections/flag.collection.js +1 -1
- package/collections/flag.collection.js.map +1 -1
- package/collections/log-method-latency.collection.js +1 -1
- package/collections/log-method-latency.collection.js.map +1 -1
- package/collections/log-subscription.collection.js +1 -1
- package/collections/log-subscription.collection.js.map +1 -1
- package/collections/log.collection.js +1 -1
- package/collections/log.collection.js.map +1 -1
- package/collections/logged-in-users.collection.js +1 -1
- package/collections/logged-in-users.collection.js.map +1 -1
- package/collections/method-response.collection.js +1 -1
- package/collections/method-response.collection.js.map +1 -1
- package/collections/monitor-cpu.collection.js +1 -1
- package/collections/monitor-cpu.collection.js.map +1 -1
- package/collections/monitor-memory.collection.js +1 -1
- package/collections/monitor-memory.collection.js.map +1 -1
- package/collections/monitor-mongo.collection.js +1 -1
- package/collections/monitor-mongo.collection.js.map +1 -1
- package/collections/notification.collection.js +1 -1
- package/collections/notification.collection.js.map +1 -1
- package/collections/report-builder-dashboard-builder.collection.js +1 -1
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
- package/collections/report-builder-library.collection.js +1 -1
- package/collections/report-builder-library.collection.js.map +1 -1
- package/collections/report-builder-report.collection.js +1 -1
- package/collections/report-builder-report.collection.js.map +1 -1
- package/collections/user-group.collection.js +1 -1
- package/collections/user-group.collection.js.map +1 -1
- package/collections/user-guide.collection.js +1 -1
- package/collections/user-guide.collection.js.map +1 -1
- package/collections/user.collection.js +1 -1
- package/collections/user.collection.js.map +1 -1
- package/collections/worker-task-request.collection.js +1 -1
- package/collections/worker-task-request.collection.js.map +1 -1
- package/collections/worker-task-response.collection.js +1 -1
- package/collections/worker-task-response.collection.js.map +1 -1
- package/fixtures/cron-jobs.js +1 -1
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +1 -1
- package/fixtures/init.js.map +1 -1
- package/http/auth.d.ts +1 -2
- package/http/auth.js +1 -1
- package/http/auth.js.map +1 -1
- package/http/home.d.ts +1 -2
- package/http/home.js +1 -1
- package/http/home.js.map +1 -1
- package/index.d.ts +0 -30
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/managers/cron.manager.js +1 -1
- package/managers/cron.manager.js.map +1 -1
- package/managers/local-log.manager.js +1 -1
- package/managers/local-log.manager.js.map +1 -1
- package/managers/method.manager.js +1 -1
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.d.ts +1 -2
- package/managers/mongo.manager.js +1 -1
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.d.ts +0 -1
- package/managers/monitor.manager.js +1 -1
- package/managers/monitor.manager.js.map +1 -1
- package/managers/subscription.manager.js +1 -1
- package/managers/subscription.manager.js.map +1 -1
- package/managers/websocket.manager.d.ts +1 -2
- package/managers/websocket.manager.js.map +1 -1
- package/methods/accounts.js +1 -1
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +1 -1
- package/methods/aws.js.map +1 -1
- package/methods/collections.js +1 -1
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +1 -1
- package/methods/counters.js.map +1 -1
- package/methods/logs.js +1 -1
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +1 -1
- package/methods/monitor.js.map +1 -1
- package/methods/report-builder.js +1 -1
- package/methods/report-builder.js.map +1 -1
- package/package.json +1 -1
- package/public_api.d.ts +1 -0
- package/public_api.js +1 -1
- package/public_api.js.map +1 -1
- package/resolveio-server-app.d.ts +31 -0
- package/resolveio-server-app.js +2 -0
- package/resolveio-server-app.js.map +1 -0
- package/server-app.d.ts +2 -1
- package/server-app.js +1 -1
- package/server-app.js.map +1 -1
- package/util/common.d.ts +1 -0
- package/util/common.js +1 -1
- package/util/common.js.map +1 -1
- package/util/schema-report-builder.js +1 -1
- package/util/schema-report-builder.js.map +1 -1
- package/client-server-app.d.ts +0 -1
- package/client-server-app.js +0 -2
- package/client-server-app.js.map +0 -1
package/http/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/http/auth.ts"],"names":["user_collection_1","require","jwt","handlebars","__1","mongo_manager_1","simpl_schema_1","bodyParser","jwt_decode_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","callMethodInternal","call","exports"],"mappings":"k8CAAAA,mB,sFAAAC,QAAA,gCAAA,GACAC,IAAAD,QAAA,cAAA,EACAE,WAAAF,QAAA,YAAA,EAEAG,IAAAH,QAAA,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IAAAiC,gBAAgBC,cAAa,EAAGC,iBAAgB,EAAGC,UAAU,oBAAqBpC,IAAAiC,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,mBAAmBC,KAAKpH,EAAW6B,iBAAgB,EAAI,oBAAqBU,EAAKM,GAAG,EAGnHrC,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 ResolveIOMainServer from '../server-app';\nimport { ResolveIOServer } from '..';\nimport { objectIdHexString } from '../managers/mongo.manager';\nimport { UserModel } from '../models/user.model';\nimport SimpleSchema from 'simpl-schema';\nimport * as bodyParser from 'body-parser';\nimport jwt_decode from 'jwt-decode';\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\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().callMethodInternal.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":["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","callMethodInternal","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,E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AAQ,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,mBAAmBC,KAAKpH,EAAW6B,iBAAgB,EAAI,oBAAqBU,EAAKM,GAAG,EAGnHrC,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().callMethodInternal.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.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function setupHomeRoutes(mainServer: ResolveIOMainServer, app: any, serverConfig: any): void;
|
|
1
|
+
export declare function setupHomeRoutes(mainServer: any, app: any, serverConfig: any): void;
|
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"),
|
|
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;
|
|
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","
|
|
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","send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,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}"]}
|
package/index.d.ts
CHANGED
|
@@ -1,31 +1 @@
|
|
|
1
|
-
import { Db, MongoClient } from 'mongodb';
|
|
2
|
-
import { LocalLogManager } from './managers/local-log.manager';
|
|
3
|
-
import { MongoManager } from './managers/mongo.manager';
|
|
4
|
-
import ResolveIOMainServer from './server-app';
|
|
5
|
-
export declare class ResolveIOServer {
|
|
6
|
-
private static _serverConfig;
|
|
7
|
-
private static _clientRoutes;
|
|
8
|
-
private static _mongoConnection;
|
|
9
|
-
private static _mainDB;
|
|
10
|
-
private static _mainServer;
|
|
11
|
-
private static _localLogManager;
|
|
12
|
-
private static _mongoManager;
|
|
13
|
-
private static _client;
|
|
14
|
-
private static _clientDir;
|
|
15
|
-
private static _sesMail;
|
|
16
|
-
private static _standardProgram;
|
|
17
|
-
constructor(serverConfig: any, clientRoutes: string[], client: string, clientDir: any, sesMail?: boolean, standardProgram?: boolean);
|
|
18
|
-
static connectAndRun(): Promise<unknown>;
|
|
19
|
-
static getClientName(): string;
|
|
20
|
-
static getMainServer(): ResolveIOMainServer;
|
|
21
|
-
static getMongoConnection(): MongoClient;
|
|
22
|
-
static getMainDB(): Db;
|
|
23
|
-
static getMongoManager(): MongoManager;
|
|
24
|
-
static getLocalLogManager(): LocalLogManager;
|
|
25
|
-
static getServerConfig(): any;
|
|
26
|
-
static getClientRoutes(): any[];
|
|
27
|
-
static getClientDir(): string;
|
|
28
|
-
static getSESMail(): boolean;
|
|
29
|
-
static getStandardProgram(): boolean;
|
|
30
|
-
}
|
|
31
1
|
export * from './public_api';
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,n,
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,n,t){void 0===t&&(t=n);var o=Object.getOwnPropertyDescriptor(r,n);o&&("get"in o?r.__esModule:!o.writable&&!o.configurable)||(o={enumerable:!0,get:function(){return r[n]}}),Object.defineProperty(e,t,o)}:function(e,r,n,t){e[t=void 0===t?n:t]=r[n]}),__exportStar=this&&this.__exportStar||function(e,r){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(r,n)||__createBinding(r,e,n)},__awaiter=this&&this.__awaiter||function(e,t,o,i){return new(o=o||Promise)(function(n,r){function fulfilled(e){try{step(i.next(e))}catch(e){r(e)}}function rejected(e){try{step(i.throw(e))}catch(e){r(e)}}function step(e){var r;e.done?n(e.value):((r=e.value)instanceof o?r:new o(function(e){e(r)})).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())})},__generator=this&&this.__generator||function(t,o){var i,s,a,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},c={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(c[Symbol.iterator]=function(){return this}),c;function verb(n){return function(e){var r=[n,e];if(i)throw new TypeError("Generator is already executing.");for(;l=c&&r[c=0]?0:l;)try{if(i=1,s&&(a=2&r[0]?s.return:r[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,r[1])).done)return a;switch(s=0,(r=a?[2&r[0],a.value]:r)[0]){case 0:case 1:a=r;break;case 4:return l.label++,{value:r[1],done:!1};case 5:l.label++,s=r[1],r=[0];continue;case 7:r=l.ops.pop(),l.trys.pop();continue;default:if(!(a=0<(a=l.trys).length&&a[a.length-1])&&(6===r[0]||2===r[0])){l=0;continue}if(3===r[0]&&(!a||r[1]>a[0]&&r[1]<a[3]))l.label=r[1];else if(6===r[0]&&l.label<a[1])l.label=a[1],a=r;else{if(!(a&&l.label<a[2])){a[2]&&l.ops.pop(),l.trys.pop();continue}l.label=a[2],l.ops.push(r)}}r=o.call(t,l)}catch(e){r=[6,e],s=0}finally{i=a=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}}},serverConfig=(Object.defineProperty(exports,"__esModule",{value:!0}),require("./settings.json")),mongodb_1=require("mongodb"),resolveio_server_app_1=require("./resolveio-server-app");function connectAndRun(){var e=this;mongodb_1.MongoClient.connect(resolveio_server_app_1.ResolveIOServer.getServerConfig().MONGO_URL).then(function(o){return __awaiter(e,void 0,void 0,function(){var r,n,t;return __generator(this,function(e){switch(e.label){case 0:return resolveio_server_app_1.ResolveIOServer.setMongoConnection(o),resolveio_server_app_1.ResolveIOServer.setMainDB(o.db(resolveio_server_app_1.ResolveIOServer.getServerConfig().DATABASE)),console.log(resolveio_server_app_1.ResolveIOServer.getServerConfig()),[4,Promise.resolve().then(function(){return require("./managers/local-log.manager")})];case 1:return r=e.sent().LocalLogManager,r=new r,resolveio_server_app_1.ResolveIOServer.setLocalLogManager(r),[4,Promise.resolve().then(function(){return require("./managers/mongo.manager")})];case 2:return r=e.sent().MongoManager,n=new r,resolveio_server_app_1.ResolveIOServer.setMongoManager(n),[4,n.initServerCollections()];case 3:return e.sent(),[4,Promise.resolve().then(function(){return require("./server-app")})];case 4:return n=e.sent().ResolveIOMainServer,t=new n,resolveio_server_app_1.ResolveIOServer.setMainServer(t),t.initServerApp(),[2]}})})},function(e){console.error(new Date,"MONGO CLIENT CONNECT FAILED",JSON.stringify(e,null,2)),process.exit(1)})}new resolveio_server_app_1.ResolveIOServer(serverConfig,[],"ResolveIO Server Library",__dirname),connectAndRun(),__exportStar(require("./public_api"),exports);
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":["serverConfig","require","mongodb_1","resolveio_server_app_1","connectAndRun","_this","this","MongoClient","connect","ResolveIOServer","getServerConfig","then","dbConnection","__awaiter","setMongoConnection","setMainDB","db","console","log","Promise","resolve","LocalLogManager","_a","sent","localLogManager","setLocalLogManager","MongoManager","mongoManager","setMongoManager","initServerCollections","serverApp","ResolveIOMainServer","app","setMainServer","initServerApp","err","error","Date","JSON","stringify","process","exit","__dirname","__exportStar","exports"],"mappings":"s5DAAIA,c,uDAAeC,QAAQ,iBAAiB,GAC5CC,UAAAD,QAAA,SAAA,EACAE,uBAAAF,QAAA,wBAAA,EAEA,SAASG,gBAAT,IAAAC,EAAAC,KACIJ,UAAAK,YAAYC,QAAQL,uBAAAM,gBAAgBC,gBAAe,EAAc,SAAC,EAAEC,KAAK,SAAMC,GAAY,OAAAC,UAAAR,EAAA,KAAA,EAAA,KAAA,EAAA,W,qEAQ5D,OAN3BF,uBAAAM,gBAAgBK,mBAAmBF,CAAY,EAC/CT,uBAAAM,gBAAgBM,UAAUH,EAAaI,GAAGb,uBAAAM,gBAAgBC,gBAAe,EAAa,QAAC,CAAC,EAExFO,QAAQC,IAAIf,uBAAAM,gBAAgBC,gBAAe,CAAE,EAGlB,CAAA,EAAAS,QAAAC,QAAA,EAAAT,KAAA,WAAA,OAAAV,QAAa,8BAA8B,CAAA,CAAA,G,OAI9C,OAJhBoB,EAAmBC,EAAAC,KAA4C,EAAEF,gBACjEG,EAAkB,IAAIH,EAC1BlB,uBAAAM,gBAAgBgB,mBAAmBD,CAAe,EAE9B,CAAA,EAAAL,QAAAC,QAAA,EAAAT,KAAA,WAAA,OAAAV,QAAa,0BAA0B,CAAA,CAAA,G,OAG3D,OAHIyB,EAAgBJ,EAAAC,KAAwC,EAAEG,aAC1DC,EAAe,IAAID,EACvBvB,uBAAAM,gBAAgBmB,gBAAgBD,CAAY,EAC5C,CAAA,EAAMA,EAAaE,sBAAqB,G,OAGvB,OAHjBP,EAAAC,KAAA,EAGiB,CAAA,EAAAJ,QAAAC,QAAA,EAAAT,KAAA,WAAA,OAAAV,QAAa,cAAc,CAAA,CAAA,G,cAAxC6B,EAAaR,EAAAC,KAA4B,EAAEQ,oBAC3CC,EAAM,IAAIF,EACd3B,uBAAAM,gBAAgBwB,cAAcD,CAAG,EACjCA,EAAIE,cAAa,E,UAItB,SAAAC,GACClB,QAAQmB,MAAM,IAAIC,KAAQ,8BAA+BC,KAAKC,UAAUJ,EAAK,KAAM,CAAC,CAAC,EACrFK,QAAQC,KAAK,CAAC,CAClB,CAAC,CACL,CAEA,IAAItC,uBAAAM,gBAAgBT,aAAc,GAAI,2BAA4B0C,SAAS,EAC3EtC,cAAa,EAEbuC,aAAA1C,QAAA,cAAA,EAAA2C,OAAA","file":"index.js","sourcesContent":["let serverConfig = require('./settings.json');\nimport { Db, MongoClient } from 'mongodb';\nimport { ResolveIOServer } from './resolveio-server-app';\n\nfunction connectAndRun() {\n MongoClient.connect(ResolveIOServer.getServerConfig()['MONGO_URL']).then(async dbConnection => {\n // dbConnection.db().listCollections().toArray().then(collections => {\n ResolveIOServer.setMongoConnection(dbConnection);\n ResolveIOServer.setMainDB(dbConnection.db(ResolveIOServer.getServerConfig()['DATABASE']));\n\n console.log(ResolveIOServer.getServerConfig());\n\n // setTimeout(async () => {\n let LocalLogManager = (await import('./managers/local-log.manager')).LocalLogManager;\n let localLogManager = new LocalLogManager();\n ResolveIOServer.setLocalLogManager(localLogManager);\n\n let MongoManager = (await import('./managers/mongo.manager')).MongoManager;\n let mongoManager = new MongoManager();\n ResolveIOServer.setMongoManager(mongoManager);\n await mongoManager.initServerCollections();\n\n \n let serverApp = (await import('./server-app')).ResolveIOMainServer;\n let app = new serverApp();\n ResolveIOServer.setMainServer(app);\n app.initServerApp();\n // }, 1000);\n\n // });\n }, err => {\n console.error(new Date(), 'MONGO CLIENT CONNECT FAILED', JSON.stringify(err, null, 2));\n process.exit(1);\n });\n}\n\nnew ResolveIOServer(serverConfig, [], 'ResolveIO Server Library', __dirname);\nconnectAndRun();\n\nexport * from './public_api';"]}
|
package/managers/cron.manager.js
CHANGED
|
@@ -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"),
|
|
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;
|
|
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","mongo_manager_1","__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,GAEAC,OAAAD,QAAA,cAAA,EAEAE,8BAAAF,QAAA,4CAAA,EACAG,gBAAAH,QAAA,2BAAA,EAEAI,IAAAJ,QAAA,IAAA,EAEAK,YAAA,WAKC,SAAAA,cAFQC,KAAAC,MAAwB,GAG/BD,KAAKE,aAAe,IAAIP,OAAAQ,eAExBH,KAAKI,WAAU,CAChB,CA6QD,OA3QcL,YAAAM,UAAAD,WAAb,W,qHAOC,OANIJ,KAAKM,cAAgB,CAACN,KAAKM,aAAaC,SAC3CP,KAAKM,aAAaE,mBAAkB,EACpCR,KAAKM,aAAaG,MAAK,EACvBT,KAAKM,aAAe,MAGrB,CAAA,EAAM,IAAII,QAAQ,SAAAC,GAAW,OAAAC,WAAWD,EAAS,GAAI,CAAxB,CAAyB,G,cAAtDE,EAAAC,KAAA,EAEKd,KAAKM,cAAgBN,CAAAA,KAAKM,aAAaC,SAC3Cd,sBAAAsB,SAASC,KAAI,EAAGC,KAAK,SAAAC,GACpBC,EAAKlB,MAAQiB,EAEbC,EAAKlB,MAAMmB,QAAQ,SAAAC,GAClBF,EAAKG,WAAWD,CAAG,EACfA,EAAIE,SACP9B,sBAAAsB,SAASS,UAAU,CAACC,IAAKJ,EAAII,GAAG,EAAG,CAACC,KAAM,CAACH,QAAS,CAAA,CAAK,CAAC,CAAC,CAE7D,CAAC,CACF,CAAC,EAEDvB,KAAKM,aAAeb,sBAAAsB,SAASY,gBAAgB,GAAI,CAACC,aAAc,cAAc,CAAC,EAE/E5B,KAAKM,aAAauB,GAAG,SAAU,SAAOC,GAAuC,OAAAC,UAAAZ,EAAA,KAAA,EAAA,KAAA,EAAA,W,kDAClD,WAAtBW,EAAIE,cACHF,EAAIF,eACF5B,KAAKC,MAAMgC,KAAK,SAAAC,GAAK,OAAAA,EAAET,MAAaK,EAAIK,YAAiB,GAApC,C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AC,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,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,EAtRY0G,QAAA1G,YAAAA","file":"cron.manager.js","sourcesContent":["import { CronJobModel } from '../models/cron-job.model';\nimport { CronJobs } from '../collections/cron-job.collection';\nimport ResolveIOMainServer from '../server-app';\nimport { CronJobManager } from '../cron/cron';\nimport { ChangeStream, ChangeStreamDocument } from 'mongodb';\nimport { CronJobHistories } from '../collections/cron-job-history.collection';\nimport { objectIdHexString } from '../managers/mongo.manager';\nimport { CronJobHistoryModel } from '../models/cron-job-history.model';\nimport { ResolveIOServer } from '..';\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\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_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,QAAA,gBAAA,EAEAK,YAAA,WAKC,SAAAA,cAFQC,KAAAC,MAAwB,GAG/BD,KAAKE,aAAe,IAAIP,OAAAQ,eACxBH,KAAKI,WAAU,CAChB,CA6QD,OA3QcL,YAAAM,UAAAD,WAAb,W,qHAOC,OANIJ,KAAKM,cAAgB,CAACN,KAAKM,aAAaC,SAC3CP,KAAKM,aAAaE,mBAAkB,EACpCR,KAAKM,aAAaG,MAAK,EACvBT,KAAKM,aAAe,MAGrB,CAAA,EAAM,IAAII,QAAQ,SAAAC,GAAW,OAAAC,WAAWD,EAAS,GAAI,CAAxB,CAAyB,G,cAAtDE,EAAAC,KAAA,EAEKd,KAAKM,cAAgBN,CAAAA,KAAKM,aAAaC,SAC3Cd,sBAAAsB,SAASC,KAAI,EAAGC,KAAK,SAAAC,GACpBC,EAAKlB,MAAQiB,EAEbC,EAAKlB,MAAMmB,QAAQ,SAAAC,GAClBF,EAAKG,WAAWD,CAAG,EACfA,EAAIE,SACP9B,sBAAAsB,SAASS,UAAU,CAACC,IAAKJ,EAAII,GAAG,EAAG,CAACC,KAAM,CAACH,QAAS,CAAA,CAAK,CAAC,CAAC,CAE7D,CAAC,CACF,CAAC,EAEDvB,KAAKM,aAAeb,sBAAAsB,SA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C,IAAI,IAAIjB,KAAQ,aAAciD,KAAKC,UAAUS,EAAK,KAAM,CAAC,CAAC,EAClE3B,EAAYS,MAAQQ,KAAKC,UAAUS,EAAK,KAAM,CAAC,EAC/C3B,EAAYQ,OAAS,CAAA,EAEjBlE,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,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,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LocalLogManager=void 0;var fs=require("fs"),LocalLogManager=function(){function LocalLogManager(){fs.existsSync("~/logs")||fs.mkdirSync("~/logs"),this._logFilePath="~/logs/local-logs.jsonl"}return LocalLogManager.prototype.writeLog=function(
|
|
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("~/logs")||fs.mkdirSync("~/logs"),this._logFilePath="~/logs/local-logs.jsonl"}return LocalLogManager.prototype.writeLog=function(e){try{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 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","LocalLogManager","existsSync","mkdirSync","this","_logFilePath","prototype","writeLog","logEntry","line","JSON","stringify","appendFileSync","encoding","err","console","error","Date","writeLogs","items","length","lines","map","item","join","offloadLogs","result","fileData","readFileSync","trim","split","filter","l","writeFileSync","exports"],"mappings":"mGAGA,IAAAA,GAAAC,QAAA,IAAA,
|
|
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","line","JSON","stringify","appendFileSync","encoding","err","console","error","Date","writeLogs","items","length","lines","map","item","join","offloadLogs","result","fileData","readFileSync","trim","split","filter","l","writeFileSync","exports"],"mappings":"mGAGA,IAAAA,GAAAC,QAAA,IAAA,EACAC,uBAAAD,QAAA,yBAAA,EAeAE,gBAAA,WAGC,SAAAA,kBAEoD,0BAAlDD,uBAAAE,gBAAgBC,gBAAe,EAAa,UACS,0BAAlDH,uBAAAE,gBAAgBC,gBAAe,EAAa,UAE1CL,GAAGM,WAAW,QAAQ,GAC1BN,GAAGO,UAAU,QAAQ,EAIvBC,KAAKC,aAAe,yBACrB,CAwDD,OArDQN,gBAAAO,UAAAC,SAAP,SAAgBC,GACf,IACC,IAAIC,EAAOC,KAAKC,UAAUH,CAAQ,EAAI,KACtCZ,GAAGgB,eAAeR,KAAKC,aAAcI,EAAM,CAAEI,SAAU,MAAM,CAAE,C,CAEhE,MAAMC,GAELC,QAAQC,MAAM,IAAIC,KAAQ,kBAAmB,+BAAgCH,CAAG,C,CAElF,EAEOf,gBAAAO,UAAAY,UAAP,SAAiBC,GAChB,GAAKA,GAA0B,IAAjBA,EAAMC,OAIpB,IAEC,IAAIC,EAAQF,EAAMG,IAAI,SAAAC,GAAQ,OAAAb,KAAKC,UAAUY,CAAI,CAAnB,CAAoB,EAAEC,KAAK,IAAI,EAAI,KACjE5B,GAAGgB,eAAeR,KAAKC,aAAcgB,EAAO,CAAER,SAAU,MAAM,CAAE,C,CAEjE,MAAOC,GACNC,QAAQC,MAAM,IAAIC,KAAQ,kBAAmB,8BAA+BH,CAAG,C,CAEjF,EAKOf,gBAAAO,UAAAmB,YAAP,WACC,IAAIC,EAAS,GAEb,IACC,GAAI,CAAC9B,GAAGM,WAAWE,KAAKC,YAAY,EACnC,OAAOqB,EAGR,IAAIC,EAAW/B,GAAGgC,aAAaxB,KAAKC,aAAc,MAAM,EACxD,GAA+B,IAA3BsB,EAASE,KAAI,EAAGT,OACnB,OAAOM,EAGRA,EAASC,EAASG,MAAM,IAAI,EAAEC,OAAO,SAAAC,GAAK,MAAa,KAAbA,EAAEH,KAAI,CAAN,CAAe,EAGzDjC,GAAGqC,cAAc7B,KAAKC,aAAc,EAAE,C,CAEvC,MAAMS,GACLC,QAAQC,MAAM,IAAIC,KAAQ,kBAAmB,0BAA2BH,CAAG,C,CAG5E,OAAOY,CACR,EACD3B,eAAA,EAAC,EAtEYmC,QAAAnC,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| 'log'\n\t| 'log-method-latency'\n\t| 'log-subscription';\n\nexport interface LocalLogModel {\n\ttype: LocalLogType;\n\tdate: Date;\n\tdata: any;\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('~/logs')) {\n\t\t\t\tfs.mkdirSync('~/logs');\n\t\t\t}\n\t\t}\n\t\t\n\t\tthis._logFilePath = '~/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\tlet line = JSON.stringify(logEntry) + '\\n';\n\t\t\tfs.appendFileSync(this._logFilePath, line, { 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(items: LocalLogModel[]): void {\n\t\tif (!items || items.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 lines = items.map(item => JSON.stringify(item)).join('\\n') + '\\n';\n\t\t\tfs.appendFileSync(this._logFilePath, lines, { 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}"]}
|