@resolveio/server-lib 1.0.0-rc19 → 1.0.0-rc2
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/active-subscription.collection.js +1 -68
- package/collections/app-status.collection.js +1 -43
- package/collections/app-version.collection.js +1 -56
- package/collections/counter.collection.js +1 -73
- package/collections/cron-job-history.collection.js +1 -86
- package/collections/cron-job.collection.js +1 -89
- package/collections/file.collection.js +1 -73
- package/collections/flag.collection.js +1 -47
- package/collections/log.collection.js +1 -64
- package/collections/logged-in-users.collection.js +1 -70
- package/collections/method-call.collection.js +1 -44
- package/collections/method-response.collection.js +1 -48
- package/collections/queue-flag.collection.js +1 -41
- package/collections/queue-method.collection.js +1 -116
- package/collections/queue-response.collection.js +1 -78
- package/collections/support-ticket.collection.js +1 -146
- package/collections/user.collection.js +1 -108
- package/cron/cron.js +1 -160
- package/fixtures/cron-jobs.js +1 -72
- package/fixtures/init.js +1 -73
- package/http/auth.js +1 -472
- package/http/health.js +1 -8
- package/index.js +1 -123
- package/managers/cron.manager.js +1 -193
- package/managers/method.manager.js +1 -513
- package/managers/queue-method.manager.js +1 -239
- package/managers/subscription.manager.js +1 -700
- package/managers/support.manager.js +1 -208
- package/methods/accounts.js +1 -253
- package/methods/aws.js +1 -323
- package/methods/cloudconvert.js +1 -37
- package/methods/collections.js +1 -738
- package/methods/counters.js +1 -404
- package/methods/cron-jobs.js +1 -63
- package/methods/flags.js +1 -6
- package/methods/logs.js +1 -29
- package/methods/pdf.js +1 -303
- package/models/active-subscription.model.js +1 -2
- package/models/app-status.model.js +1 -2
- package/models/app-version.model.js +1 -2
- package/models/collection-document.model.js +1 -2
- package/models/counter.model.js +1 -2
- package/models/cron-job-history.model.js +1 -2
- package/models/cron-job.model.js +1 -2
- package/models/dialog.model.js +1 -2
- package/models/file.model.js +1 -2
- package/models/flag.model.js +1 -2
- package/models/log.model.js +1 -2
- package/models/logged-in-users.model.js +1 -2
- package/models/method-call.model.js +1 -2
- package/models/method-response.model.js +1 -2
- package/models/method.model.js +1 -2
- package/models/pagination.model.js +1 -20
- package/models/permission.model.js +1 -2
- package/models/queue-method.model.js +1 -2
- package/models/queue-response.model.js +1 -2
- package/models/select-data-label.model.js +1 -2
- package/models/server-response.model.js +1 -2
- package/models/subscription.model.js +1 -2
- package/models/support-method.model.js +1 -2
- package/models/support-ticket.model.js +1 -2
- package/models/user.model.js +1 -2
- package/package.json +2 -5
- package/publications/app-status.js +1 -14
- package/publications/app-version.js +1 -14
- package/publications/cron-jobs.js +1 -14
- package/publications/files.js +1 -71
- package/publications/flags.js +1 -23
- package/publications/logs.js +1 -26
- package/publications/method-calls.js +1 -14
- package/publications/method-responses.js +1 -14
- package/publications/super-admin.js +1 -21
- package/publications/support-tickets.js +1 -118
- package/server-app.js +1 -640
- package/support-methods/aws.js +1 -276
- package/support-methods/collections.js +1 -471
- package/support-methods/counters.js +1 -189
- package/support-methods/support.js +1 -19
- package/util/common.js +1 -334
- package/collections/active-subscription.collection.d.ts +0 -8
- package/collections/app-status.collection.d.ts +0 -8
- package/collections/app-version.collection.d.ts +0 -8
- package/collections/counter.collection.d.ts +0 -10
- package/collections/cron-job-history.collection.d.ts +0 -8
- package/collections/cron-job.collection.d.ts +0 -8
- package/collections/file.collection.d.ts +0 -10
- package/collections/flag.collection.d.ts +0 -8
- package/collections/log.collection.d.ts +0 -8
- package/collections/logged-in-users.collection.d.ts +0 -8
- package/collections/method-call.collection.d.ts +0 -7
- package/collections/method-response.collection.d.ts +0 -7
- package/collections/queue-flag.collection.d.ts +0 -8
- package/collections/queue-method.collection.d.ts +0 -8
- package/collections/queue-response.collection.d.ts +0 -8
- package/collections/support-ticket.collection.d.ts +0 -8
- package/collections/user.collection.d.ts +0 -9
- package/cron/cron.d.ts +0 -6
- package/fixtures/cron-jobs.d.ts +0 -2
- package/fixtures/init.d.ts +0 -2
- package/http/auth.d.ts +0 -3
- package/http/health.d.ts +0 -2
- package/index.d.ts +0 -15
- package/managers/cron.manager.d.ts +0 -17
- package/managers/method.manager.d.ts +0 -27
- package/managers/queue-method.manager.d.ts +0 -14
- package/managers/subscription.manager.d.ts +0 -27
- package/managers/support.manager.d.ts +0 -18
- package/methods/accounts.d.ts +0 -3
- package/methods/aws.d.ts +0 -3
- package/methods/cloudconvert.d.ts +0 -3
- package/methods/collections.d.ts +0 -3
- package/methods/counters.d.ts +0 -3
- package/methods/cron-jobs.d.ts +0 -3
- package/methods/flags.d.ts +0 -3
- package/methods/logs.d.ts +0 -3
- package/methods/pdf.d.ts +0 -3
- package/models/active-subscription.model.d.ts +0 -14
- package/models/app-status.model.d.ts +0 -5
- package/models/app-version.model.d.ts +0 -5
- package/models/collection-document.model.d.ts +0 -7
- package/models/counter.model.d.ts +0 -6
- package/models/cron-job-history.model.d.ts +0 -13
- package/models/cron-job.model.d.ts +0 -14
- package/models/dialog.model.d.ts +0 -24
- package/models/file.model.d.ts +0 -10
- package/models/flag.model.d.ts +0 -6
- package/models/log.model.d.ts +0 -12
- package/models/logged-in-users.model.d.ts +0 -10
- package/models/method-call.model.d.ts +0 -8
- package/models/method-response.model.d.ts +0 -9
- package/models/method.model.d.ts +0 -11
- package/models/pagination.model.d.ts +0 -12
- package/models/permission.model.d.ts +0 -13
- package/models/queue-method.model.d.ts +0 -10
- package/models/queue-response.model.d.ts +0 -11
- package/models/select-data-label.model.d.ts +0 -10
- package/models/server-response.model.d.ts +0 -6
- package/models/subscription.model.d.ts +0 -31
- package/models/support-method.model.d.ts +0 -10
- package/models/support-ticket.model.d.ts +0 -40
- package/models/user.model.d.ts +0 -15
- package/publications/app-status.d.ts +0 -3
- package/publications/app-version.d.ts +0 -3
- package/publications/cron-jobs.d.ts +0 -3
- package/publications/files.d.ts +0 -3
- package/publications/flags.d.ts +0 -3
- package/publications/logs.d.ts +0 -3
- package/publications/method-calls.d.ts +0 -3
- package/publications/method-responses.d.ts +0 -3
- package/publications/super-admin.d.ts +0 -3
- package/publications/support-tickets.d.ts +0 -2
- package/server-app.d.ts +0 -33
- package/support-methods/aws.d.ts +0 -3
- package/support-methods/collections.d.ts +0 -3
- package/support-methods/counters.d.ts +0 -3
- package/support-methods/support.d.ts +0 -3
- package/util/common.d.ts +0 -15
package/http/auth.js
CHANGED
|
@@ -1,472 +1 @@
|
|
|
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?' + encodeURIComponent(serverConfig['SERVER_URL']) + '&' + 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;
|
|
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"),__1=require("..");function setupAuthRoutes(o,e,a){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===a.ROOT_URL||n.headers.origin===a.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},a.JWT_SECRET);var n={userToChangePassword:t.fullname,userWhoResetPassword:__1.default.getClientName()+" System",url:a.ROOT_URL+"/forgot-password/"+t.services.forgot_password+"/"};user_collection_1.Users.updateOne({_id:t._id},{$set:{services:t.services}}).exec(function(e,r){o.getMethodManager().readFile("email-templates/forgot-password.html").then(function(e){var r=handlebars.compile(e);handlebars.registerHelper("equals",function(e,r){return e===r}),o.getMethodManager().sendEmail(t.email,"ResolveIO ("+__1.default.getClientName()+") - 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},a.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!==a.ROOT_URL&&r.headers.origin!==a.SEC_ROOT_URL&&r.headers.origin!==a.RESOLVEIO_URL&&r.headers.origin!==a.RESOLVEIO_SECONDARY_URL?t.send(JSON.stringify({error:!0,result:"Invalid header"})):"http://localhost:4200"!==a.ROOT_URL?jwt.verify(r.body.refreshToken,a.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},a.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,a.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},a.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!==a.ROOT_URL&&n.headers.origin!==a.SEC_ROOT_URL&&n.headers.origin!==a.RESOLVEIO_URL&&n.headers.origin!==a.RESOLVEIO_SECONDARY_URL?s.send(JSON.stringify({error:!0,result:"Invalid header"})):jwt.verify(n.body.enrollmentToken,a.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!==a.ROOT_URL&&s.headers.origin!==a.SEC_ROOT_URL&&s.headers.origin!==a.RESOLVEIO_URL&&s.headers.origin!==a.RESOLVEIO_SECONDARY_URL?t.send(JSON.stringify({error:!0,result:"Invalid header"})):jwt.verify(s.body.enrollmentToken,a.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!==a.ROOT_URL&&n.headers.origin!==a.SEC_ROOT_URL&&n.headers.origin!==a.RESOLVEIO_URL&&n.headers.origin!==a.RESOLVEIO_SECONDARY_URL?s.send(JSON.stringify({error:!0,result:"Invalid header"})):jwt.verify(n.body.forgotPasswordToken,a.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!==a.ROOT_URL&&t.headers.origin!==a.SEC_ROOT_URL&&t.headers.origin!==a.RESOLVEIO_URL&&t.headers.origin!==a.RESOLVEIO_SECONDARY_URL?i.send(JSON.stringify({error:!0,result:"Invalid header"})):jwt.verify(t.body.forgotPasswordToken,a.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;
|
package/http/health.js
CHANGED
|
@@ -1,8 +1 @@
|
|
|
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;
|
|
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;
|
package/index.js
CHANGED
|
@@ -1,123 +1 @@
|
|
|
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
|
-
var ResolveIOServer = /** @class */ (function () {
|
|
40
|
-
function ResolveIOServer(serverConfig, client) {
|
|
41
|
-
ResolveIOServer._serverConfig = serverConfig;
|
|
42
|
-
ResolveIOServer._client = client;
|
|
43
|
-
}
|
|
44
|
-
ResolveIOServer.connectAndRun = function () {
|
|
45
|
-
var _this = this;
|
|
46
|
-
return new Promise(function (resolve, reject) {
|
|
47
|
-
if (ResolveIOServer._serverConfig['ROOT_URL'] !== 'http://localhost:4200') {
|
|
48
|
-
mongoose.createConnection(ResolveIOServer._serverConfig['RESOLVEIO_SUPPORT_MONGO_URL'], { useNewUrlParser: true }).then(function (db) { return __awaiter(_this, void 0, void 0, function () {
|
|
49
|
-
var _this = this;
|
|
50
|
-
return __generator(this, function (_a) {
|
|
51
|
-
ResolveIOServer._supportDB = db;
|
|
52
|
-
mongoose.createConnection(ResolveIOServer._serverConfig['MONGO_URL'], { useNewUrlParser: true }).then(function (dbMain) { return __awaiter(_this, void 0, void 0, function () {
|
|
53
|
-
var serverApp;
|
|
54
|
-
return __generator(this, function (_a) {
|
|
55
|
-
switch (_a.label) {
|
|
56
|
-
case 0:
|
|
57
|
-
ResolveIOServer._mainDB = dbMain;
|
|
58
|
-
return [4 /*yield*/, Promise.resolve().then(function () { return require('./server-app'); })];
|
|
59
|
-
case 1:
|
|
60
|
-
serverApp = (_a.sent()).default;
|
|
61
|
-
ResolveIOServer._mainServer = new serverApp(this, ResolveIOServer._serverConfig);
|
|
62
|
-
setTimeout(function () {
|
|
63
|
-
resolve();
|
|
64
|
-
}, 5000);
|
|
65
|
-
return [2 /*return*/];
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}); }, function (err) {
|
|
69
|
-
process.exit();
|
|
70
|
-
reject();
|
|
71
|
-
});
|
|
72
|
-
return [2 /*return*/];
|
|
73
|
-
});
|
|
74
|
-
}); }, function (err) {
|
|
75
|
-
process.exit();
|
|
76
|
-
reject();
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
ResolveIOServer._supportDB = null;
|
|
81
|
-
mongoose.createConnection(ResolveIOServer._serverConfig['MONGO_URL'], { useNewUrlParser: true }).then(function (dbMain) { return __awaiter(_this, void 0, void 0, function () {
|
|
82
|
-
var serverApp;
|
|
83
|
-
return __generator(this, function (_a) {
|
|
84
|
-
switch (_a.label) {
|
|
85
|
-
case 0:
|
|
86
|
-
ResolveIOServer._mainDB = dbMain;
|
|
87
|
-
return [4 /*yield*/, Promise.resolve().then(function () { return require('./server-app'); })];
|
|
88
|
-
case 1:
|
|
89
|
-
serverApp = (_a.sent()).default;
|
|
90
|
-
ResolveIOServer._mainServer = new serverApp(this, ResolveIOServer._serverConfig);
|
|
91
|
-
setTimeout(function () {
|
|
92
|
-
resolve();
|
|
93
|
-
}, 5000);
|
|
94
|
-
return [2 /*return*/];
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}); }, function (err) {
|
|
98
|
-
process.exit();
|
|
99
|
-
reject();
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
ResolveIOServer.getClientName = function () {
|
|
105
|
-
return this._client;
|
|
106
|
-
};
|
|
107
|
-
ResolveIOServer.getMainServer = function () {
|
|
108
|
-
return ResolveIOServer._mainServer;
|
|
109
|
-
};
|
|
110
|
-
ResolveIOServer.getMainDB = function () {
|
|
111
|
-
return ResolveIOServer._mainDB;
|
|
112
|
-
};
|
|
113
|
-
ResolveIOServer.getSupportDB = function () {
|
|
114
|
-
return ResolveIOServer._supportDB;
|
|
115
|
-
};
|
|
116
|
-
ResolveIOServer._serverConfig = null;
|
|
117
|
-
ResolveIOServer._mainDB = null;
|
|
118
|
-
ResolveIOServer._supportDB = null;
|
|
119
|
-
ResolveIOServer._mainServer = null;
|
|
120
|
-
ResolveIOServer._client = '';
|
|
121
|
-
return ResolveIOServer;
|
|
122
|
-
}());
|
|
123
|
-
exports.ResolveIOServer = ResolveIOServer;
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(i,u,a,s){return new(a||(a=Promise))(function(e,n){function r(e){try{o(s.next(e))}catch(e){n(e)}}function t(e){try{o(s.throw(e))}catch(e){n(e)}}function o(n){n.done?e(n.value):new a(function(e){e(n.value)}).then(r,t)}o((s=s.apply(i,u||[])).next())})},__generator=this&&this.__generator||function(r,t){var o,i,u,e,a={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return e={next:n(0),throw:n(1),return:n(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function n(n){return function(e){return function(n){if(o)throw new TypeError("Generator is already executing.");for(;a;)try{if(o=1,i&&(u=2&n[0]?i.return:n[0]?i.throw||((u=i.return)&&u.call(i),0):i.next)&&!(u=u.call(i,n[1])).done)return u;switch(i=0,u&&(n=[2&n[0],u.value]),n[0]){case 0:case 1:u=n;break;case 4:return a.label++,{value:n[1],done:!1};case 5:a.label++,i=n[1],n=[0];continue;case 7:n=a.ops.pop(),a.trys.pop();continue;default:if(!(u=0<(u=a.trys).length&&u[u.length-1])&&(6===n[0]||2===n[0])){a=0;continue}if(3===n[0]&&(!u||n[1]>u[0]&&n[1]<u[3])){a.label=n[1];break}if(6===n[0]&&a.label<u[1]){a.label=u[1],u=n;break}if(u&&a.label<u[2]){a.label=u[2],a.ops.push(n);break}u[2]&&a.ops.pop(),a.trys.pop();continue}n=t.call(r,a)}catch(e){n=[6,e],i=0}finally{o=u=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,e])}}};Object.defineProperty(exports,"__esModule",{value:!0});var mongoose=require("mongoose"),server_app_1=require("./server-app"),ResolveIOServer=function(){function o(t,e){var r=this;o._serverConfig=t,o._client=e,"http://localhost:4200"!==t.ROOT_URL?mongoose.createConnection(t.RESOLVEIO_SUPPORT_MONGO_URL,{useNewUrlParser:!0}).then(function(n){return __awaiter(r,void 0,void 0,function(){var r=this;return __generator(this,function(e){return o._supportDB=n,mongoose.createConnection(t.MONGO_URL,{useNewUrlParser:!0}).then(function(n){return __awaiter(r,void 0,void 0,function(){return __generator(this,function(e){return o._mainDB=n,o._mainServer=new server_app_1.ResolveIOMainServer(this,o._serverConfig),[2]})})},function(e){process.exit()}),[2]})})},function(e){process.exit()}):(o._supportDB=null,mongoose.createConnection(t.MONGO_URL,{useNewUrlParser:!0}).then(function(n){return __awaiter(r,void 0,void 0,function(){return __generator(this,function(e){return o._mainDB=n,o._mainServer=new server_app_1.ResolveIOMainServer(this,o._serverConfig),[2]})})},function(e){process.exit()}))}return o.getClientName=function(){return this._client},o.getMainServer=function(){return o._mainServer},o.getMainDB=function(){return o._mainDB},o.getSupportDB=function(){return o._supportDB},o._serverConfig=null,o._mainDB=null,o._supportDB=null,o._mainServer=null,o._client="",o}();exports.default=ResolveIOServer;
|