@knocklabs/react-core 0.5.0-rc.2.0 → 0.5.0

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 (26) hide show
  1. package/CHANGELOG.md +18 -4
  2. package/dist/cjs/modules/feed/hooks/useNotificationStore.js +1 -1
  3. package/dist/cjs/modules/feed/hooks/useNotificationStore.js.map +1 -1
  4. package/dist/cjs/modules/ms-teams/hooks/useMsTeamsTeams.js +1 -1
  5. package/dist/cjs/modules/ms-teams/hooks/useMsTeamsTeams.js.map +1 -1
  6. package/dist/cjs/modules/slack/hooks/useSlackChannels.js +1 -1
  7. package/dist/cjs/modules/slack/hooks/useSlackChannels.js.map +1 -1
  8. package/dist/esm/modules/feed/hooks/useNotificationStore.mjs +7 -11
  9. package/dist/esm/modules/feed/hooks/useNotificationStore.mjs.map +1 -1
  10. package/dist/esm/modules/ms-teams/hooks/useMsTeamsTeams.mjs +26 -25
  11. package/dist/esm/modules/ms-teams/hooks/useMsTeamsTeams.mjs.map +1 -1
  12. package/dist/esm/modules/slack/hooks/useSlackChannels.mjs +34 -35
  13. package/dist/esm/modules/slack/hooks/useSlackChannels.mjs.map +1 -1
  14. package/dist/types/modules/feed/hooks/index.d.ts +1 -1
  15. package/dist/types/modules/feed/hooks/index.d.ts.map +1 -1
  16. package/dist/types/modules/feed/hooks/useNotificationStore.d.ts +16 -4
  17. package/dist/types/modules/feed/hooks/useNotificationStore.d.ts.map +1 -1
  18. package/dist/types/modules/ms-teams/hooks/useMsTeamsTeams.d.ts +2 -2
  19. package/dist/types/modules/ms-teams/hooks/useMsTeamsTeams.d.ts.map +1 -1
  20. package/dist/types/modules/slack/hooks/useSlackChannels.d.ts +2 -2
  21. package/dist/types/modules/slack/hooks/useSlackChannels.d.ts.map +1 -1
  22. package/package.json +4 -4
  23. package/src/modules/feed/hooks/index.ts +1 -0
  24. package/src/modules/feed/hooks/useNotificationStore.ts +23 -29
  25. package/src/modules/ms-teams/hooks/useMsTeamsTeams.ts +3 -2
  26. package/src/modules/slack/hooks/useSlackChannels.ts +8 -13
package/CHANGELOG.md CHANGED
@@ -1,15 +1,29 @@
1
1
  # Changelog
2
2
 
3
- ## 0.5.0-rc.2.0
3
+ ## 0.5.0
4
4
 
5
5
  ### Minor Changes
6
6
 
7
- - 0fc5f2d: [JS] Support React 19 in React SDKs
7
+ - 8ba5dcb: [JS] Support React 19 in React SDKs
8
8
 
9
9
  ### Patch Changes
10
10
 
11
- - Updated dependencies [0fc5f2d]
12
- - @knocklabs/client@0.12.0-rc.2.0
11
+ - Updated dependencies [8ba5dcb]
12
+ - @knocklabs/client@0.12.0
13
+
14
+ ## 0.4.2
15
+
16
+ ### Patch Changes
17
+
18
+ - 226e319: Fix unnecessary refetches of first page by `useSlackChannels` and `useMsTeamsTeams` hooks
19
+
20
+ Previously, both the `useSlackChannels` and `useMsTeamsTeams` hooks would unnecessarily refetch the first page of data whenever multiple pages of data were loaded. This has been fixed.
21
+
22
+ ## 0.4.1
23
+
24
+ ### Patch Changes
25
+
26
+ - 1b86a0c: fix: correct pagination logic in useSlackChannels hook (KNO-7995)
13
27
 
14
28
  ## 0.4.0
15
29
 
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("zustand");function n(e,t){const o=i.useStore(e.store);return u=>{const r=u??t;return r?r(o):o}}function s(e,t){return n(e,t)}exports.default=s;exports.useCreateNotificationStore=n;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("zustand");function r(e){return u=>n.useStore(e.store,u??(t=>t))}function s(e,o){return r(e)(o??(t=>t))}exports.default=s;exports.useCreateNotificationStore=r;
2
2
  //# sourceMappingURL=useNotificationStore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useNotificationStore.js","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"sourcesContent":["import { Feed, type FeedStoreState } from \"@knocklabs/client\";\nimport { type StoreApi, type UseBoundStore, useStore } from \"zustand\";\n\n// A hook designed to create a `UseBoundStore` instance.\n// https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores\nfunction useCreateNotificationStore(\n feedClient: Feed,\n): UseBoundStore<StoreApi<FeedStoreState>>;\nfunction useCreateNotificationStore<T, U = T>(\n feedClient: Feed,\n externalSelector: (state: FeedStoreState) => U,\n): U;\n/**\n * Access a Bounded Store instance\n * Allow passing a selector down from useCreateNotificationStore OR useNotificationStore\n * We'll favor the the one passed later outside of useCreateNotificationStore instantiation\n */\nfunction useCreateNotificationStore<T, U = T>(\n feedClient: Feed,\n externalSelector?: (state: FeedStoreState) => U,\n) {\n const store = useStore(feedClient.store);\n\n return (selector?: (state: FeedStoreState) => U) => {\n const innerSelector = selector ?? externalSelector;\n return innerSelector ? innerSelector(store) : store;\n };\n}\n\n/**\n * A hook used to access content within the notification store.\n *\n * A selector can be used to access a subset of the store state.\n *\n * @example\n *\n * ```ts\n * const { items, metadata } = useNotificationStore(feedClient, (state) => ({\n * items: state.items,\n * metadata: state.metadata,\n * }));\n * ```\n */\nfunction useNotificationStore(\n feedClient: Feed,\n): UseBoundStore<StoreApi<FeedStoreState>>;\nfunction useNotificationStore<T>(\n feedClient: Feed,\n selector: (state: FeedStoreState) => T,\n): T;\nfunction useNotificationStore<T, U = T>(\n feedClient: Feed,\n selector?: (state: FeedStoreState) => U,\n) {\n return useCreateNotificationStore(feedClient, selector!);\n}\n\nexport { useCreateNotificationStore };\nexport default useNotificationStore;\n"],"names":["useCreateNotificationStore","feedClient","externalSelector","store","useStore","selector","innerSelector","useNotificationStore"],"mappings":"uIAiBA,SAASA,EACPC,EACAC,EACA,CACMC,MAAAA,EAAQC,EAAAA,SAASH,EAAWE,KAAK,EAEvC,OAAQE,GAA4C,CAClD,MAAMC,EAAgBD,GAAYH,EAC3BI,OAAAA,EAAgBA,EAAcH,CAAK,EAAIA,CAChD,CACF,CAuBA,SAASI,EACPN,EACAI,EACA,CACOL,OAAAA,EAA2BC,EAAYI,CAAS,CACzD"}
