@pexip-engage-public/plugin-instance
Advanced tools
Comparing version 2.0.0-canary-20231023080955 to 2.0.0-canary-20231025101109
# @pexip-engage-public/plugin-instance | ||
## 2.0.0-canary-20231023080955 | ||
## 2.0.0-canary-20231025101109 | ||
@@ -12,6 +12,7 @@ ### Major Changes | ||
- Updated dependencies [f94a30b50] | ||
- @pexip-engage-public/plugin-configuration-parser@2.0.0-canary-20231023080955 | ||
- @pexip-engage-public/plugin-events@2.0.0-canary-20231023080955 | ||
- @pexip-engage-public/plugin-state@2.0.0-canary-20231023080955 | ||
- @pexip-engage-public/plugin-utils@2.0.0-canary-20231023080955 | ||
- Updated dependencies [d5413de87] | ||
- @pexip-engage-public/plugin-configuration-parser@2.0.0-canary-20231025101109 | ||
- @pexip-engage-public/plugin-events@2.0.0-canary-20231025101109 | ||
- @pexip-engage-public/plugin-state@2.0.0-canary-20231025101109 | ||
- @pexip-engage-public/plugin-utils@2.0.0-canary-20231025101109 | ||
@@ -18,0 +19,0 @@ ## 1.1.3 |
@@ -1,14 +0,25 @@ | ||
import type { PluginError, PluginEvent, PluginMisconfigured } from "@pexip-engage-public/plugin-events"; | ||
import type { | ||
PluginError, | ||
PluginEvent, | ||
PluginMisconfigured, | ||
} from "@pexip-engage-public/plugin-events"; | ||
export declare const PEXIP_ENGAGE_PLUGIN_EVENT = "SkedifyPluginEvent"; | ||
interface DispatchEventOptions<T> extends CustomEventInit<T> { | ||
target: Element | Document | DocumentFragment; | ||
type: PluginEvent; | ||
subtype?: PluginMisconfigured | PluginError; | ||
target: Element | Document | DocumentFragment; | ||
type: PluginEvent; | ||
subtype?: PluginMisconfigured | PluginError; | ||
} | ||
export type PluginCustomEvent = CustomEvent<{ | ||
export type PluginCustomEvent = CustomEvent< | ||
{ | ||
type: PluginEvent; | ||
subtype: PluginMisconfigured | PluginError | undefined; | ||
} & Record<string, any>>; | ||
export declare function dispatchEvent<T>({ subtype, target, type, ...eventInitDict }: DispatchEventOptions<T>): boolean; | ||
} & Record<string, any> | ||
>; | ||
export declare function dispatchEvent<T>({ | ||
subtype, | ||
target, | ||
type, | ||
...eventInitDict | ||
}: DispatchEventOptions<T>): boolean; | ||
export {}; | ||
//# sourceMappingURL=dispatchEvent.d.ts.map | ||
//# sourceMappingURL=dispatchEvent.d.ts.map |
export const PEXIP_ENGAGE_PLUGIN_EVENT = "SkedifyPluginEvent"; | ||
export function dispatchEvent({ subtype, target, type, ...eventInitDict }) { | ||
const event = new CustomEvent(PEXIP_ENGAGE_PLUGIN_EVENT, { | ||
...eventInitDict, | ||
detail: { ...eventInitDict.detail, type, subtype }, | ||
}); | ||
return target.dispatchEvent(event); | ||
const event = new CustomEvent(PEXIP_ENGAGE_PLUGIN_EVENT, { | ||
...eventInitDict, | ||
detail: { ...eventInitDict.detail, type, subtype }, | ||
}); | ||
return target.dispatchEvent(event); | ||
} |
@@ -7,16 +7,15 @@ import { PluginInstance as _PluginInstance } from "./PluginInstance.js"; | ||
export interface PexipEngageWindow { | ||
SkedifyPlugin?: typeof PluginStatic; | ||
Skedify?: { | ||
Plugin: typeof PluginStatic; | ||
translationSource: () => void; | ||
}; | ||
PexipEngage?: { | ||
Plugin: typeof PluginStatic; | ||
}; | ||
SkedifyPlugin?: typeof PluginStatic; | ||
Skedify?: { | ||
Plugin: typeof PluginStatic; | ||
translationSource: () => void; | ||
}; | ||
PexipEngage?: { | ||
Plugin: typeof PluginStatic; | ||
}; | ||
} | ||
declare global { | ||
interface Window extends PexipEngageWindow { | ||
} | ||
interface Window extends PexipEngageWindow {} | ||
} | ||
export declare function installGlobals(): void; | ||
//# sourceMappingURL=index.d.ts.map | ||
//# sourceMappingURL=index.d.ts.map |
@@ -5,28 +5,28 @@ import { dispatchEvent } from "./dispatchEvent.js"; | ||
export const PluginStatic = new Proxy(_PluginInstance, { | ||
apply(Instance, _, argumentsList) { | ||
return new Instance(argumentsList[0], argumentsList[1]); | ||
}, | ||
apply(Instance, _, argumentsList) { | ||
return new Instance(argumentsList[0], argumentsList[1]); | ||
}, | ||
}); | ||
export function installGlobals() { | ||
if (!window.Skedify?.Plugin) { | ||
window.Skedify = { | ||
...window.Skedify, | ||
translationSource() { | ||
console.warn("translationSource is no longer supported."); | ||
}, | ||
Plugin: PluginStatic, | ||
}; | ||
} | ||
if (!window.SkedifyPlugin) { | ||
window.SkedifyPlugin = PluginStatic; | ||
} | ||
if (!window.PexipEngage?.Plugin) { | ||
window.PexipEngage = { ...window.PexipEngage, Plugin: PluginStatic }; | ||
dispatchEvent({ | ||
target: document, | ||
type: PluginStatic.EVENT_INIT, | ||
bubbles: true, | ||
cancelable: true, | ||
}); | ||
} | ||
if (!window.Skedify?.Plugin) { | ||
window.Skedify = { | ||
...window.Skedify, | ||
translationSource() { | ||
console.warn("translationSource is no longer supported."); | ||
}, | ||
Plugin: PluginStatic, | ||
}; | ||
} | ||
if (!window.SkedifyPlugin) { | ||
window.SkedifyPlugin = PluginStatic; | ||
} | ||
if (!window.PexipEngage?.Plugin) { | ||
window.PexipEngage = { ...window.PexipEngage, Plugin: PluginStatic }; | ||
dispatchEvent({ | ||
target: document, | ||
type: PluginStatic.EVENT_INIT, | ||
bubbles: true, | ||
cancelable: true, | ||
}); | ||
} | ||
} |
declare class PexipEngagePluginFrame extends HTMLElement { | ||
#private; | ||
constructor(); | ||
createPexipPlugin(src: string): HTMLIFrameElement; | ||
#private; | ||
constructor(); | ||
createPexipPlugin(src: string): HTMLIFrameElement; | ||
} | ||
export declare function getPexipEngagePluginFrame(): typeof PexipEngagePluginFrame; | ||
export {}; | ||
//# sourceMappingURL=PexipEngagePluginFrame.d.ts.map | ||
//# sourceMappingURL=PexipEngagePluginFrame.d.ts.map |
@@ -7,34 +7,34 @@ const SPINNER_STYLE = `<style>@keyframes spin{to{transform: rotate(360deg);}}.container{display: flex; align-items: center; justify-content: center; height: calc(700px - 1rem);}svg{fill: rgb(10 33 54); color: rgb(229 231 235); animation: spin 1s linear infinite;}</style>`; | ||
class PexipEngagePluginFrame extends HTMLElement { | ||
#shadowRoot; | ||
constructor() { | ||
super(); | ||
this.#shadowRoot = this.attachShadow({ mode: "open" }); | ||
this.#shadowRoot.appendChild(spinnerTemplate.content.cloneNode(true)); | ||
} | ||
createPexipPlugin(src) { | ||
const iframe = document.createElement("iframe"); | ||
iframe.src = src; | ||
iframe.style.border = "0px"; | ||
iframe.style.overflow = "hidden"; | ||
iframe.style.height = "707px"; | ||
iframe.style.width = "100%"; | ||
iframe.height = "100%"; | ||
iframe.width = "100%"; | ||
iframe.title = "Pexip Engage Plugin"; | ||
iframe.referrerPolicy = "strict-origin-when-cross-origin"; | ||
iframe.allow = "clipboard-write"; | ||
// iframe.loading = "lazy"; | ||
iframe.onload = () => iframe.removeAttribute("srcdoc"); | ||
iframe.srcdoc = spinnerHtml; | ||
this.#shadowRoot.innerHTML = ""; | ||
this.#shadowRoot.appendChild(iframe); | ||
return iframe; | ||
} | ||
#shadowRoot; | ||
constructor() { | ||
super(); | ||
this.#shadowRoot = this.attachShadow({ mode: "open" }); | ||
this.#shadowRoot.appendChild(spinnerTemplate.content.cloneNode(true)); | ||
} | ||
createPexipPlugin(src) { | ||
const iframe = document.createElement("iframe"); | ||
iframe.src = src; | ||
iframe.style.border = "0px"; | ||
iframe.style.overflow = "hidden"; | ||
iframe.style.height = "707px"; | ||
iframe.style.width = "100%"; | ||
iframe.height = "100%"; | ||
iframe.width = "100%"; | ||
iframe.title = "Pexip Engage Plugin"; | ||
iframe.referrerPolicy = "strict-origin-when-cross-origin"; | ||
iframe.allow = "clipboard-write"; | ||
// iframe.loading = "lazy"; | ||
iframe.onload = () => iframe.removeAttribute("srcdoc"); | ||
iframe.srcdoc = spinnerHtml; | ||
this.#shadowRoot.innerHTML = ""; | ||
this.#shadowRoot.appendChild(iframe); | ||
return iframe; | ||
} | ||
} | ||
const FRAME_IDENTIFIER = "pexip-engage-plugin-frame"; | ||
export function getPexipEngagePluginFrame() { | ||
if (!window.customElements.get(FRAME_IDENTIFIER)) { | ||
window.customElements.define(FRAME_IDENTIFIER, PexipEngagePluginFrame); | ||
} | ||
return window.customElements.get(FRAME_IDENTIFIER); | ||
if (!window.customElements.get(FRAME_IDENTIFIER)) { | ||
window.customElements.define(FRAME_IDENTIFIER, PexipEngagePluginFrame); | ||
} | ||
return window.customElements.get(FRAME_IDENTIFIER); | ||
} |
@@ -7,38 +7,42 @@ import { parsePluginConfiguration } from "@pexip-engage-public/plugin-configuration-parser"; | ||
export declare class PluginInstance { | ||
#private; | ||
constructor(element: unknown, options?: unknown); | ||
/** @private internal API */ | ||
get config(): ReturnType<typeof parsePluginConfiguration>; | ||
/** Configuration of this plugin instance */ | ||
get configuration(): ReturnType<typeof parsePluginConfiguration>["config"]; | ||
/** @private internal API */ | ||
get hashConfig(): string; | ||
openDebugger: () => string; | ||
/** Destroy the instance */ | ||
dispose: () => void; | ||
/** @private internal API */ | ||
setCSSVariable: (name: string, value: string) => void; | ||
setCustomCSS: (css: string) => void; | ||
/** Add an event listener */ | ||
addEventListener: (typeOrListener?: PluginEvent | PluginEventListener, cb?: PluginEventListener) => void; | ||
/** The current intention */ | ||
get intention(): PluginIntent | undefined; | ||
get appointment(): { | ||
id: string | undefined; | ||
location: { | ||
id: string | undefined; | ||
}; | ||
meeting_type: "VIDEO" | "PHONE" | "ON_LOCATION" | "OFFICE" | undefined; | ||
subject: { | ||
id: string | undefined; | ||
category_id: string | undefined; | ||
}; | ||
meta: { | ||
getAll: () => Record<string, unknown> | null; | ||
get: (key: string, defaultValue: unknown) => unknown; | ||
set: (key: string, value: unknown) => Record<string, unknown>; | ||
remove: (key: string) => void; | ||
}; | ||
#private; | ||
constructor(element: unknown, options?: unknown); | ||
/** @private internal API */ | ||
get config(): ReturnType<typeof parsePluginConfiguration>; | ||
/** Configuration of this plugin instance */ | ||
get configuration(): ReturnType<typeof parsePluginConfiguration>["config"]; | ||
/** @private internal API */ | ||
get hashConfig(): string; | ||
openDebugger: () => string; | ||
/** Destroy the instance */ | ||
dispose: () => void; | ||
/** @private internal API */ | ||
setCSSVariable: (name: string, value: string) => void; | ||
setCustomCSS: (css: string) => void; | ||
/** Add an event listener */ | ||
addEventListener: ( | ||
typeOrListener?: PluginEvent | PluginEventListener, | ||
cb?: PluginEventListener, | ||
) => void; | ||
/** The current intention */ | ||
get intention(): PluginIntent | undefined; | ||
get appointment(): { | ||
id: string | undefined; | ||
location: { | ||
id: string | undefined; | ||
}; | ||
get customer(): { | ||
meeting_type: "VIDEO" | "PHONE" | "ON_LOCATION" | "OFFICE" | undefined; | ||
subject: { | ||
id: string | undefined; | ||
category_id: string | undefined; | ||
}; | ||
meta: { | ||
getAll: () => Record<string, unknown> | null; | ||
get: (key: string, defaultValue: unknown) => unknown; | ||
set: (key: string, value: unknown) => Record<string, unknown>; | ||
remove: (key: string) => void; | ||
}; | ||
}; | ||
get customer(): | ||
| { | ||
company?: string | null | undefined; | ||
@@ -55,11 +59,14 @@ customer_number?: string | null | undefined; | ||
last_name?: string | null | undefined; | ||
location?: { | ||
geolocation?: string | null | undefined; | ||
city?: string | null | undefined; | ||
country?: string | null | undefined; | ||
formatted_address?: string | null | undefined; | ||
postal_code?: string | null | undefined; | ||
state?: string | null | undefined; | ||
street_1?: string | null | undefined; | ||
} | null | undefined; | ||
location?: | ||
| { | ||
geolocation?: string | null | undefined; | ||
city?: string | null | undefined; | ||
country?: string | null | undefined; | ||
formatted_address?: string | null | undefined; | ||
postal_code?: string | null | undefined; | ||
state?: string | null | undefined; | ||
street_1?: string | null | undefined; | ||
} | ||
| null | ||
| undefined; | ||
phone_number?: string | null | undefined; | ||
@@ -69,8 +76,13 @@ preferred_contact_id?: string | null | undefined; | ||
timezone?: string | null | undefined; | ||
} | undefined; | ||
static dispose: () => void | undefined; | ||
static disposeAll: () => void; | ||
static addEventListener: (typeOrListener?: PluginEvent | PluginEventListener | undefined, cb?: PluginEventListener | undefined) => void | undefined; | ||
static setCSSVariable(name: string, value: string): void | undefined; | ||
static get customer(): { | ||
} | ||
| undefined; | ||
static dispose: () => void | undefined; | ||
static disposeAll: () => void; | ||
static addEventListener: ( | ||
typeOrListener?: PluginEvent | PluginEventListener | undefined, | ||
cb?: PluginEventListener | undefined, | ||
) => void | undefined; | ||
static setCSSVariable(name: string, value: string): void | undefined; | ||
static get customer(): | ||
| { | ||
company?: string | null | undefined; | ||
@@ -87,11 +99,14 @@ customer_number?: string | null | undefined; | ||
last_name?: string | null | undefined; | ||
location?: { | ||
geolocation?: string | null | undefined; | ||
city?: string | null | undefined; | ||
country?: string | null | undefined; | ||
formatted_address?: string | null | undefined; | ||
postal_code?: string | null | undefined; | ||
state?: string | null | undefined; | ||
street_1?: string | null | undefined; | ||
} | null | undefined; | ||
location?: | ||
| { | ||
geolocation?: string | null | undefined; | ||
city?: string | null | undefined; | ||
country?: string | null | undefined; | ||
formatted_address?: string | null | undefined; | ||
postal_code?: string | null | undefined; | ||
state?: string | null | undefined; | ||
street_1?: string | null | undefined; | ||
} | ||
| null | ||
| undefined; | ||
phone_number?: string | null | undefined; | ||
@@ -101,65 +116,75 @@ preferred_contact_id?: string | null | undefined; | ||
timezone?: string | null | undefined; | ||
} | undefined; | ||
static get appointment(): { | ||
} | ||
| undefined; | ||
static get appointment(): | ||
| { | ||
id: string | undefined; | ||
location: { | ||
id: string | undefined; | ||
id: string | undefined; | ||
}; | ||
meeting_type: "VIDEO" | "PHONE" | "ON_LOCATION" | "OFFICE" | undefined; | ||
subject: { | ||
id: string | undefined; | ||
category_id: string | undefined; | ||
id: string | undefined; | ||
category_id: string | undefined; | ||
}; | ||
meta: { | ||
getAll: () => Record<string, unknown> | null; | ||
get: (key: string, defaultValue: unknown) => unknown; | ||
set: (key: string, value: unknown) => Record<string, unknown>; | ||
remove: (key: string) => void; | ||
getAll: () => Record<string, unknown> | null; | ||
get: (key: string, defaultValue: unknown) => unknown; | ||
set: (key: string, value: unknown) => Record<string, unknown>; | ||
remove: (key: string) => void; | ||
}; | ||
} | undefined; | ||
static get intention(): "schedule" | "reschedule" | "invite" | "edit" | "cancel" | "complete" | undefined; | ||
/** @private internal API */ | ||
static get config(): ReturnType<typeof parsePluginConfiguration> | undefined; | ||
/** @private internal API */ | ||
static get hashConfig(): string | undefined; | ||
static openDebugger(): string | undefined; | ||
/** @private internal API */ | ||
static get url(): string; | ||
/** @private internal API */ | ||
static setEnterpriseUrl: (url: string) => void; | ||
static getInstance: (num: unknown) => PluginInstance | undefined; | ||
static awaitFirstInstance: () => Promise<PluginInstance>; | ||
static get count(): number; | ||
static readonly EVENT_APPOINTMENT_CANCELLED: "APPOINTMENT_CANCELLED"; | ||
static readonly EVENT_APPOINTMENT_COMPLETED: "APPOINTMENT_COMPLETED"; | ||
static readonly EVENT_APPOINTMENT_CREATED: "APPOINTMENT_CREATED"; | ||
static readonly EVENT_INVITE_ACCEPTED: "INVITE_ACCEPTED"; | ||
static readonly EVENT_APPOINTMENT_EDITED: "APPOINTMENT_EDITED"; | ||
static readonly EVENT_CREATION: "CREATION"; | ||
static readonly EVENT_ERROR: "ERROR"; | ||
static readonly EVENT_INIT: "INIT"; | ||
static readonly EVENT_LOADED: "LOADED"; | ||
static readonly EVENT_MISCONFIGURED: "MISCONFIGURED"; | ||
static readonly EVENT_STEP_SHOWN: "STEP_SHOWN"; | ||
static readonly MISCONFIGURED_CLIENT_ID: "CLIENT_ID"; | ||
static readonly MISCONFIGURED_CONTACT_HINTS: "CONTACT_HINTS"; | ||
static readonly MISCONFIGURED_GEOLOCATION: "GEOLOCATION"; | ||
static readonly MISCONFIGURED_INTENT_WITHOUT_RESOURCE_CODE: "INTENT_WITHOUT_RESOURCE_CODE"; | ||
static readonly MISCONFIGURED_LISTING_ID: "LISTING_ID"; | ||
static readonly MISCONFIGURED_OFFICE_ID: "OFFICE_ID"; | ||
static readonly MISCONFIGURED_RESOURCE_CODE: "RESOURCE_CODE"; | ||
static readonly MISCONFIGURED_SUBJECT_ID: "SUBJECT_ID"; | ||
static readonly MISCONFIGURED_TIMEZONE: "TIMEZONE"; | ||
static readonly ERROR_API_DOWN: "API_DOWN"; | ||
static readonly ERROR_RECAPTCHA_SCRIPT_LOAD: "RECAPTCHA_SCRIPT_LOAD"; | ||
static readonly ERROR_SUB_DATE_INTERPOLATION: "SUB_DATE_INTERPOLATION"; | ||
static readonly ERROR_TRANSLATION: "TRANSLATION"; | ||
static readonly INTENT_CANCEL: PluginIntent; | ||
static readonly INTENT_EDIT: PluginIntent; | ||
static readonly INTENT_INVITE: PluginIntent; | ||
static readonly INTENT_RESCHEDULE: PluginIntent; | ||
static readonly INTENT_COMPLETE: PluginIntent; | ||
static readonly INTENT_SCHEDULE: PluginIntent; | ||
} | ||
| undefined; | ||
static get intention(): | ||
| "schedule" | ||
| "reschedule" | ||
| "invite" | ||
| "edit" | ||
| "cancel" | ||
| "complete" | ||
| undefined; | ||
/** @private internal API */ | ||
static get config(): ReturnType<typeof parsePluginConfiguration> | undefined; | ||
/** @private internal API */ | ||
static get hashConfig(): string | undefined; | ||
static openDebugger(): string | undefined; | ||
/** @private internal API */ | ||
static get url(): string; | ||
/** @private internal API */ | ||
static setEnterpriseUrl: (url: string) => void; | ||
static getInstance: (num: unknown) => PluginInstance | undefined; | ||
static awaitFirstInstance: () => Promise<PluginInstance>; | ||
static get count(): number; | ||
static readonly EVENT_APPOINTMENT_CANCELLED: "APPOINTMENT_CANCELLED"; | ||
static readonly EVENT_APPOINTMENT_COMPLETED: "APPOINTMENT_COMPLETED"; | ||
static readonly EVENT_APPOINTMENT_CREATED: "APPOINTMENT_CREATED"; | ||
static readonly EVENT_INVITE_ACCEPTED: "INVITE_ACCEPTED"; | ||
static readonly EVENT_APPOINTMENT_EDITED: "APPOINTMENT_EDITED"; | ||
static readonly EVENT_CREATION: "CREATION"; | ||
static readonly EVENT_ERROR: "ERROR"; | ||
static readonly EVENT_INIT: "INIT"; | ||
static readonly EVENT_LOADED: "LOADED"; | ||
static readonly EVENT_MISCONFIGURED: "MISCONFIGURED"; | ||
static readonly EVENT_STEP_SHOWN: "STEP_SHOWN"; | ||
static readonly MISCONFIGURED_CLIENT_ID: "CLIENT_ID"; | ||
static readonly MISCONFIGURED_CONTACT_HINTS: "CONTACT_HINTS"; | ||
static readonly MISCONFIGURED_GEOLOCATION: "GEOLOCATION"; | ||
static readonly MISCONFIGURED_INTENT_WITHOUT_RESOURCE_CODE: "INTENT_WITHOUT_RESOURCE_CODE"; | ||
static readonly MISCONFIGURED_LISTING_ID: "LISTING_ID"; | ||
static readonly MISCONFIGURED_OFFICE_ID: "OFFICE_ID"; | ||
static readonly MISCONFIGURED_RESOURCE_CODE: "RESOURCE_CODE"; | ||
static readonly MISCONFIGURED_SUBJECT_ID: "SUBJECT_ID"; | ||
static readonly MISCONFIGURED_TIMEZONE: "TIMEZONE"; | ||
static readonly ERROR_API_DOWN: "API_DOWN"; | ||
static readonly ERROR_RECAPTCHA_SCRIPT_LOAD: "RECAPTCHA_SCRIPT_LOAD"; | ||
static readonly ERROR_SUB_DATE_INTERPOLATION: "SUB_DATE_INTERPOLATION"; | ||
static readonly ERROR_TRANSLATION: "TRANSLATION"; | ||
static readonly INTENT_CANCEL: PluginIntent; | ||
static readonly INTENT_EDIT: PluginIntent; | ||
static readonly INTENT_INVITE: PluginIntent; | ||
static readonly INTENT_RESCHEDULE: PluginIntent; | ||
static readonly INTENT_COMPLETE: PluginIntent; | ||
static readonly INTENT_SCHEDULE: PluginIntent; | ||
} | ||
export {}; | ||
//# sourceMappingURL=PluginInstance.d.ts.map | ||
//# sourceMappingURL=PluginInstance.d.ts.map |
@@ -1,424 +0,436 @@ | ||
import { createSearchParamConfig, encodeConfigAsHash, encodeURIParameters, parsePluginConfiguration, } from "@pexip-engage-public/plugin-configuration-parser"; | ||
import { PluginError, PluginEvent, PluginMisconfigured, RequestEvent, } from "@pexip-engage-public/plugin-events"; | ||
import { | ||
createSearchParamConfig, | ||
encodeConfigAsHash, | ||
encodeURIParameters, | ||
parsePluginConfiguration, | ||
} from "@pexip-engage-public/plugin-configuration-parser"; | ||
import { | ||
PluginError, | ||
PluginEvent, | ||
PluginMisconfigured, | ||
RequestEvent, | ||
} from "@pexip-engage-public/plugin-events"; | ||
import { logger } from "@pexip-engage-public/plugin-utils"; | ||
import resizer, {} from "iframe-resizer/js/iframeResizer.min.js"; | ||
import { dispatchEvent, PEXIP_ENGAGE_PLUGIN_EVENT, } from "./dispatchEvent.js"; | ||
import resizer from "iframe-resizer/js/iframeResizer.min.js"; | ||
import { dispatchEvent, PEXIP_ENGAGE_PLUGIN_EVENT } from "./dispatchEvent.js"; | ||
import { getPexipEngagePluginFrame } from "./PexipEngagePluginFrame.js"; | ||
const PexipEngagePluginFrame = getPexipEngagePluginFrame(); | ||
export class PluginInstance { | ||
#instance; | ||
#target; | ||
#state = null; | ||
#meta = null; | ||
#status = "pending"; | ||
#fallbackTimeoutId = null; | ||
#fallbackHTML; | ||
#config; | ||
constructor(element, options = {}) { | ||
if (!isElement(element)) | ||
throw new Error("Invalid target passed, expected an element."); | ||
if (!isValidConfiguration(options)) | ||
throw new Error("Invalid configuration passed, expected an object."); | ||
const config = parsePluginConfiguration({ | ||
element, | ||
options, | ||
hash: window.location.hash, | ||
href: window.location.href, | ||
browserTimeZone: new Intl.DateTimeFormat().resolvedOptions().timeZone, | ||
}); | ||
this.#config = config; | ||
this.#target = element; | ||
const existingInstance = PluginInstance.#instances.find((i) => i.#target === element); | ||
this.#fallbackHTML = existingInstance ? "" : element.innerHTML; | ||
existingInstance?.dispose(); | ||
const container = new PexipEngagePluginFrame(); | ||
element.innerHTML = ""; | ||
element.appendChild(container); | ||
const searchParams = createSearchParamConfig({ config: config.config }); | ||
const src = `${PluginInstance.#url}/plugin?${searchParams}`; | ||
const iframe = container.createPexipPlugin(src); | ||
const self = this; | ||
const [instance] = resizer({ | ||
log: false, | ||
checkOrigin: false, | ||
onMessage: this.#handleMessage, | ||
resizeFrom: "child", | ||
heightCalculationMethod: "taggedElement", | ||
onInit() { | ||
self.#status = "success"; | ||
dispatchEvent({ | ||
target: element, | ||
type: PluginEvent.LOADED, | ||
bubbles: true, | ||
cancelable: true, | ||
detail: { instance: self }, | ||
}); | ||
}, | ||
}, iframe); | ||
if (!instance) | ||
throw new Error("Failed to create resizer instance"); | ||
this.#instance = instance; | ||
PluginInstance.#instances.push(this); | ||
queueMacroTask(() => { | ||
// TODO: Better fallback handling. | ||
// self.#fallbackTimeoutId = window.setTimeout(() => { | ||
// if (self.#status !== "success" && self.#status !== "disposed") { | ||
// self.#target.innerHTML = self.fallbackHTML; | ||
// self.#status = "error"; | ||
// dispatchEvent({ | ||
// target: target, | ||
// type: PluginEvent.ERROR, | ||
// bubbles: true, | ||
// cancelable: true, | ||
// detail: { instance: self }, | ||
// }); | ||
// } | ||
// }, 20 * 1000); | ||
dispatchEvent({ | ||
target: element, | ||
type: PluginEvent.CREATION, | ||
bubbles: true, | ||
cancelable: true, | ||
detail: { instance: self }, | ||
}); | ||
}); | ||
#instance; | ||
#target; | ||
#state = null; | ||
#meta = null; | ||
#status = "pending"; | ||
#fallbackTimeoutId = null; | ||
#fallbackHTML; | ||
#config; | ||
constructor(element, options = {}) { | ||
if (!isElement(element)) throw new Error("Invalid target passed, expected an element."); | ||
if (!isValidConfiguration(options)) | ||
throw new Error("Invalid configuration passed, expected an object."); | ||
const config = parsePluginConfiguration({ | ||
element, | ||
options, | ||
hash: window.location.hash, | ||
href: window.location.href, | ||
browserTimeZone: new Intl.DateTimeFormat().resolvedOptions().timeZone, | ||
}); | ||
this.#config = config; | ||
this.#target = element; | ||
const existingInstance = PluginInstance.#instances.find((i) => i.#target === element); | ||
this.#fallbackHTML = existingInstance ? "" : element.innerHTML; | ||
existingInstance?.dispose(); | ||
const container = new PexipEngagePluginFrame(); | ||
element.innerHTML = ""; | ||
element.appendChild(container); | ||
const searchParams = createSearchParamConfig({ config: config.config }); | ||
const src = `${PluginInstance.#url}/plugin?${searchParams}`; | ||
const iframe = container.createPexipPlugin(src); | ||
const self = this; | ||
const [instance] = resizer( | ||
{ | ||
log: false, | ||
checkOrigin: false, | ||
onMessage: this.#handleMessage, | ||
resizeFrom: "child", | ||
heightCalculationMethod: "taggedElement", | ||
onInit() { | ||
self.#status = "success"; | ||
dispatchEvent({ | ||
target: element, | ||
type: PluginEvent.LOADED, | ||
bubbles: true, | ||
cancelable: true, | ||
detail: { instance: self }, | ||
}); | ||
}, | ||
}, | ||
iframe, | ||
); | ||
if (!instance) throw new Error("Failed to create resizer instance"); | ||
this.#instance = instance; | ||
PluginInstance.#instances.push(this); | ||
queueMacroTask(() => { | ||
// TODO: Better fallback handling. | ||
// self.#fallbackTimeoutId = window.setTimeout(() => { | ||
// if (self.#status !== "success" && self.#status !== "disposed") { | ||
// self.#target.innerHTML = self.fallbackHTML; | ||
// self.#status = "error"; | ||
// dispatchEvent({ | ||
// target: target, | ||
// type: PluginEvent.ERROR, | ||
// bubbles: true, | ||
// cancelable: true, | ||
// detail: { instance: self }, | ||
// }); | ||
// } | ||
// }, 20 * 1000); | ||
dispatchEvent({ | ||
target: element, | ||
type: PluginEvent.CREATION, | ||
bubbles: true, | ||
cancelable: true, | ||
detail: { instance: self }, | ||
}); | ||
}); | ||
} | ||
#handleMessage = async ({ message }) => { | ||
if (message.type === "STATE_UPDATE") { | ||
this.#state = message.payload; | ||
return; | ||
} | ||
#handleMessage = async ({ message }) => { | ||
if (message.type === "STATE_UPDATE") { | ||
this.#state = message.payload; | ||
return; | ||
} | ||
const self = this; | ||
if (message.type === PluginEvent.STEP_SHOWN) { | ||
return dispatchEvent({ | ||
target: this.#target, | ||
type: PluginEvent.STEP_SHOWN, | ||
detail: { instance: self, payload: message.payload }, | ||
}); | ||
} | ||
if (message.type === PluginEvent.ERROR) { | ||
return dispatchEvent({ | ||
target: this.#target, | ||
type: PluginEvent.ERROR, | ||
subtype: message.payload, | ||
detail: { instance: self }, | ||
}); | ||
} | ||
if (isAppointmentEvent(message)) { | ||
return dispatchEvent({ | ||
target: this.#target, | ||
type: message.type, | ||
detail: { instance: self }, | ||
}); | ||
} | ||
if (isInvalidEntityEvent(message)) { | ||
return dispatchEvent({ | ||
target: this.#target, | ||
type: PluginEvent.MISCONFIGURED, | ||
subtype: message.type, | ||
detail: { instance: self }, | ||
}); | ||
} | ||
if (message.type === RequestEvent.REQUEST_METADATA) { | ||
this.#instance.iFrameResizer.sendMessage({ | ||
type: RequestEvent.REQUEST_METADATA, | ||
payload: this.#meta, | ||
}); | ||
return; | ||
} | ||
if (message.type === RequestEvent.REQUEST_ORIGIN_URL) { | ||
this.#instance.iFrameResizer.sendMessage({ | ||
type: RequestEvent.REQUEST_ORIGIN_URL, | ||
payload: { href: window.location.href }, | ||
}); | ||
return; | ||
} | ||
if (message.type === RequestEvent.REQUEST_GEOLOCATION) { | ||
const geolocation = new Promise((res, rej) => { | ||
if (navigator && "geolocation" in navigator) { | ||
return navigator.geolocation.getCurrentPosition((result) => { | ||
res({ | ||
timestamp: result.timestamp, | ||
coords: { | ||
latitude: result.coords.latitude, | ||
longitude: result.coords.longitude, | ||
accuracy: result.coords.accuracy, | ||
altitude: result.coords.altitude, | ||
altitudeAccuracy: result.coords.altitudeAccuracy, | ||
heading: result.coords.heading, | ||
speed: result.coords.speed, | ||
}, | ||
}); | ||
}, rej); | ||
} | ||
rej("User location not Available"); | ||
}); | ||
this.#instance.iFrameResizer.sendMessage({ | ||
type: RequestEvent.REQUEST_GEOLOCATION, | ||
payload: await geolocation.catch((error) => ({ error })), | ||
}); | ||
return; | ||
} | ||
logger.debug("Unhandled event: ", message); | ||
}; | ||
// KEEP STABLE UNTIL February 2024 | ||
/** @private internal API */ | ||
get config() { | ||
warnPrivate({ name: "config", type: "property" }); | ||
return this.#config; | ||
const self = this; | ||
if (message.type === PluginEvent.STEP_SHOWN) { | ||
return dispatchEvent({ | ||
target: this.#target, | ||
type: PluginEvent.STEP_SHOWN, | ||
detail: { instance: self, payload: message.payload }, | ||
}); | ||
} | ||
// TODO documentation! | ||
/** Configuration of this plugin instance */ | ||
get configuration() { | ||
return this.#config.config; | ||
if (message.type === PluginEvent.ERROR) { | ||
return dispatchEvent({ | ||
target: this.#target, | ||
type: PluginEvent.ERROR, | ||
subtype: message.payload, | ||
detail: { instance: self }, | ||
}); | ||
} | ||
// KEEP STABLE UNTIL February 2024 | ||
/** @private internal API */ | ||
get hashConfig() { | ||
warnPrivate({ name: "hashConfig", type: "property" }); | ||
return encodeConfigAsHash(this.#config.config); | ||
if (isAppointmentEvent(message)) { | ||
return dispatchEvent({ | ||
target: this.#target, | ||
type: message.type, | ||
detail: { instance: self }, | ||
}); | ||
} | ||
openDebugger = () => { | ||
const searchParams = new URLSearchParams(); | ||
searchParams.append("mergedConfig", encodeURIParameters(this.#config.config)); | ||
searchParams.append("domConfig", encodeURIParameters(this.#config.domConfig)); | ||
searchParams.append("hashConfig", encodeURIParameters(this.#config.hashConfig)); | ||
searchParams.append("jsConfig", encodeURIParameters(this.#config.jsConfig)); | ||
const url = `${PluginInstance.#url}/configuration-checker?${searchParams}`; | ||
window.open(url, "plugin-debugger"); | ||
return url; | ||
}; | ||
/** Destroy the instance */ | ||
dispose = () => { | ||
this.#status = "disposed"; | ||
this.#listeners.forEach((listener) => this.#target.removeEventListener(PEXIP_ENGAGE_PLUGIN_EVENT, listener)); | ||
this.#listeners.clear(); | ||
if (typeof this.#fallbackTimeoutId === "number") { | ||
window.clearTimeout(this.#fallbackTimeoutId); | ||
} | ||
this.#instance.iFrameResizer.close(); | ||
const idx = PluginInstance.#instances.indexOf(this); | ||
PluginInstance.#instances.splice(idx, 1); | ||
}; | ||
// KEEP STABLE UNTIL February 2024 | ||
/** @private internal API */ | ||
setCSSVariable = (name, value) => { | ||
warnPrivate({ type: "function", name: "setCSSVariable" }); | ||
this.#instance.iFrameResizer.sendMessage({ | ||
type: RequestEvent.CSS_VAR_UPDATE, | ||
payload: { name, value }, | ||
}); | ||
}; | ||
setCustomCSS = (css) => { | ||
this.#instance.iFrameResizer.sendMessage({ | ||
type: RequestEvent.CUSTOM_CSS_UPDATE, | ||
payload: { css }, | ||
}); | ||
}; | ||
#listeners = new Set(); | ||
/** Add an event listener */ | ||
addEventListener = (typeOrListener, cb) => { | ||
const type = isFunction(typeOrListener) ? undefined : typeOrListener; | ||
const listener = isFunction(typeOrListener) ? typeOrListener : cb; | ||
if (!isFunction(listener)) | ||
return; | ||
function internalListener(event) { | ||
if (!isCustomEvent(event)) | ||
return true; | ||
if (type === undefined || event.detail?.type === type) | ||
return listener?.(event); | ||
} | ||
this.#listeners.add(internalListener); | ||
this.#target.addEventListener(PEXIP_ENGAGE_PLUGIN_EVENT, internalListener); | ||
}; | ||
/** The current intention */ | ||
get intention() { | ||
return this.#state?.config.intent; | ||
if (isInvalidEntityEvent(message)) { | ||
return dispatchEvent({ | ||
target: this.#target, | ||
type: PluginEvent.MISCONFIGURED, | ||
subtype: message.type, | ||
detail: { instance: self }, | ||
}); | ||
} | ||
get appointment() { | ||
return { | ||
id: this.#state?.appointmentId, | ||
location: { | ||
id: this.#state?.officeId, | ||
}, | ||
meeting_type: this.#state?.meetingType, | ||
subject: { | ||
id: this.#state?.subjectId, | ||
category_id: this.#state?.subjectCategoryId, | ||
}, | ||
meta: { | ||
getAll: () => { | ||
return this.#meta; | ||
}, | ||
get: (key, defaultValue) => { | ||
return this.#meta?.[key] ?? defaultValue; | ||
}, | ||
set: (key, value) => { | ||
if (!this.#meta) | ||
this.#meta = {}; | ||
this.#meta[key] = value; | ||
return this.#meta; | ||
}, | ||
remove: (key) => { | ||
delete this.#meta?.[key]; | ||
}, | ||
}, | ||
}; | ||
if (message.type === RequestEvent.REQUEST_METADATA) { | ||
this.#instance.iFrameResizer.sendMessage({ | ||
type: RequestEvent.REQUEST_METADATA, | ||
payload: this.#meta, | ||
}); | ||
return; | ||
} | ||
get customer() { | ||
// fallback to config value when customer state itself it still undefined? | ||
return this.#state?.customer; | ||
if (message.type === RequestEvent.REQUEST_ORIGIN_URL) { | ||
this.#instance.iFrameResizer.sendMessage({ | ||
type: RequestEvent.REQUEST_ORIGIN_URL, | ||
payload: { href: window.location.href }, | ||
}); | ||
return; | ||
} | ||
static dispose = () => { | ||
return PluginInstance.getInstance(0)?.dispose(); | ||
}; | ||
static disposeAll = () => { | ||
PluginInstance.#instances.forEach((instance) => instance.dispose()); | ||
}; | ||
static addEventListener = (...args) => { | ||
return PluginInstance.getInstance(0)?.addEventListener(...args); | ||
}; | ||
static setCSSVariable(name, value) { | ||
return PluginInstance.getInstance(0)?.setCSSVariable(name, value); | ||
if (message.type === RequestEvent.REQUEST_GEOLOCATION) { | ||
const geolocation = new Promise((res, rej) => { | ||
if (navigator && "geolocation" in navigator) { | ||
return navigator.geolocation.getCurrentPosition((result) => { | ||
res({ | ||
timestamp: result.timestamp, | ||
coords: { | ||
latitude: result.coords.latitude, | ||
longitude: result.coords.longitude, | ||
accuracy: result.coords.accuracy, | ||
altitude: result.coords.altitude, | ||
altitudeAccuracy: result.coords.altitudeAccuracy, | ||
heading: result.coords.heading, | ||
speed: result.coords.speed, | ||
}, | ||
}); | ||
}, rej); | ||
} | ||
rej("User location not Available"); | ||
}); | ||
this.#instance.iFrameResizer.sendMessage({ | ||
type: RequestEvent.REQUEST_GEOLOCATION, | ||
payload: await geolocation.catch((error) => ({ error })), | ||
}); | ||
return; | ||
} | ||
static get customer() { | ||
return PluginInstance.getInstance(0)?.customer; | ||
logger.debug("Unhandled event: ", message); | ||
}; | ||
// KEEP STABLE UNTIL February 2024 | ||
/** @private internal API */ | ||
get config() { | ||
warnPrivate({ name: "config", type: "property" }); | ||
return this.#config; | ||
} | ||
// TODO documentation! | ||
/** Configuration of this plugin instance */ | ||
get configuration() { | ||
return this.#config.config; | ||
} | ||
// KEEP STABLE UNTIL February 2024 | ||
/** @private internal API */ | ||
get hashConfig() { | ||
warnPrivate({ name: "hashConfig", type: "property" }); | ||
return encodeConfigAsHash(this.#config.config); | ||
} | ||
openDebugger = () => { | ||
const searchParams = new URLSearchParams(); | ||
searchParams.append("mergedConfig", encodeURIParameters(this.#config.config)); | ||
searchParams.append("domConfig", encodeURIParameters(this.#config.domConfig)); | ||
searchParams.append("hashConfig", encodeURIParameters(this.#config.hashConfig)); | ||
searchParams.append("jsConfig", encodeURIParameters(this.#config.jsConfig)); | ||
const url = `${PluginInstance.#url}/configuration-checker?${searchParams}`; | ||
window.open(url, "plugin-debugger"); | ||
return url; | ||
}; | ||
/** Destroy the instance */ | ||
dispose = () => { | ||
this.#status = "disposed"; | ||
this.#listeners.forEach((listener) => | ||
this.#target.removeEventListener(PEXIP_ENGAGE_PLUGIN_EVENT, listener), | ||
); | ||
this.#listeners.clear(); | ||
if (typeof this.#fallbackTimeoutId === "number") { | ||
window.clearTimeout(this.#fallbackTimeoutId); | ||
} | ||
static get appointment() { | ||
return PluginInstance.getInstance(0)?.appointment; | ||
this.#instance.iFrameResizer.close(); | ||
const idx = PluginInstance.#instances.indexOf(this); | ||
PluginInstance.#instances.splice(idx, 1); | ||
}; | ||
// KEEP STABLE UNTIL February 2024 | ||
/** @private internal API */ | ||
setCSSVariable = (name, value) => { | ||
warnPrivate({ type: "function", name: "setCSSVariable" }); | ||
this.#instance.iFrameResizer.sendMessage({ | ||
type: RequestEvent.CSS_VAR_UPDATE, | ||
payload: { name, value }, | ||
}); | ||
}; | ||
setCustomCSS = (css) => { | ||
this.#instance.iFrameResizer.sendMessage({ | ||
type: RequestEvent.CUSTOM_CSS_UPDATE, | ||
payload: { css }, | ||
}); | ||
}; | ||
#listeners = new Set(); | ||
/** Add an event listener */ | ||
addEventListener = (typeOrListener, cb) => { | ||
const type = isFunction(typeOrListener) ? undefined : typeOrListener; | ||
const listener = isFunction(typeOrListener) ? typeOrListener : cb; | ||
if (!isFunction(listener)) return; | ||
function internalListener(event) { | ||
if (!isCustomEvent(event)) return true; | ||
if (type === undefined || event.detail?.type === type) return listener?.(event); | ||
} | ||
static get intention() { | ||
return PluginInstance.getInstance(0)?.intention; | ||
} | ||
// KEEP STABLE UNTIL February 2024 | ||
/** @private internal API */ | ||
static get config() { | ||
return PluginInstance.getInstance(0)?.config; | ||
} | ||
// KEEP STABLE UNTIL February 2024 | ||
/** @private internal API */ | ||
static get hashConfig() { | ||
return PluginInstance.getInstance(0)?.hashConfig; | ||
} | ||
static openDebugger() { | ||
return PluginInstance.getInstance(0)?.openDebugger(); | ||
} | ||
static #url; | ||
// KEEP STABLE UNTIL February 2024 | ||
/** @private internal API */ | ||
static get url() { | ||
return PluginInstance.#url; | ||
} | ||
// KEEP STABLE UNTIL February 2024 | ||
/** @private internal API */ | ||
static setEnterpriseUrl = (url) => { | ||
PluginInstance.#url = url; | ||
this.#listeners.add(internalListener); | ||
this.#target.addEventListener(PEXIP_ENGAGE_PLUGIN_EVENT, internalListener); | ||
}; | ||
/** The current intention */ | ||
get intention() { | ||
return this.#state?.config.intent; | ||
} | ||
get appointment() { | ||
return { | ||
id: this.#state?.appointmentId, | ||
location: { | ||
id: this.#state?.officeId, | ||
}, | ||
meeting_type: this.#state?.meetingType, | ||
subject: { | ||
id: this.#state?.subjectId, | ||
category_id: this.#state?.subjectCategoryId, | ||
}, | ||
meta: { | ||
getAll: () => { | ||
return this.#meta; | ||
}, | ||
get: (key, defaultValue) => { | ||
return this.#meta?.[key] ?? defaultValue; | ||
}, | ||
set: (key, value) => { | ||
if (!this.#meta) this.#meta = {}; | ||
this.#meta[key] = value; | ||
return this.#meta; | ||
}, | ||
remove: (key) => { | ||
delete this.#meta?.[key]; | ||
}, | ||
}, | ||
}; | ||
static #instances = []; | ||
static getInstance = (num) => { | ||
if (!isPositiveNumber(num)) | ||
return undefined; | ||
return PluginInstance.#instances[num]; | ||
}; | ||
static awaitFirstInstance = async () => { | ||
const instance = PluginInstance.getInstance(0); | ||
if (instance) | ||
return instance; | ||
return new Promise((resolve, reject) => { | ||
function listener(event) { | ||
if (event instanceof CustomEvent) { | ||
if (event.detail.type === PluginInstance.EVENT_CREATION) { | ||
document.removeEventListener(PEXIP_ENGAGE_PLUGIN_EVENT, listener); | ||
return resolve(event.detail.instance); | ||
} | ||
else if (event.detail.type === PluginInstance.EVENT_MISCONFIGURED || | ||
event.detail.type === PluginInstance.EVENT_ERROR) { | ||
document.removeEventListener(PEXIP_ENGAGE_PLUGIN_EVENT, listener); | ||
const errorMessage = typeof event.detail.subtype === "string" | ||
? `${event.detail.type}: ${event.detail.subtype}` | ||
: event.detail.type; | ||
return reject(errorMessage); | ||
} | ||
} | ||
} | ||
document.addEventListener(PEXIP_ENGAGE_PLUGIN_EVENT, listener); | ||
}); | ||
}; | ||
static get count() { | ||
return PluginInstance.#instances.length; | ||
} | ||
static EVENT_APPOINTMENT_CANCELLED = PluginEvent.APPOINTMENT_CANCELLED; | ||
static EVENT_APPOINTMENT_COMPLETED = PluginEvent.APPOINTMENT_COMPLETED; | ||
static EVENT_APPOINTMENT_CREATED = PluginEvent.APPOINTMENT_CREATED; | ||
static EVENT_INVITE_ACCEPTED = PluginEvent.INVITE_ACCEPTED; | ||
static EVENT_APPOINTMENT_EDITED = PluginEvent.APPOINTMENT_EDITED; | ||
static EVENT_CREATION = PluginEvent.CREATION; | ||
static EVENT_ERROR = PluginEvent.ERROR; | ||
static EVENT_INIT = PluginEvent.INIT; | ||
static EVENT_LOADED = PluginEvent.LOADED; | ||
static EVENT_MISCONFIGURED = PluginEvent.MISCONFIGURED; | ||
static EVENT_STEP_SHOWN = PluginEvent.STEP_SHOWN; | ||
static MISCONFIGURED_CLIENT_ID = PluginMisconfigured.CLIENT_ID; | ||
static MISCONFIGURED_CONTACT_HINTS = PluginMisconfigured.CONTACT_HINTS; | ||
static MISCONFIGURED_GEOLOCATION = PluginMisconfigured.GEOLOCATION; | ||
static MISCONFIGURED_INTENT_WITHOUT_RESOURCE_CODE = PluginMisconfigured.INTENT_WITHOUT_RESOURCE_CODE; | ||
static MISCONFIGURED_LISTING_ID = PluginMisconfigured.LISTING_ID; | ||
static MISCONFIGURED_OFFICE_ID = PluginMisconfigured.OFFICE_ID; | ||
static MISCONFIGURED_RESOURCE_CODE = PluginMisconfigured.RESOURCE_CODE; | ||
static MISCONFIGURED_SUBJECT_ID = PluginMisconfigured.SUBJECT_ID; | ||
static MISCONFIGURED_TIMEZONE = PluginMisconfigured.TIMEZONE; | ||
static ERROR_API_DOWN = PluginError.API_DOWN; | ||
static ERROR_RECAPTCHA_SCRIPT_LOAD = PluginError.RECAPTCHA_SCRIPT_LOAD; | ||
static ERROR_SUB_DATE_INTERPOLATION = PluginError.SUB_DATE_INTERPOLATION; | ||
static ERROR_TRANSLATION = PluginError.TRANSLATION; | ||
static INTENT_CANCEL = "cancel"; | ||
static INTENT_EDIT = "edit"; | ||
static INTENT_INVITE = "invite"; | ||
static INTENT_RESCHEDULE = "reschedule"; | ||
static INTENT_COMPLETE = "complete"; | ||
static INTENT_SCHEDULE = "schedule"; | ||
} | ||
get customer() { | ||
// fallback to config value when customer state itself it still undefined? | ||
return this.#state?.customer; | ||
} | ||
static dispose = () => { | ||
return PluginInstance.getInstance(0)?.dispose(); | ||
}; | ||
static disposeAll = () => { | ||
PluginInstance.#instances.forEach((instance) => instance.dispose()); | ||
}; | ||
static addEventListener = (...args) => { | ||
return PluginInstance.getInstance(0)?.addEventListener(...args); | ||
}; | ||
static setCSSVariable(name, value) { | ||
return PluginInstance.getInstance(0)?.setCSSVariable(name, value); | ||
} | ||
static get customer() { | ||
return PluginInstance.getInstance(0)?.customer; | ||
} | ||
static get appointment() { | ||
return PluginInstance.getInstance(0)?.appointment; | ||
} | ||
static get intention() { | ||
return PluginInstance.getInstance(0)?.intention; | ||
} | ||
// KEEP STABLE UNTIL February 2024 | ||
/** @private internal API */ | ||
static get config() { | ||
return PluginInstance.getInstance(0)?.config; | ||
} | ||
// KEEP STABLE UNTIL February 2024 | ||
/** @private internal API */ | ||
static get hashConfig() { | ||
return PluginInstance.getInstance(0)?.hashConfig; | ||
} | ||
static openDebugger() { | ||
return PluginInstance.getInstance(0)?.openDebugger(); | ||
} | ||
static #url; | ||
// KEEP STABLE UNTIL February 2024 | ||
/** @private internal API */ | ||
static get url() { | ||
return PluginInstance.#url; | ||
} | ||
// KEEP STABLE UNTIL February 2024 | ||
/** @private internal API */ | ||
static setEnterpriseUrl = (url) => { | ||
PluginInstance.#url = url; | ||
}; | ||
static #instances = []; | ||
static getInstance = (num) => { | ||
if (!isPositiveNumber(num)) return undefined; | ||
return PluginInstance.#instances[num]; | ||
}; | ||
static awaitFirstInstance = async () => { | ||
const instance = PluginInstance.getInstance(0); | ||
if (instance) return instance; | ||
return new Promise((resolve, reject) => { | ||
function listener(event) { | ||
if (event instanceof CustomEvent) { | ||
if (event.detail.type === PluginInstance.EVENT_CREATION) { | ||
document.removeEventListener(PEXIP_ENGAGE_PLUGIN_EVENT, listener); | ||
return resolve(event.detail.instance); | ||
} else if ( | ||
event.detail.type === PluginInstance.EVENT_MISCONFIGURED || | ||
event.detail.type === PluginInstance.EVENT_ERROR | ||
) { | ||
document.removeEventListener(PEXIP_ENGAGE_PLUGIN_EVENT, listener); | ||
const errorMessage = | ||
typeof event.detail.subtype === "string" | ||
? `${event.detail.type}: ${event.detail.subtype}` | ||
: event.detail.type; | ||
return reject(errorMessage); | ||
} | ||
} | ||
} | ||
document.addEventListener(PEXIP_ENGAGE_PLUGIN_EVENT, listener); | ||
}); | ||
}; | ||
static get count() { | ||
return PluginInstance.#instances.length; | ||
} | ||
static EVENT_APPOINTMENT_CANCELLED = PluginEvent.APPOINTMENT_CANCELLED; | ||
static EVENT_APPOINTMENT_COMPLETED = PluginEvent.APPOINTMENT_COMPLETED; | ||
static EVENT_APPOINTMENT_CREATED = PluginEvent.APPOINTMENT_CREATED; | ||
static EVENT_INVITE_ACCEPTED = PluginEvent.INVITE_ACCEPTED; | ||
static EVENT_APPOINTMENT_EDITED = PluginEvent.APPOINTMENT_EDITED; | ||
static EVENT_CREATION = PluginEvent.CREATION; | ||
static EVENT_ERROR = PluginEvent.ERROR; | ||
static EVENT_INIT = PluginEvent.INIT; | ||
static EVENT_LOADED = PluginEvent.LOADED; | ||
static EVENT_MISCONFIGURED = PluginEvent.MISCONFIGURED; | ||
static EVENT_STEP_SHOWN = PluginEvent.STEP_SHOWN; | ||
static MISCONFIGURED_CLIENT_ID = PluginMisconfigured.CLIENT_ID; | ||
static MISCONFIGURED_CONTACT_HINTS = PluginMisconfigured.CONTACT_HINTS; | ||
static MISCONFIGURED_GEOLOCATION = PluginMisconfigured.GEOLOCATION; | ||
static MISCONFIGURED_INTENT_WITHOUT_RESOURCE_CODE = | ||
PluginMisconfigured.INTENT_WITHOUT_RESOURCE_CODE; | ||
static MISCONFIGURED_LISTING_ID = PluginMisconfigured.LISTING_ID; | ||
static MISCONFIGURED_OFFICE_ID = PluginMisconfigured.OFFICE_ID; | ||
static MISCONFIGURED_RESOURCE_CODE = PluginMisconfigured.RESOURCE_CODE; | ||
static MISCONFIGURED_SUBJECT_ID = PluginMisconfigured.SUBJECT_ID; | ||
static MISCONFIGURED_TIMEZONE = PluginMisconfigured.TIMEZONE; | ||
static ERROR_API_DOWN = PluginError.API_DOWN; | ||
static ERROR_RECAPTCHA_SCRIPT_LOAD = PluginError.RECAPTCHA_SCRIPT_LOAD; | ||
static ERROR_SUB_DATE_INTERPOLATION = PluginError.SUB_DATE_INTERPOLATION; | ||
static ERROR_TRANSLATION = PluginError.TRANSLATION; | ||
static INTENT_CANCEL = "cancel"; | ||
static INTENT_EDIT = "edit"; | ||
static INTENT_INVITE = "invite"; | ||
static INTENT_RESCHEDULE = "reschedule"; | ||
static INTENT_COMPLETE = "complete"; | ||
static INTENT_SCHEDULE = "schedule"; | ||
} | ||
function isPositiveNumber(num) { | ||
return typeof num === "number" && num >= 0; | ||
return typeof num === "number" && num >= 0; | ||
} | ||
function isCustomEvent(event) { | ||
return event instanceof CustomEvent; | ||
return event instanceof CustomEvent; | ||
} | ||
function isElement(element) { | ||
return element instanceof HTMLElement; | ||
return element instanceof HTMLElement; | ||
} | ||
function isValidConfiguration(configuration) { | ||
return typeof configuration === "object" && configuration !== null; | ||
return typeof configuration === "object" && configuration !== null; | ||
} | ||
function isFunction(fn) { | ||
return fn instanceof Function; | ||
return fn instanceof Function; | ||
} | ||
const APPOINTMENT_EVENTS = [ | ||
PluginEvent.APPOINTMENT_CANCELLED, | ||
PluginEvent.APPOINTMENT_COMPLETED, | ||
PluginEvent.APPOINTMENT_CREATED, | ||
PluginEvent.INVITE_ACCEPTED, | ||
PluginEvent.APPOINTMENT_EDITED, | ||
PluginEvent.APPOINTMENT_CANCELLED, | ||
PluginEvent.APPOINTMENT_COMPLETED, | ||
PluginEvent.APPOINTMENT_CREATED, | ||
PluginEvent.INVITE_ACCEPTED, | ||
PluginEvent.APPOINTMENT_EDITED, | ||
]; | ||
function isAppointmentEvent(message) { | ||
return APPOINTMENT_EVENTS.includes(message.type); | ||
return APPOINTMENT_EVENTS.includes(message.type); | ||
} | ||
const INVALID_ENTITY_EVENTS = [ | ||
PluginMisconfigured.EMPLOYEE_ID, | ||
PluginMisconfigured.INTENT_WITHOUT_RESOURCE_CODE, | ||
PluginMisconfigured.INVALID_FLOW, | ||
PluginMisconfigured.INVALID_INTENT, | ||
PluginMisconfigured.INVALID_RESOURCE_CODE, | ||
PluginMisconfigured.MEETING_TYPE, | ||
PluginMisconfigured.OFFICE_ID, | ||
PluginMisconfigured.SUBJECT_ID, | ||
PluginMisconfigured.EMPLOYEE_ID, | ||
PluginMisconfigured.INTENT_WITHOUT_RESOURCE_CODE, | ||
PluginMisconfigured.INVALID_FLOW, | ||
PluginMisconfigured.INVALID_INTENT, | ||
PluginMisconfigured.INVALID_RESOURCE_CODE, | ||
PluginMisconfigured.MEETING_TYPE, | ||
PluginMisconfigured.OFFICE_ID, | ||
PluginMisconfigured.SUBJECT_ID, | ||
]; | ||
function isInvalidEntityEvent(message) { | ||
return INVALID_ENTITY_EVENTS.includes(message.type); | ||
return INVALID_ENTITY_EVENTS.includes(message.type); | ||
} | ||
function queueMacroTask(fn) { | ||
setTimeout(fn); | ||
setTimeout(fn); | ||
} | ||
function warnPrivate({ name, type }) { | ||
logger.warn(`The ${type} "${name}" is intended for debugging purposes only and might be changed at any time without notice. Its use in production is strongly discouraged and not supported`); | ||
logger.warn( | ||
`The ${type} "${name}" is intended for debugging purposes only and might be changed at any time without notice. Its use in production is strongly discouraged and not supported`, | ||
); | ||
} |
{ | ||
"name": "@pexip-engage-public/plugin-instance", | ||
"version": "2.0.0-canary-20231023080955", | ||
"version": "2.0.0-canary-20231025101109", | ||
"homepage": "https://github.com/skedify/frontend-mono/tree/develop/apps/plugin-remix/packages/plugin-instance#readme", | ||
@@ -33,11 +33,11 @@ "bugs": { | ||
"iframe-resizer": "^4.3.7", | ||
"@pexip-engage-public/plugin-configuration-parser": "2.0.0-canary-20231023080955", | ||
"@pexip-engage-public/plugin-events": "2.0.0-canary-20231023080955", | ||
"@pexip-engage-public/plugin-state": "2.0.0-canary-20231023080955", | ||
"@pexip-engage-public/plugin-utils": "2.0.0-canary-20231023080955" | ||
"@pexip-engage-public/plugin-state": "2.0.0-canary-20231025101109", | ||
"@pexip-engage-public/plugin-utils": "2.0.0-canary-20231025101109", | ||
"@pexip-engage-public/plugin-configuration-parser": "2.0.0-canary-20231025101109", | ||
"@pexip-engage-public/plugin-events": "2.0.0-canary-20231025101109" | ||
}, | ||
"devDependencies": { | ||
"@eslint/eslintrc": "^2.1.2", | ||
"@pexip-engage/tsconfig": "0.0.10-canary-20231023080955", | ||
"eslint-config-pexip-engage": "0.0.40" | ||
"@pexip-engage/tsconfig": "0.0.10-canary-20231025101109", | ||
"eslint-config-pexip-engage": "0.0.41-canary-20231025101109" | ||
}, | ||
@@ -44,0 +44,0 @@ "volta": { |
Sorry, the diff of this file is not supported yet
2109
104746
+ Added@pexip-engage-public/plugin-configuration@2.0.0-canary-20231025101109(transitive)
+ Added@pexip-engage-public/plugin-configuration-parser@2.0.0-canary-20231025101109(transitive)
+ Added@pexip-engage-public/plugin-events@2.0.0-canary-20231025101109(transitive)
+ Added@pexip-engage-public/plugin-state@2.0.0-canary-20231025101109(transitive)
+ Added@pexip-engage-public/plugin-utils@2.0.0-canary-20231025101109(transitive)
- Removed@pexip-engage-public/plugin-configuration@2.0.0-canary-20231023080955(transitive)
- Removed@pexip-engage-public/plugin-configuration-parser@2.0.0-canary-20231023080955(transitive)
- Removed@pexip-engage-public/plugin-events@2.0.0-canary-20231023080955(transitive)
- Removed@pexip-engage-public/plugin-state@2.0.0-canary-20231023080955(transitive)
- Removed@pexip-engage-public/plugin-utils@2.0.0-canary-20231023080955(transitive)
Updated@pexip-engage-public/plugin-configuration-parser@2.0.0-canary-20231025101109
Updated@pexip-engage-public/plugin-events@2.0.0-canary-20231025101109
Updated@pexip-engage-public/plugin-state@2.0.0-canary-20231025101109
Updated@pexip-engage-public/plugin-utils@2.0.0-canary-20231025101109