From 573362e6d10bcb2f5fba612e3ae1b7e5702a0a31 Mon Sep 17 00:00:00 2001 From: hemang-thakkar Date: Mon, 9 Sep 2024 22:55:09 +0000 Subject: [PATCH] =?UTF-8?q?Deploy=20preview=20for=20PR=20222=20?= =?UTF-8?q?=F0=9F=9B=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pr-preview/pr-222/demo-minimal-js.bundle.js | 6 +++--- pr-preview/pr-222/demo-react-ts.bundle.js | 2 +- pr-preview/pr-222/demo-react-ts.bundle.js.map | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pr-preview/pr-222/demo-minimal-js.bundle.js b/pr-preview/pr-222/demo-minimal-js.bundle.js index 251f870..7971018 100644 --- a/pr-preview/pr-222/demo-minimal-js.bundle.js +++ b/pr-preview/pr-222/demo-minimal-js.bundle.js @@ -36,7 +36,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac \**************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _IFrameManager__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./IFrameManager */ \"../../src/IFrameManager.js\");\n/* harmony import */ var _Constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Constants */ \"../../src/Constants.js\");\n// @ts-check\n\n\"use es6\";\n\n\n\n\nconst prefix = `[calling-extensions-sdk@${_Constants__WEBPACK_IMPORTED_MODULE_1__.VERSION}]`;\n\n/*\n * CallingExtensions allows call providers to communicate with HubSpot.\n */\nclass CallingExtensions {\n /**\n * @param {import('./typedefs').Options} options\n */\n constructor(options) {\n if (!options || !options.eventHandlers) {\n throw new Error(\"Invalid options or missing eventHandlers.\");\n }\n\n this.options = options;\n\n this.iFrameManager = new _IFrameManager__WEBPACK_IMPORTED_MODULE_0__[\"default\"]({\n iFrameOptions: options.iFrameOptions,\n debugMode: options.debugMode,\n onMessageHandler: (/** @type {any} */ event) =>\n // eslint-disable-next-line implicit-arrow-linebreak\n this.onMessageHandler(event),\n });\n }\n\n /**\n * Send a message indicating that the soft phone is ready for interaction.\n *\n * @param {import('./typedefs').OnInitialized} payload\n */\n initialized(payload) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.INITIALIZED,\n data: payload,\n });\n }\n\n /**\n * Event when user's availability is changed to available\n */\n userAvailable() {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.USER_AVAILABLE,\n });\n }\n\n /**\n * Event when user's availability is changed to unavailable\n */\n userUnavailable() {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.USER_UNAVAILABLE,\n });\n }\n\n /**\n * Sends a message indicating that the user has logged in.\n */\n userLoggedIn() {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.LOGGED_IN,\n });\n }\n\n /**\n * Sends a message indicating that the user has logged out.\n */\n userLoggedOut() {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.LOGGED_OUT,\n });\n }\n\n /**\n * Event when incoming call is received.\n *\n * @param {import('./typedefs').OnIncomingCall} callInfo\n */\n incomingCall(callInfo) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.INCOMING_CALL,\n data: callInfo,\n });\n }\n\n /**\n * Sends a message to notify HubSpot that an outgoing call has started.\n *\n * @param {import('./typedefs').OnOutgoingCall} callInfo\n */\n outgoingCall(callInfo) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.OUTGOING_CALL_STARTED,\n data: callInfo,\n });\n }\n\n /**\n * Sends a message to notify HubSpot that a call is being answered.\n *\n * @param {import('./typedefs').OnCallAnswered} payload\n */\n callAnswered(payload) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.CALL_ANSWERED,\n data: payload,\n });\n }\n\n /**\n * Event to navigate to record page.\n *\n * @param {import('./typedefs').OnNavigateToRecord} payload\n */\n navigateToRecord(payload) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.NAVIGATE_TO_RECORD,\n data: payload,\n });\n }\n\n /**\n * @param {any} payload\n */\n callData(payload) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.CALL_DATA,\n data: payload,\n });\n }\n\n /**\n * Sends a message to notify HubSpot that the call has ended.\n *\n * @param {import('./typedefs').OnCallEnded} data\n */\n callEnded(data) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.CALL_ENDED,\n data,\n });\n }\n\n /**\n * Sends a message to notify HubSpot that the call has completed.\n *\n * @param {import('./typedefs').OnCallCompleted} data\n */\n callCompleted(data) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.CALL_COMPLETED,\n data,\n });\n }\n\n /**\n * Sends a message to notify HubSpot that the calling app has encountered an error.\n * @param {import('./typedefs').OnError} data\n */\n sendError(data) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.ERROR,\n data,\n });\n }\n\n /**\n * Sends a message to notify HubSpot that the calling app needs to be resized.\n *\n * @param {import('./typedefs').OnResize} data\n */\n resizeWidget(data) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.RESIZE_WIDGET,\n data,\n });\n }\n\n /**\n *\n * @param {import('./typedefs').onMessage} message\n */\n sendMessage(message) {\n this.iFrameManager.sendMessage(message);\n }\n\n /**\n *\n * @param {{message: string, type: string}} param0\n */\n logDebugMessage({ message, type = _Constants__WEBPACK_IMPORTED_MODULE_1__.debugMessageType.GENERIC_MESSAGE }) {\n this.iFrameManager.logDebugMessage(prefix, type, message);\n }\n\n /**\n * @param {{ type: keyof import('./typedefs').EventHandlers; data: any; }} event\n */\n onMessageHandler(event) {\n const { type, data } = event;\n const { eventHandlers } = this.options;\n\n let handler;\n if (type in _Constants__WEBPACK_IMPORTED_MODULE_1__.messageHandlerNames) {\n const name = _Constants__WEBPACK_IMPORTED_MODULE_1__.messageHandlerNames[type];\n handler = eventHandlers[name];\n } else {\n // Send back a message indicating an unknown event is received\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.ERROR,\n data: {\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.errorType.UNKNOWN_MESSAGE_TYPE,\n data: {\n originalMessage: event,\n },\n },\n });\n }\n\n handler = handler || eventHandlers.defaultEventHandler;\n if (handler) {\n handler(data, event);\n } else {\n console.error(\n `No event handler is available to handle message of type: ${type}`,\n );\n }\n }\n\n /**\n * Publishes the call to a connected channel.\n *\n * @param {import('./typedefs').OnPublishToChannel} data - The data object to be published.\n */\n publishToChannel(data) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.PUBLISH_TO_CHANNEL,\n data,\n });\n }\n}\n\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (CallingExtensions);\n\n\n//# sourceURL=webpack://calling-extensions-sdk-demo-minimal-js/../../src/CallingExtensions.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _IFrameManager__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./IFrameManager */ \"../../src/IFrameManager.js\");\n/* harmony import */ var _Constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Constants */ \"../../src/Constants.js\");\n// @ts-check\n\n\"use es6\";\n\n\n\n\nconst prefix = `[calling-extensions-sdk@${_Constants__WEBPACK_IMPORTED_MODULE_1__.VERSION}]`;\n\n/*\n * CallingExtensions allows call providers to communicate with HubSpot.\n */\nclass CallingExtensions {\n /**\n * @param {import('./typedefs').Options} options\n */\n constructor(options) {\n if (!options || !options.eventHandlers) {\n throw new Error(\"Invalid options or missing eventHandlers.\");\n }\n\n this.options = options;\n\n this.iFrameManager = new _IFrameManager__WEBPACK_IMPORTED_MODULE_0__[\"default\"]({\n iFrameOptions: options.iFrameOptions,\n debugMode: options.debugMode,\n onMessageHandler: (/** @type {any} */ event) =>\n // eslint-disable-next-line implicit-arrow-linebreak\n this.onMessageHandler(event),\n });\n }\n\n /**\n * Send a message indicating that the soft phone is ready for interaction.\n *\n * @param {import('./typedefs').OnInitialized} payload\n */\n initialized(payload) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.INITIALIZED,\n data: payload,\n });\n }\n\n /**\n * Event when user's availability is changed to available\n */\n userAvailable() {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.USER_AVAILABLE,\n });\n }\n\n /**\n * Event when user's availability is changed to unavailable\n */\n userUnavailable() {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.USER_UNAVAILABLE,\n });\n }\n\n /**\n * Sends a message indicating that the user has logged in.\n */\n userLoggedIn() {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.LOGGED_IN,\n });\n }\n\n /**\n * Sends a message indicating that the user has logged out.\n */\n userLoggedOut() {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.LOGGED_OUT,\n });\n }\n\n /**\n * Event when incoming call is received.\n *\n * @param {import('./typedefs').OnIncomingCall} callInfo\n */\n incomingCall(callInfo) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.INCOMING_CALL,\n data: callInfo,\n });\n }\n\n /**\n * Sends a message to notify HubSpot that an outgoing call has started.\n *\n * @param {import('./typedefs').OnOutgoingCall} callInfo\n */\n outgoingCall(callInfo) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.OUTGOING_CALL_STARTED,\n data: callInfo,\n });\n }\n\n /**\n * Sends a message to notify HubSpot that a call is being answered.\n *\n * @param {import('./typedefs').OnCallAnswered} payload\n */\n callAnswered(payload) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.CALL_ANSWERED,\n data: payload,\n });\n }\n\n /**\n * Event to navigate to record page.\n *\n * @param {import('./typedefs').OnNavigateToRecord} payload\n */\n navigateToRecord(payload) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.NAVIGATE_TO_RECORD,\n data: payload,\n });\n }\n\n /**\n * @param {any} payload\n */\n callData(payload) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.CALL_DATA,\n data: payload,\n });\n }\n\n /**\n * Sends a message to notify HubSpot that the call has ended.\n *\n * @param {import('./typedefs').OnCallEnded} data\n */\n callEnded(data) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.CALL_ENDED,\n data,\n });\n }\n\n /**\n * Sends a message to notify HubSpot that the call has completed.\n *\n * @param {import('./typedefs').OnCallCompleted} data\n */\n callCompleted(data) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.CALL_COMPLETED,\n data,\n });\n }\n\n /**\n * Sends a message to notify HubSpot that the calling app has encountered an error.\n * @param {import('./typedefs').OnError} data\n */\n sendError(data) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.ERROR,\n data,\n });\n }\n\n /**\n * Sends a message to notify HubSpot that the calling app needs to be resized.\n *\n * @param {import('./typedefs').OnResize} data\n */\n resizeWidget(data) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.RESIZE_WIDGET,\n data,\n });\n }\n\n /**\n *\n * @param {import('./typedefs').OnMessage} message\n */\n sendMessage(message) {\n this.iFrameManager.sendMessage(message);\n }\n\n /**\n *\n * @param {{message: string, type: string}} param0\n */\n logDebugMessage({ message, type = _Constants__WEBPACK_IMPORTED_MODULE_1__.debugMessageType.GENERIC_MESSAGE }) {\n this.iFrameManager.logDebugMessage(prefix, type, message);\n }\n\n /**\n * @param {{ type: keyof import('./typedefs').EventHandlers; data: any; }} event\n */\n onMessageHandler(event) {\n const { type, data } = event;\n const { eventHandlers } = this.options;\n\n let handler;\n if (type in _Constants__WEBPACK_IMPORTED_MODULE_1__.messageHandlerNames) {\n const name = _Constants__WEBPACK_IMPORTED_MODULE_1__.messageHandlerNames[type];\n handler = eventHandlers[name];\n } else {\n // Send back a message indicating an unknown event is received\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.ERROR,\n data: {\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.errorType.UNKNOWN_MESSAGE_TYPE,\n data: {\n originalMessage: event,\n },\n },\n });\n }\n\n handler = handler || eventHandlers.defaultEventHandler;\n if (handler) {\n handler(data, event);\n } else {\n console.error(\n `No event handler is available to handle message of type: ${type}`,\n );\n }\n }\n\n /**\n * Publishes the call to a connected channel.\n *\n * @param {import('./typedefs').OnPublishToChannel} data - The data object to be published.\n */\n publishToChannel(data) {\n this.sendMessage({\n type: _Constants__WEBPACK_IMPORTED_MODULE_1__.messageType.PUBLISH_TO_CHANNEL,\n data,\n });\n }\n}\n\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (CallingExtensions);\n\n\n//# sourceURL=webpack://calling-extensions-sdk-demo-minimal-js/../../src/CallingExtensions.js?"); /***/ }), @@ -56,7 +56,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac \**********************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Constants */ \"../../src/Constants.js\");\n// @ts-check\n\n\"use es6\";\n\n\n\nconst prefix = `[calling-extensions-sdk@${_Constants__WEBPACK_IMPORTED_MODULE_0__.VERSION}]`;\n/*\n * IFrameManager abstracts the iFrame communication between the IFrameHost and an IFrame\n * An IFrameManager instance can act as part of the IFrameHost and an IFrame depending on\n * the options.\n */\nclass IFrameManager {\n /**\n *\n * @param {import('./typedefs').IframeManagerOptions} options\n */\n constructor(options) {\n /** @type {import('./typedefs').IframeManagerOptions | null} */\n this.options = options;\n const { iFrameOptions, onMessageHandler, debugMode } = options;\n\n this.onMessageHandler = onMessageHandler;\n if (!this.onMessageHandler) {\n throw new Error(\"Invalid options: onMessageHandler is not defined\");\n }\n this.isIFrameHost = !!iFrameOptions;\n this.debugMode = debugMode;\n\n // Keeps track of all the callbacks\n /** @type {{ [key: string]: Function }} */\n this.callbacks = {};\n\n this.instanceId = Date.now();\n this.instanceRegexp = new RegExp(`^${this.instanceId}`);\n this.isReady = false;\n\n this.messageHandler = (/** @type {any} */ event) => this.onMessage(event);\n window.addEventListener(\"message\", this.messageHandler);\n\n if (iFrameOptions) {\n /** @type {HTMLIFrameElement | null} */\n this.iFrame = IFrameManager.createIFrame(\n iFrameOptions,\n () => {\n this.firstSyncSent = Date.now();\n this.isReady = false;\n this.sendSync();\n },\n this.handleLoadError,\n );\n } else {\n /** @type {HTMLIFrameElement | null} */\n this.iFrame = null;\n }\n\n this.destinationWindow =\n iFrameOptions && this.iFrame ? this.iFrame.contentWindow : window.parent;\n\n this.destinationHost = IFrameManager.getDestinationHost(iFrameOptions);\n }\n\n /**\n * Creates a new message id\n * @param {string|number} instanceId\n * @returns {string}\n */\n static createMessageId(instanceId) {\n return `${instanceId}_${Date.now()}`;\n }\n\n /**\n * Gets the html element that hosts the iFrame\n * @param {string} hostElementSelector\n */\n static getHostElement(hostElementSelector) {\n const hostElement = document.querySelector(hostElementSelector);\n if (!hostElement) {\n throw new Error(\n `hostElement not found. Selector - ${hostElementSelector}`,\n );\n }\n return hostElement;\n }\n\n /**\n * @param {string} url\n */\n static extractHostFromUrl(url) {\n const a = document.createElement(\"a\");\n a.href = url;\n return `${a.protocol}//${a.host}`;\n }\n\n /**\n *\n * @param {import('./typedefs').IframeOptions} iFrameOptions\n */\n static getDestinationHost(iFrameOptions) {\n const url = iFrameOptions ? iFrameOptions.src : document.referrer;\n return IFrameManager.extractHostFromUrl(url);\n }\n\n handleLoadError() {\n this.onMessageHandler({\n type: _Constants__WEBPACK_IMPORTED_MODULE_0__.messageType.SYNC_ACK_FAILED,\n });\n }\n\n /**\n * @param {import('./typedefs').IframeOptions} iFrameOptions\n * @param { (this: GlobalEventHandlers, ev: Event) => any } onLoadCallback\n * @param { OnErrorEventHandler } onLoadErrorCallback\n * @returns {HTMLIFrameElement | null}\n */\n static createIFrame(iFrameOptions, onLoadCallback, onLoadErrorCallback) {\n // eslint-disable-next-line object-curly-newline\n const { src, width, height, hostElementSelector } = iFrameOptions;\n\n if (!src || !width || !height || !hostElementSelector) {\n throw new Error(\n \"iFrameOptions is missing one of the required properties - {src, width, height, hostElementSelector}.\",\n );\n }\n\n /** @type {HTMLIFrameElement} */\n const iFrame = document.createElement(\"iframe\");\n iFrame.onload = onLoadCallback;\n iFrame.onerror = onLoadErrorCallback;\n iFrame.src = src;\n iFrame.width = width;\n iFrame.height = height;\n iFrame.allow = \"microphone; autoplay\";\n iFrame.id = \"hubspot-calling-extension-iframe\";\n\n const element = IFrameManager.getHostElement(hostElementSelector);\n element.innerHTML = \"\";\n element.appendChild(iFrame);\n\n return element.querySelector(\"iframe\");\n }\n\n /**\n * @param {import('./typedefs').SizeInfo} sizeInfo\n */\n updateIFrameSize(sizeInfo) {\n const { width, height } = sizeInfo;\n const formatSize = (/** @type {number} */ size) => {\n return typeof size === \"number\" ? `${size}px` : size;\n };\n if (width && this.iFrame) {\n this.iFrame.setAttribute(\"width\", formatSize(width));\n }\n if (height && this.iFrame) {\n this.iFrame.setAttribute(\"height\", formatSize(height));\n }\n }\n\n onReady(data = {}) {\n this.isReady = true;\n this.onMessageHandler({\n type: _Constants__WEBPACK_IMPORTED_MODULE_0__.messageType.READY,\n data,\n });\n }\n\n /*\n * Unload the iFrame\n */\n remove() {\n window.removeEventListener(\"message\", this.messageHandler);\n\n if (this.iFrame && this.options) {\n const element = IFrameManager.getHostElement(\n this.options.iFrameOptions.hostElementSelector,\n );\n element.innerHTML = \"\";\n\n this.isReady = false;\n this.iFrame = null;\n this.options = null;\n }\n }\n\n /**\n * Send a message to the destination window.\n * @param {{type: string, messageId?: string|number, hostUrl?: string}} message\n * @param {function} [callback]\n */\n sendMessage(message, callback) {\n const { type } = message;\n if (type !== _Constants__WEBPACK_IMPORTED_MODULE_0__.messageType.SYNC && !this.isReady) {\n // Do not send a message unless the iFrame is ready to receive.\n console.warn(\n prefix,\n \"iFrame not initialized to send a message within HubSpot\",\n message,\n );\n return;\n }\n\n let { messageId } = message;\n if (!messageId) {\n // Initiating a new message\n messageId = IFrameManager.createMessageId(this.instanceId);\n if (callback) {\n // Keep track of the callback\n this.callbacks[messageId] = callback;\n }\n }\n\n const newMessage = Object.assign({}, message, {\n messageId,\n });\n\n this.logDebugMessage(prefix, _Constants__WEBPACK_IMPORTED_MODULE_0__.debugMessageType.TO_HUBSPOT, type, message);\n if (this.destinationWindow) {\n this.destinationWindow.postMessage(newMessage, this.destinationHost);\n }\n }\n\n /**\n * @param {{ data: any; origin?: any; }} event\n */\n onMessage(event) {\n const { data, origin } = event;\n // eslint-disable-next-line object-curly-newline\n const { type, engagementId, portalId, userId, ownerId } = event.data;\n if (type === _Constants__WEBPACK_IMPORTED_MODULE_0__.messageType.SYNC) {\n // The iFrame host can send this message multiple times, don't respond more than once\n if (!this.isReady) {\n this.isReady = true;\n\n const message = Object.assign({}, event.data, {\n type: _Constants__WEBPACK_IMPORTED_MODULE_0__.messageType.SYNC_ACK,\n debugMode: this.debugMode,\n version: _Constants__WEBPACK_IMPORTED_MODULE_0__.VERSION,\n iFrameUrl: IFrameManager.extractHostFromUrl(window.location.href),\n });\n\n const { hostUrl } = event.data;\n this.destinationHost = hostUrl || this.destinationHost;\n this.logDebugMessage(prefix, _Constants__WEBPACK_IMPORTED_MODULE_0__.debugMessageType.FROM_HUBSPOT, type, data);\n this.sendMessage(message);\n this.onReady({\n engagementId,\n portalId,\n userId,\n ownerId,\n });\n }\n return;\n }\n\n if (this.destinationHost !== origin) {\n // Ignore messages from an unknown origin\n return;\n }\n\n if (type === _Constants__WEBPACK_IMPORTED_MODULE_0__.messageType.SET_WIDGET_URL) {\n const { iFrameUrl } = data;\n this.destinationHost = iFrameUrl || this.destinationHost;\n return;\n }\n\n const { messageId } = data;\n\n if (!messageId || !type) {\n return;\n }\n\n this.logDebugMessage(prefix, _Constants__WEBPACK_IMPORTED_MODULE_0__.debugMessageType.FROM_HUBSPOT, type, data);\n if (this.instanceRegexp.test(messageId)) {\n // This is a response to some message generated by HubSpot\n const callBack = this.callbacks[messageId];\n if (callBack) {\n callBack(data);\n delete this.callbacks[messageId];\n }\n return;\n }\n\n // This is a new message, let the handler handle it.\n this.onMessageHandler(data);\n }\n\n sendSync() {\n // No SYNC_ACK message after 30sec results in a failure\n if (Date.now() - this.firstSyncSent > 30000) {\n this.onMessageHandler({\n type: _Constants__WEBPACK_IMPORTED_MODULE_0__.messageType.SYNC_ACK_FAILED,\n });\n return;\n }\n\n this.sendMessage(\n {\n type: _Constants__WEBPACK_IMPORTED_MODULE_0__.messageType.SYNC,\n hostUrl: IFrameManager.extractHostFromUrl(window.location.href),\n },\n (/** @type {{ debugMode?: any; iFrameUrl?: any; }} */ eventData) => {\n const { iFrameUrl } = eventData;\n this.destinationHost = iFrameUrl || this.destinationHost;\n this.onReady();\n this.debugMode = eventData && eventData.debugMode;\n },\n );\n\n // In cases where the call widget loads the calling extensions asynchronously, message\n // handlers may not be set up - retry until a response from the iFrame\n window.setTimeout(() => {\n if (this.iFrame && !this.isReady) {\n this.sendSync();\n }\n }, 100);\n }\n\n /**\n * @param {any[]} args\n */\n logDebugMessage(...args) {\n if (this.debugMode) {\n console.log.call(null, args);\n return;\n }\n console.debug.call(null, args);\n }\n}\n\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (IFrameManager);\n\n\n//# sourceURL=webpack://calling-extensions-sdk-demo-minimal-js/../../src/IFrameManager.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Constants */ \"../../src/Constants.js\");\n// @ts-check\n\n\"use es6\";\n\n\n\nconst prefix = `[calling-extensions-sdk@${_Constants__WEBPACK_IMPORTED_MODULE_0__.VERSION}]`;\n/*\n * IFrameManager abstracts the iFrame communication between the IFrameHost and an IFrame\n * An IFrameManager instance can act as part of the IFrameHost and an IFrame depending on\n * the options.\n */\nclass IFrameManager {\n /**\n *\n * @param {import('./typedefs').IframeManagerOptions} options\n */\n constructor(options) {\n /** @type {import('./typedefs').IframeManagerOptions | null} */\n this.options = options;\n const { iFrameOptions, onMessageHandler, debugMode } = options;\n\n this.onMessageHandler = onMessageHandler;\n if (!this.onMessageHandler) {\n throw new Error(\"Invalid options: onMessageHandler is not defined\");\n }\n this.isIFrameHost = !!iFrameOptions;\n this.debugMode = debugMode;\n\n // Keeps track of all the callbacks\n /** @type {{ [key: string]: Function }} */\n this.callbacks = {};\n\n this.instanceId = Date.now();\n this.instanceRegexp = new RegExp(`^${this.instanceId}`);\n this.isReady = false;\n\n this.messageHandler = (/** @type {any} */ event) => this.onMessage(event);\n window.addEventListener(\"message\", this.messageHandler);\n\n if (iFrameOptions) {\n /** @type {HTMLIFrameElement | null} */\n this.iFrame = IFrameManager.createIFrame(\n iFrameOptions,\n () => {\n this.firstSyncSent = Date.now();\n this.isReady = false;\n this.sendSync();\n },\n this.handleLoadError,\n );\n } else {\n /** @type {HTMLIFrameElement | null} */\n this.iFrame = null;\n }\n\n this.destinationWindow =\n iFrameOptions && this.iFrame ? this.iFrame.contentWindow : window.parent;\n\n this.destinationHost = IFrameManager.getDestinationHost(iFrameOptions);\n }\n\n /**\n * Creates a new message id\n * @param {string|number} instanceId\n * @returns {string}\n */\n static createMessageId(instanceId) {\n return `${instanceId}_${Date.now()}`;\n }\n\n /**\n * Gets the html element that hosts the iFrame\n * @param {string} hostElementSelector\n */\n static getHostElement(hostElementSelector) {\n const hostElement = document.querySelector(hostElementSelector);\n if (!hostElement) {\n throw new Error(\n `hostElement not found. Selector - ${hostElementSelector}`,\n );\n }\n return hostElement;\n }\n\n /**\n * @param {string} url\n */\n static extractHostFromUrl(url) {\n const a = document.createElement(\"a\");\n a.href = url;\n return `${a.protocol}//${a.host}`;\n }\n\n /**\n *\n * @param {import('./typedefs').IframeOptions} [iFrameOptions]\n */\n static getDestinationHost(iFrameOptions) {\n const url = iFrameOptions ? iFrameOptions.src : document.referrer;\n return IFrameManager.extractHostFromUrl(url);\n }\n\n handleLoadError() {\n this.onMessageHandler({\n type: _Constants__WEBPACK_IMPORTED_MODULE_0__.messageType.SYNC_ACK_FAILED,\n });\n }\n\n /**\n * @param {import('./typedefs').IframeOptions} iFrameOptions\n * @param { (this: GlobalEventHandlers, ev: Event) => any } onLoadCallback\n * @param { OnErrorEventHandler } onLoadErrorCallback\n * @returns {HTMLIFrameElement | null}\n */\n static createIFrame(iFrameOptions, onLoadCallback, onLoadErrorCallback) {\n // eslint-disable-next-line object-curly-newline\n const { src, width, height, hostElementSelector } = iFrameOptions;\n\n if (!src || !width || !height || !hostElementSelector) {\n throw new Error(\n \"iFrameOptions is missing one of the required properties - {src, width, height, hostElementSelector}.\",\n );\n }\n\n /** @type {HTMLIFrameElement} */\n const iFrame = document.createElement(\"iframe\");\n iFrame.onload = onLoadCallback;\n iFrame.onerror = onLoadErrorCallback;\n iFrame.src = src;\n iFrame.width = width;\n iFrame.height = height;\n iFrame.allow = \"microphone; autoplay\";\n iFrame.id = \"hubspot-calling-extension-iframe\";\n\n const element = IFrameManager.getHostElement(hostElementSelector);\n element.innerHTML = \"\";\n element.appendChild(iFrame);\n\n return element.querySelector(\"iframe\");\n }\n\n /**\n * @param {import('./typedefs').SizeInfo} sizeInfo\n */\n updateIFrameSize(sizeInfo) {\n const { width, height } = sizeInfo;\n const formatSize = (/** @type {number} */ size) => {\n return typeof size === \"number\" ? `${size}px` : size;\n };\n if (width && this.iFrame) {\n this.iFrame.setAttribute(\"width\", formatSize(width));\n }\n if (height && this.iFrame) {\n this.iFrame.setAttribute(\"height\", formatSize(height));\n }\n }\n\n onReady(data = {}) {\n this.isReady = true;\n this.onMessageHandler({\n type: _Constants__WEBPACK_IMPORTED_MODULE_0__.messageType.READY,\n data,\n });\n }\n\n /*\n * Unload the iFrame\n */\n remove() {\n window.removeEventListener(\"message\", this.messageHandler);\n\n if (this.iFrame && this.options && this.options.iFrameOptions) {\n const element = IFrameManager.getHostElement(\n this.options.iFrameOptions.hostElementSelector,\n );\n element.innerHTML = \"\";\n\n this.isReady = false;\n this.iFrame = null;\n this.options = null;\n }\n }\n\n /**\n * Send a message to the destination window.\n * @param {{type: string, messageId?: string|number, hostUrl?: string}} message\n * @param {function} [callback]\n */\n sendMessage(message, callback) {\n const { type } = message;\n if (type !== _Constants__WEBPACK_IMPORTED_MODULE_0__.messageType.SYNC && !this.isReady) {\n // Do not send a message unless the iFrame is ready to receive.\n console.warn(\n prefix,\n \"iFrame not initialized to send a message within HubSpot\",\n message,\n );\n return;\n }\n\n let { messageId } = message;\n if (!messageId) {\n // Initiating a new message\n messageId = IFrameManager.createMessageId(this.instanceId);\n if (callback) {\n // Keep track of the callback\n this.callbacks[messageId] = callback;\n }\n }\n\n const newMessage = Object.assign({}, message, {\n messageId,\n });\n\n this.logDebugMessage(prefix, _Constants__WEBPACK_IMPORTED_MODULE_0__.debugMessageType.TO_HUBSPOT, type, message);\n if (this.destinationWindow) {\n this.destinationWindow.postMessage(newMessage, this.destinationHost);\n }\n }\n\n /**\n * @param {{ data: any; origin?: any; }} event\n */\n onMessage(event) {\n const { data, origin } = event;\n // eslint-disable-next-line object-curly-newline\n const { type, engagementId, portalId, userId, ownerId } = event.data;\n if (type === _Constants__WEBPACK_IMPORTED_MODULE_0__.messageType.SYNC) {\n // The iFrame host can send this message multiple times, don't respond more than once\n if (!this.isReady) {\n this.isReady = true;\n\n const message = Object.assign({}, event.data, {\n type: _Constants__WEBPACK_IMPORTED_MODULE_0__.messageType.SYNC_ACK,\n debugMode: this.debugMode,\n version: _Constants__WEBPACK_IMPORTED_MODULE_0__.VERSION,\n iFrameUrl: IFrameManager.extractHostFromUrl(window.location.href),\n });\n\n const { hostUrl } = event.data;\n this.destinationHost = hostUrl || this.destinationHost;\n this.logDebugMessage(prefix, _Constants__WEBPACK_IMPORTED_MODULE_0__.debugMessageType.FROM_HUBSPOT, type, data);\n this.sendMessage(message);\n this.onReady({\n engagementId,\n portalId,\n userId,\n ownerId,\n });\n }\n return;\n }\n\n if (this.destinationHost !== origin) {\n // Ignore messages from an unknown origin\n return;\n }\n\n if (type === _Constants__WEBPACK_IMPORTED_MODULE_0__.messageType.SET_WIDGET_URL) {\n const { iFrameUrl } = data;\n this.destinationHost = iFrameUrl || this.destinationHost;\n return;\n }\n\n const { messageId } = data;\n\n if (!messageId || !type) {\n return;\n }\n\n this.logDebugMessage(prefix, _Constants__WEBPACK_IMPORTED_MODULE_0__.debugMessageType.FROM_HUBSPOT, type, data);\n if (this.instanceRegexp.test(messageId)) {\n // This is a response to some message generated by HubSpot\n const callBack = this.callbacks[messageId];\n if (callBack) {\n callBack(data);\n delete this.callbacks[messageId];\n }\n return;\n }\n\n // This is a new message, let the handler handle it.\n this.onMessageHandler(data);\n }\n\n sendSync() {\n // No SYNC_ACK message after 30sec results in a failure\n if (Date.now() - this.firstSyncSent > 30000) {\n this.onMessageHandler({\n type: _Constants__WEBPACK_IMPORTED_MODULE_0__.messageType.SYNC_ACK_FAILED,\n });\n return;\n }\n\n this.sendMessage(\n {\n type: _Constants__WEBPACK_IMPORTED_MODULE_0__.messageType.SYNC,\n hostUrl: IFrameManager.extractHostFromUrl(window.location.href),\n },\n (/** @type {{ debugMode?: any; iFrameUrl?: any; }} */ eventData) => {\n const { iFrameUrl } = eventData;\n this.destinationHost = iFrameUrl || this.destinationHost;\n this.onReady();\n this.debugMode = eventData && eventData.debugMode;\n },\n );\n\n // In cases where the call widget loads the calling extensions asynchronously, message\n // handlers may not be set up - retry until a response from the iFrame\n window.setTimeout(() => {\n if (this.iFrame && !this.isReady) {\n this.sendSync();\n }\n }, 100);\n }\n\n /**\n * @param {any[]} args\n */\n logDebugMessage(...args) {\n if (this.debugMode) {\n console.log.call(null, args);\n return;\n }\n console.debug.call(null, args);\n }\n}\n\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (IFrameManager);\n\n\n//# sourceURL=webpack://calling-extensions-sdk-demo-minimal-js/../../src/IFrameManager.js?"); /***/ }), @@ -66,7 +66,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac \**************************/ /***/ ((module) => { -eval("module.exports = /*#__PURE__*/JSON.parse('{\"name\":\"@hubspot/calling-extensions-sdk\",\"version\":\"0.6.4-alpha.6\",\"description\":\"A JavaScript SDK for integrating calling apps into HubSpot.\",\"publishConfig\":{\"access\":\"public\"},\"scripts\":{\"build\":\"webpack\",\"build:test\":\"npm run build && npm run test\",\"cover\":\"open coverage/lcov-report/index.html\",\"eslint\":\"eslint src --ext .js\",\"eslint:fix\":\"eslint src --ext .js --fix\",\"preversion\":\"npm run build:test\",\"postversion\":\"git push --follow-tags\",\"publish:alpha:current\":\"npm publish --access public --tag alpha\",\"publish:alpha:patch\":\"npm version patch --preid alpha && npm run publish:alpha:current\",\"publish:alpha:minor\":\"npm version preminor --preid alpha && npm run publish:alpha:current\",\"publish:alpha:major\":\"npm version premajor --preid alpha && npm run publish:alpha:current\",\"publish:alpha\":\"npm version prerelease --preid alpha && npm run publish:alpha:current\",\"publish:beta\":\"npm version prerelease --preid beta && npm publish --access public --tag beta\",\"publish:rc\":\"npm version prerelease --preid rc && npm publish --access public --tag rc\",\"publish:patch\":\"npm version patch && npm publish --access public\",\"publish:minor\":\"npm version minor && npm publish --access public\",\"publish:major\":\"npm version major && npm publish --access public\",\"test:build\":\"npx webpack --config webpack-test.config.js --mode development\",\"test:watch\":\"npx webpack --config webpack-test.config.js --mode development --watch\",\"test:serve\":\"cross-env NODE_ENV=test npm run test:watch & jasmine-browser-runner serve --config=test/support/jasmine-browser.json\",\"test\":\"cross-env NODE_ENV=test npm run test:build && jasmine-browser-runner runSpecs --config=test/support/jasmine-browser.json --browser=headlessChrome\"},\"main\":\"./dist/main.js\",\"files\":[\"dist/**/*\",\"src/\",\"index.js\",\"src/typedefs.js\"],\"types\":\"./dist/types/index.d.ts\",\"module\":\"./index.js\",\"author\":\"\",\"license\":\"MIT\",\"engines\":{\"node\":\">=14\"},\"devDependencies\":{\"@babel/cli\":\"^7.21.0\",\"@babel/core\":\"^7.4.5\",\"@babel/preset-env\":\"^7.21.4\",\"@typescript-eslint/eslint-plugin\":\"^5.59.7\",\"@typescript-eslint/parser\":\"^5.59.7\",\"babel-loader\":\"^8.0.6\",\"cross-env\":\"^7.0.3\",\"eslint\":\"^8.41.0\",\"eslint-config-airbnb\":\"^19.0.4\",\"eslint-plugin-import\":\"^2.27.5\",\"eslint-plugin-jsx-a11y\":\"^6.7.1\",\"eslint-plugin-react\":\"^7.32.2\",\"eslint-plugin-react-hooks\":\"^4.6.0\",\"jasmine-browser-runner\":\"^1.3.0\",\"jasmine-core\":\"^4.6.0\",\"prettier\":\"^2.8.8\",\"ts-loader\":\"^9.5.1\",\"typescript\":\"^5.5.4\",\"webpack\":\"^5.77.0\",\"webpack-cli\":\"^5.0.1\"}}');\n\n//# sourceURL=webpack://calling-extensions-sdk-demo-minimal-js/../../package.json?"); +eval("module.exports = /*#__PURE__*/JSON.parse('{\"name\":\"@hubspot/calling-extensions-sdk\",\"version\":\"0.6.4-alpha.7\",\"description\":\"A JavaScript SDK for integrating calling apps into HubSpot.\",\"publishConfig\":{\"access\":\"public\"},\"scripts\":{\"build\":\"webpack\",\"build:test\":\"npm run build && npm run test\",\"cover\":\"open coverage/lcov-report/index.html\",\"eslint\":\"eslint src --ext .js\",\"eslint:fix\":\"eslint src --ext .js --fix\",\"preversion\":\"npm run build:test\",\"postversion\":\"git push --follow-tags\",\"publish:alpha:current\":\"npm publish --access public --tag alpha\",\"publish:alpha:patch\":\"npm version patch --preid alpha && npm run publish:alpha:current\",\"publish:alpha:minor\":\"npm version preminor --preid alpha && npm run publish:alpha:current\",\"publish:alpha:major\":\"npm version premajor --preid alpha && npm run publish:alpha:current\",\"publish:alpha\":\"npm version prerelease --preid alpha && npm run publish:alpha:current\",\"publish:beta\":\"npm version prerelease --preid beta && npm publish --access public --tag beta\",\"publish:rc\":\"npm version prerelease --preid rc && npm publish --access public --tag rc\",\"publish:patch\":\"npm version patch && npm publish --access public\",\"publish:minor\":\"npm version minor && npm publish --access public\",\"publish:major\":\"npm version major && npm publish --access public\",\"test:build\":\"npx webpack --config webpack-test.config.js --mode development\",\"test:watch\":\"npx webpack --config webpack-test.config.js --mode development --watch\",\"test:serve\":\"cross-env NODE_ENV=test npm run test:watch & jasmine-browser-runner serve --config=test/support/jasmine-browser.json\",\"test\":\"cross-env NODE_ENV=test npm run test:build && jasmine-browser-runner runSpecs --config=test/support/jasmine-browser.json --browser=headlessChrome\"},\"main\":\"./dist/main.js\",\"files\":[\"dist/**/*\",\"src/\",\"index.js\",\"src/typedefs.js\"],\"types\":\"./dist/types/index.d.ts\",\"module\":\"./index.js\",\"author\":\"\",\"license\":\"MIT\",\"engines\":{\"node\":\">=14\"},\"devDependencies\":{\"@babel/cli\":\"^7.21.0\",\"@babel/core\":\"^7.4.5\",\"@babel/preset-env\":\"^7.21.4\",\"@typescript-eslint/eslint-plugin\":\"^5.59.7\",\"@typescript-eslint/parser\":\"^5.59.7\",\"babel-loader\":\"^8.0.6\",\"cross-env\":\"^7.0.3\",\"eslint\":\"^8.41.0\",\"eslint-config-airbnb\":\"^19.0.4\",\"eslint-plugin-import\":\"^2.27.5\",\"eslint-plugin-jsx-a11y\":\"^6.7.1\",\"eslint-plugin-react\":\"^7.32.2\",\"eslint-plugin-react-hooks\":\"^4.6.0\",\"jasmine-browser-runner\":\"^1.3.0\",\"jasmine-core\":\"^4.6.0\",\"prettier\":\"^2.8.8\",\"ts-loader\":\"^9.5.1\",\"typescript\":\"^5.5.4\",\"webpack\":\"^5.77.0\",\"webpack-cli\":\"^5.0.1\"}}');\n\n//# sourceURL=webpack://calling-extensions-sdk-demo-minimal-js/../../package.json?"); /***/ }) diff --git a/pr-preview/pr-222/demo-react-ts.bundle.js b/pr-preview/pr-222/demo-react-ts.bundle.js index d8509ba..f044435 100644 --- a/pr-preview/pr-222/demo-react-ts.bundle.js +++ b/pr-preview/pr-222/demo-react-ts.bundle.js @@ -1,3 +1,3 @@ /*! For license information please see demo-react-ts.bundle.js.LICENSE.txt */ -(()=>{var e={146:(e,t,n)=>{"use strict";var r=n(363),a={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},o={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},l={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},i={};function u(e){return r.isMemo(e)?l:i[e.$$typeof]||a}i[r.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},i[r.Memo]=l;var c=Object.defineProperty,s=Object.getOwnPropertyNames,f=Object.getOwnPropertySymbols,d=Object.getOwnPropertyDescriptor,p=Object.getPrototypeOf,m=Object.prototype;e.exports=function e(t,n,r){if("string"!=typeof n){if(m){var a=p(n);a&&a!==m&&e(t,a,r)}var l=s(n);f&&(l=l.concat(f(n)));for(var i=u(t),g=u(n),h=0;h{"use strict";var r=n(925);function a(){}function o(){}o.resetWarningCache=a,e.exports=function(){function e(e,t,n,a,o,l){if(l!==r){var i=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw i.name="Invariant Violation",i}}function t(){return e}e.isRequired=e;var n={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:o,resetWarningCache:a};return n.PropTypes=n,n}},556:(e,t,n)=>{e.exports=n(694)()},925:e=>{"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},551:(e,t,n)=>{"use strict";var r=n(540),a=n(982);function o(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n