Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@equinor/echo-base

Package Overview
Dependencies
Maintainers
2
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@equinor/echo-base - npm Package Compare versions

Comparing version 0.2.92 to 0.2.93

src/module/dependency.tsx

12

CHANGELOG.md

@@ -8,2 +8,4 @@ # Change Log

## 0.1.4 (2021-04-16)

@@ -13,2 +15,12 @@

## 0.1.1 (2021-04-16)
## 0.1.4 (2021-04-16)
**Note:** Version bump only for package @equinor/echo-base

2

esm/errors/ArgumentError.d.ts

@@ -1,2 +0,2 @@

import BaseError from './BaseError';
import { BaseError } from './BaseError';
interface ArgumentErrorArgs {

@@ -3,0 +3,0 @@ argumentName: string;

import { __extends } from "tslib";
import BaseError from './BaseError';
import { BaseError } from './BaseError';
var ArgumentError = /** @class */ (function (_super) {

@@ -4,0 +4,0 @@ __extends(ArgumentError, _super);

@@ -1,2 +0,2 @@

import { BaseErrorArgs, BaseErrorProps, ErrorProperties } from '../types/error';
import { BaseErrorArgs, ErrorProperties } from '../types/error';
/**

@@ -10,3 +10,3 @@ * Base Error class is intended to be used as a base class for every type of Error generated

*/
export declare class BaseError extends Error implements BaseErrorProps {
export declare class BaseError extends Error {
protected properties: ErrorProperties;

@@ -18,2 +18,1 @@ hasBeenLogged: boolean;

}
export default BaseError;

@@ -28,3 +28,2 @@ import { __assign, __extends } from "tslib";

export { BaseError };
export default BaseError;
//# sourceMappingURL=BaseError.js.map

@@ -1,2 +0,2 @@

import { BackendError, ForbiddenError, NotFoundError, ValidationError } from './network';
import { BackendError, ForbiddenError, NotFoundError, ValidationError } from './NetworkError';
export var initializeError = function (ErrorType, args) {

@@ -3,0 +3,0 @@ var _a;

import { CommonErrorArgs } from '../types/error';
import BaseError from './BaseError';
import { BaseError } from './BaseError';
export interface NetworkErrorArgs extends CommonErrorArgs {

@@ -23,2 +23,9 @@ exception: Record<string, unknown>;

}
export default NetworkError;
export declare class BackendError extends NetworkError {
}
export declare class ForbiddenError extends NetworkError {
}
export declare class NotFoundError extends NetworkError {
}
export declare class ValidationError extends NetworkError {
}
import { __extends } from "tslib";
import BaseError from './BaseError';
import { BaseError } from './BaseError';
/**

@@ -28,3 +28,34 @@ * Network Error class represent a Network error ocurred during any given HTTP request

export { NetworkError };
export default NetworkError;
var BackendError = /** @class */ (function (_super) {
__extends(BackendError, _super);
function BackendError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return BackendError;
}(NetworkError));
export { BackendError };
var ForbiddenError = /** @class */ (function (_super) {
__extends(ForbiddenError, _super);
function ForbiddenError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return ForbiddenError;
}(NetworkError));
export { ForbiddenError };
var NotFoundError = /** @class */ (function (_super) {
__extends(NotFoundError, _super);
function NotFoundError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return NotFoundError;
}(NetworkError));
export { NotFoundError };
var ValidationError = /** @class */ (function (_super) {
__extends(ValidationError, _super);
function ValidationError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return ValidationError;
}(NetworkError));
export { ValidationError };
//# sourceMappingURL=NetworkError.js.map
export * from './errors';
export { default as ArgumentError } from './errors/ArgumentError';
export { default as BaseError } from './errors/BaseError';
export { default as NetworkError } from './errors/NetworkError';
export * from './module';
export * from './types';
export * from './utils';
export { default as eventHub } from './utils/eventHub';
export * from './errors';
export { default as ArgumentError } from './errors/ArgumentError';
export { default as BaseError } from './errors/BaseError';
export { default as NetworkError } from './errors/NetworkError';
export * from './module';
export * from './types';
export * from './utils';
export { default as eventHub } from './utils/eventHub';
//# sourceMappingURL=index.js.map

@@ -1,18 +0,1 @@

import { EchoModulesLoading, LoadingModuleOptions } from '../types';
interface StartLoadingModules {
connect(notifier: EchoModulesLoading): void;
disconnect(notifier: EchoModulesLoading): void;
}
/**
* Used to start loading modules, the modules can be provided, or a fetch call can be defined to
* retrieving the moduleMetaData that in turn will load the js files, and initialize the all modules.
* Module data will be stored in the globals store trough the notifier provided trough the connect function.
*
* This function is used in Echo Framework in the Mediator Component.
*
* @export
* @param {LoadingModuleOptions} options
* @return {*} {StartLoadingModules}
*/
export declare function startLoadingModules(options: LoadingModuleOptions): StartLoadingModules;
export {};
export declare function startLoadingApps(options: {}): void;

@@ -1,46 +0,8 @@

import { standardStrategy } from './strategies';
import { fireAndForget, isfunc } from './utils';
/**
* Used to start loading modules, the modules can be provided, or a fetch call can be defined to
* retrieving the moduleMetaData that in turn will load the js files, and initialize the all modules.
* Module data will be stored in the globals store trough the notifier provided trough the connect function.
*
* This function is used in Echo Framework in the Mediator Component.
*
* @export
* @param {LoadingModuleOptions} options
* @return {*} {StartLoadingModules}
*/
export function startLoadingModules(options) {
export function startLoadingApps(options) {
var state = {
loaded: false,
modules: [],
error: undefined
loading: false,
apps: [],
error: undefined,
};
var notifiers = [];
var call = function (notifier) { return notifier(state.error, state.modules, state.loaded); };
var notify = function () { return notifiers.forEach(call); };
var setAppModules = function (error, modules) {
state.error = error;
state.modules = modules;
notify();
};
var setLoaded = function () {
state.loaded = true;
notify();
};
fireAndForget(function () { return standardStrategy(options, setAppModules).then(setLoaded, setLoaded); });
return {
connect: function (notifier) {
if (isfunc(notifier)) {
notifiers.push(notifier);
call(notifier);
}
},
disconnect: function (notifier) {
var index = notifiers.indexOf(notifier);
index !== -1 && notifiers.splice(index, 1);
}
};
}
//# sourceMappingURL=create.js.map

@@ -1,47 +0,8 @@

import { AvailableDependencies, ModuleData, ModuleMetaData } from '../types';
import { AppData, AvailableDependencies } from '../types/module';
declare global {
interface HTMLScriptElement {
module?: ModuleData;
app?: AppData;
}
}
/**
* Incudes a script tag in the DOM,
* and extracts the setup function.
*
* @export
* @param {string} name
* @param {string} fileUri
* @param {string} depName
* @param {AvailableDependencies} dependencies
* @param {string} [crossOrigin]
* @param {string} [integrity]
* @return {*} {(Promise<ModuleData | undefined>)}
*/
export declare function includeScript(name: string, fileUri: string, depName: string, dependencies: AvailableDependencies, crossOrigin?: string, integrity?: string): Promise<ModuleData | undefined>;
/**
* async wrapper of check app resolving the app ModuleData
*
* @export
* @param {string} name
* @param {(ModuleData | Promise<ModuleData>)} [module]
* @return {*} {Promise<ModuleData>}
*/
export declare function checkAppAsync(name: string, module?: ModuleData | Promise<ModuleData>): Promise<ModuleData>;
/**
* Function added to window object for retrieving AvailableDependencies
*
* @export
* @param {AvailableDependencies} [dependencies={}]
* @return {*}
*/
export declare function checkAppAsync(app?: AppData | Promise<AppData>): Promise<AppData>;
export declare function getLocalRequire(dependencies?: AvailableDependencies): (moduleName: string) => void;
/**
* Retiring the current module.
*
* @export
* @param {ModuleMetaData} { name, fileUri: link, requireRef, integrity }
* @param {AvailableDependencies} [dependencies]
* @param {string} [crossOrigin]
* @return {*} {Promise<ModuleData>}
*/
export declare function includeDependency({ name, fileUri: link, requireRef, integrity }: ModuleMetaData, dependencies?: AvailableDependencies, crossOrigin?: string): Promise<ModuleData>;

@@ -1,9 +0,1 @@

import { __awaiter, __generator } from "tslib";
/**
* Returns the module dependency if present in the AvailableDependencies
*
* @param {string} name
* @param {AvailableDependencies} dependencies
* @return {*} {*}
*/
function requireModule(name, dependencies) {

@@ -18,19 +10,11 @@ var dependency = dependencies[name];

}
/**
* Verifies if the module is a correct EchoModule with a exported setup function.
* Will provide a empty module if verification fails to prevent system crash.
*
* @param {string} name
* @param {ModuleData} [module]
* @return {*} {ModuleData}
*/
function checkModule(name, module) {
if (!module) {
console.error('Invalid module found.', name);
function checkApp(app) {
if (!app) {
console.error('Invalid module found.', app);
}
else if (typeof module.setup !== 'function') {
console.warn('Setup function is missing.', name);
else if (typeof app.setup !== 'function') {
console.warn('Setup function is missing.');
}
else {
return module;
return app;
}

@@ -43,66 +27,5 @@ return {

}
/**
* Incudes a script tag in the DOM,
* and extracts the setup function.
*
* @export
* @param {string} name
* @param {string} fileUri
* @param {string} depName
* @param {AvailableDependencies} dependencies
* @param {string} [crossOrigin]
* @param {string} [integrity]
* @return {*} {(Promise<ModuleData | undefined>)}
*/
export function includeScript(name, fileUri, depName, dependencies, crossOrigin, integrity) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, new Promise(function (resolve, reject) {
var script = document.createElement('script');
script.async = true;
script.src = fileUri;
script.id = name;
if (integrity) {
script.crossOrigin = crossOrigin || 'anonymous';
script.integrity = integrity;
}
else if (crossOrigin) {
script.crossOrigin = crossOrigin;
}
window[depName] = getLocalRequire(dependencies);
script.onload = function () { return resolve(checkAppAsync(name, script.module)); };
script.onerror = function () { return reject('could not load'); };
document.head.appendChild(script);
})];
});
});
export function checkAppAsync(app) {
return Promise.resolve(app).then(function (resolvedApp) { return checkApp(resolvedApp); });
}
/**
* async wrapper of check app resolving the app ModuleData
*
* @export
* @param {string} name
* @param {(ModuleData | Promise<ModuleData>)} [module]
* @return {*} {Promise<ModuleData>}
*/
export function checkAppAsync(name, module) {
return __awaiter(this, void 0, void 0, function () {
var resolvedModule;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.resolve(module)];
case 1:
resolvedModule = _a.sent();
return [2 /*return*/, checkModule(name, resolvedModule)];
}
});
});
}
/**
* Function added to window object for retrieving AvailableDependencies
*
* @export
* @param {AvailableDependencies} [dependencies={}]
* @return {*}
*/
export function getLocalRequire(dependencies) {

@@ -112,22 +35,2 @@ if (dependencies === void 0) { dependencies = {}; }

}
/**
* Retiring the current module.
*
* @export
* @param {ModuleMetaData} { name, fileUri: link, requireRef, integrity }
* @param {AvailableDependencies} [dependencies]
* @param {string} [crossOrigin]
* @return {*} {Promise<ModuleData>}
*/
export function includeDependency(_a, dependencies, crossOrigin) {
var name = _a.name, link = _a.fileUri, requireRef = _a.requireRef, integrity = _a.integrity;
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, includeScript(name, link, requireRef, dependencies, crossOrigin, integrity)];
case 1: return [2 /*return*/, _b.sent()];
}
});
});
}
//# sourceMappingURL=dependency.js.map

