@knocklabs/react-core 0.12.3 → 0.12.5

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/index.js +1 -1
  3. package/dist/cjs/modules/core/hooks/useAuthPolling.js +2 -0
  4. package/dist/cjs/modules/core/hooks/useAuthPolling.js.map +1 -0
  5. package/dist/cjs/modules/core/hooks/useAuthPostMessageListener.js +2 -0
  6. package/dist/cjs/modules/core/hooks/useAuthPostMessageListener.js.map +1 -0
  7. package/dist/cjs/modules/ms-teams/context/KnockMsTeamsProvider.js +1 -1
  8. package/dist/cjs/modules/ms-teams/context/KnockMsTeamsProvider.js.map +1 -1
  9. package/dist/cjs/modules/ms-teams/hooks/useMsTeamsConnectionStatus.js.map +1 -1
  10. package/dist/cjs/modules/slack/context/KnockSlackProvider.js +1 -1
  11. package/dist/cjs/modules/slack/context/KnockSlackProvider.js.map +1 -1
  12. package/dist/cjs/modules/slack/hooks/useSlackConnectionStatus.js.map +1 -1
  13. package/dist/esm/index.mjs +70 -66
  14. package/dist/esm/index.mjs.map +1 -1
  15. package/dist/esm/modules/core/hooks/useAuthPolling.mjs +50 -0
  16. package/dist/esm/modules/core/hooks/useAuthPolling.mjs.map +1 -0
  17. package/dist/esm/modules/core/hooks/useAuthPostMessageListener.mjs +19 -0
  18. package/dist/esm/modules/core/hooks/useAuthPostMessageListener.mjs.map +1 -0
  19. package/dist/esm/modules/ms-teams/context/KnockMsTeamsProvider.mjs +28 -26
  20. package/dist/esm/modules/ms-teams/context/KnockMsTeamsProvider.mjs.map +1 -1
  21. package/dist/esm/modules/ms-teams/hooks/useMsTeamsConnectionStatus.mjs.map +1 -1
  22. package/dist/esm/modules/slack/context/KnockSlackProvider.mjs +24 -22
  23. package/dist/esm/modules/slack/context/KnockSlackProvider.mjs.map +1 -1
  24. package/dist/esm/modules/slack/hooks/useSlackConnectionStatus.mjs.map +1 -1
  25. package/dist/types/index.d.ts +1 -1
  26. package/dist/types/index.d.ts.map +1 -1
  27. package/dist/types/modules/core/hooks/index.d.ts +2 -0
  28. package/dist/types/modules/core/hooks/index.d.ts.map +1 -1
  29. package/dist/types/modules/core/hooks/useAuthPolling.d.ts +34 -0
  30. package/dist/types/modules/core/hooks/useAuthPolling.d.ts.map +1 -0
  31. package/dist/types/modules/core/hooks/useAuthPostMessageListener.d.ts +27 -0
  32. package/dist/types/modules/core/hooks/useAuthPostMessageListener.d.ts.map +1 -0
  33. package/dist/types/modules/core/index.d.ts +2 -1
  34. package/dist/types/modules/core/index.d.ts.map +1 -1
  35. package/dist/types/modules/core/types.d.ts +20 -0
  36. package/dist/types/modules/core/types.d.ts.map +1 -0
  37. package/dist/types/modules/ms-teams/context/KnockMsTeamsProvider.d.ts +2 -1
  38. package/dist/types/modules/ms-teams/context/KnockMsTeamsProvider.d.ts.map +1 -1
  39. package/dist/types/modules/ms-teams/hooks/useMsTeamsConnectionStatus.d.ts +1 -1
  40. package/dist/types/modules/ms-teams/hooks/useMsTeamsConnectionStatus.d.ts.map +1 -1
  41. package/dist/types/modules/slack/context/KnockSlackProvider.d.ts +2 -1
  42. package/dist/types/modules/slack/context/KnockSlackProvider.d.ts.map +1 -1
  43. package/dist/types/modules/slack/hooks/useSlackConnectionStatus.d.ts +1 -1
  44. package/dist/types/modules/slack/hooks/useSlackConnectionStatus.d.ts.map +1 -1
  45. package/package.json +2 -2
  46. package/src/index.ts +4 -0
  47. package/src/modules/core/hooks/index.ts +2 -0
  48. package/src/modules/core/hooks/useAuthPolling.ts +115 -0
  49. package/src/modules/core/hooks/useAuthPostMessageListener.ts +70 -0
  50. package/src/modules/core/index.ts +7 -1
  51. package/src/modules/core/types.ts +25 -0
  52. package/src/modules/ms-teams/context/KnockMsTeamsProvider.tsx +5 -3
  53. package/src/modules/ms-teams/hooks/useMsTeamsConnectionStatus.ts +1 -7
  54. package/src/modules/slack/context/KnockSlackProvider.tsx +5 -3
  55. package/src/modules/slack/hooks/useSlackConnectionStatus.ts +1 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.12.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [1c486d3]
8
+ - @knocklabs/client@0.20.4
9
+
10
+ ## 0.12.4
11
+
12
+ ### Patch Changes
13
+
14
+ - f9aca69: fix: poll to check if OAuth connection succeeded in case popup communication fails during Slack and Microsoft Teams auth flows
15
+
3
16
  ## 0.12.3
4
17
 
5
18
  ### Patch Changes
