@novu/react 2.0.0 → 2.1.0
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/dist/client/index.d.mts +72 -2
- package/dist/client/index.d.ts +72 -2
- package/dist/client/index.js +356 -9
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +356 -9
- package/dist/client/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +2 -1
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/server/server.d.mts +71 -1
- package/dist/server/server.d.ts +71 -1
- package/dist/server/server.js +334 -2
- package/dist/server/server.js.map +1 -1
- package/dist/server/server.mjs +326 -1
- package/dist/server/server.mjs.map +1 -1
- package/hooks/package.json +5 -0
- package/package.json +27 -10
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/components/Bell.tsx","../../src/utils/createContextAndHook.ts","../../src/context/RenderContext.tsx","../../src/components/Mounter.tsx","../../src/components/Inbox.tsx","../../src/components/Renderer.tsx","../../src/hooks/useDataRef.ts","../../src/components/Preferences.tsx","../../src/components/Notifications.tsx"],"sourcesContent":["export * from './components';\nexport * from './utils/types';\n","import React from 'react';\nimport { useRenderer } from '../context/RenderContext';\nimport { Mounter } from './Mounter';\nimport { BellRenderer } from '../utils/types';\n\nexport type BellProps = {\n renderBell?: BellRenderer;\n};\n\nexport const Bell = React.memo((props: BellProps) => {\n const { renderBell } = props;\n const { novuUI, mountElement } = useRenderer();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n return novuUI.mountComponent({\n name: 'Bell',\n element,\n props: renderBell ? { renderBell: (el, unreadCount) => mountElement(el, renderBell(unreadCount)) } : undefined,\n });\n },\n [renderBell]\n );\n\n return <Mounter mount={mount} />;\n});\n","import React from 'react';\n\nexport function assertContextExists(contextVal: unknown, msgOrCtx: string | React.Context<any>): asserts contextVal {\n if (!contextVal) {\n throw typeof msgOrCtx === 'string' ? new Error(msgOrCtx) : new Error(`${msgOrCtx.displayName} not found`);\n }\n}\n\ntype Options = { assertCtxFn?: (v: unknown, msg: string) => void };\ntype ContextOf<T> = React.Context<{ value: T } | undefined>;\ntype UseCtxFn<T> = () => T;\n\n/**\n * Creates and returns a Context and two hooks that return the context value.\n * The Context type is derived from the type passed in by the user.\n * The first hook returned guarantees that the context exists so the returned value is always CtxValue\n * The second hook makes no guarantees, so the returned value can be CtxValue | undefined\n */\nexport const createContextAndHook = <CtxVal>(\n displayName: string,\n options?: Options\n): [ContextOf<CtxVal>, UseCtxFn<CtxVal>, UseCtxFn<CtxVal | Partial<CtxVal>>] => {\n const { assertCtxFn = assertContextExists } = options || {};\n const Ctx = React.createContext<{ value: CtxVal } | undefined>(undefined);\n Ctx.displayName = displayName;\n\n const useCtx = () => {\n const ctx = React.useContext(Ctx);\n assertCtxFn(ctx, `Component must be wrapped with the <Inbox /> Component`);\n\n return (ctx as any).value as CtxVal;\n };\n\n const useCtxWithoutGuarantee = () => {\n const ctx = React.useContext(Ctx);\n\n return ctx ? ctx.value : {};\n };\n\n return [Ctx, useCtx, useCtxWithoutGuarantee];\n};\n","import React from 'react';\nimport type { NovuUI } from '@novu/js/ui';\nimport { createContextAndHook } from '../utils/createContextAndHook';\n\nexport type MountedElement = React.ReactNode;\nexport type MountedElements = Map<HTMLElement, MountedElement>;\n\ntype RendererContextValue = {\n mountElement: (el: HTMLElement, mountedElement: MountedElement) => () => void;\n novuUI: NovuUI;\n};\n\nconst [RendererContext, useRendererContext] = createContextAndHook<RendererContextValue>('RendererContext');\n\nconst RendererProvider = (props: React.PropsWithChildren<{ value: RendererContextValue }>) => {\n return <RendererContext.Provider value={{ value: props.value }}>{props.children}</RendererContext.Provider>;\n};\n\nexport { useRendererContext as useRenderer, RendererProvider };\n","import React from 'react';\n\ntype MounterProps = {\n mount: (node: HTMLElement) => ((node: HTMLElement) => void) | void;\n};\n\n/**\n * Mounter allows you to mount a component to a DOM node.\n */\nexport function Mounter({ mount }: MounterProps) {\n const ref = React.useRef<HTMLDivElement>(null);\n\n React.useEffect(() => {\n let unmount: (node: HTMLDivElement) => void | undefined;\n const element = ref.current;\n if (element && mount) {\n const possibleUnmount = mount(element);\n if (possibleUnmount) {\n unmount = possibleUnmount;\n }\n }\n\n return () => {\n if (element && unmount) {\n unmount(element);\n }\n };\n }, [ref, mount]);\n\n return <div ref={ref} />;\n}\n","import React, { useMemo } from 'react';\nimport { useRenderer } from '../context/RenderContext';\nimport { DefaultProps, DefaultInboxProps, WithChildrenProps } from '../utils/types';\nimport { Mounter } from './Mounter';\nimport { Renderer } from './Renderer';\n\nexport type InboxProps = DefaultProps | WithChildrenProps;\n\nconst DefaultInbox = (props: DefaultInboxProps) => {\n const { open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick } =\n props;\n const { novuUI, mountElement } = useRenderer();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n return novuUI.mountComponent({\n name: 'Inbox',\n props: {\n open,\n renderNotification: renderNotification\n ? (el, notification) => mountElement(el, renderNotification(notification))\n : undefined,\n renderBell: renderBell ? (el, unreadCount) => mountElement(el, renderBell(unreadCount)) : undefined,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n },\n element,\n });\n },\n [open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]\n );\n\n return <Mounter mount={mount} />;\n};\n\nexport const Inbox = React.memo((props: InboxProps) => {\n const {\n localization,\n appearance,\n tabs,\n routerPush,\n applicationIdentifier,\n subscriberId,\n subscriberHash,\n backendUrl,\n socketUrl,\n } = props;\n\n const options = useMemo(() => {\n return {\n localization,\n appearance,\n tabs,\n routerPush,\n options: { applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl },\n };\n }, [localization, appearance, tabs, applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl]);\n\n if (isWithChildrenProps(props)) {\n return <Renderer options={options}>{props.children}</Renderer>;\n }\n\n const { open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick } =\n props;\n\n return (\n <Renderer options={options}>\n <DefaultInbox\n open={open}\n renderNotification={renderNotification}\n renderBell={renderBell}\n onNotificationClick={onNotificationClick}\n onPrimaryActionClick={onPrimaryActionClick}\n onSecondaryActionClick={onSecondaryActionClick}\n />\n </Renderer>\n );\n});\n\nfunction isWithChildrenProps(props: InboxProps): props is WithChildrenProps {\n return 'children' in props;\n}\n","import React, { useCallback, useEffect, useState } from 'react';\nimport ReactDOM from 'react-dom';\nimport { NovuUI } from '@novu/js/ui';\nimport type { NovuUIOptions } from '@novu/js/ui';\nimport { MountedElement, RendererProvider } from '../context/RenderContext';\nimport { useDataRef } from '../hooks/useDataRef';\n\ntype RendererProps = React.PropsWithChildren<{\n options: NovuUIOptions;\n}>;\n\n/**\n *\n * Renderer component that provides the NovuUI instance and mounts the elements on DOM in a portal\n */\nexport const Renderer = ({ options, children }: RendererProps) => {\n const optionsRef = useDataRef(options);\n const [novuUI, setNovuUI] = useState<NovuUI | undefined>();\n const [mountedElements, setMountedElements] = useState(new Map<HTMLElement, MountedElement>());\n\n const mountElement = useCallback(\n (el: HTMLElement, mountedElement: MountedElement) => {\n setMountedElements((prev) => {\n const newMountedElements = new Map(prev);\n newMountedElements.set(el, mountedElement);\n\n return newMountedElements;\n });\n\n return () => {\n setMountedElements((prev) => {\n const newMountedElements = new Map(prev);\n newMountedElements.delete(el);\n\n return newMountedElements;\n });\n };\n },\n [setMountedElements]\n );\n\n useEffect(() => {\n const novu = new NovuUI(optionsRef.current);\n setNovuUI(novu);\n\n return () => {\n novu.unmount();\n };\n }, []);\n\n useEffect(() => {\n if (!novuUI) {\n return;\n }\n\n novuUI.updateAppearance(options.appearance);\n novuUI.updateLocalization(options.localization);\n novuUI.updateTabs(options.tabs);\n novuUI.updateOptions(options.options);\n novuUI.updateRouterPush(options.routerPush);\n }, [options]);\n\n if (!novuUI) {\n return null;\n }\n\n return (\n <RendererProvider value={{ mountElement, novuUI }}>\n {[...mountedElements].map(([element, mountedElement]) => {\n return ReactDOM.createPortal(mountedElement, element);\n })}\n\n {children}\n </RendererProvider>\n );\n};\n","import { useRef } from 'react';\n\nexport const useDataRef = <T>(data: T) => {\n const ref = useRef(data);\n ref.current = data;\n\n return ref;\n};\n","import React from 'react';\nimport { useRenderer } from '../context/RenderContext';\nimport { Mounter } from './Mounter';\n\nexport const Preferences = () => {\n const { novuUI } = useRenderer();\n\n const mount = React.useCallback((element: HTMLElement) => {\n return novuUI.mountComponent({\n name: 'Preferences',\n element,\n });\n }, []);\n\n return <Mounter mount={mount} />;\n};\n","import React from 'react';\nimport type { NotificationClickHandler, NotificationActionClickHandler } from '@novu/js/ui';\nimport { useRenderer } from '../context/RenderContext';\nimport { Mounter } from './Mounter';\nimport { NotificationsRenderer } from '../utils/types';\n\nexport type NotificationProps = {\n renderNotification?: NotificationsRenderer;\n onNotificationClick?: NotificationClickHandler;\n onPrimaryActionClick?: NotificationActionClickHandler;\n onSecondaryActionClick?: NotificationActionClickHandler;\n};\n\nexport const Notifications = React.memo((props: NotificationProps) => {\n const { onNotificationClick, onPrimaryActionClick, renderNotification, onSecondaryActionClick } = props;\n const { novuUI, mountElement } = useRenderer();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n return novuUI.mountComponent({\n name: 'Notifications',\n element,\n props: {\n renderNotification: renderNotification\n ? (el, notification) => mountElement(el, renderNotification(notification))\n : undefined,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n },\n });\n },\n [renderNotification, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]\n );\n\n return <Mounter mount={mount} />;\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAAkB;;;ACAlB,mBAAkB;AAEX,SAAS,oBAAoB,Y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C,CAAC;AAEL,SAAO,6CAAC,WAAQ,OAAc;AAChC;;;ACfA,IAAAC,gBAAkB;AAmCT,IAAAC,sBAAA;AAtBF,IAAM,gBAAgB,cAAAC,QAAM,KAAK,CAAC,UAA6B;AACpE,QAAM,EAAE,qBAAqB,sBAAsB,oBAAoB,uBAAuB,IAAI;AAClG,QAAM,EAAE,QAAQ,aAAa,IAAI,mBAAY;AAE7C,QAAM,QAAQ,cAAAA,QAAM;AAAA,IAClB,CAAC,YAAyB;AACxB,aAAO,OAAO,eAAe;AAAA,QAC3B,MAAM;AAAA,QACN;AAAA,QACA,OAAO;AAAA,UACL,oBAAoB,qBAChB,CAAC,IAAI,iBAAiB,aAAa,IAAI,mBAAmB,YAAY,CAAC,IACvE;AAAA,UACJ;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IACA,CAAC,oBAAoB,qBAAqB,sBAAsB,sBAAsB;AAAA,EACxF;AAEA,SAAO,6CAAC,WAAQ,OAAc;AAChC,CAAC;","names":["import_react","React","import_react","import_jsx_runtime","React","import_jsx_runtime","React","import_react","import_react","import_react","import_jsx_runtime","ReactDOM","import_jsx_runtime","React","import_react","import_jsx_runtime","React","import_react","import_jsx_runtime","React"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/components/Bell.tsx","../../src/utils/createContextAndHook.ts","../../src/context/RenderContext.tsx","../../src/components/Mounter.tsx","../../src/components/Inbox.tsx","../../src/components/Renderer.tsx","../../src/hooks/internal/useDataRef.ts","../../src/components/Preferences.tsx","../../src/components/Notifications.tsx","../../src/hooks/NovuProvider.tsx","../../src/hooks/useNotifications.ts","../../src/hooks/usePreferences.ts","../../src/hooks/useCounts.ts","../../src/hooks/internal/useWebsocketEvent.ts","../../src/utils/requestLock.ts","../../src/hooks/internal/useBrowserTabsChannel.ts"],"sourcesContent":["export * from './components';\nexport * from './hooks';\nexport * from './utils/types';\n","import React from 'react';\nimport { useRenderer } from '../context/RenderContext';\nimport { Mounter } from './Mounter';\nimport { BellRenderer } from '../utils/types';\n\nexport type BellProps = {\n renderBell?: BellRenderer;\n};\n\nexport const Bell = React.memo((props: BellProps) => {\n const { renderBell } = props;\n const { novuUI, mountElement } = useRenderer();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n return novuUI.mountComponent({\n name: 'Bell',\n element,\n props: renderBell ? { renderBell: (el, unreadCount) => mountElement(el, renderBell(unreadCount)) } : undefined,\n });\n },\n [renderBell]\n );\n\n return <Mounter mount={mount} />;\n});\n","import React from 'react';\n\nexport function assertContextExists(contextVal: unknown, msgOrCtx: string | React.Context<any>): asserts contextVal {\n if (!contextVal) {\n throw typeof msgOrCtx === 'string' ? new Error(msgOrCtx) : new Error(`${msgOrCtx.displayName} not found`);\n }\n}\n\ntype Options = { assertCtxFn?: (v: unknown, msg: string) => void };\ntype ContextOf<T> = React.Context<{ value: T } | undefined>;\ntype UseCtxFn<T> = () => T;\n\n/**\n * Creates and returns a Context and two hooks that return the context value.\n * The Context type is derived from the type passed in by the user.\n * The first hook returned guarantees that the context exists so the returned value is always CtxValue\n * The second hook makes no guarantees, so the returned value can be CtxValue | undefined\n */\nexport const createContextAndHook = <CtxVal>(\n displayName: string,\n options?: Options\n): [ContextOf<CtxVal>, UseCtxFn<CtxVal>, UseCtxFn<CtxVal | Partial<CtxVal>>] => {\n const { assertCtxFn = assertContextExists } = options || {};\n const Ctx = React.createContext<{ value: CtxVal } | undefined>(undefined);\n Ctx.displayName = displayName;\n\n const useCtx = () => {\n const ctx = React.useContext(Ctx);\n assertCtxFn(ctx, `Component must be wrapped with the <Inbox /> Component`);\n\n return (ctx as any).value as CtxVal;\n };\n\n const useCtxWithoutGuarantee = () => {\n const ctx = React.useContext(Ctx);\n\n return ctx ? ctx.value : {};\n };\n\n return [Ctx, useCtx, useCtxWithoutGuarantee];\n};\n","import React from 'react';\nimport type { NovuUI } from '@novu/js/ui';\nimport { createContextAndHook } from '../utils/createContextAndHook';\n\nexport type MountedElement = React.ReactNode;\nexport type MountedElements = Map<HTMLElement, MountedElement>;\n\ntype RendererContextValue = {\n mountElement: (el: HTMLElement, mountedElement: MountedElement) => () => void;\n novuUI: NovuUI;\n};\n\nconst [RendererContext, useRendererContext] = createContextAndHook<RendererContextValue>('RendererContext');\n\nconst RendererProvider = (props: React.PropsWithChildren<{ value: RendererContextValue }>) => {\n return <RendererContext.Provider value={{ value: props.value }}>{props.children}</RendererContext.Provider>;\n};\n\nexport { useRendererContext as useRenderer, RendererProvider };\n","import React from 'react';\n\ntype MounterProps = {\n mount: (node: HTMLElement) => ((node: HTMLElement) => void) | void;\n};\n\n/**\n * Mounter allows you to mount a component to a DOM node.\n */\nexport function Mounter({ mount }: MounterProps) {\n const ref = React.useRef<HTMLDivElement>(null);\n\n React.useEffect(() => {\n let unmount: (node: HTMLDivElement) => void | undefined;\n const element = ref.current;\n if (element && mount) {\n const possibleUnmount = mount(element);\n if (possibleUnmount) {\n unmount = possibleUnmount;\n }\n }\n\n return () => {\n if (element && unmount) {\n unmount(element);\n }\n };\n }, [ref, mount]);\n\n return <div ref={ref} />;\n}\n","import React, { useMemo } from 'react';\nimport { useRenderer } from '../context/RenderContext';\nimport { DefaultProps, DefaultInboxProps, WithChildrenProps } from '../utils/types';\nimport { NovuProvider, useNovu, useUnsafeNovu } from './index';\nimport { Mounter } from './Mounter';\nimport { Renderer } from './Renderer';\n\nexport type InboxProps = DefaultProps | WithChildrenProps;\n\nconst DefaultInbox = (props: DefaultInboxProps) => {\n const { open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick } =\n props;\n const { novuUI, mountElement } = useRenderer();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n return novuUI.mountComponent({\n name: 'Inbox',\n props: {\n open,\n renderNotification: renderNotification\n ? (el, notification) => mountElement(el, renderNotification(notification))\n : undefined,\n renderBell: renderBell ? (el, unreadCount) => mountElement(el, renderBell(unreadCount)) : undefined,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n },\n element,\n });\n },\n [open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]\n );\n\n return <Mounter mount={mount} />;\n};\n\nexport const Inbox = React.memo((props: InboxProps) => {\n const { applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl } = props;\n const novu = useUnsafeNovu();\n\n if (novu) {\n return <InboxChild {...props} />;\n }\n\n return (\n <NovuProvider\n applicationIdentifier={applicationIdentifier}\n subscriberId={subscriberId}\n subscriberHash={subscriberHash}\n backendUrl={backendUrl}\n socketUrl={socketUrl}\n >\n <InboxChild {...props} />\n </NovuProvider>\n );\n});\n\nexport const InboxChild = React.memo((props: InboxProps) => {\n const {\n localization,\n appearance,\n tabs,\n routerPush,\n applicationIdentifier,\n subscriberId,\n subscriberHash,\n backendUrl,\n socketUrl,\n } = props;\n const novu = useNovu();\n\n const options = useMemo(() => {\n return {\n localization,\n appearance,\n tabs,\n routerPush,\n options: { applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl },\n };\n }, [localization, appearance, tabs, applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl]);\n\n if (isWithChildrenProps(props)) {\n return (\n <Renderer options={options} novu={novu}>\n {props.children}\n </Renderer>\n );\n }\n\n const { open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick } =\n props;\n\n return (\n <Renderer options={options} novu={novu}>\n <DefaultInbox\n open={open}\n renderNotification={renderNotification}\n renderBell={renderBell}\n onNotificationClick={onNotificationClick}\n onPrimaryActionClick={onPrimaryActionClick}\n onSecondaryActionClick={onSecondaryActionClick}\n />\n </Renderer>\n );\n});\n\nfunction isWithChildrenProps(props: InboxProps): props is WithChildrenProps {\n return 'children' in props;\n}\n","import React, { useCallback, useEffect, useState } from 'react';\nimport ReactDOM from 'react-dom';\nimport { NovuUI } from '@novu/js/ui';\nimport type { NovuUIOptions } from '@novu/js/ui';\nimport { Novu } from '@novu/js';\nimport { MountedElement, RendererProvider } from '../context/RenderContext';\nimport { useDataRef } from '../hooks/internal/useDataRef';\n\ntype RendererProps = React.PropsWithChildren<{\n options: NovuUIOptions;\n novu?: Novu;\n}>;\n\n/**\n *\n * Renderer component that provides the NovuUI instance and mounts the elements on DOM in a portal\n */\nexport const Renderer = ({ options, novu, children }: RendererProps) => {\n const optionsRef = useDataRef({ ...options, novu });\n const [novuUI, setNovuUI] = useState<NovuUI | undefined>();\n const [mountedElements, setMountedElements] = useState(new Map<HTMLElement, MountedElement>());\n\n const mountElement = useCallback(\n (el: HTMLElement, mountedElement: MountedElement) => {\n setMountedElements((prev) => {\n const newMountedElements = new Map(prev);\n newMountedElements.set(el, mountedElement);\n\n return newMountedElements;\n });\n\n return () => {\n setMountedElements((prev) => {\n const newMountedElements = new Map(prev);\n newMountedElements.delete(el);\n\n return newMountedElements;\n });\n };\n },\n [setMountedElements]\n );\n\n useEffect(() => {\n const novu = new NovuUI(optionsRef.current);\n setNovuUI(novu);\n\n return () => {\n novu.unmount();\n };\n }, []);\n\n useEffect(() => {\n if (!novuUI) {\n return;\n }\n\n novuUI.updateAppearance(options.appearance);\n novuUI.updateLocalization(options.localization);\n novuUI.updateTabs(options.tabs);\n novuUI.updateOptions(options.options);\n novuUI.updateRouterPush(options.routerPush);\n }, [options]);\n\n if (!novuUI) {\n return null;\n }\n\n return (\n <RendererProvider value={{ mountElement, novuUI }}>\n {[...mountedElements].map(([element, mountedElement]) => {\n return ReactDOM.createPortal(mountedElement, element);\n })}\n\n {children}\n </RendererProvider>\n );\n};\n","import { useRef } from 'react';\n\nexport const useDataRef = <T>(data: T) => {\n const ref = useRef(data);\n ref.current = data;\n\n return ref;\n};\n","import React from 'react';\nimport { useRenderer } from '../context/RenderContext';\nimport { Mounter } from './Mounter';\n\nexport const Preferences = () => {\n const { novuUI } = useRenderer();\n\n const mount = React.useCallback((element: HTMLElement) => {\n return novuUI.mountComponent({\n name: 'Preferences',\n element,\n });\n }, []);\n\n return <Mounter mount={mount} />;\n};\n","import React from 'react';\nimport type { NotificationClickHandler, NotificationActionClickHandler } from '@novu/js/ui';\nimport { useRenderer } from '../context/RenderContext';\nimport { Mounter } from './Mounter';\nimport { NotificationsRenderer } from '../utils/types';\n\nexport type NotificationProps = {\n renderNotification?: NotificationsRenderer;\n onNotificationClick?: NotificationClickHandler;\n onPrimaryActionClick?: NotificationActionClickHandler;\n onSecondaryActionClick?: NotificationActionClickHandler;\n};\n\nexport const Notifications = React.memo((props: NotificationProps) => {\n const { onNotificationClick, onPrimaryActionClick, renderNotification, onSecondaryActionClick } = props;\n const { novuUI, mountElement } = useRenderer();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n return novuUI.mountComponent({\n name: 'Notifications',\n element,\n props: {\n renderNotification: renderNotification\n ? (el, notification) => mountElement(el, renderNotification(notification))\n : undefined,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n },\n });\n },\n [renderNotification, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]\n );\n\n return <Mounter mount={mount} />;\n});\n","import { Novu, NovuOptions } from '@novu/js';\nimport { ReactNode, createContext, useContext, useMemo } from 'react';\n\ntype NovuProviderProps = NovuOptions & {\n children: ReactNode;\n};\n\nconst NovuContext = createContext<Novu | undefined>(undefined);\n\nexport const NovuProvider = ({\n children,\n applicationIdentifier,\n subscriberId,\n subscriberHash,\n backendUrl,\n socketUrl,\n useCache,\n}: NovuProviderProps) => {\n const novu = useMemo(\n () => new Novu({ applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache }),\n [applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache]\n );\n\n return <NovuContext.Provider value={novu}>{children}</NovuContext.Provider>;\n};\n\nexport const useNovu = () => {\n const context = useContext(NovuContext);\n if (!context) {\n throw new Error('useNovu must be used within a <NovuProvider />');\n }\n\n return context;\n};\n\nexport const useUnsafeNovu = () => {\n const context = useContext(NovuContext);\n\n return context;\n};\n","import { useState, useEffect, useRef } from 'react';\nimport { ListNotificationsResponse, Notification, NovuError, isSameFilter, NotificationFilter } from '@novu/js';\nimport { useNovu } from './NovuProvider';\n\nexport type UseNotificationsProps = {\n tags?: string[];\n read?: boolean;\n archived?: boolean;\n limit?: number;\n onSuccess?: (data: Notification[]) => void;\n onError?: (error: NovuError) => void;\n};\n\nexport const useNotifications = (props?: UseNotificationsProps) => {\n const { tags, read, archived = false, limit, onSuccess, onError } = props || {};\n const filterRef = useRef<NotificationFilter | undefined>(undefined);\n const { notifications, on, off } = useNovu();\n const [data, setData] = useState<Array<Notification>>();\n const [error, setError] = useState<NovuError>();\n const [isLoading, setIsLoading] = useState(true);\n const [isFetching, setIsFetching] = useState(false);\n const [hasMore, setHasMore] = useState(false);\n const length = data?.length;\n const after = length ? data[length - 1].id : undefined;\n\n const sync = (event: { data?: ListNotificationsResponse }) => {\n if (!event.data || (filterRef.current && !isSameFilter(filterRef.current, event.data.filter))) {\n return;\n }\n setData(event.data.notifications);\n setHasMore(event.data.hasMore);\n };\n\n useEffect(() => {\n on('notifications.list.updated', sync);\n\n return () => {\n off('notifications.list.updated', sync);\n };\n }, []);\n\n useEffect(() => {\n const newFilter = { tags, read, archived };\n if (filterRef.current && isSameFilter(filterRef.current, newFilter)) {\n return;\n }\n\n notifications.clearCache({ filter: filterRef.current });\n filterRef.current = newFilter;\n\n fetchNotifications({ refetch: true });\n }, [tags, read, archived]);\n\n const fetchNotifications = async (options?: { refetch: boolean }) => {\n if (options?.refetch) {\n setError(undefined);\n setIsLoading(true);\n setIsFetching(false);\n }\n setIsFetching(true);\n const response = await notifications.list({\n tags,\n read,\n archived,\n limit,\n after: options?.refetch ? undefined : after,\n });\n if (response.error) {\n setError(response.error);\n onError?.(response.error);\n } else {\n onSuccess?.(response.data!.notifications);\n setData(response.data!.notifications);\n setHasMore(response.data!.hasMore);\n }\n setIsLoading(false);\n setIsFetching(false);\n };\n\n const refetch = () => {\n notifications.clearCache({ filter: { tags, read, archived } });\n\n return fetchNotifications({ refetch: true });\n };\n\n const fetchMore = async () => {\n if (!hasMore || isFetching) return;\n\n return fetchNotifications();\n };\n\n const readAll = async () => {\n return await notifications.readAll({ tags });\n };\n\n const archiveAll = async () => {\n return await notifications.archiveAll({ tags });\n };\n\n const archiveAllRead = async () => {\n return await notifications.archiveAllRead({ tags });\n };\n\n return {\n readAll,\n archiveAll,\n archiveAllRead,\n notifications: data,\n error,\n isLoading,\n isFetching,\n refetch,\n fetchMore,\n hasMore,\n };\n};\n","import { NovuError, Preference } from '@novu/js';\nimport { useEffect, useState } from 'react';\nimport { useNovu } from './NovuProvider';\n\ntype UsePreferencesProps = {\n onSuccess?: (data: Preference[]) => void;\n onError?: (error: NovuError) => void;\n};\n\ntype UsePreferencesResult = {\n preferences?: Preference[];\n error?: NovuError;\n isLoading: boolean; // initial loading\n isFetching: boolean; // the request is in flight\n refetch: () => Promise<void>;\n};\n\nexport const usePreferences = (props?: UsePreferencesProps): UsePreferencesResult => {\n const { onSuccess, onError } = props || {};\n const [data, setData] = useState<Preference[]>();\n const { preferences, on, off } = useNovu();\n const [error, setError] = useState<NovuError>();\n const [isLoading, setIsLoading] = useState(true);\n const [isFetching, setIsFetching] = useState(false);\n\n const sync = (event: { data?: Preference[] }) => {\n if (!event.data) {\n return;\n }\n setData(event.data);\n };\n\n useEffect(() => {\n fetchPreferences();\n\n on('preferences.list.updated', sync);\n on('preferences.list.pending', sync);\n on('preferences.list.resolved', sync);\n\n return () => {\n off('preferences.list.updated', sync);\n off('preferences.list.pending', sync);\n off('preferences.list.resolved', sync);\n };\n }, []);\n\n const fetchPreferences = async () => {\n setIsFetching(true);\n const response = await preferences.list();\n if (response.error) {\n setError(response.error);\n onError?.(response.error);\n } else {\n onSuccess?.(response.data!);\n }\n setIsLoading(false);\n setIsFetching(false);\n };\n\n const refetch = () => {\n preferences.cache.clearAll();\n return fetchPreferences();\n };\n\n return {\n preferences: data,\n error,\n isLoading,\n isFetching,\n refetch,\n };\n};\n","import { useEffect, useState } from 'react';\nimport { Notification, NotificationFilter, NovuError, areTagsEqual } from '@novu/js';\nimport { useNovu } from './NovuProvider';\nimport { useWebSocketEvent } from './internal/useWebsocketEvent';\n\ntype Count = {\n count: number;\n filter: NotificationFilter;\n};\n\ntype UseCountsProps = {\n filters: NotificationFilter[];\n onSuccess?: (data: Count[]) => void;\n onError?: (error: NovuError) => void;\n};\n\ntype UseCountsResult = {\n counts?: Count[];\n error?: NovuError;\n isLoading: boolean; // initial loading\n isFetching: boolean; // the request is in flight\n refetch: () => Promise<void>;\n};\n\nexport const useCounts = (props: UseCountsProps): UseCountsResult => {\n const { filters, onSuccess, onError } = props;\n const { notifications } = useNovu();\n const [error, setError] = useState<NovuError>();\n const [counts, setCounts] = useState<Count[]>();\n const [isLoading, setIsLoading] = useState(true);\n const [isFetching, setIsFetching] = useState(false);\n\n const sync = async (notification?: Notification) => {\n const existingCounts = counts ?? (new Array(filters.length).fill(undefined) as (Count | undefined)[]);\n let countFiltersToFetch: NotificationFilter[] = [];\n if (notification) {\n // eslint-disable-next-line no-plusplus\n for (let i = 0; i < existingCounts.length; i++) {\n const filter = filters[i];\n if (areTagsEqual(filter.tags, notification.tags)) {\n countFiltersToFetch.push(filter);\n }\n }\n } else {\n countFiltersToFetch = filters;\n }\n\n if (countFiltersToFetch.length === 0) {\n return;\n }\n\n setIsFetching(true);\n const countsRes = await notifications.count({ filters: countFiltersToFetch });\n setIsFetching(false);\n setIsLoading(false);\n if (countsRes.error) {\n setError(countsRes.error);\n onError?.(countsRes.error);\n\n return;\n }\n const data = countsRes.data!;\n onSuccess?.(data.counts);\n\n setCounts((oldCounts) => {\n const newCounts: Count[] = [];\n const countsReceived = data.counts;\n\n // eslint-disable-next-line no-plusplus\n for (let i = 0; i < existingCounts.length; i++) {\n const countReceived = countsReceived.find((c) => areTagsEqual(c.filter.tags, existingCounts[i]?.filter.tags));\n\n newCounts.push(countReceived || oldCounts![i]);\n }\n\n return newCounts;\n });\n };\n\n useWebSocketEvent({\n event: 'notifications.notification_received',\n eventHandler: (data) => {\n sync(data.result);\n },\n });\n\n useWebSocketEvent({\n event: 'notifications.unread_count_changed',\n eventHandler: () => {\n sync();\n },\n });\n\n useEffect(() => {\n setError(undefined);\n setIsLoading(true);\n setIsFetching(false);\n sync();\n }, [JSON.stringify(filters)]);\n\n const refetch = async () => {\n await sync();\n };\n\n return { counts, error, refetch, isLoading, isFetching };\n};\n","import { EventHandler, Events, SocketEventNames } from '@novu/js';\nimport { useEffect } from 'react';\nimport { useNovu } from '../NovuProvider';\nimport { requestLock } from '../../utils/requestLock';\nimport { useBrowserTabsChannel } from './useBrowserTabsChannel';\n\nexport const useWebSocketEvent = <E extends SocketEventNames>({\n event: webSocketEvent,\n eventHandler: onMessage,\n}: {\n event: E;\n eventHandler: (args: Events[E]) => void;\n}) => {\n const novu = useNovu();\n const { postMessage } = useBrowserTabsChannel({ channelName: `nv.${webSocketEvent}`, onMessage });\n\n const updateReadCount: EventHandler<Events[E]> = (data) => {\n onMessage(data);\n postMessage(data);\n };\n\n useEffect(() => {\n const resolveLock = requestLock(`nv.${webSocketEvent}`, () => {\n novu.on(webSocketEvent, updateReadCount);\n });\n\n return () => {\n novu.off(webSocketEvent, updateReadCount);\n resolveLock();\n };\n }, []);\n};\n","export function requestLock(id: string, cb: (id: string) => void) {\n // Check if the Lock API is available\n if (!('locks' in navigator)) {\n // If Lock API is not available, immediately invoke the callback and return a no-op function\n cb(id);\n return () => {};\n }\n\n let isFulfilled = false;\n let promiseResolve: () => void;\n\n const promise = new Promise<void>((resolve) => {\n promiseResolve = resolve;\n });\n\n navigator.locks.request(id, () => {\n if (!isFulfilled) {\n cb(id);\n }\n\n return promise;\n });\n\n return () => {\n isFulfilled = true;\n promiseResolve();\n };\n}\n","import { useEffect, useState } from 'react';\n\nexport const useBrowserTabsChannel = <T = unknown>({\n channelName,\n onMessage,\n}: {\n channelName: string;\n onMessage: (args: T) => void;\n}) => {\n const [tabsChannel] = useState(\n typeof BroadcastChannel !== 'undefined' ? new BroadcastChannel(channelName) : undefined\n );\n\n const postMessage = (data: T) => {\n tabsChannel?.postMessage(data);\n };\n\n useEffect(() => {\n const listener = (event: MessageEvent<T>) => {\n onMessage(event.data);\n };\n\n tabsChannel?.addEventListener('message', listener);\n\n return () => {\n tabsChannel?.removeEventListener('message', listener);\n };\n }, []);\n\n return { postMessage };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAAkB;;;ACAlB,mBAAkB;AAEX,SAAS,oBAAoB,YAAqB,UAA2D;AAClH,MAAI,CAAC,YAAY;AACf,UAAM,OAAO,aAAa,WAAW,IAAI,MAAM,QAAQ,IAAI,IAAI,MAAM,GAAG,SAAS,WAAW,YAAY;AAAA,EAC1G;AACF;AAYO,IAAM,uBAAuB,CAClC,aACA,YAC8E;AAC9E,QAAM,EAAE,cAAc,oBAAoB,IAAI,WAAW,CAAC;AAC1D,QAAM,MAAM,aAAAC,QAAM,cAA6C,MAAS;AACxE,MAAI,cAAc;AAElB,QAAM,SAAS,MAAM;AACnB,UAAM,MAAM,aAAAA,QAAM,WAAW,GAAG;AAChC,gBAAY,KAAK,wDAAwD;AAEzE,WAAQ,IAAY;AAAA,EACtB;AAEA,QAAM,yBAAyB,MAAM;AACnC,UAAM,MAAM,aAAAA,QAAM,WAAW,GAAG;AAEhC,WAAO,MAAM,IAAI,QAAQ,CAAC;AAAA,EAC5B;AAEA,SAAO,CAAC,KAAK,QAAQ,sBAAsB;AAC7C;;;ACzBS;AAHT,IAAM,CAAC,iBAAiB,kBAAkB,IAAI,qBAA2C,iBAAiB;AAE1G,IAAM,mBAAmB,CAAC,UAAoE;AAC5F,SAAO,4CAAC,gBAAgB,UAAhB,EAAyB,OAAO,EAAE,OAAO,MAAM,MAAM,GAAI,gBAAM,UAAS;AAClF;;;AChBA,IAAAC,gBAAkB;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AAAA,IACP,cAAc,MAAM;AAClB,WAAK;AAAA,IACP;AAAA,EACF,CAAC;AAED,gCAAU,MAAM;AACd,aAAS,MAAS;AAClB,iBAAa,IAAI;AACjB,kBAAc,KAAK;AACnB,SAAK;AAAA,EACP,GAAG,CAAC,KAAK,UAAU,OAAO,CAAC,CAAC;AAE5B,QAAM,UAAU,YAAY;AAC1B,UAAM,KAAK;AAAA,EACb;AAEA,SAAO,EAAE,QAAQ,OAAO,SAAS,WAAW,WAAW;AACzD;","names":["import_react","React","import_react","import_jsx_runtime","React","import_jsx_runtime","React","import_react","import_react","import_react","import_jsx_runtime","novu","ReactDOM","import_jsx_runtime","React","import_react","import_jsx_runtime","React","import_react","import_jsx_runtime","React","import_react","import_jsx_runtime","import_react","import_js","import_react","import_react","import_js","import_react","import_react"]}
|
package/dist/client/index.mjs
CHANGED
|
@@ -80,7 +80,7 @@ import { useCallback, useEffect, useState } from "react";
|
|
|
80
80
|
import ReactDOM from "react-dom";
|
|
81
81
|
import { NovuUI } from "@novu/js/ui";
|
|
82
82
|
|
|
83
|
-
// src/hooks/useDataRef.ts
|
|
83
|
+
// src/hooks/internal/useDataRef.ts
|
|
84
84
|
import { useRef } from "react";
|
|
85
85
|
var useDataRef = (data) => {
|
|
86
86
|
const ref = useRef(data);
|
|
@@ -90,8 +90,8 @@ var useDataRef = (data) => {
|
|
|
90
90
|
|
|
91
91
|
// src/components/Renderer.tsx
|
|
92
92
|
import { jsxs } from "react/jsx-runtime";
|
|
93
|
-
var Renderer = ({ options, children }) => {
|
|
94
|
-
const optionsRef = useDataRef(options);
|
|
93
|
+
var Renderer = ({ options, novu, children }) => {
|
|
94
|
+
const optionsRef = useDataRef({ ...options, novu });
|
|
95
95
|
const [novuUI, setNovuUI] = useState();
|
|
96
96
|
const [mountedElements, setMountedElements] = useState(/* @__PURE__ */ new Map());
|
|
97
97
|
const mountElement = useCallback(
|
|
@@ -112,10 +112,10 @@ var Renderer = ({ options, children }) => {
|
|
|
112
112
|
[setMountedElements]
|
|
113
113
|
);
|
|
114
114
|
useEffect(() => {
|
|
115
|
-
const
|
|
116
|
-
setNovuUI(
|
|
115
|
+
const novu2 = new NovuUI(optionsRef.current);
|
|
116
|
+
setNovuUI(novu2);
|
|
117
117
|
return () => {
|
|
118
|
-
|
|
118
|
+
novu2.unmount();
|
|
119
119
|
};
|
|
120
120
|
}, []);
|
|
121
121
|
useEffect(() => {
|
|
@@ -164,6 +164,24 @@ var DefaultInbox = (props) => {
|
|
|
164
164
|
return /* @__PURE__ */ jsx4(Mounter, { mount });
|
|
165
165
|
};
|
|
166
166
|
var Inbox = React5.memo((props) => {
|
|
167
|
+
const { applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl } = props;
|
|
168
|
+
const novu = useUnsafeNovu();
|
|
169
|
+
if (novu) {
|
|
170
|
+
return /* @__PURE__ */ jsx4(InboxChild, { ...props });
|
|
171
|
+
}
|
|
172
|
+
return /* @__PURE__ */ jsx4(
|
|
173
|
+
NovuProvider,
|
|
174
|
+
{
|
|
175
|
+
applicationIdentifier,
|
|
176
|
+
subscriberId,
|
|
177
|
+
subscriberHash,
|
|
178
|
+
backendUrl,
|
|
179
|
+
socketUrl,
|
|
180
|
+
children: /* @__PURE__ */ jsx4(InboxChild, { ...props })
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
});
|
|
184
|
+
var InboxChild = React5.memo((props) => {
|
|
167
185
|
const {
|
|
168
186
|
localization,
|
|
169
187
|
appearance,
|
|
@@ -175,6 +193,7 @@ var Inbox = React5.memo((props) => {
|
|
|
175
193
|
backendUrl,
|
|
176
194
|
socketUrl
|
|
177
195
|
} = props;
|
|
196
|
+
const novu = useNovu();
|
|
178
197
|
const options = useMemo(() => {
|
|
179
198
|
return {
|
|
180
199
|
localization,
|
|
@@ -185,10 +204,10 @@ var Inbox = React5.memo((props) => {
|
|
|
185
204
|
};
|
|
186
205
|
}, [localization, appearance, tabs, applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl]);
|
|
187
206
|
if (isWithChildrenProps(props)) {
|
|
188
|
-
return /* @__PURE__ */ jsx4(Renderer, { options, children: props.children });
|
|
207
|
+
return /* @__PURE__ */ jsx4(Renderer, { options, novu, children: props.children });
|
|
189
208
|
}
|
|
190
209
|
const { open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick } = props;
|
|
191
|
-
return /* @__PURE__ */ jsx4(Renderer, { options, children: /* @__PURE__ */ jsx4(
|
|
210
|
+
return /* @__PURE__ */ jsx4(Renderer, { options, novu, children: /* @__PURE__ */ jsx4(
|
|
192
211
|
DefaultInbox,
|
|
193
212
|
{
|
|
194
213
|
open,
|
|
@@ -241,10 +260,338 @@ var Notifications = React7.memo((props) => {
|
|
|
241
260
|
);
|
|
242
261
|
return /* @__PURE__ */ jsx6(Mounter, { mount });
|
|
243
262
|
});
|
|
263
|
+
|
|
264
|
+
// src/hooks/NovuProvider.tsx
|
|
265
|
+
import { Novu } from "@novu/js";
|
|
266
|
+
import { createContext, useContext, useMemo as useMemo2 } from "react";
|
|
267
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
268
|
+
var NovuContext = createContext(void 0);
|
|
269
|
+
var NovuProvider = ({
|
|
270
|
+
children,
|
|
271
|
+
applicationIdentifier,
|
|
272
|
+
subscriberId,
|
|
273
|
+
subscriberHash,
|
|
274
|
+
backendUrl,
|
|
275
|
+
socketUrl,
|
|
276
|
+
useCache
|
|
277
|
+
}) => {
|
|
278
|
+
const novu = useMemo2(
|
|
279
|
+
() => new Novu({ applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache }),
|
|
280
|
+
[applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache]
|
|
281
|
+
);
|
|
282
|
+
return /* @__PURE__ */ jsx7(NovuContext.Provider, { value: novu, children });
|
|
283
|
+
};
|
|
284
|
+
var useNovu = () => {
|
|
285
|
+
const context = useContext(NovuContext);
|
|
286
|
+
if (!context) {
|
|
287
|
+
throw new Error("useNovu must be used within a <NovuProvider />");
|
|
288
|
+
}
|
|
289
|
+
return context;
|
|
290
|
+
};
|
|
291
|
+
var useUnsafeNovu = () => {
|
|
292
|
+
const context = useContext(NovuContext);
|
|
293
|
+
return context;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
// src/hooks/useNotifications.ts
|
|
297
|
+
import { useState as useState2, useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
298
|
+
import { isSameFilter } from "@novu/js";
|
|
299
|
+
var useNotifications = (props) => {
|
|
300
|
+
const { tags, read, archived = false, limit, onSuccess, onError } = props || {};
|
|
301
|
+
const filterRef = useRef2(void 0);
|
|
302
|
+
const { notifications, on, off } = useNovu();
|
|
303
|
+
const [data, setData] = useState2();
|
|
304
|
+
const [error, setError] = useState2();
|
|
305
|
+
const [isLoading, setIsLoading] = useState2(true);
|
|
306
|
+
const [isFetching, setIsFetching] = useState2(false);
|
|
307
|
+
const [hasMore, setHasMore] = useState2(false);
|
|
308
|
+
const length = data?.length;
|
|
309
|
+
const after = length ? data[length - 1].id : void 0;
|
|
310
|
+
const sync = (event) => {
|
|
311
|
+
if (!event.data || filterRef.current && !isSameFilter(filterRef.current, event.data.filter)) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
setData(event.data.notifications);
|
|
315
|
+
setHasMore(event.data.hasMore);
|
|
316
|
+
};
|
|
317
|
+
useEffect2(() => {
|
|
318
|
+
on("notifications.list.updated", sync);
|
|
319
|
+
return () => {
|
|
320
|
+
off("notifications.list.updated", sync);
|
|
321
|
+
};
|
|
322
|
+
}, []);
|
|
323
|
+
useEffect2(() => {
|
|
324
|
+
const newFilter = { tags, read, archived };
|
|
325
|
+
if (filterRef.current && isSameFilter(filterRef.current, newFilter)) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
notifications.clearCache({ filter: filterRef.current });
|
|
329
|
+
filterRef.current = newFilter;
|
|
330
|
+
fetchNotifications({ refetch: true });
|
|
331
|
+
}, [tags, read, archived]);
|
|
332
|
+
const fetchNotifications = async (options) => {
|
|
333
|
+
if (options?.refetch) {
|
|
334
|
+
setError(void 0);
|
|
335
|
+
setIsLoading(true);
|
|
336
|
+
setIsFetching(false);
|
|
337
|
+
}
|
|
338
|
+
setIsFetching(true);
|
|
339
|
+
const response = await notifications.list({
|
|
340
|
+
tags,
|
|
341
|
+
read,
|
|
342
|
+
archived,
|
|
343
|
+
limit,
|
|
344
|
+
after: options?.refetch ? void 0 : after
|
|
345
|
+
});
|
|
346
|
+
if (response.error) {
|
|
347
|
+
setError(response.error);
|
|
348
|
+
onError?.(response.error);
|
|
349
|
+
} else {
|
|
350
|
+
onSuccess?.(response.data.notifications);
|
|
351
|
+
setData(response.data.notifications);
|
|
352
|
+
setHasMore(response.data.hasMore);
|
|
353
|
+
}
|
|
354
|
+
setIsLoading(false);
|
|
355
|
+
setIsFetching(false);
|
|
356
|
+
};
|
|
357
|
+
const refetch = () => {
|
|
358
|
+
notifications.clearCache({ filter: { tags, read, archived } });
|
|
359
|
+
return fetchNotifications({ refetch: true });
|
|
360
|
+
};
|
|
361
|
+
const fetchMore = async () => {
|
|
362
|
+
if (!hasMore || isFetching) return;
|
|
363
|
+
return fetchNotifications();
|
|
364
|
+
};
|
|
365
|
+
const readAll = async () => {
|
|
366
|
+
return await notifications.readAll({ tags });
|
|
367
|
+
};
|
|
368
|
+
const archiveAll = async () => {
|
|
369
|
+
return await notifications.archiveAll({ tags });
|
|
370
|
+
};
|
|
371
|
+
const archiveAllRead = async () => {
|
|
372
|
+
return await notifications.archiveAllRead({ tags });
|
|
373
|
+
};
|
|
374
|
+
return {
|
|
375
|
+
readAll,
|
|
376
|
+
archiveAll,
|
|
377
|
+
archiveAllRead,
|
|
378
|
+
notifications: data,
|
|
379
|
+
error,
|
|
380
|
+
isLoading,
|
|
381
|
+
isFetching,
|
|
382
|
+
refetch,
|
|
383
|
+
fetchMore,
|
|
384
|
+
hasMore
|
|
385
|
+
};
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
// src/hooks/usePreferences.ts
|
|
389
|
+
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
390
|
+
var usePreferences = (props) => {
|
|
391
|
+
const { onSuccess, onError } = props || {};
|
|
392
|
+
const [data, setData] = useState3();
|
|
393
|
+
const { preferences, on, off } = useNovu();
|
|
394
|
+
const [error, setError] = useState3();
|
|
395
|
+
const [isLoading, setIsLoading] = useState3(true);
|
|
396
|
+
const [isFetching, setIsFetching] = useState3(false);
|
|
397
|
+
const sync = (event) => {
|
|
398
|
+
if (!event.data) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
setData(event.data);
|
|
402
|
+
};
|
|
403
|
+
useEffect3(() => {
|
|
404
|
+
fetchPreferences();
|
|
405
|
+
on("preferences.list.updated", sync);
|
|
406
|
+
on("preferences.list.pending", sync);
|
|
407
|
+
on("preferences.list.resolved", sync);
|
|
408
|
+
return () => {
|
|
409
|
+
off("preferences.list.updated", sync);
|
|
410
|
+
off("preferences.list.pending", sync);
|
|
411
|
+
off("preferences.list.resolved", sync);
|
|
412
|
+
};
|
|
413
|
+
}, []);
|
|
414
|
+
const fetchPreferences = async () => {
|
|
415
|
+
setIsFetching(true);
|
|
416
|
+
const response = await preferences.list();
|
|
417
|
+
if (response.error) {
|
|
418
|
+
setError(response.error);
|
|
419
|
+
onError?.(response.error);
|
|
420
|
+
} else {
|
|
421
|
+
onSuccess?.(response.data);
|
|
422
|
+
}
|
|
423
|
+
setIsLoading(false);
|
|
424
|
+
setIsFetching(false);
|
|
425
|
+
};
|
|
426
|
+
const refetch = () => {
|
|
427
|
+
preferences.cache.clearAll();
|
|
428
|
+
return fetchPreferences();
|
|
429
|
+
};
|
|
430
|
+
return {
|
|
431
|
+
preferences: data,
|
|
432
|
+
error,
|
|
433
|
+
isLoading,
|
|
434
|
+
isFetching,
|
|
435
|
+
refetch
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
// src/hooks/useCounts.ts
|
|
440
|
+
import { useEffect as useEffect6, useState as useState5 } from "react";
|
|
441
|
+
import { areTagsEqual } from "@novu/js";
|
|
442
|
+
|
|
443
|
+
// src/hooks/internal/useWebsocketEvent.ts
|
|
444
|
+
import { useEffect as useEffect5 } from "react";
|
|
445
|
+
|
|
446
|
+
// src/utils/requestLock.ts
|
|
447
|
+
function requestLock(id, cb) {
|
|
448
|
+
if (!("locks" in navigator)) {
|
|
449
|
+
cb(id);
|
|
450
|
+
return () => {
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
let isFulfilled = false;
|
|
454
|
+
let promiseResolve;
|
|
455
|
+
const promise = new Promise((resolve) => {
|
|
456
|
+
promiseResolve = resolve;
|
|
457
|
+
});
|
|
458
|
+
navigator.locks.request(id, () => {
|
|
459
|
+
if (!isFulfilled) {
|
|
460
|
+
cb(id);
|
|
461
|
+
}
|
|
462
|
+
return promise;
|
|
463
|
+
});
|
|
464
|
+
return () => {
|
|
465
|
+
isFulfilled = true;
|
|
466
|
+
promiseResolve();
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// src/hooks/internal/useBrowserTabsChannel.ts
|
|
471
|
+
import { useEffect as useEffect4, useState as useState4 } from "react";
|
|
472
|
+
var useBrowserTabsChannel = ({
|
|
473
|
+
channelName,
|
|
474
|
+
onMessage
|
|
475
|
+
}) => {
|
|
476
|
+
const [tabsChannel] = useState4(
|
|
477
|
+
typeof BroadcastChannel !== "undefined" ? new BroadcastChannel(channelName) : void 0
|
|
478
|
+
);
|
|
479
|
+
const postMessage = (data) => {
|
|
480
|
+
tabsChannel?.postMessage(data);
|
|
481
|
+
};
|
|
482
|
+
useEffect4(() => {
|
|
483
|
+
const listener = (event) => {
|
|
484
|
+
onMessage(event.data);
|
|
485
|
+
};
|
|
486
|
+
tabsChannel?.addEventListener("message", listener);
|
|
487
|
+
return () => {
|
|
488
|
+
tabsChannel?.removeEventListener("message", listener);
|
|
489
|
+
};
|
|
490
|
+
}, []);
|
|
491
|
+
return { postMessage };
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
// src/hooks/internal/useWebsocketEvent.ts
|
|
495
|
+
var useWebSocketEvent = ({
|
|
496
|
+
event: webSocketEvent,
|
|
497
|
+
eventHandler: onMessage
|
|
498
|
+
}) => {
|
|
499
|
+
const novu = useNovu();
|
|
500
|
+
const { postMessage } = useBrowserTabsChannel({ channelName: `nv.${webSocketEvent}`, onMessage });
|
|
501
|
+
const updateReadCount = (data) => {
|
|
502
|
+
onMessage(data);
|
|
503
|
+
postMessage(data);
|
|
504
|
+
};
|
|
505
|
+
useEffect5(() => {
|
|
506
|
+
const resolveLock = requestLock(`nv.${webSocketEvent}`, () => {
|
|
507
|
+
novu.on(webSocketEvent, updateReadCount);
|
|
508
|
+
});
|
|
509
|
+
return () => {
|
|
510
|
+
novu.off(webSocketEvent, updateReadCount);
|
|
511
|
+
resolveLock();
|
|
512
|
+
};
|
|
513
|
+
}, []);
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
// src/hooks/useCounts.ts
|
|
517
|
+
var useCounts = (props) => {
|
|
518
|
+
const { filters, onSuccess, onError } = props;
|
|
519
|
+
const { notifications } = useNovu();
|
|
520
|
+
const [error, setError] = useState5();
|
|
521
|
+
const [counts, setCounts] = useState5();
|
|
522
|
+
const [isLoading, setIsLoading] = useState5(true);
|
|
523
|
+
const [isFetching, setIsFetching] = useState5(false);
|
|
524
|
+
const sync = async (notification) => {
|
|
525
|
+
const existingCounts = counts ?? new Array(filters.length).fill(void 0);
|
|
526
|
+
let countFiltersToFetch = [];
|
|
527
|
+
if (notification) {
|
|
528
|
+
for (let i = 0; i < existingCounts.length; i++) {
|
|
529
|
+
const filter = filters[i];
|
|
530
|
+
if (areTagsEqual(filter.tags, notification.tags)) {
|
|
531
|
+
countFiltersToFetch.push(filter);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
} else {
|
|
535
|
+
countFiltersToFetch = filters;
|
|
536
|
+
}
|
|
537
|
+
if (countFiltersToFetch.length === 0) {
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
setIsFetching(true);
|
|
541
|
+
const countsRes = await notifications.count({ filters: countFiltersToFetch });
|
|
542
|
+
setIsFetching(false);
|
|
543
|
+
setIsLoading(false);
|
|
544
|
+
if (countsRes.error) {
|
|
545
|
+
setError(countsRes.error);
|
|
546
|
+
onError?.(countsRes.error);
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
const data = countsRes.data;
|
|
550
|
+
onSuccess?.(data.counts);
|
|
551
|
+
setCounts((oldCounts) => {
|
|
552
|
+
const newCounts = [];
|
|
553
|
+
const countsReceived = data.counts;
|
|
554
|
+
for (let i = 0; i < existingCounts.length; i++) {
|
|
555
|
+
const countReceived = countsReceived.find((c) => areTagsEqual(c.filter.tags, existingCounts[i]?.filter.tags));
|
|
556
|
+
newCounts.push(countReceived || oldCounts[i]);
|
|
557
|
+
}
|
|
558
|
+
return newCounts;
|
|
559
|
+
});
|
|
560
|
+
};
|
|
561
|
+
useWebSocketEvent({
|
|
562
|
+
event: "notifications.notification_received",
|
|
563
|
+
eventHandler: (data) => {
|
|
564
|
+
sync(data.result);
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
useWebSocketEvent({
|
|
568
|
+
event: "notifications.unread_count_changed",
|
|
569
|
+
eventHandler: () => {
|
|
570
|
+
sync();
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
useEffect6(() => {
|
|
574
|
+
setError(void 0);
|
|
575
|
+
setIsLoading(true);
|
|
576
|
+
setIsFetching(false);
|
|
577
|
+
sync();
|
|
578
|
+
}, [JSON.stringify(filters)]);
|
|
579
|
+
const refetch = async () => {
|
|
580
|
+
await sync();
|
|
581
|
+
};
|
|
582
|
+
return { counts, error, refetch, isLoading, isFetching };
|
|
583
|
+
};
|
|
244
584
|
export {
|
|
245
585
|
Bell,
|
|
246
586
|
Inbox,
|
|
587
|
+
InboxChild,
|
|
247
588
|
Notifications,
|
|
248
|
-
|
|
589
|
+
NovuProvider,
|
|
590
|
+
Preferences,
|
|
591
|
+
useCounts,
|
|
592
|
+
useNotifications,
|
|
593
|
+
useNovu,
|
|
594
|
+
usePreferences,
|
|
595
|
+
useUnsafeNovu
|
|
249
596
|
};
|
|
250
597
|
//# sourceMappingURL=index.mjs.map
|