@novu/react 3.0.0 → 3.0.3
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/cjs/hooks/NovuProvider.cjs +1 -1
- package/dist/esm/hooks/NovuProvider.js +1 -1
- package/package.json +2 -2
- package/dist/client/components/index.d.mts +0 -168
- package/dist/client/components/index.d.ts +0 -168
- package/dist/client/components/index.js +0 -853
- package/dist/client/components/index.js.map +0 -1
- package/dist/client/components/index.mjs +0 -805
- package/dist/client/components/index.mjs.map +0 -1
- package/dist/client/hooks/index.d.mts +0 -75
- package/dist/client/hooks/index.d.ts +0 -75
- package/dist/client/hooks/index.js +0 -395
- package/dist/client/hooks/index.js.map +0 -1
- package/dist/client/hooks/index.mjs +0 -364
- package/dist/client/hooks/index.mjs.map +0 -1
- package/dist/client/themes/index.d.mts +0 -1
- package/dist/client/themes/index.d.ts +0 -1
- package/dist/client/themes/index.js +0 -25
- package/dist/client/themes/index.js.map +0 -1
- package/dist/client/themes/index.mjs +0 -3
- package/dist/client/themes/index.mjs.map +0 -1
- package/dist/server/index.d.mts +0 -141
- package/dist/server/index.d.ts +0 -141
- package/dist/server/index.js +0 -415
- package/dist/server/index.js.map +0 -1
- package/dist/server/index.mjs +0 -379
- package/dist/server/index.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Bell.tsx","../../../src/components/Mounter.tsx","../../../src/components/Renderer.tsx","../../../src/utils/createContextAndHook.ts","../../../src/context/RendererContext.tsx","../../../src/context/NovuUIContext.tsx","../../../src/components/Inbox.tsx","../../../src/hooks/NovuProvider.tsx","../../../src/components/NovuUI.tsx","../../../src/hooks/internal/useDataRef.ts","../../../src/components/Preferences.tsx","../../../src/components/Notifications.tsx","../../../src/components/InboxContent.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":["import React from 'react';\nimport { Mounter } from './Mounter';\nimport { BellRenderer } from '../utils/types';\nimport { withRenderer } from './Renderer';\nimport { useNovuUI } from '../context/NovuUIContext';\nimport { useRenderer } from '../context/RendererContext';\n\nexport type BellProps = {\n renderBell?: BellRenderer;\n};\n\nconst _Bell = React.memo((props: BellProps) => {\n const { renderBell } = props;\n const { novuUI } = useNovuUI();\n const { 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\nexport const Bell = withRenderer(_Bell);\n","import { useEffect, useRef } 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 = useRef<HTMLDivElement>(null);\n\n 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 { ComponentType, PropsWithChildren, useCallback, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { MountedElement, RendererProvider } from '../context/RendererContext';\n\ntype RendererProps = PropsWithChildren;\nexport const Renderer = (props: RendererProps) => {\n const { children } = props;\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 return (\n <RendererProvider value={{ mountElement }}>\n {[...mountedElements].map(([element, mountedElement]) => {\n return createPortal(mountedElement, element);\n })}\n\n {children}\n </RendererProvider>\n );\n};\n\nexport const withRenderer = <P extends object>(\n WrappedComponent: ComponentType<P>\n): ComponentType<P & PropsWithChildren<{}>> => {\n const HOC = (props: P) => {\n return (\n <Renderer>\n <WrappedComponent {...props} />\n </Renderer>\n );\n };\n\n HOC.displayName = `WithRenderer(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;\n\n return HOC;\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 ${Ctx.displayName}`);\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};\n\nconst [RendererContext, useRendererContext, useUnsafeRendererContext] =\n 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, useUnsafeRendererContext as useUnsafeRenderer, RendererProvider };\n","import React from 'react';\nimport type { NovuUI } from '@novu/js/ui';\nimport { createContextAndHook } from '../utils/createContextAndHook';\n\ntype NovuUIContextValue = {\n novuUI: NovuUI;\n};\n\nconst [NovuUIContext, useNovuUIContext, useUnsafeNovuUIContext] =\n createContextAndHook<NovuUIContextValue>('NovuUIContext');\n\nconst NovuUIProvider = (props: React.PropsWithChildren<{ value: NovuUIContextValue }>) => {\n return <NovuUIContext.Provider value={{ value: props.value }}>{props.children}</NovuUIContext.Provider>;\n};\n\nexport { useNovuUIContext as useNovuUI, useUnsafeNovuUIContext as useUnsafeNovuUI, NovuUIProvider };\n","import React, { useMemo } from 'react';\nimport { DefaultProps, DefaultInboxProps, WithChildrenProps } from '../utils/types';\nimport { Mounter } from './Mounter';\nimport { useNovuUI } from '../context/NovuUIContext';\nimport { useRenderer } from '../context/RendererContext';\nimport { InternalNovuProvider, useNovu, useUnsafeNovu } from '../hooks/NovuProvider';\nimport { NovuUI } from './NovuUI';\nimport { withRenderer } from './Renderer';\n\nexport type InboxProps = DefaultProps | WithChildrenProps;\n\nconst _DefaultInbox = (props: DefaultInboxProps) => {\n const {\n open,\n renderNotification,\n renderSubject,\n renderBody,\n renderBell,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n placement,\n placementOffset,\n } = props;\n const { novuUI } = useNovuUI();\n const { mountElement } = useRenderer();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n if (renderNotification) {\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 placementOffset,\n placement,\n },\n element,\n });\n }\n\n return novuUI.mountComponent({\n name: 'Inbox',\n props: {\n open,\n renderSubject: renderSubject\n ? (el, notification) => mountElement(el, renderSubject(notification))\n : undefined,\n renderBody: renderBody ? (el, notification) => mountElement(el, renderBody(notification)) : undefined,\n renderBell: renderBell ? (el, unreadCount) => mountElement(el, renderBell(unreadCount)) : undefined,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n placementOffset,\n placement,\n },\n element,\n });\n },\n [\n open,\n renderNotification,\n renderSubject,\n renderBody,\n renderBell,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n ]\n );\n\n return <Mounter mount={mount} />;\n};\n\nconst DefaultInbox = withRenderer(_DefaultInbox);\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 <InternalNovuProvider\n applicationIdentifier={applicationIdentifier}\n subscriberId={subscriberId}\n subscriberHash={subscriberHash}\n backendUrl={backendUrl}\n socketUrl={socketUrl}\n userAgentType=\"components\"\n >\n <InboxChild {...props} />\n </InternalNovuProvider>\n );\n});\n\nconst InboxChild = React.memo((props: InboxProps) => {\n const {\n localization,\n appearance,\n tabs,\n preferencesFilter,\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 preferencesFilter,\n routerPush,\n options: { applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl },\n };\n }, [\n localization,\n appearance,\n tabs,\n preferencesFilter,\n applicationIdentifier,\n subscriberId,\n subscriberHash,\n backendUrl,\n socketUrl,\n ]);\n\n if (isWithChildrenProps(props)) {\n return (\n <NovuUI options={options} novu={novu}>\n {props.children}\n </NovuUI>\n );\n }\n\n const {\n open,\n renderNotification,\n renderSubject,\n renderBody,\n renderBell,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n placementOffset,\n placement,\n } = props;\n\n return (\n <NovuUI options={options} novu={novu}>\n <DefaultInbox\n open={open}\n renderNotification={renderNotification}\n renderSubject={renderSubject}\n renderBody={renderBody}\n renderBell={renderBell}\n onNotificationClick={onNotificationClick}\n onPrimaryActionClick={onPrimaryActionClick}\n onSecondaryActionClick={onSecondaryActionClick}\n placement={placement}\n placementOffset={placementOffset}\n />\n </NovuUI>\n );\n});\n\nfunction isWithChildrenProps(props: InboxProps): props is WithChildrenProps {\n return 'children' in props;\n}\n","import { Novu, NovuOptions } from '@novu/js';\nimport { ReactNode, createContext, useContext, useMemo } from 'react';\n\n// @ts-ignore\nconst version = PACKAGE_VERSION;\n// @ts-ignore\nconst name = PACKAGE_NAME;\nconst baseUserAgent = `${name}@${version}`;\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 return (\n <InternalNovuProvider\n applicationIdentifier={applicationIdentifier}\n subscriberId={subscriberId}\n subscriberHash={subscriberHash}\n backendUrl={backendUrl}\n socketUrl={socketUrl}\n useCache={useCache}\n userAgentType=\"hooks\"\n >\n {children}\n </InternalNovuProvider>\n );\n};\n\n/**\n * @internal Should be used internally not to be exposed outside of the library\n * This is needed to differentiate between the hooks and components user agents\n * Better to use this internally to avoid confusion.\n */\nexport const InternalNovuProvider = ({\n children,\n applicationIdentifier,\n subscriberId,\n subscriberHash,\n backendUrl,\n socketUrl,\n useCache,\n userAgentType,\n}: NovuProviderProps & { userAgentType: 'components' | 'hooks' }) => {\n const novu = useMemo(\n () =>\n new Novu({\n applicationIdentifier,\n subscriberId,\n subscriberHash,\n backendUrl,\n socketUrl,\n useCache,\n __userAgent: `${baseUserAgent} ${userAgentType}`,\n }),\n [applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache, userAgentType]\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 { Novu } from '@novu/js';\nimport type { NovuUIOptions } from '@novu/js/ui';\nimport { NovuUI as NovuUIClass } from '@novu/js/ui';\nimport React, { useEffect, useState } from 'react';\nimport { NovuUIProvider } from '../context/NovuUIContext';\nimport { useDataRef } from '../hooks/internal/useDataRef';\n\ntype RendererProps = React.PropsWithChildren<{\n options: NovuUIOptions;\n novu?: Novu;\n}>;\n\nexport const NovuUI = ({ options, novu, children }: RendererProps) => {\n const optionsRef = useDataRef({ ...options, novu });\n const [novuUI, setNovuUI] = useState<NovuUIClass | undefined>();\n\n useEffect(() => {\n const novu = new NovuUIClass(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 <NovuUIProvider value={{ novuUI }}>{children}</NovuUIProvider>;\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 { Mounter } from './Mounter';\nimport { useNovuUI } from '../context/NovuUIContext';\n\nexport const Preferences = () => {\n const { novuUI } = useNovuUI();\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 { Mounter } from './Mounter';\nimport { NoRendererProps, NotificationRendererProps, SubjectBodyRendererProps } from '../utils/types';\nimport { useRenderer } from '../context/RendererContext';\nimport { useNovuUI } from '../context/NovuUIContext';\nimport { withRenderer } from './Renderer';\n\nexport type NotificationProps = {\n onNotificationClick?: NotificationClickHandler;\n onPrimaryActionClick?: NotificationActionClickHandler;\n onSecondaryActionClick?: NotificationActionClickHandler;\n} & (NotificationRendererProps | SubjectBodyRendererProps | NoRendererProps);\n\nconst _Notifications = React.memo((props: NotificationProps) => {\n const {\n renderNotification,\n renderSubject,\n renderBody,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n } = props;\n const { novuUI } = useNovuUI();\n const { mountElement } = useRenderer();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n if (renderNotification) {\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\n return novuUI.mountComponent({\n name: 'Notifications',\n element,\n props: {\n renderSubject: renderSubject\n ? (el, notification) => mountElement(el, renderSubject(notification))\n : undefined,\n renderBody: renderBody ? (el, notification) => mountElement(el, renderBody(notification)) : undefined,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n },\n });\n },\n [renderNotification, renderSubject, renderBody, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]\n );\n\n return <Mounter mount={mount} />;\n});\n\nexport const Notifications = withRenderer(_Notifications);\n","import React from 'react';\nimport type { NotificationClickHandler, NotificationActionClickHandler, InboxPage } from '@novu/js/ui';\nimport { Mounter } from './Mounter';\nimport { NoRendererProps, SubjectBodyRendererProps, NotificationRendererProps } from '../utils/types';\nimport { useRenderer } from '../context/RendererContext';\nimport { useNovuUI } from '../context/NovuUIContext';\nimport { withRenderer } from './Renderer';\n\nexport type InboxContentProps = {\n onNotificationClick?: NotificationClickHandler;\n onPrimaryActionClick?: NotificationActionClickHandler;\n onSecondaryActionClick?: NotificationActionClickHandler;\n initialPage?: InboxPage;\n hideNav?: boolean;\n} & (NotificationRendererProps | SubjectBodyRendererProps | NoRendererProps);\n\nconst _InboxContent = React.memo((props: InboxContentProps) => {\n const {\n onNotificationClick,\n onPrimaryActionClick,\n renderNotification,\n renderSubject,\n renderBody,\n onSecondaryActionClick,\n initialPage,\n hideNav,\n } = props;\n const { novuUI } = useNovuUI();\n const { mountElement } = useRenderer();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n if (renderNotification) {\n return novuUI.mountComponent({\n name: 'InboxContent',\n element,\n props: {\n renderNotification: renderNotification\n ? (el, notification) => mountElement(el, renderNotification(notification))\n : undefined,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n initialPage,\n hideNav,\n },\n });\n }\n\n return novuUI.mountComponent({\n name: 'InboxContent',\n element,\n props: {\n renderSubject: renderSubject\n ? (el, notification) => mountElement(el, renderSubject(notification))\n : undefined,\n renderBody: renderBody ? (el, notification) => mountElement(el, renderBody(notification)) : undefined,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n initialPage,\n hideNav,\n },\n });\n },\n [renderNotification, renderSubject, renderBody, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]\n );\n\n return <Mounter mount={mount} />;\n});\n\nexport const InboxContent = withRenderer(_InboxContent);\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 } = 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 const cleanup = on('notifications.list.updated', sync);\n\n return () => {\n cleanup();\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 filter?: { tags?: string[] };\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 } = 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 const listUpdatedCleanup = on('preferences.list.updated', sync);\n const listPendingCleanup = on('preferences.list.pending', sync);\n const listResolvedCleanup = on('preferences.list.resolved', sync);\n\n return () => {\n listUpdatedCleanup();\n listPendingCleanup();\n listResolvedCleanup();\n };\n }, []);\n\n const fetchPreferences = async () => {\n setIsFetching(true);\n const response = await preferences.list(props?.filter);\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\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 let cleanup: () => void;\n const resolveLock = requestLock(`nv.${webSocketEvent}`, () => {\n cleanup = novu.on(webSocketEvent, updateReadCount);\n });\n\n return () => {\n if (cleanup) {\n cleanup();\n }\n\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,OAAOA,YAAW;;;ACAlB,SAAS,WAAW,cAAc;AA6BzB;AApBF,SAAS,QAAQ,EAAE,MAAM,GAAiB;AAC/C,QAAM,MAAM,OAAuB,IAAI;AAEvC,YAAU,MAAM;AACd,QAAI;AACJ,UAAM,UAAU,IAAI;AACpB,QAAI,WAAW,OAAO;AACpB,YAAM,kBAAkB,MAAM,OAAO;AACrC,UAAI,iBAAiB;AACnB,kBAAU;AAAA,MACZ;AAAA,IACF;AAEA,WAAO,MAAM;AACX,UAAI,WAAW,SAAS;AACtB,gBAAQ,OAAO;AAAA,MACjB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,KAAK,KAAK,CAAC;AAEf,SAAO,oBAAC,SAAI,KAAU;AACxB;;;AC9BA,SAA2C,aAAa,gBAAgB;AACxE,SAAS,oBAAoB;;;ACD7B,OAAO,WAAW;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,MAAM,cAA6C,MAAS;AACxE,MAAI,cAAc;AAElB,QAAM,SAAS,MAAM;AACnB,UAAM,MAAM,MAAM,WAAW,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IAChB,OAAO;AAAA,IACP,cAAc,MAAM;AAClB,WAAK;AAAA,IACP;AAAA,EACF,CAAC;AAED,EAAAC,WAAU,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":["React","jsx","jsx","jsx","jsx","React","React","useMemo","jsx","useEffect","useState","useRef","jsx","useState","useEffect","novu","jsx","React","useMemo","React","jsx","React","React","jsx","React","React","jsx","React","useState","useEffect","useRef","useRef","useState","useEffect","useEffect","useState","useState","useEffect","useEffect","useState","useEffect","useEffect","useState","useEffect","useState","useEffect"]}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { Notification, NovuError, Preference, NotificationFilter, Novu, NovuOptions } from '@novu/js';
|
|
2
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
-
import { ReactNode } from 'react';
|
|
4
|
-
|
|
5
|
-
type UseNotificationsProps = {
|
|
6
|
-
tags?: string[];
|
|
7
|
-
read?: boolean;
|
|
8
|
-
archived?: boolean;
|
|
9
|
-
limit?: number;
|
|
10
|
-
onSuccess?: (data: Notification[]) => void;
|
|
11
|
-
onError?: (error: NovuError) => void;
|
|
12
|
-
};
|
|
13
|
-
declare const useNotifications: (props?: UseNotificationsProps) => {
|
|
14
|
-
readAll: () => Promise<{
|
|
15
|
-
data?: void | undefined;
|
|
16
|
-
error?: NovuError | undefined;
|
|
17
|
-
}>;
|
|
18
|
-
archiveAll: () => Promise<{
|
|
19
|
-
data?: void | undefined;
|
|
20
|
-
error?: NovuError | undefined;
|
|
21
|
-
}>;
|
|
22
|
-
archiveAllRead: () => Promise<{
|
|
23
|
-
data?: void | undefined;
|
|
24
|
-
error?: NovuError | undefined;
|
|
25
|
-
}>;
|
|
26
|
-
notifications: Notification[] | undefined;
|
|
27
|
-
error: NovuError | undefined;
|
|
28
|
-
isLoading: boolean;
|
|
29
|
-
isFetching: boolean;
|
|
30
|
-
refetch: () => Promise<void>;
|
|
31
|
-
fetchMore: () => Promise<void>;
|
|
32
|
-
hasMore: boolean;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
type UsePreferencesProps = {
|
|
36
|
-
filter?: {
|
|
37
|
-
tags?: string[];
|
|
38
|
-
};
|
|
39
|
-
onSuccess?: (data: Preference[]) => void;
|
|
40
|
-
onError?: (error: NovuError) => void;
|
|
41
|
-
};
|
|
42
|
-
type UsePreferencesResult = {
|
|
43
|
-
preferences?: Preference[];
|
|
44
|
-
error?: NovuError;
|
|
45
|
-
isLoading: boolean;
|
|
46
|
-
isFetching: boolean;
|
|
47
|
-
refetch: () => Promise<void>;
|
|
48
|
-
};
|
|
49
|
-
declare const usePreferences: (props?: UsePreferencesProps) => UsePreferencesResult;
|
|
50
|
-
|
|
51
|
-
type Count = {
|
|
52
|
-
count: number;
|
|
53
|
-
filter: NotificationFilter;
|
|
54
|
-
};
|
|
55
|
-
type UseCountsProps = {
|
|
56
|
-
filters: NotificationFilter[];
|
|
57
|
-
onSuccess?: (data: Count[]) => void;
|
|
58
|
-
onError?: (error: NovuError) => void;
|
|
59
|
-
};
|
|
60
|
-
type UseCountsResult = {
|
|
61
|
-
counts?: Count[];
|
|
62
|
-
error?: NovuError;
|
|
63
|
-
isLoading: boolean;
|
|
64
|
-
isFetching: boolean;
|
|
65
|
-
refetch: () => Promise<void>;
|
|
66
|
-
};
|
|
67
|
-
declare const useCounts: (props: UseCountsProps) => UseCountsResult;
|
|
68
|
-
|
|
69
|
-
type NovuProviderProps = NovuOptions & {
|
|
70
|
-
children: ReactNode;
|
|
71
|
-
};
|
|
72
|
-
declare const NovuProvider: ({ children, applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache, }: NovuProviderProps) => react_jsx_runtime.JSX.Element;
|
|
73
|
-
declare const useNovu: () => Novu;
|
|
74
|
-
|
|
75
|
-
export { NovuProvider, type UseNotificationsProps, useCounts, useNotifications, useNovu, usePreferences };
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { Notification, NovuError, Preference, NotificationFilter, Novu, NovuOptions } from '@novu/js';
|
|
2
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
-
import { ReactNode } from 'react';
|
|
4
|
-
|
|
5
|
-
type UseNotificationsProps = {
|
|
6
|
-
tags?: string[];
|
|
7
|
-
read?: boolean;
|
|
8
|
-
archived?: boolean;
|
|
9
|
-
limit?: number;
|
|
10
|
-
onSuccess?: (data: Notification[]) => void;
|
|
11
|
-
onError?: (error: NovuError) => void;
|
|
12
|
-
};
|
|
13
|
-
declare const useNotifications: (props?: UseNotificationsProps) => {
|
|
14
|
-
readAll: () => Promise<{
|
|
15
|
-
data?: void | undefined;
|
|
16
|
-
error?: NovuError | undefined;
|
|
17
|
-
}>;
|
|
18
|
-
archiveAll: () => Promise<{
|
|
19
|
-
data?: void | undefined;
|
|
20
|
-
error?: NovuError | undefined;
|
|
21
|
-
}>;
|
|
22
|
-
archiveAllRead: () => Promise<{
|
|
23
|
-
data?: void | undefined;
|
|
24
|
-
error?: NovuError | undefined;
|
|
25
|
-
}>;
|
|
26
|
-
notifications: Notification[] | undefined;
|
|
27
|
-
error: NovuError | undefined;
|
|
28
|
-
isLoading: boolean;
|
|
29
|
-
isFetching: boolean;
|
|
30
|
-
refetch: () => Promise<void>;
|
|
31
|
-
fetchMore: () => Promise<void>;
|
|
32
|
-
hasMore: boolean;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
type UsePreferencesProps = {
|
|
36
|
-
filter?: {
|
|
37
|
-
tags?: string[];
|
|
38
|
-
};
|
|
39
|
-
onSuccess?: (data: Preference[]) => void;
|
|
40
|
-
onError?: (error: NovuError) => void;
|
|
41
|
-
};
|
|
42
|
-
type UsePreferencesResult = {
|
|
43
|
-
preferences?: Preference[];
|
|
44
|
-
error?: NovuError;
|
|
45
|
-
isLoading: boolean;
|
|
46
|
-
isFetching: boolean;
|
|
47
|
-
refetch: () => Promise<void>;
|
|
48
|
-
};
|
|
49
|
-
declare const usePreferences: (props?: UsePreferencesProps) => UsePreferencesResult;
|
|
50
|
-
|
|
51
|
-
type Count = {
|
|
52
|
-
count: number;
|
|
53
|
-
filter: NotificationFilter;
|
|
54
|
-
};
|
|
55
|
-
type UseCountsProps = {
|
|
56
|
-
filters: NotificationFilter[];
|
|
57
|
-
onSuccess?: (data: Count[]) => void;
|
|
58
|
-
onError?: (error: NovuError) => void;
|
|
59
|
-
};
|
|
60
|
-
type UseCountsResult = {
|
|
61
|
-
counts?: Count[];
|
|
62
|
-
error?: NovuError;
|
|
63
|
-
isLoading: boolean;
|
|
64
|
-
isFetching: boolean;
|
|
65
|
-
refetch: () => Promise<void>;
|
|
66
|
-
};
|
|
67
|
-
declare const useCounts: (props: UseCountsProps) => UseCountsResult;
|
|
68
|
-
|
|
69
|
-
type NovuProviderProps = NovuOptions & {
|
|
70
|
-
children: ReactNode;
|
|
71
|
-
};
|
|
72
|
-
declare const NovuProvider: ({ children, applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache, }: NovuProviderProps) => react_jsx_runtime.JSX.Element;
|
|
73
|
-
declare const useNovu: () => Novu;
|
|
74
|
-
|
|
75
|
-
export { NovuProvider, type UseNotificationsProps, useCounts, useNotifications, useNovu, usePreferences };
|
|
@@ -1,395 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name2 in all)
|
|
8
|
-
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/hooks/index.ts
|
|
21
|
-
var hooks_exports = {};
|
|
22
|
-
__export(hooks_exports, {
|
|
23
|
-
NovuProvider: () => NovuProvider,
|
|
24
|
-
useCounts: () => useCounts,
|
|
25
|
-
useNotifications: () => useNotifications,
|
|
26
|
-
useNovu: () => useNovu,
|
|
27
|
-
usePreferences: () => usePreferences
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(hooks_exports);
|
|
30
|
-
|
|
31
|
-
// src/hooks/useNotifications.ts
|
|
32
|
-
var import_react2 = require("react");
|
|
33
|
-
var import_js2 = require("@novu/js");
|
|
34
|
-
|
|
35
|
-
// src/hooks/NovuProvider.tsx
|
|
36
|
-
var import_js = require("@novu/js");
|
|
37
|
-
var import_react = require("react");
|
|
38
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
39
|
-
var version = "2.6.6";
|
|
40
|
-
var name = "@novu/react";
|
|
41
|
-
var baseUserAgent = `${name}@${version}`;
|
|
42
|
-
var NovuContext = (0, import_react.createContext)(void 0);
|
|
43
|
-
var NovuProvider = ({
|
|
44
|
-
children,
|
|
45
|
-
applicationIdentifier,
|
|
46
|
-
subscriberId,
|
|
47
|
-
subscriberHash,
|
|
48
|
-
backendUrl,
|
|
49
|
-
socketUrl,
|
|
50
|
-
useCache
|
|
51
|
-
}) => {
|
|
52
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
53
|
-
InternalNovuProvider,
|
|
54
|
-
{
|
|
55
|
-
applicationIdentifier,
|
|
56
|
-
subscriberId,
|
|
57
|
-
subscriberHash,
|
|
58
|
-
backendUrl,
|
|
59
|
-
socketUrl,
|
|
60
|
-
useCache,
|
|
61
|
-
userAgentType: "hooks",
|
|
62
|
-
children
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
};
|
|
66
|
-
var InternalNovuProvider = ({
|
|
67
|
-
children,
|
|
68
|
-
applicationIdentifier,
|
|
69
|
-
subscriberId,
|
|
70
|
-
subscriberHash,
|
|
71
|
-
backendUrl,
|
|
72
|
-
socketUrl,
|
|
73
|
-
useCache,
|
|
74
|
-
userAgentType
|
|
75
|
-
}) => {
|
|
76
|
-
const novu = (0, import_react.useMemo)(
|
|
77
|
-
() => new import_js.Novu({
|
|
78
|
-
applicationIdentifier,
|
|
79
|
-
subscriberId,
|
|
80
|
-
subscriberHash,
|
|
81
|
-
backendUrl,
|
|
82
|
-
socketUrl,
|
|
83
|
-
useCache,
|
|
84
|
-
__userAgent: `${baseUserAgent} ${userAgentType}`
|
|
85
|
-
}),
|
|
86
|
-
[applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache, userAgentType]
|
|
87
|
-
);
|
|
88
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NovuContext.Provider, { value: novu, children });
|
|
89
|
-
};
|
|
90
|
-
var useNovu = () => {
|
|
91
|
-
const context = (0, import_react.useContext)(NovuContext);
|
|
92
|
-
if (!context) {
|
|
93
|
-
throw new Error("useNovu must be used within a <NovuProvider />");
|
|
94
|
-
}
|
|
95
|
-
return context;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// src/hooks/useNotifications.ts
|
|
99
|
-
var useNotifications = (props) => {
|
|
100
|
-
const { tags, read, archived = false, limit, onSuccess, onError } = props || {};
|
|
101
|
-
const filterRef = (0, import_react2.useRef)(void 0);
|
|
102
|
-
const { notifications, on } = useNovu();
|
|
103
|
-
const [data, setData] = (0, import_react2.useState)();
|
|
104
|
-
const [error, setError] = (0, import_react2.useState)();
|
|
105
|
-
const [isLoading, setIsLoading] = (0, import_react2.useState)(true);
|
|
106
|
-
const [isFetching, setIsFetching] = (0, import_react2.useState)(false);
|
|
107
|
-
const [hasMore, setHasMore] = (0, import_react2.useState)(false);
|
|
108
|
-
const length = data?.length;
|
|
109
|
-
const after = length ? data[length - 1].id : void 0;
|
|
110
|
-
const sync = (event) => {
|
|
111
|
-
if (!event.data || filterRef.current && !(0, import_js2.isSameFilter)(filterRef.current, event.data.filter)) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
setData(event.data.notifications);
|
|
115
|
-
setHasMore(event.data.hasMore);
|
|
116
|
-
};
|
|
117
|
-
(0, import_react2.useEffect)(() => {
|
|
118
|
-
const cleanup = on("notifications.list.updated", sync);
|
|
119
|
-
return () => {
|
|
120
|
-
cleanup();
|
|
121
|
-
};
|
|
122
|
-
}, []);
|
|
123
|
-
(0, import_react2.useEffect)(() => {
|
|
124
|
-
const newFilter = { tags, read, archived };
|
|
125
|
-
if (filterRef.current && (0, import_js2.isSameFilter)(filterRef.current, newFilter)) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
notifications.clearCache({ filter: filterRef.current });
|
|
129
|
-
filterRef.current = newFilter;
|
|
130
|
-
fetchNotifications({ refetch: true });
|
|
131
|
-
}, [tags, read, archived]);
|
|
132
|
-
const fetchNotifications = async (options) => {
|
|
133
|
-
if (options?.refetch) {
|
|
134
|
-
setError(void 0);
|
|
135
|
-
setIsLoading(true);
|
|
136
|
-
setIsFetching(false);
|
|
137
|
-
}
|
|
138
|
-
setIsFetching(true);
|
|
139
|
-
const response = await notifications.list({
|
|
140
|
-
tags,
|
|
141
|
-
read,
|
|
142
|
-
archived,
|
|
143
|
-
limit,
|
|
144
|
-
after: options?.refetch ? void 0 : after
|
|
145
|
-
});
|
|
146
|
-
if (response.error) {
|
|
147
|
-
setError(response.error);
|
|
148
|
-
onError?.(response.error);
|
|
149
|
-
} else {
|
|
150
|
-
onSuccess?.(response.data.notifications);
|
|
151
|
-
setData(response.data.notifications);
|
|
152
|
-
setHasMore(response.data.hasMore);
|
|
153
|
-
}
|
|
154
|
-
setIsLoading(false);
|
|
155
|
-
setIsFetching(false);
|
|
156
|
-
};
|
|
157
|
-
const refetch = () => {
|
|
158
|
-
notifications.clearCache({ filter: { tags, read, archived } });
|
|
159
|
-
return fetchNotifications({ refetch: true });
|
|
160
|
-
};
|
|
161
|
-
const fetchMore = async () => {
|
|
162
|
-
if (!hasMore || isFetching) return;
|
|
163
|
-
return fetchNotifications();
|
|
164
|
-
};
|
|
165
|
-
const readAll = async () => {
|
|
166
|
-
return await notifications.readAll({ tags });
|
|
167
|
-
};
|
|
168
|
-
const archiveAll = async () => {
|
|
169
|
-
return await notifications.archiveAll({ tags });
|
|
170
|
-
};
|
|
171
|
-
const archiveAllRead = async () => {
|
|
172
|
-
return await notifications.archiveAllRead({ tags });
|
|
173
|
-
};
|
|
174
|
-
return {
|
|
175
|
-
readAll,
|
|
176
|
-
archiveAll,
|
|
177
|
-
archiveAllRead,
|
|
178
|
-
notifications: data,
|
|
179
|
-
error,
|
|
180
|
-
isLoading,
|
|
181
|
-
isFetching,
|
|
182
|
-
refetch,
|
|
183
|
-
fetchMore,
|
|
184
|
-
hasMore
|
|
185
|
-
};
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
// src/hooks/usePreferences.ts
|
|
189
|
-
var import_react3 = require("react");
|
|
190
|
-
var usePreferences = (props) => {
|
|
191
|
-
const { onSuccess, onError } = props || {};
|
|
192
|
-
const [data, setData] = (0, import_react3.useState)();
|
|
193
|
-
const { preferences, on } = useNovu();
|
|
194
|
-
const [error, setError] = (0, import_react3.useState)();
|
|
195
|
-
const [isLoading, setIsLoading] = (0, import_react3.useState)(true);
|
|
196
|
-
const [isFetching, setIsFetching] = (0, import_react3.useState)(false);
|
|
197
|
-
const sync = (event) => {
|
|
198
|
-
if (!event.data) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
setData(event.data);
|
|
202
|
-
};
|
|
203
|
-
(0, import_react3.useEffect)(() => {
|
|
204
|
-
fetchPreferences();
|
|
205
|
-
const listUpdatedCleanup = on("preferences.list.updated", sync);
|
|
206
|
-
const listPendingCleanup = on("preferences.list.pending", sync);
|
|
207
|
-
const listResolvedCleanup = on("preferences.list.resolved", sync);
|
|
208
|
-
return () => {
|
|
209
|
-
listUpdatedCleanup();
|
|
210
|
-
listPendingCleanup();
|
|
211
|
-
listResolvedCleanup();
|
|
212
|
-
};
|
|
213
|
-
}, []);
|
|
214
|
-
const fetchPreferences = async () => {
|
|
215
|
-
setIsFetching(true);
|
|
216
|
-
const response = await preferences.list(props?.filter);
|
|
217
|
-
if (response.error) {
|
|
218
|
-
setError(response.error);
|
|
219
|
-
onError?.(response.error);
|
|
220
|
-
} else {
|
|
221
|
-
onSuccess?.(response.data);
|
|
222
|
-
}
|
|
223
|
-
setIsLoading(false);
|
|
224
|
-
setIsFetching(false);
|
|
225
|
-
};
|
|
226
|
-
const refetch = () => {
|
|
227
|
-
preferences.cache.clearAll();
|
|
228
|
-
return fetchPreferences();
|
|
229
|
-
};
|
|
230
|
-
return {
|
|
231
|
-
preferences: data,
|
|
232
|
-
error,
|
|
233
|
-
isLoading,
|
|
234
|
-
isFetching,
|
|
235
|
-
refetch
|
|
236
|
-
};
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
// src/hooks/useCounts.ts
|
|
240
|
-
var import_react6 = require("react");
|
|
241
|
-
var import_js3 = require("@novu/js");
|
|
242
|
-
|
|
243
|
-
// src/hooks/internal/useWebsocketEvent.ts
|
|
244
|
-
var import_react5 = require("react");
|
|
245
|
-
|
|
246
|
-
// src/utils/requestLock.ts
|
|
247
|
-
function requestLock(id, cb) {
|
|
248
|
-
if (!("locks" in navigator)) {
|
|
249
|
-
cb(id);
|
|
250
|
-
return () => {
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
let isFulfilled = false;
|
|
254
|
-
let promiseResolve;
|
|
255
|
-
const promise = new Promise((resolve) => {
|
|
256
|
-
promiseResolve = resolve;
|
|
257
|
-
});
|
|
258
|
-
navigator.locks.request(id, () => {
|
|
259
|
-
if (!isFulfilled) {
|
|
260
|
-
cb(id);
|
|
261
|
-
}
|
|
262
|
-
return promise;
|
|
263
|
-
});
|
|
264
|
-
return () => {
|
|
265
|
-
isFulfilled = true;
|
|
266
|
-
promiseResolve();
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// src/hooks/internal/useBrowserTabsChannel.ts
|
|
271
|
-
var import_react4 = require("react");
|
|
272
|
-
var useBrowserTabsChannel = ({
|
|
273
|
-
channelName,
|
|
274
|
-
onMessage
|
|
275
|
-
}) => {
|
|
276
|
-
const [tabsChannel] = (0, import_react4.useState)(
|
|
277
|
-
typeof BroadcastChannel !== "undefined" ? new BroadcastChannel(channelName) : void 0
|
|
278
|
-
);
|
|
279
|
-
const postMessage = (data) => {
|
|
280
|
-
tabsChannel?.postMessage(data);
|
|
281
|
-
};
|
|
282
|
-
(0, import_react4.useEffect)(() => {
|
|
283
|
-
const listener = (event) => {
|
|
284
|
-
onMessage(event.data);
|
|
285
|
-
};
|
|
286
|
-
tabsChannel?.addEventListener("message", listener);
|
|
287
|
-
return () => {
|
|
288
|
-
tabsChannel?.removeEventListener("message", listener);
|
|
289
|
-
};
|
|
290
|
-
}, []);
|
|
291
|
-
return { postMessage };
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
// src/hooks/internal/useWebsocketEvent.ts
|
|
295
|
-
var useWebSocketEvent = ({
|
|
296
|
-
event: webSocketEvent,
|
|
297
|
-
eventHandler: onMessage
|
|
298
|
-
}) => {
|
|
299
|
-
const novu = useNovu();
|
|
300
|
-
const { postMessage } = useBrowserTabsChannel({ channelName: `nv.${webSocketEvent}`, onMessage });
|
|
301
|
-
const updateReadCount = (data) => {
|
|
302
|
-
onMessage(data);
|
|
303
|
-
postMessage(data);
|
|
304
|
-
};
|
|
305
|
-
(0, import_react5.useEffect)(() => {
|
|
306
|
-
let cleanup;
|
|
307
|
-
const resolveLock = requestLock(`nv.${webSocketEvent}`, () => {
|
|
308
|
-
cleanup = novu.on(webSocketEvent, updateReadCount);
|
|
309
|
-
});
|
|
310
|
-
return () => {
|
|
311
|
-
if (cleanup) {
|
|
312
|
-
cleanup();
|
|
313
|
-
}
|
|
314
|
-
resolveLock();
|
|
315
|
-
};
|
|
316
|
-
}, []);
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
// src/hooks/useCounts.ts
|
|
320
|
-
var useCounts = (props) => {
|
|
321
|
-
const { filters, onSuccess, onError } = props;
|
|
322
|
-
const { notifications } = useNovu();
|
|
323
|
-
const [error, setError] = (0, import_react6.useState)();
|
|
324
|
-
const [counts, setCounts] = (0, import_react6.useState)();
|
|
325
|
-
const [isLoading, setIsLoading] = (0, import_react6.useState)(true);
|
|
326
|
-
const [isFetching, setIsFetching] = (0, import_react6.useState)(false);
|
|
327
|
-
const sync = async (notification) => {
|
|
328
|
-
const existingCounts = counts ?? new Array(filters.length).fill(void 0);
|
|
329
|
-
let countFiltersToFetch = [];
|
|
330
|
-
if (notification) {
|
|
331
|
-
for (let i = 0; i < existingCounts.length; i++) {
|
|
332
|
-
const filter = filters[i];
|
|
333
|
-
if ((0, import_js3.areTagsEqual)(filter.tags, notification.tags)) {
|
|
334
|
-
countFiltersToFetch.push(filter);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
} else {
|
|
338
|
-
countFiltersToFetch = filters;
|
|
339
|
-
}
|
|
340
|
-
if (countFiltersToFetch.length === 0) {
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
setIsFetching(true);
|
|
344
|
-
const countsRes = await notifications.count({ filters: countFiltersToFetch });
|
|
345
|
-
setIsFetching(false);
|
|
346
|
-
setIsLoading(false);
|
|
347
|
-
if (countsRes.error) {
|
|
348
|
-
setError(countsRes.error);
|
|
349
|
-
onError?.(countsRes.error);
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
const data = countsRes.data;
|
|
353
|
-
onSuccess?.(data.counts);
|
|
354
|
-
setCounts((oldCounts) => {
|
|
355
|
-
const newCounts = [];
|
|
356
|
-
const countsReceived = data.counts;
|
|
357
|
-
for (let i = 0; i < existingCounts.length; i++) {
|
|
358
|
-
const countReceived = countsReceived.find((c) => (0, import_js3.areTagsEqual)(c.filter.tags, existingCounts[i]?.filter.tags));
|
|
359
|
-
newCounts.push(countReceived || oldCounts[i]);
|
|
360
|
-
}
|
|
361
|
-
return newCounts;
|
|
362
|
-
});
|
|
363
|
-
};
|
|
364
|
-
useWebSocketEvent({
|
|
365
|
-
event: "notifications.notification_received",
|
|
366
|
-
eventHandler: (data) => {
|
|
367
|
-
sync(data.result);
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
useWebSocketEvent({
|
|
371
|
-
event: "notifications.unread_count_changed",
|
|
372
|
-
eventHandler: () => {
|
|
373
|
-
sync();
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
(0, import_react6.useEffect)(() => {
|
|
377
|
-
setError(void 0);
|
|
378
|
-
setIsLoading(true);
|
|
379
|
-
setIsFetching(false);
|
|
380
|
-
sync();
|
|
381
|
-
}, [JSON.stringify(filters)]);
|
|
382
|
-
const refetch = async () => {
|
|
383
|
-
await sync();
|
|
384
|
-
};
|
|
385
|
-
return { counts, error, refetch, isLoading, isFetching };
|
|
386
|
-
};
|
|
387
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
388
|
-
0 && (module.exports = {
|
|
389
|
-
NovuProvider,
|
|
390
|
-
useCounts,
|
|
391
|
-
useNotifications,
|
|
392
|
-
useNovu,
|
|
393
|
-
usePreferences
|
|
394
|
-
});
|
|
395
|
-
//# sourceMappingURL=index.js.map
|