@knocklabs/react-core 0.1.2 → 0.1.4

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 (51) hide show
  1. package/dist/cjs/modules/core/constants.js.map +1 -1
  2. package/dist/cjs/modules/core/context/KnockProvider.js +1 -1
  3. package/dist/cjs/modules/core/context/KnockProvider.js.map +1 -1
  4. package/dist/cjs/modules/core/hooks/useAuthenticatedKnockClient.js +1 -1
  5. package/dist/cjs/modules/core/hooks/useAuthenticatedKnockClient.js.map +1 -1
  6. package/dist/cjs/modules/core/utils.js +1 -1
  7. package/dist/cjs/modules/core/utils.js.map +1 -1
  8. package/dist/cjs/modules/feed/context/KnockFeedProvider.js +1 -1
  9. package/dist/cjs/modules/feed/context/KnockFeedProvider.js.map +1 -1
  10. package/dist/cjs/modules/feed/hooks/useFeedSettings.js.map +1 -1
  11. package/dist/cjs/modules/feed/hooks/useNotifications.js +1 -1
  12. package/dist/cjs/modules/feed/hooks/useNotifications.js.map +1 -1
  13. package/dist/cjs/modules/i18n/context/KnockI18nProvider.js.map +1 -1
  14. package/dist/cjs/modules/i18n/hooks/useTranslations.js +1 -1
  15. package/dist/cjs/modules/i18n/hooks/useTranslations.js.map +1 -1
  16. package/dist/cjs/modules/i18n/languages/de.js.map +1 -1
  17. package/dist/cjs/modules/i18n/languages/en.js.map +1 -1
  18. package/dist/cjs/modules/i18n/languages/index.js.map +1 -1
  19. package/dist/esm/modules/core/constants.js.map +1 -1
  20. package/dist/esm/modules/core/context/KnockProvider.js +45 -24
  21. package/dist/esm/modules/core/context/KnockProvider.js.map +1 -1
  22. package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.js +19 -10
  23. package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.js.map +1 -1
  24. package/dist/esm/modules/core/utils.js +14 -10
  25. package/dist/esm/modules/core/utils.js.map +1 -1
  26. package/dist/esm/modules/feed/context/KnockFeedProvider.js +20 -11
  27. package/dist/esm/modules/feed/context/KnockFeedProvider.js.map +1 -1
  28. package/dist/esm/modules/feed/hooks/useFeedSettings.js +1 -4
  29. package/dist/esm/modules/feed/hooks/useFeedSettings.js.map +1 -1
  30. package/dist/esm/modules/feed/hooks/useNotifications.js +15 -8
  31. package/dist/esm/modules/feed/hooks/useNotifications.js.map +1 -1
  32. package/dist/esm/modules/i18n/context/KnockI18nProvider.js.map +1 -1
  33. package/dist/esm/modules/i18n/hooks/useTranslations.js +7 -12
  34. package/dist/esm/modules/i18n/hooks/useTranslations.js.map +1 -1
  35. package/dist/esm/modules/i18n/languages/de.js.map +1 -1
  36. package/dist/esm/modules/i18n/languages/en.js.map +1 -1
  37. package/dist/esm/modules/i18n/languages/index.js +1 -4
  38. package/dist/esm/modules/i18n/languages/index.js.map +1 -1
  39. package/dist/types/modules/core/context/KnockProvider.d.ts +4 -1
  40. package/dist/types/modules/core/context/KnockProvider.d.ts.map +1 -1
  41. package/dist/types/modules/core/hooks/useAuthenticatedKnockClient.d.ts +2 -2
  42. package/dist/types/modules/core/hooks/useAuthenticatedKnockClient.d.ts.map +1 -1
  43. package/dist/types/modules/core/utils.d.ts +1 -2
  44. package/dist/types/modules/core/utils.d.ts.map +1 -1
  45. package/dist/types/modules/feed/context/KnockFeedProvider.d.ts +3 -3
  46. package/dist/types/modules/feed/context/KnockFeedProvider.d.ts.map +1 -1
  47. package/dist/types/modules/feed/hooks/useNotifications.d.ts +1 -1
  48. package/dist/types/modules/feed/hooks/useNotifications.d.ts.map +1 -1
  49. package/dist/types/modules/i18n/hooks/useTranslations.d.ts +0 -2
  50. package/dist/types/modules/i18n/hooks/useTranslations.d.ts.map +1 -1
  51. package/package.json +18 -10
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../../../../src/modules/core/constants.ts"],"sourcesContent":["export enum FilterStatus {\n All = \"all\",\n Read = \"read\",\n Unseen = \"unseen\",\n Unread = \"unread\",\n}\n\nexport type ColorMode = \"light\" | \"dark\";\n"],"names":["FilterStatus","All","Read","Unseen","Unread"],"mappings":"gFAAYA,IAAAA,GAAAA,IACVC,EAAAA,IAAM,MACNC,EAAAA,KAAO,OACPC,EAAAA,OAAS,SACTC,EAAAA,OAAS,SAJCJ,IAAAA,GAAAA,CAAAA,CAAAA"}
1
+ {"version":3,"file":"constants.js","sources":["../../../../src/modules/core/constants.ts"],"sourcesContent":["export enum FilterStatus {\n All = \"all\",\n Read = \"read\",\n Unseen = \"unseen\",\n Unread = \"unread\",\n}\n\nexport type ColorMode = \"light\" | \"dark\";\n"],"names":["FilterStatus"],"mappings":"gFAAY,IAAAA,GAAAA,IACVA,EAAA,IAAM,MACNA,EAAA,KAAO,OACPA,EAAA,OAAS,SACTA,EAAA,OAAS,SAJCA,IAAAA,GAAA,CAAA,CAAA"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),d=require("react"),l=require("../hooks/useAuthenticatedKnockClient.js"),k=require("../../i18n/context/KnockI18nProvider.js");require("date-fns/locale");function f(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 c=f(d),i=c.createContext(null),v=({apiKey:e,host:n,userId:t,userToken:r,children:u,i18n:s})=>{const a=l(e,t,r,{host:n});return o.jsx(i.Provider,{value:{knock:a},children:o.jsx(k.KnockI18nProvider,{i18n:s,children:u})})},b=()=>{const e=c.useContext(i);if(e===void 0)throw new Error("useKnock must be used within a KnockProvider");return e.knock};exports.KnockProvider=v;exports.useKnockClient=b;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),b=require("react"),v=require("../../i18n/context/KnockI18nProvider.js"),P=require("../hooks/useAuthenticatedKnockClient.js");function j(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 o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const r=j(b),s=r.createContext(null),K=({apiKey:e,host:n,logLevel:t,userId:o,userToken:a,onUserTokenExpiring:c,timeBeforeExpirationInMs:u,children:d,i18n:l})=>{const k=r.useMemo(()=>({host:n,onUserTokenExpiring:c,timeBeforeExpirationInMs:u,logLevel:t}),[n,c,u,t]),f=P(e,o,a,k);return i.jsx(s.Provider,{value:{knock:f},children:i.jsx(v.KnockI18nProvider,{i18n:l,children:d})})},m=()=>{const e=r.useContext(s);if(e===void 0)throw new Error("useKnock must be used within a KnockProvider");return e.knock};exports.KnockProvider=K;exports.useKnockClient=m;
2
2
  //# sourceMappingURL=KnockProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"KnockProvider.js","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport Knock from \"@knocklabs/client\";\n\nimport { useAuthenticatedKnockClient } from \"../hooks\";\nimport { KnockI18nProvider, I18nContent } from \"../../i18n\";\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\n // Extra options\n children?: React.ReactElement;\n\n // i18n translations\n i18n?: I18nContent;\n}\n\nexport const KnockProvider: React.FC<KnockProviderProps> = ({\n apiKey,\n host,\n userId,\n userToken,\n children,\n i18n,\n}) => {\n const knock = useAuthenticatedKnockClient(apiKey, userId, userToken, {\n host,\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","userId","userToken","children","i18n","knock","useAuthenticatedKnockClient","jsx","KnockI18nProvider","useKnockClient","context","useContext","undefined","Error"],"mappings":"wlBAUMA,EAAuBC,EAAMC,cACjC,IACF,EAiBaC,EAA8CA,CAAC,CAC1DC,OAAAA,EACAC,KAAAA,EACAC,OAAAA,EACAC,UAAAA,EACAC,SAAAA,EACAC,KAAAA,CACF,IAAM,CACJ,MAAMC,EAAQC,EAA4BP,EAAQE,EAAQC,EAAW,CACnEF,KAAAA,CAAAA,CACD,EAED,OACGO,MAAAZ,EAAqB,SAArB,CACC,MAAO,CACLU,MAAAA,CAAAA,EAGF,SAAAE,EAAAA,IAACC,EAAkB,kBAAA,CAAA,KAAAJ,EAAaD,SAAAA,EAAS,CAC3C,CAAA,CAEJ,EAEaM,EAAiBA,IAAa,CACnCC,MAAAA,EAAUd,EAAMe,WAAWhB,CAAoB,EACrD,GAAIe,IAAYE,OACR,MAAA,IAAIC,MAAM,8CAA8C,EAEhE,OAAOH,EAAQL,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\";\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 // Extra options\n children?: React.ReactElement;\n\n // i18n translations\n i18n?: I18nContent;\n\n logLevel?: LogLevel;\n}\n\nexport const KnockProvider: React.FC<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 // TODO: we probably need to put this optimization into the `useAuthenticatedKnockClient`\n // hook itself to fix this\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","KnockProvider","apiKey","host","logLevel","userId","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","authenticateOptions","knock","useAuthenticatedKnockClient","jsx","KnockI18nProvider","useKnockClient","context"],"mappings":"6jBAUMA,EAAuBC,EAAM,cACjC,IACF,EAqBaC,EAA8C,CAAC,CAC1D,OAAAC,EACA,KAAAC,EACA,SAAAC,EACA,OAAAC,EACA,UAAAC,EACA,oBAAAC,EACA,yBAAAC,EACA,SAAAC,EACA,KAAAC,CACF,IAAM,CAIJ,MAAMC,EAAsBX,EAAM,QAChC,KAAO,CACL,KAAAG,EACA,oBAAAI,EACA,yBAAAC,EACA,SAAAJ,CAAA,GAEF,CAACD,EAAMI,EAAqBC,EAA0BJ,CAAQ,CAAA,EAG1DQ,EAAQC,EACZX,EACAG,EACAC,EACAK,CAAA,EAIA,OAAAG,EAAA,IAACf,EAAqB,SAArB,CACC,MAAO,CACL,MAAAa,CACF,EAEA,SAAAE,EAAAA,IAACC,EAAAA,kBAAkB,CAAA,KAAAL,EAAa,SAAAD,CAAS,CAAA,CAAA,CAAA,CAG/C,EAEaO,EAAiB,IAAa,CACnC,MAAAC,EAAUjB,EAAM,WAAWD,CAAoB,EACrD,GAAIkB,IAAY,OACR,MAAA,IAAI,MAAM,8CAA8C,EAEhE,OAAOA,EAAQ,KACjB"}
@@ -1,2 +1,2 @@
1
- "use strict";const u=require("react"),f=require("@knocklabs/client"),r=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},s=r(u),i=r(f);function l(t,c,o,a={}){const e=s.default.useRef();return u.useMemo(()=>{e.current&&e.current.teardown();const n=new i.default(t,a);return n.authenticate(c,o),e.current=n,n},[t,c,o])}module.exports=l;
1
+ "use strict";const l=require("@knocklabs/client"),i=require("react"),k=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},d=k(l),o=k(i);function f(t,c,r,e={}){t.authenticate(c,r,{onUserTokenExpiring:e==null?void 0:e.onUserTokenExpiring,timeBeforeExpirationInMs:e==null?void 0:e.timeBeforeExpirationInMs})}function h(t,c,r,e={}){const a=o.default.useRef();return i.useMemo(()=>{const n=a.current;if(n&&n.isAuthenticated()&&(n.userId!==c||n.userToken!==r))return f(n,c,r,e),n;n&&n.teardown();const u=new d.default(t,e);return f(u,c,r,e),a.current=u,u},[t,c,r,e])}module.exports=h;
2
2
  //# sourceMappingURL=useAuthenticatedKnockClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAuthenticatedKnockClient.js","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport Knock, { KnockOptions } from \"@knocklabs/client\";\n\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userId: string,\n userToken: string | undefined,\n options: KnockOptions = {},\n) {\n const knockRef = React.useRef<Knock | null>();\n\n return useMemo(() => {\n if (knockRef.current) knockRef.current.teardown();\n\n const knock = new Knock(apiKey, options);\n knock.authenticate(userId, userToken);\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, userId, userToken]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["useAuthenticatedKnockClient","apiKey","userId","userToken","options","knockRef","React","useRef","useMemo","current","teardown","knock","Knock","authenticate"],"mappings":"2IAGA,SAASA,EACPC,EACAC,EACAC,EACAC,EAAwB,CAAA,EACxB,CACMC,MAAAA,EAAWC,UAAMC,SAEvB,OAAOC,UAAQ,IAAM,CACfH,EAASI,SAASJ,EAASI,QAAQC,WAEvC,MAAMC,EAAQ,IAAIC,EAAAA,QAAMX,EAAQG,CAAO,EACjCS,OAAAA,EAAAA,aAAaX,EAAQC,CAAS,EACpCE,EAASI,QAAUE,EAEZA,CACN,EAAA,CAACV,EAAQC,EAAQC,CAAS,CAAC,CAChC"}
