@steedos/service-metadata-apps 3.0.13-beta.3 → 3.0.13-beta.30

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,443 +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
- };
325
- if (app.enable_nav_schema && app.nav_schema && (!mobile || mobile === 'false')) {
326
- menu.nav_schema = _.isString(app.nav_schema)
327
- ? JSON.parse(app.nav_schema)
328
- : app.nav_schema;
329
- }
330
- const hiddenTabNames = context.hiddenTabNames || [];
331
- if (app.tab_items) {
332
- if (_.isArray(app.tab_items)) {
333
- for (const item of app.tab_items) {
334
- try {
335
- if (hiddenTabNames.includes(item.tab_name))
336
- continue;
337
- yield tabMenus(ctx, appPath, item.tab_name, menu, mobile, userSession, context, item);
338
- }
339
- catch (error) {
340
- ctx.broker.logger.info(error.message);
341
- }
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);
342
351
  }
343
- }
344
- else {
345
- for (const tabApiName in app.tab_items) {
346
- try {
347
- if (hiddenTabNames.includes(tabApiName))
348
- continue;
349
- const props = app.tab_items[tabApiName];
350
- yield tabMenus(ctx, appPath, tabApiName, menu, mobile, userSession, context, props);
351
- }
352
- catch (error) {
353
- ctx.broker.logger.info(error.message);
354
- }
352
+ catch (error) {
353
+ ctx.broker.logger.info(error.message);
355
354
  }
356
355
  }
357
356
  }