1
+ {"version":3,"file":"useNotificationStore.js","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"sourcesContent":["import { Feed, type FeedStoreState } from \"@knocklabs/client\";\nimport { type StoreApi, type UseBoundStore, useStore } from \"zustand\";\n\nexport type Selector<T> = (state: FeedStoreState) => T;\n\n/**\n * Access a Bounded Store instance by converting our vanilla store to a UseBoundStore\n * https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores\n * Allow passing a selector down from useCreateNotificationStore OR useNotificationStore\n * We'll favor the the one passed later outside of useCreateNotificationStore instantiation\n */\nfunction useCreateNotificationStore<T>(\n feedClient: Feed,\n): UseBoundStore<StoreApi<FeedStoreState>> {\n // Keep selector optional for external use\n // useStore requires a selector so we'll pass in a default one when not provided\n const useBoundedStore = (selector?: Selector<T>) =>\n useStore(feedClient.store, selector ?? ((state) => state as T));\n return useBoundedStore as UseBoundStore<StoreApi<FeedStoreState>>;\n}\n\n/**\n * A hook used to access content within the notification store.\n *\n * @example\n *\n * ```ts\n * const { items, metadata } = useNotificationStore(feedClient);\n * ```\n *\n * A selector can be used to access a subset of the store state.\n *\n * @example\n *\n * ```ts\n * const { items, metadata } = useNotificationStore(feedClient, (state) => ({\n * items: state.items,\n * metadata: state.metadata,\n * }));\n * ```\n */\nfunction useNotificationStore(feedClient: Feed): FeedStoreState;\nfunction useNotificationStore<T>(feedClient: Feed, selector: Selector<T>): T;\nfunction useNotificationStore<T>(\n feedClient: Feed,\n selector?: Selector<T>,\n): T | FeedStoreState {\n const useStoreLocal = useCreateNotificationStore(feedClient);\n return useStoreLocal(selector ?? ((state) => state as T));\n}\n\nexport { useCreateNotificationStore };\nexport default useNotificationStore;\n"],"names":["useCreateNotificationStore","feedClient","useBoundedStore","selector","useStore","store","state","useNotificationStore","useStoreLocal"],"mappings":"uIAWA,SAASA,EACPC,EACyC,CAKlCC,OAFkBC,GACvBC,WAASH,EAAWI,MAAOF,OAAwBG,EAAW,CAElE,CAwBA,SAASC,EACPN,EACAE,EACoB,CAEbK,OADeR,EAA2BC,CAAU,EACtCE,IAAcG,GAAUA,EAAW,CAC1D"}
@@ -1,2 +1,2 @@
1
- "use strict";const r=require("react"),S=require("swr/infinite"),h=require("../../core/context/KnockProvider.js");require("@knocklabs/client");require("zustand/shallow");require("date-fns");const E=require("../context/KnockMsTeamsProvider.js"),I=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},g=I(S),x=1e3,_="MS_TEAMS_TEAMS";function P(t,n){return t===0?[_,""]:n&&["",null].includes(n.skip_token)?null:[_,n.skip_token??""]}function R({queryOptions:t={}}){const n=h.useKnockClient(),{knockMsTeamsChannelId:u,tenantId:T,connectionStatus:l}=E.useKnockMsTeamsClient(),M=e=>n.msTeams.getTeams({knockChannelId:u,tenant:T,queryOptions:{$skiptoken:e==null?void 0:e[1],$top:t==null?void 0:t.limitPerPage,$filter:t==null?void 0:t.filter,$select:t==null?void 0:t.select}}),{data:c,error:o,isLoading:s,isValidating:a,setSize:f,mutate:C}=g.default(P,M,{initialSize:0,revalidateOnFocus:!1}),m=c==null?void 0:c.at(-1),k=m===void 0||!!m.skip_token,i=r.useMemo(()=>(c??[]).flatMap(e=>e==null?void 0:e.ms_teams_teams).filter(e=>!!e),[c]),d=(t==null?void 0:t.maxCount)||x;return r.useEffect(()=>{l==="connected"&&!o&&k&&!s&&!a&&i.length<d&&f(e=>e+1)},[i.length,f,k,s,a,d,o,l]),{data:i,isLoading:s||a,refetch:()=>C()}}module.exports=R;
1
+ "use strict";const r=require("react"),S=require("swr/infinite"),h=require("../../core/context/KnockProvider.js");require("@knocklabs/client");require("zustand/shallow");require("date-fns");const g=require("../context/KnockMsTeamsProvider.js"),E=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},I=E(S),P=1e3,_="MS_TEAMS_TEAMS";function x(e,n){return e===0?[_,""]:n&&["",null].includes(n.skip_token)?null:[_,n.skip_token??""]}function R({queryOptions:e={}}){const n=h.useKnockClient(),{knockMsTeamsChannelId:u,tenantId:T,connectionStatus:l}=g.useKnockMsTeamsClient(),M=t=>n.msTeams.getTeams({knockChannelId:u,tenant:T,queryOptions:{$skiptoken:t==null?void 0:t[1],$top:e==null?void 0:e.limitPerPage,$filter:e==null?void 0:e.filter,$select:e==null?void 0:e.select}}),{data:s,error:o,isLoading:c,isValidating:a,setSize:f,mutate:C}=I.default(x,M,{initialSize:0,revalidateOnFocus:!1,revalidateFirstPage:!1}),m=s==null?void 0:s.at(-1),k=m===void 0||!!m.skip_token,i=r.useMemo(()=>(s??[]).flatMap(t=>t==null?void 0:t.ms_teams_teams).filter(t=>!!t),[s]),d=(e==null?void 0:e.maxCount)||P;return r.useEffect(()=>{l==="connected"&&!o&&k&&!c&&!a&&i.length<d&&f(t=>t+1)},[i.length,f,k,c,a,d,o,l]),{data:i,isLoading:c||a,refetch:()=>C()}}module.exports=R;
2
2
  //# sourceMappingURL=useMsTeamsTeams.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMsTeamsTeams.js","sources":["../../../../../src/modules/ms-teams/hooks/useMsTeamsTeams.ts"],"sourcesContent":["import { GetMsTeamsTeamsResponse, MsTeamsTeam } from \"@knocklabs/client\";\nimport { useEffect, useMemo } from \"react\";\nimport useSWRInfinite from \"swr/infinite\";\n\nimport { useKnockClient } from \"../../core\";\nimport { useKnockMsTeamsClient } from \"../context\";\nimport { MsTeamsTeamQueryOptions } from \"../interfaces\";\n\nconst MAX_COUNT = 1000;\n\nconst QUERY_KEY = \"MS_TEAMS_TEAMS\";\n\ntype UseMsTeamsTeamsProps = {\n queryOptions?: MsTeamsTeamQueryOptions;\n};\n\ntype UseMsTeamsTeamsOutput = {\n data: MsTeamsTeam[];\n isLoading: boolean;\n refetch: () => void;\n};\n\ntype QueryKey = [key: string, skiptoken: string] | null;\n\nfunction getQueryKey(\n pageIndex: number,\n previousPageData: GetMsTeamsTeamsResponse,\n): QueryKey {\n // First page so just pass empty\n if (pageIndex === 0) {\n return [QUERY_KEY, \"\"];\n }\n\n // If there's no more data then return an empty next skiptoken\n if (previousPageData && [\"\", null].includes(previousPageData.skip_token)) {\n return null;\n }\n\n // Next skiptoken exists so pass it\n return [QUERY_KEY, previousPageData.skip_token ?? \"\"];\n}\n\nfunction useMsTeamsTeams({\n queryOptions = {},\n}: UseMsTeamsTeamsProps): UseMsTeamsTeamsOutput {\n const knock = useKnockClient();\n const { knockMsTeamsChannelId, tenantId, connectionStatus } =\n useKnockMsTeamsClient();\n\n const fetchTeams = (queryKey: QueryKey) =>\n knock.msTeams.getTeams({\n knockChannelId: knockMsTeamsChannelId,\n tenant: tenantId,\n queryOptions: {\n $skiptoken: queryKey?.[1],\n $top: queryOptions?.limitPerPage,\n $filter: queryOptions?.filter,\n $select: queryOptions?.select,\n },\n });\n\n const { data, error, isLoading, isValidating, setSize, mutate } =\n useSWRInfinite<GetMsTeamsTeamsResponse>(getQueryKey, fetchTeams, {\n initialSize: 0,\n revalidateOnFocus: false,\n });\n\n const lastPage = data?.at(-1);\n const hasNextPage = lastPage === undefined || !!lastPage.skip_token;\n\n const teams = useMemo(\n () =>\n (data ?? [])\n .flatMap((page) => page?.ms_teams_teams)\n .filter((team) => !!team),\n [data],\n );\n\n const maxCount = queryOptions?.maxCount || MAX_COUNT;\n\n useEffect(() => {\n if (\n connectionStatus === \"connected\" &&\n !error &&\n hasNextPage &&\n !isLoading &&\n !isValidating &&\n teams.length < maxCount\n ) {\n // Fetch a page at a time until we have nothing else left to fetch\n // or we've already hit the max amount of teams to fetch\n setSize((size) => size + 1);\n }\n }, [\n teams.length,\n setSize,\n hasNextPage,\n isLoading,\n isValidating,\n maxCount,\n error,\n connectionStatus,\n ]);\n\n return {\n data: teams,\n isLoading: isLoading || isValidating,\n refetch: () => mutate(),\n };\n}\n\nexport default useMsTeamsTeams;\n"],"names":["MAX_COUNT","QUERY_KEY","getQueryKey","pageIndex","previousPageData","includes","skip_token","useMsTeamsTeams","queryOptions","knock","useKnockClient","knockMsTeamsChannelId","tenantId","connectionStatus","useKnockMsTeamsClient","fetchTeams","queryKey","msTeams","getTeams","knockChannelId","tenant","$skiptoken","$top","limitPerPage","$filter","filter","$select","select","data","error","isLoading","isValidating","setSize","mutate","useSWRInfinite","initialSize","revalidateOnFocus","lastPage","at","hasNextPage","undefined","teams","useMemo","flatMap","page","ms_teams_teams","team","maxCount","useEffect","length","size","refetch"],"mappings":"kTAQMA,EAAY,IAEZC,EAAY,iBAclB,SAASC,EACPC,EACAC,EACU,CAEV,OAAID,IAAc,EACT,CAACF,EAAW,EAAE,EAInBG,GAAoB,CAAC,GAAI,IAAI,EAAEC,SAASD,EAAiBE,UAAU,EAC9D,KAIF,CAACL,EAAWG,EAAiBE,YAAc,EAAE,CACtD,CAEA,SAASC,EAAgB,CACvBC,aAAAA,EAAe,CAAA,CACK,EAA0B,CAC9C,MAAMC,EAAQC,EAAAA,eAAe,EACvB,CAAEC,sBAAAA,EAAuBC,SAAAA,EAAUC,iBAAAA,GACvCC,wBAAsB,EAElBC,EAAcC,GAClBP,EAAMQ,QAAQC,SAAS,CACrBC,eAAgBR,EAChBS,OAAQR,EACRJ,aAAc,CACZa,WAAYL,GAAAA,YAAAA,EAAW,GACvBM,KAAMd,GAAAA,YAAAA,EAAce,aACpBC,QAAShB,GAAAA,YAAAA,EAAciB,OACvBC,QAASlB,GAAAA,YAAAA,EAAcmB,MAAAA,CACzB,CACD,EAEG,CAAEC,KAAAA,EAAMC,MAAAA,EAAOC,UAAAA,EAAWC,aAAAA,EAAcC,QAAAA,EAASC,OAAAA,CAAAA,EACrDC,EAAwChC,QAAAA,EAAaa,EAAY,CAC/DoB,YAAa,EACbC,kBAAmB,EAAA,CACpB,EAEGC,EAAWT,GAAAA,YAAAA,EAAMU,GAAG,IACpBC,EAAcF,IAAaG,QAAa,CAAC,CAACH,EAAS/B,WAEnDmC,EAAQC,EAAAA,QACZ,KACGd,GAAQ,IACNe,QAAkBC,GAAAA,GAAAA,YAAAA,EAAMC,cAAc,EACtCpB,UAAiB,CAAC,CAACqB,CAAI,EAC5B,CAAClB,CAAI,CACP,EAEMmB,GAAWvC,GAAAA,YAAAA,EAAcuC,WAAY/C,EAE3CgD,OAAAA,EAAAA,UAAU,IAAM,CAEZnC,IAAqB,aACrB,CAACgB,GACDU,GACA,CAACT,GACD,CAACC,GACDU,EAAMQ,OAASF,GAING,EAAAA,GAASA,EAAO,CAAC,CAE9B,EAAG,CACDT,EAAMQ,OACNjB,EACAO,EACAT,EACAC,EACAgB,EACAlB,EACAhB,CAAgB,CACjB,EAEM,CACLe,KAAMa,EACNX,UAAWA,GAAaC,EACxBoB,QAASA,IAAMlB,EAAO,CACxB,CACF"}
