@elliemae/microfe-common 2.25.0 → 2.26.0-alpha.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.
Files changed (72) hide show
  1. package/dist/cjs/app.js +33 -0
  2. package/dist/cjs/config.js +65 -0
  3. package/dist/cjs/frame.html +47 -0
  4. package/dist/cjs/frame.js +61 -0
  5. package/dist/cjs/history.js +27 -0
  6. package/dist/cjs/host.js +105 -0
  7. package/dist/cjs/loader.js +158 -0
  8. package/dist/cjs/logRecords.js +57 -0
  9. package/dist/cjs/logger.js +34 -0
  10. package/dist/cjs/manifestLoader.js +66 -0
  11. package/dist/cjs/scriptLoader.js +71 -0
  12. package/dist/cjs/styleLoader.js +57 -0
  13. package/dist/cjs/tests/loan/latest/index.js +80 -0
  14. package/dist/cjs/tests/loan/latest/manifest.json +3 -0
  15. package/dist/cjs/tests/server.js +29 -0
  16. package/dist/cjs/tests/serverHandlers.js +81 -0
  17. package/dist/cjs/tests/task/latest/index.js +58 -0
  18. package/dist/cjs/tests/task/latest/manifest.json +3 -0
  19. package/dist/cjs/typings/guest.js +16 -0
  20. package/dist/cjs/typings/host.js +16 -0
  21. package/dist/cjs/typings/index.js +16 -0
  22. package/dist/cjs/typings/microapp.js +16 -0
  23. package/dist/cjs/utils.js +33 -0
  24. package/dist/cjs/window.js +63 -0
  25. package/dist/esm/app.js +13 -0
  26. package/dist/esm/config.js +35 -0
  27. package/dist/esm/frame.html +47 -0
  28. package/dist/esm/frame.js +41 -0
  29. package/dist/esm/history.js +7 -0
  30. package/dist/esm/host.js +85 -0
  31. package/dist/esm/loader.js +145 -0
  32. package/dist/esm/logRecords.js +37 -0
  33. package/dist/esm/logger.js +17 -0
  34. package/dist/esm/manifestLoader.js +46 -0
  35. package/dist/esm/scriptLoader.js +51 -0
  36. package/dist/esm/styleLoader.js +37 -0
  37. package/dist/esm/tests/loan/latest/index.js +79 -0
  38. package/dist/esm/tests/loan/latest/manifest.json +3 -0
  39. package/dist/esm/tests/server.js +9 -0
  40. package/dist/esm/tests/serverHandlers.js +51 -0
  41. package/dist/esm/tests/task/latest/index.js +57 -0
  42. package/dist/esm/tests/task/latest/manifest.json +3 -0
  43. package/dist/esm/typings/guest.js +0 -0
  44. package/dist/esm/typings/host.js +0 -0
  45. package/dist/esm/typings/index.js +0 -0
  46. package/dist/esm/typings/microapp.js +0 -0
  47. package/dist/esm/utils.js +13 -0
  48. package/dist/esm/window.js +43 -0
  49. package/dist/types/lib/app.d.ts +2 -0
  50. package/dist/types/lib/config.d.ts +25 -0
  51. package/dist/types/lib/frame.d.ts +10 -0
  52. package/dist/types/lib/history.d.ts +2 -0
  53. package/dist/types/lib/host.d.ts +42 -0
  54. package/dist/types/lib/loader.d.ts +9 -0
  55. package/dist/types/lib/logRecords.d.ts +14 -0
  56. package/dist/types/lib/logger.d.ts +1 -0
  57. package/dist/types/lib/manifestLoader.d.ts +7 -0
  58. package/dist/types/lib/scriptLoader.d.ts +6 -0
  59. package/dist/types/lib/styleLoader.d.ts +5 -0
  60. package/dist/types/lib/tests/loader.test.d.ts +1 -0
  61. package/dist/types/lib/tests/loan/latest/index.d.ts +0 -0
  62. package/dist/types/lib/tests/server.d.ts +1 -0
  63. package/dist/types/lib/tests/serverHandlers.d.ts +1 -0
  64. package/dist/types/lib/tests/task/latest/index.d.ts +0 -0
  65. package/dist/types/lib/typings/guest.d.ts +67 -0
  66. package/dist/types/lib/typings/host.d.ts +60 -0
  67. package/dist/types/lib/typings/index.d.ts +3 -0
  68. package/dist/types/lib/typings/microapp.d.ts +17 -0
  69. package/dist/types/lib/utils.d.ts +3 -0
  70. package/dist/types/lib/window.d.ts +27 -0
  71. package/dist/types/tsconfig.tsbuildinfo +1 -1
  72. package/package.json +6 -2
