@resolveio/server-lib 1.0.0-rc1 → 1.0.0-rc10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/collections/active-subscription.collection.d.ts +8 -0
  2. package/collections/active-subscription.collection.js +68 -1
  3. package/collections/app-status.collection.d.ts +8 -0
  4. package/collections/app-status.collection.js +43 -1
  5. package/collections/app-version.collection.d.ts +8 -0
  6. package/collections/app-version.collection.js +56 -1
  7. package/collections/counter.collection.d.ts +10 -0
  8. package/collections/counter.collection.js +73 -1
  9. package/collections/cron-job-history.collection.d.ts +8 -0
  10. package/collections/cron-job-history.collection.js +86 -1
  11. package/collections/cron-job.collection.d.ts +8 -0
  12. package/collections/cron-job.collection.js +89 -1
  13. package/collections/file.collection.d.ts +10 -0
  14. package/collections/file.collection.js +73 -1
  15. package/collections/flag.collection.d.ts +8 -0
  16. package/collections/flag.collection.js +47 -1
  17. package/collections/log.collection.d.ts +8 -0
  18. package/collections/log.collection.js +64 -1
  19. package/collections/logged-in-users.collection.d.ts +8 -0
  20. package/collections/logged-in-users.collection.js +70 -1
  21. package/collections/method-call.collection.d.ts +7 -0
  22. package/collections/method-call.collection.js +44 -1
  23. package/collections/method-response.collection.d.ts +7 -0
  24. package/collections/method-response.collection.js +48 -1
  25. package/collections/queue-flag.collection.d.ts +8 -0
  26. package/collections/queue-flag.collection.js +41 -1
  27. package/collections/queue-method.collection.d.ts +8 -0
  28. package/collections/queue-method.collection.js +116 -1
  29. package/collections/queue-response.collection.d.ts +8 -0
  30. package/collections/queue-response.collection.js +78 -1
  31. package/collections/support-ticket.collection.d.ts +8 -0
  32. package/collections/support-ticket.collection.js +146 -1
  33. package/collections/user.collection.d.ts +9 -0
  34. package/collections/user.collection.js +108 -1
  35. package/cron/cron.d.ts +6 -0
  36. package/cron/cron.js +160 -1
  37. package/fixtures/cron-jobs.d.ts +2 -0
  38. package/fixtures/cron-jobs.js +72 -1
  39. package/fixtures/init.d.ts +2 -0
  40. package/fixtures/init.js +73 -1
  41. package/http/auth.d.ts +3 -0
  42. package/http/auth.js +472 -1
  43. package/http/health.d.ts +2 -0
  44. package/http/health.js +8 -1
  45. package/index.d.ts +14 -0
  46. package/index.js +120 -1
  47. package/managers/cron.manager.d.ts +17 -0
  48. package/managers/cron.manager.js +193 -1
  49. package/managers/method.manager.d.ts +27 -0
  50. package/managers/method.manager.js +513 -1
  51. package/managers/queue-method.manager.d.ts +14 -0
  52. package/managers/queue-method.manager.js +239 -1
  53. package/managers/subscription.manager.d.ts +27 -0
  54. package/managers/subscription.manager.js +700 -1
  55. package/managers/support.manager.d.ts +18 -0
  56. package/managers/support.manager.js +208 -1
  57. package/methods/accounts.d.ts +3 -0
  58. package/methods/accounts.js +253 -1
  59. package/methods/aws.d.ts +3 -0
  60. package/methods/aws.js +323 -1
  61. package/methods/cloudconvert.d.ts +3 -0
  62. package/methods/cloudconvert.js +37 -1
  63. package/methods/collections.d.ts +3 -0
  64. package/methods/collections.js +738 -1
  65. package/methods/counters.d.ts +3 -0
  66. package/methods/counters.js +404 -1
  67. package/methods/cron-jobs.d.ts +3 -0
  68. package/methods/cron-jobs.js +63 -1
  69. package/methods/flags.d.ts +3 -0
  70. package/methods/flags.js +6 -1
  71. package/methods/logs.d.ts +3 -0
  72. package/methods/logs.js +29 -1
  73. package/methods/pdf.d.ts +3 -0
  74. package/methods/pdf.js +303 -1
  75. package/models/active-subscription.model.d.ts +14 -0
  76. package/models/active-subscription.model.js +2 -1
  77. package/models/app-status.model.d.ts +5 -0
  78. package/models/app-status.model.js +2 -1
  79. package/models/app-version.model.d.ts +5 -0
  80. package/models/app-version.model.js +2 -1
  81. package/models/collection-document.model.d.ts +7 -0
  82. package/models/collection-document.model.js +2 -1
  83. package/models/counter.model.d.ts +6 -0
  84. package/models/counter.model.js +2 -1
  85. package/models/cron-job-history.model.d.ts +13 -0
  86. package/models/cron-job-history.model.js +2 -1
  87. package/models/cron-job.model.d.ts +14 -0
  88. package/models/cron-job.model.js +2 -1
  89. package/models/dialog.model.d.ts +24 -0
  90. package/models/dialog.model.js +2 -1
  91. package/models/file.model.d.ts +10 -0
  92. package/models/file.model.js +2 -1
  93. package/models/flag.model.d.ts +6 -0
  94. package/models/flag.model.js +2 -1
  95. package/models/log.model.d.ts +12 -0
  96. package/models/log.model.js +2 -1
  97. package/models/logged-in-users.model.d.ts +10 -0
  98. package/models/logged-in-users.model.js +2 -1
  99. package/models/method-call.model.d.ts +8 -0
  100. package/models/method-call.model.js +2 -1
  101. package/models/method-response.model.d.ts +9 -0
  102. package/models/method-response.model.js +2 -1
  103. package/models/method.model.d.ts +11 -0
  104. package/models/method.model.js +2 -1
  105. package/models/pagination.model.d.ts +12 -0
  106. package/models/pagination.model.js +20 -1
  107. package/models/permission.model.d.ts +13 -0
  108. package/models/permission.model.js +2 -1
  109. package/models/queue-method.model.d.ts +10 -0
  110. package/models/queue-method.model.js +2 -1
  111. package/models/queue-response.model.d.ts +11 -0
  112. package/models/queue-response.model.js +2 -1
  113. package/models/select-data-label.model.d.ts +10 -0
  114. package/models/select-data-label.model.js +2 -1
  115. package/models/server-response.model.d.ts +6 -0
  116. package/models/server-response.model.js +2 -1
  117. package/models/subscription.model.d.ts +31 -0
  118. package/models/subscription.model.js +2 -1
  119. package/models/support-method.model.d.ts +10 -0
  120. package/models/support-method.model.js +2 -1
  121. package/models/support-ticket.model.d.ts +40 -0
  122. package/models/support-ticket.model.js +2 -1
  123. package/models/user.model.d.ts +15 -0
  124. package/models/user.model.js +2 -1
  125. package/package.json +4 -1
  126. package/publications/app-status.d.ts +3 -0
  127. package/publications/app-status.js +14 -1
  128. package/publications/app-version.d.ts +3 -0
  129. package/publications/app-version.js +14 -1
  130. package/publications/cron-jobs.d.ts +3 -0
  131. package/publications/cron-jobs.js +14 -1
  132. package/publications/files.d.ts +3 -0
  133. package/publications/files.js +71 -1
  134. package/publications/flags.d.ts +3 -0
  135. package/publications/flags.js +23 -1
  136. package/publications/logs.d.ts +3 -0
  137. package/publications/logs.js +26 -1
  138. package/publications/method-calls.d.ts +3 -0
  139. package/publications/method-calls.js +14 -1
  140. package/publications/method-responses.d.ts +3 -0
  141. package/publications/method-responses.js +14 -1
  142. package/publications/super-admin.d.ts +3 -0
  143. package/publications/super-admin.js +21 -1
  144. package/publications/support-tickets.d.ts +2 -0
  145. package/publications/support-tickets.js +118 -1
  146. package/server-app.d.ts +33 -0
  147. package/server-app.js +640 -1
  148. package/support-methods/aws.d.ts +3 -0
  149. package/support-methods/aws.js +276 -1
  150. package/support-methods/collections.d.ts +3 -0
  151. package/support-methods/collections.js +471 -1
  152. package/support-methods/counters.d.ts +3 -0
  153. package/support-methods/counters.js +189 -1
  154. package/support-methods/support.d.ts +3 -0
  155. package/support-methods/support.js +19 -1
  156. package/util/common.d.ts +15 -0
  157. package/util/common.js +334 -1