1
+ {"version":3,"file":"useMsTeamsTeams.js","sources":["../../../../../src/modules/ms-teams/hooks/useMsTeamsTeams.ts"],"sourcesContent":["import { GetMsTeamsTeamsResponse, MsTeamsTeam } from \"@knocklabs/client\";\nimport { useEffect, useMemo } from \"react\";\nimport useSWRInfinite from \"swr/infinite\";\n\nimport { useKnockClient } from \"../../core\";\nimport { useKnockMsTeamsClient } from \"../context\";\nimport { MsTeamsTeamQueryOptions } from \"../interfaces\";\n\nconst MAX_COUNT = 1000;\n\nconst QUERY_KEY = \"MS_TEAMS_TEAMS\";\n\ntype UseMsTeamsTeamsOptions = {\n queryOptions?: MsTeamsTeamQueryOptions;\n};\n\ntype UseMsTeamsTeamsOutput = {\n data: MsTeamsTeam[];\n isLoading: boolean;\n refetch: () => void;\n};\n\ntype QueryKey = [key: string, skiptoken: string] | null;\n\nfunction getQueryKey(\n pageIndex: number,\n previousPageData: GetMsTeamsTeamsResponse,\n): QueryKey {\n // First page so just pass empty\n if (pageIndex === 0) {\n return [QUERY_KEY, \"\"];\n }\n\n // If there's no more data then return an empty next skiptoken\n if (previousPageData && [\"\", null].includes(previousPageData.skip_token)) {\n return null;\n }\n\n // Next skiptoken exists so pass it\n return [QUERY_KEY, previousPageData.skip_token ?? \"\"];\n}\n\nfunction useMsTeamsTeams({\n queryOptions = {},\n}: UseMsTeamsTeamsOptions): UseMsTeamsTeamsOutput {\n const knock = useKnockClient();\n const { knockMsTeamsChannelId, tenantId, connectionStatus } =\n useKnockMsTeamsClient();\n\n const fetchTeams = (queryKey: QueryKey) =>\n knock.msTeams.getTeams({\n knockChannelId: knockMsTeamsChannelId,\n tenant: tenantId,\n queryOptions: {\n $skiptoken: queryKey?.[1],\n $top: queryOptions?.limitPerPage,\n $filter: queryOptions?.filter,\n $select: queryOptions?.select,\n },\n });\n\n const { data, error, isLoading, isValidating, setSize, mutate } =\n useSWRInfinite<GetMsTeamsTeamsResponse>(getQueryKey, fetchTeams, {\n initialSize: 0,\n revalidateOnFocus: false,\n revalidateFirstPage: false,\n });\n\n const lastPage = data?.at(-1);\n const hasNextPage = lastPage === undefined || !!lastPage.skip_token;\n\n const teams = useMemo(\n () =>\n (data ?? [])\n .flatMap((page) => page?.ms_teams_teams)\n .filter((team) => !!team),\n [data],\n );\n\n const maxCount = queryOptions?.maxCount || MAX_COUNT;\n\n useEffect(() => {\n if (\n connectionStatus === \"connected\" &&\n !error &&\n hasNextPage &&\n !isLoading &&\n !isValidating &&\n teams.length < maxCount\n ) {\n // Fetch a page at a time until we have nothing else left to fetch\n // or we've already hit the max amount of teams to fetch\n setSize((size) => size + 1);\n }\n }, [\n teams.length,\n setSize,\n hasNextPage,\n isLoading,\n isValidating,\n maxCount,\n error,\n connectionStatus,\n ]);\n\n return {\n data: teams,\n isLoading: isLoading || isValidating,\n refetch: () => mutate(),\n };\n}\n\nexport default useMsTeamsTeams;\n"],"names":["MAX_COUNT","QUERY_KEY","getQueryKey","pageIndex","previousPageData","includes","skip_token","useMsTeamsTeams","queryOptions","knock","useKnockClient","knockMsTeamsChannelId","tenantId","connectionStatus","useKnockMsTeamsClient","fetchTeams","queryKey","msTeams","getTeams","knockChannelId","tenant","$skiptoken","$top","limitPerPage","$filter","filter","$select","select","data","error","isLoading","isValidating","setSize","mutate","useSWRInfinite","initialSize","revalidateOnFocus","revalidateFirstPage","lastPage","at","hasNextPage","undefined","teams","useMemo","flatMap","page","ms_teams_teams","team","maxCount","useEffect","length","size","refetch"],"mappings":"kTAQMA,EAAY,IAEZC,EAAY,iBAclB,SAASC,EACPC,EACAC,EACU,CAEV,OAAID,IAAc,EACT,CAACF,EAAW,EAAE,EAInBG,GAAoB,CAAC,GAAI,IAAI,EAAEC,SAASD,EAAiBE,UAAU,EAC9D,KAIF,CAACL,EAAWG,EAAiBE,YAAc,EAAE,CACtD,CAEA,SAASC,EAAgB,CACvBC,aAAAA,EAAe,CAAA,CACO,EAA0B,CAChD,MAAMC,EAAQC,EAAAA,eAAe,EACvB,CAAEC,sBAAAA,EAAuBC,SAAAA,EAAUC,iBAAAA,GACvCC,wBAAsB,EAElBC,EAAcC,GAClBP,EAAMQ,QAAQC,SAAS,CACrBC,eAAgBR,EAChBS,OAAQR,EACRJ,aAAc,CACZa,WAAYL,GAAAA,YAAAA,EAAW,GACvBM,KAAMd,GAAAA,YAAAA,EAAce,aACpBC,QAAShB,GAAAA,YAAAA,EAAciB,OACvBC,QAASlB,GAAAA,YAAAA,EAAcmB,MAAAA,CACzB,CACD,EAEG,CAAEC,KAAAA,EAAMC,MAAAA,EAAOC,UAAAA,EAAWC,aAAAA,EAAcC,QAAAA,EAASC,OAAAA,CAAAA,EACrDC,EAAwChC,QAAAA,EAAaa,EAAY,CAC/DoB,YAAa,EACbC,kBAAmB,GACnBC,oBAAqB,EAAA,CACtB,EAEGC,EAAWV,GAAAA,YAAAA,EAAMW,GAAG,IACpBC,EAAcF,IAAaG,QAAa,CAAC,CAACH,EAAShC,WAEnDoC,EAAQC,EAAAA,QACZ,KACGf,GAAQ,IACNgB,QAAkBC,GAAAA,GAAAA,YAAAA,EAAMC,cAAc,EACtCrB,UAAiB,CAAC,CAACsB,CAAI,EAC5B,CAACnB,CAAI,CACP,EAEMoB,GAAWxC,GAAAA,YAAAA,EAAcwC,WAAYhD,EAE3CiD,OAAAA,EAAAA,UAAU,IAAM,CAEZpC,IAAqB,aACrB,CAACgB,GACDW,GACA,CAACV,GACD,CAACC,GACDW,EAAMQ,OAASF,GAING,EAAAA,GAASA,EAAO,CAAC,CAE9B,EAAG,CACDT,EAAMQ,OACNlB,EACAQ,EACAV,EACAC,EACAiB,EACAnB,EACAhB,CAAgB,CACjB,EAEM,CACLe,KAAMc,EACNZ,UAAWA,GAAaC,EACxBqB,QAASA,IAAMnB,EAAO,CACxB,CACF"}
@@ -1,2 +1,2 @@
1
- "use strict";const P=require("../context/KnockSlackProvider.js"),d=require("react");require("../../i18n/context/KnockI18nProvider.js");const K=require("swr/infinite"),L=require("../../core/context/KnockProvider.js");require("@knocklabs/client");require("zustand/shallow");require("date-fns");require("swr");const N=n=>n&&typeof n=="object"&&"default"in n?n:{default:n},g=N(K),A=1e3,R=200,M="private_channel,public_channel",S="SLACK_CHANNELS";function z(n,c){return n===0?[S,""]:c&&["",null].includes(c.next_cursor)?null:[S,c.next_cursor??""]}function T({queryOptions:n}){var h,C;const c=L.useKnockClient(),{knockSlackChannelId:x,tenantId:E,connectionStatus:a}=P.useKnockSlackClient(),m=t=>c.slack.getChannels({tenant:E,knockChannelId:x,queryOptions:{...n,cursor:t?t[1]:"",limit:(n==null?void 0:n.limitPerPage)||R,types:(n==null?void 0:n.types)||M}}),{data:e,error:i,isLoading:l,isValidating:r,size:u,setSize:f,mutate:I}=g.default(z,m,{initialSize:0}),s=(e==null?void 0:e.length)||0,k=s===0||e&&((h=e[s])==null?void 0:h.next_cursor)&&((C=e[s])==null?void 0:C.next_cursor)!=="",o=d.useMemo(()=>(e??[]).flatMap(t=>t==null?void 0:t.slack_channels).filter(t=>!!t),[e]),_=(n==null?void 0:n.maxCount)||A;return d.useEffect(()=>{a==="connected"&&!i&&k&&!l&&!r&&o.length<_&&f(u+1)},[o.length,f,u,k,l,r,_,i,a]),{data:o,isLoading:l||r,refetch:()=>I()}}module.exports=T;
1
+ "use strict";const P=require("../context/KnockSlackProvider.js"),d=require("react");require("../../i18n/context/KnockI18nProvider.js");const m=require("swr/infinite"),x=require("../../core/context/KnockProvider.js");require("@knocklabs/client");require("zustand/shallow");require("date-fns");require("swr");const I=n=>n&&typeof n=="object"&&"default"in n?n:{default:n},L=I(m),N=1e3,g=200,A="private_channel,public_channel",C="SLACK_CHANNELS";function R(n,e){return n===0?[C,""]:e&&["",null].includes(e.next_cursor)?null:[C,e.next_cursor??""]}function M({queryOptions:n}){const e=x.useKnockClient(),{knockSlackChannelId:_,tenantId:h,connectionStatus:i}=P.useKnockSlackClient(),S=t=>e.slack.getChannels({tenant:h,knockChannelId:_,queryOptions:{...n,cursor:t==null?void 0:t[1],limit:(n==null?void 0:n.limitPerPage)||g,types:(n==null?void 0:n.types)||A}}),{data:c,error:r,isLoading:l,isValidating:a,setSize:o,mutate:E}=L.default(R,S,{initialSize:0,revalidateFirstPage:!1}),u=c==null?void 0:c.at(-1),f=u===void 0||!!u.next_cursor,s=d.useMemo(()=>(c??[]).flatMap(t=>t==null?void 0:t.slack_channels).filter(t=>!!t),[c]),k=(n==null?void 0:n.maxCount)||N;return d.useEffect(()=>{i==="connected"&&!r&&f&&!l&&!a&&s.length<k&&o(t=>t+1)},[s.length,o,f,l,a,k,r,i]),{data:s,isLoading:l||a,refetch:()=>E()}}module.exports=M;
2
2
  //# sourceMappingURL=useSlackChannels.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSlackChannels.js","sources":["../../../../../src/modules/slack/hooks/useSlackChannels.ts"],"sourcesContent":["import { SlackChannelQueryOptions, useKnockSlackClient } from \"..\";\nimport { GetSlackChannelsResponse, SlackChannel } from \"@knocklabs/client\";\nimport { useEffect, useMemo } from \"react\";\nimport useSWRInfinite from \"swr/infinite\";\n\nimport { useKnockClient } from \"../../core\";\n\nconst MAX_COUNT = 1000;\nconst LIMIT_PER_PAGE = 200;\nconst CHANNEL_TYPES = \"private_channel,public_channel\";\n\nconst QUERY_KEY = \"SLACK_CHANNELS\";\n\ntype UseSlackChannelsProps = {\n queryOptions?: SlackChannelQueryOptions;\n};\n\ntype UseSlackChannelOutput = {\n data: SlackChannel[];\n isLoading: boolean;\n refetch: () => void;\n};\n\ntype QueryKey = [key: string, cursor: string] | null;\n\nfunction getQueryKey(\n pageIndex: number,\n previousPageData: GetSlackChannelsResponse,\n): QueryKey {\n // First page so just pass empty\n if (pageIndex === 0) {\n return [QUERY_KEY, \"\"];\n }\n\n // If there's no more data then return an empty next cursor\n if (previousPageData && [\"\", null].includes(previousPageData.next_cursor)) {\n return null;\n }\n\n // Next cursor exists so pass it\n return [QUERY_KEY, previousPageData.next_cursor ?? \"\"];\n}\n\nfunction useSlackChannels({\n queryOptions,\n}: UseSlackChannelsProps): UseSlackChannelOutput {\n const knock = useKnockClient();\n const { knockSlackChannelId, tenantId, connectionStatus } =\n useKnockSlackClient();\n\n const fetchChannels = (queryKey: QueryKey) => {\n return knock.slack.getChannels({\n tenant: tenantId,\n knockChannelId: knockSlackChannelId,\n queryOptions: {\n ...queryOptions,\n cursor: queryKey ? queryKey[1] : \"\",\n limit: queryOptions?.limitPerPage || LIMIT_PER_PAGE,\n types: queryOptions?.types || CHANNEL_TYPES,\n },\n });\n };\n\n const { data, error, isLoading, isValidating, size, setSize, mutate } =\n useSWRInfinite<GetSlackChannelsResponse>(getQueryKey, fetchChannels, {\n initialSize: 0,\n });\n\n const currentPage = data?.length || 0;\n\n const hasNextPage =\n currentPage === 0 ||\n (data &&\n data[currentPage]?.next_cursor &&\n data[currentPage]?.next_cursor !== \"\");\n\n const slackChannels: SlackChannel[] = useMemo(\n () =>\n (data ?? [])\n .flatMap((page) => page?.slack_channels)\n .filter((channel) => !!channel),\n [data],\n );\n\n const maxCount = queryOptions?.maxCount || MAX_COUNT;\n\n useEffect(() => {\n if (\n connectionStatus === \"connected\" &&\n !error &&\n hasNextPage &&\n !isLoading &&\n !isValidating &&\n slackChannels.length < maxCount\n ) {\n // Fetch a page at a time until we have nothing else left to fetch\n // or we've already hit the max amount of channels to fetch\n setSize(size + 1);\n }\n }, [\n slackChannels.length,\n setSize,\n size,\n hasNextPage,\n isLoading,\n isValidating,\n maxCount,\n error,\n connectionStatus,\n ]);\n\n return {\n data: slackChannels,\n isLoading: isLoading || isValidating,\n refetch: () => mutate(),\n };\n}\n\nexport default useSlackChannels;\n"],"names":["MAX_COUNT","LIMIT_PER_PAGE","CHANNEL_TYPES","QUERY_KEY","getQueryKey","pageIndex","previousPageData","includes","next_cursor","useSlackChannels","queryOptions","knock","useKnockClient","knockSlackChannelId","tenantId","connectionStatus","useKnockSlackClient","fetchChannels","queryKey","slack","getChannels","tenant","knockChannelId","cursor","limit","limitPerPage","types","data","error","isLoading","isValidating","size","setSize","mutate","useSWRInfinite","initialSize","currentPage","length","hasNextPage","slackChannels","useMemo","flatMap","page","slack_channels","filter","channel","maxCount","useEffect","refetch"],"mappings":"wXAOMA,EAAY,IACZC,EAAiB,IACjBC,EAAgB,iCAEhBC,EAAY,iBAclB,SAASC,EACPC,EACAC,EACU,CAEV,OAAID,IAAc,EACT,CAACF,EAAW,EAAE,EAInBG,GAAoB,CAAC,GAAI,IAAI,EAAEC,SAASD,EAAiBE,WAAW,EAC/D,KAIF,CAACL,EAAWG,EAAiBE,aAAe,EAAE,CACvD,CAEA,SAASC,EAAiB,CACxBC,aAAAA,CACqB,EAA0B,SAC/C,MAAMC,EAAQC,EAAAA,eAAe,EACvB,CAAEC,oBAAAA,EAAqBC,SAAAA,EAAUC,iBAAAA,GACrCC,sBAAoB,EAEhBC,EAAiBC,GACdP,EAAMQ,MAAMC,YAAY,CAC7BC,OAAQP,EACRQ,eAAgBT,EAChBH,aAAc,CACZ,GAAGA,EACHa,OAAQL,EAAWA,EAAS,CAAC,EAAI,GACjCM,OAAOd,GAAAA,YAAAA,EAAce,eAAgBxB,EACrCyB,OAAOhB,GAAAA,YAAAA,EAAcgB,QAASxB,CAAAA,CAChC,CACD,EAGG,CAAEyB,KAAAA,EAAMC,MAAAA,EAAOC,UAAAA,EAAWC,aAAAA,EAAcC,KAAAA,EAAMC,QAAAA,EAASC,OAAAA,CAAAA,EAC3DC,EAAyC9B,QAAAA,EAAaa,EAAe,CACnEkB,YAAa,CAAA,CACd,EAEGC,GAAcT,GAAAA,YAAAA,EAAMU,SAAU,EAE9BC,EACJF,IAAgB,GACfT,KACCA,EAAAA,EAAKS,CAAW,IAAhBT,YAAAA,EAAmBnB,gBACnBmB,EAAAA,EAAKS,CAAW,IAAhBT,YAAAA,EAAmBnB,eAAgB,GAEjC+B,EAAgCC,EAAAA,QACpC,KACGb,GAAQ,IACNc,QAAkBC,GAAAA,GAAAA,YAAAA,EAAMC,cAAc,EACtCC,UAAoB,CAAC,CAACC,CAAO,EAClC,CAAClB,CAAI,CACP,EAEMmB,GAAWpC,GAAAA,YAAAA,EAAcoC,WAAY9C,EAE3C+C,OAAAA,EAAAA,UAAU,IAAM,CAEZhC,IAAqB,aACrB,CAACa,GACDU,GACA,CAACT,GACD,CAACC,GACDS,EAAcF,OAASS,GAIvBd,EAAQD,EAAO,CAAC,CAEjB,EAAA,CACDQ,EAAcF,OACdL,EACAD,EACAO,EACAT,EACAC,EACAgB,EACAlB,EACAb,CAAgB,CACjB,EAEM,CACLY,KAAMY,EACNV,UAAWA,GAAaC,EACxBkB,QAASA,IAAMf,EAAO,CACxB,CACF"}
