infrastructure-components
Version:
Infrastructure-Components configure the infrastructure of your React-App as part of your React-Components.
57 lines • 2.49 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = __importDefault(require("../types"));
const securedroute_component_1 = require("../authentication/securedroute-component");
const middleware_component_1 = require("../middleware/middleware-component");
const route_component_1 = require("../route/route-component");
const libs_1 = require("../libs");
exports.WEBAPP_INSTANCE_TYPE = "WebAppComponent";
/**
* identifies a component as a WebApp: it implements all the required fields
*
* @param component to be tested
*/
function isWebApp(component) {
return component !== undefined && component.instanceType === exports.WEBAPP_INSTANCE_TYPE;
}
exports.isWebApp = isWebApp;
/**
* The WebApp is a client that runs in the browser, SPA or SSR
*
* @param props
*/
exports.default = (props) => {
//console.log ("webapp: ", props);
// the WebAppComponent must have all the properties of IClient
const clientProps = {
infrastructureType: types_1.default.INFRASTRUCTURE_TYPE_CLIENT,
instanceType: exports.WEBAPP_INSTANCE_TYPE,
instanceId: props.id,
insulatesChildComponent: (child) => {
// a webapp insulates (handles itself) middlewares and routes and does not privide to higher levels
return middleware_component_1.isMiddleware(child) || route_component_1.isRoute(child);
/* && !isSecuredRoute(child) -- the WebApp does not hide secured-routes,
* we must allow the authentication component to find, process, and change (add middlewares) them to a normal route
*/
}
};
const webappProps = {
middlewares: libs_1.getChildrenArray(props.children)
.filter(child => middleware_component_1.isMiddleware(child)),
routes: libs_1.getChildrenArray(props.children)
.filter(child => route_component_1.isRoute(child) || securedroute_component_1.isSecuredRoute(child)),
// TODO add redirects!!!!
redirects: [],
setDataLayerId: (dataLayerId) => {
props.dataLayerId = dataLayerId;
},
setAuthenticationId: (authenticationId) => {
props.authenticationId = authenticationId;
}
};
return Object.assign(props, clientProps, webappProps);
};
//# sourceMappingURL=webapp-component.js.map