File without changes
@@ -0,0 +1,13 @@
1
+ import { CMicroAppHost } from "./host.js";
2
+ const isHost = () => CMicroAppHost.isInitialized();
3
+ const removeDoubleSlash = (url) => url.replace(/([^:]\/)\/+/g, "$1");
4
+ const getAbsoluteUrl = (url) => {
5
+ const a = document.createElement("a");
6
+ a.href = url;
7
+ return a.href;
8
+ };
9
+ export {
10
+ getAbsoluteUrl,
11
+ isHost,
12
+ removeDoubleSlash
13
+ };
@@ -0,0 +1,43 @@
1
+ import { getDefaultTheme } from "@elliemae/pui-theme";
2
+ const getWindow = () => {
3
+ try {
4
+ window.parent.document;
5
+ return window.parent;
6
+ } catch (err) {
7
+ return window;
8
+ }
9
+ };
10
+ const getViewportSize = () => ({
11
+ width: Math.max(
12
+ document.documentElement.clientWidth || 0,
13
+ window.innerWidth || 0
14
+ ),
15
+ height: Math.max(
16
+ document.documentElement.clientHeight || 0,
17
+ window.innerHeight || 0
18
+ )
19
+ });
20
+ const convertBreakpointToNumber = (breakpoint) => Number(breakpoint.replace("px", ""));
21
+ const getCurrentBreakpoint = () => {
22
+ const { width } = getViewportSize();
23
+ const { breakpoints } = getDefaultTheme();
24
+ if (width <= convertBreakpointToNumber(breakpoints.small)) return "small";
25
+ if (width <= convertBreakpointToNumber(breakpoints.medium)) return "medium";
26
+ return "large";
27
+ };
28
+ const getAssetPath = () => window?.emui?._ASSET_PATH || "latest/";
29
+ const isCrossDomain = () => {
30
+ try {
31
+ window.parent.document;
32
+ return false;
33
+ } catch (ex) {
34
+ return true;
35
+ }
36
+ };
37
+ export {
38
+ getAssetPath,
39
+ getCurrentBreakpoint,
40
+ getViewportSize,
41
+ getWindow,
42
+ isCrossDomain
43
+ };
@@ -0,0 +1,2 @@
1
+ import { MicroAppConfig } from './typings/microapp.js';
2
+ export declare const launchMicroApp: (appConfig: MicroAppConfig) => Promise<void>;
@@ -0,0 +1,25 @@
1
+ interface ServiceEndpoints {
2
+ api?: string;
3
+ idp?: string;
4
+ logger?: string;
5
+ }
6
+ interface Env {
7
+ serviceEndpoints?: ServiceEndpoints;
8
+ }
9
+ export interface AppConfig {
10
+ appId: string;
11
+ brand?: string;
12
+ activeEnv: string;
13
+ sessionTimeoutWarnInterval?: string;
14
+ sessionTimeoutInterval?: string;
15
+ serviceEndpoints: ServiceEndpoints;
16
+ env: {
17
+ [key: string]: Env;
18
+ };
19
+ }
20
+ export declare const setAppConfig: (config: AppConfig) => void;
21
+ export declare const getAppConfigValue: <Type>(key?: string, defaultValue?: unknown) => Type;
22
+ export declare const setAppConfigValue: <Type>(key: string, value: Type) => AppConfig;
23
+ export declare const hasItem: (key?: string) => boolean;
24
+ export declare const loadAppConfig: (assetPath?: string) => Promise<void>;
25
+ export {};
@@ -0,0 +1,10 @@
1
+ type FrameOptions = {
2
+ id: string;
3
+ sandbox?: string;
4
+ src?: string;
5
+ style?: string;
6
+ };
7
+ export declare const FRAME_CONTAINER_ID_PREFIX = "pui-iframe-container-";
8
+ export declare const FRAME_APP_CONTAINER_ID_PREFIX = "pui-app-container-";
9
+ export declare const createFrame: (options: FrameOptions) => Promise<HTMLIFrameElement>;
10
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const browserHistory: import("history").BrowserHistory;
2
+ export declare const memoryHistory: import("history").MemoryHistory;
@@ -0,0 +1,42 @@
1
+ import { History } from 'history';
2
+ import { DefaultTheme } from 'styled-components';
3
+ import { Logger } from '@elliemae/pui-diagnostics';
4
+ import { IMicroAppHost, SubscriptionListener, AppWindowSize } from './typings/host.js';
5
+ type HostOptions = {
6
+ systemVersion: string;
7
+ history: History;
8
+ theme: DefaultTheme;
9
+ };
10
+ export type OnInitCallback = (options: HostOptions) => void;
11
+ type ConstructorParams = {
12
+ logger?: Logger;
13
+ history?: History;
14
+ version?: string;
15
+ theme?: DefaultTheme;
16
+ scriptingObjects?: Record<string, any>;
17
+ onRenewSessionTimer?: () => void;
18
+ onInit?: OnInitCallback;
19
+ };
20
+ export declare class CMicroAppHost implements IMicroAppHost {
21
+ private static instance;
22
+ private readonly logger;
23
+ private readonly appId;
24
+ private props;
25
+ activeGuests: Record<string, unknown>;
26
+ private readonly onInit?;
27
+ private readonly onRenewSessionTimer?;
28
+ scriptingObjects: Record<string, any>;
29
+ private constructor();
30
+ static getInstance(params?: ConstructorParams): CMicroAppHost;
31
+ static isInitialized(): boolean;
32
+ getProps(this: CMicroAppHost): HostOptions;
33
+ getLogger(this: CMicroAppHost): Logger;
34
+ getObject<T>(name: string): Promise<T>;
35
+ getGuests(this: CMicroAppHost): Record<string, unknown>;
36
+ getGuest<T>(id: string): T | null;
37
+ setAppWindowSize(appSize: AppWindowSize): void;
38
+ publish<Type>(eventId: string | symbol, data?: Type): boolean;
39
+ subscribe<T>(eventId: string | symbol, listener: SubscriptionListener<T>): string;
40
+ unsubscribe(token: string): void;
41
+ }
42
+ export {};
@@ -0,0 +1,9 @@
1
+ import { MicroAppConfig } from './typings/microapp.js';
2
+ export declare const mountApp: ({ id, name }: MicroAppConfig) => Promise<void>;
3
+ export declare const unmountApp: ({ id, name }: MicroAppConfig) => Promise<void | null>;
4
+ export declare const loadApp: (appConfig: MicroAppConfig) => Promise<void>;
5
+ export declare const unloadApp: ({ id, hostUrl, documentEle, }: {
6
+ id: string;
7
+ hostUrl?: string;
8
+ documentEle: Document;
9
+ }) => void;
@@ -0,0 +1,14 @@
1
+ import type { LogRecord } from '@elliemae/pui-diagnostics';
2
+ export declare const logRecords: {
3
+ APP_CONFIG_LOAD_FAILED: {
4
+ code: string;
5
+ message: string;
6
+ };
7
+ ASSET_NOT_FOUND_IN_MANIFEST: (assetName: string) => LogRecord;
8
+ APP_INIT_FAILED: (appId: string, errMsg: string) => LogRecord;
9
+ APP_LOADING: (appId: string) => LogRecord;
10
+ APP_LOADING_COMPLETE: (appId: string) => LogRecord;
11
+ APP_UNLOADING: (appId: string) => LogRecord;
12
+ APP_UNLOADING_COMPLETE: (appId: string) => LogRecord;
13
+ SSF_HOST_OBJECT_NOT_FOUND: (name: string) => LogRecord;
14
+ };
@@ -0,0 +1 @@
1
+ export declare const logger: import("@elliemae/pui-diagnostics").Logger;
@@ -0,0 +1,7 @@
1
+ type Manifest = Record<string, string>;
2
+ export declare const getAppManifest: ({ hostUrl, manifestPath, }: {
3
+ hostUrl?: string;
4
+ manifestPath?: string;
5
+ }) => Promise<Manifest>;
6
+ export declare const getFullFileNameofAssetsFromManifest: (manifest: Record<string, string>, assetNames?: Array<string>) => Array<string>;
7
+ export {};
@@ -0,0 +1,6 @@
1
+ import { MicroAppConfig } from './typings/microapp.js';
2
+ export declare const APP_SCRIPT_ID_PREFIX = "emui-script-";
3
+ export declare const addScriptToDOM: ({ name, hostUrl, documentEle }: MicroAppConfig, fileName: string, index: number) => Promise<string>;
4
+ export declare const removeScriptFromDOM: (elementId?: string, documentEle?: Document) => Promise<void>;
5
+ export declare const removeDynamicImportedScripts: (hostUrl: string, documentEle: HTMLDocument) => void;
6
+ export declare const removePrefetchLinks: (hostUrl: string, documentEle: HTMLDocument) => void;
@@ -0,0 +1,5 @@
1
+ import { MicroAppConfig } from './typings/microapp.js';
2
+ export declare const APP_STYLE_ID_PREFIX = "emui-style-";
3
+ export declare const addStylesToDOM: ({ name, hostUrl, documentEle }: MicroAppConfig, fileName: string, index: number) => Promise<string>;
4
+ export declare const removeStyleFromDOM: (elementId?: string, documentEle?: Document) => Promise<void>;
5
+ export declare const removeDynamicImportedStyles: (hostUrl: string, documentEle: Document) => void;
@@ -0,0 +1 @@
1
+ export {};
File without changes
@@ -0,0 +1 @@
1
+ export declare const initServer: () => import("msw/lib/glossary-2792c6da").K;
@@ -0,0 +1 @@
1
+ export declare const serverHandlers: import("msw").RestHandler<import("msw").MockedRequest<import("msw").DefaultBodyType>>[];
File without changes
@@ -0,0 +1,67 @@
1
+ import { History, To } from 'history';
2
+ import { DefaultTheme } from 'styled-components';
3
+ import { Logger } from '@elliemae/pui-diagnostics';
4
+ import { BreakPoint } from '@elliemae/pui-theme';
5
+ import { IMicroAppHost } from './host.js';
6
+ import { JSONValue } from './index.js';
7
+ type ViewportSize = {
8
+ width: number;
9
+ height: number;
10
+ };
11
+ /**
12
+ * options to initialize the guest app
13
+ */
14
+ export type InitOptions = {
15
+ host?: IMicroAppHost;
16
+ hostName?: string;
17
+ hostUrl?: string;
18
+ manifestPath?: string;
19
+ homeRoute?: string;
20
+ prevState?: JSONValue;
21
+ history?: History;
22
+ theme?: DefaultTheme;
23
+ hostBreakpoint?: BreakPoint;
24
+ hostViewportSize?: ViewportSize;
25
+ logger?: Logger;
26
+ };
27
+ /**
28
+ * options to mount the guest app
29
+ */
30
+ export type MountOptions = {
31
+ containerId: string;
32
+ hostBreakpoint?: BreakPoint;
33
+ hostViewportSize?: ViewportSize;
34
+ };
35
+ /**
36
+ * Interface to connect and communicate with microfrontend guest application
37
+ */
38
+ export interface IMicroAppGuest {
39
+ /**
40
+ * initialize the guest application
41
+ * @param options guest initailization options
42
+ */
43
+ init(options: InitOptions): Promise<void>;
44
+ /**
45
+ * mount application to the window DOM
46
+ * @param options application dom mount options
47
+ */
48
+ mount(options: MountOptions): Promise<void>;
49
+ /**
50
+ * unmount application from the window DOM
51
+ * @param options DOM unmount options
52
+ * @returns application state serialized as JSON
53
+ */
54
+ unmount(options: MountOptions): Promise<JSONValue>;
55
+ /**
56
+ * Get scripting object exposed from guest application
57
+ * @returns scripting object
58
+ */
59
+ getObject<T>(): T | null;
60
+ /**
61
+ * navigate to a route
62
+ * @param url url to navigate the guest application to
63
+ * @param state state to pass to the guest application
64
+ */
65
+ navigate(url: To, state?: any): void;
66
+ }
67
+ export {};
@@ -0,0 +1,60 @@
1
+ import { ScriptingObjectTypes } from '@elliemae/pui-scripting-object';
2
+ /**
3
+ * event listner callback function
4
+ */
5
+ export type SubscriptionListener<T> = (message: string, data?: T) => void;
6
+ export type AppWindowSize = {
7
+ appId: string;
8
+ size: {
9
+ width: number;
10
+ height: number;
11
+ };
12
+ };
13
+ /**
14
+ * Interface to connect and communicate with parent host
15
+ */
16
+ export interface IMicroAppHost {
17
+ /**
18
+ * Get reference to the scripting object (or proxy) by name
19
+ * @param name unique name of the scripting object
20
+ * @returns scripting object (or its proxy) reference
21
+ */
22
+ getObject<T extends keyof ScriptingObjectTypes>(name: T): Promise<ScriptingObjectTypes[T]>;
23
+ /**
24
+ * Get lists of all guests attached to the host
25
+ * @returns list of guests
26
+ */
27
+ getGuests(): Record<string, unknown>;
28
+ /**
29
+ * Get reference to the guest by name
30
+ * @param id unique id of the guest
31
+ * @returns guest reference
32
+ */
33
+ getGuest<T>(id: string): T | null;
34
+ /**
35
+ * set the size of the guest application iframe window
36
+ * @param appSize window size of the application
37
+ */
38
+ setAppWindowSize(appSize: AppWindowSize): void;
39
+ /**
40
+ * emit event to all subscribers
41
+ * @param eventId unique id of the event. The format is <scripting object name>.<event name>
42
+ * @param data data to be sent to the subscribers of the event
43
+ * @returns true if event is published successfully
44
+ */
45
+ publish<Type>(eventId: string | symbol, data?: Type): boolean;
46
+ /**
47
+ * subscribe to an scripting object event
48
+ * @param eventId unique id of the event. The format is <scripting object name>.<event name>
49
+ * @param listener callback function to be called when the event is fired
50
+ * @returns token to be used to unsubscribe
51
+ */
52
+ subscribe<T>(eventId: string | symbol, listener: SubscriptionListener<T>): string;
53
+ /**
54
+ *
55
+ * @param token unique token returned by subscribe
56
+ * @param objectId scripting object name
57
+ * @param eventName event name
58
+ */
59
+ unsubscribe(token: string, eventId?: string): void;
60
+ }
@@ -0,0 +1,3 @@
1
+ export type JSONValue = Partial<{
2
+ [key: string]: JSONValue;
3
+ }> | JSONValue[] | string | number | boolean | null;
@@ -0,0 +1,17 @@
1
+ import { InitOptions } from './guest.js';
2
+ type EnvConfig = {
3
+ files: Array<string>;
4
+ };
5
+ export type MicroAppConfig = {
6
+ id: string;
7
+ name: string;
8
+ mode?: string;
9
+ hostUrl?: string;
10
+ manifestPath?: string;
11
+ homeRoute: string;
12
+ files?: Array<string>;
13
+ development?: EnvConfig;
14
+ production?: EnvConfig;
15
+ documentEle: Document;
16
+ } & InitOptions;
17
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const isHost: () => boolean;
2
+ export declare const removeDoubleSlash: (url: string) => string;
3
+ export declare const getAbsoluteUrl: (url: string) => string;
@@ -0,0 +1,27 @@
1
+ import { BreakPoint } from '@elliemae/pui-theme';
2
+ import { Logger } from '@elliemae/pui-diagnostics';
3
+ import { IMicroAppGuest } from './typings/guest.js';
4
+ import { IMicroAppHost } from './typings/host.js';
5
+ export type EMUI = {
6
+ [key: string]: IMicroAppGuest;
7
+ } & {
8
+ _BASE_PATH: string;
9
+ _ASSET_PATH: string;
10
+ version: string;
11
+ MicroAppHost?: IMicroAppHost;
12
+ logger?: Logger;
13
+ appId?: string;
14
+ };
15
+ declare global {
16
+ interface Window {
17
+ emui: EMUI;
18
+ }
19
+ }
20
+ export declare const getWindow: () => Window;
21
+ export declare const getViewportSize: () => {
22
+ width: number;
23
+ height: number;
24
+ };
25
+ export declare const getCurrentBreakpoint: () => BreakPoint;
26
+ export declare const getAssetPath: () => string;
27
+ export declare const isCrossDomain: () => boolean;