@knocklabs/react-core 0.2.29 → 0.3.0-rc-2.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.
- package/CHANGELOG.md +6 -16
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/modules/core/context/KnockProvider.js +1 -1
- package/dist/cjs/modules/core/context/KnockProvider.js.map +1 -1
- package/dist/cjs/modules/core/hooks/useStableOptions.js +1 -1
- package/dist/cjs/modules/core/hooks/useStableOptions.js.map +1 -1
- package/dist/cjs/modules/core/utils.js.map +1 -1
- package/dist/cjs/modules/feed/context/KnockFeedProvider.js +1 -1
- package/dist/cjs/modules/feed/context/KnockFeedProvider.js.map +1 -1
- package/dist/cjs/modules/in-app-messages/context/KnockInAppMessagesChannelProvider.js +2 -0
- package/dist/cjs/modules/in-app-messages/context/KnockInAppMessagesChannelProvider.js.map +1 -0
- package/dist/cjs/modules/in-app-messages/hooks/useInAppMessages.js +2 -0
- package/dist/cjs/modules/in-app-messages/hooks/useInAppMessages.js.map +1 -0
- package/dist/cjs/modules/slack/context/KnockSlackProvider.js +1 -1
- package/dist/cjs/modules/slack/hooks/useConnectedSlackChannels.js +1 -1
- package/dist/cjs/modules/slack/hooks/useConnectedSlackChannels.js.map +1 -1
- package/dist/cjs/modules/slack/hooks/useSlackAuth.js +1 -1
- package/dist/cjs/modules/slack/hooks/useSlackAuth.js.map +1 -1
- package/dist/cjs/modules/slack/hooks/useSlackChannels.js +1 -1
- package/dist/cjs/modules/slack/hooks/useSlackConnectionStatus.js.map +1 -1
- package/dist/esm/index.mjs +36 -30
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/modules/core/context/KnockProvider.mjs +15 -15
- package/dist/esm/modules/core/context/KnockProvider.mjs.map +1 -1
- package/dist/esm/modules/core/hooks/useStableOptions.mjs +8 -8
- package/dist/esm/modules/core/hooks/useStableOptions.mjs.map +1 -1
- package/dist/esm/modules/core/utils.mjs.map +1 -1
- package/dist/esm/modules/feed/context/KnockFeedProvider.mjs +20 -14
- package/dist/esm/modules/feed/context/KnockFeedProvider.mjs.map +1 -1
- package/dist/esm/modules/in-app-messages/context/KnockInAppMessagesChannelProvider.mjs +33 -0
- package/dist/esm/modules/in-app-messages/context/KnockInAppMessagesChannelProvider.mjs.map +1 -0
- package/dist/esm/modules/in-app-messages/hooks/useInAppMessages.mjs +41 -0
- package/dist/esm/modules/in-app-messages/hooks/useInAppMessages.mjs.map +1 -0
- package/dist/esm/modules/slack/context/KnockSlackProvider.mjs +1 -1
- package/dist/esm/modules/slack/hooks/useConnectedSlackChannels.mjs +3 -3
- package/dist/esm/modules/slack/hooks/useConnectedSlackChannels.mjs.map +1 -1
- package/dist/esm/modules/slack/hooks/useSlackAuth.mjs +1 -1
- package/dist/esm/modules/slack/hooks/useSlackAuth.mjs.map +1 -1
- package/dist/esm/modules/slack/hooks/useSlackChannels.mjs +1 -1
- package/dist/esm/modules/slack/hooks/useSlackConnectionStatus.mjs.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/core/context/KnockProvider.d.ts +1 -0
- package/dist/types/modules/core/context/KnockProvider.d.ts.map +1 -1
- package/dist/types/modules/core/hooks/useAuthenticatedKnockClient.d.ts +1 -0
- package/dist/types/modules/core/utils.d.ts +1 -0
- package/dist/types/modules/feed/context/KnockFeedProvider.d.ts +1 -0
- package/dist/types/modules/feed/context/KnockFeedProvider.d.ts.map +1 -1
- package/dist/types/modules/feed/hooks/useFeedSettings.d.ts +1 -0
- package/dist/types/modules/feed/hooks/useNotificationStore.d.ts +1 -0
- package/dist/types/modules/feed/hooks/useNotifications.d.ts +1 -0
- package/dist/types/modules/i18n/context/KnockI18nProvider.d.ts +1 -0
- package/dist/types/modules/i18n/languages/de.d.ts +1 -0
- package/dist/types/modules/i18n/languages/en.d.ts +1 -0
- package/dist/types/modules/in-app-messages/context/KnockInAppMessagesChannelProvider.d.ts +16 -0
- package/dist/types/modules/in-app-messages/context/KnockInAppMessagesChannelProvider.d.ts.map +1 -0
- package/dist/types/modules/in-app-messages/context/index.d.ts +2 -0
- package/dist/types/modules/in-app-messages/context/index.d.ts.map +1 -0
- package/dist/types/modules/in-app-messages/hooks/index.d.ts +2 -0
- package/dist/types/modules/in-app-messages/hooks/index.d.ts.map +1 -0
- package/dist/types/modules/in-app-messages/hooks/useInAppMessages.d.ts +21 -0
- package/dist/types/modules/in-app-messages/hooks/useInAppMessages.d.ts.map +1 -0
- package/dist/types/modules/in-app-messages/index.d.ts +3 -0
- package/dist/types/modules/in-app-messages/index.d.ts.map +1 -0
- package/dist/types/modules/slack/hooks/useConnectedSlackChannels.d.ts +1 -0
- package/dist/types/modules/slack/hooks/useSlackChannels.d.ts +1 -0
- package/dist/types/modules/slack/hooks/useSlackConnectionStatus.d.ts +1 -0
- package/package.json +10 -8
- package/src/index.ts +1 -0
- package/src/modules/core/context/KnockProvider.tsx +6 -8
- package/src/modules/core/hooks/useStableOptions.ts +2 -2
- package/src/modules/core/utils.ts +1 -1
- package/src/modules/feed/context/KnockFeedProvider.tsx +11 -6
- package/src/modules/in-app-messages/context/KnockInAppMessagesChannelProvider.tsx +68 -0
- package/src/modules/in-app-messages/context/index.ts +1 -0
- package/src/modules/in-app-messages/hooks/index.ts +1 -0
- package/src/modules/in-app-messages/hooks/useInAppMessages.ts +87 -0
- package/src/modules/in-app-messages/index.ts +3 -0
- package/src/modules/slack/hooks/useConnectedSlackChannels.ts +1 -1
- package/src/modules/slack/hooks/useSlackAuth.ts +1 -1
- package/src/modules/slack/hooks/useSlackConnectionStatus.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnockFeedProvider.mjs","sources":["../../../../../src/modules/feed/context/KnockFeedProvider.tsx"],"sourcesContent":["import Knock, {\n Feed,\n FeedClientOptions,\n FeedStoreState,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\nimport { UseBoundStore } from \"zustand\";\n\nimport { useKnockClient } from \"../../core\";\nimport { ColorMode } from \"../../core/constants\";\nimport { feedProviderKey } from \"../../core/utils\";\nimport { useCreateNotificationStore } from \"../hooks\";\nimport useNotifications from \"../hooks/useNotifications\";\n\nexport interface KnockFeedProviderState {\n knock: Knock;\n feedClient: Feed;\n useFeedStore: UseBoundStore<FeedStoreState>;\n colorMode: ColorMode;\n}\n\nconst
|
|
1
|
+
{"version":3,"file":"KnockFeedProvider.mjs","sources":["../../../../../src/modules/feed/context/KnockFeedProvider.tsx"],"sourcesContent":["import Knock, {\n Feed,\n FeedClientOptions,\n FeedStoreState,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\nimport { UseBoundStore } from \"zustand\";\n\nimport { useKnockClient } from \"../../core\";\nimport { ColorMode } from \"../../core/constants\";\nimport { feedProviderKey } from \"../../core/utils\";\nimport { useCreateNotificationStore } from \"../hooks\";\nimport useNotifications from \"../hooks/useNotifications\";\n\nexport interface KnockFeedProviderState {\n knock: Knock;\n feedClient: Feed;\n useFeedStore: UseBoundStore<FeedStoreState>;\n colorMode: ColorMode;\n}\n\nconst KnockFeedContext = React.createContext<\n KnockFeedProviderState | undefined\n>(undefined);\n\nexport interface KnockFeedProviderProps {\n // Feed props\n feedId: string;\n\n // Extra options\n colorMode?: ColorMode;\n\n // Feed client options\n defaultFeedOptions?: FeedClientOptions;\n}\n\nexport const KnockFeedProvider: React.FC<\n PropsWithChildren<KnockFeedProviderProps>\n> = ({ feedId, children, defaultFeedOptions = {}, colorMode = \"light\" }) => {\n let knock: Knock;\n try {\n knock = useKnockClient();\n } catch (error) {\n throw new Error(\"KnockFeedProvider must be used within a KnockProvider.\");\n }\n\n const feedClient = useNotifications(knock, feedId, defaultFeedOptions);\n const useFeedStore = useCreateNotificationStore(feedClient);\n\n return (\n <KnockFeedContext.Provider\n key={feedProviderKey(knock.userId, feedId, defaultFeedOptions)}\n value={{\n knock,\n feedClient,\n useFeedStore,\n colorMode,\n }}\n >\n {children}\n </KnockFeedContext.Provider>\n );\n};\n\nexport const useKnockFeed = (): KnockFeedProviderState => {\n const context = React.useContext(KnockFeedContext);\n if (!context) {\n throw new Error(\"useKnockFeed must be used within a KnockFeedProvider\");\n }\n\n return context;\n};\n"],"names":["KnockFeedContext","React","createContext","undefined","KnockFeedProvider","feedId","children","defaultFeedOptions","colorMode","knock","useKnockClient","Error","feedClient","useNotifications","useFeedStore","useCreateNotificationStore","feedProviderKey","userId","useKnockFeed","context","useContext"],"mappings":";;;;;;;AAsBA,MAAMA,IAAmBC,EAAMC,cAE7BC,MAAS,GAaEC,IAETA,CAAC;AAAA,EAAEC,QAAAA;AAAAA,EAAQC,UAAAA;AAAAA,EAAUC,oBAAAA,IAAqB,CAAC;AAAA,EAAGC,WAAAA,IAAY;AAAQ,MAAM;AACtEC,MAAAA;AACA,MAAA;AACFA,IAAAA,IAAQC,EAAe;AAAA,UACT;AACR,UAAA,IAAIC,MAAM,wDAAwD;AAAA,EAC1E;AAEA,QAAMC,IAAaC,EAAiBJ,GAAOJ,GAAQE,CAAkB,GAC/DO,IAAeC,EAA2BH,CAAU;AAGxD,SAAA,gBAAAX,EAAA,cAACD,EAAiB,UAAjB,EACC,KAAKgB,EAAgBP,EAAMQ,QAAQZ,GAAQE,CAAkB,GAC7D,OAAO;AAAA,IACLE,OAAAA;AAAAA,IACAG,YAAAA;AAAAA,IACAE,cAAAA;AAAAA,IACAN,WAAAA;AAAAA,EAAAA,KAGDF,CACH;AAEJ,GAEaY,IAAeA,MAA8B;AAClDC,QAAAA,IAAUlB,EAAMmB,WAAWpB,CAAgB;AACjD,MAAI,CAACmB;AACG,UAAA,IAAIR,MAAM,sDAAsD;AAGjEQ,SAAAA;AACT;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { InAppMessagesChannelClient as c } from "@knocklabs/client";
|
|
2
|
+
import * as n from "react";
|
|
3
|
+
import { useKnockClient as l } from "../../core/context/KnockProvider.mjs";
|
|
4
|
+
import u from "../../core/hooks/useStableOptions.mjs";
|
|
5
|
+
import "date-fns";
|
|
6
|
+
const r = n.createContext(void 0), k = ({
|
|
7
|
+
children: e,
|
|
8
|
+
channelId: t,
|
|
9
|
+
colorMode: a = "light",
|
|
10
|
+
defaultOptions: p
|
|
11
|
+
}) => {
|
|
12
|
+
let s;
|
|
13
|
+
try {
|
|
14
|
+
s = l();
|
|
15
|
+
} catch {
|
|
16
|
+
throw new Error("KnockInAppMessagesChannelProvider must be used within a KnockProvider.");
|
|
17
|
+
}
|
|
18
|
+
const o = u(p), i = n.useMemo(() => new c(s, t, o), [s, t, o]);
|
|
19
|
+
return /* @__PURE__ */ n.createElement(r.Provider, { value: {
|
|
20
|
+
inAppMessagesChannelClient: i,
|
|
21
|
+
colorMode: a
|
|
22
|
+
} }, e);
|
|
23
|
+
}, A = () => {
|
|
24
|
+
const e = n.useContext(r);
|
|
25
|
+
if (!e)
|
|
26
|
+
throw new Error("useInAppMessagesChannel must be used within a KnockInAppMessagesChannelProvider");
|
|
27
|
+
return e;
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
k as KnockInAppMessagesChannelProvider,
|
|
31
|
+
A as useInAppMessagesChannel
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=KnockInAppMessagesChannelProvider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnockInAppMessagesChannelProvider.mjs","sources":["../../../../../src/modules/in-app-messages/context/KnockInAppMessagesChannelProvider.tsx"],"sourcesContent":["import Knock, {\n InAppMessagesChannelClient,\n InAppMessagesClientOptions,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\n\nimport { useKnockClient, useStableOptions } from \"../../core\";\nimport { ColorMode } from \"../../core/constants\";\n\nexport interface KnockInAppMessagesChannelProviderState {\n inAppMessagesChannelClient: InAppMessagesChannelClient;\n colorMode: ColorMode;\n}\n\nexport interface KnockInAppMessagesChannelProviderProps {\n // In-App Message props\n channelId: string;\n defaultOptions?: InAppMessagesClientOptions;\n\n // Extra options\n colorMode?: ColorMode;\n}\n\nconst KnockInAppMessagesContext = React.createContext<\n KnockInAppMessagesChannelProviderState | undefined\n>(undefined);\n\nexport const KnockInAppMessagesChannelProvider: React.FC<\n React.PropsWithChildren<KnockInAppMessagesChannelProviderProps>\n> = ({ children, channelId, colorMode = \"light\", defaultOptions }) => {\n let knock: Knock;\n try {\n knock = useKnockClient();\n } catch (error) {\n throw new Error(\n \"KnockInAppMessagesChannelProvider must be used within a KnockProvider.\",\n );\n }\n\n const stableOptions = useStableOptions(defaultOptions);\n\n const inAppMessagesChannelClient = React.useMemo(() => {\n return new InAppMessagesChannelClient(knock, channelId, stableOptions);\n }, [knock, channelId, stableOptions]);\n\n return (\n <KnockInAppMessagesContext.Provider\n value={{\n inAppMessagesChannelClient,\n colorMode,\n }}\n >\n {children}\n </KnockInAppMessagesContext.Provider>\n );\n};\n\nexport const useInAppMessagesChannel =\n (): KnockInAppMessagesChannelProviderState => {\n const context = React.useContext(KnockInAppMessagesContext);\n if (!context) {\n throw new Error(\n \"useInAppMessagesChannel must be used within a KnockInAppMessagesChannelProvider\",\n );\n }\n\n return context;\n };\n"],"names":["KnockInAppMessagesContext","React","createContext","undefined","KnockInAppMessagesChannelProvider","children","channelId","colorMode","defaultOptions","knock","useKnockClient","Error","stableOptions","useStableOptions","inAppMessagesChannelClient","useMemo","InAppMessagesChannelClient","useInAppMessagesChannel","context","useContext"],"mappings":";;;;;AAuBA,MAAMA,IAA4BC,EAAMC,cAEtCC,MAAS,GAEEC,IAETA,CAAC;AAAA,EAAEC,UAAAA;AAAAA,EAAUC,WAAAA;AAAAA,EAAWC,WAAAA,IAAY;AAAA,EAASC,gBAAAA;AAAe,MAAM;AAChEC,MAAAA;AACA,MAAA;AACFA,IAAAA,IAAQC,EAAe;AAAA,UACT;AACR,UAAA,IAAIC,MACR,wEACF;AAAA,EACF;AAEMC,QAAAA,IAAgBC,EAAiBL,CAAc,GAE/CM,IAA6Bb,EAAMc,QAAQ,MACxC,IAAIC,EAA2BP,GAAOH,GAAWM,CAAa,GACpE,CAACH,GAAOH,GAAWM,CAAa,CAAC;AAEpC,SACG,gBAAAX,EAAA,cAAAD,EAA0B,UAA1B,EACC,OAAO;AAAA,IACLc,4BAAAA;AAAAA,IACAP,WAAAA;AAAAA,EAAAA,KAGDF,CACH;AAEJ,GAEaY,IACXA,MAA8C;AACtCC,QAAAA,IAAUjB,EAAMkB,WAAWnB,CAAyB;AAC1D,MAAI,CAACkB;AACG,UAAA,IAAIP,MACR,iFACF;AAGKO,SAAAA;AACT;"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { InAppMessagesClient as a } from "@knocklabs/client";
|
|
2
|
+
import { useStore as m } from "@tanstack/react-store";
|
|
3
|
+
import { useMemo as c, useEffect as g } from "react";
|
|
4
|
+
import "../../core/context/KnockProvider.mjs";
|
|
5
|
+
import f from "../../core/hooks/useStableOptions.mjs";
|
|
6
|
+
import "date-fns";
|
|
7
|
+
import { useInAppMessagesChannel as l } from "../context/KnockInAppMessagesChannelProvider.mjs";
|
|
8
|
+
const M = (t, o = {}) => {
|
|
9
|
+
const {
|
|
10
|
+
inAppMessagesChannelClient: s
|
|
11
|
+
} = l(), n = f(o), e = c(() => new a(s, t, n), [s, t, n]), {
|
|
12
|
+
messages: r,
|
|
13
|
+
networkStatus: p,
|
|
14
|
+
loading: i
|
|
15
|
+
} = m(s.store, (u) => e.getQueryInfoSelector(u));
|
|
16
|
+
return g(() => (e.subscribe(), e.fetch(), () => {
|
|
17
|
+
e.unsubscribe();
|
|
18
|
+
}), [e]), {
|
|
19
|
+
messages: r,
|
|
20
|
+
networkStatus: p,
|
|
21
|
+
loading: i,
|
|
22
|
+
inAppMessagesClient: e
|
|
23
|
+
};
|
|
24
|
+
}, O = (t, o = {}) => {
|
|
25
|
+
const {
|
|
26
|
+
messages: s,
|
|
27
|
+
...n
|
|
28
|
+
} = M(t, {
|
|
29
|
+
...o,
|
|
30
|
+
page_size: 1
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
message: s[0],
|
|
34
|
+
...n
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
O as useInAppMessage,
|
|
39
|
+
M as useInAppMessages
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=useInAppMessages.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInAppMessages.mjs","sources":["../../../../../src/modules/in-app-messages/hooks/useInAppMessages.ts"],"sourcesContent":["import {\n InAppMessage,\n InAppMessagesClient,\n InAppMessagesClientOptions,\n NetworkStatus,\n} from \"@knocklabs/client\";\nimport { GenericData } from \"@knocklabs/types\";\nimport { useStore } from \"@tanstack/react-store\";\nimport { useEffect, useMemo } from \"react\";\n\nimport { useStableOptions } from \"../../core\";\nimport { useInAppMessagesChannel } from \"../context\";\n\nexport interface UseInAppMessagesOptions extends InAppMessagesClientOptions {}\n\nexport interface UseInAppMessagesResponse<\n TContent extends GenericData,\n TData extends GenericData,\n> {\n messages: InAppMessage<TContent, TData>[];\n networkStatus: NetworkStatus;\n loading: boolean;\n inAppMessagesClient: InAppMessagesClient;\n}\n\nexport const useInAppMessages = <\n TContent extends GenericData = GenericData,\n TData extends GenericData = GenericData,\n>(\n messageType: string,\n options: UseInAppMessagesOptions = {},\n): UseInAppMessagesResponse<TContent, TData> => {\n const { inAppMessagesChannelClient } = useInAppMessagesChannel();\n\n const stableOptions = useStableOptions(options);\n\n const inAppMessagesClient = useMemo(() => {\n return new InAppMessagesClient(\n inAppMessagesChannelClient,\n messageType,\n stableOptions,\n );\n }, [inAppMessagesChannelClient, messageType, stableOptions]);\n\n const { messages, networkStatus, loading } = useStore(\n inAppMessagesChannelClient.store,\n (state) => inAppMessagesClient.getQueryInfoSelector<TContent, TData>(state),\n );\n\n useEffect(() => {\n inAppMessagesClient.subscribe();\n inAppMessagesClient.fetch();\n\n return () => {\n inAppMessagesClient.unsubscribe();\n };\n }, [inAppMessagesClient]);\n\n return { messages, networkStatus, loading, inAppMessagesClient };\n};\n\nexport type UseInAppMessageOptions = Omit<UseInAppMessagesOptions, \"page_size\">;\n\nexport interface UseInAppMessageResponse<\n TContent extends GenericData,\n TData extends GenericData,\n> extends GenericData {\n message?: InAppMessage<TContent, TData>;\n networkStatus: NetworkStatus;\n loading: boolean;\n inAppMessagesClient: InAppMessagesClient;\n}\n\nexport const useInAppMessage = <\n TContent extends GenericData = GenericData,\n TData extends GenericData = GenericData,\n>(\n messageType: string,\n options: UseInAppMessageOptions = {},\n): UseInAppMessageResponse<TContent, TData> => {\n const { messages, ...rest } = useInAppMessages<TContent, TData>(messageType, {\n ...options,\n page_size: 1,\n });\n\n return { message: messages[0], ...rest };\n};\n"],"names":["useInAppMessages","messageType","options","inAppMessagesChannelClient","useInAppMessagesChannel","stableOptions","useStableOptions","inAppMessagesClient","useMemo","InAppMessagesClient","messages","networkStatus","loading","useStore","store","state","getQueryInfoSelector","useEffect","subscribe","fetch","unsubscribe","useInAppMessage","rest","page_size","message"],"mappings":";;;;;;;AAyBO,MAAMA,IAAmB,CAI9BC,GACAC,IAAmC,OACW;AACxC,QAAA;AAAA,IAAEC,4BAAAA;AAAAA,MAA+BC,EAAwB,GAEzDC,IAAgBC,EAAiBJ,CAAO,GAExCK,IAAsBC,EAAQ,MAC3B,IAAIC,EACTN,GACAF,GACAI,CACF,GACC,CAACF,GAA4BF,GAAaI,CAAa,CAAC,GAErD;AAAA,IAAEK,UAAAA;AAAAA,IAAUC,eAAAA;AAAAA,IAAeC,SAAAA;AAAAA,EAAAA,IAAYC,EAC3CV,EAA2BW,OAC1BC,OAAUR,EAAoBS,qBAAsCD,CAAK,CAC5E;AAEAE,SAAAA,EAAU,OACRV,EAAoBW,UAAU,GAC9BX,EAAoBY,MAAM,GAEnB,MAAM;AACXZ,IAAAA,EAAoBa,YAAY;AAAA,EAAA,IAEjC,CAACb,CAAmB,CAAC,GAEjB;AAAA,IAAEG,UAAAA;AAAAA,IAAUC,eAAAA;AAAAA,IAAeC,SAAAA;AAAAA,IAASL,qBAAAA;AAAAA,EAAAA;AAC7C,GAcac,IAAkB,CAI7BpB,GACAC,IAAkC,OACW;AACvC,QAAA;AAAA,IAAEQ,UAAAA;AAAAA,IAAU,GAAGY;AAAAA,EAAAA,IAAStB,EAAkCC,GAAa;AAAA,IAC3E,GAAGC;AAAAA,IACHqB,WAAW;AAAA,EAAA,CACZ;AAEM,SAAA;AAAA,IAAEC,SAASd,EAAS,CAAC;AAAA,IAAG,GAAGY;AAAAA,EAAAA;AACpC;"}
|
|
@@ -3,7 +3,7 @@ import * as e from "react";
|
|
|
3
3
|
import "swr/infinite";
|
|
4
4
|
import { useKnockClient as p } from "../../core/context/KnockProvider.mjs";
|
|
5
5
|
import "@knocklabs/client";
|
|
6
|
-
import "
|
|
6
|
+
import "fast-deep-equal";
|
|
7
7
|
import { slackProviderKey as S } from "../../core/utils.mjs";
|
|
8
8
|
import "../../i18n/context/KnockI18nProvider.mjs";
|
|
9
9
|
const c = e.createContext(null), P = ({
|
|
@@ -5,9 +5,9 @@ import { useTranslations as I } from "../../i18n/hooks/useTranslations.mjs";
|
|
|
5
5
|
import "swr/infinite";
|
|
6
6
|
import { useKnockClient as j } from "../../core/context/KnockProvider.mjs";
|
|
7
7
|
import "@knocklabs/client";
|
|
8
|
-
import "
|
|
8
|
+
import "fast-deep-equal";
|
|
9
9
|
import "date-fns";
|
|
10
|
-
function
|
|
10
|
+
function q({
|
|
11
11
|
slackChannelsRecipientObject: {
|
|
12
12
|
objectId: e,
|
|
13
13
|
collection: a
|
|
@@ -56,6 +56,6 @@ function _({
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
export {
|
|
59
|
-
|
|
59
|
+
q as default
|
|
60
60
|
};
|
|
61
61
|
//# sourceMappingURL=useConnectedSlackChannels.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConnectedSlackChannels.mjs","sources":["../../../../../src/modules/slack/hooks/useConnectedSlackChannels.ts"],"sourcesContent":["import { ContainerObject, useKnockSlackClient } from \"..\";\nimport { SlackChannelConnection } from \"@knocklabs/client\";\nimport { useCallback, useEffect, useState } from \"react\";\n\nimport { useKnockClient } from \"../../core\";\nimport { useTranslations } from \"../../i18n\";\n\ntype UseSlackChannelsProps = {\n slackChannelsRecipientObject: ContainerObject;\n};\n\ntype UseSlackChannelOutput = {\n data: SlackChannelConnection[] | null;\n updateConnectedChannels: (\n connectedChannels: SlackChannelConnection[],\n ) => void;\n loading: boolean;\n error: string | null;\n updating: boolean;\n};\n\nfunction useConnectedSlackChannels({\n slackChannelsRecipientObject: { objectId, collection },\n}: UseSlackChannelsProps): UseSlackChannelOutput {\n const { t } = useTranslations();\n const knock = useKnockClient();\n const { connectionStatus, knockSlackChannelId } = useKnockSlackClient();\n const [connectedChannels, setConnectedChannels] = useState<\n null | SlackChannelConnection[]\n >(null);\n const [error, setError] = useState<string | null>(null);\n const [isLoading, setIsLoading] = useState(false);\n const [isUpdating, setIsUpdating] = useState(false);\n\n const fetchAndSetConnectedChannels = useCallback(() => {\n setIsLoading(true);\n const getConnectedChannels = async () =>\n await knock.objects.getChannelData({\n collection,\n objectId,\n channelId: knockSlackChannelId,\n });\n\n getConnectedChannels()\n .then((res) => {\n if (res?.data?.connections) {\n setConnectedChannels(res?.data?.connections);\n } else {\n setConnectedChannels([]);\n }\n setError(null);\n setIsLoading(false);\n })\n .catch(() => {\n setConnectedChannels([]);\n setError(null);\n setIsLoading(false);\n });\n }, [collection, knock.objects, knockSlackChannelId, objectId]);\n\n useEffect(() => {\n if (\n connectionStatus === \"connected\" &&\n !connectedChannels &&\n !error &&\n !isLoading\n ) {\n fetchAndSetConnectedChannels();\n }\n }, [\n connectedChannels,\n fetchAndSetConnectedChannels,\n isLoading,\n error,\n connectionStatus,\n ]);\n\n const updateConnectedChannels = async (\n channelsToSendToKnock: SlackChannelConnection[],\n ) => {\n setIsUpdating(true);\n try {\n await knock.objects.setChannelData({\n objectId,\n collection,\n channelId: knockSlackChannelId,\n data: { connections: channelsToSendToKnock },\n });\n fetchAndSetConnectedChannels();\n } catch (
|
|
1
|
+
{"version":3,"file":"useConnectedSlackChannels.mjs","sources":["../../../../../src/modules/slack/hooks/useConnectedSlackChannels.ts"],"sourcesContent":["import { ContainerObject, useKnockSlackClient } from \"..\";\nimport { SlackChannelConnection } from \"@knocklabs/client\";\nimport { useCallback, useEffect, useState } from \"react\";\n\nimport { useKnockClient } from \"../../core\";\nimport { useTranslations } from \"../../i18n\";\n\ntype UseSlackChannelsProps = {\n slackChannelsRecipientObject: ContainerObject;\n};\n\ntype UseSlackChannelOutput = {\n data: SlackChannelConnection[] | null;\n updateConnectedChannels: (\n connectedChannels: SlackChannelConnection[],\n ) => void;\n loading: boolean;\n error: string | null;\n updating: boolean;\n};\n\nfunction useConnectedSlackChannels({\n slackChannelsRecipientObject: { objectId, collection },\n}: UseSlackChannelsProps): UseSlackChannelOutput {\n const { t } = useTranslations();\n const knock = useKnockClient();\n const { connectionStatus, knockSlackChannelId } = useKnockSlackClient();\n const [connectedChannels, setConnectedChannels] = useState<\n null | SlackChannelConnection[]\n >(null);\n const [error, setError] = useState<string | null>(null);\n const [isLoading, setIsLoading] = useState(false);\n const [isUpdating, setIsUpdating] = useState(false);\n\n const fetchAndSetConnectedChannels = useCallback(() => {\n setIsLoading(true);\n const getConnectedChannels = async () =>\n await knock.objects.getChannelData({\n collection,\n objectId,\n channelId: knockSlackChannelId,\n });\n\n getConnectedChannels()\n .then((res) => {\n if (res?.data?.connections) {\n setConnectedChannels(res?.data?.connections);\n } else {\n setConnectedChannels([]);\n }\n setError(null);\n setIsLoading(false);\n })\n .catch(() => {\n setConnectedChannels([]);\n setError(null);\n setIsLoading(false);\n });\n }, [collection, knock.objects, knockSlackChannelId, objectId]);\n\n useEffect(() => {\n if (\n connectionStatus === \"connected\" &&\n !connectedChannels &&\n !error &&\n !isLoading\n ) {\n fetchAndSetConnectedChannels();\n }\n }, [\n connectedChannels,\n fetchAndSetConnectedChannels,\n isLoading,\n error,\n connectionStatus,\n ]);\n\n const updateConnectedChannels = async (\n channelsToSendToKnock: SlackChannelConnection[],\n ) => {\n setIsUpdating(true);\n try {\n await knock.objects.setChannelData({\n objectId,\n collection,\n channelId: knockSlackChannelId,\n data: { connections: channelsToSendToKnock },\n });\n fetchAndSetConnectedChannels();\n } catch (error) {\n setError(t(\"slackChannelSetError\") || \"\");\n }\n setIsUpdating(false);\n };\n\n return {\n data: connectedChannels,\n updateConnectedChannels,\n updating: isUpdating,\n loading: isLoading,\n error,\n };\n}\n\nexport default useConnectedSlackChannels;\n"],"names":["useConnectedSlackChannels","slackChannelsRecipientObject","objectId","collection","t","useTranslations","knock","useKnockClient","connectionStatus","knockSlackChannelId","useKnockSlackClient","connectedChannels","setConnectedChannels","useState","error","setError","isLoading","setIsLoading","isUpdating","setIsUpdating","fetchAndSetConnectedChannels","useCallback","objects","getChannelData","channelId","then","res","data","connections","catch","useEffect","updateConnectedChannels","channelsToSendToKnock","setChannelData","updating","loading"],"mappings":";;;;;;;;;AAqBA,SAASA,EAA0B;AAAA,EACjCC,8BAA8B;AAAA,IAAEC,UAAAA;AAAAA,IAAUC,YAAAA;AAAAA,EAAW;AAChC,GAA0B;AACzC,QAAA;AAAA,IAAEC,GAAAA;AAAAA,MAAMC,EAAgB,GACxBC,IAAQC,KACR;AAAA,IAAEC,kBAAAA;AAAAA,IAAkBC,qBAAAA;AAAAA,MAAwBC,EAAoB,GAChE,CAACC,GAAmBC,CAAoB,IAAIC,EAEhD,IAAI,GACA,CAACC,GAAOC,CAAQ,IAAIF,EAAwB,IAAI,GAChD,CAACG,GAAWC,CAAY,IAAIJ,EAAS,EAAK,GAC1C,CAACK,GAAYC,CAAa,IAAIN,EAAS,EAAK,GAE5CO,IAA+BC,EAAY,MAAM;AACrDJ,IAAAA,EAAa,EAAI,IACY,YAC3B,MAAMX,EAAMgB,QAAQC,eAAe;AAAA,MACjCpB,YAAAA;AAAAA,MACAD,UAAAA;AAAAA,MACAsB,WAAWf;AAAAA,IAAAA,CACZ,GAEkB,EAClBgB,KAAMC,CAAQA,MAAA;;AACTA,OAAAA,IAAAA,KAAAA,gBAAAA,EAAKC,SAALD,QAAAA,EAAWE,cACQF,GAAAA,IAAAA,KAAAA,gBAAAA,EAAKC,SAALD,gBAAAA,EAAWE,WAAW,IAE3ChB,EAAqB,CAAE,CAAA,GAEzBG,EAAS,IAAI,GACbE,EAAa,EAAK;AAAA,IAAA,CACnB,EACAY,MAAM,MAAM;AACXjB,MAAAA,EAAqB,CAAE,CAAA,GACvBG,EAAS,IAAI,GACbE,EAAa,EAAK;AAAA,IAAA,CACnB;AAAA,EAAA,GACF,CAACd,GAAYG,EAAMgB,SAASb,GAAqBP,CAAQ,CAAC;AAE7D4B,SAAAA,EAAU,MAAM;AACd,IACEtB,MAAqB,eACrB,CAACG,KACD,CAACG,KACD,CAACE,KAE4BI;EAC/B,GACC,CACDT,GACAS,GACAJ,GACAF,GACAN,CAAgB,CACjB,GAoBM;AAAA,IACLmB,MAAMhB;AAAAA,IACNoB,yBApB8B,OAC9BC,MACG;AACHb,MAAAA,EAAc,EAAI;AACd,UAAA;AACIb,cAAAA,EAAMgB,QAAQW,eAAe;AAAA,UACjC/B,UAAAA;AAAAA,UACAC,YAAAA;AAAAA,UACAqB,WAAWf;AAAAA,UACXkB,MAAM;AAAA,YAAEC,aAAaI;AAAAA,UAAsB;AAAA,QAAA,CAC5C,GAC4BZ;cACf;AACLhB,QAAAA,EAAAA,EAAE,sBAAsB,KAAK,EAAE;AAAA,MAC1C;AACAe,MAAAA,EAAc,EAAK;AAAA,IAAA;AAAA,IAMnBe,UAAUhB;AAAAA,IACViB,SAASnB;AAAAA,IACTF,OAAAA;AAAAA,EAAAA;AAEJ;"}
|
|
@@ -4,7 +4,7 @@ import "../../i18n/context/KnockI18nProvider.mjs";
|
|
|
4
4
|
import "swr/infinite";
|
|
5
5
|
import { useKnockClient as p } from "../../core/context/KnockProvider.mjs";
|
|
6
6
|
import { TENANT_OBJECT_COLLECTION as _ } from "@knocklabs/client";
|
|
7
|
-
import "
|
|
7
|
+
import "fast-deep-equal";
|
|
8
8
|
import "date-fns";
|
|
9
9
|
const S = "https://slack.com/oauth/v2/authorize", u = ["chat:write", "chat:write.public", "channels:read", "groups:read"];
|
|
10
10
|
function E(s, a, r) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSlackAuth.mjs","sources":["../../../../../src/modules/slack/hooks/useSlackAuth.ts"],"sourcesContent":["import { useKnockSlackClient } from \"..\";\nimport { TENANT_OBJECT_COLLECTION } from \"@knocklabs/client\";\nimport { useCallback } from \"react\";\n\nimport { useKnockClient } from \"../../core\";\n\nconst SLACK_AUTHORIZE_URL = \"https://slack.com/oauth/v2/authorize\";\nconst DEFAULT_SLACK_SCOPES = [\n \"chat:write\",\n \"chat:write.public\",\n \"channels:read\",\n \"groups:read\",\n];\n\ntype UseSlackAuthOutput = {\n buildSlackAuthUrl: () => string;\n disconnectFromSlack: () => void;\n};\n\nfunction useSlackAuth(\n slackClientId: string,\n redirectUrl?: string,\n additionalScopes?: string[],\n): UseSlackAuthOutput {\n const knock = useKnockClient();\n const { setConnectionStatus, knockSlackChannelId, tenant, setActionLabel } =\n useKnockSlackClient();\n\n const combinedScopes =\n additionalScopes && additionalScopes.length > 0\n ? Array.from(new Set(DEFAULT_SLACK_SCOPES.concat(additionalScopes)))\n : DEFAULT_SLACK_SCOPES;\n\n const disconnectFromSlack = useCallback(async () => {\n setActionLabel(null);\n setConnectionStatus(\"disconnecting\");\n try {\n const revoke = await knock.slack.revokeAccessToken({\n tenant,\n knockChannelId: knockSlackChannelId,\n });\n\n if (revoke === \"ok\") {\n setConnectionStatus(\"disconnected\");\n } else {\n setConnectionStatus(\"error\");\n }\n } catch (
|
|
1
|
+
{"version":3,"file":"useSlackAuth.mjs","sources":["../../../../../src/modules/slack/hooks/useSlackAuth.ts"],"sourcesContent":["import { useKnockSlackClient } from \"..\";\nimport { TENANT_OBJECT_COLLECTION } from \"@knocklabs/client\";\nimport { useCallback } from \"react\";\n\nimport { useKnockClient } from \"../../core\";\n\nconst SLACK_AUTHORIZE_URL = \"https://slack.com/oauth/v2/authorize\";\nconst DEFAULT_SLACK_SCOPES = [\n \"chat:write\",\n \"chat:write.public\",\n \"channels:read\",\n \"groups:read\",\n];\n\ntype UseSlackAuthOutput = {\n buildSlackAuthUrl: () => string;\n disconnectFromSlack: () => void;\n};\n\nfunction useSlackAuth(\n slackClientId: string,\n redirectUrl?: string,\n additionalScopes?: string[],\n): UseSlackAuthOutput {\n const knock = useKnockClient();\n const { setConnectionStatus, knockSlackChannelId, tenant, setActionLabel } =\n useKnockSlackClient();\n\n const combinedScopes =\n additionalScopes && additionalScopes.length > 0\n ? Array.from(new Set(DEFAULT_SLACK_SCOPES.concat(additionalScopes)))\n : DEFAULT_SLACK_SCOPES;\n\n const disconnectFromSlack = useCallback(async () => {\n setActionLabel(null);\n setConnectionStatus(\"disconnecting\");\n try {\n const revoke = await knock.slack.revokeAccessToken({\n tenant,\n knockChannelId: knockSlackChannelId,\n });\n\n if (revoke === \"ok\") {\n setConnectionStatus(\"disconnected\");\n } else {\n setConnectionStatus(\"error\");\n }\n } catch (error) {\n setConnectionStatus(\"error\");\n }\n }, [\n setConnectionStatus,\n knock.slack,\n tenant,\n knockSlackChannelId,\n setActionLabel,\n ]);\n\n const buildSlackAuthUrl = useCallback(() => {\n const rawParams = {\n state: JSON.stringify({\n redirect_url: redirectUrl,\n access_token_object: {\n object_id: tenant,\n collection: TENANT_OBJECT_COLLECTION,\n },\n channel_id: knockSlackChannelId,\n public_key: knock.apiKey,\n user_token: knock.userToken,\n }),\n client_id: slackClientId,\n scope: combinedScopes.join(\",\"),\n };\n return `${SLACK_AUTHORIZE_URL}?${new URLSearchParams(rawParams)}`;\n }, [\n redirectUrl,\n tenant,\n knockSlackChannelId,\n knock.apiKey,\n knock.userToken,\n slackClientId,\n combinedScopes,\n ]);\n\n return {\n buildSlackAuthUrl,\n disconnectFromSlack,\n };\n}\n\nexport default useSlackAuth;\n"],"names":["SLACK_AUTHORIZE_URL","DEFAULT_SLACK_SCOPES","useSlackAuth","slackClientId","redirectUrl","additionalScopes","knock","useKnockClient","setConnectionStatus","knockSlackChannelId","tenant","setActionLabel","useKnockSlackClient","combinedScopes","length","Array","from","Set","concat","disconnectFromSlack","useCallback","revoke","slack","revokeAccessToken","knockChannelId","buildSlackAuthUrl","rawParams","state","JSON","stringify","redirect_url","access_token_object","object_id","collection","TENANT_OBJECT_COLLECTION","channel_id","public_key","apiKey","user_token","userToken","client_id","scope","join","URLSearchParams"],"mappings":";;;;;;;;AAMA,MAAMA,IAAsB,wCACtBC,IAAuB,CAC3B,cACA,qBACA,iBACA,aAAa;AAQf,SAASC,EACPC,GACAC,GACAC,GACoB;AACpB,QAAMC,IAAQC,KACR;AAAA,IAAEC,qBAAAA;AAAAA,IAAqBC,qBAAAA;AAAAA,IAAqBC,QAAAA;AAAAA,IAAQC,gBAAAA;AAAAA,MACxDC,EAAoB,GAEhBC,IACJR,KAAoBA,EAAiBS,SAAS,IAC1CC,MAAMC,KAAK,IAAIC,IAAIhB,EAAqBiB,OAAOb,CAAgB,CAAC,CAAC,IACjEJ,GAEAkB,IAAsBC,EAAY,YAAY;AAClDT,IAAAA,EAAe,IAAI,GACnBH,EAAoB,eAAe;AAC/B,QAAA;AACF,YAAMa,IAAS,MAAMf,EAAMgB,MAAMC,kBAAkB;AAAA,QACjDb,QAAAA;AAAAA,QACAc,gBAAgBf;AAAAA,MAAAA,CACjB;AAED,MACED,EADEa,MAAW,OACO,iBAEA,OAFc;AAAA,YAItB;AACdb,MAAAA,EAAoB,OAAO;AAAA,IAC7B;AAAA,EAAA,GACC,CACDA,GACAF,EAAMgB,OACNZ,GACAD,GACAE,CAAc,CACf;AA4BM,SAAA;AAAA,IACLc,mBA3BwBL,EAAY,MAAM;AAC1C,YAAMM,IAAY;AAAA,QAChBC,OAAOC,KAAKC,UAAU;AAAA,UACpBC,cAAc1B;AAAAA,UACd2B,qBAAqB;AAAA,YACnBC,WAAWtB;AAAAA,YACXuB,YAAYC;AAAAA,UACd;AAAA,UACAC,YAAY1B;AAAAA,UACZ2B,YAAY9B,EAAM+B;AAAAA,UAClBC,YAAYhC,EAAMiC;AAAAA,QAAAA,CACnB;AAAA,QACDC,WAAWrC;AAAAA,QACXsC,OAAO5B,EAAe6B,KAAK,GAAG;AAAA,MAAA;AAEhC,aAAO,GAAG1C,CAAmB,IAAI,IAAI2C,gBAAgBjB,CAAS,CAAC;AAAA,IACjE,GAAG,CACDtB,GACAM,GACAD,GACAH,EAAM+B,QACN/B,EAAMiC,WACNpC,GACAU,CAAc,CACf;AAAA,IAICM,qBAAAA;AAAAA,EAAAA;AAEJ;"}
|
|
@@ -4,7 +4,7 @@ import "../../i18n/context/KnockI18nProvider.mjs";
|
|
|
4
4
|
import A from "swr/infinite";
|
|
5
5
|
import { useKnockClient as I } from "../../core/context/KnockProvider.mjs";
|
|
6
6
|
import "@knocklabs/client";
|
|
7
|
-
import "
|
|
7
|
+
import "fast-deep-equal";
|
|
8
8
|
import "date-fns";
|
|
9
9
|
const P = 1e3, K = 200, M = "private_channel,public_channel", u = "SLACK_CHANNELS";
|
|
10
10
|
function z(n, e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSlackConnectionStatus.mjs","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 tenant: 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,\n knockChannelId: knockSlackChannelId,\n });\n\n if (authRes.connection?.ok) {\n return setConnectionStatus(\"connected\");\n }\n\n if (!authRes.connection?.ok) {\n return setConnectionStatus(\"disconnected\");\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?.ok && authRes.connection?.error) {\n const errorLabel = formatSlackErrorMessage(authRes.connection?.error);\n setErrorLabel(errorLabel);\n setConnectionStatus(\"error\");\n return;\n }\n\n // This is for any Knock errors that would require a reconnect.\n\n setConnectionStatus(\"error\");\n } catch (
|
|
1
|
+
{"version":3,"file":"useSlackConnectionStatus.mjs","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 tenant: 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,\n knockChannelId: knockSlackChannelId,\n });\n\n if (authRes.connection?.ok) {\n return setConnectionStatus(\"connected\");\n }\n\n if (!authRes.connection?.ok) {\n return setConnectionStatus(\"disconnected\");\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?.ok && authRes.connection?.error) {\n const errorLabel = formatSlackErrorMessage(authRes.connection?.error);\n setErrorLabel(errorLabel);\n setConnectionStatus(\"error\");\n return;\n }\n\n // This is for any Knock errors that would require a reconnect.\n\n setConnectionStatus(\"error\");\n } catch (error) {\n setConnectionStatus(\"error\");\n }\n };\n\n checkAuthStatus();\n }, [connectionStatus, tenant, 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","tenant","t","useTranslations","connectionStatus","setConnectionStatus","useState","errorLabel","setErrorLabel","actionLabel","setActionLabel","useEffect","authRes","slack","authCheck","knockChannelId","connection","ok","code","response","data","message","error"],"mappings":";;;AA2BA,MAAMA,IAA0BA,CAACC,MAAyB;AACxD,QAAMC,IAAcD,EAAaE,UAAU,GAAG,CAAC,EAAEC,eAC3CC,IAAOJ,EAAaE,UAAU,CAAC;AACrC,SAAOD,KAAAA,gBAAAA,EAAaI,OAAOD,GAAME,QAAQ,KAAK;AAChD;AAEA,SAASC,EACPC,GACAC,GACAC,GACgC;AAC1B,QAAA;AAAA,IAAEC,GAAAA;AAAAA,MAAMC,EAAgB,GACxB,CAACC,GAAkBC,CAAmB,IAC1CC,EAA2B,YAAY,GACnC,CAACC,GAAYC,CAAa,IAAIF,EAAwB,IAAI,GAC1D,CAACG,GAAaC,CAAc,IAAIJ,EAAwB,IAAI;AAElEK,SAAAA,EAAU,MAAM;AA4CE,KA3CQ,YAAY;;AAClC,UAAIP,MAAqB;AAErB,YAAA;AACF,gBAAMQ,IAAU,MAAMb,EAAMc,MAAMC,UAAU;AAAA,YAC1Cb,QAAAA;AAAAA,YACAc,gBAAgBf;AAAAA,UAAAA,CACjB;AAEGY,eAAAA,IAAAA,EAAQI,eAARJ,QAAAA,EAAoBK;AACtB,mBAAOZ,EAAoB,WAAW;AAWtCO,cARE,GAACA,IAAAA,EAAQI,eAARJ,QAAAA,EAAoBK,OAQvBL,EAAQM,SAAS,uBACjBN,KAAAA,IAAAA,EAAQO,aAARP,gBAAAA,EAAkBQ,SAAlBR,gBAAAA,EAAwBS,aAAYnB,EAAE,wBAAwB;AAE9D,mBAAOG,EAAoB,cAAc;AAI3C,cAAI,GAACO,IAAAA,EAAQI,eAARJ,QAAAA,EAAoBK,SAAML,IAAAA,EAAQI,eAARJ,QAAAA,EAAoBU,QAAO;AACxD,kBAAMf,IAAajB,GAAwBsB,IAAAA,EAAQI,eAARJ,gBAAAA,EAAoBU,KAAK;AACpEd,YAAAA,EAAcD,CAAU,GACxBF,EAAoB,OAAO;AAC3B;AAAA,UACF;AAIAA,UAAAA,EAAoB,OAAO;AAAA,gBACb;AACdA,UAAAA,EAAoB,OAAO;AAAA,QAC7B;AAAA,IAAA;EAGc,GACf,CAACD,GAAkBH,GAAQD,GAAqBD,EAAMc,OAAOX,CAAC,CAAC,GAE3D;AAAA,IACLE,kBAAAA;AAAAA,IACAC,qBAAAA;AAAAA,IACAE,YAAAA;AAAAA,IACAC,eAAAA;AAAAA,IACAC,aAAAA;AAAAA,IACAC,gBAAAA;AAAAA,EAAAA;AAEJ;"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnockProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAqB,MAAM,YAAY,CAAC;AAG5D,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,KAAK,CAAC;CACd;
|
|
1
|
+
{"version":3,"file":"KnockProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAqB,MAAM,YAAY,CAAC;AAG5D,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,KAAK,CAAC;CACd;AAID,MAAM,WAAW,kBAAkB;IAEjC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mBAAmB,CAAC,EAAE,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;IACjE,wBAAwB,CAAC,EAAE,mBAAmB,CAAC,0BAA0B,CAAC,CAAC;IAG3E,IAAI,CAAC,EAAE,WAAW,CAAC;IAEnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAsCzE,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,KAMjC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { default as Knock, AuthenticateOptions, KnockOptions } from '@knocklabs/client';
|
|
2
|
+
|
|
2
3
|
export type AuthenticatedKnockClientOptions = KnockOptions & AuthenticateOptions;
|
|
3
4
|
declare function useAuthenticatedKnockClient(apiKey: string, userId: string, userToken?: string, options?: AuthenticatedKnockClientOptions): Knock;
|
|
4
5
|
export default useAuthenticatedKnockClient;
|
|
@@ -2,6 +2,7 @@ import { default as Knock, Feed, FeedClientOptions, FeedStoreState } from '@knoc
|
|
|
2
2
|
import { PropsWithChildren } from 'react';
|
|
3
3
|
import { UseBoundStore } from 'zustand';
|
|
4
4
|
import { ColorMode } from '../../core/constants';
|
|
5
|
+
|
|
5
6
|
import * as React from "react";
|
|
6
7
|
export interface KnockFeedProviderState {
|
|
7
8
|
knock: Knock;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnockFeedProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/context/KnockFeedProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,IAAI,EACJ,iBAAiB,EACjB,cAAc,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAKjD,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,IAAI,CAAC;IACjB,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IAC5C,SAAS,EAAE,SAAS,CAAC;CACtB;AAMD,MAAM,WAAW,sBAAsB;IAErC,MAAM,EAAE,MAAM,CAAC;IAGf,SAAS,CAAC,EAAE,SAAS,CAAC;IAGtB,kBAAkB,CAAC,EAAE,iBAAiB,CAAC;CACxC;AAED,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CACtC,iBAAiB,CAAC,sBAAsB,CAAC,
|
|
1
|
+
{"version":3,"file":"KnockFeedProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/context/KnockFeedProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,IAAI,EACJ,iBAAiB,EACjB,cAAc,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAKjD,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,IAAI,CAAC;IACjB,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IAC5C,SAAS,EAAE,SAAS,CAAC;CACtB;AAMD,MAAM,WAAW,sBAAsB;IAErC,MAAM,EAAE,MAAM,CAAC;IAGf,SAAS,CAAC,EAAE,SAAS,CAAC;IAGtB,kBAAkB,CAAC,EAAE,iBAAiB,CAAC;CACxC;AAED,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CACtC,iBAAiB,CAAC,sBAAsB,CAAC,CAyB1C,CAAC;AAEF,eAAO,MAAM,YAAY,QAAO,sBAO/B,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Feed, FeedStoreState } from '@knocklabs/client';
|
|
2
2
|
import { StateSelector } from 'zustand';
|
|
3
|
+
|
|
3
4
|
declare function useCreateNotificationStore(feedClient: Feed): import('zustand').UseBoundStore<FeedStoreState, import('zustand').StoreApi<FeedStoreState>>;
|
|
4
5
|
declare function useNotificationStore(feedClient: Feed, selector?: StateSelector<FeedStoreState, FeedStoreState>): FeedStoreState;
|
|
5
6
|
export { useCreateNotificationStore };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { default as Knock, Feed, FeedClientOptions } from '@knocklabs/client';
|
|
2
|
+
|
|
2
3
|
declare function useNotifications(knock: Knock, feedChannelId: string, options?: FeedClientOptions): Feed;
|
|
3
4
|
export default useNotifications;
|
|
4
5
|
//# sourceMappingURL=useNotifications.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { InAppMessagesChannelClient, InAppMessagesClientOptions } from '@knocklabs/client';
|
|
2
|
+
import { ColorMode } from '../../core/constants';
|
|
3
|
+
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
export interface KnockInAppMessagesChannelProviderState {
|
|
6
|
+
inAppMessagesChannelClient: InAppMessagesChannelClient;
|
|
7
|
+
colorMode: ColorMode;
|
|
8
|
+
}
|
|
9
|
+
export interface KnockInAppMessagesChannelProviderProps {
|
|
10
|
+
channelId: string;
|
|
11
|
+
defaultOptions?: InAppMessagesClientOptions;
|
|
12
|
+
colorMode?: ColorMode;
|
|
13
|
+
}
|
|
14
|
+
export declare const KnockInAppMessagesChannelProvider: React.FC<React.PropsWithChildren<KnockInAppMessagesChannelProviderProps>>;
|
|
15
|
+
export declare const useInAppMessagesChannel: () => KnockInAppMessagesChannelProviderState;
|
|
16
|
+
//# sourceMappingURL=KnockInAppMessagesChannelProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnockInAppMessagesChannelProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/in-app-messages/context/KnockInAppMessagesChannelProvider.tsx"],"names":[],"mappings":"AAAA,OAAc,EACZ,0BAA0B,EAC1B,0BAA0B,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,MAAM,WAAW,sCAAsC;IACrD,0BAA0B,EAAE,0BAA0B,CAAC;IACvD,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,WAAW,sCAAsC;IAErD,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,0BAA0B,CAAC;IAG5C,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAMD,eAAO,MAAM,iCAAiC,EAAE,KAAK,CAAC,EAAE,CACtD,KAAK,CAAC,iBAAiB,CAAC,sCAAsC,CAAC,CA2BhE,CAAC;AAEF,eAAO,MAAM,uBAAuB,QAC9B,sCASH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/in-app-messages/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/in-app-messages/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { InAppMessage, InAppMessagesClient, InAppMessagesClientOptions, NetworkStatus } from '@knocklabs/client';
|
|
2
|
+
import { GenericData } from '@knocklabs/types';
|
|
3
|
+
|
|
4
|
+
export interface UseInAppMessagesOptions extends InAppMessagesClientOptions {
|
|
5
|
+
}
|
|
6
|
+
export interface UseInAppMessagesResponse<TContent extends GenericData, TData extends GenericData> {
|
|
7
|
+
messages: InAppMessage<TContent, TData>[];
|
|
8
|
+
networkStatus: NetworkStatus;
|
|
9
|
+
loading: boolean;
|
|
10
|
+
inAppMessagesClient: InAppMessagesClient;
|
|
11
|
+
}
|
|
12
|
+
export declare const useInAppMessages: <TContent extends GenericData = GenericData, TData extends GenericData = GenericData>(messageType: string, options?: UseInAppMessagesOptions) => UseInAppMessagesResponse<TContent, TData>;
|
|
13
|
+
export type UseInAppMessageOptions = Omit<UseInAppMessagesOptions, "page_size">;
|
|
14
|
+
export interface UseInAppMessageResponse<TContent extends GenericData, TData extends GenericData> extends GenericData {
|
|
15
|
+
message?: InAppMessage<TContent, TData>;
|
|
16
|
+
networkStatus: NetworkStatus;
|
|
17
|
+
loading: boolean;
|
|
18
|
+
inAppMessagesClient: InAppMessagesClient;
|
|
19
|
+
}
|
|
20
|
+
export declare const useInAppMessage: <TContent extends GenericData = GenericData, TData extends GenericData = GenericData>(messageType: string, options?: UseInAppMessageOptions) => UseInAppMessageResponse<TContent, TData>;
|
|
21
|
+
//# sourceMappingURL=useInAppMessages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInAppMessages.d.ts","sourceRoot":"","sources":["../../../../../src/modules/in-app-messages/hooks/useInAppMessages.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,0BAA0B,EAC1B,aAAa,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAO/C,MAAM,WAAW,uBAAwB,SAAQ,0BAA0B;CAAG;AAE9E,MAAM,WAAW,wBAAwB,CACvC,QAAQ,SAAS,WAAW,EAC5B,KAAK,SAAS,WAAW;IAEzB,QAAQ,EAAE,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC;IAC1C,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,mBAAmB,EAAE,mBAAmB,CAAC;CAC1C;AAED,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,SAAS,WAAW,gBAC5B,KAAK,SAAS,WAAW,6BAEZ,MAAM,YACV,uBAAuB,KAC/B,wBAAwB,CAAC,QAAQ,EAAE,KAAK,CA4B1C,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,uBAAuB,EAAE,WAAW,CAAC,CAAC;AAEhF,MAAM,WAAW,uBAAuB,CACtC,QAAQ,SAAS,WAAW,EAC5B,KAAK,SAAS,WAAW,CACzB,SAAQ,WAAW;IACnB,OAAO,CAAC,EAAE,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACxC,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,mBAAmB,EAAE,mBAAmB,CAAC;CAC1C;AAED,eAAO,MAAM,eAAe,GAC1B,QAAQ,SAAS,WAAW,gBAC5B,KAAK,SAAS,WAAW,6BAEZ,MAAM,YACV,sBAAsB,KAC9B,uBAAuB,CAAC,QAAQ,EAAE,KAAK,CAOzC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/in-app-messages/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,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.2.
|
|
5
|
+
"version": "0.3.0-rc-2.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/cjs/index.js",
|
|
8
8
|
"module": "dist/esm/index.mjs",
|
|
@@ -49,28 +49,30 @@
|
|
|
49
49
|
"react": "^16.11.0 || ^17.0.0 || ^18.0.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@knocklabs/client": "^0.
|
|
52
|
+
"@knocklabs/client": "^0.11.0-rc-2.0",
|
|
53
|
+
"@tanstack/react-store": "^0.5.5",
|
|
53
54
|
"date-fns": "^4.0.0",
|
|
55
|
+
"fast-deep-equal": "^3.1.3",
|
|
54
56
|
"swr": "^2.2.5",
|
|
55
57
|
"zustand": "^3.7.2"
|
|
56
58
|
},
|
|
57
59
|
"devDependencies": {
|
|
58
60
|
"@testing-library/react": "^14.2.0",
|
|
59
61
|
"@types/react": "^18.3.6",
|
|
60
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
61
|
-
"@typescript-eslint/parser": "^8.
|
|
62
|
-
"@vitejs/plugin-react": "^4.3.
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^6.20.0",
|
|
63
|
+
"@typescript-eslint/parser": "^8.8.1",
|
|
64
|
+
"@vitejs/plugin-react": "^4.3.3",
|
|
63
65
|
"babel-plugin-react-require": "^4.0.3",
|
|
64
66
|
"eslint": "^8.56.0",
|
|
65
67
|
"eslint-plugin-react-hooks": "^5.0.0",
|
|
66
|
-
"eslint-plugin-react-refresh": "^0.4.
|
|
67
|
-
"jsdom": "^
|
|
68
|
+
"eslint-plugin-react-refresh": "^0.4.4",
|
|
69
|
+
"jsdom": "^24.0.0",
|
|
68
70
|
"react": "^18.2.0",
|
|
69
71
|
"rimraf": "^6.0.1",
|
|
70
72
|
"rollup-plugin-execute": "^1.1.1",
|
|
71
73
|
"typescript": "^5.6.3",
|
|
72
74
|
"vite": "^5.0.0",
|
|
73
|
-
"vite-plugin-dts": "^
|
|
75
|
+
"vite-plugin-dts": "^3.6.3",
|
|
74
76
|
"vite-plugin-no-bundle": "^4.0.0",
|
|
75
77
|
"vitest": "^2.1.4"
|
|
76
78
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,9 +9,7 @@ export interface KnockProviderState {
|
|
|
9
9
|
knock: Knock;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
null,
|
|
14
|
-
);
|
|
12
|
+
const KnockContext = React.createContext<KnockProviderState | null>(null);
|
|
15
13
|
|
|
16
14
|
export interface KnockProviderProps {
|
|
17
15
|
// Knock client props
|
|
@@ -59,20 +57,20 @@ export const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({
|
|
|
59
57
|
);
|
|
60
58
|
|
|
61
59
|
return (
|
|
62
|
-
<
|
|
60
|
+
<KnockContext.Provider
|
|
63
61
|
value={{
|
|
64
62
|
knock,
|
|
65
63
|
}}
|
|
66
64
|
>
|
|
67
65
|
<KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>
|
|
68
|
-
</
|
|
66
|
+
</KnockContext.Provider>
|
|
69
67
|
);
|
|
70
68
|
};
|
|
71
69
|
|
|
72
70
|
export const useKnockClient = (): Knock => {
|
|
73
|
-
const context = React.useContext(
|
|
74
|
-
if (context
|
|
75
|
-
throw new Error("
|
|
71
|
+
const context = React.useContext(KnockContext);
|
|
72
|
+
if (!context) {
|
|
73
|
+
throw new Error("useKnockClient must be used within a KnockProvider");
|
|
76
74
|
}
|
|
77
75
|
return context.knock;
|
|
78
76
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import fastDeepEqual from "fast-deep-equal";
|
|
1
2
|
import { useMemo, useRef } from "react";
|
|
2
|
-
import shallow from "zustand/shallow";
|
|
3
3
|
|
|
4
4
|
export default function useStableOptions<T>(options: T): T {
|
|
5
5
|
const optionsRef = useRef<T>();
|
|
@@ -7,7 +7,7 @@ export default function useStableOptions<T>(options: T): T {
|
|
|
7
7
|
return useMemo(() => {
|
|
8
8
|
const currentOptions = optionsRef.current;
|
|
9
9
|
|
|
10
|
-
if (currentOptions &&
|
|
10
|
+
if (currentOptions && fastDeepEqual(options, currentOptions)) {
|
|
11
11
|
return currentOptions;
|
|
12
12
|
}
|
|
13
13
|
|