@knocklabs/react-core 0.2.17 → 0.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/index.js +1 -1
  3. package/dist/cjs/modules/core/context/KnockProvider.js +1 -1
  4. package/dist/cjs/modules/core/context/KnockProvider.js.map +1 -1
  5. package/dist/cjs/modules/core/hooks/useAuthenticatedKnockClient.js +1 -1
  6. package/dist/cjs/modules/core/hooks/useAuthenticatedKnockClient.js.map +1 -1
  7. package/dist/cjs/modules/core/hooks/useStableOptions.js +2 -0
  8. package/dist/cjs/modules/core/hooks/useStableOptions.js.map +1 -0
  9. package/dist/cjs/modules/feed/context/KnockFeedProvider.js +1 -1
  10. package/dist/cjs/modules/feed/context/KnockFeedProvider.js.map +1 -1
  11. package/dist/cjs/modules/feed/hooks/useNotificationStore.js +2 -0
  12. package/dist/cjs/modules/feed/hooks/useNotificationStore.js.map +1 -0
  13. package/dist/cjs/modules/feed/hooks/useNotifications.js +1 -1
  14. package/dist/cjs/modules/feed/hooks/useNotifications.js.map +1 -1
  15. package/dist/esm/index.mjs +43 -38
  16. package/dist/esm/index.mjs.map +1 -1
  17. package/dist/esm/modules/core/context/KnockProvider.mjs +10 -9
  18. package/dist/esm/modules/core/context/KnockProvider.mjs.map +1 -1
  19. package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.mjs +19 -20
  20. package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.mjs.map +1 -1
  21. package/dist/esm/modules/core/hooks/useStableOptions.mjs +13 -0
  22. package/dist/esm/modules/core/hooks/useStableOptions.mjs.map +1 -0
  23. package/dist/esm/modules/feed/context/KnockFeedProvider.mjs +12 -12
  24. package/dist/esm/modules/feed/context/KnockFeedProvider.mjs.map +1 -1
  25. package/dist/esm/modules/feed/hooks/useNotificationStore.mjs +18 -0
  26. package/dist/esm/modules/feed/hooks/useNotificationStore.mjs.map +1 -0
  27. package/dist/esm/modules/feed/hooks/useNotifications.mjs +9 -8
  28. package/dist/esm/modules/feed/hooks/useNotifications.mjs.map +1 -1
  29. package/dist/types/modules/core/hooks/index.d.ts +1 -0
  30. package/dist/types/modules/core/hooks/index.d.ts.map +1 -1
  31. package/dist/types/modules/core/hooks/useAuthenticatedKnockClient.d.ts.map +1 -1
  32. package/dist/types/modules/core/hooks/useStableOptions.d.ts +2 -0
  33. package/dist/types/modules/core/hooks/useStableOptions.d.ts.map +1 -0
  34. package/dist/types/modules/feed/context/KnockFeedProvider.d.ts.map +1 -1
  35. package/dist/types/modules/feed/hooks/index.d.ts +1 -0
  36. package/dist/types/modules/feed/hooks/index.d.ts.map +1 -1
  37. package/dist/types/modules/feed/hooks/useNotificationStore.d.ts +7 -0
  38. package/dist/types/modules/feed/hooks/useNotificationStore.d.ts.map +1 -0
  39. package/dist/types/modules/feed/hooks/useNotifications.d.ts.map +1 -1
  40. package/package.json +2 -2
  41. package/src/modules/core/hooks/index.ts +1 -0
  42. package/src/modules/core/hooks/useAuthenticatedKnockClient.ts +3 -15
  43. package/src/modules/core/hooks/useStableOptions.ts +17 -0
  44. package/src/modules/feed/context/KnockFeedProvider.tsx +3 -6
  45. package/src/modules/feed/hooks/index.ts +4 -0
  46. package/src/modules/feed/hooks/useNotificationStore.ts +45 -0
  47. package/src/modules/feed/hooks/useNotifications.ts +11 -14
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.18
4
+
5
+ ### Patch Changes
6
+
7
+ - 29e3942: fix: introduce new useNotificationStore hook to prevent issues that prevent state updates
8
+ - Updated dependencies [29e3942]
9
+ - @knocklabs/client@0.10.8
10
+
3
11
  ## 0.2.17
4
12
 
5
13
  ### Patch Changes