@@ -7,2 +7,2 @@ /**

*/
export declare function defaultFetchDependency(url: string, token?: string): Promise<string>;
export declare function fetchDependency(url: string, token: string): Promise<string>;

@@ -8,3 +8,3 @@ import { __awaiter, __generator } from "tslib";

*/
export function defaultFetchDependency(url, token) {
export function fetchDependency(url, token) {
return __awaiter(this, void 0, void 0, function () {

@@ -11,0 +11,0 @@ var m;

import { __awaiter, __extends, __generator } from "tslib";
import BaseError from '../errors/BaseError';
import { BaseError } from '../errors/BaseError';
import { verifyModulesMeta } from './verify';

@@ -4,0 +4,0 @@ var ModulesMetaError = /** @class */ (function (_super) {

@@ -1,12 +0,7 @@

export * from './aggregate';
export * from './create';
export * from './dependency';
export * from './errors';
export * from './fetch';
export * from './load';
export * from './fetchModules';
export * from './loader';
export * from './persist';
export * from './setup';
export * from './strategies';
export * from './utils';
export * from './verify';

@@ -1,13 +0,8 @@

export * from './aggregate';
export * from './create';
export * from './dependency';
export * from './errors';
export * from './fetch';
export * from './load';
export * from './fetchModules';
export * from './loader';
export * from './persist';
export * from './setup';
export * from './strategies';
export * from './utils';
export * from './verify';
//# sourceMappingURL=index.js.map

@@ -1,21 +0,3 @@

import { AppDependencyGetter, AvailableDependencies, DefaultLoaderConfig, ModuleLoader } from '../types';
/**
* Create a module loader with the provided dependence's.
*
* @export
* @param {DefaultLoaderConfig} [config]
* @param {AvailableDependencies} [dependencies]
* @param {AppDependencyGetter} [getDependencies]
* @return {*} {ModuleLoader}
*/
export declare function createModuleLoader(config?: DefaultLoaderConfig, dependencies?: AvailableDependencies, getDependencies?: AppDependencyGetter): ModuleLoader;
/**
* Loader for loading modules, with dependencies, will return a empty module,
* if empty module is found, for avoiding crashes.
*
* @export
* @param {AppDependencyGetter} getDependencies
* @param {DefaultLoaderConfig} [config={}]
* @return {*} {ModuleLoader}
*/
export declare function getModuleLoader(getDependencies: AppDependencyGetter, config?: DefaultLoaderConfig): ModuleLoader;
import { App, AppData, AppMetadata, AvailableDependencies } from '../types/module';
export declare function loadModule(meta: AppMetadata, loadModuleData: (meta: AppMetadata) => AppData): App;
export declare function loadApp(link: string, depName: string, dependencies: AvailableDependencies): Promise<AppData | undefined>;

@@ -1,61 +0,22 @@

import { __assign, __awaiter, __generator } from "tslib";
import { createEmptyModule } from '../utils/emptyApp';
import { getDependencyResolver } from '../utils/getDependencyResolver';
import { includeDependency } from './dependency';
var inBrowser = typeof document !== 'undefined';
/**
* Create a module loader with the provided dependence's.
*
* @export
* @param {DefaultLoaderConfig} [config]
* @param {AvailableDependencies} [dependencies]
* @param {AppDependencyGetter} [getDependencies]
* @return {*} {ModuleLoader}
*/
export function createModuleLoader(config, dependencies, getDependencies) {
var getDeps = getDependencyResolver(dependencies, getDependencies);
return getModuleLoader(getDeps, config);
import { __assign } from "tslib";
import { checkAppAsync, getLocalRequire } from './dependency';
export function loadModule(meta, loadModuleData) {
var module = loadModuleData(meta);
return __assign(__assign({}, meta), module);
}
/**
* Loader for loading modules, with dependencies, will return a empty module,
* if empty module is found, for avoiding crashes.
*
* @export
* @param {AppDependencyGetter} getDependencies
* @param {DefaultLoaderConfig} [config={}]
* @return {*} {ModuleLoader}
*/
export function getModuleLoader(getDependencies, config) {
if (config === void 0) { config = {}; }
return function (meta) {
if (inBrowser && 'requireRef' in meta && meta.requireRef) {
return loadModule(meta, getDependencies, function (deps) { return includeDependency(meta, deps, config.crossOrigin); });
}
console.warn('Empty Module found!', meta.name);
return Promise.resolve(createEmptyModule(meta));
};
}
/**
* Loading the module and combining the javascript module with the modules Metadata.
*
* @param {ModuleMetaData} meta
* @param {AppDependencyGetter} getDependencies
* @param {(dependencies: AvailableDependencies) => Promise<ModuleData>} loader
* @return {*} {Promise<EchoModule>}
*/
function loadModule(meta, getDependencies, loader) {
return __awaiter(this, void 0, void 0, function () {
var dependencies, app;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
dependencies = __assign({}, (getDependencies(meta) || {}));
return [4 /*yield*/, loader(dependencies)];
case 1:
app = _a.sent();
return [2 /*return*/, __assign(__assign({}, app), meta)];
}
});
export function loadApp(link, depName, dependencies) {
return new Promise(function (resolve, reject) {
var s = document.createElement('script');
s.async = true;
s.src = link;
s.crossOrigin = 'cross-origin';
window[depName] = getLocalRequire(dependencies);
s.onload = function () {
var app = checkAppAsync(s.app);
resolve(app);
};
s.onerror = function () { return reject('could not load'); };
document.head.appendChild(s);
});
}
//# sourceMappingURL=loader.js.map

@@ -1,3 +0,3 @@

import { ModuleMetaData } from '../types/module';
export declare function persistLocalModuleMeta(key: string, modules: ModuleMetaData[]): void;
export declare function loadLocalModuleMeta(key: string): ModuleMetaData[];
import { AppMetadata } from '../types/module';
export declare function persistLocalModuleMeta(key: string, modules: AppMetadata[]): void;
export declare function loadLocalModuleMeta(key: string): AppMetadata[];

@@ -1,3 +0,4 @@

import { EchoModule, EchoModuleApi, EchoModuleApiCreator } from '../types';
export declare function setupSingleModule(module: EchoModule, api: EchoModuleApi): void | Promise<void>;
export declare function setupModule(module: EchoModule, apiFactory: EchoModuleApiCreator): void | Promise<void>;
import { App, AppApi, AppApiCreator, MultiApp, SingleApp } from '../types';
export declare function setupSingleApp(app: SingleApp, api: AppApi): void | Promise<void>;
export declare function setupMultiApps(app: MultiApp, apiFactory: AppApiCreator): void | Promise<void>;
export declare function setupApp(app: App, apiFactory: AppApiCreator): void | Promise<void>;

@@ -1,13 +0,24 @@

export function setupSingleModule(module, api) {
export function setupSingleApp(app, api) {
try {
var result = module.setup(api);
var result = app.setup(api);
return result;
}
catch (error) {
console.warn(error);
catch (error) { }
}
export function setupMultiApps(app, apiFactory) {
try {
return app.setup(apiFactory);
}
catch (e) {
console.error("Error while setting up " + (app === null || app === void 0 ? void 0 : app.name) + ".", e);
}
}
export function setupModule(module, apiFactory) {
return setupSingleModule(module, apiFactory(module));
export function setupApp(app, apiFactory) {
if ('bundle' in app) {
return setupMultiApps(app, apiFactory);
}
else {
return setupSingleApp(app, apiFactory(app));
}
}
//# sourceMappingURL=setup.js.map

@@ -1,35 +0,4 @@

import { EchoModuleApiCreator, ModuleRequester } from '../types/creators';
import { EchoModule, ModuleMetaData } from '../types/module';
/**
*
*
* @export
* @param {string} id
*/
import { AppMetadata, SingleApp } from '../types/module';
export declare function removeElementById(id: string): void;
/**
* Helper function for Checking if function is present.
*
* @param {EchoModuleApiCreator} createModuleApi
* @return {*} {boolean}
*/
export declare function checkFunction(func: EchoModuleApiCreator | ModuleRequester, errorMessage: string): boolean;
/**
*
*
* @export
* @param {*} f
* @return {*} {f is Function}
*/
export declare function isfunc(f: unknown): f is Function;
/**
*
*
* @export
* @param {ModuleMetaData} meta
* @return {*} {SingleApp}
*/
export declare function createEmptyApp(meta: ModuleMetaData): EchoModule;
export declare function isProduction(): boolean;
export declare function filterExcludePrivateModulesInProduction(modules: EchoModule[], isProduction?: () => boolean): EchoModule[];
export declare function fireAndForget(asyncFunc: () => Promise<void>): void;
export declare function isfunc(f: any): f is Function;
export declare function createEmptyModule(meta: AppMetadata): SingleApp;
import { __assign } from "tslib";
/**
*
*
* @export
* @param {string} id
*/
export function removeElementById(id) {

@@ -12,33 +6,6 @@ var _a;

}
/**
* Helper function for Checking if function is present.
*
* @param {EchoModuleApiCreator} createModuleApi
* @return {*} {boolean}
*/
export function checkFunction(func, errorMessage) {
if (!isfunc(func)) {
console.warn(errorMessage);
return false;
}
return true;
}
/**
*
*
* @export
* @param {*} f
* @return {*} {f is Function}
*/
export function isfunc(f) {
return typeof f === 'function';
}
/**
*
*
* @export
* @param {ModuleMetaData} meta
* @return {*} {SingleApp}
*/
export function createEmptyApp(meta) {
export function createEmptyModule(meta) {
return __assign(__assign({}, meta), { setup: function () {

@@ -48,14 +15,2 @@ // Empty module

}
export function isProduction() {
return process.env.NODE_ENV === 'production';
}
export function filterExcludePrivateModulesInProduction(modules, isProduction) {
if (isProduction && isProduction()) {
return modules.filter(function (module) { return module.private !== true; });
}
return modules;
}
export function fireAndForget(asyncFunc) {
asyncFunc();
}
//# sourceMappingURL=utils.js.map

@@ -1,2 +0,2 @@

import { ModuleMetaData } from '../types/module';
export declare function verifyModulesMeta(modules: ModuleMetaData[]): ModuleMetaData[];
import { AppMetadata } from '../types/module';
export declare function verifyModulesMeta(modules: AppMetadata[]): AppMetadata[];

@@ -0,10 +1,10 @@

import ArgumentError from '../errors/ArgumentError';
import { persistLocalModuleMeta } from './persist';
export function verifyModulesMeta(modules) {
if (modules instanceof Array) {
modules.length > 0 && persistLocalModuleMeta('EchoModules', modules);
return modules;
if (modules.length === 0) {
throw new ArgumentError({ argumentName: 'No modules awaitable' });
}
console.log('No modules awaitable.');
return [];
persistLocalModuleMeta('EchoModules', modules);
return modules;
}
//# sourceMappingURL=verify.js.map

@@ -8,8 +8,42 @@ /**

emit<T>(key: string, payload: T): void;
subscribe<T>(key: string, handler: (payload: T) => void): UnsubscribeFunction;
subscribeMany<T>(keys: Array<string | EchoEvents>, handler: (payload: T) => void): UnsubscribeFunction;
subscribe<T>(key: string, handler: (payload: T) => void): () => void;
subscribeMany<T>(keys: Array<string | EchoEvents>, handler: (payload: T) => void): () => void;
}
export declare type UnsubscribeFunction = () => void;
export declare enum EchoEvents {
PlantChanged = "plantChanged"
}
/**
* Emitter of module app shell events.
*/
export interface ModuleEventEmitter {
/**
* Attaches a new event listener.
* @param type The type of the event to listen for.
* @param callback The callback to trigger.
*/
on<K extends keyof EventMap>(type: K, callback: Listener<EventMap[K]>): ModuleEventEmitter;
/**
* Detaches an existing event listener.
* @param type The type of the event to listen for.
* @param callback The callback to trigger.
*/
of<K extends keyof EventMap>(type: K, callback: Listener<EventMap[K]>): ModuleEventEmitter;
/**
* Emits a new event with the given type.
* @param type The type of the event to emit.
* @param arg The payload of the event.
*/
emit<K extends keyof EventMap>(type: K, arg: EventMap[K]): ModuleEventEmitter;
}
export interface EventMap {
[custom: string]: unknown;
}
/**
* Listener for module app shell events.
*/
export interface Listener<T> {
/**
* Receives an event of type T.
*/
(arg: T): void;
}

@@ -1,8 +0,4 @@

export * from './common';
export * from './creators';
export * from './error';
export * from './event';
export * from './loader';
export * from './module';
export * from './options';
export * from './storage';

@@ -1,9 +0,5 @@

export * from './common';
export * from './creators';
export * from './error';
export * from './event';
export * from './loader';
export * from './module';
export * from './options';
export * from './storage';
//# sourceMappingURL=index.js.map

@@ -1,5 +0,1 @@

import BaseError from '../errors/BaseError';
import { EchoModule, ModuleMetaData } from './module';
export declare class ModuleAppError extends BaseError {
}
/**

@@ -11,16 +7,1 @@ * Configuration options for the default loader.

}
export interface ModulesLoader {
(): Array<EchoModule>;
}
export interface EchoModuleLoaded {
(error: ModuleAppError | undefined, modules: Array<EchoModule>): void;
}
export interface EchoModulesLoading {
(error: ModuleAppError | undefined, modules: Array<EchoModule>, loaded: boolean): void;
}
export interface ModuleLoader {
(meta: ModuleMetaData): Promise<EchoModule>;
}
export interface DefaultLoaderConfig {
crossOrigin?: string;
}

@@ -1,11 +0,2 @@

import { __extends } from "tslib";
import BaseError from '../errors/BaseError';
var ModuleAppError = /** @class */ (function (_super) {
__extends(ModuleAppError, _super);
function ModuleAppError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return ModuleAppError;
}(BaseError));
export { ModuleAppError };
export {};
//# sourceMappingURL=loader.js.map

@@ -1,34 +0,67 @@

import { EchoEventHub } from './event';
export interface ModuleMetaData extends MetaDataBase {
requireRef?: string;
import { ModuleEventEmitter } from "./event";
export interface SingleAppMetadata {
name: string;
link: string;
requireRef: string;
integrity?: string;
custom?: any;
config?: Record<string, any>;
}
export interface MetaDataBase {
key: string;
export interface MultiAppsMetadata {
name: string;
shortName: string;
path: string;
fileUri: string;
version: string;
link: string;
bundle: string;
integrity?: string;
private?: boolean;
custom?: any;
}
export declare type App = SingleApp | MultiApp;
/**
* Echo Module setup function and meta data combined.
* Describes the metadata transported by a Apps.
*/
export declare type EchoModule = ModuleData & ModuleMetaData;
export declare type AppMetadata = SingleAppMetadata | MultiAppsMetadata;
/**
* The metadata for a single app.
*/
export declare type SingleApp = AppData & AppMetadata;
/**
* The metadata for apps containing apps.
*/
export declare type MultiApp = MultiAppData & MultiAppsMetadata;
/**
* Defines the API accessible from Apps.
*/
export interface EchoModuleApi {
export interface AppApi extends ModuleEventEmitter {
/**
* Gets the metadata of the current App.
*/
meta: ModuleMetaData;
eventHub: EchoEventHub;
meta: AppMetadata;
}
export interface ModuleData {
setup: (api: EchoModuleApi) => void | Promise<void>;
export interface RouteRegistration extends BaseRegistration {
meta: AppMetaData;
}
export declare type AppMetaFetch = () => Promise<ModuleMetaData[]>;
export interface AppMetaData {
name: string;
icon: string;
homeScreen?: boolean;
}
export interface BaseRegistration {
key: string;
}
export interface AppData {
setup: (api: AppApi) => void | Promise<void>;
}
export interface MultiAppData {
setup: (apiFactory: AppApiCreator) => void | Promise<void>;
}
export interface EchoPortal {
isAuthenticated: boolean;
}
export declare type AppMetaFetch = () => Promise<AppMetadata[]>;
/**
* The creator function for the App API.
*/
export interface AppApiCreator {
(target: AppMetadata): AppApi;
}
/**
* The record containing all available dependencies.

@@ -35,0 +68,0 @@ */

@@ -1,2 +0,2 @@

import { EchoModule, ModuleMetaData } from '../types/module';
export declare function createEmptyModule(meta: ModuleMetaData): EchoModule;
import { AppData, AppMetadata } from "../types/module";
export declare function createEmptyModule(meta: AppMetadata): AppData;

@@ -1,2 +0,2 @@

import { EchoEventHub, EchoEvents, UnsubscribeFunction } from '../types/event';
import { EchoEventHub, EchoEvents } from '../types/event';
/**

@@ -26,3 +26,3 @@ * Class for creating an eventHub to be used for emitting and subscribing to either

*/
subscribe<T>(key: string | EchoEvents, handler: (payload: T) => void): UnsubscribeFunction;
subscribe<T>(key: string | EchoEvents, handler: (payload: T) => void): () => void;
/**

@@ -37,5 +37,5 @@ * Function for subscribing to an array of events.

*/
subscribeMany<T>(keys: Array<string | EchoEvents>, handler: (payload: T) => void): UnsubscribeFunction;
subscribeMany<T>(keys: Array<string | EchoEvents>, handler: (payload: T) => void): () => void;
}
export declare const eventHub: EventHub;
export default eventHub;

@@ -1,4 +0,2 @@

export * from './emptyApp';
export * from './eventHub';
export * from './getDependencyResolver';
export * from './storage';

@@ -1,5 +0,3 @@

export * from './emptyApp';
export * from './eventHub';
export * from './getDependencyResolver';
export * from './storage';
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import BaseError from './BaseError';
import { BaseError } from './BaseError';
interface ArgumentErrorArgs {

@@ -3,0 +3,0 @@ argumentName: string;

@@ -13,5 +13,5 @@ "use strict";

return ArgumentError;
}(BaseError_1.default));
}(BaseError_1.BaseError));
exports.ArgumentError = ArgumentError;
exports.default = ArgumentError;
//# sourceMappingURL=ArgumentError.js.map

@@ -1,2 +0,2 @@

import { BaseErrorArgs, BaseErrorProps, ErrorProperties } from '../types/error';
import { BaseErrorArgs, ErrorProperties } from '../types/error';
/**

@@ -10,3 +10,3 @@ * Base Error class is intended to be used as a base class for every type of Error generated

*/
export declare class BaseError extends Error implements BaseErrorProps {
export declare class BaseError extends Error {
protected properties: ErrorProperties;

@@ -18,2 +18,1 @@ hasBeenLogged: boolean;

}
export default BaseError;

@@ -31,3 +31,2 @@ "use strict";

exports.BaseError = BaseError;
exports.default = BaseError;
//# sourceMappingURL=BaseError.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.initializeError = void 0;
var network_1 = require("./network");
var NetworkError_1 = require("./NetworkError");
var initializeError = function (ErrorType, args) {

@@ -14,13 +14,13 @@ var _a;

exception.title && exception.title.toLowerCase().includes('validation')
? new network_1.ValidationError(args)
: new network_1.BackendError(args);
? new NetworkError_1.ValidationError(args)
: new NetworkError_1.BackendError(args);
break;
case 403:
errorInstance = new network_1.ForbiddenError(args);
errorInstance = new NetworkError_1.ForbiddenError(args);
break;
case 404:
errorInstance = new network_1.NotFoundError(args);
errorInstance = new NetworkError_1.NotFoundError(args);
break;
default:
errorInstance = new network_1.BackendError(args);
errorInstance = new NetworkError_1.BackendError(args);
break;

@@ -27,0 +27,0 @@ }

import { CommonErrorArgs } from '../types/error';
import BaseError from './BaseError';
import { BaseError } from './BaseError';
export interface NetworkErrorArgs extends CommonErrorArgs {

@@ -23,2 +23,9 @@ exception: Record<string, unknown>;

}
export default NetworkError;
export declare class BackendError extends NetworkError {
}
export declare class ForbiddenError extends NetworkError {
}
export declare class NotFoundError extends NetworkError {
}
export declare class ValidationError extends NetworkError {
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NetworkError = void 0;
exports.ValidationError = exports.NotFoundError = exports.ForbiddenError = exports.BackendError = exports.NetworkError = void 0;
var tslib_1 = require("tslib");

@@ -29,5 +29,36 @@ var BaseError_1 = require("./BaseError");

return NetworkError;
}(BaseError_1.default));
}(BaseError_1.BaseError));
exports.NetworkError = NetworkError;
exports.default = NetworkError;
var BackendError = /** @class */ (function (_super) {
tslib_1.__extends(BackendError, _super);
function BackendError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return BackendError;
}(NetworkError));
exports.BackendError = BackendError;
var ForbiddenError = /** @class */ (function (_super) {
tslib_1.__extends(ForbiddenError, _super);
function ForbiddenError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return ForbiddenError;
}(NetworkError));
exports.ForbiddenError = ForbiddenError;
var NotFoundError = /** @class */ (function (_super) {
tslib_1.__extends(NotFoundError, _super);
function NotFoundError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return NotFoundError;
}(NetworkError));
exports.NotFoundError = NotFoundError;
var ValidationError = /** @class */ (function (_super) {
tslib_1.__extends(ValidationError, _super);
function ValidationError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return ValidationError;
}(NetworkError));
exports.ValidationError = ValidationError;
//# sourceMappingURL=NetworkError.js.map
export * from './errors';
export { default as ArgumentError } from './errors/ArgumentError';
export { default as BaseError } from './errors/BaseError';
export { default as NetworkError } from './errors/NetworkError';
export * from './module';
export * from './types';
export * from './utils';
export { default as eventHub } from './utils/eventHub';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NetworkError = exports.BaseError = exports.ArgumentError = void 0;
exports.eventHub = void 0;
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./errors"), exports);
var ArgumentError_1 = require("./errors/ArgumentError");
Object.defineProperty(exports, "ArgumentError", { enumerable: true, get: function () { return ArgumentError_1.default; } });
var BaseError_1 = require("./errors/BaseError");
Object.defineProperty(exports, "BaseError", { enumerable: true, get: function () { return BaseError_1.default; } });
var NetworkError_1 = require("./errors/NetworkError");
Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return NetworkError_1.default; } });
tslib_1.__exportStar(require("./module"), exports);
tslib_1.__exportStar(require("./types"), exports);
tslib_1.__exportStar(require("./utils"), exports);
var eventHub_1 = require("./utils/eventHub");
Object.defineProperty(exports, "eventHub", { enumerable: true, get: function () { return eventHub_1.default; } });
//# sourceMappingURL=index.js.map

@@ -1,18 +0,1 @@

import { EchoModulesLoading, LoadingModuleOptions } from '../types';
interface StartLoadingModules {
connect(notifier: EchoModulesLoading): void;
disconnect(notifier: EchoModulesLoading): void;
}
/**
* Used to start loading modules, the modules can be provided, or a fetch call can be defined to
* retrieving the moduleMetaData that in turn will load the js files, and initialize the all modules.
* Module data will be stored in the globals store trough the notifier provided trough the connect function.
*
* This function is used in Echo Framework in the Mediator Component.
*
* @export
* @param {LoadingModuleOptions} options
* @return {*} {StartLoadingModules}
*/
export declare function startLoadingModules(options: LoadingModuleOptions): StartLoadingModules;
export {};
export declare function startLoadingApps(options: {}): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.startLoadingModules = void 0;
var strategies_1 = require("./strategies");
var utils_1 = require("./utils");
/**
* Used to start loading modules, the modules can be provided, or a fetch call can be defined to
* retrieving the moduleMetaData that in turn will load the js files, and initialize the all modules.
* Module data will be stored in the globals store trough the notifier provided trough the connect function.
*
* This function is used in Echo Framework in the Mediator Component.
*
* @export
* @param {LoadingModuleOptions} options
* @return {*} {StartLoadingModules}
*/
function startLoadingModules(options) {
exports.startLoadingApps = void 0;
function startLoadingApps(options) {
var state = {
loaded: false,
modules: [],
error: undefined
loading: false,
apps: [],
error: undefined,
};
var notifiers = [];
var call = function (notifier) { return notifier(state.error, state.modules, state.loaded); };
var notify = function () { return notifiers.forEach(call); };
var setAppModules = function (error, modules) {
state.error = error;
state.modules = modules;
notify();
};
var setLoaded = function () {
state.loaded = true;
notify();
};
utils_1.fireAndForget(function () { return strategies_1.standardStrategy(options, setAppModules).then(setLoaded, setLoaded); });
return {
connect: function (notifier) {
if (utils_1.isfunc(notifier)) {
notifiers.push(notifier);
call(notifier);
}
},
disconnect: function (notifier) {
var index = notifiers.indexOf(notifier);
index !== -1 && notifiers.splice(index, 1);
}
};
}
exports.startLoadingModules = startLoadingModules;
exports.startLoadingApps = startLoadingApps;
//# sourceMappingURL=create.js.map

@@ -1,47 +0,8 @@

import { AvailableDependencies, ModuleData, ModuleMetaData } from '../types';
import { AppData, AvailableDependencies } from '../types/module';
declare global {
interface HTMLScriptElement {
module?: ModuleData;
app?: AppData;
}
}
/**
* Incudes a script tag in the DOM,
* and extracts the setup function.
*
* @export
* @param {string} name
* @param {string} fileUri
* @param {string} depName
* @param {AvailableDependencies} dependencies
* @param {string} [crossOrigin]
* @param {string} [integrity]
* @return {*} {(Promise<ModuleData | undefined>)}
*/
export declare function includeScript(name: string, fileUri: string, depName: string, dependencies: AvailableDependencies, crossOrigin?: string, integrity?: string): Promise<ModuleData | undefined>;
/**
* async wrapper of check app resolving the app ModuleData
*
* @export
* @param {string} name
* @param {(ModuleData | Promise<ModuleData>)} [module]
* @return {*} {Promise<ModuleData>}
*/
export declare function checkAppAsync(name: string, module?: ModuleData | Promise<ModuleData>): Promise<ModuleData>;
/**
* Function added to window object for retrieving AvailableDependencies
*
* @export
* @param {AvailableDependencies} [dependencies={}]
* @return {*}
*/
export declare function checkAppAsync(app?: AppData | Promise<AppData>): Promise<AppData>;
export declare function getLocalRequire(dependencies?: AvailableDependencies): (moduleName: string) => void;
/**
* Retiring the current module.
*
* @export
* @param {ModuleMetaData} { name, fileUri: link, requireRef, integrity }
* @param {AvailableDependencies} [dependencies]
* @param {string} [crossOrigin]
* @return {*} {Promise<ModuleData>}
*/
export declare function includeDependency({ name, fileUri: link, requireRef, integrity }: ModuleMetaData, dependencies?: AvailableDependencies, crossOrigin?: string): Promise<ModuleData>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.includeDependency = exports.getLocalRequire = exports.checkAppAsync = exports.includeScript = void 0;
var tslib_1 = require("tslib");
/**
* Returns the module dependency if present in the AvailableDependencies
*
* @param {string} name
* @param {AvailableDependencies} dependencies
* @return {*} {*}
*/
exports.getLocalRequire = exports.checkAppAsync = void 0;
function requireModule(name, dependencies) {

@@ -21,19 +13,11 @@ var dependency = dependencies[name];

}
/**
* Verifies if the module is a correct EchoModule with a exported setup function.
* Will provide a empty module if verification fails to prevent system crash.
*
* @param {string} name
* @param {ModuleData} [module]
* @return {*} {ModuleData}
*/
function checkModule(name, module) {
if (!module) {
console.error('Invalid module found.', name);
function checkApp(app) {
if (!app) {
console.error('Invalid module found.', app);
}
else if (typeof module.setup !== 'function') {
console.warn('Setup function is missing.', name);
else if (typeof app.setup !== 'function') {
console.warn('Setup function is missing.');
}
else {
return module;
return app;
}

@@ -46,68 +30,6 @@ return {

}
/**
* Incudes a script tag in the DOM,
* and extracts the setup function.
*
* @export
* @param {string} name
* @param {string} fileUri
* @param {string} depName
* @param {AvailableDependencies} dependencies
* @param {string} [crossOrigin]
* @param {string} [integrity]
* @return {*} {(Promise<ModuleData | undefined>)}
*/
function includeScript(name, fileUri, depName, dependencies, crossOrigin, integrity) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, new Promise(function (resolve, reject) {
var script = document.createElement('script');
script.async = true;
script.src = fileUri;
script.id = name;
if (integrity) {
script.crossOrigin = crossOrigin || 'anonymous';
script.integrity = integrity;
}
else if (crossOrigin) {
script.crossOrigin = crossOrigin;
}
window[depName] = getLocalRequire(dependencies);
script.onload = function () { return resolve(checkAppAsync(name, script.module)); };
script.onerror = function () { return reject('could not load'); };
document.head.appendChild(script);
})];
});
});
function checkAppAsync(app) {
return Promise.resolve(app).then(function (resolvedApp) { return checkApp(resolvedApp); });
}
exports.includeScript = includeScript;
/**
* async wrapper of check app resolving the app ModuleData
*
* @export
* @param {string} name
* @param {(ModuleData | Promise<ModuleData>)} [module]
* @return {*} {Promise<ModuleData>}
*/
function checkAppAsync(name, module) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var resolvedModule;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.resolve(module)];
case 1:
resolvedModule = _a.sent();
return [2 /*return*/, checkModule(name, resolvedModule)];
}
});
});
}
exports.checkAppAsync = checkAppAsync;
/**
* Function added to window object for retrieving AvailableDependencies
*
* @export
* @param {AvailableDependencies} [dependencies={}]
* @return {*}
*/
function getLocalRequire(dependencies) {

@@ -118,23 +40,2 @@ if (dependencies === void 0) { dependencies = {}; }

exports.getLocalRequire = getLocalRequire;
/**
* Retiring the current module.
*
* @export
* @param {ModuleMetaData} { name, fileUri: link, requireRef, integrity }
* @param {AvailableDependencies} [dependencies]
* @param {string} [crossOrigin]
* @return {*} {Promise<ModuleData>}
*/
function includeDependency(_a, dependencies, crossOrigin) {
var name = _a.name, link = _a.fileUri, requireRef = _a.requireRef, integrity = _a.integrity;
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, includeScript(name, link, requireRef, dependencies, crossOrigin, integrity)];
case 1: return [2 /*return*/, _b.sent()];
}
});
});
}
exports.includeDependency = includeDependency;
//# sourceMappingURL=dependency.js.map

