New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bloomreach/spa-sdk

Package Overview
Dependencies
Maintainers
29
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bloomreach/spa-sdk - npm Package Compare versions

Comparing version 14.1.1 to 14.2.0

dist/cms/cms.d.ts

14

dist/emitter.d.ts

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

import { Events, Typed } from 'emittery';
import emittery, { Events } from 'emittery';
declare type Constructor = new (...args: any[]) => any;

@@ -36,10 +36,10 @@ /**

*/
emitter: Typed<U, never>;
emitter: emittery.Typed<U, never>;
on: {
<Name extends Extract<keyof U, string>>(eventName: Name, listener: (eventData: U[Name]) => any): import("emittery").UnsubscribeFn;
<Name_1 extends never>(eventName: Name_1, listener: () => any): import("emittery").UnsubscribeFn;
<Name extends Extract<keyof U, string | symbol>>(eventName: Name, listener: (eventData: U[Name]) => void): emittery.UnsubscribeFn;
<Name_1 extends never>(eventName: Name_1, listener: () => void): emittery.UnsubscribeFn;
};
off: {
<Name_2 extends Extract<keyof U, string>>(eventName: Name_2, listener: (eventData: U[Name_2]) => any): void;
<Name_3 extends never>(eventName: Name_3, listener: () => any): void;
<Name_2 extends Extract<keyof U, string | symbol>>(eventName: Name_2, listener: (eventData: U[Name_2]) => void): void;
<Name_3 extends never>(eventName: Name_3, listener: () => void): void;
};

@@ -51,3 +51,3 @@ /**

emit: {
<Name_4 extends Extract<keyof U, string>>(eventName: Name_4, eventData: U[Name_4]): Promise<void>;
<Name_4 extends Extract<keyof U, string | symbol>>(eventName: Name_4, eventData: U[Name_4]): Promise<void>;
<Name_5 extends never>(eventName: Name_5): Promise<void>;

@@ -54,0 +54,0 @@ };

import { PageModel, Page } from './page';
import { Configuration } from './spa';
import { Configuration } from './configuration';
/**

@@ -7,2 +7,3 @@ * Initializes the page model.

* @param config Configuration of the SPA integration with brXM.
* @param model Preloaded page model.
*/

@@ -15,3 +16,3 @@ export declare function initialize(config: Configuration, model?: PageModel): Promise<Page>;

export declare function destroy(page: Page): void;
export { Configuration } from './spa';
export { Component, ContainerItem, Container, Content, Link, Menu, MetaComment, Meta, PageModel, Page, Reference, isComponent, isContainerItem, isContainer, isLink, isMetaComment, isMeta, isPage, isReference, META_POSITION_BEGIN, META_POSITION_END, TYPE_CONTAINER_BOX, TYPE_CONTAINER_INLINE, TYPE_CONTAINER_NO_MARKUP, TYPE_CONTAINER_ORDERED_LIST, TYPE_CONTAINER_UNORDERED_LIST, TYPE_LINK_EXTERNAL, TYPE_LINK_INTERNAL, TYPE_LINK_RESOURCE, } from './page';
export { Configuration } from './configuration';
export { Component, ContainerItem, Container, Content, Link, Menu, MetaCollection, MetaComment, Meta, PageModel, Page, Reference, isComponent, isContainerItem, isContainer, isLink, isMetaComment, isMeta, isPage, isReference, META_POSITION_BEGIN, META_POSITION_END, TYPE_CONTAINER_BOX, TYPE_CONTAINER_INLINE, TYPE_CONTAINER_NO_MARKUP, TYPE_CONTAINER_ORDERED_LIST, TYPE_CONTAINER_UNORDERED_LIST, TYPE_LINK_EXTERNAL, TYPE_LINK_INTERNAL, TYPE_LINK_RESOURCE, } from './page';

