@steedos/objectql 3.0.13-beta.5 → 3.0.13-beta.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/lib/actions/field_updates.js +84 -153
  2. package/lib/actions/field_updates.js.map +1 -1
  3. package/lib/actions/index.js +1 -1
  4. package/lib/actions/workflow_notifications.js +50 -111
  5. package/lib/actions/workflow_notifications.js.map +1 -1
  6. package/lib/actions/workflow_outbound_messages.js +43 -94
  7. package/lib/actions/workflow_outbound_messages.js.map +1 -1
  8. package/lib/actions/workflow_rule.js +80 -177
  9. package/lib/actions/workflow_rule.js.map +1 -1
  10. package/lib/broker.js +19 -49
  11. package/lib/broker.js.map +1 -1
  12. package/lib/driver/field-encrytion/index.js +1 -1
  13. package/lib/driver/field-encrytion/mongosharedconst.js +17 -17
  14. package/lib/driver/field-encrytion/mongosharedconst.js.map +1 -1
  15. package/lib/driver/format.js +3 -3
  16. package/lib/driver/format.js.map +1 -1
  17. package/lib/driver/index.js +1 -1
  18. package/lib/driver/metadata.js +286 -387
  19. package/lib/driver/metadata.js.map +1 -1
  20. package/lib/driver/metadataOld.js +104 -105
  21. package/lib/driver/metadataOld.js.map +1 -1
  22. package/lib/driver/meteorMongo.js +5 -8
  23. package/lib/driver/meteorMongo.js.map +1 -1
  24. package/lib/driver/mongo.js +321 -506
  25. package/lib/driver/mongo.js.map +1 -1
  26. package/lib/driver/mysql.js +16 -20
  27. package/lib/driver/mysql.js.map +1 -1
  28. package/lib/driver/oracle.js +25 -38
  29. package/lib/driver/oracle.js.map +1 -1
  30. package/lib/driver/postgres.js +16 -20
  31. package/lib/driver/postgres.js.map +1 -1
  32. package/lib/driver/sqlite3.js +15 -19
  33. package/lib/driver/sqlite3.js.map +1 -1
  34. package/lib/driver/sqlserver.js +20 -33
  35. package/lib/driver/sqlserver.js.map +1 -1
  36. package/lib/errors/index.js +10 -11
  37. package/lib/errors/index.js.map +1 -1
  38. package/lib/formula/core.js +307 -594
  39. package/lib/formula/core.js.map +1 -1
  40. package/lib/formula/field_formula.js +80 -126
  41. package/lib/formula/field_formula.js.map +1 -1
  42. package/lib/formula/index.js +56 -97
  43. package/lib/formula/index.js.map +1 -1
  44. package/lib/formula/params.js +11 -11
  45. package/lib/formula/params.js.map +1 -1
  46. package/lib/formula/recompute.js +41 -166
  47. package/lib/formula/recompute.js.map +1 -1
  48. package/lib/formula/simple_params.js +12 -12
  49. package/lib/formula/simple_params.js.map +1 -1
  50. package/lib/formula/util.js +43 -67
  51. package/lib/formula/util.js.map +1 -1
  52. package/lib/functions/function.js +62 -87
  53. package/lib/functions/function.js.map +1 -1
  54. package/lib/index.js +3 -3
  55. package/lib/index.js.map +1 -1
  56. package/lib/services/datasourceServiceFactory.js +77 -111
  57. package/lib/services/datasourceServiceFactory.js.map +1 -1
  58. package/lib/services/index.js +3 -3
  59. package/lib/services/index.js.map +1 -1
  60. package/lib/summary/core.js +162 -355
  61. package/lib/summary/core.js.map +1 -1
  62. package/lib/summary/field_summary.js +44 -71
  63. package/lib/summary/field_summary.js.map +1 -1
  64. package/lib/summary/index.js +65 -80
  65. package/lib/summary/index.js.map +1 -1
  66. package/lib/summary/recompute.js +19 -47
  67. package/lib/summary/recompute.js.map +1 -1
  68. package/lib/triggers/trigger.js +101 -142
  69. package/lib/triggers/trigger.js.map +1 -1
  70. package/lib/ts-types/index.js +1 -1
  71. package/lib/typeorm/driver.js +250 -450
  72. package/lib/typeorm/driver.js.map +1 -1
  73. package/lib/typeorm/index.js +1 -1
  74. package/lib/typeorm/util.js +28 -28
  75. package/lib/typeorm/util.js.map +1 -1
  76. package/lib/types/action.js +24 -33
  77. package/lib/types/action.js.map +1 -1
  78. package/lib/types/app.js +210 -355
  79. package/lib/types/app.js.map +1 -1
  80. package/lib/types/connection.js +42 -78
  81. package/lib/types/connection.js.map +1 -1
  82. package/lib/types/dashboard.js +56 -77
  83. package/lib/types/dashboard.js.map +1 -1
  84. package/lib/types/datasource.js +359 -705
  85. package/lib/types/datasource.js.map +1 -1
  86. package/lib/types/defaultValue.js +53 -65
  87. package/lib/types/defaultValue.js.map +1 -1
  88. package/lib/types/field.js +165 -137
  89. package/lib/types/field.js.map +1 -1
  90. package/lib/types/field_permission.js +35 -66
  91. package/lib/types/field_permission.js.map +1 -1
  92. package/lib/types/index.js +1 -1
  93. package/lib/types/list_view.js +36 -43
  94. package/lib/types/list_view.js.map +1 -1
  95. package/lib/types/metadata.js +6 -6
  96. package/lib/types/metadata.js.map +1 -1
  97. package/lib/types/method_base.js +95 -128
  98. package/lib/types/method_base.js.map +1 -1
  99. package/lib/types/object.js +2005 -3015
  100. package/lib/types/object.js.map +1 -1
  101. package/lib/types/object_events.js +24 -37
  102. package/lib/types/object_events.js.map +1 -1
  103. package/lib/types/object_layouts.js +15 -38
  104. package/lib/types/object_layouts.js.map +1 -1
  105. package/lib/types/object_permission.js +99 -85
  106. package/lib/types/object_permission.js.map +1 -1
  107. package/lib/types/report.js +70 -98
  108. package/lib/types/report.js.map +1 -1
  109. package/lib/types/restrictionRule.js +47 -96
  110. package/lib/types/restrictionRule.js.map +1 -1
  111. package/lib/types/schema.js +115 -177
  112. package/lib/types/schema.js.map +1 -1
  113. package/lib/types/shareRule.js +53 -102
  114. package/lib/types/shareRule.js.map +1 -1
  115. package/lib/types/trigger.js +43 -56
  116. package/lib/types/trigger.js.map +1 -1
  117. package/lib/types/validation_rules.js +18 -56
  118. package/lib/types/validation_rules.js.map +1 -1
  119. package/lib/util/convert.js +24 -24
  120. package/lib/util/convert.js.map +1 -1
  121. package/lib/util/field.js +16 -28
  122. package/lib/util/field.js.map +1 -1
  123. package/lib/util/function_expression.js +7 -8
  124. package/lib/util/function_expression.js.map +1 -1
  125. package/lib/util/index.js +79 -97
  126. package/lib/util/index.js.map +1 -1
  127. package/lib/util/locale.js +4 -4
  128. package/lib/util/locale.js.map +1 -1
  129. package/lib/util/permission_shares.js +7 -7
  130. package/lib/util/permission_shares.js.map +1 -1
  131. package/lib/util/suffix.js +19 -19
  132. package/lib/util/suffix.js.map +1 -1
  133. package/lib/util/transform.js +1 -1
  134. package/lib/validators/index.js +10 -10
  135. package/lib/validators/index.js.map +1 -1
  136. package/package.json +12 -12