package/dist/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./modules/core/context/KnockProvider.js"),c=require("./modules/core/hooks/useAuthenticatedKnockClient.js"),a=require("./modules/core/hooks/useStableOptions.js"),d=require("./modules/core/constants.js"),e=require("./modules/core/utils.js"),n=require("./modules/feed/context/KnockFeedProvider.js"),l=require("./modules/feed/hooks/useNotifications.js"),k=require("./modules/feed/hooks/useFeedSettings.js"),r=require("./modules/feed/hooks/useNotificationStore.js"),o=require("./modules/guide/context/KnockGuideProvider.js"),C=require("./modules/guide/hooks/useGuide.js"),K=require("./modules/guide/hooks/useGuides.js"),S=require("./modules/guide/hooks/useGuideContext.js"),t=require("./modules/ms-teams/context/KnockMsTeamsProvider.js"),m=require("./modules/ms-teams/hooks/useMsTeamsConnectionStatus.js"),q=require("./modules/ms-teams/hooks/useMsTeamsAuth.js"),P=require("./modules/ms-teams/hooks/useMsTeamsTeams.js"),v=require("./modules/ms-teams/hooks/useMsTeamsChannels.js"),T=require("./modules/ms-teams/hooks/useConnectedMsTeamsChannels.js"),u=require("./modules/slack/context/KnockSlackProvider.js"),f=require("./modules/slack/hooks/useSlackConnectionStatus.js"),M=require("./modules/slack/hooks/useSlackChannels.js"),h=require("./modules/slack/hooks/useConnectedSlackChannels.js"),G=require("./modules/slack/hooks/useSlackAuth.js"),i=require("./modules/i18n/context/KnockI18nProvider.js"),F=require("./modules/i18n/hooks/useTranslations.js"),y=require("./modules/i18n/languages/index.js"),b=require("./modules/preferences/hooks/usePreferences.js"),x=require("@tanstack/react-store");exports.KnockProvider=s.KnockProvider;exports.useKnockClient=s.useKnockClient;exports.useAuthenticatedKnockClient=c;exports.useStableOptions=a;exports.FilterStatus=d.FilterStatus;exports.feedProviderKey=e.feedProviderKey;exports.formatBadgeCount=e.formatBadgeCount;exports.formatTimestamp=e.formatTimestamp;exports.msTeamsProviderKey=e.msTeamsProviderKey;exports.renderNodeOrFallback=e.renderNodeOrFallback;exports.slackProviderKey=e.slackProviderKey;exports.toSentenceCase=e.toSentenceCase;exports.KnockFeedProvider=n.KnockFeedProvider;exports.useKnockFeed=n.useKnockFeed;exports.useNotifications=l;exports.useFeedSettings=k;exports.useCreateNotificationStore=r.useCreateNotificationStore;exports.useNotificationStore=r.default;exports.KnockGuideContext=o.KnockGuideContext;exports.KnockGuideProvider=o.KnockGuideProvider;exports.useGuide=C.useGuide;exports.useGuides=K.useGuides;exports.useGuideContext=S.useGuideContext;exports.KnockMsTeamsProvider=t.KnockMsTeamsProvider;exports.useKnockMsTeamsClient=t.useKnockMsTeamsClient;exports.useMsTeamsConnectionStatus=m;exports.useMsTeamsAuth=q;exports.useMsTeamsTeams=P;exports.useMsTeamsChannels=v;exports.useConnectedMsTeamsChannels=T;exports.KnockSlackProvider=u.KnockSlackProvider;exports.useKnockSlackClient=u.useKnockSlackClient;exports.useSlackConnectionStatus=f;exports.useSlackChannels=M;exports.useConnectedSlackChannels=h;exports.useSlackAuth=G;exports.I18nContext=i.I18nContext;exports.KnockI18nProvider=i.KnockI18nProvider;exports.useTranslations=F.useTranslations;exports.locales=y.locales;exports.usePreferences=b.usePreferences;Object.defineProperty(exports,"useStore",{enumerable:!0,get:()=>x.useStore});
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./modules/core/context/KnockProvider.js"),c=require("./modules/core/hooks/useAuthenticatedKnockClient.js"),a=require("./modules/core/hooks/useStableOptions.js"),d=require("./modules/core/hooks/useAuthPostMessageListener.js"),l=require("./modules/core/hooks/useAuthPolling.js"),k=require("./modules/core/constants.js"),e=require("./modules/core/utils.js"),n=require("./modules/feed/context/KnockFeedProvider.js"),C=require("./modules/feed/hooks/useNotifications.js"),K=require("./modules/feed/hooks/useFeedSettings.js"),t=require("./modules/feed/hooks/useNotificationStore.js"),o=require("./modules/guide/context/KnockGuideProvider.js"),P=require("./modules/guide/hooks/useGuide.js"),S=require("./modules/guide/hooks/useGuides.js"),m=require("./modules/guide/hooks/useGuideContext.js"),r=require("./modules/ms-teams/context/KnockMsTeamsProvider.js"),q=require("./modules/ms-teams/hooks/useMsTeamsConnectionStatus.js"),v=require("./modules/ms-teams/hooks/useMsTeamsAuth.js"),T=require("./modules/ms-teams/hooks/useMsTeamsTeams.js"),h=require("./modules/ms-teams/hooks/useMsTeamsChannels.js"),M=require("./modules/ms-teams/hooks/useConnectedMsTeamsChannels.js"),u=require("./modules/slack/context/KnockSlackProvider.js"),f=require("./modules/slack/hooks/useSlackConnectionStatus.js"),G=require("./modules/slack/hooks/useSlackChannels.js"),g=require("./modules/slack/hooks/useConnectedSlackChannels.js"),A=require("./modules/slack/hooks/useSlackAuth.js"),i=require("./modules/i18n/context/KnockI18nProvider.js"),F=require("./modules/i18n/hooks/useTranslations.js"),y=require("./modules/i18n/languages/index.js"),b=require("./modules/preferences/hooks/usePreferences.js"),x=require("@tanstack/react-store");exports.KnockProvider=s.KnockProvider;exports.useKnockClient=s.useKnockClient;exports.useAuthenticatedKnockClient=c;exports.useStableOptions=a;exports.useAuthPostMessageListener=d.useAuthPostMessageListener;exports.useAuthPolling=l.useAuthPolling;exports.FilterStatus=k.FilterStatus;exports.feedProviderKey=e.feedProviderKey;exports.formatBadgeCount=e.formatBadgeCount;exports.formatTimestamp=e.formatTimestamp;exports.msTeamsProviderKey=e.msTeamsProviderKey;exports.renderNodeOrFallback=e.renderNodeOrFallback;exports.slackProviderKey=e.slackProviderKey;exports.toSentenceCase=e.toSentenceCase;exports.KnockFeedProvider=n.KnockFeedProvider;exports.useKnockFeed=n.useKnockFeed;exports.useNotifications=C;exports.useFeedSettings=K;exports.useCreateNotificationStore=t.useCreateNotificationStore;exports.useNotificationStore=t.default;exports.KnockGuideContext=o.KnockGuideContext;exports.KnockGuideProvider=o.KnockGuideProvider;exports.useGuide=P.useGuide;exports.useGuides=S.useGuides;exports.useGuideContext=m.useGuideContext;exports.KnockMsTeamsProvider=r.KnockMsTeamsProvider;exports.useKnockMsTeamsClient=r.useKnockMsTeamsClient;exports.useMsTeamsConnectionStatus=q;exports.useMsTeamsAuth=v;exports.useMsTeamsTeams=T;exports.useMsTeamsChannels=h;exports.useConnectedMsTeamsChannels=M;exports.KnockSlackProvider=u.KnockSlackProvider;exports.useKnockSlackClient=u.useKnockSlackClient;exports.useSlackConnectionStatus=f;exports.useSlackChannels=G;exports.useConnectedSlackChannels=g;exports.useSlackAuth=A;exports.I18nContext=i.I18nContext;exports.KnockI18nProvider=i.KnockI18nProvider;exports.useTranslations=F.useTranslations;exports.locales=y.locales;exports.usePreferences=b.usePreferences;Object.defineProperty(exports,"useStore",{enumerable:!0,get:()=>x.useStore});
2
2
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react");function h(s){const{popupWindowRef:o,setConnectionStatus:l,onAuthenticationComplete:r,authCheckFn:i}=s;d.useEffect(()=>{let c=0;const p=90;let n=null,u=!0;const e=setInterval(async()=>{var a;if(!u){clearInterval(e);return}const t=o.current;if(!t)return;if(c++,t.closed&&!n&&(n=Date.now()),c>=p){clearInterval(e),l("error");return}if(n&&Date.now()-n>1e4){clearInterval(e),o.current=null;return}try{(a=(await i()).connection)!=null&&a.ok&&(clearInterval(e),l("connected"),r&&r("authComplete"),t&&!t.closed&&t.close(),o.current=null)}catch{}},2e3);return()=>{u=!1,clearInterval(e)}},[])}exports.useAuthPolling=h;
2
+ //# sourceMappingURL=useAuthPolling.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuthPolling.js","sources":["../../../../../src/modules/core/hooks/useAuthPolling.ts"],"sourcesContent":["import { useEffect } from \"react\";\n\nimport { AuthCheckResult, ConnectionStatus } from \"../types\";\n\nexport interface UseAuthPollingOptions {\n popupWindowRef: React.MutableRefObject<Window | null>;\n setConnectionStatus: (status: ConnectionStatus) => void;\n authCheckFn: () => Promise<AuthCheckResult>;\n onAuthenticationComplete?: (authenticationResp: string) => void;\n}\n\n/**\n * Hook that polls an authentication check endpoint until success or timeout.\n *\n * Polls every 2 seconds for up to 3 minutes (90 iterations). Has three stop conditions:\n * 1. Max timeout reached → sets error status\n * 2. Popup closed + 10s grace period → stops silently\n * 3. Success detected via authCheckFn → updates status and closes popup\n *\n * @param options - Configuration options for the polling mechanism\n *\n * @example\n * ```tsx\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 */\nexport function useAuthPolling(options: UseAuthPollingOptions): void {\n const {\n popupWindowRef,\n setConnectionStatus,\n onAuthenticationComplete,\n authCheckFn,\n } = options;\n\n useEffect(\n () => {\n let pollCount = 0;\n const maxPolls = 90;\n let popupClosedAt: number | null = null;\n let isActive = true;\n\n const pollInterval = setInterval(async () => {\n if (!isActive) {\n clearInterval(pollInterval);\n return;\n }\n\n const popupWindow = popupWindowRef.current;\n if (!popupWindow) {\n return;\n }\n\n pollCount++;\n\n const isPopupClosed = popupWindow.closed;\n if (isPopupClosed && !popupClosedAt) {\n popupClosedAt = Date.now();\n }\n\n // Stop condition 1: Max timeout reached\n if (pollCount >= maxPolls) {\n clearInterval(pollInterval);\n setConnectionStatus(\"error\");\n return;\n }\n\n // Stop condition 2: Popup closed + grace period expired\n if (popupClosedAt && Date.now() - popupClosedAt > 10000) {\n clearInterval(pollInterval);\n popupWindowRef.current = null;\n return;\n }\n\n try {\n const authRes = await authCheckFn();\n\n // Stop condition 3: Success detected\n if (authRes.connection?.ok) {\n clearInterval(pollInterval);\n setConnectionStatus(\"connected\");\n if (onAuthenticationComplete) {\n onAuthenticationComplete(\"authComplete\");\n }\n if (popupWindow && !popupWindow.closed) {\n popupWindow.close();\n }\n popupWindowRef.current = null;\n }\n } catch (_error) {\n // Continue polling on error\n }\n }, 2000);\n\n return () => {\n isActive = false;\n clearInterval(pollInterval);\n };\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n // Empty deps - run once on mount and keep polling\n // This is intentionally simple/brute force\n ],\n );\n}\n"],"names":["useAuthPolling","options","popupWindowRef","setConnectionStatus","onAuthenticationComplete","authCheckFn","useEffect","pollCount","maxPolls","popupClosedAt","isActive","pollInterval","setInterval","clearInterval","popupWindow","current","closed","Date","now","authRes","connection","ok","close"],"mappings":"yGAoCO,SAASA,EAAeC,EAAsC,CAC7D,KAAA,CACJC,eAAAA,EACAC,oBAAAA,EACAC,yBAAAA,EACAC,YAAAA,CAAAA,EACEJ,EAEJK,EAAAA,UACE,IAAM,CACJ,IAAIC,EAAY,EAChB,MAAMC,EAAW,GACjB,IAAIC,EAA+B,KAC/BC,EAAW,GAETC,MAAAA,EAAeC,YAAY,SAAY,OAC3C,GAAI,CAACF,EAAU,CACbG,cAAcF,CAAY,EAC1B,MAAA,CAGF,MAAMG,EAAcZ,EAAea,QACnC,GAAI,CAACD,EACH,OAWF,GARAP,IAEsBO,EAAYE,QACb,CAACP,IACpBA,EAAgBQ,KAAKC,IAAI,GAIvBX,GAAaC,EAAU,CACzBK,cAAcF,CAAY,EAC1BR,EAAoB,OAAO,EAC3B,MAAA,CAIF,GAAIM,GAAiBQ,KAAKC,IAAI,EAAIT,EAAgB,IAAO,CACvDI,cAAcF,CAAY,EAC1BT,EAAea,QAAU,KACzB,MAAA,CAGE,GAAA,EAIEI,GAHY,MAAMd,EAAY,GAGtBe,aAARD,MAAAA,EAAoBE,KACtBR,cAAcF,CAAY,EAC1BR,EAAoB,WAAW,EAC3BC,GACFA,EAAyB,cAAc,EAErCU,GAAe,CAACA,EAAYE,QAC9BF,EAAYQ,MAAM,EAEpBpB,EAAea,QAAU,WAEZ,CAAA,GAGhB,GAAI,EAEP,MAAO,IAAM,CACAL,EAAA,GACXG,cAAcF,CAAY,CAC5B,CACF,EAEA,CAAA,CAIF,CACF"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react");function o(n){const{knockHost:u,popupWindowRef:s,setConnectionStatus:t,onAuthenticationComplete:e}=n;c.useEffect(()=>{const a=r=>{r.origin===u&&(r.data==="authComplete"?(t("connected"),e==null||e(r.data),s.current&&!s.current.closed&&s.current.close(),s.current=null):r.data==="authFailed"&&(t("error"),e==null||e(r.data),s.current=null))};return window.addEventListener("message",a,!1),()=>window.removeEventListener("message",a)},[u,e,t,s])}exports.useAuthPostMessageListener=o;
2
+ //# sourceMappingURL=useAuthPostMessageListener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuthPostMessageListener.js","sources":["../../../../../src/modules/core/hooks/useAuthPostMessageListener.ts"],"sourcesContent":["import { useEffect } from \"react\";\n\nimport { ConnectionStatus } from \"../types\";\n\nexport interface UseAuthPostMessageListenerOptions {\n knockHost: string;\n popupWindowRef: React.MutableRefObject<Window | null>;\n setConnectionStatus: (status: ConnectionStatus) => void;\n onAuthenticationComplete?: (authenticationResp: string) => void;\n}\n\n/**\n * Hook that listens for postMessage events from OAuth popup windows.\n *\n * Handles \"authComplete\" and \"authFailed\" messages sent from the OAuth flow popup,\n * validates the message origin, updates connection status, and closes the popup.\n *\n * @param options - Configuration options for the postMessage listener\n *\n * @example\n * ```tsx\n * useAuthPostMessageListener({\n * knockHost: knock.host,\n * popupWindowRef,\n * setConnectionStatus,\n * onAuthenticationComplete,\n * });\n * ```\n */\nexport function useAuthPostMessageListener(\n options: UseAuthPostMessageListenerOptions,\n): void {\n const {\n knockHost,\n popupWindowRef,\n setConnectionStatus,\n onAuthenticationComplete,\n } = options;\n\n useEffect(() => {\n const receiveMessage = (event: MessageEvent) => {\n // Validate message origin for security\n if (event.origin !== knockHost) {\n return;\n }\n\n if (event.data === \"authComplete\") {\n setConnectionStatus(\"connected\");\n onAuthenticationComplete?.(event.data);\n // Clear popup ref so polling stops and doesn't trigger callback again\n if (popupWindowRef.current && !popupWindowRef.current.closed) {\n popupWindowRef.current.close();\n }\n popupWindowRef.current = null;\n } else if (event.data === \"authFailed\") {\n setConnectionStatus(\"error\");\n onAuthenticationComplete?.(event.data);\n popupWindowRef.current = null;\n }\n };\n\n window.addEventListener(\"message\", receiveMessage, false);\n return () => window.removeEventListener(\"message\", receiveMessage);\n }, [\n knockHost,\n onAuthenticationComplete,\n setConnectionStatus,\n popupWindowRef,\n ]);\n}\n"],"names":["useAuthPostMessageListener","options","knockHost","popupWindowRef","setConnectionStatus","onAuthenticationComplete","useEffect","receiveMessage","event","origin","data","current","closed","close","addEventListener","window","removeEventListener"],"mappings":"yGA6BO,SAASA,EACdC,EACM,CACA,KAAA,CACJC,UAAAA,EACAC,eAAAA,EACAC,oBAAAA,EACAC,yBAAAA,CAAAA,EACEJ,EAEJK,EAAAA,UAAU,IAAM,CACRC,MAAAA,EAAkBC,GAAwB,CAE1CA,EAAMC,SAAWP,IAIjBM,EAAME,OAAS,gBACjBN,EAAoB,WAAW,EAC/BC,GAAAA,MAAAA,EAA2BG,EAAME,MAE7BP,EAAeQ,SAAW,CAACR,EAAeQ,QAAQC,QACpDT,EAAeQ,QAAQE,MAAM,EAE/BV,EAAeQ,QAAU,MAChBH,EAAME,OAAS,eACxBN,EAAoB,OAAO,EAC3BC,GAAAA,MAAAA,EAA2BG,EAAME,MACjCP,EAAeQ,QAAU,MAE7B,EAEOG,cAAAA,iBAAiB,UAAWP,EAAgB,EAAK,EACjD,IAAMQ,OAAOC,oBAAoB,UAAWT,CAAc,GAChE,CACDL,EACAG,EACAD,EACAD,CAAc,CACf,CACH"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react"),f=require("../../core/context/KnockProvider.js");require("@knocklabs/client");require("fast-deep-equal");const d=require("../../core/utils.js"),v=require("../hooks/useMsTeamsConnectionStatus.js");require("swr/infinite");require("swr");require("../../i18n/context/KnockI18nProvider.js");function P(e){if(e&&typeof e=="object"&&"default"in e)return e;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const n=P(b),i=n.createContext(null),p=({knockMsTeamsChannelId:e,tenantId:t,children:r})=>{const o=f.useKnockClient(),{connectionStatus:s,setConnectionStatus:u,errorLabel:c,setErrorLabel:a,actionLabel:l,setActionLabel:m}=v(o,e,t);return n.createElement(i.Provider,{key:d.msTeamsProviderKey({knockMsTeamsChannelId:e,tenantId:t,connectionStatus:s,errorLabel:c}),value:{connectionStatus:s,setConnectionStatus:u,errorLabel:c,setErrorLabel:a,actionLabel:l,setActionLabel:m,knockMsTeamsChannelId:e,tenantId:t}},r)},q=()=>{const e=n.useContext(i);if(!e)throw new Error("useKnockMsTeamsClient must be used within a KnockMsTeamsProvider");return e};exports.KnockMsTeamsProvider=p;exports.useKnockMsTeamsClient=q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),d=require("../../core/context/KnockProvider.js");require("@knocklabs/client");require("fast-deep-equal");const p=require("../../core/utils.js"),v=require("../hooks/useMsTeamsConnectionStatus.js");require("swr/infinite");require("swr");require("../../i18n/context/KnockI18nProvider.js");function P(e){if(e&&typeof e=="object"&&"default"in e)return e;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const n=P(i),u=n.createContext(null),q=({knockMsTeamsChannelId:e,tenantId:t,children:r})=>{const o=d.useKnockClient(),a=i.useRef(null),{connectionStatus:s,setConnectionStatus:l,errorLabel:c,setErrorLabel:m,actionLabel:f,setActionLabel:b}=v(o,e,t);return n.createElement(u.Provider,{key:p.msTeamsProviderKey({knockMsTeamsChannelId:e,tenantId:t,connectionStatus:s,errorLabel:c}),value:{connectionStatus:s,setConnectionStatus:l,errorLabel:c,setErrorLabel:m,actionLabel:f,setActionLabel:b,knockMsTeamsChannelId:e,tenantId:t,popupWindowRef:a}},r)},K=()=>{const e=n.useContext(u);if(!e)throw new Error("useKnockMsTeamsClient must be used within a KnockMsTeamsProvider");return e};exports.KnockMsTeamsProvider=q;exports.useKnockMsTeamsClient=K;
2
2
  //# sourceMappingURL=KnockMsTeamsProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"KnockMsTeamsProvider.js","sources":["../../../../../src/modules/ms-teams/context/KnockMsTeamsProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { useKnockClient } from \"../../core\";\nimport { msTeamsProviderKey } from \"../../core/utils\";\nimport { useMsTeamsConnectionStatus } from \"../hooks\";\nimport { ConnectionStatus } from \"../hooks/useMsTeamsConnectionStatus\";\n\nexport interface KnockMsTeamsProviderState {\n knockMsTeamsChannelId: string;\n tenantId: string;\n connectionStatus: ConnectionStatus;\n setConnectionStatus: (connectionStatus: ConnectionStatus) => void;\n errorLabel: string | null;\n setErrorLabel: (label: string) => void;\n actionLabel: string | null;\n setActionLabel: (label: string | null) => void;\n}\n\nconst MsTeamsProviderStateContext =\n React.createContext<KnockMsTeamsProviderState | null>(null);\n\nexport interface KnockMsTeamsProviderProps {\n knockMsTeamsChannelId: string;\n tenantId: string;\n}\n\nexport const KnockMsTeamsProvider: React.FC<\n PropsWithChildren<KnockMsTeamsProviderProps>\n> = ({ knockMsTeamsChannelId, tenantId, children }) => {\n const knock = useKnockClient();\n\n const {\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n } = useMsTeamsConnectionStatus(knock, knockMsTeamsChannelId, tenantId);\n\n return (\n <MsTeamsProviderStateContext.Provider\n key={msTeamsProviderKey({\n knockMsTeamsChannelId,\n tenantId,\n connectionStatus,\n errorLabel,\n })}\n value={{\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n knockMsTeamsChannelId,\n tenantId,\n }}\n >\n {children}\n </MsTeamsProviderStateContext.Provider>\n );\n};\n\nexport const useKnockMsTeamsClient = (): KnockMsTeamsProviderState => {\n const context = React.useContext(MsTeamsProviderStateContext);\n if (!context) {\n throw new Error(\n \"useKnockMsTeamsClient must be used within a KnockMsTeamsProvider\",\n );\n }\n return context;\n};\n"],"names":["MsTeamsProviderStateContext","React","createContext","KnockMsTeamsProvider","knockMsTeamsChannelId","tenantId","children","knock","useKnockClient","connectionStatus","setConnectionStatus","errorLabel","setErrorLabel","actionLabel","setActionLabel","useMsTeamsConnectionStatus","msTeamsProviderKey","useKnockMsTeamsClient","context","useContext","Error"],"mappings":"ktBAmBMA,EACJC,EAAMC,cAAgD,IAAI,EAO/CC,EAETA,CAAC,CAAEC,sBAAAA,EAAuBC,SAAAA,EAAUC,SAAAA,CAAS,IAAM,CACrD,MAAMC,EAAQC,EAAAA,eAAe,EAEvB,CACJC,iBAAAA,EACAC,oBAAAA,EACAC,WAAAA,EACAC,cAAAA,EACAC,YAAAA,EACAC,eAAAA,CACEC,EAAAA,EAA2BR,EAAOH,EAAuBC,CAAQ,EAErE,OACGJ,EAAA,cAAAD,EAA4B,SAA5B,CACC,IAAKgB,qBAAmB,CACtBZ,sBAAAA,EACAC,SAAAA,EACAI,iBAAAA,EACAE,WAAAA,CACD,CAAA,EACD,MAAO,CACLF,iBAAAA,EACAC,oBAAAA,EACAC,WAAAA,EACAC,cAAAA,EACAC,YAAAA,EACAC,eAAAA,EACAV,sBAAAA,EACAC,SAAAA,IAGDC,CACH,CAEJ,EAEaW,EAAwBA,IAAiC,CAC9DC,MAAAA,EAAUjB,EAAMkB,WAAWnB,CAA2B,EAC5D,GAAI,CAACkB,EACG,MAAA,IAAIE,MACR,kEACF,EAEKF,OAAAA,CACT"}
