@bloomreach/spa-sdk
Advanced tools
Comparing version 14.0.1 to 14.1.0
@@ -32,2 +32,11 @@ /** | ||
/** | ||
* An HTTP connection. | ||
*/ | ||
export interface HttpConnection { | ||
/** | ||
* Client's remote IP address. | ||
*/ | ||
remoteAddress?: string; | ||
} | ||
/** | ||
* An HTTP request | ||
@@ -37,6 +46,5 @@ */ | ||
/** | ||
* The path part of the URL, including a query string if present. | ||
* For example: '/path/to/page?foo=1'. The path always starts with '/'. | ||
* HTTP connection data. | ||
*/ | ||
path: string; | ||
connection?: HttpConnection; | ||
/** | ||
@@ -46,2 +54,7 @@ * All request headers (including cookies). | ||
headers?: HttpHeaders; | ||
/** | ||
* The path part of the URL, including a query string if present. | ||
* For example: '/path/to/page?foo=1'. The path always starts with '/'. | ||
*/ | ||
path: string; | ||
} | ||
@@ -48,0 +61,0 @@ /** |
@@ -6,2 +6,10 @@ (function(global, factory) { | ||
"use strict"; | ||
function __rest(s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
} | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
@@ -127,3 +135,3 @@ return new (P || (P = Promise))((function(resolve, reject) { | ||
if (!builder) { | ||
throw new Error("Unsupported component type: '".concat(model.type, "'.")); | ||
throw new Error(`Unsupported component type: '${model.type}'.`); | ||
} | ||
@@ -327,9 +335,6 @@ return builder(model, children); | ||
createLink(link) { | ||
if (!link.type) { | ||
if (!link.type || !this.mapping.has(link.type)) { | ||
return link.href; | ||
} | ||
const builder = this.mapping.get(link.type); | ||
if (!builder) { | ||
throw new Error("Unsupported link type: '".concat(link.type, "'.")); | ||
} | ||
return builder(link.href); | ||
@@ -352,3 +357,3 @@ } | ||
rewrite(content, type = "text/html") { | ||
const document = this.domParser.parseFromString("<body>".concat(content, "</body>"), type); | ||
const document = this.domParser.parseFromString(`<body>${content}</body>`, type); | ||
this.rewriteAnchors(document); | ||
@@ -422,3 +427,3 @@ this.rewriteImages(document); | ||
if (!builder) { | ||
throw new Error("Unsupported meta type: '".concat(model.type, "'.")); | ||
throw new Error(`Unsupported meta type: '${model.type}'.`); | ||
} | ||
@@ -484,2 +489,8 @@ return builder(model, position); | ||
} | ||
getVisitor() { | ||
return this.model._meta && this.model._meta.visitor; | ||
} | ||
getVisit() { | ||
return this.model._meta && this.model._meta.visit; | ||
} | ||
isPreview() { | ||
@@ -521,3 +532,3 @@ return !!(this.model._meta && this.model._meta.preview); | ||
searchParams, | ||
path: "".concat(pathname).concat(search).concat(hash) | ||
path: `${pathname}${search}${hash}` | ||
}; | ||
@@ -557,3 +568,3 @@ } | ||
this.options = options; | ||
this.apiBaseUrl = parseUrl(options.apiBaseUrl || "".concat(options.cmsBaseUrl).concat(DEFAULT_API_BASE_URL)); | ||
this.apiBaseUrl = parseUrl(options.apiBaseUrl || `${options.cmsBaseUrl}${DEFAULT_API_BASE_URL}`); | ||
this.cmsBaseUrl = parseUrl(options.cmsBaseUrl); | ||
@@ -565,11 +576,11 @@ this.spaBaseUrl = parseUrl(options.spaBaseUrl || DEFAULT_SPA_BASE_URL); | ||
if (this.spaBaseUrl.pathname && !pathname.startsWith(this.spaBaseUrl.pathname)) { | ||
throw new Error('The path "'.concat(pathname, '" does not start with the base path "').concat(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 "".concat(this.apiBaseUrl.origin).concat(this.apiBaseUrl.pathname).concat(route).concat(query && "?".concat(query)); | ||
return `${this.apiBaseUrl.origin}${this.apiBaseUrl.pathname}${route}${query && `?${query}`}`; | ||
} | ||
getCmsUrl(link) { | ||
const {path} = parseUrl(link); | ||
return "".concat(this.cmsBaseUrl.origin).concat(path); | ||
return `${this.cmsBaseUrl.origin}${path}`; | ||
} | ||
@@ -581,5 +592,5 @@ getSpaUrl(link) { | ||
if (!route.startsWith("/") && !this.spaBaseUrl.pathname) { | ||
route = "/".concat(route); | ||
route = `/${route}`; | ||
} | ||
return "".concat(this.spaBaseUrl.origin).concat(this.spaBaseUrl.pathname).concat(route).concat(query && "?".concat(query)).concat(hash || this.spaBaseUrl.hash); | ||
return `${this.spaBaseUrl.origin}${this.spaBaseUrl.pathname}${route}${query && `?${query}`}${hash || this.spaBaseUrl.hash}`; | ||
} | ||
@@ -607,5 +618,11 @@ } | ||
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: this.config.request.headers, | ||
headers: _extends(_extends(_extends({}, ip && { | ||
"x-forwarded-for": ip | ||
}), this.config.visitor && { | ||
[this.config.visitor.header]: this.config.visitor.id | ||
}), headers), | ||
method: "GET" | ||
@@ -622,5 +639,7 @@ }); | ||
data: data.toString(), | ||
headers: { | ||
headers: _extends({ | ||
"Content-Type": "application/x-www-form-urlencoded" | ||
}, | ||
}, this.config.visitor && { | ||
[this.config.visitor.header]: this.config.visitor.id | ||
}), | ||
method: "POST" | ||
@@ -677,3 +696,3 @@ }); | ||
const urlBuilder = new UrlBuilderImpl; | ||
const linkFactory = (new LinkFactory).register(TYPE_LINK_EXTERNAL, urlBuilder.getSpaUrl.bind(urlBuilder)).register(TYPE_LINK_INTERNAL, urlBuilder.getSpaUrl.bind(urlBuilder)).register(TYPE_LINK_RESOURCE, urlBuilder.getCmsUrl.bind(urlBuilder)); | ||
const linkFactory = (new LinkFactory).register(TYPE_LINK_INTERNAL, urlBuilder.getSpaUrl.bind(urlBuilder)); | ||
const linkRewriter = new LinkRewriterImpl(linkFactory, domParser, xmlSerializer); | ||
@@ -680,0 +699,0 @@ const metaFactory = (new MetaFactory).register(TYPE_META_COMMENT, (model, position) => new MetaCommentImpl(model, position)); |
@@ -16,1 +16,2 @@ export * from './component-factory'; | ||
export * from './reference'; | ||
export * from './relevance'; |
@@ -12,2 +12,3 @@ import { Typed } from 'emittery'; | ||
import { Reference } from './reference'; | ||
import { Visitor, Visit } from './relevance'; | ||
/** | ||
@@ -36,2 +37,15 @@ * @hidden | ||
interface PageMeta { | ||
/** | ||
* Meta-data about the current visitor. Available when the Relevance Module is enabled. | ||
* @see https://documentation.bloomreach.com/library/enterprise/enterprise-features/targeting/targeting.html | ||
*/ | ||
visitor?: Visitor; | ||
/** | ||
* Meta-data about the current visit. Available when the Relevance Module is enabled. | ||
* @see https://documentation.bloomreach.com/library/enterprise/enterprise-features/targeting/targeting.html | ||
*/ | ||
visit?: Visit; | ||
/** | ||
* Preview mode flag. | ||
*/ | ||
preview?: boolean; | ||
@@ -83,3 +97,3 @@ } | ||
* Generates a URL for a link object. | ||
* - If the link object type is internal or external, then it will prepend `spaBaseUrl`. | ||
* - 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. | ||
@@ -89,5 +103,2 @@ * For example, for link `/site/_cmsinternal/spa/about` with configuration options | ||
* it will generate `http://example.com/about`. | ||
* - If it is a resource link, then it will prepend the origin part from the `cmsBaseUrl` option. | ||
* For example, for link `/site/_cmsinternal/binaries/image1.jpg` with configuration option | ||
* `cmsBaseUrl = "//localhost:8080/site/spa"`, it will generate `//localhost/site/_cmsinternal/binaries/image1.jpg`. | ||
* - If the link parameter is omitted, then the link to the current page will be returned. | ||
@@ -101,3 +112,3 @@ * - In other cases, the link will be returned as-is. | ||
* - If it is a relative path, then it will prepend `spaBaseUrl`. | ||
* - If it is an absolute path, then the behavior will be similar to internal and external link generation. | ||
* - If it is an absolute path, then the behavior will be similar to internal link generation. | ||
* @param path The path to generate URL. | ||
@@ -107,2 +118,10 @@ */ | ||
/** | ||
* @return The current visitor data. | ||
*/ | ||
getVisitor(): Visitor | undefined; | ||
/** | ||
* @return The current visit data. | ||
*/ | ||
getVisit(): Visit | undefined; | ||
/** | ||
* @returns Whether the page is in the preview mode. | ||
@@ -146,2 +165,4 @@ */ | ||
getUrl(link?: Link | string): string; | ||
getVisitor(): Visitor | undefined; | ||
getVisit(): Visit | undefined; | ||
isPreview(): boolean; | ||
@@ -148,0 +169,0 @@ rewriteLinks(content: string, type?: SupportedType): string; |
import { Typed } from 'emittery'; | ||
import { Cms } from './cms'; | ||
import { Factory, PageModel, Page } from './page'; | ||
import { Factory, PageModel, Page, Visitor } from './page'; | ||
import { Events, CmsUpdateEvent } from './events'; | ||
@@ -29,2 +29,6 @@ import { HttpClient, HttpRequest } from './http'; | ||
/** | ||
* Options for generating the page model API URL. | ||
*/ | ||
options: UrlOptions; | ||
/** | ||
* Current user's request. | ||
@@ -34,5 +38,5 @@ */ | ||
/** | ||
* Options for generating the page model API URL. | ||
* Current visitor. | ||
*/ | ||
options: UrlOptions; | ||
visitor?: Omit<Visitor, 'new'>; | ||
/** | ||
@@ -39,0 +43,0 @@ * The window reference for the CMS integration. |
{ | ||
"name": "@bloomreach/spa-sdk", | ||
"version": "14.0.1", | ||
"version": "14.1.0", | ||
"description": "Bloomreach SPA SDK", | ||
@@ -58,24 +58,24 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/core": "^7.6", | ||
"@babel/plugin-proposal-class-properties": "^7.5", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.5", | ||
"@babel/plugin-transform-object-assign": "^7.2", | ||
"@babel/polyfill": "^7.6", | ||
"@babel/preset-env": "^7.6", | ||
"@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", | ||
"@types/xmldom": "^0.1", | ||
"babel-plugin-transform-async-to-promises": "^0.8", | ||
"dts-bundle-generator": "^3.2", | ||
"jest": "^24.0", | ||
"js-beautify": "^1.0", | ||
"dts-bundle-generator": "^3.3", | ||
"jest": "^24.9", | ||
"js-beautify": "^1.10", | ||
"minicat": "^1.0", | ||
"rollup": "^1.21", | ||
"rollup": "^1.27", | ||
"rollup-plugin-babel": "^4.3", | ||
"rollup-plugin-terser": "^5.1", | ||
"rollup-plugin-typescript2": "^0.24", | ||
"ts-jest": "^24.0", | ||
"tslint": "^5.0", | ||
"tslint-config-airbnb": "^5.0", | ||
"rollup-plugin-typescript2": "^0.25", | ||
"ts-jest": "^24.2", | ||
"tslint": "^5.20", | ||
"tslint-config-airbnb": "^5.11", | ||
"typedoc": "^0.15", | ||
"typescript": "^3.6" | ||
"typescript": "^3.7" | ||
}, | ||
@@ -82,0 +82,0 @@ "dependencies": { |
@@ -76,2 +76,5 @@ # Bloomreach SPA SDK | ||
`request.headers` | no | `{}` | An object holding request headers. It should contain a `Cookie` header if rendering is happening on the server-side. | ||
`visitor` | no | _none_ | An object holding information about the current visitor. | ||
`visitor.id` | yes | _none_ | The current visitor identifier. | ||
`visitor.header` | yes | _none_ | An HTTP-header using to pass the visitor identifier to the Page Model API. | ||
`window` | no | `window` | A window object reference will be used to interact with brXM. It needs to be set when initialize is being called within an iframe or worker process. | ||
@@ -120,4 +123,6 @@ | ||
<code>getTitle(): string | undefined</code> | Gets the title of the page, or `undefined` if not configured. | ||
`getUrl(link?: Link): string` | Generates a URL for a link object.<br> - If the link object type is internal or external, 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 it is a resource link, then it will prepend the origin part from the `cmsBaseUrl` option.<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. | ||
`getUrl(path: string): string` | Generates an SPA URL for the path.<br> - If it is a relative path, then it will prepend `spaBaseUrl`.<br> - If it is an absolute path, then the behavior will be similar to internal and external link generation. | ||
`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. | ||
`getUrl(path: string): string` | Generates an SPA URL for the path.<br> - If it is a relative path, then it will prepend `spaBaseUrl`.<br> - If it is an absolute path, then the behavior will be similar to internal link generation. | ||
<code>getVisitor(): Visitor | undefined</code> | Gets the current visitor information, or undefined if the [Relevance Module](https://documentation.bloomreach.com/library/enterprise/enterprise-features/targeting/targeting.html) is not enabled. The `Visitor` object consists of the following properties:<br> - `id: string` - the current visitor identifier;<br> - `header: string` - an HTTP-header using to pass the visitor identifier to the Page Model API. | ||
<code>getVisit(): Visit | undefined</code> | Gets the current visit information, or undefined if the [Relevance Module](https://documentation.bloomreach.com/library/enterprise/enterprise-features/targeting/targeting.html) is not enabled. The `Visit` object consists of the following properties:<br> - `id: string` - the current visit identifier;<br> - `new: boolean` - a flag showing that this is a new visit. | ||
`isPreview(): boolean` | Returns whether the page is in the preview mode. | ||
@@ -124,0 +129,0 @@ `rewriteLinks(content: string, type?: string): string` | Rewrite links to pages and resources in the HTML content. This method looks up for `a` tags with `data-type` and `href` attributes and `img` tags with `src` attribute. Links will be updated according to the configuration used to initialize the page. The `type` parameter is similar to `mimeType` parameter of the [DOMParser](https://developer.mozilla.org/en-US/docs/Web/API/DOMParser). |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
142266
30
3217
193
0