package/lib/types/app.js CHANGED
@@ -2,395 +2,250 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAssignedMenus = exports.getAssignedApps = exports.getAppConfig = exports.removeApp = exports.getAppConfigs = exports.addAppConfig = exports.SteedosAppType = void 0;
4
4
  exports.addAppConfigFiles = addAppConfigFiles;
5
- var tslib_1 = require("tslib");
6
- var _1 = require(".");
7
- var metadata_registrar_1 = require("@steedos/metadata-registrar");
8
- var _ = require("underscore");
9
- var _l = require("lodash");
10
- var SteedosAppType = (function () {
11
- function SteedosAppType(config, datasource) {
12
- var _this = this;
13
- this.properties = ['is_creator'];
5
+ const _1 = require(".");
6
+ const metadata_registrar_1 = require("@steedos/metadata-registrar");
7
+ const _ = require("underscore");
8
+ const _l = require("lodash");
9
+ class SteedosAppType {
10
+ _datasource;
11
+ get datasource() {
12
+ return this._datasource;
13
+ }
14
+ __id;
15
+ get _id() {
16
+ return this.__id;
17
+ }
18
+ set _id(value) {
19
+ this.__id = value;
20
+ }
21
+ _name;
22
+ get name() {
23
+ return this._name;
24
+ }
25
+ set name(value) {
26
+ this._name = value;
27
+ }
28
+ _description;
29
+ get description() {
30
+ return this._description;
31
+ }
32
+ set description(value) {
33
+ this._description = value;
34
+ }
35
+ _icon_slds;
36
+ get icon_slds() {
37
+ return this._icon_slds;
38
+ }
39
+ set icon_slds(value) {
40
+ this._icon_slds = value;
41
+ }
42
+ _objects;
43
+ get objects() {
44
+ return this._objects;
45
+ }
46
+ set objects(value) {
47
+ this._objects = value;
48
+ }
49
+ _is_creator;
50
+ get is_creator() {
51
+ return this._is_creator;
52
+ }
53
+ _mobile_objects;
54
+ get mobile_objects() {
55
+ return this._mobile_objects;
56
+ }
57
+ set mobile_objects(value) {
58
+ this._mobile_objects = value;
59
+ }
60
+ properties = ['is_creator'];
61
+ constructor(config, datasource) {
14
62
  this._datasource = datasource;
15
63
  this._is_creator = true;
16
64
  this._id = config._id;
17
- _.each(config, function (value, key) {
65
+ _.each(config, (value, key) => {
18
66
  if (key != 'is_creator') {
19
- _this[key] = value;
20
- _this.properties.push(key);
67
+ this[key] = value;
68
+ this.properties.push(key);
21
69
  }
22
70
  });
23
71
  }
24
- Object.defineProperty(SteedosAppType.prototype, "datasource", {
25
- get: function () {
26
- return this._datasource;
27
- },
28
- enumerable: false,
29
- configurable: true
30
- });
31
- Object.defineProperty(SteedosAppType.prototype, "_id", {
32
- get: function () {
33
- return this.__id;
34
- },
35
- set: function (value) {
36
- this.__id = value;
37
- },
38
- enumerable: false,
39
- configurable: true
40
- });
41
- Object.defineProperty(SteedosAppType.prototype, "name", {
42
- get: function () {
43
- return this._name;
44
- },
45
- set: function (value) {
46
- this._name = value;
47
- },
48
- enumerable: false,
49
- configurable: true
50
- });
51
- Object.defineProperty(SteedosAppType.prototype, "description", {
52
- get: function () {
53
- return this._description;
54
- },
55
- set: function (value) {
56
- this._description = value;
57
- },
58
- enumerable: false,
59
- configurable: true
60
- });
61
- Object.defineProperty(SteedosAppType.prototype, "icon_slds", {
62
- get: function () {
63
- return this._icon_slds;
64
- },
65
- set: function (value) {
66
- this._icon_slds = value;
67
- },
68
- enumerable: false,
69
- configurable: true
70
- });
71
- Object.defineProperty(SteedosAppType.prototype, "objects", {
72
- get: function () {
73
- return this._objects;
74
- },
75
- set: function (value) {
76
- this._objects = value;
77
- },
78
- enumerable: false,
79
- configurable: true
80
- });
81
- Object.defineProperty(SteedosAppType.prototype, "is_creator", {
82
- get: function () {
83
- return this._is_creator;
84
- },
85
- enumerable: false,
86
- configurable: true
87
- });
88
- Object.defineProperty(SteedosAppType.prototype, "mobile_objects", {
89
- get: function () {
90
- return this._mobile_objects;
91
- },
92
- set: function (value) {
93
- this._mobile_objects = value;
94
- },
95
- enumerable: false,
96
- configurable: true
97
- });
98
- SteedosAppType.prototype.toConfig = function () {
99
- var _this = this;
100
- var config = {};
101
- this.properties.forEach(function (property) {
102
- config[property] = _this[property];
72
+ toConfig() {
73
+ let config = {};
74
+ this.properties.forEach((property) => {
75
+ config[property] = this[property];
103
76
  });
104
77
  return config;
105
- };
106
- SteedosAppType.prototype.transformReferenceTo = function (reference_to, datasource) {
78
+ }
79
+ transformReferenceTo(reference_to, datasource) {
107
80
  if (_.isString(reference_to)) {
108
81
  if (reference_to.split('.').length = 1) {
109
82
  if (datasource.getObject(reference_to)) {
110
- return "".concat(datasource.name, ".").concat(reference_to);
83
+ return `${datasource.name}.${reference_to}`;
111
84
  }
112
85
  }
113
86
  }
114
87
  return reference_to;
115
- };
116
- SteedosAppType.prototype.transformReferenceOfObject = function () {
117
- var _this = this;
118
- var datasource = this._datasource;
88
+ }
89
+ transformReferenceOfObject() {
90
+ let datasource = this._datasource;
119
91
  if (datasource.name != 'meteor') {
120
92
  if (_.isArray(this.objects)) {
121
- var objects_1 = [];
122
- _.each(this.objects, function (object_name) {
123
- objects_1.push(_this.transformReferenceTo(object_name, datasource));
93
+ let objects = [];
94
+ _.each(this.objects, (object_name) => {
95
+ objects.push(this.transformReferenceTo(object_name, datasource));
124
96
  });
125
- this.objects = objects_1;
97
+ this.objects = objects;
126
98
  }
127
99
  }
128
- };
129
- return SteedosAppType;
130
- }());
100
+ }
101
+ }
131
102
  exports.SteedosAppType = SteedosAppType;
132
- function addAppConfigFiles(filePath, serviceName) {
133
- return tslib_1.__awaiter(this, void 0, void 0, function () {
134
- var configs, configs_1, configs_1_1, config, e_1_1;
135
- var e_1, _a;
136
- return tslib_1.__generator(this, function (_b) {
137
- switch (_b.label) {
138
- case 0:
139
- configs = (0, metadata_registrar_1.getConfigsFormFiles)('app', filePath);
140
- _b.label = 1;
141
- case 1:
142
- _b.trys.push([1, 6, 7, 8]);
143
- configs_1 = tslib_1.__values(configs), configs_1_1 = configs_1.next();
144
- _b.label = 2;
145
- case 2:
146
- if (!!configs_1_1.done) return [3, 5];
147
- config = configs_1_1.value;
148
- return [4, (0, exports.addAppConfig)(config, serviceName)];
149
- case 3:
150
- _b.sent();
151
- _b.label = 4;
152
- case 4:
153
- configs_1_1 = configs_1.next();
154
- return [3, 2];
155
- case 5: return [3, 8];
156
- case 6:
157
- e_1_1 = _b.sent();
158
- e_1 = { error: e_1_1 };
159
- return [3, 8];
160
- case 7:
161
- try {
162
- if (configs_1_1 && !configs_1_1.done && (_a = configs_1.return)) _a.call(configs_1);
163
- }
164
- finally { if (e_1) throw e_1.error; }
165
- return [7];
166
- case 8: return [2];
167
- }
168
- });
169
- });
103
+ async function addAppConfigFiles(filePath, serviceName) {
104
+ const configs = (0, metadata_registrar_1.getConfigsFormFiles)('app', filePath);
105
+ for (const config of configs) {
106
+ await (0, exports.addAppConfig)(config, serviceName);
107
+ }
170
108
  }
171
- var addAppConfig = function (appConfig_1) {
172
- var args_1 = [];
173
- for (var _i = 1; _i < arguments.length; _i++) {
174
- args_1[_i - 1] = arguments[_i];
109
+ const addAppConfig = async (appConfig, serviceName = '') => {
110
+ const schema = (0, _1.getSteedosSchema)();
111
+ await schema.metadataRegister.addApp(serviceName, appConfig);
112
+ };
113
+ exports.addAppConfig = addAppConfig;
114
+ const getAppConfigs = async (spaceId) => {
115
+ const schema = (0, _1.getSteedosSchema)();
116
+ if (!schema.metadataRegister) {
117
+ return (0, metadata_registrar_1.getConfigs)('app');
175
118
  }
176
- return tslib_1.__awaiter(void 0, tslib_1.__spreadArray([appConfig_1], tslib_1.__read(args_1), false), void 0, function (appConfig, serviceName) {
177
- var schema;
178
- if (serviceName === void 0) { serviceName = ''; }
179
- return tslib_1.__generator(this, function (_a) {
180
- switch (_a.label) {
181
- case 0:
182
- schema = (0, _1.getSteedosSchema)();
183
- return [4, schema.metadataRegister.addApp(serviceName, appConfig)];
184
- case 1:
185
- _a.sent();
186
- return [2];
119
+ const apps = await schema.metadataRegister.getApps();
120
+ const configs = _.pluck(apps, 'metadata');
121
+ if (spaceId) {
122
+ let _apps = _.filter(configs, function (config) {
123
+ if (_.has(config, 'space') && config.space) {
124
+ return config.space === spaceId;
187
125
  }
126
+ return true;
188
127
  });
189
- });
190
- };
191
- exports.addAppConfig = addAppConfig;
192
- var getAppConfigs = function (spaceId) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
193
- var schema, apps, configs, _apps, result_1;
194
- return tslib_1.__generator(this, function (_a) {
195
- switch (_a.label) {
196
- case 0:
197
- schema = (0, _1.getSteedosSchema)();
198
- if (!schema.metadataRegister) {
199
- return [2, (0, metadata_registrar_1.getConfigs)('app')];
200
- }
201
- return [4, schema.metadataRegister.getApps()];
202
- case 1:
203
- apps = _a.sent();
204
- configs = _.pluck(apps, 'metadata');
205
- if (spaceId) {
206
- _apps = _.filter(configs, function (config) {
207
- if (_.has(config, 'space') && config.space) {
208
- return config.space === spaceId;
209
- }
210
- return true;
211
- });
212
- result_1 = [];
213
- _.each(_apps, function (config) {
214
- if (!_.has(config, 'code')) {
215
- config.code = config._id;
216
- }
217
- var index = _l.findIndex(result_1, function (item) { return item.code === config.code; });
218
- if (index > -1) {
219
- var _config = result_1[index];
220
- if (_config.code === _config._id) {
221
- result_1[index] = config;
222
- }
223
- }
224
- else {
225
- result_1.push(config);
226
- }
227
- });
228
- return [2, result_1];
128
+ const result = [];
129
+ _.each(_apps, function (config) {
130
+ if (!_.has(config, 'code')) {
131
+ config.code = config._id;
132
+ }
133
+ const index = _l.findIndex(result, function (item) { return item.code === config.code; });
134
+ if (index > -1) {
135
+ const _config = result[index];
136
+ if (_config.code === _config._id) {
137
+ result[index] = config;
229
138
  }
230
- return [2, configs];
231
- }
232
- });
233
- }); };
139
+ }
140
+ else {
141
+ result.push(config);
142
+ }
143
+ });
144
+ return result;
145
+ }
146
+ return configs;
147
+ };
234
148
  exports.getAppConfigs = getAppConfigs;
235
- var removeApp = function (appApiName) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
236
- var schema;
237
- return tslib_1.__generator(this, function (_a) {
238
- switch (_a.label) {
239
- case 0:
240
- schema = (0, _1.getSteedosSchema)();
241
- return [4, schema.metadataRegister.removeApp(appApiName)];
242
- case 1: return [2, _a.sent()];
243
- }
244
- });
245
- }); };
149
+ const removeApp = async (appApiName) => {
150
+ const schema = (0, _1.getSteedosSchema)();
151
+ return await schema.metadataRegister.removeApp(appApiName);
152
+ };
246
153
  exports.removeApp = removeApp;
247
- var getAppConfig = function (appApiName) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
248
- var schema, app;
249
- return tslib_1.__generator(this, function (_a) {
250
- switch (_a.label) {
251
- case 0:
252
- schema = (0, _1.getSteedosSchema)();
253
- return [4, schema.metadataRegister.getApp(appApiName)];
254
- case 1:
255
- app = _a.sent();
256
- return [2, app === null || app === void 0 ? void 0 : app.metadata];
257
- }
258
- });
259
- }); };
154
+ const getAppConfig = async (appApiName) => {
155
+ const schema = (0, _1.getSteedosSchema)();
156
+ const app = await schema.metadataRegister.getApp(appApiName);
157
+ return app?.metadata;
158
+ };
260
159
  exports.getAppConfig = getAppConfig;
261
- var getUserProfileApiName = function (spaceId, userId) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
262
- var spaceUsers, userProfile, spaceUser;
263
- return tslib_1.__generator(this, function (_a) {
264
- switch (_a.label) {
265
- case 0: return [4, (0, _1.getObject)("space_users").find({ filters: [['space', '=', spaceId], ['user', '=', userId]], fields: ['profile'] })];
266
- case 1:
267
- spaceUsers = _a.sent();
268
- userProfile = 'user';
269
- if (spaceUsers && spaceUsers.length > 0) {
270
- spaceUser = spaceUsers[0];
271
- if (spaceUser && spaceUser.profile) {
272
- userProfile = spaceUser.profile;
273
- }
274
- }
275
- return [2, userProfile];
160
+ const getUserProfileApiName = async (spaceId, userId) => {
161
+ const spaceUsers = await (0, _1.getObject)("space_users").find({ filters: [['space', '=', spaceId], ['user', '=', userId]], fields: ['profile'] });
162
+ let userProfile = 'user';
163
+ if (spaceUsers && spaceUsers.length > 0) {
164
+ const spaceUser = spaceUsers[0];
165
+ if (spaceUser && spaceUser.profile) {
166
+ userProfile = spaceUser.profile;
276
167
  }
277
- });
278
- }); };
279
- var getProfile = function (spaceId, profileApiName) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
280
- var profiles;
281
- return tslib_1.__generator(this, function (_a) {
282
- switch (_a.label) {
283
- case 0: return [4, (0, _1.getObject)('permission_set').find({ filters: [['space', '=', spaceId], ['name', '=', profileApiName]] })];
284
- case 1:
285
- profiles = _a.sent();
286
- return [2, profiles.length > 0 ? profiles[0] : null];
168
+ }
169
+ return userProfile;
170
+ };
171
+ const getProfile = async (spaceId, profileApiName) => {
172
+ const profiles = await (0, _1.getObject)('permission_set').find({ filters: [['space', '=', spaceId], ['name', '=', profileApiName]] });
173
+ return profiles.length > 0 ? profiles[0] : null;
174
+ };
175
+ const getUserPermissionSet = async (spaceId, userId, profileApiName) => {
176
+ let filters = [['space', '=', spaceId], ['users', '=', userId]];
177
+ if (profileApiName) {
178
+ filters = [['space', '=', spaceId], [['users', '=', userId], 'or', ['name', '=', profileApiName]]];
179
+ }
180
+ return await (0, _1.getObject)('permission_set').find({ filters: filters });
181
+ };
182
+ const getAssignedApps = async (userSession) => {
183
+ let apps = [];
184
+ const { spaceId, userId, is_space_admin: isSpaceAdmin } = userSession;
185
+ if (isSpaceAdmin) {
186
+ return [];
187
+ }
188
+ else {
189
+ let userProfileApiName = await getUserProfileApiName(spaceId, userId);
190
+ let userProfile = null;
191
+ if (userProfileApiName) {
192
+ userProfile = await getProfile(spaceId, userProfileApiName);
287
193
  }
288
- });
289
- }); };
290
- var getUserPermissionSet = function (spaceId, userId, profileApiName) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
291
- var filters;
292
- return tslib_1.__generator(this, function (_a) {
293
- switch (_a.label) {
294
- case 0:
295
- filters = [['space', '=', spaceId], ['users', '=', userId]];
296
- if (profileApiName) {
297
- filters = [['space', '=', spaceId], [['users', '=', userId], 'or', ['name', '=', profileApiName]]];
298
- }
299
- return [4, (0, _1.getObject)('permission_set').find({ filters: filters })];
300
- case 1: return [2, _a.sent()];
194
+ if (userProfile?.assigned_apps?.length) {
195
+ apps = _.union(apps, userProfile.assigned_apps);
301
196
  }
302
- });
303
- }); };
304
- var getAssignedApps = function (userSession) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
305
- var apps, spaceId, userId, isSpaceAdmin, userProfileApiName, userProfile, psets;
306
- var _a;
307
- return tslib_1.__generator(this, function (_b) {
308
- switch (_b.label) {
309
- case 0:
310
- apps = [];
311
- spaceId = userSession.spaceId, userId = userSession.userId, isSpaceAdmin = userSession.is_space_admin;
312
- if (!isSpaceAdmin) return [3, 1];
313
- return [2, []];
314
- case 1: return [4, getUserProfileApiName(spaceId, userId)];
315
- case 2:
316
- userProfileApiName = _b.sent();
317
- userProfile = null;
318
- if (!userProfileApiName) return [3, 4];
319
- return [4, getProfile(spaceId, userProfileApiName)];
320
- case 3:
321
- userProfile = _b.sent();
322
- _b.label = 4;
323
- case 4:
324
- if ((_a = userProfile === null || userProfile === void 0 ? void 0 : userProfile.assigned_apps) === null || _a === void 0 ? void 0 : _a.length) {
325
- apps = _.union(apps, userProfile.assigned_apps);
326
- }
327
- else {
328
- apps = [];
329
- }
330
- return [4, getUserPermissionSet(spaceId, userId, userProfileApiName)];
331
- case 5:
332
- psets = _b.sent();
333
- _.each(psets, function (pset) {
334
- var _a;
335
- if (!pset.assigned_apps || ((_a = pset.assigned_apps) === null || _a === void 0 ? void 0 : _a.length) === 0) {
336
- return;
337
- }
338
- if (pset.name == "admin" || pset.name == "user" || pset.name == 'supplier' || pset.name == 'customer') {
339
- return;
340
- }
341
- apps = _.union(apps, pset.assigned_apps);
342
- });
343
- return [2, _.without(_.uniq(apps), undefined, null)];
197
+ else {
198
+ apps = [];
344
199
  }
345
- });
346
- }); };
200
+ const psets = await getUserPermissionSet(spaceId, userId, userProfileApiName);
201
+ _.each(psets, (pset) => {
202
+ if (!pset.assigned_apps || pset.assigned_apps?.length === 0) {
203
+ return;
204
+ }
205
+ if (pset.name == "admin" || pset.name == "user" || pset.name == 'supplier' || pset.name == 'customer') {
206
+ return;
207
+ }
208
+ apps = _.union(apps, pset.assigned_apps);
209
+ });
210
+ return _.without(_.uniq(apps), undefined, null);
211
+ }
212
+ };
347
213
  exports.getAssignedApps = getAssignedApps;
