@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.
- package/package.json +26 -26
- package/collections/active-subscription.collection.d.ts +0 -7
- package/collections/active-subscription.collection.js +0 -68
- package/collections/app-status.collection.d.ts +0 -7
- package/collections/app-status.collection.js +0 -43
- package/collections/app-version.collection.d.ts +0 -7
- package/collections/app-version.collection.js +0 -56
- package/collections/billing-logged-in-users.collection.d.ts +0 -7
- package/collections/billing-logged-in-users.collection.js +0 -73
- package/collections/counter.collection.d.ts +0 -9
- package/collections/counter.collection.js +0 -73
- package/collections/cron-job-history.collection.d.ts +0 -7
- package/collections/cron-job-history.collection.js +0 -86
- package/collections/cron-job.collection.d.ts +0 -7
- package/collections/cron-job.collection.js +0 -89
- package/collections/file.collection.d.ts +0 -9
- package/collections/file.collection.js +0 -73
- package/collections/flag.collection.d.ts +0 -7
- package/collections/flag.collection.js +0 -47
- package/collections/log.collection.d.ts +0 -7
- package/collections/log.collection.js +0 -65
- package/collections/logged-in-users.collection.d.ts +0 -7
- package/collections/logged-in-users.collection.js +0 -70
- package/collections/method-call.collection.d.ts +0 -6
- package/collections/method-call.collection.js +0 -44
- package/collections/method-response.collection.d.ts +0 -6
- package/collections/method-response.collection.js +0 -48
- package/collections/notification.collection.d.ts +0 -7
- package/collections/notification.collection.js +0 -43
- package/collections/queue-flag.collection.d.ts +0 -7
- package/collections/queue-flag.collection.js +0 -41
- package/collections/queue-method.collection.d.ts +0 -7
- package/collections/queue-method.collection.js +0 -119
- package/collections/queue-response.collection.d.ts +0 -7
- package/collections/queue-response.collection.js +0 -74
- package/collections/support-ticket.collection.d.ts +0 -7
- package/collections/support-ticket.collection.js +0 -200
- package/collections/user.collection.d.ts +0 -9
- package/collections/user.collection.js +0 -153
- package/cron/cron.d.ts +0 -5
- package/cron/cron.js +0 -160
- package/fixtures/cron-jobs.d.ts +0 -1
- package/fixtures/cron-jobs.js +0 -90
- package/fixtures/init.d.ts +0 -1
- package/fixtures/init.js +0 -67
- package/http/auth.d.ts +0 -2
- package/http/auth.js +0 -468
- package/http/health.d.ts +0 -1
- package/http/health.js +0 -8
- package/index.d.ts +0 -16
- package/index.js +0 -125
- package/managers/cron.manager.d.ts +0 -16
- package/managers/cron.manager.js +0 -202
- package/managers/database.manager.d.ts +0 -6
- package/managers/database.manager.js +0 -12
- package/managers/method.manager.d.ts +0 -28
- package/managers/method.manager.js +0 -584
- package/managers/queue-method.manager.d.ts +0 -13
- package/managers/queue-method.manager.js +0 -240
- package/managers/subscription.manager.d.ts +0 -28
- package/managers/subscription.manager.js +0 -803
- package/managers/support.manager.d.ts +0 -22
- package/managers/support.manager.js +0 -320
- package/methods/accounts.d.ts +0 -2
- package/methods/accounts.js +0 -253
- package/methods/aws.d.ts +0 -2
- package/methods/aws.js +0 -387
- package/methods/cloudconvert.d.ts +0 -2
- package/methods/cloudconvert.js +0 -37
- package/methods/collections.d.ts +0 -2
- package/methods/collections.js +0 -750
- package/methods/counters.d.ts +0 -2
- package/methods/counters.js +0 -107
- package/methods/cron-jobs.d.ts +0 -2
- package/methods/cron-jobs.js +0 -132
- package/methods/flags.d.ts +0 -2
- package/methods/flags.js +0 -6
- package/methods/logs.d.ts +0 -2
- package/methods/logs.js +0 -29
- package/methods/pdf.d.ts +0 -2
- package/methods/pdf.js +0 -303
- package/models/active-subscription.model.d.ts +0 -13
- package/models/active-subscription.model.js +0 -2
- package/models/app-status.model.d.ts +0 -4
- package/models/app-status.model.js +0 -2
- package/models/app-version.model.d.ts +0 -4
- package/models/app-version.model.js +0 -2
- package/models/billing-logged-in-users.model.d.ts +0 -7
- package/models/billing-logged-in-users.model.js +0 -2
- package/models/collection-document.model.d.ts +0 -6
- package/models/collection-document.model.js +0 -2
- package/models/counter.model.d.ts +0 -5
- package/models/counter.model.js +0 -2
- package/models/cron-job-history.model.d.ts +0 -12
- package/models/cron-job-history.model.js +0 -2
- package/models/cron-job.model.d.ts +0 -13
- package/models/cron-job.model.js +0 -2
- package/models/dialog.model.d.ts +0 -23
- package/models/dialog.model.js +0 -2
- package/models/file.model.d.ts +0 -9
- package/models/file.model.js +0 -2
- package/models/flag.model.d.ts +0 -5
- package/models/flag.model.js +0 -2
- package/models/log.model.d.ts +0 -11
- package/models/log.model.js +0 -2
- package/models/logged-in-users.model.d.ts +0 -9
- package/models/logged-in-users.model.js +0 -2
- package/models/method-call.model.d.ts +0 -7
- package/models/method-call.model.js +0 -2
- package/models/method-response.model.d.ts +0 -8
- package/models/method-response.model.js +0 -2
- package/models/method.model.d.ts +0 -10
- package/models/method.model.js +0 -2
- package/models/notification.model.d.ts +0 -4
- package/models/notification.model.js +0 -2
- package/models/pagination.model.d.ts +0 -11
- package/models/pagination.model.js +0 -20
- package/models/permission.model.d.ts +0 -12
- package/models/permission.model.js +0 -2
- package/models/queue-method.model.d.ts +0 -10
- package/models/queue-method.model.js +0 -2
- package/models/queue-response.model.d.ts +0 -10
- package/models/queue-response.model.js +0 -2
- package/models/select-data-label.model.d.ts +0 -9
- package/models/select-data-label.model.js +0 -2
- package/models/server-response.model.d.ts +0 -5
- package/models/server-response.model.js +0 -2
- package/models/subscription.model.d.ts +0 -30
- package/models/subscription.model.js +0 -2
- package/models/support-method.model.d.ts +0 -9
- package/models/support-method.model.js +0 -2
- package/models/support-ticket.model.d.ts +0 -61
- package/models/support-ticket.model.js +0 -2
- package/models/user.model.d.ts +0 -14
- package/models/user.model.js +0 -2
- package/private/email-templates/enrollment.html +0 -12
- package/private/email-templates/forgot-password.html +0 -12
- package/private/email-templates/support-ticket-deleted.html +0 -40
- package/private/email-templates/support-ticket-modified.html +0 -71
- package/private/email-templates/support-ticket.html +0 -71
- package/private/images/ResolveIO.png +0 -0
- package/publications/app-status.d.ts +0 -2
- package/publications/app-status.js +0 -14
- package/publications/app-version.d.ts +0 -2
- package/publications/app-version.js +0 -14
- package/publications/billing-logged-in-users.d.ts +0 -1
- package/publications/billing-logged-in-users.js +0 -63
- package/publications/cron-jobs.d.ts +0 -2
- package/publications/cron-jobs.js +0 -14
- package/publications/files.d.ts +0 -2
- package/publications/files.js +0 -71
- package/publications/flags.d.ts +0 -2
- package/publications/flags.js +0 -23
- package/publications/logs.d.ts +0 -2
- package/publications/logs.js +0 -26
- package/publications/method-calls.d.ts +0 -2
- package/publications/method-calls.js +0 -14
- package/publications/method-responses.d.ts +0 -2
- package/publications/method-responses.js +0 -14
- package/publications/notifications.d.ts +0 -2
- package/publications/notifications.js +0 -14
- package/publications/super-admin.d.ts +0 -2
- package/publications/super-admin.js +0 -21
- package/publications/support-tickets.d.ts +0 -1
- package/publications/support-tickets.js +0 -200
- package/server-app.d.ts +0 -35
- package/server-app.js +0 -636
- package/support-methods/aws.d.ts +0 -2
- package/support-methods/aws.js +0 -276
- package/support-methods/collections.d.ts +0 -2
- package/support-methods/collections.js +0 -471
- package/support-methods/counters.d.ts +0 -2
- package/support-methods/counters.js +0 -189
- package/support-methods/support.d.ts +0 -2
- package/support-methods/support.js +0 -236
- package/util/common.d.ts +0 -14
- package/util/common.js +0 -341
|
@@ -1,236 +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 file_collection_1 = require("../collections/file.collection");
|
|
40
|
-
var handlebars = require("handlebars");
|
|
41
|
-
function loadSupportMethods(supportManager) {
|
|
42
|
-
supportManager.supportMethods({
|
|
43
|
-
sendSupportTicketEmail: {
|
|
44
|
-
check: new simpl_schema_1.default({
|
|
45
|
-
supportTicket: {
|
|
46
|
-
type: Object,
|
|
47
|
-
blackbox: true
|
|
48
|
-
},
|
|
49
|
-
id_files: {
|
|
50
|
-
type: Array
|
|
51
|
-
},
|
|
52
|
-
'id_files.$': {
|
|
53
|
-
type: String
|
|
54
|
-
}
|
|
55
|
-
}),
|
|
56
|
-
function: function (supportTicket, id_files) {
|
|
57
|
-
var _this = this;
|
|
58
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
59
|
-
var files;
|
|
60
|
-
var _this = this;
|
|
61
|
-
return __generator(this, function (_a) {
|
|
62
|
-
switch (_a.label) {
|
|
63
|
-
case 0: return [4 /*yield*/, file_collection_1.Files.find({
|
|
64
|
-
_id: { $in: id_files }
|
|
65
|
-
})];
|
|
66
|
-
case 1:
|
|
67
|
-
files = _a.sent();
|
|
68
|
-
this.callMethodInternal.call(this, 'getSignedUrls', files.map(function (a) { return a.key; }), 900, function (err, res) {
|
|
69
|
-
if (res) {
|
|
70
|
-
_this.readFile('email-templates/support-ticket.html').then(function (html) { return __awaiter(_this, void 0, void 0, function () {
|
|
71
|
-
var template, filesAttached, fileCnt;
|
|
72
|
-
var _this = this;
|
|
73
|
-
return __generator(this, function (_a) {
|
|
74
|
-
template = handlebars.compile(html);
|
|
75
|
-
handlebars.registerHelper('greaterThan', function (a, b) {
|
|
76
|
-
return a > b;
|
|
77
|
-
});
|
|
78
|
-
handlebars.registerHelper('equals', function (a, b) {
|
|
79
|
-
return a === b;
|
|
80
|
-
});
|
|
81
|
-
filesAttached = [];
|
|
82
|
-
fileCnt = 0;
|
|
83
|
-
res.forEach(function (url) {
|
|
84
|
-
filesAttached.push({ filename: files[fileCnt].name, path: url });
|
|
85
|
-
fileCnt++;
|
|
86
|
-
});
|
|
87
|
-
this.readImage('images/ResolveIO.png').then(function (logoData) {
|
|
88
|
-
supportTicket['logo'] = 'data:image/png;base64,' + logoData;
|
|
89
|
-
if (supportTicket.client_user && supportTicket.client_user.email) {
|
|
90
|
-
supportTicket['user'] = supportTicket.client_user.user;
|
|
91
|
-
supportTicket['fileAttached'] = filesAttached;
|
|
92
|
-
_this.sendEmail(supportTicket.client_user.email, 'ResolveIO - ' + supportTicket.support_ticket_number_string + ' Priority: ' + supportTicket.priority, '', template(supportTicket), filesAttached);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
resolve(true);
|
|
96
|
-
return [2 /*return*/];
|
|
97
|
-
});
|
|
98
|
-
}); });
|
|
99
|
-
resolve(true);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
_this.callMethodInternal.call(_this, 'insertErrorLog', 'supportTicketsmethod - getsignedurl', [
|
|
103
|
-
files.map(function (a) { return a.key; }), err
|
|
104
|
-
]);
|
|
105
|
-
reject(err);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
return [2 /*return*/];
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}); });
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
sendSupportTicketModifiedEmail: {
|
|
115
|
-
check: new simpl_schema_1.default({
|
|
116
|
-
supportTicket: {
|
|
117
|
-
type: Object,
|
|
118
|
-
blackbox: true
|
|
119
|
-
},
|
|
120
|
-
id_files: {
|
|
121
|
-
type: Array
|
|
122
|
-
},
|
|
123
|
-
'id_files.$': {
|
|
124
|
-
type: String
|
|
125
|
-
}
|
|
126
|
-
}),
|
|
127
|
-
function: function (supportTicket, id_files) {
|
|
128
|
-
var _this = this;
|
|
129
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
130
|
-
var files;
|
|
131
|
-
var _this = this;
|
|
132
|
-
return __generator(this, function (_a) {
|
|
133
|
-
switch (_a.label) {
|
|
134
|
-
case 0: return [4 /*yield*/, file_collection_1.Files.find({
|
|
135
|
-
_id: { $in: id_files }
|
|
136
|
-
})];
|
|
137
|
-
case 1:
|
|
138
|
-
files = _a.sent();
|
|
139
|
-
this.callMethodInternal.call(this, 'getSignedUrls', files.map(function (a) { return a.key; }), 900, function (err, res) {
|
|
140
|
-
if (res) {
|
|
141
|
-
_this.readFile('email-templates/support-ticket-modified.html').then(function (html) { return __awaiter(_this, void 0, void 0, function () {
|
|
142
|
-
var template, filesAttached, fileCnt;
|
|
143
|
-
var _this = this;
|
|
144
|
-
return __generator(this, function (_a) {
|
|
145
|
-
template = handlebars.compile(html);
|
|
146
|
-
handlebars.registerHelper('greaterThan', function (a, b) {
|
|
147
|
-
return a > b;
|
|
148
|
-
});
|
|
149
|
-
handlebars.registerHelper('equals', function (a, b) {
|
|
150
|
-
return a === b;
|
|
151
|
-
});
|
|
152
|
-
filesAttached = [];
|
|
153
|
-
fileCnt = 0;
|
|
154
|
-
res.forEach(function (url) {
|
|
155
|
-
filesAttached.push({ filename: files[fileCnt].name, path: url });
|
|
156
|
-
fileCnt++;
|
|
157
|
-
});
|
|
158
|
-
this.readImage('images/ResolveIO.png').then(function (logoData) {
|
|
159
|
-
supportTicket['logo'] = 'data:image/png;base64,' + logoData;
|
|
160
|
-
supportTicket.current_watchers.forEach(function (user) {
|
|
161
|
-
supportTicket['user'] = user.user;
|
|
162
|
-
supportTicket['fileAttached'] = filesAttached;
|
|
163
|
-
_this.sendEmail(user.email, 'ResolveIO - a ticket has been modified: ' + supportTicket.support_ticket_number_string + ' Priority: ' + supportTicket.priority, '', template(supportTicket), filesAttached);
|
|
164
|
-
});
|
|
165
|
-
if (supportTicket.client_user && supportTicket.client_user.email) {
|
|
166
|
-
supportTicket['user'] = supportTicket.client_user.user;
|
|
167
|
-
supportTicket['fileAttached'] = filesAttached;
|
|
168
|
-
_this.sendEmail(supportTicket.client_user.email, 'ResolveIO - ' + supportTicket.support_ticket_number_string + ' Priority: ' + supportTicket.priority, '', template(supportTicket), filesAttached);
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
resolve(true);
|
|
172
|
-
return [2 /*return*/];
|
|
173
|
-
});
|
|
174
|
-
}); });
|
|
175
|
-
resolve(true);
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
_this.callMethodInternal.call(_this, 'insertErrorLog', 'supportTicketsmethod - getsignedurl', [
|
|
179
|
-
files.map(function (a) { return a.key; }), err
|
|
180
|
-
]);
|
|
181
|
-
reject(err);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
return [2 /*return*/];
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}); });
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
sendSupportTicketDeletedEmail: {
|
|
191
|
-
check: new simpl_schema_1.default({
|
|
192
|
-
supportTicket: {
|
|
193
|
-
type: Object,
|
|
194
|
-
blackbox: true
|
|
195
|
-
}
|
|
196
|
-
}),
|
|
197
|
-
function: function (supportTicket) {
|
|
198
|
-
var _this = this;
|
|
199
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
200
|
-
var _this = this;
|
|
201
|
-
return __generator(this, function (_a) {
|
|
202
|
-
this.callMethodInternal.call(this, 'getSignedUrls', [], 900, function (err, res) {
|
|
203
|
-
if (res) {
|
|
204
|
-
_this.readFile('email-templates/support-ticket-deleted.html').then(function (html) { return __awaiter(_this, void 0, void 0, function () {
|
|
205
|
-
var template;
|
|
206
|
-
return __generator(this, function (_a) {
|
|
207
|
-
template = handlebars.compile(html);
|
|
208
|
-
handlebars.registerHelper('greaterThan', function (a, b) {
|
|
209
|
-
return a > b;
|
|
210
|
-
});
|
|
211
|
-
handlebars.registerHelper('equals', function (a, b) {
|
|
212
|
-
return a === b;
|
|
213
|
-
});
|
|
214
|
-
if (supportTicket.client_user && supportTicket.client_user.email) {
|
|
215
|
-
this.sendEmail(supportTicket.client_user.email, 'ResolveIO - ' + supportTicket.support_ticket_number_string + ' Priority: ' + supportTicket.priority, '', template(supportTicket), []);
|
|
216
|
-
}
|
|
217
|
-
return [2 /*return*/];
|
|
218
|
-
});
|
|
219
|
-
}); });
|
|
220
|
-
resolve(true);
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
_this.callMethodInternal.call(_this, 'insertErrorLog', 'supportTicketsmethod - getsignedurl', [
|
|
224
|
-
[], err
|
|
225
|
-
]);
|
|
226
|
-
reject(err);
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
return [2 /*return*/];
|
|
230
|
-
});
|
|
231
|
-
}); });
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
exports.loadSupportMethods = loadSupportMethods;
|
package/util/common.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare function deepCopy(obj: any): any;
|
|
2
|
-
export declare function dateReviver(key: any, value: any): any;
|
|
3
|
-
export declare function getMongoUpdates(currDoc: any, modifiedDoc: any, incVersion: any): any;
|
|
4
|
-
export declare function getMongoMergeUpdatedDoc(f_doc: any, currentDoc: any, oldDoc: any): any;
|
|
5
|
-
export declare function mergeUpdates(...updatesToMerge: any[]): {
|
|
6
|
-
$set: {};
|
|
7
|
-
$unset: {};
|
|
8
|
-
$inc: {};
|
|
9
|
-
$push: {};
|
|
10
|
-
$pull: {};
|
|
11
|
-
};
|
|
12
|
-
export declare function getDeepDiff(doc1: any, doc2: any): any;
|
|
13
|
-
export declare function applyMongoUpdate(uDoc: any, delta: any): any;
|
|
14
|
-
export declare function getBinarySize(string: any): number;
|
package/util/common.js
DELETED
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var rusDiff = require('rus-diff');
|
|
4
|
-
var deepDiff = require('deep-diff').diff;
|
|
5
|
-
function deepCopy(obj) {
|
|
6
|
-
return JSON.parse(JSON.stringify(obj), dateReviver);
|
|
7
|
-
}
|
|
8
|
-
exports.deepCopy = deepCopy;
|
|
9
|
-
function dateReviver(key, value) {
|
|
10
|
-
if (typeof value === 'string') {
|
|
11
|
-
var a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
|
12
|
-
if (a) {
|
|
13
|
-
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6].split('.')[0], +a[6].split('.')[1]));
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return value;
|
|
17
|
-
}
|
|
18
|
-
exports.dateReviver = dateReviver;
|
|
19
|
-
function getMongoUpdates(currDoc, modifiedDoc, incVersion) {
|
|
20
|
-
if (currDoc.createdAt) {
|
|
21
|
-
modifiedDoc.createdAt = currDoc.createdAt;
|
|
22
|
-
}
|
|
23
|
-
if (currDoc.updatedAt) {
|
|
24
|
-
modifiedDoc.updatedAt = currDoc.updatedAt;
|
|
25
|
-
}
|
|
26
|
-
var updates = rusDiff.diff(currDoc, modifiedDoc);
|
|
27
|
-
if (updates) {
|
|
28
|
-
if (updates.$set && !Object.keys(updates.$set).length) {
|
|
29
|
-
delete updates.$set;
|
|
30
|
-
}
|
|
31
|
-
if (incVersion) {
|
|
32
|
-
updates.$inc = { __v: 1 };
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
if (incVersion) {
|
|
37
|
-
updates = {
|
|
38
|
-
$inc: { __v: 1 }
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return updates;
|
|
43
|
-
}
|
|
44
|
-
exports.getMongoUpdates = getMongoUpdates;
|
|
45
|
-
function getMongoMergeUpdatedDoc(f_doc, currentDoc, oldDoc) {
|
|
46
|
-
var upDoc = deepCopy(oldDoc);
|
|
47
|
-
upDoc.__v = currentDoc.__v;
|
|
48
|
-
var diff_1 = getDeepDiff(oldDoc, currentDoc);
|
|
49
|
-
var diff_2 = getDeepDiff(oldDoc, f_doc);
|
|
50
|
-
var updates = mergeUpdates(diff_2, diff_1);
|
|
51
|
-
applyMongoUpdate(upDoc, updates);
|
|
52
|
-
return upDoc;
|
|
53
|
-
}
|
|
54
|
-
exports.getMongoMergeUpdatedDoc = getMongoMergeUpdatedDoc;
|
|
55
|
-
function mergeUpdates() {
|
|
56
|
-
var updatesToMerge = [];
|
|
57
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
58
|
-
updatesToMerge[_i] = arguments[_i];
|
|
59
|
-
}
|
|
60
|
-
var merged = {
|
|
61
|
-
$set: {},
|
|
62
|
-
$unset: {},
|
|
63
|
-
$inc: {},
|
|
64
|
-
$push: {},
|
|
65
|
-
$pull: {}
|
|
66
|
-
};
|
|
67
|
-
updatesToMerge.filter(function (a) { return a; }).forEach(function (anUpdate) {
|
|
68
|
-
anUpdate.forEach(function (change) {
|
|
69
|
-
var path = change.path[0];
|
|
70
|
-
for (var i = 1; i < change.path.length; i++) {
|
|
71
|
-
path += '.' + change.path[i];
|
|
72
|
-
}
|
|
73
|
-
if (change.kind === 'E') {
|
|
74
|
-
if (typeof (change.rhs) === 'number' && path.endsWith('quantity')) {
|
|
75
|
-
if (merged.$inc[path]) {
|
|
76
|
-
merged.$inc[path] += change.rhs - change.lhs;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
merged.$inc[path] = change.rhs - change.lhs;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
merged.$set[path] = change.rhs;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
else if (change.kind === 'A') {
|
|
87
|
-
if (change.item.kind === 'N') {
|
|
88
|
-
if (!merged.$push[path] || JSON.stringify(merged.$push[path]) !== JSON.stringify(change.item.rhs)) {
|
|
89
|
-
if (!merged.$push[path]) {
|
|
90
|
-
merged.$push[path] = [];
|
|
91
|
-
}
|
|
92
|
-
if (!merged.$push[path].filter(function (a) { return JSON.stringify(a) === JSON.stringify(change.item.rhs); }).length) {
|
|
93
|
-
merged.$push[path].push(change.item.rhs);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
else if (change.item.kind === 'D') {
|
|
98
|
-
if (!merged.$pull[path] || JSON.stringify(merged.$pull[path]) !== JSON.stringify(change.item.lhs)) {
|
|
99
|
-
if (!merged.$pull[path]) {
|
|
100
|
-
merged.$pull[path] = [];
|
|
101
|
-
}
|
|
102
|
-
if (!merged.$pull[path].filter(function (a) { return JSON.stringify(a) === JSON.stringify(change.item.lhs); }).length) {
|
|
103
|
-
merged.$pull[path].push(change.item.lhs);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else if (change.item.kind === 'E') {
|
|
108
|
-
console.log('Condition E not satisfied.');
|
|
109
|
-
// if (!merged.$pull[path] || JSON.stringify(merged.$pull[path]) !== JSON.stringify(change.item.lhs)) {
|
|
110
|
-
// merged.$pull[path] = change.item.lhs;
|
|
111
|
-
// }
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
return merged;
|
|
117
|
-
}
|
|
118
|
-
exports.mergeUpdates = mergeUpdates;
|
|
119
|
-
function getDeepDiff(doc1, doc2) {
|
|
120
|
-
delete doc1._id;
|
|
121
|
-
delete doc1.__v;
|
|
122
|
-
if (doc1.updatedAt) {
|
|
123
|
-
delete doc1.updatedAt;
|
|
124
|
-
}
|
|
125
|
-
if (doc1.createdAt) {
|
|
126
|
-
delete doc1.createdAt;
|
|
127
|
-
}
|
|
128
|
-
delete doc2._id;
|
|
129
|
-
delete doc2.__v;
|
|
130
|
-
if (doc2.updatedAt) {
|
|
131
|
-
delete doc2.updatedAt;
|
|
132
|
-
}
|
|
133
|
-
if (doc2.createdAt) {
|
|
134
|
-
delete doc2.createdAt;
|
|
135
|
-
}
|
|
136
|
-
return deepDiff(doc1, doc2);
|
|
137
|
-
}
|
|
138
|
-
exports.getDeepDiff = getDeepDiff;
|
|
139
|
-
function applyMongoUpdate(uDoc, delta) {
|
|
140
|
-
var orig, k, pathk, vk, n, n1, n2, name, o, o1, o2, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9a, ref9b, ref10, ref11, ref12a, ref12b, ref13, v;
|
|
141
|
-
orig = deepCopy(uDoc);
|
|
142
|
-
if (delta != null) {
|
|
143
|
-
if (delta.$rename != null) {
|
|
144
|
-
ref = delta.$rename;
|
|
145
|
-
// tslint:disable-next-line:forin
|
|
146
|
-
for (k in ref) {
|
|
147
|
-
v = ref[k];
|
|
148
|
-
ref1 = resolve(uDoc, k), o1 = ref1[0], n1 = ref1[1];
|
|
149
|
-
ref2 = resolve(uDoc, v), o2 = ref2[0], n2 = ref2[1];
|
|
150
|
-
if ((o1 != null) && n1.length === 1) {
|
|
151
|
-
if ((o2 != null) && n2.length === 1) {
|
|
152
|
-
o2[n2[0]] = o1[n1[0]];
|
|
153
|
-
delete o1[n1[0]];
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
// throw new Error(o2 + '/' + n2 + ' - couldn\'t resolve first for ' + uDoc + ' ' + v);
|
|
157
|
-
console.log('Error', o2 + '/' + n2 + ' - couldn\'t resolve first for ' + uDoc + ' ' + v);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
// throw new Error(o1 + '/' + n1 + ' - couldn\'t resolve second for ' + uDoc + ' ' + k);
|
|
162
|
-
console.log('Error', o1 + '/' + n1 + ' - couldn\'t resolve second for ' + uDoc + ' ' + k);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
if (delta.$set != null) {
|
|
167
|
-
ref3 = delta.$set;
|
|
168
|
-
// tslint:disable-next-line:forin
|
|
169
|
-
for (k in ref3) {
|
|
170
|
-
v = ref3[k];
|
|
171
|
-
ref4 = resolve(uDoc, k, {
|
|
172
|
-
force: true
|
|
173
|
-
}), o = ref4[0], n = ref4[1];
|
|
174
|
-
if ((o != null) && n.length === 1) {
|
|
175
|
-
o[n[0]] = v;
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
// throw new Error(o + '/' + n + ' - couldn\'t set for ' + uDoc + ' ' + k);
|
|
179
|
-
console.log('Error', o + '/' + n + ' - couldn\'t set for ' + uDoc + ' ' + k);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
if (delta.$inc != null) {
|
|
184
|
-
ref5 = delta.$inc;
|
|
185
|
-
// tslint:disable-next-line:forin
|
|
186
|
-
for (k in ref5) {
|
|
187
|
-
v = ref5[k];
|
|
188
|
-
ref6 = resolve(uDoc, k, {
|
|
189
|
-
force: true
|
|
190
|
-
}), o = ref6[0], n = ref6[1];
|
|
191
|
-
if ((o != null) && n.length === 1) {
|
|
192
|
-
if (o[name = n[0]] == null) {
|
|
193
|
-
o[name] = 0;
|
|
194
|
-
}
|
|
195
|
-
o[n[0]] += v;
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
// throw new Error(o + '/' + n + ' - couldn\'t set for ' + uDoc + ' ' + k);
|
|
199
|
-
console.log('Error', o + '/' + n + ' - couldn\'t set for ' + uDoc + ' ' + k);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (delta.$unset != null) {
|
|
204
|
-
ref7 = delta.$unset;
|
|
205
|
-
// tslint:disable-next-line:forin
|
|
206
|
-
for (k in ref7) {
|
|
207
|
-
v = ref7[k];
|
|
208
|
-
ref8 = resolve(uDoc, k), o = ref8[0], n = ref8[1];
|
|
209
|
-
if ((o != null) && n.length === 1) {
|
|
210
|
-
delete o[n[0]];
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
// throw new Error(o + '/' + n + ' - couldn\'t unset for ' + uDoc + ' ' + k);
|
|
214
|
-
console.log('Error', o + '/' + n + ' - couldn\'t unset for ' + uDoc + ' ' + k);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
if (delta.$pull != null) {
|
|
219
|
-
ref9a = delta.$pull;
|
|
220
|
-
// tslint:disable-next-line:forin
|
|
221
|
-
for (pathk in ref9a) { // should only loop 1 time
|
|
222
|
-
ref9b = ref9a[pathk];
|
|
223
|
-
for (var kk = (ref9b.length - 1); kk >= 0; kk--) {
|
|
224
|
-
vk = ref9b[kk];
|
|
225
|
-
ref10 = resolve(uDoc, pathk), o = ref10[0], n = ref10[1];
|
|
226
|
-
ref11 = resolve(orig, pathk), o2 = ref11[0], n2 = ref11[1];
|
|
227
|
-
if ((o != null) && n.length === 1) {
|
|
228
|
-
o[n[0]].splice(o2[n2[0]].findIndex(function (z) { return JSON.stringify(z) === JSON.stringify(vk); }), 1);
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
// throw new Error(o + '/' + n + ' - couldn\'t unset for ' + uDoc + ' ' + pathk);
|
|
232
|
-
console.log('Error', o + '/' + n + ' - couldn\'t unset for ' + uDoc + ' ' + pathk);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
if (delta.$push != null) {
|
|
238
|
-
ref12a = delta.$push;
|
|
239
|
-
// tslint:disable-next-line:forin
|
|
240
|
-
for (pathk in ref12a) { // should only loop 1 time
|
|
241
|
-
ref12b = ref12a[pathk];
|
|
242
|
-
// for (let kk = 0; kk < ref12b.length; kk++) {
|
|
243
|
-
for (var kk = (ref12b.length - 1); kk >= 0; kk--) {
|
|
244
|
-
vk = ref12b[kk];
|
|
245
|
-
ref13 = resolve(uDoc, pathk), o = ref13[0], n = ref13[1];
|
|
246
|
-
if ((o != null) && n.length === 1) {
|
|
247
|
-
o[n[0]].push(vk);
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
// throw new Error(o + '/' + n + ' - couldn\'t unset for ' + uDoc + ' ' + pathk);
|
|
251
|
-
console.log('Error', o + '/' + n + ' - couldn\'t unset for ' + uDoc + ' ' + pathk);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
return uDoc;
|
|
258
|
-
}
|
|
259
|
-
exports.applyMongoUpdate = applyMongoUpdate;
|
|
260
|
-
function resolve(a, path, options) {
|
|
261
|
-
var e, k, last, stack;
|
|
262
|
-
if (options == null) {
|
|
263
|
-
options = {};
|
|
264
|
-
}
|
|
265
|
-
stack = arrize(path);
|
|
266
|
-
last = [];
|
|
267
|
-
if (stack.length > 0) {
|
|
268
|
-
last.unshift(stack.pop());
|
|
269
|
-
}
|
|
270
|
-
e = a;
|
|
271
|
-
if (e !== null) {
|
|
272
|
-
while ((k = stack.shift()) !== void 0) {
|
|
273
|
-
if (e[k] !== void 0) {
|
|
274
|
-
e = e[k];
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
stack.unshift(k);
|
|
278
|
-
break;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
if (options.force) {
|
|
283
|
-
while ((k = stack.shift()) !== void 0) {
|
|
284
|
-
if ((typeof stack[0] === 'number') || ((stack.length === 0) && (typeof last[0] === 'number'))) {
|
|
285
|
-
e[k] = [];
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
e[k] = {};
|
|
289
|
-
}
|
|
290
|
-
e = e[k];
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
while ((k = stack.pop()) !== void 0) {
|
|
295
|
-
last.unshift(k);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
return [e, last];
|
|
299
|
-
}
|
|
300
|
-
function arrize(path, glue) {
|
|
301
|
-
if (glue == null) {
|
|
302
|
-
glue = '.';
|
|
303
|
-
}
|
|
304
|
-
return ((function () {
|
|
305
|
-
if (Array.isArray(path)) {
|
|
306
|
-
return path.slice(0);
|
|
307
|
-
}
|
|
308
|
-
else {
|
|
309
|
-
switch (path) {
|
|
310
|
-
case void 0:
|
|
311
|
-
case null:
|
|
312
|
-
case false:
|
|
313
|
-
case '':
|
|
314
|
-
return [];
|
|
315
|
-
default:
|
|
316
|
-
return path.toString().split(glue);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
})()).map(function (e) {
|
|
320
|
-
switch (e) {
|
|
321
|
-
case void 0:
|
|
322
|
-
case null:
|
|
323
|
-
case false:
|
|
324
|
-
case '':
|
|
325
|
-
return null;
|
|
326
|
-
default:
|
|
327
|
-
return e.toString();
|
|
328
|
-
}
|
|
329
|
-
}).filter(function (e) {
|
|
330
|
-
return e != null;
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
function getBinarySize(string) {
|
|
334
|
-
if (string) {
|
|
335
|
-
return Buffer.byteLength(string, 'utf8');
|
|
336
|
-
}
|
|
337
|
-
else {
|
|
338
|
-
return 0;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
exports.getBinarySize = getBinarySize;
|