package/dist/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./modules/core/context/KnockProvider.js"),s=require("./modules/core/hooks/useAuthenticatedKnockClient.js"),c=require("./modules/core/constants.js"),e=require("./modules/core/utils.js"),o=require("./modules/feed/context/KnockFeedProvider.js"),i=require("./modules/feed/hooks/useNotifications.js"),a=require("./modules/feed/hooks/useFeedSettings.js"),r=require("./modules/slack/context/KnockSlackProvider.js"),u=require("./modules/slack/hooks/useSlackConnectionStatus.js"),l=require("./modules/slack/hooks/useSlackChannels.js"),d=require("./modules/slack/hooks/useConnectedSlackChannels.js"),k=require("./modules/slack/hooks/useSlackAuth.js"),t=require("./modules/i18n/context/KnockI18nProvider.js"),K=require("./modules/i18n/hooks/useTranslations.js"),S=require("./modules/i18n/languages/index.js");exports.KnockProvider=n.KnockProvider;exports.useKnockClient=n.useKnockClient;exports.useAuthenticatedKnockClient=s;exports.FilterStatus=c.FilterStatus;exports.feedProviderKey=e.feedProviderKey;exports.formatBadgeCount=e.formatBadgeCount;exports.formatTimestamp=e.formatTimestamp;exports.renderNodeOrFallback=e.renderNodeOrFallback;exports.slackProviderKey=e.slackProviderKey;exports.toSentenceCase=e.toSentenceCase;exports.KnockFeedProvider=o.KnockFeedProvider;exports.useKnockFeed=o.useKnockFeed;exports.useNotifications=i;exports.useFeedSettings=a;exports.KnockSlackProvider=r.KnockSlackProvider;exports.useKnockSlackClient=r.useKnockSlackClient;exports.useSlackConnectionStatus=u;exports.useSlackChannels=l;exports.useConnectedSlackChannels=d;exports.useSlackAuth=k;exports.I18nContext=t.I18nContext;exports.KnockI18nProvider=t.KnockI18nProvider;exports.useTranslations=K.useTranslations;exports.locales=S.locales;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./modules/core/context/KnockProvider.js"),i=require("./modules/core/hooks/useAuthenticatedKnockClient.js"),c=require("./modules/core/hooks/useStableOptions.js"),a=require("./modules/core/constants.js"),e=require("./modules/core/utils.js"),n=require("./modules/feed/context/KnockFeedProvider.js"),u=require("./modules/feed/hooks/useNotifications.js"),l=require("./modules/feed/hooks/useFeedSettings.js"),o=require("./modules/feed/hooks/useNotificationStore.js"),r=require("./modules/slack/context/KnockSlackProvider.js"),d=require("./modules/slack/hooks/useSlackConnectionStatus.js"),k=require("./modules/slack/hooks/useSlackChannels.js"),S=require("./modules/slack/hooks/useConnectedSlackChannels.js"),K=require("./modules/slack/hooks/useSlackAuth.js"),s=require("./modules/i18n/context/KnockI18nProvider.js"),C=require("./modules/i18n/hooks/useTranslations.js"),q=require("./modules/i18n/languages/index.js");exports.KnockProvider=t.KnockProvider;exports.useKnockClient=t.useKnockClient;exports.useAuthenticatedKnockClient=i;exports.useStableOptions=c;exports.FilterStatus=a.FilterStatus;exports.feedProviderKey=e.feedProviderKey;exports.formatBadgeCount=e.formatBadgeCount;exports.formatTimestamp=e.formatTimestamp;exports.renderNodeOrFallback=e.renderNodeOrFallback;exports.slackProviderKey=e.slackProviderKey;exports.toSentenceCase=e.toSentenceCase;exports.KnockFeedProvider=n.KnockFeedProvider;exports.useKnockFeed=n.useKnockFeed;exports.useNotifications=u;exports.useFeedSettings=l;exports.useCreateNotificationStore=o.useCreateNotificationStore;exports.useNotificationStore=o.default;exports.KnockSlackProvider=r.KnockSlackProvider;exports.useKnockSlackClient=r.useKnockSlackClient;exports.useSlackConnectionStatus=d;exports.useSlackChannels=k;exports.useConnectedSlackChannels=S;exports.useSlackAuth=K;exports.I18nContext=s.I18nContext;exports.KnockI18nProvider=s.KnockI18nProvider;exports.useTranslations=C.useTranslations;exports.locales=q.locales;
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),b=require("../../i18n/context/KnockI18nProvider.js"),v=require("../hooks/useAuthenticatedKnockClient.js");function P(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=P(f),i=o.createContext(null),m=({apiKey:e,host:n,logLevel:t,userId:r,userToken:a,onUserTokenExpiring:c,timeBeforeExpirationInMs:u,children:s,i18n:d})=>{const l=o.useMemo(()=>({host:n,onUserTokenExpiring:c,timeBeforeExpirationInMs:u,logLevel:t}),[n,c,u,t]),k=v(e,r,a,l);return o.createElement(i.Provider,{value:{knock:k}},o.createElement(b.KnockI18nProvider,{i18n:d},s))},K=()=>{const e=o.useContext(i);if(e===void 0)throw new Error("useKnock must be used within a KnockProvider");return e.knock};exports.KnockProvider=m;exports.useKnockClient=K;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),b=require("../../i18n/context/KnockI18nProvider.js"),v=require("../hooks/useAuthenticatedKnockClient.js");require("zustand/shallow");function P(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=P(f),i=o.createContext(null),m=({apiKey:e,host:n,logLevel:t,userId:r,userToken:a,onUserTokenExpiring:c,timeBeforeExpirationInMs:u,children:s,i18n:d})=>{const l=o.useMemo(()=>({host:n,onUserTokenExpiring:c,timeBeforeExpirationInMs:u,logLevel:t}),[n,c,u,t]),k=v(e,r,a,l);return o.createElement(i.Provider,{value:{knock:k}},o.createElement(b.KnockI18nProvider,{i18n:d},s))},K=()=>{const e=o.useContext(i);if(e===void 0)throw new Error("useKnock must be used within a KnockProvider");return e.knock};exports.KnockProvider=m;exports.useKnockClient=K;
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 ProviderStateContext = React.createContext<KnockProviderState | null>(\n null,\n);\n\nexport interface KnockProviderProps {\n // Knock client props\n apiKey: string;\n host?: string;\n // Authentication props\n userId: string;\n userToken?: string;\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n\n // i18n translations\n i18n?: I18nContent;\n\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 <ProviderStateContext.Provider\n value={{\n knock,\n }}\n >\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </ProviderStateContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(ProviderStateContext) as KnockProviderState;\n if (context === undefined) {\n throw new Error(\"useKnock must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["ProviderStateContext","React","createContext","KnockProvider","apiKey","host","logLevel","userId","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","authenticateOptions","useMemo","knock","useAuthenticatedKnockClient","KnockI18nProvider","useKnockClient","context","useContext","undefined","Error"],"mappings":"8hBAWMA,EAAuBC,EAAMC,cACjC,IACF,EAkBaC,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,CAAAA,GAEF,CAACD,EAAMI,EAAqBC,EAA0BJ,CAAQ,CAChE,EAEMS,EAAQC,EACZZ,EACAG,EACAC,EACAK,CACF,EAEA,OACGZ,EAAA,cAAAD,EAAqB,SAArB,CACC,MAAO,CACLe,MAAAA,CAAAA,CAGF,EAAAd,EAAA,cAACgB,EAAAA,kBAAkB,CAAA,KAAAL,CAAA,EAAaD,CAAS,CAC3C,CAEJ,EAEaO,EAAiBA,IAAa,CACnCC,MAAAA,EAAUlB,EAAMmB,WAAWpB,CAAoB,EACrD,GAAImB,IAAYE,OACR,MAAA,IAAIC,MAAM,8CAA8C,EAEhE,OAAOH,EAAQJ,KACjB"}
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 ProviderStateContext = React.createContext<KnockProviderState | null>(\n null,\n);\n\nexport interface KnockProviderProps {\n // Knock client props\n apiKey: string;\n host?: string;\n // Authentication props\n userId: string;\n userToken?: string;\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n\n // i18n translations\n i18n?: I18nContent;\n\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 <ProviderStateContext.Provider\n value={{\n knock,\n }}\n >\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </ProviderStateContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(ProviderStateContext) as KnockProviderState;\n if (context === undefined) {\n throw new Error(\"useKnock must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["ProviderStateContext","React","createContext","KnockProvider","apiKey","host","logLevel","userId","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","authenticateOptions","useMemo","knock","useAuthenticatedKnockClient","KnockI18nProvider","useKnockClient","context","useContext","undefined","Error"],"mappings":"yjBAWMA,EAAuBC,EAAMC,cACjC,IACF,EAkBaC,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,CAAAA,GAEF,CAACD,EAAMI,EAAqBC,EAA0BJ,CAAQ,CAChE,EAEMS,EAAQC,EACZZ,EACAG,EACAC,EACAK,CACF,EAEA,OACGZ,EAAA,cAAAD,EAAqB,SAArB,CACC,MAAO,CACLe,MAAAA,CAAAA,CAGF,EAAAd,EAAA,cAACgB,EAAAA,kBAAkB,CAAA,KAAAL,CAAA,EAAaD,CAAS,CAC3C,CAEJ,EAEaO,EAAiBA,IAAa,CACnCC,MAAAA,EAAUlB,EAAMmB,WAAWpB,CAAoB,EACrD,GAAImB,IAAYE,OACR,MAAA,IAAIC,MAAM,8CAA8C,EAEhE,OAAOH,EAAQJ,KACjB"}
@@ -1,2 +1,2 @@
1
- "use strict";const d=require("@knocklabs/client"),h=require("react"),k=require("zustand/shallow"),l=n=>n&&typeof n=="object"&&"default"in n?n:{default:n},_=l(d),a=l(h),R=l(k);function s(n,r,c,e={}){n.authenticate(r,c,{onUserTokenExpiring:e==null?void 0:e.onUserTokenExpiring,timeBeforeExpirationInMs:e==null?void 0:e.timeBeforeExpirationInMs})}function m(n,r,c,e={}){const o=a.default.useRef(),i=a.default.useRef(),u=a.default.useMemo(()=>{const t=i.current||{};return R.default(e,t)?t:(i.current=e,e)},[e]);return a.default.useMemo(()=>{const t=o.current;if(t&&t.isAuthenticated()&&(t.userId!==r||t.userToken!==c))return s(t,r,c,u),t;t&&t.teardown();const f=new _.default(n,{host:u.host,logLevel:u.logLevel});return s(f,r,c,u),o.current=f,f},[n,r,c,u])}module.exports=m;
1
+ "use strict";const s=require("@knocklabs/client"),d=require("react");require("../context/KnockProvider.js");const k=require("./useStableOptions.js");require("date-fns");const l=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},h=l(s),o=l(d);function f(e,r,c,t={}){e.authenticate(r,c,{onUserTokenExpiring:t==null?void 0:t.onUserTokenExpiring,timeBeforeExpirationInMs:t==null?void 0:t.timeBeforeExpirationInMs})}function q(e,r,c,t={}){const a=o.default.useRef(),u=k(t);return o.default.useMemo(()=>{const n=a.current;if(n&&n.isAuthenticated()&&(n.userId!==r||n.userToken!==c))return f(n,r,c,u),n;n&&n.teardown();const i=new h.default(e,{host:u.host,logLevel:u.logLevel});return f(i,r,c,u),a.current=i,i},[e,r,c,u])}module.exports=q;
2
2
  //# sourceMappingURL=useAuthenticatedKnockClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAuthenticatedKnockClient.js","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, { AuthenticateOptions, KnockOptions } from \"@knocklabs/client\";\nimport React from \"react\";\nimport shallow from \"zustand/shallow\";\n\nfunction authenticateWithOptions(\n knock: Knock,\n userId: string,\n userToken?: string,\n options: AuthenticateOptions = {},\n) {\n knock.authenticate(userId, userToken, {\n onUserTokenExpiring: options?.onUserTokenExpiring,\n timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,\n });\n}\n\nexport type AuthenticatedKnockClientOptions = KnockOptions &\n AuthenticateOptions;\n\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userId: string,\n userToken?: string,\n options: AuthenticatedKnockClientOptions = {},\n) {\n const knockRef = React.useRef<Knock | undefined>();\n const optionsRef = React.useRef<AuthenticatedKnockClientOptions>();\n\n // Shallow compare options so that we ensure that we have a stable\n // set of options between re-renders.\n const stableOptions = React.useMemo(() => {\n const currentOptions = optionsRef.current || {};\n\n if (shallow(options, currentOptions)) {\n return currentOptions;\n }\n\n optionsRef.current = options;\n return options;\n }, [options]);\n\n return React.useMemo(() => {\n const currentKnock = knockRef.current;\n\n // If the userId and the userToken changes then just reauth\n if (\n currentKnock &&\n currentKnock.isAuthenticated() &&\n (currentKnock.userId !== userId || currentKnock.userToken !== userToken)\n ) {\n authenticateWithOptions(currentKnock, userId, userToken, stableOptions);\n return currentKnock;\n }\n\n if (currentKnock) {\n currentKnock.teardown();\n }\n\n // Otherwise instantiate a new Knock client\n const knock = new Knock(apiKey, {\n host: stableOptions.host,\n logLevel: stableOptions.logLevel,\n });\n\n authenticateWithOptions(knock, userId, userToken, stableOptions);\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, userId, userToken, stableOptions]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userId","userToken","options","authenticate","onUserTokenExpiring","timeBeforeExpirationInMs","useAuthenticatedKnockClient","apiKey","knockRef","React","useRef","optionsRef","stableOptions","useMemo","currentOptions","current","shallow","currentKnock","isAuthenticated","teardown","Knock","host","logLevel"],"mappings":"+KAIA,SAASA,EACPC,EACAC,EACAC,EACAC,EAA+B,CAAA,EAC/B,CACMC,EAAAA,aAAaH,EAAQC,EAAW,CACpCG,oBAAqBF,GAAAA,YAAAA,EAASE,oBAC9BC,yBAA0BH,GAAAA,YAAAA,EAASG,wBAAAA,CACpC,CACH,CAKA,SAASC,EACPC,EACAP,EACAC,EACAC,EAA2C,CAAA,EAC3C,CACMM,MAAAA,EAAWC,UAAMC,SACjBC,EAAaF,UAAMC,SAInBE,EAAgBH,UAAMI,QAAQ,IAAM,CAClCC,MAAAA,EAAiBH,EAAWI,SAAW,GAEzCC,OAAAA,EAAAA,QAAQd,EAASY,CAAc,EAC1BA,GAGTH,EAAWI,QAAUb,EACdA,EAAAA,EACN,CAACA,CAAO,CAAC,EAELO,OAAAA,EAAAA,QAAMI,QAAQ,IAAM,CACzB,MAAMI,EAAeT,EAASO,QAI5BE,GAAAA,GACAA,EAAaC,gBAAgB,IAC5BD,EAAajB,SAAWA,GAAUiB,EAAahB,YAAcA,GAEtCgB,OAAAA,EAAAA,EAAcjB,EAAQC,EAAWW,CAAa,EAC/DK,EAGLA,GACFA,EAAaE,SAAS,EAIlBpB,MAAAA,EAAQ,IAAIqB,EAAAA,QAAMb,EAAQ,CAC9Bc,KAAMT,EAAcS,KACpBC,SAAUV,EAAcU,QAAAA,CACzB,EAEuBvB,OAAAA,EAAAA,EAAOC,EAAQC,EAAWW,CAAa,EAC/DJ,EAASO,QAAUhB,EAEZA,GACN,CAACQ,EAAQP,EAAQC,EAAWW,CAAa,CAAC,CAC/C"}
1
+ {"version":3,"file":"useAuthenticatedKnockClient.js","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, { AuthenticateOptions, KnockOptions } from \"@knocklabs/client\";\nimport React from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction authenticateWithOptions(\n knock: Knock,\n userId: string,\n userToken?: string,\n options: AuthenticateOptions = {},\n) {\n knock.authenticate(userId, userToken, {\n onUserTokenExpiring: options?.onUserTokenExpiring,\n timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,\n });\n}\n\nexport type AuthenticatedKnockClientOptions = KnockOptions &\n AuthenticateOptions;\n\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userId: string,\n userToken?: string,\n options: AuthenticatedKnockClientOptions = {},\n) {\n const knockRef = React.useRef<Knock | undefined>();\n const stableOptions = useStableOptions(options);\n\n return React.useMemo(() => {\n const currentKnock = knockRef.current;\n\n // If the userId and the userToken changes then just reauth\n if (\n currentKnock &&\n currentKnock.isAuthenticated() &&\n (currentKnock.userId !== userId || currentKnock.userToken !== userToken)\n ) {\n authenticateWithOptions(currentKnock, userId, userToken, stableOptions);\n return currentKnock;\n }\n\n if (currentKnock) {\n currentKnock.teardown();\n }\n\n // Otherwise instantiate a new Knock client\n const knock = new Knock(apiKey, {\n host: stableOptions.host,\n logLevel: stableOptions.logLevel,\n });\n\n authenticateWithOptions(knock, userId, userToken, stableOptions);\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, userId, userToken, stableOptions]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userId","userToken","options","authenticate","onUserTokenExpiring","timeBeforeExpirationInMs","useAuthenticatedKnockClient","apiKey","knockRef","React","useRef","stableOptions","useStableOptions","useMemo","currentKnock","current","isAuthenticated","teardown","Knock","host","logLevel"],"mappings":"qPAKA,SAASA,EACPC,EACAC,EACAC,EACAC,EAA+B,CAAA,EAC/B,CACMC,EAAAA,aAAaH,EAAQC,EAAW,CACpCG,oBAAqBF,GAAAA,YAAAA,EAASE,oBAC9BC,yBAA0BH,GAAAA,YAAAA,EAASG,wBAAAA,CACpC,CACH,CAKA,SAASC,EACPC,EACAP,EACAC,EACAC,EAA2C,CAAA,EAC3C,CACMM,MAAAA,EAAWC,UAAMC,SACjBC,EAAgBC,EAAiBV,CAAO,EAEvCO,OAAAA,EAAAA,QAAMI,QAAQ,IAAM,CACzB,MAAMC,EAAeN,EAASO,QAI5BD,GAAAA,GACAA,EAAaE,gBAAgB,IAC5BF,EAAad,SAAWA,GAAUc,EAAab,YAAcA,GAEtCa,OAAAA,EAAAA,EAAcd,EAAQC,EAAWU,CAAa,EAC/DG,EAGLA,GACFA,EAAaG,SAAS,EAIlBlB,MAAAA,EAAQ,IAAImB,EAAAA,QAAMX,EAAQ,CAC9BY,KAAMR,EAAcQ,KACpBC,SAAUT,EAAcS,QAAAA,CACzB,EAEuBrB,OAAAA,EAAAA,EAAOC,EAAQC,EAAWU,CAAa,EAC/DH,EAASO,QAAUhB,EAEZA,GACN,CAACQ,EAAQP,EAAQC,EAAWU,CAAa,CAAC,CAC/C"}
@@ -0,0 +1,2 @@
1
+ "use strict";const u=require("react"),n=require("zustand/shallow"),s=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},c=s(n);function o(t){const r=u.useRef();return u.useMemo(()=>{const e=r.current;return e&&c.default(t,e)?e:(r.current=t,t)},[t])}module.exports=o;
2
+ //# sourceMappingURL=useStableOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useStableOptions.js","sources":["../../../../../src/modules/core/hooks/useStableOptions.ts"],"sourcesContent":["import { useMemo, useRef } from \"react\";\nimport shallow from \"zustand/shallow\";\n\nexport default function useStableOptions<T>(options: T): T {\n const optionsRef = useRef<T>();\n\n return useMemo(() => {\n const currentOptions = optionsRef.current;\n\n if (currentOptions && shallow(options, currentOptions)) {\n return currentOptions;\n }\n\n optionsRef.current = options;\n return options;\n }, [options]);\n}\n"],"names":["useStableOptions","options","optionsRef","useRef","useMemo","currentOptions","current","shallow"],"mappings":"kIAGA,SAAwBA,EAAoBC,EAAe,CACzD,MAAMC,EAAaC,EAAAA,SAEnB,OAAOC,UAAQ,IAAM,CACnB,MAAMC,EAAiBH,EAAWI,QAElC,OAAID,GAAkBE,EAAAA,QAAQN,EAASI,CAAc,EAC5CA,GAGTH,EAAWI,QAAUL,EACdA,EAAAA,EACN,CAACA,CAAO,CAAC,CACd"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),d=require("zustand"),l=require("../../core/context/KnockProvider.js");require("@knocklabs/client");require("zustand/shallow");const f=require("../../core/utils.js"),k=require("../hooks/useNotifications.js"),b=e=>e&&typeof e=="object"&&"default"in e?e:{default:e};function p(e){if(e&&typeof e=="object"&&"default"in e)return e;const o=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(o,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return o.default=e,Object.freeze(o)}const n=p(a),m=b(d),i=n.createContext(void 0),v=({feedId:e,children:o,defaultFeedOptions:t={},colorMode:r="light"})=>{const c=l.useKnockClient(),u=k(c,e,t),s=n.useMemo(()=>m.default(u.store),[u]);return n.createElement(i.Provider,{key:f.feedProviderKey(c.userId,e,t),value:{knock:c,feedClient:u,useFeedStore:s,colorMode:r}},o)},y=()=>{const e=n.useContext(i);if(!e)throw new Error("useKnockFeed must be used within a KnockFeedProvider");return e};exports.KnockFeedProvider=v;exports.useKnockFeed=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),d=require("../../core/context/KnockProvider.js");require("@knocklabs/client");require("zustand/shallow");const l=require("../../core/utils.js"),f=require("../hooks/useNotifications.js"),k=require("../hooks/useNotificationStore.js");function b(e){if(e&&typeof e=="object"&&"default"in e)return e;const o=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(o,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return o.default=e,Object.freeze(o)}const c=b(a),u=c.createContext(void 0),v=({feedId:e,children:o,defaultFeedOptions:t={},colorMode:r="light"})=>{const n=d.useKnockClient(),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:r}},o)},K=()=>{const e=c.useContext(u);if(!e)throw new Error("useKnockFeed must be used within a KnockFeedProvider");return e};exports.KnockFeedProvider=v;exports.useKnockFeed=K;
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 create, { UseBoundStore } from \"zustand\";\n\nimport { useKnockClient } from \"../../core\";\nimport { ColorMode } from \"../../core/constants\";\nimport { feedProviderKey } from \"../../core/utils\";\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 FeedStateContext = 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 const knock = useKnockClient();\n const feedClient = useNotifications(knock, feedId, defaultFeedOptions);\n\n const useFeedStore = React.useMemo(\n () => create<FeedStoreState>(feedClient.store),\n [feedClient],\n );\n\n return (\n <FeedStateContext.Provider\n key={feedProviderKey(knock.userId, feedId, defaultFeedOptions)}\n value={{\n knock,\n feedClient,\n useFeedStore,\n colorMode,\n }}\n >\n {children}\n </FeedStateContext.Provider>\n );\n};\n\nexport const useKnockFeed = (): KnockFeedProviderState => {\n const context = React.useContext(FeedStateContext);\n\n if (!context) {\n throw new Error(\"useKnockFeed must be used within a KnockFeedProvider\");\n }\n\n return context;\n};\n"],"names":["FeedStateContext","React","createContext","undefined","KnockFeedProvider","feedId","children","defaultFeedOptions","colorMode","knock","useKnockClient","feedClient","useNotifications","useFeedStore","useMemo","create","store","feedProviderKey","userId","useKnockFeed","context","useContext","Error"],"mappings":"ksBAqBMA,EAAmBC,EAAMC,cAE7BC,MAAS,EAaEC,EAETA,CAAC,CAAEC,OAAAA,EAAQC,SAAAA,EAAUC,mBAAAA,EAAqB,CAAC,EAAGC,UAAAA,EAAY,OAAQ,IAAM,CAC1E,MAAMC,EAAQC,EAAAA,iBACRC,EAAaC,EAAiBH,EAAOJ,EAAQE,CAAkB,EAE/DM,EAAeZ,EAAMa,QACzB,IAAMC,EAAAA,QAAuBJ,EAAWK,KAAK,EAC7C,CAACL,CAAU,CACb,EAGE,OAAAV,EAAA,cAACD,EAAiB,SAAjB,CACC,IAAKiB,kBAAgBR,EAAMS,OAAQb,EAAQE,CAAkB,EAC7D,MAAO,CACLE,MAAAA,EACAE,WAAAA,EACAE,aAAAA,EACAL,UAAAA,CAAAA,GAGDF,CACH,CAEJ,EAEaa,EAAeA,IAA8B,CAClDC,MAAAA,EAAUnB,EAAMoB,WAAWrB,CAAgB,EAEjD,GAAI,CAACoB,EACG,MAAA,IAAIE,MAAM,sDAAsD,EAGjEF,OAAAA,CACT"}
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 { 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 FeedStateContext = 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 const knock = useKnockClient();\n const feedClient = useNotifications(knock, feedId, defaultFeedOptions);\n const useFeedStore = useCreateNotificationStore(feedClient);\n\n return (\n <FeedStateContext.Provider\n key={feedProviderKey(knock.userId, feedId, defaultFeedOptions)}\n value={{\n knock,\n feedClient,\n useFeedStore,\n colorMode,\n }}\n >\n {children}\n </FeedStateContext.Provider>\n );\n};\n\nexport const useKnockFeed = (): KnockFeedProviderState => {\n const context = React.useContext(FeedStateContext);\n\n if (!context) {\n throw new Error(\"useKnockFeed must be used within a KnockFeedProvider\");\n }\n\n return context;\n};\n"],"names":["FeedStateContext","React","createContext","undefined","KnockFeedProvider","feedId","children","defaultFeedOptions","colorMode","knock","useKnockClient","feedClient","useNotifications","useFeedStore","useCreateNotificationStore","feedProviderKey","userId","useKnockFeed","context","useContext","Error"],"mappings":"4pBAsBMA,EAAmBC,EAAMC,cAE7BC,MAAS,EAaEC,EAETA,CAAC,CAAEC,OAAAA,EAAQC,SAAAA,EAAUC,mBAAAA,EAAqB,CAAC,EAAGC,UAAAA,EAAY,OAAQ,IAAM,CAC1E,MAAMC,EAAQC,EAAAA,iBACRC,EAAaC,EAAiBH,EAAOJ,EAAQE,CAAkB,EAC/DM,EAAeC,6BAA2BH,CAAU,EAGxD,OAAAV,EAAA,cAACD,EAAiB,SAAjB,CACC,IAAKe,kBAAgBN,EAAMO,OAAQX,EAAQE,CAAkB,EAC7D,MAAO,CACLE,MAAAA,EACAE,WAAAA,EACAE,aAAAA,EACAL,UAAAA,CAAAA,GAGDF,CACH,CAEJ,EAEaW,EAAeA,IAA8B,CAClDC,MAAAA,EAAUjB,EAAMkB,WAAWnB,CAAgB,EAEjD,GAAI,CAACkB,EACG,MAAA,IAAIE,MAAM,sDAAsD,EAGjEF,OAAAA,CACT"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("react"),a=require("zustand"),i=e=>e&&typeof e=="object"&&"default"in e?e:{default:e};function f(e){if(e&&typeof e=="object"&&"default"in e)return e;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const r=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,r.get?r:{enumerable:!0,get:()=>e[o]})}}return t.default=e,Object.freeze(t)}const u=f(s),d=i(a),l=typeof window<"u"?u.useLayoutEffect:u.useEffect;function c(e){const t=u.useMemo(()=>d.default(e.store),[e]),[,o]=u.useReducer(r=>r+1,0);return l(()=>{const r=o,n=e.store.subscribe(r);return r(),n},[e]),t}function p(e,t){return c(e)(t||e.store.getState)}exports.default=p;exports.useCreateNotificationStore=c;
2
+ //# sourceMappingURL=useNotificationStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNotificationStore.js","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"sourcesContent":["import { Feed, FeedStoreState } from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport type { DispatchWithoutAction } from \"react\";\nimport create, { StateSelector } from \"zustand\";\n\nconst useIsomorphicLayoutEffect =\n typeof window !== \"undefined\" ? React.useLayoutEffect : React.useEffect;\n\n// A hook designed to create a `UseBoundStore` instance\nfunction useCreateNotificationStore(feedClient: Feed) {\n const useStore = React.useMemo(\n () => create<FeedStoreState>(feedClient.store),\n [feedClient],\n );\n\n // Warning: this is a hack that will cause any components downstream to re-render\n // as a result of the store updating.\n const [, forceUpdate] = React.useReducer((c) => c + 1, 0) as [\n never,\n () => void,\n ];\n\n useIsomorphicLayoutEffect(() => {\n const rerender = forceUpdate as DispatchWithoutAction;\n const unsubscribe = feedClient.store.subscribe(rerender);\n\n rerender();\n\n return unsubscribe;\n }, [feedClient]);\n\n return useStore;\n}\n\n// A hook used to access content *within* the notification store\nfunction useNotificationStore(\n feedClient: Feed,\n selector?: StateSelector<FeedStoreState, FeedStoreState>,\n) {\n const useStore = useCreateNotificationStore(feedClient);\n return useStore<FeedStoreState>(selector || feedClient.store.getState);\n}\n\nexport { useCreateNotificationStore };\nexport default useNotificationStore;\n"],"names":["useIsomorphicLayoutEffect","window","React","useLayoutEffect","useEffect","useCreateNotificationStore","feedClient","useStore","useMemo","create","store","forceUpdate","useReducer","c","rerender","unsubscribe","subscribe","useNotificationStore","selector","getState"],"mappings":"oiBAKMA,EACJ,OAAOC,OAAW,IAAcC,EAAMC,gBAAkBD,EAAME,UAGhE,SAASC,EAA2BC,EAAkB,CAC9CC,MAAAA,EAAWL,EAAMM,QACrB,IAAMC,EAAAA,QAAuBH,EAAWI,KAAK,EAC7C,CAACJ,CAAU,CACb,EAIM,CAAGK,CAAAA,CAAW,EAAIT,EAAMU,WAAYC,GAAMA,EAAI,EAAG,CAAC,EAKxDb,OAAAA,EAA0B,IAAM,CAC9B,MAAMc,EAAWH,EACXI,EAAcT,EAAWI,MAAMM,UAAUF,CAAQ,EAE9C,OAAAA,IAEFC,CAAAA,EACN,CAACT,CAAU,CAAC,EAERC,CACT,CAGA,SAASU,EACPX,EACAY,EACA,CAEA,OADiBb,EAA2BC,CAAU,EACtBY,GAAYZ,EAAWI,MAAMS,QAAQ,CACvE"}
@@ -1,2 +1,2 @@
1
- "use strict";const c=require("react");function i(t,s,e={}){const r=c.useRef();return c.useMemo(()=>(r.current&&r.current.dispose(),r.current=t.feeds.initialize(s,e),r.current.listenForUpdates(),r.current.store.subscribe(n=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.store.setState(n)}),r.current),[t,s,e.source,e.tenant,e.has_tenant,e.archived])}module.exports=i;
1
+ "use strict";const s=require("react");require("../../core/context/KnockProvider.js");require("@knocklabs/client");const n=require("../../core/hooks/useStableOptions.js");require("date-fns");function c(r,t,u={}){const e=s.useRef(),i=n(u);return s.useMemo(()=>(e.current&&e.current.dispose(),e.current=r.feeds.initialize(t,i),e.current.listenForUpdates(),e.current),[r,t,i])}module.exports=c;
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 { useMemo, useRef } from \"react\";\n\nfunction useNotifications(\n knock: Knock,\n feedChannelId: string,\n options: FeedClientOptions = {},\n) {\n const feedClientRef = useRef<Feed | null>();\n\n return useMemo(() => {\n if (feedClientRef.current) {\n feedClientRef.current.dispose();\n }\n\n feedClientRef.current = knock.feeds.initialize(feedChannelId, options);\n feedClientRef.current.listenForUpdates();\n feedClientRef.current.store.subscribe((t) =>\n feedClientRef?.current?.store.setState(t),\n );\n\n return feedClientRef.current;\n }, [\n knock,\n feedChannelId,\n options.source,\n options.tenant,\n options.has_tenant,\n options.archived,\n ]);\n}\n\nexport default useNotifications;\n"],"names":["useNotifications","knock","feedChannelId","options","feedClientRef","useRef","useMemo","current","dispose","feeds","initialize","listenForUpdates","store","subscribe","t","setState","source","tenant","has_tenant","archived"],"mappings":"sCAGA,SAASA,EACPC,EACAC,EACAC,EAA6B,CAAA,EAC7B,CACA,MAAMC,EAAgBC,EAAAA,SAEtB,OAAOC,UAAQ,KACTF,EAAcG,SAChBH,EAAcG,QAAQC,UAGxBJ,EAAcG,QAAUN,EAAMQ,MAAMC,WAAWR,EAAeC,CAAO,EACrEC,EAAcG,QAAQI,mBACRJ,EAAAA,QAAQK,MAAMC,UAAWC,GAAAA,OACrCV,OAAAA,EAAAA,GAAAA,YAAAA,EAAeG,UAAfH,YAAAA,EAAwBQ,MAAMG,SAASD,GACzC,EAEOV,EAAcG,SACpB,CACDN,EACAC,EACAC,EAAQa,OACRb,EAAQc,OACRd,EAAQe,WACRf,EAAQgB,QAAQ,CACjB,CACH"}
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 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","listenForUpdates"],"mappings":"8LAKA,SAASA,EACPC,EACAC,EACAC,EAA6B,CAAA,EAC7B,CACA,MAAMC,EAAgBC,EAAAA,SAChBC,EAAgBC,EAAiBJ,CAAO,EAE9C,OAAOK,UAAQ,KACTJ,EAAcK,SAChBL,EAAcK,QAAQC,UAGxBN,EAAcK,QAAUR,EAAMU,MAAMC,WAClCV,EACAI,CACF,EAEAF,EAAcK,QAAQI,mBAEfT,EAAcK,SACpB,CAACR,EAAOC,EAAeI,CAAa,CAAC,CAC1C"}
@@ -1,42 +1,47 @@
1
- import { KnockProvider as r, useKnockClient as t } from "./modules/core/context/KnockProvider.mjs";
2
- import { default as n } from "./modules/core/hooks/useAuthenticatedKnockClient.mjs";
3
- import { FilterStatus as f } from "./modules/core/constants.mjs";
4
- import { feedProviderKey as u, formatBadgeCount as c, formatTimestamp as d, renderNodeOrFallback as m, slackProviderKey as i, toSentenceCase as k } from "./modules/core/utils.mjs";
5
- import { KnockFeedProvider as x, useKnockFeed as C } from "./modules/feed/context/KnockFeedProvider.mjs";
6
- import { default as S } from "./modules/feed/hooks/useNotifications.mjs";
7
- import { default as P } from "./modules/feed/hooks/useFeedSettings.mjs";
8
- import { KnockSlackProvider as h, useKnockSlackClient as g } from "./modules/slack/context/KnockSlackProvider.mjs";
9
- import { default as A } from "./modules/slack/hooks/useSlackConnectionStatus.mjs";
10
- import { default as N } from "./modules/slack/hooks/useSlackChannels.mjs";
11
- import { default as b } from "./modules/slack/hooks/useConnectedSlackChannels.mjs";
12
- import { default as O } from "./modules/slack/hooks/useSlackAuth.mjs";
13
- import { I18nContext as q, KnockI18nProvider as w } from "./modules/i18n/context/KnockI18nProvider.mjs";
14
- import { useTranslations as D } from "./modules/i18n/hooks/useTranslations.mjs";
15
- import { locales as G } from "./modules/i18n/languages/index.mjs";
1
+ import { KnockProvider as t, useKnockClient as r } from "./modules/core/context/KnockProvider.mjs";
2
+ import { default as s } from "./modules/core/hooks/useAuthenticatedKnockClient.mjs";
3
+ import { default as f } from "./modules/core/hooks/useStableOptions.mjs";
4
+ import { FilterStatus as u } from "./modules/core/constants.mjs";
5
+ import { feedProviderKey as c, formatBadgeCount as d, formatTimestamp as m, renderNodeOrFallback as p, slackProviderKey as x, toSentenceCase as k } from "./modules/core/utils.mjs";
6
+ import { KnockFeedProvider as C, useKnockFeed as K } from "./modules/feed/context/KnockFeedProvider.mjs";
7
+ import { default as P } from "./modules/feed/hooks/useNotifications.mjs";
8
+ import { default as h } from "./modules/feed/hooks/useFeedSettings.mjs";
9
+ import { useCreateNotificationStore as b, default as g } from "./modules/feed/hooks/useNotificationStore.mjs";
10
+ import { KnockSlackProvider as A, useKnockSlackClient as I } from "./modules/slack/context/KnockSlackProvider.mjs";
11
+ import { default as T } from "./modules/slack/hooks/useSlackConnectionStatus.mjs";
12
+ import { default as j } from "./modules/slack/hooks/useSlackChannels.mjs";
13
+ import { default as w } from "./modules/slack/hooks/useConnectedSlackChannels.mjs";
14
+ import { default as D } from "./modules/slack/hooks/useSlackAuth.mjs";
15
+ import { I18nContext as G, KnockI18nProvider as H } from "./modules/i18n/context/KnockI18nProvider.mjs";
16
+ import { useTranslations as L } from "./modules/i18n/hooks/useTranslations.mjs";
17
+ import { locales as Q } from "./modules/i18n/languages/index.mjs";
16
18
  export {
17
- f as FilterStatus,
18
- q as I18nContext,
19
- x as KnockFeedProvider,
20
- w as KnockI18nProvider,
21
- r as KnockProvider,
22
- h as KnockSlackProvider,
23
- u as feedProviderKey,
24
- c as formatBadgeCount,
25
- d as formatTimestamp,
26
- G as locales,
27
- m as renderNodeOrFallback,
28
- i as slackProviderKey,
19
+ u as FilterStatus,
20
+ G as I18nContext,
21
+ C as KnockFeedProvider,
22
+ H as KnockI18nProvider,
23
+ t as KnockProvider,
24
+ A as KnockSlackProvider,
25
+ c as feedProviderKey,
26
+ d as formatBadgeCount,
27
+ m as formatTimestamp,
28
+ Q as locales,
29
+ p as renderNodeOrFallback,
30
+ x as slackProviderKey,
29
31
  k as toSentenceCase,
30
- n as useAuthenticatedKnockClient,
31
- b as useConnectedSlackChannels,
32
- P as useFeedSettings,
33
- t as useKnockClient,
34
- C as useKnockFeed,
35
- g as useKnockSlackClient,
36
- S as useNotifications,
37
- O as useSlackAuth,
38
- N as useSlackChannels,
39
- A as useSlackConnectionStatus,
40
- D as useTranslations
32
+ s as useAuthenticatedKnockClient,
33
+ w as useConnectedSlackChannels,
34
+ b as useCreateNotificationStore,
35
+ h as useFeedSettings,
36
+ r as useKnockClient,
37
+ K as useKnockFeed,
38
+ I as useKnockSlackClient,
39
+ g as useNotificationStore,
40
+ P as useNotifications,
41
+ D as useSlackAuth,
42
+ j as useSlackChannels,
43
+ T as useSlackConnectionStatus,
44
+ f as useStableOptions,
45
+ L as useTranslations
41
46
  };