@@ -7,2 +7,2 @@ /**

*/
export declare function defaultFetchDependency(url: string, token?: string): Promise<string>;
export declare function fetchDependency(url: string, token: string): Promise<string>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultFetchDependency = void 0;
exports.fetchDependency = void 0;
var tslib_1 = require("tslib");

@@ -11,3 +11,3 @@ /**

*/
function defaultFetchDependency(url, token) {
function fetchDependency(url, token) {
return tslib_1.__awaiter(this, void 0, void 0, function () {

@@ -30,3 +30,3 @@ var m;

}
exports.defaultFetchDependency = defaultFetchDependency;
exports.fetchDependency = fetchDependency;
//# sourceMappingURL=fetch.js.map

@@ -13,3 +13,3 @@ "use strict";

return ModulesMetaError;
}(BaseError_1.default));
}(BaseError_1.BaseError));
/**

@@ -16,0 +16,0 @@ * Fetch the metadata for all modules registered

@@ -1,12 +0,7 @@

export * from './aggregate';
export * from './create';
export * from './dependency';
export * from './errors';
export * from './fetch';
export * from './load';
export * from './fetchModules';
export * from './loader';
export * from './persist';
export * from './setup';
export * from './strategies';
export * from './utils';
export * from './verify';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./aggregate"), exports);
tslib_1.__exportStar(require("./create"), exports);
tslib_1.__exportStar(require("./dependency"), exports);
tslib_1.__exportStar(require("./errors"), exports);
tslib_1.__exportStar(require("./fetch"), exports);
tslib_1.__exportStar(require("./load"), exports);
tslib_1.__exportStar(require("./fetchModules"), exports);
tslib_1.__exportStar(require("./loader"), exports);
tslib_1.__exportStar(require("./persist"), exports);
tslib_1.__exportStar(require("./setup"), exports);
tslib_1.__exportStar(require("./strategies"), exports);
tslib_1.__exportStar(require("./utils"), exports);
tslib_1.__exportStar(require("./verify"), exports);
//# sourceMappingURL=index.js.map

@@ -1,21 +0,3 @@

import { AppDependencyGetter, AvailableDependencies, DefaultLoaderConfig, ModuleLoader } from '../types';
/**
* Create a module loader with the provided dependence's.
*
* @export
* @param {DefaultLoaderConfig} [config]
* @param {AvailableDependencies} [dependencies]
* @param {AppDependencyGetter} [getDependencies]
* @return {*} {ModuleLoader}
*/
export declare function createModuleLoader(config?: DefaultLoaderConfig, dependencies?: AvailableDependencies, getDependencies?: AppDependencyGetter): ModuleLoader;
/**
* Loader for loading modules, with dependencies, will return a empty module,
* if empty module is found, for avoiding crashes.
*
* @export
* @param {AppDependencyGetter} getDependencies
* @param {DefaultLoaderConfig} [config={}]
* @return {*} {ModuleLoader}
*/
export declare function getModuleLoader(getDependencies: AppDependencyGetter, config?: DefaultLoaderConfig): ModuleLoader;
import { App, AppData, AppMetadata, AvailableDependencies } from '../types/module';
export declare function loadModule(meta: AppMetadata, loadModuleData: (meta: AppMetadata) => AppData): App;
export declare function loadApp(link: string, depName: string, dependencies: AvailableDependencies): Promise<AppData | undefined>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getModuleLoader = exports.createModuleLoader = void 0;
exports.loadApp = exports.loadModule = void 0;
var tslib_1 = require("tslib");
var emptyApp_1 = require("../utils/emptyApp");
var getDependencyResolver_1 = require("../utils/getDependencyResolver");
var dependency_1 = require("./dependency");
var inBrowser = typeof document !== 'undefined';
/**
* Create a module loader with the provided dependence's.
*
* @export
* @param {DefaultLoaderConfig} [config]
* @param {AvailableDependencies} [dependencies]
* @param {AppDependencyGetter} [getDependencies]
* @return {*} {ModuleLoader}
*/
function createModuleLoader(config, dependencies, getDependencies) {
var getDeps = getDependencyResolver_1.getDependencyResolver(dependencies, getDependencies);
return getModuleLoader(getDeps, config);
function loadModule(meta, loadModuleData) {
var module = loadModuleData(meta);
return tslib_1.__assign(tslib_1.__assign({}, meta), module);
}
exports.createModuleLoader = createModuleLoader;
/**
* Loader for loading modules, with dependencies, will return a empty module,
* if empty module is found, for avoiding crashes.
*
* @export
* @param {AppDependencyGetter} getDependencies
* @param {DefaultLoaderConfig} [config={}]
* @return {*} {ModuleLoader}
*/
function getModuleLoader(getDependencies, config) {
if (config === void 0) { config = {}; }
return function (meta) {
if (inBrowser && 'requireRef' in meta && meta.requireRef) {
return loadModule(meta, getDependencies, function (deps) { return dependency_1.includeDependency(meta, deps, config.crossOrigin); });
}
console.warn('Empty Module found!', meta.name);
return Promise.resolve(emptyApp_1.createEmptyModule(meta));
};
}
exports.getModuleLoader = getModuleLoader;
/**
* Loading the module and combining the javascript module with the modules Metadata.
*
* @param {ModuleMetaData} meta
* @param {AppDependencyGetter} getDependencies
* @param {(dependencies: AvailableDependencies) => Promise<ModuleData>} loader
* @return {*} {Promise<EchoModule>}
*/
function loadModule(meta, getDependencies, loader) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var dependencies, app;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
dependencies = tslib_1.__assign({}, (getDependencies(meta) || {}));
return [4 /*yield*/, loader(dependencies)];
case 1:
app = _a.sent();
return [2 /*return*/, tslib_1.__assign(tslib_1.__assign({}, app), meta)];
}
});
exports.loadModule = loadModule;
function loadApp(link, depName, dependencies) {
return new Promise(function (resolve, reject) {
var s = document.createElement('script');
s.async = true;
s.src = link;
s.crossOrigin = 'cross-origin';
window[depName] = dependency_1.getLocalRequire(dependencies);
s.onload = function () {
var app = dependency_1.checkAppAsync(s.app);
resolve(app);
};
s.onerror = function () { return reject('could not load'); };
document.head.appendChild(s);
});
}
exports.loadApp = loadApp;
//# sourceMappingURL=loader.js.map