package/http/auth.js CHANGED
@@ -1 +1,472 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(i,o,a,u){return new(a||(a=Promise))(function(e,r){function n(e){try{t(u.next(e))}catch(e){r(e)}}function s(e){try{t(u.throw(e))}catch(e){r(e)}}function t(r){r.done?e(r.value):new a(function(e){e(r.value)}).then(n,s)}t((u=u.apply(i,o||[])).next())})},__generator=this&&this.__generator||function(n,s){var t,i,o,e,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return e={next:r(0),throw:r(1),return:r(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function r(r){return function(e){return function(r){if(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,i&&(o=2&r[0]?i.return:r[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,r[1])).done)return o;switch(i=0,o&&(r=[2&r[0],o.value]),r[0]){case 0:case 1:o=r;break;case 4:return a.label++,{value:r[1],done:!1};case 5:a.label++,i=r[1],r=[0];continue;case 7:r=a.ops.pop(),a.trys.pop();continue;default:if(!(o=0<(o=a.trys).length&&o[o.length-1])&&(6===r[0]||2===r[0])){a=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]<o[3])){a.label=r[1];break}if(6===r[0]&&a.label<o[1]){a.label=o[1],o=r;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(r);break}o[2]&&a.ops.pop(),a.trys.pop();continue}r=s.call(n,a)}catch(e){r=[6,e],i=0}finally{t=o=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,e])}}};Object.defineProperty(exports,"__esModule",{value:!0});var user_collection_1=require("../collections/user.collection"),jwt=require("jsonwebtoken"),handlebars=require("handlebars"),method_manager_1=require("../managers/method.manager");function setupAuthRoutes(e,o){var r=this;e.post("/login",function(n,i){return __awaiter(r,void 0,void 0,function(){var t,r;return __generator(this,function(e){switch(e.label){case 0:return n.headers.origin===o.ROOT_URL||n.headers.origin===o.SEC_ROOT_URL?[3,1]:(i.send(JSON.stringify({error:!0,result:"Invalid header"})),[3,5]);case 1:return[4,user_collection_1.Users.findOne({username:n.body.username}).exec()];case 2:return(t=e.sent())?[3,4]:[4,user_collection_1.Users.findOne({email:n.body.username}).exec()];case 3:t=e.sent(),e.label=4;case 4:r=t?t.username:n.body.username,user_collection_1.Users.authenticate()(r,n.body.password,function(e,s,r){if(r)if("TooManyAttemptsError"===r.name){i.send(JSON.stringify({error:!0,result:r.message+". A password reset link has been sent to your email, please reset your password."})),t.services.forgot_password=jwt.sign({id_user:t._id},o.JWT_SECRET);var n={userToChangePassword:t.fullname,userWhoResetPassword:"DCS System",url:o.ROOT_URL+"/forgot-password/"+t.services.forgot_password+"/"};user_collection_1.Users.updateOne({_id:t._id},{$set:{services:t.services}}).exec(function(e,r){method_manager_1.default.readFile("email-templates/forgot-password.html").then(function(e){var r=handlebars.compile(e);handlebars.registerHelper("equals",function(e,r){return e===r}),method_manager_1.default.sendEmail(t.email,"ResolveIO (DCS) - Forgot Password","",r(n))},function(e){return console.log(e)})})}else i.send(JSON.stringify({error:!0,result:r.message}));else s&&s.active&&s.resetAttempts(function(e,r,n){i.send(JSON.stringify({error:!1,result:{token:jwt.sign({id_user:s._id},o.JWT_SECRET,{expiresIn:7776e6})}}))})}),e.label=5;case 5:return[2]}})})}),e.post("/accessToken",function(r,t){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){return r.headers.origin!==o.ROOT_URL&&r.headers.origin!==o.SEC_ROOT_URL&&r.headers.origin!==o.RESOLVEIO_URL&&r.headers.origin!==o.RESOLVEIO_SECONDARY_URL?t.send(JSON.stringify({error:!0,result:"Invalid header"})):"http://localhost:4200"!==o.ROOT_URL?jwt.verify(r.body.refreshToken,o.JWT_SECRET,function(e,r){e?t.send(JSON.stringify({error:!0,result:"Invalid Token"})):user_collection_1.Users.findById(r.id_user).exec().then(function(s){s?s.active?s.resetAttempts(function(e,r,n){s.save(),t.send(JSON.stringify({error:!1,result:{token:jwt.sign({id_user:s._id},o.JWT_SECRET,{expiresIn:2592e5}),user:s}}))}):t.send(JSON.stringify({error:!0,result:"Account is Disabled"})):t.send(JSON.stringify({error:!0,result:"Invalid User"}))},function(e){t.send(JSON.stringify({error:!0,result:"Invalid Mongoose Get User"}))})}):jwt.verify(r.body.refreshToken,o.JWT_SECRET,function(e,r){e?t.send(JSON.stringify({error:!0,result:"Invalid Token"})):user_collection_1.Users.findById(r.id_user).exec().then(function(s){s?s.active?s.resetAttempts(function(e,r,n){s.save(),t.send(JSON.stringify({error:!1,result:{token:jwt.sign({id_user:s._id},o.JWT_SECRET,{expiresIn:2592e5}),user:s}}))}):t.send(JSON.stringify({error:!0,result:"Account is Disabled"})):t.send(JSON.stringify({error:!0,result:"Invalid User"}))},function(e){t.send(JSON.stringify({error:!0,result:"Invalid Mongoose Get User"}))})}),[2]})})}),e.post("/userWithEnrollmentToken",function(n,s){n.headers.origin!==o.ROOT_URL&&n.headers.origin!==o.SEC_ROOT_URL&&n.headers.origin!==o.RESOLVEIO_URL&&n.headers.origin!==o.RESOLVEIO_SECONDARY_URL?s.send(JSON.stringify({error:!0,result:"Invalid header"})):jwt.verify(n.body.enrollmentToken,o.JWT_SECRET,function(e,r){e?s.send(JSON.stringify({error:!0,result:"Invalid Token"})):user_collection_1.Users.findOne({$and:[{_id:r.id_user},{"services.enrollment":n.body.enrollmentToken}]}).select("_id __v username active").exec().then(function(e){e?e.active?s.send(JSON.stringify({error:!1,result:{user:e}})):s.send(JSON.stringify({error:!0,result:"Account is Disabled"})):s.send(JSON.stringify({error:!0,result:"Invalid User"}))},function(e){s.send(JSON.stringify({error:!0,result:"Invalid Mongoose Get User"}))})})}),e.post("/setUserWithEnrollmentToken",function(s,t){var e=this;s.headers.origin!==o.ROOT_URL&&s.headers.origin!==o.SEC_ROOT_URL&&s.headers.origin!==o.RESOLVEIO_URL&&s.headers.origin!==o.RESOLVEIO_SECONDARY_URL?t.send(JSON.stringify({error:!0,result:"Invalid header"})):jwt.verify(s.body.enrollmentToken,o.JWT_SECRET,function(r,n){return __awaiter(e,void 0,void 0,function(){return __generator(this,function(e){return r?t.send(JSON.stringify({error:!0,result:"Invalid Token"})):user_collection_1.Users.findOne({$and:[{_id:n.id_user},{"services.enrollment":s.body.enrollmentToken}]}).exec().then(function(n){n?n.active?n.setPassword(s.body.password,function(e,r){r?(n.services.enrollment="",n.save(),t.send(JSON.stringify({error:!1,result:!0}))):t.send(JSON.stringify({error:!0,result:e}))}):t.send(JSON.stringify({error:!0,result:"Account is Disabled"})):t.send(JSON.stringify({error:!0,result:"Invalid User"}))},function(e){t.send(JSON.stringify({error:!0,result:"Invalid Mongoose Get User"}))}),[2]})})})}),e.post("/userWithForgotPasswordToken",function(n,s){n.headers.origin!==o.ROOT_URL&&n.headers.origin!==o.SEC_ROOT_URL&&n.headers.origin!==o.RESOLVEIO_URL&&n.headers.origin!==o.RESOLVEIO_SECONDARY_URL?s.send(JSON.stringify({error:!0,result:"Invalid header"})):jwt.verify(n.body.forgotPasswordToken,o.JWT_SECRET,function(e,r){e?s.send(JSON.stringify({error:!0,result:"Invalid Token"})):user_collection_1.Users.findOne({$and:[{_id:r.id_user},{"services.forgot_password":n.body.forgotPasswordToken}]}).select("_id __v username active").exec().then(function(e){e?e.active?s.send(JSON.stringify({error:!1,result:{user:e}})):s.send(JSON.stringify({error:!0,result:"Account is Disabled"})):s.send(JSON.stringify({error:!0,result:"Invalid User"}))},function(e){s.send(JSON.stringify({error:!0,result:"Invalid Mongoose Get User"}))})})}),e.post("/setUserWithForgotPasswordToken",function(t,i){var e=this;t.headers.origin!==o.ROOT_URL&&t.headers.origin!==o.SEC_ROOT_URL&&t.headers.origin!==o.RESOLVEIO_URL&&t.headers.origin!==o.RESOLVEIO_SECONDARY_URL?i.send(JSON.stringify({error:!0,result:"Invalid header"})):jwt.verify(t.body.forgotPasswordToken,o.JWT_SECRET,function(r,n){return __awaiter(e,void 0,void 0,function(){return __generator(this,function(e){return r?i.send(JSON.stringify({error:!0,result:"Invalid Token"})):user_collection_1.Users.findOne({$and:[{_id:n.id_user},{"services.forgot_password":t.body.forgotPasswordToken}]}).exec().then(function(s){s?s.active?s.setPassword(t.body.password,function(e,r){r?(s.services.forgot_password="",s.resetAttempts(function(e,r,n){s.save()}),i.send(JSON.stringify({error:!1,result:!0}))):i.send(JSON.stringify({error:!0,result:e}))}):i.send(JSON.stringify({error:!0,result:"Account is Disabled"})):i.send(JSON.stringify({error:!0,result:"Invalid User"}))},function(e){i.send(JSON.stringify({error:!0,result:"Invalid Mongoose Get User"}))}),[2]})})})})}exports.setupAuthRoutes=setupAuthRoutes;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ var user_collection_1 = require("../collections/user.collection");
39
+ var jwt = require("jsonwebtoken");
40
+ var handlebars = require("handlebars");
41
+ var __1 = require("..");
42
+ function setupAuthRoutes(mainServer, app, serverConfig) {
43
+ var _this = this;
44
+ // Login via HTTP, return refresh token if authenticated
45
+ app.post('/login', function (request, response) { return __awaiter(_this, void 0, void 0, function () {
46
+ var user_1, username;
47
+ return __generator(this, function (_a) {
48
+ switch (_a.label) {
49
+ case 0:
50
+ if (!(request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'])) return [3 /*break*/, 1];
51
+ response.send(JSON.stringify({
52
+ error: true,
53
+ result: 'Invalid header'
54
+ }));
55
+ return [3 /*break*/, 5];
56
+ case 1: return [4 /*yield*/, user_collection_1.Users.findOne({ username: request.body.username }).exec()];
57
+ case 2:
58
+ user_1 = _a.sent();
59
+ if (!!user_1) return [3 /*break*/, 4];
60
+ return [4 /*yield*/, user_collection_1.Users.findOne({ email: request.body.username }).exec()];
61
+ case 3:
62
+ user_1 = _a.sent();
63
+ _a.label = 4;
64
+ case 4:
65
+ username = user_1 ? user_1.username : request.body.username;
66
+ user_collection_1.Users.authenticate()(username, request.body.password, function (err, res, error) {
67
+ if (error) {
68
+ if (error.name === 'TooManyAttemptsError') {
69
+ response.send(JSON.stringify({
70
+ error: true,
71
+ result: error.message + '. A password reset link has been sent to your email, please reset your password.'
72
+ }));
73
+ user_1.services.forgot_password = jwt.sign({ id_user: user_1._id }, serverConfig['JWT_SECRET']);
74
+ var emailData_1 = {
75
+ userToChangePassword: user_1.fullname,
76
+ userWhoResetPassword: __1.ResolveIOServer.getClientName() + ' System',
77
+ url: serverConfig['ROOT_URL'] + '/forgot-password/' + user_1.services.forgot_password + '/'
78
+ };
79
+ user_collection_1.Users.updateOne({ _id: user_1._id }, { $set: { services: user_1.services } }).exec(function (errUp, resUp) {
80
+ mainServer.getMethodManager().readFile('email-templates/forgot-password.html').then(function (html) {
81
+ var template = handlebars.compile(html);
82
+ handlebars.registerHelper('equals', function (a, b) {
83
+ return a === b;
84
+ });
85
+ mainServer.getMethodManager().sendEmail(user_1.email, 'ResolveIO (' + __1.ResolveIOServer.getClientName() + ') - Forgot Password', '', template(emailData_1));
86
+ }, function (errEmail) { return console.log(errEmail); });
87
+ });
88
+ }
89
+ else {
90
+ response.send(JSON.stringify({
91
+ error: true,
92
+ result: error.message
93
+ }));
94
+ }
95
+ }
96
+ else {
97
+ if (res && res.active) {
98
+ res.resetAttempts(function (errAt, resAt, errorAt) {
99
+ response.send(JSON.stringify({
100
+ error: false,
101
+ result: {
102
+ token: jwt.sign({ id_user: res._id }, serverConfig['JWT_SECRET'], {
103
+ expiresIn: 90 * 24 * 60 * 60 * 1000 // 90 days
104
+ })
105
+ }
106
+ }));
107
+ });
108
+ }
109
+ }
110
+ });
111
+ _a.label = 5;
112
+ case 5: return [2 /*return*/];
113
+ }
114
+ });
115
+ }); });
116
+ app.post('/accessToken', function (request, response) {
117
+ return __awaiter(this, void 0, void 0, function () {
118
+ return __generator(this, function (_a) {
119
+ if (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']) {
120
+ response.send(JSON.stringify({
121
+ error: true,
122
+ result: 'Invalid header'
123
+ }));
124
+ }
125
+ else {
126
+ if (serverConfig['ROOT_URL'] !== 'http://localhost:4200') {
127
+ jwt.verify(request.body.refreshToken, serverConfig['JWT_SECRET'], function (err, decoded) {
128
+ if (err) {
129
+ response.send(JSON.stringify({
130
+ error: true,
131
+ result: 'Invalid Token'
132
+ }));
133
+ }
134
+ else {
135
+ user_collection_1.Users.findById(decoded['id_user']).exec().then(function (user) {
136
+ if (user) {
137
+ if (user.active) {
138
+ user.resetAttempts(function (errAt, resAt, errorAt) {
139
+ user.save();
140
+ response.send(JSON.stringify({
141
+ error: false,
142
+ result: {
143
+ token: jwt.sign({ id_user: user._id }, serverConfig['JWT_SECRET'], {
144
+ expiresIn: 3 * 24 * 60 * 60 * 1000 // 3 days
145
+ }),
146
+ user: user
147
+ }
148
+ }));
149
+ });
150
+ }
151
+ else {
152
+ response.send(JSON.stringify({
153
+ error: true,
154
+ result: 'Account is Disabled'
155
+ }));
156
+ }
157
+ }
158
+ else {
159
+ response.send(JSON.stringify({
160
+ error: true,
161
+ result: 'Invalid User'
162
+ }));
163
+ }
164
+ }, function (error) {
165
+ response.send(JSON.stringify({
166
+ error: true,
167
+ result: 'Invalid Mongoose Get User'
168
+ }));
169
+ });
170
+ }
171
+ });
172
+ }
173
+ else {
174
+ jwt.verify(request.body.refreshToken, serverConfig['JWT_SECRET'], function (err, decoded) {
175
+ if (err) {
176
+ response.send(JSON.stringify({
177
+ error: true,
178
+ result: 'Invalid Token'
179
+ }));
180
+ }
181
+ else {
182
+ user_collection_1.Users.findById(decoded['id_user']).exec().then(function (user) {
183
+ if (user) {
184
+ if (user.active) {
185
+ user.resetAttempts(function (errAt, resAt, errorAt) {
186
+ user.save();
187
+ response.send(JSON.stringify({
188
+ error: false,
189
+ result: {
190
+ token: jwt.sign({ id_user: user._id }, serverConfig['JWT_SECRET'], {
191
+ expiresIn: 3 * 24 * 60 * 60 * 1000 // 3 days
192
+ }),
193
+ user: user
194
+ }
195
+ }));
196
+ });
197
+ }
198
+ else {
199
+ response.send(JSON.stringify({
200
+ error: true,
201
+ result: 'Account is Disabled'
202
+ }));
203
+ }
204
+ }
205
+ else {
206
+ response.send(JSON.stringify({
207
+ error: true,
208
+ result: 'Invalid User'
209
+ }));
210
+ }
211
+ }, function (error) {
212
+ response.send(JSON.stringify({
213
+ error: true,
214
+ result: 'Invalid Mongoose Get User'
215
+ }));
216
+ });
217
+ }
218
+ });
219
+ }
220
+ }
221
+ return [2 /*return*/];
222
+ });
223
+ });
224
+ });
225
+ app.post('/userWithEnrollmentToken', function (request, response) {
226
+ if (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']) {
227
+ response.send(JSON.stringify({
228
+ error: true,
229
+ result: 'Invalid header'
230
+ }));
231
+ }
232
+ else {
233
+ jwt.verify(request.body.enrollmentToken, serverConfig['JWT_SECRET'], function (err, decoded) {
234
+ if (err) {
235
+ response.send(JSON.stringify({
236
+ error: true,
237
+ result: 'Invalid Token'
238
+ }));
239
+ }
240
+ else {
241
+ user_collection_1.Users.findOne({
242
+ $and: [
243
+ { _id: decoded['id_user'] },
244
+ { 'services.enrollment': request.body.enrollmentToken }
245
+ ]
246
+ }).select('_id __v username active').exec().then(function (user) {
247
+ if (user) {
248
+ if (user.active) {
249
+ response.send(JSON.stringify({
250
+ error: false,
251
+ result: {
252
+ user: user
253
+ }
254
+ }));
255
+ }
256
+ else {
257
+ response.send(JSON.stringify({
258
+ error: true,
259
+ result: 'Account is Disabled'
260
+ }));
261
+ }
262
+ }
263
+ else {
264
+ response.send(JSON.stringify({
265
+ error: true,
266
+ result: 'Invalid User'
267
+ }));
268
+ }
269
+ }, function (error) {
270
+ response.send(JSON.stringify({
271
+ error: true,
272
+ result: 'Invalid Mongoose Get User'
273
+ }));
274
+ });
275
+ }
276
+ });
277
+ }
278
+ });
279
+ app.post('/setUserWithEnrollmentToken', function (request, response) {
280
+ var _this = this;
281
+ if (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']) {
282
+ response.send(JSON.stringify({
283
+ error: true,
284
+ result: 'Invalid header'
285
+ }));
286
+ }
287
+ else {
288
+ jwt.verify(request.body.enrollmentToken, serverConfig['JWT_SECRET'], function (err, decoded) { return __awaiter(_this, void 0, void 0, function () {
289
+ return __generator(this, function (_a) {
290
+ if (err) {
291
+ response.send(JSON.stringify({
292
+ error: true,
293
+ result: 'Invalid Token'
294
+ }));
295
+ }
296
+ else {
297
+ user_collection_1.Users.findOne({
298
+ $and: [
299
+ { _id: decoded['id_user'] },
300
+ { 'services.enrollment': request.body.enrollmentToken }
301
+ ]
302
+ }).exec().then(function (user) {
303
+ if (user) {
304
+ if (user.active) {
305
+ user.setPassword(request.body.password, function (errSet, resSet) {
306
+ if (resSet) {
307
+ user.services.enrollment = '';
308
+ user.save();
309
+ response.send(JSON.stringify({
310
+ error: false,
311
+ result: true
312
+ }));
313
+ }
314
+ else {
315
+ response.send(JSON.stringify({
316
+ error: true,
317
+ result: errSet
318
+ }));
319
+ }
320
+ });
321
+ }
322
+ else {
323
+ response.send(JSON.stringify({
324
+ error: true,
325
+ result: 'Account is Disabled'
326
+ }));
327
+ }
328
+ }
329
+ else {
330
+ response.send(JSON.stringify({
331
+ error: true,
332
+ result: 'Invalid User'
333
+ }));
334
+ }
335
+ }, function (error) {
336
+ response.send(JSON.stringify({
337
+ error: true,
338
+ result: 'Invalid Mongoose Get User'
339
+ }));
340
+ });
341
+ }
342
+ return [2 /*return*/];
343
+ });
344
+ }); });
345
+ }
346
+ });
347
+ app.post('/userWithForgotPasswordToken', function (request, response) {
348
+ if (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']) {
349
+ response.send(JSON.stringify({
350
+ error: true,
351
+ result: 'Invalid header'
352
+ }));
353
+ }
354
+ else {
355
+ jwt.verify(request.body.forgotPasswordToken, serverConfig['JWT_SECRET'], function (err, decoded) {
356
+ if (err) {
357
+ response.send(JSON.stringify({
358
+ error: true,
359
+ result: 'Invalid Token'
360
+ }));
361
+ }
362
+ else {
363
+ user_collection_1.Users.findOne({
364
+ $and: [
365
+ { _id: decoded['id_user'] },
366
+ { 'services.forgot_password': request.body.forgotPasswordToken }
367
+ ]
368
+ }).select('_id __v username active').exec().then(function (user) {
369
+ if (user) {
370
+ if (user.active) {
371
+ response.send(JSON.stringify({
372
+ error: false,
373
+ result: {
374
+ user: user
375
+ }
376
+ }));
377
+ }
378
+ else {
379
+ response.send(JSON.stringify({
380
+ error: true,
381
+ result: 'Account is Disabled'
382
+ }));
383
+ }
384
+ }
385
+ else {
386
+ response.send(JSON.stringify({
387
+ error: true,
388
+ result: 'Invalid User'
389
+ }));
390
+ }
391
+ }, function (error) {
392
+ response.send(JSON.stringify({
393
+ error: true,
394
+ result: 'Invalid Mongoose Get User'
395
+ }));
396
+ });
397
+ }
398
+ });
399
+ }
400
+ });
401
+ app.post('/setUserWithForgotPasswordToken', function (request, response) {
402
+ var _this = this;
403
+ if (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']) {
404
+ response.send(JSON.stringify({
405
+ error: true,
406
+ result: 'Invalid header'
407
+ }));
408
+ }
409
+ else {
410
+ jwt.verify(request.body.forgotPasswordToken, serverConfig['JWT_SECRET'], function (err, decoded) { return __awaiter(_this, void 0, void 0, function () {
411
+ return __generator(this, function (_a) {
412
+ if (err) {
413
+ response.send(JSON.stringify({
414
+ error: true,
415
+ result: 'Invalid Token'
416
+ }));
417
+ }
418
+ else {
419
+ user_collection_1.Users.findOne({
420
+ $and: [
421
+ { _id: decoded['id_user'] },
422
+ { 'services.forgot_password': request.body.forgotPasswordToken }
423
+ ]
424
+ }).exec().then(function (user) {
425
+ if (user) {
426
+ if (user.active) {
427
+ user.setPassword(request.body.password, function (errSet, resSet) {
428
+ if (resSet) {
429
+ user.services.forgot_password = '';
430
+ user.resetAttempts(function (errAt, resAtt, errorAtt) {
431
+ user.save();
432
+ });
433
+ response.send(JSON.stringify({
434
+ error: false,
435
+ result: true
436
+ }));
437
+ }
438
+ else {
439
+ response.send(JSON.stringify({
440
+ error: true,
441
+ result: errSet
442
+ }));
443
+ }
444
+ });
445
+ }
446
+ else {
447
+ response.send(JSON.stringify({
448
+ error: true,
449
+ result: 'Account is Disabled'
450
+ }));
451
+ }
452
+ }
453
+ else {
454
+ response.send(JSON.stringify({
455
+ error: true,
456
+ result: 'Invalid User'
457
+ }));
458
+ }
459
+ }, function (error) {
460
+ response.send(JSON.stringify({
461
+ error: true,
462
+ result: 'Invalid Mongoose Get User'
463
+ }));
464
+ });
465
+ }
466
+ return [2 /*return*/];
467
+ });
468
+ }); });
469
+ }
470
+ });
471
+ }
472
+ exports.setupAuthRoutes = setupAuthRoutes;
@@ -0,0 +1,2 @@
1
+ export declare function setupHealthRoutes(app: any, serverConfig: any): void;
2
+ //# sourceMappingURL=health.d.ts.map
package/http/health.js CHANGED
@@ -1 +1,8 @@
1
- "use strict";function setupHealthRoutes(e,t){e.get("/health",function(e,t){t.sendStatus(200)})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.setupHealthRoutes=setupHealthRoutes;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function setupHealthRoutes(app, serverConfig) {
4
+ app.get('/health', function (request, response) {
5
+ response.sendStatus(200);
6
+ });
7
+ }
8
+ exports.setupHealthRoutes = setupHealthRoutes;
package/index.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ export declare class ResolveIOServer {
2
+ private static _serverConfig;
3
+ private static _mainDB;
4
+ private static _supportDB;
5
+ private static _mainServer;
6
+ private static _client;
7
+ constructor(serverConfig: any, client: string);
8
+ connectAndRun(serverConfig: any): Promise<void>;
9
+ static getClientName(): string;
10
+ static getMainServer(): any;
11
+ static getMainDB(): any;
12
+ static getSupportDB(): any;
13
+ }
14
+ //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -1 +1,120 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(i,u,s,a){return new(s||(s=Promise))(function(e,t){function n(e){try{o(a.next(e))}catch(e){t(e)}}function r(e){try{o(a.throw(e))}catch(e){t(e)}}function o(t){t.done?e(t.value):new s(function(e){e(t.value)}).then(n,r)}o((a=a.apply(i,u||[])).next())})},__generator=this&&this.__generator||function(n,r){var o,i,u,e,s={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return e={next:t(0),throw:t(1),return:t(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(o)throw new TypeError("Generator is already executing.");for(;s;)try{if(o=1,i&&(u=2&t[0]?i.return:t[0]?i.throw||((u=i.return)&&u.call(i),0):i.next)&&!(u=u.call(i,t[1])).done)return u;switch(i=0,u&&(t=[2&t[0],u.value]),t[0]){case 0:case 1:u=t;break;case 4:return s.label++,{value:t[1],done:!1};case 5:s.label++,i=t[1],t=[0];continue;case 7:t=s.ops.pop(),s.trys.pop();continue;default:if(!(u=0<(u=s.trys).length&&u[u.length-1])&&(6===t[0]||2===t[0])){s=0;continue}if(3===t[0]&&(!u||t[1]>u[0]&&t[1]<u[3])){s.label=t[1];break}if(6===t[0]&&s.label<u[1]){s.label=u[1],u=t;break}if(u&&s.label<u[2]){s.label=u[2],s.ops.push(t);break}u[2]&&s.ops.pop(),s.trys.pop();continue}t=r.call(n,s)}catch(e){t=[6,e],i=0}finally{o=u=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}},_this=this;Object.defineProperty(exports,"__esModule",{value:!0});var _mainDB,_supportDB,mongoose=require("mongoose"),serverConfig=require("./settings.json");function getMainDB(){return _mainDB}function getSupportDB(){return _supportDB}exports.getMainDB=getMainDB,exports.getSupportDB=getSupportDB,"http://localhost:4200"!==serverConfig.ROOT_URL?mongoose.createConnection(serverConfig.RESOLVEIO_SUPPORT_MONGO_URL,{useNewUrlParser:!0}).then(function(t){return __awaiter(_this,void 0,void 0,function(){var n=this;return __generator(this,function(e){return _supportDB=t,mongoose.createConnection(serverConfig.MONGO_URL,{useNewUrlParser:!0}).then(function(t){return __awaiter(n,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return _mainDB=t,[4,Promise.resolve().then(function(){return require("./server-app")})];case 1:return e.sent().default.init(),[2]}})})},function(e){process.exit()}),[2]})})},function(e){process.exit()}):(_supportDB=null,mongoose.createConnection(serverConfig.MONGO_URL,{useNewUrlParser:!0}).then(function(t){return __awaiter(_this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return _mainDB=t,[4,Promise.resolve().then(function(){return require("./server-app")})];case 1:return e.sent().default.init(),[2]}})})},function(e){process.exit()}));
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ var mongoose = require("mongoose");
39
+ // import { ResolveIOMainServer } from './server-app';
40
+ // let serverConfig = require('./settings.json');
41
+ var ResolveIOServer = /** @class */ (function () {
42
+ function ResolveIOServer(serverConfig, client) {
43
+ ResolveIOServer._serverConfig = serverConfig;
44
+ ResolveIOServer._client = client;
45
+ }
46
+ ResolveIOServer.prototype.connectAndRun = function (serverConfig) {
47
+ return __awaiter(this, void 0, void 0, function () {
48
+ var _this = this;
49
+ return __generator(this, function (_a) {
50
+ if (serverConfig['ROOT_URL'] !== 'http://localhost:4200') {
51
+ mongoose.createConnection(serverConfig['RESOLVEIO_SUPPORT_MONGO_URL'], { useNewUrlParser: true }).then(function (db) { return __awaiter(_this, void 0, void 0, function () {
52
+ var _this = this;
53
+ return __generator(this, function (_a) {
54
+ ResolveIOServer._supportDB = db;
55
+ mongoose.createConnection(serverConfig['MONGO_URL'], { useNewUrlParser: true }).then(function (dbMain) { return __awaiter(_this, void 0, void 0, function () {
56
+ var serverApp;
57
+ return __generator(this, function (_a) {
58
+ switch (_a.label) {
59
+ case 0:
60
+ ResolveIOServer._mainDB = dbMain;
61
+ return [4 /*yield*/, Promise.resolve().then(function () { return require('./server-app'); })];
62
+ case 1:
63
+ serverApp = (_a.sent()).default;
64
+ ResolveIOServer._mainServer = new serverApp(this, ResolveIOServer._serverConfig);
65
+ return [2 /*return*/];
66
+ }
67
+ });
68
+ }); }, function (err) {
69
+ process.exit();
70
+ });
71
+ return [2 /*return*/];
72
+ });
73
+ }); }, function (err) {
74
+ process.exit();
75
+ });
76
+ }
77
+ else {
78
+ ResolveIOServer._supportDB = null;
79
+ mongoose.createConnection(serverConfig['MONGO_URL'], { useNewUrlParser: true }).then(function (dbMain) { return __awaiter(_this, void 0, void 0, function () {
80
+ var serverApp;
81
+ return __generator(this, function (_a) {
82
+ switch (_a.label) {
83
+ case 0:
84
+ ResolveIOServer._mainDB = dbMain;
85
+ return [4 /*yield*/, Promise.resolve().then(function () { return require('./server-app'); })];
86
+ case 1:
87
+ serverApp = (_a.sent()).default;
88
+ ResolveIOServer._mainServer = new serverApp(this, ResolveIOServer._serverConfig);
89
+ return [2 /*return*/];
90
+ }
91
+ });
92
+ }); }, function (err) {
93
+ process.exit();
94
+ });
95
+ }
96
+ return [2 /*return*/];
97
+ });
98
+ });
99
+ };
100
+ ResolveIOServer.getClientName = function () {
101
+ return this._client;
102
+ };
103
+ ResolveIOServer.getMainServer = function () {
104
+ return ResolveIOServer._mainServer;
105
+ };
106
+ ResolveIOServer.getMainDB = function () {
107
+ return ResolveIOServer._mainDB;
108
+ };
109
+ ResolveIOServer.getSupportDB = function () {
110
+ return ResolveIOServer._supportDB;
111
+ };
112
+ ResolveIOServer._serverConfig = null;
113
+ ResolveIOServer._mainDB = null;
114
+ ResolveIOServer._supportDB = null;
115
+ ResolveIOServer._mainServer = null;
116
+ ResolveIOServer._client = '';
117
+ return ResolveIOServer;
118
+ }());
119
+ exports.ResolveIOServer = ResolveIOServer;
120
+ // export * from './server-app';