@coveo/atomic-hosted-page
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -1,2 +0,2 @@ | ||
import{p as t,b as i}from"./p-d60c5453.js";const o=()=>{const i=import.meta.url;const o={};if(i!==""){o.resourcesUrl=new URL(".",i).href}return t(o)};o().then((t=>i([["p-1a5cb08e",[[0,"atomic-hosted-page",{initialize:[64]}]]]],t))); | ||
import{p as i,b as t}from"./p-d60c5453.js";const a=()=>{const t=import.meta.url;const a={};if(t!==""){a.resourcesUrl=new URL(".",t).href}return i(a)};a().then((i=>t([["p-57ab8a87",[[0,"atomic-hosted-page",{initialize:[64]}]]],["p-ab3823e5",[[0,"atomic-simple-builder",{initialize:[64]}]]]],i))); | ||
//# sourceMappingURL=atomic-hosted-page.esm.js.map |
@@ -6,145 +6,4 @@ 'use strict'; | ||
const index = require('./index-4798ddc4.js'); | ||
const hostedPages = require('./hosted-pages-62ae0cd7.js'); | ||
/** | ||
* @license | ||
* | ||
* Copyright 2023 Coveo Solutions Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
// src/schema.ts | ||
function buildSchemaValidationError(errors, context) { | ||
const message = ` | ||
The following properties are invalid: | ||
${errors.join("\n ")} | ||
${context} | ||
`; | ||
return new SchemaValidationError(message); | ||
} | ||
var SchemaValidationError = class extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = "SchemaValidationError"; | ||
} | ||
}; | ||
var Schema = class { | ||
constructor(definition) { | ||
this.definition = definition; | ||
} | ||
validate(values = {}, message = "") { | ||
const mergedValues = { | ||
...this.default, | ||
...values | ||
}; | ||
const errors = []; | ||
for (const property in this.definition) { | ||
const error = this.definition[property].validate(mergedValues[property]); | ||
error && errors.push(`${property}: ${error}`); | ||
} | ||
if (errors.length) { | ||
throw buildSchemaValidationError(errors, message); | ||
} | ||
return mergedValues; | ||
} | ||
get default() { | ||
const defaultValues = {}; | ||
for (const property in this.definition) { | ||
const defaultValue = this.definition[property].default; | ||
if (defaultValue !== void 0) { | ||
defaultValues[property] = defaultValue; | ||
} | ||
} | ||
return defaultValues; | ||
} | ||
}; | ||
// src/values/value.ts | ||
var Value = class { | ||
constructor(baseConfig = {}) { | ||
this.baseConfig = baseConfig; | ||
} | ||
validate(value) { | ||
if (this.baseConfig.required && isNullOrUndefined(value)) { | ||
return "value is required."; | ||
} | ||
return null; | ||
} | ||
get default() { | ||
return this.baseConfig.default instanceof Function ? this.baseConfig.default() : this.baseConfig.default; | ||
} | ||
get required() { | ||
return this.baseConfig.required === true; | ||
} | ||
}; | ||
function isUndefined(value) { | ||
return value === void 0; | ||
} | ||
function isNull(value) { | ||
return value === null; | ||
} | ||
function isNullOrUndefined(value) { | ||
return isUndefined(value) || isNull(value); | ||
} | ||
// src/values/string-value.ts | ||
var urlRegex = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i; | ||
var StringValue = class { | ||
constructor(config = {}) { | ||
this.config = { | ||
emptyAllowed: true, | ||
url: false, | ||
...config | ||
}; | ||
this.value = new Value(this.config); | ||
} | ||
validate(value) { | ||
const { emptyAllowed, url, regex, constrainTo } = this.config; | ||
const valueValidation = this.value.validate(value); | ||
if (valueValidation) { | ||
return valueValidation; | ||
} | ||
if (isUndefined(value)) { | ||
return null; | ||
} | ||
if (!isString(value)) { | ||
return "value is not a string."; | ||
} | ||
if (!emptyAllowed && !value.length) { | ||
return "value is an empty string."; | ||
} | ||
if (url && !urlRegex.test(value)) { | ||
return "value is not a valid URL."; | ||
} | ||
if (regex && !regex.test(value)) { | ||
return `value did not match provided regex ${regex}`; | ||
} | ||
if (constrainTo && !constrainTo.includes(value)) { | ||
const values = constrainTo.join(", "); | ||
return `value should be one of: ${values}.`; | ||
} | ||
return null; | ||
} | ||
get default() { | ||
return this.value.default; | ||
} | ||
get required() { | ||
return this.value.required; | ||
} | ||
}; | ||
function isString(value) { | ||
return Object.prototype.toString.call(value) === "[object String]"; | ||
} | ||
const AtomicHostedPage = class { | ||
@@ -156,7 +15,7 @@ constructor(hostRef) { | ||
try { | ||
new Schema({ | ||
organizationId: new StringValue({ required: true, emptyAllowed: false }), | ||
pageId: new StringValue({ required: true, emptyAllowed: false }), | ||
accessToken: new StringValue({ required: true, emptyAllowed: false }), | ||
platformUrl: new StringValue({ required: false, emptyAllowed: false }), | ||
new hostedPages.Schema({ | ||
organizationId: new hostedPages.StringValue({ required: true, emptyAllowed: false }), | ||
pageId: new hostedPages.StringValue({ required: true, emptyAllowed: false }), | ||
accessToken: new hostedPages.StringValue({ required: true, emptyAllowed: false }), | ||
platformUrl: new hostedPages.StringValue({ required: false, emptyAllowed: false }), | ||
}).validate(opts); | ||
@@ -168,32 +27,2 @@ } | ||
} | ||
processHostedPage(hostedPage) { | ||
var _a, _b; | ||
this.element.innerHTML = hostedPage.html; | ||
(_a = hostedPage.javascript) === null || _a === void 0 ? void 0 : _a.forEach((file) => this.insertJS(file)); | ||
(_b = hostedPage.css) === null || _b === void 0 ? void 0 : _b.forEach((file) => this.insertCSS(file)); | ||
} | ||
insertJS(file) { | ||
const script = document.createElement('script'); | ||
if (file.isModule) { | ||
script.type = 'module'; | ||
} | ||
if (file.url) { | ||
script.src = file.url; | ||
} | ||
if (file.inlineContent) { | ||
script.innerHTML = file.inlineContent; | ||
} | ||
document.head.appendChild(script); | ||
} | ||
insertCSS(file) { | ||
const link = document.createElement('link'); | ||
link.rel = 'stylesheet'; | ||
if (file.url) { | ||
link.href = file.url; | ||
} | ||
if (file.inlineContent) { | ||
link.innerHTML = file.inlineContent; | ||
} | ||
document.head.appendChild(link); | ||
} | ||
async initialize(options) { | ||
@@ -208,3 +37,3 @@ this.validateOptions(options); | ||
}); | ||
this.processHostedPage(await pageResponse.json()); | ||
hostedPages.processHostedPage(this.element, await pageResponse.json()); | ||
} | ||
@@ -211,0 +40,0 @@ catch (e) { |
@@ -18,5 +18,5 @@ 'use strict'; | ||
patchBrowser().then(options => { | ||
return index.bootstrapLazy([["atomic-hosted-page.cjs",[[0,"atomic-hosted-page",{"initialize":[64]}]]]], options); | ||
return index.bootstrapLazy([["atomic-hosted-page.cjs",[[0,"atomic-hosted-page",{"initialize":[64]}]]],["atomic-simple-builder.cjs",[[0,"atomic-simple-builder",{"initialize":[64]}]]]], options); | ||
}); | ||
//# sourceMappingURL=atomic-hosted-page.cjs.js.map |
@@ -17,3 +17,3 @@ 'use strict'; | ||
return patchEsm().then(() => { | ||
return index.bootstrapLazy([["atomic-hosted-page.cjs",[[0,"atomic-hosted-page",{"initialize":[64]}]]]], options); | ||
return index.bootstrapLazy([["atomic-hosted-page.cjs",[[0,"atomic-hosted-page",{"initialize":[64]}]]],["atomic-simple-builder.cjs",[[0,"atomic-simple-builder",{"initialize":[64]}]]]], options); | ||
}); | ||
@@ -20,0 +20,0 @@ }; |
import { r as registerInstance, g as getElement } from './index-7c6277cb.js'; | ||
import { S as Schema, a as StringValue, p as processHostedPage } from './hosted-pages-b5ef1bd0.js'; | ||
/** | ||
* @license | ||
* | ||
* Copyright 2023 Coveo Solutions Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
// src/schema.ts | ||
function buildSchemaValidationError(errors, context) { | ||
const message = ` | ||
The following properties are invalid: | ||
${errors.join("\n ")} | ||
${context} | ||
`; | ||
return new SchemaValidationError(message); | ||
} | ||
var SchemaValidationError = class extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = "SchemaValidationError"; | ||
} | ||
}; | ||
var Schema = class { | ||
constructor(definition) { | ||
this.definition = definition; | ||
} | ||
validate(values = {}, message = "") { | ||
const mergedValues = { | ||
...this.default, | ||
...values | ||
}; | ||
const errors = []; | ||
for (const property in this.definition) { | ||
const error = this.definition[property].validate(mergedValues[property]); | ||
error && errors.push(`${property}: ${error}`); | ||
} | ||
if (errors.length) { | ||
throw buildSchemaValidationError(errors, message); | ||
} | ||
return mergedValues; | ||
} | ||
get default() { | ||
const defaultValues = {}; | ||
for (const property in this.definition) { | ||
const defaultValue = this.definition[property].default; | ||
if (defaultValue !== void 0) { | ||
defaultValues[property] = defaultValue; | ||
} | ||
} | ||
return defaultValues; | ||
} | ||
}; | ||
// src/values/value.ts | ||
var Value = class { | ||
constructor(baseConfig = {}) { | ||
this.baseConfig = baseConfig; | ||
} | ||
validate(value) { | ||
if (this.baseConfig.required && isNullOrUndefined(value)) { | ||
return "value is required."; | ||
} | ||
return null; | ||
} | ||
get default() { | ||
return this.baseConfig.default instanceof Function ? this.baseConfig.default() : this.baseConfig.default; | ||
} | ||
get required() { | ||
return this.baseConfig.required === true; | ||
} | ||
}; | ||
function isUndefined(value) { | ||
return value === void 0; | ||
} | ||
function isNull(value) { | ||
return value === null; | ||
} | ||
function isNullOrUndefined(value) { | ||
return isUndefined(value) || isNull(value); | ||
} | ||
// src/values/string-value.ts | ||
var urlRegex = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i; | ||
var StringValue = class { | ||
constructor(config = {}) { | ||
this.config = { | ||
emptyAllowed: true, | ||
url: false, | ||
...config | ||
}; | ||
this.value = new Value(this.config); | ||
} | ||
validate(value) { | ||
const { emptyAllowed, url, regex, constrainTo } = this.config; | ||
const valueValidation = this.value.validate(value); | ||
if (valueValidation) { | ||
return valueValidation; | ||
} | ||
if (isUndefined(value)) { | ||
return null; | ||
} | ||
if (!isString(value)) { | ||
return "value is not a string."; | ||
} | ||
if (!emptyAllowed && !value.length) { | ||
return "value is an empty string."; | ||
} | ||
if (url && !urlRegex.test(value)) { | ||
return "value is not a valid URL."; | ||
} | ||
if (regex && !regex.test(value)) { | ||
return `value did not match provided regex ${regex}`; | ||
} | ||
if (constrainTo && !constrainTo.includes(value)) { | ||
const values = constrainTo.join(", "); | ||
return `value should be one of: ${values}.`; | ||
} | ||
return null; | ||
} | ||
get default() { | ||
return this.value.default; | ||
} | ||
get required() { | ||
return this.value.required; | ||
} | ||
}; | ||
function isString(value) { | ||
return Object.prototype.toString.call(value) === "[object String]"; | ||
} | ||
const AtomicHostedPage = class { | ||
@@ -162,32 +21,2 @@ constructor(hostRef) { | ||
} | ||
processHostedPage(hostedPage) { | ||
var _a, _b; | ||
this.element.innerHTML = hostedPage.html; | ||
(_a = hostedPage.javascript) === null || _a === void 0 ? void 0 : _a.forEach((file) => this.insertJS(file)); | ||
(_b = hostedPage.css) === null || _b === void 0 ? void 0 : _b.forEach((file) => this.insertCSS(file)); | ||
} | ||
insertJS(file) { | ||
const script = document.createElement('script'); | ||
if (file.isModule) { | ||
script.type = 'module'; | ||
} | ||
if (file.url) { | ||
script.src = file.url; | ||
} | ||
if (file.inlineContent) { | ||
script.innerHTML = file.inlineContent; | ||
} | ||
document.head.appendChild(script); | ||
} | ||
insertCSS(file) { | ||
const link = document.createElement('link'); | ||
link.rel = 'stylesheet'; | ||
if (file.url) { | ||
link.href = file.url; | ||
} | ||
if (file.inlineContent) { | ||
link.innerHTML = file.inlineContent; | ||
} | ||
document.head.appendChild(link); | ||
} | ||
async initialize(options) { | ||
@@ -202,3 +31,3 @@ this.validateOptions(options); | ||
}); | ||
this.processHostedPage(await pageResponse.json()); | ||
processHostedPage(this.element, await pageResponse.json()); | ||
} | ||
@@ -205,0 +34,0 @@ catch (e) { |
@@ -16,5 +16,5 @@ import { p as promiseResolve, b as bootstrapLazy } from './index-7c6277cb.js'; | ||
patchBrowser().then(options => { | ||
return bootstrapLazy([["atomic-hosted-page",[[0,"atomic-hosted-page",{"initialize":[64]}]]]], options); | ||
return bootstrapLazy([["atomic-hosted-page",[[0,"atomic-hosted-page",{"initialize":[64]}]]],["atomic-simple-builder",[[0,"atomic-simple-builder",{"initialize":[64]}]]]], options); | ||
}); | ||
//# sourceMappingURL=atomic-hosted-page.js.map |
@@ -13,3 +13,3 @@ import { p as promiseResolve, b as bootstrapLazy } from './index-7c6277cb.js'; | ||
return patchEsm().then(() => { | ||
return bootstrapLazy([["atomic-hosted-page",[[0,"atomic-hosted-page",{"initialize":[64]}]]]], options); | ||
return bootstrapLazy([["atomic-hosted-page",[[0,"atomic-hosted-page",{"initialize":[64]}]]],["atomic-simple-builder",[[0,"atomic-simple-builder",{"initialize":[64]}]]]], options); | ||
}); | ||
@@ -16,0 +16,0 @@ }; |
@@ -10,4 +10,7 @@ /* eslint-disable */ | ||
interface AtomicHostedPage { | ||
"initialize": (options: AtomicPageInitializationOptions) => Promise<void>; | ||
"initialize": (options: AtomicHostedPageInitializationOptions) => Promise<void>; | ||
} | ||
interface AtomicSimpleBuilder { | ||
"initialize": (options: AtomicSimpleBuilderInitializationOptions) => Promise<void>; | ||
} | ||
} | ||
@@ -21,4 +24,11 @@ declare global { | ||
}; | ||
interface HTMLAtomicSimpleBuilderElement extends Components.AtomicSimpleBuilder, HTMLStencilElement { | ||
} | ||
var HTMLAtomicSimpleBuilderElement: { | ||
prototype: HTMLAtomicSimpleBuilderElement; | ||
new (): HTMLAtomicSimpleBuilderElement; | ||
}; | ||
interface HTMLElementTagNameMap { | ||
"atomic-hosted-page": HTMLAtomicHostedPageElement; | ||
"atomic-simple-builder": HTMLAtomicSimpleBuilderElement; | ||
} | ||
@@ -29,4 +39,7 @@ } | ||
} | ||
interface AtomicSimpleBuilder { | ||
} | ||
interface IntrinsicElements { | ||
"atomic-hosted-page": AtomicHostedPage; | ||
"atomic-simple-builder": AtomicSimpleBuilder; | ||
} | ||
@@ -39,4 +52,5 @@ } | ||
"atomic-hosted-page": LocalJSX.AtomicHostedPage & JSXBase.HTMLAttributes<HTMLAtomicHostedPageElement>; | ||
"atomic-simple-builder": LocalJSX.AtomicSimpleBuilder & JSXBase.HTMLAttributes<HTMLAtomicSimpleBuilderElement>; | ||
} | ||
} | ||
} |
{ | ||
"name": "@coveo/atomic-hosted-page", | ||
"description": "Web Component used to inject a Coveo Hosted Search Page in the DOM.", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
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
820966
62
3819
8