1
+ {"version":3,"file":"KnockMsTeamsProvider.js","sources":["../../../../../src/modules/ms-teams/context/KnockMsTeamsProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { PropsWithChildren, useRef } from \"react\";\n\nimport { type ConnectionStatus, useKnockClient } from \"../../core\";\nimport { msTeamsProviderKey } from \"../../core/utils\";\nimport { useMsTeamsConnectionStatus } from \"../hooks\";\n\nexport interface KnockMsTeamsProviderState {\n knockMsTeamsChannelId: string;\n tenantId: string;\n connectionStatus: ConnectionStatus;\n setConnectionStatus: (connectionStatus: ConnectionStatus) => void;\n errorLabel: string | null;\n setErrorLabel: (label: string) => void;\n actionLabel: string | null;\n setActionLabel: (label: string | null) => void;\n popupWindowRef: React.MutableRefObject<Window | null>;\n}\n\nconst MsTeamsProviderStateContext =\n React.createContext<KnockMsTeamsProviderState | null>(null);\n\nexport interface KnockMsTeamsProviderProps {\n knockMsTeamsChannelId: string;\n tenantId: string;\n}\n\nexport const KnockMsTeamsProvider: React.FC<\n PropsWithChildren<KnockMsTeamsProviderProps>\n> = ({ knockMsTeamsChannelId, tenantId, children }) => {\n const knock = useKnockClient();\n const popupWindowRef = useRef<Window | null>(null);\n\n const {\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n } = useMsTeamsConnectionStatus(knock, knockMsTeamsChannelId, tenantId);\n\n return (\n <MsTeamsProviderStateContext.Provider\n key={msTeamsProviderKey({\n knockMsTeamsChannelId,\n tenantId,\n connectionStatus,\n errorLabel,\n })}\n value={{\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n knockMsTeamsChannelId,\n tenantId,\n popupWindowRef,\n }}\n >\n {children}\n </MsTeamsProviderStateContext.Provider>\n );\n};\n\nexport const useKnockMsTeamsClient = (): KnockMsTeamsProviderState => {\n const context = React.useContext(MsTeamsProviderStateContext);\n if (!context) {\n throw new Error(\n \"useKnockMsTeamsClient must be used within a KnockMsTeamsProvider\",\n );\n }\n return context;\n};\n"],"names":["MsTeamsProviderStateContext","React","createContext","KnockMsTeamsProvider","knockMsTeamsChannelId","tenantId","children","knock","useKnockClient","popupWindowRef","useRef","connectionStatus","setConnectionStatus","errorLabel","setErrorLabel","actionLabel","setActionLabel","useMsTeamsConnectionStatus","msTeamsProviderKey","useKnockMsTeamsClient","context","useContext","Error"],"mappings":"ktBAmBMA,EACJC,EAAMC,cAAgD,IAAI,EAO/CC,EAETA,CAAC,CAAEC,sBAAAA,EAAuBC,SAAAA,EAAUC,SAAAA,CAAS,IAAM,CACrD,MAAMC,EAAQC,EAAAA,eAAe,EACvBC,EAAiBC,SAAsB,IAAI,EAE3C,CACJC,iBAAAA,EACAC,oBAAAA,EACAC,WAAAA,EACAC,cAAAA,EACAC,YAAAA,EACAC,eAAAA,CACEC,EAAAA,EAA2BV,EAAOH,EAAuBC,CAAQ,EAErE,OACGJ,EAAA,cAAAD,EAA4B,SAA5B,CACC,IAAKkB,qBAAmB,CACtBd,sBAAAA,EACAC,SAAAA,EACAM,iBAAAA,EACAE,WAAAA,CACD,CAAA,EACD,MAAO,CACLF,iBAAAA,EACAC,oBAAAA,EACAC,WAAAA,EACAC,cAAAA,EACAC,YAAAA,EACAC,eAAAA,EACAZ,sBAAAA,EACAC,SAAAA,EACAI,eAAAA,IAGDH,CACH,CAEJ,EAEaa,EAAwBA,IAAiC,CAC9DC,MAAAA,EAAUnB,EAAMoB,WAAWrB,CAA2B,EAC5D,GAAI,CAACoB,EACG,MAAA,IAAIE,MACR,kEACF,EAEKF,OAAAA,CACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"useMsTeamsConnectionStatus.js","sources":["../../../../../src/modules/ms-teams/hooks/useMsTeamsConnectionStatus.ts"],"sourcesContent":["import Knock from \"@knocklabs/client\";\nimport { useEffect, useState } from \"react\";\n\nimport { useTranslations } from \"../../i18n\";\n\nexport type ConnectionStatus =\n | \"connecting\"\n | \"connected\"\n | \"disconnected\"\n | \"error\"\n | \"disconnecting\";\n\ntype UseMsTeamsConnectionStatusOutput = {\n connectionStatus: ConnectionStatus;\n setConnectionStatus: (status: ConnectionStatus) => void;\n errorLabel: string | null;\n setErrorLabel: (errorLabel: string) => void;\n actionLabel: string | null;\n setActionLabel: (actionLabel: string | null) => void;\n};\n\nfunction useMsTeamsConnectionStatus(\n knock: Knock,\n knockMsTeamsChannelId: string,\n tenantId: string,\n): UseMsTeamsConnectionStatusOutput {\n const { t } = useTranslations();\n\n const [connectionStatus, setConnectionStatus] =\n useState<ConnectionStatus>(\"connecting\");\n const [errorLabel, setErrorLabel] = useState<string | null>(null);\n const [actionLabel, setActionLabel] = useState<string | null>(null);\n\n useEffect(() => {\n const checkAuthStatus = async () => {\n if (connectionStatus !== \"connecting\") return;\n\n try {\n const authRes = await knock.msTeams.authCheck({\n tenant: tenantId,\n knockChannelId: knockMsTeamsChannelId,\n });\n\n if (authRes.connection?.ok === true) {\n return setConnectionStatus(\"connected\");\n }\n\n if (authRes.connection?.ok === false) {\n return setConnectionStatus(\"disconnected\");\n }\n\n // This is a normal response for a tenant that doesn't have\n // ms_teams_tenant_id set on it, meaning it's not connected to MS Teams,\n // so we give it a \"disconnected\" status instead of an error status.\n if (\n authRes.code === \"ERR_BAD_REQUEST\" &&\n authRes.response?.data?.message === t(\"msTeamsTenantIdNotSet\")\n ) {\n return setConnectionStatus(\"disconnected\");\n }\n\n // This is for any Knock errors that would require a reconnect.\n setConnectionStatus(\"error\");\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n };\n\n checkAuthStatus();\n }, [connectionStatus, tenantId, knockMsTeamsChannelId, knock.msTeams, t]);\n\n return {\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n };\n}\n\nexport default useMsTeamsConnectionStatus;\n"],"names":["useMsTeamsConnectionStatus","knock","knockMsTeamsChannelId","tenantId","t","useTranslations","connectionStatus","setConnectionStatus","useState","errorLabel","setErrorLabel","actionLabel","setActionLabel","useEffect","authRes","msTeams","authCheck","tenant","knockChannelId","connection","ok","code","response","data","message"],"mappings":"gJAqBA,SAASA,EACPC,EACAC,EACAC,EACkC,CAC5B,KAAA,CAAEC,EAAAA,GAAMC,kBAAgB,EAExB,CAACC,EAAkBC,CAAmB,EAC1CC,EAAAA,SAA2B,YAAY,EACnC,CAACC,EAAYC,CAAa,EAAIF,EAAAA,SAAwB,IAAI,EAC1D,CAACG,EAAaC,CAAc,EAAIJ,EAAAA,SAAwB,IAAI,EAElEK,OAAAA,EAAAA,UAAU,IAAM,EACU,SAAY,aAClC,GAAIP,IAAqB,aAErB,GAAA,CACF,MAAMQ,EAAU,MAAMb,EAAMc,QAAQC,UAAU,CAC5CC,OAAQd,EACRe,eAAgBhB,CAAAA,CACjB,EAEGY,KAAAA,EAAAA,EAAQK,aAARL,YAAAA,EAAoBM,MAAO,GAC7B,OAAOb,EAAoB,WAAW,EAWtCO,KAREA,EAAAA,EAAQK,aAARL,YAAAA,EAAoBM,MAAO,IAQ7BN,EAAQO,OAAS,qBACjBP,GAAAA,EAAAA,EAAQQ,WAARR,YAAAA,EAAkBS,OAAlBT,YAAAA,EAAwBU,WAAYpB,EAAE,uBAAuB,EAE7D,OAAOG,EAAoB,cAAc,EAI3CA,EAAoB,OAAO,OACZ,CACfA,EAAoB,OAAO,CAAA,CAE/B,GAEgB,CAAA,EACf,CAACD,EAAkBH,EAAUD,EAAuBD,EAAMc,QAASX,CAAC,CAAC,EAEjE,CACLE,iBAAAA,EACAC,oBAAAA,EACAE,WAAAA,EACAC,cAAAA,EACAC,YAAAA,EACAC,eAAAA,CACF,CACF"}
1
+ {"version":3,"file":"useMsTeamsConnectionStatus.js","sources":["../../../../../src/modules/ms-teams/hooks/useMsTeamsConnectionStatus.ts"],"sourcesContent":["import Knock from \"@knocklabs/client\";\nimport { useEffect, useState } from \"react\";\n\nimport { type ConnectionStatus } from \"../../core/types\";\nimport { useTranslations } from \"../../i18n\";\n\ntype UseMsTeamsConnectionStatusOutput = {\n connectionStatus: ConnectionStatus;\n setConnectionStatus: (status: ConnectionStatus) => void;\n errorLabel: string | null;\n setErrorLabel: (errorLabel: string) => void;\n actionLabel: string | null;\n setActionLabel: (actionLabel: string | null) => void;\n};\n\nfunction useMsTeamsConnectionStatus(\n knock: Knock,\n knockMsTeamsChannelId: string,\n tenantId: string,\n): UseMsTeamsConnectionStatusOutput {\n const { t } = useTranslations();\n\n const [connectionStatus, setConnectionStatus] =\n useState<ConnectionStatus>(\"connecting\");\n const [errorLabel, setErrorLabel] = useState<string | null>(null);\n const [actionLabel, setActionLabel] = useState<string | null>(null);\n\n useEffect(() => {\n const checkAuthStatus = async () => {\n if (connectionStatus !== \"connecting\") return;\n\n try {\n const authRes = await knock.msTeams.authCheck({\n tenant: tenantId,\n knockChannelId: knockMsTeamsChannelId,\n });\n\n if (authRes.connection?.ok === true) {\n return setConnectionStatus(\"connected\");\n }\n\n if (authRes.connection?.ok === false) {\n return setConnectionStatus(\"disconnected\");\n }\n\n // This is a normal response for a tenant that doesn't have\n // ms_teams_tenant_id set on it, meaning it's not connected to MS Teams,\n // so we give it a \"disconnected\" status instead of an error status.\n if (\n authRes.code === \"ERR_BAD_REQUEST\" &&\n authRes.response?.data?.message === t(\"msTeamsTenantIdNotSet\")\n ) {\n return setConnectionStatus(\"disconnected\");\n }\n\n // This is for any Knock errors that would require a reconnect.\n setConnectionStatus(\"error\");\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n };\n\n checkAuthStatus();\n }, [connectionStatus, tenantId, knockMsTeamsChannelId, knock.msTeams, t]);\n\n return {\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n };\n}\n\nexport default useMsTeamsConnectionStatus;\n"],"names":["useMsTeamsConnectionStatus","knock","knockMsTeamsChannelId","tenantId","t","useTranslations","connectionStatus","setConnectionStatus","useState","errorLabel","setErrorLabel","actionLabel","setActionLabel","useEffect","authRes","msTeams","authCheck","tenant","knockChannelId","connection","ok","code","response","data","message"],"mappings":"gJAeA,SAASA,EACPC,EACAC,EACAC,EACkC,CAC5B,KAAA,CAAEC,EAAAA,GAAMC,kBAAgB,EAExB,CAACC,EAAkBC,CAAmB,EAC1CC,EAAAA,SAA2B,YAAY,EACnC,CAACC,EAAYC,CAAa,EAAIF,EAAAA,SAAwB,IAAI,EAC1D,CAACG,EAAaC,CAAc,EAAIJ,EAAAA,SAAwB,IAAI,EAElEK,OAAAA,EAAAA,UAAU,IAAM,EACU,SAAY,aAClC,GAAIP,IAAqB,aAErB,GAAA,CACF,MAAMQ,EAAU,MAAMb,EAAMc,QAAQC,UAAU,CAC5CC,OAAQd,EACRe,eAAgBhB,CAAAA,CACjB,EAEGY,KAAAA,EAAAA,EAAQK,aAARL,YAAAA,EAAoBM,MAAO,GAC7B,OAAOb,EAAoB,WAAW,EAWtCO,KAREA,EAAAA,EAAQK,aAARL,YAAAA,EAAoBM,MAAO,IAQ7BN,EAAQO,OAAS,qBACjBP,GAAAA,EAAAA,EAAQQ,WAARR,YAAAA,EAAkBS,OAAlBT,YAAAA,EAAwBU,WAAYpB,EAAE,uBAAuB,EAE7D,OAAOG,EAAoB,cAAc,EAI3CA,EAAoB,OAAO,OACZ,CACfA,EAAoB,OAAO,CAAA,CAE/B,GAEgB,CAAA,EACf,CAACD,EAAkBH,EAAUD,EAAuBD,EAAMc,QAASX,CAAC,CAAC,EAEjE,CACLE,iBAAAA,EACAC,oBAAAA,EACAE,WAAAA,EACAC,cAAAA,EACAC,YAAAA,EACAC,eAAAA,CACF,CACF"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../hooks/useSlackConnectionStatus.js"),b=require("react");require("swr/infinite");const f=require("../../core/context/KnockProvider.js");require("@knocklabs/client");require("fast-deep-equal");const v=require("../../core/utils.js");require("swr");require("../../i18n/context/KnockI18nProvider.js");function C(e){if(e&&typeof e=="object"&&"default"in e)return e;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const o=C(b),i=o.createContext(null),P=e=>{const{knockSlackChannelId:t,children:r}=e,n="tenantId"in e?e.tenantId:e.tenant,u=f.useKnockClient(),{connectionStatus:c,setConnectionStatus:l,errorLabel:a,setErrorLabel:s,actionLabel:k,setActionLabel:d}=S(u,t,n);return o.createElement(i.Provider,{key:v.slackProviderKey({knockSlackChannelId:t,tenantId:n,connectionStatus:c,errorLabel:a}),value:{connectionStatus:c,setConnectionStatus:l,errorLabel:a,setErrorLabel:s,actionLabel:k,setActionLabel:d,knockSlackChannelId:t,tenant:n,tenantId:n}},r)},q=()=>{const e=o.useContext(i);if(e===void 0)throw new Error("useKnockSlackClient must be used within a KnockSlackProvider");return e};exports.KnockSlackProvider=P;exports.useKnockSlackClient=q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("../hooks/useSlackConnectionStatus.js"),a=require("react");require("swr/infinite");const v=require("../../core/context/KnockProvider.js");require("@knocklabs/client");require("fast-deep-equal");const C=require("../../core/utils.js");require("swr");require("../../i18n/context/KnockI18nProvider.js");function P(e){if(e&&typeof e=="object"&&"default"in e)return e;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const o=P(a),u=o.createContext(null),q=e=>{const{knockSlackChannelId:t,children:r}=e,n="tenantId"in e?e.tenantId:e.tenant,l=v.useKnockClient(),s=a.useRef(null),{connectionStatus:c,setConnectionStatus:k,errorLabel:i,setErrorLabel:d,actionLabel:S,setActionLabel:f}=b(l,t,n);return o.createElement(u.Provider,{key:C.slackProviderKey({knockSlackChannelId:t,tenantId:n,connectionStatus:c,errorLabel:i}),value:{connectionStatus:c,setConnectionStatus:k,errorLabel:i,setErrorLabel:d,actionLabel:S,setActionLabel:f,knockSlackChannelId:t,tenant:n,tenantId:n,popupWindowRef:s}},r)},K=()=>{const e=o.useContext(u);if(e===void 0)throw new Error("useKnockSlackClient must be used within a KnockSlackProvider");return e};exports.KnockSlackProvider=q;exports.useKnockSlackClient=K;
2
2
  //# sourceMappingURL=KnockSlackProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"KnockSlackProvider.js","sources":["../../../../../src/modules/slack/context/KnockSlackProvider.tsx"],"sourcesContent":["import { useSlackConnectionStatus } from \"..\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { slackProviderKey } from \"../../core\";\nimport { useKnockClient } from \"../../core\";\nimport { ConnectionStatus } from \"../hooks/useSlackConnectionStatus\";\n\nexport interface KnockSlackProviderState {\n knockSlackChannelId: string;\n tenantId: string;\n /**\n * @deprecated Use `tenantId` instead. This field will be removed in a future release.\n */\n tenant: string;\n connectionStatus: ConnectionStatus;\n setConnectionStatus: (connectionStatus: ConnectionStatus) => void;\n errorLabel: string | null;\n setErrorLabel: (label: string) => void;\n actionLabel: string | null;\n setActionLabel: (label: string | null) => void;\n}\n\nconst SlackProviderStateContext =\n React.createContext<KnockSlackProviderState | null>(null);\n\nexport type KnockSlackProviderProps =\n | {\n knockSlackChannelId: string;\n /**\n * @deprecated Use `tenantId` instead. This field will be removed in a future release.\n */\n tenant: string;\n }\n | {\n knockSlackChannelId: string;\n tenantId: string;\n };\n\nexport const KnockSlackProvider: React.FC<\n PropsWithChildren<KnockSlackProviderProps>\n> = (props) => {\n const { knockSlackChannelId, children } = props;\n const tenantId = \"tenantId\" in props ? props.tenantId : props.tenant;\n\n const knock = useKnockClient();\n\n const {\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n } = useSlackConnectionStatus(knock, knockSlackChannelId, tenantId);\n\n return (\n <SlackProviderStateContext.Provider\n key={slackProviderKey({\n knockSlackChannelId,\n tenantId,\n connectionStatus,\n errorLabel,\n })}\n value={{\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n knockSlackChannelId,\n // Assign the same value to both tenant and tenantId for backwards compatibility\n tenant: tenantId,\n tenantId,\n }}\n >\n {children}\n </SlackProviderStateContext.Provider>\n );\n};\n\nexport const useKnockSlackClient = (): KnockSlackProviderState => {\n const context = React.useContext(\n SlackProviderStateContext,\n ) as KnockSlackProviderState;\n if (context === undefined) {\n throw new Error(\n \"useKnockSlackClient must be used within a KnockSlackProvider\",\n );\n }\n return context as KnockSlackProviderState;\n};\n"],"names":["SlackProviderStateContext","React","createContext","KnockSlackProvider","props","knockSlackChannelId","children","tenantId","tenant","knock","useKnockClient","connectionStatus","setConnectionStatus","errorLabel","setErrorLabel","actionLabel","setActionLabel","useSlackConnectionStatus","slackProviderKey","useKnockSlackClient","context","useContext","undefined","Error"],"mappings":"stBAuBMA,EACJC,EAAMC,cAA8C,IAAI,EAe7CC,EAEEC,GAAA,CACP,KAAA,CAAEC,oBAAAA,EAAqBC,SAAAA,CAAAA,EAAaF,EACpCG,EAAW,aAAcH,EAAQA,EAAMG,SAAWH,EAAMI,OAExDC,EAAQC,EAAAA,eAAe,EAEvB,CACJC,iBAAAA,EACAC,oBAAAA,EACAC,WAAAA,EACAC,cAAAA,EACAC,YAAAA,EACAC,eAAAA,CACEC,EAAAA,EAAyBR,EAAOJ,EAAqBE,CAAQ,EAEjE,OACGN,EAAA,cAAAD,EAA0B,SAA1B,CACC,IAAKkB,mBAAiB,CACpBb,oBAAAA,EACAE,SAAAA,EACAI,iBAAAA,EACAE,WAAAA,CACD,CAAA,EACD,MAAO,CACLF,iBAAAA,EACAC,oBAAAA,EACAC,WAAAA,EACAC,cAAAA,EACAC,YAAAA,EACAC,eAAAA,EACAX,oBAAAA,EAEAG,OAAQD,EACRA,SAAAA,IAGDD,CACH,CAEJ,EAEaa,EAAsBA,IAA+B,CAC1DC,MAAAA,EAAUnB,EAAMoB,WACpBrB,CACF,EACA,GAAIoB,IAAYE,OACR,MAAA,IAAIC,MACR,8DACF,EAEKH,OAAAA,CACT"}
1
+ {"version":3,"file":"KnockSlackProvider.js","sources":["../../../../../src/modules/slack/context/KnockSlackProvider.tsx"],"sourcesContent":["import { useSlackConnectionStatus } from \"..\";\nimport * as React from \"react\";\nimport { PropsWithChildren, useRef } from \"react\";\n\nimport { type ConnectionStatus, slackProviderKey } from \"../../core\";\nimport { useKnockClient } from \"../../core\";\n\nexport interface KnockSlackProviderState {\n knockSlackChannelId: string;\n tenantId: string;\n /**\n * @deprecated Use `tenantId` instead. This field will be removed in a future release.\n */\n tenant: string;\n connectionStatus: ConnectionStatus;\n setConnectionStatus: (connectionStatus: ConnectionStatus) => void;\n errorLabel: string | null;\n setErrorLabel: (label: string) => void;\n actionLabel: string | null;\n setActionLabel: (label: string | null) => void;\n popupWindowRef: React.MutableRefObject<Window | null>;\n}\n\nconst SlackProviderStateContext =\n React.createContext<KnockSlackProviderState | null>(null);\n\nexport type KnockSlackProviderProps =\n | {\n knockSlackChannelId: string;\n /**\n * @deprecated Use `tenantId` instead. This field will be removed in a future release.\n */\n tenant: string;\n }\n | {\n knockSlackChannelId: string;\n tenantId: string;\n };\n\nexport const KnockSlackProvider: React.FC<\n PropsWithChildren<KnockSlackProviderProps>\n> = (props) => {\n const { knockSlackChannelId, children } = props;\n const tenantId = \"tenantId\" in props ? props.tenantId : props.tenant;\n\n const knock = useKnockClient();\n const popupWindowRef = useRef<Window | null>(null);\n\n const {\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n } = useSlackConnectionStatus(knock, knockSlackChannelId, tenantId);\n\n return (\n <SlackProviderStateContext.Provider\n key={slackProviderKey({\n knockSlackChannelId,\n tenantId,\n connectionStatus,\n errorLabel,\n })}\n value={{\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n knockSlackChannelId,\n // Assign the same value to both tenant and tenantId for backwards compatibility\n tenant: tenantId,\n tenantId,\n popupWindowRef,\n }}\n >\n {children}\n </SlackProviderStateContext.Provider>\n );\n};\n\nexport const useKnockSlackClient = (): KnockSlackProviderState => {\n const context = React.useContext(\n SlackProviderStateContext,\n ) as KnockSlackProviderState;\n if (context === undefined) {\n throw new Error(\n \"useKnockSlackClient must be used within a KnockSlackProvider\",\n );\n }\n return context as KnockSlackProviderState;\n};\n"],"names":["SlackProviderStateContext","React","createContext","KnockSlackProvider","props","knockSlackChannelId","children","tenantId","tenant","knock","useKnockClient","popupWindowRef","useRef","connectionStatus","setConnectionStatus","errorLabel","setErrorLabel","actionLabel","setActionLabel","useSlackConnectionStatus","slackProviderKey","useKnockSlackClient","context","useContext","undefined","Error"],"mappings":"stBAuBMA,EACJC,EAAMC,cAA8C,IAAI,EAe7CC,EAEEC,GAAA,CACP,KAAA,CAAEC,oBAAAA,EAAqBC,SAAAA,CAAAA,EAAaF,EACpCG,EAAW,aAAcH,EAAQA,EAAMG,SAAWH,EAAMI,OAExDC,EAAQC,EAAAA,eAAe,EACvBC,EAAiBC,SAAsB,IAAI,EAE3C,CACJC,iBAAAA,EACAC,oBAAAA,EACAC,WAAAA,EACAC,cAAAA,EACAC,YAAAA,EACAC,eAAAA,CACEC,EAAAA,EAAyBV,EAAOJ,EAAqBE,CAAQ,EAEjE,OACGN,EAAA,cAAAD,EAA0B,SAA1B,CACC,IAAKoB,mBAAiB,CACpBf,oBAAAA,EACAE,SAAAA,EACAM,iBAAAA,EACAE,WAAAA,CACD,CAAA,EACD,MAAO,CACLF,iBAAAA,EACAC,oBAAAA,EACAC,WAAAA,EACAC,cAAAA,EACAC,YAAAA,EACAC,eAAAA,EACAb,oBAAAA,EAEAG,OAAQD,EACRA,SAAAA,EACAI,eAAAA,IAGDL,CACH,CAEJ,EAEae,EAAsBA,IAA+B,CAC1DC,MAAAA,EAAUrB,EAAMsB,WACpBvB,CACF,EACA,GAAIsB,IAAYE,OACR,MAAA,IAAIC,MACR,8DACF,EAEKH,OAAAA,CACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"useSlackConnectionStatus.js","sources":["../../../../../src/modules/slack/hooks/useSlackConnectionStatus.ts"],"sourcesContent":["import Knock from \"@knocklabs/client\";\nimport { useEffect, useState } from \"react\";\n\nimport { useTranslations } from \"../../i18n\";\n\nexport type ConnectionStatus =\n | \"connecting\"\n | \"connected\"\n | \"disconnected\"\n | \"error\"\n | \"disconnecting\";\n\ntype UseSlackConnectionStatusOutput = {\n connectionStatus: ConnectionStatus;\n setConnectionStatus: (status: ConnectionStatus) => void;\n errorLabel: string | null;\n setErrorLabel: (errorLabel: string) => void;\n actionLabel: string | null;\n setActionLabel: (actionLabel: string | null) => void;\n};\n\n/**\n * Transforms a slack error message into\n * a formatted one. Slack error messages: https://api.slack.com/methods/auth.test#errors\n *\n * Ex.: \"account_inactive\" -> \"Account inactive\"\n */\nconst formatSlackErrorMessage = (errorMessage: string) => {\n const firstLetter = errorMessage.substring(0, 1).toUpperCase();\n const rest = errorMessage.substring(1);\n return firstLetter?.concat(rest).replace(\"_\", \" \");\n};\n\nfunction useSlackConnectionStatus(\n knock: Knock,\n knockSlackChannelId: string,\n tenantId: string,\n): UseSlackConnectionStatusOutput {\n const { t } = useTranslations();\n const [connectionStatus, setConnectionStatus] =\n useState<ConnectionStatus>(\"connecting\");\n const [errorLabel, setErrorLabel] = useState<string | null>(null);\n const [actionLabel, setActionLabel] = useState<string | null>(null);\n\n useEffect(() => {\n const checkAuthStatus = async () => {\n if (connectionStatus !== \"connecting\") return;\n\n try {\n const authRes = await knock.slack.authCheck({\n tenant: tenantId,\n knockChannelId: knockSlackChannelId,\n });\n\n if (authRes.connection?.ok) {\n return setConnectionStatus(\"connected\");\n }\n\n // This is a normal response for a tenant that doesn't have an access\n // token set on it, meaning it's not connected to Slack, so we\n // give it a \"disconnected\" status instead of an error status.\n if (\n authRes.code === \"ERR_BAD_REQUEST\" &&\n authRes.response?.data?.message === t(\"slackAccessTokenNotSet\")\n ) {\n return setConnectionStatus(\"disconnected\");\n }\n\n // This is for an error coming directly from Slack.\n if (authRes.connection && authRes.connection.error) {\n const errorLabel = formatSlackErrorMessage(authRes.connection.error);\n setErrorLabel(errorLabel);\n setConnectionStatus(\"error\");\n return;\n }\n\n if (authRes.connection) {\n return setConnectionStatus(\"disconnected\");\n }\n\n setConnectionStatus(\"error\");\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n };\n\n checkAuthStatus();\n }, [connectionStatus, tenantId, knockSlackChannelId, knock.slack, t]);\n\n return {\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n };\n}\n\nexport default useSlackConnectionStatus;\n"],"names":["formatSlackErrorMessage","errorMessage","firstLetter","substring","toUpperCase","rest","concat","replace","useSlackConnectionStatus","knock","knockSlackChannelId","tenantId","t","useTranslations","connectionStatus","setConnectionStatus","useState","errorLabel","setErrorLabel","actionLabel","setActionLabel","useEffect","authRes","slack","authCheck","tenant","knockChannelId","connection","ok","code","response","data","message","error"],"mappings":"gJA2BMA,EAA2BC,GAAyB,CACxD,MAAMC,EAAcD,EAAaE,UAAU,EAAG,CAAC,EAAEC,YAAY,EACvDC,EAAOJ,EAAaE,UAAU,CAAC,EACrC,OAAOD,GAAAA,YAAAA,EAAaI,OAAOD,GAAME,QAAQ,IAAK,IAChD,EAEA,SAASC,EACPC,EACAC,EACAC,EACgC,CAC1B,KAAA,CAAEC,EAAAA,GAAMC,kBAAgB,EACxB,CAACC,EAAkBC,CAAmB,EAC1CC,EAAAA,SAA2B,YAAY,EACnC,CAACC,EAAYC,CAAa,EAAIF,EAAAA,SAAwB,IAAI,EAC1D,CAACG,EAAaC,CAAc,EAAIJ,EAAAA,SAAwB,IAAI,EAElEK,OAAAA,EAAAA,UAAU,IAAM,EACU,SAAY,WAClC,GAAIP,IAAqB,aAErB,GAAA,CACF,MAAMQ,EAAU,MAAMb,EAAMc,MAAMC,UAAU,CAC1CC,OAAQd,EACRe,eAAgBhB,CAAAA,CACjB,EAEGY,IAAAA,EAAAA,EAAQK,aAARL,MAAAA,EAAoBM,GACtB,OAAOb,EAAoB,WAAW,EAOtCO,GAAAA,EAAQO,OAAS,qBACjBP,GAAAA,EAAAA,EAAQQ,WAARR,YAAAA,EAAkBS,OAAlBT,YAAAA,EAAwBU,WAAYpB,EAAE,wBAAwB,EAE9D,OAAOG,EAAoB,cAAc,EAI3C,GAAIO,EAAQK,YAAcL,EAAQK,WAAWM,MAAO,CAClD,MAAMhB,EAAajB,EAAwBsB,EAAQK,WAAWM,KAAK,EACnEf,EAAcD,CAAU,EACxBF,EAAoB,OAAO,EAC3B,MAAA,CAGF,GAAIO,EAAQK,WACV,OAAOZ,EAAoB,cAAc,EAG3CA,EAAoB,OAAO,OACZ,CACfA,EAAoB,OAAO,CAAA,CAE/B,GAEgB,CAAA,EACf,CAACD,EAAkBH,EAAUD,EAAqBD,EAAMc,MAAOX,CAAC,CAAC,EAE7D,CACLE,iBAAAA,EACAC,oBAAAA,EACAE,WAAAA,EACAC,cAAAA,EACAC,YAAAA,EACAC,eAAAA,CACF,CACF"}
1
+ {"version":3,"file":"useSlackConnectionStatus.js","sources":["../../../../../src/modules/slack/hooks/useSlackConnectionStatus.ts"],"sourcesContent":["import Knock from \"@knocklabs/client\";\nimport { useEffect, useState } from \"react\";\n\nimport { type ConnectionStatus } from \"../../core/types\";\nimport { useTranslations } from \"../../i18n\";\n\ntype UseSlackConnectionStatusOutput = {\n connectionStatus: ConnectionStatus;\n setConnectionStatus: (status: ConnectionStatus) => void;\n errorLabel: string | null;\n setErrorLabel: (errorLabel: string) => void;\n actionLabel: string | null;\n setActionLabel: (actionLabel: string | null) => void;\n};\n\n/**\n * Transforms a slack error message into\n * a formatted one. Slack error messages: https://api.slack.com/methods/auth.test#errors\n *\n * Ex.: \"account_inactive\" -> \"Account inactive\"\n */\nconst formatSlackErrorMessage = (errorMessage: string) => {\n const firstLetter = errorMessage.substring(0, 1).toUpperCase();\n const rest = errorMessage.substring(1);\n return firstLetter?.concat(rest).replace(\"_\", \" \");\n};\n\nfunction useSlackConnectionStatus(\n knock: Knock,\n knockSlackChannelId: string,\n tenantId: string,\n): UseSlackConnectionStatusOutput {\n const { t } = useTranslations();\n const [connectionStatus, setConnectionStatus] =\n useState<ConnectionStatus>(\"connecting\");\n const [errorLabel, setErrorLabel] = useState<string | null>(null);\n const [actionLabel, setActionLabel] = useState<string | null>(null);\n\n useEffect(() => {\n const checkAuthStatus = async () => {\n if (connectionStatus !== \"connecting\") return;\n\n try {\n const authRes = await knock.slack.authCheck({\n tenant: tenantId,\n knockChannelId: knockSlackChannelId,\n });\n\n if (authRes.connection?.ok) {\n return setConnectionStatus(\"connected\");\n }\n\n // This is a normal response for a tenant that doesn't have an access\n // token set on it, meaning it's not connected to Slack, so we\n // give it a \"disconnected\" status instead of an error status.\n if (\n authRes.code === \"ERR_BAD_REQUEST\" &&\n authRes.response?.data?.message === t(\"slackAccessTokenNotSet\")\n ) {\n return setConnectionStatus(\"disconnected\");\n }\n\n // This is for an error coming directly from Slack.\n if (authRes.connection && authRes.connection.error) {\n const errorLabel = formatSlackErrorMessage(authRes.connection.error);\n setErrorLabel(errorLabel);\n setConnectionStatus(\"error\");\n return;\n }\n\n if (authRes.connection) {\n return setConnectionStatus(\"disconnected\");\n }\n\n setConnectionStatus(\"error\");\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n };\n\n checkAuthStatus();\n }, [connectionStatus, tenantId, knockSlackChannelId, knock.slack, t]);\n\n return {\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n };\n}\n\nexport default useSlackConnectionStatus;\n"],"names":["formatSlackErrorMessage","errorMessage","firstLetter","substring","toUpperCase","rest","concat","replace","useSlackConnectionStatus","knock","knockSlackChannelId","tenantId","t","useTranslations","connectionStatus","setConnectionStatus","useState","errorLabel","setErrorLabel","actionLabel","setActionLabel","useEffect","authRes","slack","authCheck","tenant","knockChannelId","connection","ok","code","response","data","message","error"],"mappings":"gJAqBMA,EAA2BC,GAAyB,CACxD,MAAMC,EAAcD,EAAaE,UAAU,EAAG,CAAC,EAAEC,YAAY,EACvDC,EAAOJ,EAAaE,UAAU,CAAC,EACrC,OAAOD,GAAAA,YAAAA,EAAaI,OAAOD,GAAME,QAAQ,IAAK,IAChD,EAEA,SAASC,EACPC,EACAC,EACAC,EACgC,CAC1B,KAAA,CAAEC,EAAAA,GAAMC,kBAAgB,EACxB,CAACC,EAAkBC,CAAmB,EAC1CC,EAAAA,SAA2B,YAAY,EACnC,CAACC,EAAYC,CAAa,EAAIF,EAAAA,SAAwB,IAAI,EAC1D,CAACG,EAAaC,CAAc,EAAIJ,EAAAA,SAAwB,IAAI,EAElEK,OAAAA,EAAAA,UAAU,IAAM,EACU,SAAY,WAClC,GAAIP,IAAqB,aAErB,GAAA,CACF,MAAMQ,EAAU,MAAMb,EAAMc,MAAMC,UAAU,CAC1CC,OAAQd,EACRe,eAAgBhB,CAAAA,CACjB,EAEGY,IAAAA,EAAAA,EAAQK,aAARL,MAAAA,EAAoBM,GACtB,OAAOb,EAAoB,WAAW,EAOtCO,GAAAA,EAAQO,OAAS,qBACjBP,GAAAA,EAAAA,EAAQQ,WAARR,YAAAA,EAAkBS,OAAlBT,YAAAA,EAAwBU,WAAYpB,EAAE,wBAAwB,EAE9D,OAAOG,EAAoB,cAAc,EAI3C,GAAIO,EAAQK,YAAcL,EAAQK,WAAWM,MAAO,CAClD,MAAMhB,EAAajB,EAAwBsB,EAAQK,WAAWM,KAAK,EACnEf,EAAcD,CAAU,EACxBF,EAAoB,OAAO,EAC3B,MAAA,CAGF,GAAIO,EAAQK,WACV,OAAOZ,EAAoB,cAAc,EAG3CA,EAAoB,OAAO,OACZ,CACfA,EAAoB,OAAO,CAAA,CAE/B,GAEgB,CAAA,EACf,CAACD,EAAkBH,EAAUD,EAAqBD,EAAMc,MAAOX,CAAC,CAAC,EAE7D,CACLE,iBAAAA,EACAC,oBAAAA,EACAE,WAAAA,EACAC,cAAAA,EACAC,YAAAA,EACAC,eAAAA,CACF,CACF"}
@@ -1,74 +1,78 @@
1
1
  import { KnockProvider as t, useKnockClient as r } from "./modules/core/context/KnockProvider.mjs";
