@resolveio/server-lib 1.0.0-rc28 → 1.0.0-rc3
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 -125
- package/managers/cron.manager.js +1 -193
- package/managers/method.manager.js +1 -544
- 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 -345
- 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 -641
- 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 -17
- package/managers/cron.manager.d.ts +0 -17
- package/managers/method.manager.d.ts +0 -28
- 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/notification.model.d.ts +0 -5
- package/models/notification.model.js +0 -2
- 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 -34
- 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
|
@@ -1,208 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var nodemailer = require("nodemailer");
|
|
4
|
-
var aws = require("aws-sdk");
|
|
5
|
-
var collections_1 = require("../support-methods/collections");
|
|
6
|
-
var support_1 = require("../support-methods/support");
|
|
7
|
-
var counters_1 = require("../support-methods/counters");
|
|
8
|
-
var mongoose_1 = require("mongoose");
|
|
9
|
-
var common_1 = require("../util/common");
|
|
10
|
-
var log_collection_1 = require("../collections/log.collection");
|
|
11
|
-
var SupportManager = /** @class */ (function () {
|
|
12
|
-
function SupportManager(mainServer, serverConfig) {
|
|
13
|
-
var _this = this;
|
|
14
|
-
this._supportMethods = {};
|
|
15
|
-
this._sendQueue = [];
|
|
16
|
-
this._runningQueue = false;
|
|
17
|
-
this._mainServer = mainServer;
|
|
18
|
-
this.serverConfig = serverConfig;
|
|
19
|
-
collections_1.loadSupportCollectionMethods(this);
|
|
20
|
-
support_1.loadSupportMethods(this);
|
|
21
|
-
counters_1.loadCounterMethods(this);
|
|
22
|
-
this._mailer = nodemailer.createTransport({
|
|
23
|
-
SES: new aws.SES({
|
|
24
|
-
apiVersion: '2010-12-01',
|
|
25
|
-
accessKeyId: serverConfig.AWSACCESSKEYID,
|
|
26
|
-
secretAccessKey: serverConfig.AWSSECRETACCESSKEY,
|
|
27
|
-
region: serverConfig.AWSSES_REGION
|
|
28
|
-
})
|
|
29
|
-
});
|
|
30
|
-
this._aws = new aws.S3({
|
|
31
|
-
accessKeyId: serverConfig.AWSACCESSKEYID,
|
|
32
|
-
secretAccessKey: serverConfig.AWSSECRETACCESSKEY,
|
|
33
|
-
region: serverConfig.AWSREGION
|
|
34
|
-
});
|
|
35
|
-
setInterval(function () {
|
|
36
|
-
if (!_this._runningQueue) {
|
|
37
|
-
if (_this._sendQueue.length) {
|
|
38
|
-
_this._runningQueue = true;
|
|
39
|
-
var _loop_1 = function (i) {
|
|
40
|
-
var ws = _this._mainServer.getWS(_this._sendQueue[i].id_ws);
|
|
41
|
-
if (ws && ws.readyState === ws.OPEN) {
|
|
42
|
-
if (ws.bufferedAmount < 20480) {
|
|
43
|
-
var sendItem = _this._sendQueue.pop();
|
|
44
|
-
ws.send(JSON.stringify(sendItem.data), function (error) {
|
|
45
|
-
if (error) {
|
|
46
|
-
console.log('Error on WS: ', error);
|
|
47
|
-
_this._mainServer.unsubscribeWS(ws);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
// if (sendItem.method !== 'countQuery' && sendItem.method !== 'countCollectionWithQuery' && sendItem.method !== 'find' && sendItem.method !== 'findOne' && sendItem.method !== 'findWithOptions' && sendItem.method !== 'setWSAppVersion' && sendItem.method !== 'uploadFileAndSave') {
|
|
51
|
-
if (common_1.getBinarySize(JSON.stringify(sendItem.methodData)) < 200000 && common_1.getBinarySize(JSON.stringify(sendItem.data)) < 200000) {
|
|
52
|
-
log_collection_1.Logs.create({
|
|
53
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
54
|
-
date: new Date(),
|
|
55
|
-
type: 'client-response',
|
|
56
|
-
title: 'Client Response - Support',
|
|
57
|
-
message: 'User: ' + ws['user'] + ', MessageId: ' + sendItem.data.messageId + ', Support Method: ' + sendItem.method,
|
|
58
|
-
payload: [JSON.stringify(sendItem.methodData), sendItem.data],
|
|
59
|
-
method: sendItem.method,
|
|
60
|
-
user: ws['user'],
|
|
61
|
-
messageId: sendItem.data.messageId
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
log_collection_1.Logs.create({
|
|
66
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
67
|
-
date: new Date(),
|
|
68
|
-
type: 'client-response',
|
|
69
|
-
title: 'Client Response - Support',
|
|
70
|
-
message: 'User: ' + ws['user'] + ', MessageId: ' + sendItem.data.messageId + ', Support Method: ' + sendItem.method,
|
|
71
|
-
payload: 'Too Big',
|
|
72
|
-
method: sendItem.method,
|
|
73
|
-
user: ws['user'],
|
|
74
|
-
messageId: sendItem.data.messageId
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
// }
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
_this._sendQueue.splice(i, 1);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
for (var i = _this._sendQueue.length - 1; i >= 0; i--) {
|
|
85
|
-
_loop_1(i);
|
|
86
|
-
}
|
|
87
|
-
_this._runningQueue = false;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}, 250);
|
|
91
|
-
}
|
|
92
|
-
SupportManager.prototype.getMainServer = function () {
|
|
93
|
-
return this._mainServer;
|
|
94
|
-
};
|
|
95
|
-
// Add methods to private methods object
|
|
96
|
-
SupportManager.prototype.supportMethods = function (supportMethod) {
|
|
97
|
-
this._supportMethods = Object.assign(this._supportMethods, supportMethod);
|
|
98
|
-
};
|
|
99
|
-
// Call/run method (Emit on Socket)
|
|
100
|
-
SupportManager.prototype.callSupportMethod = function (ws, messageId, supportMethod) {
|
|
101
|
-
var _this = this;
|
|
102
|
-
var methodData = [];
|
|
103
|
-
for (var _i = 3; _i < arguments.length; _i++) {
|
|
104
|
-
methodData[_i - 3] = arguments[_i];
|
|
105
|
-
}
|
|
106
|
-
var _a;
|
|
107
|
-
var that = this;
|
|
108
|
-
if (!that._supportMethods[supportMethod]) {
|
|
109
|
-
console.log('No Support Method: ' + supportMethod);
|
|
110
|
-
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Support Method: ' + supportMethod);
|
|
111
|
-
var serverRes = {
|
|
112
|
-
messageId: messageId,
|
|
113
|
-
hasError: true,
|
|
114
|
-
data: 'Internal Error'
|
|
115
|
-
};
|
|
116
|
-
this.sendWS(ws, supportMethod, methodData, serverRes);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if ((methodData.length > 1 || methodData[0])) {
|
|
120
|
-
if (!that._supportMethods[supportMethod].check) {
|
|
121
|
-
console.error('No Check Function For Support Method ' + supportMethod);
|
|
122
|
-
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Support Method ' + supportMethod);
|
|
123
|
-
var serverRes = {
|
|
124
|
-
messageId: messageId,
|
|
125
|
-
hasError: true,
|
|
126
|
-
data: 'Internal Error'
|
|
127
|
-
};
|
|
128
|
-
this.sendWS(ws, supportMethod, methodData, serverRes);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
else if (!that._supportMethods[supportMethod].check._schema) {
|
|
132
|
-
console.error('No Check Schema For Method ' + supportMethod);
|
|
133
|
-
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Support Method ' + supportMethod);
|
|
134
|
-
var serverRes = {
|
|
135
|
-
messageId: messageId,
|
|
136
|
-
hasError: true,
|
|
137
|
-
data: 'Internal Error'
|
|
138
|
-
};
|
|
139
|
-
this.sendWS(ws, supportMethod, methodData, serverRes);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
var valObj = {};
|
|
144
|
-
var valKeys = Object.keys(that._supportMethods[supportMethod].check._schema);
|
|
145
|
-
var rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
|
|
146
|
-
for (var i = 0; i < methodData.length; i++) {
|
|
147
|
-
valObj[rootKeys[i]] = methodData[i];
|
|
148
|
-
}
|
|
149
|
-
try {
|
|
150
|
-
that._supportMethods[supportMethod].check.validate(valObj);
|
|
151
|
-
}
|
|
152
|
-
catch (errors) {
|
|
153
|
-
if (errors) {
|
|
154
|
-
console.error('Error in Support Method Check (' + supportMethod + ')', errors);
|
|
155
|
-
that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'Match Error On Support Method ' + supportMethod + '\n\nData Being Checked\n' + JSON.stringify(valObj, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
|
|
156
|
-
var serverRes = {
|
|
157
|
-
messageId: messageId,
|
|
158
|
-
hasError: true,
|
|
159
|
-
data: 'Internal Error'
|
|
160
|
-
};
|
|
161
|
-
this.sendWS(ws, supportMethod, methodData, serverRes);
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
(_a = that._supportMethods[supportMethod].function).call.apply(_a, [Object.assign({}, that, SupportManager.prototype, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] })].concat(methodData)).then(function (res) {
|
|
168
|
-
var serverRes = {
|
|
169
|
-
messageId: messageId,
|
|
170
|
-
hasError: false,
|
|
171
|
-
data: res
|
|
172
|
-
};
|
|
173
|
-
_this.sendWS(ws, supportMethod, methodData, serverRes);
|
|
174
|
-
}, function (err) {
|
|
175
|
-
var serverRes = {
|
|
176
|
-
messageId: messageId,
|
|
177
|
-
hasError: true,
|
|
178
|
-
data: err
|
|
179
|
-
};
|
|
180
|
-
_this.sendWS(ws, supportMethod, methodData, serverRes);
|
|
181
|
-
});
|
|
182
|
-
};
|
|
183
|
-
SupportManager.prototype.sendWS = function (ws, method, methodData, data) {
|
|
184
|
-
this._sendQueue.splice(0, 0, {
|
|
185
|
-
id_ws: ws['id_socket'],
|
|
186
|
-
method: method,
|
|
187
|
-
methodData: methodData,
|
|
188
|
-
data: data
|
|
189
|
-
});
|
|
190
|
-
};
|
|
191
|
-
SupportManager.prototype.sendEmail = function (sendTo, subject, text, html, attachments) {
|
|
192
|
-
this._mailer.sendMail({
|
|
193
|
-
replyTo: undefined,
|
|
194
|
-
from: this.serverConfig.MAIL_FROM,
|
|
195
|
-
to: sendTo,
|
|
196
|
-
subject: subject,
|
|
197
|
-
text: text,
|
|
198
|
-
html: html,
|
|
199
|
-
attachments: attachments
|
|
200
|
-
}, function (err, info) {
|
|
201
|
-
if (err) {
|
|
202
|
-
console.log(err);
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
};
|
|
206
|
-
return SupportManager;
|
|
207
|
-
}());
|
|
208
|
-
exports.SupportManager = SupportManager;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var nodemailer=require("nodemailer"),aws=require("aws-sdk"),collections_1=require("../support-methods/collections"),support_1=require("../support-methods/support"),counters_1=require("../support-methods/counters"),mongoose_1=require("mongoose"),common_1=require("../util/common"),log_collection_1=require("../collections/log.collection"),SupportManager=function(){function e(e,o){var r=this;this._supportMethods={},this._sendQueue=[],this._runningQueue=!1,this._mainServer=e,this.serverConfig=o,collections_1.loadSupportCollectionMethods(this),support_1.loadSupportMethods(this),counters_1.loadCounterMethods(this),this._mailer=nodemailer.createTransport({SES:new aws.SES({apiVersion:"2010-12-01",accessKeyId:o.AWSACCESSKEYID,secretAccessKey:o.AWSSECRETACCESSKEY,region:o.AWSSES_REGION})}),this._aws=new aws.S3({accessKeyId:o.AWSACCESSKEYID,secretAccessKey:o.AWSSECRETACCESSKEY,region:o.AWSREGION}),setInterval(function(){if(!r._runningQueue&&r._sendQueue.length){r._runningQueue=!0;for(var e=function(e){var o=r._mainServer.getWS(r._sendQueue[e].id_ws);if(o&&o.readyState===o.OPEN){if(o.bufferedAmount<20480){var t=r._sendQueue.pop();o.send(JSON.stringify(t.data),function(e){e&&(console.log("Error on WS: ",e),r._mainServer.unsubscribeWS(o))}),common_1.getBinarySize(JSON.stringify(t.methodData))<2e5&&common_1.getBinarySize(JSON.stringify(t.data))<2e5?log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-response",title:"Client Response - Support",message:"User: "+o.user+", MessageId: "+t.data.messageId+", Support Method: "+t.method,payload:[JSON.stringify(t.methodData),t.data],method:t.method,user:o.user,messageId:t.data.messageId}):log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"client-response",title:"Client Response - Support",message:"User: "+o.user+", MessageId: "+t.data.messageId+", Support Method: "+t.method,payload:"Too Big",method:t.method,user:o.user,messageId:t.data.messageId})}}else r._sendQueue.splice(e,1)},o=r._sendQueue.length-1;0<=o;o--)e(o);r._runningQueue=!1}},250)}return e.prototype.getMainServer=function(){return this._mainServer},e.prototype.supportMethods=function(e){this._supportMethods=Object.assign(this._supportMethods,e)},e.prototype.callSupportMethod=function(t,r,s){for(var e,n=this,i=[],o=3;o<arguments.length;o++)i[o-3]=arguments[o];var a=this;if(a._supportMethods[s]){if(1<i.length||i[0]){if(!a._supportMethods[s].check){console.error("No Check Function For Support Method "+s),a.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+a.serverConfig.CLIENT_NAME,"No Check Function For Support Method "+s);p={messageId:r,hasError:!0,data:"Internal Error"};return void this.sendWS(t,s,i,p)}if(!a._supportMethods[s].check._schema){console.error("No Check Schema For Method "+s),a.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+a.serverConfig.CLIENT_NAME,"No Check Function For Support Method "+s);p={messageId:r,hasError:!0,data:"Internal Error"};return void this.sendWS(t,s,i,p)}for(var d={},u=Object.keys(a._supportMethods[s].check._schema).filter(function(e){return!e.includes(".")}),c=0;c<i.length;c++)d[u[c]]=i[c];try{a._supportMethods[s].check.validate(d)}catch(e){if(e){console.error("Error in Support Method Check ("+s+")",e),a.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+a.serverConfig.CLIENT_NAME,"Match Error On Support Method "+s+"\n\nData Being Checked\n"+JSON.stringify(d,null,2)+"\n\nErrors\n"+JSON.stringify(e,null,2));p={messageId:r,hasError:!0,data:"Internal Error"};return void this.sendWS(t,s,i,p)}}}(e=a._supportMethods[s].function).call.apply(e,[Object.assign({},a,{id_user:t.id_user,user:t.user,id_ws:t.id_socket})].concat(i)).then(function(e){var o={messageId:r,hasError:!1,data:e};n.sendWS(t,s,i,o)},function(e){var o={messageId:r,hasError:!0,data:e};n.sendWS(t,s,i,o)})}else{console.log("No Support Method: "+s),a.sendEmail("dev@resolveio.com","SERVER - Error Detected - "+a.serverConfig.CLIENT_NAME,"No Support Method: "+s);var p={messageId:r,hasError:!0,data:"Internal Error"};this.sendWS(t,s,i,p)}},e.prototype.sendWS=function(e,o,t,r){this._sendQueue.splice(0,0,{id_ws:e.id_socket,method:o,methodData:t,data:r})},e.prototype.sendEmail=function(e,o,t,r,s){this._mailer.sendMail({replyTo:void 0,from:this.serverConfig.MAIL_FROM,to:e,subject:o,text:t,html:r,attachments:s},function(e,o){e&&console.log(e)})},e}();exports.SupportManager=SupportManager;
|
package/methods/accounts.js
CHANGED
|
@@ -1,253 +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 simpl_schema_1 = require("simpl-schema");
|
|
39
|
-
var mongoose_1 = require("mongoose");
|
|
40
|
-
var user_collection_1 = require("../collections/user.collection");
|
|
41
|
-
var handlebars = require("handlebars");
|
|
42
|
-
var jwt = require("jsonwebtoken");
|
|
43
|
-
var logged_in_users_collection_1 = require("../collections/logged-in-users.collection");
|
|
44
|
-
var queue_response_collection_1 = require("../collections/queue-response.collection");
|
|
45
|
-
var index_1 = require("../index");
|
|
46
|
-
function loadAccountMethods(methodManager) {
|
|
47
|
-
methodManager.methods({
|
|
48
|
-
setWSAppVersion: {
|
|
49
|
-
skipQueue: true,
|
|
50
|
-
check: new simpl_schema_1.default({
|
|
51
|
-
version: Number
|
|
52
|
-
}),
|
|
53
|
-
function: function (version) {
|
|
54
|
-
return logged_in_users_collection_1.LoggedInUsers.updateOne({ id_ws: this.id_ws }, { $set: { app_version: version } }).exec();
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
reloadWS: {
|
|
58
|
-
skipQueue: true,
|
|
59
|
-
check: new simpl_schema_1.default({
|
|
60
|
-
id_ws: String
|
|
61
|
-
}),
|
|
62
|
-
function: function (id_ws) {
|
|
63
|
-
var _this = this;
|
|
64
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
65
|
-
return __generator(this, function (_a) {
|
|
66
|
-
queue_response_collection_1.QueueResponses.create({
|
|
67
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
68
|
-
__v: 0,
|
|
69
|
-
method: 'reloadWSCommand',
|
|
70
|
-
method_data: [],
|
|
71
|
-
id_ws: id_ws,
|
|
72
|
-
messageId: 0,
|
|
73
|
-
id_user: this.id_user,
|
|
74
|
-
user: this.user,
|
|
75
|
-
response: {
|
|
76
|
-
messageId: 0,
|
|
77
|
-
hasError: false,
|
|
78
|
-
data: 'reloadWSCommand'
|
|
79
|
-
}
|
|
80
|
-
}).then(function (val) {
|
|
81
|
-
// console.log(val);
|
|
82
|
-
});
|
|
83
|
-
resolve();
|
|
84
|
-
return [2 /*return*/];
|
|
85
|
-
});
|
|
86
|
-
}); });
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
reconnectWS: {
|
|
90
|
-
skipQueue: true,
|
|
91
|
-
check: new simpl_schema_1.default({
|
|
92
|
-
id_ws: String
|
|
93
|
-
}),
|
|
94
|
-
function: function (id_ws) {
|
|
95
|
-
var _this = this;
|
|
96
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
97
|
-
return __generator(this, function (_a) {
|
|
98
|
-
queue_response_collection_1.QueueResponses.create({
|
|
99
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
100
|
-
__v: 0,
|
|
101
|
-
method: 'reconnectWSCommand',
|
|
102
|
-
method_data: [],
|
|
103
|
-
id_ws: id_ws,
|
|
104
|
-
messageId: 0,
|
|
105
|
-
id_user: this.id_user,
|
|
106
|
-
user: this.user,
|
|
107
|
-
response: {
|
|
108
|
-
messageId: 0,
|
|
109
|
-
hasError: false,
|
|
110
|
-
data: 'reconnectWSCommand'
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
resolve();
|
|
114
|
-
return [2 /*return*/];
|
|
115
|
-
});
|
|
116
|
-
}); });
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
disconnectWS: {
|
|
120
|
-
skipQueue: true,
|
|
121
|
-
check: new simpl_schema_1.default({
|
|
122
|
-
id_ws: String
|
|
123
|
-
}),
|
|
124
|
-
function: function (id_ws) {
|
|
125
|
-
var _this = this;
|
|
126
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
127
|
-
return __generator(this, function (_a) {
|
|
128
|
-
queue_response_collection_1.QueueResponses.create({
|
|
129
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
130
|
-
__v: 0,
|
|
131
|
-
method: 'disconnectWSCommand',
|
|
132
|
-
method_data: [],
|
|
133
|
-
id_ws: id_ws,
|
|
134
|
-
messageId: 0,
|
|
135
|
-
id_user: this.id_user,
|
|
136
|
-
user: this.user,
|
|
137
|
-
response: {
|
|
138
|
-
messageId: 0,
|
|
139
|
-
hasError: false,
|
|
140
|
-
data: 'disconnectWSCommand'
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
resolve();
|
|
144
|
-
return [2 /*return*/];
|
|
145
|
-
});
|
|
146
|
-
}); });
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
createUserAndEmailEnrollment: {
|
|
150
|
-
check: new simpl_schema_1.default({
|
|
151
|
-
data: {
|
|
152
|
-
type: user_collection_1.Users['simplschema']
|
|
153
|
-
}
|
|
154
|
-
}),
|
|
155
|
-
function: function (data) {
|
|
156
|
-
var _this = this;
|
|
157
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
158
|
-
var userId, user;
|
|
159
|
-
var _this = this;
|
|
160
|
-
return __generator(this, function (_a) {
|
|
161
|
-
switch (_a.label) {
|
|
162
|
-
case 0:
|
|
163
|
-
userId = mongoose_1.Types.ObjectId().toHexString();
|
|
164
|
-
return [4 /*yield*/, user_collection_1.Users.create({
|
|
165
|
-
_id: userId,
|
|
166
|
-
__v: 0,
|
|
167
|
-
username: data.username,
|
|
168
|
-
email: data.email,
|
|
169
|
-
fullname: data.fullname,
|
|
170
|
-
roles: [],
|
|
171
|
-
active: true,
|
|
172
|
-
readonly: false,
|
|
173
|
-
services: {
|
|
174
|
-
enrollment: jwt.sign({ id_user: userId }, this.serverConfig['JWT_SECRET'], {
|
|
175
|
-
expiresIn: 3 * 24 * 60 * 60 * 1000 // 3 days
|
|
176
|
-
})
|
|
177
|
-
},
|
|
178
|
-
phonenumber: data.phonenumber
|
|
179
|
-
})];
|
|
180
|
-
case 1:
|
|
181
|
-
user = _a.sent();
|
|
182
|
-
user.setPassword(randomString(20, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), (function (err, res) {
|
|
183
|
-
user.save();
|
|
184
|
-
var emailData = {
|
|
185
|
-
fullname: user.fullname,
|
|
186
|
-
user: _this.user,
|
|
187
|
-
url: _this.serverConfig['ROOT_URL'] + '/enroll-account?' + encodeURIComponent(_this.serverConfig['SERVER_URL']) + '&' + user.services.enrollment
|
|
188
|
-
};
|
|
189
|
-
_this.readFile('email-templates/enrollment.html').then(function (html) {
|
|
190
|
-
var template = handlebars.compile(html);
|
|
191
|
-
handlebars.registerHelper('equals', function (a, b) {
|
|
192
|
-
return a === b;
|
|
193
|
-
});
|
|
194
|
-
_this.sendEmail(user.email, 'ResolveIO (' + index_1.ResolveIOServer.getClientName() + ') - Enrollment Email', '', template(emailData));
|
|
195
|
-
resolve(true);
|
|
196
|
-
}, function (errEmail) { return reject(errEmail); });
|
|
197
|
-
}));
|
|
198
|
-
return [2 /*return*/];
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}); });
|
|
202
|
-
}
|
|
203
|
-
},
|
|
204
|
-
resetUserPassword: {
|
|
205
|
-
check: new simpl_schema_1.default({
|
|
206
|
-
userId: {
|
|
207
|
-
type: String
|
|
208
|
-
}
|
|
209
|
-
}),
|
|
210
|
-
function: function (userId) {
|
|
211
|
-
var _this = this;
|
|
212
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
213
|
-
var user, emailData_1;
|
|
214
|
-
var _this = this;
|
|
215
|
-
return __generator(this, function (_a) {
|
|
216
|
-
switch (_a.label) {
|
|
217
|
-
case 0: return [4 /*yield*/, user_collection_1.Users.findOne({ _id: userId })];
|
|
218
|
-
case 1:
|
|
219
|
-
user = _a.sent();
|
|
220
|
-
if (user) {
|
|
221
|
-
user.services.forgot_password = jwt.sign({ id_user: userId }, this.serverConfig['JWT_SECRET']);
|
|
222
|
-
emailData_1 = {
|
|
223
|
-
userToChangePassword: user.fullname,
|
|
224
|
-
userWhoResetPassword: this.user,
|
|
225
|
-
url: this.serverConfig['ROOT_URL'] + '/forgot-password?' + encodeURIComponent(this.serverConfig['SERVER_URL']) + '&' + user.services.forgot_password
|
|
226
|
-
};
|
|
227
|
-
user_collection_1.Users.updateOne({ _id: user._id }, { $set: { services: user.services } }).exec(function (err, res) {
|
|
228
|
-
_this.readFile('email-templates/forgot-password.html').then(function (html) {
|
|
229
|
-
var template = handlebars.compile(html);
|
|
230
|
-
handlebars.registerHelper('equals', function (a, b) {
|
|
231
|
-
return a === b;
|
|
232
|
-
});
|
|
233
|
-
_this.sendEmail(user.email, 'ResolveIO (' + index_1.ResolveIOServer.getClientName() + ') - Forgot Password', '', template(emailData_1));
|
|
234
|
-
resolve(true);
|
|
235
|
-
}, function (errEmail) { return reject(errEmail); });
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
return [2 /*return*/];
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}); });
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
exports.loadAccountMethods = loadAccountMethods;
|
|
247
|
-
function randomString(length, chars) {
|
|
248
|
-
var result = '';
|
|
249
|
-
for (var i = length; i > 0; --i) {
|
|
250
|
-
result += chars[Math.floor(Math.random() * chars.length)];
|
|
251
|
-
}
|
|
252
|
-
return result;
|
|
253
|
-
}
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(s,i,u,a){return new(u||(u=Promise))(function(e,n){function r(e){try{o(a.next(e))}catch(e){n(e)}}function t(e){try{o(a.throw(e))}catch(e){n(e)}}function o(n){n.done?e(n.value):new u(function(e){e(n.value)}).then(r,t)}o((a=a.apply(s,i||[])).next())})},__generator=this&&this.__generator||function(r,t){var o,s,i,e,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[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(;u;)try{if(o=1,s&&(i=2&n[0]?s.return:n[0]?s.throw||((i=s.return)&&i.call(s),0):s.next)&&!(i=i.call(s,n[1])).done)return i;switch(s=0,i&&(n=[2&n[0],i.value]),n[0]){case 0:case 1:i=n;break;case 4:return u.label++,{value:n[1],done:!1};case 5:u.label++,s=n[1],n=[0];continue;case 7:n=u.ops.pop(),u.trys.pop();continue;default:if(!(i=0<(i=u.trys).length&&i[i.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!i||n[1]>i[0]&&n[1]<i[3])){u.label=n[1];break}if(6===n[0]&&u.label<i[1]){u.label=i[1],i=n;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(n);break}i[2]&&u.ops.pop(),u.trys.pop();continue}n=t.call(r,u)}catch(e){n=[6,e],s=0}finally{o=i=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 simpl_schema_1=require("simpl-schema"),mongoose_1=require("mongoose"),user_collection_1=require("../collections/user.collection"),handlebars=require("handlebars"),jwt=require("jsonwebtoken"),logged_in_users_collection_1=require("../collections/logged-in-users.collection"),queue_response_collection_1=require("../collections/queue-response.collection"),index_1=require("../index");function loadAccountMethods(e){e.methods({setWSAppVersion:{skipQueue:!0,check:new simpl_schema_1.default({version:Number}),function:function(e){return logged_in_users_collection_1.LoggedInUsers.updateOne({id_ws:this.id_ws},{$set:{app_version:e}}).exec()}},reloadWS:{skipQueue:!0,check:new simpl_schema_1.default({id_ws:String}),function:function(r){var t=this;return new Promise(function(n,e){return __awaiter(t,void 0,void 0,function(){return __generator(this,function(e){return queue_response_collection_1.QueueResponses.create({_id:mongoose_1.Types.ObjectId().toHexString(),__v:0,method:"reloadWSCommand",method_data:[],id_ws:r,messageId:0,id_user:this.id_user,user:this.user,response:{messageId:0,hasError:!1,data:"reloadWSCommand"}}).then(function(e){}),n(),[2]})})})}},reconnectWS:{skipQueue:!0,check:new simpl_schema_1.default({id_ws:String}),function:function(r){var t=this;return new Promise(function(n,e){return __awaiter(t,void 0,void 0,function(){return __generator(this,function(e){return queue_response_collection_1.QueueResponses.create({_id:mongoose_1.Types.ObjectId().toHexString(),__v:0,method:"reconnectWSCommand",method_data:[],id_ws:r,messageId:0,id_user:this.id_user,user:this.user,response:{messageId:0,hasError:!1,data:"reconnectWSCommand"}}),n(),[2]})})})}},disconnectWS:{skipQueue:!0,check:new simpl_schema_1.default({id_ws:String}),function:function(r){var t=this;return new Promise(function(n,e){return __awaiter(t,void 0,void 0,function(){return __generator(this,function(e){return queue_response_collection_1.QueueResponses.create({_id:mongoose_1.Types.ObjectId().toHexString(),__v:0,method:"disconnectWSCommand",method_data:[],id_ws:r,messageId:0,id_user:this.id_user,user:this.user,response:{messageId:0,hasError:!1,data:"disconnectWSCommand"}}),n(),[2]})})})}},createUserAndEmailEnrollment:{check:new simpl_schema_1.default({data:{type:user_collection_1.Users.simplschema}}),function:function(r){var e=this;return new Promise(function(s,i){return __awaiter(e,void 0,void 0,function(){var n,t,o=this;return __generator(this,function(e){switch(e.label){case 0:return n=mongoose_1.Types.ObjectId().toHexString(),[4,user_collection_1.Users.create({_id:n,__v:0,username:r.username,email:r.email,fullname:r.fullname,roles:[],active:!0,readonly:!1,services:{enrollment:jwt.sign({id_user:n},this.serverConfig.JWT_SECRET,{expiresIn:2592e5})},phonenumber:r.phonenumber})];case 1:return(t=e.sent()).setPassword(randomString(20,"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"),function(e,n){t.save();var r={fullname:t.fullname,user:o.user,url:o.serverConfig.ROOT_URL+"/enroll-account?"+encodeURIComponent(o.serverConfig.SERVER_URL)+"&"+t.services.enrollment};o.readFile("email-templates/enrollment.html").then(function(e){var n=handlebars.compile(e);handlebars.registerHelper("equals",function(e,n){return e===n}),o.sendEmail(t.email,"ResolveIO ("+index_1.default.getClientName()+") - Enrollment Email","",n(r)),s(!0)},function(e){return i(e)})}),[2]}})})})}},resetUserPassword:{check:new simpl_schema_1.default({userId:{type:String}}),function:function(n){var e=this;return new Promise(function(s,i){return __awaiter(e,void 0,void 0,function(){var r,t,o=this;return __generator(this,function(e){switch(e.label){case 0:return[4,user_collection_1.Users.findOne({_id:n})];case 1:return(r=e.sent())&&(r.services.forgot_password=jwt.sign({id_user:n},this.serverConfig.JWT_SECRET),t={userToChangePassword:r.fullname,userWhoResetPassword:this.user,url:this.serverConfig.ROOT_URL+"/forgot-password?"+encodeURIComponent(this.serverConfig.SERVER_URL)+"&"+r.services.forgot_password},user_collection_1.Users.updateOne({_id:r._id},{$set:{services:r.services}}).exec(function(e,n){o.readFile("email-templates/forgot-password.html").then(function(e){var n=handlebars.compile(e);handlebars.registerHelper("equals",function(e,n){return e===n}),o.sendEmail(r.email,"ResolveIO ("+index_1.default.getClientName()+") - Forgot Password","",n(t)),s(!0)},function(e){return i(e)})})),[2]}})})})}}})}function randomString(e,n){for(var r="",t=e;0<t;--t)r+=n[Math.floor(Math.random()*n.length)];return r}exports.loadAccountMethods=loadAccountMethods;
|