1
+ {"version":3,"file":"useSlackChannels.js","sources":["../../../../../src/modules/slack/hooks/useSlackChannels.ts"],"sourcesContent":["import { SlackChannelQueryOptions, useKnockSlackClient } from \"..\";\nimport { GetSlackChannelsResponse, SlackChannel } from \"@knocklabs/client\";\nimport { useEffect, useMemo } from \"react\";\nimport useSWRInfinite from \"swr/infinite\";\n\nimport { useKnockClient } from \"../../core\";\n\nconst MAX_COUNT = 1000;\nconst LIMIT_PER_PAGE = 200;\nconst CHANNEL_TYPES = \"private_channel,public_channel\";\n\nconst QUERY_KEY = \"SLACK_CHANNELS\";\n\ntype UseSlackChannelsOptions = {\n queryOptions?: SlackChannelQueryOptions;\n};\n\ntype UseSlackChannelOutput = {\n data: SlackChannel[];\n isLoading: boolean;\n refetch: () => void;\n};\n\ntype QueryKey = [key: string, cursor: string] | null;\n\nfunction getQueryKey(\n pageIndex: number,\n previousPageData: GetSlackChannelsResponse,\n): QueryKey {\n // First page so just pass empty\n if (pageIndex === 0) {\n return [QUERY_KEY, \"\"];\n }\n\n // If there's no more data then return an empty next cursor\n if (previousPageData && [\"\", null].includes(previousPageData.next_cursor)) {\n return null;\n }\n\n // Next cursor exists so pass it\n return [QUERY_KEY, previousPageData.next_cursor ?? \"\"];\n}\n\nfunction useSlackChannels({\n queryOptions,\n}: UseSlackChannelsOptions): UseSlackChannelOutput {\n const knock = useKnockClient();\n const { knockSlackChannelId, tenantId, connectionStatus } =\n useKnockSlackClient();\n\n const fetchChannels = (queryKey: QueryKey) => {\n return knock.slack.getChannels({\n tenant: tenantId,\n knockChannelId: knockSlackChannelId,\n queryOptions: {\n ...queryOptions,\n cursor: queryKey?.[1],\n limit: queryOptions?.limitPerPage || LIMIT_PER_PAGE,\n types: queryOptions?.types || CHANNEL_TYPES,\n },\n });\n };\n\n const { data, error, isLoading, isValidating, setSize, mutate } =\n useSWRInfinite<GetSlackChannelsResponse>(getQueryKey, fetchChannels, {\n initialSize: 0,\n revalidateFirstPage: false,\n });\n\n const lastPage = data?.at(-1);\n const hasNextPage = lastPage === undefined || !!lastPage.next_cursor;\n\n const slackChannels: SlackChannel[] = useMemo(\n () =>\n (data ?? [])\n .flatMap((page) => page?.slack_channels)\n .filter((channel) => !!channel),\n [data],\n );\n\n const maxCount = queryOptions?.maxCount || MAX_COUNT;\n\n useEffect(() => {\n if (\n connectionStatus === \"connected\" &&\n !error &&\n hasNextPage &&\n !isLoading &&\n !isValidating &&\n slackChannels.length < maxCount\n ) {\n // Fetch a page at a time until we have nothing else left to fetch\n // or we've already hit the max amount of channels to fetch\n setSize((size) => size + 1);\n }\n }, [\n slackChannels.length,\n setSize,\n hasNextPage,\n isLoading,\n isValidating,\n maxCount,\n error,\n connectionStatus,\n ]);\n\n return {\n data: slackChannels,\n isLoading: isLoading || isValidating,\n refetch: () => mutate(),\n };\n}\n\nexport default useSlackChannels;\n"],"names":["MAX_COUNT","LIMIT_PER_PAGE","CHANNEL_TYPES","QUERY_KEY","getQueryKey","pageIndex","previousPageData","includes","next_cursor","useSlackChannels","queryOptions","knock","useKnockClient","knockSlackChannelId","tenantId","connectionStatus","useKnockSlackClient","fetchChannels","queryKey","slack","getChannels","tenant","knockChannelId","cursor","limit","limitPerPage","types","data","error","isLoading","isValidating","setSize","mutate","useSWRInfinite","initialSize","revalidateFirstPage","lastPage","at","hasNextPage","undefined","slackChannels","useMemo","flatMap","page","slack_channels","filter","channel","maxCount","useEffect","length","size","refetch"],"mappings":"wXAOMA,EAAY,IACZC,EAAiB,IACjBC,EAAgB,iCAEhBC,EAAY,iBAclB,SAASC,EACPC,EACAC,EACU,CAEV,OAAID,IAAc,EACT,CAACF,EAAW,EAAE,EAInBG,GAAoB,CAAC,GAAI,IAAI,EAAEC,SAASD,EAAiBE,WAAW,EAC/D,KAIF,CAACL,EAAWG,EAAiBE,aAAe,EAAE,CACvD,CAEA,SAASC,EAAiB,CACxBC,aAAAA,CACuB,EAA0B,CACjD,MAAMC,EAAQC,EAAAA,eAAe,EACvB,CAAEC,oBAAAA,EAAqBC,SAAAA,EAAUC,iBAAAA,GACrCC,sBAAoB,EAEhBC,EAAiBC,GACdP,EAAMQ,MAAMC,YAAY,CAC7BC,OAAQP,EACRQ,eAAgBT,EAChBH,aAAc,CACZ,GAAGA,EACHa,OAAQL,GAAAA,YAAAA,EAAW,GACnBM,OAAOd,GAAAA,YAAAA,EAAce,eAAgBxB,EACrCyB,OAAOhB,GAAAA,YAAAA,EAAcgB,QAASxB,CAAAA,CAChC,CACD,EAGG,CAAEyB,KAAAA,EAAMC,MAAAA,EAAOC,UAAAA,EAAWC,aAAAA,EAAcC,QAAAA,EAASC,OAAAA,CAAAA,EACrDC,EAAyC7B,QAAAA,EAAaa,EAAe,CACnEiB,YAAa,EACbC,oBAAqB,EAAA,CACtB,EAEGC,EAAWT,GAAAA,YAAAA,EAAMU,GAAG,IACpBC,EAAcF,IAAaG,QAAa,CAAC,CAACH,EAAS5B,YAEnDgC,EAAgCC,EAAAA,QACpC,KACGd,GAAQ,IACNe,QAAkBC,GAAAA,GAAAA,YAAAA,EAAMC,cAAc,EACtCC,UAAoB,CAAC,CAACC,CAAO,EAClC,CAACnB,CAAI,CACP,EAEMoB,GAAWrC,GAAAA,YAAAA,EAAcqC,WAAY/C,EAE3CgD,OAAAA,EAAAA,UAAU,IAAM,CAEZjC,IAAqB,aACrB,CAACa,GACDU,GACA,CAACT,GACD,CAACC,GACDU,EAAcS,OAASF,GAIdG,EAAAA,GAASA,EAAO,CAAC,CAE9B,EAAG,CACDV,EAAcS,OACdlB,EACAO,EACAT,EACAC,EACAiB,EACAnB,EACAb,CAAgB,CACjB,EAEM,CACLY,KAAMa,EACNX,UAAWA,GAAaC,EACxBqB,QAASA,IAAMnB,EAAO,CACxB,CACF"}
@@ -1,16 +1,12 @@
1
- import { useStore as i } from "zustand";
2
- function u(t, e) {
3
- const o = i(t.store);
4
- return (n) => {
5
- const r = n ?? e;
6
- return r ? r(o) : o;
7
- };
1
+ import { useStore as u } from "zustand";
2
+ function n(e) {
3
+ return (r) => u(e.store, r ?? ((o) => o));
8
4
  }
9
- function c(t, e) {
10
- return u(t, e);
5
+ function i(e, t) {
6
+ return n(e)(t ?? ((o) => o));
11
7
  }
12
8
  export {
13
- c as default,
14
- u as useCreateNotificationStore
9
+ i as default,
10
+ n as useCreateNotificationStore
15
11
  };
16
12
  //# sourceMappingURL=useNotificationStore.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useNotificationStore.mjs","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"sourcesContent":["import { Feed, type FeedStoreState } from \"@knocklabs/client\";\nimport { type StoreApi, type UseBoundStore, useStore } from \"zustand\";\n\n// A hook designed to create a `UseBoundStore` instance.\n// https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores\nfunction useCreateNotificationStore(\n feedClient: Feed,\n): UseBoundStore<StoreApi<FeedStoreState>>;\nfunction useCreateNotificationStore<T, U = T>(\n feedClient: Feed,\n externalSelector: (state: FeedStoreState) => U,\n): U;\n/**\n * Access a Bounded Store instance\n * Allow passing a selector down from useCreateNotificationStore OR useNotificationStore\n * We'll favor the the one passed later outside of useCreateNotificationStore instantiation\n */\nfunction useCreateNotificationStore<T, U = T>(\n feedClient: Feed,\n externalSelector?: (state: FeedStoreState) => U,\n) {\n const store = useStore(feedClient.store);\n\n return (selector?: (state: FeedStoreState) => U) => {\n const innerSelector = selector ?? externalSelector;\n return innerSelector ? innerSelector(store) : store;\n };\n}\n\n/**\n * A hook used to access content within the notification store.\n *\n * A selector can be used to access a subset of the store state.\n *\n * @example\n *\n * ```ts\n * const { items, metadata } = useNotificationStore(feedClient, (state) => ({\n * items: state.items,\n * metadata: state.metadata,\n * }));\n * ```\n */\nfunction useNotificationStore(\n feedClient: Feed,\n): UseBoundStore<StoreApi<FeedStoreState>>;\nfunction useNotificationStore<T>(\n feedClient: Feed,\n selector: (state: FeedStoreState) => T,\n): T;\nfunction useNotificationStore<T, U = T>(\n feedClient: Feed,\n selector?: (state: FeedStoreState) => U,\n) {\n return useCreateNotificationStore(feedClient, selector!);\n}\n\nexport { useCreateNotificationStore };\nexport default useNotificationStore;\n"],"names":["useCreateNotificationStore","feedClient","externalSelector","store","useStore","selector","innerSelector","useNotificationStore"],"mappings":";AAiBA,SAASA,EACPC,GACAC,GACA;AACMC,QAAAA,IAAQC,EAASH,EAAWE,KAAK;AAEvC,SAAO,CAACE,MAA4C;AAClD,UAAMC,IAAgBD,KAAYH;AAC3BI,WAAAA,IAAgBA,EAAcH,CAAK,IAAIA;AAAAA,EAChD;AACF;AAuBA,SAASI,EACPN,GACAI,GACA;AACOL,SAAAA,EAA2BC,GAAYI,CAAS;AACzD;"}
1
+ {"version":3,"file":"useNotificationStore.mjs","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"sourcesContent":["import { Feed, type FeedStoreState } from \"@knocklabs/client\";\nimport { type StoreApi, type UseBoundStore, useStore } from \"zustand\";\n\nexport type Selector<T> = (state: FeedStoreState) => T;\n\n/**\n * Access a Bounded Store instance by converting our vanilla store to a UseBoundStore\n * https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores\n * Allow passing a selector down from useCreateNotificationStore OR useNotificationStore\n * We'll favor the the one passed later outside of useCreateNotificationStore instantiation\n */\nfunction useCreateNotificationStore<T>(\n feedClient: Feed,\n): UseBoundStore<StoreApi<FeedStoreState>> {\n // Keep selector optional for external use\n // useStore requires a selector so we'll pass in a default one when not provided\n const useBoundedStore = (selector?: Selector<T>) =>\n useStore(feedClient.store, selector ?? ((state) => state as T));\n return useBoundedStore as UseBoundStore<StoreApi<FeedStoreState>>;\n}\n\n/**\n * A hook used to access content within the notification store.\n *\n * @example\n *\n * ```ts\n * const { items, metadata } = useNotificationStore(feedClient);\n * ```\n *\n * A selector can be used to access a subset of the store state.\n *\n * @example\n *\n * ```ts\n * const { items, metadata } = useNotificationStore(feedClient, (state) => ({\n * items: state.items,\n * metadata: state.metadata,\n * }));\n * ```\n */\nfunction useNotificationStore(feedClient: Feed): FeedStoreState;\nfunction useNotificationStore<T>(feedClient: Feed, selector: Selector<T>): T;\nfunction useNotificationStore<T>(\n feedClient: Feed,\n selector?: Selector<T>,\n): T | FeedStoreState {\n const useStoreLocal = useCreateNotificationStore(feedClient);\n return useStoreLocal(selector ?? ((state) => state as T));\n}\n\nexport { useCreateNotificationStore };\nexport default useNotificationStore;\n"],"names":["useCreateNotificationStore","feedClient","useBoundedStore","selector","useStore","store","state","useNotificationStore","useStoreLocal"],"mappings":";AAWA,SAASA,EACPC,GACyC;AAKlCC,SAFiBA,CAACC,MACvBC,EAASH,EAAWI,OAAOF,MAAcG,OAAUA,EAAW;AAElE;AAwBA,SAASC,EACPN,GACAE,GACoB;AAEbK,SADeR,EAA2BC,CAAU,EACtCE,MAAcG,CAAAA,MAAUA,EAAW;AAC1D;"}
@@ -1,50 +1,51 @@
1
- import { useMemo as S, useEffect as r } from "react";
2
- import E from "swr/infinite";
3
- import { useKnockClient as g } from "../../core/context/KnockProvider.mjs";
1
+ import { useMemo as C, useEffect as S } from "react";
2
+ import g from "swr/infinite";
3
+ import { useKnockClient as E } from "../../core/context/KnockProvider.mjs";
4
4
  import "@knocklabs/client";
5
5
  import "zustand/shallow";
6
6
  import "date-fns";
7
7
  import { useKnockMsTeamsClient as x } from "../context/KnockMsTeamsProvider.mjs";
8
8
  const I = 1e3, T = "MS_TEAMS_TEAMS";
9
- function $(t, e) {
10
- return t === 0 ? [T, ""] : e && ["", null].includes(e.skip_token) ? null : [T, e.skip_token ?? ""];
9
+ function $(t, n) {
10
+ return t === 0 ? [T, ""] : n && ["", null].includes(n.skip_token) ? null : [T, n.skip_token ?? ""];
11
11
  }
12
- function U({
12
+ function R({
13
13
  queryOptions: t = {}
14
14
  }) {
15
- const e = g(), {
15
+ const n = E(), {
16
16
  knockMsTeamsChannelId: M,
17
17
  tenantId: _,
18
- connectionStatus: o
19
- } = x(), h = (n) => e.msTeams.getTeams({
18
+ connectionStatus: l
19
+ } = x(), r = (e) => n.msTeams.getTeams({
20
20
  knockChannelId: M,
21
21
  tenant: _,
22
22
  queryOptions: {
23
- $skiptoken: n == null ? void 0 : n[1],
23
+ $skiptoken: e == null ? void 0 : e[1],
24
24
  $top: t == null ? void 0 : t.limitPerPage,
25
25
  $filter: t == null ? void 0 : t.filter,
26
26
  $select: t == null ? void 0 : t.select
27
27
  }
28
28
  }), {
29
- data: c,
30
- error: l,
31
- isLoading: m,
32
- isValidating: s,
29
+ data: a,
30
+ error: o,
31
+ isLoading: s,
32
+ isValidating: c,
33
33
  setSize: i,
34
- mutate: C
35
- } = E($, h, {
34
+ mutate: h
35
+ } = g($, r, {
36
36
  initialSize: 0,
37
- revalidateOnFocus: !1
38
- }), f = c == null ? void 0 : c.at(-1), k = f === void 0 || !!f.skip_token, a = S(() => (c ?? []).flatMap((n) => n == null ? void 0 : n.ms_teams_teams).filter((n) => !!n), [c]), d = (t == null ? void 0 : t.maxCount) || I;
39
- return r(() => {
40
- o === "connected" && !l && k && !m && !s && a.length < d && i((n) => n + 1);
41
- }, [a.length, i, k, m, s, d, l, o]), {
42
- data: a,
43
- isLoading: m || s,
44
- refetch: () => C()
37
+ revalidateOnFocus: !1,
38
+ revalidateFirstPage: !1
39
+ }), f = a == null ? void 0 : a.at(-1), k = f === void 0 || !!f.skip_token, m = C(() => (a ?? []).flatMap((e) => e == null ? void 0 : e.ms_teams_teams).filter((e) => !!e), [a]), d = (t == null ? void 0 : t.maxCount) || I;
40
+ return S(() => {
41
+ l === "connected" && !o && k && !s && !c && m.length < d && i((e) => e + 1);
42
+ }, [m.length, i, k, s, c, d, o, l]), {
43
+ data: m,
44
+ isLoading: s || c,
45
+ refetch: () => h()
45
46
  };
46
47
  }
47
48
  export {
48
- U as default
49
+ R as default
49
50
  };
50
51
  //# sourceMappingURL=useMsTeamsTeams.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMsTeamsTeams.mjs","sources":["../../../../../src/modules/ms-teams/hooks/useMsTeamsTeams.ts"],"sourcesContent":["import { GetMsTeamsTeamsResponse, MsTeamsTeam } from \"@knocklabs/client\";\nimport { useEffect, useMemo } from \"react\";\nimport useSWRInfinite from \"swr/infinite\";\n\nimport { useKnockClient } from \"../../core\";\nimport { useKnockMsTeamsClient } from \"../context\";\nimport { MsTeamsTeamQueryOptions } from \"../interfaces\";\n\nconst MAX_COUNT = 1000;\n\nconst QUERY_KEY = \"MS_TEAMS_TEAMS\";\n\ntype UseMsTeamsTeamsProps = {\n queryOptions?: MsTeamsTeamQueryOptions;\n};\n\ntype UseMsTeamsTeamsOutput = {\n data: MsTeamsTeam[];\n isLoading: boolean;\n refetch: () => void;\n};\n\ntype QueryKey = [key: string, skiptoken: string] | null;\n\nfunction getQueryKey(\n pageIndex: number,\n previousPageData: GetMsTeamsTeamsResponse,\n): QueryKey {\n // First page so just pass empty\n if (pageIndex === 0) {\n return [QUERY_KEY, \"\"];\n }\n\n // If there's no more data then return an empty next skiptoken\n if (previousPageData && [\"\", null].includes(previousPageData.skip_token)) {\n return null;\n }\n\n // Next skiptoken exists so pass it\n return [QUERY_KEY, previousPageData.skip_token ?? \"\"];\n}\n\nfunction useMsTeamsTeams({\n queryOptions = {},\n}: UseMsTeamsTeamsProps): UseMsTeamsTeamsOutput {\n const knock = useKnockClient();\n const { knockMsTeamsChannelId, tenantId, connectionStatus } =\n useKnockMsTeamsClient();\n\n const fetchTeams = (queryKey: QueryKey) =>\n knock.msTeams.getTeams({\n knockChannelId: knockMsTeamsChannelId,\n tenant: tenantId,\n queryOptions: {\n $skiptoken: queryKey?.[1],\n $top: queryOptions?.limitPerPage,\n $filter: queryOptions?.filter,\n $select: queryOptions?.select,\n },\n });\n\n const { data, error, isLoading, isValidating, setSize, mutate } =\n useSWRInfinite<GetMsTeamsTeamsResponse>(getQueryKey, fetchTeams, {\n initialSize: 0,\n revalidateOnFocus: false,\n });\n\n const lastPage = data?.at(-1);\n const hasNextPage = lastPage === undefined || !!lastPage.skip_token;\n\n const teams = useMemo(\n () =>\n (data ?? [])\n .flatMap((page) => page?.ms_teams_teams)\n .filter((team) => !!team),\n [data],\n );\n\n const maxCount = queryOptions?.maxCount || MAX_COUNT;\n\n useEffect(() => {\n if (\n connectionStatus === \"connected\" &&\n !error &&\n hasNextPage &&\n !isLoading &&\n !isValidating &&\n teams.length < maxCount\n ) {\n // Fetch a page at a time until we have nothing else left to fetch\n // or we've already hit the max amount of teams to fetch\n setSize((size) => size + 1);\n }\n }, [\n teams.length,\n setSize,\n hasNextPage,\n isLoading,\n isValidating,\n maxCount,\n error,\n connectionStatus,\n ]);\n\n return {\n data: teams,\n isLoading: isLoading || isValidating,\n refetch: () => mutate(),\n };\n}\n\nexport default useMsTeamsTeams;\n"],"names":["MAX_COUNT","QUERY_KEY","getQueryKey","pageIndex","previousPageData","includes","skip_token","useMsTeamsTeams","queryOptions","knock","useKnockClient","knockMsTeamsChannelId","tenantId","connectionStatus","useKnockMsTeamsClient","fetchTeams","queryKey","msTeams","getTeams","knockChannelId","tenant","$skiptoken","$top","limitPerPage","$filter","filter","$select","select","data","error","isLoading","isValidating","setSize","mutate","useSWRInfinite","initialSize","revalidateOnFocus","lastPage","at","hasNextPage","undefined","teams","useMemo","flatMap","page","ms_teams_teams","team","maxCount","useEffect","length","size","refetch"],"mappings":";;;;;;;AAQA,MAAMA,IAAY,KAEZC,IAAY;AAclB,SAASC,EACPC,GACAC,GACU;AAEV,SAAID,MAAc,IACT,CAACF,GAAW,EAAE,IAInBG,KAAoB,CAAC,IAAI,IAAI,EAAEC,SAASD,EAAiBE,UAAU,IAC9D,OAIF,CAACL,GAAWG,EAAiBE,cAAc,EAAE;AACtD;AAEA,SAASC,EAAgB;AAAA,EACvBC,cAAAA,IAAe,CAAA;AACK,GAA0B;AAC9C,QAAMC,IAAQC,EAAe,GACvB;AAAA,IAAEC,uBAAAA;AAAAA,IAAuBC,UAAAA;AAAAA,IAAUC,kBAAAA;AAAAA,MACvCC,EAAsB,GAElBC,IAAaA,CAACC,MAClBP,EAAMQ,QAAQC,SAAS;AAAA,IACrBC,gBAAgBR;AAAAA,IAChBS,QAAQR;AAAAA,IACRJ,cAAc;AAAA,MACZa,YAAYL,KAAAA,gBAAAA,EAAW;AAAA,MACvBM,MAAMd,KAAAA,gBAAAA,EAAce;AAAAA,MACpBC,SAAShB,KAAAA,gBAAAA,EAAciB;AAAAA,MACvBC,SAASlB,KAAAA,gBAAAA,EAAcmB;AAAAA,IAAAA;AAAAA,EACzB,CACD,GAEG;AAAA,IAAEC,MAAAA;AAAAA,IAAMC,OAAAA;AAAAA,IAAOC,WAAAA;AAAAA,IAAWC,cAAAA;AAAAA,IAAcC,SAAAA;AAAAA,IAASC,QAAAA;AAAAA,EAAAA,IACrDC,EAAwChC,GAAaa,GAAY;AAAA,IAC/DoB,aAAa;AAAA,IACbC,mBAAmB;AAAA,EAAA,CACpB,GAEGC,IAAWT,KAAAA,gBAAAA,EAAMU,GAAG,KACpBC,IAAcF,MAAaG,UAAa,CAAC,CAACH,EAAS/B,YAEnDmC,IAAQC,EACZ,OACGd,KAAQ,IACNe,QAASC,CAASA,MAAAA,KAAAA,gBAAAA,EAAMC,cAAc,EACtCpB,OAAQqB,OAAS,CAAC,CAACA,CAAI,GAC5B,CAAClB,CAAI,CACP,GAEMmB,KAAWvC,KAAAA,gBAAAA,EAAcuC,aAAY/C;AAE3CgD,SAAAA,EAAU,MAAM;AAEZnC,IAAAA,MAAqB,eACrB,CAACgB,KACDU,KACA,CAACT,KACD,CAACC,KACDU,EAAMQ,SAASF,KAING,EAAAA,CAAAA,MAASA,IAAO,CAAC;AAAA,EAE9B,GAAG,CACDT,EAAMQ,QACNjB,GACAO,GACAT,GACAC,GACAgB,GACAlB,GACAhB,CAAgB,CACjB,GAEM;AAAA,IACLe,MAAMa;AAAAA,IACNX,WAAWA,KAAaC;AAAAA,IACxBoB,SAASA,MAAMlB,EAAO;AAAA,EACxB;AACF;"}
1
+ {"version":3,"file":"useMsTeamsTeams.mjs","sources":["../../../../../src/modules/ms-teams/hooks/useMsTeamsTeams.ts"],"sourcesContent":["import { GetMsTeamsTeamsResponse, MsTeamsTeam } from \"@knocklabs/client\";\nimport { useEffect, useMemo } from \"react\";\nimport useSWRInfinite from \"swr/infinite\";\n\nimport { useKnockClient } from \"../../core\";\nimport { useKnockMsTeamsClient } from \"../context\";\nimport { MsTeamsTeamQueryOptions } from \"../interfaces\";\n\nconst MAX_COUNT = 1000;\n\nconst QUERY_KEY = \"MS_TEAMS_TEAMS\";\n\ntype UseMsTeamsTeamsOptions = {\n queryOptions?: MsTeamsTeamQueryOptions;\n};\n\ntype UseMsTeamsTeamsOutput = {\n data: MsTeamsTeam[];\n isLoading: boolean;\n refetch: () => void;\n};\n\ntype QueryKey = [key: string, skiptoken: string] | null;\n\nfunction getQueryKey(\n pageIndex: number,\n previousPageData: GetMsTeamsTeamsResponse,\n): QueryKey {\n // First page so just pass empty\n if (pageIndex === 0) {\n return [QUERY_KEY, \"\"];\n }\n\n // If there's no more data then return an empty next skiptoken\n if (previousPageData && [\"\", null].includes(previousPageData.skip_token)) {\n return null;\n }\n\n // Next skiptoken exists so pass it\n return [QUERY_KEY, previousPageData.skip_token ?? \"\"];\n}\n\nfunction useMsTeamsTeams({\n queryOptions = {},\n}: UseMsTeamsTeamsOptions): UseMsTeamsTeamsOutput {\n const knock = useKnockClient();\n const { knockMsTeamsChannelId, tenantId, connectionStatus } =\n useKnockMsTeamsClient();\n\n const fetchTeams = (queryKey: QueryKey) =>\n knock.msTeams.getTeams({\n knockChannelId: knockMsTeamsChannelId,\n tenant: tenantId,\n queryOptions: {\n $skiptoken: queryKey?.[1],\n $top: queryOptions?.limitPerPage,\n $filter: queryOptions?.filter,\n $select: queryOptions?.select,\n },\n });\n\n const { data, error, isLoading, isValidating, setSize, mutate } =\n useSWRInfinite<GetMsTeamsTeamsResponse>(getQueryKey, fetchTeams, {\n initialSize: 0,\n revalidateOnFocus: false,\n revalidateFirstPage: false,\n });\n\n const lastPage = data?.at(-1);\n const hasNextPage = lastPage === undefined || !!lastPage.skip_token;\n\n const teams = useMemo(\n () =>\n (data ?? [])\n .flatMap((page) => page?.ms_teams_teams)\n .filter((team) => !!team),\n [data],\n );\n\n const maxCount = queryOptions?.maxCount || MAX_COUNT;\n\n useEffect(() => {\n if (\n connectionStatus === \"connected\" &&\n !error &&\n hasNextPage &&\n !isLoading &&\n !isValidating &&\n teams.length < maxCount\n ) {\n // Fetch a page at a time until we have nothing else left to fetch\n // or we've already hit the max amount of teams to fetch\n setSize((size) => size + 1);\n }\n }, [\n teams.length,\n setSize,\n hasNextPage,\n isLoading,\n isValidating,\n maxCount,\n error,\n connectionStatus,\n ]);\n\n return {\n data: teams,\n isLoading: isLoading || isValidating,\n refetch: () => mutate(),\n };\n}\n\nexport default useMsTeamsTeams;\n"],"names":["MAX_COUNT","QUERY_KEY","getQueryKey","pageIndex","previousPageData","includes","skip_token","useMsTeamsTeams","queryOptions","knock","useKnockClient","knockMsTeamsChannelId","tenantId","connectionStatus","useKnockMsTeamsClient","fetchTeams","queryKey","msTeams","getTeams","knockChannelId","tenant","$skiptoken","$top","limitPerPage","$filter","filter","$select","select","data","error","isLoading","isValidating","setSize","mutate","useSWRInfinite","initialSize","revalidateOnFocus","revalidateFirstPage","lastPage","at","hasNextPage","undefined","teams","useMemo","flatMap","page","ms_teams_teams","team","maxCount","useEffect","length","size","refetch"],"mappings":";;;;;;;AAQA,MAAMA,IAAY,KAEZC,IAAY;AAclB,SAASC,EACPC,GACAC,GACU;AAEV,SAAID,MAAc,IACT,CAACF,GAAW,EAAE,IAInBG,KAAoB,CAAC,IAAI,IAAI,EAAEC,SAASD,EAAiBE,UAAU,IAC9D,OAIF,CAACL,GAAWG,EAAiBE,cAAc,EAAE;AACtD;AAEA,SAASC,EAAgB;AAAA,EACvBC,cAAAA,IAAe,CAAA;AACO,GAA0B;AAChD,QAAMC,IAAQC,EAAe,GACvB;AAAA,IAAEC,uBAAAA;AAAAA,IAAuBC,UAAAA;AAAAA,IAAUC,kBAAAA;AAAAA,MACvCC,EAAsB,GAElBC,IAAaA,CAACC,MAClBP,EAAMQ,QAAQC,SAAS;AAAA,IACrBC,gBAAgBR;AAAAA,IAChBS,QAAQR;AAAAA,IACRJ,cAAc;AAAA,MACZa,YAAYL,KAAAA,gBAAAA,EAAW;AAAA,MACvBM,MAAMd,KAAAA,gBAAAA,EAAce;AAAAA,MACpBC,SAAShB,KAAAA,gBAAAA,EAAciB;AAAAA,MACvBC,SAASlB,KAAAA,gBAAAA,EAAcmB;AAAAA,IAAAA;AAAAA,EACzB,CACD,GAEG;AAAA,IAAEC,MAAAA;AAAAA,IAAMC,OAAAA;AAAAA,IAAOC,WAAAA;AAAAA,IAAWC,cAAAA;AAAAA,IAAcC,SAAAA;AAAAA,IAASC,QAAAA;AAAAA,EAAAA,IACrDC,EAAwChC,GAAaa,GAAY;AAAA,IAC/DoB,aAAa;AAAA,IACbC,mBAAmB;AAAA,IACnBC,qBAAqB;AAAA,EAAA,CACtB,GAEGC,IAAWV,KAAAA,gBAAAA,EAAMW,GAAG,KACpBC,IAAcF,MAAaG,UAAa,CAAC,CAACH,EAAShC,YAEnDoC,IAAQC,EACZ,OACGf,KAAQ,IACNgB,QAASC,CAASA,MAAAA,KAAAA,gBAAAA,EAAMC,cAAc,EACtCrB,OAAQsB,OAAS,CAAC,CAACA,CAAI,GAC5B,CAACnB,CAAI,CACP,GAEMoB,KAAWxC,KAAAA,gBAAAA,EAAcwC,aAAYhD;AAE3CiD,SAAAA,EAAU,MAAM;AAEZpC,IAAAA,MAAqB,eACrB,CAACgB,KACDW,KACA,CAACV,KACD,CAACC,KACDW,EAAMQ,SAASF,KAING,EAAAA,CAAAA,MAASA,IAAO,CAAC;AAAA,EAE9B,GAAG,CACDT,EAAMQ,QACNlB,GACAQ,GACAV,GACAC,GACAiB,GACAnB,GACAhB,CAAgB,CACjB,GAEM;AAAA,IACLe,MAAMc;AAAAA,IACNZ,WAAWA,KAAaC;AAAAA,IACxBqB,SAASA,MAAMnB,EAAO;AAAA,EACxB;AACF;"}
@@ -1,53 +1,52 @@
1
- import { useKnockSlackClient as I } from "../context/KnockSlackProvider.mjs";
2
- import { useMemo as L, useEffect as N } from "react";
1
+ import { useKnockSlackClient as E } from "../context/KnockSlackProvider.mjs";
2
+ import { useMemo as u, useEffect as x } from "react";
3
3
  import "../../i18n/context/KnockI18nProvider.mjs";
4
- import g from "swr/infinite";
5
- import { useKnockClient as A } from "../../core/context/KnockProvider.mjs";
4
+ import I from "swr/infinite";
5
+ import { useKnockClient as L } from "../../core/context/KnockProvider.mjs";
6
6
  import "@knocklabs/client";
7
7
  import "zustand/shallow";
8
8
  import "date-fns";
9
9
  import "swr";
10
- const P = 1e3, K = 200, M = "private_channel,public_channel", u = "SLACK_CHANNELS";
11
- function z(n, e) {
12
- return n === 0 ? [u, ""] : e && ["", null].includes(e.next_cursor) ? null : [u, e.next_cursor ?? ""];
10
+ const N = 1e3, P = 200, g = "private_channel,public_channel", k = "SLACK_CHANNELS";
11
+ function A(n, c) {
12
+ return n === 0 ? [k, ""] : c && ["", null].includes(c.next_cursor) ? null : [k, c.next_cursor ?? ""];
13
13
  }
14
- function W({
14
+ function v({
15
15
  queryOptions: n
16
16
  }) {
17
- var C, _;
18
- const e = A(), {
19
- knockSlackChannelId: S,
20
- tenantId: d,
21
- connectionStatus: a
22
- } = I(), x = (c) => e.slack.getChannels({
23
- tenant: d,
24
- knockChannelId: S,
17
+ const c = L(), {
18
+ knockSlackChannelId: C,
19
+ tenantId: _,
20
+ connectionStatus: s
21
+ } = E(), d = (t) => c.slack.getChannels({
22
+ tenant: _,
23
+ knockChannelId: C,
25
24
  queryOptions: {
26
25
  ...n,
27
- cursor: c ? c[1] : "",
28
- limit: (n == null ? void 0 : n.limitPerPage) || K,
29
- types: (n == null ? void 0 : n.types) || M
26
+ cursor: t == null ? void 0 : t[1],
27
+ limit: (n == null ? void 0 : n.limitPerPage) || P,
28
+ types: (n == null ? void 0 : n.types) || g
30
29
  }
31
30
  }), {
32
- data: t,
31
+ data: l,
33
32
  error: i,
34
- isLoading: l,
35
- isValidating: o,
36
- size: m,
37
- setSize: f,
38
- mutate: E
39
- } = g(z, x, {
40
- initialSize: 0
41
- }), r = (t == null ? void 0 : t.length) || 0, h = r === 0 || t && ((C = t[r]) == null ? void 0 : C.next_cursor) && ((_ = t[r]) == null ? void 0 : _.next_cursor) !== "", s = L(() => (t ?? []).flatMap((c) => c == null ? void 0 : c.slack_channels).filter((c) => !!c), [t]), k = (n == null ? void 0 : n.maxCount) || P;
42
- return N(() => {
43
- a === "connected" && !i && h && !l && !o && s.length < k && f(m + 1);
44
- }, [s.length, f, m, h, l, o, k, i, a]), {
45
- data: s,
46
- isLoading: l || o,
47
- refetch: () => E()
33
+ isLoading: e,
34
+ isValidating: a,
35
+ setSize: r,
36
+ mutate: S
37
+ } = I(A, d, {
38
+ initialSize: 0,
39
+ revalidateFirstPage: !1
40
+ }), m = l == null ? void 0 : l.at(-1), f = m === void 0 || !!m.next_cursor, o = u(() => (l ?? []).flatMap((t) => t == null ? void 0 : t.slack_channels).filter((t) => !!t), [l]), h = (n == null ? void 0 : n.maxCount) || N;
41
+ return x(() => {
42
+ s === "connected" && !i && f && !e && !a && o.length < h && r((t) => t + 1);
43
+ }, [o.length, r, f, e, a, h, i, s]), {
44
+ data: o,
45
+ isLoading: e || a,
46
+ refetch: () => S()
48
47
  };
49
48
  }
50
49
  export {
51
- W as default
50
+ v as default
52
51
  };
53
52
  //# sourceMappingURL=useSlackChannels.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSlackChannels.mjs","sources":["../../../../../src/modules/slack/hooks/useSlackChannels.ts"],"sourcesContent":["import { SlackChannelQueryOptions, useKnockSlackClient } from \"..\";\nimport { GetSlackChannelsResponse, SlackChannel } from \"@knocklabs/client\";\nimport { useEffect, useMemo } from \"react\";\nimport useSWRInfinite from \"swr/infinite\";\n\nimport { useKnockClient } from \"../../core\";\n\nconst MAX_COUNT = 1000;\nconst LIMIT_PER_PAGE = 200;\nconst CHANNEL_TYPES = \"private_channel,public_channel\";\n\nconst QUERY_KEY = \"SLACK_CHANNELS\";\n\ntype UseSlackChannelsProps = {\n queryOptions?: SlackChannelQueryOptions;\n};\n\ntype UseSlackChannelOutput = {\n data: SlackChannel[];\n isLoading: boolean;\n refetch: () => void;\n};\n\ntype QueryKey = [key: string, cursor: string] | null;\n\nfunction getQueryKey(\n pageIndex: number,\n previousPageData: GetSlackChannelsResponse,\n): QueryKey {\n // First page so just pass empty\n if (pageIndex === 0) {\n return [QUERY_KEY, \"\"];\n }\n\n // If there's no more data then return an empty next cursor\n if (previousPageData && [\"\", null].includes(previousPageData.next_cursor)) {\n return null;\n }\n\n // Next cursor exists so pass it\n return [QUERY_KEY, previousPageData.next_cursor ?? \"\"];\n}\n\nfunction useSlackChannels({\n queryOptions,\n}: UseSlackChannelsProps): UseSlackChannelOutput {\n const knock = useKnockClient();\n const { knockSlackChannelId, tenantId, connectionStatus } =\n useKnockSlackClient();\n\n const fetchChannels = (queryKey: QueryKey) => {\n return knock.slack.getChannels({\n tenant: tenantId,\n knockChannelId: knockSlackChannelId,\n queryOptions: {\n ...queryOptions,\n cursor: queryKey ? queryKey[1] : \"\",\n limit: queryOptions?.limitPerPage || LIMIT_PER_PAGE,\n types: queryOptions?.types || CHANNEL_TYPES,\n },\n });\n };\n\n const { data, error, isLoading, isValidating, size, setSize, mutate } =\n useSWRInfinite<GetSlackChannelsResponse>(getQueryKey, fetchChannels, {\n initialSize: 0,\n });\n\n const currentPage = data?.length || 0;\n\n const hasNextPage =\n currentPage === 0 ||\n (data &&\n data[currentPage]?.next_cursor &&\n data[currentPage]?.next_cursor !== \"\");\n\n const slackChannels: SlackChannel[] = useMemo(\n () =>\n (data ?? [])\n .flatMap((page) => page?.slack_channels)\n .filter((channel) => !!channel),\n [data],\n );\n\n const maxCount = queryOptions?.maxCount || MAX_COUNT;\n\n useEffect(() => {\n if (\n connectionStatus === \"connected\" &&\n !error &&\n hasNextPage &&\n !isLoading &&\n !isValidating &&\n slackChannels.length < maxCount\n ) {\n // Fetch a page at a time until we have nothing else left to fetch\n // or we've already hit the max amount of channels to fetch\n setSize(size + 1);\n }\n }, [\n slackChannels.length,\n setSize,\n size,\n hasNextPage,\n isLoading,\n isValidating,\n maxCount,\n error,\n connectionStatus,\n ]);\n\n return {\n data: slackChannels,\n isLoading: isLoading || isValidating,\n refetch: () => mutate(),\n };\n}\n\nexport default useSlackChannels;\n"],"names":["MAX_COUNT","LIMIT_PER_PAGE","CHANNEL_TYPES","QUERY_KEY","getQueryKey","pageIndex","previousPageData","includes","next_cursor","useSlackChannels","queryOptions","knock","useKnockClient","knockSlackChannelId","tenantId","connectionStatus","useKnockSlackClient","fetchChannels","queryKey","slack","getChannels","tenant","knockChannelId","cursor","limit","limitPerPage","types","data","error","isLoading","isValidating","size","setSize","mutate","useSWRInfinite","initialSize","currentPage","length","hasNextPage","slackChannels","useMemo","flatMap","page","slack_channels","filter","channel","maxCount","useEffect","refetch"],"mappings":";;;;;;;;;AAOA,MAAMA,IAAY,KACZC,IAAiB,KACjBC,IAAgB,kCAEhBC,IAAY;AAclB,SAASC,EACPC,GACAC,GACU;AAEV,SAAID,MAAc,IACT,CAACF,GAAW,EAAE,IAInBG,KAAoB,CAAC,IAAI,IAAI,EAAEC,SAASD,EAAiBE,WAAW,IAC/D,OAIF,CAACL,GAAWG,EAAiBE,eAAe,EAAE;AACvD;AAEA,SAASC,EAAiB;AAAA,EACxBC,cAAAA;AACqB,GAA0B;;AAC/C,QAAMC,IAAQC,EAAe,GACvB;AAAA,IAAEC,qBAAAA;AAAAA,IAAqBC,UAAAA;AAAAA,IAAUC,kBAAAA;AAAAA,MACrCC,EAAoB,GAEhBC,IAAgBA,CAACC,MACdP,EAAMQ,MAAMC,YAAY;AAAA,IAC7BC,QAAQP;AAAAA,IACRQ,gBAAgBT;AAAAA,IAChBH,cAAc;AAAA,MACZ,GAAGA;AAAAA,MACHa,QAAQL,IAAWA,EAAS,CAAC,IAAI;AAAA,MACjCM,QAAOd,KAAAA,gBAAAA,EAAce,iBAAgBxB;AAAAA,MACrCyB,QAAOhB,KAAAA,gBAAAA,EAAcgB,UAASxB;AAAAA,IAAAA;AAAAA,EAChC,CACD,GAGG;AAAA,IAAEyB,MAAAA;AAAAA,IAAMC,OAAAA;AAAAA,IAAOC,WAAAA;AAAAA,IAAWC,cAAAA;AAAAA,IAAcC,MAAAA;AAAAA,IAAMC,SAAAA;AAAAA,IAASC,QAAAA;AAAAA,EAAAA,IAC3DC,EAAyC9B,GAAaa,GAAe;AAAA,IACnEkB,aAAa;AAAA,EAAA,CACd,GAEGC,KAAcT,KAAAA,gBAAAA,EAAMU,WAAU,GAE9BC,IACJF,MAAgB,KACfT,OACCA,IAAAA,EAAKS,CAAW,MAAhBT,gBAAAA,EAAmBnB,kBACnBmB,IAAAA,EAAKS,CAAW,MAAhBT,gBAAAA,EAAmBnB,iBAAgB,IAEjC+B,IAAgCC,EACpC,OACGb,KAAQ,IACNc,QAASC,CAASA,MAAAA,KAAAA,gBAAAA,EAAMC,cAAc,EACtCC,OAAQC,OAAY,CAAC,CAACA,CAAO,GAClC,CAAClB,CAAI,CACP,GAEMmB,KAAWpC,KAAAA,gBAAAA,EAAcoC,aAAY9C;AAE3C+C,SAAAA,EAAU,MAAM;AAEZhC,IAAAA,MAAqB,eACrB,CAACa,KACDU,KACA,CAACT,KACD,CAACC,KACDS,EAAcF,SAASS,KAIvBd,EAAQD,IAAO,CAAC;AAAA,EAEjB,GAAA,CACDQ,EAAcF,QACdL,GACAD,GACAO,GACAT,GACAC,GACAgB,GACAlB,GACAb,CAAgB,CACjB,GAEM;AAAA,IACLY,MAAMY;AAAAA,IACNV,WAAWA,KAAaC;AAAAA,IACxBkB,SAASA,MAAMf,EAAO;AAAA,EACxB;AACF;"}
1
+ {"version":3,"file":"useSlackChannels.mjs","sources":["../../../../../src/modules/slack/hooks/useSlackChannels.ts"],"sourcesContent":["import { SlackChannelQueryOptions, useKnockSlackClient } from \"..\";\nimport { GetSlackChannelsResponse, SlackChannel } from \"@knocklabs/client\";\nimport { useEffect, useMemo } from \"react\";\nimport useSWRInfinite from \"swr/infinite\";\n\nimport { useKnockClient } from \"../../core\";\n\nconst MAX_COUNT = 1000;\nconst LIMIT_PER_PAGE = 200;\nconst CHANNEL_TYPES = \"private_channel,public_channel\";\n\nconst QUERY_KEY = \"SLACK_CHANNELS\";\n\ntype UseSlackChannelsOptions = {\n queryOptions?: SlackChannelQueryOptions;\n};\n\ntype UseSlackChannelOutput = {\n data: SlackChannel[];\n isLoading: boolean;\n refetch: () => void;\n};\n\ntype QueryKey = [key: string, cursor: string] | null;\n\nfunction getQueryKey(\n pageIndex: number,\n previousPageData: GetSlackChannelsResponse,\n): QueryKey {\n // First page so just pass empty\n if (pageIndex === 0) {\n return [QUERY_KEY, \"\"];\n }\n\n // If there's no more data then return an empty next cursor\n if (previousPageData && [\"\", null].includes(previousPageData.next_cursor)) {\n return null;\n }\n\n // Next cursor exists so pass it\n return [QUERY_KEY, previousPageData.next_cursor ?? \"\"];\n}\n\nfunction useSlackChannels({\n queryOptions,\n}: UseSlackChannelsOptions): UseSlackChannelOutput {\n const knock = useKnockClient();\n const { knockSlackChannelId, tenantId, connectionStatus } =\n useKnockSlackClient();\n\n const fetchChannels = (queryKey: QueryKey) => {\n return knock.slack.getChannels({\n tenant: tenantId,\n knockChannelId: knockSlackChannelId,\n queryOptions: {\n ...queryOptions,\n cursor: queryKey?.[1],\n limit: queryOptions?.limitPerPage || LIMIT_PER_PAGE,\n types: queryOptions?.types || CHANNEL_TYPES,\n },\n });\n };\n\n const { data, error, isLoading, isValidating, setSize, mutate } =\n useSWRInfinite<GetSlackChannelsResponse>(getQueryKey, fetchChannels, {\n initialSize: 0,\n revalidateFirstPage: false,\n });\n\n const lastPage = data?.at(-1);\n const hasNextPage = lastPage === undefined || !!lastPage.next_cursor;\n\n const slackChannels: SlackChannel[] = useMemo(\n () =>\n (data ?? [])\n .flatMap((page) => page?.slack_channels)\n .filter((channel) => !!channel),\n [data],\n );\n\n const maxCount = queryOptions?.maxCount || MAX_COUNT;\n\n useEffect(() => {\n if (\n connectionStatus === \"connected\" &&\n !error &&\n hasNextPage &&\n !isLoading &&\n !isValidating &&\n slackChannels.length < maxCount\n ) {\n // Fetch a page at a time until we have nothing else left to fetch\n // or we've already hit the max amount of channels to fetch\n setSize((size) => size + 1);\n }\n }, [\n slackChannels.length,\n setSize,\n hasNextPage,\n isLoading,\n isValidating,\n maxCount,\n error,\n connectionStatus,\n ]);\n\n return {\n data: slackChannels,\n isLoading: isLoading || isValidating,\n refetch: () => mutate(),\n };\n}\n\nexport default useSlackChannels;\n"],"names":["MAX_COUNT","LIMIT_PER_PAGE","CHANNEL_TYPES","QUERY_KEY","getQueryKey","pageIndex","previousPageData","includes","next_cursor","useSlackChannels","queryOptions","knock","useKnockClient","knockSlackChannelId","tenantId","connectionStatus","useKnockSlackClient","fetchChannels","queryKey","slack","getChannels","tenant","knockChannelId","cursor","limit","limitPerPage","types","data","error","isLoading","isValidating","setSize","mutate","useSWRInfinite","initialSize","revalidateFirstPage","lastPage","at","hasNextPage","undefined","slackChannels","useMemo","flatMap","page","slack_channels","filter","channel","maxCount","useEffect","length","size","refetch"],"mappings":";;;;;;;;;AAOA,MAAMA,IAAY,KACZC,IAAiB,KACjBC,IAAgB,kCAEhBC,IAAY;AAclB,SAASC,EACPC,GACAC,GACU;AAEV,SAAID,MAAc,IACT,CAACF,GAAW,EAAE,IAInBG,KAAoB,CAAC,IAAI,IAAI,EAAEC,SAASD,EAAiBE,WAAW,IAC/D,OAIF,CAACL,GAAWG,EAAiBE,eAAe,EAAE;AACvD;AAEA,SAASC,EAAiB;AAAA,EACxBC,cAAAA;AACuB,GAA0B;AACjD,QAAMC,IAAQC,EAAe,GACvB;AAAA,IAAEC,qBAAAA;AAAAA,IAAqBC,UAAAA;AAAAA,IAAUC,kBAAAA;AAAAA,MACrCC,EAAoB,GAEhBC,IAAgBA,CAACC,MACdP,EAAMQ,MAAMC,YAAY;AAAA,IAC7BC,QAAQP;AAAAA,IACRQ,gBAAgBT;AAAAA,IAChBH,cAAc;AAAA,MACZ,GAAGA;AAAAA,MACHa,QAAQL,KAAAA,gBAAAA,EAAW;AAAA,MACnBM,QAAOd,KAAAA,gBAAAA,EAAce,iBAAgBxB;AAAAA,MACrCyB,QAAOhB,KAAAA,gBAAAA,EAAcgB,UAASxB;AAAAA,IAAAA;AAAAA,EAChC,CACD,GAGG;AAAA,IAAEyB,MAAAA;AAAAA,IAAMC,OAAAA;AAAAA,IAAOC,WAAAA;AAAAA,IAAWC,cAAAA;AAAAA,IAAcC,SAAAA;AAAAA,IAASC,QAAAA;AAAAA,EAAAA,IACrDC,EAAyC7B,GAAaa,GAAe;AAAA,IACnEiB,aAAa;AAAA,IACbC,qBAAqB;AAAA,EAAA,CACtB,GAEGC,IAAWT,KAAAA,gBAAAA,EAAMU,GAAG,KACpBC,IAAcF,MAAaG,UAAa,CAAC,CAACH,EAAS5B,aAEnDgC,IAAgCC,EACpC,OACGd,KAAQ,IACNe,QAASC,CAASA,MAAAA,KAAAA,gBAAAA,EAAMC,cAAc,EACtCC,OAAQC,OAAY,CAAC,CAACA,CAAO,GAClC,CAACnB,CAAI,CACP,GAEMoB,KAAWrC,KAAAA,gBAAAA,EAAcqC,aAAY/C;AAE3CgD,SAAAA,EAAU,MAAM;AAEZjC,IAAAA,MAAqB,eACrB,CAACa,KACDU,KACA,CAACT,KACD,CAACC,KACDU,EAAcS,SAASF,KAIdG,EAAAA,CAAAA,MAASA,IAAO,CAAC;AAAA,EAE9B,GAAG,CACDV,EAAcS,QACdlB,GACAO,GACAT,GACAC,GACAiB,GACAnB,GACAb,CAAgB,CACjB,GAEM;AAAA,IACLY,MAAMa;AAAAA,IACNX,WAAWA,KAAaC;AAAAA,IACxBqB,SAASA,MAAMnB,EAAO;AAAA,EACxB;AACF;"}
@@ -1,4 +1,4 @@
1
1
  export { default as useNotifications } from './useNotifications';
2
2
  export { default as useFeedSettings } from './useFeedSettings';
3
- export { default as useNotificationStore, useCreateNotificationStore, } from './useNotificationStore';
3
+ export { default as useNotificationStore, useCreateNotificationStore, type Selector, } from './useNotificationStore';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EACL,OAAO,IAAI,oBAAoB,EAC/B,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EACL,OAAO,IAAI,oBAAoB,EAC/B,0BAA0B,EAC1B,KAAK,QAAQ,GACd,MAAM,wBAAwB,CAAC"}
@@ -1,10 +1,22 @@
1
1
  import { Feed, FeedStoreState } from '@knocklabs/client';
2
2
  import { StoreApi, UseBoundStore } from 'zustand';
3
- declare function useCreateNotificationStore(feedClient: Feed): UseBoundStore<StoreApi<FeedStoreState>>;
4
- declare function useCreateNotificationStore<T, U = T>(feedClient: Feed, externalSelector: (state: FeedStoreState) => U): U;
3
+ export type Selector<T> = (state: FeedStoreState) => T;
4
+ /**
5
+ * Access a Bounded Store instance by converting our vanilla store to a UseBoundStore
6
+ * https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores
7
+ * Allow passing a selector down from useCreateNotificationStore OR useNotificationStore
8
+ * We'll favor the the one passed later outside of useCreateNotificationStore instantiation
9
+ */
10
+ declare function useCreateNotificationStore<T>(feedClient: Feed): UseBoundStore<StoreApi<FeedStoreState>>;
5
11
  /**
6
12
  * A hook used to access content within the notification store.
7
13
  *
14
+ * @example
15
+ *
16
+ * ```ts
17
+ * const { items, metadata } = useNotificationStore(feedClient);
18
+ * ```
19
+ *
8
20
  * A selector can be used to access a subset of the store state.
9
21
  *
10
22
  * @example
@@ -16,8 +28,8 @@ declare function useCreateNotificationStore<T, U = T>(feedClient: Feed, external
16
28
  * }));
17
29
  * ```
18
30
  */
19
- declare function useNotificationStore(feedClient: Feed): UseBoundStore<StoreApi<FeedStoreState>>;
20
- declare function useNotificationStore<T>(feedClient: Feed, selector: (state: FeedStoreState) => T): T;
31
+ declare function useNotificationStore(feedClient: Feed): FeedStoreState;
32
+ declare function useNotificationStore<T>(feedClient: Feed, selector: Selector<T>): T;
21
33
  export { useCreateNotificationStore };
22
34
  export default useNotificationStore;
23
35
  //# sourceMappingURL=useNotificationStore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useNotificationStore.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAY,MAAM,SAAS,CAAC;AAItE,iBAAS,0BAA0B,CACjC,UAAU,EAAE,IAAI,GACf,aAAa,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC;AAC3C,iBAAS,0BAA0B,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAC1C,UAAU,EAAE,IAAI,EAChB,gBAAgB,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,CAAC,GAC7C,CAAC,CAAC;AAkBL;;;;;;;;;;;;;GAaG;AACH,iBAAS,oBAAoB,CAC3B,UAAU,EAAE,IAAI,GACf,aAAa,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC;AAC3C,iBAAS,oBAAoB,CAAC,CAAC,EAC7B,UAAU,EAAE,IAAI,EAChB,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,CAAC,GACrC,CAAC,CAAC;AAQL,OAAO,EAAE,0BAA0B,EAAE,CAAC;AACtC,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"useNotificationStore.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAY,MAAM,SAAS,CAAC;AAEtE,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,cAAc,KAAK,CAAC,CAAC;AAEvD;;;;;GAKG;AACH,iBAAS,0BAA0B,CAAC,CAAC,EACnC,UAAU,EAAE,IAAI,GACf,aAAa,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAMzC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,iBAAS,oBAAoB,CAAC,UAAU,EAAE,IAAI,GAAG,cAAc,CAAC;AAChE,iBAAS,oBAAoB,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAS7E,OAAO,EAAE,0BAA0B,EAAE,CAAC;AACtC,eAAe,oBAAoB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { MsTeamsTeam } from '@knocklabs/client';
2
2
  import { MsTeamsTeamQueryOptions } from '../interfaces';
3
- type UseMsTeamsTeamsProps = {
3
+ type UseMsTeamsTeamsOptions = {
4
4
  queryOptions?: MsTeamsTeamQueryOptions;
5
5
  };
6
6
  type UseMsTeamsTeamsOutput = {
@@ -8,6 +8,6 @@ type UseMsTeamsTeamsOutput = {
8
8
  isLoading: boolean;
9
9
  refetch: () => void;
10
10
  };
11
- declare function useMsTeamsTeams({ queryOptions, }: UseMsTeamsTeamsProps): UseMsTeamsTeamsOutput;
11
+ declare function useMsTeamsTeams({ queryOptions, }: UseMsTeamsTeamsOptions): UseMsTeamsTeamsOutput;
12
12
  export default useMsTeamsTeams;
13
13
  //# sourceMappingURL=useMsTeamsTeams.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMsTeamsTeams.d.ts","sourceRoot":"","sources":["../../../../../src/modules/ms-teams/hooks/useMsTeamsTeams.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAMxD,KAAK,oBAAoB,GAAG;IAC1B,YAAY,CAAC,EAAE,uBAAuB,CAAC;CACxC,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,WAAW,EAAE,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAsBF,iBAAS,eAAe,CAAC,EACvB,YAAiB,GAClB,EAAE,oBAAoB,GAAG,qBAAqB,CAiE9C;AAED,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"useMsTeamsTeams.d.ts","sourceRoot":"","sources":["../../../../../src/modules/ms-teams/hooks/useMsTeamsTeams.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAMxD,KAAK,sBAAsB,GAAG;IAC5B,YAAY,CAAC,EAAE,uBAAuB,CAAC;CACxC,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,WAAW,EAAE,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAsBF,iBAAS,eAAe,CAAC,EACvB,YAAiB,GAClB,EAAE,sBAAsB,GAAG,qBAAqB,CAkEhD;AAED,eAAe,eAAe,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { SlackChannelQueryOptions } from '..';
2
2
  import { SlackChannel } from '@knocklabs/client';
3
- type UseSlackChannelsProps = {
3
+ type UseSlackChannelsOptions = {
4
4
  queryOptions?: SlackChannelQueryOptions;
5
5
  };
6
6
  type UseSlackChannelOutput = {
@@ -8,6 +8,6 @@ type UseSlackChannelOutput = {
8
8
  isLoading: boolean;
9
9
  refetch: () => void;
10
10
  };
11
- declare function useSlackChannels({ queryOptions, }: UseSlackChannelsProps): UseSlackChannelOutput;
11
+ declare function useSlackChannels({ queryOptions, }: UseSlackChannelsOptions): UseSlackChannelOutput;
12
12
  export default useSlackChannels;
13
13
  //# sourceMappingURL=useSlackChannels.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSlackChannels.d.ts","sourceRoot":"","sources":["../../../../../src/modules/slack/hooks/useSlackChannels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAuB,MAAM,IAAI,CAAC;AACnE,OAAO,EAA4B,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAY3E,KAAK,qBAAqB,GAAG;IAC3B,YAAY,CAAC,EAAE,wBAAwB,CAAC;CACzC,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,YAAY,EAAE,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAsBF,iBAAS,gBAAgB,CAAC,EACxB,YAAY,GACb,EAAE,qBAAqB,GAAG,qBAAqB,CAuE/C;AAED,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"useSlackChannels.d.ts","sourceRoot":"","sources":["../../../../../src/modules/slack/hooks/useSlackChannels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAuB,MAAM,IAAI,CAAC;AACnE,OAAO,EAA4B,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAY3E,KAAK,uBAAuB,GAAG;IAC7B,YAAY,CAAC,EAAE,wBAAwB,CAAC;CACzC,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,YAAY,EAAE,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAsBF,iBAAS,gBAAgB,CAAC,EACxB,YAAY,GACb,EAAE,uBAAuB,GAAG,qBAAqB,CAkEjD;AAED,eAAe,gBAAgB,CAAC"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@knocklabs/react-core",
3
3
  "description": "A set of React components to build notification experiences powered by Knock",
4
4
  "author": "@knocklabs",
5
- "version": "0.5.0-rc.2.0",
5
+ "version": "0.5.0",
6
6
  "license": "MIT",
7
7
  "main": "dist/cjs/index.js",
8
8
  "module": "dist/esm/index.mjs",
@@ -49,9 +49,9 @@
49
49
  "react": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
50
50
  },
51
51
  "dependencies": {
52
- "@knocklabs/client": "^0.12.0-rc.2.0",
52
+ "@knocklabs/client": "^0.12.0",
53
53
  "date-fns": "^4.0.0",
54
- "swr": "^2.3.2",
54
+ "swr": "^2.3.3",
55
55
  "zustand": "^4.5.6"
56
56
  },
57
57
  "devDependencies": {
@@ -63,7 +63,7 @@
63
63
  "@vitejs/plugin-react": "^4.3.4",
64
64
  "babel-plugin-react-require": "^4.0.3",
65
65
  "eslint": "^8.56.0",
66
- "eslint-plugin-react-hooks": "^5.0.0",
66
+ "eslint-plugin-react-hooks": "^5.2.0",
67
67
  "eslint-plugin-react-refresh": "^0.4.14",
68
68
  "jsdom": "^25.0.1",
69
69
  "react": "^18.2.0",
@@ -3,4 +3,5 @@ export { default as useFeedSettings } from "./useFeedSettings";
3
3
  export {
4
4
  default as useNotificationStore,
5
5
  useCreateNotificationStore,
6
+ type Selector,
6
7
  } from "./useNotificationStore";
@@ -1,35 +1,33 @@
1
1
  import { Feed, type FeedStoreState } from "@knocklabs/client";
2
2
  import { type StoreApi, type UseBoundStore, useStore } from "zustand";
3
3
 
4
- // A hook designed to create a `UseBoundStore` instance.
5
- // https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores
6
- function useCreateNotificationStore(
7
- feedClient: Feed,
8
- ): UseBoundStore<StoreApi<FeedStoreState>>;
9
- function useCreateNotificationStore<T, U = T>(
10
- feedClient: Feed,
11
- externalSelector: (state: FeedStoreState) => U,
12
- ): U;
4
+ export type Selector<T> = (state: FeedStoreState) => T;
5
+
13
6
  /**
14
- * Access a Bounded Store instance
7
+ * Access a Bounded Store instance by converting our vanilla store to a UseBoundStore
8
+ * https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores
15
9
  * Allow passing a selector down from useCreateNotificationStore OR useNotificationStore
16
10
  * We'll favor the the one passed later outside of useCreateNotificationStore instantiation
17
11
  */
18
- function useCreateNotificationStore<T, U = T>(
12
+ function useCreateNotificationStore<T>(
19
13
  feedClient: Feed,
20
- externalSelector?: (state: FeedStoreState) => U,
21
- ) {
22
- const store = useStore(feedClient.store);
23
-
24
- return (selector?: (state: FeedStoreState) => U) => {
25
- const innerSelector = selector ?? externalSelector;
26
- return innerSelector ? innerSelector(store) : store;
27
- };
14
+ ): UseBoundStore<StoreApi<FeedStoreState>> {
15
+ // Keep selector optional for external use
16
+ // useStore requires a selector so we'll pass in a default one when not provided
17
+ const useBoundedStore = (selector?: Selector<T>) =>
18
+ useStore(feedClient.store, selector ?? ((state) => state as T));
19
+ return useBoundedStore as UseBoundStore<StoreApi<FeedStoreState>>;
28
20
  }
29
21
 
30
22
  /**
31
23
  * A hook used to access content within the notification store.
32
24
  *
25
+ * @example
26
+ *
27
+ * ```ts
28
+ * const { items, metadata } = useNotificationStore(feedClient);
29
+ * ```
30
+ *
33
31
  * A selector can be used to access a subset of the store state.
34
32
  *
35
33
  * @example
@@ -41,18 +39,14 @@ function useCreateNotificationStore<T, U = T>(
41
39
  * }));
42
40
  * ```
43
41
  */
44
- function useNotificationStore(
45
- feedClient: Feed,
46
- ): UseBoundStore<StoreApi<FeedStoreState>>;
42
+ function useNotificationStore(feedClient: Feed): FeedStoreState;
43
+ function useNotificationStore<T>(feedClient: Feed, selector: Selector<T>): T;
47
44
  function useNotificationStore<T>(
48
45
  feedClient: Feed,
49
- selector: (state: FeedStoreState) => T,
50
- ): T;
51
- function useNotificationStore<T, U = T>(
52
- feedClient: Feed,
53
- selector?: (state: FeedStoreState) => U,
54
- ) {
55
- return useCreateNotificationStore(feedClient, selector!);
46
+ selector?: Selector<T>,
47
+ ): T | FeedStoreState {
48
+ const useStoreLocal = useCreateNotificationStore(feedClient);
49
+ return useStoreLocal(selector ?? ((state) => state as T));
56
50
  }
57
51
 
58
52
  export { useCreateNotificationStore };
@@ -10,7 +10,7 @@ const MAX_COUNT = 1000;
10
10
 
11
11
  const QUERY_KEY = "MS_TEAMS_TEAMS";
12
12
 
13
- type UseMsTeamsTeamsProps = {
13
+ type UseMsTeamsTeamsOptions = {
14
14
  queryOptions?: MsTeamsTeamQueryOptions;
15
15
  };
16
16
 
@@ -42,7 +42,7 @@ function getQueryKey(
42
42
 
43
43
  function useMsTeamsTeams({
44
44
  queryOptions = {},
45
- }: UseMsTeamsTeamsProps): UseMsTeamsTeamsOutput {
45
+ }: UseMsTeamsTeamsOptions): UseMsTeamsTeamsOutput {
46
46
  const knock = useKnockClient();
47
47
  const { knockMsTeamsChannelId, tenantId, connectionStatus } =
48
48
  useKnockMsTeamsClient();
@@ -63,6 +63,7 @@ function useMsTeamsTeams({
63
63
  useSWRInfinite<GetMsTeamsTeamsResponse>(getQueryKey, fetchTeams, {
64
64
  initialSize: 0,
65
65
  revalidateOnFocus: false,
66
+ revalidateFirstPage: false,
66
67
  });
67
68
 
68
69
  const lastPage = data?.at(-1);
@@ -11,7 +11,7 @@ const CHANNEL_TYPES = "private_channel,public_channel";
11
11
 
12
12
  const QUERY_KEY = "SLACK_CHANNELS";
13
13
 
14
- type UseSlackChannelsProps = {
14
+ type UseSlackChannelsOptions = {
15
15
  queryOptions?: SlackChannelQueryOptions;
16
16
  };
17
17
 
@@ -43,7 +43,7 @@ function getQueryKey(
43
43
 
44
44
  function useSlackChannels({
45
45
  queryOptions,
46
- }: UseSlackChannelsProps): UseSlackChannelOutput {
46
+ }: UseSlackChannelsOptions): UseSlackChannelOutput {
47
47
  const knock = useKnockClient();
48
48
  const { knockSlackChannelId, tenantId, connectionStatus } =
49
49
  useKnockSlackClient();
@@ -54,25 +54,21 @@ function useSlackChannels({
54
54
  knockChannelId: knockSlackChannelId,
55
55
  queryOptions: {
56
56
  ...queryOptions,
57
- cursor: queryKey ? queryKey[1] : "",
57
+ cursor: queryKey?.[1],
58
58
  limit: queryOptions?.limitPerPage || LIMIT_PER_PAGE,
59
59
  types: queryOptions?.types || CHANNEL_TYPES,
60
60
  },
61
61
  });
62
62
  };
63
63
 
64
- const { data, error, isLoading, isValidating, size, setSize, mutate } =
64
+ const { data, error, isLoading, isValidating, setSize, mutate } =
65
65
  useSWRInfinite<GetSlackChannelsResponse>(getQueryKey, fetchChannels, {
66
66
  initialSize: 0,
67
+ revalidateFirstPage: false,
67
68
  });
68
69
 
69
- const currentPage = data?.length || 0;
70
-
71
- const hasNextPage =
72
- currentPage === 0 ||
73
- (data &&
74
- data[currentPage]?.next_cursor &&
75
- data[currentPage]?.next_cursor !== "");
70
+ const lastPage = data?.at(-1);
71
+ const hasNextPage = lastPage === undefined || !!lastPage.next_cursor;
76
72
 
77
73
  const slackChannels: SlackChannel[] = useMemo(
78
74
  () =>
@@ -95,12 +91,11 @@ function useSlackChannels({
95
91
  ) {
96
92
  // Fetch a page at a time until we have nothing else left to fetch
97
93
  // or we've already hit the max amount of channels to fetch
98
- setSize(size + 1);
94
+ setSize((size) => size + 1);
99
95
  }
100
96
  }, [
101
97
  slackChannels.length,
102
98
  setSize,
103
- size,
104
99
  hasNextPage,
105
100
  isLoading,
106
101
  isValidating,