@hubspot/calling-extensions-sdk
Advanced tools
Comparing version
@@ -1,1 +0,1 @@ | ||
var e={d:(t,s)=>{for(var E in s)e.o(s,E)&&!e.o(t,E)&&Object.defineProperty(t,E,{enumerable:!0,get:s[E]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.d(t,{YM:()=>s,qO:()=>p,Ay:()=>H});var s={};e.r(s),e.d(s,{COMPANY:()=>G,CONTACT:()=>O,VERSION:()=>E,callEndStatus:()=>M,callEndingStatus:()=>c,callInProgressStatus:()=>R,callRingingStatus:()=>h,callStatus:()=>S,callerIdTypes:()=>U,debugMessageType:()=>a,errorType:()=>A,messageHandlerNames:()=>o,messageType:()=>i,thirdPartyToHostEvents:()=>n});const E=JSON.parse('{"rE":"0.9.3-beta.0"}').rE,a={FROM_HUBSPOT:"From HubSpot",TO_HUBSPOT:"To HubSpot",GENERIC_MESSAGE:"Generic Message"},n={CALL_ANSWERED:"CALL_ANSWERED",CALL_COMPLETED:"CALL_COMPLETED",CALL_DATA:"CALL_DATA",CALL_ENDED:"CALL_ENDED",INCOMING_CALL:"INCOMING_CALL",INITIALIZED:"INITIALIZED",LOGGED_IN:"LOGGED_IN",LOGGED_OUT:"LOGGED_OUT",NAVIGATE_TO_RECORD:"NAVIGATE_TO_RECORD",OUTGOING_CALL_STARTED:"OUTGOING_CALL_STARTED",PUBLISH_TO_CHANNEL:"PUBLISH_TO_CHANNEL",RESIZE_WIDGET:"RESIZE_WIDGET",USER_AVAILABLE:"USER_AVAILABLE",USER_UNAVAILABLE:"USER_UNAVAILABLE"},i={...n,CALLER_ID_MATCH_FAILED:"CALLER_ID_MATCH_FAILED",CALLER_ID_MATCH_SUCCEEDED:"CALLER_ID_MATCH_SUCCEEDED",CREATE_ENGAGEMENT_FAILED:"CREATE_ENGAGEMENT_FAILED",CREATE_ENGAGEMENT_SUCCEEDED:"CREATE_ENGAGEMENT_SUCCEEDED",DIAL_NUMBER:"DIAL_NUMBER",ENGAGEMENT_CREATED:"ENGAGEMENT_CREATED",INITIATE_CALL_ID_FAILED:"INITIATE_CALL_ID_FAILED",INITIATE_CALL_ID_SUCCEEDED:"INITIATE_CALL_ID_SUCCEEDED",NAVIGATE_TO_RECORD_FAILED:"NAVIGATE_TO_RECORD_FAILED",UPDATE_ASSOCIATIONS_FAILED:"UPDATE_ASSOCIATIONS_FAILED",PUBLISH_TO_CHANNEL_FAILED:"PUBLISH_TO_CHANNEL_FAILED",PUBLISH_TO_CHANNEL_SUCCEEDED:"PUBLISH_TO_CHANNEL_SUCCEEDED",SET_WIDGET_URL_FAILED:"SET_WIDGET_URL_FAILED",UPDATE_ENGAGEMENT_FAILED:"UPDATE_ENGAGEMENT_FAILED",UPDATE_ENGAGEMENT_SUCCEEDED:"UPDATE_ENGAGEMENT_SUCCEEDED",VISIBILITY_CHANGED:"VISIBILITY_CHANGED",END_CALL:"END_CALL",ERROR:"ERROR",READY:"READY",SET_CALL_STATE:"SET_CALL_STATE",SET_WIDGET_URL:"SET_WIDGET_URL",SYNC_ACK_FAILED:"SYNC_ACK_FAILED",SYNC_ACK:"SYNC_ACK",SYNC:"SYNC",UNLOADING:"UNLOADING",FAILED:"FAILED"},o={[i.CALLER_ID_MATCH_FAILED]:"onCallerIdMatchFailed",[i.CALLER_ID_MATCH_SUCCEEDED]:"onCallerIdMatchSucceeded",[i.CREATE_ENGAGEMENT_FAILED]:"onCreateEngagementFailed",[i.CREATE_ENGAGEMENT_SUCCEEDED]:"onCreateEngagementSucceeded",[i.DIAL_NUMBER]:"onDialNumber",[i.END_CALL]:"onEndCall",[i.ENGAGEMENT_CREATED]:"onEngagementCreated",[i.INITIATE_CALL_ID_FAILED]:"onInitiateCallIdFailed",[i.INITIATE_CALL_ID_SUCCEEDED]:"onInitiateCallIdSucceeded",[i.NAVIGATE_TO_RECORD_FAILED]:"onNavigateToRecordFailed",[i.UPDATE_ASSOCIATIONS_FAILED]:"onUpdateAssociationsFailed",[i.PUBLISH_TO_CHANNEL_FAILED]:"onPublishToChannelFailed",[i.PUBLISH_TO_CHANNEL_SUCCEEDED]:"onPublishToChannelSucceeded",[i.READY]:"onReady",[i.SET_CALL_STATE]:"onSetCallState",[i.SET_WIDGET_URL_FAILED]:"onSetWidgetUrlFailed",[i.UPDATE_ENGAGEMENT_FAILED]:"onUpdateEngagementFailed",[i.UPDATE_ENGAGEMENT_SUCCEEDED]:"onUpdateEngagementSucceeded",[i.VISIBILITY_CHANGED]:"onVisibilityChanged",[i.FAILED]:"onFailed"},A={UNKNOWN_MESSAGE_TYPE:"UNKNOWN_MESSAGE_TYPE"},r="CONNECTING",_="CALLING_CRM_USER",d="IN_PROGRESS",I="CANCELED",N="FAILED",L="BUSY",l="NO_ANSWER",T="COMPLETED",C="ENDING",D="QUEUED",g="RINGING",S={INTERNAL_CONNECTING:r,INTERNAL_CALLING_CRM_USER:_,INTERNAL_IN_PROGRESS:d,INTERNAL_CANCELED:I,INTERNAL_FAILED:N,INTERNAL_BUSY:L,INTERNAL_NO_ANSWER:l,INTERNAL_COMPLETED:T,INTERNAL_ENDING:C,INTERNAL_QUEUED:D,INTERNAL_RINGING:g},h={INTERNAL_QUEUED:D,INTERNAL_RINGING:g,INTERNAL_CONNECTING:r,INTERNAL_CALLING_CRM_USER:_},R={INTERNAL_IN_PROGRESS:d},c={INTERNAL_ENDING:C},M={INTERNAL_COMPLETED:T,INTERNAL_FAILED:N,INTERNAL_CANCELED:I,INTERNAL_BUSY:L,INTERNAL_NO_ANSWER:l},O="CONTACT",G="COMPANY",U={CONTACT:O,COMPANY:G},m=`[calling-extensions-sdk@${E}]`;class u{constructor(e){this.firstSyncSent=0,this.options=e;const{iFrameOptions:t,onMessageHandler:s,debugMode:E}=e;if(this.onMessageHandler=s,!this.onMessageHandler)throw new Error("Invalid options: onMessageHandler is not defined");this.isIFrameHost=!!t,this.debugMode=E,this.callbacks={},this.instanceId=Date.now(),this.instanceRegexp=new RegExp(`^${this.instanceId}`),this.isReady=!1,this.messageHandler=e=>this.onMessage(e),window.addEventListener("message",this.messageHandler),this.iFrame=t?u.createIFrame(t,(()=>{this.firstSyncSent=Date.now(),this.isReady=!1,this.sendSync()}),this.handleLoadError):null,this.destinationWindow=t&&this.iFrame?this.iFrame.contentWindow:window.parent,this.destinationHost=u.getDestinationHost(t)}static createMessageId(e){return`${e}_${Date.now()}`}static getHostElement(e){const t=document.querySelector(e);if(!t)throw new Error(`hostElement not found. Selector - ${e}`);return t}static extractHostFromUrl(e){const t=document.createElement("a");return t.href=e,`${t.protocol}//${t.host}`}static getDestinationHost(e){const t=e?e.src:document.referrer;return u.extractHostFromUrl(t)}handleLoadError(){this.onMessageHandler({type:i.SYNC_ACK_FAILED})}static createIFrame(e,t,s){const{src:E,width:a,height:n,hostElementSelector:i}=e;if(!(E&&a&&n&&i))throw new Error("iFrameOptions is missing one of the required properties - {src, width, height, hostElementSelector}.");const o=document.createElement("iframe");o.onload=t,o.onerror=s,o.src=E,o.width=a,o.height=n,o.allow="microphone; autoplay",o.id="hubspot-calling-extension-iframe";const A=u.getHostElement(i);return A.innerHTML="",A.appendChild(o),A.querySelector("iframe")}updateIFrameSize(e){const{width:t,height:s}=e;this.iFrame&&(t&&this.iFrame.setAttribute("width",u.formatSize(t)),s&&this.iFrame.setAttribute("height",u.formatSize(s)))}static formatSize(e){return"number"==typeof e?`${e}px`:e}onReady(e={}){this.isReady=!0,this.onMessageHandler({type:i.READY,data:e})}remove(){window.removeEventListener("message",this.messageHandler),this.iFrame&&this.options&&this.options.iFrameOptions&&(u.getHostElement(this.options.iFrameOptions.hostElementSelector).innerHTML="",this.isReady=!1,this.iFrame=null,this.options=null)}sendMessage(e,t){const{type:s}=e;if(s!==i.SYNC&&!this.isReady)return void console.warn(m,"iFrame not initialized to send a message within HubSpot",e);let{messageId:E}=e;E||(E=u.createMessageId(this.instanceId),t&&(this.callbacks[E]=t));const n=Object.assign({},e,{messageId:E});this.logDebugMessage(m,a.TO_HUBSPOT,s,e),this.destinationWindow&&this.destinationWindow.postMessage(n,this.destinationHost)}onMessage(e){const{data:t,origin:s}=e,{type:n}=e.data;if(n===i.SYNC){const{portalId:s,userId:o,ownerId:A,engagementId:r,iframeLocation:_,usesCallingWindow:d}=e.data;if(!this.isReady){this.isReady=!0;const I=Object.assign({},e.data,{type:i.SYNC_ACK,debugMode:this.debugMode,version:E,iFrameUrl:u.extractHostFromUrl(window.location.href)}),{hostUrl:N}=e.data;this.destinationHost=N||this.destinationHost,this.logDebugMessage(m,a.FROM_HUBSPOT,n,t),this.sendMessage(I),this.onReady({engagementId:r,portalId:s,userId:o,ownerId:A,iframeLocation:_,usesCallingWindow:d,hostUrl:N})}return}if(this.destinationHost!==s)return;const{messageId:o}=t;if(o&&n){if(this.logDebugMessage(m,a.FROM_HUBSPOT,n,t),n===i.SET_WIDGET_URL){const{iFrameUrl:e}=t;return this.destinationHost=e||this.destinationHost,void this.onReady({iFrameUrl:e})}if(this.instanceRegexp.test(o)){const e=this.callbacks[o];e&&(e(t),delete this.callbacks[o])}else this.onMessageHandler(t)}}sendSync(){Date.now()-this.firstSyncSent>3e4?this.onMessageHandler({type:i.SYNC_ACK_FAILED}):(this.sendMessage({type:i.SYNC,hostUrl:u.extractHostFromUrl(window.location.href)},(e=>{const{iFrameUrl:t}=e;this.destinationHost=t||this.destinationHost,this.onReady(),this.debugMode=e&&e.debugMode})),window.setTimeout((()=>{this.iFrame&&!this.isReady&&this.sendSync()}),100))}logDebugMessage(...e){this.debugMode?console.log.call(null,e):console.debug.call(null,e)}}const p=u,F=`[calling-extensions-sdk@${E}]`,H=class{constructor(e){if(!e||!e.eventHandlers)throw new Error("Invalid options or missing eventHandlers.");this.options=e,this.iFrameManager=new p({iFrameOptions:e.iFrameOptions,debugMode:e.debugMode,onMessageHandler:e=>this.onMessageHandler(e)})}initialized(e){this.sendMessage({type:i.INITIALIZED,data:e})}userAvailable(){this.sendMessage({type:i.USER_AVAILABLE})}userUnavailable(){this.sendMessage({type:i.USER_UNAVAILABLE})}userLoggedIn(){this.sendMessage({type:i.LOGGED_IN})}userLoggedOut(){this.sendMessage({type:i.LOGGED_OUT})}incomingCall(e){this.sendMessage({type:i.INCOMING_CALL,data:e})}outgoingCall(e){this.sendMessage({type:i.OUTGOING_CALL_STARTED,data:e})}callAnswered(e){this.sendMessage({type:i.CALL_ANSWERED,data:e})}navigateToRecord(e){this.sendMessage({type:i.NAVIGATE_TO_RECORD,data:e})}callData(e){this.sendMessage({type:i.CALL_DATA,data:e})}callEnded(e){this.sendMessage({type:i.CALL_ENDED,data:e})}callCompleted(e){this.sendMessage({type:i.CALL_COMPLETED,data:e})}sendError(e){this.sendMessage({type:i.ERROR,data:e})}resizeWidget(e){this.sendMessage({type:i.RESIZE_WIDGET,data:e})}sendMessage(e){this.iFrameManager.sendMessage(e)}logDebugMessage({message:e,type:t=a.GENERIC_MESSAGE}){this.iFrameManager.logDebugMessage(F,t,e)}onMessageHandler(e){const{type:t,data:s}=e,{eventHandlers:E}=this.options;let a;if(t in o){const e=o[t];e in E&&(a=E[e])}else this.sendMessage({type:i.ERROR,data:{type:A.UNKNOWN_MESSAGE_TYPE,data:{originalMessage:e}}});if(String(t).endsWith("_FAILED")){const t=E[i.FAILED];t&&t(s,e)}a=a||E.defaultEventHandler,a?a(s,e):console.error(`No event handler is available to handle message of type: ${t}`)}publishToChannel(e){this.sendMessage({type:i.PUBLISH_TO_CHANNEL,data:e})}setWidgetUrl(e){this.sendMessage({type:i.SET_WIDGET_URL,data:e})}};var y=t.YM,b=t.qO,P=t.Ay;export{y as Constants,b as IFrameManager,P as default}; | ||
var e={d:(t,s)=>{for(var E in s)e.o(s,E)&&!e.o(t,E)&&Object.defineProperty(t,E,{enumerable:!0,get:s[E]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.d(t,{YM:()=>s,qO:()=>u,Ay:()=>H});var s={};e.r(s),e.d(s,{COMPANY:()=>O,CONTACT:()=>G,VERSION:()=>E,callEndStatus:()=>M,callEndingStatus:()=>c,callInProgressStatus:()=>R,callRingingStatus:()=>h,callStatus:()=>S,callerIdTypes:()=>U,debugMessageType:()=>a,errorType:()=>A,messageHandlerNames:()=>o,messageType:()=>i,thirdPartyToHostEvents:()=>n});const E=JSON.parse('{"rE":"0.9.4-alpha.0"}').rE,a={FROM_HUBSPOT:"From HubSpot",TO_HUBSPOT:"To HubSpot",GENERIC_MESSAGE:"Generic Message"},n={CALL_ANSWERED:"CALL_ANSWERED",CALL_COMPLETED:"CALL_COMPLETED",CALL_DATA:"CALL_DATA",CALL_ENDED:"CALL_ENDED",INCOMING_CALL:"INCOMING_CALL",INITIALIZED:"INITIALIZED",LOGGED_IN:"LOGGED_IN",LOGGED_OUT:"LOGGED_OUT",NAVIGATE_TO_RECORD:"NAVIGATE_TO_RECORD",OUTGOING_CALL_STARTED:"OUTGOING_CALL_STARTED",PUBLISH_TO_CHANNEL:"PUBLISH_TO_CHANNEL",RESIZE_WIDGET:"RESIZE_WIDGET",USER_AVAILABLE:"USER_AVAILABLE",USER_UNAVAILABLE:"USER_UNAVAILABLE",FINALIZE_ENGAGEMENT:"FINALIZE_ENGAGEMENT"},i={...n,CALLER_ID_MATCH_FAILED:"CALLER_ID_MATCH_FAILED",CALLER_ID_MATCH_SUCCEEDED:"CALLER_ID_MATCH_SUCCEEDED",CREATE_ENGAGEMENT_FAILED:"CREATE_ENGAGEMENT_FAILED",CREATE_ENGAGEMENT_SUCCEEDED:"CREATE_ENGAGEMENT_SUCCEEDED",DIAL_NUMBER:"DIAL_NUMBER",ENGAGEMENT_CREATED:"ENGAGEMENT_CREATED",INITIATE_CALL_ID_FAILED:"INITIATE_CALL_ID_FAILED",INITIATE_CALL_ID_SUCCEEDED:"INITIATE_CALL_ID_SUCCEEDED",NAVIGATE_TO_RECORD_FAILED:"NAVIGATE_TO_RECORD_FAILED",UPDATE_ASSOCIATIONS_FAILED:"UPDATE_ASSOCIATIONS_FAILED",PUBLISH_TO_CHANNEL_FAILED:"PUBLISH_TO_CHANNEL_FAILED",PUBLISH_TO_CHANNEL_SUCCEEDED:"PUBLISH_TO_CHANNEL_SUCCEEDED",FINALIZE_ENGAGEMENT_FAILED:"FINALIZE_ENGAGEMENT_FAILED",FINALIZE_ENGAGEMENT_SUCCEEDED:"FINALIZE_ENGAGEMENT_SUCCEEDED",SET_WIDGET_URL_FAILED:"SET_WIDGET_URL_FAILED",UPDATE_ENGAGEMENT_FAILED:"UPDATE_ENGAGEMENT_FAILED",UPDATE_ENGAGEMENT_SUCCEEDED:"UPDATE_ENGAGEMENT_SUCCEEDED",VISIBILITY_CHANGED:"VISIBILITY_CHANGED",END_CALL:"END_CALL",ERROR:"ERROR",READY:"READY",SET_CALL_STATE:"SET_CALL_STATE",SET_WIDGET_URL:"SET_WIDGET_URL",SYNC_ACK_FAILED:"SYNC_ACK_FAILED",SYNC_ACK:"SYNC_ACK",SYNC:"SYNC",UNLOADING:"UNLOADING",FAILED:"FAILED"},o={[i.CALLER_ID_MATCH_FAILED]:"onCallerIdMatchFailed",[i.CALLER_ID_MATCH_SUCCEEDED]:"onCallerIdMatchSucceeded",[i.CREATE_ENGAGEMENT_FAILED]:"onCreateEngagementFailed",[i.CREATE_ENGAGEMENT_SUCCEEDED]:"onCreateEngagementSucceeded",[i.DIAL_NUMBER]:"onDialNumber",[i.END_CALL]:"onEndCall",[i.ENGAGEMENT_CREATED]:"onEngagementCreated",[i.INITIATE_CALL_ID_FAILED]:"onInitiateCallIdFailed",[i.INITIATE_CALL_ID_SUCCEEDED]:"onInitiateCallIdSucceeded",[i.NAVIGATE_TO_RECORD_FAILED]:"onNavigateToRecordFailed",[i.UPDATE_ASSOCIATIONS_FAILED]:"onUpdateAssociationsFailed",[i.PUBLISH_TO_CHANNEL_FAILED]:"onPublishToChannelFailed",[i.PUBLISH_TO_CHANNEL_SUCCEEDED]:"onPublishToChannelSucceeded",[i.FINALIZE_ENGAGEMENT_FAILED]:"onFinalizeEngagementFailed",[i.FINALIZE_ENGAGEMENT_SUCCEEDED]:"onFinalizeEngagementSucceeded",[i.READY]:"onReady",[i.SET_CALL_STATE]:"onSetCallState",[i.SET_WIDGET_URL_FAILED]:"onSetWidgetUrlFailed",[i.UPDATE_ENGAGEMENT_FAILED]:"onUpdateEngagementFailed",[i.UPDATE_ENGAGEMENT_SUCCEEDED]:"onUpdateEngagementSucceeded",[i.VISIBILITY_CHANGED]:"onVisibilityChanged",[i.FAILED]:"onFailed"},A={UNKNOWN_MESSAGE_TYPE:"UNKNOWN_MESSAGE_TYPE"},_="CONNECTING",I="CALLING_CRM_USER",N="IN_PROGRESS",r="CANCELED",d="FAILED",L="BUSY",T="NO_ANSWER",l="COMPLETED",C="ENDING",D="QUEUED",g="RINGING",S={INTERNAL_CONNECTING:_,INTERNAL_CALLING_CRM_USER:I,INTERNAL_IN_PROGRESS:N,INTERNAL_CANCELED:r,INTERNAL_FAILED:d,INTERNAL_BUSY:L,INTERNAL_NO_ANSWER:T,INTERNAL_COMPLETED:l,INTERNAL_ENDING:C,INTERNAL_QUEUED:D,INTERNAL_RINGING:g},h={INTERNAL_QUEUED:D,INTERNAL_RINGING:g,INTERNAL_CONNECTING:_,INTERNAL_CALLING_CRM_USER:I},R={INTERNAL_IN_PROGRESS:N},c={INTERNAL_ENDING:C},M={INTERNAL_COMPLETED:l,INTERNAL_FAILED:d,INTERNAL_CANCELED:r,INTERNAL_BUSY:L,INTERNAL_NO_ANSWER:T},G="CONTACT",O="COMPANY",U={CONTACT:G,COMPANY:O},F=`[calling-extensions-sdk@${E}]`;class m{constructor(e){this.firstSyncSent=0,this.options=e;const{iFrameOptions:t,onMessageHandler:s,debugMode:E}=e;if(this.onMessageHandler=s,!this.onMessageHandler)throw new Error("Invalid options: onMessageHandler is not defined");this.isIFrameHost=!!t,this.debugMode=E,this.callbacks={},this.instanceId=Date.now(),this.instanceRegexp=new RegExp(`^${this.instanceId}`),this.isReady=!1,this.messageHandler=e=>this.onMessage(e),window.addEventListener("message",this.messageHandler),this.iFrame=t?m.createIFrame(t,(()=>{this.firstSyncSent=Date.now(),this.isReady=!1,this.sendSync()}),this.handleLoadError):null,this.destinationWindow=t&&this.iFrame?this.iFrame.contentWindow:window.parent,this.destinationHost=m.getDestinationHost(t)}static createMessageId(e){return`${e}_${Date.now()}`}static getHostElement(e){const t=document.querySelector(e);if(!t)throw new Error(`hostElement not found. Selector - ${e}`);return t}static extractHostFromUrl(e){const t=document.createElement("a");return t.href=e,`${t.protocol}//${t.host}`}static getDestinationHost(e){const t=e?e.src:document.referrer;return m.extractHostFromUrl(t)}handleLoadError(){this.onMessageHandler({type:i.SYNC_ACK_FAILED})}static createIFrame(e,t,s){const{src:E,width:a,height:n,hostElementSelector:i}=e;if(!(E&&a&&n&&i))throw new Error("iFrameOptions is missing one of the required properties - {src, width, height, hostElementSelector}.");const o=document.createElement("iframe");o.onload=t,o.onerror=s,o.src=E,o.width=a,o.height=n,o.allow="microphone; autoplay",o.id="hubspot-calling-extension-iframe";const A=m.getHostElement(i);return A.innerHTML="",A.appendChild(o),A.querySelector("iframe")}updateIFrameSize(e){const{width:t,height:s}=e;this.iFrame&&(t&&this.iFrame.setAttribute("width",m.formatSize(t)),s&&this.iFrame.setAttribute("height",m.formatSize(s)))}static formatSize(e){return"number"==typeof e?`${e}px`:e}onReady(e={}){this.isReady=!0,this.onMessageHandler({type:i.READY,data:e})}remove(){window.removeEventListener("message",this.messageHandler),this.iFrame&&this.options&&this.options.iFrameOptions&&(m.getHostElement(this.options.iFrameOptions.hostElementSelector).innerHTML="",this.isReady=!1,this.iFrame=null,this.options=null)}sendMessage(e,t){const{type:s}=e;if(s!==i.SYNC&&!this.isReady)return void console.warn(F,"iFrame not initialized to send a message within HubSpot",e);let{messageId:E}=e;E||(E=m.createMessageId(this.instanceId),t&&(this.callbacks[E]=t));const n=Object.assign({},e,{messageId:E});this.logDebugMessage(F,a.TO_HUBSPOT,s,e),this.destinationWindow&&this.destinationWindow.postMessage(n,this.destinationHost)}onMessage(e){const{data:t,origin:s}=e,{type:n}=e.data;if(n===i.SYNC){const{portalId:s,userId:o,ownerId:A,engagementId:_,iframeLocation:I,usesCallingWindow:N}=e.data;if(!this.isReady){this.isReady=!0;const r=Object.assign({},e.data,{type:i.SYNC_ACK,debugMode:this.debugMode,version:E,iFrameUrl:m.extractHostFromUrl(window.location.href)}),{hostUrl:d}=e.data;this.destinationHost=d||this.destinationHost,this.logDebugMessage(F,a.FROM_HUBSPOT,n,t),this.sendMessage(r),this.onReady({engagementId:_,portalId:s,userId:o,ownerId:A,iframeLocation:I,usesCallingWindow:N,hostUrl:d})}return}if(this.destinationHost!==s)return;const{messageId:o}=t;if(o&&n){if(this.logDebugMessage(F,a.FROM_HUBSPOT,n,t),n===i.SET_WIDGET_URL){const{iFrameUrl:e}=t;return this.destinationHost=e||this.destinationHost,void this.onReady({iFrameUrl:e})}if(this.instanceRegexp.test(o)){const e=this.callbacks[o];e&&(e(t),delete this.callbacks[o])}else this.onMessageHandler(t)}}sendSync(){Date.now()-this.firstSyncSent>3e4?this.onMessageHandler({type:i.SYNC_ACK_FAILED}):(this.sendMessage({type:i.SYNC,hostUrl:m.extractHostFromUrl(window.location.href)},(e=>{const{iFrameUrl:t}=e;this.destinationHost=t||this.destinationHost,this.onReady(),this.debugMode=e&&e.debugMode})),window.setTimeout((()=>{this.iFrame&&!this.isReady&&this.sendSync()}),100))}logDebugMessage(...e){this.debugMode?console.log.call(null,e):console.debug.call(null,e)}}const u=m,p=`[calling-extensions-sdk@${E}]`,H=class{constructor(e){if(!e||!e.eventHandlers)throw new Error("Invalid options or missing eventHandlers.");this.options=e,this.iFrameManager=new u({iFrameOptions:e.iFrameOptions,debugMode:e.debugMode,onMessageHandler:e=>this.onMessageHandler(e)})}initialized(e){this.sendMessage({type:i.INITIALIZED,data:e})}userAvailable(){this.sendMessage({type:i.USER_AVAILABLE})}userUnavailable(){this.sendMessage({type:i.USER_UNAVAILABLE})}userLoggedIn(){this.sendMessage({type:i.LOGGED_IN})}userLoggedOut(){this.sendMessage({type:i.LOGGED_OUT})}incomingCall(e){this.sendMessage({type:i.INCOMING_CALL,data:e})}outgoingCall(e){this.sendMessage({type:i.OUTGOING_CALL_STARTED,data:e})}callAnswered(e){this.sendMessage({type:i.CALL_ANSWERED,data:e})}navigateToRecord(e){this.sendMessage({type:i.NAVIGATE_TO_RECORD,data:e})}callData(e){this.sendMessage({type:i.CALL_DATA,data:e})}callEnded(e){this.sendMessage({type:i.CALL_ENDED,data:e})}callCompleted(e){this.sendMessage({type:i.CALL_COMPLETED,data:e})}sendError(e){this.sendMessage({type:i.ERROR,data:e})}resizeWidget(e){this.sendMessage({type:i.RESIZE_WIDGET,data:e})}sendMessage(e){this.iFrameManager.sendMessage(e)}logDebugMessage({message:e,type:t=a.GENERIC_MESSAGE}){this.iFrameManager.logDebugMessage(p,t,e)}onMessageHandler(e){const{type:t,data:s}=e,{eventHandlers:E}=this.options;let a;if(t in o){const e=o[t];e in E&&(a=E[e])}else this.sendMessage({type:i.ERROR,data:{type:A.UNKNOWN_MESSAGE_TYPE,data:{originalMessage:e}}});if(String(t).endsWith("_FAILED")){const t=E[i.FAILED];t&&t(s,e)}a=a||E.defaultEventHandler,a?a(s,e):console.error(`No event handler is available to handle message of type: ${t}`)}publishToChannel(e){this.sendMessage({type:i.PUBLISH_TO_CHANNEL,data:e})}finalizeEngagement(e){this.sendMessage({type:i.FINALIZE_ENGAGEMENT,data:e})}setWidgetUrl(e){this.sendMessage({type:i.SET_WIDGET_URL,data:e})}};var y=t.YM,b=t.qO,P=t.Ay;export{y as Constants,b as IFrameManager,P as default}; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var s=t();for(var n in s)("object"==typeof exports?exports:e)[n]=s[n]}}(self,(()=>(()=>{"use strict";var e={416:function(e,t,s){var n=this&&this.__createBinding||(Object.create?function(e,t,s,n){void 0===n&&(n=s);var a=Object.getOwnPropertyDescriptor(t,s);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,n,a)}:function(e,t,s,n){void 0===n&&(n=s),e[n]=t[s]}),a=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var s in e)"default"!==s&&Object.prototype.hasOwnProperty.call(e,s)&&n(t,e,s);return a(t,e),t},o=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||n(t,e,s)},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.IFrameManager=t.Constants=void 0;var E=r(s(683)),p=i(s(628));t.Constants=p;var l=r(s(950));t.IFrameManager=l.default,t.default=E.default,o(s(696),t)},683:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var a=n(s(950)),i=s(628),o="[calling-extensions-sdk@".concat(i.VERSION,"]"),r=function(){function e(e){var t=this;if(!e||!e.eventHandlers)throw new Error("Invalid options or missing eventHandlers.");this.options=e,this.iFrameManager=new a.default({iFrameOptions:e.iFrameOptions,debugMode:e.debugMode,onMessageHandler:function(e){return t.onMessageHandler(e)}})}return e.prototype.initialized=function(e){this.sendMessage({type:i.messageType.INITIALIZED,data:e})},e.prototype.userAvailable=function(){this.sendMessage({type:i.messageType.USER_AVAILABLE})},e.prototype.userUnavailable=function(){this.sendMessage({type:i.messageType.USER_UNAVAILABLE})},e.prototype.userLoggedIn=function(){this.sendMessage({type:i.messageType.LOGGED_IN})},e.prototype.userLoggedOut=function(){this.sendMessage({type:i.messageType.LOGGED_OUT})},e.prototype.incomingCall=function(e){this.sendMessage({type:i.messageType.INCOMING_CALL,data:e})},e.prototype.outgoingCall=function(e){this.sendMessage({type:i.messageType.OUTGOING_CALL_STARTED,data:e})},e.prototype.callAnswered=function(e){this.sendMessage({type:i.messageType.CALL_ANSWERED,data:e})},e.prototype.navigateToRecord=function(e){this.sendMessage({type:i.messageType.NAVIGATE_TO_RECORD,data:e})},e.prototype.callData=function(e){this.sendMessage({type:i.messageType.CALL_DATA,data:e})},e.prototype.callEnded=function(e){this.sendMessage({type:i.messageType.CALL_ENDED,data:e})},e.prototype.callCompleted=function(e){this.sendMessage({type:i.messageType.CALL_COMPLETED,data:e})},e.prototype.sendError=function(e){this.sendMessage({type:i.messageType.ERROR,data:e})},e.prototype.resizeWidget=function(e){this.sendMessage({type:i.messageType.RESIZE_WIDGET,data:e})},e.prototype.sendMessage=function(e){this.iFrameManager.sendMessage(e)},e.prototype.logDebugMessage=function(e){var t=e.message,s=e.type,n=void 0===s?i.debugMessageType.GENERIC_MESSAGE:s;this.iFrameManager.logDebugMessage(o,n,t)},e.prototype.onMessageHandler=function(e){var t,s=e.type,n=e.data,a=this.options.eventHandlers;if(s in i.messageHandlerNames){var o=i.messageHandlerNames[s];o in a&&(t=a[o])}else this.sendMessage({type:i.messageType.ERROR,data:{type:i.errorType.UNKNOWN_MESSAGE_TYPE,data:{originalMessage:e}}});if(String(s).endsWith("_FAILED")){var r=a[i.messageType.FAILED];r&&r(n,e)}(t=t||a.defaultEventHandler)?t(n,e):console.error("No event handler is available to handle message of type: ".concat(s))},e.prototype.publishToChannel=function(e){this.sendMessage({type:i.messageType.PUBLISH_TO_CHANNEL,data:e})},e.prototype.setWidgetUrl=function(e){this.sendMessage({type:i.messageType.SET_WIDGET_URL,data:e})},e}();t.default=r},628:function(e,t,s){var n,a=this&&this.__assign||function(){return a=Object.assign||function(e){for(var t,s=1,n=arguments.length;s<n;s++)for(var a in t=arguments[s])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e},a.apply(this,arguments)},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.callerIdTypes=t.COMPANY=t.CONTACT=t.callEndStatus=t.callEndingStatus=t.callInProgressStatus=t.callRingingStatus=t.callStatus=t.errorType=t.messageHandlerNames=t.messageType=t.thirdPartyToHostEvents=t.debugMessageType=t.VERSION=void 0;var o=i(s(330));t.VERSION=o.default.version,t.debugMessageType={FROM_HUBSPOT:"From HubSpot",TO_HUBSPOT:"To HubSpot",GENERIC_MESSAGE:"Generic Message"},t.thirdPartyToHostEvents={CALL_ANSWERED:"CALL_ANSWERED",CALL_COMPLETED:"CALL_COMPLETED",CALL_DATA:"CALL_DATA",CALL_ENDED:"CALL_ENDED",INCOMING_CALL:"INCOMING_CALL",INITIALIZED:"INITIALIZED",LOGGED_IN:"LOGGED_IN",LOGGED_OUT:"LOGGED_OUT",NAVIGATE_TO_RECORD:"NAVIGATE_TO_RECORD",OUTGOING_CALL_STARTED:"OUTGOING_CALL_STARTED",PUBLISH_TO_CHANNEL:"PUBLISH_TO_CHANNEL",RESIZE_WIDGET:"RESIZE_WIDGET",USER_AVAILABLE:"USER_AVAILABLE",USER_UNAVAILABLE:"USER_UNAVAILABLE"},t.messageType=a(a(a({},t.thirdPartyToHostEvents),{CALLER_ID_MATCH_FAILED:"CALLER_ID_MATCH_FAILED",CALLER_ID_MATCH_SUCCEEDED:"CALLER_ID_MATCH_SUCCEEDED",CREATE_ENGAGEMENT_FAILED:"CREATE_ENGAGEMENT_FAILED",CREATE_ENGAGEMENT_SUCCEEDED:"CREATE_ENGAGEMENT_SUCCEEDED",DIAL_NUMBER:"DIAL_NUMBER",ENGAGEMENT_CREATED:"ENGAGEMENT_CREATED",INITIATE_CALL_ID_FAILED:"INITIATE_CALL_ID_FAILED",INITIATE_CALL_ID_SUCCEEDED:"INITIATE_CALL_ID_SUCCEEDED",NAVIGATE_TO_RECORD_FAILED:"NAVIGATE_TO_RECORD_FAILED",UPDATE_ASSOCIATIONS_FAILED:"UPDATE_ASSOCIATIONS_FAILED",PUBLISH_TO_CHANNEL_FAILED:"PUBLISH_TO_CHANNEL_FAILED",PUBLISH_TO_CHANNEL_SUCCEEDED:"PUBLISH_TO_CHANNEL_SUCCEEDED",SET_WIDGET_URL_FAILED:"SET_WIDGET_URL_FAILED",UPDATE_ENGAGEMENT_FAILED:"UPDATE_ENGAGEMENT_FAILED",UPDATE_ENGAGEMENT_SUCCEEDED:"UPDATE_ENGAGEMENT_SUCCEEDED",VISIBILITY_CHANGED:"VISIBILITY_CHANGED"}),{END_CALL:"END_CALL",ERROR:"ERROR",READY:"READY",SET_CALL_STATE:"SET_CALL_STATE",SET_WIDGET_URL:"SET_WIDGET_URL",SYNC_ACK_FAILED:"SYNC_ACK_FAILED",SYNC_ACK:"SYNC_ACK",SYNC:"SYNC",UNLOADING:"UNLOADING",FAILED:"FAILED"}),t.messageHandlerNames=((n={})[t.messageType.CALLER_ID_MATCH_FAILED]="onCallerIdMatchFailed",n[t.messageType.CALLER_ID_MATCH_SUCCEEDED]="onCallerIdMatchSucceeded",n[t.messageType.CREATE_ENGAGEMENT_FAILED]="onCreateEngagementFailed",n[t.messageType.CREATE_ENGAGEMENT_SUCCEEDED]="onCreateEngagementSucceeded",n[t.messageType.DIAL_NUMBER]="onDialNumber",n[t.messageType.END_CALL]="onEndCall",n[t.messageType.ENGAGEMENT_CREATED]="onEngagementCreated",n[t.messageType.INITIATE_CALL_ID_FAILED]="onInitiateCallIdFailed",n[t.messageType.INITIATE_CALL_ID_SUCCEEDED]="onInitiateCallIdSucceeded",n[t.messageType.NAVIGATE_TO_RECORD_FAILED]="onNavigateToRecordFailed",n[t.messageType.UPDATE_ASSOCIATIONS_FAILED]="onUpdateAssociationsFailed",n[t.messageType.PUBLISH_TO_CHANNEL_FAILED]="onPublishToChannelFailed",n[t.messageType.PUBLISH_TO_CHANNEL_SUCCEEDED]="onPublishToChannelSucceeded",n[t.messageType.READY]="onReady",n[t.messageType.SET_CALL_STATE]="onSetCallState",n[t.messageType.SET_WIDGET_URL_FAILED]="onSetWidgetUrlFailed",n[t.messageType.UPDATE_ENGAGEMENT_FAILED]="onUpdateEngagementFailed",n[t.messageType.UPDATE_ENGAGEMENT_SUCCEEDED]="onUpdateEngagementSucceeded",n[t.messageType.VISIBILITY_CHANGED]="onVisibilityChanged",n[t.messageType.FAILED]="onFailed",n),t.errorType={UNKNOWN_MESSAGE_TYPE:"UNKNOWN_MESSAGE_TYPE"};var r="CONNECTING",E="CALLING_CRM_USER",p="IN_PROGRESS",l="CANCELED",d="FAILED",c="BUSY",_="NO_ANSWER",u="COMPLETED",A="ENDING",g="QUEUED",T="RINGING";t.callStatus={INTERNAL_CONNECTING:r,INTERNAL_CALLING_CRM_USER:E,INTERNAL_IN_PROGRESS:p,INTERNAL_CANCELED:l,INTERNAL_FAILED:d,INTERNAL_BUSY:c,INTERNAL_NO_ANSWER:_,INTERNAL_COMPLETED:u,INTERNAL_ENDING:A,INTERNAL_QUEUED:g,INTERNAL_RINGING:T},t.callRingingStatus={INTERNAL_QUEUED:g,INTERNAL_RINGING:T,INTERNAL_CONNECTING:r,INTERNAL_CALLING_CRM_USER:E},t.callInProgressStatus={INTERNAL_IN_PROGRESS:p},t.callEndingStatus={INTERNAL_ENDING:A},t.callEndStatus={INTERNAL_COMPLETED:u,INTERNAL_FAILED:d,INTERNAL_CANCELED:l,INTERNAL_BUSY:c,INTERNAL_NO_ANSWER:_},t.CONTACT="CONTACT",t.COMPANY="COMPANY",t.callerIdTypes={CONTACT:t.CONTACT,COMPANY:t.COMPANY}},950:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=s(628),a="[calling-extensions-sdk@".concat(n.VERSION,"]"),i=function(){function e(t){var s=this;this.firstSyncSent=0,this.options=t;var n=t.iFrameOptions,a=t.onMessageHandler,i=t.debugMode;if(this.onMessageHandler=a,!this.onMessageHandler)throw new Error("Invalid options: onMessageHandler is not defined");this.isIFrameHost=!!n,this.debugMode=i,this.callbacks={},this.instanceId=Date.now(),this.instanceRegexp=new RegExp("^".concat(this.instanceId)),this.isReady=!1,this.messageHandler=function(e){return s.onMessage(e)},window.addEventListener("message",this.messageHandler),this.iFrame=n?e.createIFrame(n,(function(){s.firstSyncSent=Date.now(),s.isReady=!1,s.sendSync()}),this.handleLoadError):null,this.destinationWindow=n&&this.iFrame?this.iFrame.contentWindow:window.parent,this.destinationHost=e.getDestinationHost(n)}return e.createMessageId=function(e){return"".concat(e,"_").concat(Date.now())},e.getHostElement=function(e){var t=document.querySelector(e);if(!t)throw new Error("hostElement not found. Selector - ".concat(e));return t},e.extractHostFromUrl=function(e){var t=document.createElement("a");return t.href=e,"".concat(t.protocol,"//").concat(t.host)},e.getDestinationHost=function(t){var s=t?t.src:document.referrer;return e.extractHostFromUrl(s)},e.prototype.handleLoadError=function(){this.onMessageHandler({type:n.messageType.SYNC_ACK_FAILED})},e.createIFrame=function(t,s,n){var a=t.src,i=t.width,o=t.height,r=t.hostElementSelector;if(!(a&&i&&o&&r))throw new Error("iFrameOptions is missing one of the required properties - {src, width, height, hostElementSelector}.");var E=document.createElement("iframe");E.onload=s,E.onerror=n,E.src=a,E.width=i,E.height=o,E.allow="microphone; autoplay",E.id="hubspot-calling-extension-iframe";var p=e.getHostElement(r);return p.innerHTML="",p.appendChild(E),p.querySelector("iframe")},e.prototype.updateIFrameSize=function(t){var s=t.width,n=t.height;this.iFrame&&(s&&this.iFrame.setAttribute("width",e.formatSize(s)),n&&this.iFrame.setAttribute("height",e.formatSize(n)))},e.formatSize=function(e){return"number"==typeof e?"".concat(e,"px"):e},e.prototype.onReady=function(e){void 0===e&&(e={}),this.isReady=!0,this.onMessageHandler({type:n.messageType.READY,data:e})},e.prototype.remove=function(){window.removeEventListener("message",this.messageHandler),this.iFrame&&this.options&&this.options.iFrameOptions&&(e.getHostElement(this.options.iFrameOptions.hostElementSelector).innerHTML="",this.isReady=!1,this.iFrame=null,this.options=null)},e.prototype.sendMessage=function(t,s){var i=t.type;if(i===n.messageType.SYNC||this.isReady){var o=t.messageId;o||(o=e.createMessageId(this.instanceId),s&&(this.callbacks[o]=s));var r=Object.assign({},t,{messageId:o});this.logDebugMessage(a,n.debugMessageType.TO_HUBSPOT,i,t),this.destinationWindow&&this.destinationWindow.postMessage(r,this.destinationHost)}else console.warn(a,"iFrame not initialized to send a message within HubSpot",t)},e.prototype.onMessage=function(t){var s=t.data,i=t.origin,o=t.data.type;if(o!==n.messageType.SYNC){if(this.destinationHost===i){var r=s.messageId;if(r&&o){if(this.logDebugMessage(a,n.debugMessageType.FROM_HUBSPOT,o,s),o===n.messageType.SET_WIDGET_URL){var E=s.iFrameUrl;return this.destinationHost=E||this.destinationHost,void this.onReady({iFrameUrl:E})}if(this.instanceRegexp.test(r)){var p=this.callbacks[r];p&&(p(s),delete this.callbacks[r])}else this.onMessageHandler(s)}}}else{var l=t.data,d=l.portalId,c=l.userId,_=l.ownerId,u=l.engagementId,A=l.iframeLocation,g=l.usesCallingWindow;if(!this.isReady){this.isReady=!0;var T=Object.assign({},t.data,{type:n.messageType.SYNC_ACK,debugMode:this.debugMode,version:n.VERSION,iFrameUrl:e.extractHostFromUrl(window.location.href)}),I=t.data.hostUrl;this.destinationHost=I||this.destinationHost,this.logDebugMessage(a,n.debugMessageType.FROM_HUBSPOT,o,s),this.sendMessage(T),this.onReady({engagementId:u,portalId:d,userId:c,ownerId:_,iframeLocation:A,usesCallingWindow:g,hostUrl:I})}}},e.prototype.sendSync=function(){var t=this;Date.now()-this.firstSyncSent>3e4?this.onMessageHandler({type:n.messageType.SYNC_ACK_FAILED}):(this.sendMessage({type:n.messageType.SYNC,hostUrl:e.extractHostFromUrl(window.location.href)},(function(e){var s=e.iFrameUrl;t.destinationHost=s||t.destinationHost,t.onReady(),t.debugMode=e&&e.debugMode})),window.setTimeout((function(){t.iFrame&&!t.isReady&&t.sendSync()}),100))},e.prototype.logDebugMessage=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.debugMode?console.log.call(null,e):console.debug.call(null,e)},e}();t.default=i},696:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},330:e=>{e.exports=JSON.parse('{"name":"@hubspot/calling-extensions-sdk","version":"0.9.3-beta.0","description":"A JavaScript SDK for integrating calling apps into HubSpot.","publishConfig":{"access":"public"},"scripts":{"build":"rm -rf dist && npm run build:cjs && npm run build:esm","build:cjs":"webpack --config webpack.cjs.config.js","build:esm":"webpack --config webpack.esm.config.js","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","module":"./dist/main.esm.js","files":["dist/**/*","src/","index.ts"],"types":"./dist/types/index.d.ts","author":"","license":"MIT","engines":{"node":">=14"},"devDependencies":{"@babel/cli":"^7.21.0","@babel/core":"^7.4.5","@babel/preset-env":"^7.21.4","@babel/preset-typescript":"^7.26.0","@types/jasmine":"^5.1.5","@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","webpack-merge":"^6.0.1"}}')}},t={};return function s(n){var a=t[n];if(void 0!==a)return a.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,s),i.exports}(416)})())); | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var s=t();for(var n in s)("object"==typeof exports?exports:e)[n]=s[n]}}(self,(()=>(()=>{"use strict";var e={416:function(e,t,s){var n=this&&this.__createBinding||(Object.create?function(e,t,s,n){void 0===n&&(n=s);var a=Object.getOwnPropertyDescriptor(t,s);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,n,a)}:function(e,t,s,n){void 0===n&&(n=s),e[n]=t[s]}),a=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var s in e)"default"!==s&&Object.prototype.hasOwnProperty.call(e,s)&&n(t,e,s);return a(t,e),t},o=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||n(t,e,s)},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.IFrameManager=t.Constants=void 0;var E=r(s(683)),p=i(s(628));t.Constants=p;var l=r(s(950));t.IFrameManager=l.default,t.default=E.default,o(s(696),t)},683:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var a=n(s(950)),i=s(628),o="[calling-extensions-sdk@".concat(i.VERSION,"]"),r=function(){function e(e){var t=this;if(!e||!e.eventHandlers)throw new Error("Invalid options or missing eventHandlers.");this.options=e,this.iFrameManager=new a.default({iFrameOptions:e.iFrameOptions,debugMode:e.debugMode,onMessageHandler:function(e){return t.onMessageHandler(e)}})}return e.prototype.initialized=function(e){this.sendMessage({type:i.messageType.INITIALIZED,data:e})},e.prototype.userAvailable=function(){this.sendMessage({type:i.messageType.USER_AVAILABLE})},e.prototype.userUnavailable=function(){this.sendMessage({type:i.messageType.USER_UNAVAILABLE})},e.prototype.userLoggedIn=function(){this.sendMessage({type:i.messageType.LOGGED_IN})},e.prototype.userLoggedOut=function(){this.sendMessage({type:i.messageType.LOGGED_OUT})},e.prototype.incomingCall=function(e){this.sendMessage({type:i.messageType.INCOMING_CALL,data:e})},e.prototype.outgoingCall=function(e){this.sendMessage({type:i.messageType.OUTGOING_CALL_STARTED,data:e})},e.prototype.callAnswered=function(e){this.sendMessage({type:i.messageType.CALL_ANSWERED,data:e})},e.prototype.navigateToRecord=function(e){this.sendMessage({type:i.messageType.NAVIGATE_TO_RECORD,data:e})},e.prototype.callData=function(e){this.sendMessage({type:i.messageType.CALL_DATA,data:e})},e.prototype.callEnded=function(e){this.sendMessage({type:i.messageType.CALL_ENDED,data:e})},e.prototype.callCompleted=function(e){this.sendMessage({type:i.messageType.CALL_COMPLETED,data:e})},e.prototype.sendError=function(e){this.sendMessage({type:i.messageType.ERROR,data:e})},e.prototype.resizeWidget=function(e){this.sendMessage({type:i.messageType.RESIZE_WIDGET,data:e})},e.prototype.sendMessage=function(e){this.iFrameManager.sendMessage(e)},e.prototype.logDebugMessage=function(e){var t=e.message,s=e.type,n=void 0===s?i.debugMessageType.GENERIC_MESSAGE:s;this.iFrameManager.logDebugMessage(o,n,t)},e.prototype.onMessageHandler=function(e){var t,s=e.type,n=e.data,a=this.options.eventHandlers;if(s in i.messageHandlerNames){var o=i.messageHandlerNames[s];o in a&&(t=a[o])}else this.sendMessage({type:i.messageType.ERROR,data:{type:i.errorType.UNKNOWN_MESSAGE_TYPE,data:{originalMessage:e}}});if(String(s).endsWith("_FAILED")){var r=a[i.messageType.FAILED];r&&r(n,e)}(t=t||a.defaultEventHandler)?t(n,e):console.error("No event handler is available to handle message of type: ".concat(s))},e.prototype.publishToChannel=function(e){this.sendMessage({type:i.messageType.PUBLISH_TO_CHANNEL,data:e})},e.prototype.finalizeEngagement=function(e){this.sendMessage({type:i.messageType.FINALIZE_ENGAGEMENT,data:e})},e.prototype.setWidgetUrl=function(e){this.sendMessage({type:i.messageType.SET_WIDGET_URL,data:e})},e}();t.default=r},628:function(e,t,s){var n,a=this&&this.__assign||function(){return a=Object.assign||function(e){for(var t,s=1,n=arguments.length;s<n;s++)for(var a in t=arguments[s])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e},a.apply(this,arguments)},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.callerIdTypes=t.COMPANY=t.CONTACT=t.callEndStatus=t.callEndingStatus=t.callInProgressStatus=t.callRingingStatus=t.callStatus=t.errorType=t.messageHandlerNames=t.messageType=t.thirdPartyToHostEvents=t.debugMessageType=t.VERSION=void 0;var o=i(s(330));t.VERSION=o.default.version,t.debugMessageType={FROM_HUBSPOT:"From HubSpot",TO_HUBSPOT:"To HubSpot",GENERIC_MESSAGE:"Generic Message"},t.thirdPartyToHostEvents={CALL_ANSWERED:"CALL_ANSWERED",CALL_COMPLETED:"CALL_COMPLETED",CALL_DATA:"CALL_DATA",CALL_ENDED:"CALL_ENDED",INCOMING_CALL:"INCOMING_CALL",INITIALIZED:"INITIALIZED",LOGGED_IN:"LOGGED_IN",LOGGED_OUT:"LOGGED_OUT",NAVIGATE_TO_RECORD:"NAVIGATE_TO_RECORD",OUTGOING_CALL_STARTED:"OUTGOING_CALL_STARTED",PUBLISH_TO_CHANNEL:"PUBLISH_TO_CHANNEL",RESIZE_WIDGET:"RESIZE_WIDGET",USER_AVAILABLE:"USER_AVAILABLE",USER_UNAVAILABLE:"USER_UNAVAILABLE",FINALIZE_ENGAGEMENT:"FINALIZE_ENGAGEMENT"},t.messageType=a(a(a({},t.thirdPartyToHostEvents),{CALLER_ID_MATCH_FAILED:"CALLER_ID_MATCH_FAILED",CALLER_ID_MATCH_SUCCEEDED:"CALLER_ID_MATCH_SUCCEEDED",CREATE_ENGAGEMENT_FAILED:"CREATE_ENGAGEMENT_FAILED",CREATE_ENGAGEMENT_SUCCEEDED:"CREATE_ENGAGEMENT_SUCCEEDED",DIAL_NUMBER:"DIAL_NUMBER",ENGAGEMENT_CREATED:"ENGAGEMENT_CREATED",INITIATE_CALL_ID_FAILED:"INITIATE_CALL_ID_FAILED",INITIATE_CALL_ID_SUCCEEDED:"INITIATE_CALL_ID_SUCCEEDED",NAVIGATE_TO_RECORD_FAILED:"NAVIGATE_TO_RECORD_FAILED",UPDATE_ASSOCIATIONS_FAILED:"UPDATE_ASSOCIATIONS_FAILED",PUBLISH_TO_CHANNEL_FAILED:"PUBLISH_TO_CHANNEL_FAILED",PUBLISH_TO_CHANNEL_SUCCEEDED:"PUBLISH_TO_CHANNEL_SUCCEEDED",FINALIZE_ENGAGEMENT_FAILED:"FINALIZE_ENGAGEMENT_FAILED",FINALIZE_ENGAGEMENT_SUCCEEDED:"FINALIZE_ENGAGEMENT_SUCCEEDED",SET_WIDGET_URL_FAILED:"SET_WIDGET_URL_FAILED",UPDATE_ENGAGEMENT_FAILED:"UPDATE_ENGAGEMENT_FAILED",UPDATE_ENGAGEMENT_SUCCEEDED:"UPDATE_ENGAGEMENT_SUCCEEDED",VISIBILITY_CHANGED:"VISIBILITY_CHANGED"}),{END_CALL:"END_CALL",ERROR:"ERROR",READY:"READY",SET_CALL_STATE:"SET_CALL_STATE",SET_WIDGET_URL:"SET_WIDGET_URL",SYNC_ACK_FAILED:"SYNC_ACK_FAILED",SYNC_ACK:"SYNC_ACK",SYNC:"SYNC",UNLOADING:"UNLOADING",FAILED:"FAILED"}),t.messageHandlerNames=((n={})[t.messageType.CALLER_ID_MATCH_FAILED]="onCallerIdMatchFailed",n[t.messageType.CALLER_ID_MATCH_SUCCEEDED]="onCallerIdMatchSucceeded",n[t.messageType.CREATE_ENGAGEMENT_FAILED]="onCreateEngagementFailed",n[t.messageType.CREATE_ENGAGEMENT_SUCCEEDED]="onCreateEngagementSucceeded",n[t.messageType.DIAL_NUMBER]="onDialNumber",n[t.messageType.END_CALL]="onEndCall",n[t.messageType.ENGAGEMENT_CREATED]="onEngagementCreated",n[t.messageType.INITIATE_CALL_ID_FAILED]="onInitiateCallIdFailed",n[t.messageType.INITIATE_CALL_ID_SUCCEEDED]="onInitiateCallIdSucceeded",n[t.messageType.NAVIGATE_TO_RECORD_FAILED]="onNavigateToRecordFailed",n[t.messageType.UPDATE_ASSOCIATIONS_FAILED]="onUpdateAssociationsFailed",n[t.messageType.PUBLISH_TO_CHANNEL_FAILED]="onPublishToChannelFailed",n[t.messageType.PUBLISH_TO_CHANNEL_SUCCEEDED]="onPublishToChannelSucceeded",n[t.messageType.FINALIZE_ENGAGEMENT_FAILED]="onFinalizeEngagementFailed",n[t.messageType.FINALIZE_ENGAGEMENT_SUCCEEDED]="onFinalizeEngagementSucceeded",n[t.messageType.READY]="onReady",n[t.messageType.SET_CALL_STATE]="onSetCallState",n[t.messageType.SET_WIDGET_URL_FAILED]="onSetWidgetUrlFailed",n[t.messageType.UPDATE_ENGAGEMENT_FAILED]="onUpdateEngagementFailed",n[t.messageType.UPDATE_ENGAGEMENT_SUCCEEDED]="onUpdateEngagementSucceeded",n[t.messageType.VISIBILITY_CHANGED]="onVisibilityChanged",n[t.messageType.FAILED]="onFailed",n),t.errorType={UNKNOWN_MESSAGE_TYPE:"UNKNOWN_MESSAGE_TYPE"};var r="CONNECTING",E="CALLING_CRM_USER",p="IN_PROGRESS",l="CANCELED",d="FAILED",c="BUSY",_="NO_ANSWER",A="COMPLETED",u="ENDING",g="QUEUED",N="RINGING";t.callStatus={INTERNAL_CONNECTING:r,INTERNAL_CALLING_CRM_USER:E,INTERNAL_IN_PROGRESS:p,INTERNAL_CANCELED:l,INTERNAL_FAILED:d,INTERNAL_BUSY:c,INTERNAL_NO_ANSWER:_,INTERNAL_COMPLETED:A,INTERNAL_ENDING:u,INTERNAL_QUEUED:g,INTERNAL_RINGING:N},t.callRingingStatus={INTERNAL_QUEUED:g,INTERNAL_RINGING:N,INTERNAL_CONNECTING:r,INTERNAL_CALLING_CRM_USER:E},t.callInProgressStatus={INTERNAL_IN_PROGRESS:p},t.callEndingStatus={INTERNAL_ENDING:u},t.callEndStatus={INTERNAL_COMPLETED:A,INTERNAL_FAILED:d,INTERNAL_CANCELED:l,INTERNAL_BUSY:c,INTERNAL_NO_ANSWER:_},t.CONTACT="CONTACT",t.COMPANY="COMPANY",t.callerIdTypes={CONTACT:t.CONTACT,COMPANY:t.COMPANY}},950:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=s(628),a="[calling-extensions-sdk@".concat(n.VERSION,"]"),i=function(){function e(t){var s=this;this.firstSyncSent=0,this.options=t;var n=t.iFrameOptions,a=t.onMessageHandler,i=t.debugMode;if(this.onMessageHandler=a,!this.onMessageHandler)throw new Error("Invalid options: onMessageHandler is not defined");this.isIFrameHost=!!n,this.debugMode=i,this.callbacks={},this.instanceId=Date.now(),this.instanceRegexp=new RegExp("^".concat(this.instanceId)),this.isReady=!1,this.messageHandler=function(e){return s.onMessage(e)},window.addEventListener("message",this.messageHandler),this.iFrame=n?e.createIFrame(n,(function(){s.firstSyncSent=Date.now(),s.isReady=!1,s.sendSync()}),this.handleLoadError):null,this.destinationWindow=n&&this.iFrame?this.iFrame.contentWindow:window.parent,this.destinationHost=e.getDestinationHost(n)}return e.createMessageId=function(e){return"".concat(e,"_").concat(Date.now())},e.getHostElement=function(e){var t=document.querySelector(e);if(!t)throw new Error("hostElement not found. Selector - ".concat(e));return t},e.extractHostFromUrl=function(e){var t=document.createElement("a");return t.href=e,"".concat(t.protocol,"//").concat(t.host)},e.getDestinationHost=function(t){var s=t?t.src:document.referrer;return e.extractHostFromUrl(s)},e.prototype.handleLoadError=function(){this.onMessageHandler({type:n.messageType.SYNC_ACK_FAILED})},e.createIFrame=function(t,s,n){var a=t.src,i=t.width,o=t.height,r=t.hostElementSelector;if(!(a&&i&&o&&r))throw new Error("iFrameOptions is missing one of the required properties - {src, width, height, hostElementSelector}.");var E=document.createElement("iframe");E.onload=s,E.onerror=n,E.src=a,E.width=i,E.height=o,E.allow="microphone; autoplay",E.id="hubspot-calling-extension-iframe";var p=e.getHostElement(r);return p.innerHTML="",p.appendChild(E),p.querySelector("iframe")},e.prototype.updateIFrameSize=function(t){var s=t.width,n=t.height;this.iFrame&&(s&&this.iFrame.setAttribute("width",e.formatSize(s)),n&&this.iFrame.setAttribute("height",e.formatSize(n)))},e.formatSize=function(e){return"number"==typeof e?"".concat(e,"px"):e},e.prototype.onReady=function(e){void 0===e&&(e={}),this.isReady=!0,this.onMessageHandler({type:n.messageType.READY,data:e})},e.prototype.remove=function(){window.removeEventListener("message",this.messageHandler),this.iFrame&&this.options&&this.options.iFrameOptions&&(e.getHostElement(this.options.iFrameOptions.hostElementSelector).innerHTML="",this.isReady=!1,this.iFrame=null,this.options=null)},e.prototype.sendMessage=function(t,s){var i=t.type;if(i===n.messageType.SYNC||this.isReady){var o=t.messageId;o||(o=e.createMessageId(this.instanceId),s&&(this.callbacks[o]=s));var r=Object.assign({},t,{messageId:o});this.logDebugMessage(a,n.debugMessageType.TO_HUBSPOT,i,t),this.destinationWindow&&this.destinationWindow.postMessage(r,this.destinationHost)}else console.warn(a,"iFrame not initialized to send a message within HubSpot",t)},e.prototype.onMessage=function(t){var s=t.data,i=t.origin,o=t.data.type;if(o!==n.messageType.SYNC){if(this.destinationHost===i){var r=s.messageId;if(r&&o){if(this.logDebugMessage(a,n.debugMessageType.FROM_HUBSPOT,o,s),o===n.messageType.SET_WIDGET_URL){var E=s.iFrameUrl;return this.destinationHost=E||this.destinationHost,void this.onReady({iFrameUrl:E})}if(this.instanceRegexp.test(r)){var p=this.callbacks[r];p&&(p(s),delete this.callbacks[r])}else this.onMessageHandler(s)}}}else{var l=t.data,d=l.portalId,c=l.userId,_=l.ownerId,A=l.engagementId,u=l.iframeLocation,g=l.usesCallingWindow;if(!this.isReady){this.isReady=!0;var N=Object.assign({},t.data,{type:n.messageType.SYNC_ACK,debugMode:this.debugMode,version:n.VERSION,iFrameUrl:e.extractHostFromUrl(window.location.href)}),T=t.data.hostUrl;this.destinationHost=T||this.destinationHost,this.logDebugMessage(a,n.debugMessageType.FROM_HUBSPOT,o,s),this.sendMessage(N),this.onReady({engagementId:A,portalId:d,userId:c,ownerId:_,iframeLocation:u,usesCallingWindow:g,hostUrl:T})}}},e.prototype.sendSync=function(){var t=this;Date.now()-this.firstSyncSent>3e4?this.onMessageHandler({type:n.messageType.SYNC_ACK_FAILED}):(this.sendMessage({type:n.messageType.SYNC,hostUrl:e.extractHostFromUrl(window.location.href)},(function(e){var s=e.iFrameUrl;t.destinationHost=s||t.destinationHost,t.onReady(),t.debugMode=e&&e.debugMode})),window.setTimeout((function(){t.iFrame&&!t.isReady&&t.sendSync()}),100))},e.prototype.logDebugMessage=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.debugMode?console.log.call(null,e):console.debug.call(null,e)},e}();t.default=i},696:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},330:e=>{e.exports=JSON.parse('{"name":"@hubspot/calling-extensions-sdk","version":"0.9.4-alpha.0","description":"A JavaScript SDK for integrating calling apps into HubSpot.","publishConfig":{"access":"public"},"scripts":{"build":"rm -rf dist && npm run build:cjs && npm run build:esm","build:cjs":"webpack --config webpack.cjs.config.js","build:esm":"webpack --config webpack.esm.config.js","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","module":"./dist/main.esm.js","files":["dist/**/*","src/","index.ts"],"types":"./dist/types/index.d.ts","author":"","license":"MIT","engines":{"node":">=14"},"devDependencies":{"@babel/cli":"^7.21.0","@babel/core":"^7.4.5","@babel/preset-env":"^7.21.4","@babel/preset-typescript":"^7.26.0","@types/jasmine":"^5.1.5","@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","webpack-merge":"^6.0.1"}}')}},t={};return function s(n){var a=t[n];if(void 0!==a)return a.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,s),i.exports}(416)})())); |
import IFrameManager from "./IFrameManager"; | ||
import { EventHandlers, OnCallAnswered, OnCallCompleted, OnCallEnded, OnError, OnIncomingCall, OnInitialized, OnMessage, OnNavigateToRecord, OnOutgoingCall, OnPublishToChannel, OnResize, OnSetWidgetUrl, Options } from "./types"; | ||
import { EventHandlers, OnCallAnswered, OnCallCompleted, OnCallEnded, OnError, OnFinalizeEngagement, OnIncomingCall, OnInitialized, OnMessage, OnNavigateToRecord, OnOutgoingCall, OnPublishToChannel, OnResize, OnSetWidgetUrl, Options } from "./types"; | ||
declare class CallingExtensions { | ||
@@ -107,5 +107,12 @@ options: Options; | ||
* @param {OnPublishToChannel} data - The data object to be published. | ||
* @deprecated use finalizeEngagement instead | ||
*/ | ||
publishToChannel(data: OnPublishToChannel): void; | ||
/** | ||
* Finalizes the engagement. | ||
* | ||
* @param {OnFinalizeEngagement} data - The data object to be published. | ||
*/ | ||
finalizeEngagement(data: OnFinalizeEngagement): void; | ||
/** | ||
* Sends a message to update the widget url. | ||
@@ -112,0 +119,0 @@ * |
@@ -19,2 +19,3 @@ import { EventHandlers } from "./types"; | ||
OUTGOING_CALL_STARTED: string; | ||
/** @deprecated use FINALIZE_ENGAGEMENT instead */ | ||
PUBLISH_TO_CHANNEL: string; | ||
@@ -24,2 +25,3 @@ RESIZE_WIDGET: string; | ||
USER_UNAVAILABLE: string; | ||
FINALIZE_ENGAGEMENT: string; | ||
}; | ||
@@ -48,4 +50,8 @@ export declare const messageType: { | ||
UPDATE_ASSOCIATIONS_FAILED: string; | ||
/** @deprecated use FINALIZE_ENGAGEMENT_FAILED instead */ | ||
PUBLISH_TO_CHANNEL_FAILED: string; | ||
/** @deprecated use FINALIZE_ENGAGEMENT_SUCCEEDED instead */ | ||
PUBLISH_TO_CHANNEL_SUCCEEDED: string; | ||
FINALIZE_ENGAGEMENT_FAILED: string; | ||
FINALIZE_ENGAGEMENT_SUCCEEDED: string; | ||
SET_WIDGET_URL_FAILED: string; | ||
@@ -65,2 +71,3 @@ UPDATE_ENGAGEMENT_FAILED: string; | ||
OUTGOING_CALL_STARTED: string; | ||
/** @deprecated use FINALIZE_ENGAGEMENT instead */ | ||
PUBLISH_TO_CHANNEL: string; | ||
@@ -70,2 +77,3 @@ RESIZE_WIDGET: string; | ||
USER_UNAVAILABLE: string; | ||
FINALIZE_ENGAGEMENT: string; | ||
}; | ||
@@ -72,0 +80,0 @@ export declare const messageHandlerNames: Record<string, keyof EventHandlers>; |
@@ -15,2 +15,4 @@ export type EventHandlers = { | ||
onPublishToChannelSucceeded: Function; | ||
onFinalizeEngagementFailed: Function; | ||
onFinalizeEngagementSucceeded: Function; | ||
onReady: Function; | ||
@@ -67,2 +69,5 @@ onSetCallState: Function; | ||
}; | ||
/** | ||
* @deprecated use OnFinalizeEngagement instead | ||
*/ | ||
export type OnPublishToChannel = { | ||
@@ -72,2 +77,6 @@ externalCallId: string; | ||
}; | ||
export type OnFinalizeEngagement = { | ||
externalCallId: string; | ||
engagementId: number; | ||
}; | ||
export type OnSetWidgetUrl = { | ||
@@ -74,0 +83,0 @@ iFrameUrl: string; |
{ | ||
"name": "@hubspot/calling-extensions-sdk", | ||
"version": "0.9.3", | ||
"version": "0.9.4-alpha.1", | ||
"description": "A JavaScript SDK for integrating calling apps into HubSpot.", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -15,2 +15,3 @@ import IFrameManager from "./IFrameManager"; | ||
OnError, | ||
OnFinalizeEngagement, | ||
OnIncomingCall, | ||
@@ -280,2 +281,3 @@ OnInitialized, | ||
* @param {OnPublishToChannel} data - The data object to be published. | ||
* @deprecated use finalizeEngagement instead | ||
*/ | ||
@@ -290,2 +292,14 @@ publishToChannel(data: OnPublishToChannel) { | ||
/** | ||
* Finalizes the engagement. | ||
* | ||
* @param {OnFinalizeEngagement} data - The data object to be published. | ||
*/ | ||
finalizeEngagement(data: OnFinalizeEngagement) { | ||
this.sendMessage({ | ||
type: messageType.FINALIZE_ENGAGEMENT, | ||
data, | ||
}); | ||
} | ||
/** | ||
* Sends a message to update the widget url. | ||
@@ -292,0 +306,0 @@ * |
@@ -23,2 +23,3 @@ import packageJson from "../package.json"; | ||
OUTGOING_CALL_STARTED: "OUTGOING_CALL_STARTED", | ||
/** @deprecated use FINALIZE_ENGAGEMENT instead */ | ||
PUBLISH_TO_CHANNEL: "PUBLISH_TO_CHANNEL", | ||
@@ -28,2 +29,3 @@ RESIZE_WIDGET: "RESIZE_WIDGET", | ||
USER_UNAVAILABLE: "USER_UNAVAILABLE", | ||
FINALIZE_ENGAGEMENT: "FINALIZE_ENGAGEMENT", | ||
}; | ||
@@ -43,4 +45,8 @@ | ||
UPDATE_ASSOCIATIONS_FAILED: "UPDATE_ASSOCIATIONS_FAILED", | ||
/** @deprecated use FINALIZE_ENGAGEMENT_FAILED instead */ | ||
PUBLISH_TO_CHANNEL_FAILED: "PUBLISH_TO_CHANNEL_FAILED", | ||
/** @deprecated use FINALIZE_ENGAGEMENT_SUCCEEDED instead */ | ||
PUBLISH_TO_CHANNEL_SUCCEEDED: "PUBLISH_TO_CHANNEL_SUCCEEDED", | ||
FINALIZE_ENGAGEMENT_FAILED: "FINALIZE_ENGAGEMENT_FAILED", | ||
FINALIZE_ENGAGEMENT_SUCCEEDED: "FINALIZE_ENGAGEMENT_SUCCEEDED", | ||
SET_WIDGET_URL_FAILED: "SET_WIDGET_URL_FAILED", | ||
@@ -81,2 +87,4 @@ UPDATE_ENGAGEMENT_FAILED: "UPDATE_ENGAGEMENT_FAILED", | ||
[messageType.PUBLISH_TO_CHANNEL_SUCCEEDED]: "onPublishToChannelSucceeded", | ||
[messageType.FINALIZE_ENGAGEMENT_FAILED]: "onFinalizeEngagementFailed", | ||
[messageType.FINALIZE_ENGAGEMENT_SUCCEEDED]: "onFinalizeEngagementSucceeded", | ||
[messageType.READY]: "onReady", | ||
@@ -83,0 +91,0 @@ [messageType.SET_CALL_STATE]: "onSetCallState", |
@@ -15,2 +15,4 @@ export type EventHandlers = { | ||
onPublishToChannelSucceeded: Function; | ||
onFinalizeEngagementFailed: Function; | ||
onFinalizeEngagementSucceeded: Function; | ||
onReady: Function; | ||
@@ -77,2 +79,5 @@ onSetCallState: Function; | ||
/** | ||
* @deprecated use OnFinalizeEngagement instead | ||
*/ | ||
export type OnPublishToChannel = { | ||
@@ -83,2 +88,7 @@ externalCallId: string; | ||
export type OnFinalizeEngagement = { | ||
externalCallId: string; | ||
engagementId: number; | ||
}; | ||
export type OnSetWidgetUrl = { | ||
@@ -85,0 +95,0 @@ iFrameUrl: string; |
75116
3.8%1359
4.14%