1
+ {"version":3,"file":"useAuthenticatedKnockClient.js","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, { AuthenticateOptions, KnockOptions } from \"@knocklabs/client\";\nimport React, { useMemo } from \"react\";\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\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userId: string,\n userToken?: string,\n options: KnockOptions & AuthenticateOptions = {},\n) {\n const knockRef = React.useRef<Knock | null>();\n\n return 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, options);\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, options);\n authenticateWithOptions(knock, userId, userToken, options);\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, userId, userToken, options]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userId","userToken","options","useAuthenticatedKnockClient","apiKey","knockRef","React","useMemo","currentKnock","Knock"],"mappings":"2IAGA,SAASA,EACPC,EACAC,EACAC,EACAC,EAA+B,CAAA,EAC/B,CACMH,EAAA,aAAaC,EAAQC,EAAW,CACpC,oBAAqBC,GAAA,YAAAA,EAAS,oBAC9B,yBAA0BA,GAAA,YAAAA,EAAS,wBAAA,CACpC,CACH,CAEA,SAASC,EACPC,EACAJ,EACAC,EACAC,EAA8C,CAAA,EAC9C,CACM,MAAAG,EAAWC,UAAM,SAEvB,OAAOC,UAAQ,IAAM,CACnB,MAAMC,EAAeH,EAAS,QAI5B,GAAAG,GACAA,EAAa,gBAAgB,IAC5BA,EAAa,SAAWR,GAAUQ,EAAa,YAAcP,GAEtC,OAAAH,EAAAU,EAAcR,EAAQC,EAAWC,CAAO,EACzDM,EAGLA,GACFA,EAAa,SAAS,EAIxB,MAAMT,EAAQ,IAAIU,EAAAA,QAAML,EAAQF,CAAO,EACf,OAAAJ,EAAAC,EAAOC,EAAQC,EAAWC,CAAO,EACzDG,EAAS,QAAUN,EAEZA,GACN,CAACK,EAAQJ,EAAQC,EAAWC,CAAO,CAAC,CACzC"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("date-fns/formatDistance"),o=require("date-fns/parseISO"),a=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},c=a(n),u=a(o);function f(e){return e>9?"9+":e}function d(e,t={}){try{const r=u.default(e);return c.default(r,new Date,{addSuffix:!0,locale:t.locale})}catch{return e}}function l(e){return e.charAt(0).toUpperCase()+e.slice(1)}function i(e,t){return e!==void 0?e:t}function s(e,t={}){return[e,t.source,t.tenant,t.has_tenant,t.archived].filter(r=>r!=null).join("-")}exports.feedProviderKey=s;exports.formatBadgeCount=f;exports.formatTimestamp=d;exports.renderNodeOrFallback=i;exports.toSentenceCase=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("date-fns");function n(e){return e>9?"9+":e}function o(e,t={}){try{const r=a.parseISO(e);return a.intlFormatDistance(r,new Date,{locale:t.locale})}catch{return e}}function c(e){return e.charAt(0).toUpperCase()+e.slice(1)}function d(e,t){return e!==void 0?e:t}function u(e,t={}){return[e,t.source,t.tenant,t.has_tenant,t.archived].filter(r=>r!=null).join("-")}exports.feedProviderKey=u;exports.formatBadgeCount=n;exports.formatTimestamp=o;exports.renderNodeOrFallback=d;exports.toSentenceCase=c;
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 { parseISO, formatDistance, Locale } 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?: Locale;\n};\n\nexport function formatTimestamp(\n ts: string,\n options: FormatTimestampOptions = {},\n) {\n try {\n const parsedTs = parseISO(ts);\n const formatted = formatDistance(parsedTs, new Date(), {\n addSuffix: true,\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 userFeedId: string,\n options: FeedClientOptions = {},\n) {\n return [\n userFeedId,\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"],"names":["formatBadgeCount","count","formatTimestamp","ts","options","parsedTs","parseISO","formatted","formatDistance","Date","addSuffix","locale","toSentenceCase","string","charAt","toUpperCase","slice","renderNodeOrFallback","node","fallback","undefined","feedProviderKey","userFeedId","source","tenant","has_tenant","archived","filter","f","join"],"mappings":"gOAIO,SAASA,EAAiBC,EAAgC,CACxDA,OAAAA,EAAQ,EAAI,KAAOA,CAC5B,CAMO,SAASC,EACdC,EACAC,EAAkC,GAClC,CACI,GAAA,CACIC,MAAAA,EAAWC,UAASH,CAAE,EAMrBI,OALWC,EAAAA,QAAeH,EAAU,IAAII,KAAQ,CACrDC,UAAW,GACXC,OAAQP,EAAQO,MAAAA,CACjB,OAGS,CACHR,OAAAA,CACT,CACF,CAEO,SAASS,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,EACAlB,EAA6B,GAC7B,CACA,MAAO,CACLkB,EACAlB,EAAQmB,OACRnB,EAAQoB,OACRpB,EAAQqB,WACRrB,EAAQsB,QAAQ,EAEfC,UAAcC,GAAM,IAAuB,EAC3CC,KAAK,GAAG,CACb"}
1
+ {"version":3,"file":"utils.js","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["import { FeedClientOptions } from \"@knocklabs/client\";\nimport { parseISO, intlFormatDistance } 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 userFeedId: string,\n options: FeedClientOptions = {},\n) {\n return [\n userFeedId,\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"],"names":["formatBadgeCount","count","formatTimestamp","ts","options","parsedTs","parseISO","intlFormatDistance","toSentenceCase","string","renderNodeOrFallback","node","fallback","feedProviderKey","userFeedId","f"],"mappings":"4GAIO,SAASA,EAAiBC,EAAgC,CACxD,OAAAA,EAAQ,EAAI,KAAOA,CAC5B,CAMO,SAASC,EACdC,EACAC,EAAkC,GAClC,CACI,GAAA,CACI,MAAAC,EAAWC,WAASH,CAAE,EAKrB,OAJWI,EAAA,mBAAmBF,EAAU,IAAI,KAAQ,CACzD,OAAQD,EAAQ,MAAA,CACjB,OAGS,CACH,OAAAD,CACT,CACF,CAEO,SAASK,EAAeC,EAAwB,CAC9C,OAAAA,EAAO,OAAO,CAAC,EAAE,cAAgBA,EAAO,MAAM,CAAC,CACxD,CAEgB,SAAAC,EAAqBC,EAAiBC,EAAqB,CAClE,OAAAD,IAAS,OAAYA,EAAOC,CACrC,CAMO,SAASC,EACdC,EACAV,EAA6B,GAC7B,CACO,MAAA,CACLU,EACAV,EAAQ,OACRA,EAAQ,OACRA,EAAQ,WACRA,EAAQ,QACV,EACG,OAAQW,GAAMA,GAAM,IAAuB,EAC3C,KAAK,GAAG,CACb"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),d=require("react"),l=require("zustand"),f=require("../hooks/useNotifications.js"),b=require("../../core/utils.js"),k=require("../../core/context/KnockProvider.js");require("@knocklabs/client");const p=e=>e&&typeof e=="object"&&"default"in e?e:{default:e};function v(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 u=v(d),j=p(l),i=u.createContext(null),m=({feedId:e,children:o,defaultFeedOptions:t={},colorMode:r="light"})=>{const n=k.useKnockClient(),c=f(n,e,t),s=j.default(c.store);return a.jsx(i.Provider,{value:{knock:n,feedClient:c,useFeedStore:s,colorMode:r},children:o},b.feedProviderKey(e,t))},K=()=>{const e=u.useContext(i);if(e===void 0)throw new Error("useKnockFeed must be used within a KnockFeedProvider");return e};exports.KnockFeedProvider=m;exports.useKnockFeed=K;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),d=require("react"),l=require("zustand"),f=require("../../core/context/KnockProvider.js");require("@knocklabs/client");const b=require("../../core/utils.js"),k=require("../hooks/useNotifications.js"),p=e=>e&&typeof e=="object"&&"default"in e?e:{default:e};function v(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 u=v(d),j=p(l),i=u.createContext(null),m=({feedId:e,children:o,defaultFeedOptions:t={},colorMode:r="light"})=>{const n=f.useKnockClient(),c=k(n,e,t),s=j.default(c.store);return a.jsx(i.Provider,{value:{knock:n,feedClient:c,useFeedStore:s,colorMode:r},children:o},b.feedProviderKey(e,t))},K=()=>{const e=u.useContext(i);if(e===void 0)throw new Error("useKnockFeed must be used within a KnockFeedProvider");return e};exports.KnockFeedProvider=m;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 * as React from \"react\";\nimport Knock, {\n Feed,\n FeedClientOptions,\n FeedStoreState,\n} from \"@knocklabs/client\";\nimport create, { StoreApi, UseStore } from \"zustand\";\n\nimport { ColorMode } from \"../../core/constants\";\nimport useNotifications from \"../hooks/useNotifications\";\nimport { feedProviderKey } from \"../../core/utils\";\nimport { useKnockClient } from \"../../core\";\n\nexport interface KnockFeedProviderState {\n knock: Knock;\n feedClient: Feed;\n useFeedStore: UseStore<FeedStoreState>;\n colorMode: ColorMode;\n}\n\nconst FeedStateContext = React.createContext<KnockFeedProviderState | null>(\n null,\n);\n\nexport interface KnockFeedProviderProps {\n // Feed props\n feedId: string;\n\n // Extra options\n children?: React.ReactElement;\n colorMode?: ColorMode;\n\n // Feed client options\n defaultFeedOptions?: FeedClientOptions;\n}\n\nexport const KnockFeedProvider: React.FC<KnockFeedProviderProps> = ({\n feedId,\n children,\n defaultFeedOptions = {},\n colorMode = \"light\",\n}) => {\n const knock = useKnockClient();\n\n const feedClient = useNotifications(knock, feedId, defaultFeedOptions);\n const useFeedStore = create(feedClient.store as StoreApi<FeedStoreState>);\n\n return (\n <FeedStateContext.Provider\n key={feedProviderKey(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 if (context === undefined) {\n throw new Error(\"useKnockFeed must be used within a KnockFeedProvider\");\n }\n return context as KnockFeedProviderState;\n};\n"],"names":["FeedStateContext","React","createContext","KnockFeedProvider","feedId","children","defaultFeedOptions","colorMode","knock","useKnockClient","feedClient","useNotifications","useFeedStore","create","store","jsx","feedProviderKey","useKnockFeed","context","useContext","undefined","Error"],"mappings":"ssBAoBMA,EAAmBC,EAAMC,cAC7B,IACF,EAcaC,EAAsDA,CAAC,CAClEC,OAAAA,EACAC,SAAAA,EACAC,mBAAAA,EAAqB,CAAC,EACtBC,UAAAA,EAAY,OACd,IAAM,CACJ,MAAMC,EAAQC,EAAAA,iBAERC,EAAaC,EAAiBH,EAAOJ,EAAQE,CAAkB,EAC/DM,EAAeC,EAAAA,QAAOH,EAAWI,KAAkC,EAEzE,OACGC,MAAAf,EAAiB,SAAjB,CAEC,MAAO,CACLQ,MAAAA,EACAE,WAAAA,EACAE,aAAAA,EACAL,UAAAA,CAGDF,EAAAA,SAAAA,CAAAA,EARIW,EAAAA,gBAAgBZ,EAAQE,CAAkB,CASjD,CAEJ,EAEaW,EAAeA,IAA8B,CAClDC,MAAAA,EAAUjB,EAAMkB,WAAWnB,CAAgB,EACjD,GAAIkB,IAAYE,OACR,MAAA,IAAIC,MAAM,sDAAsD,EAEjEH,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 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<KnockFeedProviderState | null>(\n null,\n);\n\nexport interface KnockFeedProviderProps {\n // Feed props\n feedId: string;\n\n // Extra options\n children?: React.ReactElement;\n colorMode?: ColorMode;\n\n // Feed client options\n defaultFeedOptions?: FeedClientOptions;\n}\n\nexport const KnockFeedProvider: React.FC<KnockFeedProviderProps> = ({\n feedId,\n children,\n defaultFeedOptions = {},\n colorMode = \"light\",\n}) => {\n const knock = useKnockClient();\n const feedClient = useNotifications(knock, feedId, defaultFeedOptions);\n const useFeedStore = create<FeedStoreState>(feedClient.store);\n\n return (\n <FeedStateContext.Provider\n key={feedProviderKey(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 if (context === undefined) {\n throw new Error(\"useKnockFeed must be used within a KnockFeedProvider\");\n }\n return context as KnockFeedProviderState;\n};\n"],"names":["FeedStateContext","React","KnockFeedProvider","feedId","children","defaultFeedOptions","colorMode","knock","useKnockClient","feedClient","useNotifications","useFeedStore","create","jsx","feedProviderKey","useKnockFeed","context"],"mappings":"ssBAoBMA,EAAmBC,EAAM,cAC7B,IACF,EAcaC,EAAsD,CAAC,CAClE,OAAAC,EACA,SAAAC,EACA,mBAAAC,EAAqB,CAAC,EACtB,UAAAC,EAAY,OACd,IAAM,CACJ,MAAMC,EAAQC,EAAAA,iBACRC,EAAaC,EAAiBH,EAAOJ,EAAQE,CAAkB,EAC/DM,EAAeC,EAAAA,QAAuBH,EAAW,KAAK,EAG1D,OAAAI,EAAA,IAACb,EAAiB,SAAjB,CAEC,MAAO,CACL,MAAAO,EACA,WAAAE,EACA,aAAAE,EACA,UAAAL,CACF,EAEC,SAAAF,CAAA,EARIU,EAAA,gBAAgBX,EAAQE,CAAkB,CAAA,CAWrD,EAEaU,EAAe,IAA8B,CAClD,MAAAC,EAAUf,EAAM,WAAWD,CAAgB,EACjD,GAAIgB,IAAY,OACR,MAAA,IAAI,MAAM,sDAAsD,EAEjE,OAAAA,CACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"useFeedSettings.js","sources":["../../../../../src/modules/feed/hooks/useFeedSettings.ts"],"sourcesContent":["import { Feed } from \"@knocklabs/client\";\nimport { useEffect, useState } from \"react\";\n\nexport type FeedSettings = {\n features: {\n branding_required: boolean;\n };\n};\n\nfunction useFeedSettings(feedClient: Feed): {\n settings: FeedSettings | null;\n loading: boolean;\n} {\n const [settings, setSettings] = useState(null);\n const [isLoading, setIsLoading] = useState(false);\n\n // TODO: consider moving this into the feed client and into the feed store state when\n // we're using this in other areas of the feed\n useEffect(() => {\n async function getSettings() {\n const knock = feedClient.knock;\n const apiClient = knock.client();\n const feedSettingsPath = `/v1/users/${knock.userId}/feeds/${feedClient.feedId}/settings`;\n setIsLoading(true);\n\n const response = await apiClient.makeRequest({\n method: \"GET\",\n url: feedSettingsPath,\n });\n\n if (!response.error) {\n setSettings(response.body);\n }\n\n setIsLoading(false);\n }\n\n getSettings();\n }, []);\n\n return { settings, loading: isLoading };\n}\n\nexport default useFeedSettings;\n"],"names":["useFeedSettings","feedClient","settings","setSettings","useState","isLoading","setIsLoading","useEffect","getSettings","knock","apiClient","client","feedSettingsPath","userId","feedId","response","makeRequest","method","url","error","body","loading"],"mappings":"sCASA,SAASA,EAAgBC,EAGvB,CACA,KAAM,CAACC,EAAUC,CAAW,EAAIC,WAAS,IAAI,EACvC,CAACC,EAAWC,CAAY,EAAIF,WAAS,EAAK,EAIhDG,OAAAA,EAAAA,UAAU,IAAM,CACd,eAAeC,GAAc,CAC3B,MAAMC,EAAQR,EAAWQ,MACnBC,EAAYD,EAAME,SAClBC,EAAoB,aAAYH,EAAMI,MAAO,UAASZ,EAAWa,MAAO,YAC9ER,EAAa,EAAI,EAEXS,MAAAA,EAAW,MAAML,EAAUM,YAAY,CAC3CC,OAAQ,MACRC,IAAKN,CAAAA,CACN,EAEIG,EAASI,OACZhB,EAAYY,EAASK,IAAI,EAG3Bd,EAAa,EAAK,CACpB,CAEYE,GACd,EAAG,CAAE,CAAA,EAEE,CAAEN,SAAAA,EAAUmB,QAAShB,CAAAA,CAC9B"}
1
+ {"version":3,"file":"useFeedSettings.js","sources":["../../../../../src/modules/feed/hooks/useFeedSettings.ts"],"sourcesContent":["import { Feed } from \"@knocklabs/client\";\nimport { useEffect, useState } from \"react\";\n\nexport type FeedSettings = {\n features: {\n branding_required: boolean;\n };\n};\n\nfunction useFeedSettings(feedClient: Feed): {\n settings: FeedSettings | null;\n loading: boolean;\n} {\n const [settings, setSettings] = useState(null);\n const [isLoading, setIsLoading] = useState(false);\n\n // TODO: consider moving this into the feed client and into the feed store state when\n // we're using this in other areas of the feed\n useEffect(() => {\n async function getSettings() {\n const knock = feedClient.knock;\n const apiClient = knock.client();\n const feedSettingsPath = `/v1/users/${knock.userId}/feeds/${feedClient.feedId}/settings`;\n setIsLoading(true);\n\n const response = await apiClient.makeRequest({\n method: \"GET\",\n url: feedSettingsPath,\n });\n\n if (!response.error) {\n setSettings(response.body);\n }\n\n setIsLoading(false);\n }\n\n getSettings();\n }, []);\n\n return { settings, loading: isLoading };\n}\n\nexport default useFeedSettings;\n"],"names":["useFeedSettings","feedClient","settings","setSettings","useState","isLoading","setIsLoading","useEffect","getSettings","knock","apiClient","feedSettingsPath","response"],"mappings":"sCASA,SAASA,EAAgBC,EAGvB,CACA,KAAM,CAACC,EAAUC,CAAW,EAAIC,WAAS,IAAI,EACvC,CAACC,EAAWC,CAAY,EAAIF,WAAS,EAAK,EAIhDG,OAAAA,EAAAA,UAAU,IAAM,CACd,eAAeC,GAAc,CAC3B,MAAMC,EAAQR,EAAW,MACnBS,EAAYD,EAAM,SAClBE,EAAmB,aAAaF,EAAM,MAAM,UAAUR,EAAW,MAAM,YAC7EK,EAAa,EAAI,EAEX,MAAAM,EAAW,MAAMF,EAAU,YAAY,CAC3C,OAAQ,MACR,IAAKC,CAAA,CACN,EAEIC,EAAS,OACZT,EAAYS,EAAS,IAAI,EAG3BN,EAAa,EAAK,CACpB,CAEYE,GACd,EAAG,CAAE,CAAA,EAEE,CAAE,SAAAN,EAAU,QAASG,EAC9B"}
@@ -1,2 +1,2 @@
1
- "use strict";const c=require("react");function i(n,u,e={}){const t=c.useRef();return c.useMemo(()=>{t.current&&t.current.teardown();const r=n.feeds.initialize(u,e);return r.listenForUpdates(),t.current=r,r},[n,u,e.source,e.tenant,e.has_tenant,e.archived])}module.exports=i;
1
+ "use strict";const n=require("react");function u(s,i,e={}){const t=n.useRef();return n.useMemo(()=>{t.current&&t.current.dispose();const r=s.feeds.initialize(i,e);return r.listenForUpdates(),t.current=r,r},[s,i,e.source,e.tenant,e.has_tenant,e.archived])}module.exports=u;
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 feedId: string,\n options: FeedClientOptions = {},\n) {\n const feedClientRef = useRef<Feed | null>();\n\n return useMemo(() => {\n if (feedClientRef.current) feedClientRef.current.teardown();\n\n const feedClient = knock.feeds.initialize(feedId, options);\n\n feedClient.listenForUpdates();\n feedClientRef.current = feedClient;\n\n return feedClient;\n }, [\n knock,\n feedId,\n options.source,\n options.tenant,\n options.has_tenant,\n options.archived,\n ]);\n}\n\nexport default useNotifications;\n"],"names":["useNotifications","knock","feedId","options","feedClientRef","useRef","useMemo","current","teardown","feedClient","feeds","initialize","listenForUpdates","source","tenant","has_tenant","archived"],"mappings":"sCAGA,SAASA,EACPC,EACAC,EACAC,EAA6B,CAAA,EAC7B,CACA,MAAMC,EAAgBC,EAAAA,SAEtB,OAAOC,UAAQ,IAAM,CACfF,EAAcG,SAASH,EAAcG,QAAQC,WAEjD,MAAMC,EAAaR,EAAMS,MAAMC,WAAWT,EAAQC,CAAO,EAEzDM,OAAAA,EAAWG,iBAAiB,EAC5BR,EAAcG,QAAUE,EAEjBA,CACN,EAAA,CACDR,EACAC,EACAC,EAAQU,OACRV,EAAQW,OACRX,EAAQY,WACRZ,EAAQa,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\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 const feedClient = knock.feeds.initialize(feedChannelId, options);\n\n feedClient.listenForUpdates();\n feedClientRef.current = feedClient;\n\n return feedClient;\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","feedClient"],"mappings":"sCAGA,SAASA,EACPC,EACAC,EACAC,EAA6B,CAAA,EAC7B,CACA,MAAMC,EAAgBC,EAAAA,SAEtB,OAAOC,UAAQ,IAAM,CACfF,EAAc,SAChBA,EAAc,QAAQ,UAGxB,MAAMG,EAAaN,EAAM,MAAM,WAAWC,EAAeC,CAAO,EAEhE,OAAAI,EAAW,iBAAiB,EAC5BH,EAAc,QAAUG,EAEjBA,CAAA,EACN,CACDN,EACAC,EACAC,EAAQ,OACRA,EAAQ,OACRA,EAAQ,WACRA,EAAQ,QAAA,CACT,CACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"KnockI18nProvider.js","sources":["../../../../../src/modules/i18n/context/KnockI18nProvider.tsx"],"sourcesContent":["import React from \"react\";\nimport { locales, I18nContent } from \"../languages\";\n\nexport const I18nContext = React.createContext<I18nContent>(locales.en);\n\ninterface KnockI18nProviderProps {\n i18n?: I18nContent;\n children: JSX.Element | undefined;\n}\n\nexport function KnockI18nProvider({\n i18n = locales.en,\n ...props\n}: KnockI18nProviderProps) {\n return <I18nContext.Provider {...props} value={i18n} />;\n}\n"],"names":["I18nContext","React","createContext","locales","en","KnockI18nProvider","i18n","props"],"mappings":"0OAGaA,EAAcC,EAAAA,QAAMC,cAA2BC,EAAAA,QAAQC,EAAE,EAO/D,SAASC,EAAkB,CAChCC,KAAAA,EAAOH,EAAQC,QAAAA,GACf,GAAGG,CACmB,EAAG,CACzB,aAAQP,EAAY,SAAZ,CAAyBO,GAAAA,EAAO,MAAOD,CAAQ,CAAA,CACzD"}
1
+ {"version":3,"file":"KnockI18nProvider.js","sources":["../../../../../src/modules/i18n/context/KnockI18nProvider.tsx"],"sourcesContent":["import React from \"react\";\nimport { locales, I18nContent } from \"../languages\";\n\nexport const I18nContext = React.createContext<I18nContent>(locales.en);\n\ninterface KnockI18nProviderProps {\n i18n?: I18nContent;\n children: JSX.Element | undefined;\n}\n\nexport function KnockI18nProvider({\n i18n = locales.en,\n ...props\n}: KnockI18nProviderProps) {\n return <I18nContext.Provider {...props} value={i18n} />;\n}\n"],"names":["I18nContext","React","locales","KnockI18nProvider","i18n","props"],"mappings":"0OAGaA,EAAcC,EAAA,QAAM,cAA2BC,EAAAA,QAAQ,EAAE,EAO/D,SAASC,EAAkB,CAChC,KAAAC,EAAOF,EAAQ,QAAA,GACf,GAAGG,CACL,EAA2B,CACzB,aAAQL,EAAY,SAAZ,CAAsB,GAAGK,EAAO,MAAOD,CAAM,CAAA,CACvD"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),s=require("date-fns/locale"),c=require("../languages/index.js"),i=require("../context/KnockI18nProvider.js");function u(e){if(e&&typeof e=="object"&&"default"in e)return e;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const r=u(s);function l(){const{translations:e,locale:t}=a.useContext(i.I18nContext);return{locale:t,t:n=>e[n]||c.locales.en.translations[n],dateFnsLocale:()=>t in r?r[t]:r.enUS}}exports.useTranslations=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),o=require("../languages/index.js"),s=require("../context/KnockI18nProvider.js");function a(){const{translations:n,locale:t}=r.useContext(s.I18nContext);return{locale:t,t:e=>n[e]||o.locales.en.translations[e]}}exports.useTranslations=a;
2
2
  //# sourceMappingURL=useTranslations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTranslations.js","sources":["../../../../../src/modules/i18n/hooks/useTranslations.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { Locale as DateFnLocale } from \"date-fns\";\nimport * as dateFnsLocales from \"date-fns/locale\";\nimport { I18nContent, locales } from \"../languages\";\nimport { I18nContext } from \"../context/KnockI18nProvider\";\n\nexport function useTranslations() {\n const { translations, locale } = useContext<I18nContent>(I18nContext);\n\n return {\n locale,\n t: (key: keyof typeof translations) => {\n // We always use english as the default translation when a key doesn't exist\n return translations[key] || locales.en.translations[key];\n },\n dateFnsLocale: (): DateFnLocale => {\n return locale in dateFnsLocales\n ? dateFnsLocales[locale as keyof typeof dateFnsLocales]\n : dateFnsLocales.enUS;\n },\n };\n}\n"],"names":["useTranslations","translations","locale","useContext","I18nContext","t","key","locales","en","dateFnsLocale","dateFnsLocales","enUS"],"mappings":"iiBAMO,SAASA,GAAkB,CAC1B,KAAA,CAAEC,aAAAA,EAAcC,OAAAA,CAAAA,EAAWC,EAAAA,WAAwBC,EAAAA,WAAW,EAE7D,MAAA,CACLF,OAAAA,EACAG,EAAIC,GAEKL,EAAaK,CAAG,GAAKC,EAAAA,QAAQC,GAAGP,aAAaK,CAAG,EAEzDG,cAAeA,IACNP,KAAUQ,EACbA,EAAeR,CAAqC,EACpDQ,EAAeC,IACrB,CAEJ"}
