@knocklabs/react-core 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/esm/{index.js → index.mjs} +11 -11
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/modules/core/{constants.js → constants.mjs} +1 -1
- package/dist/esm/modules/core/constants.mjs.map +1 -0
- package/dist/esm/modules/core/context/{KnockProvider.js → KnockProvider.mjs} +3 -3
- package/dist/esm/modules/core/context/KnockProvider.mjs.map +1 -0
- package/dist/esm/modules/core/hooks/{useAuthenticatedKnockClient.js → useAuthenticatedKnockClient.mjs} +1 -1
- package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.mjs.map +1 -0
- package/dist/esm/modules/core/{utils.js → utils.mjs} +1 -1
- package/dist/esm/modules/core/utils.mjs.map +1 -0
- package/dist/esm/modules/feed/context/{KnockFeedProvider.js → KnockFeedProvider.mjs} +4 -4
- package/dist/esm/modules/feed/context/KnockFeedProvider.mjs.map +1 -0
- package/dist/esm/modules/feed/hooks/{useFeedSettings.js → useFeedSettings.mjs} +1 -1
- package/dist/esm/modules/feed/hooks/useFeedSettings.mjs.map +1 -0
- package/dist/esm/modules/feed/hooks/{useNotifications.js → useNotifications.mjs} +1 -1
- package/dist/esm/modules/feed/hooks/useNotifications.mjs.map +1 -0
- package/dist/esm/modules/i18n/context/{KnockI18nProvider.js → KnockI18nProvider.mjs} +2 -2
- package/dist/esm/modules/i18n/context/KnockI18nProvider.mjs.map +1 -0
- package/dist/esm/modules/i18n/hooks/{useTranslations.js → useTranslations.mjs} +3 -3
- package/dist/esm/modules/i18n/hooks/useTranslations.mjs.map +1 -0
- package/dist/esm/modules/i18n/languages/{de.js → de.mjs} +1 -1
- package/dist/esm/modules/i18n/languages/de.mjs.map +1 -0
- package/dist/esm/modules/i18n/languages/{en.js → en.mjs} +1 -1
- package/dist/esm/modules/i18n/languages/en.mjs.map +1 -0
- package/dist/esm/modules/i18n/languages/index.mjs +7 -0
- package/dist/esm/modules/i18n/languages/index.mjs.map +1 -0
- package/package.json +7 -6
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/modules/core/constants.js.map +0 -1
- package/dist/esm/modules/core/context/KnockProvider.js.map +0 -1
- package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.js.map +0 -1
- package/dist/esm/modules/core/utils.js.map +0 -1
- package/dist/esm/modules/feed/context/KnockFeedProvider.js.map +0 -1
- package/dist/esm/modules/feed/hooks/useFeedSettings.js.map +0 -1
- package/dist/esm/modules/feed/hooks/useNotifications.js.map +0 -1
- package/dist/esm/modules/i18n/context/KnockI18nProvider.js.map +0 -1
- package/dist/esm/modules/i18n/hooks/useTranslations.js.map +0 -1
- package/dist/esm/modules/i18n/languages/de.js.map +0 -1
- package/dist/esm/modules/i18n/languages/en.js.map +0 -1
- package/dist/esm/modules/i18n/languages/index.js +0 -7
- package/dist/esm/modules/i18n/languages/index.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { KnockProvider as r, useKnockClient as t } from "./modules/core/context/KnockProvider.
|
|
2
|
-
import { default as a } from "./modules/core/hooks/useAuthenticatedKnockClient.
|
|
3
|
-
import { FilterStatus as s } from "./modules/core/constants.
|
|
4
|
-
import { feedProviderKey as i, formatBadgeCount as m, formatTimestamp as u, renderNodeOrFallback as c, toSentenceCase as l } from "./modules/core/utils.
|
|
5
|
-
import { KnockFeedProvider as x, useKnockFeed as k } from "./modules/feed/context/KnockFeedProvider.
|
|
6
|
-
import { default as C } from "./modules/feed/hooks/useNotifications.
|
|
7
|
-
import { default as v } from "./modules/feed/hooks/useFeedSettings.
|
|
8
|
-
import { I18nContext as S, KnockI18nProvider as g } from "./modules/i18n/context/KnockI18nProvider.
|
|
9
|
-
import { useTranslations as N } from "./modules/i18n/hooks/useTranslations.
|
|
10
|
-
import { locales as b } from "./modules/i18n/languages/index.
|
|
1
|
+
import { KnockProvider as r, useKnockClient as t } from "./modules/core/context/KnockProvider.mjs";
|
|
2
|
+
import { default as a } from "./modules/core/hooks/useAuthenticatedKnockClient.mjs";
|
|
3
|
+
import { FilterStatus as s } from "./modules/core/constants.mjs";
|
|
4
|
+
import { feedProviderKey as i, formatBadgeCount as m, formatTimestamp as u, renderNodeOrFallback as c, toSentenceCase as l } from "./modules/core/utils.mjs";
|
|
5
|
+
import { KnockFeedProvider as x, useKnockFeed as k } from "./modules/feed/context/KnockFeedProvider.mjs";
|
|
6
|
+
import { default as C } from "./modules/feed/hooks/useNotifications.mjs";
|
|
7
|
+
import { default as v } from "./modules/feed/hooks/useFeedSettings.mjs";
|
|
8
|
+
import { I18nContext as S, KnockI18nProvider as g } from "./modules/i18n/context/KnockI18nProvider.mjs";
|
|
9
|
+
import { useTranslations as N } from "./modules/i18n/hooks/useTranslations.mjs";
|
|
10
|
+
import { locales as b } from "./modules/i18n/languages/index.mjs";
|
|
11
11
|
export {
|
|
12
12
|
s as FilterStatus,
|
|
13
13
|
S as I18nContext,
|
|
@@ -27,4 +27,4 @@ export {
|
|
|
27
27
|
C as useNotifications,
|
|
28
28
|
N as useTranslations
|
|
29
29
|
};
|
|
30
|
-
//# sourceMappingURL=index.
|
|
30
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.mjs","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,7 +1,7 @@
|
|
|
1
1
|
import { jsx as i } from "react/jsx-runtime";
|
|
2
2
|
import * as o from "react";
|
|
3
|
-
import { KnockI18nProvider as K } from "../../i18n/context/KnockI18nProvider.
|
|
4
|
-
import C from "../hooks/useAuthenticatedKnockClient.
|
|
3
|
+
import { KnockI18nProvider as K } from "../../i18n/context/KnockI18nProvider.mjs";
|
|
4
|
+
import C from "../hooks/useAuthenticatedKnockClient.mjs";
|
|
5
5
|
const s = o.createContext(
|
|
6
6
|
null
|
|
7
7
|
), l = ({
|
|
@@ -48,4 +48,4 @@ export {
|
|
|
48
48
|
l as KnockProvider,
|
|
49
49
|
p as useKnockClient
|
|
50
50
|
};
|
|
51
|
-
//# sourceMappingURL=KnockProvider.
|
|
51
|
+
//# sourceMappingURL=KnockProvider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnockProvider.mjs","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, { AuthenticateOptions, LogLevel } from \"@knocklabs/client\";\nimport * as React from \"react\";\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;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuthenticatedKnockClient.mjs","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;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","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,10 +1,10 @@
|
|
|
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 { useKnockClient as f } from "../../core/context/KnockProvider.
|
|
4
|
+
import { useKnockClient as f } from "../../core/context/KnockProvider.mjs";
|
|
5
5
|
import "@knocklabs/client";
|
|
6
|
-
import { feedProviderKey as a } from "../../core/utils.
|
|
7
|
-
import k from "../hooks/useNotifications.
|
|
6
|
+
import { feedProviderKey as a } from "../../core/utils.mjs";
|
|
7
|
+
import k from "../hooks/useNotifications.mjs";
|
|
8
8
|
const i = n.createContext(
|
|
9
9
|
null
|
|
10
10
|
), F = ({
|
|
@@ -37,4 +37,4 @@ export {
|
|
|
37
37
|
F as KnockFeedProvider,
|
|
38
38
|
P as useKnockFeed
|
|
39
39
|
};
|
|
40
|
-
//# sourceMappingURL=KnockFeedProvider.
|
|
40
|
+
//# sourceMappingURL=KnockFeedProvider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnockFeedProvider.mjs","sources":["../../../../../src/modules/feed/context/KnockFeedProvider.tsx"],"sourcesContent":["import Knock, {\n Feed,\n FeedClientOptions,\n FeedStoreState,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport 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;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFeedSettings.mjs","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;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNotifications.mjs","sources":["../../../../../src/modules/feed/hooks/useNotifications.ts"],"sourcesContent":["import Knock, { Feed, FeedClientOptions } from \"@knocklabs/client\";\nimport { useMemo, useRef } from \"react\";\n\nfunction useNotifications(\n knock: Knock,\n feedChannelId: string,\n options: FeedClientOptions = {},\n) {\n const feedClientRef = useRef<Feed | null>();\n\n return useMemo(() => {\n if (feedClientRef.current) {\n feedClientRef.current.dispose();\n }\n\n 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,6 +1,6 @@
|
|
|
1
1
|
import { jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import n from "react";
|
|
3
|
-
import { locales as o } from "../languages/index.
|
|
3
|
+
import { locales as o } from "../languages/index.mjs";
|
|
4
4
|
const c = n.createContext(o.en);
|
|
5
5
|
function f({
|
|
6
6
|
i18n: e = o.en,
|
|
@@ -12,4 +12,4 @@ export {
|
|
|
12
12
|
c as I18nContext,
|
|
13
13
|
f as KnockI18nProvider
|
|
14
14
|
};
|
|
15
|
-
//# sourceMappingURL=KnockI18nProvider.
|
|
15
|
+
//# sourceMappingURL=KnockI18nProvider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnockI18nProvider.mjs","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,6 +1,6 @@
|
|
|
1
1
|
import { useContext as r } from "react";
|
|
2
|
-
import { locales as s } from "../languages/index.
|
|
3
|
-
import { I18nContext as e } from "../context/KnockI18nProvider.
|
|
2
|
+
import { locales as s } from "../languages/index.mjs";
|
|
3
|
+
import { I18nContext as e } from "../context/KnockI18nProvider.mjs";
|
|
4
4
|
function m() {
|
|
5
5
|
const { translations: o, locale: n } = r(e);
|
|
6
6
|
return {
|
|
@@ -11,4 +11,4 @@ function m() {
|
|
|
11
11
|
export {
|
|
12
12
|
m as useTranslations
|
|
13
13
|
};
|
|
14
|
-
//# sourceMappingURL=useTranslations.
|
|
14
|
+
//# sourceMappingURL=useTranslations.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTranslations.mjs","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;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"de.mjs","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;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"en.mjs","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;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","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;"}
|
package/package.json
CHANGED
|
@@ -2,17 +2,18 @@
|
|
|
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.
|
|
5
|
+
"version": "0.1.6",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/cjs/index.js",
|
|
8
|
-
"module": "dist/esm/index.
|
|
8
|
+
"module": "dist/esm/index.mjs",
|
|
9
9
|
"types": "dist/types/index.d.ts",
|
|
10
10
|
"typings": "dist/types/index.d.ts",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
13
|
"require": "./dist/cjs/index.js",
|
|
14
|
+
"import": "./dist/esm/index.mjs",
|
|
14
15
|
"types": "./dist/types/index.d.ts",
|
|
15
|
-
"default": "./dist/
|
|
16
|
+
"default": "./dist/cjs/index.js"
|
|
16
17
|
}
|
|
17
18
|
},
|
|
18
19
|
"files": [
|
|
@@ -23,8 +24,8 @@
|
|
|
23
24
|
"clean": "rimraf dist",
|
|
24
25
|
"dev": "tsc && vite build --watch --emptyOutDir false",
|
|
25
26
|
"build": "yarn clean && yarn build:esm && yarn build:cjs",
|
|
26
|
-
"build:esm": "BUILD_TARGET=esm;
|
|
27
|
-
"build:cjs": "BUILD_TARGET=cjs;
|
|
27
|
+
"build:esm": "BUILD_TARGET=esm; vite build",
|
|
28
|
+
"build:cjs": "BUILD_TARGET=cjs; vite build",
|
|
28
29
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
29
30
|
"format": "prettier \"src/**/*.{js,ts,tsx}\" --write",
|
|
30
31
|
"format:check": "prettier \"src/**/*.{js,ts,tsx}\" --check",
|
|
@@ -44,7 +45,7 @@
|
|
|
44
45
|
"react": ">=16.8.0"
|
|
45
46
|
},
|
|
46
47
|
"dependencies": {
|
|
47
|
-
"@knocklabs/client": "^0.8.
|
|
48
|
+
"@knocklabs/client": "^0.8.21",
|
|
48
49
|
"date-fns": "^3.3.1",
|
|
49
50
|
"zustand": "^3.7.2"
|
|
50
51
|
},
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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;"}
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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;"}
|