2
2
  import { default as a } from "./modules/core/hooks/useAuthenticatedKnockClient.mjs";
3
- import { default as u } from "./modules/core/hooks/useStableOptions.mjs";
4
- import { FilterStatus as m } from "./modules/core/constants.mjs";
5
- import { feedProviderKey as l, formatBadgeCount as i, formatTimestamp as x, msTeamsProviderKey as c, renderNodeOrFallback as p, slackProviderKey as k, toSentenceCase as C } from "./modules/core/utils.mjs";
6
- import { KnockFeedProvider as S, useKnockFeed as T } from "./modules/feed/context/KnockFeedProvider.mjs";
7
- import { default as v } from "./modules/feed/hooks/useNotifications.mjs";
8
- import { default as M } from "./modules/feed/hooks/useFeedSettings.mjs";
9
- import { useCreateNotificationStore as G, default as N } from "./modules/feed/hooks/useNotificationStore.mjs";
10
- import { KnockGuideContext as A, KnockGuideProvider as b } from "./modules/guide/context/KnockGuideProvider.mjs";
11
- import { useGuide as I } from "./modules/guide/hooks/useGuide.mjs";
12
- import { useGuides as B } from "./modules/guide/hooks/useGuides.mjs";
13
- import { useGuideContext as q } from "./modules/guide/hooks/useGuideContext.mjs";
14
- import { KnockMsTeamsProvider as z, useKnockMsTeamsClient as D } from "./modules/ms-teams/context/KnockMsTeamsProvider.mjs";
15
- import { default as H } from "./modules/ms-teams/hooks/useMsTeamsConnectionStatus.mjs";
16
- import { default as L } from "./modules/ms-teams/hooks/useMsTeamsAuth.mjs";
17
- import { default as R } from "./modules/ms-teams/hooks/useMsTeamsTeams.mjs";
18
- import { default as V } from "./modules/ms-teams/hooks/useMsTeamsChannels.mjs";
19
- import { default as X } from "./modules/ms-teams/hooks/useConnectedMsTeamsChannels.mjs";
20
- import { KnockSlackProvider as Z, useKnockSlackClient as _ } from "./modules/slack/context/KnockSlackProvider.mjs";
21
- import { default as ee } from "./modules/slack/hooks/useSlackConnectionStatus.mjs";
22
- import { default as te } from "./modules/slack/hooks/useSlackChannels.mjs";
23
- import { default as se } from "./modules/slack/hooks/useConnectedSlackChannels.mjs";
24
- import { default as ne } from "./modules/slack/hooks/useSlackAuth.mjs";
25
- import { I18nContext as fe, KnockI18nProvider as me } from "./modules/i18n/context/KnockI18nProvider.mjs";
26
- import { useTranslations as le } from "./modules/i18n/hooks/useTranslations.mjs";
27
- import { locales as xe } from "./modules/i18n/languages/index.mjs";
28
- import { usePreferences as pe } from "./modules/preferences/hooks/usePreferences.mjs";
29
- import { useStore as Ce } from "@tanstack/react-store";
3
+ import { default as n } from "./modules/core/hooks/useStableOptions.mjs";
4
+ import { useAuthPostMessageListener as m } from "./modules/core/hooks/useAuthPostMessageListener.mjs";
5
+ import { useAuthPolling as l } from "./modules/core/hooks/useAuthPolling.mjs";
6
+ import { FilterStatus as x } from "./modules/core/constants.mjs";
7
+ import { feedProviderKey as c, formatBadgeCount as k, formatTimestamp as C, msTeamsProviderKey as K, renderNodeOrFallback as S, slackProviderKey as P, toSentenceCase as T } from "./modules/core/utils.mjs";
8
+ import { KnockFeedProvider as v, useKnockFeed as M } from "./modules/feed/context/KnockFeedProvider.mjs";
9
+ import { default as F } from "./modules/feed/hooks/useNotifications.mjs";
10
+ import { default as g } from "./modules/feed/hooks/useFeedSettings.mjs";
11
+ import { useCreateNotificationStore as y, default as b } from "./modules/feed/hooks/useNotificationStore.mjs";
12
+ import { KnockGuideContext as O, KnockGuideProvider as B } from "./modules/guide/context/KnockGuideProvider.mjs";
13
+ import { useGuide as j } from "./modules/guide/hooks/useGuide.mjs";
14
+ import { useGuides as w } from "./modules/guide/hooks/useGuides.mjs";
15
+ import { useGuideContext as D } from "./modules/guide/hooks/useGuideContext.mjs";
16
+ import { KnockMsTeamsProvider as H, useKnockMsTeamsClient as J } from "./modules/ms-teams/context/KnockMsTeamsProvider.mjs";
17
+ import { default as R } from "./modules/ms-teams/hooks/useMsTeamsConnectionStatus.mjs";
18
+ import { default as V } from "./modules/ms-teams/hooks/useMsTeamsAuth.mjs";
19
+ import { default as X } from "./modules/ms-teams/hooks/useMsTeamsTeams.mjs";
20
+ import { default as Z } from "./modules/ms-teams/hooks/useMsTeamsChannels.mjs";
21
+ import { default as $ } from "./modules/ms-teams/hooks/useConnectedMsTeamsChannels.mjs";
22
+ import { KnockSlackProvider as oe, useKnockSlackClient as te } from "./modules/slack/context/KnockSlackProvider.mjs";
23
+ import { default as se } from "./modules/slack/hooks/useSlackConnectionStatus.mjs";
24
+ import { default as ue } from "./modules/slack/hooks/useSlackChannels.mjs";
25
+ import { default as fe } from "./modules/slack/hooks/useConnectedSlackChannels.mjs";
26
+ import { default as de } from "./modules/slack/hooks/useSlackAuth.mjs";
27
+ import { I18nContext as ie, KnockI18nProvider as xe } from "./modules/i18n/context/KnockI18nProvider.mjs";
28
+ import { useTranslations as ce } from "./modules/i18n/hooks/useTranslations.mjs";
29
+ import { locales as Ce } from "./modules/i18n/languages/index.mjs";
30
+ import { usePreferences as Se } from "./modules/preferences/hooks/usePreferences.mjs";
31
+ import { useStore as Te } from "@tanstack/react-store";
30
32
  export {
31
- m as FilterStatus,
32
- fe as I18nContext,
33
- S as KnockFeedProvider,
34
- A as KnockGuideContext,
35
- b as KnockGuideProvider,
36
- me as KnockI18nProvider,
37
- z as KnockMsTeamsProvider,
33
+ x as FilterStatus,
34
+ ie as I18nContext,
35
+ v as KnockFeedProvider,
36
+ O as KnockGuideContext,
37
+ B as KnockGuideProvider,
38
+ xe as KnockI18nProvider,
39
+ H as KnockMsTeamsProvider,
38
40
  t as KnockProvider,
39
- Z as KnockSlackProvider,
40
- l as feedProviderKey,
41
- i as formatBadgeCount,
42
- x as formatTimestamp,
43
- xe as locales,
44
- c as msTeamsProviderKey,
45
- p as renderNodeOrFallback,
46
- k as slackProviderKey,
47
- C as toSentenceCase,
41
+ oe as KnockSlackProvider,
42
+ c as feedProviderKey,
43
+ k as formatBadgeCount,
44
+ C as formatTimestamp,
45
+ Ce as locales,
46
+ K as msTeamsProviderKey,
47
+ S as renderNodeOrFallback,
48
+ P as slackProviderKey,
49
+ T as toSentenceCase,
50
+ l as useAuthPolling,
51
+ m as useAuthPostMessageListener,
48
52
  a as useAuthenticatedKnockClient,
49
- X as useConnectedMsTeamsChannels,
50
- se as useConnectedSlackChannels,
51
- G as useCreateNotificationStore,
52
- M as useFeedSettings,
53
- I as useGuide,
54
- q as useGuideContext,
55
- B as useGuides,
53
+ $ as useConnectedMsTeamsChannels,
54
+ fe as useConnectedSlackChannels,
55
+ y as useCreateNotificationStore,
56
+ g as useFeedSettings,
57
+ j as useGuide,
58
+ D as useGuideContext,
59
+ w as useGuides,
56
60
  r as useKnockClient,
57
- T as useKnockFeed,
58
- D as useKnockMsTeamsClient,
59
- _ as useKnockSlackClient,
60
- L as useMsTeamsAuth,
61
- V as useMsTeamsChannels,
62
- H as useMsTeamsConnectionStatus,
63
- R as useMsTeamsTeams,
64
- N as useNotificationStore,
65
- v as useNotifications,
66
- pe as usePreferences,
67
- ne as useSlackAuth,
68
- te as useSlackChannels,
69
- ee as useSlackConnectionStatus,
70
- u as useStableOptions,
71
- Ce as useStore,
72
- le as useTranslations
61
+ M as useKnockFeed,
62
+ J as useKnockMsTeamsClient,
63
+ te as useKnockSlackClient,
64
+ V as useMsTeamsAuth,
65
+ Z as useMsTeamsChannels,
66
+ R as useMsTeamsConnectionStatus,
67
+ X as useMsTeamsTeams,
68
+ b as useNotificationStore,
69
+ F as useNotifications,
70
+ Se as usePreferences,
71
+ de as useSlackAuth,
72
+ ue as useSlackChannels,
73
+ se as useSlackConnectionStatus,
74
+ n as useStableOptions,
75
+ Te as useStore,
76
+ ce as useTranslations
73
77
  };