1
+ {"version":3,"file":"useTranslations.js","sources":["../../../../../src/modules/i18n/hooks/useTranslations.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { I18nContent, locales } from \"../languages\";\nimport { I18nContext } from \"../context/KnockI18nProvider\";\n\nexport function useTranslations() {\n const { translations, locale } = useContext<I18nContent>(I18nContext);\n\n return {\n locale,\n t: (key: keyof typeof translations) => {\n // We always use english as the default translation when a key doesn't exist\n return translations[key] || locales.en.translations[key];\n },\n };\n}\n"],"names":["useTranslations","translations","locale","useContext","I18nContext","key","locales"],"mappings":"yLAIO,SAASA,GAAkB,CAChC,KAAM,CAAE,aAAAC,EAAc,OAAAC,CAAO,EAAIC,aAAwBC,EAAW,WAAA,EAE7D,MAAA,CACL,OAAAF,EACA,EAAIG,GAEKJ,EAAaI,CAAG,GAAKC,EAAAA,QAAQ,GAAG,aAAaD,CAAG,CACzD,CAEJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"de.js","sources":["../../../../../src/modules/i18n/languages/de.ts"],"sourcesContent":["import { I18nContent } from \".\";\n\nconst de: I18nContent = {\n translations: {\n archiveNotification: \"Benachrichtigung archivieren\",\n markAllAsRead: \"Alle als gelesen markieren\",\n notifications: \"Benachrichtigungen\",\n emptyFeedTitle: \"Noch keine Benachrichtigungen\",\n emptyFeedBody:\n \"Wir werden dich benachrichtigen, sobald wir etwas Neues für dich haben.\",\n all: \"Alle\",\n unread: \"Ungelesen\",\n read: \"Gelesen\",\n unseen: \"Ungesehen\",\n },\n locale: \"de\",\n};\n\nexport default de;\n"],"names":["de","translations","archiveNotification","markAllAsRead","notifications","emptyFeedTitle","emptyFeedBody","all","unread","read","unseen","locale"],"mappings":"aAEA,MAAMA,EAAkB,CACtBC,aAAc,CACZC,oBAAqB,+BACrBC,cAAe,6BACfC,cAAe,qBACfC,eAAgB,gCAChBC,cACE,0EACFC,IAAK,OACLC,OAAQ,YACRC,KAAM,UACNC,OAAQ,WACV,EACAC,OAAQ,IACV"}
1
+ {"version":3,"file":"de.js","sources":["../../../../../src/modules/i18n/languages/de.ts"],"sourcesContent":["import { I18nContent } from \".\";\n\nconst de: I18nContent = {\n translations: {\n archiveNotification: \"Benachrichtigung archivieren\",\n markAllAsRead: \"Alle als gelesen markieren\",\n notifications: \"Benachrichtigungen\",\n emptyFeedTitle: \"Noch keine Benachrichtigungen\",\n emptyFeedBody:\n \"Wir werden dich benachrichtigen, sobald wir etwas Neues für dich haben.\",\n all: \"Alle\",\n unread: \"Ungelesen\",\n read: \"Gelesen\",\n unseen: \"Ungesehen\",\n },\n locale: \"de\",\n};\n\nexport default de;\n"],"names":["de"],"mappings":"aAEA,MAAMA,EAAkB,CACtB,aAAc,CACZ,oBAAqB,+BACrB,cAAe,6BACf,cAAe,qBACf,eAAgB,gCAChB,cACE,0EACF,IAAK,OACL,OAAQ,YACR,KAAM,UACN,OAAQ,WACV,EACA,OAAQ,IACV"}
@@ -1 +1 @@
1
- {"version":3,"file":"en.js","sources":["../../../../../src/modules/i18n/languages/en.ts"],"sourcesContent":["import { I18nContent } from \".\";\n\nconst en: I18nContent = {\n translations: {\n archiveNotification: \"Archive this notification\",\n markAllAsRead: \"Mark all as read\",\n notifications: \"Notifications\",\n emptyFeedTitle: \"No notifications yet\",\n emptyFeedBody: \"We'll let you know when we've got something new for you.\",\n all: \"All\",\n unread: \"Unread\",\n read: \"Read\",\n unseen: \"Unseen\",\n },\n locale: \"en\",\n};\n\nexport default en;\n"],"names":["en","translations","archiveNotification","markAllAsRead","notifications","emptyFeedTitle","emptyFeedBody","all","unread","read","unseen","locale"],"mappings":"aAEA,MAAMA,EAAkB,CACtBC,aAAc,CACZC,oBAAqB,4BACrBC,cAAe,mBACfC,cAAe,gBACfC,eAAgB,uBAChBC,cAAe,2DACfC,IAAK,MACLC,OAAQ,SACRC,KAAM,OACNC,OAAQ,QACV,EACAC,OAAQ,IACV"}
1
+ {"version":3,"file":"en.js","sources":["../../../../../src/modules/i18n/languages/en.ts"],"sourcesContent":["import { I18nContent } from \".\";\n\nconst en: I18nContent = {\n translations: {\n archiveNotification: \"Archive this notification\",\n markAllAsRead: \"Mark all as read\",\n notifications: \"Notifications\",\n emptyFeedTitle: \"No notifications yet\",\n emptyFeedBody: \"We'll let you know when we've got something new for you.\",\n all: \"All\",\n unread: \"Unread\",\n read: \"Read\",\n unseen: \"Unseen\",\n },\n locale: \"en\",\n};\n\nexport default en;\n"],"names":["en"],"mappings":"aAEA,MAAMA,EAAkB,CACtB,aAAc,CACZ,oBAAqB,4BACrB,cAAe,mBACf,cAAe,gBACf,eAAgB,uBAChB,cAAe,2DACf,IAAK,MACL,OAAQ,SACR,KAAM,OACN,OAAQ,QACV,EACA,OAAQ,IACV"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../../src/modules/i18n/languages/index.ts"],"sourcesContent":["import en from \"./en\";\nimport de from \"./de\";\n\nexport interface Translations {\n readonly emptyFeedTitle: string;\n readonly emptyFeedBody: string;\n readonly notifications: string;\n readonly poweredBy: string;\n readonly markAllAsRead: string;\n readonly archiveNotification: string;\n readonly all: string;\n readonly unread: string;\n readonly read: string;\n readonly unseen: string;\n}\n\nexport interface I18nContent {\n readonly translations: Partial<Translations>;\n readonly locale: string;\n}\n\nexport const locales = { en, de };\n"],"names":["locales","en","de"],"mappings":"gIAqBaA,EAAU,CAAEC,GAAAA,EAAIC,GAAAA,CAAG"}
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/modules/i18n/languages/index.ts"],"sourcesContent":["import en from \"./en\";\nimport de from \"./de\";\n\nexport interface Translations {\n readonly emptyFeedTitle: string;\n readonly emptyFeedBody: string;\n readonly notifications: string;\n readonly poweredBy: string;\n readonly markAllAsRead: string;\n readonly archiveNotification: string;\n readonly all: string;\n readonly unread: string;\n readonly read: string;\n readonly unseen: string;\n}\n\nexport interface I18nContent {\n readonly translations: Partial<Translations>;\n readonly locale: string;\n}\n\nexport const locales = { en, de };\n"],"names":["locales","en","de"],"mappings":"gIAqBaA,EAAU,CAAE,GAAAC,EAAI,GAAAC,CAAG"}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../../../../src/modules/core/constants.ts"],"sourcesContent":["export enum FilterStatus {\n All = \"all\",\n Read = \"read\",\n Unseen = \"unseen\",\n Unread = \"unread\",\n}\n\nexport type ColorMode = \"light\" | \"dark\";\n"],"names":["FilterStatus","All","Read","Unseen","Unread"],"mappings":"AAAYA,IAAAA,sBAAAA,OACVC,EAAAA,MAAM,OACNC,EAAAA,OAAO,QACPC,EAAAA,SAAS,UACTC,EAAAA,SAAS,UAJCJ,IAAAA,KAAAA,CAAAA,CAAAA;"}
1
+ {"version":3,"file":"constants.js","sources":["../../../../src/modules/core/constants.ts"],"sourcesContent":["export enum FilterStatus {\n All = \"all\",\n Read = \"read\",\n Unseen = \"unseen\",\n Unread = \"unread\",\n}\n\nexport type ColorMode = \"light\" | \"dark\";\n"],"names":["FilterStatus"],"mappings":"AAAY,IAAAA,sBAAAA,OACVA,EAAA,MAAM,OACNA,EAAA,OAAO,QACPA,EAAA,SAAS,UACTA,EAAA,SAAS,UAJCA,IAAAA,KAAA,CAAA,CAAA;"}
@@ -1,30 +1,51 @@
1
- import { jsx as t } from "react/jsx-runtime";
2
- import * as r from "react";
3
- import m from "../hooks/useAuthenticatedKnockClient.js";
4
- import { KnockI18nProvider as d } from "../../i18n/context/KnockI18nProvider.js";
5
- import "date-fns/locale";
6
- const e = r.createContext(null), x = ({
7
- apiKey: o,
8
- host: n,
9
- userId: c,
10
- userToken: i,
11
- children: s,
12
- i18n: u
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ import * as o from "react";
3
+ import { KnockI18nProvider as K } from "../../i18n/context/KnockI18nProvider.js";
4
+ import C from "../hooks/useAuthenticatedKnockClient.js";
5
+ const s = o.createContext(
6
+ null
7
+ ), l = ({
8
+ apiKey: t,
9
+ host: e,
10
+ logLevel: n,
11
+ userId: u,
12
+ userToken: d,
13
+ onUserTokenExpiring: r,
14
+ timeBeforeExpirationInMs: c,
15
+ children: k,
16
+ i18n: m
13
17
  }) => {
14
- const k = m(o, c, i, {
15
- host: n
16
- });
17
- return /* @__PURE__ */ t(e.Provider, { value: {
18
- knock: k
19
- }, children: /* @__PURE__ */ t(d, { i18n: u, children: s }) });
20
- }, K = () => {
21
- const o = r.useContext(e);
22
- if (o === void 0)
18
+ const a = o.useMemo(
19
+ () => ({
20
+ host: e,
21
+ onUserTokenExpiring: r,
22
+ timeBeforeExpirationInMs: c,
23
+ logLevel: n
24
+ }),
25
+ [e, r, c, n]
26
+ ), v = C(
27
+ t,
28
+ u,
29
+ d,
30
+ a
31
+ );
32
+ return /* @__PURE__ */ i(
33
+ s.Provider,
34
+ {
35
+ value: {
36
+ knock: v
37
+ },
38
+ children: /* @__PURE__ */ i(K, { i18n: m, children: k })
39
+ }
40
+ );
41
+ }, p = () => {
42
+ const t = o.useContext(s);
43
+ if (t === void 0)
23
44
  throw new Error("useKnock must be used within a KnockProvider");
24
- return o.knock;
45
+ return t.knock;
25
46
  };
26
47
  export {
27
- x as KnockProvider,
28
- K as useKnockClient
48
+ l as KnockProvider,
49
+ p as useKnockClient
29
50
  };
30
51
  //# sourceMappingURL=KnockProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"KnockProvider.js","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport Knock from \"@knocklabs/client\";\n\nimport { useAuthenticatedKnockClient } from \"../hooks\";\nimport { KnockI18nProvider, I18nContent } from \"../../i18n\";\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\n // Extra options\n children?: React.ReactElement;\n\n // i18n translations\n i18n?: I18nContent;\n}\n\nexport const KnockProvider: React.FC<KnockProviderProps> = ({\n apiKey,\n host,\n userId,\n userToken,\n children,\n i18n,\n}) => {\n const knock = useAuthenticatedKnockClient(apiKey, userId, userToken, {\n host,\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","userId","userToken","children","i18n","knock","useAuthenticatedKnockClient","jsx","KnockI18nProvider","useKnockClient","context","useContext","undefined","Error"],"mappings":";;;;;AAUA,MAAMA,IAAuBC,EAAMC,cACjC,IACF,GAiBaC,IAA8CA,CAAC;AAAA,EAC1DC,QAAAA;AAAAA,EACAC,MAAAA;AAAAA,EACAC,QAAAA;AAAAA,EACAC,WAAAA;AAAAA,EACAC,UAAAA;AAAAA,EACAC,MAAAA;AACF,MAAM;AACJ,QAAMC,IAAQC,EAA4BP,GAAQE,GAAQC,GAAW;AAAA,IACnEF,MAAAA;AAAAA,EAAAA,CACD;AAED,SACG,gBAAAO,EAAAZ,EAAqB,UAArB,EACC,OAAO;AAAA,IACLU,OAAAA;AAAAA,EAAAA,GAGF,UAAA,gBAAAE,EAACC,GAAkB,EAAA,MAAAJ,GAAaD,UAAAA,GAAS,EAC3C,CAAA;AAEJ,GAEaM,IAAiBA,MAAa;AACnCC,QAAAA,IAAUd,EAAMe,WAAWhB,CAAoB;AACrD,MAAIe,MAAYE;AACR,UAAA,IAAIC,MAAM,8CAA8C;AAEhE,SAAOH,EAAQL;AACjB;"}
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\";\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 // Extra options\n children?: React.ReactElement;\n\n // i18n translations\n i18n?: I18nContent;\n\n logLevel?: LogLevel;\n}\n\nexport const KnockProvider: React.FC<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 // TODO: we probably need to put this optimization into the `useAuthenticatedKnockClient`\n // hook itself to fix this\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","KnockProvider","apiKey","host","logLevel","userId","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","authenticateOptions","knock","useAuthenticatedKnockClient","jsx","KnockI18nProvider","useKnockClient","context"],"mappings":";;;;AAUA,MAAMA,IAAuBC,EAAM;AAAA,EACjC;AACF,GAqBaC,IAA8C,CAAC;AAAA,EAC1D,QAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,QAAAC;AAAA,EACA,WAAAC;AAAA,EACA,qBAAAC;AAAA,EACA,0BAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC;AACF,MAAM;AAIJ,QAAMC,IAAsBX,EAAM;AAAA,IAChC,OAAO;AAAA,MACL,MAAAG;AAAA,MACA,qBAAAI;AAAA,MACA,0BAAAC;AAAA,MACA,UAAAJ;AAAA,IAAA;AAAA,IAEF,CAACD,GAAMI,GAAqBC,GAA0BJ,CAAQ;AAAA,EAAA,GAG1DQ,IAAQC;AAAA,IACZX;AAAA,IACAG;AAAA,IACAC;AAAA,IACAK;AAAA,EAAA;AAIA,SAAA,gBAAAG;AAAA,IAACf,EAAqB;AAAA,IAArB;AAAA,MACC,OAAO;AAAA,QACL,OAAAa;AAAA,MACF;AAAA,MAEA,UAAA,gBAAAE,EAACC,GAAkB,EAAA,MAAAL,GAAa,UAAAD,EAAS,CAAA;AAAA,IAAA;AAAA,EAAA;AAG/C,GAEaO,IAAiB,MAAa;AACnC,QAAAC,IAAUjB,EAAM,WAAWD,CAAoB;AACrD,MAAIkB,MAAY;AACR,UAAA,IAAI,MAAM,8CAA8C;AAEhE,SAAOA,EAAQ;AACjB;"}
@@ -1,14 +1,23 @@
1
- import u, { useMemo as f } from "react";
2
- import a from "@knocklabs/client";
3
- function m(n, r, c, o = {}) {
4
- const t = u.useRef();
5
- return f(() => {
6
- t.current && t.current.teardown();
7
- const e = new a(n, o);
8
- return e.authenticate(r, c), t.current = e, e;
9
- }, [n, r, c]);
1
+ import i from "@knocklabs/client";
2
+ import k, { useMemo as m } from "react";
3
+ function f(c, n, r, e = {}) {
4
+ c.authenticate(n, r, {
5
+ onUserTokenExpiring: e == null ? void 0 : e.onUserTokenExpiring,
6
+ timeBeforeExpirationInMs: e == null ? void 0 : e.timeBeforeExpirationInMs
7
+ });
8
+ }
9
+ function E(c, n, r, e = {}) {
10
+ const a = k.useRef();
11
+ return m(() => {
12
+ const t = a.current;
13
+ if (t && t.isAuthenticated() && (t.userId !== n || t.userToken !== r))
14
+ return f(t, n, r, e), t;
15
+ t && t.teardown();
16
+ const u = new i(c, e);
17
+ return f(u, n, r, e), a.current = u, u;
18
+ }, [c, n, r, e]);
10
19
  }
11
20
  export {
12
- m as default
21
+ E as default
13
22
  };
14
23
  //# sourceMappingURL=useAuthenticatedKnockClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAuthenticatedKnockClient.js","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport Knock, { KnockOptions } from \"@knocklabs/client\";\n\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userId: string,\n userToken: string | undefined,\n options: KnockOptions = {},\n) {\n const knockRef = React.useRef<Knock | null>();\n\n return useMemo(() => {\n if (knockRef.current) knockRef.current.teardown();\n\n const knock = new Knock(apiKey, options);\n knock.authenticate(userId, userToken);\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, userId, userToken]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["useAuthenticatedKnockClient","apiKey","userId","userToken","options","knockRef","React","useRef","useMemo","current","teardown","knock","Knock","authenticate"],"mappings":";;AAGA,SAASA,EACPC,GACAC,GACAC,GACAC,IAAwB,CAAA,GACxB;AACMC,QAAAA,IAAWC,EAAMC;AAEvB,SAAOC,EAAQ,MAAM;AACnB,IAAIH,EAASI,WAASJ,EAASI,QAAQC;AAEvC,UAAMC,IAAQ,IAAIC,EAAMX,GAAQG,CAAO;AACjCS,WAAAA,EAAAA,aAAaX,GAAQC,CAAS,GACpCE,EAASI,UAAUE,GAEZA;AAAAA,EACN,GAAA,CAACV,GAAQC,GAAQC,CAAS,CAAC;AAChC;"}
1
+ {"version":3,"file":"useAuthenticatedKnockClient.js","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, { AuthenticateOptions, KnockOptions } from \"@knocklabs/client\";\nimport React, { useMemo } from \"react\";\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\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userId: string,\n userToken?: string,\n options: KnockOptions & AuthenticateOptions = {},\n) {\n const knockRef = React.useRef<Knock | null>();\n\n return 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, options);\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, options);\n authenticateWithOptions(knock, userId, userToken, options);\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, userId, userToken, options]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userId","userToken","options","useAuthenticatedKnockClient","apiKey","knockRef","React","useMemo","currentKnock","Knock"],"mappings":";;AAGA,SAASA,EACPC,GACAC,GACAC,GACAC,IAA+B,CAAA,GAC/B;AACM,EAAAH,EAAA,aAAaC,GAAQC,GAAW;AAAA,IACpC,qBAAqBC,KAAA,gBAAAA,EAAS;AAAA,IAC9B,0BAA0BA,KAAA,gBAAAA,EAAS;AAAA,EAAA,CACpC;AACH;AAEA,SAASC,EACPC,GACAJ,GACAC,GACAC,IAA8C,CAAA,GAC9C;AACM,QAAAG,IAAWC,EAAM;AAEvB,SAAOC,EAAQ,MAAM;AACnB,UAAMC,IAAeH,EAAS;AAI5B,QAAAG,KACAA,EAAa,gBAAgB,MAC5BA,EAAa,WAAWR,KAAUQ,EAAa,cAAcP;AAEtC,aAAAH,EAAAU,GAAcR,GAAQC,GAAWC,CAAO,GACzDM;AAGT,IAAIA,KACFA,EAAa,SAAS;AAIxB,UAAMT,IAAQ,IAAIU,EAAML,GAAQF,CAAO;AACf,WAAAJ,EAAAC,GAAOC,GAAQC,GAAWC,CAAO,GACzDG,EAAS,UAAUN,GAEZA;AAAA,KACN,CAACK,GAAQJ,GAAQC,GAAWC,CAAO,CAAC;AACzC;"}
@@ -1,5 +1,4 @@
1
- import a from "date-fns/formatDistance";
2
- import n from "date-fns/parseISO";
1
+ import { parseISO as n, intlFormatDistance as a } from "date-fns";
3
2
  function u(e) {
4
3
  return e > 9 ? "9+" : e;
5
4
  }
