@telia-ace/widget-core-flamingo 1.1.119 → 1.1.120-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap.d.ts +6 -0
- package/components/ace-widget.component.d.ts +21 -0
- package/components/trigger-slot.component.d.ts +8 -0
- package/components/trigger.component.d.ts +24 -0
- package/components/unresolved.component.d.ts +7 -0
- package/components/widget.component.d.ts +18 -0
- package/components/wrapper.component.d.ts +20 -0
- package/index.d.ts +14 -0
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/mocks/configs.d.ts +168 -0
- package/models/application.d.ts +52 -0
- package/models/container.d.ts +16 -0
- package/models/environment.d.ts +25 -0
- package/models/site.d.ts +18 -0
- package/package.json +1 -1
- package/services/component-platform.d.ts +13 -0
- package/services/component-resolver.d.ts +8 -0
- package/services/http-client.service.d.ts +18 -0
- package/services/site-api.d.ts +7 -0
- package/services/storage.service.d.ts +21 -0
- package/services/texts.service.d.ts +10 -0
- package/services/widget-api.d.ts +15 -0
- package/types.d.ts +73 -0
- package/utils/map-branding.d.ts +1 -0
package/bootstrap.d.ts
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
import { Environment } from './models/environment';
|
2
|
+
import { InitConfig } from './types';
|
3
|
+
import { IHttpClient } from './services/http-client.service';
|
4
|
+
export declare const bootstrap: (urlOrConfig: string | InitConfig, handler: (environment: Environment) => void, config?: {
|
5
|
+
httpClient?: IHttpClient;
|
6
|
+
}) => Promise<void>;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { LitElement, nothing } from 'lit';
|
2
|
+
import { Application } from '../models/application';
|
3
|
+
import { Trigger } from './trigger.component';
|
4
|
+
declare enum AceWidgetState {
|
5
|
+
Deactivated = "deactivated",
|
6
|
+
Activated = "activated"
|
7
|
+
}
|
8
|
+
export declare class AceWidget extends LitElement {
|
9
|
+
static styles: import('lit').CSSResult[];
|
10
|
+
name: string;
|
11
|
+
widget?: Application;
|
12
|
+
status: AceWidgetState;
|
13
|
+
constructor();
|
14
|
+
connectedCallback(): Promise<void>;
|
15
|
+
disconnectedCallback(): void;
|
16
|
+
onEnvironmentCreated(event: any): Promise<void>;
|
17
|
+
activate(): Promise<void>;
|
18
|
+
getGlobalEnvironment(): Promise<void>;
|
19
|
+
render(): typeof nothing | Trigger | import('./wrapper.component').Wrapper | undefined;
|
20
|
+
}
|
21
|
+
export {};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { LitElement } from 'lit';
|
2
|
+
import { WidgetAnchor } from '../types';
|
3
|
+
export declare class TriggerSlot extends LitElement {
|
4
|
+
static styles: import('lit').CSSResult[];
|
5
|
+
anchor: WidgetAnchor;
|
6
|
+
appendChild<T extends Node>(node: T): T;
|
7
|
+
render(): symbol;
|
8
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { LitElement, nothing } from 'lit';
|
2
|
+
import { Application } from '../models/application';
|
3
|
+
import { Ref } from 'lit-html/directives/ref.js';
|
4
|
+
import { BehaviorSubject, Subject } from 'rxjs';
|
5
|
+
export declare class Trigger extends LitElement {
|
6
|
+
static styles: import('lit').CSSResult[];
|
7
|
+
application?: Application;
|
8
|
+
active: boolean;
|
9
|
+
triggerVisible: boolean;
|
10
|
+
loaded: boolean;
|
11
|
+
icon: any;
|
12
|
+
containerRef: Ref<HTMLDivElement>;
|
13
|
+
widgetActive$: BehaviorSubject<boolean>;
|
14
|
+
componentIsDestroyed$: Subject<void>;
|
15
|
+
connectedCallback(): Promise<void>;
|
16
|
+
disconnectedCallback(): void;
|
17
|
+
toggleActive(): void;
|
18
|
+
notify(type: string, data?: Record<string, any>): void;
|
19
|
+
_applyBranding(): void;
|
20
|
+
_renderSymbol(): Promise<typeof nothing | import('lit-html').TemplateResult<1>>;
|
21
|
+
hideTrigger(): void;
|
22
|
+
showTrigger(): void;
|
23
|
+
render(): import('lit-html').TemplateResult<1>;
|
24
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { LitElement } from 'lit';
|
2
|
+
declare const UnresolvedComponent_base: (new (...args: any[]) => import('./widget.component').WidgetComponentType) & typeof LitElement;
|
3
|
+
export declare class UnresolvedComponent extends UnresolvedComponent_base {
|
4
|
+
static styles: import('lit').CSSResult[];
|
5
|
+
render(): import('lit-html').TemplateResult<1>;
|
6
|
+
}
|
7
|
+
export {};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { LitElement } from 'lit';
|
2
|
+
import { Application } from '../models/application';
|
3
|
+
type Constructor<T = object> = new (...args: any[]) => T;
|
4
|
+
export declare class WidgetComponentType {
|
5
|
+
name: string;
|
6
|
+
type: string;
|
7
|
+
application: Application;
|
8
|
+
parent?: WidgetComponentType;
|
9
|
+
properties: Record<string, any>;
|
10
|
+
context: Record<string, any>;
|
11
|
+
layout: Record<string, any>;
|
12
|
+
writeProperties: (properties: Record<string, any>) => void;
|
13
|
+
writeContext: (context: Record<string, any>) => void;
|
14
|
+
writeLayout: (layout: Record<string, any>) => void;
|
15
|
+
addChild: (node: WidgetComponentType) => void;
|
16
|
+
}
|
17
|
+
export declare const WidgetComponent: <T extends Constructor<LitElement>>(superClass: T) => Constructor<WidgetComponentType> & T;
|
18
|
+
export {};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { LitElement, PropertyValueMap } from 'lit';
|
2
|
+
import { Ref } from 'lit/directives/ref.js';
|
3
|
+
import { Application } from '../models/application';
|
4
|
+
import { BehaviorSubject } from 'rxjs';
|
5
|
+
export declare const applicationContext: {
|
6
|
+
__context__: Application;
|
7
|
+
};
|
8
|
+
export declare class Wrapper extends LitElement {
|
9
|
+
static styles: import('lit').CSSResult;
|
10
|
+
private nodes;
|
11
|
+
wrapperRef: Ref<HTMLDivElement>;
|
12
|
+
fullscreen: boolean;
|
13
|
+
application: Application;
|
14
|
+
isReady: BehaviorSubject<boolean>;
|
15
|
+
addChild(node: any): void;
|
16
|
+
private applyBranding;
|
17
|
+
private applyStyles;
|
18
|
+
protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void;
|
19
|
+
render(): import('lit-html').TemplateResult<1>;
|
20
|
+
}
|
package/index.d.ts
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
export { Container } from './models/container';
|
2
|
+
export { Application } from './models/application';
|
3
|
+
export { Site } from './models/site';
|
4
|
+
export { Environment } from './models/environment';
|
5
|
+
export { bootstrap } from './bootstrap';
|
6
|
+
export { Trigger } from './components/trigger.component';
|
7
|
+
export { WidgetComponent } from './components/widget.component';
|
8
|
+
export { AceWidget } from './components/ace-widget.component';
|
9
|
+
export { HttpClient, createHttpClient } from './services/http-client.service';
|
10
|
+
export { StorageService, StorageCategory } from './services/storage.service';
|
11
|
+
export { applicationContext } from './components/wrapper.component';
|
12
|
+
export type { IHttpClient } from './services/http-client.service';
|
13
|
+
export type { WidgetComponentType } from './components/widget.component';
|
14
|
+
export type { SiteConfig, WidgetConfig } from './types';
|
package/index.js
CHANGED
@@ -451,7 +451,7 @@
|
|
451
451
|
:host(.expanded.embedded) {
|
452
452
|
animation: none;
|
453
453
|
}
|
454
|
-
`;let U=Ut;Se([m({attribute:!0})],U.prototype,"fullscreen");Se([m({attribute:!1}),ki({context:Ee})],U.prototype,"application");class Ri{constructor(){this.root=this.createRoot()}createComponentModel(t,e){this.root.application=e;const i=a=>{if(Array.isArray(a)){const[c,...l]=a;return{definitionId:c,overrides:l}}return{definitionId:a,overrides:[]}},s=(a,c,l,h)=>{l.forEach(d=>{const u=i(d),f=h[u.definitionId];if(!f){console.error(`No definition found for component type '${u.definitionId}'.`);return}const g=a.createNode(f.type,f.type);g&&(g.name=u.definitionId,g.application=e,f.properties&&g.writeProperties(f.properties),f.context&&g.writeContext(f.context),f.layout&&g.writeLayout(f.layout),c.addChild(g),f.children&&s(a,g,f.children,h))})},{entry:o,components:n}=t;return s(this,this.root,[o],n),this.root}createRoot(){return typeof window<"u"&&(window.customElements.get("ace-wrapper")||window.customElements.define("ace-wrapper",U)),document.createElement("ace-wrapper")}createNode(t,e){if(!this.resolveComponent(e))return console.warn(`Unable to resolve component: ${e}`),new it;const s=document.createElement(`ace-${e}`);return s.type=e,s.name=t,s}resolveComponent(t){return customElements.get(`ace-${t}`)}getRoot(){return this.root}}const st=class st{constructor(){this.components=new Map}getComponent(t){const e=this.components.get(t);return e||console.warn(`Unable to resolve component: ${t}. You most likely forgot to register the required plugin.`),e}registerComponent(t,e){this.components.set(t,e)}async loadComponents(){const t=[...this.components.entries()].map(([e,i])=>i.then(s=>{this.defineAsWebComponent(e,s.default)}));await Promise.all(t)}defineAsWebComponent(t,e){const i=st.ResolveWebComponentName(t);customElements.get(i)||customElements.define(i,e)}};st.ResolveWebComponentName=t=>`ace-${t}`;let At=st;var y=(r=>(r.Necessary="necessary",r.Functional="functional",r.Analytics="analytics",r))(y||{});class Pe{constructor(t,e,i,s){this.disallowedKeys=[],this.widgetId=t,this.storage=e==="localStorage"?window.localStorage:window.sessionStorage,this.policy=i,this.storageEntries=s}set(t,e){if(this.disallowedKeys.includes(t))return;const i=this.storageEntries[t];if(!i){console.warn(`Storage key '${t}' is not defined.`);return}const s=i.category;if(this.policy[s]){const o={value:e,category:s};this.storage.setItem(this._prefixKey(t),JSON.stringify(o))}else console.warn(`Storage policy does not allow storing items in category: ${s}`)}get(t){const e=this.storage.getItem(this._prefixKey(t));if(!e)return null;try{const i=JSON.parse(e);return this.policy[i.category]?i.value:(console.warn(`Storage policy does not allow retrieving items from category: ${i.category}`),null)}catch{return null}}removeItem(t){this.storage.removeItem(this._prefixKey(t))}enforcePolicy(){var t;for(const[e,i]of Object.entries(this.storage)){const s=(t=JSON.parse(i))==null?void 0:t.category;this.policy[s]||this.storage.removeItem(e)}}updatePolicy(t){this.policy=t,this.enforcePolicy()}disallowKey(t){this.disallowedKeys.includes(t)||this.disallowedKeys.push(t),this.removeItem(t)}stringify(){return JSON.stringify(this.storage)}_prefixKey(t){return`ace_${this.widgetId.substring(0,7)}-${t}`}}class Mi{constructor(){this.texts=new Map}loadTexts(t){this.texts=new Map(Object.entries(t))}get(t,e){const i=this.texts.get(t);return i||e||null}getOrFallback(t,e){return this.texts.get(t)||e}}const Ni="##__WIDGETS_VERSION__##";class Ui{constructor(t){this.widget=t,this.name=t.name}open(t={}){this.widget.appendToDOM(t)}close(){this.widget.hide()}setFullscreenMode(t){this.widget.setFullscreenMode(t)}setZIndex(t){this.widget.setZIndex(t)}version(){return{version:Ni}}}class Oe{constructor(t,e,i,s,o){this.id=t,this.name=e,this.container=i,this.settings=s,this.options=o,this.platform=new Ri,this.texts=new Mi,this.renderStrategy=$.Inline,this.fullscreen=!1,this.anchor="BottomRight",this.autoActivate=!1,this.plugins=[],this.componentResolver=new At,this.components=[],this.trigger=null,this.api=new Ui(this),this.onMessageReceived=async a=>{var l;const c=a.data;switch(c.type){case"set-storage-policies":{const{policies:h}=c.data||[],d={[y.Analytics]:h.includes("analytics"),[y.Necessary]:h.includes("necessary"),[y.Functional]:h.includes("functional")};this.storage.updatePolicy(d);return}case"disallow-storage-key":{const{storageKey:h}=c.data||null;h&&this.storage.disallowKey(h);return}case"set-fullscreen-mode":{const{value:h}=c.data;typeof h=="boolean"&&this.setFullscreenMode(h);return}case"open":{this.appendToDOM();return}case"close":{this.hide();return}case"set-z-index":{const{zIndex:h}=c.data||null;h&&this.setZIndex(h);return}case"deactivate-widget":{const h=this.storage.get("open");this.hide(),(l=this.trigger)==null||l.hideTrigger(),h&&this.storage.set("open",!0);return}case"set-open":{typeof c.data.value=="boolean"&&(this.storage.set("open",c.data.value),this.root&&c.data.value===!0&&!this.root.isReady.getValue()&&this.root.isReady.next(!0));return}default:return}},this.renderStrategy=this.options.renderStrategy||$.Inline,this.triggerIcon=this.options.triggerIcon;const n={[y.Necessary]:!0,[y.Functional]:!0,[y.Analytics]:!0};this.storage=new Pe(this.id,"sessionStorage",n,this.settings.storage),typeof o.autoActivate=="boolean"&&(this.autoActivate=o.autoActivate),o.anchor&&(this.anchor=o.anchor),this.container.register("$settings",s),this.texts.loadTexts(s.texts||{}),window.addEventListener("message",this.onMessageReceived)}async activate(){if(await this.loadPlugins(),await this.componentResolver.loadComponents(),this.root=this.platform.createComponentModel(this.settings,this),this.container.setState(ue.Ready),this.autoActivate){const t=this.render();t&&this._getTargetElement().appendChild(t)}if(window!=null&&window.parent){const{version:t}=this.api.version();window.parent.postMessage({type:"widget-activated",data:{widgetId:this.id,version:t,storage:this.storage.stringify()}},"*")}}async loadPlugins(){for await(const t of this.plugins)await t(this)}styles(){return this.settings.styles||{}}branding(){return this.settings.branding||{}}plugin(t){return this.plugins.push(t),this}appendToDOM(t={}){this.root&&(this.root.classList.add("expanded"),this.root.classList.remove("hidden"),document.body.appendChild(this.root)),t.ignoreStorage||this.storage.set("open",!0)}hide(){this.root&&(this.root.classList.add("hidden"),this.root.classList.remove("expanded")),this.storage.set("open",!1)}setZIndex(t){this.root&&(this.root.style.zIndex=t.toString())}mute(){this.storage.set("muteAudioNotifications",!0)}unmute(){this.storage.set("muteAudioNotifications",!1)}registerComponent(t,e){this.componentResolver.registerComponent(t,e)}resolveComponent(t){return this.componentResolver.getComponent(t)}mountComponent(t){this.components.push(t)}getComponent(t){const e=this.components.find(i=>i.type===t);return e||null}_getTargetElement(){let t="bottom-right";if(this.anchor==="BottomRight"?t="bottom-right":this.anchor==="BottomLeft"&&(t="bottom-left"),this.renderStrategy===$.Trigger){let e=document.querySelector(`ace-trigger-slot.${t}`);return e||(e=new q,e.anchor=this.anchor,document.body.appendChild(e)),e}return document.body}_isEmbeddedInIFrame(){return window.self!==window.top&&window.__RENDER_WIDGET_FULLSCREEN__}setFullscreenMode(t){this.fullscreen=t,this.root&&(this.root.fullscreen=!0)}render(){if(this._isEmbeddedInIFrame())return this.root;if(!this._isEmbeddedInIFrame()&&this.root&&(this.root.isReady.getValue()||this.root.isReady.next(!0)),this.renderStrategy===$.Trigger){const t=new b;return t.application=this,this.trigger=t,this.storage.get("open")&&this.trigger.toggleActive(),t}return this.root}}const Li=r=>new L(r),rt=class rt{constructor(t=rt.endpoint){this._endpoint=t}async getSite(t){const i=await(await fetch(t)).json();return i?{id:i.id,triggers:i.triggers||[],apps:(i.widgets||[]).map(s=>{let o=$.Trigger;s.renderStrategy.toLowerCase()==="inline"&&(o=$.Inline);const n=s.widgetId?s.widgetId:s.id,a=typeof s.autoActivate=="boolean"?s.autoActivate:!1,c=typeof s.anchor=="string"?s.anchor:"BottomRight",l=typeof s.triggerIcon=="string"?s.triggerIcon:"question";return{id:n,widgetId:n,renderStrategy:o,autoActivate:a,anchor:c,triggerIcon:{type:"Telia",content:l}}})}:null}async getWidget(t){const i=await(await fetch(`${this._endpoint}/widget/${t}`)).json();return i?{name:i.name,config:JSON.parse(i.configuration)}:null}};rt.endpoint="https://widgets.ace.teliacompany.net/api";let L=rt;class ji{constructor(t){this.site=t}storagePolicy(t){var i;(((i=this.site.environment)==null?void 0:i.applications)||[]).forEach(s=>{if(s.storage){const o={[y.Analytics]:t.includes("analytics"),[y.Necessary]:t.includes("necessary"),[y.Functional]:t.includes("functional")};s.storage.updatePolicy(o)}})}disallowStorageKey(t){var e;(((e=this.site.environment)==null?void 0:e.applications)||[]).forEach(i=>{i.storage&&i.storage.disallowKey(t)})}}class Ie{constructor(){this.applications=[],this.container=new $t("environment",this),this.bootstrapped=!1,this.site=null,this.widgetAPIHandlers=new Map,this.siteConfigurationHandlers=[],setTimeout(()=>{this.notifyWidgetsOfCreation()},1e3)}async bootstrap(){await this.activate(),this.siteConfigurationHandlers.forEach(t=>{this.site&&t(this.site.api)});for(const[t,e]of this.widgetAPIHandlers)e.forEach(i=>{i()});this.bootstrapped=!0}async activate(){var e;const t=this.applications.filter(i=>i.autoActivate);(((e=this.site)==null?void 0:e.triggers)||[]).filter(i=>i.triggerType==="visit").forEach(i=>{const s=window.location.pathname,o=i.condition.outputs||[];i.condition.type==="url"&&o.forEach(n=>{const a=n.action.type==="render_widget";if((n.value===s||n.value==="*")&&a){let l={widgetId:""};try{l=JSON.parse(n.action.data)}catch{l={widgetId:""}}const h=t.findIndex(u=>u.id===l.widgetId)>-1,d=this.applications.find(u=>u.id===l.widgetId);d&&!h&&(d.autoActivate=!0,t.push(d))}})});for await(const i of t)await i.activate()}notifyWidgetsOfCreation(){document.querySelectorAll("ace-widget").forEach(e=>{const i=this.applications.find(s=>s.name===e.name);i&&e.dispatchEvent(new CustomEvent("environment-created",{detail:{widget:i}}))})}configure(t){if(!this.site||!this.bootstrapped){this.siteConfigurationHandlers.push(t);return}t(this.site.api)}widget(t,e){const i=this.applications.find(s=>s.name===t);if(!i){const s=this.widgetAPIHandlers.get(t)||[];s.push(()=>{const o=this.applications.find(n=>n.name===t);e(o==null?void 0:o.api)}),this.widgetAPIHandlers.set(t,s);return}e(i==null?void 0:i.api)}registerApp(t,e,i,s){const o=new $t(e,this),n=new Oe(t,e,o,i,s);this.applications.push(n)}registerSite(t){this.site=t}plugin(t){return this.applications.forEach(e=>{e.plugin(t)}),this}}class ke{constructor(t){this.configurations=[],this.httpClient=new L,this.api=new ji(this),this.triggers=[],this.httpClient=new L,typeof t=="string"?this.url=t:(t.httpClient&&(this.httpClient=t.httpClient),this.loadFromConfig(t))}async load(t){const e=await this.httpClient.getSite(t);if(!e){console.warn(`Unable to load site from the url provided: ${t}`);return}this.configurations=e.apps,this.triggers=e.triggers||[]}loadFromConfig(t){this.configurations=t.apps.map(e=>({id:"",renderStrategy:e.renderStrategy,widgetId:e.widgetId,autoActivate:e.autoActivate,anchor:e.anchor,triggerIcon:{type:"Telia",content:e.triggerIcon||"question"}}))}setHttpClient(t){this.httpClient=t}async bootstrap(t){var e;this.url&&await this.load(this.url),this.environment=new Ie,this.addGlobal(this.environment);for await(const i of this.configurations){const s=await this.httpClient.getWidget(i.widgetId);s&&((e=this.environment)==null||e.registerApp(i.widgetId,s.name,s.config,{renderStrategy:i.renderStrategy,triggerIcon:i.triggerIcon,autoActivate:i.autoActivate,anchor:i.anchor}))}t(this.environment),this.environment.registerSite(this),await this.environment.bootstrap()}addGlobal(t){const e=globalThis.ace;((e==null?void 0:e._w)||[]).forEach(([i,s])=>{t.widget(i,s)}),((e==null?void 0:e._c)||[]).forEach(i=>{t.configure(i)}),globalThis.ace=t}}var Hi=Object.defineProperty,Tt=(r,t,e,i)=>{for(var s=void 0,o=r.length-1,n;o>=0;o--)(n=r[o])&&(s=n(t,e,s)||s);return s&&Hi(t,e,s),s};const Lt=class Lt extends A{constructor(){super(),this.status="deactivated",this.addEventListener("environment-created",this.onEnvironmentCreated)}async connectedCallback(){super.connectedCallback(),await this.getGlobalEnvironment()}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("environment-created",this.onEnvironmentCreated)}async onEnvironmentCreated(t){this.widget=t.detail.widget,await this.activate(),this.requestUpdate()}async activate(){this.widget&&(await this.widget.activate(),this.status="activated")}async getGlobalEnvironment(){const t=globalThis.widgets;t&&(this.widget=t.applications.find(e=>e.name===this.name),await this.activate())}render(){if(!this.widget||this.status!=="activated")return p;if(this.widget.renderStrategy===$.Trigger){const t=new b;return t.application=this.widget,t}return this.widget.render()}};Lt.styles=[j`
|
454
|
+
`;let U=Ut;Se([m({attribute:!0})],U.prototype,"fullscreen");Se([m({attribute:!1}),ki({context:Ee})],U.prototype,"application");class Ri{constructor(){this.root=this.createRoot()}createComponentModel(t,e){this.root.application=e;const i=a=>{if(Array.isArray(a)){const[c,...l]=a;return{definitionId:c,overrides:l}}return{definitionId:a,overrides:[]}},s=(a,c,l,h)=>{l.forEach(d=>{const u=i(d),f=h[u.definitionId];if(!f){console.error(`No definition found for component type '${u.definitionId}'.`);return}const g=a.createNode(f.type,f.type);g&&(g.name=u.definitionId,g.application=e,f.properties&&g.writeProperties(f.properties),f.context&&g.writeContext(f.context),f.layout&&g.writeLayout(f.layout),c.addChild(g),f.children&&s(a,g,f.children,h))})},{entry:o,components:n}=t;return s(this,this.root,[o],n),this.root}createRoot(){return typeof window<"u"&&(window.customElements.get("ace-wrapper")||window.customElements.define("ace-wrapper",U)),document.createElement("ace-wrapper")}createNode(t,e){if(!this.resolveComponent(e))return console.warn(`Unable to resolve component: ${e}`),new it;const s=document.createElement(`ace-${e}`);return s.type=e,s.name=t,s}resolveComponent(t){return customElements.get(`ace-${t}`)}getRoot(){return this.root}}const st=class st{constructor(){this.components=new Map}getComponent(t){const e=this.components.get(t);return e||console.warn(`Unable to resolve component: ${t}. You most likely forgot to register the required plugin.`),e}registerComponent(t,e){this.components.set(t,e)}async loadComponents(){const t=[...this.components.entries()].map(([e,i])=>i.then(s=>{this.defineAsWebComponent(e,s.default)}));await Promise.all(t)}defineAsWebComponent(t,e){const i=st.ResolveWebComponentName(t);customElements.get(i)||customElements.define(i,e)}};st.ResolveWebComponentName=t=>`ace-${t}`;let At=st;var y=(r=>(r.Necessary="necessary",r.Functional="functional",r.Analytics="analytics",r))(y||{});class Pe{constructor(t,e,i,s){this.disallowedKeys=[],this.widgetId=t,this.storage=e==="localStorage"?window.localStorage:window.sessionStorage,this.policy=i,this.storageEntries=s}set(t,e){if(this.disallowedKeys.includes(t))return;const i=this.storageEntries[t];if(!i){console.warn(`Storage key '${t}' is not defined.`);return}const s=i.category;if(this.policy[s]){const o={value:e,category:s};this.storage.setItem(this._prefixKey(t),JSON.stringify(o))}else console.warn(`Storage policy does not allow storing items in category: ${s}`)}get(t){const e=this.storage.getItem(this._prefixKey(t));if(!e)return null;try{const i=JSON.parse(e);return this.policy[i.category]?i.value:(console.warn(`Storage policy does not allow retrieving items from category: ${i.category}`),null)}catch{return null}}removeItem(t){this.storage.removeItem(this._prefixKey(t))}enforcePolicy(){var t;for(const[e,i]of Object.entries(this.storage)){const s=(t=JSON.parse(i))==null?void 0:t.category;this.policy[s]||this.storage.removeItem(e)}}updatePolicy(t){this.policy=t,this.enforcePolicy()}disallowKey(t){this.disallowedKeys.includes(t)||this.disallowedKeys.push(t),this.removeItem(t)}stringify(){return JSON.stringify(this.storage)}_prefixKey(t){return`ace_${this.widgetId.substring(0,7)}-${t}`}}class Mi{constructor(){this.texts=new Map}loadTexts(t){this.texts=new Map(Object.entries(t))}get(t,e){const i=this.texts.get(t);return i||e||null}getOrFallback(t,e){return this.texts.get(t)||e}}const Ni="1.1.120-rc.1";class Ui{constructor(t){this.widget=t,this.name=t.name}open(t={}){this.widget.appendToDOM(t)}close(){this.widget.hide()}setFullscreenMode(t){this.widget.setFullscreenMode(t)}setZIndex(t){this.widget.setZIndex(t)}version(){return{version:Ni}}}class Oe{constructor(t,e,i,s,o){this.id=t,this.name=e,this.container=i,this.settings=s,this.options=o,this.platform=new Ri,this.texts=new Mi,this.renderStrategy=$.Inline,this.fullscreen=!1,this.anchor="BottomRight",this.autoActivate=!1,this.plugins=[],this.componentResolver=new At,this.components=[],this.trigger=null,this.api=new Ui(this),this.onMessageReceived=async a=>{var l;const c=a.data;switch(c.type){case"set-storage-policies":{const{policies:h}=c.data||[],d={[y.Analytics]:h.includes("analytics"),[y.Necessary]:h.includes("necessary"),[y.Functional]:h.includes("functional")};this.storage.updatePolicy(d);return}case"disallow-storage-key":{const{storageKey:h}=c.data||null;h&&this.storage.disallowKey(h);return}case"set-fullscreen-mode":{const{value:h}=c.data;typeof h=="boolean"&&this.setFullscreenMode(h);return}case"open":{this.appendToDOM();return}case"close":{this.hide();return}case"set-z-index":{const{zIndex:h}=c.data||null;h&&this.setZIndex(h);return}case"deactivate-widget":{const h=this.storage.get("open");this.hide(),(l=this.trigger)==null||l.hideTrigger(),h&&this.storage.set("open",!0);return}case"set-open":{typeof c.data.value=="boolean"&&(this.storage.set("open",c.data.value),this.root&&c.data.value===!0&&!this.root.isReady.getValue()&&this.root.isReady.next(!0));return}default:return}},this.renderStrategy=this.options.renderStrategy||$.Inline,this.triggerIcon=this.options.triggerIcon;const n={[y.Necessary]:!0,[y.Functional]:!0,[y.Analytics]:!0};this.storage=new Pe(this.id,"sessionStorage",n,this.settings.storage),typeof o.autoActivate=="boolean"&&(this.autoActivate=o.autoActivate),o.anchor&&(this.anchor=o.anchor),this.container.register("$settings",s),this.texts.loadTexts(s.texts||{}),window.addEventListener("message",this.onMessageReceived)}async activate(){if(await this.loadPlugins(),await this.componentResolver.loadComponents(),this.root=this.platform.createComponentModel(this.settings,this),this.container.setState(ue.Ready),this.autoActivate){const t=this.render();t&&this._getTargetElement().appendChild(t)}if(window!=null&&window.parent){const{version:t}=this.api.version();window.parent.postMessage({type:"widget-activated",data:{widgetId:this.id,version:t,storage:this.storage.stringify()}},"*")}}async loadPlugins(){for await(const t of this.plugins)await t(this)}styles(){return this.settings.styles||{}}branding(){return this.settings.branding||{}}plugin(t){return this.plugins.push(t),this}appendToDOM(t={}){this.root&&(this.root.classList.add("expanded"),this.root.classList.remove("hidden"),document.body.appendChild(this.root)),t.ignoreStorage||this.storage.set("open",!0)}hide(){this.root&&(this.root.classList.add("hidden"),this.root.classList.remove("expanded")),this.storage.set("open",!1)}setZIndex(t){this.root&&(this.root.style.zIndex=t.toString())}mute(){this.storage.set("muteAudioNotifications",!0)}unmute(){this.storage.set("muteAudioNotifications",!1)}registerComponent(t,e){this.componentResolver.registerComponent(t,e)}resolveComponent(t){return this.componentResolver.getComponent(t)}mountComponent(t){this.components.push(t)}getComponent(t){const e=this.components.find(i=>i.type===t);return e||null}_getTargetElement(){let t="bottom-right";if(this.anchor==="BottomRight"?t="bottom-right":this.anchor==="BottomLeft"&&(t="bottom-left"),this.renderStrategy===$.Trigger){let e=document.querySelector(`ace-trigger-slot.${t}`);return e||(e=new q,e.anchor=this.anchor,document.body.appendChild(e)),e}return document.body}_isEmbeddedInIFrame(){return window.self!==window.top&&window.__RENDER_WIDGET_FULLSCREEN__}setFullscreenMode(t){this.fullscreen=t,this.root&&(this.root.fullscreen=!0)}render(){if(this._isEmbeddedInIFrame())return this.root;if(!this._isEmbeddedInIFrame()&&this.root&&(this.root.isReady.getValue()||this.root.isReady.next(!0)),this.renderStrategy===$.Trigger){const t=new b;return t.application=this,this.trigger=t,this.storage.get("open")&&this.trigger.toggleActive(),t}return this.root}}const Li=r=>new L(r),rt=class rt{constructor(t=rt.endpoint){this._endpoint=t}async getSite(t){const i=await(await fetch(t)).json();return i?{id:i.id,triggers:i.triggers||[],apps:(i.widgets||[]).map(s=>{let o=$.Trigger;s.renderStrategy.toLowerCase()==="inline"&&(o=$.Inline);const n=s.widgetId?s.widgetId:s.id,a=typeof s.autoActivate=="boolean"?s.autoActivate:!1,c=typeof s.anchor=="string"?s.anchor:"BottomRight",l=typeof s.triggerIcon=="string"?s.triggerIcon:"question";return{id:n,widgetId:n,renderStrategy:o,autoActivate:a,anchor:c,triggerIcon:{type:"Telia",content:l}}})}:null}async getWidget(t){const i=await(await fetch(`${this._endpoint}/widget/${t}`)).json();return i?{name:i.name,config:JSON.parse(i.configuration)}:null}};rt.endpoint="https://widgets.ace.teliacompany.net/api";let L=rt;class ji{constructor(t){this.site=t}storagePolicy(t){var i;(((i=this.site.environment)==null?void 0:i.applications)||[]).forEach(s=>{if(s.storage){const o={[y.Analytics]:t.includes("analytics"),[y.Necessary]:t.includes("necessary"),[y.Functional]:t.includes("functional")};s.storage.updatePolicy(o)}})}disallowStorageKey(t){var e;(((e=this.site.environment)==null?void 0:e.applications)||[]).forEach(i=>{i.storage&&i.storage.disallowKey(t)})}}class Ie{constructor(){this.applications=[],this.container=new $t("environment",this),this.bootstrapped=!1,this.site=null,this.widgetAPIHandlers=new Map,this.siteConfigurationHandlers=[],setTimeout(()=>{this.notifyWidgetsOfCreation()},1e3)}async bootstrap(){await this.activate(),this.siteConfigurationHandlers.forEach(t=>{this.site&&t(this.site.api)});for(const[t,e]of this.widgetAPIHandlers)e.forEach(i=>{i()});this.bootstrapped=!0}async activate(){var e;const t=this.applications.filter(i=>i.autoActivate);(((e=this.site)==null?void 0:e.triggers)||[]).filter(i=>i.triggerType==="visit").forEach(i=>{const s=window.location.pathname,o=i.condition.outputs||[];i.condition.type==="url"&&o.forEach(n=>{const a=n.action.type==="render_widget";if((n.value===s||n.value==="*")&&a){let l={widgetId:""};try{l=JSON.parse(n.action.data)}catch{l={widgetId:""}}const h=t.findIndex(u=>u.id===l.widgetId)>-1,d=this.applications.find(u=>u.id===l.widgetId);d&&!h&&(d.autoActivate=!0,t.push(d))}})});for await(const i of t)await i.activate()}notifyWidgetsOfCreation(){document.querySelectorAll("ace-widget").forEach(e=>{const i=this.applications.find(s=>s.name===e.name);i&&e.dispatchEvent(new CustomEvent("environment-created",{detail:{widget:i}}))})}configure(t){if(!this.site||!this.bootstrapped){this.siteConfigurationHandlers.push(t);return}t(this.site.api)}widget(t,e){const i=this.applications.find(s=>s.name===t);if(!i){const s=this.widgetAPIHandlers.get(t)||[];s.push(()=>{const o=this.applications.find(n=>n.name===t);e(o==null?void 0:o.api)}),this.widgetAPIHandlers.set(t,s);return}e(i==null?void 0:i.api)}registerApp(t,e,i,s){const o=new $t(e,this),n=new Oe(t,e,o,i,s);this.applications.push(n)}registerSite(t){this.site=t}plugin(t){return this.applications.forEach(e=>{e.plugin(t)}),this}}class ke{constructor(t){this.configurations=[],this.httpClient=new L,this.api=new ji(this),this.triggers=[],this.httpClient=new L,typeof t=="string"?this.url=t:(t.httpClient&&(this.httpClient=t.httpClient),this.loadFromConfig(t))}async load(t){const e=await this.httpClient.getSite(t);if(!e){console.warn(`Unable to load site from the url provided: ${t}`);return}this.configurations=e.apps,this.triggers=e.triggers||[]}loadFromConfig(t){this.configurations=t.apps.map(e=>({id:"",renderStrategy:e.renderStrategy,widgetId:e.widgetId,autoActivate:e.autoActivate,anchor:e.anchor,triggerIcon:{type:"Telia",content:e.triggerIcon||"question"}}))}setHttpClient(t){this.httpClient=t}async bootstrap(t){var e;this.url&&await this.load(this.url),this.environment=new Ie,this.addGlobal(this.environment);for await(const i of this.configurations){const s=await this.httpClient.getWidget(i.widgetId);s&&((e=this.environment)==null||e.registerApp(i.widgetId,s.name,s.config,{renderStrategy:i.renderStrategy,triggerIcon:i.triggerIcon,autoActivate:i.autoActivate,anchor:i.anchor}))}t(this.environment),this.environment.registerSite(this),await this.environment.bootstrap()}addGlobal(t){const e=globalThis.ace;((e==null?void 0:e._w)||[]).forEach(([i,s])=>{t.widget(i,s)}),((e==null?void 0:e._c)||[]).forEach(i=>{t.configure(i)}),globalThis.ace=t}}var Hi=Object.defineProperty,Tt=(r,t,e,i)=>{for(var s=void 0,o=r.length-1,n;o>=0;o--)(n=r[o])&&(s=n(t,e,s)||s);return s&&Hi(t,e,s),s};const Lt=class Lt extends A{constructor(){super(),this.status="deactivated",this.addEventListener("environment-created",this.onEnvironmentCreated)}async connectedCallback(){super.connectedCallback(),await this.getGlobalEnvironment()}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("environment-created",this.onEnvironmentCreated)}async onEnvironmentCreated(t){this.widget=t.detail.widget,await this.activate(),this.requestUpdate()}async activate(){this.widget&&(await this.widget.activate(),this.status="activated")}async getGlobalEnvironment(){const t=globalThis.widgets;t&&(this.widget=t.applications.find(e=>e.name===this.name),await this.activate())}render(){if(!this.widget||this.status!=="activated")return p;if(this.widget.renderStrategy===$.Trigger){const t=new b;return t.application=this.widget,t}return this.widget.render()}};Lt.styles=[j`
|
455
455
|
:host {
|
456
456
|
display: block;
|
457
457
|
}
|
package/index.mjs
CHANGED
@@ -0,0 +1,168 @@
|
|
1
|
+
export declare const configs: {
|
2
|
+
'my-widget': {
|
3
|
+
entry: string;
|
4
|
+
components: {
|
5
|
+
'root-area': {
|
6
|
+
name: string;
|
7
|
+
type: string;
|
8
|
+
properties: {
|
9
|
+
role: string;
|
10
|
+
'css-grid-template-rows': string;
|
11
|
+
'acss-height': string;
|
12
|
+
'acss-width': string;
|
13
|
+
};
|
14
|
+
context: {};
|
15
|
+
children: string[];
|
16
|
+
layout: {
|
17
|
+
size: string;
|
18
|
+
};
|
19
|
+
};
|
20
|
+
'widget-header': {
|
21
|
+
name: string;
|
22
|
+
type: string;
|
23
|
+
properties: {
|
24
|
+
header: string;
|
25
|
+
};
|
26
|
+
};
|
27
|
+
'main-area': {
|
28
|
+
name: string;
|
29
|
+
type: string;
|
30
|
+
properties: {
|
31
|
+
'css-overflow-y': string;
|
32
|
+
'css-position': string;
|
33
|
+
'css-height': string;
|
34
|
+
'css-flex': number;
|
35
|
+
};
|
36
|
+
children: string[];
|
37
|
+
layout: {
|
38
|
+
size: string;
|
39
|
+
};
|
40
|
+
};
|
41
|
+
copyright: {
|
42
|
+
name: string;
|
43
|
+
type: string;
|
44
|
+
properties: {
|
45
|
+
mode: string;
|
46
|
+
'css-box-shadow': string;
|
47
|
+
'css-z-index': number;
|
48
|
+
};
|
49
|
+
context: {};
|
50
|
+
children: never[];
|
51
|
+
layout: {};
|
52
|
+
};
|
53
|
+
conversation: {
|
54
|
+
name: string;
|
55
|
+
type: string;
|
56
|
+
properties: {
|
57
|
+
inputHidden: boolean;
|
58
|
+
inputDisabled: boolean;
|
59
|
+
multilineForm: boolean;
|
60
|
+
inputPlaceholder: string;
|
61
|
+
sendButtonLabel: string;
|
62
|
+
userLabel: string;
|
63
|
+
providers: string[];
|
64
|
+
knowledgeBotEndpoint: string;
|
65
|
+
secondaryAction: {
|
66
|
+
action: string;
|
67
|
+
label: string;
|
68
|
+
icon: string;
|
69
|
+
};
|
70
|
+
};
|
71
|
+
children: never[];
|
72
|
+
layout: {};
|
73
|
+
plugins: string[];
|
74
|
+
};
|
75
|
+
};
|
76
|
+
branding: {
|
77
|
+
colors: {
|
78
|
+
primaryBackground: string;
|
79
|
+
textOnPrimaryBackground: string;
|
80
|
+
secondaryBackground: string;
|
81
|
+
textOnSecondaryBackground: string;
|
82
|
+
};
|
83
|
+
};
|
84
|
+
};
|
85
|
+
'my-other-widget': {
|
86
|
+
entry: string;
|
87
|
+
components: {
|
88
|
+
'root-area': {
|
89
|
+
name: string;
|
90
|
+
type: string;
|
91
|
+
properties: {
|
92
|
+
role: string;
|
93
|
+
'css-grid-template-rows': string;
|
94
|
+
'acss-height': string;
|
95
|
+
'acss-width': string;
|
96
|
+
};
|
97
|
+
context: {};
|
98
|
+
children: string[];
|
99
|
+
layout: {
|
100
|
+
size: string;
|
101
|
+
};
|
102
|
+
};
|
103
|
+
'widget-header': {
|
104
|
+
name: string;
|
105
|
+
type: string;
|
106
|
+
properties: {
|
107
|
+
header: string;
|
108
|
+
};
|
109
|
+
};
|
110
|
+
'main-area': {
|
111
|
+
name: string;
|
112
|
+
type: string;
|
113
|
+
properties: {
|
114
|
+
'css-overflow-y': string;
|
115
|
+
'css-position': string;
|
116
|
+
'css-height': string;
|
117
|
+
'css-flex': number;
|
118
|
+
};
|
119
|
+
children: string[];
|
120
|
+
layout: {
|
121
|
+
size: string;
|
122
|
+
};
|
123
|
+
};
|
124
|
+
copyright: {
|
125
|
+
name: string;
|
126
|
+
type: string;
|
127
|
+
properties: {
|
128
|
+
mode: string;
|
129
|
+
'css-box-shadow': string;
|
130
|
+
'css-z-index': number;
|
131
|
+
};
|
132
|
+
context: {};
|
133
|
+
children: never[];
|
134
|
+
layout: {};
|
135
|
+
};
|
136
|
+
conversation: {
|
137
|
+
name: string;
|
138
|
+
type: string;
|
139
|
+
properties: {
|
140
|
+
inputHidden: boolean;
|
141
|
+
inputDisabled: boolean;
|
142
|
+
multilineForm: boolean;
|
143
|
+
inputPlaceholder: string;
|
144
|
+
sendButtonLabel: string;
|
145
|
+
userLabel: string;
|
146
|
+
providers: string[];
|
147
|
+
knowledgeBotEndpoint: string;
|
148
|
+
secondaryAction: {
|
149
|
+
action: string;
|
150
|
+
label: string;
|
151
|
+
icon: string;
|
152
|
+
};
|
153
|
+
};
|
154
|
+
children: never[];
|
155
|
+
layout: {};
|
156
|
+
plugins: string[];
|
157
|
+
};
|
158
|
+
};
|
159
|
+
branding: {
|
160
|
+
colors: {
|
161
|
+
primaryBackground: string;
|
162
|
+
textOnPrimaryBackground: string;
|
163
|
+
secondaryBackground: string;
|
164
|
+
textOnSecondaryBackground: string;
|
165
|
+
};
|
166
|
+
};
|
167
|
+
};
|
168
|
+
};
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import { Trigger } from '../components/trigger.component';
|
2
|
+
import { WidgetComponentType } from '../components/widget.component';
|
3
|
+
import { Wrapper } from '../components/wrapper.component';
|
4
|
+
import { ComponentPlatform } from '../services/component-platform';
|
5
|
+
import { StorageService } from '../services/storage.service';
|
6
|
+
import { TextsService } from '../services/texts.service';
|
7
|
+
import { WidgetAPI } from '../services/widget-api';
|
8
|
+
import { ApplicationOptions, PluginType, RenderStrategy, TriggerIcon, WidgetAnchor, WidgetConfig } from '../types';
|
9
|
+
import { Container } from './container';
|
10
|
+
export declare class Application {
|
11
|
+
id: string;
|
12
|
+
name: string;
|
13
|
+
container: Container;
|
14
|
+
settings: WidgetConfig;
|
15
|
+
private options;
|
16
|
+
platform: ComponentPlatform;
|
17
|
+
texts: TextsService;
|
18
|
+
storage: StorageService;
|
19
|
+
root?: Wrapper;
|
20
|
+
renderStrategy: RenderStrategy;
|
21
|
+
fullscreen: boolean;
|
22
|
+
triggerIcon?: TriggerIcon;
|
23
|
+
anchor: WidgetAnchor;
|
24
|
+
autoActivate: boolean;
|
25
|
+
private plugins;
|
26
|
+
private componentResolver;
|
27
|
+
private components;
|
28
|
+
trigger: Trigger | null;
|
29
|
+
api: WidgetAPI;
|
30
|
+
constructor(id: string, name: string, container: Container, settings: WidgetConfig, options: ApplicationOptions);
|
31
|
+
activate(): Promise<void>;
|
32
|
+
private loadPlugins;
|
33
|
+
onMessageReceived: (event: any) => Promise<void>;
|
34
|
+
styles(): Record<string, any>;
|
35
|
+
branding(): Record<string, any>;
|
36
|
+
plugin(plugin: PluginType): this;
|
37
|
+
appendToDOM(options?: {
|
38
|
+
ignoreStorage?: boolean;
|
39
|
+
}): void;
|
40
|
+
hide(): void;
|
41
|
+
setZIndex(zIndex: number): void;
|
42
|
+
mute(): void;
|
43
|
+
unmute(): void;
|
44
|
+
registerComponent(type: string, component: any): void;
|
45
|
+
resolveComponent(type: string): any;
|
46
|
+
mountComponent(component: WidgetComponentType): void;
|
47
|
+
getComponent<T extends WidgetComponentType>(type: string): T | null;
|
48
|
+
private _getTargetElement;
|
49
|
+
private _isEmbeddedInIFrame;
|
50
|
+
setFullscreenMode(value: boolean): void;
|
51
|
+
render(): Trigger | Wrapper | undefined;
|
52
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { BehaviorSubject } from 'rxjs';
|
2
|
+
import { Environment } from './environment';
|
3
|
+
export declare enum ContainerState {
|
4
|
+
Loading = "loading",
|
5
|
+
Ready = "ready"
|
6
|
+
}
|
7
|
+
export declare class Container {
|
8
|
+
name: string;
|
9
|
+
environment: Environment;
|
10
|
+
state: BehaviorSubject<ContainerState>;
|
11
|
+
private resolvers;
|
12
|
+
constructor(name: string, environment: Environment);
|
13
|
+
setState(state: ContainerState): void;
|
14
|
+
register(name: string, value: unknown): Promise<void>;
|
15
|
+
get<T>(name: string): Promise<T | undefined>;
|
16
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { Application } from './application';
|
2
|
+
import { Container } from './container';
|
3
|
+
import { ApplicationOptions, PluginType, WidgetConfig } from '../types';
|
4
|
+
import { WidgetAPI } from '../services/widget-api';
|
5
|
+
import { SiteAPI } from '../services/site-api';
|
6
|
+
import { Site } from './site';
|
7
|
+
export type WidgetAPIHandler = (widget?: WidgetAPI) => void;
|
8
|
+
export type SiteConfigurationHandler = (site: SiteAPI) => void;
|
9
|
+
export declare class Environment {
|
10
|
+
applications: Application[];
|
11
|
+
container: Container;
|
12
|
+
private bootstrapped;
|
13
|
+
private site;
|
14
|
+
widgetAPIHandlers: Map<string, WidgetAPIHandler[]>;
|
15
|
+
siteConfigurationHandlers: SiteConfigurationHandler[];
|
16
|
+
constructor();
|
17
|
+
bootstrap(): Promise<void>;
|
18
|
+
private activate;
|
19
|
+
private notifyWidgetsOfCreation;
|
20
|
+
configure(delegate: SiteConfigurationHandler): void;
|
21
|
+
widget(name: string, delegate: WidgetAPIHandler): void;
|
22
|
+
registerApp(id: string, name: string, config: WidgetConfig, options: ApplicationOptions): void;
|
23
|
+
registerSite(site: Site): void;
|
24
|
+
plugin(plugin: PluginType): this;
|
25
|
+
}
|
package/models/site.d.ts
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
import { IHttpClient } from '../services/http-client.service';
|
2
|
+
import { SiteAPI } from '../services/site-api';
|
3
|
+
import { InitConfig, SiteTrigger } from '../types';
|
4
|
+
import { Environment } from './environment';
|
5
|
+
export declare class Site {
|
6
|
+
environment?: Environment;
|
7
|
+
private configurations;
|
8
|
+
private url?;
|
9
|
+
private httpClient;
|
10
|
+
api: SiteAPI;
|
11
|
+
triggers: SiteTrigger[];
|
12
|
+
constructor(urlOrConfig: string | InitConfig);
|
13
|
+
load(url: string): Promise<void>;
|
14
|
+
loadFromConfig(config: InitConfig): void;
|
15
|
+
setHttpClient(client: IHttpClient): void;
|
16
|
+
bootstrap(handler: (environment: Environment) => void): Promise<void>;
|
17
|
+
private addGlobal;
|
18
|
+
}
|
package/package.json
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
import { WidgetComponentType } from '../components/widget.component';
|
2
|
+
import { Wrapper } from '../components/wrapper.component';
|
3
|
+
import { Application } from '../models/application';
|
4
|
+
import { WidgetConfig } from '../types';
|
5
|
+
export declare class ComponentPlatform {
|
6
|
+
private root;
|
7
|
+
constructor();
|
8
|
+
createComponentModel(settings: WidgetConfig, application: Application): Wrapper;
|
9
|
+
createRoot(): Wrapper;
|
10
|
+
createNode(name: string, type: string): WidgetComponentType;
|
11
|
+
private resolveComponent;
|
12
|
+
getRoot(): Wrapper;
|
13
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
export declare class ComponentResolver {
|
2
|
+
components: Map<string, any>;
|
3
|
+
getComponent(type: string): any;
|
4
|
+
registerComponent(type: string, component: any): void;
|
5
|
+
loadComponents(): Promise<void>;
|
6
|
+
private defineAsWebComponent;
|
7
|
+
static ResolveWebComponentName: (widgetComponentName: string) => string;
|
8
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { SiteConfig, WidgetConfig } from '../types';
|
2
|
+
type GetWidgetResponse = {
|
3
|
+
name: string;
|
4
|
+
config: WidgetConfig;
|
5
|
+
};
|
6
|
+
export interface IHttpClient {
|
7
|
+
getSite(url: string): Promise<SiteConfig | null>;
|
8
|
+
getWidget(widgetId: string): Promise<GetWidgetResponse | null>;
|
9
|
+
}
|
10
|
+
export declare const createHttpClient: (endpoint?: string) => IHttpClient;
|
11
|
+
export declare class HttpClient implements IHttpClient {
|
12
|
+
private _endpoint;
|
13
|
+
private static endpoint;
|
14
|
+
constructor(_endpoint?: string);
|
15
|
+
getSite(url: string): Promise<SiteConfig | null>;
|
16
|
+
getWidget(widgetId: string): Promise<GetWidgetResponse | null>;
|
17
|
+
}
|
18
|
+
export {};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
export declare enum StorageCategory {
|
2
|
+
Necessary = "necessary",
|
3
|
+
Functional = "functional",
|
4
|
+
Analytics = "analytics"
|
5
|
+
}
|
6
|
+
export declare class StorageService {
|
7
|
+
private storage;
|
8
|
+
private policy;
|
9
|
+
private widgetId;
|
10
|
+
private storageEntries;
|
11
|
+
private disallowedKeys;
|
12
|
+
constructor(widgetId: string, storageType: 'localStorage' | 'sessionStorage', policy: Record<StorageCategory, boolean>, storageEntries: Record<string, any>);
|
13
|
+
set<T>(key: string, value: T): void;
|
14
|
+
get<T>(key: string): T | null;
|
15
|
+
removeItem(key: string): void;
|
16
|
+
enforcePolicy(): void;
|
17
|
+
updatePolicy(newPolicy: Record<StorageCategory, boolean>): void;
|
18
|
+
disallowKey(key: string): void;
|
19
|
+
stringify(): string;
|
20
|
+
private _prefixKey;
|
21
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
export interface ITextsService {
|
2
|
+
loadTexts(texts: Record<string, string>): void;
|
3
|
+
get(key: string): string | null;
|
4
|
+
}
|
5
|
+
export declare class TextsService implements ITextsService {
|
6
|
+
private texts;
|
7
|
+
loadTexts(texts: Record<string, string>): void;
|
8
|
+
get(key: string, fallback?: string): string | null;
|
9
|
+
getOrFallback(key: string, fallback: string): string;
|
10
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { Application } from '../models/application';
|
2
|
+
export declare class WidgetAPI {
|
3
|
+
private widget;
|
4
|
+
name: string;
|
5
|
+
constructor(widget: Application);
|
6
|
+
open(options?: {
|
7
|
+
ignoreStorage?: boolean;
|
8
|
+
}): void;
|
9
|
+
close(): void;
|
10
|
+
setFullscreenMode(value: boolean): void;
|
11
|
+
setZIndex(zIndex: number): void;
|
12
|
+
version(): {
|
13
|
+
version: string;
|
14
|
+
};
|
15
|
+
}
|
package/types.d.ts
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
import { Application } from './models/application';
|
2
|
+
import { IHttpClient } from './services/http-client.service';
|
3
|
+
export type ComponentDefinition = {
|
4
|
+
name: string;
|
5
|
+
type: string;
|
6
|
+
properties?: Record<string, any>;
|
7
|
+
context?: Record<string, any>;
|
8
|
+
layout?: Record<string, any>;
|
9
|
+
children?: string[];
|
10
|
+
};
|
11
|
+
export type WidgetConfig = {
|
12
|
+
entry: string;
|
13
|
+
texts?: Record<string, string>;
|
14
|
+
components: Record<string, ComponentDefinition>;
|
15
|
+
storage: Record<string, any>;
|
16
|
+
branding: Record<string, any>;
|
17
|
+
styles?: Record<string, any>;
|
18
|
+
survey?: Record<string, any>;
|
19
|
+
};
|
20
|
+
export declare enum RenderStrategy {
|
21
|
+
Inline = "inline",
|
22
|
+
Trigger = "trigger"
|
23
|
+
}
|
24
|
+
export type ApplicationOptions = {
|
25
|
+
renderStrategy: RenderStrategy;
|
26
|
+
triggerIcon?: TriggerIcon;
|
27
|
+
autoActivate?: boolean;
|
28
|
+
anchor?: WidgetAnchor;
|
29
|
+
};
|
30
|
+
export type TriggerIcon = {
|
31
|
+
type: string;
|
32
|
+
content: string;
|
33
|
+
};
|
34
|
+
export type AppConfig = {
|
35
|
+
id: string;
|
36
|
+
widgetId: string;
|
37
|
+
renderStrategy: RenderStrategy;
|
38
|
+
triggerIcon?: TriggerIcon;
|
39
|
+
autoActivate?: boolean;
|
40
|
+
anchor?: WidgetAnchor;
|
41
|
+
};
|
42
|
+
export type SiteConfig = {
|
43
|
+
id: string;
|
44
|
+
triggers?: SiteTrigger[];
|
45
|
+
apps: AppConfig[];
|
46
|
+
};
|
47
|
+
export type SiteTrigger = {
|
48
|
+
id: string;
|
49
|
+
triggerType: 'visit';
|
50
|
+
condition: TriggerCondition;
|
51
|
+
};
|
52
|
+
export type TriggerCondition = {
|
53
|
+
type: 'url';
|
54
|
+
outputs: {
|
55
|
+
value: string;
|
56
|
+
action: {
|
57
|
+
type: string;
|
58
|
+
data: string;
|
59
|
+
};
|
60
|
+
}[];
|
61
|
+
};
|
62
|
+
export type InitConfig = {
|
63
|
+
apps: {
|
64
|
+
widgetId: string;
|
65
|
+
renderStrategy?: 'inline' | 'trigger';
|
66
|
+
triggerIcon?: string;
|
67
|
+
autoActivate?: boolean;
|
68
|
+
anchor?: WidgetAnchor;
|
69
|
+
}[];
|
70
|
+
httpClient?: IHttpClient;
|
71
|
+
};
|
72
|
+
export type PluginType = (app: Application) => Promise<void>;
|
73
|
+
export type WidgetAnchor = 'BottomRight' | 'BottomLeft';
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const mapBranding: (context: Record<string, any>, el: HTMLElement) => void;
|