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

@equinor/echo-base

Package Overview
Dependencies
Maintainers
3
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.100 to 0.2.104

3

esm/errors/BaseError.d.ts

@@ -6,2 +6,5 @@ import { BaseErrorArgs, ErrorProperties } from '../types/error';

* @param exception a generated exception provided as a {Record<string, unknown>} type
* Add custom properties in exception as desired
* like: .exception = { aCustomProperty: 'test custom property' };
* access with: .getProperties()['aCustomProperty']
* @export

@@ -8,0 +11,0 @@ * @class BaseError

@@ -6,2 +6,5 @@ import { __assign, __extends } from "tslib";

* @param exception a generated exception provided as a {Record<string, unknown>} type
* Add custom properties in exception as desired
* like: .exception = { aCustomProperty: 'test custom property' };
* access with: .getProperties()['aCustomProperty']
* @export

@@ -8,0 +11,0 @@ * @class BaseError

import { ErrorInitializerFunction } from '../types/error';
import { NetworkError, NetworkErrorArgs } from './NetworkError';
/**
* Tries to initialize an error to specific type.
* Returns:
* @type {ValidationError} if 400 and with property exception.title which includes value 'validation'
* @type {UnauthorizedError} if 401
* @type {ForbiddenError} if 403
* @type {NotFoundError} if 404
* @type {BackendError} if it includes property exception (since echopedia api returns an error with this format)
* @type {BadRequestError} if 400
* Fall backs to ErrorType with @type {NetworkError} as base, if none of the above constraints are fulfilled
* @param ErrorType Default error type to return if no match
* @param args Arguments to initialize error with. Add custom properties in args.exception as desired,
* like: .exception = { aCustomProperty: 'test custom property' };
* access with: .getProperties()['aCustomProperty']
* @returns Specific error type with base as type
*/
export declare const initializeError: ErrorInitializerFunction<NetworkError, NetworkErrorArgs>;

60

esm/errors/errorHandlers.js

@@ -1,30 +0,38 @@

import { BackendError, ForbiddenError, NotFoundError, ValidationError } from './NetworkError';
import { BackendError, BadRequestError, ForbiddenError, NotFoundError, UnauthorizedError, ValidationError } from './NetworkError';
/**
* Tries to initialize an error to specific type.
* Returns:
* @type {ValidationError} if 400 and with property exception.title which includes value 'validation'
* @type {UnauthorizedError} if 401
* @type {ForbiddenError} if 403
* @type {NotFoundError} if 404
* @type {BackendError} if it includes property exception (since echopedia api returns an error with this format)
* @type {BadRequestError} if 400
* Fall backs to ErrorType with @type {NetworkError} as base, if none of the above constraints are fulfilled
* @param ErrorType Default error type to return if no match
* @param args Arguments to initialize error with. Add custom properties in args.exception as desired,
* like: .exception = { aCustomProperty: 'test custom property' };
* access with: .getProperties()['aCustomProperty']
* @returns Specific error type with base as type
*/
export var initializeError = function (ErrorType, args) {
var _a;
var errorInstance;
if ((_a = args.exception) === null || _a === void 0 ? void 0 : _a.errors) {
var exception = args.exception, httpStatusCode = args.httpStatusCode;
switch (httpStatusCode) {
case 400:
errorInstance =
exception.title && exception.title.toLowerCase().includes('validation')
? new ValidationError(args)
: new BackendError(args);
break;
case 403:
errorInstance = new ForbiddenError(args);
break;
case 404:
errorInstance = new NotFoundError(args);
break;
default:
errorInstance = new BackendError(args);
break;
}
var _a, _b;
switch (args.httpStatusCode) {
case 400:
if (((_a = args.exception) === null || _a === void 0 ? void 0 : _a.title) && ((_b = args.exception) === null || _b === void 0 ? void 0 : _b.title).toLowerCase().includes('validation'))
return new ValidationError(args);
break;
case 401:
return new UnauthorizedError(args);
case 403:
return new ForbiddenError(args);
case 404:
return new NotFoundError(args);
}
else {
errorInstance = new ErrorType(args);
}
return errorInstance;
if (args.httpStatusCode > 0 && args.httpStatusCode < 550 && args.exception)
return new BackendError(args); //our backEnd return a json property called exception.
if (args.httpStatusCode == 400)
return new BadRequestError(args);
return new ErrorType(args);
};
//# sourceMappingURL=errorHandlers.js.map
import { CommonErrorArgs } from '../types/error';
import { BaseError } from './BaseError';
export interface NetworkErrorArgs extends CommonErrorArgs {
exception: Record<string, unknown>;
exception?: Record<string, unknown>;
httpStatusCode: number;

@@ -23,2 +23,4 @@ url: string;

}
export declare class BadRequestError extends NetworkError {
}
export declare class BackendError extends NetworkError {

@@ -28,2 +30,4 @@ }

}
export declare class UnauthorizedError extends ForbiddenError {
}
export declare class NotFoundError extends NetworkError {

@@ -30,0 +34,0 @@ }

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

