@resolveio/server-lib 3.2.10 → 3.2.11

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 (177) hide show
  1. package/package.json +26 -26
  2. package/collections/active-subscription.collection.d.ts +0 -7
  3. package/collections/active-subscription.collection.js +0 -68
  4. package/collections/app-status.collection.d.ts +0 -7
  5. package/collections/app-status.collection.js +0 -43
  6. package/collections/app-version.collection.d.ts +0 -7
  7. package/collections/app-version.collection.js +0 -56
  8. package/collections/billing-logged-in-users.collection.d.ts +0 -7
  9. package/collections/billing-logged-in-users.collection.js +0 -73
  10. package/collections/counter.collection.d.ts +0 -9
  11. package/collections/counter.collection.js +0 -73
  12. package/collections/cron-job-history.collection.d.ts +0 -7
  13. package/collections/cron-job-history.collection.js +0 -86
  14. package/collections/cron-job.collection.d.ts +0 -7
  15. package/collections/cron-job.collection.js +0 -89
  16. package/collections/file.collection.d.ts +0 -9
  17. package/collections/file.collection.js +0 -73
  18. package/collections/flag.collection.d.ts +0 -7
  19. package/collections/flag.collection.js +0 -47
  20. package/collections/log.collection.d.ts +0 -7
  21. package/collections/log.collection.js +0 -65
  22. package/collections/logged-in-users.collection.d.ts +0 -7
  23. package/collections/logged-in-users.collection.js +0 -70
  24. package/collections/method-call.collection.d.ts +0 -6
  25. package/collections/method-call.collection.js +0 -44
  26. package/collections/method-response.collection.d.ts +0 -6
  27. package/collections/method-response.collection.js +0 -48
  28. package/collections/notification.collection.d.ts +0 -7
  29. package/collections/notification.collection.js +0 -43
  30. package/collections/queue-flag.collection.d.ts +0 -7
  31. package/collections/queue-flag.collection.js +0 -41
  32. package/collections/queue-method.collection.d.ts +0 -7
  33. package/collections/queue-method.collection.js +0 -119
  34. package/collections/queue-response.collection.d.ts +0 -7
  35. package/collections/queue-response.collection.js +0 -74
  36. package/collections/support-ticket.collection.d.ts +0 -7
  37. package/collections/support-ticket.collection.js +0 -200
  38. package/collections/user.collection.d.ts +0 -9
  39. package/collections/user.collection.js +0 -153
  40. package/cron/cron.d.ts +0 -5
  41. package/cron/cron.js +0 -160
  42. package/fixtures/cron-jobs.d.ts +0 -1
  43. package/fixtures/cron-jobs.js +0 -90
  44. package/fixtures/init.d.ts +0 -1
  45. package/fixtures/init.js +0 -67
  46. package/http/auth.d.ts +0 -2
  47. package/http/auth.js +0 -468
  48. package/http/health.d.ts +0 -1
  49. package/http/health.js +0 -8
  50. package/index.d.ts +0 -16
  51. package/index.js +0 -125
  52. package/managers/cron.manager.d.ts +0 -16
  53. package/managers/cron.manager.js +0 -202
  54. package/managers/database.manager.d.ts +0 -6
  55. package/managers/database.manager.js +0 -12
  56. package/managers/method.manager.d.ts +0 -28
  57. package/managers/method.manager.js +0 -584
  58. package/managers/queue-method.manager.d.ts +0 -13
  59. package/managers/queue-method.manager.js +0 -240
  60. package/managers/subscription.manager.d.ts +0 -28
  61. package/managers/subscription.manager.js +0 -803
  62. package/managers/support.manager.d.ts +0 -22
  63. package/managers/support.manager.js +0 -320
  64. package/methods/accounts.d.ts +0 -2
  65. package/methods/accounts.js +0 -253
  66. package/methods/aws.d.ts +0 -2
  67. package/methods/aws.js +0 -387
  68. package/methods/cloudconvert.d.ts +0 -2
  69. package/methods/cloudconvert.js +0 -37
  70. package/methods/collections.d.ts +0 -2
  71. package/methods/collections.js +0 -750
  72. package/methods/counters.d.ts +0 -2
  73. package/methods/counters.js +0 -107
  74. package/methods/cron-jobs.d.ts +0 -2
  75. package/methods/cron-jobs.js +0 -132
  76. package/methods/flags.d.ts +0 -2
  77. package/methods/flags.js +0 -6
  78. package/methods/logs.d.ts +0 -2
  79. package/methods/logs.js +0 -29
  80. package/methods/pdf.d.ts +0 -2
  81. package/methods/pdf.js +0 -303
  82. package/models/active-subscription.model.d.ts +0 -13
  83. package/models/active-subscription.model.js +0 -2
  84. package/models/app-status.model.d.ts +0 -4
  85. package/models/app-status.model.js +0 -2
  86. package/models/app-version.model.d.ts +0 -4
  87. package/models/app-version.model.js +0 -2
  88. package/models/billing-logged-in-users.model.d.ts +0 -7
  89. package/models/billing-logged-in-users.model.js +0 -2
  90. package/models/collection-document.model.d.ts +0 -6
  91. package/models/collection-document.model.js +0 -2
  92. package/models/counter.model.d.ts +0 -5
  93. package/models/counter.model.js +0 -2
  94. package/models/cron-job-history.model.d.ts +0 -12
  95. package/models/cron-job-history.model.js +0 -2
  96. package/models/cron-job.model.d.ts +0 -13
  97. package/models/cron-job.model.js +0 -2
  98. package/models/dialog.model.d.ts +0 -23
  99. package/models/dialog.model.js +0 -2
  100. package/models/file.model.d.ts +0 -9
  101. package/models/file.model.js +0 -2
  102. package/models/flag.model.d.ts +0 -5
  103. package/models/flag.model.js +0 -2
  104. package/models/log.model.d.ts +0 -11
  105. package/models/log.model.js +0 -2
  106. package/models/logged-in-users.model.d.ts +0 -9
  107. package/models/logged-in-users.model.js +0 -2
  108. package/models/method-call.model.d.ts +0 -7
  109. package/models/method-call.model.js +0 -2
  110. package/models/method-response.model.d.ts +0 -8
  111. package/models/method-response.model.js +0 -2
  112. package/models/method.model.d.ts +0 -10
  113. package/models/method.model.js +0 -2
  114. package/models/notification.model.d.ts +0 -4
  115. package/models/notification.model.js +0 -2
  116. package/models/pagination.model.d.ts +0 -11
  117. package/models/pagination.model.js +0 -20
  118. package/models/permission.model.d.ts +0 -12
  119. package/models/permission.model.js +0 -2
  120. package/models/queue-method.model.d.ts +0 -10
  121. package/models/queue-method.model.js +0 -2
  122. package/models/queue-response.model.d.ts +0 -10
  123. package/models/queue-response.model.js +0 -2
  124. package/models/select-data-label.model.d.ts +0 -9
  125. package/models/select-data-label.model.js +0 -2
  126. package/models/server-response.model.d.ts +0 -5
  127. package/models/server-response.model.js +0 -2
  128. package/models/subscription.model.d.ts +0 -30
  129. package/models/subscription.model.js +0 -2
  130. package/models/support-method.model.d.ts +0 -9
  131. package/models/support-method.model.js +0 -2
  132. package/models/support-ticket.model.d.ts +0 -61
  133. package/models/support-ticket.model.js +0 -2
  134. package/models/user.model.d.ts +0 -14
  135. package/models/user.model.js +0 -2
  136. package/private/email-templates/enrollment.html +0 -12
  137. package/private/email-templates/forgot-password.html +0 -12
  138. package/private/email-templates/support-ticket-deleted.html +0 -40
  139. package/private/email-templates/support-ticket-modified.html +0 -71
  140. package/private/email-templates/support-ticket.html +0 -71
  141. package/private/images/ResolveIO.png +0 -0
  142. package/publications/app-status.d.ts +0 -2
  143. package/publications/app-status.js +0 -14
  144. package/publications/app-version.d.ts +0 -2
  145. package/publications/app-version.js +0 -14
  146. package/publications/billing-logged-in-users.d.ts +0 -1
  147. package/publications/billing-logged-in-users.js +0 -63
  148. package/publications/cron-jobs.d.ts +0 -2
  149. package/publications/cron-jobs.js +0 -14
  150. package/publications/files.d.ts +0 -2
  151. package/publications/files.js +0 -71
  152. package/publications/flags.d.ts +0 -2
  153. package/publications/flags.js +0 -23
  154. package/publications/logs.d.ts +0 -2
  155. package/publications/logs.js +0 -26
  156. package/publications/method-calls.d.ts +0 -2
  157. package/publications/method-calls.js +0 -14
  158. package/publications/method-responses.d.ts +0 -2
  159. package/publications/method-responses.js +0 -14
  160. package/publications/notifications.d.ts +0 -2
  161. package/publications/notifications.js +0 -14
  162. package/publications/super-admin.d.ts +0 -2
  163. package/publications/super-admin.js +0 -21
  164. package/publications/support-tickets.d.ts +0 -1
  165. package/publications/support-tickets.js +0 -200
  166. package/server-app.d.ts +0 -35
  167. package/server-app.js +0 -636
  168. package/support-methods/aws.d.ts +0 -2
  169. package/support-methods/aws.js +0 -276
  170. package/support-methods/collections.d.ts +0 -2
  171. package/support-methods/collections.js +0 -471
  172. package/support-methods/counters.d.ts +0 -2
  173. package/support-methods/counters.js +0 -189
  174. package/support-methods/support.d.ts +0 -2
  175. package/support-methods/support.js +0 -236
  176. package/util/common.d.ts +0 -14
  177. package/util/common.js +0 -341