74
78
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,50 @@
1
+ import { useEffect as d } from "react";
2
+ function C(s) {
3
+ const {
4
+ popupWindowRef: o,
5
+ setConnectionStatus: r,
6
+ onAuthenticationComplete: l,
7
+ authCheckFn: i
8
+ } = s;
9
+ d(
10
+ () => {
11
+ let c = 0;
12
+ const p = 90;
13
+ let n = null, u = !0;
14
+ const e = setInterval(async () => {
15
+ var a;
16
+ if (!u) {
17
+ clearInterval(e);
18
+ return;
19
+ }
20
+ const t = o.current;
21
+ if (!t)
22
+ return;
23
+ if (c++, t.closed && !n && (n = Date.now()), c >= p) {
24
+ clearInterval(e), r("error");
25
+ return;
26
+ }
27
+ if (n && Date.now() - n > 1e4) {
28
+ clearInterval(e), o.current = null;
29
+ return;
30
+ }
31
+ try {
32
+ (a = (await i()).connection) != null && a.ok && (clearInterval(e), r("connected"), l && l("authComplete"), t && !t.closed && t.close(), o.current = null);
33
+ } catch {
34
+ }
35
+ }, 2e3);
36
+ return () => {
37
+ u = !1, clearInterval(e);
38
+ };
39
+ },
40
+ // eslint-disable-next-line react-hooks/exhaustive-deps
41
+ [
42
+ // Empty deps - run once on mount and keep polling
43
+ // This is intentionally simple/brute force
44
+ ]
45
+ );
46
+ }
47
+ export {
48
+ C as useAuthPolling
49
+ };
50
+ //# sourceMappingURL=useAuthPolling.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuthPolling.mjs","sources":["../../../../../src/modules/core/hooks/useAuthPolling.ts"],"sourcesContent":["import { useEffect } from \"react\";\n\nimport { AuthCheckResult, ConnectionStatus } from \"../types\";\n\nexport interface UseAuthPollingOptions {\n popupWindowRef: React.MutableRefObject<Window | null>;\n setConnectionStatus: (status: ConnectionStatus) => void;\n authCheckFn: () => Promise<AuthCheckResult>;\n onAuthenticationComplete?: (authenticationResp: string) => void;\n}\n\n/**\n * Hook that polls an authentication check endpoint until success or timeout.\n *\n * Polls every 2 seconds for up to 3 minutes (90 iterations). Has three stop conditions:\n * 1. Max timeout reached → sets error status\n * 2. Popup closed + 10s grace period → stops silently\n * 3. Success detected via authCheckFn → updates status and closes popup\n *\n * @param options - Configuration options for the polling mechanism\n *\n * @example\n * ```tsx\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 */\nexport function useAuthPolling(options: UseAuthPollingOptions): void {\n const {\n popupWindowRef,\n setConnectionStatus,\n onAuthenticationComplete,\n authCheckFn,\n } = options;\n\n useEffect(\n () => {\n let pollCount = 0;\n const maxPolls = 90;\n let popupClosedAt: number | null = null;\n let isActive = true;\n\n const pollInterval = setInterval(async () => {\n if (!isActive) {\n clearInterval(pollInterval);\n return;\n }\n\n const popupWindow = popupWindowRef.current;\n if (!popupWindow) {\n return;\n }\n\n pollCount++;\n\n const isPopupClosed = popupWindow.closed;\n if (isPopupClosed && !popupClosedAt) {\n popupClosedAt = Date.now();\n }\n\n // Stop condition 1: Max timeout reached\n if (pollCount >= maxPolls) {\n clearInterval(pollInterval);\n setConnectionStatus(\"error\");\n return;\n }\n\n // Stop condition 2: Popup closed + grace period expired\n if (popupClosedAt && Date.now() - popupClosedAt > 10000) {\n clearInterval(pollInterval);\n popupWindowRef.current = null;\n return;\n }\n\n try {\n const authRes = await authCheckFn();\n\n // Stop condition 3: Success detected\n if (authRes.connection?.ok) {\n clearInterval(pollInterval);\n setConnectionStatus(\"connected\");\n if (onAuthenticationComplete) {\n onAuthenticationComplete(\"authComplete\");\n }\n if (popupWindow && !popupWindow.closed) {\n popupWindow.close();\n }\n popupWindowRef.current = null;\n }\n } catch (_error) {\n // Continue polling on error\n }\n }, 2000);\n\n return () => {\n isActive = false;\n clearInterval(pollInterval);\n };\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n // Empty deps - run once on mount and keep polling\n // This is intentionally simple/brute force\n ],\n );\n}\n"],"names":["useAuthPolling","options","popupWindowRef","setConnectionStatus","onAuthenticationComplete","authCheckFn","useEffect","pollCount","maxPolls","popupClosedAt","isActive","pollInterval","setInterval","clearInterval","popupWindow","current","closed","Date","now","authRes","connection","ok","close"],"mappings":";AAoCO,SAASA,EAAeC,GAAsC;AAC7D,QAAA;AAAA,IACJC,gBAAAA;AAAAA,IACAC,qBAAAA;AAAAA,IACAC,0BAAAA;AAAAA,IACAC,aAAAA;AAAAA,EAAAA,IACEJ;AAEJK,EAAAA;AAAAA,IACE,MAAM;AACJ,UAAIC,IAAY;AAChB,YAAMC,IAAW;AACjB,UAAIC,IAA+B,MAC/BC,IAAW;AAETC,YAAAA,IAAeC,YAAY,YAAY;;AAC3C,YAAI,CAACF,GAAU;AACbG,wBAAcF,CAAY;AAC1B;AAAA,QAAA;AAGF,cAAMG,IAAcZ,EAAea;AACnC,YAAI,CAACD;AACH;AAWF,YARAP,KAEsBO,EAAYE,UACb,CAACP,MACpBA,IAAgBQ,KAAKC,IAAI,IAIvBX,KAAaC,GAAU;AACzBK,wBAAcF,CAAY,GAC1BR,EAAoB,OAAO;AAC3B;AAAA,QAAA;AAIF,YAAIM,KAAiBQ,KAAKC,IAAI,IAAIT,IAAgB,KAAO;AACvDI,wBAAcF,CAAY,GAC1BT,EAAea,UAAU;AACzB;AAAA,QAAA;AAGE,YAAA;AAIEI,WAAAA,KAHY,MAAMd,EAAY,GAGtBe,eAARD,QAAAA,EAAoBE,OACtBR,cAAcF,CAAY,GAC1BR,EAAoB,WAAW,GAC3BC,KACFA,EAAyB,cAAc,GAErCU,KAAe,CAACA,EAAYE,UAC9BF,EAAYQ,MAAM,GAEpBpB,EAAea,UAAU;AAAA,gBAEZ;AAAA,QAAA;AAAA,SAGhB,GAAI;AAEP,aAAO,MAAM;AACA,QAAAL,IAAA,IACXG,cAAcF,CAAY;AAAA,MAC5B;AAAA,IACF;AAAA;AAAA,IAEA;AAAA;AAAA;AAAA,IAAA;AAAA,EAIF;AACF;"}
@@ -0,0 +1,19 @@
1
+ import { useEffect as c } from "react";
2
+ function d(u) {
3
+ const {
4
+ knockHost: a,
5
+ popupWindowRef: r,
6
+ setConnectionStatus: t,
7
+ onAuthenticationComplete: e
8
+ } = u;
9
+ c(() => {
10
+ const n = (s) => {
11
+ s.origin === a && (s.data === "authComplete" ? (t("connected"), e == null || e(s.data), r.current && !r.current.closed && r.current.close(), r.current = null) : s.data === "authFailed" && (t("error"), e == null || e(s.data), r.current = null));
12
+ };
13
+ return window.addEventListener("message", n, !1), () => window.removeEventListener("message", n);
14
+ }, [a, e, t, r]);
15
+ }
16
+ export {
17
+ d as useAuthPostMessageListener
18
+ };
19
+ //# sourceMappingURL=useAuthPostMessageListener.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuthPostMessageListener.mjs","sources":["../../../../../src/modules/core/hooks/useAuthPostMessageListener.ts"],"sourcesContent":["import { useEffect } from \"react\";\n\nimport { ConnectionStatus } from \"../types\";\n\nexport interface UseAuthPostMessageListenerOptions {\n knockHost: string;\n popupWindowRef: React.MutableRefObject<Window | null>;\n setConnectionStatus: (status: ConnectionStatus) => void;\n onAuthenticationComplete?: (authenticationResp: string) => void;\n}\n\n/**\n * Hook that listens for postMessage events from OAuth popup windows.\n *\n * Handles \"authComplete\" and \"authFailed\" messages sent from the OAuth flow popup,\n * validates the message origin, updates connection status, and closes the popup.\n *\n * @param options - Configuration options for the postMessage listener\n *\n * @example\n * ```tsx\n * useAuthPostMessageListener({\n * knockHost: knock.host,\n * popupWindowRef,\n * setConnectionStatus,\n * onAuthenticationComplete,\n * });\n * ```\n */\nexport function useAuthPostMessageListener(\n options: UseAuthPostMessageListenerOptions,\n): void {\n const {\n knockHost,\n popupWindowRef,\n setConnectionStatus,\n onAuthenticationComplete,\n } = options;\n\n useEffect(() => {\n const receiveMessage = (event: MessageEvent) => {\n // Validate message origin for security\n if (event.origin !== knockHost) {\n return;\n }\n\n if (event.data === \"authComplete\") {\n setConnectionStatus(\"connected\");\n onAuthenticationComplete?.(event.data);\n // Clear popup ref so polling stops and doesn't trigger callback again\n if (popupWindowRef.current && !popupWindowRef.current.closed) {\n popupWindowRef.current.close();\n }\n popupWindowRef.current = null;\n } else if (event.data === \"authFailed\") {\n setConnectionStatus(\"error\");\n onAuthenticationComplete?.(event.data);\n popupWindowRef.current = null;\n }\n };\n\n window.addEventListener(\"message\", receiveMessage, false);\n return () => window.removeEventListener(\"message\", receiveMessage);\n }, [\n knockHost,\n onAuthenticationComplete,\n setConnectionStatus,\n popupWindowRef,\n ]);\n}\n"],"names":["useAuthPostMessageListener","options","knockHost","popupWindowRef","setConnectionStatus","onAuthenticationComplete","useEffect","receiveMessage","event","origin","data","current","closed","close","addEventListener","window","removeEventListener"],"mappings":";AA6BO,SAASA,EACdC,GACM;AACA,QAAA;AAAA,IACJC,WAAAA;AAAAA,IACAC,gBAAAA;AAAAA,IACAC,qBAAAA;AAAAA,IACAC,0BAAAA;AAAAA,EAAAA,IACEJ;AAEJK,EAAAA,EAAU,MAAM;AACRC,UAAAA,IAAiBA,CAACC,MAAwB;AAE1CA,MAAAA,EAAMC,WAAWP,MAIjBM,EAAME,SAAS,kBACjBN,EAAoB,WAAW,GAC/BC,KAAAA,QAAAA,EAA2BG,EAAME,OAE7BP,EAAeQ,WAAW,CAACR,EAAeQ,QAAQC,UACpDT,EAAeQ,QAAQE,MAAM,GAE/BV,EAAeQ,UAAU,QAChBH,EAAME,SAAS,iBACxBN,EAAoB,OAAO,GAC3BC,KAAAA,QAAAA,EAA2BG,EAAME,OACjCP,EAAeQ,UAAU;AAAA,IAE7B;AAEOG,kBAAAA,iBAAiB,WAAWP,GAAgB,EAAK,GACjD,MAAMQ,OAAOC,oBAAoB,WAAWT,CAAc;AAAA,KAChE,CACDL,GACAG,GACAD,GACAD,CAAc,CACf;AACH;"}
@@ -1,48 +1,50 @@
1
- import * as o from "react";
2
- import { useKnockClient as l } from "../../core/context/KnockProvider.mjs";
1
+ import * as e from "react";
2
+ import { useRef as f } from "react";
3
+ import { useKnockClient as v } from "../../core/context/KnockProvider.mjs";
3
4
  import "@knocklabs/client";
