@resolveio/server-lib 3.2.11 → 3.2.12
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.d.ts +7 -0
- package/collections/active-subscription.collection.js +68 -0
- package/collections/app-status.collection.d.ts +7 -0
- package/collections/app-status.collection.js +43 -0
- package/collections/app-version.collection.d.ts +7 -0
- package/collections/app-version.collection.js +56 -0
- package/collections/billing-logged-in-users.collection.d.ts +7 -0
- package/collections/billing-logged-in-users.collection.js +73 -0
- package/collections/counter.collection.d.ts +9 -0
- package/collections/counter.collection.js +73 -0
- package/collections/cron-job-history.collection.d.ts +7 -0
- package/collections/cron-job-history.collection.js +86 -0
- package/collections/cron-job.collection.d.ts +7 -0
- package/collections/cron-job.collection.js +89 -0
- package/collections/file.collection.d.ts +9 -0
- package/collections/file.collection.js +73 -0
- package/collections/flag.collection.d.ts +7 -0
- package/collections/flag.collection.js +47 -0
- package/collections/log.collection.d.ts +7 -0
- package/collections/log.collection.js +65 -0
- package/collections/logged-in-users.collection.d.ts +7 -0
- package/collections/logged-in-users.collection.js +70 -0
- package/collections/method-call.collection.d.ts +6 -0
- package/collections/method-call.collection.js +44 -0
- package/collections/method-response.collection.d.ts +6 -0
- package/collections/method-response.collection.js +48 -0
- package/collections/notification.collection.d.ts +7 -0
- package/collections/notification.collection.js +43 -0
- package/collections/queue-flag.collection.d.ts +7 -0
- package/collections/queue-flag.collection.js +41 -0
- package/collections/queue-method.collection.d.ts +7 -0
- package/collections/queue-method.collection.js +119 -0
- package/collections/queue-response.collection.d.ts +7 -0
- package/collections/queue-response.collection.js +74 -0
- package/collections/support-ticket.collection.d.ts +7 -0
- package/collections/support-ticket.collection.js +200 -0
- package/collections/user.collection.d.ts +9 -0
- package/collections/user.collection.js +153 -0
- package/cron/cron.d.ts +5 -0
- package/cron/cron.js +160 -0
- package/fixtures/cron-jobs.d.ts +1 -0
- package/fixtures/cron-jobs.js +90 -0
- package/fixtures/init.d.ts +1 -0
- package/fixtures/init.js +67 -0
- package/http/auth.d.ts +2 -0
- package/http/auth.js +468 -0
- package/http/health.d.ts +1 -0
- package/http/health.js +8 -0
- package/index.d.ts +16 -0
- package/index.js +125 -0
- package/managers/cron.manager.d.ts +16 -0
- package/managers/cron.manager.js +202 -0
- package/managers/database.manager.d.ts +6 -0
- package/managers/database.manager.js +12 -0
- package/managers/method.manager.d.ts +28 -0
- package/managers/method.manager.js +584 -0
- package/managers/queue-method.manager.d.ts +13 -0
- package/managers/queue-method.manager.js +240 -0
- package/managers/subscription.manager.d.ts +28 -0
- package/managers/subscription.manager.js +808 -0
- package/managers/support.manager.d.ts +22 -0
- package/managers/support.manager.js +320 -0
- package/methods/accounts.d.ts +2 -0
- package/methods/accounts.js +253 -0
- package/methods/aws.d.ts +2 -0
- package/methods/aws.js +387 -0
- package/methods/cloudconvert.d.ts +2 -0
- package/methods/cloudconvert.js +37 -0
- package/methods/collections.d.ts +2 -0
- package/methods/collections.js +750 -0
- package/methods/counters.d.ts +2 -0
- package/methods/counters.js +107 -0
- package/methods/cron-jobs.d.ts +2 -0
- package/methods/cron-jobs.js +132 -0
- package/methods/flags.d.ts +2 -0
- package/methods/flags.js +6 -0
- package/methods/logs.d.ts +2 -0
- package/methods/logs.js +29 -0
- package/methods/pdf.d.ts +2 -0
- package/methods/pdf.js +303 -0
- package/models/active-subscription.model.d.ts +13 -0
- package/models/active-subscription.model.js +2 -0
- package/models/app-status.model.d.ts +4 -0
- package/models/app-status.model.js +2 -0
- package/models/app-version.model.d.ts +4 -0
- package/models/app-version.model.js +2 -0
- package/models/billing-logged-in-users.model.d.ts +7 -0
- package/models/billing-logged-in-users.model.js +2 -0
- package/models/collection-document.model.d.ts +6 -0
- package/models/collection-document.model.js +2 -0
- package/models/counter.model.d.ts +5 -0
- package/models/counter.model.js +2 -0
- package/models/cron-job-history.model.d.ts +12 -0
- package/models/cron-job-history.model.js +2 -0
- package/models/cron-job.model.d.ts +13 -0
- package/models/cron-job.model.js +2 -0
- package/models/dialog.model.d.ts +23 -0
- package/models/dialog.model.js +2 -0
- package/models/file.model.d.ts +9 -0
- package/models/file.model.js +2 -0
- package/models/flag.model.d.ts +5 -0
- package/models/flag.model.js +2 -0
- package/models/log.model.d.ts +11 -0
- package/models/log.model.js +2 -0
- package/models/logged-in-users.model.d.ts +9 -0
- package/models/logged-in-users.model.js +2 -0
- package/models/method-call.model.d.ts +7 -0
- package/models/method-call.model.js +2 -0
- package/models/method-response.model.d.ts +8 -0
- package/models/method-response.model.js +2 -0
- package/models/method.model.d.ts +10 -0
- package/models/method.model.js +2 -0
- package/models/notification.model.d.ts +4 -0
- package/models/notification.model.js +2 -0
- package/models/pagination.model.d.ts +11 -0
- package/models/pagination.model.js +20 -0
- package/models/permission.model.d.ts +12 -0
- package/models/permission.model.js +2 -0
- package/models/queue-method.model.d.ts +10 -0
- package/models/queue-method.model.js +2 -0
- package/models/queue-response.model.d.ts +10 -0
- package/models/queue-response.model.js +2 -0
- package/models/select-data-label.model.d.ts +9 -0
- package/models/select-data-label.model.js +2 -0
- package/models/server-response.model.d.ts +5 -0
- package/models/server-response.model.js +2 -0
- package/models/subscription.model.d.ts +30 -0
- package/models/subscription.model.js +2 -0
- package/models/support-method.model.d.ts +9 -0
- package/models/support-method.model.js +2 -0
- package/models/support-ticket.model.d.ts +61 -0
- package/models/support-ticket.model.js +2 -0
- package/models/user.model.d.ts +14 -0
- package/models/user.model.js +2 -0
- package/package.json +1 -1
- package/private/email-templates/enrollment.html +12 -0
- package/private/email-templates/forgot-password.html +12 -0
- package/private/email-templates/support-ticket-deleted.html +40 -0
- package/private/email-templates/support-ticket-modified.html +71 -0
- package/private/email-templates/support-ticket.html +71 -0
- package/private/images/ResolveIO.png +0 -0
- package/publications/app-status.d.ts +2 -0
- package/publications/app-status.js +14 -0
- package/publications/app-version.d.ts +2 -0
- package/publications/app-version.js +14 -0
- package/publications/billing-logged-in-users.d.ts +1 -0
- package/publications/billing-logged-in-users.js +63 -0
- package/publications/cron-jobs.d.ts +2 -0
- package/publications/cron-jobs.js +14 -0
- package/publications/files.d.ts +2 -0
- package/publications/files.js +71 -0
- package/publications/flags.d.ts +2 -0
- package/publications/flags.js +23 -0
- package/publications/logs.d.ts +2 -0
- package/publications/logs.js +26 -0
- package/publications/method-calls.d.ts +2 -0
- package/publications/method-calls.js +14 -0
- package/publications/method-responses.d.ts +2 -0
- package/publications/method-responses.js +14 -0
- package/publications/notifications.d.ts +2 -0
- package/publications/notifications.js +14 -0
- package/publications/super-admin.d.ts +2 -0
- package/publications/super-admin.js +21 -0
- package/publications/support-tickets.d.ts +1 -0
- package/publications/support-tickets.js +200 -0
- package/server-app.d.ts +35 -0
- package/server-app.js +638 -0
- package/support-methods/aws.d.ts +2 -0
- package/support-methods/aws.js +276 -0
- package/support-methods/collections.d.ts +2 -0
- package/support-methods/collections.js +471 -0
- package/support-methods/counters.d.ts +2 -0
- package/support-methods/counters.js +189 -0
- package/support-methods/support.d.ts +2 -0
- package/support-methods/support.js +236 -0
- package/util/common.d.ts +14 -0
- package/util/common.js +341 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
var mongoose_1 = require("mongoose");
|
|
39
|
+
var counter_collection_1 = require("../collections/counter.collection");
|
|
40
|
+
var simpl_schema_1 = require("simpl-schema");
|
|
41
|
+
var __1 = require("..");
|
|
42
|
+
function loadCounterMethods(methodManager) {
|
|
43
|
+
methodManager.methods({
|
|
44
|
+
incCounter: {
|
|
45
|
+
skipQueue: true,
|
|
46
|
+
check: new simpl_schema_1.default({
|
|
47
|
+
counterType: {
|
|
48
|
+
type: String
|
|
49
|
+
}
|
|
50
|
+
}),
|
|
51
|
+
function: function (counterType) {
|
|
52
|
+
var _this = this;
|
|
53
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
54
|
+
var counter, newCount;
|
|
55
|
+
return __generator(this, function (_a) {
|
|
56
|
+
switch (_a.label) {
|
|
57
|
+
case 0: return [4 /*yield*/, counter_collection_1.Counters.findOne({ type: counterType })];
|
|
58
|
+
case 1:
|
|
59
|
+
counter = _a.sent();
|
|
60
|
+
if (!!counter) return [3 /*break*/, 2];
|
|
61
|
+
counter_collection_1.Counters.create({
|
|
62
|
+
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
63
|
+
count: 2,
|
|
64
|
+
type: counterType
|
|
65
|
+
});
|
|
66
|
+
resolve(1);
|
|
67
|
+
return [3 /*break*/, 4];
|
|
68
|
+
case 2: return [4 /*yield*/, counter_collection_1.Counters.findOneAndUpdate({ type: counterType }, { $inc: { count: 1 } }).exec()];
|
|
69
|
+
case 3:
|
|
70
|
+
newCount = _a.sent();
|
|
71
|
+
resolve(newCount.count);
|
|
72
|
+
_a.label = 4;
|
|
73
|
+
case 4: return [2 /*return*/];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}); });
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
countCollectionWithQuery: {
|
|
80
|
+
skipQueue: true,
|
|
81
|
+
check: new simpl_schema_1.default({
|
|
82
|
+
collectionType: {
|
|
83
|
+
type: String
|
|
84
|
+
},
|
|
85
|
+
query: {
|
|
86
|
+
type: Object,
|
|
87
|
+
blackbox: true
|
|
88
|
+
}
|
|
89
|
+
}),
|
|
90
|
+
function: function (collectionType, query) {
|
|
91
|
+
return __1.ResolveIOServer.getMainDB().model(collectionType).collection.countDocuments(query);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
countCollection: {
|
|
95
|
+
skipQueue: true,
|
|
96
|
+
check: new simpl_schema_1.default({
|
|
97
|
+
collectionType: {
|
|
98
|
+
type: String
|
|
99
|
+
}
|
|
100
|
+
}),
|
|
101
|
+
function: function (collectionType) {
|
|
102
|
+
return __1.ResolveIOServer.getMainDB().model(collectionType).collection.countDocuments();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
exports.loadCounterMethods = loadCounterMethods;
|
|
@@ -0,0 +1,132 @@
|
|
|
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 queue_method_collection_1 = require("../collections/queue-method.collection");
|
|
39
|
+
var user_collection_1 = require("../collections/user.collection");
|
|
40
|
+
var simpl_schema_1 = require("simpl-schema");
|
|
41
|
+
var mongoose_1 = require("mongoose");
|
|
42
|
+
function loadCronJobMethods(methodManager) {
|
|
43
|
+
methodManager.methods({
|
|
44
|
+
methodQueue: {
|
|
45
|
+
function: function () {
|
|
46
|
+
var _this = this;
|
|
47
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
48
|
+
var updateCnt;
|
|
49
|
+
return __generator(this, function (_a) {
|
|
50
|
+
switch (_a.label) {
|
|
51
|
+
case 0: return [4 /*yield*/, queue_method_collection_1.QueueMethods.collection.countDocuments()];
|
|
52
|
+
case 1:
|
|
53
|
+
updateCnt = _a.sent();
|
|
54
|
+
if (updateCnt) {
|
|
55
|
+
methodManager.getMainServer().getQueueManager().runMethodQueue();
|
|
56
|
+
}
|
|
57
|
+
resolve();
|
|
58
|
+
return [2 /*return*/];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}); });
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
updateClientUsers: {
|
|
65
|
+
function: function () {
|
|
66
|
+
var _this = this;
|
|
67
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
68
|
+
var users, count, interval;
|
|
69
|
+
var _this = this;
|
|
70
|
+
return __generator(this, function (_a) {
|
|
71
|
+
switch (_a.label) {
|
|
72
|
+
case 0:
|
|
73
|
+
if (!user_collection_1.ClientUsers) {
|
|
74
|
+
resolve();
|
|
75
|
+
return [2 /*return*/];
|
|
76
|
+
}
|
|
77
|
+
return [4 /*yield*/, user_collection_1.Users.find({})];
|
|
78
|
+
case 1:
|
|
79
|
+
users = _a.sent();
|
|
80
|
+
count = 0;
|
|
81
|
+
interval = setInterval(function () {
|
|
82
|
+
var updateChunk = users.slice(count * 10, Math.min(users.length, (count + 1) * 10));
|
|
83
|
+
_this.callMethodInternal.call(_this, 'updateClientUserChunk', updateChunk);
|
|
84
|
+
count++;
|
|
85
|
+
if (count * 10 > users.length) {
|
|
86
|
+
clearInterval(interval);
|
|
87
|
+
resolve(true);
|
|
88
|
+
}
|
|
89
|
+
}, 1000);
|
|
90
|
+
resolve();
|
|
91
|
+
return [2 /*return*/];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}); });
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
updateClientUserChunk: {
|
|
98
|
+
check: new simpl_schema_1.default({
|
|
99
|
+
users: {
|
|
100
|
+
type: Array
|
|
101
|
+
},
|
|
102
|
+
'users.$': {
|
|
103
|
+
type: Object,
|
|
104
|
+
blackbox: true
|
|
105
|
+
}
|
|
106
|
+
}),
|
|
107
|
+
function: function (users) {
|
|
108
|
+
var _this = this;
|
|
109
|
+
return new Promise(function (resolve, reject) {
|
|
110
|
+
users.forEach(function (user) {
|
|
111
|
+
user['client'] = _this.serverConfig['CLIENT_NAME'];
|
|
112
|
+
user_collection_1.ClientUsers.updateOne({
|
|
113
|
+
$and: [
|
|
114
|
+
{ id_user: user._id },
|
|
115
|
+
{ client: user['client'] }
|
|
116
|
+
]
|
|
117
|
+
}, { $setOnInsert: {
|
|
118
|
+
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
119
|
+
__v: 0,
|
|
120
|
+
id_user: user._id,
|
|
121
|
+
fullname: user.fullname,
|
|
122
|
+
client: user['client']
|
|
123
|
+
},
|
|
124
|
+
$set: { email: user.email } }, { upsert: true, strict: false }).exec();
|
|
125
|
+
});
|
|
126
|
+
resolve();
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
exports.loadCronJobMethods = loadCronJobMethods;
|
package/methods/flags.js
ADDED
package/methods/logs.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mongoose_1 = require("mongoose");
|
|
4
|
+
var log_collection_1 = require("../collections/log.collection");
|
|
5
|
+
var index_1 = require("../index");
|
|
6
|
+
function loadLogMethods(methodManager) {
|
|
7
|
+
methodManager.methods({
|
|
8
|
+
insertErrorLog: {
|
|
9
|
+
skipQueue: true,
|
|
10
|
+
function: function (message, data) {
|
|
11
|
+
this.sendEmail('dev@resolveio.com', 'Error Detected - ' + index_1.ResolveIOServer.getClientName(), this.user + '\n' + message + '\n' + JSON.stringify(data, null, 2));
|
|
12
|
+
return log_collection_1.Logs.create({
|
|
13
|
+
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
14
|
+
__v: 0,
|
|
15
|
+
date: new Date(),
|
|
16
|
+
type: 'error',
|
|
17
|
+
title: 'Error - User: ' + this.user,
|
|
18
|
+
message: message,
|
|
19
|
+
payload: JSON.stringify(data),
|
|
20
|
+
method: '',
|
|
21
|
+
user: this.user,
|
|
22
|
+
messageId: ''
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
skipValidation: true
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.loadLogMethods = loadLogMethods;
|
package/methods/pdf.d.ts
ADDED
package/methods/pdf.js
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var request = require("request");
|
|
5
|
+
var mongoose_1 = require("mongoose");
|
|
6
|
+
var simpl_schema_1 = require("simpl-schema");
|
|
7
|
+
var pdfCnt = 0;
|
|
8
|
+
function loadPDFMethods(methodManager) {
|
|
9
|
+
methodManager.methods({
|
|
10
|
+
generatePDF: {
|
|
11
|
+
skipQueue: true,
|
|
12
|
+
check: new simpl_schema_1.default({
|
|
13
|
+
html: {
|
|
14
|
+
type: String
|
|
15
|
+
},
|
|
16
|
+
fileName: {
|
|
17
|
+
type: String
|
|
18
|
+
},
|
|
19
|
+
orientation: {
|
|
20
|
+
type: String,
|
|
21
|
+
optional: true
|
|
22
|
+
},
|
|
23
|
+
fontSize: {
|
|
24
|
+
type: String,
|
|
25
|
+
optional: true
|
|
26
|
+
},
|
|
27
|
+
upload: {
|
|
28
|
+
type: Boolean,
|
|
29
|
+
optional: true
|
|
30
|
+
},
|
|
31
|
+
uploadFileOrder: {
|
|
32
|
+
type: Number,
|
|
33
|
+
optional: true
|
|
34
|
+
},
|
|
35
|
+
uploadFileType: {
|
|
36
|
+
type: String,
|
|
37
|
+
optional: true
|
|
38
|
+
}
|
|
39
|
+
}),
|
|
40
|
+
function: function (html, fileName, orientation, fontSize, upload, uploadFileOrder, uploadFileType) {
|
|
41
|
+
if (orientation === void 0) { orientation = 'portrait'; }
|
|
42
|
+
if (fontSize === void 0) { fontSize = '8px'; }
|
|
43
|
+
if (upload === void 0) { upload = false; }
|
|
44
|
+
if (uploadFileOrder === void 0) { uploadFileOrder = -1; }
|
|
45
|
+
if (uploadFileType === void 0) { uploadFileType = ''; }
|
|
46
|
+
var that = this;
|
|
47
|
+
return new Promise(function (resolve, reject) {
|
|
48
|
+
var phantom = require('phantom');
|
|
49
|
+
var phInstance = null;
|
|
50
|
+
phantom.create().then(function (instance) {
|
|
51
|
+
phInstance = instance;
|
|
52
|
+
return instance.createPage();
|
|
53
|
+
}).then(function (page) {
|
|
54
|
+
page.property('paperSize', {
|
|
55
|
+
format: 'letter',
|
|
56
|
+
margin: '1cm',
|
|
57
|
+
orientation: orientation,
|
|
58
|
+
footer: {
|
|
59
|
+
height: '1cm',
|
|
60
|
+
contents: phInstance.callback(function (pageNum, numPages) {
|
|
61
|
+
return '<span style=\'float:right; font-size: 12px;\'>Page ' + pageNum + ' of ' + numPages + '</span>';
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
page.property('content', "\n\t\t\t\t\t\t<head>\n\t\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif', serif;\n\t\t\t\t\t\t\t\t\tfont-style: normal;\n\t\t\t\t\t\t\t\t\tfont-weight: normal;\n\t\t\t\t\t\t\t\t\tsrc: url(\"/usr/share/fonts/dejavu/DejaVuSerif.ttf\");\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif', serif;\n\t\t\t\t\t\t\t\t\tfont-style: normal;\n\t\t\t\t\t\t\t\t\tfont-weight: bold;\n\t\t\t\t\t\t\t\t\tsrc: url(\"/usr/share/fonts/dejavu/DejaVuSerif-Bold.ttf\");\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif', serif;\n\t\t\t\t\t\t\t\t\tfont-style: italic;\n\t\t\t\t\t\t\t\t\tfont-weight: normal;\n\t\t\t\t\t\t\t\t\tsrc: url(\"/usr/share/fonts/dejavu/DejaVuSerif-Italic.ttf\");\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t@font-face {\n\t\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif', serif;\n\t\t\t\t\t\t\t\t\tfont-style: italic;\n\t\t\t\t\t\t\t\t\tfont-weight: bold;\n\t\t\t\t\t\t\t\t\tsrc: url(\"/usr/share/fonts/dejavu/DejaVuSerif-BoldItalic.ttf\");\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tbody {\n\t\t\t\t\t\t\t\t\tfont-family: 'Dejavu Serif', serif;\n\t\t\t\t\t\t\t\t\tfont-size: " + (fontSize ? fontSize : '8px') + ";\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t.row {\n\t\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\t\tdisplay: flex;\n\t\t\t\t\t\t\t\t\tflex-wrap: wrap;\n\t\t\t\t\t\t\t\t\t-webkit-flex-wrap: wrap;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t.page-break {\n\t\t\t\t\t\t\t\t\tpage-break-before: always !important;\n\t\t\t\t\t\t\t\t\tmargin-bottom: 1px;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t.cell {\n\t\t\t\t\t\t\t\t\tbox-sizing: border-box;\n\t\t\t\t\t\t\t\t\tpadding : 2px;\n\t\t\t\t\t\t\t\t\t-webkit-flex: 1;\n\t\t\t\t\t\t\t\t\tword-wrap: break-word;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t.cell-no-padding {\n\t\t\t\t\t\t\t\t\tbox-sizing: border-box;\n\t\t\t\t\t\t\t\t\t-webkit-flex: 1;\n\t\t\t\t\t\t\t\t\tword-wrap: break-word;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t.centered {\n\t\t\t\t\t\t\t\t\t-webkit-justify-content: center;\n\t\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\t\ttext-align: center;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t.centered-left {\n\t\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\t\t-webkit-justify-content: flex-start;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t.centered-right {\n\t\t\t\t\t\t\t\t\t-webkit-justify-content: flex-end;\n\t\t\t\t\t\t\t\t\t-webkit-align-items: center;\n\t\t\t\t\t\t\t\t\tdisplay: -webkit-flex;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t.box {\n\t\t\t\t\t\t\t\t\tborder: 1px solid black;\n\t\t\t\t\t\t\t\t\tmargin: -1px 0px 0px -1px;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t.boxNoBorder {\n\t\t\t\t\t\t\t\t\tmargin: -1px 0px 0px -1px;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tpre {\n\t\t\t\t\t\t\t\t\twhite-space: pre-wrap; /* css-3 */\n\t\t\t\t\t\t\t\t\twhite-space: -moz-pre-wrap; /* Mozilla, since 1999 */\n\t\t\t\t\t\t\t\t\twhite-space: -pre-wrap; /* Opera 4-6 */\n\t\t\t\t\t\t\t\t\twhite-space: -o-pre-wrap; /* Opera 7 */\n\t\t\t\t\t\t\t\t\tword-wrap: break-word; /* Internet Explorer 5.5+ */\n\t\t\t\t\t\t\t\t\tfont-size: 12px;\n\t\t\t\t\t\t\t\t\tfont-family: Open Sans; \n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</style>\n\t\t\t\t\t\t</head>\n\t\t\t\t\t\t<body>\n\t\t\t\t\t" + html.replace(new RegExp('flex-basis:', 'g'), '-webkit-flex-basis:').replace(new RegExp('flex:', 'g'), '-webkit-flex:') + '</body>');
|
|
66
|
+
var tmpFileName = (pdfCnt++) + '-' + fileName;
|
|
67
|
+
page.render(tmpFileName, {
|
|
68
|
+
format: 'pdf',
|
|
69
|
+
quality: '100'
|
|
70
|
+
}).then(function () {
|
|
71
|
+
if (fs.existsSync(tmpFileName)) {
|
|
72
|
+
fs.readFile(tmpFileName, function (errRead, data) {
|
|
73
|
+
if (!errRead) {
|
|
74
|
+
fs.unlinkSync(tmpFileName);
|
|
75
|
+
if (!upload) {
|
|
76
|
+
resolve('data:application/pdf;base64,' + Buffer.from(data).toString('base64'));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
var fileData = 'data:application/pdf;base64,' + Buffer.from(data).toString('base64');
|
|
80
|
+
that.callMethodInternal.call(that, 'uploadFileAndSave', fileName, fileData, (4 * Math.ceil(fileData.length / 3)), uploadFileOrder, uploadFileType, function (err, res) {
|
|
81
|
+
if (err) {
|
|
82
|
+
reject(err);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
resolve(res);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.log(errRead);
|
|
92
|
+
}
|
|
93
|
+
phInstance.exit();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
reject('No tmp file');
|
|
98
|
+
console.log('No tmp file ', tmpFileName);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
})
|
|
102
|
+
.catch(function (error) {
|
|
103
|
+
reject(error);
|
|
104
|
+
phInstance.exit();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
mergePDF: {
|
|
110
|
+
skipQueue: true,
|
|
111
|
+
check: new simpl_schema_1.default({
|
|
112
|
+
fileKeys: {
|
|
113
|
+
type: Array
|
|
114
|
+
},
|
|
115
|
+
'fileKeys.$': {
|
|
116
|
+
type: String
|
|
117
|
+
},
|
|
118
|
+
fileName: {
|
|
119
|
+
type: String
|
|
120
|
+
},
|
|
121
|
+
fileType: {
|
|
122
|
+
type: String,
|
|
123
|
+
optional: true
|
|
124
|
+
}
|
|
125
|
+
}),
|
|
126
|
+
function: function (fileKeys, fileName, fileType) {
|
|
127
|
+
var _this = this;
|
|
128
|
+
return new Promise(function (resolve, reject) {
|
|
129
|
+
_this.callMethodInternal.call(_this, 'getCCProcessURL').then(function (resCC) {
|
|
130
|
+
var mergeFileName = 'uploads/' + Date.now() + '-' + (pdfCnt++) + '-' + fileName;
|
|
131
|
+
//send request
|
|
132
|
+
request({
|
|
133
|
+
method: 'POST',
|
|
134
|
+
url: 'https:' + resCC.url,
|
|
135
|
+
headers: {
|
|
136
|
+
'Content-Type': 'application/json'
|
|
137
|
+
},
|
|
138
|
+
json: {
|
|
139
|
+
mode: 'combine',
|
|
140
|
+
input: {
|
|
141
|
+
s3: {
|
|
142
|
+
'accesskeyid': _this.serverConfig['AWSACCESSKEYID'],
|
|
143
|
+
'secretaccesskey': _this.serverConfig['AWSSECRETACCESSKEY'],
|
|
144
|
+
'region': _this.serverConfig['AWSREGION'],
|
|
145
|
+
'bucket': _this.serverConfig['AWSBUCKET']
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
files: fileKeys,
|
|
149
|
+
outputformat: 'pdf',
|
|
150
|
+
wait: true,
|
|
151
|
+
output: {
|
|
152
|
+
's3': {
|
|
153
|
+
'accesskeyid': _this.serverConfig['AWSACCESSKEYID'],
|
|
154
|
+
'secretaccesskey': _this.serverConfig['AWSSECRETACCESSKEY'],
|
|
155
|
+
'region': _this.serverConfig['AWSREGION'],
|
|
156
|
+
'bucket': _this.serverConfig['AWSBUCKET'],
|
|
157
|
+
'path': mergeFileName
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
converteroptions: {
|
|
161
|
+
'resize': '612x792',
|
|
162
|
+
'resizemode': 'scale',
|
|
163
|
+
'resizeenlarge': null,
|
|
164
|
+
'grayscale': null,
|
|
165
|
+
'auto_orient': null,
|
|
166
|
+
'strip_metatags': false,
|
|
167
|
+
'density': 72,
|
|
168
|
+
'rotate': null,
|
|
169
|
+
'command': null
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
}, function (error, response, body) {
|
|
173
|
+
if (!error) {
|
|
174
|
+
var resFile_1 = {
|
|
175
|
+
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
176
|
+
__v: 0,
|
|
177
|
+
name: fileName,
|
|
178
|
+
size: body.output.size,
|
|
179
|
+
key: mergeFileName,
|
|
180
|
+
type: fileType ? fileType : '',
|
|
181
|
+
order: -1
|
|
182
|
+
};
|
|
183
|
+
if (body.output.size) {
|
|
184
|
+
_this.callMethodInternal.call(_this, 'insertDocument', 'files', resFile_1, function (errUpFile, resUpFile) {
|
|
185
|
+
if (resUpFile) {
|
|
186
|
+
resFile_1.status = 'Uploaded';
|
|
187
|
+
resolve(resFile_1);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
reject(errUpFile);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
reject('Merged file has no size, merge failed');
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
reject(error);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}, function (errCC) { return reject(errCC); });
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
mergePDFNoUpload: {
|
|
207
|
+
skipQueue: true,
|
|
208
|
+
check: new simpl_schema_1.default({
|
|
209
|
+
fileKeys: {
|
|
210
|
+
type: Array
|
|
211
|
+
},
|
|
212
|
+
'fileKeys.$': {
|
|
213
|
+
type: String
|
|
214
|
+
},
|
|
215
|
+
fileName: {
|
|
216
|
+
type: String
|
|
217
|
+
},
|
|
218
|
+
fileType: {
|
|
219
|
+
type: String,
|
|
220
|
+
optional: true
|
|
221
|
+
}
|
|
222
|
+
}),
|
|
223
|
+
function: function (fileKeys, fileName, fileType) {
|
|
224
|
+
var _this = this;
|
|
225
|
+
return new Promise(function (resolve, reject) {
|
|
226
|
+
_this.callMethodInternal.call(_this, 'getCCProcessURL').then(function (resCC) {
|
|
227
|
+
var mergeFileName = 'uploads/' + Date.now() + '-' + (pdfCnt++) + '-' + fileName;
|
|
228
|
+
//send request
|
|
229
|
+
request({
|
|
230
|
+
method: 'POST',
|
|
231
|
+
url: 'https:' + resCC.url,
|
|
232
|
+
headers: {
|
|
233
|
+
'Content-Type': 'application/json'
|
|
234
|
+
},
|
|
235
|
+
json: {
|
|
236
|
+
mode: 'combine',
|
|
237
|
+
input: {
|
|
238
|
+
s3: {
|
|
239
|
+
'accesskeyid': _this.serverConfig['AWSACCESSKEYID'],
|
|
240
|
+
'secretaccesskey': _this.serverConfig['AWSSECRETACCESSKEY'],
|
|
241
|
+
'region': _this.serverConfig['AWSREGION'],
|
|
242
|
+
'bucket': _this.serverConfig['AWSBUCKET']
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
files: fileKeys,
|
|
246
|
+
outputformat: 'pdf',
|
|
247
|
+
wait: true,
|
|
248
|
+
output: {
|
|
249
|
+
's3': {
|
|
250
|
+
'accesskeyid': _this.serverConfig['AWSACCESSKEYID'],
|
|
251
|
+
'secretaccesskey': _this.serverConfig['AWSSECRETACCESSKEY'],
|
|
252
|
+
'region': _this.serverConfig['AWSREGION'],
|
|
253
|
+
'bucket': _this.serverConfig['AWSBUCKET'],
|
|
254
|
+
'path': mergeFileName
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
converteroptions: {
|
|
258
|
+
'resize': '612x792',
|
|
259
|
+
'resizemode': 'scale',
|
|
260
|
+
'resizeenlarge': null,
|
|
261
|
+
'grayscale': null,
|
|
262
|
+
'auto_orient': null,
|
|
263
|
+
'strip_metatags': false,
|
|
264
|
+
'density': 72,
|
|
265
|
+
'rotate': null,
|
|
266
|
+
'command': null
|
|
267
|
+
},
|
|
268
|
+
}
|
|
269
|
+
}, function (error, response, body) {
|
|
270
|
+
if (!error) {
|
|
271
|
+
var resFile_2 = {
|
|
272
|
+
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
273
|
+
name: fileName,
|
|
274
|
+
size: body.output.size,
|
|
275
|
+
key: mergeFileName,
|
|
276
|
+
type: fileType ? fileType : '',
|
|
277
|
+
order: -1
|
|
278
|
+
};
|
|
279
|
+
_this.callMethodInternal.call(_this, 'insertDocument', 'files', resFile_2, function (errUpFile, resUpFile) {
|
|
280
|
+
if (resUpFile) {
|
|
281
|
+
resFile_2.status = 'Uploaded';
|
|
282
|
+
resolve(resFile_2);
|
|
283
|
+
var that_1 = _this;
|
|
284
|
+
setTimeout(function () {
|
|
285
|
+
that_1.callMethodInternal.call(that_1, 'deleteFile', mergeFileName);
|
|
286
|
+
}, 60000);
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
reject(errUpFile);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
reject(error);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
}, function (errCC) { return reject(errCC); });
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
exports.loadPDFMethods = loadPDFMethods;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CollectionDocument } from './collection-document.model';
|
|
2
|
+
export interface ActiveSubscriptionModel extends CollectionDocument {
|
|
3
|
+
date: Date;
|
|
4
|
+
publication: string;
|
|
5
|
+
subData: string | Object;
|
|
6
|
+
collections: string[];
|
|
7
|
+
clients: ActiveSubscriptionClientModel[];
|
|
8
|
+
}
|
|
9
|
+
export interface ActiveSubscriptionClientModel {
|
|
10
|
+
id_user: string;
|
|
11
|
+
messageId: number;
|
|
12
|
+
id_socket: string;
|
|
13
|
+
}
|