@steedos/service-metadata-apps 3.0.13-beta.8 → 3.0.13

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.
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ActionHandlers = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const _1 = require(".");
6
5
  const _ = require("lodash");
7
6
  const utils_1 = require("@steedos/utils");
@@ -11,118 +10,104 @@ const getNotLicensedTabNames_1 = require("./getNotLicensedTabNames");
11
10
  function cacherKey(appApiName) {
12
11
  return `$steedos.#${_1.METADATA_TYPE}.${appApiName}`;
13
12
  }
14
- function registerApp(ctx, appApiName, data, meta) {
15
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
- return yield ctx.broker.call("metadata.add", { key: cacherKey(appApiName), data: data }, { meta: meta });
17
- });
13
+ async function registerApp(ctx, appApiName, data, meta) {
14
+ return await ctx.broker.call("metadata.add", { key: cacherKey(appApiName), data: data }, { meta: meta });
18
15
  }
19
- function getSpaceApp(ctx, appApiName) {
20
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
21
- const allApps = yield getAllApps(ctx);
22
- const userSession = ctx.meta.user;
23
- const spaceId = userSession.spaceId;
24
- const userApps = _.filter(allApps, function (metadataConfig) {
25
- const config = metadataConfig.metadata;
26
- if (!config.visible) {
27
- return false;
28
- }
29
- if (_.has(config, "space") && config.space) {
30
- return config.space === spaceId;
31
- }
32
- if (!_.isEmpty(config.tabs) ||
33
- !_.isEmpty(config.objects) ||
34
- !_.isEmpty(config.mobile_objects)) {
35
- return true;
36
- }
16
+ async function getSpaceApp(ctx, appApiName) {
17
+ const allApps = await getAllApps(ctx);
18
+ const userSession = ctx.meta.user;
19
+ const spaceId = userSession.spaceId;
20
+ const userApps = _.filter(allApps, function (metadataConfig) {
21
+ const config = metadataConfig.metadata;
22
+ if (!config.visible) {
23
+ return false;
24
+ }
25
+ if (_.has(config, "space") && config.space) {
26
+ return config.space === spaceId;
27
+ }
28
+ if (!_.isEmpty(config.tabs) ||
29
+ !_.isEmpty(config.objects) ||
30
+ !_.isEmpty(config.mobile_objects)) {
37
31
  return true;
38
- });
39
- return _.find(userApps, function (metadataConfig) {
40
- const config = metadataConfig.metadata;
41
- return config.space && config.code === appApiName;
42
- });
32
+ }
33
+ return true;
34
+ });
35
+ return _.find(userApps, function (metadataConfig) {
36
+ const config = metadataConfig.metadata;
37
+ return config.space && config.code === appApiName;
43
38
  });
44
39
  }
45
- function get(ctx) {
46
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
47
- const spaceAppMetadataConfig = yield getSpaceApp(ctx, ctx.params.appApiName);
48
- if (spaceAppMetadataConfig) {
49
- return spaceAppMetadataConfig;
40
+ async function get(ctx) {
41
+ const spaceAppMetadataConfig = await getSpaceApp(ctx, ctx.params.appApiName);
42
+ if (spaceAppMetadataConfig) {
43
+ return spaceAppMetadataConfig;
44
+ }
45
+ else {
46
+ const metadataConfig = await ctx.broker.call("metadata.get", { key: cacherKey(ctx.params.appApiName) }, { meta: ctx.meta });
47
+ if (metadataConfig) {
48
+ return metadataConfig;
50
49
  }
51
50
  else {
52
- const metadataConfig = yield ctx.broker.call("metadata.get", { key: cacherKey(ctx.params.appApiName) }, { meta: ctx.meta });
53
- if (metadataConfig) {
54
- return metadataConfig;
55
- }
56
- else {
57
- const allApps = yield getAllApps(ctx);
58
- const userSession = ctx.meta.user;
59
- const spaceId = userSession.spaceId;
60
- const userApps = _.filter(allApps, function (metadataConfig) {
61
- const config = metadataConfig.metadata;
62
- if (!config.visible) {
63
- return false;
64
- }
65
- if (_.has(config, "space") && config.space) {
66
- return config.space === spaceId;
67
- }
68
- if (!_.isEmpty(config.tabs) ||
69
- !_.isEmpty(config.objects) ||
70
- !_.isEmpty(config.mobile_objects)) {
71
- return true;
72
- }
51
+ const allApps = await getAllApps(ctx);
52
+ const userSession = ctx.meta.user;
53
+ const spaceId = userSession.spaceId;
54
+ const userApps = _.filter(allApps, function (metadataConfig) {
55
+ const config = metadataConfig.metadata;
56
+ if (!config.visible) {
57
+ return false;
58
+ }
59
+ if (_.has(config, "space") && config.space) {
60
+ return config.space === spaceId;
61
+ }
62
+ if (!_.isEmpty(config.tabs) ||
63
+ !_.isEmpty(config.objects) ||
64
+ !_.isEmpty(config.mobile_objects)) {
73
65
  return true;
74
- });
75
- if (ctx.params.appApiName === "-") {
76
- return _.first(_.sortBy(userApps, ["metadata.sort"]));
77
66
  }
78
- return _.find(userApps, function (metadataConfig) {
79
- const app = metadataConfig.metadata;
80
- return app.code === ctx.params.appApiName;
81
- });
67
+ return true;
68
+ });
69
+ if (ctx.params.appApiName === "-") {
70
+ return _.first(_.sortBy(userApps, ["metadata.sort"]));
82
71
  }
72
+ return _.find(userApps, function (metadataConfig) {
73
+ const app = metadataConfig.metadata;
74
+ return app.code === ctx.params.appApiName;
75
+ });
83
76
  }
84
- });
77
+ }
85
78
  }
86
- function getAllApps(ctx) {
87
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
88
- return yield ctx.broker.call("metadata.filter", { key: cacherKey("*") }, { meta: ctx.meta });
89
- });
79
+ async function getAllApps(ctx) {
80
+ return await ctx.broker.call("metadata.filter", { key: cacherKey("*") }, { meta: ctx.meta });
90
81
  }
91
- function getAllTabs(ctx) {
92
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
93
- return yield ctx.broker.call("tabs.getAll");
94
- });
82
+ async function getAllTabs(ctx) {
83
+ return await ctx.broker.call("tabs.getAll");
95
84
  }
96
- function getContext(ctx) {
97
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
98
- const userSession = ctx.meta.user;
99
- const allTabs = yield getAllTabs(ctx);
100
- if (userSession.is_space_admin) {
101
- return {
102
- tabs: allTabs,
103
- hiddenTabNames: [],
104
- };
105
- }
106
- let hiddenTabNames = yield getHiddenTabNames(ctx, allTabs);
107
- const notLicensedTabNames = yield (0, getNotLicensedTabNames_1.getNotLicensedTabNames)(ctx, allTabs);
108
- hiddenTabNames = hiddenTabNames.concat(notLicensedTabNames);
85
+ async function getContext(ctx) {
86
+ const userSession = ctx.meta.user;
87
+ const allTabs = await getAllTabs(ctx);
88
+ if (userSession.is_space_admin) {
109
89
  return {
110
90
  tabs: allTabs,
111
- hiddenTabNames: hiddenTabNames,
91
+ hiddenTabNames: [],
112
92
  };
113
- });
93
+ }
94
+ let hiddenTabNames = await getHiddenTabNames(ctx, allTabs);
95
+ const notLicensedTabNames = await (0, getNotLicensedTabNames_1.getNotLicensedTabNames)(ctx, allTabs);
96
+ hiddenTabNames = hiddenTabNames.concat(notLicensedTabNames);
97
+ return {
98
+ tabs: allTabs,
99
+ hiddenTabNames: hiddenTabNames,
100
+ };
114
101
  }
