@knocklabs/react-core 0.2.16 → 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.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/modules/core/context/KnockProvider.js +1 -1
- package/dist/cjs/modules/core/context/KnockProvider.js.map +1 -1
- package/dist/cjs/modules/core/hooks/useAuthenticatedKnockClient.js +1 -1
- package/dist/cjs/modules/core/hooks/useAuthenticatedKnockClient.js.map +1 -1
- package/dist/cjs/modules/core/hooks/useStableOptions.js +2 -0
- package/dist/cjs/modules/core/hooks/useStableOptions.js.map +1 -0
- package/dist/cjs/modules/core/utils.js +1 -1
- package/dist/cjs/modules/core/utils.js.map +1 -1
- package/dist/cjs/modules/feed/context/KnockFeedProvider.js +1 -1
- package/dist/cjs/modules/feed/context/KnockFeedProvider.js.map +1 -1
- package/dist/cjs/modules/feed/hooks/useNotificationStore.js +2 -0
- package/dist/cjs/modules/feed/hooks/useNotificationStore.js.map +1 -0
- package/dist/cjs/modules/feed/hooks/useNotifications.js +1 -1
- package/dist/cjs/modules/feed/hooks/useNotifications.js.map +1 -1
- package/dist/esm/index.mjs +43 -38
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/modules/core/context/KnockProvider.mjs +10 -9
- package/dist/esm/modules/core/context/KnockProvider.mjs.map +1 -1
- package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.mjs +15 -16
- package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.mjs.map +1 -1
- package/dist/esm/modules/core/hooks/useStableOptions.mjs +13 -0
- package/dist/esm/modules/core/hooks/useStableOptions.mjs.map +1 -0
- package/dist/esm/modules/core/utils.mjs +11 -11
- package/dist/esm/modules/core/utils.mjs.map +1 -1
- package/dist/esm/modules/feed/context/KnockFeedProvider.mjs +15 -15
- package/dist/esm/modules/feed/context/KnockFeedProvider.mjs.map +1 -1
- package/dist/esm/modules/feed/hooks/useNotificationStore.mjs +18 -0
- package/dist/esm/modules/feed/hooks/useNotificationStore.mjs.map +1 -0
- package/dist/esm/modules/feed/hooks/useNotifications.mjs +9 -8
- package/dist/esm/modules/feed/hooks/useNotifications.mjs.map +1 -1
- package/dist/types/modules/core/hooks/index.d.ts +1 -0
- package/dist/types/modules/core/hooks/index.d.ts.map +1 -1
- package/dist/types/modules/core/hooks/useAuthenticatedKnockClient.d.ts.map +1 -1
- package/dist/types/modules/core/hooks/useStableOptions.d.ts +2 -0
- package/dist/types/modules/core/hooks/useStableOptions.d.ts.map +1 -0
- package/dist/types/modules/core/utils.d.ts +1 -1
- package/dist/types/modules/core/utils.d.ts.map +1 -1
- package/dist/types/modules/feed/context/KnockFeedProvider.d.ts.map +1 -1
- package/dist/types/modules/feed/hooks/index.d.ts +1 -0
- package/dist/types/modules/feed/hooks/index.d.ts.map +1 -1
- package/dist/types/modules/feed/hooks/useNotificationStore.d.ts +7 -0
- package/dist/types/modules/feed/hooks/useNotificationStore.d.ts.map +1 -0
- package/dist/types/modules/feed/hooks/useNotifications.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/modules/core/hooks/index.ts +1 -0
- package/src/modules/core/hooks/useAuthenticatedKnockClient.ts +3 -9
- package/src/modules/core/hooks/useStableOptions.ts +17 -0
- package/src/modules/core/utils.ts +4 -2
- package/src/modules/feed/context/KnockFeedProvider.tsx +11 -8
- package/src/modules/feed/hooks/index.ts +4 -0
- package/src/modules/feed/hooks/useNotificationStore.ts +45 -0
- package/src/modules/feed/hooks/useNotifications.ts +11 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
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
|
+
|
|
11
|
+
## 0.2.17
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- f25b112: fix: ensure feed store reference re-renders after changes to user
|
|
16
|
+
- Updated dependencies [f25b112]
|
|
17
|
+
- @knocklabs/client@0.10.7
|
|
18
|
+
|
|
3
19
|
## 0.2.16
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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":"
|
|
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
|
|
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
|
|
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 o=require("date-fns");function c(e){return e>9?"9+":e}function i(e,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("date-fns");function c(e){return e>9?"9+":e}function i(e,t={}){try{const r=o.parseISO(e);return o.intlFormatDistance(r,new Date,{locale:t.locale})}catch{return e}}function d(e){return e.charAt(0).toUpperCase()+e.slice(1)}function l(e,t){return e!==void 0?e:t}function u(e,t,r={}){return[e,t,r.source,r.tenant,r.has_tenant,r.archived].filter(n=>n!=null).join("-")}function f({knockSlackChannelId:e,tenant:t,connectionStatus:r,errorLabel:n}){return[e,t,r,n].filter(a=>a!=null).join("-")}exports.feedProviderKey=u;exports.formatBadgeCount=c;exports.formatTimestamp=i;exports.renderNodeOrFallback=l;exports.slackProviderKey=f;exports.toSentenceCase=d;
|
|
2
2
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["import { FeedClientOptions } from \"@knocklabs/client\";\nimport { intlFormatDistance, parseISO } from \"date-fns\";\nimport { ReactNode } from \"react\";\n\nexport function formatBadgeCount(count: number): string | number {\n return count > 9 ? \"9+\" : count;\n}\n\ntype FormatTimestampOptions = {\n locale?: string | string[];\n};\n\nexport function formatTimestamp(\n ts: string,\n options: FormatTimestampOptions = {},\n) {\n try {\n const parsedTs = parseISO(ts);\n const formatted = intlFormatDistance(parsedTs, new Date(), {\n locale: options.locale,\n });\n\n return formatted;\n } catch (e) {\n return ts;\n }\n}\n\nexport function toSentenceCase(string: string): string {\n return string.charAt(0).toUpperCase() + string.slice(1);\n}\n\nexport function renderNodeOrFallback(node: ReactNode, fallback: ReactNode) {\n return node !== undefined ? node : fallback;\n}\n\n/*\n Used to build a consistent key for the KnockFeedProvider so that React knows when\n to trigger a re-render of the context when a key property changes.\n*/\nexport function feedProviderKey(\n
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["import { FeedClientOptions } from \"@knocklabs/client\";\nimport { intlFormatDistance, parseISO } from \"date-fns\";\nimport { ReactNode } from \"react\";\n\nexport function formatBadgeCount(count: number): string | number {\n return count > 9 ? \"9+\" : count;\n}\n\ntype FormatTimestampOptions = {\n locale?: string | string[];\n};\n\nexport function formatTimestamp(\n ts: string,\n options: FormatTimestampOptions = {},\n) {\n try {\n const parsedTs = parseISO(ts);\n const formatted = intlFormatDistance(parsedTs, new Date(), {\n locale: options.locale,\n });\n\n return formatted;\n } catch (e) {\n return ts;\n }\n}\n\nexport function toSentenceCase(string: string): string {\n return string.charAt(0).toUpperCase() + string.slice(1);\n}\n\nexport function renderNodeOrFallback(node: ReactNode, fallback: ReactNode) {\n return node !== undefined ? node : fallback;\n}\n\n/*\n Used to build a consistent key for the KnockFeedProvider so that React knows when\n to trigger a re-render of the context when a key property changes.\n*/\nexport function feedProviderKey(\n userId: string | undefined,\n feedId: string,\n options: FeedClientOptions = {},\n) {\n return [\n userId,\n feedId,\n options.source,\n options.tenant,\n options.has_tenant,\n options.archived,\n ]\n .filter((f) => f !== null && f !== undefined)\n .join(\"-\");\n}\n\n/*\n Used to build a consistent key for the KnockSlackProvider so that React knows when\n to trigger a re-render of the context when a key property changes.\n*/\nexport function slackProviderKey({\n knockSlackChannelId,\n tenant,\n connectionStatus,\n errorLabel,\n}: {\n knockSlackChannelId: string;\n tenant: string;\n connectionStatus: string;\n errorLabel: string | null;\n}) {\n return [knockSlackChannelId, tenant, connectionStatus, errorLabel]\n .filter((f) => f !== null && f !== undefined)\n .join(\"-\");\n}\n"],"names":["formatBadgeCount","count","formatTimestamp","ts","options","parsedTs","parseISO","formatted","intlFormatDistance","Date","locale","toSentenceCase","string","charAt","toUpperCase","slice","renderNodeOrFallback","node","fallback","undefined","feedProviderKey","userId","feedId","source","tenant","has_tenant","archived","filter","f","join","slackProviderKey","knockSlackChannelId","connectionStatus","errorLabel"],"mappings":"4GAIO,SAASA,EAAiBC,EAAgC,CACxDA,OAAAA,EAAQ,EAAI,KAAOA,CAC5B,CAMO,SAASC,EACdC,EACAC,EAAkC,GAClC,CACI,GAAA,CACIC,MAAAA,EAAWC,WAASH,CAAE,EAKrBI,OAJWC,EAAAA,mBAAmBH,EAAU,IAAII,KAAQ,CACzDC,OAAQN,EAAQM,MAAAA,CACjB,OAGS,CACHP,OAAAA,CACT,CACF,CAEO,SAASQ,EAAeC,EAAwB,CAC9CA,OAAAA,EAAOC,OAAO,CAAC,EAAEC,cAAgBF,EAAOG,MAAM,CAAC,CACxD,CAEgBC,SAAAA,EAAqBC,EAAiBC,EAAqB,CAClED,OAAAA,IAASE,OAAYF,EAAOC,CACrC,CAMO,SAASE,EACdC,EACAC,EACAlB,EAA6B,CAAA,EAC7B,CACO,MAAA,CACLiB,EACAC,EACAlB,EAAQmB,OACRnB,EAAQoB,OACRpB,EAAQqB,WACRrB,EAAQsB,QAAQ,EAEfC,UAAcC,GAAM,IAAuB,EAC3CC,KAAK,GAAG,CACb,CAMO,SAASC,EAAiB,CAC/BC,oBAAAA,EACAP,OAAAA,EACAQ,iBAAAA,EACAC,WAAAA,CAMF,EAAG,CACD,MAAO,CAACF,EAAqBP,EAAQQ,EAAkBC,CAAU,EAC9DN,OAAcC,GAAAA,GAAM,IAAuB,EAC3CC,KAAK,GAAG,CACb"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),d=require("
|
|
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
|
|
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
|
|
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
|
|
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"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,42 +1,47 @@
|
|
|
1
|
-
import { KnockProvider as
|
|
2
|
-
import { default as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { default as P } from "./modules/feed/hooks/
|
|
8
|
-
import {
|
|
9
|
-
import { default as
|
|
10
|
-
import {
|
|
11
|
-
import { default as
|
|
12
|
-
import { default as
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -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
|
-
|
|
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:
|
|
9
|
+
userId: u,
|
|
9
10
|
userToken: s,
|
|
10
11
|
onUserTokenExpiring: r,
|
|
11
12
|
timeBeforeExpirationInMs: c,
|
|
12
13
|
children: a,
|
|
13
|
-
i18n:
|
|
14
|
+
i18n: m
|
|
14
15
|
}) => {
|
|
15
|
-
const
|
|
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,
|
|
21
|
-
return /* @__PURE__ */ t.createElement(
|
|
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:
|
|
24
|
+
} }, /* @__PURE__ */ t.createElement(v, { i18n: m }, a));
|
|
24
25
|
}, f = () => {
|
|
25
|
-
const e = t.useContext(
|
|
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
|
-
|
|
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":"
|
|
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
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
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, {
|
|
6
8
|
onUserTokenExpiring: t == null ? void 0 : t.onUserTokenExpiring,
|
|
7
9
|
timeBeforeExpirationInMs: t == null ? void 0 : t.timeBeforeExpirationInMs
|
|
8
10
|
});
|
|
9
11
|
}
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}, [t]);
|
|
15
|
-
return o.useMemo(() => {
|
|
16
|
-
const e = f.current;
|
|
12
|
+
function E(i, n, r, t = {}) {
|
|
13
|
+
const a = u.useRef(), c = l(t);
|
|
14
|
+
return u.useMemo(() => {
|
|
15
|
+
const e = a.current;
|
|
17
16
|
if (e && e.isAuthenticated() && (e.userId !== n || e.userToken !== r))
|
|
18
|
-
return
|
|
17
|
+
return f(e, n, r, c), e;
|
|
19
18
|
e && e.teardown();
|
|
20
|
-
const
|
|
19
|
+
const o = new m(i, {
|
|
21
20
|
host: c.host,
|
|
22
21
|
logLevel: c.logLevel
|
|
23
22
|
});
|
|
24
|
-
return
|
|
25
|
-
}, [
|
|
23
|
+
return f(o, n, r, c), a.current = o, o;
|
|
24
|
+
}, [i, n, r, c]);
|
|
26
25
|
}
|
|
27
26
|
export {
|
|
28
|
-
|
|
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
|
|
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;"}
|
|
@@ -2,11 +2,11 @@ import { parseISO as o, intlFormatDistance as c } from "date-fns";
|
|
|
2
2
|
function u(e) {
|
|
3
3
|
return e > 9 ? "9+" : e;
|
|
4
4
|
}
|
|
5
|
-
function l(e,
|
|
5
|
+
function l(e, t = {}) {
|
|
6
6
|
try {
|
|
7
|
-
const
|
|
8
|
-
return c(
|
|
9
|
-
locale:
|
|
7
|
+
const r = o(e);
|
|
8
|
+
return c(r, /* @__PURE__ */ new Date(), {
|
|
9
|
+
locale: t.locale
|
|
10
10
|
});
|
|
11
11
|
} catch {
|
|
12
12
|
return e;
|
|
@@ -15,19 +15,19 @@ function l(e, r = {}) {
|
|
|
15
15
|
function d(e) {
|
|
16
16
|
return e.charAt(0).toUpperCase() + e.slice(1);
|
|
17
17
|
}
|
|
18
|
-
function f(e,
|
|
19
|
-
return e !== void 0 ? e :
|
|
18
|
+
function f(e, t) {
|
|
19
|
+
return e !== void 0 ? e : t;
|
|
20
20
|
}
|
|
21
|
-
function m(e, r = {}) {
|
|
22
|
-
return [e, r.source, r.tenant, r.has_tenant, r.archived].filter((
|
|
21
|
+
function m(e, t, r = {}) {
|
|
22
|
+
return [e, t, r.source, r.tenant, r.has_tenant, r.archived].filter((n) => n != null).join("-");
|
|
23
23
|
}
|
|
24
24
|
function s({
|
|
25
25
|
knockSlackChannelId: e,
|
|
26
|
-
tenant:
|
|
27
|
-
connectionStatus:
|
|
26
|
+
tenant: t,
|
|
27
|
+
connectionStatus: r,
|
|
28
28
|
errorLabel: n
|
|
29
29
|
}) {
|
|
30
|
-
return [e,
|
|
30
|
+
return [e, t, r, n].filter((a) => a != null).join("-");
|
|
31
31
|
}
|
|
32
32
|
export {
|
|
33
33
|
m as feedProviderKey,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["import { FeedClientOptions } from \"@knocklabs/client\";\nimport { intlFormatDistance, parseISO } from \"date-fns\";\nimport { ReactNode } from \"react\";\n\nexport function formatBadgeCount(count: number): string | number {\n return count > 9 ? \"9+\" : count;\n}\n\ntype FormatTimestampOptions = {\n locale?: string | string[];\n};\n\nexport function formatTimestamp(\n ts: string,\n options: FormatTimestampOptions = {},\n) {\n try {\n const parsedTs = parseISO(ts);\n const formatted = intlFormatDistance(parsedTs, new Date(), {\n locale: options.locale,\n });\n\n return formatted;\n } catch (e) {\n return ts;\n }\n}\n\nexport function toSentenceCase(string: string): string {\n return string.charAt(0).toUpperCase() + string.slice(1);\n}\n\nexport function renderNodeOrFallback(node: ReactNode, fallback: ReactNode) {\n return node !== undefined ? node : fallback;\n}\n\n/*\n Used to build a consistent key for the KnockFeedProvider so that React knows when\n to trigger a re-render of the context when a key property changes.\n*/\nexport function feedProviderKey(\n
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["import { FeedClientOptions } from \"@knocklabs/client\";\nimport { intlFormatDistance, parseISO } from \"date-fns\";\nimport { ReactNode } from \"react\";\n\nexport function formatBadgeCount(count: number): string | number {\n return count > 9 ? \"9+\" : count;\n}\n\ntype FormatTimestampOptions = {\n locale?: string | string[];\n};\n\nexport function formatTimestamp(\n ts: string,\n options: FormatTimestampOptions = {},\n) {\n try {\n const parsedTs = parseISO(ts);\n const formatted = intlFormatDistance(parsedTs, new Date(), {\n locale: options.locale,\n });\n\n return formatted;\n } catch (e) {\n return ts;\n }\n}\n\nexport function toSentenceCase(string: string): string {\n return string.charAt(0).toUpperCase() + string.slice(1);\n}\n\nexport function renderNodeOrFallback(node: ReactNode, fallback: ReactNode) {\n return node !== undefined ? node : fallback;\n}\n\n/*\n Used to build a consistent key for the KnockFeedProvider so that React knows when\n to trigger a re-render of the context when a key property changes.\n*/\nexport function feedProviderKey(\n userId: string | undefined,\n feedId: string,\n options: FeedClientOptions = {},\n) {\n return [\n userId,\n feedId,\n options.source,\n options.tenant,\n options.has_tenant,\n options.archived,\n ]\n .filter((f) => f !== null && f !== undefined)\n .join(\"-\");\n}\n\n/*\n Used to build a consistent key for the KnockSlackProvider so that React knows when\n to trigger a re-render of the context when a key property changes.\n*/\nexport function slackProviderKey({\n knockSlackChannelId,\n tenant,\n connectionStatus,\n errorLabel,\n}: {\n knockSlackChannelId: string;\n tenant: string;\n connectionStatus: string;\n errorLabel: string | null;\n}) {\n return [knockSlackChannelId, tenant, connectionStatus, errorLabel]\n .filter((f) => f !== null && f !== undefined)\n .join(\"-\");\n}\n"],"names":["formatBadgeCount","count","formatTimestamp","ts","options","parsedTs","parseISO","formatted","intlFormatDistance","Date","locale","toSentenceCase","string","charAt","toUpperCase","slice","renderNodeOrFallback","node","fallback","undefined","feedProviderKey","userId","feedId","source","tenant","has_tenant","archived","filter","f","join","slackProviderKey","knockSlackChannelId","connectionStatus","errorLabel"],"mappings":";AAIO,SAASA,EAAiBC,GAAgC;AACxDA,SAAAA,IAAQ,IAAI,OAAOA;AAC5B;AAMO,SAASC,EACdC,GACAC,IAAkC,IAClC;AACI,MAAA;AACIC,UAAAA,IAAWC,EAASH,CAAE;AAKrBI,WAJWC,EAAmBH,GAAU,oBAAII,QAAQ;AAAA,MACzDC,QAAQN,EAAQM;AAAAA,IAAAA,CACjB;AAAA,UAGS;AACHP,WAAAA;AAAAA,EACT;AACF;AAEO,SAASQ,EAAeC,GAAwB;AAC9CA,SAAAA,EAAOC,OAAO,CAAC,EAAEC,gBAAgBF,EAAOG,MAAM,CAAC;AACxD;AAEgBC,SAAAA,EAAqBC,GAAiBC,GAAqB;AAClED,SAAAA,MAASE,SAAYF,IAAOC;AACrC;AAMO,SAASE,EACdC,GACAC,GACAlB,IAA6B,CAAA,GAC7B;AACO,SAAA,CACLiB,GACAC,GACAlB,EAAQmB,QACRnB,EAAQoB,QACRpB,EAAQqB,YACRrB,EAAQsB,QAAQ,EAEfC,OAAQC,OAAMA,KAAM,IAAuB,EAC3CC,KAAK,GAAG;AACb;AAMO,SAASC,EAAiB;AAAA,EAC/BC,qBAAAA;AAAAA,EACAP,QAAAA;AAAAA,EACAQ,kBAAAA;AAAAA,EACAC,YAAAA;AAMF,GAAG;AACD,SAAO,CAACF,GAAqBP,GAAQQ,GAAkBC,CAAU,EAC9DN,OAAQC,CAAMA,MAAAA,KAAM,IAAuB,EAC3CC,KAAK,GAAG;AACb;"}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import u from "
|
|
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
|
|
7
|
-
import
|
|
8
|
-
|
|
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:
|
|
11
|
+
defaultFeedOptions: r = {},
|
|
12
12
|
colorMode: s = "light"
|
|
13
13
|
}) => {
|
|
14
|
-
const
|
|
15
|
-
return /* @__PURE__ */
|
|
16
|
-
knock:
|
|
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
17
|
feedClient: n,
|
|
18
18
|
useFeedStore: m,
|
|
19
19
|
colorMode: s
|
|
20
20
|
} }, c);
|
|
21
|
-
},
|
|
22
|
-
const e =
|
|
23
|
-
if (e
|
|
21
|
+
}, l = () => {
|
|
22
|
+
const e = t.useContext(i);
|
|
23
|
+
if (!e)
|
|
24
24
|
throw new Error("useKnockFeed must be used within a KnockFeedProvider");
|
|
25
25
|
return e;
|
|
26
26
|
};
|
|
27
27
|
export {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
F as KnockFeedProvider,
|
|
29
|
+
l as useKnockFeed
|
|
30
30
|
};
|
|
31
31
|
//# sourceMappingURL=KnockFeedProvider.mjs.map
|
|
@@ -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
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
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
|
|
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 +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;
|
|
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 @@
|
|
|
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"}
|
|
@@ -7,7 +7,7 @@ type FormatTimestampOptions = {
|
|
|
7
7
|
export declare function formatTimestamp(ts: string, options?: FormatTimestampOptions): string;
|
|
8
8
|
export declare function toSentenceCase(string: string): string;
|
|
9
9
|
export declare function renderNodeOrFallback(node: ReactNode, fallback: ReactNode): ReactNode;
|
|
10
|
-
export declare function feedProviderKey(
|
|
10
|
+
export declare function feedProviderKey(userId: string | undefined, feedId: string, options?: FeedClientOptions): string;
|
|
11
11
|
export declare function slackProviderKey({ knockSlackChannelId, tenant, connectionStatus, errorLabel, }: {
|
|
12
12
|
knockSlackChannelId: string;
|
|
13
13
|
tenant: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/modules/core/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAE/D;AAED,KAAK,sBAAsB,GAAG;IAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF,wBAAgB,eAAe,CAC7B,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,sBAA2B,UAYrC;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,aAExE;AAMD,wBAAgB,eAAe,CAC7B,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/modules/core/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAE/D;AAED,KAAK,sBAAsB,GAAG;IAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF,wBAAgB,eAAe,CAC7B,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,sBAA2B,UAYrC;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,aAExE;AAMD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,iBAAsB,UAYhC;AAMD,wBAAgB,gBAAgB,CAAC,EAC/B,mBAAmB,EACnB,MAAM,EACN,gBAAgB,EAChB,UAAU,GACX,EAAE;IACD,mBAAmB,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,UAIA"}
|
|
@@ -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,
|
|
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;
|
|
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.
|
|
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.
|
|
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,6 +1,7 @@
|
|
|
1
1
|
import Knock, { AuthenticateOptions, KnockOptions } from "@knocklabs/client";
|
|
2
2
|
import React from "react";
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
import { useStableOptions } from "../../core";
|
|
4
5
|
|
|
5
6
|
function authenticateWithOptions(
|
|
6
7
|
knock: Knock,
|
|
@@ -24,14 +25,7 @@ function useAuthenticatedKnockClient(
|
|
|
24
25
|
options: AuthenticatedKnockClientOptions = {},
|
|
25
26
|
) {
|
|
26
27
|
const knockRef = React.useRef<Knock | undefined>();
|
|
27
|
-
const
|
|
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
|
-
return shallow(options, currentOptions) ? currentOptions : options;
|
|
34
|
-
}, [options]);
|
|
28
|
+
const stableOptions = useStableOptions(options);
|
|
35
29
|
|
|
36
30
|
return React.useMemo(() => {
|
|
37
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
|
+
}
|
|
@@ -39,11 +39,13 @@ export function renderNodeOrFallback(node: ReactNode, fallback: ReactNode) {
|
|
|
39
39
|
to trigger a re-render of the context when a key property changes.
|
|
40
40
|
*/
|
|
41
41
|
export function feedProviderKey(
|
|
42
|
-
|
|
42
|
+
userId: string | undefined,
|
|
43
|
+
feedId: string,
|
|
43
44
|
options: FeedClientOptions = {},
|
|
44
45
|
) {
|
|
45
46
|
return [
|
|
46
|
-
|
|
47
|
+
userId,
|
|
48
|
+
feedId,
|
|
47
49
|
options.source,
|
|
48
50
|
options.tenant,
|
|
49
51
|
options.has_tenant,
|
|
@@ -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
|
|
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 {
|
|
@@ -19,9 +20,9 @@ export interface KnockFeedProviderState {
|
|
|
19
20
|
colorMode: ColorMode;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
const FeedStateContext = React.createContext<
|
|
23
|
-
|
|
24
|
-
);
|
|
23
|
+
const FeedStateContext = React.createContext<
|
|
24
|
+
KnockFeedProviderState | undefined
|
|
25
|
+
>(undefined);
|
|
25
26
|
|
|
26
27
|
export interface KnockFeedProviderProps {
|
|
27
28
|
// Feed props
|
|
@@ -39,11 +40,11 @@ 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
|
-
const useFeedStore =
|
|
43
|
+
const useFeedStore = useCreateNotificationStore(feedClient);
|
|
43
44
|
|
|
44
45
|
return (
|
|
45
46
|
<FeedStateContext.Provider
|
|
46
|
-
key={feedProviderKey(feedId, defaultFeedOptions)}
|
|
47
|
+
key={feedProviderKey(knock.userId, feedId, defaultFeedOptions)}
|
|
47
48
|
value={{
|
|
48
49
|
knock,
|
|
49
50
|
feedClient,
|
|
@@ -58,8 +59,10 @@ export const KnockFeedProvider: React.FC<
|
|
|
58
59
|
|
|
59
60
|
export const useKnockFeed = (): KnockFeedProviderState => {
|
|
60
61
|
const context = React.useContext(FeedStateContext);
|
|
61
|
-
|
|
62
|
+
|
|
63
|
+
if (!context) {
|
|
62
64
|
throw new Error("useKnockFeed must be used within a KnockFeedProvider");
|
|
63
65
|
}
|
|
64
|
-
|
|
66
|
+
|
|
67
|
+
return context;
|
|
65
68
|
};
|
|
@@ -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
|
|
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
|
|
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(
|
|
17
|
-
|
|
18
|
-
|
|
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;
|