@resolveio/server-lib 20.12.71 → 20.13.0

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.
@@ -0,0 +1,432 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.loadMongoExplorerMethods = loadMongoExplorerMethods;
40
+ var simpl_schema_1 = require("simpl-schema");
41
+ var user_collection_1 = require("../collections/user.collection");
42
+ var resolveio_server_app_1 = require("../resolveio-server-app");
43
+ var common_1 = require("../util/common");
44
+ var DEFAULT_LIMIT = 100;
45
+ var MAX_LIMIT = 2000;
46
+ function resolveDatabaseName(database) {
47
+ var _a, _b;
48
+ var defaultDb = ((_a = resolveio_server_app_1.ResolveIOServer.getServerConfig()) === null || _a === void 0 ? void 0 : _a.DATABASE) || '';
49
+ var dbName = typeof database === 'string' && database.trim().length ? database.trim() : defaultDb;
50
+ if (!dbName) {
51
+ throw new Error('Mongo Explorer: Database is required');
52
+ }
53
+ var allowedDatabases = ((_b = resolveio_server_app_1.ResolveIOServer.getMongoManager()) === null || _b === void 0 ? void 0 : _b.getWatchedDatabases()) || [];
54
+ if (allowedDatabases.length && !allowedDatabases.includes(dbName)) {
55
+ throw new Error('Mongo Explorer: Database access denied');
56
+ }
57
+ return dbName;
58
+ }
59
+ function resolveDatabase(database) {
60
+ var dbName = resolveDatabaseName(database);
61
+ return resolveio_server_app_1.ResolveIOServer.getMongoConnection().db(dbName);
62
+ }
63
+ function resolveCollectionHandle(database, collection) {
64
+ var _a, _b;
65
+ var mainDb = ((_a = resolveio_server_app_1.ResolveIOServer.getServerConfig()) === null || _a === void 0 ? void 0 : _a.DATABASE) || '';
66
+ var isMainDb = database === mainDb;
67
+ var managerCollection = isMainDb ? (_b = resolveio_server_app_1.ResolveIOServer.getMongoManager()) === null || _b === void 0 ? void 0 : _b.collection(collection) : null;
68
+ var db = resolveio_server_app_1.ResolveIOServer.getMongoConnection().db(database);
69
+ return {
70
+ managerCollection: managerCollection,
71
+ dbCollection: db.collection(collection)
72
+ };
73
+ }
74
+ function normalizeFindOptions(options) {
75
+ var normalized = options || {};
76
+ var projection = normalized.projection && Object.keys(normalized.projection).length ? normalized.projection : undefined;
77
+ var sort = normalized.sort && Object.keys(normalized.sort).length ? normalized.sort : undefined;
78
+ var limit = typeof normalized.limit === 'number' ? Math.min(Math.max(normalized.limit, 0), MAX_LIMIT) : DEFAULT_LIMIT;
79
+ var skip = typeof normalized.skip === 'number' ? Math.max(normalized.skip, 0) : 0;
80
+ return {
81
+ findOptions: {
82
+ projection: projection,
83
+ sort: sort,
84
+ limit: limit,
85
+ skip: skip
86
+ },
87
+ includeTotal: normalized.includeTotal === true
88
+ };
89
+ }
90
+ function userHasView(user, view) {
91
+ var _a, _b, _c;
92
+ if (!user || !view) {
93
+ return false;
94
+ }
95
+ if ((_a = user.roles) === null || _a === void 0 ? void 0 : _a.super_admin) {
96
+ return true;
97
+ }
98
+ var groups = Array.isArray((_b = user.roles) === null || _b === void 0 ? void 0 : _b.groups) ? user.roles.groups : [];
99
+ var miscs = Array.isArray((_c = user.roles) === null || _c === void 0 ? void 0 : _c.miscs) ? user.roles.miscs : [];
100
+ if (groups.some(function (group) { return Array.isArray(group.views) && group.views.some(function (v) { return v.startsWith(view); }); })) {
101
+ return true;
102
+ }
103
+ if (miscs.some(function (v) { return v.startsWith(view); })) {
104
+ return true;
105
+ }
106
+ if (groups.some(function (group) { return group.name === view; })) {
107
+ return true;
108
+ }
109
+ return false;
110
+ }
111
+ function ensureWriteAccess(context, permissionView) {
112
+ return __awaiter(this, void 0, void 0, function () {
113
+ var idUser, user, normalizedPermission;
114
+ var _a;
115
+ return __generator(this, function (_b) {
116
+ switch (_b.label) {
117
+ case 0:
118
+ idUser = context === null || context === void 0 ? void 0 : context.id_user;
119
+ if (!idUser) {
120
+ throw new Error('Mongo Explorer: Unauthorized');
121
+ }
122
+ return [4 /*yield*/, user_collection_1.Users.findOne({ _id: idUser })];
123
+ case 1:
124
+ user = _b.sent();
125
+ if (!user) {
126
+ throw new Error('Mongo Explorer: Unauthorized');
127
+ }
128
+ if (user.readonly) {
129
+ throw new Error('Mongo Explorer: Readonly user');
130
+ }
131
+ if ((_a = user.roles) === null || _a === void 0 ? void 0 : _a.super_admin) {
132
+ return [2 /*return*/];
133
+ }
134
+ normalizedPermission = typeof permissionView === 'string' ? permissionView.trim() : '';
135
+ if (!normalizedPermission) {
136
+ return [2 /*return*/];
137
+ }
138
+ if (userHasView(user, normalizedPermission)) {
139
+ return [2 /*return*/];
140
+ }
141
+ throw new Error('Mongo Explorer: Write access denied');
142
+ }
143
+ });
144
+ });
145
+ }
146
+ function loadMongoExplorerMethods(methodManager) {
147
+ methodManager.methods({
148
+ mongoExplorerListCollections: {
149
+ check: new simpl_schema_1.default({
150
+ database: {
151
+ type: String,
152
+ optional: true
153
+ }
154
+ }),
155
+ function: function (database) {
156
+ return __awaiter(this, void 0, void 0, function () {
157
+ var db, collections;
158
+ return __generator(this, function (_a) {
159
+ switch (_a.label) {
160
+ case 0:
161
+ db = resolveDatabase(database);
162
+ return [4 /*yield*/, db.listCollections().toArray()];
163
+ case 1:
164
+ collections = _a.sent();
165
+ return [2 /*return*/, collections
166
+ .map(function (col) { return ({
167
+ name: col.name,
168
+ type: col.type || 'collection'
169
+ }); })
170
+ .sort(function (a, b) { return a.name.localeCompare(b.name); })];
171
+ }
172
+ });
173
+ });
174
+ }
175
+ },
176
+ mongoExplorerFind: {
177
+ bypassSession: true,
178
+ check: new simpl_schema_1.default({
179
+ database: {
180
+ type: String,
181
+ optional: true
182
+ },
183
+ collection: {
184
+ type: String
185
+ },
186
+ query: {
187
+ type: Object,
188
+ blackbox: true,
189
+ optional: true
190
+ },
191
+ options: {
192
+ type: Object,
193
+ blackbox: true,
194
+ optional: true
195
+ }
196
+ }),
197
+ function: function (database_1, collection_1) {
198
+ return __awaiter(this, arguments, void 0, function (database, collection, query, options) {
199
+ var db, normalized, documents, total;
200
+ if (query === void 0) { query = {}; }
201
+ return __generator(this, function (_a) {
202
+ switch (_a.label) {
203
+ case 0:
204
+ db = resolveDatabase(database);
205
+ normalized = normalizeFindOptions(options);
206
+ return [4 /*yield*/, db.collection(collection).find(query || {}, normalized.findOptions).toArray()];
207
+ case 1:
208
+ documents = _a.sent();
209
+ total = null;
210
+ if (!normalized.includeTotal) return [3 /*break*/, 3];
211
+ return [4 /*yield*/, db.collection(collection).countDocuments(query || {})];
212
+ case 2:
213
+ total = _a.sent();
214
+ _a.label = 3;
215
+ case 3: return [2 /*return*/, {
216
+ documents: documents,
217
+ total: total
218
+ }];
219
+ }
220
+ });
221
+ });
222
+ }
223
+ },
224
+ mongoExplorerAggregate: {
225
+ bypassSession: true,
226
+ check: new simpl_schema_1.default({
227
+ database: {
228
+ type: String,
229
+ optional: true
230
+ },
231
+ collection: {
232
+ type: String
233
+ },
234
+ pipeline: {
235
+ type: Array
236
+ },
237
+ 'pipeline.$': {
238
+ type: Object,
239
+ blackbox: true
240
+ },
241
+ options: {
242
+ type: Object,
243
+ optional: true,
244
+ blackbox: true
245
+ }
246
+ }),
247
+ function: function (database_1, collection_1, pipeline_1) {
248
+ return __awaiter(this, arguments, void 0, function (database, collection, pipeline, options) {
249
+ var db;
250
+ if (options === void 0) { options = {}; }
251
+ return __generator(this, function (_a) {
252
+ db = resolveDatabase(database);
253
+ return [2 /*return*/, db.collection(collection).aggregate(pipeline || [], options || undefined).toArray()];
254
+ });
255
+ });
256
+ }
257
+ },
258
+ mongoExplorerCommand: {
259
+ check: new simpl_schema_1.default({
260
+ database: {
261
+ type: String,
262
+ optional: true
263
+ },
264
+ command: {
265
+ type: Object,
266
+ blackbox: true
267
+ },
268
+ permissionView: {
269
+ type: String,
270
+ optional: true
271
+ }
272
+ }),
273
+ function: function (database, command, permissionView) {
274
+ return __awaiter(this, void 0, void 0, function () {
275
+ var db;
276
+ return __generator(this, function (_a) {
277
+ switch (_a.label) {
278
+ case 0: return [4 /*yield*/, ensureWriteAccess(this, permissionView)];
279
+ case 1:
280
+ _a.sent();
281
+ db = resolveDatabase(database);
282
+ return [2 /*return*/, db.command(command)];
283
+ }
284
+ });
285
+ });
286
+ }
287
+ },
288
+ mongoExplorerInsertDocument: {
289
+ check: new simpl_schema_1.default({
290
+ database: {
291
+ type: String,
292
+ optional: true
293
+ },
294
+ collection: {
295
+ type: String
296
+ },
297
+ document: {
298
+ type: Object,
299
+ blackbox: true
300
+ },
301
+ permissionView: {
302
+ type: String,
303
+ optional: true
304
+ }
305
+ }),
306
+ function: function (database, collection, document, permissionView) {
307
+ return __awaiter(this, void 0, void 0, function () {
308
+ var dbName, _a, managerCollection, dbCollection;
309
+ return __generator(this, function (_b) {
310
+ switch (_b.label) {
311
+ case 0: return [4 /*yield*/, ensureWriteAccess(this, permissionView)];
312
+ case 1:
313
+ _b.sent();
314
+ dbName = resolveDatabaseName(database);
315
+ _a = resolveCollectionHandle(dbName, collection), managerCollection = _a.managerCollection, dbCollection = _a.dbCollection;
316
+ if (!document || typeof document !== 'object') {
317
+ throw new Error('Mongo Explorer: Document is required');
318
+ }
319
+ if (!document._id) {
320
+ document._id = (0, common_1.objectIdHexString)();
321
+ }
322
+ if (document.__v === undefined) {
323
+ document.__v = 0;
324
+ }
325
+ if (!managerCollection) return [3 /*break*/, 3];
326
+ return [4 /*yield*/, managerCollection.insertOne(document)];
327
+ case 2:
328
+ _b.sent();
329
+ return [3 /*break*/, 5];
330
+ case 3: return [4 /*yield*/, dbCollection.insertOne(document)];
331
+ case 4:
332
+ _b.sent();
333
+ _b.label = 5;
334
+ case 5: return [2 /*return*/, document._id];
335
+ }
336
+ });
337
+ });
338
+ }
339
+ },
340
+ mongoExplorerReplaceDocument: {
341
+ check: new simpl_schema_1.default({
342
+ database: {
343
+ type: String,
344
+ optional: true
345
+ },
346
+ collection: {
347
+ type: String
348
+ },
349
+ document: {
350
+ type: Object,
351
+ blackbox: true
352
+ },
353
+ permissionView: {
354
+ type: String,
355
+ optional: true
356
+ }
357
+ }),
358
+ function: function (database, collection, document, permissionView) {
359
+ return __awaiter(this, void 0, void 0, function () {
360
+ var dbName, _a, managerCollection, dbCollection;
361
+ return __generator(this, function (_b) {
362
+ switch (_b.label) {
363
+ case 0: return [4 /*yield*/, ensureWriteAccess(this, permissionView)];
364
+ case 1:
365
+ _b.sent();
366
+ dbName = resolveDatabaseName(database);
367
+ _a = resolveCollectionHandle(dbName, collection), managerCollection = _a.managerCollection, dbCollection = _a.dbCollection;
368
+ if (!document || typeof document !== 'object' || !document._id) {
369
+ throw new Error('Mongo Explorer: Document with _id is required');
370
+ }
371
+ if (!managerCollection) return [3 /*break*/, 3];
372
+ return [4 /*yield*/, managerCollection.replaceOne({ _id: document._id }, document)];
373
+ case 2:
374
+ _b.sent();
375
+ return [3 /*break*/, 5];
376
+ case 3: return [4 /*yield*/, dbCollection.replaceOne({ _id: document._id }, document)];
377
+ case 4:
378
+ _b.sent();
379
+ _b.label = 5;
380
+ case 5: return [2 /*return*/, true];
381
+ }
382
+ });
383
+ });
384
+ }
385
+ },
386
+ mongoExplorerDeleteDocument: {
387
+ check: new simpl_schema_1.default({
388
+ database: {
389
+ type: String,
390
+ optional: true
391
+ },
392
+ collection: {
393
+ type: String
394
+ },
395
+ doc_id: {
396
+ type: String
397
+ },
398
+ permissionView: {
399
+ type: String,
400
+ optional: true
401
+ }
402
+ }),
403
+ function: function (database, collection, doc_id, permissionView) {
404
+ return __awaiter(this, void 0, void 0, function () {
405
+ var dbName, _a, managerCollection, dbCollection, deleteFilter;
406
+ return __generator(this, function (_b) {
407
+ switch (_b.label) {
408
+ case 0: return [4 /*yield*/, ensureWriteAccess(this, permissionView)];
409
+ case 1:
410
+ _b.sent();
411
+ dbName = resolveDatabaseName(database);
412
+ _a = resolveCollectionHandle(dbName, collection), managerCollection = _a.managerCollection, dbCollection = _a.dbCollection;
413
+ deleteFilter = { _id: doc_id };
414
+ if (!managerCollection) return [3 /*break*/, 3];
415
+ return [4 /*yield*/, managerCollection.deleteOne(deleteFilter)];
416
+ case 2:
417
+ _b.sent();
418
+ return [3 /*break*/, 5];
419
+ case 3: return [4 /*yield*/, dbCollection.deleteOne(deleteFilter)];
420
+ case 4:
421
+ _b.sent();
422
+ _b.label = 5;
423
+ case 5: return [2 /*return*/, true];
424
+ }
425
+ });
426
+ });
427
+ }
428
+ }
429
+ });
430
+ }
431
+
432
+ //# sourceMappingURL=mongo-explorer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/methods/mongo-explorer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgIA,4DA8NC;AA9VD,6CAAwC;AAExC,kEAAuD;AAEvD,gEAA0D;AAC1D,yCAAmD;AAEnD,IAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,IAAM,SAAS,GAAG,IAAI,CAAC;AAUvB,SAAS,mBAAmB,CAAC,QAAiB;;IAC7C,IAAM,SAAS,GAAG,CAAA,MAAA,sCAAe,CAAC,eAAe,EAAE,0CAAE,QAAQ,KAAI,EAAE,CAAC;IACpE,IAAM,MAAM,GAAG,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAEpG,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACzD,CAAC;IAED,IAAM,gBAAgB,GAAG,CAAA,MAAA,sCAAe,CAAC,eAAe,EAAE,0CAAE,mBAAmB,EAAE,KAAI,EAAE,CAAC;IACxF,IAAI,gBAAgB,CA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MAAM;iBACZ;gBACD,cAAc,EAAE;oBACf,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,IAAI;iBACd;aACD,CAAC;YACD,QAAQ,EAAE,UAAe,QAAgB,EAAE,UAAkB,EAAE,MAAc,EAAE,cAAuB;;;;;oCACrG,qBAAM,iBAAiB,CAAC,IAAI,EAAE,cAAc,CAAC,EAAA;;gCAA7C,SAA6C,CAAC;gCACxC,MAAM,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;gCACvC,KAAsC,uBAAuB,CAAC,MAAM,EAAE,UAAU,CAAC,EAA/E,iBAAiB,uBAAA,EAAE,YAAY,kBAAA,CAAiD;gCAClF,YAAY,GAAG,EAAE,GAAG,EAAE,MAAM,EAAS,CAAC;qCAExC,iBAAiB,EAAjB,wBAAiB;gCACpB,qBAAM,iBAAiB,CAAC,SAAS,CAAC,YAAY,CAAC,EAAA;;gCAA/C,SAA+C,CAAC;;oCAGhD,qBAAM,YAAY,CAAC,SAAS,CAAC,YAAY,CAAC,EAAA;;gCAA1C,SAA0C,CAAC;;oCAG7C,sBAAO,IAAI,EAAC;;;;aACZ;SACD;KACD,CAAC,CAAC;AACJ,CAAC","file":"mongo-explorer.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { Db } from 'mongodb';\nimport { Users } from '../collections/user.collection';\nimport { MethodManager } from '../managers/method.manager';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { objectIdHexString } from '../util/common';\n\nconst DEFAULT_LIMIT = 100;\nconst MAX_LIMIT = 2000;\n\ntype ExplorerFindOptions = {\n\tprojection?: Record<string, number>;\n\tsort?: Record<string, any>;\n\tlimit?: number;\n\tskip?: number;\n\tincludeTotal?: boolean;\n};\n\nfunction resolveDatabaseName(database?: string): string {\n\tconst defaultDb = ResolveIOServer.getServerConfig()?.DATABASE || '';\n\tconst dbName = typeof database === 'string' && database.trim().length ? database.trim() : defaultDb;\n\n\tif (!dbName) {\n\t\tthrow new Error('Mongo Explorer: Database is required');\n\t}\n\n\tconst allowedDatabases = ResolveIOServer.getMongoManager()?.getWatchedDatabases() || [];\n\tif (allowedDatabases.length && !allowedDatabases.includes(dbName)) {\n\t\tthrow new Error('Mongo Explorer: Database access denied');\n\t}\n\n\treturn dbName;\n}\n\nfunction resolveDatabase(database?: string): Db {\n\tconst dbName = resolveDatabaseName(database);\n\treturn ResolveIOServer.getMongoConnection().db(dbName);\n}\n\nfunction resolveCollectionHandle(database: string, collection: string) {\n\tconst mainDb = ResolveIOServer.getServerConfig()?.DATABASE || '';\n\tconst isMainDb = database === mainDb;\n\tconst managerCollection = isMainDb ? ResolveIOServer.getMongoManager()?.collection(collection) : null;\n\tconst db = ResolveIOServer.getMongoConnection().db(database);\n\n\treturn {\n\t\tmanagerCollection,\n\t\tdbCollection: db.collection(collection)\n\t};\n}\n\nfunction normalizeFindOptions(options?: ExplorerFindOptions) {\n\tconst normalized = options || {};\n\tconst projection = normalized.projection && Object.keys(normalized.projection).length ? normalized.projection : undefined;\n\tconst sort = normalized.sort && Object.keys(normalized.sort).length ? normalized.sort : undefined;\n\tconst limit = typeof normalized.limit === 'number' ? Math.min(Math.max(normalized.limit, 0), MAX_LIMIT) : DEFAULT_LIMIT;\n\tconst skip = typeof normalized.skip === 'number' ? Math.max(normalized.skip, 0) : 0;\n\n\treturn {\n\t\tfindOptions: {\n\t\t\tprojection,\n\t\t\tsort,\n\t\t\tlimit,\n\t\t\tskip\n\t\t},\n\t\tincludeTotal: normalized.includeTotal === true\n\t};\n}\n\nfunction userHasView(user, view: string): boolean {\n\tif (!user || !view) {\n\t\treturn false;\n\t}\n\n\tif (user.roles?.super_admin) {\n\t\treturn true;\n\t}\n\n\tconst groups = Array.isArray(user.roles?.groups) ? user.roles.groups : [];\n\tconst miscs = Array.isArray(user.roles?.miscs) ? user.roles.miscs : [];\n\n\tif (groups.some(group => Array.isArray(group.views) && group.views.some(v => v.startsWith(view)))) {\n\t\treturn true;\n\t}\n\n\tif (miscs.some(v => v.startsWith(view))) {\n\t\treturn true;\n\t}\n\n\tif (groups.some(group => group.name === view)) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\nasync function ensureWriteAccess(context: any, permissionView?: string) {\n\tconst idUser = context?.id_user;\n\tif (!idUser) {\n\t\tthrow new Error('Mongo Explorer: Unauthorized');\n\t}\n\n\tconst user = await Users.findOne({_id: idUser});\n\tif (!user) {\n\t\tthrow new Error('Mongo Explorer: Unauthorized');\n\t}\n\n\tif (user.readonly) {\n\t\tthrow new Error('Mongo Explorer: Readonly user');\n\t}\n\n\tif (user.roles?.super_admin) {\n\t\treturn;\n\t}\n\n\tconst normalizedPermission = typeof permissionView === 'string' ? permissionView.trim() : '';\n\n\tif (!normalizedPermission) {\n\t\treturn;\n\t}\n\n\tif (userHasView(user, normalizedPermission)) {\n\t\treturn;\n\t}\n\n\tthrow new Error('Mongo Explorer: Write access denied');\n}\n\nexport function loadMongoExplorerMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tmongoExplorerListCollections: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tdatabase: {\n\t\t\t\t\ttype: String,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(database?: string) {\n\t\t\t\tconst db = resolveDatabase(database);\n\t\t\t\tconst collections = await db.listCollections().toArray();\n\t\t\t\treturn collections\n\t\t\t\t\t.map(col => ({\n\t\t\t\t\t\tname: col.name,\n\t\t\t\t\t\ttype: col.type || 'collection'\n\t\t\t\t\t}))\n\t\t\t\t\t.sort((a, b) => a.name.localeCompare(b.name));\n\t\t\t}\n\t\t},\n\t\tmongoExplorerFind: {\n\t\t\tbypassSession: true,\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tdatabase: {\n\t\t\t\t\ttype: String,\n\t\t\t\t\toptional: true\n\t\t\t\t},\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true,\n\t\t\t\t\toptional: true\n\t\t\t\t},\n\t\t\t\toptions: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(database: string, collection: string, query: any = {}, options?: ExplorerFindOptions) {\n\t\t\t\tconst db = resolveDatabase(database);\n\t\t\t\tconst normalized = normalizeFindOptions(options);\n\t\t\t\tconst documents = await db.collection(collection).find(query || {}, normalized.findOptions).toArray();\n\t\t\t\tlet total = null;\n\n\t\t\t\tif (normalized.includeTotal) {\n\t\t\t\t\ttotal = await db.collection(collection).countDocuments(query || {});\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tdocuments,\n\t\t\t\t\ttotal\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t\tmongoExplorerAggregate: {\n\t\t\tbypassSession: true,\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tdatabase: {\n\t\t\t\t\ttype: String,\n\t\t\t\t\toptional: true\n\t\t\t\t},\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tpipeline: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'pipeline.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\toptions: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\toptional: true,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(database: string, collection: string, pipeline: any[], options: any = {}) {\n\t\t\t\tconst db = resolveDatabase(database);\n\t\t\t\treturn db.collection(collection).aggregate(pipeline || [], options || undefined).toArray();\n\t\t\t}\n\t\t},\n\t\tmongoExplorerCommand: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tdatabase: {\n\t\t\t\t\ttype: String,\n\t\t\t\t\toptional: true\n\t\t\t\t},\n\t\t\t\tcommand: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tpermissionView: {\n\t\t\t\t\ttype: String,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(database: string, command: any, permissionView?: string) {\n\t\t\t\tawait ensureWriteAccess(this, permissionView);\n\t\t\t\tconst db = resolveDatabase(database);\n\t\t\t\treturn db.command(command);\n\t\t\t}\n\t\t},\n\t\tmongoExplorerInsertDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tdatabase: {\n\t\t\t\t\ttype: String,\n\t\t\t\t\toptional: true\n\t\t\t\t},\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdocument: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tpermissionView: {\n\t\t\t\t\ttype: String,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(database: string, collection: string, document: any, permissionView?: string) {\n\t\t\t\tawait ensureWriteAccess(this, permissionView);\n\t\t\t\tconst dbName = resolveDatabaseName(database);\n\t\t\t\tconst { managerCollection, dbCollection } = resolveCollectionHandle(dbName, collection);\n\n\t\t\t\tif (!document || typeof document !== 'object') {\n\t\t\t\t\tthrow new Error('Mongo Explorer: Document is required');\n\t\t\t\t}\n\n\t\t\t\tif (!document._id) {\n\t\t\t\t\tdocument._id = objectIdHexString();\n\t\t\t\t}\n\n\t\t\t\tif (document.__v === undefined) {\n\t\t\t\t\tdocument.__v = 0;\n\t\t\t\t}\n\n\t\t\t\tif (managerCollection) {\n\t\t\t\t\tawait managerCollection.insertOne(document);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tawait dbCollection.insertOne(document);\n\t\t\t\t}\n\n\t\t\t\treturn document._id;\n\t\t\t}\n\t\t},\n\t\tmongoExplorerReplaceDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tdatabase: {\n\t\t\t\t\ttype: String,\n\t\t\t\t\toptional: true\n\t\t\t\t},\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdocument: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tpermissionView: {\n\t\t\t\t\ttype: String,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(database: string, collection: string, document: any, permissionView?: string) {\n\t\t\t\tawait ensureWriteAccess(this, permissionView);\n\t\t\t\tconst dbName = resolveDatabaseName(database);\n\t\t\t\tconst { managerCollection, dbCollection } = resolveCollectionHandle(dbName, collection);\n\n\t\t\t\tif (!document || typeof document !== 'object' || !document._id) {\n\t\t\t\t\tthrow new Error('Mongo Explorer: Document with _id is required');\n\t\t\t\t}\n\n\t\t\t\tif (managerCollection) {\n\t\t\t\t\tawait managerCollection.replaceOne({_id: document._id}, document);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tawait dbCollection.replaceOne({_id: document._id}, document);\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\tmongoExplorerDeleteDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tdatabase: {\n\t\t\t\t\ttype: String,\n\t\t\t\t\toptional: true\n\t\t\t\t},\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdoc_id: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tpermissionView: {\n\t\t\t\t\ttype: String,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\t\tfunction: async function(database: string, collection: string, doc_id: string, permissionView?: string) {\n\t\t\t\t\tawait ensureWriteAccess(this, permissionView);\n\t\t\t\t\tconst dbName = resolveDatabaseName(database);\n\t\t\t\t\tconst { managerCollection, dbCollection } = resolveCollectionHandle(dbName, collection);\n\t\t\t\t\tconst deleteFilter = { _id: doc_id } as any;\n\n\t\t\t\t\tif (managerCollection) {\n\t\t\t\t\t\tawait managerCollection.deleteOne(deleteFilter);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tawait dbCollection.deleteOne(deleteFilter);\n\t\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t});\n}\n"]}
package/methods.ts CHANGED
@@ -96,6 +96,27 @@ export function SERVER_METHODS(resolveioServer) {
96
96
  mergePDFResolveNoSave: (fileKeys: string[], cb?: Function): Promise<any> => {
97
97
  return resolveioServer.call('mergePDFResolveNoSave', fileKeys, cb);
98
98
  },
99
+ mongoExplorerAggregate: (database: string, collection: string, pipeline: any[], options: any = {}, cb?: Function): Promise<any> => {
100
+ return resolveioServer.call('mongoExplorerAggregate', database, collection, pipeline, options, cb);
101
+ },
102
+ mongoExplorerCommand: (database: string, command: any, permissionView?: string, cb?: Function): Promise<any> => {
103
+ return resolveioServer.call('mongoExplorerCommand', database, command, permissionView, cb);
104
+ },
105
+ mongoExplorerDeleteDocument: (database: string, collection: string, doc_id: string, permissionView?: string, cb?: Function): Promise<any> => {
106
+ return resolveioServer.call('mongoExplorerDeleteDocument', database, collection, doc_id, permissionView, cb);
107
+ },
108
+ mongoExplorerFind: (database: string, collection: string, query: any = {}, options?: ExplorerFindOptions, cb?: Function): Promise<any> => {
109
+ return resolveioServer.call('mongoExplorerFind', database, collection, query, options, cb);
110
+ },
111
+ mongoExplorerInsertDocument: (database: string, collection: string, document: any, permissionView?: string, cb?: Function): Promise<any> => {
112
+ return resolveioServer.call('mongoExplorerInsertDocument', database, collection, document, permissionView, cb);
113
+ },
114
+ mongoExplorerListCollections: (database?: string, cb?: Function): Promise<any> => {
115
+ return resolveioServer.call('mongoExplorerListCollections', database, cb);
116
+ },
117
+ mongoExplorerReplaceDocument: (database: string, collection: string, document: any, permissionView?: string, cb?: Function): Promise<any> => {
118
+ return resolveioServer.call('mongoExplorerReplaceDocument', database, collection, document, permissionView, cb);
119
+ },
99
120
  monitorCPUs: (cb?: Function): Promise<any> => {
100
121
  return resolveioServer.call('monitorCPUs', cb);
101
122
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "20.12.71",
3
+ "version": "20.13.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "package": "./build_package.sh",
package/server-app.js CHANGED
@@ -1263,7 +1263,7 @@ var ResolveIOMainServer = /** @class */ (function () {
1263
1263
  }
1264
1264
  if (!(method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'getDrivers' && method !== 'processAirdropDistribution' && method !== 'qbHandleResponse')) return [3 /*break*/, 8];
1265
1265
  if (!(resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'https://resolveio.com'
1266
- && resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200' && resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4201')) return [3 /*break*/, 6];
1266
+ && resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200')) return [3 /*break*/, 6];
1267
1267
  resolveio_server_app_1.ResolveIOServer.getLocalLogManager().writeLog({
1268
1268
  type: 'log',
1269
1269
  data: {
@@ -1340,7 +1340,7 @@ var ResolveIOMainServer = /** @class */ (function () {
1340
1340
  }
1341
1341
  if (!(methodName !== 'reportBuilderGetResults' && methodName !== 'reportBuilderGetDistinctValue' && methodName !== 'reportBuilderBuildTree' && methodName !== 'generatePDF' && methodName !== 'getWOOfflineData' && methodName !== 'countQuery' && methodName !== 'countWithQuery' && methodName !== 'countCollectionWithQuery' && methodName !== 'find' && methodName !== 'findOne' && methodName !== 'findWithOptions' && methodName !== 'getDrivers' && methodName !== 'processAirdropDistribution')) return [3 /*break*/, 19];
1342
1342
  if (!(resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'https://resolveio.com'
1343
- && resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200' && resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4201')) return [3 /*break*/, 17];
1343
+ && resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200')) return [3 /*break*/, 17];
1344
1344
  resolveio_server_app_1.ResolveIOServer.getLocalLogManager().writeLog({
1345
1345
  type: 'log',
1346
1346
  data: {