@@ -7,27 +6,32 @@ function i(e, r = {}) {
7
6
  try {
8
7
  const t = n(e);
9
8
  return a(t, /* @__PURE__ */ new Date(), {
10
- addSuffix: !0,
11
9
  locale: r.locale
12
10
  });
13
11
  } catch {
14
12
  return e;
15
13
  }
16
14
  }
17
- function d(e) {
15
+ function f(e) {
18
16
  return e.charAt(0).toUpperCase() + e.slice(1);
19
17
  }
20
- function m(e, r) {
18
+ function l(e, r) {
21
19
  return e !== void 0 ? e : r;
22
20
  }
23
- function l(e, r = {}) {
24
- return [e, r.source, r.tenant, r.has_tenant, r.archived].filter((t) => t != null).join("-");
21
+ function d(e, r = {}) {
22
+ return [
23
+ e,
24
+ r.source,
25
+ r.tenant,
26
+ r.has_tenant,
27
+ r.archived
28
+ ].filter((t) => t != null).join("-");
25
29
  }
26
30
  export {
27
- l as feedProviderKey,
31
+ d as feedProviderKey,
28
32
  u as formatBadgeCount,
29
33
  i as formatTimestamp,
30
- m as renderNodeOrFallback,
31
- d as toSentenceCase
34
+ l as renderNodeOrFallback,
35
+ f as toSentenceCase
32
36
  };
33
37
  //# 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 { parseISO, formatDistance, Locale } 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?: Locale;\n};\n\nexport function formatTimestamp(\n ts: string,\n options: FormatTimestampOptions = {},\n) {\n try {\n const parsedTs = parseISO(ts);\n const formatted = formatDistance(parsedTs, new Date(), {\n addSuffix: true,\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 userFeedId: string,\n options: FeedClientOptions = {},\n) {\n return [\n userFeedId,\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"],"names":["formatBadgeCount","count","formatTimestamp","ts","options","parsedTs","parseISO","formatted","formatDistance","Date","addSuffix","locale","toSentenceCase","string","charAt","toUpperCase","slice","renderNodeOrFallback","node","fallback","undefined","feedProviderKey","userFeedId","source","tenant","has_tenant","archived","filter","f","join"],"mappings":";;AAIO,SAASA,EAAiBC,GAAgC;AACxDA,SAAAA,IAAQ,IAAI,OAAOA;AAC5B;AAMO,SAASC,EACdC,GACAC,IAAkC,IAClC;AACI,MAAA;AACIC,UAAAA,IAAWC,EAASH,CAAE;AAMrBI,WALWC,EAAeH,GAAU,oBAAII,QAAQ;AAAA,MACrDC,WAAW;AAAA,MACXC,QAAQP,EAAQO;AAAAA,IAAAA,CACjB;AAAA,UAGS;AACHR,WAAAA;AAAAA,EACT;AACF;AAEO,SAASS,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,GACAlB,IAA6B,IAC7B;AACA,SAAO,CACLkB,GACAlB,EAAQmB,QACRnB,EAAQoB,QACRpB,EAAQqB,YACRrB,EAAQsB,QAAQ,EAEfC,OAAQC,OAAMA,KAAM,IAAuB,EAC3CC,KAAK,GAAG;AACb;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["import { FeedClientOptions } from \"@knocklabs/client\";\nimport { parseISO, intlFormatDistance } 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 userFeedId: string,\n options: FeedClientOptions = {},\n) {\n return [\n userFeedId,\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"],"names":["formatBadgeCount","count","formatTimestamp","ts","options","parsedTs","parseISO","intlFormatDistance","toSentenceCase","string","renderNodeOrFallback","node","fallback","feedProviderKey","userFeedId","f"],"mappings":";AAIO,SAASA,EAAiBC,GAAgC;AACxD,SAAAA,IAAQ,IAAI,OAAOA;AAC5B;AAMO,SAASC,EACdC,GACAC,IAAkC,IAClC;AACI,MAAA;AACI,UAAAC,IAAWC,EAASH,CAAE;AAKrB,WAJWI,EAAmBF,GAAU,oBAAI,QAAQ;AAAA,MACzD,QAAQD,EAAQ;AAAA,IAAA,CACjB;AAAA,UAGS;AACH,WAAAD;AAAA,EACT;AACF;AAEO,SAASK,EAAeC,GAAwB;AAC9C,SAAAA,EAAO,OAAO,CAAC,EAAE,gBAAgBA,EAAO,MAAM,CAAC;AACxD;AAEgB,SAAAC,EAAqBC,GAAiBC,GAAqB;AAClE,SAAAD,MAAS,SAAYA,IAAOC;AACrC;AAMO,SAASC,EACdC,GACAV,IAA6B,IAC7B;AACO,SAAA;AAAA,IACLU;AAAA,IACAV,EAAQ;AAAA,IACRA,EAAQ;AAAA,IACRA,EAAQ;AAAA,IACRA,EAAQ;AAAA,EACV,EACG,OAAO,CAACW,MAAMA,KAAM,IAAuB,EAC3C,KAAK,GAAG;AACb;"}
@@ -1,23 +1,32 @@
1
1
  import { jsx as u } from "react/jsx-runtime";
2
2
  import * as n from "react";
3
3
  import d from "zustand";
4
- import f from "../hooks/useNotifications.js";
5
- import { feedProviderKey as a } from "../../core/utils.js";
6
- import { useKnockClient as k } from "../../core/context/KnockProvider.js";
4
+ import { useKnockClient as f } from "../../core/context/KnockProvider.js";
7
5
  import "@knocklabs/client";
8
- const i = n.createContext(null), F = ({
6
+ import { feedProviderKey as a } from "../../core/utils.js";
7
+ import k from "../hooks/useNotifications.js";
8
+ const i = n.createContext(
9
+ null
10
+ ), F = ({
9
11
  feedId: e,
10
12
  children: c,
11
13
  defaultFeedOptions: o = {},
12
14
  colorMode: s = "light"
13
15
  }) => {
14
- const t = k(), r = f(t, e, o), m = d(r.store);
15
- return /* @__PURE__ */ u(i.Provider, { value: {
16
- knock: t,
17
- feedClient: r,
18
- useFeedStore: m,
19
- colorMode: s
20
- }, children: c }, a(e, o));
16
+ const t = f(), r = k(t, e, o), m = d(r.store);
17
+ return /* @__PURE__ */ u(
18
+ i.Provider,
19
+ {
20
+ value: {
21
+ knock: t,
22
+ feedClient: r,
23
+ useFeedStore: m,
24
+ colorMode: s
25
+ },
26
+ children: c
27
+ },
28
+ a(e, o)
29
+ );
21
30
  }, P = () => {
22
31
  const e = n.useContext(i);
23
32
  if (e === void 0)
@@ -1 +1 @@
1
- {"version":3,"file":"KnockFeedProvider.js","sources":["../../../../../src/modules/feed/context/KnockFeedProvider.tsx"],"sourcesContent":["import * as React from \"react\";\nimport Knock, {\n Feed,\n FeedClientOptions,\n FeedStoreState,\n} from \"@knocklabs/client\";\nimport create, { StoreApi, UseStore } from \"zustand\";\n\nimport { ColorMode } from \"../../core/constants\";\nimport useNotifications from \"../hooks/useNotifications\";\nimport { feedProviderKey } from \"../../core/utils\";\nimport { useKnockClient } from \"../../core\";\n\nexport interface KnockFeedProviderState {\n knock: Knock;\n feedClient: Feed;\n useFeedStore: UseStore<FeedStoreState>;\n colorMode: ColorMode;\n}\n\nconst FeedStateContext = React.createContext<KnockFeedProviderState | null>(\n null,\n);\n\nexport interface KnockFeedProviderProps {\n // Feed props\n feedId: string;\n\n // Extra options\n children?: React.ReactElement;\n colorMode?: ColorMode;\n\n // Feed client options\n defaultFeedOptions?: FeedClientOptions;\n}\n\nexport const KnockFeedProvider: React.FC<KnockFeedProviderProps> = ({\n feedId,\n children,\n defaultFeedOptions = {},\n colorMode = \"light\",\n}) => {\n const knock = useKnockClient();\n\n const feedClient = useNotifications(knock, feedId, defaultFeedOptions);\n const useFeedStore = create(feedClient.store as StoreApi<FeedStoreState>);\n\n return (\n <FeedStateContext.Provider\n key={feedProviderKey(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 if (context === undefined) {\n throw new Error(\"useKnockFeed must be used within a KnockFeedProvider\");\n }\n return context as KnockFeedProviderState;\n};\n"],"names":["FeedStateContext","React","createContext","KnockFeedProvider","feedId","children","defaultFeedOptions","colorMode","knock","useKnockClient","feedClient","useNotifications","useFeedStore","create","store","jsx","feedProviderKey","useKnockFeed","context","useContext","undefined","Error"],"mappings":";;;;;;;AAoBA,MAAMA,IAAmBC,EAAMC,cAC7B,IACF,GAcaC,IAAsDA,CAAC;AAAA,EAClEC,QAAAA;AAAAA,EACAC,UAAAA;AAAAA,EACAC,oBAAAA,IAAqB,CAAC;AAAA,EACtBC,WAAAA,IAAY;AACd,MAAM;AACJ,QAAMC,IAAQC,KAERC,IAAaC,EAAiBH,GAAOJ,GAAQE,CAAkB,GAC/DM,IAAeC,EAAOH,EAAWI,KAAkC;AAEzE,SACG,gBAAAC,EAAAf,EAAiB,UAAjB,EAEC,OAAO;AAAA,IACLQ,OAAAA;AAAAA,IACAE,YAAAA;AAAAA,IACAE,cAAAA;AAAAA,IACAL,WAAAA;AAAAA,EAGDF,GAAAA,UAAAA,EAAAA,GARIW,EAAgBZ,GAAQE,CAAkB,CASjD;AAEJ,GAEaW,IAAeA,MAA8B;AAClDC,QAAAA,IAAUjB,EAAMkB,WAAWnB,CAAgB;AACjD,MAAIkB,MAAYE;AACR,UAAA,IAAIC,MAAM,sDAAsD;AAEjEH,SAAAA;AACT;"}
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 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<KnockFeedProviderState | null>(\n null,\n);\n\nexport interface KnockFeedProviderProps {\n // Feed props\n feedId: string;\n\n // Extra options\n children?: React.ReactElement;\n colorMode?: ColorMode;\n\n // Feed client options\n defaultFeedOptions?: FeedClientOptions;\n}\n\nexport const KnockFeedProvider: React.FC<KnockFeedProviderProps> = ({\n feedId,\n children,\n defaultFeedOptions = {},\n colorMode = \"light\",\n}) => {\n const knock = useKnockClient();\n const feedClient = useNotifications(knock, feedId, defaultFeedOptions);\n const useFeedStore = create<FeedStoreState>(feedClient.store);\n\n return (\n <FeedStateContext.Provider\n key={feedProviderKey(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 if (context === undefined) {\n throw new Error(\"useKnockFeed must be used within a KnockFeedProvider\");\n }\n return context as KnockFeedProviderState;\n};\n"],"names":["FeedStateContext","React","KnockFeedProvider","feedId","children","defaultFeedOptions","colorMode","knock","useKnockClient","feedClient","useNotifications","useFeedStore","create","jsx","feedProviderKey","useKnockFeed","context"],"mappings":";;;;;;;AAoBA,MAAMA,IAAmBC,EAAM;AAAA,EAC7B;AACF,GAcaC,IAAsD,CAAC;AAAA,EAClE,QAAAC;AAAA,EACA,UAAAC;AAAA,EACA,oBAAAC,IAAqB,CAAC;AAAA,EACtB,WAAAC,IAAY;AACd,MAAM;AACJ,QAAMC,IAAQC,KACRC,IAAaC,EAAiBH,GAAOJ,GAAQE,CAAkB,GAC/DM,IAAeC,EAAuBH,EAAW,KAAK;AAG1D,SAAA,gBAAAI;AAAA,IAACb,EAAiB;AAAA,IAAjB;AAAA,MAEC,OAAO;AAAA,QACL,OAAAO;AAAA,QACA,YAAAE;AAAA,QACA,cAAAE;AAAA,QACA,WAAAL;AAAA,MACF;AAAA,MAEC,UAAAF;AAAA,IAAA;AAAA,IARIU,EAAgBX,GAAQE,CAAkB;AAAA,EAAA;AAWrD,GAEaU,IAAe,MAA8B;AAClD,QAAAC,IAAUf,EAAM,WAAWD,CAAgB;AACjD,MAAIgB,MAAY;AACR,UAAA,IAAI,MAAM,sDAAsD;AAEjE,SAAAA;AACT;"}
@@ -12,10 +12,7 @@ function l(e) {
12
12
  n.error || a(n.body), t(!1);
13
13
  }
14
14
  r();
15
- }, []), {
16
- settings: i,
17
- loading: c
18
- };
15
+ }, []), { settings: i, loading: c };
19
16
  }
20
17
  export {
21
18
  l as default
@@ -1 +1 @@
1
- {"version":3,"file":"useFeedSettings.js","sources":["../../../../../src/modules/feed/hooks/useFeedSettings.ts"],"sourcesContent":["import { Feed } from \"@knocklabs/client\";\nimport { useEffect, useState } from \"react\";\n\nexport type FeedSettings = {\n features: {\n branding_required: boolean;\n };\n};\n\nfunction useFeedSettings(feedClient: Feed): {\n settings: FeedSettings | null;\n loading: boolean;\n} {\n const [settings, setSettings] = useState(null);\n const [isLoading, setIsLoading] = useState(false);\n\n // TODO: consider moving this into the feed client and into the feed store state when\n // we're using this in other areas of the feed\n useEffect(() => {\n async function getSettings() {\n const knock = feedClient.knock;\n const apiClient = knock.client();\n const feedSettingsPath = `/v1/users/${knock.userId}/feeds/${feedClient.feedId}/settings`;\n setIsLoading(true);\n\n const response = await apiClient.makeRequest({\n method: \"GET\",\n url: feedSettingsPath,\n });\n\n if (!response.error) {\n setSettings(response.body);\n }\n\n setIsLoading(false);\n }\n\n getSettings();\n }, []);\n\n return { settings, loading: isLoading };\n}\n\nexport default useFeedSettings;\n"],"names":["useFeedSettings","feedClient","settings","setSettings","useState","isLoading","setIsLoading","useEffect","getSettings","knock","apiClient","client","feedSettingsPath","userId","feedId","response","makeRequest","method","url","error","body","loading"],"mappings":";AASA,SAASA,EAAgBC,GAGvB;AACA,QAAM,CAACC,GAAUC,CAAW,IAAIC,EAAS,IAAI,GACvC,CAACC,GAAWC,CAAY,IAAIF,EAAS,EAAK;AAIhDG,SAAAA,EAAU,MAAM;AACd,mBAAeC,IAAc;AAC3B,YAAMC,IAAQR,EAAWQ,OACnBC,IAAYD,EAAME,UAClBC,IAAoB,aAAYH,EAAMI,MAAO,UAASZ,EAAWa,MAAO;AAC9ER,MAAAA,EAAa,EAAI;AAEXS,YAAAA,IAAW,MAAML,EAAUM,YAAY;AAAA,QAC3CC,QAAQ;AAAA,QACRC,KAAKN;AAAAA,MAAAA,CACN;AAEG,MAACG,EAASI,SACZhB,EAAYY,EAASK,IAAI,GAG3Bd,EAAa,EAAK;AAAA,IACpB;AAEY,IAAAE;EACd,GAAG,CAAE,CAAA,GAEE;AAAA,IAAEN,UAAAA;AAAAA,IAAUmB,SAAShB;AAAAA,EAAAA;AAC9B;"}
1
+ {"version":3,"file":"useFeedSettings.js","sources":["../../../../../src/modules/feed/hooks/useFeedSettings.ts"],"sourcesContent":["import { Feed } from \"@knocklabs/client\";\nimport { useEffect, useState } from \"react\";\n\nexport type FeedSettings = {\n features: {\n branding_required: boolean;\n };\n};\n\nfunction useFeedSettings(feedClient: Feed): {\n settings: FeedSettings | null;\n loading: boolean;\n} {\n const [settings, setSettings] = useState(null);\n const [isLoading, setIsLoading] = useState(false);\n\n // TODO: consider moving this into the feed client and into the feed store state when\n // we're using this in other areas of the feed\n useEffect(() => {\n async function getSettings() {\n const knock = feedClient.knock;\n const apiClient = knock.client();\n const feedSettingsPath = `/v1/users/${knock.userId}/feeds/${feedClient.feedId}/settings`;\n setIsLoading(true);\n\n const response = await apiClient.makeRequest({\n method: \"GET\",\n url: feedSettingsPath,\n });\n\n if (!response.error) {\n setSettings(response.body);\n }\n\n setIsLoading(false);\n }\n\n getSettings();\n }, []);\n\n return { settings, loading: isLoading };\n}\n\nexport default useFeedSettings;\n"],"names":["useFeedSettings","feedClient","settings","setSettings","useState","isLoading","setIsLoading","useEffect","getSettings","knock","apiClient","feedSettingsPath","response"],"mappings":";AASA,SAASA,EAAgBC,GAGvB;AACA,QAAM,CAACC,GAAUC,CAAW,IAAIC,EAAS,IAAI,GACvC,CAACC,GAAWC,CAAY,IAAIF,EAAS,EAAK;AAIhD,SAAAG,EAAU,MAAM;AACd,mBAAeC,IAAc;AAC3B,YAAMC,IAAQR,EAAW,OACnBS,IAAYD,EAAM,UAClBE,IAAmB,aAAaF,EAAM,MAAM,UAAUR,EAAW,MAAM;AAC7E,MAAAK,EAAa,EAAI;AAEX,YAAAM,IAAW,MAAMF,EAAU,YAAY;AAAA,QAC3C,QAAQ;AAAA,QACR,KAAKC;AAAA,MAAA,CACN;AAEG,MAACC,EAAS,SACZT,EAAYS,EAAS,IAAI,GAG3BN,EAAa,EAAK;AAAA,IACpB;AAEY,IAAAE;EACd,GAAG,CAAE,CAAA,GAEE,EAAE,UAAAN,GAAU,SAASG;AAC9B;"}
@@ -1,13 +1,20 @@
1
- import { useRef as a, useMemo as i } from "react";
2
- function c(n, u, e = {}) {
3
- const t = a();
4
- return i(() => {
5
- t.current && t.current.teardown();
6
- const r = n.feeds.initialize(u, e);
1
+ import { useRef as u, useMemo as s } from "react";
2
+ function a(i, n, e = {}) {
3
+ const t = u();
4
+ return s(() => {
5
+ t.current && t.current.dispose();
6
+ const r = i.feeds.initialize(n, e);
7
7
  return r.listenForUpdates(), t.current = r, r;
8
- }, [n, u, e.source, e.tenant, e.has_tenant, e.archived]);
8
+ }, [
9
+ i,
10
+ n,
11
+ e.source,
12
+ e.tenant,
13
+ e.has_tenant,
14
+ e.archived
15
+ ]);
9
16
  }
10
17
  export {
11
- c as default
18
+ a as default
12
19
  };
13
20
  //# 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 feedId: string,\n options: FeedClientOptions = {},\n) {\n const feedClientRef = useRef<Feed | null>();\n\n return useMemo(() => {\n if (feedClientRef.current) feedClientRef.current.teardown();\n\n const feedClient = knock.feeds.initialize(feedId, options);\n\n feedClient.listenForUpdates();\n feedClientRef.current = feedClient;\n\n return feedClient;\n }, [\n knock,\n feedId,\n options.source,\n options.tenant,\n options.has_tenant,\n options.archived,\n ]);\n}\n\nexport default useNotifications;\n"],"names":["useNotifications","knock","feedId","options","feedClientRef","useRef","useMemo","current","teardown","feedClient","feeds","initialize","listenForUpdates","source","tenant","has_tenant","archived"],"mappings":";AAGA,SAASA,EACPC,GACAC,GACAC,IAA6B,CAAA,GAC7B;AACA,QAAMC,IAAgBC;AAEtB,SAAOC,EAAQ,MAAM;AACnB,IAAIF,EAAcG,WAASH,EAAcG,QAAQC;AAEjD,UAAMC,IAAaR,EAAMS,MAAMC,WAAWT,GAAQC,CAAO;AAEzDM,WAAAA,EAAWG,iBAAiB,GAC5BR,EAAcG,UAAUE,GAEjBA;AAAAA,EACN,GAAA,CACDR,GACAC,GACAC,EAAQU,QACRV,EAAQW,QACRX,EAAQY,YACRZ,EAAQa,QAAQ,CACjB;AACH;"}
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 const feedClient = knock.feeds.initialize(feedChannelId, options);\n\n feedClient.listenForUpdates();\n feedClientRef.current = feedClient;\n\n return feedClient;\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","feedClient"],"mappings":";AAGA,SAASA,EACPC,GACAC,GACAC,IAA6B,CAAA,GAC7B;AACA,QAAMC,IAAgBC;AAEtB,SAAOC,EAAQ,MAAM;AACnB,IAAIF,EAAc,WAChBA,EAAc,QAAQ;AAGxB,UAAMG,IAAaN,EAAM,MAAM,WAAWC,GAAeC,CAAO;AAEhE,WAAAI,EAAW,iBAAiB,GAC5BH,EAAc,UAAUG,GAEjBA;AAAA,EAAA,GACN;AAAA,IACDN;AAAA,IACAC;AAAA,IACAC,EAAQ;AAAA,IACRA,EAAQ;AAAA,IACRA,EAAQ;AAAA,IACRA,EAAQ;AAAA,EAAA,CACT;AACH;"}
@@ -1 +1 @@
1
- {"version":3,"file":"KnockI18nProvider.js","sources":["../../../../../src/modules/i18n/context/KnockI18nProvider.tsx"],"sourcesContent":["import React from \"react\";\nimport { locales, I18nContent } from \"../languages\";\n\nexport const I18nContext = React.createContext<I18nContent>(locales.en);\n\ninterface KnockI18nProviderProps {\n i18n?: I18nContent;\n children: JSX.Element | undefined;\n}\n\nexport function KnockI18nProvider({\n i18n = locales.en,\n ...props\n}: KnockI18nProviderProps) {\n return <I18nContext.Provider {...props} value={i18n} />;\n}\n"],"names":["I18nContext","React","createContext","locales","en","KnockI18nProvider","i18n","props"],"mappings":";;;AAGO,MAAMA,IAAcC,EAAMC,cAA2BC,EAAQC,EAAE;AAO/D,SAASC,EAAkB;AAAA,EAChCC,MAAAA,IAAOH,EAAQC;AAAAA,EACf,GAAGG;AACmB,GAAG;AACzB,2BAAQP,EAAY,UAAZ,EAAyBO,GAAAA,GAAO,OAAOD,EAAQ,CAAA;AACzD;"}
1
+ {"version":3,"file":"KnockI18nProvider.js","sources":["../../../../../src/modules/i18n/context/KnockI18nProvider.tsx"],"sourcesContent":["import React from \"react\";\nimport { locales, I18nContent } from \"../languages\";\n\nexport const I18nContext = React.createContext<I18nContent>(locales.en);\n\ninterface KnockI18nProviderProps {\n i18n?: I18nContent;\n children: JSX.Element | undefined;\n}\n\nexport function KnockI18nProvider({\n i18n = locales.en,\n ...props\n}: KnockI18nProviderProps) {\n return <I18nContext.Provider {...props} value={i18n} />;\n}\n"],"names":["I18nContext","React","locales","KnockI18nProvider","i18n","props"],"mappings":";;;AAGO,MAAMA,IAAcC,EAAM,cAA2BC,EAAQ,EAAE;AAO/D,SAASC,EAAkB;AAAA,EAChC,MAAAC,IAAOF,EAAQ;AAAA,EACf,GAAGG;AACL,GAA2B;AACzB,2BAAQL,EAAY,UAAZ,EAAsB,GAAGK,GAAO,OAAOD,EAAM,CAAA;AACvD;"}
@@ -1,19 +1,14 @@
1
- import { useContext as e } from "react";
2
- import * as n from "date-fns/locale";
1
+ import { useContext as r } from "react";
3
2
  import { locales as s } from "../languages/index.js";
4
- import { I18nContext as a } from "../context/KnockI18nProvider.js";
5
- function c() {
6
- const {
7
- translations: r,
8
- locale: t
9
- } = e(a);
3
+ import { I18nContext as e } from "../context/KnockI18nProvider.js";
4
+ function m() {
5
+ const { translations: o, locale: n } = r(e);
10
6
  return {
11
- locale: t,
12
- t: (o) => r[o] || s.en.translations[o],
13
- dateFnsLocale: () => t in n ? n[t] : n.enUS
7
+ locale: n,
8
+ t: (t) => o[t] || s.en.translations[t]
14
9
  };
15
10
  }
16
11
  export {
17
- c as useTranslations
12
+ m as useTranslations
18
13
  };
19
14
  //# sourceMappingURL=useTranslations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTranslations.js","sources":["../../../../../src/modules/i18n/hooks/useTranslations.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { Locale as DateFnLocale } from \"date-fns\";\nimport * as dateFnsLocales from \"date-fns/locale\";\nimport { I18nContent, locales } from \"../languages\";\nimport { I18nContext } from \"../context/KnockI18nProvider\";\n\nexport function useTranslations() {\n const { translations, locale } = useContext<I18nContent>(I18nContext);\n\n return {\n locale,\n t: (key: keyof typeof translations) => {\n // We always use english as the default translation when a key doesn't exist\n return translations[key] || locales.en.translations[key];\n },\n dateFnsLocale: (): DateFnLocale => {\n return locale in dateFnsLocales\n ? dateFnsLocales[locale as keyof typeof dateFnsLocales]\n : dateFnsLocales.enUS;\n },\n };\n}\n"],"names":["useTranslations","translations","locale","useContext","I18nContext","t","key","locales","en","dateFnsLocale","dateFnsLocales","enUS"],"mappings":";;;;AAMO,SAASA,IAAkB;AAC1B,QAAA;AAAA,IAAEC,cAAAA;AAAAA,IAAcC,QAAAA;AAAAA,EAAAA,IAAWC,EAAwBC,CAAW;AAE7D,SAAA;AAAA,IACLF,QAAAA;AAAAA,IACAG,GAAGA,CAACC,MAEKL,EAAaK,CAAG,KAAKC,EAAQC,GAAGP,aAAaK,CAAG;AAAA,IAEzDG,eAAeA,MACNP,KAAUQ,IACbA,EAAeR,CAAqC,IACpDQ,EAAeC;AAAAA,EACrB;AAEJ;"}
1
+ {"version":3,"file":"useTranslations.js","sources":["../../../../../src/modules/i18n/hooks/useTranslations.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { I18nContent, locales } from \"../languages\";\nimport { I18nContext } from \"../context/KnockI18nProvider\";\n\nexport function useTranslations() {\n const { translations, locale } = useContext<I18nContent>(I18nContext);\n\n return {\n locale,\n t: (key: keyof typeof translations) => {\n // We always use english as the default translation when a key doesn't exist\n return translations[key] || locales.en.translations[key];\n },\n };\n}\n"],"names":["useTranslations","translations","locale","useContext","I18nContext","key","locales"],"mappings":";;;AAIO,SAASA,IAAkB;AAChC,QAAM,EAAE,cAAAC,GAAc,QAAAC,EAAO,IAAIC,EAAwBC,CAAW;AAE7D,SAAA;AAAA,IACL,QAAAF;AAAA,IACA,GAAG,CAACG,MAEKJ,EAAaI,CAAG,KAAKC,EAAQ,GAAG,aAAaD,CAAG;AAAA,EACzD;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"de.js","sources":["../../../../../src/modules/i18n/languages/de.ts"],"sourcesContent":["import { I18nContent } from \".\";\n\nconst de: I18nContent = {\n translations: {\n archiveNotification: \"Benachrichtigung archivieren\",\n markAllAsRead: \"Alle als gelesen markieren\",\n notifications: \"Benachrichtigungen\",\n emptyFeedTitle: \"Noch keine Benachrichtigungen\",\n emptyFeedBody:\n \"Wir werden dich benachrichtigen, sobald wir etwas Neues für dich haben.\",\n all: \"Alle\",\n unread: \"Ungelesen\",\n read: \"Gelesen\",\n unseen: \"Ungesehen\",\n },\n locale: \"de\",\n};\n\nexport default de;\n"],"names":["de","translations","archiveNotification","markAllAsRead","notifications","emptyFeedTitle","emptyFeedBody","all","unread","read","unseen","locale"],"mappings":"AAEA,MAAMA,IAAkB;AAAA,EACtBC,cAAc;AAAA,IACZC,qBAAqB;AAAA,IACrBC,eAAe;AAAA,IACfC,eAAe;AAAA,IACfC,gBAAgB;AAAA,IAChBC,eACE;AAAA,IACFC,KAAK;AAAA,IACLC,QAAQ;AAAA,IACRC,MAAM;AAAA,IACNC,QAAQ;AAAA,EACV;AAAA,EACAC,QAAQ;AACV;"}
1
+ {"version":3,"file":"de.js","sources":["../../../../../src/modules/i18n/languages/de.ts"],"sourcesContent":["import { I18nContent } from \".\";\n\nconst de: I18nContent = {\n translations: {\n archiveNotification: \"Benachrichtigung archivieren\",\n markAllAsRead: \"Alle als gelesen markieren\",\n notifications: \"Benachrichtigungen\",\n emptyFeedTitle: \"Noch keine Benachrichtigungen\",\n emptyFeedBody:\n \"Wir werden dich benachrichtigen, sobald wir etwas Neues für dich haben.\",\n all: \"Alle\",\n unread: \"Ungelesen\",\n read: \"Gelesen\",\n unseen: \"Ungesehen\",\n },\n locale: \"de\",\n};\n\nexport default de;\n"],"names":["de"],"mappings":"AAEA,MAAMA,IAAkB;AAAA,EACtB,cAAc;AAAA,IACZ,qBAAqB;AAAA,IACrB,eAAe;AAAA,IACf,eAAe;AAAA,IACf,gBAAgB;AAAA,IAChB,eACE;AAAA,IACF,KAAK;AAAA,IACL,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,QAAQ;AAAA,EACV;AAAA,EACA,QAAQ;AACV;"}
@@ -1 +1 @@
1
- {"version":3,"file":"en.js","sources":["../../../../../src/modules/i18n/languages/en.ts"],"sourcesContent":["import { I18nContent } from \".\";\n\nconst en: I18nContent = {\n translations: {\n archiveNotification: \"Archive this notification\",\n markAllAsRead: \"Mark all as read\",\n notifications: \"Notifications\",\n emptyFeedTitle: \"No notifications yet\",\n emptyFeedBody: \"We'll let you know when we've got something new for you.\",\n all: \"All\",\n unread: \"Unread\",\n read: \"Read\",\n unseen: \"Unseen\",\n },\n locale: \"en\",\n};\n\nexport default en;\n"],"names":["en","translations","archiveNotification","markAllAsRead","notifications","emptyFeedTitle","emptyFeedBody","all","unread","read","unseen","locale"],"mappings":"AAEA,MAAMA,IAAkB;AAAA,EACtBC,cAAc;AAAA,IACZC,qBAAqB;AAAA,IACrBC,eAAe;AAAA,IACfC,eAAe;AAAA,IACfC,gBAAgB;AAAA,IAChBC,eAAe;AAAA,IACfC,KAAK;AAAA,IACLC,QAAQ;AAAA,IACRC,MAAM;AAAA,IACNC,QAAQ;AAAA,EACV;AAAA,EACAC,QAAQ;AACV;"}
1
+ {"version":3,"file":"en.js","sources":["../../../../../src/modules/i18n/languages/en.ts"],"sourcesContent":["import { I18nContent } from \".\";\n\nconst en: I18nContent = {\n translations: {\n archiveNotification: \"Archive this notification\",\n markAllAsRead: \"Mark all as read\",\n notifications: \"Notifications\",\n emptyFeedTitle: \"No notifications yet\",\n emptyFeedBody: \"We'll let you know when we've got something new for you.\",\n all: \"All\",\n unread: \"Unread\",\n read: \"Read\",\n unseen: \"Unseen\",\n },\n locale: \"en\",\n};\n\nexport default en;\n"],"names":["en"],"mappings":"AAEA,MAAMA,IAAkB;AAAA,EACtB,cAAc;AAAA,IACZ,qBAAqB;AAAA,IACrB,eAAe;AAAA,IACf,eAAe;AAAA,IACf,gBAAgB;AAAA,IAChB,eAAe;AAAA,IACf,KAAK;AAAA,IACL,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,QAAQ;AAAA,EACV;AAAA,EACA,QAAQ;AACV;"}
@@ -1,9 +1,6 @@
1
1
  import o from "./en.js";
2
2
  import r from "./de.js";
3
- const t = {
4
- en: o,
5
- de: r
6
- };
3
+ const t = { en: o, de: r };
7
4
  export {
8
5
  t as locales
9
6
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../../src/modules/i18n/languages/index.ts"],"sourcesContent":["import en from \"./en\";\nimport de from \"./de\";\n\nexport interface Translations {\n readonly emptyFeedTitle: string;\n readonly emptyFeedBody: string;\n readonly notifications: string;\n readonly poweredBy: string;\n readonly markAllAsRead: string;\n readonly archiveNotification: string;\n readonly all: string;\n readonly unread: string;\n readonly read: string;\n readonly unseen: string;\n}\n\nexport interface I18nContent {\n readonly translations: Partial<Translations>;\n readonly locale: string;\n}\n\nexport const locales = { en, de };\n"],"names":["locales","en","de"],"mappings":";;AAqBO,MAAMA,IAAU;AAAA,EAAEC,IAAAA;AAAAA,EAAIC,IAAAA;AAAG;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/modules/i18n/languages/index.ts"],"sourcesContent":["import en from \"./en\";\nimport de from \"./de\";\n\nexport interface Translations {\n readonly emptyFeedTitle: string;\n readonly emptyFeedBody: string;\n readonly notifications: string;\n readonly poweredBy: string;\n readonly markAllAsRead: string;\n readonly archiveNotification: string;\n readonly all: string;\n readonly unread: string;\n readonly read: string;\n readonly unseen: string;\n}\n\nexport interface I18nContent {\n readonly translations: Partial<Translations>;\n readonly locale: string;\n}\n\nexport const locales = { en, de };\n"],"names":["locales","en","de"],"mappings":";;AAqBa,MAAAA,IAAU,EAAE,IAAAC,GAAI,IAAAC,EAAG;"}
@@ -1,5 +1,5 @@
1
+ import Knock, { AuthenticateOptions, LogLevel } from "@knocklabs/client";
1
2
  import * as React from "react";
2
- import Knock from "@knocklabs/client";
3
3
  import { I18nContent } from "../../i18n";
4
4
  export interface KnockProviderState {
5
5
  knock: Knock;
@@ -9,8 +9,11 @@ export interface KnockProviderProps {
9
9
  host?: string;
10
10
  userId: string;
11
11
  userToken?: string;
12
+ onUserTokenExpiring?: AuthenticateOptions["onUserTokenExpiring"];
13
+ timeBeforeExpirationInMs?: AuthenticateOptions["timeBeforeExpirationInMs"];
12
14
  children?: React.ReactElement;
13
15
  i18n?: I18nContent;
16
+ logLevel?: LogLevel;
14
17
  }
15
18
  export declare const KnockProvider: React.FC<KnockProviderProps>;
16
19
  export declare const useKnockClient: () => Knock;
@@ -1 +1 @@
1
- {"version":3,"file":"KnockProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,MAAM,mBAAmB,CAAC;AAGtC,OAAO,EAAqB,WAAW,EAAE,MAAM,YAAY,CAAC;AAE5D,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,KAAK,CAAC;CACd;AAMD,MAAM,WAAW,kBAAkB;IAEjC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IAGnB,QAAQ,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;IAG9B,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAqBtD,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,KAMjC,CAAC"}
1
+ {"version":3,"file":"KnockProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAqB,MAAM,YAAY,CAAC;AAG5D,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,KAAK,CAAC;CACd;AAMD,MAAM,WAAW,kBAAkB;IAEjC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mBAAmB,CAAC,EAAE,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;IACjE,wBAAwB,CAAC,EAAE,mBAAmB,CAAC,0BAA0B,CAAC,CAAC;IAG3E,QAAQ,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;IAG9B,IAAI,CAAC,EAAE,WAAW,CAAC;IAEnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAwCtD,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,KAMjC,CAAC"}
@@ -1,4 +1,4 @@
1
- import Knock, { KnockOptions } from "@knocklabs/client";
2
- declare function useAuthenticatedKnockClient(apiKey: string, userId: string, userToken: string | undefined, options?: KnockOptions): Knock;
1
+ import Knock, { AuthenticateOptions, KnockOptions } from "@knocklabs/client";
2
+ declare function useAuthenticatedKnockClient(apiKey: string, userId: string, userToken?: string, options?: KnockOptions & AuthenticateOptions): Knock;
3
3
  export default useAuthenticatedKnockClient;
4
4
  //# sourceMappingURL=useAuthenticatedKnockClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAuthenticatedKnockClient.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAExD,iBAAS,2BAA2B,CAClC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,OAAO,GAAE,YAAiB,SAa3B;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;AAe7E,iBAAS,2BAA2B,CAClC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,GAAE,YAAY,GAAG,mBAAwB,SA4BjD;AAED,eAAe,2BAA2B,CAAC"}
@@ -1,9 +1,8 @@
1
1
  import { FeedClientOptions } from "@knocklabs/client";
2
- import { Locale } from "date-fns";
3
2
  import { ReactNode } from "react";
4
3
  export declare function formatBadgeCount(count: number): string | number;
5
4
  type FormatTimestampOptions = {
6
- locale?: Locale;
5
+ locale?: string | string[];
7
6
  };
8
7
  export declare function formatTimestamp(ts: string, options?: FormatTimestampOptions): string;
9
8
  export declare function toSentenceCase(string: string): 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;AACtD,OAAO,EAA4B,MAAM,EAAE,MAAM,UAAU,CAAC;AAC5D,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,CAAC;CACjB,CAAC;AAEF,wBAAgB,eAAe,CAC7B,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,sBAA2B,UAarC;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,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,iBAAsB,UAWhC"}
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,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,iBAAsB,UAWhC"}
@@ -1,11 +1,11 @@
1
- import * as React from "react";
2
1
  import Knock, { Feed, FeedClientOptions, FeedStoreState } from "@knocklabs/client";
3
- import { UseStore } from "zustand";
2
+ import * as React from "react";
3
+ import { UseBoundStore } from "zustand";
4
4
  import { ColorMode } from "../../core/constants";
5
5
  export interface KnockFeedProviderState {
6
6
  knock: Knock;
7
7
  feedClient: Feed;
8
- useFeedStore: UseStore<FeedStoreState>;
8
+ useFeedStore: UseBoundStore<FeedStoreState>;
9
9
  colorMode: ColorMode;
10
10
  }
11
11
  export interface KnockFeedProviderProps {
@@ -1 +1 @@
1
- {"version":3,"file":"KnockFeedProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/context/KnockFeedProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,EACZ,IAAI,EACJ,iBAAiB,EACjB,cAAc,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAe,EAAY,QAAQ,EAAE,MAAM,SAAS,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAKjD,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,IAAI,CAAC;IACjB,YAAY,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC;IACvC,SAAS,EAAE,SAAS,CAAC;CACtB;AAMD,MAAM,WAAW,sBAAsB;IAErC,MAAM,EAAE,MAAM,CAAC;IAGf,QAAQ,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;IAC9B,SAAS,CAAC,EAAE,SAAS,CAAC;IAGtB,kBAAkB,CAAC,EAAE,iBAAiB,CAAC;CACxC;AAED,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAwB9D,CAAC;AAEF,eAAO,MAAM,YAAY,QAAO,sBAM/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,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,QAAQ,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;IAC9B,SAAS,CAAC,EAAE,SAAS,CAAC;IAGtB,kBAAkB,CAAC,EAAE,iBAAiB,CAAC;CACxC;AAED,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAuB9D,CAAC;AAEF,eAAO,MAAM,YAAY,QAAO,sBAM/B,CAAC"}
@@ -1,4 +1,4 @@
1
1
  import Knock, { Feed, FeedClientOptions } from "@knocklabs/client";
2
- declare function useNotifications(knock: Knock, feedId: string, options?: FeedClientOptions): Feed;
2
+ declare function useNotifications(knock: Knock, feedChannelId: string, options?: FeedClientOptions): Feed;
3
3
  export default useNotifications;
4
4
  //# sourceMappingURL=useNotifications.d.ts.map
@@ -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,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,iBAAsB,QAqBhC;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;AAGnE,iBAAS,gBAAgB,CACvB,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,iBAAsB,QAuBhC;AAED,eAAe,gBAAgB,CAAC"}
@@ -1,7 +1,5 @@
1
- import { Locale as DateFnLocale } from "date-fns";
2
1
  export declare function useTranslations(): {
3
2
  locale: string;
4
3
  t: (key: keyof import("../languages").Translations) => string | undefined;
5
- dateFnsLocale: () => DateFnLocale;
6
4
  };
7
5
  //# sourceMappingURL=useTranslations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTranslations.d.ts","sourceRoot":"","sources":["../../../../../src/modules/i18n/hooks/useTranslations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,UAAU,CAAC;AAKlD,wBAAgB,eAAe;;;yBASR,YAAY;EAMlC"}
1
+ {"version":3,"file":"useTranslations.d.ts","sourceRoot":"","sources":["../../../../../src/modules/i18n/hooks/useTranslations.ts"],"names":[],"mappings":"AAIA,wBAAgB,eAAe;;;EAU9B"}
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.1.2",
5
+ "version": "0.1.4",
6
6
  "license": "MIT",
7
7
  "main": "dist/cjs/index.js",
8
8
  "module": "dist/esm/index.js",
@@ -21,11 +21,16 @@
21
21
  ],
22
22
  "scripts": {
23
23
  "clean": "rimraf dist",
24
- "dev": "tsc && vite build --watch",
24
+ "dev": "tsc && vite build --watch --emptyOutDir false",
25
25
  "build": "yarn clean && yarn build:esm && yarn build:cjs",
26
- "build:esm": "export BUILD_TARGET=esm; tsc && vite build",
27
- "build:cjs": "export BUILD_TARGET=cjs; tsc && vite build",
26
+ "build:esm": "BUILD_TARGET=esm; tsc && vite build",
27
+ "build:cjs": "BUILD_TARGET=cjs; tsc && vite build",
28
28
  "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
29
+ "format": "prettier \"src/**/*.{js,ts,tsx}\" --write",
30
+ "format:check": "prettier \"src/**/*.{js,ts,tsx}\" --check",
31
+ "test": "vitest run",
32
+ "test:watch": "vitest",
33
+ "coverage": "vitest run --coverage",
29
34
  "preview": "vite preview"
30
35
  },
31
36
  "repository": {
@@ -39,24 +44,27 @@
39
44
  "react": ">=16.8.0"
40
45
  },
41
46
  "dependencies": {
42
- "@knocklabs/client": "*",
43
- "date-fns": "^2.24.0",
44
- "zustand": "^3.5.10"
47
+ "@knocklabs/client": "workspace:^",
48
+ "date-fns": "^3.3.1",
49
+ "zustand": "^3.7.2"
45
50
  },
46
51
  "devDependencies": {
52
+ "@testing-library/react": "^14.2.0",
47
53
  "@types/react": "^18.2.37",
48
54
  "@typescript-eslint/eslint-plugin": "^6.10.0",
49
55
  "@typescript-eslint/parser": "^6.10.0",
50
56
  "@vitejs/plugin-react": "^4.2.0",
51
- "babel-plugin-date-fns": "^2.0.0",
52
57
  "eslint": "^8.53.0",
53
58
  "eslint-plugin-react-hooks": "^4.6.0",
54
59
  "eslint-plugin-react-refresh": "^0.4.4",
60
+ "jsdom": "^24.0.0",
61
+ "react": "^18.2.0",
55
62
  "rimraf": "^5.0.5",
56
63
  "rollup-plugin-execute": "^1.1.1",
57
64
  "typescript": "^5.2.2",
58
65
  "vite": "^5.0.0",
59
66
  "vite-plugin-dts": "^3.6.3",
60
- "vite-plugin-no-bundle": "^3.0.0"
67
+ "vite-plugin-no-bundle": "^3.0.0",
68
+ "vitest": "^1.2.2"
61
69
  }
62
- }
70
+ }