348
- var getAssignedMenus = function (userSession) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
349
- var result, spaceId, userId, isSpaceAdmin, roles, adminApp, apps, adminMenus, aboutMenu, otherMenuApps, otherMenus, allMenus, userProfile_1, menus;
350
- return tslib_1.__generator(this, function (_a) {
351
- switch (_a.label) {
352
- case 0:
353
- result = null;
354
- spaceId = userSession.spaceId, userId = userSession.userId, isSpaceAdmin = userSession.is_space_admin, roles = userSession.roles;
355
- return [4, (0, exports.getAppConfig)('admin')];
356
- case 1:
357
- adminApp = _a.sent();
358
- return [4, (0, exports.getAppConfigs)()];
359
- case 2:
360
- apps = _a.sent();
361
- adminMenus = adminApp.admin_menus;
362
- if (!adminMenus) {
363
- return [2, []];
364
- }
365
- aboutMenu = _.find(adminMenus, function (menu) {
366
- return menu._id == 'about';
367
- });
368
- adminMenus = _.filter(adminMenus, function (menu) {
369
- return menu._id != 'about';
370
- });
371
- otherMenuApps = _.sortBy(_.filter(apps, function (menu) {
372
- return menu.admin_menus && menu._id != 'admin';
373
- }), 'sort');
374
- otherMenus = _.flatten(_.pluck(otherMenuApps, "admin_menus"));
375
- allMenus = _.union(adminMenus, otherMenus, [aboutMenu]);
376
- if (!isSpaceAdmin) return [3, 3];
377
- result = allMenus;
378
- return [3, 5];
379
- case 3: return [4, getUserProfileApiName(spaceId, userId)];
380
- case 4:
381
- userProfile_1 = _a.sent();
382
- menus = _.filter(allMenus, function (menu) {
383
- var psetsMenu = menu.permission_sets;
384
- if (psetsMenu && psetsMenu.indexOf(userProfile_1) > -1) {
385
- return true;
386
- }
387
- return _.intersection(roles, psetsMenu).length;
388
- });
389
- result = menus;
390
- _a.label = 5;
391
- case 5: return [2, _.sortBy(result, "sort")];
392
- }
393
- });
394
- }); };
214
+ const getAssignedMenus = async (userSession) => {
215
+ let result = null;
216
+ const { spaceId, userId, is_space_admin: isSpaceAdmin, roles } = userSession;
217
+ const adminApp = await (0, exports.getAppConfig)('admin');
218
+ const apps = await (0, exports.getAppConfigs)();
219
+ let { admin_menus: adminMenus } = adminApp;
220
+ if (!adminMenus) {
221
+ return [];
222
+ }
223
+ const aboutMenu = _.find(adminMenus, (menu) => {
224
+ return menu._id == 'about';
225
+ });
226
+ adminMenus = _.filter(adminMenus, (menu) => {
227
+ return menu._id != 'about';
228
+ });
229
+ const otherMenuApps = _.sortBy(_.filter(apps, (menu) => {
230
+ return menu.admin_menus && menu._id != 'admin';
231
+ }), 'sort');
232
+ const otherMenus = _.flatten(_.pluck(otherMenuApps, "admin_menus"));
233
+ const allMenus = _.union(adminMenus, otherMenus, [aboutMenu]);
234
+ if (isSpaceAdmin) {
235
+ result = allMenus;
236
+ }
237
+ else {
238
+ let userProfile = await getUserProfileApiName(spaceId, userId);
239
+ const menus = _.filter(allMenus, (menu) => {
240
+ const psetsMenu = menu.permission_sets;
241
+ if (psetsMenu && psetsMenu.indexOf(userProfile) > -1) {
242
+ return true;
243
+ }
244
+ return _.intersection(roles, psetsMenu).length;
245
+ });
246
+ result = menus;
247
+ }
248
+ return _.sortBy(result, "sort");
249
+ };
395
250
  exports.getAssignedMenus = getAssignedMenus;
396
251
  //# sourceMappingURL=app.js.map