358
- else if (_.isArray(app.tabs)) {
359
- for (const tabApiName of app.tabs) {
357
+ else {
358
+ for (const tabApiName in app.tab_items) {
360
359
  try {
361
360
  if (hiddenTabNames.includes(tabApiName))
362
361
  continue;
363
- 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);
364
364
  }
365
365
  catch (error) {
366
366
  ctx.broker.logger.info(error.message);
367
367
  }
368
368
  }
369
369
  }
370
- const objects = mobile ? app.mobile_objects : app.objects;
371
- if (_.isArray(objects)) {
372
- const getChildrenPromises = [];
373
- for (const objectApiName of objects) {
374
- getChildrenPromises.push(getMenuChildren({
375
- objectApiName,
376
- userSession,
377
- ctx,
378
- appPath,
379
- app,
380
- }));
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);
381
377
  }
382
- const children = yield Promise.all(getChildrenPromises);
383
- for (const child of children) {
384
- if (child) {
385
- menu.children.push(child);
386
- }
378
+ catch (error) {
379
+ ctx.broker.logger.info(error.message);
387
380
  }
388
381
  }
389
- return menu;
390
- });
391
- }
392
- function getMenuChildren(_a) {
393
- return tslib_1.__awaiter(this, arguments, void 0, function* ({ objectApiName, userSession, ctx, appPath, app, }) {
394
- try {
395
- const objectConfig = yield (0, objectql_1.getObject)(objectApiName).getConfig();
396
- if (!objectConfig) {
397
- ctx.broker.logger.error(`${objectApiName} is not found in the objects of app ${app.code} `);
398
- return;
399
- }
400
- const allowRead = yield objectAllowRead(objectApiName, userSession);
401
- if (!allowRead) {
402
- return;
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);
403
399
  }
404
- if (objectConfig) {
405
- const objectLabel = (0, i18n_1.translationObjectLabel)(userSession.language, objectConfig.name, objectConfig.label || objectConfig.name);
406
- return {
407
- id: objectConfig.name,
408
- icon: objectConfig.icon,
409
- path: `${appPath}/${objectConfig.name}`,
410
- name: `${objectLabel}`,
411
- };
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";
440
+ }
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)}`;
444
+ }
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";
469
+ }
470
+ else {
471
+ defaultTab.is_use_iframe = true;
472
+ defaultTab.path = `${appPath}/tab_iframe/${tab.name}/?url=${url}`;
473
+ }
474
+ }
475
+ }
476
+ catch (e) {
477
+ console.error(e);
478
+ }
479
+ }
412
480
  }
413
481
  }
414
- catch (error) {
415
- ctx.broker.logger.error(error);
482
+ if (defaultTab) {
483
+ menu.default_tab = defaultTab;
416
484
  }
417
- });
485
+ }
486
+ return menu;
418
487
  }
419
- function getAppsMenus(ctx) {
420
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
421
- const userSession = ctx.meta.user;
422
- if (!userSession) {
423
- throw new Error("no permission.");
424
- }
425
- let assigned_apps = yield (0, objectql_1.getAssignedApps)(userSession);
426
- let mobile = ctx.params.mobile;
427
- if (typeof mobile !== "boolean") {
428
- mobile = mobile === "true" ? true : false;
429
- }
430
- const spaceId = userSession.spaceId;
431
- const metadataApps = yield getAllApps(ctx);
432
- const context = yield getContext(ctx);
433
- const allApps = _.map(metadataApps, "metadata");
434
- if (assigned_apps && assigned_apps.length) {
435
- assigned_apps = _.filter(allApps, (item) => {
436
- return assigned_apps.includes(item.code);
437
- });
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;
438
494
  }
439
- else {
440
- assigned_apps = allApps;
495
+ const allowRead = await objectAllowRead(objectApiName, userSession);
496
+ if (!allowRead) {
497
+ return;
441
498
  }
442
- const _userApps = _.filter(assigned_apps, function (config) {
443
- if (!config.visible) {
444
- return false;
445
- }
446
- if (config._id === config.code) {
447
- let dbApp = _.find(assigned_apps, (item) => {
448
- return (item.code === config.code &&
449
- item._id != item.code &&
450
- item.space === spaceId);
451
- });
452
- if (dbApp) {
453
- return dbApp.visible;
454
- }
455
- }
456
- if (_.has(config, "space") && config.space) {
457
- return config.space === spaceId;
458
- }
459
- 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);
460
530
  });
461
- const menus = [];
462
- let userApps = [];
463
- _.each(_.sortBy(_userApps, ["sort"]), function (app) {
464
- if (!app.code) {
465
- app.code = app._id;
466
- }
467
- const _appIndex = _.findIndex(userApps, function (item) {
468
- 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);
469
544
  });
470
- if (_appIndex < 0) {
471
- userApps.push(app);
472
- }
473
- else {
474
- const _app = userApps[_appIndex];
475
- if (!_app.space && app.space) {
476
- userApps[_appIndex] = app;
477
- }
545
+ if (dbApp) {
546
+ return dbApp.visible;
478
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;
479
562
  });
480
- for (const app of _.sortBy(userApps, ["sort"])) {
481
- const menu = yield transformAppToMenus(ctx, app, mobile, userSession, context);
482
- if (menu) {
483
- 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;
484
570
  }
485
571
  }
486
- return menus;
487
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;
488
580
  }
489
- function getAppMenus(ctx) {
490
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
491
- const userSession = ctx.meta.user;
492
- const { mobile } = ctx.params;
493
- if (!userSession) {
494
- throw new Error("no permission.");
495
- }
496
- const spaceId = userSession.spaceId;
497
- const metadataConf = yield get(ctx);
498
- if (metadataConf) {
499
- const appConfig = metadataConf.metadata;
500
- if (_.has(appConfig, "space") &&
501
- appConfig.space &&
502
- appConfig.space != spaceId) {
503
- return;
504
- }
505
- const context = yield getContext(ctx);
506
- const appMenus = yield transformAppToMenus(ctx, appConfig, mobile, userSession, context);
507
- if (userSession.is_space_admin &&
508
- appConfig._id &&
509
- appConfig.code &&
510
- appConfig._id != appConfig.code) {
511
- appMenus.allowEditApp = true;
512
- }
513
- 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;
514
595
  }
515
- });
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
+ }
516
606
  }
517
607
  exports.ActionHandlers = {
518
- get(ctx) {
519
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
520
- return yield ctx.broker.call("metadata.get", { key: cacherKey(ctx.params.appApiName) }, { meta: ctx.meta });
521
- });
608
+ async get(ctx) {
609
+ return await ctx.broker.call("metadata.get", { key: cacherKey(ctx.params.appApiName) }, { meta: ctx.meta });
522
610
  },
523
- getAll(ctx) {
524
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
525
- return yield getAllApps(ctx);
526
- });
611
+ async getAll(ctx) {
612
+ return await getAllApps(ctx);
527
613
  },
528
- getMenus(ctx) {
529
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
530
- const menus = yield getAppsMenus(ctx);
531
- return menus;
532
- });
614
+ async getMenus(ctx) {
615
+ const menus = await getAppsMenus(ctx);
616
+ return menus;
533
617
  },
534
- getAppMenus(ctx) {
535
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
536
- return yield getAppMenus(ctx);
537
- });
618
+ async getAppMenus(ctx) {
619
+ return await getAppMenus(ctx);
538
620
  },
539
- add(ctx) {
540
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
541
- let config = ctx.params.data;
542
- const serviceName = ctx.meta.metadataServiceName;
543
- const metadataApiName = ctx.params.appApiName;
544
- const metadataConfig = yield (0, _1.getServiceAppConfig)(ctx, serviceName, metadataApiName);
545
- if (metadataConfig && metadataConfig.metadata) {
546
- config = (0, utils_1.defaultsDeep)(config, metadataConfig.metadata);
547
- }
548
- yield ctx.broker.call("metadata.addServiceMetadata", { key: cacherKey(metadataApiName), data: config }, {
549
- meta: Object.assign({}, ctx.meta, {
550
- metadataType: _1.METADATA_TYPE,
551
- metadataApiName: metadataApiName,
552
- }),
553
- });
554
- const appConfig = yield (0, _1.refreshApp)(ctx, metadataApiName);
555
- 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
+ }),
556
634
  });
635
+ const appConfig = await (0, _1.refreshApp)(ctx, metadataApiName);
636
+ return await registerApp(ctx, metadataApiName, appConfig, ctx.meta);
557
637
  },
558
- delete(ctx) {
559
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
560
- return yield ctx.broker.call("metadata.delete", { key: cacherKey(ctx.params.appApiName) }, { meta: ctx.meta });
561
- });
638
+ async delete(ctx) {
639
+ return await ctx.broker.call("metadata.delete", { key: cacherKey(ctx.params.appApiName) }, { meta: ctx.meta });
562
640
  },
563
- verify(ctx) {
564
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
565
- console.log("verify");
566
- return true;
567
- });
641
+ async verify(ctx) {
642
+ console.log("verify");
643
+ return true;
568
644
  },
569
- refresh(ctx) {
570
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
571
- const { isClear, metadataApiNames } = ctx.params;
572
- if (isClear) {
573
- for (const metadataApiName of metadataApiNames) {
574
- const appConfig = yield (0, _1.refreshApp)(ctx, metadataApiName);
575
- if (!appConfig) {
576
- yield ctx.broker.call("metadata.delete", {
577
- key: cacherKey(metadataApiName),
578
- });
579
- }
580
- else {
581
- yield registerApp(ctx, metadataApiName, appConfig, {});
582
- }
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, {});
583
657
  }
584
658
  }
585
- });
659
+ }
586
660
  },
587
661
  };
588
662
  //# sourceMappingURL=actionsHandler.js.map