export { NetworkError };
var BadRequestError = /** @class */ (function (_super) {
__extends(BadRequestError, _super);
function BadRequestError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return BadRequestError;
}(NetworkError));
export { BadRequestError };
var BackendError = /** @class */ (function (_super) {

@@ -45,2 +53,10 @@ __extends(BackendError, _super);

export { ForbiddenError };
var UnauthorizedError = /** @class */ (function (_super) {
__extends(UnauthorizedError, _super);
function UnauthorizedError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return UnauthorizedError;
}(ForbiddenError));
export { UnauthorizedError };
var NotFoundError = /** @class */ (function (_super) {

@@ -47,0 +63,0 @@ __extends(NotFoundError, _super);

@@ -6,1 +6,2 @@ export * from './errors';

export * from './utils';
export { default as eventHub } from './utils/eventHub';

@@ -6,2 +6,3 @@ export * from './errors';

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,5 +8,5 @@ import { __awaiter, __generator } from "tslib";

*/
export function defaultFetchDependency(url, token) {
export function fetchDependency(url, token) {
return __awaiter(this, void 0, void 0, function () {
var module;
var m;
return __generator(this, function (_a) {

@@ -20,4 +20,4 @@ switch (_a.label) {

case 1:
module = _a.sent();
return [4 /*yield*/, module.text()];
m = _a.sent();
return [4 /*yield*/, m.text()];
case 2: return [2 /*return*/, _a.sent()];

@@ -24,0 +24,0 @@ }

@@ -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 dependencies.
*
* @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 an empty module, 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 dependencies.
*
* @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 an empty module, 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.info('No modules awaitable.');
return [];
persistLocalModuleMeta('EchoModules', modules);
return modules;
}
//# sourceMappingURL=verify.js.map

@@ -8,6 +8,5 @@ /**

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 {

@@ -17,2 +16,25 @@ 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 {

@@ -19,0 +41,0 @@ [custom: string]: unknown;

@@ -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';
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';
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 {};
export default eventHub;

@@ -60,2 +60,3 @@ /**

export var eventHub = new EventHub();
export default eventHub;
//# sourceMappingURL=eventHub.js.map

@@ -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

@@ -6,2 +6,5 @@ import { BaseErrorArgs, ErrorProperties } from '../types/error';

* @param exception a generated exception provided as a {Record<string, unknown>} type
* Add custom properties in exception as desired
* like: .exception = { aCustomProperty: 'test custom property' };
* access with: .getProperties()['aCustomProperty']
* @export

@@ -8,0 +11,0 @@ * @class BaseError

@@ -9,2 +9,5 @@ "use strict";

* @param exception a generated exception provided as a {Record<string, unknown>} type
* Add custom properties in exception as desired
* like: .exception = { aCustomProperty: 'test custom property' };
* access with: .getProperties()['aCustomProperty']
* @export

@@ -11,0 +14,0 @@ * @class BaseError

import { ErrorInitializerFunction } from '../types/error';
import { NetworkError, NetworkErrorArgs } from './NetworkError';
/**
* Tries to initialize an error to specific type.
* Returns:
* @type {ValidationError} if 400 and with property exception.title which includes value 'validation'
* @type {UnauthorizedError} if 401
* @type {ForbiddenError} if 403
* @type {NotFoundError} if 404
* @type {BackendError} if it includes property exception (since echopedia api returns an error with this format)
* @type {BadRequestError} if 400
* Fall backs to ErrorType with @type {NetworkError} as base, if none of the above constraints are fulfilled
* @param ErrorType Default error type to return if no match
* @param args Arguments to initialize error with. Add custom properties in args.exception as desired,
* like: .exception = { aCustomProperty: 'test custom property' };
* access with: .getProperties()['aCustomProperty']
* @returns Specific error type with base as type
*/
export declare const initializeError: ErrorInitializerFunction<NetworkError, NetworkErrorArgs>;

@@ -5,31 +5,39 @@ "use strict";

var NetworkError_1 = require("./NetworkError");
/**
* Tries to initialize an error to specific type.
* Returns:
* @type {ValidationError} if 400 and with property exception.title which includes value 'validation'
* @type {UnauthorizedError} if 401
* @type {ForbiddenError} if 403
* @type {NotFoundError} if 404
* @type {BackendError} if it includes property exception (since echopedia api returns an error with this format)
* @type {BadRequestError} if 400
* Fall backs to ErrorType with @type {NetworkError} as base, if none of the above constraints are fulfilled
* @param ErrorType Default error type to return if no match
* @param args Arguments to initialize error with. Add custom properties in args.exception as desired,
* like: .exception = { aCustomProperty: 'test custom property' };
* access with: .getProperties()['aCustomProperty']
* @returns Specific error type with base as type
*/
var initializeError = function (ErrorType, args) {
var _a;
var errorInstance;
if ((_a = args.exception) === null || _a === void 0 ? void 0 : _a.errors) {
var exception = args.exception, httpStatusCode = args.httpStatusCode;
switch (httpStatusCode) {
case 400:
errorInstance =
exception.title && exception.title.toLowerCase().includes('validation')
? new NetworkError_1.ValidationError(args)
: new NetworkError_1.BackendError(args);
break;
case 403:
errorInstance = new NetworkError_1.ForbiddenError(args);
break;
case 404:
errorInstance = new NetworkError_1.NotFoundError(args);
break;
default:
errorInstance = new NetworkError_1.BackendError(args);
break;
}
var _a, _b;
switch (args.httpStatusCode) {
case 400:
if (((_a = args.exception) === null || _a === void 0 ? void 0 : _a.title) && ((_b = args.exception) === null || _b === void 0 ? void 0 : _b.title).toLowerCase().includes('validation'))
return new NetworkError_1.ValidationError(args);
break;
case 401:
return new NetworkError_1.UnauthorizedError(args);
case 403:
return new NetworkError_1.ForbiddenError(args);
case 404:
return new NetworkError_1.NotFoundError(args);
}
else {
errorInstance = new ErrorType(args);
}
return errorInstance;
if (args.httpStatusCode > 0 && args.httpStatusCode < 550 && args.exception)
return new NetworkError_1.BackendError(args); //our backEnd return a json property called exception.
if (args.httpStatusCode == 400)
return new NetworkError_1.BadRequestError(args);
return new ErrorType(args);
};
exports.initializeError = initializeError;
//# sourceMappingURL=errorHandlers.js.map
import { CommonErrorArgs } from '../types/error';
import { BaseError } from './BaseError';
export interface NetworkErrorArgs extends CommonErrorArgs {
exception: Record<string, unknown>;
exception?: Record<string, unknown>;
httpStatusCode: number;

@@ -23,2 +23,4 @@ url: string;

}
export declare class BadRequestError extends NetworkError {
}
export declare class BackendError extends NetworkError {

@@ -28,2 +30,4 @@ }

}
export declare class UnauthorizedError extends ForbiddenError {
}
export declare class NotFoundError extends NetworkError {

@@ -30,0 +34,0 @@ }

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

@@ -31,2 +31,10 @@ var BaseError_1 = require("./BaseError");

exports.NetworkError = NetworkError;
var BadRequestError = /** @class */ (function (_super) {
tslib_1.__extends(BadRequestError, _super);
function BadRequestError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return BadRequestError;
}(NetworkError));
exports.BadRequestError = BadRequestError;
var BackendError = /** @class */ (function (_super) {

@@ -48,2 +56,10 @@ tslib_1.__extends(BackendError, _super);

exports.ForbiddenError = ForbiddenError;
var UnauthorizedError = /** @class */ (function (_super) {
tslib_1.__extends(UnauthorizedError, _super);
function UnauthorizedError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return UnauthorizedError;
}(ForbiddenError));
exports.UnauthorizedError = UnauthorizedError;
var NotFoundError = /** @class */ (function (_super) {

@@ -50,0 +66,0 @@ tslib_1.__extends(NotFoundError, _super);

@@ -6,1 +6,2 @@ export * from './errors';

export * from './utils';
export { default as eventHub } from './utils/eventHub';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EchoEvents = void 0;
exports.eventHub = exports.EchoEvents = void 0;
var tslib_1 = require("tslib");

@@ -11,2 +11,4 @@ tslib_1.__exportStar(require("./errors"), 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,5 +11,5 @@ /**

*/
function defaultFetchDependency(url, token) {
function fetchDependency(url, token) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var module;
var m;
return tslib_1.__generator(this, function (_a) {

@@ -23,4 +23,4 @@ switch (_a.label) {

case 1:
module = _a.sent();
return [4 /*yield*/, module.text()];
m = _a.sent();
return [4 /*yield*/, m.text()];
case 2: return [2 /*return*/, _a.sent()];

@@ -31,3 +31,3 @@ }

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

@@ -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 dependencies.
*
* @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 an empty module, 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 dependencies.
*
* @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 an empty module, 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.info('No modules awaitable.');
return [];
persist_1.persistLocalModuleMeta('EchoModules', modules);
return modules;
}
exports.verifyModulesMeta = verifyModulesMeta;
//# sourceMappingURL=verify.js.map

@@ -8,6 +8,5 @@ /**

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 {

@@ -17,2 +16,25 @@ 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 {

@@ -19,0 +41,0 @@ [custom: string]: unknown;

@@ -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';
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 errors_1 = require("../errors");
var ModuleAppError = /** @class */ (function (_super) {
tslib_1.__extends(ModuleAppError, _super);
function ModuleAppError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return ModuleAppError;
}(errors_1.BaseError));
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 {};
export default eventHub;

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

exports.eventHub = new EventHub();
exports.default = exports.eventHub;
//# sourceMappingURL=eventHub.js.map

@@ -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.100",
"version": "0.2.104",
"module": "esm/index.js",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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