@next-core/runtime 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/auth.js +17 -47
- package/dist/cjs/auth.js.map +1 -1
- package/dist/cjs/index.js +8 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/Renderer.js +4 -4
- package/dist/cjs/internal/Renderer.js.map +1 -1
- package/dist/cjs/internal/Router.js +4 -6
- package/dist/cjs/internal/Router.js.map +1 -1
- package/dist/cjs/internal/Runtime.js +2 -0
- package/dist/cjs/internal/Runtime.js.map +1 -1
- package/dist/cjs/internal/compute/evaluate.js +10 -5
- package/dist/cjs/internal/compute/evaluate.js.map +1 -1
- package/dist/cjs/internal/compute/getGeneralGlobals.js +3 -2
- package/dist/cjs/internal/compute/getGeneralGlobals.js.map +1 -1
- package/dist/cjs/internal/matchRoutes.js +2 -2
- package/dist/cjs/internal/matchRoutes.js.map +1 -1
- package/dist/cjs/internal/secret_internals.js +2 -0
- package/dist/cjs/internal/secret_internals.js.map +1 -1
- package/dist/cjs/internal/test_only.js +22 -0
- package/dist/cjs/internal/test_only.js.map +1 -0
- package/dist/esm/auth.js +20 -46
- package/dist/esm/auth.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/Renderer.js +5 -5
- package/dist/esm/internal/Renderer.js.map +1 -1
- package/dist/esm/internal/Router.js +4 -6
- package/dist/esm/internal/Router.js.map +1 -1
- package/dist/esm/internal/Runtime.js +2 -0
- package/dist/esm/internal/Runtime.js.map +1 -1
- package/dist/esm/internal/compute/evaluate.js +11 -6
- package/dist/esm/internal/compute/evaluate.js.map +1 -1
- package/dist/esm/internal/compute/getGeneralGlobals.js +3 -2
- package/dist/esm/internal/compute/getGeneralGlobals.js.map +1 -1
- package/dist/esm/internal/matchRoutes.js +2 -2
- package/dist/esm/internal/matchRoutes.js.map +1 -1
- package/dist/esm/internal/secret_internals.js +2 -0
- package/dist/esm/internal/secret_internals.js.map +1 -1
- package/dist/esm/internal/test_only.js +15 -0
- package/dist/esm/internal/test_only.js.map +1 -0
- package/dist/types/auth.d.ts +8 -19
- package/dist/types/index.d.ts +2 -1
- package/dist/types/internal/Runtime.d.ts +26 -2
- package/dist/types/internal/secret_internals.d.ts +2 -0
- package/dist/types/internal/test_only.d.ts +5 -0
- package/package.json +5 -6
- package/dist/cjs/internal/checkPermissions.js +0 -102
- package/dist/cjs/internal/checkPermissions.js.map +0 -1
- package/dist/cjs/internal/menu/computeMenuData.js +0 -37
- package/dist/cjs/internal/menu/computeMenuData.js.map +0 -1
- package/dist/cjs/internal/menu/constants.js +0 -13
- package/dist/cjs/internal/menu/constants.js.map +0 -1
- package/dist/cjs/internal/menu/fetchMenuById.js +0 -102
- package/dist/cjs/internal/menu/fetchMenuById.js.map +0 -1
- package/dist/cjs/internal/menu/fetchMenuTitle.js +0 -37
- package/dist/cjs/internal/menu/fetchMenuTitle.js.map +0 -1
- package/dist/cjs/internal/menu/getMenusOfStandaloneApp.js +0 -27
- package/dist/cjs/internal/menu/getMenusOfStandaloneApp.js.map +0 -1
- package/dist/cjs/internal/menu/interfaces.js +0 -4
- package/dist/cjs/internal/menu/interfaces.js.map +0 -1
- package/dist/cjs/internal/menu/loadDynamicMenuItems.js +0 -28
- package/dist/cjs/internal/menu/loadDynamicMenuItems.js.map +0 -1
- package/dist/cjs/internal/menu/mergeMenu.js +0 -74
- package/dist/cjs/internal/menu/mergeMenu.js.map +0 -1
- package/dist/cjs/internal/menu/reorderMenuItems.js +0 -20
- package/dist/cjs/internal/menu/reorderMenuItems.js.map +0 -1
- package/dist/esm/internal/checkPermissions.js +0 -107
- package/dist/esm/internal/checkPermissions.js.map +0 -1
- package/dist/esm/internal/menu/computeMenuData.js +0 -38
- package/dist/esm/internal/menu/computeMenuData.js.map +0 -1
- package/dist/esm/internal/menu/constants.js +0 -4
- package/dist/esm/internal/menu/constants.js.map +0 -1
- package/dist/esm/internal/menu/fetchMenuById.js +0 -104
- package/dist/esm/internal/menu/fetchMenuById.js.map +0 -1
- package/dist/esm/internal/menu/fetchMenuTitle.js +0 -38
- package/dist/esm/internal/menu/fetchMenuTitle.js.map +0 -1
- package/dist/esm/internal/menu/getMenusOfStandaloneApp.js +0 -19
- package/dist/esm/internal/menu/getMenusOfStandaloneApp.js.map +0 -1
- package/dist/esm/internal/menu/interfaces.js +0 -8
- package/dist/esm/internal/menu/interfaces.js.map +0 -1
- package/dist/esm/internal/menu/loadDynamicMenuItems.js +0 -28
- package/dist/esm/internal/menu/loadDynamicMenuItems.js.map +0 -1
- package/dist/esm/internal/menu/mergeMenu.js +0 -78
- package/dist/esm/internal/menu/mergeMenu.js.map +0 -1
- package/dist/esm/internal/menu/reorderMenuItems.js +0 -14
- package/dist/esm/internal/menu/reorderMenuItems.js.map +0 -1
- package/dist/types/internal/checkPermissions.d.ts +0 -17
- package/dist/types/internal/menu/computeMenuData.d.ts +0 -7
- package/dist/types/internal/menu/constants.d.ts +0 -3
- package/dist/types/internal/menu/fetchMenuById.d.ts +0 -3
- package/dist/types/internal/menu/fetchMenuTitle.d.ts +0 -2
- package/dist/types/internal/menu/getMenusOfStandaloneApp.d.ts +0 -2
- package/dist/types/internal/menu/interfaces.d.ts +0 -74
- package/dist/types/internal/menu/loadDynamicMenuItems.d.ts +0 -3
- package/dist/types/internal/menu/mergeMenu.d.ts +0 -3
- package/dist/types/internal/menu/reorderMenuItems.d.ts +0 -2
|
@@ -92,6 +92,8 @@ export function unmountUseBrick(_ref2, mountResult) {
|
|
|
92
92
|
rendererContext.dispatchOnUnmount();
|
|
93
93
|
rendererContext.dispose();
|
|
94
94
|
}
|
|
95
|
+
|
|
96
|
+
/** For v2 compatibility of `doTransform` from brick-kit. */
|
|
95
97
|
export function legacyDoTransform(data, to, options) {
|
|
96
98
|
if (options) {
|
|
97
99
|
throw new Error("Legacy doTransform does not support options in v3");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secret_internals.js","names":["flushStableLoadBricks","pick","_internalApiGetRuntimeContext","_internalApiGetStoryboardInBootstrapData","renderBrick","RendererContext","mountTree","unmountTree","RenderTag","computeRealValue","isStrictMode","warnAboutStrictMode","customTemplates","registerAppI18n","renderUseBrick","_x","_x2","_renderUseBrick","apply","arguments","_asyncToGenerator","useBrick","data","_runtimeContext$tplSt","_runtimeContext$formS","_output$node","tplStateStoreScope","formStateStoreScope","runtimeContext","_objectSpread","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","rendererContext","renderRoot","tag","ROOT","createPortal","transform","strict","output","properties","Promise","all","blockingList","map","store","waitForAll","node","portal","Error","child","tagName","type","mountUseBrick","_ref","element","portalRoot","document","querySelector","createElement","appendChild","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","unmountUseBrick","_ref2","mountResult","remove","dispatchOnUnmount","dispose","legacyDoTransform","to","options","noInject","updateStoryboard","appId","storyboardPatch","storyboard","Object","assign","$$fulfilling","$$fulfilled","$$registerCustomTemplateProcessed","updateStoryboardByRoute","newRoute","match","getKey","route","concat","path","exact","replaceRoute","routes","key","routeKey","unshift","updateStoryboardByTemplate","newTemplate","settings","tplName","name","define","bricks","proxy","state","updateTemplatePreviewSettings","templateId","_updatePreviewSettings","brick","updateStoryboardBySnippet","snippetData","_snippetData$bricks","snippetId","length","updateSnippetPreviewSettings","previewRouteIndex","findIndex","newPreviewRoute","menu","splice"],"sources":["../../../src/internal/secret_internals.ts"],"sourcesContent":["import type {\n BrickConf,\n CustomTemplate,\n RouteConf,\n Storyboard,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { flushStableLoadBricks } from \"@next-core/loader\";\nimport { pick } from \"lodash\";\nimport {\n _internalApiGetRuntimeContext,\n _internalApiGetStoryboardInBootstrapData,\n} from \"./Runtime.js\";\nimport { renderBrick } from \"./Renderer.js\";\nimport { RendererContext } from \"./RendererContext.js\";\nimport type { DataStore } from \"./data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./interfaces.js\";\nimport { mountTree, unmountTree } from \"./mount.js\";\nimport { RenderTag } from \"./enums.js\";\nimport { computeRealValue } from \"./compute/computeRealValue.js\";\nimport { isStrictMode, warnAboutStrictMode } from \"../isStrictMode.js\";\nimport { customTemplates } from \"../CustomTemplates.js\";\nimport { registerAppI18n } from \"./registerAppI18n.js\";\n\nexport interface RenderUseBrickResult {\n tagName: string | null;\n renderRoot: RenderRoot;\n rendererContext: RendererContext;\n}\n\nexport async function renderUseBrick(\n useBrick: UseSingleBrickConf,\n data: unknown\n): Promise<RenderUseBrickResult> {\n const tplStateStoreScope: DataStore<\"STATE\">[] = [];\n const formStateStoreScope: DataStore<\"FORM_STATE\">[] = [];\n const runtimeContext: RuntimeContext = {\n ..._internalApiGetRuntimeContext()!,\n data,\n pendingPermissionsPreCheck: [],\n tplStateStoreScope,\n formStateStoreScope,\n };\n\n runtimeContext.tplStateStoreMap ??= new Map();\n runtimeContext.formStateStoreMap ??= new Map();\n\n const rendererContext = new RendererContext(\"fragment\");\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n // Will set during `mountUseBrick`\n createPortal: null!,\n };\n\n const transform = (useBrick as { transform?: Record<string, unknown> })\n .transform;\n const strict = isStrictMode();\n if (transform) {\n warnAboutStrictMode(\n strict,\n \"`useBrick.transform`\",\n 'please use \"properties\" instead, check your useBrick:',\n useBrick\n );\n }\n\n const output = await renderBrick(\n renderRoot,\n strict\n ? useBrick\n : {\n ...useBrick,\n properties: {\n ...useBrick.properties,\n ...transform,\n },\n },\n runtimeContext,\n rendererContext\n );\n\n flushStableLoadBricks();\n\n await Promise.all([\n ...output.blockingList,\n // Wait for local tpl state stores belong to current `useBrick` only.\n ...[...tplStateStoreScope, ...formStateStoreScope].map((store) =>\n store.waitForAll()\n ),\n ...runtimeContext.pendingPermissionsPreCheck,\n ]);\n\n if (output.node?.portal) {\n throw new Error(\"The root brick of useBrick cannot be a portal brick\");\n }\n\n renderRoot.child = output.node;\n\n const tagName = output.node ? output.node.type : null;\n\n return { tagName, renderRoot, rendererContext };\n}\n\nexport interface MountUseBrickResult {\n portal?: HTMLElement;\n}\n\nexport function mountUseBrick(\n { renderRoot, rendererContext }: RenderUseBrickResult,\n element: HTMLElement\n): MountUseBrickResult {\n let portal: HTMLElement | undefined;\n renderRoot.createPortal = () => {\n const portalRoot = document.querySelector(\n \"#portal-mount-point\"\n ) as HTMLElement;\n portal = document.createElement(\"div\");\n portalRoot.appendChild(portal);\n return portal;\n };\n\n mountTree(renderRoot, element);\n\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n\n return {\n portal,\n };\n}\n\nexport function unmountUseBrick(\n { rendererContext }: RenderUseBrickResult,\n mountResult: MountUseBrickResult\n): void {\n // if (mountResult.mainBrick) {\n // mountResult.mainBrick.unmount();\n // }\n if (mountResult.portal) {\n unmountTree(mountResult.portal);\n mountResult.portal.remove();\n }\n rendererContext.dispatchOnUnmount();\n rendererContext.dispose();\n}\n\nexport function legacyDoTransform(\n data: unknown,\n to: unknown,\n options?: unknown\n) {\n if (options) {\n throw new Error(\"Legacy doTransform does not support options in v3\");\n }\n return computeRealValue(\n to,\n {\n ..._internalApiGetRuntimeContext()!,\n data,\n },\n {\n noInject: true,\n }\n );\n}\n\nexport function updateStoryboard(\n appId: string,\n storyboardPatch: Partial<Storyboard>\n): void {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n Object.assign(storyboard, {\n ...storyboardPatch,\n $$fulfilling: null,\n $$fulfilled: true,\n $$registerCustomTemplateProcessed: false,\n });\n registerAppI18n(storyboard);\n}\n\nexport function updateStoryboardByRoute(appId: string, newRoute: RouteConf) {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n let match = false;\n const getKey = (route: RouteConf): string => `${route.path}.${route.exact}`;\n const replaceRoute = (routes: RouteConf[], key: string): RouteConf[] => {\n return routes.map((route) => {\n const routeKey = getKey(route);\n if (route.type === \"routes\") {\n route.routes = replaceRoute(route.routes, key);\n return route;\n } else if (routeKey === key) {\n match = true;\n return newRoute;\n } else {\n return route;\n }\n });\n };\n storyboard.routes = replaceRoute(storyboard.routes, getKey(newRoute));\n if (!match) {\n storyboard.routes.unshift(newRoute);\n }\n}\n\nexport function updateStoryboardByTemplate(\n appId: string,\n newTemplate: CustomTemplate,\n settings: unknown\n): void {\n const tplName = `${appId}.${newTemplate.name}`;\n // customTemplateRegistry.delete(tplName);\n customTemplates.define(tplName, {\n bricks: newTemplate.bricks,\n proxy: newTemplate.proxy,\n state: newTemplate.state,\n });\n updateTemplatePreviewSettings(appId, newTemplate.name, settings);\n}\n\nexport function updateTemplatePreviewSettings(\n appId: string,\n templateId: string,\n settings?: unknown\n): void {\n _updatePreviewSettings(\n appId,\n `\\${APP.homepage}/_dev_only_/template-preview/${templateId}`,\n [\n {\n brick: templateId,\n ...pick(settings, \"properties\", \"events\", \"lifeCycle\", \"context\"),\n },\n ]\n );\n}\n\nexport function updateStoryboardBySnippet(\n appId: string,\n snippetData: {\n snippetId: string;\n bricks?: BrickConf[];\n }\n): void {\n _updatePreviewSettings(\n appId,\n `\\${APP.homepage}/_dev_only_/snippet-preview/${snippetData.snippetId}`,\n snippetData.bricks?.length ? snippetData.bricks : [{ brick: \"span\" }]\n );\n}\n\nexport const updateSnippetPreviewSettings = updateStoryboardBySnippet;\n\nfunction _updatePreviewSettings(\n appId: string,\n path: string,\n bricks: BrickConf[]\n) {\n const { routes } = _internalApiGetStoryboardInBootstrapData(appId)!;\n const previewRouteIndex = routes.findIndex((route) => route.path === path);\n const newPreviewRoute: RouteConf = {\n path,\n bricks,\n menu: false,\n exact: true,\n };\n if (previewRouteIndex === -1) {\n routes.unshift(newPreviewRoute);\n } else {\n routes.splice(previewRouteIndex, 1, newPreviewRoute);\n }\n}\n"],"mappings":";;AAOA,SAASA,qBAAqB,QAAQ,mBAAmB;AACzD,SAASC,IAAI,QAAQ,QAAQ;AAC7B,SACEC,6B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AKA,IAAI,CAAC;EAC1E,IAAM4B,eAA0B,GAAG;IACjC5B,IAAI;IACJa,MAAM;IACNgB,IAAI,EAAE,KAAK;IACX5B,KAAK,EAAE;EACT,CAAC;EACD,IAAIyB,iBAAiB,KAAK,CAAC,CAAC,EAAE;IAC5BvB,MAAM,CAACG,OAAO,CAACsB,eAAe,CAAC;EACjC,CAAC,MAAM;IACLzB,MAAM,CAAC2B,MAAM,CAACJ,iBAAiB,EAAE,CAAC,EAAEE,eAAe,CAAC;EACtD;AACF"}
|
|
1
|
+
{"version":3,"file":"secret_internals.js","names":["flushStableLoadBricks","pick","_internalApiGetRuntimeContext","_internalApiGetStoryboardInBootstrapData","renderBrick","RendererContext","mountTree","unmountTree","RenderTag","computeRealValue","isStrictMode","warnAboutStrictMode","customTemplates","registerAppI18n","renderUseBrick","_x","_x2","_renderUseBrick","apply","arguments","_asyncToGenerator","useBrick","data","_runtimeContext$tplSt","_runtimeContext$formS","_output$node","tplStateStoreScope","formStateStoreScope","runtimeContext","_objectSpread","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","rendererContext","renderRoot","tag","ROOT","createPortal","transform","strict","output","properties","Promise","all","blockingList","map","store","waitForAll","node","portal","Error","child","tagName","type","mountUseBrick","_ref","element","portalRoot","document","querySelector","createElement","appendChild","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","unmountUseBrick","_ref2","mountResult","remove","dispatchOnUnmount","dispose","legacyDoTransform","to","options","noInject","updateStoryboard","appId","storyboardPatch","storyboard","Object","assign","$$fulfilling","$$fulfilled","$$registerCustomTemplateProcessed","updateStoryboardByRoute","newRoute","match","getKey","route","concat","path","exact","replaceRoute","routes","key","routeKey","unshift","updateStoryboardByTemplate","newTemplate","settings","tplName","name","define","bricks","proxy","state","updateTemplatePreviewSettings","templateId","_updatePreviewSettings","brick","updateStoryboardBySnippet","snippetData","_snippetData$bricks","snippetId","length","updateSnippetPreviewSettings","previewRouteIndex","findIndex","newPreviewRoute","menu","splice"],"sources":["../../../src/internal/secret_internals.ts"],"sourcesContent":["import type {\n BrickConf,\n CustomTemplate,\n RouteConf,\n Storyboard,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { flushStableLoadBricks } from \"@next-core/loader\";\nimport { pick } from \"lodash\";\nimport {\n _internalApiGetRuntimeContext,\n _internalApiGetStoryboardInBootstrapData,\n} from \"./Runtime.js\";\nimport { renderBrick } from \"./Renderer.js\";\nimport { RendererContext } from \"./RendererContext.js\";\nimport type { DataStore } from \"./data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./interfaces.js\";\nimport { mountTree, unmountTree } from \"./mount.js\";\nimport { RenderTag } from \"./enums.js\";\nimport { computeRealValue } from \"./compute/computeRealValue.js\";\nimport { isStrictMode, warnAboutStrictMode } from \"../isStrictMode.js\";\nimport { customTemplates } from \"../CustomTemplates.js\";\nimport { registerAppI18n } from \"./registerAppI18n.js\";\n\nexport type { RuntimeContext } from \"./interfaces.js\";\n\nexport interface RenderUseBrickResult {\n tagName: string | null;\n renderRoot: RenderRoot;\n rendererContext: RendererContext;\n}\n\nexport async function renderUseBrick(\n useBrick: UseSingleBrickConf,\n data: unknown\n): Promise<RenderUseBrickResult> {\n const tplStateStoreScope: DataStore<\"STATE\">[] = [];\n const formStateStoreScope: DataStore<\"FORM_STATE\">[] = [];\n const runtimeContext: RuntimeContext = {\n ..._internalApiGetRuntimeContext()!,\n data,\n pendingPermissionsPreCheck: [],\n tplStateStoreScope,\n formStateStoreScope,\n };\n\n runtimeContext.tplStateStoreMap ??= new Map();\n runtimeContext.formStateStoreMap ??= new Map();\n\n const rendererContext = new RendererContext(\"fragment\");\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n // Will set during `mountUseBrick`\n createPortal: null!,\n };\n\n const transform = (useBrick as { transform?: Record<string, unknown> })\n .transform;\n const strict = isStrictMode();\n if (transform) {\n warnAboutStrictMode(\n strict,\n \"`useBrick.transform`\",\n 'please use \"properties\" instead, check your useBrick:',\n useBrick\n );\n }\n\n const output = await renderBrick(\n renderRoot,\n strict\n ? useBrick\n : {\n ...useBrick,\n properties: {\n ...useBrick.properties,\n ...transform,\n },\n },\n runtimeContext,\n rendererContext\n );\n\n flushStableLoadBricks();\n\n await Promise.all([\n ...output.blockingList,\n // Wait for local tpl state stores belong to current `useBrick` only.\n ...[...tplStateStoreScope, ...formStateStoreScope].map((store) =>\n store.waitForAll()\n ),\n ...runtimeContext.pendingPermissionsPreCheck,\n ]);\n\n if (output.node?.portal) {\n throw new Error(\"The root brick of useBrick cannot be a portal brick\");\n }\n\n renderRoot.child = output.node;\n\n const tagName = output.node ? output.node.type : null;\n\n return { tagName, renderRoot, rendererContext };\n}\n\nexport interface MountUseBrickResult {\n portal?: HTMLElement;\n}\n\nexport function mountUseBrick(\n { renderRoot, rendererContext }: RenderUseBrickResult,\n element: HTMLElement\n): MountUseBrickResult {\n let portal: HTMLElement | undefined;\n renderRoot.createPortal = () => {\n const portalRoot = document.querySelector(\n \"#portal-mount-point\"\n ) as HTMLElement;\n portal = document.createElement(\"div\");\n portalRoot.appendChild(portal);\n return portal;\n };\n\n mountTree(renderRoot, element);\n\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n\n return {\n portal,\n };\n}\n\nexport function unmountUseBrick(\n { rendererContext }: RenderUseBrickResult,\n mountResult: MountUseBrickResult\n): void {\n // if (mountResult.mainBrick) {\n // mountResult.mainBrick.unmount();\n // }\n if (mountResult.portal) {\n unmountTree(mountResult.portal);\n mountResult.portal.remove();\n }\n rendererContext.dispatchOnUnmount();\n rendererContext.dispose();\n}\n\n/** For v2 compatibility of `doTransform` from brick-kit. */\nexport function legacyDoTransform(\n data: unknown,\n to: unknown,\n options?: unknown\n) {\n if (options) {\n throw new Error(\"Legacy doTransform does not support options in v3\");\n }\n return computeRealValue(\n to,\n {\n ..._internalApiGetRuntimeContext()!,\n data,\n },\n {\n noInject: true,\n }\n );\n}\n\nexport function updateStoryboard(\n appId: string,\n storyboardPatch: Partial<Storyboard>\n): void {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n Object.assign(storyboard, {\n ...storyboardPatch,\n $$fulfilling: null,\n $$fulfilled: true,\n $$registerCustomTemplateProcessed: false,\n });\n registerAppI18n(storyboard);\n}\n\nexport function updateStoryboardByRoute(appId: string, newRoute: RouteConf) {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n let match = false;\n const getKey = (route: RouteConf): string => `${route.path}.${route.exact}`;\n const replaceRoute = (routes: RouteConf[], key: string): RouteConf[] => {\n return routes.map((route) => {\n const routeKey = getKey(route);\n if (route.type === \"routes\") {\n route.routes = replaceRoute(route.routes, key);\n return route;\n } else if (routeKey === key) {\n match = true;\n return newRoute;\n } else {\n return route;\n }\n });\n };\n storyboard.routes = replaceRoute(storyboard.routes, getKey(newRoute));\n if (!match) {\n storyboard.routes.unshift(newRoute);\n }\n}\n\nexport function updateStoryboardByTemplate(\n appId: string,\n newTemplate: CustomTemplate,\n settings: unknown\n): void {\n const tplName = `${appId}.${newTemplate.name}`;\n // customTemplateRegistry.delete(tplName);\n customTemplates.define(tplName, {\n bricks: newTemplate.bricks,\n proxy: newTemplate.proxy,\n state: newTemplate.state,\n });\n updateTemplatePreviewSettings(appId, newTemplate.name, settings);\n}\n\nexport function updateTemplatePreviewSettings(\n appId: string,\n templateId: string,\n settings?: unknown\n): void {\n _updatePreviewSettings(\n appId,\n `\\${APP.homepage}/_dev_only_/template-preview/${templateId}`,\n [\n {\n brick: templateId,\n ...pick(settings, \"properties\", \"events\", \"lifeCycle\", \"context\"),\n },\n ]\n );\n}\n\nexport function updateStoryboardBySnippet(\n appId: string,\n snippetData: {\n snippetId: string;\n bricks?: BrickConf[];\n }\n): void {\n _updatePreviewSettings(\n appId,\n `\\${APP.homepage}/_dev_only_/snippet-preview/${snippetData.snippetId}`,\n snippetData.bricks?.length ? snippetData.bricks : [{ brick: \"span\" }]\n );\n}\n\nexport const updateSnippetPreviewSettings = updateStoryboardBySnippet;\n\nfunction _updatePreviewSettings(\n appId: string,\n path: string,\n bricks: BrickConf[]\n) {\n const { routes } = _internalApiGetStoryboardInBootstrapData(appId)!;\n const previewRouteIndex = routes.findIndex((route) => route.path === path);\n const newPreviewRoute: RouteConf = {\n path,\n bricks,\n menu: false,\n exact: true,\n };\n if (previewRouteIndex === -1) {\n routes.unshift(newPreviewRoute);\n } else {\n routes.splice(previewRouteIndex, 1, newPreviewRoute);\n }\n}\n"],"mappings":";;AAOA,SAASA,qBAAqB,QAAQ,mBAAmB;AACzD,SAASC,IAAI,QAAQ,QAAQ;AAC7B,SACEC,6BAA6B,EAC7BC,wCAAwC,QACnC,cAAc;AACrB,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,eAAe,QAAQ,sBAAsB;AAGtD,SAASC,SAAS,EAAEC,WAAW,QAAQ,YAAY;AACnD,SAASC,SAAS,QAAQ,YAAY;AACtC,SAASC,gBAAgB,QAAQ,+BAA+B;AAChE,SAASC,YAAY,EAAEC,mBAAmB,QAAQ,oBAAoB;AACtE,SAASC,eAAe,QAAQ,uBAAuB;AACvD,SAASC,eAAe,QAAQ,sBAAsB;AAUtD,gBAAsBC,cAAcA,CAAAC,EAAA,EAAAC,GAAA;EAAA,OAAAC,eAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;AAwEnC,SAAAF,gBAAA;EAAAA,eAAA,GAAAG,iBAAA,CAxEM,WACLC,QAA4B,EAC5BC,IAAa,EACkB;IAAA,IAAAC,qBAAA,EAAAC,qBAAA,EAAAC,YAAA;IAC/B,IAAMC,kBAAwC,GAAG,EAAE;IACnD,IAAMC,mBAA8C,GAAG,EAAE;IACzD,IAAMC,cAA8B,GAAAC,aAAA,CAAAA,aAAA,KAC/B3B,6BAA6B,EAAE;MAClCoB,IAAI;MACJQ,0BAA0B,EAAE,EAAE;MAC9BJ,kBAAkB;MAClBC;IAAmB,EACpB;IAED,CAAAJ,qBAAA,GAAAK,cAAc,CAAC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MAAM,cAAAS,mBAAA,eAAlBA,mBAAA,CAAoBE,MAAM,GAAGH,WAAW,CAACR,MAAM,GAAG,CAAC;IAAEM,KAAK,EAAE;EAAO,CAAC,CAAC,CACtE;AACH;AAEA,OAAO,IAAMM,4BAA4B,GAAGL,yBAAyB;AAErE,SAASF,sBAAsBA,CAC7BhC,KAAa,EACbc,IAAY,EACZa,MAAmB,EACnB;EACA,IAAM;IAAEV;EAAO,CAAC,GAAG3F,wCAAwC,CAAC0E,KAAK,CAAE;EACnE,IAAMwC,iBAAiB,GAAGvB,MAAM,CAACwB,SAAS,CAAE7B,KAAK,IAAKA,KAAK,CAACE,IAAI,KAAKA,IAAI,CAAC;EAC1E,IAAM4B,eAA0B,GAAG;IACjC5B,IAAI;IACJa,MAAM;IACNgB,IAAI,EAAE,KAAK;IACX5B,KAAK,EAAE;EACT,CAAC;EACD,IAAIyB,iBAAiB,KAAK,CAAC,CAAC,EAAE;IAC5BvB,MAAM,CAACG,OAAO,CAACsB,eAAe,CAAC;EACjC,CAAC,MAAM;IACLzB,MAAM,CAAC2B,MAAM,CAACJ,iBAAiB,EAAE,CAAC,EAAEE,eAAe,CAAC;EACtD;AACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// istanbul ignore file
|
|
2
|
+
|
|
3
|
+
import { _internalApiGetStoryboardInBootstrapData, _test_only_setBootstrapData } from "./Runtime.js";
|
|
4
|
+
import { resolveData } from "./data/resolveData.js";
|
|
5
|
+
import { asyncComputeRealValue } from "./compute/computeRealValue.js";
|
|
6
|
+
export var __test_only;
|
|
7
|
+
if (process.env.NODE_ENV === "test") {
|
|
8
|
+
__test_only = {
|
|
9
|
+
setBootstrapData: _test_only_setBootstrapData,
|
|
10
|
+
getStoryboardByAppId: _internalApiGetStoryboardInBootstrapData,
|
|
11
|
+
resolveData,
|
|
12
|
+
asyncComputeRealValue
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=test_only.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test_only.js","names":["_internalApiGetStoryboardInBootstrapData","_test_only_setBootstrapData","resolveData","asyncComputeRealValue","__test_only","process","env","NODE_ENV","setBootstrapData","getStoryboardByAppId"],"sources":["../../../src/internal/test_only.ts"],"sourcesContent":["// istanbul ignore file\nimport type { BootstrapData } from \"@next-core/types\";\nimport {\n RuntimeHooksMenuHelpers,\n _internalApiGetStoryboardInBootstrapData,\n _test_only_setBootstrapData,\n} from \"./Runtime.js\";\nimport { resolveData } from \"./data/resolveData.js\";\nimport { asyncComputeRealValue } from \"./compute/computeRealValue.js\";\n\nexport let __test_only: RuntimeHooksMenuHelpers & {\n setBootstrapData(data: BootstrapData): void;\n};\n\nif (process.env.NODE_ENV === \"test\") {\n __test_only = {\n setBootstrapData: _test_only_setBootstrapData,\n getStoryboardByAppId: _internalApiGetStoryboardInBootstrapData,\n resolveData,\n asyncComputeRealValue,\n };\n}\n"],"mappings":"AAAA;;AAEA,SAEEA,wCAAwC,EACxCC,2BAA2B,QACtB,cAAc;AACrB,SAASC,WAAW,QAAQ,uBAAuB;AACnD,SAASC,qBAAqB,QAAQ,+BAA+B;AAErE,OAAO,IAAIC,WAEV;AAED,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,MAAM,EAAE;EACnCH,WAAW,GAAG;IACZI,gBAAgB,EAAEP,2BAA2B;IAC7CQ,oBAAoB,EAAET,wCAAwC;IAC9DE,WAAW;IACXC;EACF,CAAC;AACH"}
|
package/dist/types/auth.d.ts
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* @returns 当前登录认证信息。
|
|
10
|
-
*/
|
|
11
|
-
export declare function getAuth(): AuthInfo;
|
|
12
|
-
/** @internal */
|
|
13
|
-
export declare function logout(): void;
|
|
14
|
-
/**
|
|
15
|
-
* 查看当前是否已登录。
|
|
16
|
-
*
|
|
17
|
-
* @returns 当前是否已登录。
|
|
18
|
-
*/
|
|
19
|
-
export declare function isLoggedIn(): boolean;
|
|
1
|
+
/** @deprecated import it from "@next-core/easyops-runtime" instead */
|
|
2
|
+
export declare function authenticate(...args: unknown[]): void;
|
|
3
|
+
/** @deprecated import it from "@next-core/easyops-runtime" instead */
|
|
4
|
+
export declare function getAuth(): object | undefined;
|
|
5
|
+
/** @deprecated import it from "@next-core/easyops-runtime" instead */
|
|
6
|
+
export declare function logout(): unknown;
|
|
7
|
+
/** @deprecated import it from "@next-core/easyops-runtime" instead */
|
|
8
|
+
export declare function isLoggedIn(): boolean | undefined;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -7,9 +7,10 @@ export * from "./getPageInfo.js";
|
|
|
7
7
|
export * from "./handleHttpError.js";
|
|
8
8
|
export * from "./history.js";
|
|
9
9
|
export * from "./createRoot.js";
|
|
10
|
-
export { createRuntime, getRuntime, type RuntimeOptions, type RuntimeHooks, } from "./internal/Runtime.js";
|
|
10
|
+
export { createRuntime, getRuntime, type RuntimeOptions, type RuntimeHooks, type RuntimeHooksMenuHelpers, } from "./internal/Runtime.js";
|
|
11
11
|
import * as __secret_internals from "./internal/secret_internals.js";
|
|
12
12
|
export { __secret_internals };
|
|
13
|
+
export { __test_only } from "./internal/test_only.js";
|
|
13
14
|
export { getCssPropertyValue, getCurrentTheme, getCurrentMode, batchSetAppsLocalTheme, applyTheme, } from "./themeAndMode.js";
|
|
14
15
|
export { checkIfOfComputed, checkIfByTransform, } from "./internal/compute/checkIf.js";
|
|
15
16
|
export { registerWidgetFunctions } from "./internal/compute/WidgetFunctions.js";
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import type { RuntimeStoryboard, FeatureFlags, BootstrapData, Contract, Storyboard } from "@next-core/types";
|
|
1
|
+
import type { RuntimeStoryboard, FeatureFlags, BootstrapData, Contract, Storyboard, BrickConf, RouteConf, ResolveConf } from "@next-core/types";
|
|
2
2
|
import type { PermissionApi_validatePermissions } from "@next-api-sdk/micro-app-sdk";
|
|
3
3
|
import "moment/locale/zh-cn.js";
|
|
4
4
|
import type { AppForCheck } from "./hasInstalledApp.js";
|
|
5
|
+
import type { RuntimeContext } from "./interfaces.js";
|
|
5
6
|
export interface RuntimeOptions {
|
|
6
7
|
hooks?: RuntimeHooks;
|
|
7
8
|
}
|
|
8
9
|
export interface RuntimeHooks {
|
|
10
|
+
auth?: {
|
|
11
|
+
getAuth(): object;
|
|
12
|
+
isLoggedIn(): boolean;
|
|
13
|
+
authenticate?(...args: unknown[]): unknown;
|
|
14
|
+
logout?(...args: unknown[]): unknown;
|
|
15
|
+
};
|
|
9
16
|
fulfilStoryboard?: (storyboard: RuntimeStoryboard) => Promise<void>;
|
|
10
17
|
validatePermissions?: typeof PermissionApi_validatePermissions;
|
|
18
|
+
checkPermissions?: {
|
|
19
|
+
checkPermissions(...actions: string[]): boolean;
|
|
20
|
+
preCheckPermissions(storyboard: Storyboard): Promise<void> | undefined;
|
|
21
|
+
preCheckPermissionsForBrickOrRoute(container: BrickConf | RouteConf, asyncComputeRealValue: (value: unknown) => Promise<unknown>): Promise<void> | undefined;
|
|
22
|
+
};
|
|
11
23
|
checkInstalledApps?: {
|
|
12
24
|
preCheckInstalledApps(storyboard: Storyboard, hasAppInBootstrap: (appId: string) => boolean): void;
|
|
13
25
|
waitForCheckingApps(appIds: string[]): Promise<void>;
|
|
@@ -22,6 +34,18 @@ export interface RuntimeHooks {
|
|
|
22
34
|
collectWidgetContract(contracts: Contract[] | undefined): void;
|
|
23
35
|
clearCollectWidgetContract(): void;
|
|
24
36
|
};
|
|
37
|
+
menu?: {
|
|
38
|
+
getMenuById(menuId: string): unknown;
|
|
39
|
+
fetchMenuById(menuId: string, runtimeContext: RuntimeContext, runtimeHelpers: RuntimeHooksMenuHelpers): Promise<unknown>;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export interface RuntimeHooksMenuHelpers {
|
|
43
|
+
getStoryboardByAppId(appId: string): Storyboard | undefined;
|
|
44
|
+
resolveData(resolveConf: ResolveConf, runtimeContext: RuntimeContext): Promise<unknown>;
|
|
45
|
+
asyncComputeRealValue(value: unknown, runtimeContext: RuntimeContext, options?: {
|
|
46
|
+
ignoreSymbols?: boolean;
|
|
47
|
+
noInject?: boolean;
|
|
48
|
+
}): Promise<unknown>;
|
|
25
49
|
}
|
|
26
50
|
export declare let hooks: RuntimeHooks | undefined;
|
|
27
51
|
export declare function createRuntime(options?: RuntimeOptions): Runtime;
|
|
@@ -54,7 +78,7 @@ export declare function getBrickPackages(): import("@next-core/types").BrickPack
|
|
|
54
78
|
export declare function _internalApiLoadBricks(bricks: string[] | Set<string>): Promise<void>;
|
|
55
79
|
export declare function _internalApiGetRenderId(): string | undefined;
|
|
56
80
|
export declare function _internalApiMatchStoryboard(pathname: string): RuntimeStoryboard | undefined;
|
|
57
|
-
export declare function _internalApiGetRuntimeContext():
|
|
81
|
+
export declare function _internalApiGetRuntimeContext(): RuntimeContext | undefined;
|
|
58
82
|
export declare function _internalApiGetStoryboardInBootstrapData(appId: string): Storyboard | undefined;
|
|
59
83
|
export declare function _internalApiGetAppInBootstrapData(appId: string): import("@next-core/types").MicroApp | undefined;
|
|
60
84
|
export declare let _test_only_setBootstrapData: (data: BootstrapData) => void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { BrickConf, CustomTemplate, RouteConf, Storyboard, UseSingleBrickConf } from "@next-core/types";
|
|
2
2
|
import { RendererContext } from "./RendererContext.js";
|
|
3
3
|
import type { RenderRoot } from "./interfaces.js";
|
|
4
|
+
export type { RuntimeContext } from "./interfaces.js";
|
|
4
5
|
export interface RenderUseBrickResult {
|
|
5
6
|
tagName: string | null;
|
|
6
7
|
renderRoot: RenderRoot;
|
|
@@ -12,6 +13,7 @@ export interface MountUseBrickResult {
|
|
|
12
13
|
}
|
|
13
14
|
export declare function mountUseBrick({ renderRoot, rendererContext }: RenderUseBrickResult, element: HTMLElement): MountUseBrickResult;
|
|
14
15
|
export declare function unmountUseBrick({ rendererContext }: RenderUseBrickResult, mountResult: MountUseBrickResult): void;
|
|
16
|
+
/** For v2 compatibility of `doTransform` from brick-kit. */
|
|
15
17
|
export declare function legacyDoTransform(data: unknown, to: unknown, options?: unknown): unknown;
|
|
16
18
|
export declare function updateStoryboard(appId: string, storyboardPatch: Partial<Storyboard>): void;
|
|
17
19
|
export declare function updateStoryboardByRoute(appId: string, newRoute: RouteConf): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-core/runtime",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"homepage": "https://github.com/easyops-cn/next-core/tree/v3/packages/runtime",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,15 +43,14 @@
|
|
|
43
43
|
"test:ci": "cross-env NODE_ENV='test' CI=true test-next"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@next-
|
|
47
|
-
"@next-core/cook": "^2.2.0",
|
|
46
|
+
"@next-core/cook": "^2.2.1",
|
|
48
47
|
"@next-core/http": "^1.0.5",
|
|
49
|
-
"@next-core/i18n": "^1.0.
|
|
48
|
+
"@next-core/i18n": "^1.0.18",
|
|
50
49
|
"@next-core/inject": "^1.0.11",
|
|
51
50
|
"@next-core/loader": "^1.3.1",
|
|
52
51
|
"@next-core/supply": "^2.1.0",
|
|
53
52
|
"@next-core/types": "^1.3.0",
|
|
54
|
-
"@next-core/utils": "^1.5.
|
|
53
|
+
"@next-core/utils": "^1.5.1",
|
|
55
54
|
"@ungap/event-target": "^0.2.3",
|
|
56
55
|
"compare-versions": "^5.0.3",
|
|
57
56
|
"history": "^4.10.1",
|
|
@@ -66,5 +65,5 @@
|
|
|
66
65
|
"@next-core/build-next-libs": "^1.0.4",
|
|
67
66
|
"@next-core/test-next": "^1.0.5"
|
|
68
67
|
},
|
|
69
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "356cc700fe17242f01c76cd77e3f8d3c4971c4d4"
|
|
70
69
|
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.checkPermissions = checkPermissions;
|
|
7
|
-
exports.preCheckPermissions = preCheckPermissions;
|
|
8
|
-
exports.preCheckPermissionsForAny = preCheckPermissionsForAny;
|
|
9
|
-
exports.preCheckPermissionsForBrickOrRoute = preCheckPermissionsForBrickOrRoute;
|
|
10
|
-
exports.resetPermissionPreChecks = resetPermissionPreChecks;
|
|
11
|
-
exports.validatePermissions = validatePermissions;
|
|
12
|
-
var _lodash = require("lodash");
|
|
13
|
-
var _storyboard = require("@next-core/utils/storyboard");
|
|
14
|
-
var _auth = require("../auth.js");
|
|
15
|
-
var _computeRealValue = require("./compute/computeRealValue.js");
|
|
16
|
-
var _Runtime = require("./Runtime.js");
|
|
17
|
-
const checkedPermissions = [];
|
|
18
|
-
const permissionMap = new Map();
|
|
19
|
-
function preCheckPermissions(storyboard) {
|
|
20
|
-
if (_Runtime.hooks !== null && _Runtime.hooks !== void 0 && _Runtime.hooks.validatePermissions && (0, _auth.isLoggedIn)() && !(0, _auth.getAuth)().isAdmin) {
|
|
21
|
-
const usedActions = (0, _storyboard.scanPermissionActionsInStoryboard)(storyboard);
|
|
22
|
-
return validatePermissions(usedActions);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
async function preCheckPermissionsForBrickOrRoute(container, runtimeContext) {
|
|
26
|
-
if (_Runtime.hooks !== null && _Runtime.hooks !== void 0 && _Runtime.hooks.validatePermissions && (0, _auth.isLoggedIn)() && !(0, _auth.getAuth)().isAdmin && Array.isArray(container.permissionsPreCheck)) {
|
|
27
|
-
const actions = await (0, _computeRealValue.asyncComputeRealValue)(container.permissionsPreCheck, runtimeContext);
|
|
28
|
-
return validatePermissions(actions);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function preCheckPermissionsForAny(data) {
|
|
32
|
-
if (_Runtime.hooks !== null && _Runtime.hooks !== void 0 && _Runtime.hooks.validatePermissions && (0, _auth.isLoggedIn)() && !(0, _auth.getAuth)().isAdmin) {
|
|
33
|
-
const usedActions = (0, _storyboard.scanPermissionActionsInAny)(data);
|
|
34
|
-
return validatePermissions(usedActions);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
async function validatePermissions(usedActions) {
|
|
38
|
-
// Do not request known actions.
|
|
39
|
-
const actions = (0, _lodash.difference)(usedActions, [...checkedPermissions]);
|
|
40
|
-
if (actions.length === 0) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
checkedPermissions.push(...actions);
|
|
44
|
-
try {
|
|
45
|
-
const result = await _Runtime.hooks.validatePermissions({
|
|
46
|
-
actions
|
|
47
|
-
});
|
|
48
|
-
for (const item of result.actions) {
|
|
49
|
-
permissionMap.set(item.action, item.authorizationStatus);
|
|
50
|
-
if (item.authorizationStatus === "undefined") {
|
|
51
|
-
// eslint-disable-next-line no-console
|
|
52
|
-
console.error(`Undefined permission action: "${item.action}"`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
} catch (error) {
|
|
56
|
-
// Allow pre-check to fail, and
|
|
57
|
-
// make it not crash when the backend service is not updated.
|
|
58
|
-
// eslint-disable-next-line no-console
|
|
59
|
-
console.error("Pre-check permissions failed", error);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Check the current logged-in user whether to have all
|
|
65
|
-
* permissions of actions passed to it.
|
|
66
|
-
*
|
|
67
|
-
* @param actions - Required permission actions.
|
|
68
|
-
*/
|
|
69
|
-
function checkPermissions(...actions) {
|
|
70
|
-
if (!(0, _auth.isLoggedIn)()) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
if ((0, _auth.getAuth)().isAdmin) {
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
for (const action of actions) {
|
|
77
|
-
// Only **exclusively authorized** permissions are ok.
|
|
78
|
-
// Those scenarios below will fail:
|
|
79
|
-
// - unauthorized actions (pre-check results)
|
|
80
|
-
// - undefined actions (pre-check results)
|
|
81
|
-
// - Un-pre-checked or pre-check failed
|
|
82
|
-
switch (permissionMap.get(action)) {
|
|
83
|
-
case "unauthorized":
|
|
84
|
-
case "undefined":
|
|
85
|
-
return false;
|
|
86
|
-
case undefined:
|
|
87
|
-
// eslint-disable-next-line no-console
|
|
88
|
-
console.error(`Un-checked permission action: "${action}", please make sure the permission to check is defined in permissionsPreCheck.`);
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Reset permission pre-checks after logged-out.
|
|
97
|
-
*/
|
|
98
|
-
function resetPermissionPreChecks() {
|
|
99
|
-
checkedPermissions.length = 0;
|
|
100
|
-
permissionMap.clear();
|
|
101
|
-
}
|
|
102
|
-
//# sourceMappingURL=checkPermissions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkPermissions.js","names":["_lodash","require","_storyboard","_auth","_computeRealValue","_Runtime","checkedPermissions","permissionMap","Map","preCheckPermissions","storyboard","hooks","validatePermissions","isLoggedIn","getAuth","isAdmin","usedActions","scanPermissionActionsInStoryboard","preCheckPermissionsForBrickOrRoute","container","runtimeContext","Array","isArray","permissionsPreCheck","actions","asyncComputeRealValue","preCheckPermissionsForAny","data","scanPermissionActionsInAny","difference","length","push","result","item","set","action","authorizationStatus","console","error","checkPermissions","get","undefined","resetPermissionPreChecks","clear"],"sources":["../../../src/internal/checkPermissions.ts"],"sourcesContent":["import { difference } from \"lodash\";\nimport {\n scanPermissionActionsInAny,\n scanPermissionActionsInStoryboard,\n} from \"@next-core/utils/storyboard\";\nimport type { BrickConf, RouteConf, Storyboard } from \"@next-core/types\";\nimport { getAuth, isLoggedIn } from \"../auth.js\";\nimport type { RuntimeContext } from \"./interfaces.js\";\nimport { asyncComputeRealValue } from \"./compute/computeRealValue.js\";\nimport { hooks } from \"./Runtime.js\";\n\ntype PermissionStatus = \"authorized\" | \"unauthorized\" | \"undefined\";\n\nconst checkedPermissions: string[] = [];\nconst permissionMap = new Map<string, PermissionStatus>();\n\nexport function preCheckPermissions(\n storyboard: Storyboard\n): Promise<void> | undefined {\n if (hooks?.validatePermissions && isLoggedIn() && !getAuth().isAdmin) {\n const usedActions = scanPermissionActionsInStoryboard(storyboard);\n return validatePermissions(usedActions);\n }\n}\n\nexport async function preCheckPermissionsForBrickOrRoute(\n container: BrickConf | RouteConf,\n runtimeContext: RuntimeContext\n) {\n if (\n hooks?.validatePermissions &&\n isLoggedIn() &&\n !getAuth().isAdmin &&\n Array.isArray(container.permissionsPreCheck)\n ) {\n const actions = (await asyncComputeRealValue(\n container.permissionsPreCheck,\n runtimeContext\n )) as string[];\n return validatePermissions(actions);\n }\n}\n\nexport function preCheckPermissionsForAny(\n data: unknown\n): Promise<void> | undefined {\n if (hooks?.validatePermissions && isLoggedIn() && !getAuth().isAdmin) {\n const usedActions = scanPermissionActionsInAny(data);\n return validatePermissions(usedActions);\n }\n}\n\nexport async function validatePermissions(\n usedActions: string[]\n): Promise<void> {\n // Do not request known actions.\n const actions = difference(usedActions, [...checkedPermissions]);\n if (actions.length === 0) {\n return;\n }\n checkedPermissions.push(...actions);\n try {\n const result = await hooks!.validatePermissions!({ actions });\n for (const item of result.actions!) {\n permissionMap.set(item.action!, item.authorizationStatus!);\n if (item.authorizationStatus === \"undefined\") {\n // eslint-disable-next-line no-console\n console.error(`Undefined permission action: \"${item.action}\"`);\n }\n }\n } catch (error) {\n // Allow pre-check to fail, and\n // make it not crash when the backend service is not updated.\n // eslint-disable-next-line no-console\n console.error(\"Pre-check permissions failed\", error);\n }\n}\n\n/**\n * Check the current logged-in user whether to have all\n * permissions of actions passed to it.\n *\n * @param actions - Required permission actions.\n */\nexport function checkPermissions(...actions: string[]): boolean {\n if (!isLoggedIn()) {\n return false;\n }\n\n if (getAuth().isAdmin) {\n return true;\n }\n\n for (const action of actions) {\n // Only **exclusively authorized** permissions are ok.\n // Those scenarios below will fail:\n // - unauthorized actions (pre-check results)\n // - undefined actions (pre-check results)\n // - Un-pre-checked or pre-check failed\n switch (permissionMap.get(action)) {\n case \"unauthorized\":\n case \"undefined\":\n return false;\n case undefined:\n // eslint-disable-next-line no-console\n console.error(\n `Un-checked permission action: \"${action}\", please make sure the permission to check is defined in permissionsPreCheck.`\n );\n return false;\n }\n }\n return true;\n}\n\n/**\n * Reset permission pre-checks after logged-out.\n */\nexport function resetPermissionPreChecks(): void {\n checkedPermissions.length = 0;\n permissionMap.clear();\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAKA,IAAAE,KAAA,GAAAF,OAAA;AAEA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAIA,MAAMK,kBAA4B,GAAG,EAAE;AACvC,MAAMC,aAAa,GAAG,IAAIC,GAAG,EAA4B;AAElD,SAASC,mBAAmBA,CACjCC,UAAsB,EACK;EAC3B,IAAIC,cAAK,aAALA,cAAK,eAALA,cAAK,CAAEC,mBAAmB,IAAI,IAAAC,gBAAU,GAAE,IAAI,CAAC,IAAAC,aAAO,GAAE,CAACC,OAAO,EAAE;IACpE,MAAMC,WAAW,GAAG,IAAAC,6CAAiC,EAACP,UAAU,CAAC;IACjE,OAAOE,mBAAmB,CAACI,WAAW,CAAC;EACzC;AACF;AAEO,eAAeE,kCAAkCA,CACtDC,SAAgC,EAChCC,cAA8B,EAC9B;EACA,IACET,cAAK,aAALA,cAAK,eAALA,cAAK,CAAEC,mBAAmB,IAC1B,IAAAC,gBAAU,GAAE,IACZ,CAA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ACC,KAAK,CAAC,8BAA8B,EAAEA,KAAK,CAAC;EACtD;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,gBAAgBA,CAAC,GAAGf,OAAiB,EAAW;EAC9D,IAAI,CAAC,IAAAX,gBAAU,GAAE,EAAE;IACjB,OAAO,KAAK;EACd;EAEA,IAAI,IAAAC,aAAO,GAAE,CAACC,OAAO,EAAE;IACrB,OAAO,IAAI;EACb;EAEA,KAAK,MAAMoB,MAAM,IAAIX,OAAO,EAAE;IAC5B;IACA;IACA;IACA;IACA;IACA,QAAQjB,aAAa,CAACiC,GAAG,CAACL,MAAM,CAAC;MAC/B,KAAK,cAAc;MACnB,KAAK,WAAW;QACd,OAAO,KAAK;MACd,KAAKM,SAAS;QACZ;QACAJ,OAAO,CAACC,KAAK,CACV,kCAAiCH,MAAO,gFAA+E,CACzH;QACD,OAAO,KAAK;IAAC;EAEnB;EACA,OAAO,IAAI;AACb;;AAEA;AACA;AACA;AACO,SAASO,wBAAwBA,CAAA,EAAS;EAC/CpC,kBAAkB,CAACwB,MAAM,GAAG,CAAC;EAC7BvB,aAAa,CAACoC,KAAK,EAAE;AACvB"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.computeMenuData = computeMenuData;
|
|
7
|
-
exports.computeMenuItems = computeMenuItems;
|
|
8
|
-
var _computeRealValue = require("../compute/computeRealValue.js");
|
|
9
|
-
var _Runtime = require("../Runtime.js");
|
|
10
|
-
var _constants = require("./constants.js");
|
|
11
|
-
function computeMenuData(data, overrideAppId, runtimeContext) {
|
|
12
|
-
let newRuntimeContext = runtimeContext;
|
|
13
|
-
if (overrideAppId !== runtimeContext.app.id) {
|
|
14
|
-
const overrideApp = window.STANDALONE_MICRO_APPS ? data[_constants.symbolOverrideApp] : (0, _Runtime._internalApiGetAppInBootstrapData)(overrideAppId);
|
|
15
|
-
newRuntimeContext = {
|
|
16
|
-
...runtimeContext,
|
|
17
|
-
overrideApp,
|
|
18
|
-
appendI18nNamespace: data[_constants.symbolMenuI18nNamespace]
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
return (0, _computeRealValue.asyncComputeRealValue)(data, newRuntimeContext, {
|
|
22
|
-
ignoreSymbols: true
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
function computeMenuItems(items, runtimeContext) {
|
|
26
|
-
return Promise.all(items.map(async ({
|
|
27
|
-
children,
|
|
28
|
-
...rest
|
|
29
|
-
}) => {
|
|
30
|
-
const [computedRest, computedChildren] = await Promise.all([computeMenuData(rest, rest[_constants.symbolAppId], runtimeContext), children && (await computeMenuItems(children, runtimeContext))]);
|
|
31
|
-
return {
|
|
32
|
-
...computedRest,
|
|
33
|
-
children: computedChildren
|
|
34
|
-
};
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=computeMenuData.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"computeMenuData.js","names":["_computeRealValue","require","_Runtime","_constants","computeMenuData","data","overrideAppId","runtimeContext","newRuntimeContext","app","id","overrideApp","window","STANDALONE_MICRO_APPS","symbolOverrideApp","_internalApiGetAppInBootstrapData","appendI18nNamespace","symbolMenuI18nNamespace","asyncComputeRealValue","ignoreSymbols","computeMenuItems","items","Promise","all","map","children","rest","computedRest","computedChildren","symbolAppId"],"sources":["../../../../src/internal/menu/computeMenuData.ts"],"sourcesContent":["import { asyncComputeRealValue } from \"../compute/computeRealValue.js\";\nimport type { RuntimeContext } from \"../interfaces.js\";\nimport type {\n RuntimeMenuItemRawData,\n RuntimeMenuRawData,\n} from \"./interfaces.js\";\nimport { _internalApiGetAppInBootstrapData } from \"../Runtime.js\";\nimport {\n symbolAppId,\n symbolMenuI18nNamespace,\n symbolOverrideApp,\n} from \"./constants.js\";\n\ntype RuntimeMenuRestRawData = Omit<RuntimeMenuRawData, \"app\" | \"items\">;\ntype RuntimeMenuItemRestRawData = Omit<RuntimeMenuItemRawData, \"children\">;\n\nexport function computeMenuData<\n T extends RuntimeMenuRestRawData | RuntimeMenuItemRestRawData\n>(data: T, overrideAppId: string, runtimeContext: RuntimeContext): Promise<T> {\n let newRuntimeContext = runtimeContext;\n if (overrideAppId !== runtimeContext.app.id) {\n const overrideApp = window.STANDALONE_MICRO_APPS\n ? data[symbolOverrideApp]\n : _internalApiGetAppInBootstrapData(overrideAppId);\n newRuntimeContext = {\n ...runtimeContext,\n overrideApp,\n appendI18nNamespace: data[symbolMenuI18nNamespace],\n };\n }\n return asyncComputeRealValue(data, newRuntimeContext, {\n ignoreSymbols: true,\n }) as Promise<T>;\n}\n\nexport function computeMenuItems(\n items: RuntimeMenuItemRawData[],\n runtimeContext: RuntimeContext\n): Promise<RuntimeMenuItemRawData[]> {\n return Promise.all(\n items.map(async ({ children, ...rest }) => {\n const [computedRest, computedChildren] = await Promise.all([\n computeMenuData(rest, rest[symbolAppId], runtimeContext),\n children && (await computeMenuItems(children, runtimeContext)),\n ]);\n return {\n ...computedRest,\n children: computedChildren,\n };\n })\n );\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AAMA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AASO,SAASG,eAAeA,CAE7BC,IAAO,EAAEC,aAAqB,EAAEC,cAA8B,EAAc;EAC5E,IAAIC,iBAAiB,GAAGD,cAAc;EACtC,IAAID,aAAa,KAAKC,cAAc,CAACE,GAAG,CAACC,EAAE,EAAE;IAC3C,MAAMC,WAAW,GAAGC,MAAM,CAACC,qBAAqB,GAC5CR,IAAI,CAACS,4BAAiB,CAAC,GACvB,IAAAC,0CAAiC,EAACT,aAAa,CAAC;IACpDE,iBAAiB,GAAG;MAClB,GAAGD,cAAc;MACjBI,WAAW;MACXK,mBAAmB,EAAEX,IAAI,CAACY,kCAAuB;IACnD,CAAC;EACH;EACA,OAAO,IAAAC,uCAAqB,EAACb,IAAI,EAAEG,iBAAiB,EAAE;IACpDW,aAAa,EAAE;EACjB,CAAC,CAAC;AACJ;AAEO,SAASC,gBAAgBA,CAC9BC,KAA+B,EAC/Bd,cAA8B,EACK;EACnC,OAAOe,OAAO,CAACC,GAAG,CAChBF,KAAK,CAACG,GAAG,CAAC,OAAO;IAAEC,QAAQ;IAAE,GAAGC;EAAK,CAAC,KAAK;IACzC,MAAM,CAACC,YAAY,EAAEC,gBAAgB,CAAC,GAAG,MAAMN,OAAO,CAACC,GAAG,CAAC,CACzDnB,eAAe,CAACsB,IAAI,EAAEA,IAAI,CAACG,sBAAW,CAAC,EAAEtB,cAAc,CAAC,EACxDkB,QAAQ,KAAK,MAAML,gBAAgB,CAACK,QAAQ,EAAElB,cAAc,CAAC,CAAC,CAC/D,CAAC;IACF,OAAO;MACL,GAAGoB,YAAY;MACfF,QAAQ,EAAEG;IACZ,CAAC;EACH,CAAC,CAAC,CACH;AACH"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.symbolOverrideApp = exports.symbolMenuI18nNamespace = exports.symbolAppId = void 0;
|
|
7
|
-
const symbolAppId = Symbol("appId");
|
|
8
|
-
exports.symbolAppId = symbolAppId;
|
|
9
|
-
const symbolMenuI18nNamespace = Symbol("menuI18nNamespace");
|
|
10
|
-
exports.symbolMenuI18nNamespace = symbolMenuI18nNamespace;
|
|
11
|
-
const symbolOverrideApp = Symbol("overrideApp");
|
|
12
|
-
exports.symbolOverrideApp = symbolOverrideApp;
|
|
13
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["symbolAppId","Symbol","exports","symbolMenuI18nNamespace","symbolOverrideApp"],"sources":["../../../../src/internal/menu/constants.ts"],"sourcesContent":["export const symbolAppId = Symbol(\"appId\");\nexport const symbolMenuI18nNamespace = Symbol(\"menuI18nNamespace\");\nexport const symbolOverrideApp = Symbol(\"overrideApp\");\n"],"mappings":";;;;;;AAAO,MAAMA,WAAW,GAAGC,MAAM,CAAC,OAAO,CAAC;AAACC,OAAA,CAAAF,WAAA,GAAAA,WAAA;AACpC,MAAMG,uBAAuB,GAAGF,MAAM,CAAC,mBAAmB,CAAC;AAACC,OAAA,CAAAC,uBAAA,GAAAA,uBAAA;AAC5D,MAAMC,iBAAiB,GAAGH,MAAM,CAAC,aAAa,CAAC;AAACC,OAAA,CAAAE,iBAAA,GAAAA,iBAAA"}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.fetchMenuById = fetchMenuById;
|
|
7
|
-
exports.getMenuById = getMenuById;
|
|
8
|
-
var _cmdbSdk = require("@next-api-sdk/cmdb-sdk");
|
|
9
|
-
var _lodash = require("lodash");
|
|
10
|
-
var _mergeMenu = require("./mergeMenu.js");
|
|
11
|
-
var _reorderMenuItems = require("./reorderMenuItems.js");
|
|
12
|
-
var _checkPermissions = require("../checkPermissions.js");
|
|
13
|
-
var _checkIf = require("../compute/checkIf.js");
|
|
14
|
-
var _computeMenuData = require("./computeMenuData.js");
|
|
15
|
-
var _fetchMenuTitle = require("./fetchMenuTitle.js");
|
|
16
|
-
var _getMenusOfStandaloneApp = require("./getMenusOfStandaloneApp.js");
|
|
17
|
-
const menuPromises = new Map();
|
|
18
|
-
const menuCache = new Map();
|
|
19
|
-
function getMenuById(menuId) {
|
|
20
|
-
return menuCache.get(menuId);
|
|
21
|
-
}
|
|
22
|
-
function fetchMenuById(menuId, runtimeContext) {
|
|
23
|
-
let promise = menuPromises.get(menuId);
|
|
24
|
-
if (!promise) {
|
|
25
|
-
promise = _fetchMenuById(menuId, runtimeContext);
|
|
26
|
-
}
|
|
27
|
-
return promise;
|
|
28
|
-
}
|
|
29
|
-
async function _fetchMenuById(menuId, runtimeContext) {
|
|
30
|
-
const menuList = window.STANDALONE_MICRO_APPS ? (0, _getMenusOfStandaloneApp.getMenusOfStandaloneApp)(menuId, runtimeContext.app.id) : (await (0, _cmdbSdk.InstanceApi_postSearch)("EASYOPS_STORYBOARD_MENU", {
|
|
31
|
-
page: 1,
|
|
32
|
-
page_size: 200,
|
|
33
|
-
fields: {
|
|
34
|
-
menuId: true,
|
|
35
|
-
title: true,
|
|
36
|
-
icon: true,
|
|
37
|
-
link: true,
|
|
38
|
-
titleDataSource: true,
|
|
39
|
-
defaultCollapsed: true,
|
|
40
|
-
defaultCollapsedBreakpoint: true,
|
|
41
|
-
type: true,
|
|
42
|
-
injectMenuGroupId: true,
|
|
43
|
-
dynamicItems: true,
|
|
44
|
-
itemsResolve: true,
|
|
45
|
-
items: true,
|
|
46
|
-
i18n: true,
|
|
47
|
-
"items.children": true,
|
|
48
|
-
"app.appId": true
|
|
49
|
-
},
|
|
50
|
-
query: {
|
|
51
|
-
menuId: {
|
|
52
|
-
$eq: menuId
|
|
53
|
-
},
|
|
54
|
-
app: {
|
|
55
|
-
$size: {
|
|
56
|
-
$gt: 0
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
})).list;
|
|
61
|
-
const menuData = await (0, _mergeMenu.mergeMenu)(menuList, runtimeContext);
|
|
62
|
-
if (!menuData) {
|
|
63
|
-
throw new Error(`Menu not found: ${menuId}`);
|
|
64
|
-
}
|
|
65
|
-
(0, _reorderMenuItems.reorderMenuItems)(menuData);
|
|
66
|
-
const {
|
|
67
|
-
items,
|
|
68
|
-
app,
|
|
69
|
-
...restMenuData
|
|
70
|
-
} = menuData;
|
|
71
|
-
const newRuntimeContext = {
|
|
72
|
-
...runtimeContext,
|
|
73
|
-
pendingPermissionsPreCheck: [...runtimeContext.pendingPermissionsPreCheck, (0, _checkPermissions.preCheckPermissionsForAny)([items, restMenuData])]
|
|
74
|
-
};
|
|
75
|
-
delete newRuntimeContext.tplStateStoreId;
|
|
76
|
-
delete newRuntimeContext.forEachItem;
|
|
77
|
-
const rootAppId = app[0].appId;
|
|
78
|
-
const [computedMenuData, computedMenuItems] = await Promise.all([(0, _computeMenuData.computeMenuData)(restMenuData, rootAppId, newRuntimeContext), (0, _computeMenuData.computeMenuItems)(items, newRuntimeContext)]);
|
|
79
|
-
const finalMenuData = {
|
|
80
|
-
title: await (0, _fetchMenuTitle.fetchMenuTitle)(computedMenuData),
|
|
81
|
-
...(0, _lodash.pick)(computedMenuData, ["icon", "link", "defaultCollapsed", "defaultCollapsedBreakpoint"]),
|
|
82
|
-
menuItems: computedMenuItems.filter(_checkIf.checkIfOfComputed).map(item => {
|
|
83
|
-
var _item$children;
|
|
84
|
-
const children = (_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.filter(_checkIf.checkIfOfComputed);
|
|
85
|
-
return item.type === "group" ? {
|
|
86
|
-
type: "group",
|
|
87
|
-
title: item.text,
|
|
88
|
-
items: children
|
|
89
|
-
} : children !== null && children !== void 0 && children.length ? {
|
|
90
|
-
type: "subMenu",
|
|
91
|
-
title: item.text,
|
|
92
|
-
icon: item.icon,
|
|
93
|
-
items: children,
|
|
94
|
-
defaultExpanded: item.defaultExpanded
|
|
95
|
-
} : item;
|
|
96
|
-
})
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
// Todo(steve): reconsider the menu cache strategy
|
|
100
|
-
menuCache.set(menuId, finalMenuData);
|
|
101
|
-
}
|
|
102
|
-
//# sourceMappingURL=fetchMenuById.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetchMenuById.js","names":["_cmdbSdk","require","_lodash","_mergeMenu","_reorderMenuItems","_checkPermissions","_checkIf","_computeMenuData","_fetchMenuTitle","_getMenusOfStandaloneApp","menuPromises","Map","menuCache","getMenuById","menuId","get","fetchMenuById","runtimeContext","promise","_fetchMenuById","menuList","window","STANDALONE_MICRO_APPS","getMenusOfStandaloneApp","app","id","InstanceApi_postSearch","page","page_size","fields","title","icon","link","titleDataSource","defaultCollapsed","defaultCollapsedBreakpoint","type","injectMenuGroupId","dynamicItems","itemsResolve","items","i18n","query","$eq","$size","$gt","list","menuData","mergeMenu","Error","reorderMenuItems","restMenuData","newRuntimeContext","pendingPermissionsPreCheck","preCheckPermissionsForAny","tplStateStoreId","forEachItem","rootAppId","appId","computedMenuData","computedMenuItems","Promise","all","computeMenuData","computeMenuItems","finalMenuData","fetchMenuTitle","pick","menuItems","filter","checkIfOfComputed","map","item","_item$children","children","text","length","defaultExpanded","set"],"sources":["../../../../src/internal/menu/fetchMenuById.ts"],"sourcesContent":["import { InstanceApi_postSearch } from \"@next-api-sdk/cmdb-sdk\";\nimport { pick } from \"lodash\";\nimport { mergeMenu } from \"./mergeMenu.js\";\nimport { reorderMenuItems } from \"./reorderMenuItems.js\";\nimport { preCheckPermissionsForAny } from \"../checkPermissions.js\";\nimport type { RuntimeContext } from \"../interfaces.js\";\nimport type { MenuRawData } from \"./interfaces.js\";\nimport { checkIfOfComputed } from \"../compute/checkIf.js\";\nimport { computeMenuItems, computeMenuData } from \"./computeMenuData.js\";\nimport { fetchMenuTitle } from \"./fetchMenuTitle.js\";\nimport { getMenusOfStandaloneApp } from \"./getMenusOfStandaloneApp.js\";\n\nconst menuPromises = new Map<string, Promise<void>>();\n\nconst menuCache = new Map<string, unknown>();\n\nexport function getMenuById(menuId: string) {\n return menuCache.get(menuId);\n}\n\nexport function fetchMenuById(menuId: string, runtimeContext: RuntimeContext) {\n let promise = menuPromises.get(menuId);\n if (!promise) {\n promise = _fetchMenuById(menuId, runtimeContext);\n }\n return promise;\n}\n\nasync function _fetchMenuById(menuId: string, runtimeContext: RuntimeContext) {\n const menuList = window.STANDALONE_MICRO_APPS\n ? getMenusOfStandaloneApp(menuId, runtimeContext.app.id)\n : ((\n await InstanceApi_postSearch(\"EASYOPS_STORYBOARD_MENU\", {\n page: 1,\n page_size: 200,\n fields: {\n menuId: true,\n title: true,\n icon: true,\n link: true,\n titleDataSource: true,\n defaultCollapsed: true,\n defaultCollapsedBreakpoint: true,\n type: true,\n injectMenuGroupId: true,\n dynamicItems: true,\n itemsResolve: true,\n items: true,\n i18n: true,\n \"items.children\": true,\n \"app.appId\": true,\n },\n query: {\n menuId: {\n $eq: menuId,\n },\n app: {\n $size: {\n $gt: 0,\n },\n },\n },\n })\n ).list as MenuRawData[]);\n\n const menuData = await mergeMenu(menuList, runtimeContext);\n if (!menuData) {\n throw new Error(`Menu not found: ${menuId}`);\n }\n\n reorderMenuItems(menuData);\n\n const { items, app, ...restMenuData } = menuData;\n const newRuntimeContext: RuntimeContext = {\n ...runtimeContext,\n pendingPermissionsPreCheck: [\n ...runtimeContext.pendingPermissionsPreCheck,\n preCheckPermissionsForAny([items, restMenuData]),\n ],\n };\n delete newRuntimeContext.tplStateStoreId;\n delete newRuntimeContext.forEachItem;\n const rootAppId = app[0].appId;\n\n const [computedMenuData, computedMenuItems] = await Promise.all([\n computeMenuData(restMenuData, rootAppId, newRuntimeContext),\n computeMenuItems(items, newRuntimeContext),\n ]);\n\n const finalMenuData = {\n title: await fetchMenuTitle(computedMenuData),\n ...pick(computedMenuData, [\n \"icon\",\n \"link\",\n \"defaultCollapsed\",\n \"defaultCollapsedBreakpoint\",\n ]),\n menuItems: computedMenuItems.filter(checkIfOfComputed).map((item) => {\n const children = item.children?.filter(checkIfOfComputed);\n return item.type === \"group\"\n ? {\n type: \"group\",\n title: item.text,\n items: children,\n }\n : children?.length\n ? {\n type: \"subMenu\",\n title: item.text,\n icon: item.icon,\n items: children,\n defaultExpanded: item.defaultExpanded,\n }\n : item;\n }),\n };\n\n // Todo(steve): reconsider the menu cache strategy\n menuCache.set(menuId, finalMenuData);\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,I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ACR,gBAAgB,EAAE,CACxB,MAAM,EACN,MAAM,EACN,kBAAkB,EAClB,4BAA4B,CAC7B,CAAC;IACFS,SAAS,EAAER,iBAAiB,CAACS,MAAM,CAACC,0BAAiB,CAAC,CAACC,GAAG,CAAEC,IAAI,IAAK;MAAA,IAAAC,cAAA;MACnE,MAAMC,QAAQ,IAAAD,cAAA,GAAGD,IAAI,CAACE,QAAQ,cAAAD,cAAA,uBAAbA,cAAA,CAAeJ,MAAM,CAACC,0BAAiB,CAAC;MACzD,OAAOE,IAAI,CAACpC,IAAI,KAAK,OAAO,GACxB;QACEA,IAAI,EAAE,OAAO;QACbN,KAAK,EAAE0C,IAAI,CAACG,IAAI;QAChBnC,KAAK,EAAEkC;MACT,CAAC,GACDA,QAAQ,aAARA,QAAQ,eAARA,QAAQ,CAAEE,MAAM,GAChB;QACExC,IAAI,EAAE,SAAS;QACfN,KAAK,EAAE0C,IAAI,CAACG,IAAI;QAChB5C,IAAI,EAAEyC,IAAI,CAACzC,IAAI;QACfS,KAAK,EAAEkC,QAAQ;QACfG,eAAe,EAAEL,IAAI,CAACK;MACxB,CAAC,GACDL,IAAI;IACV,CAAC;EACH,CAAC;;EAED;EACA5D,SAAS,CAACkE,GAAG,CAAChE,MAAM,EAAEmD,aAAa,CAAC;AACtC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.fetchMenuTitle = fetchMenuTitle;
|
|
7
|
-
var _lodash = require("lodash");
|
|
8
|
-
var _cmdbSdk = require("@next-api-sdk/cmdb-sdk");
|
|
9
|
-
const menuTitleCache = new Map();
|
|
10
|
-
async function fetchMenuTitle(menuData) {
|
|
11
|
-
if (menuData.title || (0, _lodash.isEmpty)(menuData.titleDataSource)) {
|
|
12
|
-
return menuData.title;
|
|
13
|
-
}
|
|
14
|
-
const cacheKey = JSON.stringify(menuData.titleDataSource);
|
|
15
|
-
if (menuTitleCache.has(cacheKey)) {
|
|
16
|
-
return menuTitleCache.get(cacheKey);
|
|
17
|
-
}
|
|
18
|
-
const {
|
|
19
|
-
objectId,
|
|
20
|
-
instanceId,
|
|
21
|
-
attributeId
|
|
22
|
-
} = menuData.titleDataSource;
|
|
23
|
-
const attr = attributeId !== null && attributeId !== void 0 ? attributeId : "name";
|
|
24
|
-
const instanceData = await (0, _cmdbSdk.InstanceApi_getDetail)(objectId, instanceId, {
|
|
25
|
-
fields: attr
|
|
26
|
-
});
|
|
27
|
-
let title;
|
|
28
|
-
if (attributeId === "#showKey" && Array.isArray(instanceData[attr])) {
|
|
29
|
-
const [primary, ...rest] = instanceData[attr];
|
|
30
|
-
title = rest.length > 0 ? `${primary}(${rest.join(",")})` : String(primary);
|
|
31
|
-
} else {
|
|
32
|
-
title = String(instanceData[attr]);
|
|
33
|
-
}
|
|
34
|
-
menuTitleCache.set(cacheKey, title);
|
|
35
|
-
return title;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=fetchMenuTitle.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetchMenuTitle.js","names":["_lodash","require","_cmdbSdk","menuTitleCache","Map","fetchMenuTitle","menuData","title","isEmpty","titleDataSource","cacheKey","JSON","stringify","has","get","objectId","instanceId","attributeId","attr","instanceData","InstanceApi_getDetail","fields","Array","isArray","primary","rest","length","join","String","set"],"sources":["../../../../src/internal/menu/fetchMenuTitle.ts"],"sourcesContent":["import { isEmpty } from \"lodash\";\nimport { InstanceApi_getDetail } from \"@next-api-sdk/cmdb-sdk\";\nimport type { MenuRawData } from \"./interfaces.js\";\n\nconst menuTitleCache = new Map<string, string>();\n\nexport async function fetchMenuTitle(\n menuData: Pick<MenuRawData, \"title\" | \"titleDataSource\">\n) {\n if (menuData.title || isEmpty(menuData.titleDataSource)) {\n return menuData.title;\n }\n const cacheKey = JSON.stringify(menuData.titleDataSource);\n if (menuTitleCache.has(cacheKey)) {\n return menuTitleCache.get(cacheKey);\n }\n const { objectId, instanceId, attributeId } = menuData.titleDataSource;\n const attr = attributeId ?? \"name\";\n const instanceData = await InstanceApi_getDetail(objectId, instanceId, {\n fields: attr,\n });\n let title: string;\n if (attributeId === \"#showKey\" && Array.isArray(instanceData[attr])) {\n const [primary, ...rest] = instanceData[attr];\n title = rest.length > 0 ? `${primary}(${rest.join(\",\")})` : String(primary);\n } else {\n title = String(instanceData[attr]);\n }\n menuTitleCache.set(cacheKey, title);\n return title;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAGA,MAAME,cAAc,GAAG,IAAIC,GAAG,EAAkB;AAEzC,eAAeC,cAAcA,CAClCC,QAAwD,EACxD;EACA,IAAIA,QAAQ,CAACC,KAAK,IAAI,IAAAC,eAAO,EAACF,QAAQ,CAACG,eAAe,CAAC,EAAE;IACvD,OAAOH,QAAQ,CAACC,KAAK;EACvB;EACA,MAAMG,QAAQ,GAAGC,IAAI,CAACC,SAAS,CAACN,QAAQ,CAACG,eAAe,CAAC;EACzD,IAAIN,cAAc,CAACU,GAAG,CAACH,QAAQ,CAAC,EAAE;IAChC,OAAOP,cAAc,CAACW,GAAG,CAACJ,QAAQ,CAAC;EACrC;EACA,MAAM;IAAEK,QAAQ;IAAEC,UAAU;IAAEC;EAAY,CAAC,GAAGX,QAAQ,CAACG,eAAe;EACtE,MAAMS,IAAI,GAAGD,WAAW,aAAXA,WAAW,cAAXA,WAAW,GAAI,MAAM;EAClC,MAAME,YAAY,GAAG,MAAM,IAAAC,8BAAqB,EAACL,QAAQ,EAAEC,UAAU,EAAE;IACrEK,MAAM,EAAEH;EACV,CAAC,CAAC;EACF,IAAIX,KAAa;EACjB,IAAIU,WAAW,KAAK,UAAU,IAAIK,KAAK,CAACC,OAAO,CAACJ,YAAY,CAACD,IAAI,CAAC,CAAC,EAAE;IACnE,MAAM,CAACM,OAAO,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