@@ -1,3 +0,3 @@

import { ModuleMetaData } from '../types/module';
export declare function persistLocalModuleMeta(key: string, modules: ModuleMetaData[]): void;
export declare function loadLocalModuleMeta(key: string): ModuleMetaData[];
import { AppMetadata } from '../types/module';
export declare function persistLocalModuleMeta(key: string, modules: AppMetadata[]): void;
export declare function loadLocalModuleMeta(key: string): AppMetadata[];

@@ -1,3 +0,4 @@

import { EchoModule, EchoModuleApi, EchoModuleApiCreator } from '../types';
export declare function setupSingleModule(module: EchoModule, api: EchoModuleApi): void | Promise<void>;
export declare function setupModule(module: EchoModule, apiFactory: EchoModuleApiCreator): void | Promise<void>;
import { App, AppApi, AppApiCreator, MultiApp, SingleApp } from '../types';
export declare function setupSingleApp(app: SingleApp, api: AppApi): void | Promise<void>;
export declare function setupMultiApps(app: MultiApp, apiFactory: AppApiCreator): void | Promise<void>;
export declare function setupApp(app: App, apiFactory: AppApiCreator): void | Promise<void>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setupModule = exports.setupSingleModule = void 0;
function setupSingleModule(module, api) {
exports.setupApp = exports.setupMultiApps = exports.setupSingleApp = void 0;
function setupSingleApp(app, api) {
try {
var result = module.setup(api);
var result = app.setup(api);
return result;
}
catch (error) {
console.warn(error);
catch (error) { }
}
exports.setupSingleApp = setupSingleApp;
function setupMultiApps(app, apiFactory) {
try {
return app.setup(apiFactory);
}
catch (e) {
console.error("Error while setting up " + (app === null || app === void 0 ? void 0 : app.name) + ".", e);
}
}
exports.setupSingleModule = setupSingleModule;
function setupModule(module, apiFactory) {
return setupSingleModule(module, apiFactory(module));
exports.setupMultiApps = setupMultiApps;
function setupApp(app, apiFactory) {
if ('bundle' in app) {
return setupMultiApps(app, apiFactory);
}
else {
return setupSingleApp(app, apiFactory(app));
}
}
exports.setupModule = setupModule;
exports.setupApp = setupApp;
//# sourceMappingURL=setup.js.map

@@ -1,35 +0,4 @@

import { EchoModuleApiCreator, ModuleRequester } from '../types/creators';
import { EchoModule, ModuleMetaData } from '../types/module';
/**
*
*
* @export
* @param {string} id
*/
import { AppMetadata, SingleApp } from '../types/module';
export declare function removeElementById(id: string): void;
/**
* Helper function for Checking if function is present.
*
* @param {EchoModuleApiCreator} createModuleApi
* @return {*} {boolean}
*/
export declare function checkFunction(func: EchoModuleApiCreator | ModuleRequester, errorMessage: string): boolean;
/**
*
*
* @export
* @param {*} f
* @return {*} {f is Function}
*/
export declare function isfunc(f: unknown): f is Function;
/**
*
*
* @export
* @param {ModuleMetaData} meta
* @return {*} {SingleApp}
*/
export declare function createEmptyApp(meta: ModuleMetaData): EchoModule;
export declare function isProduction(): boolean;
export declare function filterExcludePrivateModulesInProduction(modules: EchoModule[], isProduction?: () => boolean): EchoModule[];
export declare function fireAndForget(asyncFunc: () => Promise<void>): void;
export declare function isfunc(f: any): f is Function;
export declare function createEmptyModule(meta: AppMetadata): SingleApp;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fireAndForget = exports.filterExcludePrivateModulesInProduction = exports.isProduction = exports.createEmptyApp = exports.isfunc = exports.checkFunction = exports.removeElementById = void 0;
exports.createEmptyModule = exports.isfunc = exports.removeElementById = void 0;
var tslib_1 = require("tslib");
/**
*
*
* @export
* @param {string} id
*/
function removeElementById(id) {

@@ -16,23 +10,2 @@ var _a;

exports.removeElementById = removeElementById;
/**
* Helper function for Checking if function is present.
*
* @param {EchoModuleApiCreator} createModuleApi
* @return {*} {boolean}
*/
function checkFunction(func, errorMessage) {
if (!isfunc(func)) {
console.warn(errorMessage);
return false;
}
return true;
}
exports.checkFunction = checkFunction;
/**
*
*
* @export
* @param {*} f
* @return {*} {f is Function}
*/
function isfunc(f) {

@@ -42,10 +15,3 @@ return typeof f === 'function';

exports.isfunc = isfunc;
/**
*
*
* @export
* @param {ModuleMetaData} meta
* @return {*} {SingleApp}
*/
function createEmptyApp(meta) {
function createEmptyModule(meta) {
return tslib_1.__assign(tslib_1.__assign({}, meta), { setup: function () {

@@ -55,18 +21,3 @@ // Empty module

}
exports.createEmptyApp = createEmptyApp;
function isProduction() {
return process.env.NODE_ENV === 'production';
}
exports.isProduction = isProduction;
function filterExcludePrivateModulesInProduction(modules, isProduction) {
if (isProduction && isProduction()) {
return modules.filter(function (module) { return module.private !== true; });
}
return modules;
}
exports.filterExcludePrivateModulesInProduction = filterExcludePrivateModulesInProduction;
function fireAndForget(asyncFunc) {
asyncFunc();
}
exports.fireAndForget = fireAndForget;
exports.createEmptyModule = createEmptyModule;
//# sourceMappingURL=utils.js.map

@@ -1,2 +0,2 @@

import { ModuleMetaData } from '../types/module';
export declare function verifyModulesMeta(modules: ModuleMetaData[]): ModuleMetaData[];
import { AppMetadata } from '../types/module';
export declare function verifyModulesMeta(modules: AppMetadata[]): AppMetadata[];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifyModulesMeta = void 0;
var ArgumentError_1 = require("../errors/ArgumentError");
var persist_1 = require("./persist");
function verifyModulesMeta(modules) {
if (modules instanceof Array) {
modules.length > 0 && persist_1.persistLocalModuleMeta('EchoModules', modules);
return modules;
if (modules.length === 0) {
throw new ArgumentError_1.default({ argumentName: 'No modules awaitable' });
}
console.log('No modules awaitable.');
return [];
persist_1.persistLocalModuleMeta('EchoModules', modules);
return modules;
}
exports.verifyModulesMeta = verifyModulesMeta;
//# sourceMappingURL=verify.js.map

@@ -8,8 +8,42 @@ /**

emit<T>(key: string, payload: T): void;
subscribe<T>(key: string, handler: (payload: T) => void): UnsubscribeFunction;
subscribeMany<T>(keys: Array<string | EchoEvents>, handler: (payload: T) => void): UnsubscribeFunction;
subscribe<T>(key: string, handler: (payload: T) => void): () => void;
subscribeMany<T>(keys: Array<string | EchoEvents>, handler: (payload: T) => void): () => void;
}
export declare type UnsubscribeFunction = () => void;
export declare enum EchoEvents {
PlantChanged = "plantChanged"
}
/**
* Emitter of module app shell events.
*/
export interface ModuleEventEmitter {
/**
* Attaches a new event listener.
* @param type The type of the event to listen for.
* @param callback The callback to trigger.
*/
on<K extends keyof EventMap>(type: K, callback: Listener<EventMap[K]>): ModuleEventEmitter;
/**
* Detaches an existing event listener.
* @param type The type of the event to listen for.
* @param callback The callback to trigger.
*/
of<K extends keyof EventMap>(type: K, callback: Listener<EventMap[K]>): ModuleEventEmitter;
/**
* Emits a new event with the given type.
* @param type The type of the event to emit.
* @param arg The payload of the event.
*/
emit<K extends keyof EventMap>(type: K, arg: EventMap[K]): ModuleEventEmitter;
}
export interface EventMap {
[custom: string]: unknown;
}
/**
* Listener for module app shell events.
*/
export interface Listener<T> {
/**
* Receives an event of type T.
*/
(arg: T): void;
}

@@ -1,8 +0,4 @@

export * from './common';
export * from './creators';
export * from './error';
export * from './event';
export * from './loader';
export * from './module';
export * from './options';
export * from './storage';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./common"), exports);
tslib_1.__exportStar(require("./creators"), exports);
tslib_1.__exportStar(require("./error"), exports);
tslib_1.__exportStar(require("./event"), exports);
tslib_1.__exportStar(require("./loader"), exports);
tslib_1.__exportStar(require("./module"), exports);
tslib_1.__exportStar(require("./options"), exports);
tslib_1.__exportStar(require("./storage"), exports);
//# sourceMappingURL=index.js.map

@@ -1,5 +0,1 @@

import BaseError from '../errors/BaseError';
import { EchoModule, ModuleMetaData } from './module';
export declare class ModuleAppError extends BaseError {
}
/**

@@ -11,16 +7,1 @@ * Configuration options for the default loader.

}
export interface ModulesLoader {
(): Array<EchoModule>;
}
export interface EchoModuleLoaded {
(error: ModuleAppError | undefined, modules: Array<EchoModule>): void;
}
export interface EchoModulesLoading {
(error: ModuleAppError | undefined, modules: Array<EchoModule>, loaded: boolean): void;
}
export interface ModuleLoader {
(meta: ModuleMetaData): Promise<EchoModule>;
}
export interface DefaultLoaderConfig {
crossOrigin?: string;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModuleAppError = void 0;
var tslib_1 = require("tslib");
var BaseError_1 = require("../errors/BaseError");
var ModuleAppError = /** @class */ (function (_super) {
tslib_1.__extends(ModuleAppError, _super);
function ModuleAppError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return ModuleAppError;
}(BaseError_1.default));
exports.ModuleAppError = ModuleAppError;
//# sourceMappingURL=loader.js.map

@@ -1,34 +0,67 @@

import { EchoEventHub } from './event';
export interface ModuleMetaData extends MetaDataBase {
requireRef?: string;
import { ModuleEventEmitter } from "./event";
export interface SingleAppMetadata {
name: string;
link: string;
requireRef: string;
integrity?: string;
custom?: any;
config?: Record<string, any>;
}
export interface MetaDataBase {
key: string;
export interface MultiAppsMetadata {
name: string;
shortName: string;
path: string;
fileUri: string;
version: string;
link: string;
bundle: string;
integrity?: string;
private?: boolean;
custom?: any;
}
export declare type App = SingleApp | MultiApp;
/**
* Echo Module setup function and meta data combined.
* Describes the metadata transported by a Apps.
*/
export declare type EchoModule = ModuleData & ModuleMetaData;
export declare type AppMetadata = SingleAppMetadata | MultiAppsMetadata;
/**
* The metadata for a single app.
*/
export declare type SingleApp = AppData & AppMetadata;
/**
* The metadata for apps containing apps.
*/
export declare type MultiApp = MultiAppData & MultiAppsMetadata;
/**
* Defines the API accessible from Apps.
*/
export interface EchoModuleApi {
export interface AppApi extends ModuleEventEmitter {
/**
* Gets the metadata of the current App.
*/
meta: ModuleMetaData;
eventHub: EchoEventHub;
meta: AppMetadata;
}
export interface ModuleData {
setup: (api: EchoModuleApi) => void | Promise<void>;
export interface RouteRegistration extends BaseRegistration {
meta: AppMetaData;
}
export declare type AppMetaFetch = () => Promise<ModuleMetaData[]>;
export interface AppMetaData {
name: string;
icon: string;
homeScreen?: boolean;
}
export interface BaseRegistration {
key: string;
}
export interface AppData {
setup: (api: AppApi) => void | Promise<void>;
}
export interface MultiAppData {
setup: (apiFactory: AppApiCreator) => void | Promise<void>;
}
export interface EchoPortal {
isAuthenticated: boolean;
}
export declare type AppMetaFetch = () => Promise<AppMetadata[]>;
/**
* The creator function for the App API.
*/
export interface AppApiCreator {
(target: AppMetadata): AppApi;
}
/**
* The record containing all available dependencies.

@@ -35,0 +68,0 @@ */

@@ -1,2 +0,2 @@

import { EchoModule, ModuleMetaData } from '../types/module';
export declare function createEmptyModule(meta: ModuleMetaData): EchoModule;
import { AppData, AppMetadata } from "../types/module";
export declare function createEmptyModule(meta: AppMetadata): AppData;

@@ -1,2 +0,2 @@

import { EchoEventHub, EchoEvents, UnsubscribeFunction } from '../types/event';
import { EchoEventHub, EchoEvents } from '../types/event';
/**

@@ -26,3 +26,3 @@ * Class for creating an eventHub to be used for emitting and subscribing to either

*/
subscribe<T>(key: string | EchoEvents, handler: (payload: T) => void): UnsubscribeFunction;
subscribe<T>(key: string | EchoEvents, handler: (payload: T) => void): () => void;
/**

@@ -37,5 +37,5 @@ * Function for subscribing to an array of events.

*/
subscribeMany<T>(keys: Array<string | EchoEvents>, handler: (payload: T) => void): UnsubscribeFunction;
subscribeMany<T>(keys: Array<string | EchoEvents>, handler: (payload: T) => void): () => void;
}
export declare const eventHub: EventHub;
export default eventHub;

@@ -1,4 +0,2 @@

export * from './emptyApp';
export * from './eventHub';
export * from './getDependencyResolver';
export * from './storage';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./emptyApp"), exports);
tslib_1.__exportStar(require("./eventHub"), exports);
tslib_1.__exportStar(require("./getDependencyResolver"), exports);
tslib_1.__exportStar(require("./storage"), exports);
//# sourceMappingURL=index.js.map
{
"name": "@equinor/echo-base",
"version": "0.2.92",
"version": "0.2.93",
"module": "esm/index.js",

@@ -15,4 +15,3 @@ "main": "lib/index.js",

"echo-publish-next": "npm publish --access public --tag next",
"test": "echo \"Run test from root folder\" && exit 1",
"build-docs": "npx typedoc --out docs src/index.ts"
"test": "echo \"Run test from root folder\" && exit 1"
},

@@ -35,9 +34,4 @@ "keywords": [

"@types/node": "^14.14.37",
"typedoc": "^0.20.35",
"typescript": "^4.2.4"
},
"peerDependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"files": [

@@ -44,0 +38,0 @@ "esm",

@@ -1,2 +0,2 @@

import BaseError from '../../errors/BaseError';
import { BaseError } from '../../errors/BaseError';

@@ -3,0 +3,0 @@ describe('BaseError', () => {

import { initializeError } from '../../errors/errorHandlers';
import BackendError from '../../errors/network/BackendError';
import ForbiddenError from '../../errors/network/ForbiddenError';
import NotFoundError from '../../errors/network/NotFoundError';
import ValidationError from '../../errors/network/ValidationError';
import NetworkError, { NetworkErrorArgs } from '../../errors/NetworkError';
import {
BackendError,
ForbiddenError,
NetworkError,
NetworkErrorArgs,
NotFoundError,
ValidationError
} from '../../errors/NetworkError';

@@ -8,0 +11,0 @@ describe('handleClientError', () => {

@@ -1,2 +0,2 @@

import NetworkError from '../../errors/NetworkError';
import { ForbiddenError, NetworkError, NetworkErrorArgs } from '../../errors/NetworkError';

@@ -15,2 +15,7 @@ describe('NetworkError', () => {

it('should be correct instanceOf', () => {
const forbiddenError = new ForbiddenError({} as NetworkErrorArgs);
expect(forbiddenError instanceof ForbiddenError).toBeTruthy();
});
it('check properties', () => {

@@ -17,0 +22,0 @@ const properties = {

@@ -1,2 +0,2 @@

import BaseError from './BaseError';
import { BaseError } from './BaseError';

@@ -3,0 +3,0 @@ interface ArgumentErrorArgs {

@@ -1,2 +0,2 @@

import { BaseErrorArgs, BaseErrorProps, ErrorProperties } from '../types/error';
import { BaseErrorArgs, ErrorProperties } from '../types/error';

@@ -11,3 +11,3 @@ /**

*/
export class BaseError extends Error implements BaseErrorProps {
export class BaseError extends Error {
protected properties: ErrorProperties;

@@ -29,3 +29,1 @@ hasBeenLogged = false;

}
export default BaseError;
import { ErrorInitializerFunction } from '../types/error';
import BaseError from './BaseError';
import { BackendError, ForbiddenError, NotFoundError, ValidationError } from './network';
import { NetworkError, NetworkErrorArgs } from './NetworkError';
import { BaseError } from './BaseError';
import {
BackendError,
ForbiddenError,
NetworkError,
NetworkErrorArgs,
NotFoundError,
ValidationError
} from './NetworkError';

@@ -6,0 +12,0 @@ export const initializeError: ErrorInitializerFunction<NetworkError, NetworkErrorArgs> = (

import { CommonErrorArgs } from '../types/error';
import BaseError from './BaseError';
import { BaseError } from './BaseError';

@@ -33,2 +33,8 @@ export interface NetworkErrorArgs extends CommonErrorArgs {

export default NetworkError;
export class BackendError extends NetworkError {}
export class ForbiddenError extends NetworkError {}
export class NotFoundError extends NetworkError {}
export class ValidationError extends NetworkError {}
export * from './errors';
export { default as ArgumentError } from './errors/ArgumentError';
export { default as BaseError } from './errors/BaseError';
export { default as NetworkError } from './errors/NetworkError';
export * from './module';
export * from './types';
export * from './utils';
export { default as eventHub } from './utils/eventHub';

@@ -1,56 +0,16 @@

import { EchoModulesLoading, LoadingModuleOptions } from '../types';
import { EchoModule } from '../types/module';
import { standardStrategy } from './strategies';
import { fireAndForget, isfunc } from './utils';
interface StartLoadingModules {
connect(notifier: EchoModulesLoading): void;
disconnect(notifier: EchoModulesLoading): void;
}
/**
* Used to start loading modules, the modules can be provided, or a fetch call can be defined to
* retrieving the moduleMetaData that in turn will load the js files, and initialize the all modules.
* Module data will be stored in the globals store trough the notifier provided trough the connect function.
*
* This function is used in Echo Framework in the Mediator Component.
*
* @export
* @param {LoadingModuleOptions} options
* @return {*} {StartLoadingModules}
*/
export function startLoadingModules(options: LoadingModuleOptions): StartLoadingModules {
const state = {
loaded: false,
modules: [],
error: undefined
};
const notifiers: EchoModulesLoading[] = [];
const call = (notifier: EchoModulesLoading): void => notifier(state.error, state.modules, state.loaded);
const notify = (): void => notifiers.forEach(call);
const setAppModules = (error: Error, modules: Array<EchoModule>): void => {
state.error = error;
state.modules = modules;
notify();
};
const setLoaded = (): void => {
state.loaded = true;
notify();
};
fireAndForget(() => standardStrategy(options, setAppModules).then(setLoaded, setLoaded));
return {
connect(notifier: EchoModulesLoading): void {
if (isfunc(notifier)) {
notifiers.push(notifier);
call(notifier);
}
},
disconnect(notifier: EchoModulesLoading): void {
const index = notifiers.indexOf(notifier);
index !== -1 && notifiers.splice(index, 1);
}
};
}
export function startLoadingApps(options: {} ) {
const state = {
loading: false,
apps: [],
error: undefined,
}
}

@@ -7,3 +7,3 @@ /**

*/
export async function defaultFetchDependency(url: string, token?: string): Promise<string> {
export async function fetchDependency(url: string, token: string): Promise<string> {
const m = await fetch(url, {

@@ -10,0 +10,0 @@ headers: { token },

@@ -1,12 +0,8 @@

export * from './aggregate';
export * from './create';
export * from './dependency';
export * from './errors';
export * from './fetch';
export * from './load';
export * from './fetchModules';
export * from './loader';
export * from './persist';
export * from './setup';
export * from './strategies';
export * from './utils';
export * from './verify';

@@ -1,75 +0,27 @@

import {
AppDependencyGetter,
AvailableDependencies,
DefaultLoaderConfig,
EchoModule,
ModuleData,
ModuleLoader,
ModuleMetaData
} from '../types';
import { createEmptyModule } from '../utils/emptyApp';
import { getDependencyResolver } from '../utils/getDependencyResolver';
import { includeDependency } from './dependency';
import { App, AppData, AppMetadata, AvailableDependencies } from '../types/module';
import { checkAppAsync, getLocalRequire } from './dependency';
const inBrowser = typeof document !== 'undefined';
/**
* Create a module loader with the provided dependence's.
*
* @export
* @param {DefaultLoaderConfig} [config]
* @param {AvailableDependencies} [dependencies]
* @param {AppDependencyGetter} [getDependencies]
* @return {*} {ModuleLoader}
*/
export function createModuleLoader(
config?: DefaultLoaderConfig,
dependencies?: AvailableDependencies,
getDependencies?: AppDependencyGetter
): ModuleLoader {
const getDeps = getDependencyResolver(dependencies, getDependencies);
return getModuleLoader(getDeps, config);
export function loadModule(meta: AppMetadata, loadModuleData: (meta: AppMetadata) => AppData): App {
const module = loadModuleData(meta);
return { ...meta, ...module };
}
/**
* Loader for loading modules, with dependencies, will return a empty module,
* if empty module is found, for avoiding crashes.
*
* @export
* @param {AppDependencyGetter} getDependencies
* @param {DefaultLoaderConfig} [config={}]
* @return {*} {ModuleLoader}
*/
export function getModuleLoader(getDependencies: AppDependencyGetter, config: DefaultLoaderConfig = {}): ModuleLoader {
return (meta: ModuleMetaData): Promise<EchoModule> => {
if (inBrowser && 'requireRef' in meta && meta.requireRef) {
return loadModule(meta, getDependencies, (deps) => includeDependency(meta, deps, config.crossOrigin));
}
console.warn('Empty Module found!', meta.name);
return Promise.resolve(createEmptyModule(meta));
};
export function loadApp(
link: string,
depName: string,
dependencies: AvailableDependencies
): Promise<AppData | undefined> {
return new Promise<AppData | undefined>((resolve, reject) => {
const s = document.createElement('script');
s.async = true;
s.src = link;
s.crossOrigin = 'cross-origin';
window[depName] = getLocalRequire(dependencies);
s.onload = (): void => {
const app = checkAppAsync(s.app);
resolve(app);
};
s.onerror = (): void => reject('could not load');
document.head.appendChild(s);
});
}
/**
* Loading the module and combining the javascript module with the modules Metadata.
*
* @param {ModuleMetaData} meta
* @param {AppDependencyGetter} getDependencies
* @param {(dependencies: AvailableDependencies) => Promise<ModuleData>} loader
* @return {*} {Promise<EchoModule>}
*/
async function loadModule(
meta: ModuleMetaData,
getDependencies: AppDependencyGetter,
loader: (dependencies: AvailableDependencies) => Promise<ModuleData>
): Promise<EchoModule> {
const dependencies = {
...(getDependencies(meta) || {})
};
const app = await loader(dependencies);
return {
...app,
...meta
};
}

@@ -1,10 +0,10 @@

import { ModuleMetaData } from '../types/module';
import { AppMetadata } from '../types/module';
import { storage } from '../utils/storage';
export function persistLocalModuleMeta(key: string, modules: ModuleMetaData[]): void {
export function persistLocalModuleMeta(key: string, modules: AppMetadata[]): void {
storage.setItem(key, modules);
}
export function loadLocalModuleMeta(key: string): ModuleMetaData[] {
const localModules: ModuleMetaData[] | undefined | string = storage.getItem(key);
export function loadLocalModuleMeta(key: string): AppMetadata[] {
const localModules: AppMetadata[] | undefined | string = storage.getItem(key);
if (!localModules || !(localModules instanceof Array)) {

@@ -11,0 +11,0 @@ return [];

@@ -1,14 +0,24 @@

import { EchoModule, EchoModuleApi, EchoModuleApiCreator } from '../types';
import { App, AppApi, AppApiCreator, MultiApp, SingleApp } from '../types';
export function setupSingleModule(module: EchoModule, api: EchoModuleApi): void | Promise<void> {
export function setupSingleApp(app: SingleApp, api: AppApi): void | Promise<void> {
try {
const result = module.setup(api);
const result = app.setup(api);
return result;
} catch (error) {
console.warn(error);
} catch (error) {}
}
export function setupMultiApps(app: MultiApp, apiFactory: AppApiCreator): void | Promise<void> {
try {
return app.setup(apiFactory);
} catch (e) {
console.error(`Error while setting up ${app?.name}.`, e);
}
}
export function setupModule(module: EchoModule, apiFactory: EchoModuleApiCreator): void | Promise<void> {
return setupSingleModule(module, apiFactory(module));
export function setupApp(app: App, apiFactory: AppApiCreator): void | Promise<void> {
if ('bundle' in app) {
return setupMultiApps(app as MultiApp, apiFactory);
} else {
return setupSingleApp(app, apiFactory(app));
}
}

@@ -1,10 +0,4 @@

import { EchoModuleApiCreator, ModuleRequester } from '../types/creators';
import { EchoModule, ModuleMetaData } from '../types/module';
/* eslint-disable @typescript-eslint/no-explicit-any */
import { AppMetadata, SingleApp } from '../types/module';
/**
*
*
* @export
* @param {string} id
*/
export function removeElementById(id: string): void {

@@ -14,36 +8,7 @@ document.getElementById(id)?.remove();

/**
* Helper function for Checking if function is present.
*
* @param {EchoModuleApiCreator} createModuleApi
* @return {*} {boolean}
*/
export function checkFunction(func: EchoModuleApiCreator | ModuleRequester, errorMessage: string): boolean {
if (!isfunc(func)) {
console.warn(errorMessage);
return false;
}
return true;
}
/**
*
*
* @export
* @param {*} f
* @return {*} {f is Function}
*/
export function isfunc(f: unknown): f is Function {
export function isfunc(f: any): f is Function {
return typeof f === 'function';
}
/**
*
*
* @export
* @param {ModuleMetaData} meta
* @return {*} {SingleApp}
*/
export function createEmptyApp(meta: ModuleMetaData): EchoModule {
export function createEmptyModule(meta: AppMetadata): SingleApp {
return {

@@ -56,19 +21,1 @@ ...meta,

}
export function isProduction(): boolean {
return process.env.NODE_ENV === 'production';
}
export function filterExcludePrivateModulesInProduction(
modules: EchoModule[],
isProduction?: () => boolean
): EchoModule[] {
if (isProduction && isProduction()) {
return modules.filter((module) => module.private !== true);
}
return modules;
}
export function fireAndForget(asyncFunc: () => Promise<void>): void {
asyncFunc();
}

@@ -1,11 +0,11 @@

import { ModuleMetaData } from '../types/module';
import ArgumentError from '../errors/ArgumentError';
import { AppMetadata } from '../types/module';
import { persistLocalModuleMeta } from './persist';
export function verifyModulesMeta(modules: ModuleMetaData[]): ModuleMetaData[] {
if (modules instanceof Array) {
modules.length > 0 && persistLocalModuleMeta('EchoModules', modules);
return modules;
export function verifyModulesMeta(modules: AppMetadata[]): AppMetadata[] {
if (modules.length === 0) {
throw new ArgumentError({ argumentName: 'No modules awaitable' });
}
console.log('No modules awaitable.');
return [];
persistLocalModuleMeta('EchoModules', modules);
return modules;
}

@@ -8,10 +8,48 @@ /**

emit<T>(key: string, payload: T): void;
subscribe<T>(key: string, handler: (payload: T) => void): UnsubscribeFunction;
subscribeMany<T>(keys: Array<string | EchoEvents>, handler: (payload: T) => void): UnsubscribeFunction;
subscribe<T>(key: string, handler: (payload: T) => void): () => void;
subscribeMany<T>(keys: Array<string | EchoEvents>, handler: (payload: T) => void): () => void;
}
export type UnsubscribeFunction = () => void;
export enum EchoEvents {
PlantChanged = 'plantChanged'
}
/**
* Emitter of module app shell events.
*/
export interface ModuleEventEmitter {
/**
* Attaches a new event listener.
* @param type The type of the event to listen for.
* @param callback The callback to trigger.
*/
on<K extends keyof EventMap>(type: K, callback: Listener<EventMap[K]>): ModuleEventEmitter;
/**
* Detaches an existing event listener.
* @param type The type of the event to listen for.
* @param callback The callback to trigger.
*/
of<K extends keyof EventMap>(type: K, callback: Listener<EventMap[K]>): ModuleEventEmitter;
/**
* Emits a new event with the given type.
* @param type The type of the event to emit.
* @param arg The payload of the event.
*/
emit<K extends keyof EventMap>(type: K, arg: EventMap[K]): ModuleEventEmitter;
}
export interface EventMap {
[custom: string]: unknown;
}
/**
* Listener for module app shell events.
*/
export interface Listener<T> {
/**
* Receives an event of type T.
*/
(arg: T): void;
}

@@ -1,8 +0,5 @@

export * from './common';
export * from './creators';
export * from './error';
export * from './event';
export * from './loader';
export * from './module';
export * from './options';
export * from './storage';

@@ -1,29 +0,7 @@

import BaseError from '../errors/BaseError';
import { EchoModule, ModuleMetaData } from './module';
export class ModuleAppError extends BaseError {}
/**
* Configuration options for the default loader.
*/
export interface LoaderConfig {
export interface LoaderConfig {
crossOrigin?: string;
}
export interface ModulesLoader {
(): Array<EchoModule>;
}
export interface EchoModuleLoaded {
(error: ModuleAppError | undefined, modules: Array<EchoModule>): void;
}
export interface EchoModulesLoading {
(error: ModuleAppError | undefined, modules: Array<EchoModule>, loaded: boolean): void;
}
export interface ModuleLoader {
(meta: ModuleMetaData): Promise<EchoModule>;
}
export interface DefaultLoaderConfig {
crossOrigin?: string;
}
}

@@ -1,40 +0,84 @@

import { EchoEventHub } from './event';
import { ModuleEventEmitter } from "./event";
export interface ModuleMetaData extends MetaDataBase {
requireRef?: string;
/* eslint-disable @typescript-eslint/no-explicit-any */
export interface SingleAppMetadata {
name: string;
link: string;
requireRef: string;
integrity?: string;
custom?: any;
config?: Record<string, any>;
}
export interface MetaDataBase {
key: string;
export interface MultiAppsMetadata {
name: string;
shortName: string;
path: string;
fileUri: string;
version: string;
link: string;
bundle: string;
integrity?: string;
private?: boolean;
custom?: any;
}
export type App = SingleApp | MultiApp;
/**
* Echo Module setup function and meta data combined.
* Describes the metadata transported by a Apps.
*/
export type EchoModule = ModuleData & ModuleMetaData;
export type AppMetadata = SingleAppMetadata | MultiAppsMetadata;
/**
* The metadata for a single app.
*/
export type SingleApp = AppData & AppMetadata;
/**
* The metadata for apps containing apps.
*/
export type MultiApp = MultiAppData & MultiAppsMetadata;
/**
* Defines the API accessible from Apps.
*/
export interface EchoModuleApi {
export interface AppApi extends ModuleEventEmitter {
/**
* Gets the metadata of the current App.
*/
meta: ModuleMetaData;
eventHub: EchoEventHub;
meta: AppMetadata;
}
export interface ModuleData {
setup: (api: EchoModuleApi) => void | Promise<void>;
export interface RouteRegistration extends BaseRegistration {
meta: AppMetaData;
}
export type AppMetaFetch = () => Promise<ModuleMetaData[]>;
export interface AppMetaData {
name: string;
icon: string;
homeScreen?: boolean;
}
export interface BaseRegistration {
key: string;
}
export interface AppData {
setup: (api: AppApi) => void | Promise<void>;
}
export interface MultiAppData {
setup: (apiFactory: AppApiCreator) => void | Promise<void>;
}
export interface EchoPortal {
isAuthenticated: boolean;
}
export type AppMetaFetch = () => Promise<AppMetadata[]>;
/**
* The creator function for the App API.
*/
export interface AppApiCreator {
(target: AppMetadata): AppApi;
}
/**
* The record containing all available dependencies.

@@ -41,0 +85,0 @@ */

@@ -1,10 +0,10 @@

import { EchoModule, ModuleMetaData } from '../types/module';
import { AppData, AppMetadata } from "../types/module";
export function createEmptyModule(meta: ModuleMetaData): EchoModule {
export function createEmptyModule(meta: AppMetadata): AppData {
return {
...meta,
setup(): void {
// Empty Setup
}
...meta,
setup(): void {
// Empty Setup
},
};
}
}

@@ -1,2 +0,2 @@

import { EchoEventHub, EchoEvents, UnsubscribeFunction } from '../types/event';
import { EchoEventHub, EchoEvents } from '../types/event';

@@ -31,3 +31,3 @@ /**

*/
subscribe<T>(key: string | EchoEvents, handler: (payload: T) => void): UnsubscribeFunction {
subscribe<T>(key: string | EchoEvents, handler: (payload: T) => void): () => void {
const eventHandler = (e: Event): void => {

@@ -51,3 +51,3 @@ const customEvent = e as CustomEvent;

*/
subscribeMany<T>(keys: Array<string | EchoEvents>, handler: (payload: T) => void): UnsubscribeFunction {
subscribeMany<T>(keys: Array<string | EchoEvents>, handler: (payload: T) => void): () => void {
const unsubscribeFunctions: Array<() => void> = keys.map((key) => this.subscribe(key, handler));

@@ -54,0 +54,0 @@ return (): void => {

@@ -1,4 +0,2 @@

export * from './emptyApp';
export * from './eventHub';
export * from './getDependencyResolver';
export * from './storage';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc