@knocklabs/react 0.10.2 → 0.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.4
4
+
5
+ ### Patch Changes
6
+
7
+ - f9aca69: fix: poll to check if OAuth connection succeeded in case popup communication fails during Slack and Microsoft Teams auth flows
8
+ - Updated dependencies [f9aca69]
9
+ - @knocklabs/react-core@0.12.4
10
+
11
+ ## 0.10.3
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [cf04e5f]
16
+ - @knocklabs/client@0.20.3
17
+ - @knocklabs/react-core@0.12.3
18
+
3
19
  ## 0.10.2
4
20
 
5
21
  ### Patch Changes
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=e=>{const n=window.screenLeft??window.screenX,t=window.screenTop??window.screenY,o=window.innerWidth??document.documentElement.clientWidth??screen.width,i=window.innerHeight??document.documentElement.clientHeight??screen.height,c=o/2-600/2+n,d=`width=600,height=800,top=${i/2-800/2+t},left=${c}`;window.open(e,"_blank",d)},h=()=>{if(typeof window<"u")return window};exports.checkForWindow=h;exports.openPopupWindow=w;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=e=>{const n=window.screenLeft??window.screenX,t=window.screenTop??window.screenY,o=window.innerWidth??document.documentElement.clientWidth??screen.width,i=window.innerHeight??document.documentElement.clientHeight??screen.height,c=o/2-600/2+n,d=`width=600,height=800,top=${i/2-800/2+t},left=${c}`;return window.open(e,"_blank",d)},h=()=>{if(typeof window<"u")return window};exports.checkForWindow=h;exports.openPopupWindow=w;
2
2
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["export const openPopupWindow = (url: string) => {\n const width = 600;\n const height = 800;\n // Calculate the position to center the window\n const screenLeft = window.screenLeft ?? window.screenX;\n const screenTop = window.screenTop ?? window.screenY;\n\n const innerWidth =\n window.innerWidth ?? document.documentElement.clientWidth ?? screen.width;\n const innerHeight =\n window.innerHeight ??\n document.documentElement.clientHeight ??\n screen.height;\n\n const left = innerWidth / 2 - width / 2 + screenLeft;\n const top = innerHeight / 2 - height / 2 + screenTop;\n\n // Window features\n const features = `width=${width},height=${height},top=${top},left=${left}`;\n\n window.open(url, \"_blank\", features);\n};\n\nexport const checkForWindow = () => {\n if (typeof window !== \"undefined\") {\n return window;\n }\n};\n"],"names":["openPopupWindow","url","screenLeft","window","screenX","screenTop","screenY","innerWidth","document","documentElement","clientWidth","screen","width","innerHeight","clientHeight","height","left","features","open","checkForWindow"],"mappings":"gFAAaA,MAAAA,EAAmBC,GAAgB,CAIxCC,MAAAA,EAAaC,OAAOD,YAAcC,OAAOC,QACzCC,EAAYF,OAAOE,WAAaF,OAAOG,QAEvCC,EACJJ,OAAOI,YAAcC,SAASC,gBAAgBC,aAAeC,OAAOC,MAChEC,EACJV,OAAOU,aACPL,SAASC,gBAAgBK,cACzBH,OAAOI,OAEHC,EAAOT,EAAa,EAAIK,IAAQ,EAAIV,EAIpCe,EAAW,4BAHLJ,EAAc,EAAIE,IAAS,EAAIV,CAGgB,SAASW,CAAI,GAEjEE,OAAAA,KAAKjB,EAAK,SAAUgB,CAAQ,CACrC,EAEaE,EAAiBA,IAAM,CAC9B,GAAA,OAAOhB,OAAW,IACbA,OAAAA,MAEX"}
1
+ {"version":3,"file":"utils.js","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["export const openPopupWindow = (url: string) => {\n const width = 600;\n const height = 800;\n // Calculate the position to center the window\n const screenLeft = window.screenLeft ?? window.screenX;\n const screenTop = window.screenTop ?? window.screenY;\n\n const innerWidth =\n window.innerWidth ?? document.documentElement.clientWidth ?? screen.width;\n const innerHeight =\n window.innerHeight ??\n document.documentElement.clientHeight ??\n screen.height;\n\n const left = innerWidth / 2 - width / 2 + screenLeft;\n const top = innerHeight / 2 - height / 2 + screenTop;\n\n // Window features\n const features = `width=${width},height=${height},top=${top},left=${left}`;\n\n return window.open(url, \"_blank\", features);\n};\n\nexport const checkForWindow = () => {\n if (typeof window !== \"undefined\") {\n return window;\n }\n};\n"],"names":["openPopupWindow","url","screenLeft","window","screenX","screenTop","screenY","innerWidth","document","documentElement","clientWidth","screen","width","innerHeight","clientHeight","height","left","features","open","checkForWindow"],"mappings":"gFAAaA,MAAAA,EAAmBC,GAAgB,CAIxCC,MAAAA,EAAaC,OAAOD,YAAcC,OAAOC,QACzCC,EAAYF,OAAOE,WAAaF,OAAOG,QAEvCC,EACJJ,OAAOI,YAAcC,SAASC,gBAAgBC,aAAeC,OAAOC,MAChEC,EACJV,OAAOU,aACPL,SAASC,gBAAgBK,cACzBH,OAAOI,OAEHC,EAAOT,EAAa,EAAIK,IAAQ,EAAIV,EAIpCe,EAAW,4BAHLJ,EAAc,EAAIE,IAAS,EAAIV,CAGgB,SAASW,CAAI,GAExE,OAAOb,OAAOe,KAAKjB,EAAK,SAAUgB,CAAQ,CAC5C,EAEaE,EAAiBA,IAAM,CAC9B,GAAA,OAAOhB,OAAW,IACbA,OAAAA,MAEX"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("react"),u=require("@knocklabs/react-core"),b=require("../../../core/utils.js");;/* empty css */const l=require("../MsTeamsIcon/MsTeamsIcon.js");;/* empty css */const M=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},e=M(T),w=({redirectUrl:t,onAuthenticationComplete:s,...i})=>{const p="graphApiClientId"in i?i.graphApiClientId:i.msTeamsBotId,{t:n}=u.useTranslations(),d=u.useKnockClient(),{setConnectionStatus:o,connectionStatus:c,setActionLabel:a,actionLabel:m,errorLabel:g}=u.useKnockMsTeamsClient(),{buildMsTeamsAuthUrl:_,disconnectFromMsTeams:h}=u.useMsTeamsAuth(p,t);T.useEffect(()=>{const f=r=>{if(r.origin===d.host)try{r.data==="authComplete"&&o("connected"),r.data==="authFailed"&&o("error"),s==null||s(r.data)}catch{o("error")}};return window.addEventListener("message",f,!1),()=>{window.removeEventListener("message",f)}},[d.host,s,o]);const E=n("msTeamsDisconnect")||null,k=n("msTeamsReconnect")||null;return c==="connecting"||c==="disconnecting"?e.default.createElement("div",{className:"rtk-connect__button rtk-connect__button--loading"},e.default.createElement(l.MsTeamsIcon,{height:"16px",width:"16px"}),e.default.createElement("span",null,n(c==="connecting"?"msTeamsConnecting":"msTeamsDisconnecting"))):c==="error"?e.default.createElement("button",{onClick:()=>b.openPopupWindow(_()),className:"rtk-connect__button rtk-connect__button--error",onMouseEnter:()=>a(k),onMouseLeave:()=>a(null)},e.default.createElement(l.MsTeamsIcon,{height:"16px",width:"16px"}),e.default.createElement("span",{className:"rtk-connect__button__text--error"},m||g||n("msTeamsError"))):c==="disconnected"?e.default.createElement("button",{onClick:()=>b.openPopupWindow(_()),className:"rtk-connect__button rtk-connect__button--disconnected"},e.default.createElement(l.MsTeamsIcon,{height:"16px",width:"16px"}),e.default.createElement("span",null,n("msTeamsConnect"))):e.default.createElement("button",{onClick:h,className:"rtk-connect__button rtk-connect__button--connected",onMouseEnter:()=>a(E),onMouseLeave:()=>a(null)},e.default.createElement(l.MsTeamsIcon,{height:"16px",width:"16px"}),e.default.createElement("span",{className:"rtk-connect__button__text--connected"},m||n("msTeamsConnected")))};exports.MsTeamsAuthButton=w;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react"),c=require("@knocklabs/react-core"),T=require("../../../core/utils.js");;/* empty css */const r=require("../MsTeamsIcon/MsTeamsIcon.js");;/* empty css */const I=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},e=I(b),x=({redirectUrl:t,onAuthenticationComplete:d,...l})=>{const f="graphApiClientId"in l?l.graphApiClientId:l.msTeamsBotId,{t:n}=c.useTranslations(),i=c.useKnockClient(),{setConnectionStatus:s,connectionStatus:o,setActionLabel:a,actionLabel:p,errorLabel:g,tenantId:h,knockMsTeamsChannelId:_,popupWindowRef:u}=c.useKnockMsTeamsClient(),{buildMsTeamsAuthUrl:k,disconnectFromMsTeams:C}=c.useMsTeamsAuth(f,t);c.useAuthPostMessageListener({knockHost:i.host,popupWindowRef:u,setConnectionStatus:s,onAuthenticationComplete:d}),c.useAuthPolling({popupWindowRef:u,setConnectionStatus:s,onAuthenticationComplete:d,authCheckFn:b.useCallback(async()=>i.msTeams.authCheck({tenant:h,knockChannelId:_}),[i.msTeams,h,_])});const M=n("msTeamsDisconnect")||null,E=n("msTeamsReconnect")||null;return o==="connecting"||o==="disconnecting"?e.default.createElement("div",{className:"rtk-connect__button rtk-connect__button--loading"},e.default.createElement(r.MsTeamsIcon,{height:"16px",width:"16px"}),e.default.createElement("span",null,n(o==="connecting"?"msTeamsConnecting":"msTeamsDisconnecting"))):o==="error"?e.default.createElement("button",{onClick:()=>{const m=T.openPopupWindow(k());u.current=m,s("connecting")},className:"rtk-connect__button rtk-connect__button--error",onMouseEnter:()=>a(E),onMouseLeave:()=>a(null)},e.default.createElement(r.MsTeamsIcon,{height:"16px",width:"16px"}),e.default.createElement("span",{className:"rtk-connect__button__text--error"},p||g||n("msTeamsError"))):o==="disconnected"?e.default.createElement("button",{onClick:()=>{const m=T.openPopupWindow(k());u.current=m,s("connecting")},className:"rtk-connect__button rtk-connect__button--disconnected"},e.default.createElement(r.MsTeamsIcon,{height:"16px",width:"16px"}),e.default.createElement("span",null,n("msTeamsConnect"))):e.default.createElement("button",{onClick:C,className:"rtk-connect__button rtk-connect__button--connected",onMouseEnter:()=>a(M),onMouseLeave:()=>a(null)},e.default.createElement(r.MsTeamsIcon,{height:"16px",width:"16px"}),e.default.createElement("span",{className:"rtk-connect__button__text--connected"},p||n("msTeamsConnected")))};exports.MsTeamsAuthButton=x;
2
2
  //# sourceMappingURL=MsTeamsAuthButton.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MsTeamsAuthButton.js","sources":["../../../../../../src/modules/ms-teams/components/MsTeamsAuthButton/MsTeamsAuthButton.tsx"],"sourcesContent":["import {\n useKnockClient,\n useKnockMsTeamsClient,\n useMsTeamsAuth,\n useTranslations,\n} from \"@knocklabs/react-core\";\nimport { FunctionComponent, useEffect } from \"react\";\n\nimport { openPopupWindow } from \"../../../core/utils\";\nimport \"../../theme.css\";\nimport { MsTeamsIcon } from \"../MsTeamsIcon\";\n\nimport \"./styles.css\";\n\nexport type MsTeamsAuthButtonProps = {\n redirectUrl?: string;\n onAuthenticationComplete?: (authenticationResp: string) => void;\n} & (\n | {\n /**\n * The client ID of your Microsoft Graph API-enabled application registered with Microsoft Entra. This should\n * match the \"Graph API client ID\" setting of your Microsoft Teams channel in the Knock dashboard.\n */\n graphApiClientId: string;\n }\n | {\n /**\n * @deprecated Use `graphApiClientId` instead. This field will be removed in a future release.\n */\n msTeamsBotId: string;\n }\n);\n\nexport const MsTeamsAuthButton: FunctionComponent<MsTeamsAuthButtonProps> = ({\n redirectUrl,\n onAuthenticationComplete,\n ...props\n}) => {\n const graphApiClientId =\n \"graphApiClientId\" in props ? props.graphApiClientId : props.msTeamsBotId;\n\n const { t } = useTranslations();\n const knock = useKnockClient();\n\n const {\n setConnectionStatus,\n connectionStatus,\n setActionLabel,\n actionLabel,\n errorLabel,\n } = useKnockMsTeamsClient();\n\n const { buildMsTeamsAuthUrl, disconnectFromMsTeams } = useMsTeamsAuth(\n graphApiClientId,\n redirectUrl,\n );\n\n useEffect(() => {\n const receiveMessage = (event: MessageEvent) => {\n if (event.origin !== knock.host) {\n return;\n }\n\n try {\n if (event.data === \"authComplete\") {\n setConnectionStatus(\"connected\");\n }\n\n if (event.data === \"authFailed\") {\n setConnectionStatus(\"error\");\n }\n\n onAuthenticationComplete?.(event.data);\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n };\n\n window.addEventListener(\"message\", receiveMessage, false);\n\n // Cleanup the event listener when the component unmounts\n return () => {\n window.removeEventListener(\"message\", receiveMessage);\n };\n }, [knock.host, onAuthenticationComplete, setConnectionStatus]);\n\n const disconnectLabel = t(\"msTeamsDisconnect\") || null;\n const reconnectLabel = t(\"msTeamsReconnect\") || null;\n\n // Loading states\n if (\n connectionStatus === \"connecting\" ||\n connectionStatus === \"disconnecting\"\n ) {\n return (\n <div className=\"rtk-connect__button rtk-connect__button--loading\">\n <MsTeamsIcon height=\"16px\" width=\"16px\" />\n <span>\n {connectionStatus === \"connecting\"\n ? t(\"msTeamsConnecting\")\n : t(\"msTeamsDisconnecting\")}\n </span>\n </div>\n );\n }\n\n // Error state\n if (connectionStatus === \"error\") {\n return (\n <button\n onClick={() => openPopupWindow(buildMsTeamsAuthUrl())}\n className=\"rtk-connect__button rtk-connect__button--error\"\n onMouseEnter={() => setActionLabel(reconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <MsTeamsIcon height=\"16px\" width=\"16px\" />\n <span className=\"rtk-connect__button__text--error\">\n {actionLabel || errorLabel || t(\"msTeamsError\")}\n </span>\n </button>\n );\n }\n\n // Disconnected state\n if (connectionStatus === \"disconnected\") {\n return (\n <button\n onClick={() => openPopupWindow(buildMsTeamsAuthUrl())}\n className=\"rtk-connect__button rtk-connect__button--disconnected\"\n >\n <MsTeamsIcon height=\"16px\" width=\"16px\" />\n <span>{t(\"msTeamsConnect\")}</span>\n </button>\n );\n }\n\n // Connected state\n return (\n <button\n onClick={disconnectFromMsTeams}\n className=\"rtk-connect__button rtk-connect__button--connected\"\n onMouseEnter={() => setActionLabel(disconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <MsTeamsIcon height=\"16px\" width=\"16px\" />\n <span className=\"rtk-connect__button__text--connected\">\n {actionLabel || t(\"msTeamsConnected\")}\n </span>\n </button>\n );\n};\n"],"names":["MsTeamsAuthButton","redirectUrl","onAuthenticationComplete","props","graphApiClientId","msTeamsBotId","t","useTranslations","knock","useKnockClient","setConnectionStatus","connectionStatus","setActionLabel","actionLabel","errorLabel","useKnockMsTeamsClient","buildMsTeamsAuthUrl","disconnectFromMsTeams","useMsTeamsAuth","useEffect","receiveMessage","event","origin","host","data","addEventListener","removeEventListener","disconnectLabel","reconnectLabel","React","MsTeamsIcon","openPopupWindow"],"mappings":"+VAiCaA,EAA+DA,CAAC,CAC3EC,YAAAA,EACAC,yBAAAA,EACA,GAAGC,CACL,IAAM,CACJ,MAAMC,EACJ,qBAAsBD,EAAQA,EAAMC,iBAAmBD,EAAME,aAEzD,CAAEC,EAAAA,GAAMC,kBAAgB,EACxBC,EAAQC,EAAAA,eAAe,EAEvB,CACJC,oBAAAA,EACAC,iBAAAA,EACAC,eAAAA,EACAC,YAAAA,EACAC,WAAAA,GACEC,wBAAsB,EAEpB,CAAEC,oBAAAA,EAAqBC,sBAAAA,CAAAA,EAA0BC,EACrDd,eAAAA,EACAH,CACF,EAEAkB,EAAAA,UAAU,IAAM,CACRC,MAAAA,EAAkBC,GAAwB,CAC1CA,GAAAA,EAAMC,SAAWd,EAAMe,KAIvB,GAAA,CACEF,EAAMG,OAAS,gBACjBd,EAAoB,WAAW,EAG7BW,EAAMG,OAAS,cACjBd,EAAoB,OAAO,EAG7BR,GAAAA,MAAAA,EAA2BmB,EAAMG,WAClB,CACfd,EAAoB,OAAO,CAAA,CAE/B,EAEOe,cAAAA,iBAAiB,UAAWL,EAAgB,EAAK,EAGjD,IAAM,CACJM,OAAAA,oBAAoB,UAAWN,CAAc,CACtD,GACC,CAACZ,EAAMe,KAAMrB,EAA0BQ,CAAmB,CAAC,EAExDiB,MAAAA,EAAkBrB,EAAE,mBAAmB,GAAK,KAC5CsB,EAAiBtB,EAAE,kBAAkB,GAAK,KAI9CK,OAAAA,IAAqB,cACrBA,IAAqB,gBAGnBkB,EAAA,QAAA,cAAC,OAAI,UAAU,kDAAA,0BACZC,EAAY,YAAA,CAAA,OAAO,OAAO,MAAM,MAAM,CAAA,EACtCD,EAAAA,QAAA,cAAA,OAAA,KAEKvB,EADHK,IAAqB,aAChB,oBACA,sBADmB,CAE3B,CACF,EAKAA,IAAqB,gCAEpB,SACC,CAAA,QAAS,IAAMoB,EAAAA,gBAAgBf,GAAqB,EACpD,UAAU,iDACV,aAAc,IAAMJ,EAAegB,CAAc,EACjD,aAAc,IAAMhB,EAAe,IAAI,CAAA,0BAEtCkB,EAAAA,YAAY,CAAA,OAAO,OAAO,MAAM,OAAM,EACvCD,UAAA,cAAC,OAAK,CAAA,UAAU,oCACbhB,GAAeC,GAAcR,EAAE,cAAc,CAChD,CACF,EAKAK,IAAqB,eAErBkB,EAAA,QAAA,cAAC,UACC,QAAS,IAAME,EAAAA,gBAAgBf,EAAoB,CAAC,EACpD,UAAU,uDAEV,EAAAa,EAAA,QAAA,cAACC,eAAY,OAAO,OAAO,MAAM,MAAM,CAAA,0BACtC,OAAMxB,KAAAA,EAAE,gBAAgB,CAAE,CAC7B,EAMDuB,EAAAA,QAAA,cAAA,SAAA,CACC,QAASZ,EACT,UAAU,qDACV,aAAc,IAAML,EAAee,CAAe,EAClD,aAAc,IAAMf,EAAe,IAAI,GAEvCiB,EAAAA,QAAA,cAACC,EAAAA,YAAY,CAAA,OAAO,OAAO,MAAM,MAAM,CAAA,EACvCD,EAAA,QAAA,cAAC,OAAK,CAAA,UAAU,sCACbhB,EAAAA,GAAeP,EAAE,kBAAkB,CACtC,CACF,CAEJ"}
1
+ {"version":3,"file":"MsTeamsAuthButton.js","sources":["../../../../../../src/modules/ms-teams/components/MsTeamsAuthButton/MsTeamsAuthButton.tsx"],"sourcesContent":["import {\n useAuthPolling,\n useAuthPostMessageListener,\n useKnockClient,\n useKnockMsTeamsClient,\n useMsTeamsAuth,\n useTranslations,\n} from \"@knocklabs/react-core\";\nimport { FunctionComponent, useCallback } from \"react\";\n\nimport { openPopupWindow } from \"../../../core/utils\";\nimport \"../../theme.css\";\nimport { MsTeamsIcon } from \"../MsTeamsIcon\";\n\nimport \"./styles.css\";\n\nexport type MsTeamsAuthButtonProps = {\n redirectUrl?: string;\n onAuthenticationComplete?: (authenticationResp: string) => void;\n} & (\n | {\n /**\n * The client ID of your Microsoft Graph API-enabled application registered with Microsoft Entra. This should\n * match the \"Graph API client ID\" setting of your Microsoft Teams channel in the Knock dashboard.\n */\n graphApiClientId: string;\n }\n | {\n /**\n * @deprecated Use `graphApiClientId` instead. This field will be removed in a future release.\n */\n msTeamsBotId: string;\n }\n);\n\nexport const MsTeamsAuthButton: FunctionComponent<MsTeamsAuthButtonProps> = ({\n redirectUrl,\n onAuthenticationComplete,\n ...props\n}) => {\n const graphApiClientId =\n \"graphApiClientId\" in props ? props.graphApiClientId : props.msTeamsBotId;\n\n const { t } = useTranslations();\n const knock = useKnockClient();\n\n const {\n setConnectionStatus,\n connectionStatus,\n setActionLabel,\n actionLabel,\n errorLabel,\n tenantId,\n knockMsTeamsChannelId,\n popupWindowRef,\n } = useKnockMsTeamsClient();\n\n const { buildMsTeamsAuthUrl, disconnectFromMsTeams } = useMsTeamsAuth(\n graphApiClientId,\n redirectUrl,\n );\n\n useAuthPostMessageListener({\n knockHost: knock.host,\n popupWindowRef,\n setConnectionStatus,\n onAuthenticationComplete,\n });\n\n useAuthPolling({\n popupWindowRef,\n setConnectionStatus,\n onAuthenticationComplete,\n authCheckFn: useCallback(async () => {\n return knock.msTeams.authCheck({\n tenant: tenantId,\n knockChannelId: knockMsTeamsChannelId,\n });\n }, [knock.msTeams, tenantId, knockMsTeamsChannelId]),\n });\n\n const disconnectLabel = t(\"msTeamsDisconnect\") || null;\n const reconnectLabel = t(\"msTeamsReconnect\") || null;\n\n // Loading states\n if (\n connectionStatus === \"connecting\" ||\n connectionStatus === \"disconnecting\"\n ) {\n return (\n <div className=\"rtk-connect__button rtk-connect__button--loading\">\n <MsTeamsIcon height=\"16px\" width=\"16px\" />\n <span>\n {connectionStatus === \"connecting\"\n ? t(\"msTeamsConnecting\")\n : t(\"msTeamsDisconnecting\")}\n </span>\n </div>\n );\n }\n\n // Error state\n if (connectionStatus === \"error\") {\n return (\n <button\n onClick={() => {\n const popup = openPopupWindow(buildMsTeamsAuthUrl());\n popupWindowRef.current = popup;\n setConnectionStatus(\"connecting\");\n }}\n className=\"rtk-connect__button rtk-connect__button--error\"\n onMouseEnter={() => setActionLabel(reconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <MsTeamsIcon height=\"16px\" width=\"16px\" />\n <span className=\"rtk-connect__button__text--error\">\n {actionLabel || errorLabel || t(\"msTeamsError\")}\n </span>\n </button>\n );\n }\n\n // Disconnected state\n if (connectionStatus === \"disconnected\") {\n return (\n <button\n onClick={() => {\n const popup = openPopupWindow(buildMsTeamsAuthUrl());\n popupWindowRef.current = popup;\n setConnectionStatus(\"connecting\");\n }}\n className=\"rtk-connect__button rtk-connect__button--disconnected\"\n >\n <MsTeamsIcon height=\"16px\" width=\"16px\" />\n <span>{t(\"msTeamsConnect\")}</span>\n </button>\n );\n }\n\n // Connected state\n return (\n <button\n onClick={disconnectFromMsTeams}\n className=\"rtk-connect__button rtk-connect__button--connected\"\n onMouseEnter={() => setActionLabel(disconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <MsTeamsIcon height=\"16px\" width=\"16px\" />\n <span className=\"rtk-connect__button__text--connected\">\n {actionLabel || t(\"msTeamsConnected\")}\n </span>\n </button>\n );\n};\n"],"names":["MsTeamsAuthButton","redirectUrl","onAuthenticationComplete","props","graphApiClientId","msTeamsBotId","t","useTranslations","knock","useKnockClient","setConnectionStatus","connectionStatus","setActionLabel","actionLabel","errorLabel","tenantId","knockMsTeamsChannelId","popupWindowRef","useKnockMsTeamsClient","buildMsTeamsAuthUrl","disconnectFromMsTeams","useMsTeamsAuth","useAuthPostMessageListener","knockHost","host","useAuthPolling","authCheckFn","useCallback","msTeams","authCheck","tenant","knockChannelId","disconnectLabel","reconnectLabel","React","MsTeamsIcon","popup","openPopupWindow","current"],"mappings":"+VAmCaA,EAA+DA,CAAC,CAC3EC,YAAAA,EACAC,yBAAAA,EACA,GAAGC,CACL,IAAM,CACJ,MAAMC,EACJ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AM,MAAM,CAAA,EACtCD,EAAAA,QAAA,cAAA,OAAA,CAAK,UAAU,kCAAA,EACbrB,GAAeC,GAAcR,EAAE,cAAc,CAChD,CACF,EAKAK,IAAqB,eAErBuB,EAAA,QAAA,cAAC,SACC,CAAA,QAAS,IAAM,CACPE,MAAAA,EAAQC,kBAAgBlB,GAAqB,EACnDF,EAAeqB,QAAUF,EACzB1B,EAAoB,YAAY,CAAA,EAElC,UAAU,uDAEV,EAAAwB,EAAA,QAAA,cAACC,eAAY,OAAO,OAAO,MAAM,OAAM,EACtCD,EAAA,QAAA,cAAA,OAAA,KAAM5B,EAAE,gBAAgB,CAAE,CAC7B,EAMD4B,EAAAA,QAAA,cAAA,SAAA,CACC,QAASd,EACT,UAAU,qDACV,aAAc,IAAMR,EAAeoB,CAAe,EAClD,aAAc,IAAMpB,EAAe,IAAI,GAEvCsB,EAAAA,QAAA,cAACC,EAAAA,YAAY,CAAA,OAAO,OAAO,MAAM,MAAM,CAAA,EACvCD,EAAA,QAAA,cAAC,OAAK,CAAA,UAAU,sCACbrB,EAAAA,GAAeP,EAAE,kBAAkB,CACtC,CACF,CAEJ"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),s=require("@knocklabs/react-core"),h=require("../../../core/utils.js");;/* empty css */const l=require("../SlackIcon/SlackIcon.js");;/* empty css */const C=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},e=C(i),L=({slackClientId:t,redirectUrl:p,onAuthenticationComplete:u,scopes:d,additionalScopes:k})=>{const{t:n}=s.useTranslations(),f=s.useKnockClient(),{setConnectionStatus:o,connectionStatus:c,setActionLabel:a,actionLabel:_,errorLabel:E}=s.useKnockSlackClient(),g=i.useMemo(()=>({scopes:d,additionalScopes:k}),[d,k]),{buildSlackAuthUrl:m,disconnectFromSlack:S}=s.useSlackAuth(t,p,g);i.useEffect(()=>{const b=r=>{if(r.origin===f.host)try{r.data==="authComplete"&&o("connected"),r.data==="authFailed"&&o("error"),u&&u(r.data)}catch{o("error")}};return window.addEventListener("message",b,!1),()=>{window.removeEventListener("message",b)}},[f.host,u,o]);const w=n("slackDisconnect")||null,x=n("slackReconnect")||null;return c==="connecting"||c==="disconnecting"?e.default.createElement("div",{className:"rsk-connect__button rsk-connect__button--loading"},e.default.createElement(l.SlackIcon,{height:"16px",width:"16px"}),e.default.createElement("span",null,n(c==="connecting"?"slackConnecting":"slackDisconnecting"))):c==="error"?e.default.createElement("button",{onClick:()=>h.openPopupWindow(m()),className:"rsk-connect__button rsk-connect__button--error",onMouseEnter:()=>a(x),onMouseLeave:()=>a(null)},e.default.createElement(l.SlackIcon,{height:"16px",width:"16px"}),e.default.createElement("span",{className:"rsk-connect__button__text--error"},_||E||n("slackError"))):c==="disconnected"?e.default.createElement("button",{onClick:()=>h.openPopupWindow(m()),className:"rsk-connect__button rsk-connect__button--disconnected"},e.default.createElement(l.SlackIcon,{height:"16px",width:"16px"}),e.default.createElement("span",null,n("slackConnect"))):e.default.createElement("button",{onClick:S,className:"rsk-connect__button rsk-connect__button--connected",onMouseEnter:()=>a(w),onMouseLeave:()=>a(null)},e.default.createElement(l.SlackIcon,{height:"16px",width:"16px"}),e.default.createElement("span",{className:"rsk-connect__button__text--connected"},_||n("slackConnected")))};exports.SlackAuthButton=L;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("react"),c=require("@knocklabs/react-core"),g=require("../../../core/utils.js");;/* empty css */const u=require("../SlackIcon/SlackIcon.js");;/* empty css */const w=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},e=w(k),A=({slackClientId:t,redirectUrl:S,onAuthenticationComplete:d,scopes:p,additionalScopes:_})=>{const{t:n}=c.useTranslations(),r=c.useKnockClient(),{setConnectionStatus:a,connectionStatus:o,setActionLabel:l,actionLabel:h,errorLabel:C,tenantId:b,knockSlackChannelId:f,popupWindowRef:s}=c.useKnockSlackClient(),E=k.useMemo(()=>({scopes:p,additionalScopes:_}),[p,_]),{buildSlackAuthUrl:m,disconnectFromSlack:x}=c.useSlackAuth(t,S,E);c.useAuthPostMessageListener({knockHost:r.host,popupWindowRef:s,setConnectionStatus:a,onAuthenticationComplete:d}),c.useAuthPolling({popupWindowRef:s,setConnectionStatus:a,onAuthenticationComplete:d,authCheckFn:k.useCallback(async()=>r.slack.authCheck({tenant:b,knockChannelId:f}),[r.slack,b,f])});const I=n("slackDisconnect")||null,L=n("slackReconnect")||null;return o==="connecting"||o==="disconnecting"?e.default.createElement("div",{className:"rsk-connect__button rsk-connect__button--loading"},e.default.createElement(u.SlackIcon,{height:"16px",width:"16px"}),e.default.createElement("span",null,n(o==="connecting"?"slackConnecting":"slackDisconnecting"))):o==="error"?e.default.createElement("button",{onClick:()=>{const i=g.openPopupWindow(m());s.current=i,a("connecting")},className:"rsk-connect__button rsk-connect__button--error",onMouseEnter:()=>l(L),onMouseLeave:()=>l(null)},e.default.createElement(u.SlackIcon,{height:"16px",width:"16px"}),e.default.createElement("span",{className:"rsk-connect__button__text--error"},h||C||n("slackError"))):o==="disconnected"?e.default.createElement("button",{onClick:()=>{const i=g.openPopupWindow(m());s.current=i,a("connecting")},className:"rsk-connect__button rsk-connect__button--disconnected"},e.default.createElement(u.SlackIcon,{height:"16px",width:"16px"}),e.default.createElement("span",null,n("slackConnect"))):e.default.createElement("button",{onClick:x,className:"rsk-connect__button rsk-connect__button--connected",onMouseEnter:()=>l(I),onMouseLeave:()=>l(null)},e.default.createElement(u.SlackIcon,{height:"16px",width:"16px"}),e.default.createElement("span",{className:"rsk-connect__button__text--connected"},h||n("slackConnected")))};exports.SlackAuthButton=A;
2
2
  //# sourceMappingURL=SlackAuthButton.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SlackAuthButton.js","sources":["../../../../../../src/modules/slack/components/SlackAuthButton/SlackAuthButton.tsx"],"sourcesContent":["import {\n useKnockClient,\n useKnockSlackClient,\n useSlackAuth,\n useTranslations,\n} from \"@knocklabs/react-core\";\nimport { FunctionComponent, useMemo } from \"react\";\nimport { useEffect } from \"react\";\n\nimport { openPopupWindow } from \"../../../core/utils\";\nimport \"../../theme.css\";\nimport { SlackIcon } from \"../SlackIcon\";\n\nimport \"./styles.css\";\n\nexport interface SlackAuthButtonProps {\n slackClientId: string;\n redirectUrl?: string;\n onAuthenticationComplete?: (authenticationResp: string) => void;\n // When provided, the default scopes will be overridden with the provided scopes\n scopes?: string[];\n // Additional scopes to add to the default scopes\n additionalScopes?: string[];\n}\n\nexport const SlackAuthButton: FunctionComponent<SlackAuthButtonProps> = ({\n slackClientId,\n redirectUrl,\n onAuthenticationComplete,\n scopes,\n additionalScopes,\n}) => {\n const { t } = useTranslations();\n const knock = useKnockClient();\n\n const {\n setConnectionStatus,\n connectionStatus,\n setActionLabel,\n actionLabel,\n errorLabel,\n } = useKnockSlackClient();\n\n const useSlackAuthOptions = useMemo(\n () => ({\n scopes,\n additionalScopes,\n }),\n [scopes, additionalScopes],\n );\n\n const { buildSlackAuthUrl, disconnectFromSlack } = useSlackAuth(\n slackClientId,\n redirectUrl,\n useSlackAuthOptions,\n );\n\n useEffect(() => {\n const receiveMessage = (event: MessageEvent) => {\n if (event.origin !== knock.host) {\n return;\n }\n\n try {\n if (event.data === \"authComplete\") {\n setConnectionStatus(\"connected\");\n }\n\n if (event.data === \"authFailed\") {\n setConnectionStatus(\"error\");\n }\n\n if (onAuthenticationComplete) {\n onAuthenticationComplete(event.data);\n }\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n };\n\n window.addEventListener(\"message\", receiveMessage, false);\n\n // Cleanup the event listener when the component unmounts\n return () => {\n window.removeEventListener(\"message\", receiveMessage);\n };\n }, [knock.host, onAuthenticationComplete, setConnectionStatus]);\n\n const disconnectLabel = t(\"slackDisconnect\") || null;\n const reconnectLabel = t(\"slackReconnect\") || null;\n\n // Loading states\n if (\n connectionStatus === \"connecting\" ||\n connectionStatus === \"disconnecting\"\n ) {\n return (\n <div className=\"rsk-connect__button rsk-connect__button--loading\">\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span>\n {connectionStatus === \"connecting\"\n ? t(\"slackConnecting\")\n : t(\"slackDisconnecting\")}\n </span>\n </div>\n );\n }\n\n // Error state\n if (connectionStatus === \"error\") {\n return (\n <button\n onClick={() => openPopupWindow(buildSlackAuthUrl())}\n className=\"rsk-connect__button rsk-connect__button--error\"\n onMouseEnter={() => setActionLabel(reconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span className=\"rsk-connect__button__text--error\">\n {actionLabel || errorLabel || t(\"slackError\")}\n </span>\n </button>\n );\n }\n\n // Disconnected state\n if (connectionStatus === \"disconnected\") {\n return (\n <button\n onClick={() => openPopupWindow(buildSlackAuthUrl())}\n className=\"rsk-connect__button rsk-connect__button--disconnected\"\n >\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span>{t(\"slackConnect\")}</span>\n </button>\n );\n }\n\n // Connected state\n return (\n <button\n onClick={disconnectFromSlack}\n className=\"rsk-connect__button rsk-connect__button--connected\"\n onMouseEnter={() => setActionLabel(disconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span className=\"rsk-connect__button__text--connected\">\n {actionLabel || t(\"slackConnected\")}\n </span>\n </button>\n );\n};\n"],"names":["SlackAuthButton","slackClientId","redirectUrl","onAuthenticationComplete","scopes","additionalScopes","t","useTranslations","knock","useKnockClient","setConnectionStatus","connectionStatus","setActionLabel","actionLabel","errorLabel","useKnockSlackClient","useSlackAuthOptions","useMemo","buildSlackAuthUrl","disconnectFromSlack","useSlackAuth","useEffect","receiveMessage","event","origin","host","data","addEventListener","removeEventListener","disconnectLabel","reconnectLabel","React","SlackIcon","openPopupWindow"],"mappings":"2VAyBaA,EAA2DA,CAAC,CACvEC,cAAAA,EACAC,YAAAA,EACAC,yBAAAA,EACAC,OAAAA,EACAC,iBAAAA,CACF,IAAM,CACE,KAAA,CAAEC,EA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U,CAAA,OAAO,OAAO,MAAM,OAAM,EACrCD,UAAA,cAAC,OAAK,CAAA,UAAU,oCACblB,GAAeC,GAAcR,EAAE,YAAY,CAC9C,CACF,EAKAK,IAAqB,eAErBoB,EAAA,QAAA,cAAC,UACC,QAAS,IAAME,EAAAA,gBAAgBf,EAAkB,CAAC,EAClD,UAAU,uDAEV,EAAAa,EAAA,QAAA,cAACC,aAAU,OAAO,OAAO,MAAM,MAAM,CAAA,0BACpC,OAAM1B,KAAAA,EAAE,cAAc,CAAE,CAC3B,EAMDyB,EAAAA,QAAA,cAAA,SAAA,CACC,QAASZ,EACT,UAAU,qDACV,aAAc,IAAMP,EAAeiB,CAAe,EAClD,aAAc,IAAMjB,EAAe,IAAI,GAEvCmB,EAAAA,QAAA,cAACC,EAAAA,UAAU,CAAA,OAAO,OAAO,MAAM,MAAM,CAAA,EACrCD,EAAA,QAAA,cAAC,OAAK,CAAA,UAAU,sCACblB,EAAAA,GAAeP,EAAE,gBAAgB,CACpC,CACF,CAEJ"}
1
+ {"version":3,"file":"SlackAuthButton.js","sources":["../../../../../../src/modules/slack/components/SlackAuthButton/SlackAuthButton.tsx"],"sourcesContent":["import {\n useAuthPolling,\n useAuthPostMessageListener,\n useKnockClient,\n useKnockSlackClient,\n useSlackAuth,\n useTranslations,\n} from \"@knocklabs/react-core\";\nimport { FunctionComponent, useCallback, useMemo } from \"react\";\n\nimport { openPopupWindow } from \"../../../core/utils\";\nimport \"../../theme.css\";\nimport { SlackIcon } from \"../SlackIcon\";\n\nimport \"./styles.css\";\n\nexport interface SlackAuthButtonProps {\n slackClientId: string;\n redirectUrl?: string;\n onAuthenticationComplete?: (authenticationResp: string) => void;\n // When provided, the default scopes will be overridden with the provided scopes\n scopes?: string[];\n // Additional scopes to add to the default scopes\n additionalScopes?: string[];\n}\n\nexport const SlackAuthButton: FunctionComponent<SlackAuthButtonProps> = ({\n slackClientId,\n redirectUrl,\n onAuthenticationComplete,\n scopes,\n additionalScopes,\n}) => {\n const { t } = useTranslations();\n const knock = useKnockClient();\n\n const {\n setConnectionStatus,\n connectionStatus,\n setActionLabel,\n actionLabel,\n errorLabel,\n tenantId,\n knockSlackChannelId,\n popupWindowRef,\n } = useKnockSlackClient();\n\n const useSlackAuthOptions = useMemo(\n () => ({\n scopes,\n additionalScopes,\n }),\n [scopes, additionalScopes],\n );\n\n const { buildSlackAuthUrl, disconnectFromSlack } = useSlackAuth(\n slackClientId,\n redirectUrl,\n useSlackAuthOptions,\n );\n\n useAuthPostMessageListener({\n knockHost: knock.host,\n popupWindowRef,\n setConnectionStatus,\n onAuthenticationComplete,\n });\n\n useAuthPolling({\n popupWindowRef,\n setConnectionStatus,\n onAuthenticationComplete,\n authCheckFn: useCallback(async () => {\n return knock.slack.authCheck({\n tenant: tenantId,\n knockChannelId: knockSlackChannelId,\n });\n }, [knock.slack, tenantId, knockSlackChannelId]),\n });\n\n const disconnectLabel = t(\"slackDisconnect\") || null;\n const reconnectLabel = t(\"slackReconnect\") || null;\n\n // Loading states\n if (\n connectionStatus === \"connecting\" ||\n connectionStatus === \"disconnecting\"\n ) {\n return (\n <div className=\"rsk-connect__button rsk-connect__button--loading\">\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span>\n {connectionStatus === \"connecting\"\n ? t(\"slackConnecting\")\n : t(\"slackDisconnecting\")}\n </span>\n </div>\n );\n }\n\n // Error state\n if (connectionStatus === \"error\") {\n return (\n <button\n onClick={() => {\n const popup = openPopupWindow(buildSlackAuthUrl());\n popupWindowRef.current = popup;\n setConnectionStatus(\"connecting\");\n }}\n className=\"rsk-connect__button rsk-connect__button--error\"\n onMouseEnter={() => setActionLabel(reconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span className=\"rsk-connect__button__text--error\">\n {actionLabel || errorLabel || t(\"slackError\")}\n </span>\n </button>\n );\n }\n\n // Disconnected state\n if (connectionStatus === \"disconnected\") {\n return (\n <button\n onClick={() => {\n const popup = openPopupWindow(buildSlackAuthUrl());\n popupWindowRef.current = popup;\n setConnectionStatus(\"connecting\");\n }}\n className=\"rsk-connect__button rsk-connect__button--disconnected\"\n >\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span>{t(\"slackConnect\")}</span>\n </button>\n );\n }\n\n // Connected state\n return (\n <button\n onClick={disconnectFromSlack}\n className=\"rsk-connect__button rsk-connect__button--connected\"\n onMouseEnter={() => setActionLabel(disconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span className=\"rsk-connect__button__text--connected\">\n {actionLabel || t(\"slackConnected\")}\n </span>\n </button>\n );\n};\n"],"names":["SlackAuthButton","slackClientId","redirectUrl","onAuthenticationComplete","scopes","additionalScopes","t","useTranslations","knock","useKnockClient","setConnectionStatus","connectionStatus","setActionLabel","actionLabel","errorLabel","tenantId","knockSlackChannelId","popupWindowRef","useKnockSlackClient","useSlackAuthOptions","useMemo","buildSlackAuthUrl","disconnectFromSlack","useSlackAuth","useAuthPostMessageListener","knockHost","host","useAuthPolling","authCheckFn","useCallback","slack","authCheck","tenant","knockChannelId","disconnectLabel","reconnectLabel","React","SlackIcon","popup","openPopupWindow","current"],"mappings":"2VA0BaA,EAA2DA,CAAC,CACvEC,cAAAA,EACAC,YAAAA,EACAC,yBAAAA,EACAC,OAAAA,EACAC,iBAAAA,CACF,IAAM,CACE,KAAA,CAAEC,EAAAA,GAAMC,kBAAgB,EACxBC,EAAQC,EAAAA,eAAe,EAEvB,CACJC,oBAAAA,EACAC,iBAAAA,EACAC,eAAAA,EACAC,YAAAA,EACAC,WAAAA,EACAC,SAAAA,EACAC,oBAAAA,EACAC,eAAAA,GACEC,sBAAoB,EAElBC,EAAsBC,EAAAA,QAC1B,KAAO,CACLhB,OAAAA,EACAC,iBAAAA,CAAAA,GAEF,CAACD,EAAQC,CAAgB,CAC3B,EAEM,CAAEgB,kBAAAA,EAAmBC,oBAAAA,CAAwBC,EAAAA,eACjDt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AA,QAAA,cAACC,aAAU,OAAO,OAAO,MAAM,OAAM,EACpCD,EAAA,QAAA,cAAA,OAAA,KAAM9B,EAAE,cAAc,CAAE,CAC3B,EAMD8B,EAAAA,QAAA,cAAA,SAAA,CACC,QAASd,EACT,UAAU,qDACV,aAAc,IAAMV,EAAesB,CAAe,EAClD,aAAc,IAAMtB,EAAe,IAAI,GAEvCwB,EAAAA,QAAA,cAACC,EAAAA,UAAU,CAAA,OAAO,OAAO,MAAM,MAAM,CAAA,EACrCD,EAAA,QAAA,cAAC,OAAK,CAAA,UAAU,sCACbvB,EAAAA,GAAeP,EAAE,gBAAgB,CACpC,CACF,CAEJ"}
@@ -1,6 +1,6 @@
1
1
  const r = (e) => {
2
2
  const n = window.screenLeft ?? window.screenX, t = window.screenTop ?? window.screenY, o = window.innerWidth ?? document.documentElement.clientWidth ?? screen.width, i = window.innerHeight ?? document.documentElement.clientHeight ?? screen.height, c = o / 2 - 600 / 2 + n, d = `width=600,height=800,top=${i / 2 - 800 / 2 + t},left=${c}`;
3
- window.open(e, "_blank", d);
3
+ return window.open(e, "_blank", d);
4
4
  }, p = () => {
5
5
  if (typeof window < "u")
6
6
  return window;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["export const openPopupWindow = (url: string) => {\n const width = 600;\n const height = 800;\n // Calculate the position to center the window\n const screenLeft = window.screenLeft ?? window.screenX;\n const screenTop = window.screenTop ?? window.screenY;\n\n const innerWidth =\n window.innerWidth ?? document.documentElement.clientWidth ?? screen.width;\n const innerHeight =\n window.innerHeight ??\n document.documentElement.clientHeight ??\n screen.height;\n\n const left = innerWidth / 2 - width / 2 + screenLeft;\n const top = innerHeight / 2 - height / 2 + screenTop;\n\n // Window features\n const features = `width=${width},height=${height},top=${top},left=${left}`;\n\n window.open(url, \"_blank\", features);\n};\n\nexport const checkForWindow = () => {\n if (typeof window !== \"undefined\") {\n return window;\n }\n};\n"],"names":["openPopupWindow","url","screenLeft","window","screenX","screenTop","screenY","innerWidth","document","documentElement","clientWidth","screen","width","innerHeight","clientHeight","height","left","features","open","checkForWindow"],"mappings":"AAAaA,MAAAA,IAAkBA,CAACC,MAAgB;AAIxCC,QAAAA,IAAaC,OAAOD,cAAcC,OAAOC,SACzCC,IAAYF,OAAOE,aAAaF,OAAOG,SAEvCC,IACJJ,OAAOI,cAAcC,SAASC,gBAAgBC,eAAeC,OAAOC,OAChEC,IACJV,OAAOU,eACPL,SAASC,gBAAgBK,gBACzBH,OAAOI,QAEHC,IAAOT,IAAa,IAAIK,MAAQ,IAAIV,GAIpCe,IAAW,4BAHLJ,IAAc,IAAIE,MAAS,IAAIV,CAGgB,SAASW,CAAI;AAEjEE,SAAAA,KAAKjB,GAAK,UAAUgB,CAAQ;AACrC,GAEaE,IAAiBA,MAAM;AAC9B,MAAA,OAAOhB,SAAW;AACbA,WAAAA;AAEX;"}
