m2m-components 5.2.1-alpha-1728044132642-9a8e1e1.0 → 5.2.1
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/chunk-3WB3H5FQ.mjs +2 -0
- package/index.mjs +1 -2
- package/notification/domain.mjs +0 -1
- package/notification/index.js.map +1 -1
- package/notification/index.mjs +1 -2
- package/package.json +1 -1
- package/chunk-IOZIVEOV.mjs +0 -2
- package/chunk-YUHXVW6K.mjs +0 -2
- package/chunk-YUHXVW6K.mjs.map +0 -1
- /package/{chunk-IOZIVEOV.mjs.map → chunk-3WB3H5FQ.mjs.map} +0 -0
package/index.mjs
CHANGED
|
@@ -3,11 +3,10 @@ import "./chunk-YZIPEODC.mjs";
|
|
|
3
3
|
import "./chunk-GHZTTY3R.mjs";
|
|
4
4
|
import "./chunk-RDG67OF7.mjs";
|
|
5
5
|
import "./chunk-IH72EYIB.mjs";
|
|
6
|
-
import "./chunk-
|
|
6
|
+
import "./chunk-3WB3H5FQ.mjs";
|
|
7
7
|
import "./chunk-V65OEKRZ.mjs";
|
|
8
8
|
import "./chunk-ARKJVMNQ.mjs";
|
|
9
9
|
import "./chunk-JTZEHJPB.mjs";
|
|
10
|
-
import "./chunk-YUHXVW6K.mjs";
|
|
11
10
|
import "./chunk-M2D55I4L.mjs";
|
|
12
11
|
import "./chunk-SXIYWN76.mjs";
|
|
13
12
|
import "./chunk-CTGSJWXT.mjs";
|
package/notification/domain.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/notification/index.ts","../../src/notification/api.ts","../../src/endpoints/m2m-notifications.v1.ts","../../src/notification/ServiceIdProvider.tsx","../../src/notification/NotificationProvider.tsx"],"sourcesContent":["export * from \"./domain\";\nexport * from \"./api\";\nexport * from \"./ServiceIdProvider\";\nexport * from \"./NotificationProvider\";\n","import { Subscription } from \"./domain\";\nimport { fetcher } from \"matsuri-hooks\";\nimport { m2mNotifications_v1 } from \"../endpoints/m2m-notifications.v1\";\n\nexport const requestUpdateNotificationStatusToRead = async (\n token: string,\n id: string,\n) => {\n await fetcher(\n m2mNotifications_v1.updateNotificationStatus({\n id,\n }),\n {\n method: \"PUT\",\n token,\n body: JSON.stringify({ status: \"read\" }),\n },\n );\n};\n\nexport const requestSubscribe = async (\n token: string,\n serviceId: string,\n input: Pick<Subscription, \"notificationType\" | \"resourceSubscription\">,\n) => {\n const { error } = await fetcher(m2mNotifications_v1.saveSubscription(), {\n method: \"POST\",\n token,\n body: JSON.stringify({\n ...input,\n serviceId,\n status: \"subscribed\",\n }),\n });\n if (error) {\n console.error(error);\n }\n};\n\nexport const requestUnSubscribe = async (\n token: string,\n serviceId: string,\n input: Pick<Subscription, \"notificationType\" | \"resourceSubscription\">,\n) => {\n const { error } = await fetcher(m2mNotifications_v1.saveSubscription(), {\n method: \"POST\",\n token,\n body: JSON.stringify({\n ...input,\n serviceId,\n status: \"denied\",\n }),\n });\n if (error) {\n console.error(error);\n }\n};\n","/* eslint-disable */\n/**\n * A function that returns the URL part common to the endpoints.\n */\nexport const root = () => {\n let __root = \"\";\n\n if (globalThis.M2M_COMPONENTS_ENV === \"local\") {\n __root = \"\";\n }\n\n if (globalThis.M2M_COMPONENTS_ENV === \"localDev\") {\n __root = \"\";\n }\n\n if (globalThis.M2M_COMPONENTS_ENV === \"development\") {\n __root = \"https://api-notifications.dev.m2msystems.cloud\";\n }\n\n if (globalThis.M2M_COMPONENTS_ENV === \"production\") {\n __root = \"https://api-notifications.m2msystems.cloud\";\n }\n\n return __root;\n};\n/**\n * health check\n *\n */\nexport const healthCheck = () => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`health_check`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\n\n/**\n * 通知を登録する\n *\n */\nexport const registerNotification = () => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`notifications`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\n\n/**\n * 自分宛の通知をserviceIdを使って取得する\n *\n */\nexport const findNotificationsByServiceId = ({ id }: { id: string }) => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`notifications/by_service_id/${id}`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\n\n/**\n * 通知のステータスを更新する\n *\n */\nexport const updateNotificationStatus = ({ id }: { id: string }) => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`notifications/${id}`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\n\n/**\n * 通知の購読を更新する\n *\n */\nexport const saveSubscription = () => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`subscriptions`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\n\n/**\n * 自分の購読している通知を取得する\n *\n */\nexport const findMySubscriptions = () => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`subscriptions`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\nexport const m2mNotifications_v1 = {\n healthCheck,\n registerNotification,\n findNotificationsByServiceId,\n updateNotificationStatus,\n saveSubscription,\n findMySubscriptions,\n};\n","import React, { createContext, useMemo } from \"react\";\n\ninterface ServiceIdContextState {\n serviceId: string;\n}\n\nconst ServiceIdContext = createContext<ServiceIdContextState | undefined>(\n undefined,\n);\n\nexport const ServiceIdProvider = ({\n serviceId,\n children,\n}: {\n serviceId: string;\n children: React.ReactNode;\n}) => {\n const state = useMemo(() => ({ serviceId }), [serviceId]);\n\n return (\n <ServiceIdContext.Provider value={state}>\n {children}\n </ServiceIdContext.Provider>\n );\n};\n\nexport const useServiceId = () => {\n const context = React.useContext(ServiceIdContext);\n if (context === undefined) {\n throw new Error(\"useServiceId must be used within a ServiceIdProvider\");\n }\n return context.serviceId;\n};\n","import { Notification, Subscription, SubscriptionStatus } from \"./domain\";\nimport {\n PropsWithChildren,\n createContext,\n useCallback,\n useContext,\n} from \"react\";\nimport { m2mNotifications_v1 } from \"../endpoints/m2m-notifications.v1\";\nimport { useAuthFetch } from \"matsuri-hooks\";\nimport { useMemo } from \"react\";\nimport { useServiceId } from \"./ServiceIdProvider\";\n\nconst NotificationPermissionContext = createContext<\n | {\n checkPermission: (\n notificationType: string,\n ) => SubscriptionStatus | undefined;\n refetch: () => void;\n }\n | undefined\n>(undefined);\n\nconst NotificationsContext = createContext<\n | { notifications: Notification[]; isAllRead: boolean; refetch: () => void }\n | undefined\n>(undefined);\n\n// ServiceIdProviderの中で使うこと\nexport const NotificationsProvider = ({\n token,\n children,\n}: PropsWithChildren<{ token: string }>) => {\n const serviceId = useServiceId();\n\n const { data: subscriptions, refetch: refetchSubscriptions } = useAuthFetch<\n Subscription[]\n >(token, m2mNotifications_v1.findMySubscriptions(), {});\n const checkPermission = useCallback(\n (notificationType: string) => {\n const subscription = subscriptions?.find((item) => {\n return (\n item.serviceId === serviceId &&\n item.notificationType === notificationType &&\n item.resourceSubscription.resourceSelectType === \"any\"\n );\n });\n\n return subscription?.status;\n },\n [serviceId, subscriptions],\n );\n\n const {\n data: notifications,\n error,\n refetch: refetchNotifications,\n } = useAuthFetch<{ data: Notification[] }>(\n token,\n m2mNotifications_v1.findNotificationsByServiceId({ id: serviceId }),\n { swrConfig: { refreshInterval: 1000 * 60 * 5 } },\n );\n if (error) {\n // エラーが出てもユーザーは特に困らないので、ユーザーに伝える必要はないが、監視は必要。\n console.error(error);\n }\n\n const permissionContextState = useMemo(() => {\n return {\n checkPermission,\n refetch: refetchSubscriptions,\n };\n }, [checkPermission, refetchSubscriptions]);\n\n const notificationsContextState = useMemo(() => {\n return {\n notifications: notifications?.data ?? [],\n isAllRead: notifications?.data.every((n) => n.status === \"read\") ?? true,\n refetch: refetchNotifications,\n };\n }, [refetchNotifications, notifications?.data]);\n\n return (\n <NotificationPermissionContext.Provider value={permissionContextState}>\n <NotificationsContext.Provider value={notificationsContextState}>\n {children}\n </NotificationsContext.Provider>\n </NotificationPermissionContext.Provider>\n );\n};\n\nexport const useNotifications = () => {\n const ctx = useContext(NotificationsContext);\n if (!ctx) {\n throw new Error(\"NotificatoinProvider is not found\");\n }\n\n return ctx;\n};\n\nexport const useNotificationPermission = () => {\n const ctx = useContext(NotificationPermissionContext);\n if (!ctx) {\n throw new Error(\"NotificatoinProvider is not found\");\n }\n\n return ctx;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,2BAAwB;;;ACGjB,IAAM,OAAO,MAAM;AACxB,MAAI,SAAS;AAEb,MAAI,WAAW,uBAAuB,SAAS;AAC7C,aAAS;AAAA,EACX;AAEA,MAAI,WAAW,uBAAuB,YAAY;AAChD,aAAS;AAAA,EACX;AAEA,MAAI,WAAW,uBAAuB,eAAe;AACnD,aAAS;AAAA,EACX;AAEA,MAAI,WAAW,uBAAuB,cAAc;AAClD,aAAS;AAAA,EACX;AAEA,SAAO;AACT;AAKO,IAAM,cAAc,MAAM;AAC/B,QAAM,SAAS,KAAK;AACpB,QAAM,YAAY,OAAO,QAAQ,CAAC,CAAC,EAChC,OAAO,CAAC,CAAC,GAAG,KAAK,MAAM;AACtB,WAAO,UAAU;AAAA,EAC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B,MAAM;AACpC,QAAM,UAAM,0BAAW,oBAAoB;AAC3C,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AAEA,SAAO;AACT;AAEO,IAAM,4BAA4B,MAAM;AAC7C,QAAM,UAAM,0BAAW,6BAA6B;AACpD,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AAEA,SAAO;AACT;","names":["React","import_react","import_matsuri_hooks","import_react","import_jsx_runtime"]}
|
|
1
|
+
{"version":3,"sources":["../../src/notification/index.ts","../../src/notification/api.ts","../../src/endpoints/m2m-notifications.v1.ts","../../src/notification/ServiceIdProvider.tsx","../../src/notification/NotificationProvider.tsx"],"sourcesContent":["export type * from \"./domain\";\nexport * from \"./api\";\nexport * from \"./ServiceIdProvider\";\nexport * from \"./NotificationProvider\";\n","import { Subscription } from \"./domain\";\nimport { fetcher } from \"matsuri-hooks\";\nimport { m2mNotifications_v1 } from \"../endpoints/m2m-notifications.v1\";\n\nexport const requestUpdateNotificationStatusToRead = async (\n token: string,\n id: string,\n) => {\n await fetcher(\n m2mNotifications_v1.updateNotificationStatus({\n id,\n }),\n {\n method: \"PUT\",\n token,\n body: JSON.stringify({ status: \"read\" }),\n },\n );\n};\n\nexport const requestSubscribe = async (\n token: string,\n serviceId: string,\n input: Pick<Subscription, \"notificationType\" | \"resourceSubscription\">,\n) => {\n const { error } = await fetcher(m2mNotifications_v1.saveSubscription(), {\n method: \"POST\",\n token,\n body: JSON.stringify({\n ...input,\n serviceId,\n status: \"subscribed\",\n }),\n });\n if (error) {\n console.error(error);\n }\n};\n\nexport const requestUnSubscribe = async (\n token: string,\n serviceId: string,\n input: Pick<Subscription, \"notificationType\" | \"resourceSubscription\">,\n) => {\n const { error } = await fetcher(m2mNotifications_v1.saveSubscription(), {\n method: \"POST\",\n token,\n body: JSON.stringify({\n ...input,\n serviceId,\n status: \"denied\",\n }),\n });\n if (error) {\n console.error(error);\n }\n};\n","/* eslint-disable */\n/**\n * A function that returns the URL part common to the endpoints.\n */\nexport const root = () => {\n let __root = \"\";\n\n if (globalThis.M2M_COMPONENTS_ENV === \"local\") {\n __root = \"\";\n }\n\n if (globalThis.M2M_COMPONENTS_ENV === \"localDev\") {\n __root = \"\";\n }\n\n if (globalThis.M2M_COMPONENTS_ENV === \"development\") {\n __root = \"https://api-notifications.dev.m2msystems.cloud\";\n }\n\n if (globalThis.M2M_COMPONENTS_ENV === \"production\") {\n __root = \"https://api-notifications.m2msystems.cloud\";\n }\n\n return __root;\n};\n/**\n * health check\n *\n */\nexport const healthCheck = () => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`health_check`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\n\n/**\n * 通知を登録する\n *\n */\nexport const registerNotification = () => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`notifications`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\n\n/**\n * 自分宛の通知をserviceIdを使って取得する\n *\n */\nexport const findNotificationsByServiceId = ({ id }: { id: string }) => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`notifications/by_service_id/${id}`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\n\n/**\n * 通知のステータスを更新する\n *\n */\nexport const updateNotificationStatus = ({ id }: { id: string }) => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`notifications/${id}`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\n\n/**\n * 通知の購読を更新する\n *\n */\nexport const saveSubscription = () => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`subscriptions`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\n\n/**\n * 自分の購読している通知を取得する\n *\n */\nexport const findMySubscriptions = () => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`subscriptions`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\nexport const m2mNotifications_v1 = {\n healthCheck,\n registerNotification,\n findNotificationsByServiceId,\n updateNotificationStatus,\n saveSubscription,\n findMySubscriptions,\n};\n","import React, { createContext, useMemo } from \"react\";\n\ninterface ServiceIdContextState {\n serviceId: string;\n}\n\nconst ServiceIdContext = createContext<ServiceIdContextState | undefined>(\n undefined,\n);\n\nexport const ServiceIdProvider = ({\n serviceId,\n children,\n}: {\n serviceId: string;\n children: React.ReactNode;\n}) => {\n const state = useMemo(() => ({ serviceId }), [serviceId]);\n\n return (\n <ServiceIdContext.Provider value={state}>\n {children}\n </ServiceIdContext.Provider>\n );\n};\n\nexport const useServiceId = () => {\n const context = React.useContext(ServiceIdContext);\n if (context === undefined) {\n throw new Error(\"useServiceId must be used within a ServiceIdProvider\");\n }\n return context.serviceId;\n};\n","import { Notification, Subscription, SubscriptionStatus } from \"./domain\";\nimport {\n PropsWithChildren,\n createContext,\n useCallback,\n useContext,\n} from \"react\";\nimport { m2mNotifications_v1 } from \"../endpoints/m2m-notifications.v1\";\nimport { useAuthFetch } from \"matsuri-hooks\";\nimport { useMemo } from \"react\";\nimport { useServiceId } from \"./ServiceIdProvider\";\n\nconst NotificationPermissionContext = createContext<\n | {\n checkPermission: (\n notificationType: string,\n ) => SubscriptionStatus | undefined;\n refetch: () => void;\n }\n | undefined\n>(undefined);\n\nconst NotificationsContext = createContext<\n | { notifications: Notification[]; isAllRead: boolean; refetch: () => void }\n | undefined\n>(undefined);\n\n// ServiceIdProviderの中で使うこと\nexport const NotificationsProvider = ({\n token,\n children,\n}: PropsWithChildren<{ token: string }>) => {\n const serviceId = useServiceId();\n\n const { data: subscriptions, refetch: refetchSubscriptions } = useAuthFetch<\n Subscription[]\n >(token, m2mNotifications_v1.findMySubscriptions(), {});\n const checkPermission = useCallback(\n (notificationType: string) => {\n const subscription = subscriptions?.find((item) => {\n return (\n item.serviceId === serviceId &&\n item.notificationType === notificationType &&\n item.resourceSubscription.resourceSelectType === \"any\"\n );\n });\n\n return subscription?.status;\n },\n [serviceId, subscriptions],\n );\n\n const {\n data: notifications,\n error,\n refetch: refetchNotifications,\n } = useAuthFetch<{ data: Notification[] }>(\n token,\n m2mNotifications_v1.findNotificationsByServiceId({ id: serviceId }),\n { swrConfig: { refreshInterval: 1000 * 60 * 5 } },\n );\n if (error) {\n // エラーが出てもユーザーは特に困らないので、ユーザーに伝える必要はないが、監視は必要。\n console.error(error);\n }\n\n const permissionContextState = useMemo(() => {\n return {\n checkPermission,\n refetch: refetchSubscriptions,\n };\n }, [checkPermission, refetchSubscriptions]);\n\n const notificationsContextState = useMemo(() => {\n return {\n notifications: notifications?.data ?? [],\n isAllRead: notifications?.data.every((n) => n.status === \"read\") ?? true,\n refetch: refetchNotifications,\n };\n }, [refetchNotifications, notifications?.data]);\n\n return (\n <NotificationPermissionContext.Provider value={permissionContextState}>\n <NotificationsContext.Provider value={notificationsContextState}>\n {children}\n </NotificationsContext.Provider>\n </NotificationPermissionContext.Provider>\n );\n};\n\nexport const useNotifications = () => {\n const ctx = useContext(NotificationsContext);\n if (!ctx) {\n throw new Error(\"NotificatoinProvider is not found\");\n }\n\n return ctx;\n};\n\nexport const useNotificationPermission = () => {\n const ctx = useContext(NotificationPermissionContext);\n if (!ctx) {\n throw new Error(\"NotificatoinProvider is not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KAAK,EAAE,EAAE;AAAA,EAClD;AACA,MAAI,OAAO;AAET,YAAQ,MAAM,KAAK;AAAA,EACrB;AAEA,QAAM,6BAAyB,uBAAQ,MAAM;AAC3C,WAAO;AAAA,MACL;AAAA,MACA,SAAS;AAAA,IACX;AAAA,EACF,GAAG,CAAC,iBAAiB,oBAAoB,CAAC;AAE1C,QAAM,gCAA4B,uBAAQ,MAAM;AAzElD;AA0EI,WAAO;AAAA,MACL,gBAAe,oDAAe,SAAf,YAAuB,CAAC;AAAA,MACvC,YAAW,oDAAe,KAAK,MAAM,CAAC,MAAM,EAAE,WAAW,YAA9C,YAAyD;AAAA,MACpE,SAAS;AAAA,IACX;AAAA,EACF,GAAG,CAAC,sBAAsB,+CAAe,IAAI,CAAC;AAE9C,SACE,6CAAC,8BAA8B,UAA9B,EAAuC,OAAO,wBAC7C,uDAAC,qBAAqB,UAArB,EAA8B,OAAO,2BACnC,UACH,GACF;AAEJ;AAEO,IAAM,mBAAmB,MAAM;AACpC,QAAM,UAAM,0BAAW,oBAAoB;AAC3C,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AAEA,SAAO;AACT;AAEO,IAAM,4BAA4B,MAAM;AAC7C,QAAM,UAAM,0BAAW,6BAA6B;AACpD,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AAEA,SAAO;AACT;","names":["React","import_react","import_matsuri_hooks","import_react","import_jsx_runtime"]}
|
package/notification/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import "../chunk-
|
|
2
|
+
import "../chunk-3WB3H5FQ.mjs";
|
|
3
3
|
import {
|
|
4
4
|
NotificationsProvider,
|
|
5
5
|
useNotificationPermission,
|
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
requestUnSubscribe,
|
|
15
15
|
requestUpdateNotificationStatusToRead
|
|
16
16
|
} from "../chunk-JTZEHJPB.mjs";
|
|
17
|
-
import "../chunk-YUHXVW6K.mjs";
|
|
18
17
|
import "../chunk-M2D55I4L.mjs";
|
|
19
18
|
import "../chunk-QH5I6YL2.mjs";
|
|
20
19
|
export {
|
package/package.json
CHANGED
package/chunk-IOZIVEOV.mjs
DELETED
package/chunk-YUHXVW6K.mjs
DELETED
package/chunk-YUHXVW6K.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
File without changes
|