42
47
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -1,34 +1,35 @@
1
1
  import * as t from "react";
2
2
  import { KnockI18nProvider as v } from "../../i18n/context/KnockI18nProvider.mjs";
3
3
  import K from "../hooks/useAuthenticatedKnockClient.mjs";
4
- const u = t.createContext(null), P = ({
4
+ import "zustand/shallow";
5
+ const i = t.createContext(null), p = ({
5
6
  apiKey: e,
6
7
  host: o,
7
8
  logLevel: n,
8
- userId: i,
9
+ userId: u,
9
10
  userToken: s,
10
11
  onUserTokenExpiring: r,
11
12
  timeBeforeExpirationInMs: c,
12
13
  children: a,
13
- i18n: k
14
+ i18n: m
14
15
  }) => {
15
- const m = t.useMemo(() => ({
16
+ const k = t.useMemo(() => ({
16
17
  host: o,
17
18
  onUserTokenExpiring: r,
18
19
  timeBeforeExpirationInMs: c,
19
20
  logLevel: n
20
- }), [o, r, c, n]), d = K(e, i, s, m);
21
- return /* @__PURE__ */ t.createElement(u.Provider, { value: {
21
+ }), [o, r, c, n]), d = K(e, u, s, k);
22
+ return /* @__PURE__ */ t.createElement(i.Provider, { value: {
22
23
  knock: d
23
- } }, /* @__PURE__ */ t.createElement(v, { i18n: k }, a));
24
+ } }, /* @__PURE__ */ t.createElement(v, { i18n: m }, a));
24
25
  }, f = () => {
25
- const e = t.useContext(u);
26
+ const e = t.useContext(i);
26
27
  if (e === void 0)
27
28
  throw new Error("useKnock must be used within a KnockProvider");
28
29
  return e.knock;
29
30
  };
30
31
  export {
31
- P as KnockProvider,
32
+ p as KnockProvider,
32
33
  f as useKnockClient
33
34
  };
34
35
  //# sourceMappingURL=KnockProvider.mjs.map
@@ -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 ProviderStateContext = React.createContext<KnockProviderState | null>(\n null,\n);\n\nexport interface KnockProviderProps {\n // Knock client props\n apiKey: string;\n host?: string;\n // Authentication props\n userId: string;\n userToken?: string;\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n\n // i18n translations\n i18n?: I18nContent;\n\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 <ProviderStateContext.Provider\n value={{\n knock,\n }}\n >\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </ProviderStateContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(ProviderStateContext) as KnockProviderState;\n if (context === undefined) {\n throw new Error(\"useKnock must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["ProviderStateContext","React","createContext","KnockProvider","apiKey","host","logLevel","userId","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","authenticateOptions","useMemo","knock","useAuthenticatedKnockClient","KnockI18nProvider","useKnockClient","context","useContext","undefined","Error"],"mappings":";;;AAWA,MAAMA,IAAuBC,EAAMC,cACjC,IACF,GAkBaC,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,EAAAA,IAEF,CAACD,GAAMI,GAAqBC,GAA0BJ,CAAQ,CAChE,GAEMS,IAAQC,EACZZ,GACAG,GACAC,GACAK,CACF;AAEA,SACG,gBAAAZ,EAAA,cAAAD,EAAqB,UAArB,EACC,OAAO;AAAA,IACLe,OAAAA;AAAAA,EAAAA,EAGF,GAAA,gBAAAd,EAAA,cAACgB,GAAkB,EAAA,MAAAL,EAAA,GAAaD,CAAS,CAC3C;AAEJ,GAEaO,IAAiBA,MAAa;AACnCC,QAAAA,IAAUlB,EAAMmB,WAAWpB,CAAoB;AACrD,MAAImB,MAAYE;AACR,UAAA,IAAIC,MAAM,8CAA8C;AAEhE,SAAOH,EAAQJ;AACjB;"}
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 ProviderStateContext = React.createContext<KnockProviderState | null>(\n null,\n);\n\nexport interface KnockProviderProps {\n // Knock client props\n apiKey: string;\n host?: string;\n // Authentication props\n userId: string;\n userToken?: string;\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n\n // i18n translations\n i18n?: I18nContent;\n\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 <ProviderStateContext.Provider\n value={{\n knock,\n }}\n >\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </ProviderStateContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(ProviderStateContext) as KnockProviderState;\n if (context === undefined) {\n throw new Error(\"useKnock must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["ProviderStateContext","React","createContext","KnockProvider","apiKey","host","logLevel","userId","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","authenticateOptions","useMemo","knock","useAuthenticatedKnockClient","KnockI18nProvider","useKnockClient","context","useContext","undefined","Error"],"mappings":";;;;AAWA,MAAMA,IAAuBC,EAAMC,cACjC,IACF,GAkBaC,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,EAAAA,IAEF,CAACD,GAAMI,GAAqBC,GAA0BJ,CAAQ,CAChE,GAEMS,IAAQC,EACZZ,GACAG,GACAC,GACAK,CACF;AAEA,SACG,gBAAAZ,EAAA,cAAAD,EAAqB,UAArB,EACC,OAAO;AAAA,IACLe,OAAAA;AAAAA,EAAAA,EAGF,GAAA,gBAAAd,EAAA,cAACgB,GAAkB,EAAA,MAAAL,EAAA,GAAaD,CAAS,CAC3C;AAEJ,GAEaO,IAAiBA,MAAa;AACnCC,QAAAA,IAAUlB,EAAMmB,WAAWpB,CAAoB;AACrD,MAAImB,MAAYE;AACR,UAAA,IAAIC,MAAM,8CAA8C;AAEhE,SAAOH,EAAQJ;AACjB;"}
@@ -1,30 +1,29 @@
1
1
  import m from "@knocklabs/client";
2
- import f from "react";
3
- import s from "zustand/shallow";
4
- function l(u, r, n, e = {}) {
5
- u.authenticate(r, n, {
6
- onUserTokenExpiring: e == null ? void 0 : e.onUserTokenExpiring,
7
- timeBeforeExpirationInMs: e == null ? void 0 : e.timeBeforeExpirationInMs
2
+ import u from "react";
3
+ import "../context/KnockProvider.mjs";
4
+ import l from "./useStableOptions.mjs";
5
+ import "date-fns";
6
+ function f(i, n, r, t = {}) {
7
+ i.authenticate(n, r, {
8
+ onUserTokenExpiring: t == null ? void 0 : t.onUserTokenExpiring,
9
+ timeBeforeExpirationInMs: t == null ? void 0 : t.timeBeforeExpirationInMs
8
10
  });
9
11
  }
10
- function R(u, r, n, e = {}) {
11
- const o = f.useRef(), a = f.useRef(), c = f.useMemo(() => {
12
- const t = a.current || {};
13
- return s(e, t) ? t : (a.current = e, e);
14
- }, [e]);
15
- return f.useMemo(() => {
16
- const t = o.current;
17
- if (t && t.isAuthenticated() && (t.userId !== r || t.userToken !== n))
18
- return l(t, r, n, c), t;
19
- t && t.teardown();
20
- const i = new m(u, {
12
+ function E(i, n, r, t = {}) {
13
+ const a = u.useRef(), c = l(t);
14
+ return u.useMemo(() => {
15
+ const e = a.current;
16
+ if (e && e.isAuthenticated() && (e.userId !== n || e.userToken !== r))
17
+ return f(e, n, r, c), e;
18
+ e && e.teardown();
19
+ const o = new m(i, {
21
20
  host: c.host,
22
21
  logLevel: c.logLevel
23
22
  });
24
- return l(i, r, n, c), o.current = i, i;
25
- }, [u, r, n, c]);
23
+ return f(o, n, r, c), a.current = o, o;
24
+ }, [i, n, r, c]);
26
25
  }
27
26
  export {
28
- R as default
27
+ E as default
29
28
  };
30
29
  //# sourceMappingURL=useAuthenticatedKnockClient.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAuthenticatedKnockClient.mjs","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, { AuthenticateOptions, KnockOptions } from \"@knocklabs/client\";\nimport React from \"react\";\nimport shallow from \"zustand/shallow\";\n\nfunction authenticateWithOptions(\n knock: Knock,\n userId: string,\n userToken?: string,\n options: AuthenticateOptions = {},\n) {\n knock.authenticate(userId, userToken, {\n onUserTokenExpiring: options?.onUserTokenExpiring,\n timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,\n });\n}\n\nexport type AuthenticatedKnockClientOptions = KnockOptions &\n AuthenticateOptions;\n\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userId: string,\n userToken?: string,\n options: AuthenticatedKnockClientOptions = {},\n) {\n const knockRef = React.useRef<Knock | undefined>();\n const optionsRef = React.useRef<AuthenticatedKnockClientOptions>();\n\n // Shallow compare options so that we ensure that we have a stable\n // set of options between re-renders.\n const stableOptions = React.useMemo(() => {\n const currentOptions = optionsRef.current || {};\n\n if (shallow(options, currentOptions)) {\n return currentOptions;\n }\n\n optionsRef.current = options;\n return options;\n }, [options]);\n\n return React.useMemo(() => {\n const currentKnock = knockRef.current;\n\n // If the userId and the userToken changes then just reauth\n if (\n currentKnock &&\n currentKnock.isAuthenticated() &&\n (currentKnock.userId !== userId || currentKnock.userToken !== userToken)\n ) {\n authenticateWithOptions(currentKnock, userId, userToken, stableOptions);\n return currentKnock;\n }\n\n if (currentKnock) {\n currentKnock.teardown();\n }\n\n // Otherwise instantiate a new Knock client\n const knock = new Knock(apiKey, {\n host: stableOptions.host,\n logLevel: stableOptions.logLevel,\n });\n\n authenticateWithOptions(knock, userId, userToken, stableOptions);\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, userId, userToken, stableOptions]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userId","userToken","options","authenticate","onUserTokenExpiring","timeBeforeExpirationInMs","useAuthenticatedKnockClient","apiKey","knockRef","React","useRef","optionsRef","stableOptions","useMemo","currentOptions","current","shallow","currentKnock","isAuthenticated","teardown","Knock","host","logLevel"],"mappings":";;;AAIA,SAASA,EACPC,GACAC,GACAC,GACAC,IAA+B,CAAA,GAC/B;AACMC,EAAAA,EAAAA,aAAaH,GAAQC,GAAW;AAAA,IACpCG,qBAAqBF,KAAAA,gBAAAA,EAASE;AAAAA,IAC9BC,0BAA0BH,KAAAA,gBAAAA,EAASG;AAAAA,EAAAA,CACpC;AACH;AAKA,SAASC,EACPC,GACAP,GACAC,GACAC,IAA2C,CAAA,GAC3C;AACMM,QAAAA,IAAWC,EAAMC,UACjBC,IAAaF,EAAMC,UAInBE,IAAgBH,EAAMI,QAAQ,MAAM;AAClCC,UAAAA,IAAiBH,EAAWI,WAAW;AAEzCC,WAAAA,EAAQd,GAASY,CAAc,IAC1BA,KAGTH,EAAWI,UAAUb,GACdA;AAAAA,EAAAA,GACN,CAACA,CAAO,CAAC;AAELO,SAAAA,EAAMI,QAAQ,MAAM;AACzB,UAAMI,IAAeT,EAASO;AAI5BE,QAAAA,KACAA,EAAaC,gBAAgB,MAC5BD,EAAajB,WAAWA,KAAUiB,EAAahB,cAAcA;AAEtCgB,aAAAA,EAAAA,GAAcjB,GAAQC,GAAWW,CAAa,GAC/DK;AAGT,IAAIA,KACFA,EAAaE,SAAS;AAIlBpB,UAAAA,IAAQ,IAAIqB,EAAMb,GAAQ;AAAA,MAC9Bc,MAAMT,EAAcS;AAAAA,MACpBC,UAAUV,EAAcU;AAAAA,IAAAA,CACzB;AAEuBvB,WAAAA,EAAAA,GAAOC,GAAQC,GAAWW,CAAa,GAC/DJ,EAASO,UAAUhB,GAEZA;AAAAA,KACN,CAACQ,GAAQP,GAAQC,GAAWW,CAAa,CAAC;AAC/C;"}
1
+ {"version":3,"file":"useAuthenticatedKnockClient.mjs","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, { AuthenticateOptions, KnockOptions } from \"@knocklabs/client\";\nimport React from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction authenticateWithOptions(\n knock: Knock,\n userId: string,\n userToken?: string,\n options: AuthenticateOptions = {},\n) {\n knock.authenticate(userId, userToken, {\n onUserTokenExpiring: options?.onUserTokenExpiring,\n timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,\n });\n}\n\nexport type AuthenticatedKnockClientOptions = KnockOptions &\n AuthenticateOptions;\n\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userId: string,\n userToken?: string,\n options: AuthenticatedKnockClientOptions = {},\n) {\n const knockRef = React.useRef<Knock | undefined>();\n const stableOptions = useStableOptions(options);\n\n return React.useMemo(() => {\n const currentKnock = knockRef.current;\n\n // If the userId and the userToken changes then just reauth\n if (\n currentKnock &&\n currentKnock.isAuthenticated() &&\n (currentKnock.userId !== userId || currentKnock.userToken !== userToken)\n ) {\n authenticateWithOptions(currentKnock, userId, userToken, stableOptions);\n return currentKnock;\n }\n\n if (currentKnock) {\n currentKnock.teardown();\n }\n\n // Otherwise instantiate a new Knock client\n const knock = new Knock(apiKey, {\n host: stableOptions.host,\n logLevel: stableOptions.logLevel,\n });\n\n authenticateWithOptions(knock, userId, userToken, stableOptions);\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, userId, userToken, stableOptions]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userId","userToken","options","authenticate","onUserTokenExpiring","timeBeforeExpirationInMs","useAuthenticatedKnockClient","apiKey","knockRef","React","useRef","stableOptions","useStableOptions","useMemo","currentKnock","current","isAuthenticated","teardown","Knock","host","logLevel"],"mappings":";;;;;AAKA,SAASA,EACPC,GACAC,GACAC,GACAC,IAA+B,CAAA,GAC/B;AACMC,EAAAA,EAAAA,aAAaH,GAAQC,GAAW;AAAA,IACpCG,qBAAqBF,KAAAA,gBAAAA,EAASE;AAAAA,IAC9BC,0BAA0BH,KAAAA,gBAAAA,EAASG;AAAAA,EAAAA,CACpC;AACH;AAKA,SAASC,EACPC,GACAP,GACAC,GACAC,IAA2C,CAAA,GAC3C;AACMM,QAAAA,IAAWC,EAAMC,UACjBC,IAAgBC,EAAiBV,CAAO;AAEvCO,SAAAA,EAAMI,QAAQ,MAAM;AACzB,UAAMC,IAAeN,EAASO;AAI5BD,QAAAA,KACAA,EAAaE,gBAAgB,MAC5BF,EAAad,WAAWA,KAAUc,EAAab,cAAcA;AAEtCa,aAAAA,EAAAA,GAAcd,GAAQC,GAAWU,CAAa,GAC/DG;AAGT,IAAIA,KACFA,EAAaG,SAAS;AAIlBlB,UAAAA,IAAQ,IAAImB,EAAMX,GAAQ;AAAA,MAC9BY,MAAMR,EAAcQ;AAAAA,MACpBC,UAAUT,EAAcS;AAAAA,IAAAA,CACzB;AAEuBrB,WAAAA,EAAAA,GAAOC,GAAQC,GAAWU,CAAa,GAC/DH,EAASO,UAAUhB,GAEZA;AAAAA,KACN,CAACQ,GAAQP,GAAQC,GAAWU,CAAa,CAAC;AAC/C;"}
@@ -0,0 +1,13 @@
1
+ import { useRef as u, useMemo as n } from "react";
2
+ import o from "zustand/shallow";
3
+ function c(r) {
4
+ const t = u();
5
+ return n(() => {
6
+ const e = t.current;
7
+ return e && o(r, e) ? e : (t.current = r, r);
8
+ }, [r]);
9
+ }
10
+ export {
11
+ c as default
12
+ };
13
+ //# sourceMappingURL=useStableOptions.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useStableOptions.mjs","sources":["../../../../../src/modules/core/hooks/useStableOptions.ts"],"sourcesContent":["import { useMemo, useRef } from \"react\";\nimport shallow from \"zustand/shallow\";\n\nexport default function useStableOptions<T>(options: T): T {\n const optionsRef = useRef<T>();\n\n return useMemo(() => {\n const currentOptions = optionsRef.current;\n\n if (currentOptions && shallow(options, currentOptions)) {\n return currentOptions;\n }\n\n optionsRef.current = options;\n return options;\n }, [options]);\n}\n"],"names":["useStableOptions","options","optionsRef","useRef","useMemo","currentOptions","current","shallow"],"mappings":";;AAGA,SAAwBA,EAAoBC,GAAe;AACzD,QAAMC,IAAaC;AAEnB,SAAOC,EAAQ,MAAM;AACnB,UAAMC,IAAiBH,EAAWI;AAElC,WAAID,KAAkBE,EAAQN,GAASI,CAAc,IAC5CA,KAGTH,EAAWI,UAAUL,GACdA;AAAAA,EAAAA,GACN,CAACA,CAAO,CAAC;AACd;"}
@@ -1,25 +1,25 @@
1
- import * as o from "react";
2
- import u from "zustand";
3
- import { useKnockClient as d } from "../../core/context/KnockProvider.mjs";
1
+ import * as t from "react";
2
+ import { useKnockClient as u } from "../../core/context/KnockProvider.mjs";
4
3
  import "@knocklabs/client";
5
4
  import "zustand/shallow";
6
- import { feedProviderKey as a } from "../../core/utils.mjs";
7
- import k from "../hooks/useNotifications.mjs";
8
- const i = o.createContext(void 0), F = ({
5
+ import { feedProviderKey as d } from "../../core/utils.mjs";
6
+ import a from "../hooks/useNotifications.mjs";
7
+ import { useCreateNotificationStore as f } from "../hooks/useNotificationStore.mjs";
8
+ const i = t.createContext(void 0), F = ({
9
9
  feedId: e,
10
10
  children: c,
11
- defaultFeedOptions: n = {},
11
+ defaultFeedOptions: r = {},
12
12
  colorMode: s = "light"
13
13
  }) => {
14
- const t = d(), r = k(t, e, n), m = o.useMemo(() => u(r.store), [r]);
15
- return /* @__PURE__ */ o.createElement(i.Provider, { key: a(t.userId, e, n), value: {
16
- knock: t,
17
- feedClient: r,
14
+ const o = u(), n = a(o, e, r), m = f(n);
15
+ return /* @__PURE__ */ t.createElement(i.Provider, { key: d(o.userId, e, r), value: {
16
+ knock: o,
17
+ feedClient: n,
18
18
  useFeedStore: m,
19
19
  colorMode: s
20
20
  } }, c);
21
21
  }, l = () => {
22
- const e = o.useContext(i);
22
+ const e = t.useContext(i);
23
23
  if (!e)
24
24
  throw new Error("useKnockFeed must be used within a KnockFeedProvider");
25
25
  return e;
@@ -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 create, { UseBoundStore } from \"zustand\";\n\nimport { useKnockClient } from \"../../core\";\nimport { ColorMode } from \"../../core/constants\";\nimport { feedProviderKey } from \"../../core/utils\";\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 FeedStateContext = 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 const knock = useKnockClient();\n const feedClient = useNotifications(knock, feedId, defaultFeedOptions);\n\n const useFeedStore = React.useMemo(\n () => create<FeedStoreState>(feedClient.store),\n [feedClient],\n );\n\n return (\n <FeedStateContext.Provider\n key={feedProviderKey(knock.userId, feedId, defaultFeedOptions)}\n value={{\n knock,\n feedClient,\n useFeedStore,\n colorMode,\n }}\n >\n {children}\n </FeedStateContext.Provider>\n );\n};\n\nexport const useKnockFeed = (): KnockFeedProviderState => {\n const context = React.useContext(FeedStateContext);\n\n if (!context) {\n throw new Error(\"useKnockFeed must be used within a KnockFeedProvider\");\n }\n\n return context;\n};\n"],"names":["FeedStateContext","React","createContext","undefined","KnockFeedProvider","feedId","children","defaultFeedOptions","colorMode","knock","useKnockClient","feedClient","useNotifications","useFeedStore","useMemo","create","store","feedProviderKey","userId","useKnockFeed","context","useContext","Error"],"mappings":";;;;;;;AAqBA,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;AAC1E,QAAMC,IAAQC,KACRC,IAAaC,EAAiBH,GAAOJ,GAAQE,CAAkB,GAE/DM,IAAeZ,EAAMa,QACzB,MAAMC,EAAuBJ,EAAWK,KAAK,GAC7C,CAACL,CAAU,CACb;AAGE,SAAA,gBAAAV,EAAA,cAACD,EAAiB,UAAjB,EACC,KAAKiB,EAAgBR,EAAMS,QAAQb,GAAQE,CAAkB,GAC7D,OAAO;AAAA,IACLE,OAAAA;AAAAA,IACAE,YAAAA;AAAAA,IACAE,cAAAA;AAAAA,IACAL,WAAAA;AAAAA,EAAAA,KAGDF,CACH;AAEJ,GAEaa,IAAeA,MAA8B;AAClDC,QAAAA,IAAUnB,EAAMoB,WAAWrB,CAAgB;AAEjD,MAAI,CAACoB;AACG,UAAA,IAAIE,MAAM,sDAAsD;AAGjEF,SAAAA;AACT;"}
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 FeedStateContext = 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 const knock = useKnockClient();\n const feedClient = useNotifications(knock, feedId, defaultFeedOptions);\n const useFeedStore = useCreateNotificationStore(feedClient);\n\n return (\n <FeedStateContext.Provider\n key={feedProviderKey(knock.userId, feedId, defaultFeedOptions)}\n value={{\n knock,\n feedClient,\n useFeedStore,\n colorMode,\n }}\n >\n {children}\n </FeedStateContext.Provider>\n );\n};\n\nexport const useKnockFeed = (): KnockFeedProviderState => {\n const context = React.useContext(FeedStateContext);\n\n if (!context) {\n throw new Error(\"useKnockFeed must be used within a KnockFeedProvider\");\n }\n\n return context;\n};\n"],"names":["FeedStateContext","React","createContext","undefined","KnockFeedProvider","feedId","children","defaultFeedOptions","colorMode","knock","useKnockClient","feedClient","useNotifications","useFeedStore","useCreateNotificationStore","feedProviderKey","userId","useKnockFeed","context","useContext","Error"],"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;AAC1E,QAAMC,IAAQC,KACRC,IAAaC,EAAiBH,GAAOJ,GAAQE,CAAkB,GAC/DM,IAAeC,EAA2BH,CAAU;AAGxD,SAAA,gBAAAV,EAAA,cAACD,EAAiB,UAAjB,EACC,KAAKe,EAAgBN,EAAMO,QAAQX,GAAQE,CAAkB,GAC7D,OAAO;AAAA,IACLE,OAAAA;AAAAA,IACAE,YAAAA;AAAAA,IACAE,cAAAA;AAAAA,IACAL,WAAAA;AAAAA,EAAAA,KAGDF,CACH;AAEJ,GAEaW,IAAeA,MAA8B;AAClDC,QAAAA,IAAUjB,EAAMkB,WAAWnB,CAAgB;AAEjD,MAAI,CAACkB;AACG,UAAA,IAAIE,MAAM,sDAAsD;AAGjEF,SAAAA;AACT;"}
@@ -0,0 +1,18 @@
1
+ import * as o from "react";
2
+ import c from "zustand";
3
+ const n = typeof window < "u" ? o.useLayoutEffect : o.useEffect;
4
+ function a(t) {
5
+ const r = o.useMemo(() => c(t.store), [t]), [, s] = o.useReducer((e) => e + 1, 0);
6
+ return n(() => {
7
+ const e = s, u = t.store.subscribe(e);
8
+ return e(), u;
9
+ }, [t]), r;
10
+ }
11
+ function i(t, r) {
12
+ return a(t)(r || t.store.getState);
13
+ }
14
+ export {
15
+ i as default,
16
+ a as useCreateNotificationStore
17
+ };
18
+ //# sourceMappingURL=useNotificationStore.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNotificationStore.mjs","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"sourcesContent":["import { Feed, FeedStoreState } from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport type { DispatchWithoutAction } from \"react\";\nimport create, { StateSelector } from \"zustand\";\n\nconst useIsomorphicLayoutEffect =\n typeof window !== \"undefined\" ? React.useLayoutEffect : React.useEffect;\n\n// A hook designed to create a `UseBoundStore` instance\nfunction useCreateNotificationStore(feedClient: Feed) {\n const useStore = React.useMemo(\n () => create<FeedStoreState>(feedClient.store),\n [feedClient],\n );\n\n // Warning: this is a hack that will cause any components downstream to re-render\n // as a result of the store updating.\n const [, forceUpdate] = React.useReducer((c) => c + 1, 0) as [\n never,\n () => void,\n ];\n\n useIsomorphicLayoutEffect(() => {\n const rerender = forceUpdate as DispatchWithoutAction;\n const unsubscribe = feedClient.store.subscribe(rerender);\n\n rerender();\n\n return unsubscribe;\n }, [feedClient]);\n\n return useStore;\n}\n\n// A hook used to access content *within* the notification store\nfunction useNotificationStore(\n feedClient: Feed,\n selector?: StateSelector<FeedStoreState, FeedStoreState>,\n) {\n const useStore = useCreateNotificationStore(feedClient);\n return useStore<FeedStoreState>(selector || feedClient.store.getState);\n}\n\nexport { useCreateNotificationStore };\nexport default useNotificationStore;\n"],"names":["useIsomorphicLayoutEffect","window","React","useLayoutEffect","useEffect","useCreateNotificationStore","feedClient","useStore","useMemo","create","store","forceUpdate","useReducer","c","rerender","unsubscribe","subscribe","useNotificationStore","selector","getState"],"mappings":";;AAKA,MAAMA,IACJ,OAAOC,SAAW,MAAcC,EAAMC,kBAAkBD,EAAME;AAGhE,SAASC,EAA2BC,GAAkB;AAC9CC,QAAAA,IAAWL,EAAMM,QACrB,MAAMC,EAAuBH,EAAWI,KAAK,GAC7C,CAACJ,CAAU,CACb,GAIM,CAAGK,EAAAA,CAAW,IAAIT,EAAMU,WAAYC,CAAAA,MAAMA,IAAI,GAAG,CAAC;AAKxDb,SAAAA,EAA0B,MAAM;AAC9B,UAAMc,IAAWH,GACXI,IAAcT,EAAWI,MAAMM,UAAUF,CAAQ;AAE9C,WAAAA,KAEFC;AAAAA,EAAAA,GACN,CAACT,CAAU,CAAC,GAERC;AACT;AAGA,SAASU,EACPX,GACAY,GACA;AAEA,SADiBb,EAA2BC,CAAU,EACtBY,KAAYZ,EAAWI,MAAMS,QAAQ;AACvE;"}
@@ -1,12 +1,13 @@
1
- import { useRef as n, useMemo as a } from "react";
2
- function f(t, u, e = {}) {
3
- const r = n();
4
- return a(() => (r.current && r.current.dispose(), r.current = t.feeds.initialize(u, e), r.current.listenForUpdates(), r.current.store.subscribe((c) => {
5
- var s;
6
- return (s = r == null ? void 0 : r.current) == null ? void 0 : s.store.setState(c);
7
- }), r.current), [t, u, e.source, e.tenant, e.has_tenant, e.archived]);
1
+ import { useRef as s, useMemo as n } from "react";
2
+ import "../../core/context/KnockProvider.mjs";
3
+ import "@knocklabs/client";
4
+ import u from "../../core/hooks/useStableOptions.mjs";
5
+ import "date-fns";
6
+ function l(e, r, o = {}) {
7
+ const t = s(), i = u(o);
8
+ return n(() => (t.current && t.current.dispose(), t.current = e.feeds.initialize(r, i), t.current.listenForUpdates(), t.current), [e, r, i]);
8
9
  }
9
10
  export {
10
- f as default
11
+ l as default
11
12
  };
12
13
  //# sourceMappingURL=useNotifications.mjs.map
@@ -1 +1 @@
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\nfunction useNotifications(\n knock: Knock,\n feedChannelId: string,\n options: FeedClientOptions = {},\n) {\n const feedClientRef = useRef<Feed | null>();\n\n return useMemo(() => {\n if (feedClientRef.current) {\n feedClientRef.current.dispose();\n }\n\n feedClientRef.current = knock.feeds.initialize(feedChannelId, options);\n feedClientRef.current.listenForUpdates();\n feedClientRef.current.store.subscribe((t) =>\n feedClientRef?.current?.store.setState(t),\n );\n\n return feedClientRef.current;\n }, [\n knock,\n feedChannelId,\n options.source,\n options.tenant,\n options.has_tenant,\n options.archived,\n ]);\n}\n\nexport default useNotifications;\n"],"names":["useNotifications","knock","feedChannelId","options","feedClientRef","useRef","useMemo","current","dispose","feeds","initialize","listenForUpdates","store","subscribe","t","setState","source","tenant","has_tenant","archived"],"mappings":";AAGA,SAASA,EACPC,GACAC,GACAC,IAA6B,CAAA,GAC7B;AACA,QAAMC,IAAgBC;AAEtB,SAAOC,EAAQ,OACTF,EAAcG,WAChBH,EAAcG,QAAQC,WAGxBJ,EAAcG,UAAUN,EAAMQ,MAAMC,WAAWR,GAAeC,CAAO,GACrEC,EAAcG,QAAQI,oBACRJ,EAAAA,QAAQK,MAAMC,UAAWC,CAAAA,MAAAA;;AACrCV,YAAAA,IAAAA,KAAAA,gBAAAA,EAAeG,YAAfH,gBAAAA,EAAwBQ,MAAMG,SAASD;AAAAA,GACzC,GAEOV,EAAcG,UACpB,CACDN,GACAC,GACAC,EAAQa,QACRb,EAAQc,QACRd,EAAQe,YACRf,EAAQgB,QAAQ,CACjB;AACH;"}
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 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","listenForUpdates"],"mappings":";;;;;AAKA,SAASA,EACPC,GACAC,GACAC,IAA6B,CAAA,GAC7B;AACA,QAAMC,IAAgBC,KAChBC,IAAgBC,EAAiBJ,CAAO;AAE9C,SAAOK,EAAQ,OACTJ,EAAcK,WAChBL,EAAcK,QAAQC,WAGxBN,EAAcK,UAAUR,EAAMU,MAAMC,WAClCV,GACAI,CACF,GAEAF,EAAcK,QAAQI,oBAEfT,EAAcK,UACpB,CAACR,GAAOC,GAAeI,CAAa,CAAC;AAC1C;"}
@@ -1,2 +1,3 @@
1
1
  export { default as useAuthenticatedKnockClient } from "./useAuthenticatedKnockClient";
2
+ export { default as useStableOptions } from "./useStableOptions";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,2BAA2B,EAAE,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AACvF,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useAuthenticatedKnockClient.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAgB7E,MAAM,MAAM,+BAA+B,GAAG,YAAY,GACxD,mBAAmB,CAAC;AAEtB,iBAAS,2BAA2B,CAClC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,GAAE,+BAAoC,SA8C9C;AAED,eAAe,2BAA2B,CAAC"}
1
+ {"version":3,"file":"useAuthenticatedKnockClient.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAiB7E,MAAM,MAAM,+BAA+B,GAAG,YAAY,GACxD,mBAAmB,CAAC;AAEtB,iBAAS,2BAA2B,CAClC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,GAAE,+BAAoC,SAiC9C;AAED,eAAe,2BAA2B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export default function useStableOptions<T>(options: T): T;
2
+ //# sourceMappingURL=useStableOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useStableOptions.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/hooks/useStableOptions.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,CAazD"}
@@ -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,OAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAIjD,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,CAuB1C,CAAC;AAEF,eAAO,MAAM,YAAY,QAAO,sBAQ/B,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,CAmB1C,CAAC;AAEF,eAAO,MAAM,YAAY,QAAO,sBAQ/B,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export { default as useNotifications } from "./useNotifications";
2
2
  export { default as useFeedSettings } from "./useFeedSettings";
3
+ export { default as useNotificationStore, useCreateNotificationStore, } from "./useNotificationStore";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EACL,OAAO,IAAI,oBAAoB,EAC/B,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Feed, FeedStoreState } from "@knocklabs/client";
2
+ import { StateSelector } from "zustand";
3
+ declare function useCreateNotificationStore(feedClient: Feed): import("zustand").UseBoundStore<FeedStoreState, import("zustand").StoreApi<FeedStoreState>>;
4
+ declare function useNotificationStore(feedClient: Feed, selector?: StateSelector<FeedStoreState, FeedStoreState>): FeedStoreState;
5
+ export { useCreateNotificationStore };
6
+ export default useNotificationStore;
7
+ //# sourceMappingURL=useNotificationStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNotificationStore.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGzD,OAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAMhD,iBAAS,0BAA0B,CAAC,UAAU,EAAE,IAAI,+FAuBnD;AAGD,iBAAS,oBAAoB,CAC3B,UAAU,EAAE,IAAI,EAChB,QAAQ,CAAC,EAAE,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC,kBAIzD;AAED,OAAO,EAAE,0BAA0B,EAAE,CAAC;AACtC,eAAe,oBAAoB,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;AAGnE,iBAAS,gBAAgB,CACvB,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,iBAAsB,QAwBhC;AAED,eAAe,gBAAgB,CAAC"}
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,QAmBhC;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.2.17",
5
+ "version": "0.2.18",
6
6
  "license": "MIT",
7
7
  "main": "dist/cjs/index.js",
8
8
  "module": "dist/esm/index.mjs",
@@ -48,7 +48,7 @@
48
48
  "react": "^16.11.0 || ^17.0.0 || ^18.0.0"
49
49
  },
50
50
  "dependencies": {
51
- "@knocklabs/client": "^0.10.7",
51
+ "@knocklabs/client": "^0.10.8",
52
52
  "date-fns": "^3.3.1",
53
53
  "swr": "^2.2.5",
54
54
  "zustand": "^3.7.2"
@@ -1 +1,2 @@
1
1
  export { default as useAuthenticatedKnockClient } from "./useAuthenticatedKnockClient";
2
+ export { default as useStableOptions } from "./useStableOptions";
@@ -1,6 +1,7 @@
1
1
  import Knock, { AuthenticateOptions, KnockOptions } from "@knocklabs/client";
2
2
  import React from "react";
3
- import shallow from "zustand/shallow";
3
+
4
+ import { useStableOptions } from "../../core";
4
5
 
5
6
  function authenticateWithOptions(
6
7
  knock: Knock,
@@ -24,20 +25,7 @@ function useAuthenticatedKnockClient(
24
25
  options: AuthenticatedKnockClientOptions = {},
25
26
  ) {
26
27
  const knockRef = React.useRef<Knock | undefined>();
27
- const optionsRef = React.useRef<AuthenticatedKnockClientOptions>();
28
-
29
- // Shallow compare options so that we ensure that we have a stable
30
- // set of options between re-renders.
31
- const stableOptions = React.useMemo(() => {
32
- const currentOptions = optionsRef.current || {};
33
-
34
- if (shallow(options, currentOptions)) {
35
- return currentOptions;
36
- }
37
-
38
- optionsRef.current = options;
39
- return options;
40
- }, [options]);
28
+ const stableOptions = useStableOptions(options);
41
29
 
42
30
  return React.useMemo(() => {
43
31
  const currentKnock = knockRef.current;
@@ -0,0 +1,17 @@
1
+ import { useMemo, useRef } from "react";
2
+ import shallow from "zustand/shallow";
3
+
4
+ export default function useStableOptions<T>(options: T): T {
5
+ const optionsRef = useRef<T>();
6
+
7
+ return useMemo(() => {
8
+ const currentOptions = optionsRef.current;
9
+
10
+ if (currentOptions && shallow(options, currentOptions)) {
11
+ return currentOptions;
12
+ }
13
+
14
+ optionsRef.current = options;
15
+ return options;
16
+ }, [options]);
17
+ }
@@ -5,11 +5,12 @@ import Knock, {
5
5
  } from "@knocklabs/client";
6
6
  import * as React from "react";
7
7
  import { PropsWithChildren } from "react";
8
- import create, { UseBoundStore } from "zustand";
8
+ import { UseBoundStore } from "zustand";
9
9
 
10
10
  import { useKnockClient } from "../../core";
11
11
  import { ColorMode } from "../../core/constants";
12
12
  import { feedProviderKey } from "../../core/utils";
13
+ import { useCreateNotificationStore } from "../hooks";
13
14
  import useNotifications from "../hooks/useNotifications";
14
15
 
15
16
  export interface KnockFeedProviderState {
@@ -39,11 +40,7 @@ export const KnockFeedProvider: React.FC<
39
40
  > = ({ feedId, children, defaultFeedOptions = {}, colorMode = "light" }) => {
40
41
  const knock = useKnockClient();
41
42
  const feedClient = useNotifications(knock, feedId, defaultFeedOptions);
42
-
43
- const useFeedStore = React.useMemo(
44
- () => create<FeedStoreState>(feedClient.store),
45
- [feedClient],
46
- );
43
+ const useFeedStore = useCreateNotificationStore(feedClient);
47
44
 
48
45
  return (
49
46
  <FeedStateContext.Provider
@@ -1,2 +1,6 @@
1
1
  export { default as useNotifications } from "./useNotifications";
2
2
  export { default as useFeedSettings } from "./useFeedSettings";
3
+ export {
4
+ default as useNotificationStore,
5
+ useCreateNotificationStore,
6
+ } from "./useNotificationStore";
@@ -0,0 +1,45 @@
1
+ import { Feed, FeedStoreState } from "@knocklabs/client";
2
+ import * as React from "react";
3
+ import type { DispatchWithoutAction } from "react";
4
+ import create, { StateSelector } from "zustand";
5
+
6
+ const useIsomorphicLayoutEffect =
7
+ typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
8
+
9
+ // A hook designed to create a `UseBoundStore` instance
10
+ function useCreateNotificationStore(feedClient: Feed) {
11
+ const useStore = React.useMemo(
12
+ () => create<FeedStoreState>(feedClient.store),
13
+ [feedClient],
14
+ );
15
+
16
+ // Warning: this is a hack that will cause any components downstream to re-render
17
+ // as a result of the store updating.
18
+ const [, forceUpdate] = React.useReducer((c) => c + 1, 0) as [
19
+ never,
20
+ () => void,
21
+ ];
22
+
23
+ useIsomorphicLayoutEffect(() => {
24
+ const rerender = forceUpdate as DispatchWithoutAction;
25
+ const unsubscribe = feedClient.store.subscribe(rerender);
26
+
27
+ rerender();
28
+
29
+ return unsubscribe;
30
+ }, [feedClient]);
31
+
32
+ return useStore;
33
+ }
34
+
35
+ // A hook used to access content *within* the notification store
36
+ function useNotificationStore(
37
+ feedClient: Feed,
38
+ selector?: StateSelector<FeedStoreState, FeedStoreState>,
39
+ ) {
40
+ const useStore = useCreateNotificationStore(feedClient);
41
+ return useStore<FeedStoreState>(selector || feedClient.store.getState);
42
+ }
43
+
44
+ export { useCreateNotificationStore };
45
+ export default useNotificationStore;
@@ -1,33 +1,30 @@
1
1
  import Knock, { Feed, FeedClientOptions } from "@knocklabs/client";
2
- import { useMemo, useRef } from "react";
2
+ import { useMemo, useRef } from "react";
3
+
4
+ import { useStableOptions } from "../../core";
3
5
 
4
6
  function useNotifications(
5
7
  knock: Knock,
6
8
  feedChannelId: string,
7
9
  options: FeedClientOptions = {},
8
10
  ) {
9
- const feedClientRef = useRef<Feed | null>();
11
+ const feedClientRef = useRef<Feed>();
12
+ const stableOptions = useStableOptions(options);
10
13
 
11
14
  return useMemo(() => {
12
15
  if (feedClientRef.current) {
13
16
  feedClientRef.current.dispose();
14
17
  }
15
18
 
16
- feedClientRef.current = knock.feeds.initialize(feedChannelId, options);
17
- feedClientRef.current.listenForUpdates();
18
- feedClientRef.current.store.subscribe((t) =>
19
- feedClientRef?.current?.store.setState(t),
19
+ feedClientRef.current = knock.feeds.initialize(
20
+ feedChannelId,
21
+ stableOptions,
20
22
  );
21
23
 
24
+ feedClientRef.current.listenForUpdates();
25
+
22
26
  return feedClientRef.current;
23
- }, [
24
- knock,
25
- feedChannelId,
26
- options.source,
27
- options.tenant,
28
- options.has_tenant,
29
- options.archived,
30
- ]);
27
+ }, [knock, feedChannelId, stableOptions]);
31
28
  }
32
29
 
33
30
  export default useNotifications;