@@ -6,2 +6,18 @@ (function(global, factory) {

"use strict";
xmldom = xmldom && Object.prototype.hasOwnProperty.call(xmldom, "default") ? xmldom["default"] : xmldom;
emittery = emittery && Object.prototype.hasOwnProperty.call(emittery, "default") ? emittery["default"] : emittery;
function _extends() {
_extends = Object.assign || function(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function __rest(s, e) {

@@ -16,2 +32,7 @@ var t = {};

function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P((function(resolve) {
resolve(value);
}));
}
return new (P || (P = Promise))((function(resolve, reject) {

@@ -33,5 +54,3 @@ function fulfilled(value) {

function step(result) {
result.done ? resolve(result.value) : new P((function(resolve) {
resolve(result.value);
})).then(fulfilled, rejected);
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}

@@ -41,4 +60,157 @@ step((generator = generator.apply(thisArg, _arguments || [])).next());

}
const DEFAULT_AUTHORIZATION_HEADER = "Authorization";
const DEFAULT_SERVER_ID_HEADER = "Server-Id";
class ApiImpl {
constructor(urlBuilder) {
this.urlBuilder = urlBuilder;
}
initialize(options) {
this.options = options;
}
getPage(path) {
const url = this.urlBuilder.getApiUrl(path);
return this.send({
url,
method: "GET"
});
}
getComponent(path, payload) {
const url = this.urlBuilder.getApiUrl(path);
const data = new URLSearchParams(payload);
return this.send({
url,
data: data.toString(),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST"
});
}
send(config) {
return __awaiter(this, void 0, void 0, (function*() {
const {remoteAddress: ip} = this.options.request.connection || {};
const _a = this.options.request.headers || {}, headers = __rest(_a, [ "host" ]);
const {authorizationHeader = DEFAULT_AUTHORIZATION_HEADER, authorizationToken, serverIdHeader = DEFAULT_SERVER_ID_HEADER, serverId, visitor} = this.options;
const response = yield this.options.httpClient(_extends(_extends({}, config), {
headers: _extends(_extends(_extends(_extends(_extends(_extends({}, ip && {
"x-forwarded-for": ip
}), authorizationToken && {
[authorizationHeader]: `Bearer ${authorizationToken}`
}), serverId && {
[serverIdHeader]: serverId
}), visitor && {
[visitor.header]: visitor.id
}), headers), config.headers)
}));
return response.data;
}));
}
}
/**
* SPA entry point interacting with the Channel Manager and the Page Model API.
*/ class Spa {
/**
* @param eventBus Event bus to exchange data between submodules.
* @param pageFactory Factory to produce page instances.
* @param urlBuilder API URL builder.
*/
constructor(eventBus, api, pageFactory) {
this.eventBus = eventBus;
this.api = api;
this.pageFactory = pageFactory;
this.onCmsUpdate = this.onCmsUpdate.bind(this);
}
onCmsUpdate(event) {
return __awaiter(this, void 0, void 0, (function*() {
const root = this.page.getComponent();
const component = root.getComponentById(event.id);
const url = component === null || component === void 0 ? void 0 : component.getUrl();
if (!url) {
return;
}
const model = yield this.api.getComponent(url, event.properties);
this.eventBus.emit("page.update", {
page: model
});
}));
}
/**
* Initializes the SPA.
* @param path Page path.
* @param model Preloaded page model.
*/ initialize(path, model) {
return __awaiter(this, void 0, void 0, (function*() {
this.page = this.pageFactory.create(model || (yield this.api.getPage(path)));
if (this.page.isPreview()) {
this.eventBus.on("cms.update", this.onCmsUpdate);
}
return this.page;
}));
}
/**
* Destroys the integration with the SPA page.
*/ destroy() {
this.eventBus.off("cms.update", this.onCmsUpdate);
delete this.page;
}
}
const GLOBAL_WINDOW = typeof window === "undefined" ? undefined : window;
class Cms {
class CmsImpl {
constructor(eventBus, rpcClient, rpcServer) {
this.eventBus = eventBus;
this.rpcClient = rpcClient;
this.rpcServer = rpcServer;
this.onPageReady = this.onPageReady.bind(this);
this.onUpdate = this.onUpdate.bind(this);
this.inject = this.inject.bind(this);
}
initialize({window = GLOBAL_WINDOW}) {
if (this.window === window) {
return;
}
this.window = window;
this.notifyOnReady();
this.eventBus.on("page.ready", this.onPageReady);
this.rpcClient.on("update", this.onUpdate);
this.rpcServer.register("inject", this.inject);
}
notifyOnReady() {
var _a, _b, _c, _d;
const notify = () => this.rpcServer.trigger("ready", undefined);
const onStateChange = () => {
if (this.window.document.readyState === "loading") {
return;
}
notify();
this.window.document.removeEventListener("readystatechange", onStateChange);
};
if (((_b = (_a = this.window) === null || _a === void 0 ? void 0 : _a.document) === null || _b === void 0 ? void 0 : _b.readyState) !== "loading") {
return notify();
}
(_d = (_c = this.window) === null || _c === void 0 ? void 0 : _c.document) === null || _d === void 0 ? void 0 : _d.addEventListener("readystatechange", onStateChange);
}
onPageReady() {
this.rpcClient.call("sync");
}
onUpdate(event) {
this.eventBus.emit("cms.update", event);
}
inject(resource) {
var _a;
if (!((_a = this.window) === null || _a === void 0 ? void 0 : _a.document)) {
return Promise.reject(new Error("SPA document is not ready."));
}
return new Promise((resolve, reject) => {
const script = this.window.document.createElement("script");
script.type = "text/javascript";
script.src = resource;
script.crossOrigin = "use-credentials";
script.addEventListener("load", () => resolve());
script.addEventListener("error", () => reject(new Error(`Failed to load resource '${resource}'.`)));
this.window.document.body.appendChild(script);
});
}
}
const GLOBAL_WINDOW$1 = typeof window === "undefined" ? undefined : window;
class Cms14Impl {
constructor(eventBus) {

@@ -61,3 +233,3 @@ this.eventBus = eventBus;

}
initialize(window = GLOBAL_WINDOW) {
initialize({window = GLOBAL_WINDOW$1}) {
if (this.api || !window || window.SPA) {

@@ -86,2 +258,266 @@ return;

}
function appendSearchParams(url, params) {
const {hash, origin, pathname, searchParams} = parseUrl(url);
return buildUrl({
hash,
origin,
pathname,
searchParams: mergeSearchParams(searchParams, params)
});
}
function buildUrl(url) {
var _a, _b, _c, _d, _e, _f, _g;
const searchParams = (_b = (_a = url.searchParams) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "";
const search = (_c = url.search) !== null && _c !== void 0 ? _c : `${searchParams && `?${searchParams}`}`;
const path = (_d = url.path) !== null && _d !== void 0 ? _d : `${(_e = url.pathname) !== null && _e !== void 0 ? _e : ""}${search}${(_f = url.hash) !== null && _f !== void 0 ? _f : ""}`;
return `${(_g = url.origin) !== null && _g !== void 0 ? _g : ""}${path}`;
}
function extractSearchParams(url, params) {
const {hash, origin, pathname, searchParams} = parseUrl(url);
const extracted = new URLSearchParams;
params.forEach(param => {
if (searchParams.has(param)) {
extracted.set(param, searchParams.get(param));
searchParams.delete(param);
}
});
return {
searchParams: extracted,
url: buildUrl({
hash,
origin,
pathname,
searchParams
})
};
}
function isMatchedOrigin(origin, baseOrigin) {
const [schema, host = ""] = origin.split("//", 2);
const [baseSchema, baseHost = ""] = baseOrigin.split("//", 2);
return !baseOrigin || !origin || (!schema || !baseSchema || schema === baseSchema) && baseHost === host;
}
function isMatchedPathname(pathname, basePathname) {
return !basePathname || pathname.startsWith(basePathname);
}
function isMatchedQuery(search, baseSearch) {
let match = true;
baseSearch.forEach((value, key) => {
match = match && (!value && search.has(key) || search.getAll(key).includes(value));
});
return match;
}
function isMatched(link, base = "") {
const linkUrl = parseUrl(link);
const baseUrl = parseUrl(base);
return isMatchedOrigin(linkUrl.origin, baseUrl.origin) && isMatchedPathname(linkUrl.pathname, baseUrl.pathname) && isMatchedQuery(linkUrl.searchParams, baseUrl.searchParams);
}
function mergeSearchParams(params, ...rest) {
const result = new URLSearchParams(params);
rest.forEach(params => params.forEach((value, key) => result.set(key, value)));
return result;
}
function parseUrl(url) {
const parsedUrl = url ? new URL(url, "http://example.com") : {};
const {hash = "", search = "", searchParams = new URLSearchParams} = parsedUrl;
let origin = url.substring(0, url.length - search.length - hash.length);
let {pathname = ""} = parsedUrl;
if (!origin.endsWith(pathname)) {
pathname = pathname.substring(1);
}
origin = origin.substring(0, origin.length - pathname.length);
return {
hash,
origin,
pathname,
search,
searchParams,
path: `${pathname}${search}${hash}`
};
}
const DEFAULT_API_BASE_URL = "/resourceapi";
const DEFAULT_SPA_BASE_URL = "";
class UrlBuilderImpl {
constructor(options = {
cmsBaseUrl: ""
}) {
this.options = options;
this.initialize(options);
}
initialize(options) {
this.options = options;
this.apiBaseUrl = parseUrl(options.apiBaseUrl || `${options.cmsBaseUrl}${DEFAULT_API_BASE_URL}`);
this.cmsBaseUrl = parseUrl(options.cmsBaseUrl);
this.spaBaseUrl = parseUrl(options.spaBaseUrl || DEFAULT_SPA_BASE_URL);
}
getApiUrl(link) {
const {pathname, searchParams} = parseUrl(link);
if (this.apiBaseUrl.pathname && pathname.startsWith(this.apiBaseUrl.pathname)) {
return buildUrl({
pathname,
origin: this.apiBaseUrl.origin,
searchParams: mergeSearchParams(this.apiBaseUrl.searchParams, searchParams)
});
}
if (this.spaBaseUrl.pathname && !pathname.startsWith(this.spaBaseUrl.pathname)) {
throw new Error(`The path "${pathname}" does not start with the base path "${this.spaBaseUrl.pathname}".`);
}
const route = pathname.substring(this.spaBaseUrl.pathname.length);
return buildUrl({
origin: this.apiBaseUrl.origin,
pathname: `${this.apiBaseUrl.pathname}${route}`,
searchParams: mergeSearchParams(searchParams, this.apiBaseUrl.searchParams)
});
}
getSpaUrl(link) {
const {hash, pathname, searchParams} = parseUrl(link);
let route = pathname.startsWith(this.cmsBaseUrl.pathname) ? pathname.substring(this.cmsBaseUrl.pathname.length) : pathname;
if (!route.startsWith("/") && !this.spaBaseUrl.pathname) {
route = `/${route}`;
}
return buildUrl({
origin: this.spaBaseUrl.origin,
pathname: `${this.spaBaseUrl.pathname}${route}`,
searchParams: mergeSearchParams(searchParams, this.spaBaseUrl.searchParams),
hash: hash || this.spaBaseUrl.hash
});
}
}
function EmitterMixin(Super) {
return class EmitterMixin extends Super {
constructor() {
super(...arguments);
/**
* @todo should be private
* @see https://github.com/Microsoft/TypeScript/issues/17293
*/ this.emitter = new emittery.Typed;
this.on = this.emitter.on.bind(this.emitter);
this.off = this.emitter.off.bind(this.emitter);
/**
* @todo should be private
* @see https://github.com/Microsoft/TypeScript/issues/17293
*/ this.emit = this.emitter.emit.bind(this.emitter);
}
};
}
const TYPE_EVENT = "brxm:event";
const TYPE_RESPONSE = "brxm:response";
const TYPE_REQUEST = "brxm:request";
const STATE_FULFILLED = "fulfilled";
const STATE_REJECTED = "rejected";
class Dummy {}
class Rpc extends(EmitterMixin(Dummy)){
constructor() {
super(...arguments);
this.calls = new Map;
this.callbacks = new Map;
}
generateId() {
let id;
do {
id = `${Math.random()}`.slice(2);
} while (this.calls.has(id));
return id;
}
call(command, ...payload) {
return new Promise((resolve, reject) => {
const id = this.generateId();
this.calls.set(id, [ resolve, reject ]);
this.send({
id,
command,
payload,
type: TYPE_REQUEST
});
});
}
register(command, callback) {
this.callbacks.set(command, callback);
}
trigger(event, payload) {
this.send({
event,
payload,
type: TYPE_EVENT
});
}
process(message) {
switch (message === null || message === void 0 ? void 0 : message.type) {
case TYPE_EVENT:
this.processEvent(message);
break;
case TYPE_RESPONSE:
this.processResponse(message);
break;
case TYPE_REQUEST:
this.processRequest(message);
break;
}
}
processEvent(event) {
this.emit(event.event, event.payload);
}
processResponse(response) {
if (!this.calls.has(response.id)) {
return;
}
const [resolve, reject] = this.calls.get(response.id);
this.calls.delete(response.id);
if (response.state === STATE_REJECTED) {
return void reject(response.result);
}
resolve(response.result);
}
processRequest(request) {
return __awaiter(this, void 0, void 0, (function*() {
const callback = this.callbacks.get(request.command);
if (!callback) {
return;
}
try {
return this.send({
type: TYPE_RESPONSE,
id: request.id,
state: STATE_FULFILLED,
result: yield callback(...request.payload)
});
} catch (result) {
return this.send({
result,
type: TYPE_RESPONSE,
id: request.id,
state: STATE_REJECTED
});
}
}));
}
}
const GLOBAL_WINDOW$2 = typeof window === "undefined" ? undefined : window;
class PostMessage extends Rpc {
constructor() {
super();
this.onMessage = this.onMessage.bind(this);
}
get window() {
var _a;
return ((_a = this.options) === null || _a === void 0 ? void 0 : _a.window) || GLOBAL_WINDOW$2;
}
initialize(options) {
var _a, _b;
(_a = this.window) === null || _a === void 0 ? void 0 : _a.removeEventListener("message", this.onMessage, false);
this.options = options;
(_b = this.window) === null || _b === void 0 ? void 0 : _b.addEventListener("message", this.onMessage, false);
}
send(message) {
var _a, _b;
(_b = (_a = this.window) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.postMessage(message, this.options.origin);
}
onMessage(event) {
if (!event.data || !this.options || !isMatched(event.origin, this.options.origin)) {
return;
}
this.process(event.data);
}
}
class SingleTypeFactory {

@@ -100,6 +536,6 @@ constructor(builder) {

/**
* Registers a builder for the specified type.
* @param type The entity type.
* @param builder The entity builder.
*/ register(type, builder) {
* Registers a builder for the specified type.
* @param type The entity type.
* @param builder The entity builder.
*/ register(type, builder) {
this.mapping.set(type, builder);

@@ -110,9 +546,10 @@ return this;

/**
* A component factory producing components based on a type.
*/ class ComponentFactory extends MultipleTypeFactory {
* A component factory producing components based on a type.
*/ class ComponentFactory extends MultipleTypeFactory {
/**
* Produces a component based on the model.
* @param model The component model.
*/
* Produces a component based on the model.
* @param model The component model.
*/
create(model) {
var _a, _b;
let component;

@@ -124,3 +561,3 @@ const queue = [ {

const head = queue.shift();
if (!head.children && head.model.components && head.model.components.length) {
if (!head.children && ((_a = head.model.components) === null || _a === void 0 ? void 0 : _a.length)) {
head.children = [];

@@ -133,3 +570,3 @@ queue.unshift(...head.model.components.map(model => ({

}
component = this.buildComponent(head.model, head.children || []);
component = this.buildComponent(head.model, (_b = head.children) !== null && _b !== void 0 ? _b : []);
if (head.siblings) {

@@ -150,10 +587,10 @@ head.siblings.push(component);

/**
* Generic component type.
*/ const TYPE_COMPONENT = "COMPONENT";
* Generic component type.
*/ const TYPE_COMPONENT = "COMPONENT";
/**
* Container item type.
*/ const TYPE_COMPONENT_CONTAINER_ITEM = "CONTAINER_ITEM_COMPONENT";
* Container item type.
*/ const TYPE_COMPONENT_CONTAINER_ITEM = "CONTAINER_ITEM_COMPONENT";
/**
* Container type.
*/ const TYPE_COMPONENT_CONTAINER = "CONTAINER_COMPONENT";
* Container type.
*/ const TYPE_COMPONENT_CONTAINER = "CONTAINER_COMPONENT";
class ComponentImpl {

@@ -164,3 +601,3 @@ constructor(model, children, linkFactory, metaFactory) {

this.linkFactory = linkFactory;
this.meta = metaFactory.create(model._meta || {});
this.meta = metaFactory.create(model._meta);
}

@@ -177,3 +614,3 @@ getId() {

getUrl() {
return this.model._links && this.linkFactory.create(this.model._links.componentRendering);
return this.linkFactory.create(this.model._links.componentRendering);
}

@@ -184,3 +621,3 @@ getName() {

getParameters() {
return this.model._meta && this.model._meta.params || {};
return this.model._meta.params || {};
}

@@ -210,24 +647,7 @@ getChildren() {

/**
* Checks whether a value is a page component.
* @param value The value to check.
*/ function isComponent(value) {
* Checks whether a value is a page component.
* @param value The value to check.
*/ function isComponent(value) {
return value instanceof ComponentImpl;
}
function EmitterMixin(Super) {
return class EmitterMixin extends Super {
constructor() {
super(...arguments);
/**
* @todo should be private
* @see https://github.com/Microsoft/TypeScript/issues/17293
*/ this.emitter = new emittery.Typed;
this.on = this.emitter.on.bind(this.emitter);
this.off = this.emitter.off.bind(this.emitter);
/**
* @todo should be private
* @see https://github.com/Microsoft/TypeScript/issues/17293
*/ this.emit = this.emitter.emit.bind(this.emitter);
}
};
}
const PARAMETER_HIDDEN = "com.onehippo.cms7.targeting.TargetingParameterUtil.hide";

@@ -247,3 +667,3 @@ class ContainerItemImpl extends(EmitterMixin(ComponentImpl)){

this.model = model;
this.meta = this.metaFactory.create(model._meta || {});
this.meta = this.metaFactory.create(model._meta);
this.emit("update", {});

@@ -255,29 +675,30 @@ }

isHidden() {
return !!(this.model._meta && this.model._meta.params && this.model._meta.params[PARAMETER_HIDDEN] === "on");
var _a;
return ((_a = this.model._meta.params) === null || _a === void 0 ? void 0 : _a[PARAMETER_HIDDEN]) === "on";
}
getParameters() {
return this.model._meta && this.model._meta.paramsInfo || {};
return this.model._meta.paramsInfo || {};
}
}
/**
* Checks whether a value is a page container item.
* @param value The value to check.
*/ function isContainerItem(value) {
* Checks whether a value is a page container item.
* @param value The value to check.
*/ function isContainerItem(value) {
return value instanceof ContainerItemImpl;
}
/**
* A blocked container with blocked items.
*/ const TYPE_CONTAINER_BOX = "hst.vbox";
* A blocked container with blocked items.
*/ const TYPE_CONTAINER_BOX = "hst.vbox";
/**
* An unordered list container.
*/ const TYPE_CONTAINER_UNORDERED_LIST = "hst.unorderedlist";
* An unordered list container.
*/ const TYPE_CONTAINER_UNORDERED_LIST = "hst.unorderedlist";
/**
* An ordered list container.
*/ const TYPE_CONTAINER_ORDERED_LIST = "hst.orderedlist";
* An ordered list container.
*/ const TYPE_CONTAINER_ORDERED_LIST = "hst.orderedlist";
/**
* A blocked container with inline items.
*/ const TYPE_CONTAINER_INLINE = "hst.span";
* A blocked container with inline items.
*/ const TYPE_CONTAINER_INLINE = "hst.span";
/**
* A container without surrounding markup.
*/ const TYPE_CONTAINER_NO_MARKUP = "hst.nomarkup";
* A container without surrounding markup.
*/ const TYPE_CONTAINER_NO_MARKUP = "hst.nomarkup";
class ContainerImpl extends ComponentImpl {

@@ -293,9 +714,10 @@ constructor(model, children, linkFactory, metaFactory) {

getType() {
return this.model.xtype && this.model.xtype.toLowerCase();
var _a;
return (_a = this.model.xtype) === null || _a === void 0 ? void 0 : _a.toLowerCase();
}
}
/**
* Checks whether a value is a page container.
* @param value The value to check.
*/ function isContainer(value) {
* Checks whether a value is a page container.
* @param value The value to check.
*/ function isContainer(value) {
return value instanceof ContainerImpl;

@@ -325,19 +747,19 @@ }

getUrl() {
return this.model._links && this.linkFactory.create(this.model._links.site);
return this.linkFactory.create(this.model._links.site);
}
}
/**
* Link to a page outside the current application.
*/ const TYPE_LINK_EXTERNAL = "external";
* Link to a page outside the current application.
*/ const TYPE_LINK_EXTERNAL = "external";
/**
* Link to a page inside the current application.
*/ const TYPE_LINK_INTERNAL = "internal";
* Link to a page inside the current application.
*/ const TYPE_LINK_INTERNAL = "internal";
/**
* Link to a CMS resource.
*/ const TYPE_LINK_RESOURCE = "resource";
* Link to a CMS resource.
*/ const TYPE_LINK_RESOURCE = "resource";
/**
* Checks whether a value is a link.
* @param value The value to check.
*/ function isLink(value) {
return !!(value && value.href);
* Checks whether a value is a link.
* @param value The value to check.
*/ function isLink(value) {
return !!(value === null || value === void 0 ? void 0 : value.href);
}

@@ -394,7 +816,7 @@ class LinkFactory extends MultipleTypeFactory {

/**
* Meta-data following before a page component.
*/ const META_POSITION_BEGIN = "begin";
* Meta-data following before a page component.
*/ const META_POSITION_BEGIN = "begin";
/**
* Meta-data following after a page component.
*/ const META_POSITION_END = "end";
* Meta-data following after a page component.
*/ const META_POSITION_END = "end";
class MetaImpl {

@@ -413,5 +835,5 @@ constructor(model, position) {

/**
* Checks whether a value is a meta-data object.
* @param value The value to check.
*/ function isMeta(value) {
* Checks whether a value is a meta-data object.
* @param value The value to check.
*/ function isMeta(value) {
return value instanceof MetaImpl;

@@ -421,4 +843,4 @@ }

/**
* Meta information stored in HST-comments.
*/ class MetaCommentImpl extends MetaImpl {
* Meta information stored in HST-comments.
*/ class MetaCommentImpl extends MetaImpl {
getData() {

@@ -431,40 +853,53 @@ const data = super.getData();

/**
* Checks whether a value is a meta-data comment.
* @param value The value to check.
*/ function isMetaComment(value) {
* Checks whether a value is a meta-data comment.
* @param value The value to check.
*/ function isMetaComment(value) {
return value instanceof MetaCommentImpl;
}
/**
* The factory to produce meta-data collection from the page model meta-data.
*/ class MetaFactory extends MultipleTypeFactory {
create(meta) {
return [ ...(meta.beginNodeSpan || []).map(this.buildMeta.bind(this, META_POSITION_BEGIN)), ...(meta.endNodeSpan || []).map(this.buildMeta.bind(this, META_POSITION_END)) ];
class MetaCollectionImpl extends Array {
constructor(model, factory) {
super(...(model.beginNodeSpan || []).map(model => factory.create(model, META_POSITION_BEGIN)), ...(model.endNodeSpan || []).map(model => factory.create(model, META_POSITION_END)));
this.comments = [];
Object.setPrototypeOf(this, Object.create(MetaCollectionImpl.prototype));
}
buildMeta(position, model) {
const builder = this.mapping.get(model.type);
if (!builder) {
throw new Error(`Unsupported meta type: '${model.type}'.`);
clear() {
this.comments.splice(0).forEach(comment => comment.remove());
}
render(head, tail) {
var _a;
const document = (_a = head.ownerDocument) !== null && _a !== void 0 ? _a : tail.ownerDocument;
if (!document) {
return;
}
return builder(model, position);
this.comments.push(...this.filter(isMetaComment).filter(meta => meta.getPosition() === META_POSITION_BEGIN).map(meta => document.createComment(meta.getData())).map(comment => {
var _a;
(_a = head.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(comment, head);
return comment;
}), ...this.filter(isMetaComment).filter(meta => meta.getPosition() === META_POSITION_END).reverse().map(meta => document.createComment(meta.getData())).map(comment => {
var _a, _b;
if (tail.nextSibling) {
(_a = tail.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(comment, tail.nextSibling);
} else {
(_b = tail.parentNode) === null || _b === void 0 ? void 0 : _b.appendChild(comment);
}
return comment;
}));
}
}
function _extends() {
_extends = Object.assign || function(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
/**
* The factory to produce meta-data collection from the page model meta-data.
*/ class MetaFactory extends MultipleTypeFactory {
create(meta, position) {
const builder = this.mapping.get(meta.type);
if (!builder) {
throw new Error(`Unsupported meta type: '${meta.type}'.`);
}
return target;
};
return _extends.apply(this, arguments);
return builder(meta, position);
}
}
/**
* Checks whether a value is a reference.
* @param value The value to check.
*/ function isReference(value) {
return !!(value && value.$ref);
* Checks whether a value is a reference.
* @param value The value to check.
*/ function isReference(value) {
return !!(value === null || value === void 0 ? void 0 : value.$ref);
}

@@ -500,17 +935,17 @@ class PageImpl {

getTitle() {
return this.model.page._meta && this.model.page._meta.pageTitle;
return this.model.page._meta.pageTitle;
}
getUrl(link) {
return this.linkFactory.create(link || (this.model._links ? _extends(_extends({}, this.model._links.site), {
return this.linkFactory.create(link || _extends(_extends({}, this.model._links.site), {
type: TYPE_LINK_INTERNAL
}) : ""));
}));
}
getVisitor() {
return this.model._meta && this.model._meta.visitor;
return this.model._meta.visitor;
}
getVisit() {
return this.model._meta && this.model._meta.visit;
return this.model._meta.visit;
}
isPreview() {
return !!(this.model._meta && this.model._meta.preview);
return !!this.model._meta.preview;
}

@@ -528,172 +963,17 @@ rewriteLinks(content, type = "text/html") {

/**
* Checks whether a value is a page.
* @param value The value to check.
*/ function isPage(value) {
* Checks whether a value is a page.
* @param value The value to check.
*/ function isPage(value) {
return value instanceof PageImpl;
}
const DEFAULT_API_BASE_URL = "/resourceapi";
const DEFAULT_SPA_BASE_URL = "";
function parseUrl(url) {
const parsedUrl = url ? new URL(url, "http://example.com") : {};
const {hash = "", search = "", searchParams = new URLSearchParams} = parsedUrl;
let origin = url.substring(0, url.length - search.length - hash.length);
let {pathname = ""} = parsedUrl;
if (!origin.endsWith(pathname)) {
pathname = pathname.substring(1);
}
origin = origin.substring(0, origin.length - pathname.length);
return {
hash,
origin,
pathname,
search,
searchParams,
path: `${pathname}${search}${hash}`
};
function isConfigurationWithProxy(value) {
var _a, _b;
return !!(((_a = value === null || value === void 0 ? void 0 : value.options) === null || _a === void 0 ? void 0 : _a.live) && ((_b = value === null || value === void 0 ? void 0 : value.options) === null || _b === void 0 ? void 0 : _b.preview));
}
function isMatchedOrigin(origin, baseOrigin) {
return !baseOrigin || !origin || baseOrigin === origin;
}
function isMatchedPathname(pathname, basePathname) {
return !basePathname || pathname.startsWith(basePathname);
}
function isMatchedQuery(search, baseSearch) {
let match = true;
baseSearch.forEach((value, key) => {
match = match && (!value && search.has(key) || search.getAll(key).includes(value));
});
return match;
}
function isMatched(link, base = DEFAULT_SPA_BASE_URL) {
const linkUrl = parseUrl(link);
const baseUrl = parseUrl(base);
return isMatchedOrigin(linkUrl.origin, baseUrl.origin) && isMatchedPathname(linkUrl.pathname, baseUrl.pathname) && isMatchedQuery(linkUrl.searchParams, baseUrl.searchParams);
}
function mergeSearchParams(params1, params2) {
const result = new URLSearchParams(params1);
params2.forEach((value, key) => result.set(key, value));
return result;
}
class UrlBuilderImpl {
constructor(options = {
cmsBaseUrl: ""
}) {
this.options = options;
this.initialize(options);
}
initialize(options) {
this.options = options;
this.apiBaseUrl = parseUrl(options.apiBaseUrl || `${options.cmsBaseUrl}${DEFAULT_API_BASE_URL}`);
this.cmsBaseUrl = parseUrl(options.cmsBaseUrl);
this.spaBaseUrl = parseUrl(options.spaBaseUrl || DEFAULT_SPA_BASE_URL);
}
getApiUrl(link) {
const {pathname, searchParams} = parseUrl(link);
if (this.spaBaseUrl.pathname && !pathname.startsWith(this.spaBaseUrl.pathname)) {
throw new Error(`The path "${pathname}" does not start with the base path "${this.spaBaseUrl.pathname}".`);
}
const route = pathname.substring(this.spaBaseUrl.pathname.length);
const query = mergeSearchParams(searchParams, this.apiBaseUrl.searchParams).toString();
return `${this.apiBaseUrl.origin}${this.apiBaseUrl.pathname}${route}${query && `?${query}`}`;
}
getCmsUrl(link) {
const {path} = parseUrl(link);
return `${this.cmsBaseUrl.origin}${path}`;
}
getSpaUrl(link) {
const {hash, pathname, searchParams} = parseUrl(link);
const query = mergeSearchParams(searchParams, this.spaBaseUrl.searchParams).toString();
let route = pathname.startsWith(this.cmsBaseUrl.pathname) ? pathname.substring(this.cmsBaseUrl.pathname.length) : pathname;
if (!route.startsWith("/") && !this.spaBaseUrl.pathname) {
route = `/${route}`;
}
return `${this.spaBaseUrl.origin}${this.spaBaseUrl.pathname}${route}${query && `?${query}`}${hash || this.spaBaseUrl.hash}`;
}
}
/**
* SPA entry point interacting with the Channel Manager and the Page Model API.
*/ class Spa {
/**
* @param config Configuration of the SPA integration with brXM.
* @param cms Cms integration instance.
* @param eventBus Event bus to exchange data between submodules.
* @param pageFactory Factory to produce page instances.
* @param urlBuilder API URL builder.
*/
constructor(config, cms, eventBus, pageFactory, urlBuilder) {
this.config = config;
this.cms = cms;
this.eventBus = eventBus;
this.pageFactory = pageFactory;
this.urlBuilder = urlBuilder;
this.onCmsUpdate = this.onCmsUpdate.bind(this);
}
fetchPageModel(url) {
return __awaiter(this, void 0, void 0, (function*() {
const {remoteAddress: ip} = this.config.request.connection || {};
const _a = this.config.request.headers || {}, headers = __rest(_a, [ "host" ]);
const response = yield this.config.httpClient({
url,
headers: _extends(_extends(_extends({}, ip && {
"x-forwarded-for": ip
}), this.config.visitor && {
[this.config.visitor.header]: this.config.visitor.id
}), headers),
method: "GET"
});
return response.data;
}));
}
fetchComponentModel(url, payload) {
return __awaiter(this, void 0, void 0, (function*() {
const data = new URLSearchParams(payload);
const response = yield this.config.httpClient({
url,
data: data.toString(),
headers: _extends({
"Content-Type": "application/x-www-form-urlencoded"
}, this.config.visitor && {
[this.config.visitor.header]: this.config.visitor.id
}),
method: "POST"
});
return response.data;
}));
}
onCmsUpdate(event) {
return __awaiter(this, void 0, void 0, (function*() {
const root = this.page.getComponent();
const component = root.getComponentById(event.id);
const url = component && component.getUrl();
if (!url) {
return;
}
const model = yield this.fetchComponentModel(url, event.properties);
this.eventBus.emit("page.update", {
page: model
});
}));
}
/**
* Intitializes the SPA.
*/ initialize(model) {
return __awaiter(this, void 0, void 0, (function*() {
const options = isMatched(this.config.request.path, this.config.options.preview.spaBaseUrl) ? this.config.options.preview : this.config.options.live;
this.urlBuilder.initialize(options);
this.cms.initialize(this.config.window);
const url = this.urlBuilder.getApiUrl(this.config.request.path);
this.page = this.pageFactory.create(model || (yield this.fetchPageModel(url)));
this.eventBus.on("cms.update", this.onCmsUpdate);
return this.page;
}));
}
/**
* Destroys the integration with the SPA page.
*/ destroy() {
this.eventBus.off("cms.update", this.onCmsUpdate);
delete this.page;
}
}
const DEFAULT_AUTHORIZATION_PARAMETER = "token";
const DEFAULT_SERVER_ID_PARAMETER = "server-id";
const eventBus = new emittery.Typed;
const cms = new Cms(eventBus);
const postMessage = new PostMessage;
const cms14 = new Cms14Impl(eventBus);
const cms = new CmsImpl(eventBus, postMessage, postMessage);
const domParser = new xmldom.DOMParser;

@@ -703,16 +983,47 @@ const pages = new WeakMap;

/**
* Initializes the page model.
*
* @param config Configuration of the SPA integration with brXM.
*/ function initialize(config, model) {
* Initializes the page model.
*
* @param config Configuration of the SPA integration with brXM.
* @param model Preloaded page model.
*/ function initialize(config, model) {
return __awaiter(this, void 0, void 0, (function*() {
const urlBuilder = new UrlBuilderImpl;
const api = new ApiImpl(urlBuilder);
const linkFactory = (new LinkFactory).register(TYPE_LINK_INTERNAL, urlBuilder.getSpaUrl.bind(urlBuilder));
const linkRewriter = new LinkRewriterImpl(linkFactory, domParser, xmlSerializer);
const metaFactory = (new MetaFactory).register(TYPE_META_COMMENT, (model, position) => new MetaCommentImpl(model, position));
const componentFactory = (new ComponentFactory).register(TYPE_COMPONENT, (model, children) => new ComponentImpl(model, children, linkFactory, metaFactory)).register(TYPE_COMPONENT_CONTAINER, (model, children) => new ContainerImpl(model, children, linkFactory, metaFactory)).register(TYPE_COMPONENT_CONTAINER_ITEM, model => new ContainerItemImpl(model, eventBus, linkFactory, metaFactory));
const contentFactory = new SingleTypeFactory(model => new ContentImpl(model, linkFactory, metaFactory));
const pageFactory = new SingleTypeFactory(model => new PageImpl(model, componentFactory.create(model.page), contentFactory, eventBus, linkFactory, linkRewriter, metaFactory));
const spa = new Spa(config, cms, eventBus, pageFactory, urlBuilder);
const page = yield spa.initialize(model);
const metaCollectionFactory = new SingleTypeFactory(model => new MetaCollectionImpl(model, metaFactory));
const componentFactory = (new ComponentFactory).register(TYPE_COMPONENT, (model, children) => new ComponentImpl(model, children, linkFactory, metaCollectionFactory)).register(TYPE_COMPONENT_CONTAINER, (model, children) => new ContainerImpl(model, children, linkFactory, metaCollectionFactory)).register(TYPE_COMPONENT_CONTAINER_ITEM, model => new ContainerItemImpl(model, eventBus, linkFactory, metaCollectionFactory));
const contentFactory = new SingleTypeFactory(model => new ContentImpl(model, linkFactory, metaCollectionFactory));
const pageFactory = new SingleTypeFactory(model => new PageImpl(model, componentFactory.create(model.page), contentFactory, eventBus, linkFactory, linkRewriter, metaCollectionFactory));
const spa = new Spa(eventBus, api, pageFactory);
if (isConfigurationWithProxy(config)) {
const options = isMatched(config.request.path, config.options.preview.spaBaseUrl) ? config.options.preview : config.options.live;
urlBuilder.initialize(options);
api.initialize(config);
cms14.initialize(config);
const page = yield spa.initialize(config.request.path, model);
pages.set(page, spa);
return page;
}
const authorizationParameter = config.authorizationQueryParameter || DEFAULT_AUTHORIZATION_PARAMETER;
const serverIdParameter = config.serverIdQueryParameter || DEFAULT_SERVER_ID_PARAMETER;
const {url: path, searchParams} = extractSearchParams(config.request.path, [ authorizationParameter, serverIdParameter ]);
const authorizationToken = searchParams.get(authorizationParameter) || undefined;
const serverId = searchParams.get(serverIdParameter) || undefined;
urlBuilder.initialize(_extends(_extends({}, config), {
spaBaseUrl: appendSearchParams(config.spaBaseUrl || "", searchParams)
}));
api.initialize(_extends({
authorizationToken,
serverId
}, config));
const page = yield spa.initialize(path, model);
if (page.isPreview()) {
const {origin} = parseUrl(config.cmsBaseUrl);
postMessage.initialize(_extends(_extends({}, config), {
origin
}));
cms.initialize(config);
}
pages.set(page, spa);

@@ -723,7 +1034,7 @@ return page;

/**
* Destroys the integration with the SPA page.
* @param page Page instance to destroy.
*/ function destroy(page) {
const spa = pages.get(page);
return spa && spa.destroy();
* Destroys the integration with the SPA page.
* @param page Page instance to destroy.
*/ function destroy(page) {
var _a;
return (_a = pages.get(page)) === null || _a === void 0 ? void 0 : _a.destroy();
}

@@ -730,0 +1041,0 @@ exports.META_POSITION_BEGIN = META_POSITION_BEGIN;

import { Factory } from './factory';
import { Link } from './link';
import { MetaCollectionModel, Meta } from './meta';
import { MetaCollectionModel, MetaCollection } from './meta-collection';
/**

@@ -42,4 +42,4 @@ * Generic component type.

export interface ComponentModel {
_links?: Record<ComponentLinks, Link>;
_meta?: ComponentMeta;
_links: Record<ComponentLinks, Link>;
_meta: ComponentMeta;
id: string;

@@ -62,3 +62,3 @@ models?: ComponentModels;

*/
getMeta(): Meta[];
getMeta(): MetaCollection;
/**

@@ -100,8 +100,8 @@ * @return The map of the component models.

private linkFactory;
protected meta: Meta[];
constructor(model: ComponentModel, children: Component[], linkFactory: Factory<[Link], string>, metaFactory: Factory<[MetaCollectionModel], Meta[]>);
protected meta: MetaCollection;
constructor(model: ComponentModel, children: Component[], linkFactory: Factory<[Link], string>, metaFactory: Factory<[MetaCollectionModel], MetaCollection>);
getId(): string;
getMeta(): Meta[];
getMeta(): MetaCollection;
getModels<T extends ComponentModels>(): T;
getUrl(): string | undefined;
getUrl(): string;
getName(): string;

@@ -108,0 +108,0 @@ getParameters(): Partial<Record<string, string>>;

@@ -7,3 +7,3 @@ import { Typed } from 'emittery';

import { Link } from './link';
import { MetaCollectionModel, Meta } from './meta';
import { MetaCollectionModel, MetaCollection } from './meta-collection';
declare const PARAMETER_HIDDEN = "com.onehippo.cms7.targeting.TargetingParameterUtil.hide";

@@ -30,3 +30,3 @@ /**

export interface ContainerItemModel extends ComponentModel {
_meta?: ContainerItemMeta;
_meta: ContainerItemMeta;
label?: string;

@@ -67,8 +67,8 @@ type: typeof TYPE_COMPONENT_CONTAINER_ITEM;

on: {
<Name extends "update">(eventName: Name, listener: (eventData: ContainerItemEvents[Name]) => any): import("emittery").UnsubscribeFn;
<Name_1 extends never>(eventName: Name_1, listener: () => any): import("emittery").UnsubscribeFn;
<Name extends "update">(eventName: Name, listener: (eventData: ContainerItemEvents[Name]) => void): import("emittery").UnsubscribeFn;
<Name_1 extends never>(eventName: Name_1, listener: () => void): import("emittery").UnsubscribeFn;
};
off: {
<Name_2 extends "update">(eventName: Name_2, listener: (eventData: ContainerItemEvents[Name_2]) => any): void;
<Name_3 extends never>(eventName: Name_3, listener: () => any): void;
<Name_2 extends "update">(eventName: Name_2, listener: (eventData: ContainerItemEvents[Name_2]) => void): void;
<Name_3 extends never>(eventName: Name_3, listener: () => void): void;
};

@@ -84,3 +84,3 @@ emit: {

private metaFactory;
constructor(model: ContainerItemModel, eventBus: Typed<Events>, linkFactory: Factory<[Link], string>, metaFactory: Factory<[MetaCollectionModel], Meta[]>);
constructor(model: ContainerItemModel, eventBus: Typed<Events>, linkFactory: Factory<[Link], string>, metaFactory: Factory<[MetaCollectionModel], MetaCollection>);
protected onPageUpdate(event: PageUpdateEvent): void;

@@ -87,0 +87,0 @@ getType(): string | undefined;

@@ -5,3 +5,3 @@ import { ComponentImpl, ComponentModel, Component, TYPE_COMPONENT_CONTAINER } from './component';

import { Link } from './link';
import { MetaCollectionModel, Meta } from './meta';
import { MetaCollectionModel, MetaCollection } from './meta-collection';
/**

@@ -59,5 +59,5 @@ * A blocked container with blocked items.

protected children: ContainerItem[];
constructor(model: ContainerModel, children: ContainerItem[], linkFactory: Factory<[Link], string>, metaFactory: Factory<[MetaCollectionModel], Meta[]>);
constructor(model: ContainerModel, children: ContainerItem[], linkFactory: Factory<[Link], string>, metaFactory: Factory<[MetaCollectionModel], MetaCollection>);
getChildren(): ContainerItem[];
getType(): "hst.vbox" | "hst.unorderedlist" | "hst.orderedlist" | "hst.span" | "hst.nomarkup" | undefined;
getType(): ContainerType;
}

@@ -64,0 +64,0 @@ /**

import { Factory } from './factory';
import { Link } from './link';
import { MetaCollectionModel, Meta } from './meta';
import { MetaCollectionModel, MetaCollection } from './meta-collection';
/**

@@ -13,3 +13,3 @@ * @hidden

export interface ContentModel {
_links?: Record<ContentLinks, Link>;
_links: Record<ContentLinks, Link>;
_meta?: MetaCollectionModel;

@@ -36,3 +36,3 @@ id: string;

*/
getMeta(): Meta[];
getMeta(): MetaCollection;
/**

@@ -55,11 +55,11 @@ * @return The content name.

private linkFactory;
protected meta: Meta[];
constructor(model: ContentModel, linkFactory: Factory<[Link], string>, metaFactory: Factory<[MetaCollectionModel], Meta[]>);
protected meta: MetaCollection;
constructor(model: ContentModel, linkFactory: Factory<[Link], string>, metaFactory: Factory<[MetaCollectionModel], MetaCollection>);
getId(): string;
getLocale(): string | undefined;
getMeta(): Meta[];
getMeta(): MetaCollection;
getName(): string;
getData(): ContentModel;
getUrl(): string | undefined;
getUrl(): string;
}
export {};

@@ -11,2 +11,3 @@ export * from './component-factory';

export * from './menu';
export * from './meta-collection';
export * from './meta-comment';

@@ -13,0 +14,0 @@ export * from './meta-factory';

import { Link } from './link';
import { MetaCollectionModel } from './meta';
import { MetaCollectionModel } from './meta-collection';
/**

@@ -4,0 +4,0 @@ * @hidden

import { MultipleTypeFactory } from './factory';
import { MetaCollectionModel, MetaModel, MetaPosition, MetaType, Meta } from './meta';
import { MetaModel, MetaPosition, MetaType, Meta } from './meta';
declare type MetaBuilder = (model: MetaModel, position: MetaPosition) => Meta;

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

export declare class MetaFactory extends MultipleTypeFactory<MetaType, MetaBuilder> {
create(meta: MetaCollectionModel): Meta[];
private buildMeta;
create(meta: MetaModel, position: MetaPosition): Meta;
}
export {};

@@ -20,9 +20,2 @@ export declare const TYPE_META_COMMENT = "comment";

/**
* @hidden
*/
export interface MetaCollectionModel {
beginNodeSpan?: MetaModel[];
endNodeSpan?: MetaModel[];
}
/**
* Meta information describing a part of the page.

@@ -29,0 +22,0 @@ */

@@ -10,3 +10,3 @@ import { Typed } from 'emittery';

import { Events, PageUpdateEvent } from '../events';
import { MetaCollectionModel, Meta } from './meta';
import { MetaCollectionModel, MetaCollection } from './meta-collection';
import { Reference } from './reference';

@@ -30,3 +30,3 @@ import { Visitor, Visit } from './relevance';

interface PageRootModel {
_meta?: PageRootMeta;
_meta: PageRootMeta;
}

@@ -58,4 +58,4 @@ /**

export interface PageModel {
_links?: Record<PageLinks, Link>;
_meta?: PageMeta;
_links: Record<PageLinks, Link>;
_meta: PageMeta;
content?: {

@@ -88,6 +88,6 @@ [reference: string]: ContentModel;

/**
* Generates a meta-data from the provided meta-data model.
* @param meta the meta-collection as returned by the page-model-api
* Generates a meta-data collection from the provided meta-data model.
* @param meta The meta-data collection model as returned by the page-model-api.
*/
getMeta(meta: MetaCollectionModel): Meta[];
getMeta(meta: MetaCollectionModel): MetaCollection;
/**

@@ -154,3 +154,3 @@ * @return The title of the page, or `undefined` if not configured.

protected content: Map<string, Content>;
constructor(model: PageModel, root: Component, contentFactory: Factory<[ContentModel], Content>, eventBus: Typed<Events>, linkFactory: Factory<[Link | string], string>, linkRewriter: LinkRewriter, metaFactory: Factory<[MetaCollectionModel], Meta[]>);
constructor(model: PageModel, root: Component, contentFactory: Factory<[ContentModel], Content>, eventBus: Typed<Events>, linkFactory: Factory<[Link | string], string>, linkRewriter: LinkRewriter, metaFactory: Factory<[MetaCollectionModel], MetaCollection>);
protected onPageUpdate(event: PageUpdateEvent): void;

@@ -161,3 +161,3 @@ private static getContentReference;

getContent(reference: Reference | string): Content | undefined;
getMeta(meta: MetaCollectionModel): Meta[];
getMeta(meta: MetaCollectionModel): MetaCollection;
getTitle(): string | undefined;

@@ -164,0 +164,0 @@ getUrl(link?: Link | string): string;

{
"name": "@bloomreach/spa-sdk",
"version": "14.1.1",
"version": "14.2.0",
"description": "Bloomreach SPA SDK",

@@ -32,55 +32,43 @@ "keywords": [

"lint": "tslint --project .",
"test": "jest"
"prepare": "$npm_execpath run build",
"test": "jest --coverage"
},
"jest": {
"testEnvironment": "jsdom",
"coverageDirectory": "./coverage",
"collectCoverage": true,
"collectCoverageFrom": [
"src/**/*.ts"
],
"moduleFileExtensions": [
"ts",
"js"
],
"transform": {
"^.+\\.ts$": "ts-jest"
},
"globals": {
"ts-jest": {
"tsConfig": "tsconfig.json"
}
},
"testMatch": [
"**/?(*.)spec.ts"
]
"preset": "ts-jest",
"testEnvironment": "jsdom"
},
"browserslist": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version",
"last 1 edge version"
],
"devDependencies": {
"@babel/core": "^7.7",
"@babel/plugin-proposal-class-properties": "^7.7",
"@babel/plugin-proposal-object-rest-spread": "^7.7",
"@babel/plugin-transform-object-assign": "^7.7",
"@babel/polyfill": "^7.7",
"@babel/preset-env": "^7.7",
"@types/jest": "^24.0",
"@babel/core": "^7.9",
"@babel/plugin-proposal-class-properties": "^7.8",
"@babel/plugin-proposal-object-rest-spread": "^7.9",
"@babel/plugin-transform-object-assign": "^7.8",
"@babel/polyfill": "^7.8",
"@babel/preset-env": "^7.9",
"@types/jest": "^25.1",
"@types/xmldom": "^0.1",
"babel-plugin-transform-async-to-promises": "^0.8",
"dts-bundle-generator": "^3.3",
"jest": "^24.9",
"dts-bundle-generator": "^4.0",
"jest": "^25.2",
"js-beautify": "^1.10",
"minicat": "^1.0",
"rollup": "^1.27",
"rollup-plugin-babel": "^4.3",
"rollup-plugin-terser": "^5.1",
"rollup-plugin-typescript2": "^0.25",
"ts-jest": "^24.2",
"tslint": "^5.20",
"rollup": "^2.3",
"rollup-plugin-babel": "^4.4",
"rollup-plugin-terser": "^5.3",
"rollup-plugin-typescript2": "^0.27",
"ts-jest": "^25.3",
"tslint": "^6.1",
"tslint-config-airbnb": "^5.11",
"typedoc": "^0.15",
"typescript": "^3.7"
"typedoc": "^0.17",
"typescript": "^3.8"
},
"dependencies": {
"emittery": "^0.4",
"xmldom": "^0.1"
"emittery": "^0.6",
"xmldom": "^0.3"
}
}

@@ -38,13 +38,4 @@ # Bloomreach SPA SDK

const page = await initialize({
cmsBaseUrl: 'http://localhost:8080/site',
httpClient: axios,
options: {
live: {
cmsBaseUrl: 'http://localhost:8080/site',
spaBaseUrl: '',
},
preview: {
cmsBaseUrl: 'http://localhost:8080/site/_cmsinternal',
spaBaseUrl: '/site/_cmsinternal?bloomreach-preview=true',
},
},
request: { path },

@@ -64,4 +55,6 @@ });

--- | :---: | --- | ---
`apiBaseUrl` | no | `cmsBaseUrl` + `"/resourceapi"` | Base URL of the Page Model API (e.g. `http://localhost:8080/site/resourceapi` or `http://localhost:8080/site/channel/resourceapi`). This option will be ignored if `options` is present.
`cmsBaseUrl` | _exclusive_ | _none_ | Base URL of the site (e.g. `http://localhost:8080/site` or `http://localhost:8080/site/channel`). This option is exclusive and should not be used together with `options`.
`httpClient` | yes | _none_ | The HTTP client that will be used to fetch the page model. Signature is similar to [Axios](https://github.com/axios/axios#axiosconfig) client.
`options` | yes | _none_ | The CMS URL options.
`options` | _exclusive_ | _none_ | The CMS URL options. This option is exclusive and should not be used together with `cmsBaseUrl`. Use this property to enable the UrlRewriter-based setup. The option is **deprecated** and will be removed in the next major release.
`options.live` | yes | _none_ | The CMS URL options for the live site.

@@ -78,2 +71,3 @@ `options.live.apiBaseUrl` | no | `options.live.cmsBaseUrl` + `"/resourceapi"` | Base URL of the Page Model API for the live site (e.g. `http://localhost:8080/site/resourceapi` or `http://localhost:8080/site/channel/resourceapi`).

`request.headers` | no | `{}` | An object holding request headers. It should contain a `Cookie` header if rendering is happening on the server-side.
`spaBaseUrl` | no | `""` | Base URL of the SPA (e.g. `/account` or `//www.example.com`). This option will be ignored if `options` is present.
`visitor` | no | _none_ | An object holding information about the current visitor.

@@ -123,3 +117,3 @@ `visitor.id` | yes | _none_ | The current visitor identifier.

<code>getContent(reference: Reference &vert; string): Content &vert; undefined</code> | Gets a content item used on the page.
`getMeta(meta): Meta[]` | Generates a meta-data from the provided `meta` model.
`getMeta(meta): MetaCollection` | Generates a meta-data collection from the provided `meta` model.
<code>getTitle(): string &vert; undefined</code> | Gets the title of the page, or `undefined` if not configured.

@@ -141,3 +135,3 @@ `getUrl(link?: Link): string` | Generates a URL for a link object.<br> - If the link object type is internal, then it will prepend `spaBaseUrl`. In case when the link starts with the same path as in `cmsBaseUrl`, this part will be removed.<br> - If the link parameter is omitted, then the link to the current page will be returned.<br> - In other cases, the link will be returned as-is.

`getId(): string` | Returns the component id.
`getMeta(): Meta[]` | Returns the component meta-data collection.
`getMeta(): MetaCollection` | Returns the component meta-data collection.
`getModels(): object` | Returns the map of the component models.

@@ -175,3 +169,3 @@ <code>getUrl(): string &vert; undefined</code> | Returns the link to the partial component model.

<code>getLocale(): string &vert; undefined</code> | Returns the content locale.
`getMeta(): Meta[]` | Returns the content meta-data collection.
`getMeta(): MetaCollection` | Returns the content meta-data collection.
`getName(): string` | Returns the content name.

@@ -181,2 +175,8 @@ `getData(): object` | Returns the content data as it is returned in the Page Model API.

##### MetaCollection
Method | Description
--- | ---
`clear(): void` | Clears previously rendered meta-data objects.
`render(head: HTMLElement, tail: HTMLElement): void;` | Renders meta-data objects on the page.
##### Meta

@@ -183,0 +183,0 @@ The `Meta` objects are being used by the brXM to page and its components.

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