1
+ {"version":3,"file":"utils.mjs","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["export const openPopupWindow = (url: string) => {\n const width = 600;\n const height = 800;\n // Calculate the position to center the window\n const screenLeft = window.screenLeft ?? window.screenX;\n const screenTop = window.screenTop ?? window.screenY;\n\n const innerWidth =\n window.innerWidth ?? document.documentElement.clientWidth ?? screen.width;\n const innerHeight =\n window.innerHeight ??\n document.documentElement.clientHeight ??\n screen.height;\n\n const left = innerWidth / 2 - width / 2 + screenLeft;\n const top = innerHeight / 2 - height / 2 + screenTop;\n\n // Window features\n const features = `width=${width},height=${height},top=${top},left=${left}`;\n\n return window.open(url, \"_blank\", features);\n};\n\nexport const checkForWindow = () => {\n if (typeof window !== \"undefined\") {\n return window;\n }\n};\n"],"names":["openPopupWindow","url","screenLeft","window","screenX","screenTop","screenY","innerWidth","document","documentElement","clientWidth","screen","width","innerHeight","clientHeight","height","left","features","open","checkForWindow"],"mappings":"AAAaA,MAAAA,IAAkBA,CAACC,MAAgB;AAIxCC,QAAAA,IAAaC,OAAOD,cAAcC,OAAOC,SACzCC,IAAYF,OAAOE,aAAaF,OAAOG,SAEvCC,IACJJ,OAAOI,cAAcC,SAASC,gBAAgBC,eAAeC,OAAOC,OAChEC,IACJV,OAAOU,eACPL,SAASC,gBAAgBK,gBACzBH,OAAOI,QAEHC,IAAOT,IAAa,IAAIK,MAAQ,IAAIV,GAIpCe,IAAW,4BAHLJ,IAAc,IAAIE,MAAS,IAAIV,CAGgB,SAASW,CAAI;AAExE,SAAOb,OAAOe,KAAKjB,GAAK,UAAUgB,CAAQ;AAC5C,GAEaE,IAAiBA,MAAM;AAC9B,MAAA,OAAOhB,SAAW;AACbA,WAAAA;AAEX;"}
@@ -1,43 +1,53 @@
1
- import e, { useEffect as T } from "react";
2
- import { useTranslations as f, useKnockClient as x, useKnockMsTeamsClient as M, useMsTeamsAuth as w } from "@knocklabs/react-core";
3
- import { openPopupWindow as _ } from "../../../core/utils.mjs";
1
+ import e, { useCallback as M } from "react";
2
+ import { useTranslations as x, useKnockClient as f, useKnockMsTeamsClient as A, useMsTeamsAuth as I, useAuthPostMessageListener as L, useAuthPolling as w } from "@knocklabs/react-core";
3
+ import { openPopupWindow as k } from "../../../core/utils.mjs";
4
4
  /* empty css */
5
5
  import { MsTeamsIcon as a } from "../MsTeamsIcon/MsTeamsIcon.mjs";
6
6
  /* empty css */
7
- const D = ({
8
- redirectUrl: p,
9
- onAuthenticationComplete: c,
10
- ...i
7
+ const F = ({
8
+ redirectUrl: _,
9
+ onAuthenticationComplete: l,
10
+ ...r
11
11
  }) => {
12
- const b = "graphApiClientId" in i ? i.graphApiClientId : i.msTeamsBotId, {
13
- t
14
- } = f(), m = x(), {
15
- setConnectionStatus: o,
16
- connectionStatus: n,
17
- setActionLabel: s,
18
- actionLabel: l,
19
- errorLabel: h
20
- } = M(), {
21
- buildMsTeamsAuthUrl: u,
22
- disconnectFromMsTeams: E
23
- } = w(b, p);
24
- T(() => {
25
- const d = (r) => {
26
- if (r.origin === m.host)
27
- try {
28
- r.data === "authComplete" && o("connected"), r.data === "authFailed" && o("error"), c == null || c(r.data);
29
- } catch {
30
- o("error");
31
- }
32
- };
33
- return window.addEventListener("message", d, !1), () => {
34
- window.removeEventListener("message", d);
35
- };
36
- }, [m.host, c, o]);
37
- const g = t("msTeamsDisconnect") || null, k = t("msTeamsReconnect") || null;
38
- return n === "connecting" || n === "disconnecting" ? /* @__PURE__ */ e.createElement("div", { className: "rtk-connect__button rtk-connect__button--loading" }, /* @__PURE__ */ e.createElement(a, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", null, t(n === "connecting" ? "msTeamsConnecting" : "msTeamsDisconnecting"))) : n === "error" ? /* @__PURE__ */ e.createElement("button", { onClick: () => _(u()), className: "rtk-connect__button rtk-connect__button--error", onMouseEnter: () => s(k), onMouseLeave: () => s(null) }, /* @__PURE__ */ e.createElement(a, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", { className: "rtk-connect__button__text--error" }, l || h || t("msTeamsError"))) : n === "disconnected" ? /* @__PURE__ */ e.createElement("button", { onClick: () => _(u()), className: "rtk-connect__button rtk-connect__button--disconnected" }, /* @__PURE__ */ e.createElement(a, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", null, t("msTeamsConnect"))) : /* @__PURE__ */ e.createElement("button", { onClick: E, className: "rtk-connect__button rtk-connect__button--connected", onMouseEnter: () => s(g), onMouseLeave: () => s(null) }, /* @__PURE__ */ e.createElement(a, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", { className: "rtk-connect__button__text--connected" }, l || t("msTeamsConnected")));
12
+ const b = "graphApiClientId" in r ? r.graphApiClientId : r.msTeamsBotId, {
13
+ t: n
14
+ } = x(), m = f(), {
15
+ setConnectionStatus: c,
16
+ connectionStatus: t,
17
+ setActionLabel: o,
18
+ actionLabel: u,
19
+ errorLabel: T,
20
+ tenantId: p,
21
+ knockMsTeamsChannelId: d,
22
+ popupWindowRef: s
23
+ } = A(), {
24
+ buildMsTeamsAuthUrl: h,
25
+ disconnectFromMsTeams: g
26
+ } = I(b, _);
27
+ L({
28
+ knockHost: m.host,
29
+ popupWindowRef: s,
30
+ setConnectionStatus: c,
31
+ onAuthenticationComplete: l
32
+ }), w({
33
+ popupWindowRef: s,
34
+ setConnectionStatus: c,
35
+ onAuthenticationComplete: l,
36
+ authCheckFn: M(async () => m.msTeams.authCheck({
37
+ tenant: p,
38
+ knockChannelId: d
39
+ }), [m.msTeams, p, d])
40
+ });
41
+ const C = n("msTeamsDisconnect") || null, E = n("msTeamsReconnect") || null;
42
+ return t === "connecting" || t === "disconnecting" ? /* @__PURE__ */ e.createElement("div", { className: "rtk-connect__button rtk-connect__button--loading" }, /* @__PURE__ */ e.createElement(a, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", null, n(t === "connecting" ? "msTeamsConnecting" : "msTeamsDisconnecting"))) : t === "error" ? /* @__PURE__ */ e.createElement("button", { onClick: () => {
43
+ const i = k(h());
44
+ s.current = i, c("connecting");
45
+ }, className: "rtk-connect__button rtk-connect__button--error", onMouseEnter: () => o(E), onMouseLeave: () => o(null) }, /* @__PURE__ */ e.createElement(a, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", { className: "rtk-connect__button__text--error" }, u || T || n("msTeamsError"))) : t === "disconnected" ? /* @__PURE__ */ e.createElement("button", { onClick: () => {
46
+ const i = k(h());
47
+ s.current = i, c("connecting");
48
+ }, className: "rtk-connect__button rtk-connect__button--disconnected" }, /* @__PURE__ */ e.createElement(a, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", null, n("msTeamsConnect"))) : /* @__PURE__ */ e.createElement("button", { onClick: g, className: "rtk-connect__button rtk-connect__button--connected", onMouseEnter: () => o(C), onMouseLeave: () => o(null) }, /* @__PURE__ */ e.createElement(a, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", { className: "rtk-connect__button__text--connected" }, u || n("msTeamsConnected")));
39
49
  };
40
50
  export {
41
- D as MsTeamsAuthButton
51
+ F as MsTeamsAuthButton
42
52
  };
43
53
  //# sourceMappingURL=MsTeamsAuthButton.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"MsTeamsAuthButton.mjs","sources":["../../../../../../src/modules/ms-teams/components/MsTeamsAuthButton/MsTeamsAuthButton.tsx"],"sourcesContent":["import {\n useKnockClient,\n useKnockMsTeamsClient,\n useMsTeamsAuth,\n useTranslations,\n} from \"@knocklabs/react-core\";\nimport { FunctionComponent, useEffect } from \"react\";\n\nimport { openPopupWindow } from \"../../../core/utils\";\nimport \"../../theme.css\";\nimport { MsTeamsIcon } from \"../MsTeamsIcon\";\n\nimport \"./styles.css\";\n\nexport type MsTeamsAuthButtonProps = {\n redirectUrl?: string;\n onAuthenticationComplete?: (authenticationResp: string) => void;\n} & (\n | {\n /**\n * The client ID of your Microsoft Graph API-enabled application registered with Microsoft Entra. This should\n * match the \"Graph API client ID\" setting of your Microsoft Teams channel in the Knock dashboard.\n */\n graphApiClientId: string;\n }\n | {\n /**\n * @deprecated Use `graphApiClientId` instead. This field will be removed in a future release.\n */\n msTeamsBotId: string;\n }\n);\n\nexport const MsTeamsAuthButton: FunctionComponent<MsTeamsAuthButtonProps> = ({\n redirectUrl,\n onAuthenticationComplete,\n ...props\n}) => {\n const graphApiClientId =\n \"graphApiClientId\" in props ? props.graphApiClientId : props.msTeamsBotId;\n\n const { t } = useTranslations();\n const knock = useKnockClient();\n\n const {\n setConnectionStatus,\n connectionStatus,\n setActionLabel,\n actionLabel,\n errorLabel,\n } = useKnockMsTeamsClient();\n\n const { buildMsTeamsAuthUrl, disconnectFromMsTeams } = useMsTeamsAuth(\n graphApiClientId,\n redirectUrl,\n );\n\n useEffect(() => {\n const receiveMessage = (event: MessageEvent) => {\n if (event.origin !== knock.host) {\n return;\n }\n\n try {\n if (event.data === \"authComplete\") {\n setConnectionStatus(\"connected\");\n }\n\n if (event.data === \"authFailed\") {\n setConnectionStatus(\"error\");\n }\n\n onAuthenticationComplete?.(event.data);\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n };\n\n window.addEventListener(\"message\", receiveMessage, false);\n\n // Cleanup the event listener when the component unmounts\n return () => {\n window.removeEventListener(\"message\", receiveMessage);\n };\n }, [knock.host, onAuthenticationComplete, setConnectionStatus]);\n\n const disconnectLabel = t(\"msTeamsDisconnect\") || null;\n const reconnectLabel = t(\"msTeamsReconnect\") || null;\n\n // Loading states\n if (\n connectionStatus === \"connecting\" ||\n connectionStatus === \"disconnecting\"\n ) {\n return (\n <div className=\"rtk-connect__button rtk-connect__button--loading\">\n <MsTeamsIcon height=\"16px\" width=\"16px\" />\n <span>\n {connectionStatus === \"connecting\"\n ? t(\"msTeamsConnecting\")\n : t(\"msTeamsDisconnecting\")}\n </span>\n </div>\n );\n }\n\n // Error state\n if (connectionStatus === \"error\") {\n return (\n <button\n onClick={() => openPopupWindow(buildMsTeamsAuthUrl())}\n className=\"rtk-connect__button rtk-connect__button--error\"\n onMouseEnter={() => setActionLabel(reconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <MsTeamsIcon height=\"16px\" width=\"16px\" />\n <span className=\"rtk-connect__button__text--error\">\n {actionLabel || errorLabel || t(\"msTeamsError\")}\n </span>\n </button>\n );\n }\n\n // Disconnected state\n if (connectionStatus === \"disconnected\") {\n return (\n <button\n onClick={() => openPopupWindow(buildMsTeamsAuthUrl())}\n className=\"rtk-connect__button rtk-connect__button--disconnected\"\n >\n <MsTeamsIcon height=\"16px\" width=\"16px\" />\n <span>{t(\"msTeamsConnect\")}</span>\n </button>\n );\n }\n\n // Connected state\n return (\n <button\n onClick={disconnectFromMsTeams}\n className=\"rtk-connect__button rtk-connect__button--connected\"\n onMouseEnter={() => setActionLabel(disconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <MsTeamsIcon height=\"16px\" width=\"16px\" />\n <span className=\"rtk-connect__button__text--connected\">\n {actionLabel || t(\"msTeamsConnected\")}\n </span>\n </button>\n );\n};\n"],"names":["MsTeamsAuthButton","redirectUrl","onAuthenticationComplete","props","graphApiClientId","msTeamsBotId","t","useTranslations","knock","useKnockClient","setConnectionStatus","connectionStatus","setActionLabel","actionLabel","errorLabel","useKnockMsTeamsClient","buildMsTeamsAuthUrl","disconnectFromMsTeams","useMsTeamsAuth","useEffect","receiveMessage","event","origin","host","data","addEventListener","removeEventListener","disconnectLabel","reconnectLabel","React","MsTeamsIcon","openPopupWindow"],"mappings":";;;;;;AAiCO,MAAMA,IAA+DA,CAAC;AAAA,EAC3EC,aAAAA;AAAAA,EACAC,0BAAAA;AAAAA,EACA,GAAGC;AACL,MAAM;AACJ,QAAMC,IACJ,sBAAsBD,IAAQA,EAAMC,mBAAmBD,EAAME,cAEzD;AAAA,IAAEC;AAAAA,MAAMC,EAAgB,GACxBC,IAAQC,EAAe,GAEvB;AAAA,IACJC,qBAAAA;AAAAA,IACAC,kBAAAA;AAAAA,IACAC,gBAAAA;AAAAA,IACAC,aAAAA;AAAAA,IACAC,YAAAA;AAAAA,MACEC,EAAsB,GAEpB;AAAA,IAAEC,qBAAAA;AAAAA,IAAqBC,uBAAAA;AAAAA,EAAAA,IAA0BC,EACrDd,GACAH,CACF;AAEAkB,EAAAA,EAAU,MAAM;AACRC,UAAAA,IAAiBA,CAACC,MAAwB;AAC1CA,UAAAA,EAAMC,WAAWd,EAAMe;AAIvB,YAAA;AACEF,UAAAA,EAAMG,SAAS,kBACjBd,EAAoB,WAAW,GAG7BW,EAAMG,SAAS,gBACjBd,EAAoB,OAAO,GAG7BR,KAAAA,QAAAA,EAA2BmB,EAAMG;AAAAA,gBAClB;AACfd,UAAAA,EAAoB,OAAO;AAAA,QAAA;AAAA,IAE/B;AAEOe,kBAAAA,iBAAiB,WAAWL,GAAgB,EAAK,GAGjD,MAAM;AACJM,aAAAA,oBAAoB,WAAWN,CAAc;AAAA,IACtD;AAAA,KACC,CAACZ,EAAMe,MAAMrB,GAA0BQ,CAAmB,CAAC;AAExDiB,QAAAA,IAAkBrB,EAAE,mBAAmB,KAAK,MAC5CsB,IAAiBtB,EAAE,kBAAkB,KAAK;AAI9CK,SAAAA,MAAqB,gBACrBA,MAAqB,kBAGnBkB,gBAAAA,EAAA,cAAC,SAAI,WAAU,mDAAA,mCACZC,GAAY,EAAA,QAAO,QAAO,OAAM,OAAM,CAAA,GACtCD,gBAAAA,EAAA,cAAA,QAAA,MAEKvB,EADHK,MAAqB,eAChB,sBACA,sBADmB,CAE3B,CACF,IAKAA,MAAqB,0CAEpB,UACC,EAAA,SAAS,MAAMoB,EAAgBf,GAAqB,GACpD,WAAU,kDACV,cAAc,MAAMJ,EAAegB,CAAc,GACjD,cAAc,MAAMhB,EAAe,IAAI,EAAA,mCAEtCkB,GAAY,EAAA,QAAO,QAAO,OAAM,QAAM,GACvCD,gBAAAA,EAAA,cAAC,QAAK,EAAA,WAAU,sCACbhB,KAAeC,KAAcR,EAAE,cAAc,CAChD,CACF,IAKAK,MAAqB,iBAErBkB,gBAAAA,EAAA,cAAC,YACC,SAAS,MAAME,EAAgBf,EAAoB,CAAC,GACpD,WAAU,wDAEV,GAAAa,gBAAAA,EAAA,cAACC,KAAY,QAAO,QAAO,OAAM,OAAM,CAAA,mCACtC,QAAMxB,MAAAA,EAAE,gBAAgB,CAAE,CAC7B,IAMDuB,gBAAAA,EAAA,cAAA,UAAA,EACC,SAASZ,GACT,WAAU,sDACV,cAAc,MAAML,EAAee,CAAe,GAClD,cAAc,MAAMf,EAAe,IAAI,KAEvCiB,gBAAAA,EAAA,cAACC,GAAY,EAAA,QAAO,QAAO,OAAM,OAAM,CAAA,GACvCD,gBAAAA,EAAA,cAAC,QAAK,EAAA,WAAU,uCACbhB,GAAAA,KAAeP,EAAE,kBAAkB,CACtC,CACF;AAEJ;"}
1
+ {"version":3,"file":"MsTeamsAuthButton.mjs","sources":["../../../../../../src/modules/ms-teams/components/MsTeamsAuthButton/MsTeamsAuthButton.tsx"],"sourcesContent":["import {\n useAuthPolling,\n useAuthPostMessageListener,\n useKnockClient,\n useKnockMsTeamsClient,\n useMsTeamsAuth,\n useTranslations,\n} from \"@knocklabs/react-core\";\nimport { FunctionComponent, useCallback } from \"react\";\n\nimport { openPopupWindow } from \"../../../core/utils\";\nimport \"../../theme.css\";\nimport { MsTeamsIcon } from \"../MsTeamsIcon\";\n\nimport \"./styles.css\";\n\nexport type MsTeamsAuthButtonProps = {\n redirectUrl?: string;\n onAuthenticationComplete?: (authenticationResp: string) => void;\n} & (\n | {\n /**\n * The client ID of your Microsoft Graph API-enabled application registered with Microsoft Entra. This should\n * match the \"Graph API client ID\" setting of your Microsoft Teams channel in the Knock dashboard.\n */\n graphApiClientId: string;\n }\n | {\n /**\n * @deprecated Use `graphApiClientId` instead. This field will be removed in a future release.\n */\n msTeamsBotId: string;\n }\n);\n\nexport const MsTeamsAuthButton: FunctionComponent<MsTeamsAuthButtonProps> = ({\n redirectUrl,\n onAuthenticationComplete,\n ...props\n}) => {\n const graphApiClientId =\n \"graphApiClientId\" in props ? props.graphApiClientId : props.msTeamsBotId;\n\n const { t } = useTranslations();\n const knock = useKnockClient();\n\n const {\n setConnectionStatus,\n connectionStatus,\n setActionLabel,\n actionLabel,\n errorLabel,\n tenantId,\n knockMsTeamsChannelId,\n popupWindowRef,\n } = useKnockMsTeamsClient();\n\n const { buildMsTeamsAuthUrl, disconnectFromMsTeams } = useMsTeamsAuth(\n graphApiClientId,\n redirectUrl,\n );\n\n useAuthPostMessageListener({\n knockHost: knock.host,\n popupWindowRef,\n setConnectionStatus,\n onAuthenticationComplete,\n });\n\n useAuthPolling({\n popupWindowRef,\n setConnectionStatus,\n onAuthenticationComplete,\n authCheckFn: useCallback(async () => {\n return knock.msTeams.authCheck({\n tenant: tenantId,\n knockChannelId: knockMsTeamsChannelId,\n });\n }, [knock.msTeams, tenantId, knockMsTeamsChannelId]),\n });\n\n const disconnectLabel = t(\"msTeamsDisconnect\") || null;\n const reconnectLabel = t(\"msTeamsReconnect\") || null;\n\n // Loading states\n if (\n connectionStatus === \"connecting\" ||\n connectionStatus === \"disconnecting\"\n ) {\n return (\n <div className=\"rtk-connect__button rtk-connect__button--loading\">\n <MsTeamsIcon height=\"16px\" width=\"16px\" />\n <span>\n {connectionStatus === \"connecting\"\n ? t(\"msTeamsConnecting\")\n : t(\"msTeamsDisconnecting\")}\n </span>\n </div>\n );\n }\n\n // Error state\n if (connectionStatus === \"error\") {\n return (\n <button\n onClick={() => {\n const popup = openPopupWindow(buildMsTeamsAuthUrl());\n popupWindowRef.current = popup;\n setConnectionStatus(\"connecting\");\n }}\n className=\"rtk-connect__button rtk-connect__button--error\"\n onMouseEnter={() => setActionLabel(reconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <MsTeamsIcon height=\"16px\" width=\"16px\" />\n <span className=\"rtk-connect__button__text--error\">\n {actionLabel || errorLabel || t(\"msTeamsError\")}\n </span>\n </button>\n );\n }\n\n // Disconnected state\n if (connectionStatus === \"disconnected\") {\n return (\n <button\n onClick={() => {\n const popup = openPopupWindow(buildMsTeamsAuthUrl());\n popupWindowRef.current = popup;\n setConnectionStatus(\"connecting\");\n }}\n className=\"rtk-connect__button rtk-connect__button--disconnected\"\n >\n <MsTeamsIcon height=\"16px\" width=\"16px\" />\n <span>{t(\"msTeamsConnect\")}</span>\n </button>\n );\n }\n\n // Connected state\n return (\n <button\n onClick={disconnectFromMsTeams}\n className=\"rtk-connect__button rtk-connect__button--connected\"\n onMouseEnter={() => setActionLabel(disconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <MsTeamsIcon height=\"16px\" width=\"16px\" />\n <span className=\"rtk-connect__button__text--connected\">\n {actionLabel || t(\"msTeamsConnected\")}\n </span>\n </button>\n );\n};\n"],"names":["MsTeamsAuthButton","redirectUrl","onAuthenticationComplete","props","graphApiClientId","msTeamsBotId","t","useTranslations","knock","useKnockClient","setConnectionStatus","connectionStatus","setActionLabel","actionLabel","errorLabel","tenantId","knockMsTeamsChannelId","popupWindowRef","useKnockMsTeamsClient","buildMsTeamsAuthUrl","disconnectFromMsTeams","useMsTeamsAuth","useAuthPostMessageListener","knockHost","host","useAuthPolling","authCheckFn","useCallback","msTeams","authCheck","tenant","knockChannelId","disconnectLabel","reconnectLabel","React","MsTeamsIcon","popup","openPopupWindow","current"],"mappings":";;;;;;AAmCO,MAAMA,IAA+DA,CAAC;AAAA,EAC3EC,aAAAA;AAAAA,EACAC,0BAAAA;AAAAA,EACA,GAAGC;AACL,MAAM;AACJ,QAAMC,IACJ,sBAAsBD,IAAQA,EAAMC,mBAAmBD,EAAME,cAEzD;AAAA,IAAEC,GAAAA;AAAAA,MAAMC,EAAgB,GACxBC,IAAQC,EAAe,GAEvB;AAAA,IACJC,qBAAAA;AAAAA,IACAC,kBAAAA;AAAAA,IACAC,gBAAAA;AAAAA,IACAC,aAAAA;AAAAA,IACAC,YAAAA;AAAAA,IACAC,UAAAA;AAAAA,IACAC,uBAAAA;AAAAA,IACAC,gBAAAA;AAAAA,MACEC,EAAsB,GAEpB;AAAA,IAAEC,qBAAAA;AAAAA,IAAqBC,uBAAAA;AAAAA,EAAAA,IAA0BC,EACrDjB,GACAH,CACF;AAE2B,EAAAqB,EAAA;AAAA,IACzBC,WAAWf,EAAMgB;AAAAA,IACjBP,gBAAAA;AAAAA,IACAP,qBAAAA;AAAAA,IACAR,0BAAAA;AAAAA,EAAAA,CACD,GAEcuB,EAAA;AAAA,IACbR,gBAAAA;AAAAA,IACAP,qBAAAA;AAAAA,IACAR,0BAAAA;AAAAA,IACAwB,aAAaC,EAAY,YAChBnB,EAAMoB,QAAQC,UAAU;AAAA,MAC7BC,QAAQf;AAAAA,MACRgB,gBAAgBf;AAAAA,IAAAA,CACjB,GACA,CAACR,EAAMoB,SAASb,GAAUC,CAAqB,CAAC;AAAA,EAAA,CACpD;AAEKgB,QAAAA,IAAkB1B,EAAE,mBAAmB,KAAK,MAC5C2B,IAAiB3B,EAAE,kBAAkB,KAAK;AAI9CK,SAAAA,MAAqB,gBACrBA,MAAqB,kBAGnBuB,gBAAAA,EAAA,cAAC,SAAI,WAAU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
- import { useTranslations as C, useKnockClient as S, useKnockSlackClient as M, useSlackAuth as N } from "@knocklabs/react-core";
1
+ import n, { useMemo as L, useCallback as w } from "react";
2
+ import { useTranslations as A, useKnockClient as M, useKnockSlackClient as N, useSlackAuth as I, useAuthPostMessageListener as v, useAuthPolling as P } from "@knocklabs/react-core";
3
3
  import { openPopupWindow as d } from "../../../core/utils.mjs";
4
4
  /* empty css */
5
- import { SlackIcon as s } from "../SlackIcon/SlackIcon.mjs";
5
+ import { SlackIcon as r } from "../SlackIcon/SlackIcon.mjs";
6
6
  /* empty css */
7
7
  const B = ({
8
- slackClientId: p,
9
- redirectUrl: b,
10
- onAuthenticationComplete: a,
11
- scopes: l,
12
- additionalScopes: i
8
+ slackClientId: b,
9
+ redirectUrl: E,
10
+ onAuthenticationComplete: u,
11
+ scopes: i,
12
+ additionalScopes: k
13
13
  }) => {
14
14
  const {
15
- t
16
- } = C(), u = S(), {
15
+ t: e
16
+ } = A(), a = M(), {
17
17
  setConnectionStatus: c,
18
- connectionStatus: n,
18
+ connectionStatus: t,
19
19
  setActionLabel: o,
20
20
  actionLabel: m,
21
- errorLabel: h
22
- } = M(), E = w(() => ({
23
- scopes: l,
24
- additionalScopes: i
25
- }), [l, i]), {
26
- buildSlackAuthUrl: k,
27
- disconnectFromSlack: f
28
- } = N(p, b, E);
29
- L(() => {
30
- const _ = (r) => {
31
- if (r.origin === u.host)
32
- try {
33
- r.data === "authComplete" && c("connected"), r.data === "authFailed" && c("error"), a && a(r.data);
34
- } catch {
35
- c("error");
36
- }
37
- };
38
- return window.addEventListener("message", _, !1), () => {
39
- window.removeEventListener("message", _);
40
- };
41
- }, [u.host, a, c]);
42
- const g = t("slackDisconnect") || null, x = t("slackReconnect") || null;
43
- return n === "connecting" || n === "disconnecting" ? /* @__PURE__ */ e.createElement("div", { className: "rsk-connect__button rsk-connect__button--loading" }, /* @__PURE__ */ e.createElement(s, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", null, t(n === "connecting" ? "slackConnecting" : "slackDisconnecting"))) : n === "error" ? /* @__PURE__ */ e.createElement("button", { onClick: () => d(k()), className: "rsk-connect__button rsk-connect__button--error", onMouseEnter: () => o(x), onMouseLeave: () => o(null) }, /* @__PURE__ */ e.createElement(s, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", { className: "rsk-connect__button__text--error" }, m || h || t("slackError"))) : n === "disconnected" ? /* @__PURE__ */ e.createElement("button", { onClick: () => d(k()), className: "rsk-connect__button rsk-connect__button--disconnected" }, /* @__PURE__ */ e.createElement(s, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", null, t("slackConnect"))) : /* @__PURE__ */ e.createElement("button", { onClick: f, className: "rsk-connect__button rsk-connect__button--connected", onMouseEnter: () => o(g), onMouseLeave: () => o(null) }, /* @__PURE__ */ e.createElement(s, { height: "16px", width: "16px" }), /* @__PURE__ */ e.createElement("span", { className: "rsk-connect__button__text--connected" }, m || t("slackConnected")));
21
+ errorLabel: g,
22
+ tenantId: p,
23
+ knockSlackChannelId: _,
24
+ popupWindowRef: s
25
+ } = N(), C = L(() => ({
26
+ scopes: i,
27
+ additionalScopes: k
28
+ }), [i, k]), {
29
+ buildSlackAuthUrl: h,
30
+ disconnectFromSlack: x
31
+ } = I(b, E, C);
32
+ v({
33
+ knockHost: a.host,
34
+ popupWindowRef: s,
35
+ setConnectionStatus: c,
36
+ onAuthenticationComplete: u
37
+ }), P({
38
+ popupWindowRef: s,
39
+ setConnectionStatus: c,
40
+ onAuthenticationComplete: u,
41
+ authCheckFn: w(async () => a.slack.authCheck({
42
+ tenant: p,
43
+ knockChannelId: _
44
+ }), [a.slack, p, _])
45
+ });
46
+ const f = e("slackDisconnect") || null, S = e("slackReconnect") || null;
47
+ return t === "connecting" || t === "disconnecting" ? /* @__PURE__ */ n.createElement("div", { className: "rsk-connect__button rsk-connect__button--loading" }, /* @__PURE__ */ n.createElement(r, { height: "16px", width: "16px" }), /* @__PURE__ */ n.createElement("span", null, e(t === "connecting" ? "slackConnecting" : "slackDisconnecting"))) : t === "error" ? /* @__PURE__ */ n.createElement("button", { onClick: () => {
48
+ const l = d(h());
49
+ s.current = l, c("connecting");
50
+ }, className: "rsk-connect__button rsk-connect__button--error", onMouseEnter: () => o(S), onMouseLeave: () => o(null) }, /* @__PURE__ */ n.createElement(r, { height: "16px", width: "16px" }), /* @__PURE__ */ n.createElement("span", { className: "rsk-connect__button__text--error" }, m || g || e("slackError"))) : t === "disconnected" ? /* @__PURE__ */ n.createElement("button", { onClick: () => {
51
+ const l = d(h());
52
+ s.current = l, c("connecting");
53
+ }, className: "rsk-connect__button rsk-connect__button--disconnected" }, /* @__PURE__ */ n.createElement(r, { height: "16px", width: "16px" }), /* @__PURE__ */ n.createElement("span", null, e("slackConnect"))) : /* @__PURE__ */ n.createElement("button", { onClick: x, className: "rsk-connect__button rsk-connect__button--connected", onMouseEnter: () => o(f), onMouseLeave: () => o(null) }, /* @__PURE__ */ n.createElement(r, { height: "16px", width: "16px" }), /* @__PURE__ */ n.createElement("span", { className: "rsk-connect__button__text--connected" }, m || e("slackConnected")));
44
54
  };
45
55
  export {
46
56
  B as SlackAuthButton
@@ -1 +1 @@
1
- {"version":3,"file":"SlackAuthButton.mjs","sources":["../../../../../../src/modules/slack/components/SlackAuthButton/SlackAuthButton.tsx"],"sourcesContent":["import {\n useKnockClient,\n useKnockSlackClient,\n useSlackAuth,\n useTranslations,\n} from \"@knocklabs/react-core\";\nimport { FunctionComponent, useMemo } from \"react\";\nimport { useEffect } from \"react\";\n\nimport { openPopupWindow } from \"../../../core/utils\";\nimport \"../../theme.css\";\nimport { SlackIcon } from \"../SlackIcon\";\n\nimport \"./styles.css\";\n\nexport interface SlackAuthButtonProps {\n slackClientId: string;\n redirectUrl?: string;\n onAuthenticationComplete?: (authenticationResp: string) => void;\n // When provided, the default scopes will be overridden with the provided scopes\n scopes?: string[];\n // Additional scopes to add to the default scopes\n additionalScopes?: string[];\n}\n\nexport const SlackAuthButton: FunctionComponent<SlackAuthButtonProps> = ({\n slackClientId,\n redirectUrl,\n onAuthenticationComplete,\n scopes,\n additionalScopes,\n}) => {\n const { t } = useTranslations();\n const knock = useKnockClient();\n\n const {\n setConnectionStatus,\n connectionStatus,\n setActionLabel,\n actionLabel,\n errorLabel,\n } = useKnockSlackClient();\n\n const useSlackAuthOptions = useMemo(\n () => ({\n scopes,\n additionalScopes,\n }),\n [scopes, additionalScopes],\n );\n\n const { buildSlackAuthUrl, disconnectFromSlack } = useSlackAuth(\n slackClientId,\n redirectUrl,\n useSlackAuthOptions,\n );\n\n useEffect(() => {\n const receiveMessage = (event: MessageEvent) => {\n if (event.origin !== knock.host) {\n return;\n }\n\n try {\n if (event.data === \"authComplete\") {\n setConnectionStatus(\"connected\");\n }\n\n if (event.data === \"authFailed\") {\n setConnectionStatus(\"error\");\n }\n\n if (onAuthenticationComplete) {\n onAuthenticationComplete(event.data);\n }\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n };\n\n window.addEventListener(\"message\", receiveMessage, false);\n\n // Cleanup the event listener when the component unmounts\n return () => {\n window.removeEventListener(\"message\", receiveMessage);\n };\n }, [knock.host, onAuthenticationComplete, setConnectionStatus]);\n\n const disconnectLabel = t(\"slackDisconnect\") || null;\n const reconnectLabel = t(\"slackReconnect\") || null;\n\n // Loading states\n if (\n connectionStatus === \"connecting\" ||\n connectionStatus === \"disconnecting\"\n ) {\n return (\n <div className=\"rsk-connect__button rsk-connect__button--loading\">\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span>\n {connectionStatus === \"connecting\"\n ? t(\"slackConnecting\")\n : t(\"slackDisconnecting\")}\n </span>\n </div>\n );\n }\n\n // Error state\n if (connectionStatus === \"error\") {\n return (\n <button\n onClick={() => openPopupWindow(buildSlackAuthUrl())}\n className=\"rsk-connect__button rsk-connect__button--error\"\n onMouseEnter={() => setActionLabel(reconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span className=\"rsk-connect__button__text--error\">\n {actionLabel || errorLabel || t(\"slackError\")}\n </span>\n </button>\n );\n }\n\n // Disconnected state\n if (connectionStatus === \"disconnected\") {\n return (\n <button\n onClick={() => openPopupWindow(buildSlackAuthUrl())}\n className=\"rsk-connect__button rsk-connect__button--disconnected\"\n >\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span>{t(\"slackConnect\")}</span>\n </button>\n );\n }\n\n // Connected state\n return (\n <button\n onClick={disconnectFromSlack}\n className=\"rsk-connect__button rsk-connect__button--connected\"\n onMouseEnter={() => setActionLabel(disconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span className=\"rsk-connect__button__text--connected\">\n {actionLabel || t(\"slackConnected\")}\n </span>\n </button>\n );\n};\n"],"names":["SlackAuthButton","slackClientId","redirectUrl","onAuthenticationComplete","scopes","additionalScopes","t","useTranslations","knock","useKnockClient","setConnectionStatus","connectionStatus","setActionLabel","actionLabel","errorLabel","useKnockSlackClient","useSlackAuthOptions","useMemo","buildSlackAuthUrl","disconnectFromSlack","useSlackAuth","useEffect","receiveMessage","event","origin","host","data","addEventListener","removeEventListener","disconnectLabel","reconnectLabel","React","SlackIcon","openPopupWindow"],"mappings":";;;;;;AAyBO,MAAMA,IAA2DA,CAAC;AAAA,EACvEC,eAAAA;AAAAA,EACAC,aAAAA;AAAAA,EACAC,0BAAAA;AAAAA,EACAC,QAAAA;AAAAA,EACAC,kBAAAA;AACF,MAAM;AACE,QAAA;AAAA,IAAEC;AAAAA,MAAMC,EAAgB,GACxBC,IAAQC,EAAe,GAEvB;AAAA,IACJC,qBAAAA;AAAAA,IACAC,kBAAAA;AAAAA,IACAC,gBAAAA;AAAAA,IACAC,aAAAA;AAAAA,IACAC,YAAAA;AAAAA,MACEC,EAAoB,GAElBC,IAAsBC,EAC1B,OAAO;AAAA,IACLb,QAAAA;AAAAA,IACAC,kBAAAA;AAAAA,EAAAA,IAEF,CAACD,GAAQC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ACC,SAAS,MAAME,EAAgBf,EAAkB,CAAC,GAClD,WAAU,wDAEV,GAAAa,gBAAAA,EAAA,cAACC,KAAU,QAAO,QAAO,OAAM,OAAM,CAAA,mCACpC,QAAM1B,MAAAA,EAAE,cAAc,CAAE,CAC3B,IAMDyB,gBAAAA,EAAA,cAAA,UAAA,EACC,SAASZ,GACT,WAAU,sDACV,cAAc,MAAMP,EAAeiB,CAAe,GAClD,cAAc,MAAMjB,EAAe,IAAI,KAEvCmB,gBAAAA,EAAA,cAACC,GAAU,EAAA,QAAO,QAAO,OAAM,OAAM,CAAA,GACrCD,gBAAAA,EAAA,cAAC,QAAK,EAAA,WAAU,uCACblB,GAAAA,KAAeP,EAAE,gBAAgB,CACpC,CACF;AAEJ;"}
1
+ {"version":3,"file":"SlackAuthButton.mjs","sources":["../../../../../../src/modules/slack/components/SlackAuthButton/SlackAuthButton.tsx"],"sourcesContent":["import {\n useAuthPolling,\n useAuthPostMessageListener,\n useKnockClient,\n useKnockSlackClient,\n useSlackAuth,\n useTranslations,\n} from \"@knocklabs/react-core\";\nimport { FunctionComponent, useCallback, useMemo } from \"react\";\n\nimport { openPopupWindow } from \"../../../core/utils\";\nimport \"../../theme.css\";\nimport { SlackIcon } from \"../SlackIcon\";\n\nimport \"./styles.css\";\n\nexport interface SlackAuthButtonProps {\n slackClientId: string;\n redirectUrl?: string;\n onAuthenticationComplete?: (authenticationResp: string) => void;\n // When provided, the default scopes will be overridden with the provided scopes\n scopes?: string[];\n // Additional scopes to add to the default scopes\n additionalScopes?: string[];\n}\n\nexport const SlackAuthButton: FunctionComponent<SlackAuthButtonProps> = ({\n slackClientId,\n redirectUrl,\n onAuthenticationComplete,\n scopes,\n additionalScopes,\n}) => {\n const { t } = useTranslations();\n const knock = useKnockClient();\n\n const {\n setConnectionStatus,\n connectionStatus,\n setActionLabel,\n actionLabel,\n errorLabel,\n tenantId,\n knockSlackChannelId,\n popupWindowRef,\n } = useKnockSlackClient();\n\n const useSlackAuthOptions = useMemo(\n () => ({\n scopes,\n additionalScopes,\n }),\n [scopes, additionalScopes],\n );\n\n const { buildSlackAuthUrl, disconnectFromSlack } = useSlackAuth(\n slackClientId,\n redirectUrl,\n useSlackAuthOptions,\n );\n\n useAuthPostMessageListener({\n knockHost: knock.host,\n popupWindowRef,\n setConnectionStatus,\n onAuthenticationComplete,\n });\n\n useAuthPolling({\n popupWindowRef,\n setConnectionStatus,\n onAuthenticationComplete,\n authCheckFn: useCallback(async () => {\n return knock.slack.authCheck({\n tenant: tenantId,\n knockChannelId: knockSlackChannelId,\n });\n }, [knock.slack, tenantId, knockSlackChannelId]),\n });\n\n const disconnectLabel = t(\"slackDisconnect\") || null;\n const reconnectLabel = t(\"slackReconnect\") || null;\n\n // Loading states\n if (\n connectionStatus === \"connecting\" ||\n connectionStatus === \"disconnecting\"\n ) {\n return (\n <div className=\"rsk-connect__button rsk-connect__button--loading\">\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span>\n {connectionStatus === \"connecting\"\n ? t(\"slackConnecting\")\n : t(\"slackDisconnecting\")}\n </span>\n </div>\n );\n }\n\n // Error state\n if (connectionStatus === \"error\") {\n return (\n <button\n onClick={() => {\n const popup = openPopupWindow(buildSlackAuthUrl());\n popupWindowRef.current = popup;\n setConnectionStatus(\"connecting\");\n }}\n className=\"rsk-connect__button rsk-connect__button--error\"\n onMouseEnter={() => setActionLabel(reconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span className=\"rsk-connect__button__text--error\">\n {actionLabel || errorLabel || t(\"slackError\")}\n </span>\n </button>\n );\n }\n\n // Disconnected state\n if (connectionStatus === \"disconnected\") {\n return (\n <button\n onClick={() => {\n const popup = openPopupWindow(buildSlackAuthUrl());\n popupWindowRef.current = popup;\n setConnectionStatus(\"connecting\");\n }}\n className=\"rsk-connect__button rsk-connect__button--disconnected\"\n >\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span>{t(\"slackConnect\")}</span>\n </button>\n );\n }\n\n // Connected state\n return (\n <button\n onClick={disconnectFromSlack}\n className=\"rsk-connect__button rsk-connect__button--connected\"\n onMouseEnter={() => setActionLabel(disconnectLabel)}\n onMouseLeave={() => setActionLabel(null)}\n >\n <SlackIcon height=\"16px\" width=\"16px\" />\n <span className=\"rsk-connect__button__text--connected\">\n {actionLabel || t(\"slackConnected\")}\n </span>\n </button>\n );\n};\n"],"names":["SlackAuthButton","slackClientId","redirectUrl","onAuthenticationComplete","scopes","additionalScopes","t","useTranslations","knock","useKnockClient","setConnectionStatus","connectionStatus","setActionLabel","actionLabel","errorLabel","tenantId","knockSlackChannelId","popupWindowRef","useKnockSlackClient","useSlackAuthOptions","useMemo","buildSlackAuthUrl","disconnectFromSlack","useSlackAuth","useAuthPostMessageListener","knockHost","host","useAuthPolling","authCheckFn","useCallback","slack","authCheck","tenant","knockChannelId","disconnectLabel","reconnectLabel","React","SlackIcon","popup","openPopupWindow","current"],"mappings":";;;;;;AA0BO,MAAMA,IAA2DA,CAAC;AAAA,EACvEC,eAAAA;AAAAA,EACAC,aAAAA;AAAAA,EACAC,0BAAAA;AAAAA,EACAC,QAAAA;AAAAA,EACAC,kBAAAA;AACF,MAAM;AACE,QAAA;AAAA,IAAEC,GAAAA;AAAAA,MAAMC,EAAgB,GACxBC,IAAQC,EAAe,GAEvB;AAAA,IACJC,qBAAAA;AAAAA,IACAC,kBAAAA;AAAAA,IACAC,gBAAAA;AAAAA,IACAC,aAAAA;AAAAA,IACAC,YAAAA;AAAAA,IACAC,UAAAA;AAAAA,IACAC,qBAAAA;AAAAA,IACAC,gBAAAA;AAAAA,MACEC,EAAoB,GAElBC,IAAsBC,EAC1B,OAAO;AAAA,IACLhB,QAAAA;AAAAA,IACAC,kBAAAA;AAAAA,EAAAA,IAEF,CAACD,GAAQC,CAAgB,CAC3B,GAEM;AAAA,IAAEgB,mBAAAA;AAAAA,IAAmBC,qBAAAA;AAAAA,EAAwBC,IAAAA,EACjDtB,GACAC,GACAi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AgBlB,GAAmB;AACjDJ,IAAAA,EAAeuB,UAAUF,GACzB5B,EAAoB,YAAY;AAAA,EAAA,GAElC,WAAU,wDAEV,GAAA0B,gBAAAA,EAAA,cAACC,KAAU,QAAO,QAAO,OAAM,QAAM,GACpCD,gBAAAA,EAAA,cAAA,QAAA,MAAM9B,EAAE,cAAc,CAAE,CAC3B,IAMD8B,gBAAAA,EAAA,cAAA,UAAA,EACC,SAASd,GACT,WAAU,sDACV,cAAc,MAAMV,EAAesB,CAAe,GAClD,cAAc,MAAMtB,EAAe,IAAI,KAEvCwB,gBAAAA,EAAA,cAACC,GAAU,EAAA,QAAO,QAAO,OAAM,OAAM,CAAA,GACrCD,gBAAAA,EAAA,cAAC,QAAK,EAAA,WAAU,uCACbvB,GAAAA,KAAeP,EAAE,gBAAgB,CACpC,CACF;AAEJ;"}
@@ -1,3 +1,3 @@
1
- export declare const openPopupWindow: (url: string) => void;
1
+ export declare const openPopupWindow: (url: string) => Window | null;
2
2
  export declare const checkForWindow: () => (Window & typeof globalThis) | undefined;
3
3
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/modules/core/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,SAqB1C,CAAC;AAEF,eAAO,MAAM,cAAc,gDAI1B,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/modules/core/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,kBAqB1C,CAAC;AAEF,eAAO,MAAM,cAAc,gDAI1B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"MsTeamsAuthButton.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/ms-teams/components/MsTeamsAuthButton/MsTeamsAuthButton.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAGrD,OAAO,iBAAiB,CAAC;AAGzB,OAAO,cAAc,CAAC;AAEtB,MAAM,MAAM,sBAAsB,GAAG;IACnC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wBAAwB,CAAC,EAAE,CAAC,kBAAkB,EAAE,MAAM,KAAK,IAAI,CAAC;CACjE,GAAG,CACA;IACE;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;CAC1B,GACD;IACE;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;CACtB,CACJ,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,iBAAiB,CAAC,sBAAsB,CAqHvE,CAAC"}
1
+ {"version":3,"file":"MsTeamsAuthButton.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/ms-teams/components/MsTeamsAuthButton/MsTeamsAuthButton.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAe,MAAM,OAAO,CAAC;AAGvD,OAAO,iBAAiB,CAAC;AAGzB,OAAO,cAAc,CAAC;AAEtB,MAAM,MAAM,sBAAsB,GAAG;IACnC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wBAAwB,CAAC,EAAE,CAAC,kBAAkB,EAAE,MAAM,KAAK,IAAI,CAAC;CACjE,GAAG,CACA;IACE;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;CAC1B,GACD;IACE;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;CACtB,CACJ,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,iBAAiB,CAAC,sBAAsB,CAsHvE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"SlackAuthButton.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/slack/components/SlackAuthButton/SlackAuthButton.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAW,MAAM,OAAO,CAAC;AAInD,OAAO,iBAAiB,CAAC;AAGzB,OAAO,cAAc,CAAC;AAEtB,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wBAAwB,CAAC,EAAE,CAAC,kBAAkB,EAAE,MAAM,KAAK,IAAI,CAAC;IAEhE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,eAAO,MAAM,eAAe,EAAE,iBAAiB,CAAC,oBAAoB,CA+HnE,CAAC"}
1
+ {"version":3,"file":"SlackAuthButton.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/slack/components/SlackAuthButton/SlackAuthButton.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAwB,MAAM,OAAO,CAAC;AAGhE,OAAO,iBAAiB,CAAC;AAGzB,OAAO,cAAc,CAAC;AAEtB,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wBAAwB,CAAC,EAAE,CAAC,kBAAkB,EAAE,MAAM,KAAK,IAAI,CAAC;IAEhE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,eAAO,MAAM,eAAe,EAAE,iBAAiB,CAAC,oBAAoB,CA8HnE,CAAC"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@knocklabs/react",
3
3
  "description": "A set of React components to build notification experiences powered by Knock",
4
4
  "author": "@knocklabs",
5
- "version": "0.10.2",
5
+ "version": "0.10.4",
6
6
  "license": "MIT",
7
7
  "main": "dist/cjs/index.js",
8
8
  "module": "dist/esm/index.mjs",
@@ -72,8 +72,8 @@
72
72
  }
73
73
  },
74
74
  "dependencies": {
75
- "@knocklabs/client": "^0.20.2",
76
- "@knocklabs/react-core": "^0.12.2",
75
+ "@knocklabs/client": "^0.20.3",
76
+ "@knocklabs/react-core": "^0.12.4",
77
77
  "@popperjs/core": "^2.11.8",
78
78
  "@radix-ui/react-dialog": "^1.1.15",
79
79
  "@telegraph/combobox": "^0.1.16",