@knocklabs/react-core 0.6.4 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- 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/feed/context/KnockFeedProvider.js +1 -1
- package/dist/cjs/modules/feed/context/KnockFeedProvider.js.map +1 -1
- package/dist/cjs/modules/feed/hooks/useNotifications.js +1 -1
- package/dist/cjs/modules/feed/hooks/useNotifications.js.map +1 -1
- package/dist/esm/modules/core/context/KnockProvider.mjs +1 -1
- package/dist/esm/modules/core/context/KnockProvider.mjs.map +1 -1
- package/dist/esm/modules/feed/context/KnockFeedProvider.mjs +2 -2
- package/dist/esm/modules/feed/context/KnockFeedProvider.mjs.map +1 -1
- package/dist/esm/modules/feed/hooks/useNotifications.mjs +8 -10
- package/dist/esm/modules/feed/hooks/useNotifications.mjs.map +1 -1
- package/dist/types/modules/core/context/KnockProvider.d.ts +1 -1
- package/dist/types/modules/core/context/KnockProvider.d.ts.map +1 -1
- package/dist/types/modules/feed/context/KnockFeedProvider.d.ts +1 -1
- package/dist/types/modules/feed/context/KnockFeedProvider.d.ts.map +1 -1
- package/dist/types/modules/feed/hooks/useNotifications.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/modules/core/context/KnockProvider.tsx +3 -7
- package/src/modules/feed/context/KnockFeedProvider.tsx +3 -3
- package/src/modules/feed/hooks/useNotifications.ts +1 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),b=require("../../i18n/context/KnockI18nProvider.js"),K=require("../hooks/useAuthenticatedKnockClient.js");require("fast-deep-equal");function m(e){if(e&&typeof e=="object"&&"default"in e)return e;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const o=m(f),i=o.createContext(null),P=({apiKey:e,host:n,logLevel:t,userId:r,userToken:s,onUserTokenExpiring:c,timeBeforeExpirationInMs:u,children:a,i18n:l})=>{const d=o.useMemo(()=>({host:n,onUserTokenExpiring:c,timeBeforeExpirationInMs:u,logLevel:t}),[n,c,u,t]),k=K(e,r,s,d);return o.createElement(i.Provider,{value:{knock:k}},o.createElement(b.KnockI18nProvider,{i18n:l},a))},p=()=>{const e=o.useContext(i);if(!e)throw new Error("useKnockClient must be used within a KnockProvider");return e.knock};exports.KnockProvider=P;exports.useKnockClient=p;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),b=require("../../i18n/context/KnockI18nProvider.js"),K=require("../hooks/useAuthenticatedKnockClient.js");require("fast-deep-equal");function m(e){if(e&&typeof e=="object"&&"default"in e)return e;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const o=m(f),i=o.createContext(null),P=({apiKey:e,host:n,logLevel:t,userId:r,userToken:s,onUserTokenExpiring:c,timeBeforeExpirationInMs:u,children:a,i18n:l})=>{const d=o.useMemo(()=>({host:n,onUserTokenExpiring:c,timeBeforeExpirationInMs:u,logLevel:t}),[n,c,u,t]),k=K(e??"",r,s,d);return o.createElement(i.Provider,{value:{knock:k}},o.createElement(b.KnockI18nProvider,{i18n:l},a))},p=()=>{const e=o.useContext(i);if(!e)throw new Error("useKnockClient must be used within a KnockProvider");return e.knock};exports.KnockProvider=P;exports.useKnockClient=p;
|
|
2
2
|
//# sourceMappingURL=KnockProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnockProvider.js","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, { AuthenticateOptions, LogLevel } from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { I18nContent, KnockI18nProvider } from \"../../i18n\";\nimport { useAuthenticatedKnockClient } from \"../hooks\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst KnockContext = React.createContext<KnockProviderState | null>(null);\n\nexport interface KnockProviderProps {\n // Knock client props\n apiKey: string;\n host?: string;\n // Authentication props\n userId: Knock[\"userId\"];\n userToken?: Knock[\"userToken\"];\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n // i18n translations\n i18n?: I18nContent;\n logLevel?: LogLevel;\n}\n\nexport const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({\n apiKey,\n host,\n logLevel,\n userId,\n userToken,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n children,\n i18n,\n}) => {\n // We memoize the options here so that we don't create a new object on every re-render\n const authenticateOptions = React.useMemo(\n () => ({\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n }),\n [host, onUserTokenExpiring, timeBeforeExpirationInMs, logLevel],\n );\n\n const knock = useAuthenticatedKnockClient(\n apiKey,\n userId,\n userToken,\n authenticateOptions,\n );\n\n return (\n <KnockContext.Provider
|
|
1
|
+
{"version":3,"file":"KnockProvider.js","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, { AuthenticateOptions, LogLevel } from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { I18nContent, KnockI18nProvider } from \"../../i18n\";\nimport { useAuthenticatedKnockClient } from \"../hooks\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst KnockContext = React.createContext<KnockProviderState | null>(null);\n\nexport interface KnockProviderProps {\n // Knock client props\n apiKey: string | undefined;\n host?: string;\n // Authentication props\n userId: Knock[\"userId\"];\n userToken?: Knock[\"userToken\"];\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n // i18n translations\n i18n?: I18nContent;\n logLevel?: LogLevel;\n}\n\nexport const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({\n apiKey,\n host,\n logLevel,\n userId,\n userToken,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n children,\n i18n,\n}) => {\n // We memoize the options here so that we don't create a new object on every re-render\n const authenticateOptions = React.useMemo(\n () => ({\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n }),\n [host, onUserTokenExpiring, timeBeforeExpirationInMs, logLevel],\n );\n\n const knock = useAuthenticatedKnockClient(\n apiKey ?? \"\",\n userId,\n userToken,\n authenticateOptions,\n );\n\n return (\n <KnockContext.Provider value={{ knock }}>\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </KnockContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(KnockContext);\n if (!context) {\n throw new Error(\"useKnockClient must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["KnockContext","React","createContext","KnockProvider","apiKey","host","logLevel","userId","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","authenticateOptions","useMemo","knock","useAuthenticatedKnockClient","KnockI18nProvider","useKnockClient","context","useContext","Error"],"mappings":"yjBAWMA,EAAeC,EAAMC,cAAyC,IAAI,EAgB3DC,EAAiEA,CAAC,CAC7EC,OAAAA,EACAC,KAAAA,EACAC,SAAAA,EACAC,OAAAA,EACAC,UAAAA,EACAC,oBAAAA,EACAC,yBAAAA,EACAC,SAAAA,EACAC,KAAAA,CACF,IAAM,CAEEC,MAAAA,EAAsBZ,EAAMa,QAChC,KAAO,CACLT,KAAAA,EACAI,oBAAAA,EACAC,yBAAAA,EACAJ,SAAAA,IAEF,CAACD,EAAMI,EAAqBC,EAA0BJ,CAAQ,CAChE,EAEMS,EAAQC,EACZZ,GAAU,GACVG,EACAC,EACAK,CACF,EAEA,OACGZ,EAAA,cAAAD,EAAa,SAAb,CAAsB,MAAO,CAAEe,MAAAA,CAAAA,CAC9B,EAAAd,EAAA,cAACgB,EAAAA,kBAAkB,CAAA,KAAAL,CAAA,EAAaD,CAAS,CAC3C,CAEJ,EAEaO,EAAiBA,IAAa,CACnCC,MAAAA,EAAUlB,EAAMmB,WAAWpB,CAAY,EAC7C,GAAI,CAACmB,EACG,MAAA,IAAIE,MAAM,oDAAoD,EAEtE,OAAOF,EAAQJ,KACjB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),a=require("../../core/context/KnockProvider.js");require("@knocklabs/client");require("fast-deep-equal");const l=require("../../core/utils.js"),f=require("../hooks/useNotifications.js"),k=require("../hooks/useNotificationStore.js");function v(e){if(e&&typeof e=="object"&&"default"in e)return e;const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,o.get?o:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const c=v(d),u=c.createContext(void 0),K=({feedId:e,children:r,defaultFeedOptions:t={},colorMode:o="light"})=>{let n;try{n=a.useKnockClient()}catch{throw new Error("KnockFeedProvider must be used within a KnockProvider.")}const i=f(n,e,t),s=k.useCreateNotificationStore(i);return c.createElement(u.Provider,{key:l.feedProviderKey(n.userId,e,t),value:{knock:n,feedClient:i,useFeedStore:s,colorMode:o}},r)},b=()=>{const e=c.useContext(u);if(!e)throw new Error("useKnockFeed must be used within a KnockFeedProvider");return e};exports.KnockFeedProvider=K;exports.useKnockFeed=b;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),a=require("../../core/context/KnockProvider.js");require("@knocklabs/client");require("fast-deep-equal");const l=require("../../core/utils.js"),f=require("../hooks/useNotifications.js"),k=require("../hooks/useNotificationStore.js");function v(e){if(e&&typeof e=="object"&&"default"in e)return e;const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,o.get?o:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const c=v(d),u=c.createContext(void 0),K=({feedId:e,children:r,defaultFeedOptions:t={},colorMode:o="light"})=>{let n;try{n=a.useKnockClient()}catch{throw new Error("KnockFeedProvider must be used within a KnockProvider.")}const i=f(n,e??"",t),s=k.useCreateNotificationStore(i);return c.createElement(u.Provider,{key:l.feedProviderKey(n.userId,e??"",t),value:{knock:n,feedClient:i,useFeedStore:s,colorMode:o}},r)},b=()=>{const e=c.useContext(u);if(!e)throw new Error("useKnockFeed must be used within a KnockFeedProvider");return e};exports.KnockFeedProvider=K;exports.useKnockFeed=b;
|
|
2
2
|
//# sourceMappingURL=KnockFeedProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnockFeedProvider.js","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 type { StoreApi, 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<StoreApi<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 (_) {\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":"4pBAsBMA,EAAmBC,EAAMC,cAE7BC,MAAS,EAaEC,EAETA,CAAC,CAAEC,OAAAA,EAAQC,SAAAA,EAAUC,mBAAAA,EAAqB,CAAC,EAAGC,UAAAA,EAAY,OAAQ,IAAM,CACtEC,IAAAA,EACA,GAAA,CACFA,EAAQC,EAAAA,eAAe,OACb,CACJ,MAAA,IAAIC,MAAM,wDAAwD,CAAA,CAG1E,MAAMC,EAAaC,EAAiBJ,EAAOJ,
|
|
1
|
+
{"version":3,"file":"KnockFeedProvider.js","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 type { StoreApi, 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<StoreApi<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 | undefined;\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 (_) {\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":"4pBAsBMA,EAAmBC,EAAMC,cAE7BC,MAAS,EAaEC,EAETA,CAAC,CAAEC,OAAAA,EAAQC,SAAAA,EAAUC,mBAAAA,EAAqB,CAAC,EAAGC,UAAAA,EAAY,OAAQ,IAAM,CACtEC,IAAAA,EACA,GAAA,CACFA,EAAQC,EAAAA,eAAe,OACb,CACJ,MAAA,IAAIC,MAAM,wDAAwD,CAAA,CAG1E,MAAMC,EAAaC,EAAiBJ,EAAOJ,GAAU,GAAIE,CAAkB,EACrEO,EAAeC,6BAA2BH,CAAU,EAE1D,OACGX,EAAA,cAAAD,EAAiB,SAAjB,CACC,IAAKgB,EAAAA,gBAAgBP,EAAMQ,OAAQZ,GAAU,GAAIE,CAAkB,EACnE,MAAO,CACLE,MAAAA,EACAG,WAAAA,EACAE,aAAAA,EACAN,UAAAA,IAGDF,CACH,CAEJ,EAEaY,EAAeA,IAA8B,CAClDC,MAAAA,EAAUlB,EAAMmB,WAAWpB,CAAgB,EACjD,GAAI,CAACmB,EACG,MAAA,IAAIR,MAAM,sDAAsD,EAGjEQ,OAAAA,CACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const i=require("react");require("../../core/context/KnockProvider.js");require("@knocklabs/client");const o=require("../../core/hooks/useStableOptions.js");require("date-fns");function a(r,t,n={}){const e=i.useRef(),s=o(n);return i.useMemo(()=>(e.current&&e.current.dispose(),e.current=r.feeds.initialize(t,s),e.current.store.subscribe(c=>{var u;return(u=e==null?void 0:e.current)==null?void 0:u.store.setState(c)}),e.current.listenForUpdates(),e.current),[r,t,s])}module.exports=a;
|
|
2
2
|
//# sourceMappingURL=useNotifications.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNotifications.js","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"sourcesContent":["import Knock, { Feed, FeedClientOptions } from \"@knocklabs/client\";\nimport {
|
|
1
|
+
{"version":3,"file":"useNotifications.js","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"sourcesContent":["import Knock, { Feed, FeedClientOptions } from \"@knocklabs/client\";\nimport { useMemo, useRef } from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction useNotifications(\n knock: Knock,\n feedChannelId: string,\n options: FeedClientOptions = {},\n) {\n const feedClientRef = useRef<Feed>();\n const stableOptions = useStableOptions(options);\n\n return useMemo(() => {\n if (feedClientRef.current) {\n feedClientRef.current.dispose();\n }\n\n feedClientRef.current = knock.feeds.initialize(\n feedChannelId,\n stableOptions,\n );\n\n // In development, we need to introduce this extra set state to force a render\n // for Zustand as otherwise the state doesn't get reflected correctly\n feedClientRef.current.store.subscribe((t) =>\n feedClientRef?.current?.store.setState(t),\n );\n\n feedClientRef.current.listenForUpdates();\n\n return feedClientRef.current;\n }, [knock, feedChannelId, stableOptions]);\n}\n\nexport default useNotifications;\n"],"names":["useNotifications","knock","feedChannelId","options","feedClientRef","useRef","stableOptions","useStableOptions","useMemo","current","dispose","feeds","initialize","store","subscribe","t","setState","listenForUpdates"],"mappings":"8LAKA,SAASA,EACPC,EACAC,EACAC,EAA6B,CAAA,EAC7B,CACA,MAAMC,EAAgBC,EAAAA,OAAa,EAC7BC,EAAgBC,EAAiBJ,CAAO,EAE9C,OAAOK,UAAQ,KACTJ,EAAcK,SAChBL,EAAcK,QAAQC,QAAQ,EAGhCN,EAAcK,QAAUR,EAAMU,MAAMC,WAClCV,EACAI,CACF,EAIcG,EAAAA,QAAQI,MAAMC,UAAWC,UACrCX,OAAAA,EAAAA,GAAAA,YAAAA,EAAeK,UAAfL,YAAAA,EAAwBS,MAAMG,SAASD,GACzC,EAEAX,EAAcK,QAAQQ,iBAAiB,EAEhCb,EAAcK,SACpB,CAACR,EAAOC,EAAeI,CAAa,CAAC,CAC1C"}
|
|
@@ -18,7 +18,7 @@ const u = t.createContext(null), P = ({
|
|
|
18
18
|
onUserTokenExpiring: r,
|
|
19
19
|
timeBeforeExpirationInMs: c,
|
|
20
20
|
logLevel: n
|
|
21
|
-
}), [o, r, c, n]), K = l(e, i, s, a);
|
|
21
|
+
}), [o, r, c, n]), K = l(e ?? "", i, s, a);
|
|
22
22
|
return /* @__PURE__ */ t.createElement(u.Provider, { value: {
|
|
23
23
|
knock: K
|
|
24
24
|
} }, /* @__PURE__ */ t.createElement(d, { i18n: m }, k));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnockProvider.mjs","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, { AuthenticateOptions, LogLevel } from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { I18nContent, KnockI18nProvider } from \"../../i18n\";\nimport { useAuthenticatedKnockClient } from \"../hooks\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst KnockContext = React.createContext<KnockProviderState | null>(null);\n\nexport interface KnockProviderProps {\n // Knock client props\n apiKey: string;\n host?: string;\n // Authentication props\n userId: Knock[\"userId\"];\n userToken?: Knock[\"userToken\"];\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n // i18n translations\n i18n?: I18nContent;\n logLevel?: LogLevel;\n}\n\nexport const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({\n apiKey,\n host,\n logLevel,\n userId,\n userToken,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n children,\n i18n,\n}) => {\n // We memoize the options here so that we don't create a new object on every re-render\n const authenticateOptions = React.useMemo(\n () => ({\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n }),\n [host, onUserTokenExpiring, timeBeforeExpirationInMs, logLevel],\n );\n\n const knock = useAuthenticatedKnockClient(\n apiKey,\n userId,\n userToken,\n authenticateOptions,\n );\n\n return (\n <KnockContext.Provider
|
|
1
|
+
{"version":3,"file":"KnockProvider.mjs","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, { AuthenticateOptions, LogLevel } from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { I18nContent, KnockI18nProvider } from \"../../i18n\";\nimport { useAuthenticatedKnockClient } from \"../hooks\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst KnockContext = React.createContext<KnockProviderState | null>(null);\n\nexport interface KnockProviderProps {\n // Knock client props\n apiKey: string | undefined;\n host?: string;\n // Authentication props\n userId: Knock[\"userId\"];\n userToken?: Knock[\"userToken\"];\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n // i18n translations\n i18n?: I18nContent;\n logLevel?: LogLevel;\n}\n\nexport const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({\n apiKey,\n host,\n logLevel,\n userId,\n userToken,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n children,\n i18n,\n}) => {\n // We memoize the options here so that we don't create a new object on every re-render\n const authenticateOptions = React.useMemo(\n () => ({\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n }),\n [host, onUserTokenExpiring, timeBeforeExpirationInMs, logLevel],\n );\n\n const knock = useAuthenticatedKnockClient(\n apiKey ?? \"\",\n userId,\n userToken,\n authenticateOptions,\n );\n\n return (\n <KnockContext.Provider value={{ knock }}>\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </KnockContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(KnockContext);\n if (!context) {\n throw new Error(\"useKnockClient must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["KnockContext","React","createContext","KnockProvider","apiKey","host","logLevel","userId","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","authenticateOptions","useMemo","knock","useAuthenticatedKnockClient","KnockI18nProvider","useKnockClient","context","useContext","Error"],"mappings":";;;;AAWA,MAAMA,IAAeC,EAAMC,cAAyC,IAAI,GAgB3DC,IAAiEA,CAAC;AAAA,EAC7EC,QAAAA;AAAAA,EACAC,MAAAA;AAAAA,EACAC,UAAAA;AAAAA,EACAC,QAAAA;AAAAA,EACAC,WAAAA;AAAAA,EACAC,qBAAAA;AAAAA,EACAC,0BAAAA;AAAAA,EACAC,UAAAA;AAAAA,EACAC,MAAAA;AACF,MAAM;AAEEC,QAAAA,IAAsBZ,EAAMa,QAChC,OAAO;AAAA,IACLT,MAAAA;AAAAA,IACAI,qBAAAA;AAAAA,IACAC,0BAAAA;AAAAA,IACAJ,UAAAA;AAAAA,MAEF,CAACD,GAAMI,GAAqBC,GAA0BJ,CAAQ,CAChE,GAEMS,IAAQC,EACZZ,KAAU,IACVG,GACAC,GACAK,CACF;AAEA,SACG,gBAAAZ,EAAA,cAAAD,EAAa,UAAb,EAAsB,OAAO;AAAA,IAAEe,OAAAA;AAAAA,EAAAA,EAC9B,GAAA,gBAAAd,EAAA,cAACgB,GAAkB,EAAA,MAAAL,EAAA,GAAaD,CAAS,CAC3C;AAEJ,GAEaO,IAAiBA,MAAa;AACnCC,QAAAA,IAAUlB,EAAMmB,WAAWpB,CAAY;AAC7C,MAAI,CAACmB;AACG,UAAA,IAAIE,MAAM,oDAAoD;AAEtE,SAAOF,EAAQJ;AACjB;"}
|
|
@@ -17,8 +17,8 @@ const i = t.createContext(void 0), F = ({
|
|
|
17
17
|
} catch {
|
|
18
18
|
throw new Error("KnockFeedProvider must be used within a KnockProvider.");
|
|
19
19
|
}
|
|
20
|
-
const n = k(o, e, r), d = a(n);
|
|
21
|
-
return /* @__PURE__ */ t.createElement(i.Provider, { key: u(o.userId, e, r), value: {
|
|
20
|
+
const n = k(o, e ?? "", r), d = a(n);
|
|
21
|
+
return /* @__PURE__ */ t.createElement(i.Provider, { key: u(o.userId, e ?? "", r), value: {
|
|
22
22
|
knock: o,
|
|
23
23
|
feedClient: n,
|
|
24
24
|
useFeedStore: d,
|
|
@@ -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 type { StoreApi, 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<StoreApi<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 (_) {\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,UACb;AACJ,UAAA,IAAIC,MAAM,wDAAwD;AAAA,EAAA;AAG1E,QAAMC,IAAaC,EAAiBJ,GAAOJ,
|
|
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 type { StoreApi, 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<StoreApi<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 | undefined;\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 (_) {\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,UACb;AACJ,UAAA,IAAIC,MAAM,wDAAwD;AAAA,EAAA;AAG1E,QAAMC,IAAaC,EAAiBJ,GAAOJ,KAAU,IAAIE,CAAkB,GACrEO,IAAeC,EAA2BH,CAAU;AAE1D,SACG,gBAAAX,EAAA,cAAAD,EAAiB,UAAjB,EACC,KAAKgB,EAAgBP,EAAMQ,QAAQZ,KAAU,IAAIE,CAAkB,GACnE,OAAO;AAAA,IACLE,OAAAA;AAAAA,IACAG,YAAAA;AAAAA,IACAE,cAAAA;AAAAA,IACAN,WAAAA;AAAAA,OAGDF,CACH;AAEJ,GAEaY,IAAeA,MAA8B;AAClDC,QAAAA,IAAUlB,EAAMmB,WAAWpB,CAAgB;AACjD,MAAI,CAACmB;AACG,UAAA,IAAIR,MAAM,sDAAsD;AAGjEQ,SAAAA;AACT;"}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { useRef as n,
|
|
1
|
+
import { useRef as n, useMemo as c } from "react";
|
|
2
2
|
import "../../core/context/KnockProvider.mjs";
|
|
3
3
|
import "@knocklabs/client";
|
|
4
|
-
import
|
|
4
|
+
import p from "../../core/hooks/useStableOptions.mjs";
|
|
5
5
|
import "date-fns";
|
|
6
|
-
function O(
|
|
7
|
-
const
|
|
8
|
-
return c(() => () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return (i = r == null ? void 0 : r.current) == null ? void 0 : i.store.setState(u);
|
|
13
|
-
}), r.current.listenForUpdates(), r.current), [t, e, s]);
|
|
6
|
+
function O(r, e, i = {}) {
|
|
7
|
+
const t = n(), s = p(i);
|
|
8
|
+
return c(() => (t.current && t.current.dispose(), t.current = r.feeds.initialize(e, s), t.current.store.subscribe((u) => {
|
|
9
|
+
var o;
|
|
10
|
+
return (o = t == null ? void 0 : t.current) == null ? void 0 : o.store.setState(u);
|
|
11
|
+
}), t.current.listenForUpdates(), t.current), [r, e, s]);
|
|
14
12
|
}
|
|
15
13
|
export {
|
|
16
14
|
O as default
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNotifications.mjs","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"sourcesContent":["import Knock, { Feed, FeedClientOptions } from \"@knocklabs/client\";\nimport {
|
|
1
|
+
{"version":3,"file":"useNotifications.mjs","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"sourcesContent":["import Knock, { Feed, FeedClientOptions } from \"@knocklabs/client\";\nimport { useMemo, useRef } from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction useNotifications(\n knock: Knock,\n feedChannelId: string,\n options: FeedClientOptions = {},\n) {\n const feedClientRef = useRef<Feed>();\n const stableOptions = useStableOptions(options);\n\n return useMemo(() => {\n if (feedClientRef.current) {\n feedClientRef.current.dispose();\n }\n\n feedClientRef.current = knock.feeds.initialize(\n feedChannelId,\n stableOptions,\n );\n\n // In development, we need to introduce this extra set state to force a render\n // for Zustand as otherwise the state doesn't get reflected correctly\n feedClientRef.current.store.subscribe((t) =>\n feedClientRef?.current?.store.setState(t),\n );\n\n feedClientRef.current.listenForUpdates();\n\n return feedClientRef.current;\n }, [knock, feedChannelId, stableOptions]);\n}\n\nexport default useNotifications;\n"],"names":["useNotifications","knock","feedChannelId","options","feedClientRef","useRef","stableOptions","useStableOptions","useMemo","current","dispose","feeds","initialize","store","subscribe","t","setState","listenForUpdates"],"mappings":";;;;;AAKA,SAASA,EACPC,GACAC,GACAC,IAA6B,CAAA,GAC7B;AACA,QAAMC,IAAgBC,EAAa,GAC7BC,IAAgBC,EAAiBJ,CAAO;AAE9C,SAAOK,EAAQ,OACTJ,EAAcK,WAChBL,EAAcK,QAAQC,QAAQ,GAGhCN,EAAcK,UAAUR,EAAMU,MAAMC,WAClCV,GACAI,CACF,GAIcG,EAAAA,QAAQI,MAAMC,UAAWC,CAAAA;;AACrCX,YAAAA,IAAAA,KAAAA,gBAAAA,EAAeK,YAAfL,gBAAAA,EAAwBS,MAAMG,SAASD;AAAAA,GACzC,GAEAX,EAAcK,QAAQQ,iBAAiB,GAEhCb,EAAcK,UACpB,CAACR,GAAOC,GAAeI,CAAa,CAAC;AAC1C;"}
|
|
@@ -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;AAID,MAAM,WAAW,kBAAkB;IAEjC,MAAM,EAAE,MAAM,CAAC;
|
|
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,GAAG,SAAS,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACxB,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAC/B,mBAAmB,CAAC,EAAE,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;IACjE,wBAAwB,CAAC,EAAE,mBAAmB,CAAC,0BAA0B,CAAC,CAAC;IAE3E,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAkCzE,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,KAMjC,CAAC"}
|
|
@@ -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,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGvD,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,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC;IACtD,SAAS,EAAE,SAAS,CAAC;CACtB;AAMD,MAAM,WAAW,sBAAsB;IAErC,MAAM,EAAE,MAAM,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,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGvD,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,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC;IACtD,SAAS,EAAE,SAAS,CAAC;CACtB;AAMD,MAAM,WAAW,sBAAsB;IAErC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAG3B,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNotifications.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAKnE,iBAAS,gBAAgB,CACvB,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,iBAAsB,
|
|
1
|
+
{"version":3,"file":"useNotifications.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAKnE,iBAAS,gBAAgB,CACvB,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,iBAAsB,QAyBhC;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.6.
|
|
5
|
+
"version": "0.6.5",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/cjs/index.js",
|
|
8
8
|
"module": "dist/esm/index.mjs",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"react": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@knocklabs/client": "^0.14.
|
|
52
|
+
"@knocklabs/client": "^0.14.4",
|
|
53
53
|
"@tanstack/react-store": "^0.7.0",
|
|
54
54
|
"date-fns": "^4.0.0",
|
|
55
55
|
"fast-deep-equal": "^3.1.3",
|
|
@@ -13,7 +13,7 @@ const KnockContext = React.createContext<KnockProviderState | null>(null);
|
|
|
13
13
|
|
|
14
14
|
export interface KnockProviderProps {
|
|
15
15
|
// Knock client props
|
|
16
|
-
apiKey: string;
|
|
16
|
+
apiKey: string | undefined;
|
|
17
17
|
host?: string;
|
|
18
18
|
// Authentication props
|
|
19
19
|
userId: Knock["userId"];
|
|
@@ -48,18 +48,14 @@ export const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({
|
|
|
48
48
|
);
|
|
49
49
|
|
|
50
50
|
const knock = useAuthenticatedKnockClient(
|
|
51
|
-
apiKey,
|
|
51
|
+
apiKey ?? "",
|
|
52
52
|
userId,
|
|
53
53
|
userToken,
|
|
54
54
|
authenticateOptions,
|
|
55
55
|
);
|
|
56
56
|
|
|
57
57
|
return (
|
|
58
|
-
<KnockContext.Provider
|
|
59
|
-
value={{
|
|
60
|
-
knock,
|
|
61
|
-
}}
|
|
62
|
-
>
|
|
58
|
+
<KnockContext.Provider value={{ knock }}>
|
|
63
59
|
<KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>
|
|
64
60
|
</KnockContext.Provider>
|
|
65
61
|
);
|
|
@@ -26,7 +26,7 @@ const KnockFeedContext = React.createContext<
|
|
|
26
26
|
|
|
27
27
|
export interface KnockFeedProviderProps {
|
|
28
28
|
// Feed props
|
|
29
|
-
feedId: string;
|
|
29
|
+
feedId: string | undefined;
|
|
30
30
|
|
|
31
31
|
// Extra options
|
|
32
32
|
colorMode?: ColorMode;
|
|
@@ -45,12 +45,12 @@ export const KnockFeedProvider: React.FC<
|
|
|
45
45
|
throw new Error("KnockFeedProvider must be used within a KnockProvider.");
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const feedClient = useNotifications(knock, feedId, defaultFeedOptions);
|
|
48
|
+
const feedClient = useNotifications(knock, feedId ?? "", defaultFeedOptions);
|
|
49
49
|
const useFeedStore = useCreateNotificationStore(feedClient);
|
|
50
50
|
|
|
51
51
|
return (
|
|
52
52
|
<KnockFeedContext.Provider
|
|
53
|
-
key={feedProviderKey(knock.userId, feedId, defaultFeedOptions)}
|
|
53
|
+
key={feedProviderKey(knock.userId, feedId ?? "", defaultFeedOptions)}
|
|
54
54
|
value={{
|
|
55
55
|
knock,
|
|
56
56
|
feedClient,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Knock, { Feed, FeedClientOptions } from "@knocklabs/client";
|
|
2
|
-
import {
|
|
2
|
+
import { useMemo, useRef } from "react";
|
|
3
3
|
|
|
4
4
|
import { useStableOptions } from "../../core";
|
|
5
5
|
|
|
@@ -11,14 +11,6 @@ function useNotifications(
|
|
|
11
11
|
const feedClientRef = useRef<Feed>();
|
|
12
12
|
const stableOptions = useStableOptions(options);
|
|
13
13
|
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
return () => {
|
|
16
|
-
if (feedClientRef.current) {
|
|
17
|
-
feedClientRef.current.dispose();
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}, []);
|
|
21
|
-
|
|
22
14
|
return useMemo(() => {
|
|
23
15
|
if (feedClientRef.current) {
|
|
24
16
|
feedClientRef.current.dispose();
|