@@ -1,22 +0,0 @@
1
- import { SupportMethodModel } from '../models/support-method.model';
2
- import ResolveIOMainServer from '../server-app';
3
- export declare class SupportManager {
4
- private _mainServer;
5
- _supportMethods: SupportMethodModel;
6
- private _mailer;
7
- private _aws;
8
- private serverConfig;
9
- private clientDir;
10
- private _sendQueue;
11
- private _runningQueue;
12
- constructor(mainServer: any, serverConfig: any, clientDir: any);
13
- getMainServer(): ResolveIOMainServer;
14
- supportMethods(supportMethod: SupportMethodModel): void;
15
- callSupportMethod(ws: WebSocket, messageId: any, supportMethod: any, ...methodData: any[]): void;
16
- callSupportMethodInternal(supportMethod: any, ...methodData: any[]): Promise<any>;
17
- callMethodInternal(method: any, ...methodData: any[]): Promise<any>;
18
- private sendWS;
19
- sendEmail(sendTo: string, subject: string, text?: string, html?: string, attachments?: any[]): void;
20
- readFile(fileName: any): Promise<{}>;
21
- readImage(fileName: any): Promise<{}>;
22
- }
@@ -1,320 +0,0 @@
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 method_manager_1 = require("./method.manager");
12
- var path = require("path");
13
- var fs = require("fs");
14
- var SupportManager = /** @class */ (function () {
15
- function SupportManager(mainServer, serverConfig, clientDir) {
16
- var _this = this;
17
- this._supportMethods = {};
18
- this._sendQueue = [];
19
- this._runningQueue = false;
20
- this._mainServer = mainServer;
21
- this.serverConfig = serverConfig;
22
- this.clientDir = clientDir;
23
- collections_1.loadSupportCollectionMethods(this);
24
- support_1.loadSupportMethods(this);
25
- counters_1.loadCounterMethods(this);
26
- this._mailer = nodemailer.createTransport({
27
- SES: new aws.SES({
28
- apiVersion: '2010-12-01',
29
- accessKeyId: serverConfig.AWSACCESSKEYID,
30
- secretAccessKey: serverConfig.AWSSECRETACCESSKEY,
31
- region: serverConfig.AWSSES_REGION
32
- })
33
- });
34
- this._aws = new aws.S3({
35
- accessKeyId: serverConfig.AWSACCESSKEYID,
36
- secretAccessKey: serverConfig.AWSSECRETACCESSKEY,
37
- region: serverConfig.AWSREGION
38
- });
39
- setInterval(function () {
40
- if (!_this._runningQueue) {
41
- if (_this._sendQueue.length) {
42
- _this._runningQueue = true;
43
- var _loop_1 = function (i) {
44
- var ws = _this._mainServer.getWS(_this._sendQueue[i].id_ws);
45
- if (ws && ws.readyState === ws.OPEN) {
46
- if (ws.bufferedAmount < 20480) {
47
- var sendItem = _this._sendQueue.pop();
48
- ws.send(JSON.stringify(sendItem.data), function (error) {
49
- if (error) {
50
- console.log('Error on WS: ', error);
51
- _this._mainServer.unsubscribeWS(ws);
52
- }
53
- });
54
- // if (sendItem.method !== 'countQuery' && sendItem.method !== 'countCollectionWithQuery' && sendItem.method !== 'find' && sendItem.method !== 'findOne' && sendItem.method !== 'findWithOptions' && sendItem.method !== 'setWSAppVersion' && sendItem.method !== 'uploadFileAndSave') {
55
- if (common_1.getBinarySize(JSON.stringify(sendItem.methodData)) < 200000 && common_1.getBinarySize(JSON.stringify(sendItem.data)) < 200000) {
56
- log_collection_1.Logs.create({
57
- _id: mongoose_1.Types.ObjectId().toHexString(),
58
- date: new Date(),
59
- type: 'client-response',
60
- title: 'Client Response - Support',
61
- message: 'User: ' + ws['user'] + ', MessageId: ' + sendItem.data.messageId + ', Support Method: ' + sendItem.method,
62
- payload: JSON.stringify([sendItem.methodData, sendItem.data]),
63
- method: sendItem.method,
64
- user: ws['user'],
65
- messageId: sendItem.data.messageId
66
- });
67
- }
68
- else {
69
- log_collection_1.Logs.create({
70
- _id: mongoose_1.Types.ObjectId().toHexString(),
71
- date: new Date(),
72
- type: 'client-response',
73
- title: 'Client Response - Support',
74
- message: 'User: ' + ws['user'] + ', MessageId: ' + sendItem.data.messageId + ', Support Method: ' + sendItem.method,
75
- payload: 'Too Big',
76
- method: sendItem.method,
77
- user: ws['user'],
78
- messageId: sendItem.data.messageId
79
- });
80
- }
81
- // }
82
- }
83
- }
84
- else {
85
- _this._sendQueue.splice(i, 1);
86
- }
87
- };
88
- for (var i = _this._sendQueue.length - 1; i >= 0; i--) {
89
- _loop_1(i);
90
- }
91
- _this._runningQueue = false;
92
- }
93
- }
94
- }, 25);
95
- }
96
- SupportManager.prototype.getMainServer = function () {
97
- return this._mainServer;
98
- };
99
- // Add methods to private methods object
100
- SupportManager.prototype.supportMethods = function (supportMethod) {
101
- this._supportMethods = Object.assign(this._supportMethods, supportMethod);
102
- };
103
- // Call/run method (Emit on Socket)
104
- SupportManager.prototype.callSupportMethod = function (ws, messageId, supportMethod) {
105
- var _this = this;
106
- var methodData = [];
107
- for (var _i = 3; _i < arguments.length; _i++) {
108
- methodData[_i - 3] = arguments[_i];
109
- }
110
- var _a;
111
- var that = this;
112
- if (!that._supportMethods[supportMethod]) {
113
- console.log('No Support Method: ' + supportMethod);
114
- that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Support Method: ' + supportMethod);
115
- var serverRes = {
116
- messageId: messageId,
117
- hasError: true,
118
- data: 'Internal Error'
119
- };
120
- this.sendWS(ws, supportMethod, methodData, serverRes);
121
- return;
122
- }
123
- if ((methodData.length > 1 || methodData[0])) {
124
- if (!that._supportMethods[supportMethod].check) {
125
- console.error('No Check Function For Support Method ' + supportMethod);
126
- that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Support Method ' + supportMethod);
127
- var serverRes = {
128
- messageId: messageId,
129
- hasError: true,
130
- data: 'Internal Error'
131
- };
132
- this.sendWS(ws, supportMethod, methodData, serverRes);
133
- return;
134
- }
135
- else if (!that._supportMethods[supportMethod].check._schema) {
136
- console.error('No Check Schema For Method ' + supportMethod);
137
- that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Support Method ' + supportMethod);
138
- var serverRes = {
139
- messageId: messageId,
140
- hasError: true,
141
- data: 'Internal Error'
142
- };
143
- this.sendWS(ws, supportMethod, methodData, serverRes);
144
- return;
145
- }
146
- else {
147
- var valObj = {};
148
- var valKeys = Object.keys(that._supportMethods[supportMethod].check._schema);
149
- var rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
150
- for (var i = 0; i < methodData.length; i++) {
151
- valObj[rootKeys[i]] = methodData[i];
152
- }
153
- try {
154
- that._supportMethods[supportMethod].check.validate(valObj);
155
- }
156
- catch (errors) {
157
- if (errors) {
158
- console.error('Error in Support Method Check (' + supportMethod + ')', errors);
159
- 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));
160
- var serverRes = {
161
- messageId: messageId,
162
- hasError: true,
163
- data: 'Internal Error'
164
- };
165
- this.sendWS(ws, supportMethod, methodData, serverRes);
166
- return;
167
- }
168
- }
169
- }
170
- }
171
- (_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) {
172
- var serverRes = {
173
- messageId: messageId,
174
- hasError: false,
175
- data: res
176
- };
177
- _this.sendWS(ws, supportMethod, methodData, serverRes);
178
- }, function (err) {
179
- var serverRes = {
180
- messageId: messageId,
181
- hasError: true,
182
- data: err
183
- };
184
- _this.sendWS(ws, supportMethod, methodData, serverRes);
185
- });
186
- };
187
- SupportManager.prototype.callSupportMethodInternal = function (supportMethod) {
188
- var methodData = [];
189
- for (var _i = 1; _i < arguments.length; _i++) {
190
- methodData[_i - 1] = arguments[_i];
191
- }
192
- var _a;
193
- var that = this;
194
- if (!that._supportMethods[supportMethod]) {
195
- console.log('No Support Method: ' + supportMethod);
196
- return;
197
- }
198
- if ((methodData.length > 1 || (methodData[0] && typeof (methodData[0]) !== 'function')) && !that._supportMethods[supportMethod].skipValidation) {
199
- if (!that._supportMethods[supportMethod].check) {
200
- console.error('No Check Function For Method ' + supportMethod);
201
- return;
202
- }
203
- else if (!that._supportMethods[supportMethod].check._schema) {
204
- console.error('No Check Schema For Method ' + supportMethod);
205
- return;
206
- }
207
- }
208
- var promise = (_a = that._supportMethods[supportMethod].function).call.apply(_a, [Object.assign({}, that, SupportManager.prototype)].concat(methodData));
209
- if (methodData[methodData.length - 1] && typeof (methodData[methodData.length - 1]) === 'function') {
210
- promise.then(function (res) { return methodData[methodData.length - 1](null, res); }, function (err) { return methodData[methodData.length - 1](err, null); });
211
- }
212
- return promise;
213
- };
214
- SupportManager.prototype.callMethodInternal = function (method) {
215
- var methodData = [];
216
- for (var _i = 1; _i < arguments.length; _i++) {
217
- methodData[_i - 1] = arguments[_i];
218
- }
219
- var _a;
220
- var that = this;
221
- if (!that._mainServer.getMethodManager()._methods[method]) {
222
- console.log('No Method: ' + method);
223
- return;
224
- }
225
- if ((methodData.length > 1 || (methodData[0] && typeof (methodData[0]) !== 'function')) && !that._mainServer.getMethodManager()._methods[method].skipValidation) {
226
- if (!that._mainServer.getMethodManager()._methods[method].check) {
227
- console.error('No Check Function For Method ' + method);
228
- return;
229
- }
230
- else if (!that._mainServer.getMethodManager()._methods[method].check._schema) {
231
- console.error('No Check Schema For Method ' + method);
232
- return;
233
- }
234
- }
235
- var promise = (_a = that._mainServer.getMethodManager()._methods[method].function).call.apply(_a, [Object.assign({}, that, method_manager_1.MethodManager.prototype)].concat(methodData));
236
- if (methodData[methodData.length - 1] && typeof (methodData[methodData.length - 1]) === 'function') {
237
- promise.then(function (res) { return methodData[methodData.length - 1](null, res); }, function (err) { return methodData[methodData.length - 1](err, null); });
238
- }
239
- return promise;
240
- };
241
- SupportManager.prototype.sendWS = function (ws, method, methodData, data) {
242
- this._sendQueue.splice(0, 0, {
243
- id_ws: ws['id_socket'],
244
- method: method,
245
- methodData: methodData,
246
- data: data
247
- });
248
- };
249
- SupportManager.prototype.sendEmail = function (sendTo, subject, text, html, attachments) {
250
- this._mailer.sendMail({
251
- replyTo: undefined,
252
- from: this.serverConfig.MAIL_FROM,
253
- to: sendTo,
254
- subject: subject,
255
- text: text,
256
- html: html,
257
- attachments: attachments
258
- }, function (err, info) {
259
- if (err) {
260
- console.log(err);
261
- }
262
- });
263
- };
264
- SupportManager.prototype.readFile = function (fileName) {
265
- var _this = this;
266
- return new Promise(function (resolve, reject) {
267
- if (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {
268
- fs.readFile(path.join(__dirname, ('../private/' + fileName)), 'utf-8', function (err, res) {
269
- if (err) {
270
- reject(err);
271
- }
272
- else {
273
- resolve(res);
274
- }
275
- });
276
- }
277
- else {
278
- if (fs.existsSync(path.join(_this.clientDir, ('./private/' + fileName)))) {
279
- fs.readFile(path.join(_this.clientDir, ('./private/' + fileName)), 'utf-8', function (err, res) {
280
- if (err) {
281
- reject(err);
282
- }
283
- else {
284
- resolve(res);
285
- }
286
- });
287
- }
288
- }
289
- });
290
- };
291
- SupportManager.prototype.readImage = function (fileName) {
292
- var _this = this;
293
- return new Promise(function (resolve, reject) {
294
- if (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {
295
- fs.readFile(path.join(__dirname, ('../private/' + fileName)), 'base64', function (err, res) {
296
- if (err) {
297
- reject(err);
298
- }
299
- else {
300
- resolve(res);
301
- }
302
- });
303
- }
304
- else {
305
- if (fs.existsSync(path.join(_this.clientDir, ('./private/' + fileName)))) {
306
- fs.readFile(path.join(_this.clientDir, ('./private/' + fileName)), 'base64', function (err, res) {
307
- if (err) {
308
- reject(err);
309
- }
310
- else {
311
- resolve(res);
312
- }
313
- });
314
- }
315
- }
316
- });
317
- };
318
- return SupportManager;
319
- }());
320
- exports.SupportManager = SupportManager;
@@ -1,2 +0,0 @@
1
- import { MethodManager } from '../managers/method.manager';
2
- export declare function loadAccountMethods(methodManager: MethodManager): void;
@@ -1,253 +0,0 @@
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: data.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
- }
package/methods/aws.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { MethodManager } from '../managers/method.manager';
2
- export declare function loadAWSMethods(methodManager: MethodManager): void;