4
5
  import "fast-deep-equal";
5
- import { msTeamsProviderKey as v } from "../../core/utils.mjs";
6
- import C from "../hooks/useMsTeamsConnectionStatus.mjs";
6
+ import { msTeamsProviderKey as C } from "../../core/utils.mjs";
7
+ import K from "../hooks/useMsTeamsConnectionStatus.mjs";
7
8
  import "swr/infinite";
8
9
  import "swr";
9
10
  import "../../i18n/context/KnockI18nProvider.mjs";
10
- const n = o.createContext(null), M = ({
11
- knockMsTeamsChannelId: t,
12
- tenantId: e,
11
+ const n = e.createContext(null), d = ({
12
+ knockMsTeamsChannelId: o,
13
+ tenantId: t,
13
14
  children: i
14
15
  }) => {
15
- const m = l(), {
16
+ const m = v(), c = f(null), {
16
17
  connectionStatus: r,
17
- setConnectionStatus: c,
18
+ setConnectionStatus: u,
18
19
  errorLabel: s,
19
20
  setErrorLabel: a,
20
- actionLabel: u,
21
- setActionLabel: p
22
- } = C(m, t, e);
23
- return /* @__PURE__ */ o.createElement(n.Provider, { key: v({
24
- knockMsTeamsChannelId: t,
25
- tenantId: e,
21
+ actionLabel: p,
22
+ setActionLabel: l
23
+ } = K(m, o, t);
24
+ return /* @__PURE__ */ e.createElement(n.Provider, { key: C({
25
+ knockMsTeamsChannelId: o,
26
+ tenantId: t,
26
27
  connectionStatus: r,
27
28
  errorLabel: s
28
29
  }), value: {
29
30
  connectionStatus: r,
30
- setConnectionStatus: c,
31
+ setConnectionStatus: u,
31
32
  errorLabel: s,
32
33
  setErrorLabel: a,
33
- actionLabel: u,
34
- setActionLabel: p,
35
- knockMsTeamsChannelId: t,
36
- tenantId: e
34
+ actionLabel: p,
35
+ setActionLabel: l,
36
+ knockMsTeamsChannelId: o,
37
+ tenantId: t,
38
+ popupWindowRef: c
37
39
  } }, i);
38
- }, S = () => {
39
- const t = o.useContext(n);
40
- if (!t)
40
+ }, E = () => {
41
+ const o = e.useContext(n);
42
+ if (!o)
41
43
  throw new Error("useKnockMsTeamsClient must be used within a KnockMsTeamsProvider");
42
- return t;
44
+ return o;
43
45
  };
44
46
  export {
45
- M as KnockMsTeamsProvider,
46
- S as useKnockMsTeamsClient
47
+ d as KnockMsTeamsProvider,
48
+ E as useKnockMsTeamsClient
47
49
  };
48
50
  //# sourceMappingURL=KnockMsTeamsProvider.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"KnockMsTeamsProvider.mjs","sources":["../../../../../src/modules/ms-teams/context/KnockMsTeamsProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { useKnockClient } from \"../../core\";\nimport { msTeamsProviderKey } from \"../../core/utils\";\nimport { useMsTeamsConnectionStatus } from \"../hooks\";\nimport { ConnectionStatus } from \"../hooks/useMsTeamsConnectionStatus\";\n\nexport interface KnockMsTeamsProviderState {\n knockMsTeamsChannelId: string;\n tenantId: string;\n connectionStatus: ConnectionStatus;\n setConnectionStatus: (connectionStatus: ConnectionStatus) => void;\n errorLabel: string | null;\n setErrorLabel: (label: string) => void;\n actionLabel: string | null;\n setActionLabel: (label: string | null) => void;\n}\n\nconst MsTeamsProviderStateContext =\n React.createContext<KnockMsTeamsProviderState | null>(null);\n\nexport interface KnockMsTeamsProviderProps {\n knockMsTeamsChannelId: string;\n tenantId: string;\n}\n\nexport const KnockMsTeamsProvider: React.FC<\n PropsWithChildren<KnockMsTeamsProviderProps>\n> = ({ knockMsTeamsChannelId, tenantId, children }) => {\n const knock = useKnockClient();\n\n const {\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n } = useMsTeamsConnectionStatus(knock, knockMsTeamsChannelId, tenantId);\n\n return (\n <MsTeamsProviderStateContext.Provider\n key={msTeamsProviderKey({\n knockMsTeamsChannelId,\n tenantId,\n connectionStatus,\n errorLabel,\n })}\n value={{\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n knockMsTeamsChannelId,\n tenantId,\n }}\n >\n {children}\n </MsTeamsProviderStateContext.Provider>\n );\n};\n\nexport const useKnockMsTeamsClient = (): KnockMsTeamsProviderState => {\n const context = React.useContext(MsTeamsProviderStateContext);\n if (!context) {\n throw new Error(\n \"useKnockMsTeamsClient must be used within a KnockMsTeamsProvider\",\n );\n }\n return context;\n};\n"],"names":["MsTeamsProviderStateContext","React","createContext","KnockMsTeamsProvider","knockMsTeamsChannelId","tenantId","children","knock","useKnockClient","connectionStatus","setConnectionStatus","errorLabel","setErrorLabel","actionLabel","setActionLabel","useMsTeamsConnectionStatus","msTeamsProviderKey","useKnockMsTeamsClient","context","useContext","Error"],"mappings":";;;;;;;;;AAmBA,MAAMA,IACJC,EAAMC,cAAgD,IAAI,GAO/CC,IAETA,CAAC;AAAA,EAAEC,uBAAAA;AAAAA,EAAuBC,UAAAA;AAAAA,EAAUC,UAAAA;AAAS,MAAM;AACrD,QAAMC,IAAQC,EAAe,GAEvB;AAAA,IACJC,kBAAAA;AAAAA,IACAC,qBAAAA;AAAAA,IACAC,YAAAA;AAAAA,IACAC,eAAAA;AAAAA,IACAC,aAAAA;AAAAA,IACAC,gBAAAA;AAAAA,EACEC,IAAAA,EAA2BR,GAAOH,GAAuBC,CAAQ;AAErE,SACG,gBAAAJ,EAAA,cAAAD,EAA4B,UAA5B,EACC,KAAKgB,EAAmB;AAAA,IACtBZ,uBAAAA;AAAAA,IACAC,UAAAA;AAAAA,IACAI,kBAAAA;AAAAA,IACAE,YAAAA;AAAAA,EACD,CAAA,GACD,OAAO;AAAA,IACLF,kBAAAA;AAAAA,IACAC,qBAAAA;AAAAA,IACAC,YAAAA;AAAAA,IACAC,eAAAA;AAAAA,IACAC,aAAAA;AAAAA,IACAC,gBAAAA;AAAAA,IACAV,uBAAAA;AAAAA,IACAC,UAAAA;AAAAA,OAGDC,CACH;AAEJ,GAEaW,IAAwBA,MAAiC;AAC9DC,QAAAA,IAAUjB,EAAMkB,WAAWnB,CAA2B;AAC5D,MAAI,CAACkB;AACG,UAAA,IAAIE,MACR,kEACF;AAEKF,SAAAA;AACT;"}
1
+ {"version":3,"file":"KnockMsTeamsProvider.mjs","sources":["../../../../../src/modules/ms-teams/context/KnockMsTeamsProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { PropsWithChildren, useRef } from \"react\";\n\nimport { type ConnectionStatus, useKnockClient } from \"../../core\";\nimport { msTeamsProviderKey } from \"../../core/utils\";\nimport { useMsTeamsConnectionStatus } from \"../hooks\";\n\nexport interface KnockMsTeamsProviderState {\n knockMsTeamsChannelId: string;\n tenantId: string;\n connectionStatus: ConnectionStatus;\n setConnectionStatus: (connectionStatus: ConnectionStatus) => void;\n errorLabel: string | null;\n setErrorLabel: (label: string) => void;\n actionLabel: string | null;\n setActionLabel: (label: string | null) => void;\n popupWindowRef: React.MutableRefObject<Window | null>;\n}\n\nconst MsTeamsProviderStateContext =\n React.createContext<KnockMsTeamsProviderState | null>(null);\n\nexport interface KnockMsTeamsProviderProps {\n knockMsTeamsChannelId: string;\n tenantId: string;\n}\n\nexport const KnockMsTeamsProvider: React.FC<\n PropsWithChildren<KnockMsTeamsProviderProps>\n> = ({ knockMsTeamsChannelId, tenantId, children }) => {\n const knock = useKnockClient();\n const popupWindowRef = useRef<Window | null>(null);\n\n const {\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n } = useMsTeamsConnectionStatus(knock, knockMsTeamsChannelId, tenantId);\n\n return (\n <MsTeamsProviderStateContext.Provider\n key={msTeamsProviderKey({\n knockMsTeamsChannelId,\n tenantId,\n connectionStatus,\n errorLabel,\n })}\n value={{\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n knockMsTeamsChannelId,\n tenantId,\n popupWindowRef,\n }}\n >\n {children}\n </MsTeamsProviderStateContext.Provider>\n );\n};\n\nexport const useKnockMsTeamsClient = (): KnockMsTeamsProviderState => {\n const context = React.useContext(MsTeamsProviderStateContext);\n if (!context) {\n throw new Error(\n \"useKnockMsTeamsClient must be used within a KnockMsTeamsProvider\",\n );\n }\n return context;\n};\n"],"names":["MsTeamsProviderStateContext","React","createContext","KnockMsTeamsProvider","knockMsTeamsChannelId","tenantId","children","knock","useKnockClient","popupWindowRef","useRef","connectionStatus","setConnectionStatus","errorLabel","setErrorLabel","actionLabel","setActionLabel","useMsTeamsConnectionStatus","msTeamsProviderKey","useKnockMsTeamsClient","context","useContext","Error"],"mappings":";;;;;;;;;;AAmBA,MAAMA,IACJC,EAAMC,cAAgD,IAAI,GAO/CC,IAETA,CAAC;AAAA,EAAEC,uBAAAA;AAAAA,EAAuBC,UAAAA;AAAAA,EAAUC,UAAAA;AAAS,MAAM;AACrD,QAAMC,IAAQC,EAAe,GACvBC,IAAiBC,EAAsB,IAAI,GAE3C;AAAA,IACJC,kBAAAA;AAAAA,IACAC,qBAAAA;AAAAA,IACAC,YAAAA;AAAAA,IACAC,eAAAA;AAAAA,IACAC,aAAAA;AAAAA,IACAC,gBAAAA;AAAAA,EACEC,IAAAA,EAA2BV,GAAOH,GAAuBC,CAAQ;AAErE,SACG,gBAAAJ,EAAA,cAAAD,EAA4B,UAA5B,EACC,KAAKkB,EAAmB;AAAA,IACtBd,uBAAAA;AAAAA,IACAC,UAAAA;AAAAA,IACAM,kBAAAA;AAAAA,IACAE,YAAAA;AAAAA,EACD,CAAA,GACD,OAAO;AAAA,IACLF,kBAAAA;AAAAA,IACAC,qBAAAA;AAAAA,IACAC,YAAAA;AAAAA,IACAC,eAAAA;AAAAA,IACAC,aAAAA;AAAAA,IACAC,gBAAAA;AAAAA,IACAZ,uBAAAA;AAAAA,IACAC,UAAAA;AAAAA,IACAI,gBAAAA;AAAAA,OAGDH,CACH;AAEJ,GAEaa,IAAwBA,MAAiC;AAC9DC,QAAAA,IAAUnB,EAAMoB,WAAWrB,CAA2B;AAC5D,MAAI,CAACoB;AACG,UAAA,IAAIE,MACR,kEACF;AAEKF,SAAAA;AACT;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useMsTeamsConnectionStatus.mjs","sources":["../../../../../src/modules/ms-teams/hooks/useMsTeamsConnectionStatus.ts"],"sourcesContent":["import Knock from \"@knocklabs/client\";\nimport { useEffect, useState } from \"react\";\n\nimport { useTranslations } from \"../../i18n\";\n\nexport type ConnectionStatus =\n | \"connecting\"\n | \"connected\"\n | \"disconnected\"\n | \"error\"\n | \"disconnecting\";\n\ntype UseMsTeamsConnectionStatusOutput = {\n connectionStatus: ConnectionStatus;\n setConnectionStatus: (status: ConnectionStatus) => void;\n errorLabel: string | null;\n setErrorLabel: (errorLabel: string) => void;\n actionLabel: string | null;\n setActionLabel: (actionLabel: string | null) => void;\n};\n\nfunction useMsTeamsConnectionStatus(\n knock: Knock,\n knockMsTeamsChannelId: string,\n tenantId: string,\n): UseMsTeamsConnectionStatusOutput {\n const { t } = useTranslations();\n\n const [connectionStatus, setConnectionStatus] =\n useState<ConnectionStatus>(\"connecting\");\n const [errorLabel, setErrorLabel] = useState<string | null>(null);\n const [actionLabel, setActionLabel] = useState<string | null>(null);\n\n useEffect(() => {\n const checkAuthStatus = async () => {\n if (connectionStatus !== \"connecting\") return;\n\n try {\n const authRes = await knock.msTeams.authCheck({\n tenant: tenantId,\n knockChannelId: knockMsTeamsChannelId,\n });\n\n if (authRes.connection?.ok === true) {\n return setConnectionStatus(\"connected\");\n }\n\n if (authRes.connection?.ok === false) {\n return setConnectionStatus(\"disconnected\");\n }\n\n // This is a normal response for a tenant that doesn't have\n // ms_teams_tenant_id set on it, meaning it's not connected to MS Teams,\n // so we give it a \"disconnected\" status instead of an error status.\n if (\n authRes.code === \"ERR_BAD_REQUEST\" &&\n authRes.response?.data?.message === t(\"msTeamsTenantIdNotSet\")\n ) {\n return setConnectionStatus(\"disconnected\");\n }\n\n // This is for any Knock errors that would require a reconnect.\n setConnectionStatus(\"error\");\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n };\n\n checkAuthStatus();\n }, [connectionStatus, tenantId, knockMsTeamsChannelId, knock.msTeams, t]);\n\n return {\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n };\n}\n\nexport default useMsTeamsConnectionStatus;\n"],"names":["useMsTeamsConnectionStatus","knock","knockMsTeamsChannelId","tenantId","t","useTranslations","connectionStatus","setConnectionStatus","useState","errorLabel","setErrorLabel","actionLabel","setActionLabel","useEffect","authRes","msTeams","authCheck","tenant","knockChannelId","connection","ok","code","response","data","message"],"mappings":";;;AAqBA,SAASA,EACPC,GACAC,GACAC,GACkC;AAC5B,QAAA;AAAA,IAAEC,GAAAA;AAAAA,MAAMC,EAAgB,GAExB,CAACC,GAAkBC,CAAmB,IAC1CC,EAA2B,YAAY,GACnC,CAACC,GAAYC,CAAa,IAAIF,EAAwB,IAAI,GAC1D,CAACG,GAAaC,CAAc,IAAIJ,EAAwB,IAAI;AAElEK,SAAAA,EAAU,MAAM;AAmCE,KAlCQ,YAAY;;AAClC,UAAIP,MAAqB;AAErB,YAAA;AACF,gBAAMQ,IAAU,MAAMb,EAAMc,QAAQC,UAAU;AAAA,YAC5CC,QAAQd;AAAAA,YACRe,gBAAgBhB;AAAAA,UAAAA,CACjB;AAEGY,gBAAAA,IAAAA,EAAQK,eAARL,gBAAAA,EAAoBM,QAAO;AAC7B,mBAAOb,EAAoB,WAAW;AAWtCO,gBAREA,IAAAA,EAAQK,eAARL,gBAAAA,EAAoBM,QAAO,MAQ7BN,EAAQO,SAAS,uBACjBP,KAAAA,IAAAA,EAAQQ,aAARR,gBAAAA,EAAkBS,SAAlBT,gBAAAA,EAAwBU,aAAYpB,EAAE,uBAAuB;AAE7D,mBAAOG,EAAoB,cAAc;AAI3CA,UAAAA,EAAoB,OAAO;AAAA,gBACZ;AACfA,UAAAA,EAAoB,OAAO;AAAA,QAAA;AAAA,IAE/B,GAEgB;AAAA,EAAA,GACf,CAACD,GAAkBH,GAAUD,GAAuBD,EAAMc,SAASX,CAAC,CAAC,GAEjE;AAAA,IACLE,kBAAAA;AAAAA,IACAC,qBAAAA;AAAAA,IACAE,YAAAA;AAAAA,IACAC,eAAAA;AAAAA,IACAC,aAAAA;AAAAA,IACAC,gBAAAA;AAAAA,EACF;AACF;"}
1
+ {"version":3,"file":"useMsTeamsConnectionStatus.mjs","sources":["../../../../../src/modules/ms-teams/hooks/useMsTeamsConnectionStatus.ts"],"sourcesContent":["import Knock from \"@knocklabs/client\";\nimport { useEffect, useState } from \"react\";\n\nimport { type ConnectionStatus } from \"../../core/types\";\nimport { useTranslations } from \"../../i18n\";\n\ntype UseMsTeamsConnectionStatusOutput = {\n connectionStatus: ConnectionStatus;\n setConnectionStatus: (status: ConnectionStatus) => void;\n errorLabel: string | null;\n setErrorLabel: (errorLabel: string) => void;\n actionLabel: string | null;\n setActionLabel: (actionLabel: string | null) => void;\n};\n\nfunction useMsTeamsConnectionStatus(\n knock: Knock,\n knockMsTeamsChannelId: string,\n tenantId: string,\n): UseMsTeamsConnectionStatusOutput {\n const { t } = useTranslations();\n\n const [connectionStatus, setConnectionStatus] =\n useState<ConnectionStatus>(\"connecting\");\n const [errorLabel, setErrorLabel] = useState<string | null>(null);\n const [actionLabel, setActionLabel] = useState<string | null>(null);\n\n useEffect(() => {\n const checkAuthStatus = async () => {\n if (connectionStatus !== \"connecting\") return;\n\n try {\n const authRes = await knock.msTeams.authCheck({\n tenant: tenantId,\n knockChannelId: knockMsTeamsChannelId,\n });\n\n if (authRes.connection?.ok === true) {\n return setConnectionStatus(\"connected\");\n }\n\n if (authRes.connection?.ok === false) {\n return setConnectionStatus(\"disconnected\");\n }\n\n // This is a normal response for a tenant that doesn't have\n // ms_teams_tenant_id set on it, meaning it's not connected to MS Teams,\n // so we give it a \"disconnected\" status instead of an error status.\n if (\n authRes.code === \"ERR_BAD_REQUEST\" &&\n authRes.response?.data?.message === t(\"msTeamsTenantIdNotSet\")\n ) {\n return setConnectionStatus(\"disconnected\");\n }\n\n // This is for any Knock errors that would require a reconnect.\n setConnectionStatus(\"error\");\n } catch (_error) {\n setConnectionStatus(\"error\");\n }\n };\n\n checkAuthStatus();\n }, [connectionStatus, tenantId, knockMsTeamsChannelId, knock.msTeams, t]);\n\n return {\n connectionStatus,\n setConnectionStatus,\n errorLabel,\n setErrorLabel,\n actionLabel,\n setActionLabel,\n };\n}\n\nexport default useMsTeamsConnectionStatus;\n"],"names":["useMsTeamsConnectionStatus","knock","knockMsTeamsChannelId","tenantId","t","useTranslations","connectionStatus","setConnectionStatus","useState","errorLabel","setErrorLabel","actionLabel","setActionLabel","useEffect","authRes","msTeams","authCheck","tenant","knockChannelId","connection","ok","code","response","data","message"],"mappings":";;;AAeA,SAASA,EACPC,GACAC,GACAC,GACkC;AAC5B,QAAA;AAAA,IAAEC,GAAAA;AAAAA,MAAMC,EAAgB,GAExB,CAACC,GAAkBC,CAAmB,IAC1CC,EAA2B,YAAY,GACnC,CAACC,GAAYC,CAAa,IAAIF,EAAwB,IAAI,GAC1D,CAACG,GAAaC,CAAc,IAAIJ,EAAwB,IAAI;AAElEK,SAAAA,EAAU,MAAM;AAmCE,KAlCQ,YAAY;;AAClC,UAAIP,MAAqB;AAErB,YAAA;AACF,gBAAMQ,IAAU,MAAMb,EAAMc,QAAQC,UAAU;AAAA,YAC5CC,QAAQd;AAAAA,YACRe,gBAAgBhB;AAAAA,UAAAA,CACjB;AAEGY,gBAAAA,IAAAA,EAAQK,eAARL,gBAAAA,EAAoBM,QAAO;AAC7B,mBAAOb,EAAoB,WAAW;AAWtCO,gBAREA,IAAAA,EAAQK,eAARL,gBAAAA,EAAoBM,QAAO,MAQ7BN,EAAQO,SAAS,uBACjBP,KAAAA,IAAAA,EAAQQ,aAARR,gBAAAA,EAAkBS,SAAlBT,gBAAAA,EAAwBU,aAAYpB,EAAE,uBAAuB;AAE7D,mBAAOG,EAAoB,cAAc;AAI3CA,UAAAA,EAAoB,OAAO;AAAA,gBACZ;AACfA,UAAAA,EAAoB,OAAO;AAAA,QAAA;AAAA,IAE/B,GAEgB;AAAA,EAAA,GACf,CAACD,GAAkBH,GAAUD,GAAuBD,EAAMc,SAASX,CAAC,CAAC,GAEjE;AAAA,IACLE,kBAAAA;AAAAA,IACAC,qBAAAA;AAAAA,IACAE,YAAAA;AAAAA,IACAC,eAAAA;AAAAA,IACAC,aAAAA;AAAAA,IACAC,gBAAAA;AAAAA,EACF;AACF;"}