@burdenoff/microfe-notification 2026.1029.1 → 2026.1109.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.
Files changed (218) hide show
  1. package/dist/AdminNotificationRoot.d.ts +33 -0
  2. package/dist/AdminNotificationRoot.js +9 -6
  3. package/dist/AdminNotificationRoot.js.map +1 -1
  4. package/dist/AdminNotificationRoutes.d.ts +1 -0
  5. package/dist/AdminNotificationRoutes.js +22 -23
  6. package/dist/AdminNotificationRoutes.js.map +1 -1
  7. package/dist/NotificationRoot.d.ts +29 -0
  8. package/dist/NotificationRoot.js +9 -6
  9. package/dist/NotificationRoot.js.map +1 -1
  10. package/dist/NotificationRoutes.d.ts +18 -0
  11. package/dist/NotificationRoutes.js +1 -2
  12. package/dist/NotificationRoutes.js.map +1 -1
  13. package/dist/UserNotificationRoot.d.ts +32 -0
  14. package/dist/UserNotificationRoot.js +9 -6
  15. package/dist/UserNotificationRoot.js.map +1 -1
  16. package/dist/UserNotificationRoutes.d.ts +16 -0
  17. package/dist/UserNotificationRoutes.js +9 -10
  18. package/dist/UserNotificationRoutes.js.map +1 -1
  19. package/dist/components/FeatureDisabledPage.d.ts +6 -0
  20. package/dist/components/FeatureDisabledPage.js +1 -2
  21. package/dist/components/FeatureDisabledPage.js.map +1 -1
  22. package/dist/components/NotificationBell.d.ts +13 -0
  23. package/dist/components/NotificationBell.js +6 -7
  24. package/dist/components/NotificationBell.js.map +1 -1
  25. package/dist/components/NotificationCard.d.ts +18 -0
  26. package/dist/components/NotificationCard.js +10 -11
  27. package/dist/components/NotificationCard.js.map +1 -1
  28. package/dist/components/NotificationPanel.d.ts +10 -0
  29. package/dist/components/NotificationPanel.js +5 -6
  30. package/dist/components/NotificationPanel.js.map +1 -1
  31. package/dist/components/RecipientSelector.d.ts +32 -0
  32. package/dist/components/RecipientSelector.js +2 -3
  33. package/dist/components/RecipientSelector.js.map +1 -1
  34. package/dist/components/TemplatePreview.d.ts +21 -0
  35. package/dist/components/TemplatePreview.js +3 -4
  36. package/dist/components/TemplatePreview.js.map +1 -1
  37. package/dist/components/VariableInserter.d.ts +11 -0
  38. package/dist/components/index.d.ts +3 -0
  39. package/dist/components/index.js +4 -3
  40. package/dist/constants/permissions.d.ts +23 -0
  41. package/dist/constants/permissions.js +1 -2
  42. package/dist/constants/permissions.js.map +1 -1
  43. package/dist/dev/main.d.ts +0 -0
  44. package/dist/generated/global-operations.d.ts +2119 -0
  45. package/dist/generated/global-operations.js +80 -69
  46. package/dist/generated/global-operations.js.map +1 -1
  47. package/dist/generated/global-types.d.ts +23507 -0
  48. package/dist/generated/wspace-operations.d.ts +4 -0
  49. package/dist/generated/wspace-types.d.ts +57831 -0
  50. package/dist/graphql/global-client.d.ts +32 -0
  51. package/dist/graphql/global-client.js +23 -30
  52. package/dist/graphql/global-client.js.map +1 -1
  53. package/dist/hooks/index.d.ts +7 -0
  54. package/dist/hooks/index.js +7 -6
  55. package/dist/hooks/useNotificationAdmin.d.ts +46 -0
  56. package/dist/hooks/useNotificationAdmin.js +18 -17
  57. package/dist/hooks/useNotificationAdmin.js.map +1 -1
  58. package/dist/hooks/useNotificationAnalytics.d.ts +65 -0
  59. package/dist/hooks/useNotificationAnalytics.js +1 -2
  60. package/dist/hooks/useNotificationAnalytics.js.map +1 -1
  61. package/dist/hooks/useNotificationPreferences.d.ts +10 -0
  62. package/dist/hooks/useNotificationPreferences.js +7 -7
  63. package/dist/hooks/useNotificationPreferences.js.map +1 -1
  64. package/dist/hooks/useNotificationTemplates.d.ts +131 -0
  65. package/dist/hooks/useNotificationTemplates.js +1 -2
  66. package/dist/hooks/useNotificationTemplates.js.map +1 -1
  67. package/dist/hooks/useNotificationTopics.d.ts +35 -0
  68. package/dist/hooks/useNotificationTopics.js +22 -22
  69. package/dist/hooks/useNotificationTopics.js.map +1 -1
  70. package/dist/hooks/useNotifications.d.ts +39 -0
  71. package/dist/hooks/useNotifications.js +6 -4
  72. package/dist/hooks/useNotifications.js.map +1 -1
  73. package/dist/hooks/useSendNotification.d.ts +158 -0
  74. package/dist/hooks/useSendNotification.js +12 -10
  75. package/dist/hooks/useSendNotification.js.map +1 -1
  76. package/dist/hooks/useUserSearch.d.ts +26 -0
  77. package/dist/hooks/useUserSearch.js +8 -10
  78. package/dist/hooks/useUserSearch.js.map +1 -1
  79. package/dist/index.d.ts +36 -0
  80. package/dist/index.js +8 -8
  81. package/dist/node_modules/@apollo/client/errors/CombinedGraphQLErrors.js +1 -2
  82. package/dist/node_modules/@apollo/client/errors/CombinedGraphQLErrors.js.map +1 -1
  83. package/dist/node_modules/@apollo/client/errors/utils.js +1 -2
  84. package/dist/node_modules/@apollo/client/errors/utils.js.map +1 -1
  85. package/dist/node_modules/@apollo/client/link/core/ApolloLink.js +7 -8
  86. package/dist/node_modules/@apollo/client/link/core/ApolloLink.js.map +1 -1
  87. package/dist/node_modules/@apollo/client/link/subscriptions/index.js +9 -10
  88. package/dist/node_modules/@apollo/client/link/subscriptions/index.js.map +1 -1
  89. package/dist/node_modules/@apollo/client/link/utils/createOperation.js +5 -6
  90. package/dist/node_modules/@apollo/client/link/utils/createOperation.js.map +1 -1
  91. package/dist/node_modules/@apollo/client/utilities/caching/sizes.js +0 -1
  92. package/dist/node_modules/@apollo/client/utilities/caching/sizes.js.map +1 -1
  93. package/dist/node_modules/@apollo/client/utilities/graphql/print.js +4 -5
  94. package/dist/node_modules/@apollo/client/utilities/graphql/print.js.map +1 -1
  95. package/dist/node_modules/@apollo/client/utilities/internal/caches.js +1 -2
  96. package/dist/node_modules/@apollo/client/utilities/internal/caches.js.map +1 -1
  97. package/dist/node_modules/@apollo/client/utilities/internal/checkDocument.js +1 -2
  98. package/dist/node_modules/@apollo/client/utilities/internal/checkDocument.js.map +1 -1
  99. package/dist/node_modules/@apollo/client/utilities/internal/getMainDefinition.js +2 -3
  100. package/dist/node_modules/@apollo/client/utilities/internal/getMainDefinition.js.map +1 -1
  101. package/dist/node_modules/@apollo/client/utilities/internal/getMemoryInternals.js +1 -2
  102. package/dist/node_modules/@apollo/client/utilities/internal/getMemoryInternals.js.map +1 -1
  103. package/dist/node_modules/@apollo/client/utilities/internal/getOperationDefinition.js +1 -2
  104. package/dist/node_modules/@apollo/client/utilities/internal/getOperationDefinition.js.map +1 -1
  105. package/dist/node_modules/@apollo/client/utilities/internal/getOperationName.js +1 -2
  106. package/dist/node_modules/@apollo/client/utilities/internal/getOperationName.js.map +1 -1
  107. package/dist/node_modules/@apollo/client/utilities/internal/globals/global.js +1 -2
  108. package/dist/node_modules/@apollo/client/utilities/internal/globals/global.js.map +1 -1
  109. package/dist/node_modules/@apollo/client/utilities/internal/globals/maybe.js +1 -2
  110. package/dist/node_modules/@apollo/client/utilities/internal/globals/maybe.js.map +1 -1
  111. package/dist/node_modules/@apollo/client/utilities/internal/isNonNullObject.js +1 -2
  112. package/dist/node_modules/@apollo/client/utilities/internal/isNonNullObject.js.map +1 -1
  113. package/dist/node_modules/@apollo/client/utilities/internal/makeUniqueId.js +1 -2
  114. package/dist/node_modules/@apollo/client/utilities/internal/makeUniqueId.js.map +1 -1
  115. package/dist/node_modules/@apollo/client/utilities/internal/memoize.js +1 -2
  116. package/dist/node_modules/@apollo/client/utilities/internal/memoize.js.map +1 -1
  117. package/dist/node_modules/@apollo/client/utilities/internal/stringifyForDisplay.js +1 -2
  118. package/dist/node_modules/@apollo/client/utilities/internal/stringifyForDisplay.js.map +1 -1
  119. package/dist/node_modules/@apollo/client/utilities/invariant/index.js +2 -3
  120. package/dist/node_modules/@apollo/client/utilities/invariant/index.js.map +1 -1
  121. package/dist/node_modules/@apollo/client/version.js +2 -3
  122. package/dist/node_modules/@apollo/client/version.js.map +1 -1
  123. package/dist/node_modules/@wry/caches/lib/weak.js +1 -2
  124. package/dist/node_modules/@wry/caches/lib/weak.js.map +1 -1
  125. package/dist/node_modules/@wry/trie/lib/index.js +2 -3
  126. package/dist/node_modules/@wry/trie/lib/index.js.map +1 -1
  127. package/dist/node_modules/graphql-ws/dist/client.js +76 -69
  128. package/dist/node_modules/graphql-ws/dist/client.js.map +1 -1
  129. package/dist/node_modules/graphql-ws/dist/common-CGW11Fyb.js +2 -3
  130. package/dist/node_modules/graphql-ws/dist/common-CGW11Fyb.js.map +1 -1
  131. package/dist/node_modules/rxjs/dist/esm5/internal/NotificationFactories.js +2 -3
  132. package/dist/node_modules/rxjs/dist/esm5/internal/NotificationFactories.js.map +1 -1
  133. package/dist/node_modules/rxjs/dist/esm5/internal/Observable.js +41 -42
  134. package/dist/node_modules/rxjs/dist/esm5/internal/Observable.js.map +1 -1
  135. package/dist/node_modules/rxjs/dist/esm5/internal/Subscriber.js +14 -15
  136. package/dist/node_modules/rxjs/dist/esm5/internal/Subscriber.js.map +1 -1
  137. package/dist/node_modules/rxjs/dist/esm5/internal/Subscription.js +21 -18
  138. package/dist/node_modules/rxjs/dist/esm5/internal/Subscription.js.map +1 -1
  139. package/dist/node_modules/rxjs/dist/esm5/internal/config.js +1 -2
  140. package/dist/node_modules/rxjs/dist/esm5/internal/config.js.map +1 -1
  141. package/dist/node_modules/rxjs/dist/esm5/internal/observable/empty.js +1 -2
  142. package/dist/node_modules/rxjs/dist/esm5/internal/observable/empty.js.map +1 -1
  143. package/dist/node_modules/rxjs/dist/esm5/internal/scheduler/timeoutProvider.js +2 -3
  144. package/dist/node_modules/rxjs/dist/esm5/internal/scheduler/timeoutProvider.js.map +1 -1
  145. package/dist/node_modules/rxjs/dist/esm5/internal/symbol/observable.js +1 -2
  146. package/dist/node_modules/rxjs/dist/esm5/internal/symbol/observable.js.map +1 -1
  147. package/dist/node_modules/rxjs/dist/esm5/internal/util/UnsubscriptionError.js +1 -2
  148. package/dist/node_modules/rxjs/dist/esm5/internal/util/UnsubscriptionError.js.map +1 -1
  149. package/dist/node_modules/rxjs/dist/esm5/internal/util/arrRemove.js +1 -2
  150. package/dist/node_modules/rxjs/dist/esm5/internal/util/arrRemove.js.map +1 -1
  151. package/dist/node_modules/rxjs/dist/esm5/internal/util/createErrorClass.js +1 -2
  152. package/dist/node_modules/rxjs/dist/esm5/internal/util/createErrorClass.js.map +1 -1
  153. package/dist/node_modules/rxjs/dist/esm5/internal/util/errorContext.js +1 -2
  154. package/dist/node_modules/rxjs/dist/esm5/internal/util/errorContext.js.map +1 -1
  155. package/dist/node_modules/rxjs/dist/esm5/internal/util/identity.js +1 -2
  156. package/dist/node_modules/rxjs/dist/esm5/internal/util/identity.js.map +1 -1
  157. package/dist/node_modules/rxjs/dist/esm5/internal/util/isFunction.js +1 -2
  158. package/dist/node_modules/rxjs/dist/esm5/internal/util/isFunction.js.map +1 -1
  159. package/dist/node_modules/rxjs/dist/esm5/internal/util/noop.js +1 -2
  160. package/dist/node_modules/rxjs/dist/esm5/internal/util/noop.js.map +1 -1
  161. package/dist/node_modules/rxjs/dist/esm5/internal/util/pipe.js +1 -2
  162. package/dist/node_modules/rxjs/dist/esm5/internal/util/pipe.js.map +1 -1
  163. package/dist/node_modules/rxjs/dist/esm5/internal/util/reportUnhandledError.js +1 -2
  164. package/dist/node_modules/rxjs/dist/esm5/internal/util/reportUnhandledError.js.map +1 -1
  165. package/dist/node_modules/{rxjs/node_modules/tslib → tslib}/tslib.es6.js +1 -2
  166. package/dist/node_modules/tslib/tslib.es6.js.map +1 -0
  167. package/dist/pages/CreateNotificationPage.d.ts +5 -0
  168. package/dist/pages/CreateNotificationPage.js +18 -19
  169. package/dist/pages/CreateNotificationPage.js.map +1 -1
  170. package/dist/pages/NotificationCenterPage.d.ts +6 -0
  171. package/dist/pages/NotificationCenterPage.js +13 -14
  172. package/dist/pages/NotificationCenterPage.js.map +1 -1
  173. package/dist/pages/NotificationHistoryAdminPage.d.ts +2 -0
  174. package/dist/pages/NotificationHistoryAdminPage.js +7 -8
  175. package/dist/pages/NotificationHistoryAdminPage.js.map +1 -1
  176. package/dist/pages/NotificationHistoryPage.d.ts +2 -0
  177. package/dist/pages/NotificationHistoryPage.js +13 -14
  178. package/dist/pages/NotificationHistoryPage.js.map +1 -1
  179. package/dist/pages/NotificationLandingPage.d.ts +10 -0
  180. package/dist/pages/NotificationLandingPage.js +5 -6
  181. package/dist/pages/NotificationLandingPage.js.map +1 -1
  182. package/dist/pages/NotificationPreferencesPage.d.ts +1 -0
  183. package/dist/pages/NotificationPreferencesPage.js +14 -15
  184. package/dist/pages/NotificationPreferencesPage.js.map +1 -1
  185. package/dist/pages/NotificationTemplatesPage.d.ts +7 -0
  186. package/dist/pages/NotificationTemplatesPage.js +25 -23
  187. package/dist/pages/NotificationTemplatesPage.js.map +1 -1
  188. package/dist/pages/NotificationTopicsPage.d.ts +1 -0
  189. package/dist/pages/NotificationTopicsPage.js +6 -7
  190. package/dist/pages/NotificationTopicsPage.js.map +1 -1
  191. package/dist/pages/TemplateEditorPage.d.ts +12 -0
  192. package/dist/pages/TemplateEditorPage.js +294 -285
  193. package/dist/pages/TemplateEditorPage.js.map +1 -1
  194. package/dist/providers/NotificationProvider.d.ts +11 -0
  195. package/dist/providers/NotificationProvider.js +1 -2
  196. package/dist/providers/NotificationProvider.js.map +1 -1
  197. package/dist/shared/hooks/useTr.d.ts +13 -0
  198. package/dist/shared/hooks/useTr.js +1 -2
  199. package/dist/shared/hooks/useTr.js.map +1 -1
  200. package/dist/store/notificationStore.d.ts +30 -0
  201. package/dist/store/notificationStore.js +1 -2
  202. package/dist/store/notificationStore.js.map +1 -1
  203. package/dist/test/happydom.d.ts +1 -0
  204. package/dist/translations/en.d.ts +468 -0
  205. package/dist/types/index.d.ts +249 -0
  206. package/dist/utils/inAppNavigation.d.ts +37 -0
  207. package/dist/utils/inAppNavigation.js +2 -3
  208. package/dist/utils/inAppNavigation.js.map +1 -1
  209. package/dist/utils/index.d.ts +68 -0
  210. package/dist/utils/index.js +16 -10
  211. package/dist/utils/index.js.map +1 -1
  212. package/dist/utils/nativeBridge.d.ts +2 -0
  213. package/dist/utils/nativeBridge.js +1 -2
  214. package/dist/utils/notificationHistoryExport.d.ts +12 -0
  215. package/dist/utils/notificationHistoryExport.js +1 -2
  216. package/dist/utils/notificationHistoryExport.js.map +1 -1
  217. package/package.json +66 -48
  218. package/dist/node_modules/rxjs/node_modules/tslib/tslib.es6.js.map +0 -1