115
- function getTab(ctx, tabApiName) {
116
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
117
- const metadataConfig = yield ctx.broker.call("tabs.get", { tabApiName });
118
- return metadataConfig === null || metadataConfig === void 0 ? void 0 : metadataConfig.metadata;
119
- });
102
+ async function getTab(ctx, tabApiName) {
103
+ const metadataConfig = await ctx.broker.call("tabs.get", { tabApiName });
104
+ return metadataConfig?.metadata;
120
105
  }
121
106
  function getTabChildren(context, tabApiName) {
122
107
  if (context) {
123
108
  const { tabs } = context;
124
109
  return _.filter(tabs, function (tab) {
125
- return (tab === null || tab === void 0 ? void 0 : tab.metadata.parent) === tabApiName;
110
+ return tab?.metadata.parent === tabApiName;
126
111
  });
127
112
  }
128
113
  }
@@ -146,530 +131,532 @@ function checkAppMobile(app, mobile) {
146
131
  }
147
132
  return isChecked;
148
133
  }
149
- function getHiddenTabNames(ctx, allTabs) {
150
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
151
- const userSession = ctx.meta.user;
152
- if (!userSession) {
153
- throw new Error("no permission.");
154
- }
155
- const hiddenTabNames = [];
156
- const permissionTabs = yield getPermissionTabs(ctx, userSession);
157
- const showTabNames = [];
158
- for (const permissionTab of permissionTabs) {
159
- if (permissionTab.permission === "on") {
160
- showTabNames.push(permissionTab.tab);
161
- }
134
+ async function getHiddenTabNames(ctx, allTabs) {
135
+ const userSession = ctx.meta.user;
136
+ if (!userSession) {
137
+ throw new Error("no permission.");
138
+ }
139
+ const hiddenTabNames = [];
140
+ const permissionTabs = await getPermissionTabs(ctx, userSession);
141
+ const showTabNames = [];
142
+ for (const permissionTab of permissionTabs) {
143
+ if (permissionTab.permission === "on") {
144
+ showTabNames.push(permissionTab.tab);
162
145
  }
163
- for (const permissionTab of permissionTabs) {
164
- if ((permissionTab.permission === "off" ||
165
- permissionTab.permission === "hidden") &&
166
- !showTabNames.includes(permissionTab.tab)) {
167
- hiddenTabNames.push(permissionTab.tab);
168
- }
146
+ }
147
+ for (const permissionTab of permissionTabs) {
148
+ if ((permissionTab.permission === "off" ||
149
+ permissionTab.permission === "hidden") &&
150
+ !showTabNames.includes(permissionTab.tab)) {
151
+ hiddenTabNames.push(permissionTab.tab);
169
152
  }
170
- for (const config of allTabs) {
171
- if (config.metadata && config.metadata.hidden) {
172
- hiddenTabNames.push(config.metadata.name);
173
- }
153
+ }
154
+ for (const config of allTabs) {
155
+ if (config.metadata && config.metadata.hidden) {
156
+ hiddenTabNames.push(config.metadata.name);
174
157
  }
175
- return hiddenTabNames;
176
- });
158
+ }
159
+ return hiddenTabNames;
177
160
  }
178
- function getPermissionTabs(ctx, userSession) {
179
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
180
- const { roles, spaceId } = userSession;
181
- const permissionTabs = [];
182
- for (const role of roles) {
183
- const pattern = `${role}_*`;
184
- const filterResult = yield ctx.broker.call("permission_tabs.filter", {
185
- pattern: pattern,
186
- }, {
187
- user: { spaceId: spaceId },
188
- });
189
- for (const ptConfig of filterResult) {
190
- if (ptConfig.metadata.permission_set === role &&
191
- (!_.has(ptConfig.metadata, "space") ||
192
- ptConfig.metadata.space === spaceId)) {
193
- permissionTabs.push(ptConfig.metadata);
194
- }
161
+ async function getPermissionTabs(ctx, userSession) {
162
+ const { roles, spaceId } = userSession;
163
+ const permissionTabs = [];
164
+ for (const role of roles) {
165
+ const pattern = `${role}_*`;
166
+ const filterResult = await ctx.broker.call("permission_tabs.filter", {
167
+ pattern: pattern,
168
+ }, {
169
+ user: { spaceId: spaceId },
170
+ });
171
+ for (const ptConfig of filterResult) {
172
+ if (ptConfig.metadata.permission_set === role &&
173
+ (!_.has(ptConfig.metadata, "space") ||
174
+ ptConfig.metadata.space === spaceId)) {
175
+ permissionTabs.push(ptConfig.metadata);
195
176
  }
196
177
  }
197
- return permissionTabs;
198
- });
178
+ }
179
+ return permissionTabs;
199
180
  }
200
- function tabMenus(ctx_1, appPath_1, tabApiName_1, menu_1, mobile_1, userSession_1, context_1) {
201
- return tslib_1.__awaiter(this, arguments, void 0, function* (ctx, appPath, tabApiName, menu, mobile, userSession, context, props = {}) {
202
- var _a;
203
- try {
204
- const tab = yield getTab(ctx, tabApiName);
205
- if (props.group) {
206
- props.group =
207
- ((_a = _.find(menu.tab_groups, { id: props.group })) === null || _a === void 0 ? void 0 : _a.group_name) || props.group;
208
- }
209
- if (tabApiName) {
210
- props.tabApiName = tabApiName;
181
+ async function tabMenus(ctx, appPath, tabApiName, menu, mobile, userSession, context, props = {}) {
182
+ try {
183
+ const tab = await getTab(ctx, tabApiName);
184
+ if (props.group) {
185
+ props.group =
186
+ _.find(menu.tab_groups, { id: props.group })?.group_name || props.group;
187
+ }
188
+ if (tabApiName) {
189
+ props.tabApiName = tabApiName;
190
+ }
191
+ if (tab) {
192
+ const isMobileChecked = checkTabMobile(tab, mobile);
193
+ if (!isMobileChecked) {
194
+ return;
211
195
  }
212
- if (tab) {
213
- const isMobileChecked = checkTabMobile(tab, mobile);
214
- if (!isMobileChecked) {
215
- return;
196
+ const tabChildren = getTabChildren(context, tabApiName);
197
+ if (tabChildren && tabChildren.length > 0) {
198
+ const tabMenu = {
199
+ id: tab.name,
200
+ icon: tab.icon,
201
+ name: `${tab.label}`,
202
+ children: [],
203
+ ...props,
204
+ };
205
+ for (const { metadata: tabChild } of tabChildren) {
206
+ if (tabChild && tabChild.apiName) {
207
+ await tabMenus(ctx, appPath, tabChild.apiName, tabMenu, mobile, userSession, context);
208
+ }
216
209
  }
217
- const tabChildren = getTabChildren(context, tabApiName);
218
- if (tabChildren && tabChildren.length > 0) {
219
- const tabMenu = Object.assign({ id: tab.name, icon: tab.icon, name: `${tab.label}`, children: [] }, props);
220
- for (const { metadata: tabChild } of tabChildren) {
221
- if (tabChild && tabChild.apiName) {
222
- yield tabMenus(ctx, appPath, tabChild.apiName, tabMenu, mobile, userSession, context);
223
- }
210
+ menu.children.push(tabMenu);
211
+ }
212
+ else {
213
+ if (tab.type === "object") {
214
+ const allowRead = await objectAllowRead(tab.object, userSession);
215
+ if (!allowRead) {
216
+ return;
217
+ }
218
+ const objectConfig = await (0, objectql_1.getObject)(tab.object).getConfig();
219
+ if (objectConfig) {
220
+ const objectLabel = (0, i18n_1.translationObjectLabel)(userSession.language, objectConfig.name, objectConfig.label || objectConfig.name);
221
+ menu.children.push({
222
+ id: objectConfig.name,
223
+ type: tab.type,
224
+ icon: objectConfig.icon,
225
+ path: `${appPath}/${objectConfig.name}`,
226
+ name: `${objectLabel}`,
227
+ ...props,
228
+ });
224
229
  }
225
- menu.children.push(tabMenu);
226
230
  }
227
- else {
228
- if (tab.type === "object") {
229
- const allowRead = yield objectAllowRead(tab.object, userSession);
230
- if (!allowRead) {
231
- return;
232
- }
233
- const objectConfig = yield (0, objectql_1.getObject)(tab.object).getConfig();
234
- if (objectConfig) {
235
- const objectLabel = (0, i18n_1.translationObjectLabel)(userSession.language, objectConfig.name, objectConfig.label || objectConfig.name);
236
- menu.children.push(Object.assign({ id: objectConfig.name, type: tab.type, icon: objectConfig.icon, path: `${appPath}/${objectConfig.name}`, name: `${objectLabel}` }, props));
237
- }
231
+ if (tab.type === "url") {
232
+ tab.label = (0, i18n_1.translationTabLabel)(userSession.language, tab.name, tab.label || tab.name);
233
+ let urlMenu = {
234
+ id: `${tab.name}`,
235
+ type: tab.type,
236
+ icon: tab.icon,
237
+ path: `${tab.url}`,
238
+ name: `${tab.label}`,
239
+ ...props,
240
+ };
241
+ if (tab.is_new_window) {
242
+ urlMenu.target = "_blank";
238
243
  }
239
- if (tab.type === "url") {
240
- tab.label = (0, i18n_1.translationTabLabel)(userSession.language, tab.name, tab.label || tab.name);
241
- let urlMenu = Object.assign({ id: `${tab.name}`, type: tab.type, icon: tab.icon, path: `${tab.url}`, name: `${tab.label}` }, props);
242
- if (tab.is_new_window) {
243
- urlMenu.target = "_blank";
244
- }
245
- else if (tab.is_use_iframe) {
246
- urlMenu.is_use_iframe = true;
247
- urlMenu.path = `${appPath}/tab_iframe/${tab.name}/?url=${encodeURIComponent(tab.url)}`;
248
- }
249
- menu.children.push(urlMenu);
244
+ else if (tab.is_use_iframe) {
245
+ urlMenu.is_use_iframe = true;
246
+ urlMenu.path = `${appPath}/tab_iframe/${tab.name}/?url=${encodeURIComponent(tab.url)}`;
250
247
  }
251
- if (tab.type === "page") {
252
- tab.label = (0, i18n_1.translationTabLabel)(userSession.language, tab.name, tab.label || tab.name);
253
- menu.children.push(Object.assign({ id: `${tab.name}`, icon: tab.icon, type: tab.type, page: tab.page, path: `${appPath}/${tab.type}/${tab.page}`, name: `${tab.label}` }, props));
248
+ menu.children.push(urlMenu);
249
+ }
250
+ if (tab.type === "page") {
251
+ tab.label = (0, i18n_1.translationTabLabel)(userSession.language, tab.name, tab.label || tab.name);
252
+ menu.children.push({
253
+ id: `${tab.name}`,
254
+ icon: tab.icon,
255
+ type: tab.type,
256
+ page: tab.page,
257
+ path: `${appPath}/${tab.type}/${tab.page}`,
258
+ name: `${tab.label}`,
259
+ ...props,
260
+ });
261
+ }
262
+ if (tab.type === "analytics_dashboard") {
263
+ const url = `/analytics/embed/dashboard/${tab.analytics_dashboard}?titled=false&bordered=false`;
264
+ tab.label = (0, i18n_1.translationTabLabel)(userSession.language, tab.name, tab.label || tab.name);
265
+ let urlMenu = {
266
+ id: `${tab.name}`,
267
+ type: tab.type,
268
+ icon: tab.icon,
269
+ path: `${url}`,
270
+ name: `${tab.label}`,
271
+ ...props,
272
+ };
273
+ if (tab.is_new_window) {
274
+ urlMenu.target = "_blank";
254
275
  }
255
- if (tab.type === "analytics_dashboard") {
256
- const url = `/analytics/embed/dashboard/${tab.analytics_dashboard}?titled=false&bordered=false`;
257
- tab.label = (0, i18n_1.translationTabLabel)(userSession.language, tab.name, tab.label || tab.name);
258
- let urlMenu = Object.assign({ id: `${tab.name}`, type: tab.type, icon: tab.icon, path: `${url}`, name: `${tab.label}` }, props);
259
- if (tab.is_new_window) {
260
- urlMenu.target = "_blank";
261
- }
262
- else {
263
- urlMenu.is_use_iframe = true;
264
- urlMenu.path = `${appPath}/tab_iframe/${tab.name}/?url=${url}`;
265
- }
266
- menu.children.push(urlMenu);
276
+ else {
277
+ urlMenu.is_use_iframe = true;
278
+ urlMenu.path = `${appPath}/tab_iframe/${tab.name}/?url=${url}`;
267
279
  }
280
+ menu.children.push(urlMenu);
268
281
  }
269
282
  }
270
283
  }
271
- catch (error) {
272
- ctx.broker.logger.info(error.message);
273
- }
274
- });
284
+ }
285
+ catch (error) {
286
+ ctx.broker.logger.info(error.message);
287
+ }
275
288
  }
276
- function objectAllowRead(objectApiName, userSession) {
277
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
278
- return yield (0, objectql_1.getObject)(objectApiName).allowRead(userSession);
279
- });
289
+ async function objectAllowRead(objectApiName, userSession) {
290
+ return await (0, objectql_1.getObject)(objectApiName).allowRead(userSession);
280
291
  }
281
- function transformAppToMenus(ctx, app, mobile, userSession, context) {
282
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
283
- if (!app.code && !app._id) {
284
- return;
285
- }
286
- const isAppShow = checkAppMobile(app, mobile);
287
- if (!isAppShow) {
288
- return;
289
- }
290
- if (!app.code) {
291
- app.code = app._id;
292
- }
293
- (0, i18n_1.translationApp)(userSession.language, app.code, app);
294
- var appPath = `/app/${app.code}`;
295
- if (app.url) {
296
- if (/^http(s?):\/\//.test(app.url)) {
297
- if (app.secret) {
298
- appPath = (0, objectql_1.absoluteUrl)("/api/external/app/" + (app._id || app.code));
299
- }
300
- else {
301
- appPath = app.url;
302
- }
292
+ async function transformAppToMenus(ctx, app, mobile, userSession, context) {
293
+ if (!app.code && !app._id) {
294
+ return;
295
+ }
296
+ const isAppShow = checkAppMobile(app, mobile);
297
+ if (!isAppShow) {
298
+ return;
299
+ }
300
+ if (!app.code) {
301
+ app.code = app._id;
302
+ }
303
+ (0, i18n_1.translationApp)(userSession.language, app.code, app);
304
+ var appPath = `/app/${app.code}`;
305
+ if (app.url) {
306
+ if (/^http(s?):\/\//.test(app.url)) {
307
+ if (app.secret) {
308
+ appPath = (0, objectql_1.absoluteUrl)("/api/external/app/" + (app._id || app.code));
303
309
  }
304
310
  else {
305
311
  appPath = app.url;
306
312
  }
307
313
  }
308
- const menu = {
309
- id: app.code,
310
- path: appPath,
311
- name: `${app.label || app.name}`,
312
- icon: app.icon_slds,
313
- color: app.color,
314
- dark: app.dark,
315
- showSidebar: app.showSidebar,
316
- description: app.description,
317
- children: [],
318
- blank: app.is_new_window,
319
- on_click: app.on_click,
320
- isExternalUrl: !!app.url,
321
- tab_groups: app.tab_groups,
322
- is_hide_mobile_menu: app.is_hide_mobile_menu,
323
- visible_on: app.visible_on || "${true}",
324
- default_tab: app.default_tab,
325
- };
326
- if (app.enable_nav_schema &&
327
- app.nav_schema &&
328
- (!mobile || mobile === "false")) {
329
- menu.nav_schema = _.isString(app.nav_schema)
330
- ? JSON.parse(app.nav_schema)
331
- : app.nav_schema;
332
- }
333
- const hiddenTabNames = context.hiddenTabNames || [];
334
- if (app.tab_items) {
335
- if (_.isArray(app.tab_items)) {
336
- for (const item of app.tab_items) {
337
- try {
338
- if (hiddenTabNames.includes(item.tab_name))
339
- continue;
340
- yield tabMenus(ctx, appPath, item.tab_name, menu, mobile, userSession, context, item);
341
- }
342
- catch (error) {
343
- ctx.broker.logger.info(error.message);
344
- }
314
+ else {
315
+ appPath = app.url;
316
+ }
317
+ }
318
+ const menu = {
319
+ id: app.code,
320
+ path: appPath,
321
+ name: `${app.label || app.name}`,
322
+ icon: app.icon_slds,
323
+ color: app.color,
324
+ dark: app.dark,
325
+ showSidebar: app.showSidebar,
326
+ description: app.description,
327
+ children: [],
328
+ blank: app.is_new_window,
329
+ on_click: app.on_click,
330
+ isExternalUrl: !!app.url,
331
+ tab_groups: app.tab_groups,
332
+ is_hide_mobile_menu: app.is_hide_mobile_menu,
333
+ visible_on: app.visible_on || "${true}",
334
+ default_tab: app.default_tab,
335
+ };
336
+ if (app.enable_nav_schema &&
337
+ app.nav_schema &&
338
+ (!mobile || mobile === "false")) {
339
+ menu.nav_schema = _.isString(app.nav_schema)
340
+ ? JSON.parse(app.nav_schema)
341
+ : app.nav_schema;
342
+ }
343
+ const hiddenTabNames = context.hiddenTabNames || [];
344
+ if (app.tab_items) {
345
+ if (_.isArray(app.tab_items)) {
346
+ for (const item of app.tab_items) {
347
+ try {
348
+ if (hiddenTabNames.includes(item.tab_name))
349
+ continue;
350
+ await tabMenus(ctx, appPath, item.tab_name, menu, mobile, userSession, context, item);
345
351
  }
346
- }
347
- else {
348
- for (const tabApiName in app.tab_items) {
349
- try {
350
- if (hiddenTabNames.includes(tabApiName))
351
- continue;
352
- const props = app.tab_items[tabApiName];
353
- yield tabMenus(ctx, appPath, tabApiName, menu, mobile, userSession, context, props);
354
- }
355
- catch (error) {
356
- ctx.broker.logger.info(error.message);
357
- }
352
+ catch (error) {
353
+ ctx.broker.logger.info(error.message);
358
354
  }
359
355
  }
360
356
  }
361
- else if (_.isArray(app.tabs)) {
362
- for (const tabApiName of app.tabs) {
357
+ else {
358
+ for (const tabApiName in app.tab_items) {
363
359
  try {
364
360
  if (hiddenTabNames.includes(tabApiName))
365
361
  continue;
366
- yield tabMenus(ctx, appPath, tabApiName, menu, mobile, userSession, context);
362
+ const props = app.tab_items[tabApiName];
363
+ await tabMenus(ctx, appPath, tabApiName, menu, mobile, userSession, context, props);
367
364
  }
368
365
  catch (error) {
369
366
  ctx.broker.logger.info(error.message);
370
367
  }
371
368
  }
372
369
  }
373
- const objects = mobile ? app.mobile_objects : app.objects;
374
- if (_.isArray(objects)) {
375
- const getChildrenPromises = [];
376
- for (const objectApiName of objects) {
377
- getChildrenPromises.push(getMenuChildren({
378
- objectApiName,
379
- userSession,
380
- ctx,
381
- appPath,
382
- app,
383
- }));
370
+ }
371
+ else if (_.isArray(app.tabs)) {
372
+ for (const tabApiName of app.tabs) {
373
+ try {
374
+ if (hiddenTabNames.includes(tabApiName))
375
+ continue;
376
+ await tabMenus(ctx, appPath, tabApiName, menu, mobile, userSession, context);
384
377
  }
385
- const children = yield Promise.all(getChildrenPromises);
386
- for (const child of children) {
387
- if (child) {
388
- menu.children.push(child);
389
- }
378
+ catch (error) {
379
+ ctx.broker.logger.info(error.message);
390
380
  }
391
381
  }
392
- if (menu.default_tab && _.isString(menu.default_tab)) {
393
- const defaultTabStr = menu.default_tab;
394
- let defaultTab = _.find(menu.children, (item) => {
395
- return item.id === defaultTabStr || item.tabApiName === defaultTabStr;
396
- });
397
- if (!defaultTab && context && context.tabs) {
398
- const tabConfig = _.find(context.tabs, (t) => t.metadata && t.metadata.name === defaultTabStr);
399
- if (tabConfig && tabConfig.metadata) {
400
- const tab = tabConfig.metadata;
401
- if (tab.type === "object" && tab.object) {
402
- defaultTab = _.find(menu.children, (item) => item.id === tab.object);
403
- }
404
- else {
405
- defaultTab = _.find(menu.children, (item) => item.id === tab.name);
406
- }
407
- if (!defaultTab) {
408
- try {
409
- if (tab.type === "object") {
410
- defaultTab = {
411
- id: tab.object,
412
- type: tab.type,
413
- icon: tab.icon,
414
- path: `${appPath}/${tab.object}`,
415
- name: tab.label || tab.name,
416
- tabApiName: tab.name,
417
- };
382
+ }
383
+ const objects = mobile ? app.mobile_objects : app.objects;
384
+ if (_.isArray(objects)) {
385
+ const getChildrenPromises = [];
386
+ for (const objectApiName of objects) {
387
+ getChildrenPromises.push(getMenuChildren({
388
+ objectApiName,
389
+ userSession,
390
+ ctx,
391
+ appPath,
392
+ app,
393
+ }));
394
+ }
395
+ const children = await Promise.all(getChildrenPromises);
396
+ for (const child of children) {
397
+ if (child) {
398
+ menu.children.push(child);
399
+ }
400
+ }
401
+ }
402
+ if (menu.default_tab && _.isString(menu.default_tab)) {
403
+ const defaultTabStr = menu.default_tab;
404
+ let defaultTab = _.find(menu.children, (item) => {
405
+ return item.id === defaultTabStr || item.tabApiName === defaultTabStr;
406
+ });
407
+ if (!defaultTab && context && context.tabs) {
408
+ const tabConfig = _.find(context.tabs, (t) => t.metadata && t.metadata.name === defaultTabStr);
409
+ if (tabConfig && tabConfig.metadata) {
410
+ const tab = tabConfig.metadata;
411
+ if (tab.type === "object" && tab.object) {
412
+ defaultTab = _.find(menu.children, (item) => item.id === tab.object);
413
+ }
414
+ else {
415
+ defaultTab = _.find(menu.children, (item) => item.id === tab.name);
416
+ }
417
+ if (!defaultTab) {
418
+ try {
419
+ if (tab.type === "object") {
420
+ defaultTab = {
421
+ id: tab.object,
422
+ type: tab.type,
423
+ icon: tab.icon,
424
+ path: `${appPath}/${tab.object}`,
425
+ name: tab.label || tab.name,
426
+ tabApiName: tab.name,
427
+ };
428
+ }
429
+ else if (tab.type === "url") {
430
+ defaultTab = {
431
+ id: tab.name,
432
+ type: tab.type,
433
+ icon: tab.icon,
434
+ path: tab.url,
435
+ name: tab.label || tab.name,
436
+ tabApiName: tab.name,
437
+ };
438
+ if (tab.is_new_window) {
439
+ defaultTab.target = "_blank";
418
440
  }
419
- else if (tab.type === "url") {
420
- defaultTab = {
421
- id: tab.name,
422
- type: tab.type,
423
- icon: tab.icon,
424
- path: tab.url,
425
- name: tab.label || tab.name,
426
- tabApiName: tab.name,
427
- };
428
- if (tab.is_new_window) {
429
- defaultTab.target = "_blank";
430
- }
431
- else if (tab.is_use_iframe) {
432
- defaultTab.is_use_iframe = true;
433
- defaultTab.path = `${appPath}/tab_iframe/${tab.name}/?url=${encodeURIComponent(tab.url)}`;
434
- }
441
+ else if (tab.is_use_iframe) {
442
+ defaultTab.is_use_iframe = true;
443
+ defaultTab.path = `${appPath}/tab_iframe/${tab.name}/?url=${encodeURIComponent(tab.url)}`;
435
444
  }
436
- else if (tab.type === "page") {
437
- defaultTab = {
438
- id: tab.name,
439
- icon: tab.icon,
440
- type: tab.type,
441
- page: tab.page,
442
- path: `${appPath}/${tab.type}/${tab.page}`,
443
- name: tab.label || tab.name,
444
- tabApiName: tab.name,
445
- };
445
+ }
446
+ else if (tab.type === "page") {
447
+ defaultTab = {
448
+ id: tab.name,
449
+ icon: tab.icon,
450
+ type: tab.type,
451
+ page: tab.page,
452
+ path: `${appPath}/${tab.type}/${tab.page}`,
453
+ name: tab.label || tab.name,
454
+ tabApiName: tab.name,
455
+ };
456
+ }
457
+ else if (tab.type === "analytics_dashboard") {
458
+ const url = `/analytics/embed/dashboard/${tab.analytics_dashboard}?titled=false&bordered=false`;
459
+ defaultTab = {
460
+ id: tab.name,
461
+ type: tab.type,
462
+ icon: tab.icon,
463
+ path: url,
464
+ name: tab.label || tab.name,
465
+ tabApiName: tab.name,
466
+ };
467
+ if (tab.is_new_window) {
468
+ defaultTab.target = "_blank";
446
469
  }
447
- else if (tab.type === "analytics_dashboard") {
448
- const url = `/analytics/embed/dashboard/${tab.analytics_dashboard}?titled=false&bordered=false`;
449
- defaultTab = {
450
- id: tab.name,
451
- type: tab.type,
452
- icon: tab.icon,
453
- path: url,
454
- name: tab.label || tab.name,
455
- tabApiName: tab.name,
456
- };
457
- if (tab.is_new_window) {
458
- defaultTab.target = "_blank";
459
- }
460
- else {
461
- defaultTab.is_use_iframe = true;
462
- defaultTab.path = `${appPath}/tab_iframe/${tab.name}/?url=${url}`;
463
- }
470
+ else {
471
+ defaultTab.is_use_iframe = true;
472
+ defaultTab.path = `${appPath}/tab_iframe/${tab.name}/?url=${url}`;
464
473
  }
465
474
  }
466
- catch (e) {
467
- console.error(e);
468
- }
475
+ }
476
+ catch (e) {
477
+ console.error(e);
469
478
  }
470
479
  }
471
480
  }
472
- if (defaultTab) {
473
- menu.default_tab = defaultTab;
474
- }
475
481
  }
476
- return menu;
477
- });
478
- }
479
- function getMenuChildren(_a) {
480
- return tslib_1.__awaiter(this, arguments, void 0, function* ({ objectApiName, userSession, ctx, appPath, app, }) {
481
- try {
482
- const objectConfig = yield (0, objectql_1.getObject)(objectApiName).getConfig();
483
- if (!objectConfig) {
484
- ctx.broker.logger.error(`${objectApiName} is not found in the objects of app ${app.code} `);
485
- return;
486
- }
487
- const allowRead = yield objectAllowRead(objectApiName, userSession);
488
- if (!allowRead) {
489
- return;
490
- }
491
- if (objectConfig) {
492
- const objectLabel = (0, i18n_1.translationObjectLabel)(userSession.language, objectConfig.name, objectConfig.label || objectConfig.name);
493
- return {
494
- id: objectConfig.name,
495
- icon: objectConfig.icon,
496
- path: `${appPath}/${objectConfig.name}`,
497
- name: `${objectLabel}`,
498
- };
499
- }
500
- }
501
- catch (error) {
502
- ctx.broker.logger.error(error);
482
+ if (defaultTab) {
483
+ menu.default_tab = defaultTab;
503
484
  }
504
- });
485
+ }
486
+ return menu;
505
487
  }
506
- function getAppsMenus(ctx) {
507
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
508
- const userSession = ctx.meta.user;
509
- if (!userSession) {
510
- throw new Error("no permission.");
511
- }
512
- let assigned_apps = yield (0, objectql_1.getAssignedApps)(userSession);
513
- let mobile = ctx.params.mobile;
514
- if (typeof mobile !== "boolean") {
515
- mobile = mobile === "true" ? true : false;
516
- }
517
- const spaceId = userSession.spaceId;
518
- const metadataApps = yield getAllApps(ctx);
519
- const context = yield getContext(ctx);
520
- const allApps = _.map(metadataApps, "metadata");
521
- if (assigned_apps && assigned_apps.length) {
522
- assigned_apps = _.filter(allApps, (item) => {
523
- return assigned_apps.includes(item.code);
524
- });
488
+ async function getMenuChildren({ objectApiName, userSession, ctx, appPath, app, }) {
489
+ try {
490
+ const objectConfig = await (0, objectql_1.getObject)(objectApiName).getConfig();
491
+ if (!objectConfig) {
492
+ ctx.broker.logger.error(`${objectApiName} is not found in the objects of app ${app.code} `);
493
+ return;
525
494
  }
526
- else {
527
- assigned_apps = allApps;
495
+ const allowRead = await objectAllowRead(objectApiName, userSession);
496
+ if (!allowRead) {
497
+ return;
528
498
  }
529
- const _userApps = _.filter(assigned_apps, function (config) {
530
- if (!config.visible) {
531
- return false;
532
- }
533
- if (config._id === config.code) {
534
- let dbApp = _.find(assigned_apps, (item) => {
535
- return (item.code === config.code &&
536
- item._id != item.code &&
537
- item.space === spaceId);
538
- });
539
- if (dbApp) {
540
- return dbApp.visible;
541
- }
542
- }
543
- if (_.has(config, "space") && config.space) {
544
- return config.space === spaceId;
545
- }
546
- return true;
499
+ if (objectConfig) {
500
+ const objectLabel = (0, i18n_1.translationObjectLabel)(userSession.language, objectConfig.name, objectConfig.label || objectConfig.name);
501
+ return {
502
+ id: objectConfig.name,
503
+ icon: objectConfig.icon,
504
+ path: `${appPath}/${objectConfig.name}`,
505
+ name: `${objectLabel}`,
506
+ };
507
+ }
508
+ }
509
+ catch (error) {
510
+ ctx.broker.logger.error(error);
511
+ }
512
+ }
513
+ async function getAppsMenus(ctx) {
514
+ const userSession = ctx.meta.user;
515
+ if (!userSession) {
516
+ throw new Error("no permission.");
517
+ }
518
+ let assigned_apps = await (0, objectql_1.getAssignedApps)(userSession);
519
+ let mobile = ctx.params.mobile;
520
+ if (typeof mobile !== "boolean") {
521
+ mobile = mobile === "true" ? true : false;
522
+ }
523
+ const spaceId = userSession.spaceId;
524
+ const metadataApps = await getAllApps(ctx);
525
+ const context = await getContext(ctx);
526
+ const allApps = _.map(metadataApps, "metadata");
527
+ if (assigned_apps && assigned_apps.length) {
528
+ assigned_apps = _.filter(allApps, (item) => {
529
+ return assigned_apps.includes(item.code);
547
530
  });
548
- const menus = [];
549
- let userApps = [];
550
- _.each(_.sortBy(_userApps, ["sort"]), function (app) {
551
- if (!app.code) {
552
- app.code = app._id;
553
- }
554
- const _appIndex = _.findIndex(userApps, function (item) {
555
- return item.code === app.code;
531
+ }
532
+ else {
533
+ assigned_apps = allApps;
534
+ }
535
+ const _userApps = _.filter(assigned_apps, function (config) {
536
+ if (!config.visible) {
537
+ return false;
538
+ }
539
+ if (config._id === config.code) {
540
+ let dbApp = _.find(assigned_apps, (item) => {
541
+ return (item.code === config.code &&
542
+ item._id != item.code &&
543
+ item.space === spaceId);
556
544
  });
557
- if (_appIndex < 0) {
558
- userApps.push(app);
559
- }
560
- else {
561
- const _app = userApps[_appIndex];
562
- if (!_app.space && app.space) {
563
- userApps[_appIndex] = app;
564
- }
545
+ if (dbApp) {
546
+ return dbApp.visible;
565
547
  }
548
+ }
549
+ if (_.has(config, "space") && config.space) {
550
+ return config.space === spaceId;
551
+ }
552
+ return true;
553
+ });
554
+ const menus = [];
555
+ let userApps = [];
556
+ _.each(_.sortBy(_userApps, ["sort"]), function (app) {
557
+ if (!app.code) {
558
+ app.code = app._id;
559
+ }
560
+ const _appIndex = _.findIndex(userApps, function (item) {
561
+ return item.code === app.code;
566
562
  });
567
- for (const app of _.sortBy(userApps, ["sort"])) {
568
- const menu = yield transformAppToMenus(ctx, app, mobile, userSession, context);
569
- if (menu) {
570
- menus.push(menu);
563
+ if (_appIndex < 0) {
564
+ userApps.push(app);
565
+ }
566
+ else {
567
+ const _app = userApps[_appIndex];
568
+ if (!_app.space && app.space) {
569
+ userApps[_appIndex] = app;
571
570
  }
572
571
  }
573
- return menus;
574
572
  });
573
+ for (const app of _.sortBy(userApps, ["sort"])) {
574
+ const menu = await transformAppToMenus(ctx, app, mobile, userSession, context);
575
+ if (menu) {
576
+ menus.push(menu);
577
+ }
578
+ }
579
+ return menus;
575
580
  }
576
- function getAppMenus(ctx) {
577
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
578
- const userSession = ctx.meta.user;
579
- const { mobile } = ctx.params;
580
- if (!userSession) {
581
- throw new Error("no permission.");
582
- }
583
- const spaceId = userSession.spaceId;
584
- const metadataConf = yield get(ctx);
585
- if (metadataConf) {
586
- const appConfig = metadataConf.metadata;
587
- if (_.has(appConfig, "space") &&
588
- appConfig.space &&
589
- appConfig.space != spaceId) {
590
- return;
591
- }
592
- const context = yield getContext(ctx);
593
- const appMenus = yield transformAppToMenus(ctx, appConfig, mobile, userSession, context);
594
- if (userSession.is_space_admin &&
595
- appConfig._id &&
596
- appConfig.code &&
597
- appConfig._id != appConfig.code) {
598
- appMenus.allowEditApp = true;
599
- }
600
- return appMenus;
581
+ async function getAppMenus(ctx) {
582
+ const userSession = ctx.meta.user;
583
+ const { mobile } = ctx.params;
584
+ if (!userSession) {
585
+ throw new Error("no permission.");
586
+ }
587
+ const spaceId = userSession.spaceId;
588
+ const metadataConf = await get(ctx);
589
+ if (metadataConf) {
590
+ const appConfig = metadataConf.metadata;
591
+ if (_.has(appConfig, "space") &&
592
+ appConfig.space &&
593
+ appConfig.space != spaceId) {
594
+ return;
601
595
  }
602
- });
596
+ const context = await getContext(ctx);
597
+ const appMenus = await transformAppToMenus(ctx, appConfig, mobile, userSession, context);
598
+ if (userSession.is_space_admin &&
599
+ appConfig._id &&
600
+ appConfig.code &&
601
+ appConfig._id != appConfig.code) {
602
+ appMenus.allowEditApp = true;
603
+ }
604
+ return appMenus;
605
+ }
603
606
  }
604
607
  exports.ActionHandlers = {
605
- get(ctx) {
606
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
607
- return yield ctx.broker.call("metadata.get", { key: cacherKey(ctx.params.appApiName) }, { meta: ctx.meta });
608
- });
608
+ async get(ctx) {
609
+ return await ctx.broker.call("metadata.get", { key: cacherKey(ctx.params.appApiName) }, { meta: ctx.meta });
609
610
  },
610
- getAll(ctx) {
611
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
612
- return yield getAllApps(ctx);
613
- });
611
+ async getAll(ctx) {
612
+ return await getAllApps(ctx);
614
613
  },
615
- getMenus(ctx) {
616
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
617
- const menus = yield getAppsMenus(ctx);
618
- return menus;
619
- });
614
+ async getMenus(ctx) {
615
+ const menus = await getAppsMenus(ctx);
616
+ return menus;
620
617
  },
621
- getAppMenus(ctx) {
622
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
623
- return yield getAppMenus(ctx);
624
- });
618
+ async getAppMenus(ctx) {
619
+ return await getAppMenus(ctx);
625
620
  },
626
- add(ctx) {
627
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
628
- let config = ctx.params.data;
629
- const serviceName = ctx.meta.metadataServiceName;
630
- const metadataApiName = ctx.params.appApiName;
631
- const metadataConfig = yield (0, _1.getServiceAppConfig)(ctx, serviceName, metadataApiName);
632
- if (metadataConfig && metadataConfig.metadata) {
633
- config = (0, utils_1.defaultsDeep)(config, metadataConfig.metadata);
634
- }
635
- yield ctx.broker.call("metadata.addServiceMetadata", { key: cacherKey(metadataApiName), data: config }, {
636
- meta: Object.assign({}, ctx.meta, {
637
- metadataType: _1.METADATA_TYPE,
638
- metadataApiName: metadataApiName,
639
- }),
640
- });
641
- const appConfig = yield (0, _1.refreshApp)(ctx, metadataApiName);
642
- return yield registerApp(ctx, metadataApiName, appConfig, ctx.meta);
621
+ async add(ctx) {
622
+ let config = ctx.params.data;
623
+ const serviceName = ctx.meta.metadataServiceName;
624
+ const metadataApiName = ctx.params.appApiName;
625
+ const metadataConfig = await (0, _1.getServiceAppConfig)(ctx, serviceName, metadataApiName);
626
+ if (metadataConfig && metadataConfig.metadata) {
627
+ config = (0, utils_1.defaultsDeep)(config, metadataConfig.metadata);
628
+ }
629
+ await ctx.broker.call("metadata.addServiceMetadata", { key: cacherKey(metadataApiName), data: config }, {
630
+ meta: Object.assign({}, ctx.meta, {
631
+ metadataType: _1.METADATA_TYPE,
632
+ metadataApiName: metadataApiName,
633
+ }),
643
634
  });
635
+ const appConfig = await (0, _1.refreshApp)(ctx, metadataApiName);
636
+ return await registerApp(ctx, metadataApiName, appConfig, ctx.meta);
644
637
  },
645
- delete(ctx) {
646
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
647
- return yield ctx.broker.call("metadata.delete", { key: cacherKey(ctx.params.appApiName) }, { meta: ctx.meta });
648
- });
638
+ async delete(ctx) {
639
+ return await ctx.broker.call("metadata.delete", { key: cacherKey(ctx.params.appApiName) }, { meta: ctx.meta });
649
640
  },
650
- verify(ctx) {
651
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
652
- console.log("verify");
653
- return true;
654
- });
641
+ async verify(ctx) {
642
+ console.log("verify");
643
+ return true;
655
644
  },
656
- refresh(ctx) {
657
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
658
- const { isClear, metadataApiNames } = ctx.params;
659
- if (isClear) {
660
- for (const metadataApiName of metadataApiNames) {
661
- const appConfig = yield (0, _1.refreshApp)(ctx, metadataApiName);
662
- if (!appConfig) {
663
- yield ctx.broker.call("metadata.delete", {
664
- key: cacherKey(metadataApiName),
665
- });
666
- }
667
- else {
668
- yield registerApp(ctx, metadataApiName, appConfig, {});
669
- }
645
+ async refresh(ctx) {
646
+ const { isClear, metadataApiNames } = ctx.params;
647
+ if (isClear) {
648
+ for (const metadataApiName of metadataApiNames) {
649
+ const appConfig = await (0, _1.refreshApp)(ctx, metadataApiName);
650
+ if (!appConfig) {
651
+ await ctx.broker.call("metadata.delete", {
652
+ key: cacherKey(metadataApiName),
653
+ });
654
+ }
655
+ else {
656
+ await registerApp(ctx, metadataApiName, appConfig, {});
670
657
  }
671
658
  }
672
- });
659
+ }
673
660
  },
674
661
  };
675
662
  //# sourceMappingURL=actionsHandler.js.map