@@ -1,8 +1,8 @@
1
- import { useNotification as e } from "../providers/NotificationProvider.js";
2
- import { getGlobalNotificationClient as t } from "../graphql/global-client.js";
1
+ import { getGlobalNotificationClient as e } from "../graphql/global-client.js";
2
+ import { useNotification as t } from "../providers/NotificationProvider.js";
3
3
  import { CreateNotificationPreferenceDocument as n, DeleteNotificationPreferenceDocument as r, GetNotificationPreferencesDocument as i, UpdateNotificationPreferenceDocument as a } from "../generated/global-operations.js";
4
4
  import { useCallback as o, useEffect as s, useMemo as c, useState as l } from "react";
5
- //#region src/hooks/useNotificationPreferences.ts
5
+ // src/hooks/useNotificationPreferences.ts
6
6
  function u(e) {
7
7
  return e.scope === "CHANNEL" ? `CHANNEL:${e.channel || ""}` : e.scope === "TYPE" ? `TYPE:${e.type || ""}` : e.scope === "TOPIC" ? `TOPIC:${e.topicId || ""}` : "GLOBAL";
8
8
  }
@@ -33,17 +33,18 @@ function d(e) {
33
33
  };
34
34
  }
35
35
  function f() {
36
- let { authToken: f, apiGatewayUrl: p } = e(), [m, h] = l([]), [g, _] = l(!1), [v, y] = l(null), b = o(() => t(p ?? void 0, f ?? void 0), [p, f]), x = c(() => new Map(m.map((e) => [e.preferenceKey, e])), [m]), S = o(async () => {
36
+ let { authToken: f, apiGatewayUrl: p } = t(), [m, h] = l([]), [g, _] = l(!1), [v, y] = l(null), b = o(() => e(p ?? void 0, f ?? void 0), [p, f]), x = c(() => new Map(m.map((e) => [e.preferenceKey, e])), [m]), S = o(async () => {
37
37
  _(!0), y(null);
38
38
  try {
39
- h(((await b().query({
39
+ let e = await b().query({
40
40
  query: i,
41
41
  variables: {
42
42
  limit: 100,
43
43
  offset: 0
44
44
  },
45
45
  fetchPolicy: "cache-first"
46
- })).data?.notificationPreferences.items || []).map(d));
46
+ });
47
+ h((e.data?.notificationPreferences.items || []).map(d));
47
48
  } catch (e) {
48
49
  console.error("[useNotificationPreferences] Failed to fetch preferences:", e), y(e instanceof Error ? e.message : "Failed to fetch notification preferences");
49
50
  } finally {
@@ -108,7 +109,6 @@ function f() {
108
109
  })).data?.deleteNotificationPreference ? (h((t) => t.filter((t) => t.id !== e)), !0) : !1, [b])
109
110
  };
110
111
  }
111
- //#endregion
112
112
  export { f as useNotificationPreferences };
113
113
 
114
114
  //# sourceMappingURL=useNotificationPreferences.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useNotificationPreferences.js","names":[],"sources":["../../src/hooks/useNotificationPreferences.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react';\nimport { getGlobalNotificationClient } from '../graphql/global-client';\nimport { useNotification } from '../providers/NotificationProvider';\nimport * as NotificationOps from '../generated/global-operations';\nimport type {\n CreateNotificationPreferenceMutation,\n CreateNotificationPreferenceMutationVariables,\n DeleteNotificationPreferenceMutation,\n DeleteNotificationPreferenceMutationVariables,\n GetNotificationPreferencesQuery,\n NotificationPreferenceFieldsFragment,\n UpdateNotificationPreferenceMutation,\n UpdateNotificationPreferenceMutationVariables,\n} from '../generated/global-operations';\nimport type {\n NotificationPreference,\n NotificationPreferenceScope,\n UpsertNotificationPreferenceInput,\n} from '../types';\n\nfunction buildPreferenceKey(input: {\n scope: NotificationPreferenceScope;\n channel?: string;\n type?: string;\n topicId?: string;\n}): string {\n if (input.scope === 'CHANNEL') return `CHANNEL:${input.channel || ''}`;\n if (input.scope === 'TYPE') return `TYPE:${input.type || ''}`;\n if (input.scope === 'TOPIC') return `TOPIC:${input.topicId || ''}`;\n return 'GLOBAL';\n}\n\nfunction mapPreference(preference: NotificationPreferenceFieldsFragment): NotificationPreference {\n return {\n id: preference.id,\n userId: preference.userId,\n preferenceKey: preference.preferenceKey,\n scope: preference.scope,\n channel: preference.channel ?? undefined,\n type: preference.type ?? undefined,\n topicId: preference.topicId ?? undefined,\n enabled: preference.enabled,\n frequency: preference.frequency,\n quietHoursStart: preference.quietHoursStart ?? undefined,\n quietHoursEnd: preference.quietHoursEnd ?? undefined,\n timezone: preference.timezone ?? undefined,\n metadata: preference.metadata ?? undefined,\n createdAt: preference.createdAt,\n updatedAt: preference.updatedAt,\n topic: preference.topic\n ? {\n id: preference.topic.id,\n name: preference.topic.name,\n slug: preference.topic.slug,\n type: preference.topic.type,\n description: preference.topic.description ?? undefined,\n }\n : undefined,\n };\n}\n\nexport function useNotificationPreferences() {\n const { authToken, apiGatewayUrl } = useNotification();\n const [preferences, setPreferences] = useState<NotificationPreference[]>([]);\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const getClient = useCallback(() => {\n return getGlobalNotificationClient(apiGatewayUrl ?? undefined, authToken ?? undefined);\n }, [apiGatewayUrl, authToken]);\n\n const preferencesByKey = useMemo(() => {\n return new Map(preferences.map((preference) => [preference.preferenceKey, preference]));\n }, [preferences]);\n\n const fetchPreferences = useCallback(async () => {\n setIsLoading(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.query<GetNotificationPreferencesQuery>({\n query: NotificationOps.GetNotificationPreferencesDocument,\n variables: { limit: 100, offset: 0 },\n fetchPolicy: 'cache-first',\n });\n setPreferences((result.data?.notificationPreferences.items || []).map(mapPreference));\n } catch (err) {\n console.error('[useNotificationPreferences] Failed to fetch preferences:', err);\n setError(err instanceof Error ? err.message : 'Failed to fetch notification preferences');\n } finally {\n setIsLoading(false);\n }\n }, [getClient]);\n\n useEffect(() => {\n fetchPreferences();\n }, [fetchPreferences]);\n\n const setPreference = useCallback(\n async (input: UpsertNotificationPreferenceInput): Promise<NotificationPreference | null> => {\n const client = getClient();\n const preferenceKey = buildPreferenceKey(input);\n const existing = preferencesByKey.get(preferenceKey);\n\n if (existing) {\n const result = await client.mutate<\n UpdateNotificationPreferenceMutation,\n UpdateNotificationPreferenceMutationVariables\n >({\n mutation: NotificationOps.UpdateNotificationPreferenceDocument,\n variables: {\n id: existing.id,\n input: {\n scope: input.scope,\n channel: input.channel,\n type: input.type,\n topicId: input.topicId,\n enabled: input.enabled,\n frequency: input.frequency,\n quietHoursStart: input.quietHoursStart,\n quietHoursEnd: input.quietHoursEnd,\n timezone: input.timezone,\n metadata: input.metadata,\n } as UpdateNotificationPreferenceMutationVariables['input'],\n },\n });\n const updated = result.data?.updateNotificationPreference;\n if (!updated) return null;\n const mapped = mapPreference(updated);\n setPreferences((prev) => prev.map((item) => (item.id === mapped.id ? mapped : item)));\n return mapped;\n }\n\n const result = await client.mutate<\n CreateNotificationPreferenceMutation,\n CreateNotificationPreferenceMutationVariables\n >({\n mutation: NotificationOps.CreateNotificationPreferenceDocument,\n variables: {\n input: {\n scope: input.scope,\n channel: input.channel,\n type: input.type,\n topicId: input.topicId,\n enabled: input.enabled,\n frequency: input.frequency || 'IMMEDIATE',\n quietHoursStart: input.quietHoursStart,\n quietHoursEnd: input.quietHoursEnd,\n timezone: input.timezone,\n metadata: input.metadata,\n } as CreateNotificationPreferenceMutationVariables['input'],\n },\n });\n const created = result.data?.createNotificationPreference;\n if (!created) return null;\n const mapped = mapPreference(created);\n setPreferences((prev) => [mapped, ...prev]);\n return mapped;\n },\n [getClient, preferencesByKey]\n );\n\n const deletePreference = useCallback(\n async (id: string): Promise<boolean> => {\n const client = getClient();\n const result = await client.mutate<\n DeleteNotificationPreferenceMutation,\n DeleteNotificationPreferenceMutationVariables\n >({\n mutation: NotificationOps.DeleteNotificationPreferenceDocument,\n variables: { id },\n });\n if (result.data?.deleteNotificationPreference) {\n setPreferences((prev) => prev.filter((preference) => preference.id !== id));\n return true;\n }\n return false;\n },\n [getClient]\n );\n\n return {\n preferences,\n preferencesByKey,\n isLoading,\n error,\n refetch: fetchPreferences,\n setPreference,\n deletePreference,\n };\n}\n"],"mappings":";;;;;AAoBA,SAAS,EAAmB,GAKjB;AAIT,QAHI,EAAM,UAAU,YAAkB,WAAW,EAAM,WAAW,OAC9D,EAAM,UAAU,SAAe,QAAQ,EAAM,QAAQ,OACrD,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MAAS,CAAC,GAAQ,GAAG,EAAK,CAAC,EACpC;KAET,CAAC,GAAW,EAAiB,CAC9B;EA4BC,kBA1BuB,EACvB,OAAO,OAEU,MADA,GAAW,CACE,OAG1B;GACA,UAAU;GACV,WAAW,EAAE,OAAI;GAClB,CAAC,EACS,MAAM,gCACf,GAAgB,MAAS,EAAK,QAAQ,MAAe,EAAW,OAAO,EAAG,CAAC,EACpE,MAEF,IAET,CAAC,EAAU,CACZ;EAUA"}
1
+ {"version":3,"file":"useNotificationPreferences.js","names":["NotificationOps.GetNotificationPreferencesDocument","NotificationOps.UpdateNotificationPreferenceDocument","NotificationOps.CreateNotificationPreferenceDocument","NotificationOps.DeleteNotificationPreferenceDocument","buildPreferenceKey","input","mapPreference","preference","useNotificationPreferences","useNotification","preferences","setPreferences","useState","isLoading","setIsLoading","error","setError","getClient","useCallback","getGlobalNotificationClient","apiGatewayUrl","authToken","preferencesByKey","useMemo","fetchPreferences","result","GetNotificationPreferencesDocument","err","useEffect","client","preferenceKey","existing","updated","UpdateNotificationPreferenceDocument","mapped","prev","item","created","CreateNotificationPreferenceDocument","DeleteNotificationPreferenceDocument","id"],"sources":["../../src/hooks/useNotificationPreferences.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react';\nimport { getGlobalNotificationClient } from '../graphql/global-client';\nimport { useNotification } from '../providers/NotificationProvider';\nimport * as NotificationOps from '../generated/global-operations';\nimport type {\n CreateNotificationPreferenceMutation,\n CreateNotificationPreferenceMutationVariables,\n DeleteNotificationPreferenceMutation,\n DeleteNotificationPreferenceMutationVariables,\n GetNotificationPreferencesQuery,\n NotificationPreferenceFieldsFragment,\n UpdateNotificationPreferenceMutation,\n UpdateNotificationPreferenceMutationVariables,\n} from '../generated/global-operations';\nimport type {\n NotificationPreference,\n NotificationPreferenceScope,\n UpsertNotificationPreferenceInput,\n} from '../types';\n\nfunction buildPreferenceKey(input: {\n scope: NotificationPreferenceScope;\n channel?: string;\n type?: string;\n topicId?: string;\n}): string {\n if (input.scope === 'CHANNEL') return `CHANNEL:${input.channel || ''}`;\n if (input.scope === 'TYPE') return `TYPE:${input.type || ''}`;\n if (input.scope === 'TOPIC') return `TOPIC:${input.topicId || ''}`;\n return 'GLOBAL';\n}\n\nfunction mapPreference(preference: NotificationPreferenceFieldsFragment): NotificationPreference {\n return {\n id: preference.id,\n userId: preference.userId,\n preferenceKey: preference.preferenceKey,\n scope: preference.scope,\n channel: preference.channel ?? undefined,\n type: preference.type ?? undefined,\n topicId: preference.topicId ?? undefined,\n enabled: preference.enabled,\n frequency: preference.frequency,\n quietHoursStart: preference.quietHoursStart ?? undefined,\n quietHoursEnd: preference.quietHoursEnd ?? undefined,\n timezone: preference.timezone ?? undefined,\n metadata: preference.metadata ?? undefined,\n createdAt: preference.createdAt,\n updatedAt: preference.updatedAt,\n topic: preference.topic\n ? {\n id: preference.topic.id,\n name: preference.topic.name,\n slug: preference.topic.slug,\n type: preference.topic.type,\n description: preference.topic.description ?? undefined,\n }\n : undefined,\n };\n}\n\nexport function useNotificationPreferences() {\n const { authToken, apiGatewayUrl } = useNotification();\n const [preferences, setPreferences] = useState<NotificationPreference[]>([]);\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const getClient = useCallback(() => {\n return getGlobalNotificationClient(apiGatewayUrl ?? undefined, authToken ?? undefined);\n }, [apiGatewayUrl, authToken]);\n\n const preferencesByKey = useMemo(() => {\n return new Map(preferences.map((preference) => [preference.preferenceKey, preference]));\n }, [preferences]);\n\n const fetchPreferences = useCallback(async () => {\n setIsLoading(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.query<GetNotificationPreferencesQuery>({\n query: NotificationOps.GetNotificationPreferencesDocument,\n variables: { limit: 100, offset: 0 },\n fetchPolicy: 'cache-first',\n });\n setPreferences((result.data?.notificationPreferences.items || []).map(mapPreference));\n } catch (err) {\n console.error('[useNotificationPreferences] Failed to fetch preferences:', err);\n setError(err instanceof Error ? err.message : 'Failed to fetch notification preferences');\n } finally {\n setIsLoading(false);\n }\n }, [getClient]);\n\n useEffect(() => {\n fetchPreferences();\n }, [fetchPreferences]);\n\n const setPreference = useCallback(\n async (input: UpsertNotificationPreferenceInput): Promise<NotificationPreference | null> => {\n const client = getClient();\n const preferenceKey = buildPreferenceKey(input);\n const existing = preferencesByKey.get(preferenceKey);\n\n if (existing) {\n const result = await client.mutate<\n UpdateNotificationPreferenceMutation,\n UpdateNotificationPreferenceMutationVariables\n >({\n mutation: NotificationOps.UpdateNotificationPreferenceDocument,\n variables: {\n id: existing.id,\n input: {\n scope: input.scope,\n channel: input.channel,\n type: input.type,\n topicId: input.topicId,\n enabled: input.enabled,\n frequency: input.frequency,\n quietHoursStart: input.quietHoursStart,\n quietHoursEnd: input.quietHoursEnd,\n timezone: input.timezone,\n metadata: input.metadata,\n } as UpdateNotificationPreferenceMutationVariables['input'],\n },\n });\n const updated = result.data?.updateNotificationPreference;\n if (!updated) return null;\n const mapped = mapPreference(updated);\n setPreferences((prev) => prev.map((item) => (item.id === mapped.id ? mapped : item)));\n return mapped;\n }\n\n const result = await client.mutate<\n CreateNotificationPreferenceMutation,\n CreateNotificationPreferenceMutationVariables\n >({\n mutation: NotificationOps.CreateNotificationPreferenceDocument,\n variables: {\n input: {\n scope: input.scope,\n channel: input.channel,\n type: input.type,\n topicId: input.topicId,\n enabled: input.enabled,\n frequency: input.frequency || 'IMMEDIATE',\n quietHoursStart: input.quietHoursStart,\n quietHoursEnd: input.quietHoursEnd,\n timezone: input.timezone,\n metadata: input.metadata,\n } as CreateNotificationPreferenceMutationVariables['input'],\n },\n });\n const created = result.data?.createNotificationPreference;\n if (!created) return null;\n const mapped = mapPreference(created);\n setPreferences((prev) => [mapped, ...prev]);\n return mapped;\n },\n [getClient, preferencesByKey]\n );\n\n const deletePreference = useCallback(\n async (id: string): Promise<boolean> => {\n const client = getClient();\n const result = await client.mutate<\n DeleteNotificationPreferenceMutation,\n DeleteNotificationPreferenceMutationVariables\n >({\n mutation: NotificationOps.DeleteNotificationPreferenceDocument,\n variables: { id },\n });\n if (result.data?.deleteNotificationPreference) {\n setPreferences((prev) => prev.filter((preference) => preference.id !== id));\n return true;\n }\n return false;\n },\n [getClient]\n );\n\n return {\n preferences,\n preferencesByKey,\n isLoading,\n error,\n refetch: fetchPreferences,\n setPreference,\n deletePreference,\n };\n}\n"],"mappings":";;;;;AAoBA,SAASI,EAAmB,GAKjB;CAIT,OAHIC,EAAM,UAAU,YAAkB,WAAWA,EAAM,WAAW,OAC9DA,EAAM,UAAU,SAAe,QAAQA,EAAM,QAAQ,OACrDA,EAAM,UAAU,UAAgB,SAASA,EAAM,WAAW,OACvD;AACT;AAEA,SAASC,EAAc,GAA0E;CAC/F,OAAO;EACL,IAAIC,EAAW;EACf,QAAQA,EAAW;EACnB,eAAeA,EAAW;EAC1B,OAAOA,EAAW;EAClB,SAASA,EAAW,WAAW,KAAA;EAC/B,MAAMA,EAAW,QAAQ,KAAA;EACzB,SAASA,EAAW,WAAW,KAAA;EAC/B,SAASA,EAAW;EACpB,WAAWA,EAAW;EACtB,iBAAiBA,EAAW,mBAAmB,KAAA;EAC/C,eAAeA,EAAW,iBAAiB,KAAA;EAC3C,UAAUA,EAAW,YAAY,KAAA;EACjC,UAAUA,EAAW,YAAY,KAAA;EACjC,WAAWA,EAAW;EACtB,WAAWA,EAAW;EACtB,OAAOA,EAAW,QACd;GACE,IAAIA,EAAW,MAAM;GACrB,MAAMA,EAAW,MAAM;GACvB,MAAMA,EAAW,MAAM;GACvB,MAAMA,EAAW,MAAM;GACvB,aAAaA,EAAW,MAAM,eAAe,KAAA;EAC/C,IACA,KAAA;CACN;AACF;AAEA,SAAgBC,IAA6B;CAC3C,IAAM,EAAE,cAAW,qBAAkBC,EAAgB,GAC/C,CAACC,GAAaC,KAAkBC,EAAmC,CAAC,CAAC,GACrE,CAACC,GAAWC,KAAgBF,EAAS,EAAK,GAC1C,CAACG,GAAOC,KAAYJ,EAAwB,IAAI,GAEhDK,IAA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,CACsB,MAAM;IAC7B,IAAI,CAAC2B,GAAS,OAAO;IACrB,IAAME,IAAS5B,EAAc0B,CAAO;IAEpC,OADArB,GAAgB,MAASwB,EAAK,KAAK,MAAUC,EAAK,OAAOF,EAAO,KAAKA,IAASE,CAAK,CAAC,GAC7EF;GACT;GAsBA,IAAMG,KAAU,MApBKR,EAAO,OAG1B;IACA,UAAU3B;IACV,WAAW,EACT,OAAO;KACL,OAAOG,EAAM;KACb,SAASA,EAAM;KACf,MAAMA,EAAM;KACZ,SAASA,EAAM;KACf,SAASA,EAAM;KACf,WAAWA,EAAM,aAAa;KAC9B,iBAAiBA,EAAM;KACvB,eAAeA,EAAM;KACrB,UAAUA,EAAM;KAChB,UAAUA,EAAM;IAClB,EACF;GACF,CAAC,EAAA,CACsB,MAAM;GAC7B,IAAI,CAACgC,GAAS,OAAO;GACrB,IAAMH,IAAS5B,EAAc+B,CAAO;GAEpC,OADA1B,GAAgB,MAAS,CAACuB,GAAQ,GAAGC,CAAI,CAAC,GACnCD;EACT,GACA,CAACjB,GAAWK,CAAgB,CA4B5B;EACA,kBA1BuBJ,EACvB,OAAO,OASD,MARWD,EACM,CAAA,CAAO,OAG1B;GACA,UAAUd;GACV,WAAW,EAAE,MAAG;EAClB,CAAC,EAAA,CACU,MAAM,gCACfQ,GAAgB,MAASwB,EAAK,QAAQ,MAAe5B,EAAW,OAAOiC,CAAE,CAAC,GACnE,MAEF,IAET,CAACvB,CAAS,CAUV;CACF;AACF"}
@@ -0,0 +1,131 @@
1
+ import { NotificationType } from '../types';
2
+ import { GetNotificationTemplatesQuery } from '../generated/global-operations';
3
+ /**
4
+ * Backend template type derived from the generated query
5
+ */
6
+ export type BackendNotificationTemplate = GetNotificationTemplatesQuery['notificationTemplates']['items'][number];
7
+ /**
8
+ * Input type for creating a template (matches backend CreateTemplateInput)
9
+ * Note: Templates are content-only - channel is specified at send time
10
+ */
11
+ export interface CreateTemplateInput {
12
+ slug: string;
13
+ name: string;
14
+ description?: string;
15
+ type: NotificationType;
16
+ channel?: string;
17
+ locale?: string;
18
+ subject?: string;
19
+ bodyTemplate: string;
20
+ htmlTemplate?: string;
21
+ variables: Record<string, unknown>;
22
+ metadata?: Record<string, unknown>;
23
+ }
24
+ /**
25
+ * Input type for updating a template (matches backend UpdateTemplateInput)
26
+ */
27
+ export interface UpdateTemplateInput {
28
+ name?: string;
29
+ description?: string;
30
+ subject?: string;
31
+ bodyTemplate?: string;
32
+ htmlTemplate?: string;
33
+ variables?: Record<string, unknown>;
34
+ enabled?: boolean;
35
+ metadata?: Record<string, unknown>;
36
+ }
37
+ /**
38
+ * Filter options for templates (matches backend TemplateFilterInput)
39
+ * Note: channel filter removed - templates are content-only
40
+ */
41
+ export interface TemplateFilter {
42
+ type?: NotificationType;
43
+ locale?: string;
44
+ enabled?: boolean;
45
+ search?: string;
46
+ }
47
+ /**
48
+ * Hook to manage notification templates
49
+ * Uses the GLOBAL Apollo client for API calls
50
+ */
51
+ export declare function useNotificationTemplates(initialFilter?: TemplateFilter): {
52
+ templates: {
53
+ id: string;
54
+ slug: string;
55
+ name: string;
56
+ description: string | null;
57
+ type: import('../generated/global-types').NotificationType;
58
+ locale: string;
59
+ subject: string | null;
60
+ bodyTemplate: string;
61
+ htmlTemplate: string | null;
62
+ variables: Record<string, unknown>;
63
+ enabled: boolean;
64
+ version: number;
65
+ createdAt: string;
66
+ updatedAt: string;
67
+ createdBy: string;
68
+ metadata: Record<string, unknown> | null;
69
+ }[];
70
+ allTemplates: {
71
+ id: string;
72
+ slug: string;
73
+ name: string;
74
+ description: string | null;
75
+ type: import('../generated/global-types').NotificationType;
76
+ locale: string;
77
+ subject: string | null;
78
+ bodyTemplate: string;
79
+ htmlTemplate: string | null;
80
+ variables: Record<string, unknown>;
81
+ enabled: boolean;
82
+ version: number;
83
+ createdAt: string;
84
+ updatedAt: string;
85
+ createdBy: string;
86
+ metadata: Record<string, unknown> | null;
87
+ }[];
88
+ isLoading: boolean;
89
+ isCreating: boolean;
90
+ isUpdating: boolean;
91
+ isDeleting: boolean;
92
+ isMutating: boolean;
93
+ error: string | null;
94
+ hasMore: boolean;
95
+ total: number;
96
+ filter: TemplateFilter;
97
+ refetch: () => Promise<void>;
98
+ loadMore: () => Promise<void>;
99
+ createTemplate: (input: CreateTemplateInput) => Promise<BackendNotificationTemplate>;
100
+ updateTemplate: (id: string, input: UpdateTemplateInput) => Promise<BackendNotificationTemplate>;
101
+ deleteTemplate: (id: string) => Promise<boolean>;
102
+ updateFilter: (newFilter: Partial<TemplateFilter>) => void;
103
+ resetFilter: () => void;
104
+ };
105
+ /**
106
+ * Hook to fetch a single template by slug
107
+ * Uses the GLOBAL Apollo client for API calls
108
+ */
109
+ export declare function useNotificationTemplate(slug: string | undefined, locale?: string): {
110
+ template: {
111
+ id: string;
112
+ slug: string;
113
+ name: string;
114
+ description: string | null;
115
+ type: import('../generated/global-types').NotificationType;
116
+ locale: string;
117
+ subject: string | null;
118
+ bodyTemplate: string;
119
+ htmlTemplate: string | null;
120
+ variables: Record<string, unknown>;
121
+ enabled: boolean;
122
+ version: number;
123
+ createdAt: string;
124
+ updatedAt: string;
125
+ createdBy: string;
126
+ metadata: Record<string, unknown> | null;
127
+ } | undefined;
128
+ isLoading: boolean;
129
+ error: string | null;
130
+ refetch: () => Promise<void>;
131
+ };
@@ -2,7 +2,7 @@ import { useNotification as e } from "../providers/NotificationProvider.js";
2
2
  import { getGlobalNotificationClient as t } from "../graphql/global-client.js";
3
3
  import { CreateNotificationTemplateDocument as n, DeleteNotificationTemplateDocument as r, GetNotificationTemplateDocument as i, GetNotificationTemplatesDocument as a, UpdateNotificationTemplateDocument as o } from "../generated/global-operations.js";
4
4
  import { useCallback as s, useEffect as c, useState as l } from "react";
5
- //#region src/hooks/useNotificationTemplates.ts
5
+ // src/hooks/useNotificationTemplates.ts
6
6
  function u(i) {
7
7
  let { authToken: u, apiGatewayUrl: d } = e(), [f, p] = l([]), [m, h] = l(!1), [g, _] = l(!1), [v, y] = l(!1), [b, x] = l(!1), [S, C] = l(null), [w, T] = l(!1), [E, D] = l(0), [O, k] = l(0), [A, j] = l(i || {}), M = s(() => t(d ?? void 0, u ?? void 0), [d, u]), N = s(() => {
8
8
  let e = {};
@@ -162,7 +162,6 @@ function d(n, r) {
162
162
  refetch: _
163
163
  };
164
164
  }
165
- //#endregion
166
165
  export { d as useNotificationTemplate, u as useNotificationTemplates };
167
166
 
168
167
  //# sourceMappingURL=useNotificationTemplates.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useNotificationTemplates.js","names":[],"sources":["../../src/hooks/useNotificationTemplates.ts"],"sourcesContent":["import { useState, useCallback, useEffect } from 'react';\nimport { useNotification } from '../providers/NotificationProvider';\nimport { getGlobalNotificationClient } from '../graphql/global-client';\nimport type { NotificationType } from '../types';\nimport * as NotificationOps from '../generated/global-operations';\nimport type {\n GetNotificationTemplatesQuery,\n GetNotificationTemplateQuery,\n CreateNotificationTemplateMutation,\n UpdateNotificationTemplateMutation,\n} from '../generated/global-operations';\n\n/**\n * Backend template type derived from the generated query\n */\nexport type BackendNotificationTemplate =\n GetNotificationTemplatesQuery['notificationTemplates']['items'][number];\n/**\n * Input type for creating a template (matches backend CreateTemplateInput)\n * Note: Templates are content-only - channel is specified at send time\n */\nexport interface CreateTemplateInput {\n slug: string;\n name: string;\n description?: string;\n type: NotificationType;\n channel?: string;\n locale?: string;\n subject?: string;\n bodyTemplate: string;\n htmlTemplate?: string;\n variables: Record<string, unknown>;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Input type for updating a template (matches backend UpdateTemplateInput)\n */\nexport interface UpdateTemplateInput {\n name?: string;\n description?: string;\n subject?: string;\n bodyTemplate?: string;\n htmlTemplate?: string;\n variables?: Record<string, unknown>;\n enabled?: boolean;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Filter options for templates (matches backend TemplateFilterInput)\n * Note: channel filter removed - templates are content-only\n */\nexport interface TemplateFilter {\n type?: NotificationType;\n locale?: string;\n enabled?: boolean;\n search?: string; // Local filter only\n}\n\n/**\n * Hook to manage notification templates\n * Uses the GLOBAL Apollo client for API calls\n */\nexport function useNotificationTemplates(initialFilter?: TemplateFilter) {\n const { authToken, apiGatewayUrl } = useNotification();\n const [templates, setTemplates] = useState<BackendNotificationTemplate[]>([]);\n const [isLoading, setIsLoading] = useState(false);\n const [isCreating, setIsCreating] = useState(false);\n const [isUpdating, setIsUpdating] = useState(false);\n const [isDeleting, setIsDeleting] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const [hasMore, setHasMore] = useState(false);\n const [total, setTotal] = useState(0);\n const [offset, setOffset] = useState(0);\n const [filter, setFilter] = useState<TemplateFilter>(initialFilter || {});\n\n const LIMIT = 50;\n\n // Get global client — coerce null/undefined authToken to undefined\n const getClient = useCallback(() => {\n return getGlobalNotificationClient(apiGatewayUrl ?? undefined, authToken ?? undefined);\n }, [apiGatewayUrl, authToken]);\n\n // Build backend filter (excludes local-only 'search')\n const buildBackendFilter = useCallback(() => {\n const backendFilter: Record<string, unknown> = {};\n if (filter.type) backendFilter.type = filter.type;\n if (filter.locale) backendFilter.locale = filter.locale;\n if (filter.enabled !== undefined) backendFilter.enabled = filter.enabled;\n return Object.keys(backendFilter).length > 0 ? backendFilter : undefined;\n }, [filter]);\n\n // Fetch templates\n const fetchTemplates = useCallback(async () => {\n setIsLoading(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.query<GetNotificationTemplatesQuery>({\n query: NotificationOps.GetNotificationTemplatesDocument,\n variables: {\n filter: buildBackendFilter(),\n limit: LIMIT,\n offset: 0,\n },\n fetchPolicy: 'cache-first',\n });\n\n if (result.data?.notificationTemplates) {\n setTemplates(result.data.notificationTemplates.items || []);\n setTotal(result.data.notificationTemplates.total || 0);\n setHasMore(result.data.notificationTemplates.hasMore || false);\n setOffset(LIMIT);\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to fetch templates';\n console.error('[useNotificationTemplates] Failed to fetch templates:', err);\n setError(message);\n } finally {\n setIsLoading(false);\n }\n }, [getClient, buildBackendFilter]);\n\n // Initial fetch\n useEffect(() => {\n fetchTemplates();\n }, [fetchTemplates]);\n\n // Filter by search locally\n const filteredTemplates = filter.search\n ? templates.filter(\n (t) =>\n t.name.toLowerCase().includes(filter.search!.toLowerCase()) ||\n t.slug.toLowerCase().includes(filter.search!.toLowerCase()) ||\n t.description?.toLowerCase().includes(filter.search!.toLowerCase())\n )\n : templates;\n\n // Create template\n const createTemplate = useCallback(\n async (input: CreateTemplateInput): Promise<BackendNotificationTemplate> => {\n setIsCreating(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.mutate<CreateNotificationTemplateMutation>({\n mutation: NotificationOps.CreateNotificationTemplateDocument,\n variables: { input },\n });\n await fetchTemplates();\n return result.data!.createNotificationTemplate;\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to create template';\n console.error('Failed to create template:', err);\n setError(message);\n throw err;\n } finally {\n setIsCreating(false);\n }\n },\n [getClient, fetchTemplates]\n );\n\n // Update template\n const updateTemplate = useCallback(\n async (id: string, input: UpdateTemplateInput): Promise<BackendNotificationTemplate> => {\n setIsUpdating(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.mutate<UpdateNotificationTemplateMutation>({\n mutation: NotificationOps.UpdateNotificationTemplateDocument,\n variables: { id, input },\n });\n await fetchTemplates();\n return result.data!.updateNotificationTemplate;\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to update template';\n console.error('Failed to update template:', err);\n setError(message);\n throw err;\n } finally {\n setIsUpdating(false);\n }\n },\n [getClient, fetchTemplates]\n );\n\n // Delete template\n const deleteTemplate = useCallback(\n async (id: string): Promise<boolean> => {\n setIsDeleting(true);\n setError(null);\n\n try {\n const client = getClient();\n await client.mutate({\n mutation: NotificationOps.DeleteNotificationTemplateDocument,\n variables: { id },\n });\n await fetchTemplates();\n return true;\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to delete template';\n console.error('Failed to delete template:', err);\n setError(message);\n throw err;\n } finally {\n setIsDeleting(false);\n }\n },\n [getClient, fetchTemplates]\n );\n\n // Load more templates\n const loadMore = useCallback(async () => {\n if (!hasMore) return;\n\n try {\n const client = getClient();\n const result = await client.query<GetNotificationTemplatesQuery>({\n query: NotificationOps.GetNotificationTemplatesDocument,\n variables: {\n filter: buildBackendFilter(),\n limit: LIMIT,\n offset: offset,\n },\n fetchPolicy: 'cache-first',\n });\n\n if (result.data?.notificationTemplates) {\n const moreTemplates = result.data.notificationTemplates.items || [];\n setTemplates((prev) => [...prev, ...moreTemplates]);\n setHasMore(result.data.notificationTemplates.hasMore || false);\n setOffset((prev) => prev + LIMIT);\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to load more templates';\n console.error('Failed to load more templates:', err);\n setError(message);\n }\n }, [getClient, buildBackendFilter, hasMore, offset]);\n\n // Update filter\n const updateFilter = useCallback((newFilter: Partial<TemplateFilter>) => {\n setFilter((prev) => ({ ...prev, ...newFilter }));\n }, []);\n\n // Reset filter\n const resetFilter = useCallback(() => {\n setFilter({});\n }, []);\n\n return {\n templates: filteredTemplates,\n allTemplates: templates,\n isLoading,\n isCreating,\n isUpdating,\n isDeleting,\n isMutating: isCreating || isUpdating || isDeleting,\n error,\n hasMore,\n total,\n filter,\n refetch: fetchTemplates,\n loadMore,\n createTemplate,\n updateTemplate,\n deleteTemplate,\n updateFilter,\n resetFilter,\n };\n}\n\n/**\n * Hook to fetch a single template by slug\n * Uses the GLOBAL Apollo client for API calls\n */\nexport function useNotificationTemplate(slug: string | undefined, locale?: string) {\n const { authToken, apiGatewayUrl } = useNotification();\n const [template, setTemplate] = useState<BackendNotificationTemplate | undefined>(undefined);\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n // Get global client — coerce null/undefined authToken to undefined\n const getClient = useCallback(() => {\n return getGlobalNotificationClient(apiGatewayUrl ?? undefined, authToken ?? undefined);\n }, [apiGatewayUrl, authToken]);\n\n // Fetch template\n const fetchTemplate = useCallback(async () => {\n if (!slug) return;\n\n setIsLoading(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.query<GetNotificationTemplateQuery>({\n query: NotificationOps.GetNotificationTemplateDocument,\n variables: { slug, locale },\n fetchPolicy: 'cache-first',\n });\n\n if (result.data?.notificationTemplate) {\n setTemplate(result.data.notificationTemplate);\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to fetch template';\n console.error('[useNotificationTemplate] Failed to fetch template:', err);\n setError(message);\n } finally {\n setIsLoading(false);\n }\n }, [getClient, slug, locale]);\n\n // Fetch on mount and when slug changes\n useEffect(() => {\n fetchTemplate();\n }, [fetchTemplate]);\n\n return {\n template,\n isLoading,\n error,\n refetch: fetchTemplate,\n };\n}\n"],"mappings":";;;;;AAgEA,SAAgB,EAAyB,GAAgC;CACvE,IAAM,EAAE,cAAW,qBAAkB,GAAiB,EAChD,CAAC,GAAW,KAAgB,EAAwC,EAAE,CAAC,EACvE,CAAC,GAAW,KAAgB,EAAS,GAAM,EAC3C,CAAC,GAAY,KAAiB,EAAS,GAAM,EAC7C,CAAC,GAAY,KAAiB,EAAS,GAAM,EAC7C,CAAC,GAAY,KAAiB,EAAS,GAAM,EAC7C,CAAC,GAAO,KAAY,EAAwB,KAAK,EACjD,CAAC,GAAS,KAAc,EAAS,GAAM,EACvC,CAAC,GAAO,KAAY,EAAS,EAAE,EAC/B,CAAC,GAAQ,KAAa,EAAS,EAAE,EACjC,CAAC,GAAQ,KAAa,EAAyB,KAAiB,EAAE,CAAC,EAKnE,IAAY,QACT,EAA4B,KAAiB,KAAA,GAAW,KAAa,KAAA,EAAU,EACrF,CAAC,GAAe,EAAU,CAAC,EAGxB,IAAqB,QAAkB;EAC3C,IAAM,IAAyC,EAAE;AAIjD,SAHI,EAAO,SAAM,EAAc,OAAO,EAAO,OACzC,EAAO,WAAQ,EAAc,SAAS,EAAO,SAC7C,EAAO,YAAY,KAAA,MAAW,EAAc,UAAU,EAA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IACd,CAAC,EAAc,CAAC,EAEZ;EACL;EACA;EACA;EACA,SAAS;EACV"}
1
+ {"version":3,"file":"useNotificationTemplates.js","names":["NotificationOps.GetNotificationTemplatesDocument","NotificationOps.CreateNotificationTemplateDocument","NotificationOps.UpdateNotificationTemplateDocument","NotificationOps.DeleteNotificationTemplateDocument","NotificationOps.GetNotificationTemplateDocument","useNotificationTemplates","useNotification","templates","setTemplates","useState","isLoading","setIsLoading","isCreating","setIsCreating","isUpdating","setIsUpdating","isDeleting","setIsDeleting","error","setError","hasMore","setHasMore","total","setTotal","offset","setOffset","filter","setFilter","initialFilter","getClient","useCallback","getGlobalNotificationClient","apiGatewayUrl","authToken","buildBackendFilter","backendFilter","fetchTemplates","result","GetNotificationTemplatesDocument","err","message","filteredTemplates","t","createTemplate","CreateNotificationTemplateDocument","updateTemplate","UpdateNotificationTemplateDocument","deleteTemplate","DeleteNotificationTemplateDocument","loadMore","moreTemplates","prev","updateFilter","newFilter","resetFilter","useNotificationTemplate","template","setTemplate","fetchTemplate","slug","GetNotificationTemplateDocument","locale","useEffect"],"sources":["../../src/hooks/useNotificationTemplates.ts"],"sourcesContent":["import { useState, useCallback, useEffect } from 'react';\nimport { useNotification } from '../providers/NotificationProvider';\nimport { getGlobalNotificationClient } from '../graphql/global-client';\nimport type { NotificationType } from '../types';\nimport * as NotificationOps from '../generated/global-operations';\nimport type {\n GetNotificationTemplatesQuery,\n GetNotificationTemplateQuery,\n CreateNotificationTemplateMutation,\n UpdateNotificationTemplateMutation,\n} from '../generated/global-operations';\n\n/**\n * Backend template type derived from the generated query\n */\nexport type BackendNotificationTemplate =\n GetNotificationTemplatesQuery['notificationTemplates']['items'][number];\n/**\n * Input type for creating a template (matches backend CreateTemplateInput)\n * Note: Templates are content-only - channel is specified at send time\n */\nexport interface CreateTemplateInput {\n slug: string;\n name: string;\n description?: string;\n type: NotificationType;\n channel?: string;\n locale?: string;\n subject?: string;\n bodyTemplate: string;\n htmlTemplate?: string;\n variables: Record<string, unknown>;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Input type for updating a template (matches backend UpdateTemplateInput)\n */\nexport interface UpdateTemplateInput {\n name?: string;\n description?: string;\n subject?: string;\n bodyTemplate?: string;\n htmlTemplate?: string;\n variables?: Record<string, unknown>;\n enabled?: boolean;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Filter options for templates (matches backend TemplateFilterInput)\n * Note: channel filter removed - templates are content-only\n */\nexport interface TemplateFilter {\n type?: NotificationType;\n locale?: string;\n enabled?: boolean;\n search?: string; // Local filter only\n}\n\n/**\n * Hook to manage notification templates\n * Uses the GLOBAL Apollo client for API calls\n */\nexport function useNotificationTemplates(initialFilter?: TemplateFilter) {\n const { authToken, apiGatewayUrl } = useNotification();\n const [templates, setTemplates] = useState<BackendNotificationTemplate[]>([]);\n const [isLoading, setIsLoading] = useState(false);\n const [isCreating, setIsCreating] = useState(false);\n const [isUpdating, setIsUpdating] = useState(false);\n const [isDeleting, setIsDeleting] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const [hasMore, setHasMore] = useState(false);\n const [total, setTotal] = useState(0);\n const [offset, setOffset] = useState(0);\n const [filter, setFilter] = useState<TemplateFilter>(initialFilter || {});\n\n const LIMIT = 50;\n\n // Get global client — coerce null/undefined authToken to undefined\n const getClient = useCallback(() => {\n return getGlobalNotificationClient(apiGatewayUrl ?? undefined, authToken ?? undefined);\n }, [apiGatewayUrl, authToken]);\n\n // Build backend filter (excludes local-only 'search')\n const buildBackendFilter = useCallback(() => {\n const backendFilter: Record<string, unknown> = {};\n if (filter.type) backendFilter.type = filter.type;\n if (filter.locale) backendFilter.locale = filter.locale;\n if (filter.enabled !== undefined) backendFilter.enabled = filter.enabled;\n return Object.keys(backendFilter).length > 0 ? backendFilter : undefined;\n }, [filter]);\n\n // Fetch templates\n const fetchTemplates = useCallback(async () => {\n setIsLoading(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.query<GetNotificationTemplatesQuery>({\n query: NotificationOps.GetNotificationTemplatesDocument,\n variables: {\n filter: buildBackendFilter(),\n limit: LIMIT,\n offset: 0,\n },\n fetchPolicy: 'cache-first',\n });\n\n if (result.data?.notificationTemplates) {\n setTemplates(result.data.notificationTemplates.items || []);\n setTotal(result.data.notificationTemplates.total || 0);\n setHasMore(result.data.notificationTemplates.hasMore || false);\n setOffset(LIMIT);\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to fetch templates';\n console.error('[useNotificationTemplates] Failed to fetch templates:', err);\n setError(message);\n } finally {\n setIsLoading(false);\n }\n }, [getClient, buildBackendFilter]);\n\n // Initial fetch\n useEffect(() => {\n fetchTemplates();\n }, [fetchTemplates]);\n\n // Filter by search locally\n const filteredTemplates = filter.search\n ? templates.filter(\n (t) =>\n t.name.toLowerCase().includes(filter.search!.toLowerCase()) ||\n t.slug.toLowerCase().includes(filter.search!.toLowerCase()) ||\n t.description?.toLowerCase().includes(filter.search!.toLowerCase())\n )\n : templates;\n\n // Create template\n const createTemplate = useCallback(\n async (input: CreateTemplateInput): Promise<BackendNotificationTemplate> => {\n setIsCreating(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.mutate<CreateNotificationTemplateMutation>({\n mutation: NotificationOps.CreateNotificationTemplateDocument,\n variables: { input },\n });\n await fetchTemplates();\n return result.data!.createNotificationTemplate;\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to create template';\n console.error('Failed to create template:', err);\n setError(message);\n throw err;\n } finally {\n setIsCreating(false);\n }\n },\n [getClient, fetchTemplates]\n );\n\n // Update template\n const updateTemplate = useCallback(\n async (id: string, input: UpdateTemplateInput): Promise<BackendNotificationTemplate> => {\n setIsUpdating(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.mutate<UpdateNotificationTemplateMutation>({\n mutation: NotificationOps.UpdateNotificationTemplateDocument,\n variables: { id, input },\n });\n await fetchTemplates();\n return result.data!.updateNotificationTemplate;\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to update template';\n console.error('Failed to update template:', err);\n setError(message);\n throw err;\n } finally {\n setIsUpdating(false);\n }\n },\n [getClient, fetchTemplates]\n );\n\n // Delete template\n const deleteTemplate = useCallback(\n async (id: string): Promise<boolean> => {\n setIsDeleting(true);\n setError(null);\n\n try {\n const client = getClient();\n await client.mutate({\n mutation: NotificationOps.DeleteNotificationTemplateDocument,\n variables: { id },\n });\n await fetchTemplates();\n return true;\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to delete template';\n console.error('Failed to delete template:', err);\n setError(message);\n throw err;\n } finally {\n setIsDeleting(false);\n }\n },\n [getClient, fetchTemplates]\n );\n\n // Load more templates\n const loadMore = useCallback(async () => {\n if (!hasMore) return;\n\n try {\n const client = getClient();\n const result = await client.query<GetNotificationTemplatesQuery>({\n query: NotificationOps.GetNotificationTemplatesDocument,\n variables: {\n filter: buildBackendFilter(),\n limit: LIMIT,\n offset: offset,\n },\n fetchPolicy: 'cache-first',\n });\n\n if (result.data?.notificationTemplates) {\n const moreTemplates = result.data.notificationTemplates.items || [];\n setTemplates((prev) => [...prev, ...moreTemplates]);\n setHasMore(result.data.notificationTemplates.hasMore || false);\n setOffset((prev) => prev + LIMIT);\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to load more templates';\n console.error('Failed to load more templates:', err);\n setError(message);\n }\n }, [getClient, buildBackendFilter, hasMore, offset]);\n\n // Update filter\n const updateFilter = useCallback((newFilter: Partial<TemplateFilter>) => {\n setFilter((prev) => ({ ...prev, ...newFilter }));\n }, []);\n\n // Reset filter\n const resetFilter = useCallback(() => {\n setFilter({});\n }, []);\n\n return {\n templates: filteredTemplates,\n allTemplates: templates,\n isLoading,\n isCreating,\n isUpdating,\n isDeleting,\n isMutating: isCreating || isUpdating || isDeleting,\n error,\n hasMore,\n total,\n filter,\n refetch: fetchTemplates,\n loadMore,\n createTemplate,\n updateTemplate,\n deleteTemplate,\n updateFilter,\n resetFilter,\n };\n}\n\n/**\n * Hook to fetch a single template by slug\n * Uses the GLOBAL Apollo client for API calls\n */\nexport function useNotificationTemplate(slug: string | undefined, locale?: string) {\n const { authToken, apiGatewayUrl } = useNotification();\n const [template, setTemplate] = useState<BackendNotificationTemplate | undefined>(undefined);\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n // Get global client — coerce null/undefined authToken to undefined\n const getClient = useCallback(() => {\n return getGlobalNotificationClient(apiGatewayUrl ?? undefined, authToken ?? undefined);\n }, [apiGatewayUrl, authToken]);\n\n // Fetch template\n const fetchTemplate = useCallback(async () => {\n if (!slug) return;\n\n setIsLoading(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.query<GetNotificationTemplateQuery>({\n query: NotificationOps.GetNotificationTemplateDocument,\n variables: { slug, locale },\n fetchPolicy: 'cache-first',\n });\n\n if (result.data?.notificationTemplate) {\n setTemplate(result.data.notificationTemplate);\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to fetch template';\n console.error('[useNotificationTemplate] Failed to fetch template:', err);\n setError(message);\n } finally {\n setIsLoading(false);\n }\n }, [getClient, slug, locale]);\n\n // Fetch on mount and when slug changes\n useEffect(() => {\n fetchTemplate();\n }, [fetchTemplate]);\n\n return {\n template,\n isLoading,\n error,\n refetch: fetchTemplate,\n };\n}\n"],"mappings":";;;;;AAgEA,SAAgBK,EAAyB,GAAgC;CACvE,IAAM,EAAE,cAAW,qBAAkBC,EAAgB,GAC/C,CAACC,GAAWC,KAAgBC,EAAwC,CAAC,CAAC,GACtE,CAACC,GAAWC,KAAgBF,EAAS,EAAK,GAC1C,CAACG,GAAYC,KAAiBJ,EAAS,EAAK,GAC5C,CAACK,GAAYC,KAAiBN,EAAS,EAAK,GAC5C,CAACO,GAAYC,KAAiBR,EAAS,EAAK,GAC5C,CAACS,GAAOC,KAAYV,EAAwB,IAAI,GAChD,CAACW,GAASC,KAAcZ,EAAS,EAAK,GACtC,CAACa,GAAOC,KAAYd,EAAS,CAAC,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;AACF;AAMA,SAAgBmB,EAAwB,GAA0B,GAAiB;CACjF,IAAM,EAAE,cAAW,qBAAkBjD,EAAgB,GAC/C,CAACkD,GAAUC,KAAehD,EAAkD,KAAA,CAAS,GACrF,CAACC,GAAWC,KAAgBF,EAAS,EAAK,GAC1C,CAACS,GAAOC,KAAYV,EAAwB,IAAI,GAGhDoB,IAAYC,QACTC,EAA4BC,KAAiB,KAAA,GAAWC,KAAa,KAAA,CAAS,GACpF,CAACD,GAAeC,CAAS,CAAC,GAGvByB,IAAgB5B,EAAY,YAAY;EAC5C,IAAK6B,GAEL;GACA,AADAhD,EAAa,EAAI,GACjBQ,EAAS,IAAI;GAEb,IAAI;IAEF,IAAMkB,IAAS,MADAR,EACM,CAAA,CAAO,MAAoC;KAC9D,OAAOzB;KACP,WAAW;MAAE;MAAM;KAAO;KAC1B,aAAa;IACf,CAAC;IAED,AAAIiC,EAAO,MAAM,wBACfoB,EAAYpB,EAAO,KAAK,oBAAoB;GAEhD,SAASE,GAAc;IACrB,IAAMC,IAAUD,aAAe,QAAQA,EAAI,UAAU;IAErD,AADA,QAAQ,MAAM,uDAAuDA,CAAG,GACxEpB,EAASqB,CAAO;GAClB,UAAU;IACR,EAAa,EAAK;GACpB;EApBiB;CAqBnB,GAAG;EAACX;EAAW8B;EAAME;CAAM,CAAC;CAO5B,OAJAC,QAAgB;EACd,EAAc;CAChB,GAAG,CAACJ,CAAa,CAAC,GAEX;EACL;EACA;EACA;EACA,SAASA;CACX;AACF"}
@@ -0,0 +1,35 @@
1
+ import { NotificationTopic, NotificationTopicSubscription } from '../types';
2
+ export interface NotificationTopicFilter {
3
+ search?: string;
4
+ type?: string;
5
+ isActive?: boolean;
6
+ }
7
+ export interface CreateNotificationTopicInput {
8
+ name: string;
9
+ slug: string;
10
+ description?: string;
11
+ type: string;
12
+ isActive?: boolean;
13
+ metadata?: Record<string, unknown>;
14
+ }
15
+ export interface UpdateNotificationTopicInput {
16
+ name?: string;
17
+ slug?: string;
18
+ description?: string;
19
+ type?: string;
20
+ isActive?: boolean;
21
+ metadata?: Record<string, unknown>;
22
+ }
23
+ export declare function useNotificationTopics(initialFilter?: NotificationTopicFilter): {
24
+ topics: NotificationTopic[];
25
+ isLoading: boolean;
26
+ error: string | null;
27
+ isForbidden: boolean;
28
+ filter: NotificationTopicFilter;
29
+ setFilter: import('react').Dispatch<import('react').SetStateAction<NotificationTopicFilter>>;
30
+ refetch: () => Promise<void>;
31
+ createTopic: (input: CreateNotificationTopicInput) => Promise<NotificationTopic | null>;
32
+ updateTopic: (id: string, input: UpdateNotificationTopicInput) => Promise<NotificationTopic | null>;
33
+ deleteTopic: (id: string) => Promise<boolean>;
34
+ setTopicSubscription: (topicId: string, subscribed: boolean) => Promise<NotificationTopicSubscription | null>;
35
+ };
@@ -1,9 +1,9 @@
1
1
  import { useNotification as e } from "../providers/NotificationProvider.js";
2
2
  import { getGlobalNotificationClient as t } from "../graphql/global-client.js";
3
- import { CreateNotificationTopicDocument as n, DeleteNotificationTopicDocument as r, GetNotificationTopicsDocument as i, SetNotificationTopicSubscriptionDocument as a, UpdateNotificationTopicDocument as o } from "../generated/global-operations.js";
4
- import { isPermissionError as s } from "../utils/index.js";
3
+ import { isPermissionError as n } from "../utils/index.js";
4
+ import { CreateNotificationTopicDocument as r, DeleteNotificationTopicDocument as i, GetNotificationTopicsDocument as a, SetNotificationTopicSubscriptionDocument as o, UpdateNotificationTopicDocument as s } from "../generated/global-operations.js";
5
5
  import { useCallback as c, useEffect as l, useState as u } from "react";
6
- //#region src/hooks/useNotificationTopics.ts
6
+ // src/hooks/useNotificationTopics.ts
7
7
  function d(e) {
8
8
  return {
9
9
  id: e.id,
@@ -29,8 +29,8 @@ function f(f) {
29
29
  let { authToken: p, apiGatewayUrl: m } = e(), [h, g] = u([]), [_, v] = u(!1), [y, b] = u(null), [x, S] = u(!1), [C, w] = u(f || {}), T = c(() => t(m ?? void 0, p ?? void 0), [m, p]), E = c(async () => {
30
30
  v(!0), b(null), S(!1);
31
31
  try {
32
- g(((await T().query({
33
- query: i,
32
+ let e = await T().query({
33
+ query: a,
34
34
  variables: {
35
35
  filter: {
36
36
  ...C.search ? { search: C.search } : {},
@@ -41,9 +41,10 @@ function f(f) {
41
41
  offset: 0
42
42
  },
43
43
  fetchPolicy: "network-only"
44
- })).data?.notificationTopics.items || []).map(d));
44
+ });
45
+ g((e.data?.notificationTopics.items || []).map(d));
45
46
  } catch (e) {
46
- s(e) ? S(!0) : (console.error("[useNotificationTopics] Failed to fetch topics:", e), b(e instanceof Error ? e.message : "Failed to fetch topics")), g([]);
47
+ n(e) ? S(!0) : (console.error("[useNotificationTopics] Failed to fetch topics:", e), b(e instanceof Error ? e.message : "Failed to fetch topics")), g([]);
47
48
  } finally {
48
49
  v(!1);
49
50
  }
@@ -60,26 +61,26 @@ function f(f) {
60
61
  refetch: E,
61
62
  createTopic: c(async (e) => {
62
63
  let t = await T().mutate({
63
- mutation: n,
64
+ mutation: r,
64
65
  variables: { input: e }
65
66
  });
66
67
  await E();
67
- let r = t.data?.createNotificationTopic;
68
- return r ? {
69
- id: r.id,
70
- slug: r.slug,
71
- name: r.name,
72
- description: r.description ?? void 0,
73
- type: r.type,
74
- isActive: r.isActive,
68
+ let n = t.data?.createNotificationTopic;
69
+ return n ? {
70
+ id: n.id,
71
+ slug: n.slug,
72
+ name: n.name,
73
+ description: n.description ?? void 0,
74
+ type: n.type,
75
+ isActive: n.isActive,
75
76
  subscriberCount: 0,
76
- createdAt: r.createdAt,
77
- updatedAt: r.updatedAt
77
+ createdAt: n.createdAt,
78
+ updatedAt: n.updatedAt
78
79
  } : null;
79
80
  }, [E, T]),
80
81
  updateTopic: c(async (e, t) => {
81
82
  let n = await T().mutate({
82
- mutation: o,
83
+ mutation: s,
83
84
  variables: {
84
85
  id: e,
85
86
  input: t
@@ -100,12 +101,12 @@ function f(f) {
100
101
  } : null;
101
102
  }, [E, T]),
102
103
  deleteTopic: c(async (e) => (await T().mutate({
103
- mutation: r,
104
+ mutation: i,
104
105
  variables: { id: e }
105
106
  }), await E(), !0), [E, T]),
106
107
  setTopicSubscription: c(async (e, t) => {
107
108
  let n = await T().mutate({
108
- mutation: a,
109
+ mutation: o,
109
110
  variables: { input: {
110
111
  topicId: e,
111
112
  subscribed: t
@@ -123,7 +124,6 @@ function f(f) {
123
124
  }, [E, T])
124
125
  };
125
126
  }
126
- //#endregion
127
127
  export { f as useNotificationTopics };
128
128
 
129
129
  //# sourceMappingURL=useNotificationTopics.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useNotificationTopics.js","names":[],"sources":["../../src/hooks/useNotificationTopics.ts"],"sourcesContent":["import { useState, useEffect, useCallback } from 'react';\nimport { useNotification } from '../providers/NotificationProvider';\nimport { getGlobalNotificationClient } from '../graphql/global-client';\nimport type { NotificationTopic, NotificationTopicSubscription } from '../types';\nimport { isPermissionError } from '../utils';\nimport * as NotificationOps from '../generated/global-operations';\nimport type {\n GetNotificationTopicsQuery,\n CreateNotificationTopicMutation,\n UpdateNotificationTopicMutation,\n SetNotificationTopicSubscriptionMutation,\n} from '../generated/global-operations';\n\nexport interface NotificationTopicFilter {\n search?: string;\n type?: string;\n isActive?: boolean;\n}\n\nexport interface CreateNotificationTopicInput {\n name: string;\n slug: string;\n description?: string;\n type: string;\n isActive?: boolean;\n metadata?: Record<string, unknown>;\n}\n\nexport interface UpdateNotificationTopicInput {\n name?: string;\n slug?: string;\n description?: string;\n type?: string;\n isActive?: boolean;\n metadata?: Record<string, unknown>;\n}\n\nfunction mapTopic(\n topic: GetNotificationTopicsQuery['notificationTopics']['items'][number]\n): NotificationTopic {\n return {\n id: topic.id,\n slug: topic.slug,\n name: topic.name,\n description: topic.description ?? undefined,\n type: topic.type as NotificationTopic['type'],\n isActive: topic.isActive,\n metadata: topic.metadata ?? undefined,\n subscriberCount: topic.subscriberCount ?? 0,\n mySubscription: topic.mySubscription\n ? {\n id: topic.mySubscription.id,\n subscribed: topic.mySubscription.subscribed,\n unsubscribedAt: topic.mySubscription.unsubscribedAt ?? undefined,\n topicId: topic.mySubscription.topicId,\n userId: topic.mySubscription.userId,\n }\n : undefined,\n createdAt: topic.createdAt,\n updatedAt: topic.updatedAt,\n };\n}\n\nexport function useNotificationTopics(initialFilter?: NotificationTopicFilter) {\n const { authToken, apiGatewayUrl } = useNotification();\n const [topics, setTopics] = useState<NotificationTopic[]>([]);\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n // True when the gateway denied `notificationTopics` (no notification-topic\n // read). Pages show a no-access state instead of \"no topics\" (BOFF-10104).\n const [isForbidden, setIsForbidden] = useState(false);\n const [filter, setFilter] = useState<NotificationTopicFilter>(initialFilter || {});\n\n const getClient = useCallback(() => {\n return getGlobalNotificationClient(apiGatewayUrl ?? undefined, authToken ?? undefined);\n }, [apiGatewayUrl, authToken]);\n\n const fetchTopics = useCallback(async () => {\n setIsLoading(true);\n setError(null);\n setIsForbidden(false);\n\n try {\n const client = getClient();\n const result = await client.query<GetNotificationTopicsQuery>({\n query: NotificationOps.GetNotificationTopicsDocument,\n variables: {\n filter: {\n ...(filter.search ? { search: filter.search } : {}),\n ...(filter.type ? { type: filter.type } : {}),\n ...(filter.isActive !== undefined ? { isActive: filter.isActive } : {}),\n },\n limit: 100,\n offset: 0,\n },\n // Always revalidate: access to topics can be revoked while the app is\n // open, and a cached list would hide the FORBIDDEN (BOFF-10104).\n fetchPolicy: 'network-only',\n });\n\n setTopics((result.data?.notificationTopics.items || []).map(mapTopic));\n } catch (err) {\n // A denial is a handled state (isForbidden), not a load error.\n if (isPermissionError(err)) {\n setIsForbidden(true);\n } else {\n console.error('[useNotificationTopics] Failed to fetch topics:', err);\n setError(err instanceof Error ? err.message : 'Failed to fetch topics');\n }\n setTopics([]);\n } finally {\n setIsLoading(false);\n }\n }, [filter, getClient]);\n\n useEffect(() => {\n fetchTopics();\n }, [fetchTopics]);\n\n const createTopic = useCallback(\n async (input: CreateNotificationTopicInput): Promise<NotificationTopic | null> => {\n const client = getClient();\n const result = await client.mutate<CreateNotificationTopicMutation>({\n mutation: NotificationOps.CreateNotificationTopicDocument,\n variables: { input },\n });\n await fetchTopics();\n const created = result.data?.createNotificationTopic;\n return created\n ? {\n id: created.id,\n slug: created.slug,\n name: created.name,\n description: created.description ?? undefined,\n type: created.type as NotificationTopic['type'],\n isActive: created.isActive,\n subscriberCount: 0,\n createdAt: created.createdAt,\n updatedAt: created.updatedAt,\n }\n : null;\n },\n [fetchTopics, getClient]\n );\n\n const updateTopic = useCallback(\n async (id: string, input: UpdateNotificationTopicInput): Promise<NotificationTopic | null> => {\n const client = getClient();\n const result = await client.mutate<UpdateNotificationTopicMutation>({\n mutation: NotificationOps.UpdateNotificationTopicDocument,\n variables: { id, input },\n });\n await fetchTopics();\n const updated = result.data?.updateNotificationTopic;\n return updated\n ? {\n id: updated.id,\n slug: updated.slug,\n name: updated.name,\n description: updated.description ?? undefined,\n type: updated.type as NotificationTopic['type'],\n isActive: updated.isActive,\n subscriberCount: 0,\n createdAt: updated.createdAt,\n updatedAt: updated.updatedAt,\n }\n : null;\n },\n [fetchTopics, getClient]\n );\n\n const deleteTopic = useCallback(\n async (id: string): Promise<boolean> => {\n const client = getClient();\n await client.mutate({\n mutation: NotificationOps.DeleteNotificationTopicDocument,\n variables: { id },\n });\n await fetchTopics();\n return true;\n },\n [fetchTopics, getClient]\n );\n\n const setTopicSubscription = useCallback(\n async (topicId: string, subscribed: boolean): Promise<NotificationTopicSubscription | null> => {\n const client = getClient();\n const result = await client.mutate<SetNotificationTopicSubscriptionMutation>({\n mutation: NotificationOps.SetNotificationTopicSubscriptionDocument,\n variables: {\n input: {\n topicId,\n subscribed,\n },\n },\n });\n await fetchTopics();\n\n const subscription = result.data?.setNotificationTopicSubscription;\n return subscription\n ? {\n id: subscription.id,\n subscribed: subscription.subscribed,\n unsubscribedAt: subscription.unsubscribedAt ?? undefined,\n topicId: subscription.topicId,\n userId: subscription.userId,\n }\n : null;\n },\n [fetchTopics, getClient]\n );\n\n return {\n topics,\n isLoading,\n error,\n isForbidden,\n filter,\n setFilter,\n refetch: fetchTopics,\n createTopic,\n updateTopic,\n deleteTopic,\n setTopicSubscription,\n };\n}\n"],"mappings":";;;;;;AAqCA,SAAS,EACP,GACmB;AACnB,QAAO;EACL,IAAI,EAAM;EACV,MAAM,EAAM;EACZ,MAAM,EAAM;EACZ,aAAa,EAAM,eAAe,KAAA;EAClC,MAAM,EAAM;EACZ,UAAU,EAAM;EAChB,UAAU,EAAM,YAAY,KAAA;EAC5B,iBAAiB,EAAM,mBAAmB;EAC1C,gBAAgB,EAAM,iBAClB;GACE,IAAI,EAAM,eAAe;GACzB,YAAY,EAAM,eAAe;GACjC,gBAAgB,EAAM,eAAe,kBAAkB,KAAA;GACvD,SAAS,EAAM,eAAe;GAC9B,QAAQ,EAAM,eAAe;GAC9B,GACD,KAAA;EACJ,WAAW,EAAM;EACjB,WAAW,EAAM;EAClB;;AAGH,SAAgB,EAAsB,GAAyC;CAC7E,IAAM,EAAE,cAAW,qBAAkB,GAAiB,EAChD,CAAC,GAAQ,KAAa,EAA8B,EAAE,CAAC,EACvD,CAAC,GAAW,KAAgB,EAAS,GAAM,EAC3C,CAAC,GAAO,KAAY,EAAwB,KAAK,EAGjD,CAAC,GAAa,KAAkB,EAAS,GAAM,EAC/C,CAAC,GAAQ,KAAa,EAAkC,KAAiB,EAAE,CAAC,EAE5E,IAAY,QACT,EAA4B,KAAiB,KAAA,GAAW,KAAa,KAAA,EAAU,EACrF,CAAC,GAAe,EAAU,CAAC,EAExB,IAAc,EAAY,YAAY;AAG1C,EAFA,EAAa,GAAK,EAClB,EAAS,KAAK,EACd,EAAe,GAAM;AAErB,MAAI;AAkBF,OAhBe,MADA,GAAW,CACE,MAAkC;IAC5D,OAAO;IACP,WAAW;KACT,QAAQ;MACN,GAAI,EAAO,SAAS,EAAE,QAAQ,EAAO,QAAQ,GAAG,EAAE;MAClD,GAAI,EAAO,OAAO,EAAE,MAAM,EAAO,MAAM,GAAG,EAAE;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AAQ;IAClB,iBAAiB;IACjB,WAAW,EAAQ;IACnB,WAAW,EAAQ;IACpB,GACD;KAEN,CAAC,GAAa,EAAU,CACzB;EAqDC,aAnDkB,EAClB,OAAO,OAEL,MADe,GAAW,CACb,OAAO;GAClB,UAAU;GACV,WAAW,EAAE,OAAI;GAClB,CAAC,EACF,MAAM,GAAa,EACZ,KAET,CAAC,GAAa,EAAU,CACzB;EAyCC,sBAvC2B,EAC3B,OAAO,GAAiB,MAAuE;GAE7F,IAAM,IAAS,MADA,GAAW,CACE,OAAiD;IAC3E,UAAU;IACV,WAAW,EACT,OAAO;KACL;KACA;KACD,EACF;IACF,CAAC;AACF,SAAM,GAAa;GAEnB,IAAM,IAAe,EAAO,MAAM;AAClC,UAAO,IACH;IACE,IAAI,EAAa;IACjB,YAAY,EAAa;IACzB,gBAAgB,EAAa,kBAAkB,KAAA;IAC/C,SAAS,EAAa;IACtB,QAAQ,EAAa;IACtB,GACD;KAEN,CAAC,GAAa,EAAU,CACzB;EAcA"}
1
+ {"version":3,"file":"useNotificationTopics.js","names":["NotificationOps.GetNotificationTopicsDocument","NotificationOps.CreateNotificationTopicDocument","NotificationOps.UpdateNotificationTopicDocument","NotificationOps.DeleteNotificationTopicDocument","NotificationOps.SetNotificationTopicSubscriptionDocument","mapTopic","topic","useNotificationTopics","useNotification","topics","setTopics","useState","isLoading","setIsLoading","error","setError","isForbidden","setIsForbidden","filter","setFilter","initialFilter","getClient","useCallback","getGlobalNotificationClient","apiGatewayUrl","authToken","fetchTopics","result","GetNotificationTopicsDocument","err","isPermissionError","useEffect","CreateNotificationTopicDocument","created","UpdateNotificationTopicDocument","updated","DeleteNotificationTopicDocument","SetNotificationTopicSubscriptionDocument","subscription"],"sources":["../../src/hooks/useNotificationTopics.ts"],"sourcesContent":["import { useState, useEffect, useCallback } from 'react';\nimport { useNotification } from '../providers/NotificationProvider';\nimport { getGlobalNotificationClient } from '../graphql/global-client';\nimport type { NotificationTopic, NotificationTopicSubscription } from '../types';\nimport { isPermissionError } from '../utils';\nimport * as NotificationOps from '../generated/global-operations';\nimport type {\n GetNotificationTopicsQuery,\n CreateNotificationTopicMutation,\n UpdateNotificationTopicMutation,\n SetNotificationTopicSubscriptionMutation,\n} from '../generated/global-operations';\n\nexport interface NotificationTopicFilter {\n search?: string;\n type?: string;\n isActive?: boolean;\n}\n\nexport interface CreateNotificationTopicInput {\n name: string;\n slug: string;\n description?: string;\n type: string;\n isActive?: boolean;\n metadata?: Record<string, unknown>;\n}\n\nexport interface UpdateNotificationTopicInput {\n name?: string;\n slug?: string;\n description?: string;\n type?: string;\n isActive?: boolean;\n metadata?: Record<string, unknown>;\n}\n\nfunction mapTopic(\n topic: GetNotificationTopicsQuery['notificationTopics']['items'][number]\n): NotificationTopic {\n return {\n id: topic.id,\n slug: topic.slug,\n name: topic.name,\n description: topic.description ?? undefined,\n type: topic.type as NotificationTopic['type'],\n isActive: topic.isActive,\n metadata: topic.metadata ?? undefined,\n subscriberCount: topic.subscriberCount ?? 0,\n mySubscription: topic.mySubscription\n ? {\n id: topic.mySubscription.id,\n subscribed: topic.mySubscription.subscribed,\n unsubscribedAt: topic.mySubscription.unsubscribedAt ?? undefined,\n topicId: topic.mySubscription.topicId,\n userId: topic.mySubscription.userId,\n }\n : undefined,\n createdAt: topic.createdAt,\n updatedAt: topic.updatedAt,\n };\n}\n\nexport function useNotificationTopics(initialFilter?: NotificationTopicFilter) {\n const { authToken, apiGatewayUrl } = useNotification();\n const [topics, setTopics] = useState<NotificationTopic[]>([]);\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n // True when the gateway denied `notificationTopics` (no notification-topic\n // read). Pages show a no-access state instead of \"no topics\" (BOFF-10104).\n const [isForbidden, setIsForbidden] = useState(false);\n const [filter, setFilter] = useState<NotificationTopicFilter>(initialFilter || {});\n\n const getClient = useCallback(() => {\n return getGlobalNotificationClient(apiGatewayUrl ?? undefined, authToken ?? undefined);\n }, [apiGatewayUrl, authToken]);\n\n const fetchTopics = useCallback(async () => {\n setIsLoading(true);\n setError(null);\n setIsForbidden(false);\n\n try {\n const client = getClient();\n const result = await client.query<GetNotificationTopicsQuery>({\n query: NotificationOps.GetNotificationTopicsDocument,\n variables: {\n filter: {\n ...(filter.search ? { search: filter.search } : {}),\n ...(filter.type ? { type: filter.type } : {}),\n ...(filter.isActive !== undefined ? { isActive: filter.isActive } : {}),\n },\n limit: 100,\n offset: 0,\n },\n // Always revalidate: access to topics can be revoked while the app is\n // open, and a cached list would hide the FORBIDDEN (BOFF-10104).\n fetchPolicy: 'network-only',\n });\n\n setTopics((result.data?.notificationTopics.items || []).map(mapTopic));\n } catch (err) {\n // A denial is a handled state (isForbidden), not a load error.\n if (isPermissionError(err)) {\n setIsForbidden(true);\n } else {\n console.error('[useNotificationTopics] Failed to fetch topics:', err);\n setError(err instanceof Error ? err.message : 'Failed to fetch topics');\n }\n setTopics([]);\n } finally {\n setIsLoading(false);\n }\n }, [filter, getClient]);\n\n useEffect(() => {\n fetchTopics();\n }, [fetchTopics]);\n\n const createTopic = useCallback(\n async (input: CreateNotificationTopicInput): Promise<NotificationTopic | null> => {\n const client = getClient();\n const result = await client.mutate<CreateNotificationTopicMutation>({\n mutation: NotificationOps.CreateNotificationTopicDocument,\n variables: { input },\n });\n await fetchTopics();\n const created = result.data?.createNotificationTopic;\n return created\n ? {\n id: created.id,\n slug: created.slug,\n name: created.name,\n description: created.description ?? undefined,\n type: created.type as NotificationTopic['type'],\n isActive: created.isActive,\n subscriberCount: 0,\n createdAt: created.createdAt,\n updatedAt: created.updatedAt,\n }\n : null;\n },\n [fetchTopics, getClient]\n );\n\n const updateTopic = useCallback(\n async (id: string, input: UpdateNotificationTopicInput): Promise<NotificationTopic | null> => {\n const client = getClient();\n const result = await client.mutate<UpdateNotificationTopicMutation>({\n mutation: NotificationOps.UpdateNotificationTopicDocument,\n variables: { id, input },\n });\n await fetchTopics();\n const updated = result.data?.updateNotificationTopic;\n return updated\n ? {\n id: updated.id,\n slug: updated.slug,\n name: updated.name,\n description: updated.description ?? undefined,\n type: updated.type as NotificationTopic['type'],\n isActive: updated.isActive,\n subscriberCount: 0,\n createdAt: updated.createdAt,\n updatedAt: updated.updatedAt,\n }\n : null;\n },\n [fetchTopics, getClient]\n );\n\n const deleteTopic = useCallback(\n async (id: string): Promise<boolean> => {\n const client = getClient();\n await client.mutate({\n mutation: NotificationOps.DeleteNotificationTopicDocument,\n variables: { id },\n });\n await fetchTopics();\n return true;\n },\n [fetchTopics, getClient]\n );\n\n const setTopicSubscription = useCallback(\n async (topicId: string, subscribed: boolean): Promise<NotificationTopicSubscription | null> => {\n const client = getClient();\n const result = await client.mutate<SetNotificationTopicSubscriptionMutation>({\n mutation: NotificationOps.SetNotificationTopicSubscriptionDocument,\n variables: {\n input: {\n topicId,\n subscribed,\n },\n },\n });\n await fetchTopics();\n\n const subscription = result.data?.setNotificationTopicSubscription;\n return subscription\n ? {\n id: subscription.id,\n subscribed: subscription.subscribed,\n unsubscribedAt: subscription.unsubscribedAt ?? undefined,\n topicId: subscription.topicId,\n userId: subscription.userId,\n }\n : null;\n },\n [fetchTopics, getClient]\n );\n\n return {\n topics,\n isLoading,\n error,\n isForbidden,\n filter,\n setFilter,\n refetch: fetchTopics,\n createTopic,\n updateTopic,\n deleteTopic,\n setTopicSubscription,\n };\n}\n"],"mappings":";;;;;;AAqCA,SAASK,EACP,GACmB;CACnB,OAAO;EACL,IAAIC,EAAM;EACV,MAAMA,EAAM;EACZ,MAAMA,EAAM;EACZ,aAAaA,EAAM,eAAe,KAAA;EAClC,MAAMA,EAAM;EACZ,UAAUA,EAAM;EAChB,UAAUA,EAAM,YAAY,KAAA;EAC5B,iBAAiBA,EAAM,mBAAmB;EAC1C,gBAAgBA,EAAM,iBAClB;GACE,IAAIA,EAAM,eAAe;GACzB,YAAYA,EAAM,eAAe;GACjC,gBAAgBA,EAAM,eAAe,kBAAkB,KAAA;GACvD,SAASA,EAAM,eAAe;GAC9B,QAAQA,EAAM,eA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AAMK,IAAS,MADAN,EACM,CAAA,CAAO,OAAiD;IAC3E,UAAUjB;IACV,WAAW,EACT,OAAO;KACL;KACA;IACF,EACF;GACF,CAAC;GACD,MAAMsB,EAAY;GAElB,IAAMY,IAAeX,EAAO,MAAM;GAClC,OAAOW,IACH;IACE,IAAIA,EAAa;IACjB,YAAYA,EAAa;IACzB,gBAAgBA,EAAa,kBAAkB,KAAA;IAC/C,SAASA,EAAa;IACtB,QAAQA,EAAa;GACvB,IACA;EACN,GACA,CAACZ,GAAaL,CAAS,CAcvB;CACF;AACF"}
@@ -0,0 +1,39 @@
1
+ import { Notification, NotificationFilter } from '../types';
2
+ interface UseNotificationsOptions {
3
+ baseFilter?: Partial<NotificationFilter>;
4
+ unreadFilter?: Record<string, unknown>;
5
+ }
6
+ /**
7
+ * Hook to manage notifications with real GraphQL backend integration.
8
+ *
9
+ * Uses the global Apollo client to query the notification service via the
10
+ * public gateway (https://gw-global.local.burdenoff.com/global/graphql).
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const { notifications, unreadCount, markAsRead } = useNotifications();
15
+ * ```
16
+ */
17
+ export declare function useNotifications(options?: UseNotificationsOptions): {
18
+ notifications: Notification[];
19
+ allNotifications: Notification[];
20
+ unreadCount: number;
21
+ selectedNotification: Notification | null;
22
+ notificationFilter: NotificationFilter;
23
+ isLoading: boolean;
24
+ error: string | null;
25
+ hasMore: boolean;
26
+ total: number;
27
+ markAsRead: (notificationId: string) => Promise<void>;
28
+ markAllAsRead: () => Promise<void>;
29
+ archiveNotification: (notificationId: string) => Promise<void>;
30
+ bulkArchive: (notificationIds: string[]) => Promise<void>;
31
+ unarchiveNotification: (notificationId: string) => Promise<void>;
32
+ recordAction: (notificationId: string, actionId?: string) => Promise<void>;
33
+ setSelectedNotification: import('react').Dispatch<import('react').SetStateAction<Notification | null>>;
34
+ updateFilter: (filter: Partial<NotificationFilter>) => void;
35
+ resetFilter: () => void;
36
+ refetch: () => Promise<void>;
37
+ loadMore: () => Promise<void>;
38
+ };
39
+ export {};
@@ -3,7 +3,7 @@ import { USER_NOTIFICATION_CONTEXT as t, getGlobalNotificationClient as n } from
3
3
  import { useNotificationStore as r } from "../store/notificationStore.js";
4
4
  import { ArchiveNotificationDocument as i, ArchiveNotificationsDocument as a, GetMyUnreadNotificationCountDocument as o, GetNotificationsDocument as s, MarkAllMyNotificationsAsReadDocument as c, MarkNotificationAsReadDocument as l, NotificationReceivedDocument as u, RecordNotificationActionDocument as d, UnarchiveNotificationDocument as f, UnreadCountUpdatedDocument as p } from "../generated/global-operations.js";
5
5
  import { useCallback as m, useEffect as h, useMemo as g, useState as _ } from "react";
6
- //#region src/hooks/useNotifications.ts
6
+ // src/hooks/useNotifications.ts
7
7
  function v(e) {
8
8
  return {
9
9
  id: e.id,
@@ -143,7 +143,10 @@ function w(y = {}) {
143
143
  },
144
144
  fetchPolicy: "network-only"
145
145
  });
146
- e.data?.notifications && (N(e.data.notifications.items.map(v)), U(e.data.notifications.total), V(e.data.notifications.hasMore), G(50));
146
+ if (e.data?.notifications) {
147
+ let t = e.data.notifications.items.map(v);
148
+ N(t), U(e.data.notifications.total), V(e.data.notifications.hasMore), G(50);
149
+ }
147
150
  } catch (e) {
148
151
  let t = e instanceof Error ? e.message : "Failed to fetch notifications";
149
152
  console.error("[useNotifications] Failed to fetch notifications:", e), z(t);
@@ -328,7 +331,7 @@ function w(y = {}) {
328
331
  };
329
332
  return document.addEventListener("visibilitychange", e), () => document.removeEventListener("visibilitychange", e);
330
333
  }, [X, Z]), {
331
- notifications: g(() => M.filter((e) => e.deliveryStatus === "UNSUBSCRIBED" || e.status === "ARCHIVED" && !e.archivedAt ? !1 : K.archived === !0 ? !!e.archivedAt : K.archived === !1 ? !e.archivedAt : !0), [K.archived, M]),
334
+ notifications: g(() => M.filter((e) => e.deliveryStatus === "UNSUBSCRIBED" || e.status === "ARCHIVED" && !e.archivedAt ? !1 : K.archived === !0 ? !!e.archivedAt : K.archived !== !1 || !e.archivedAt), [K.archived, M]),
332
335
  allNotifications: M,
333
336
  unreadCount: k,
334
337
  selectedNotification: P,
@@ -350,7 +353,6 @@ function w(y = {}) {
350
353
  loadMore: Q
351
354
  };
352
355
  }
353
- //#endregion
354
356
  export { w as useNotifications };
355
357
 
356
358
  //# sourceMappingURL=useNotifications.js.map