@xk2800/nextjs-template 0.7.2-beta.1 → 0.7.2-beta.11

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 (248) hide show
  1. package/README.md +1 -0
  2. package/components/auth/{loginErrorRecovery.tsx → forms/login-error-recovery.tsx} +1 -1
  3. package/components/auth/{emailPasswordLogin.tsx → forms/login-form.tsx} +8 -8
  4. package/components/auth/{emailPasswordSignup.tsx → forms/signup-form.tsx} +11 -8
  5. package/components/auth/{authCard.tsx → layout/auth-card.tsx} +5 -5
  6. package/components/auth/{authShell.tsx → layout/auth-shell.tsx} +17 -5
  7. package/components/auth/{oneTap.tsx → methods/one-tap.tsx} +2 -2
  8. package/components/auth/{passkeyLogin.tsx → methods/passkey-login.tsx} +2 -2
  9. package/components/auth/{socialLogin.tsx → methods/social-login.tsx} +3 -3
  10. package/components/auth/{twoFactorVerifyForm.tsx → mfa/two-factor-verify-form.tsx} +5 -5
  11. package/components/auth/{forgotPasswordForm.tsx → recovery/forgot-password-form.tsx} +4 -4
  12. package/components/auth/{resetPasswordForm.tsx → recovery/reset-password-form.tsx} +4 -4
  13. package/components/auth/{deviceCheck.tsx → session/device-check.tsx} +3 -3
  14. package/components/auth/{logoutButtons.tsx → session/logout-buttons.tsx} +2 -2
  15. package/components/dashboard/admin/{activityLogsSection.tsx → activity-logs/activity-logs-section.tsx} +1 -1
  16. package/components/dashboard/admin/activity-logs/admin-activity-logs-table.tsx +375 -0
  17. package/components/dashboard/admin/activity-logs/audit-severity-badge.tsx +50 -0
  18. package/components/dashboard/admin/activity-logs/security-highlights-collapsible.tsx +129 -0
  19. package/components/dashboard/admin/{adminActivityLogsSkeleton.tsx → activity-logs/skeletons/activity-logs-skeleton.tsx} +2 -2
  20. package/components/dashboard/admin/{adminStatsGrid.tsx → home/admin-stats-grid.tsx} +1 -1
  21. package/components/dashboard/admin/{deviceThrottleCard.tsx → home/device-throttle-card.tsx} +8 -5
  22. package/components/dashboard/admin/{deviceThrottleTable.tsx → home/device-throttle-table.tsx} +3 -3
  23. package/components/dashboard/admin/{newDeviceCard.tsx → home/new-device-card.tsx} +6 -2
  24. package/components/dashboard/admin/{newDeviceTable.tsx → home/new-device-table.tsx} +4 -4
  25. package/components/dashboard/admin/{sharedDeviceCard.tsx → home/shared-device-card.tsx} +3 -3
  26. package/components/dashboard/admin/{sharedDeviceTable.tsx → home/shared-device-table.tsx} +3 -3
  27. package/components/dashboard/admin/{adminStatsGridSkeleton.tsx → home/skeletons/admin-stats-skeleton.tsx} +2 -2
  28. package/components/dashboard/admin/{broadcastActions.tsx → marketing/broadcast-actions.tsx} +3 -3
  29. package/components/dashboard/admin/{confirmSendDialog.tsx → marketing/confirm-send-dialog.tsx} +1 -1
  30. package/components/dashboard/admin/{marketingEmailForm.tsx → marketing/marketing-email-form.tsx} +7 -7
  31. package/components/dashboard/admin/{marketingSection.tsx → marketing/marketing-section.tsx} +6 -6
  32. package/components/dashboard/admin/{subscribersCard.tsx → marketing/subscribers-card.tsx} +3 -3
  33. package/components/dashboard/admin/{feedbackTestForm.tsx → system-settings/feedback-test-form.tsx} +4 -4
  34. package/components/dashboard/admin/{systemSettingsSkeleton.tsx → system-settings/skeletons/system-settings-skeleton.tsx} +2 -2
  35. package/components/dashboard/admin/system-settings/system-settings-form.tsx +362 -0
  36. package/components/dashboard/admin/{systemSettingsSection.tsx → system-settings/system-settings-section.tsx} +3 -2
  37. package/components/dashboard/admin/users/admin-user-actions.tsx +238 -0
  38. package/components/dashboard/admin/users/admin-user-profile-card.tsx +70 -0
  39. package/components/dashboard/admin/users/admin-user-security-card.tsx +47 -0
  40. package/components/dashboard/admin/users/admin-user-status-card.tsx +89 -0
  41. package/components/dashboard/admin/{adminUsersTable.tsx → users/admin-users-table.tsx} +129 -132
  42. package/components/dashboard/admin/{adminUserActivityLogCard.tsx → users/detail/admin-user-activity-log-card.tsx} +3 -3
  43. package/components/dashboard/admin/{adminUserActivityLogTable.tsx → users/detail/admin-user-activity-log-table.tsx} +3 -3
  44. package/components/dashboard/admin/{adminUserConsentCard.tsx → users/detail/admin-user-consent-card.tsx} +4 -4
  45. package/components/dashboard/admin/{adminUserDevicesCard.tsx → users/detail/admin-user-devices-card.tsx} +2 -2
  46. package/components/dashboard/admin/{adminUserLoginInfoCard.tsx → users/detail/admin-user-login-info-card.tsx} +3 -3
  47. package/components/dashboard/admin/{adminUserLoginInfoTable.tsx → users/detail/admin-user-login-info-table.tsx} +3 -3
  48. package/components/dashboard/admin/{adminUserSessionsCard.tsx → users/detail/admin-user-sessions-card.tsx} +5 -5
  49. package/components/dashboard/admin/{impersonationLogCard.tsx → users/impersonation-log-card.tsx} +10 -5
  50. package/components/dashboard/admin/users/impersonation-tab.tsx +255 -0
  51. package/components/dashboard/admin/users/invite-user-dialog.tsx +80 -0
  52. package/components/dashboard/admin/{revokeAllSessionsButton.tsx → users/revoke-all-sessions.tsx} +5 -3
  53. package/components/dashboard/admin/{adminUsersSkeleton.tsx → users/skeletons/admin-users-skeleton.tsx} +2 -2
  54. package/components/dashboard/admin/{usersSection.tsx → users/users-section.tsx} +1 -1
  55. package/components/dashboard/{errorFeedback.tsx → common/error-feedback.tsx} +1 -1
  56. package/components/dashboard/{feedbackDialog.tsx → common/feedback-dialog.tsx} +4 -4
  57. package/components/dashboard/{sectionErrorFallback.tsx → common/section-error-fallback.tsx} +1 -1
  58. package/components/dashboard/{verifyEmailButton.tsx → common/verify-email-button.tsx} +2 -2
  59. package/components/dashboard/{appSidebar.tsx → layout/app-sidebar.tsx} +11 -8
  60. package/components/dashboard/{dashboardHeader.tsx → layout/dashboard-header.tsx} +1 -1
  61. package/components/dashboard/{impersonationBanner.tsx → layout/impersonation-banner.tsx} +2 -2
  62. package/components/dashboard/layout/mobile-nav.tsx +95 -0
  63. package/components/dashboard/{navStyleToggle.tsx → layout/nav-style-toggle.tsx} +1 -1
  64. package/components/dashboard/{topNav.tsx → layout/top-nav.tsx} +19 -38
  65. package/components/dashboard/{installAppCard.tsx → overview/install-app-card.tsx} +2 -2
  66. package/components/dashboard/{accountDetailsCard.tsx → settings/account-details-card.tsx} +5 -5
  67. package/components/dashboard/{activityLogsCard.tsx → settings/activity-logs-card.tsx} +6 -6
  68. package/components/dashboard/{activityLogsSection.tsx → settings/activity-logs-section.tsx} +1 -1
  69. package/components/dashboard/{adminSection.tsx → settings/admin-section.tsx} +2 -2
  70. package/components/dashboard/{deleteAccountCard.tsx → settings/delete-account-card.tsx} +7 -7
  71. package/components/dashboard/{marketingUpdatesCard.tsx → settings/marketing-updates-card.tsx} +3 -3
  72. package/components/dashboard/{marketingUpdatesSection.tsx → settings/marketing-updates-section.tsx} +1 -1
  73. package/components/dashboard/{passkeysCard.tsx → settings/passkeys-card.tsx} +8 -8
  74. package/components/dashboard/{profileCard.tsx → settings/profile-card.tsx} +4 -4
  75. package/components/dashboard/{sessionsCard.tsx → settings/sessions/sessions-card.tsx} +6 -6
  76. package/components/dashboard/{sessionsSection.tsx → settings/sessions/sessions-section.tsx} +1 -1
  77. package/components/dashboard/{sessionsCardSkeleton.tsx → settings/sessions/skeletons/sessions-card-skeleton.tsx} +2 -2
  78. package/components/dashboard/{activityLogsCardSkeleton.tsx → settings/skeletons/activity-logs-card-skeleton.tsx} +2 -2
  79. package/components/dashboard/{twoFactorCard.tsx → settings/two-factor-card.tsx} +8 -8
  80. package/components/email/team/workspace-invite.tsx +51 -0
  81. package/components/email/{send-email-button.tsx → ui/send-email-button.tsx} +1 -1
  82. package/components/error-boundary.tsx +32 -0
  83. package/components/settings/appearance/appearance-section.tsx +64 -0
  84. package/components/settings/index.ts +5 -0
  85. package/components/settings/notifications/notifications-section.tsx +31 -0
  86. package/components/settings/profile/profile-section.tsx +38 -0
  87. package/components/settings/security/security-section.tsx +24 -0
  88. package/components/settings/settings-nav.tsx +35 -0
  89. package/components/site/{cookie-banner.tsx → compliance/cookie-banner.tsx} +6 -6
  90. package/components/site/push/push-notifications-card.tsx +117 -0
  91. package/components/ui/collapsible.tsx +9 -0
  92. package/components/ui/column-picker.tsx +1 -1
  93. package/components/ui/data-table.tsx +1 -1
  94. package/components/ui/dialog.tsx +46 -13
  95. package/components/ui/drawer.tsx +88 -0
  96. package/components/ui/tabs.tsx +52 -0
  97. package/dist/activity/logger.d.mts +2 -1
  98. package/dist/activity/logger.d.ts +2 -1
  99. package/dist/activity/logger.js +66 -15
  100. package/dist/activity/logger.js.map +1 -1
  101. package/dist/activity/logger.mjs +4 -4
  102. package/dist/activity/queries.d.mts +32 -21
  103. package/dist/activity/queries.d.ts +32 -21
  104. package/dist/activity/queries.js +86 -22
  105. package/dist/activity/queries.js.map +1 -1
  106. package/dist/activity/queries.mjs +27 -14
  107. package/dist/activity/queries.mjs.map +1 -1
  108. package/dist/admin/queries.d.mts +2 -1
  109. package/dist/admin/queries.d.ts +2 -1
  110. package/dist/admin/queries.js +48 -17
  111. package/dist/admin/queries.js.map +1 -1
  112. package/dist/admin/queries.mjs +9 -9
  113. package/dist/admin/queries.mjs.map +1 -1
  114. package/dist/api/feedback.js +302 -248
  115. package/dist/api/feedback.js.map +1 -1
  116. package/dist/api/feedback.mjs +14 -12
  117. package/dist/api/feedback.mjs.map +1 -1
  118. package/dist/api/marketing.js +320 -266
  119. package/dist/api/marketing.js.map +1 -1
  120. package/dist/api/marketing.mjs +16 -25
  121. package/dist/api/marketing.mjs.map +1 -1
  122. package/dist/auth/helpers.d.mts +60 -18
  123. package/dist/auth/helpers.d.ts +60 -18
  124. package/dist/auth/helpers.js +332 -267
  125. package/dist/auth/helpers.js.map +1 -1
  126. package/dist/auth/helpers.mjs +9 -9
  127. package/dist/auth/index.d.mts +86 -47
  128. package/dist/auth/index.d.ts +86 -47
  129. package/dist/auth/index.js +296 -244
  130. package/dist/auth/index.js.map +1 -1
  131. package/dist/auth/index.mjs +8 -8
  132. package/dist/auth-client/index.d.mts +1215 -2527
  133. package/dist/auth-client/index.d.ts +1215 -2527
  134. package/dist/auth-client/index.js +37 -3
  135. package/dist/auth-client/index.js.map +1 -1
  136. package/dist/auth-client/index.mjs +19 -3
  137. package/dist/auth-client/index.mjs.map +1 -1
  138. package/dist/{chunk-TE5BEAQB.mjs → chunk-3BH6BVBQ.mjs} +17 -7
  139. package/dist/chunk-3BH6BVBQ.mjs.map +1 -0
  140. package/dist/chunk-D56ENLSX.mjs +6 -0
  141. package/dist/chunk-D56ENLSX.mjs.map +1 -0
  142. package/dist/{chunk-HUEDEAY3.mjs → chunk-DCPVEZS7.mjs} +14 -4
  143. package/dist/chunk-DCPVEZS7.mjs.map +1 -0
  144. package/dist/{chunk-NQELV53D.mjs → chunk-DWLMCMXF.mjs} +4 -4
  145. package/dist/chunk-DWLMCMXF.mjs.map +1 -0
  146. package/dist/{chunk-653GF7OT.mjs → chunk-EXMUANQ3.mjs} +4 -4
  147. package/dist/chunk-EXMUANQ3.mjs.map +1 -0
  148. package/dist/chunk-LADVCLEQ.mjs +43 -0
  149. package/dist/chunk-LADVCLEQ.mjs.map +1 -0
  150. package/dist/{chunk-2BJ3B4FR.mjs → chunk-NJBRKKLK.mjs} +46 -7
  151. package/dist/chunk-NJBRKKLK.mjs.map +1 -0
  152. package/dist/{chunk-6OAHCEDJ.mjs → chunk-QDUPSU5O.mjs} +5 -5
  153. package/dist/chunk-QDUPSU5O.mjs.map +1 -0
  154. package/dist/{chunk-H3XZTZ5K.mjs → chunk-RK2B5AOQ.mjs} +41 -29
  155. package/dist/chunk-RK2B5AOQ.mjs.map +1 -0
  156. package/dist/{chunk-L242CZ64.mjs → chunk-TIR7KHXL.mjs} +3 -3
  157. package/dist/chunk-TIR7KHXL.mjs.map +1 -0
  158. package/dist/{chunk-O5EQYHNC.mjs → chunk-ZOQHHFYA.mjs} +7 -4
  159. package/dist/chunk-ZOQHHFYA.mjs.map +1 -0
  160. package/dist/{chunk-EIS4SCQW.mjs → chunk-ZQTI4T2K.mjs} +231 -220
  161. package/dist/chunk-ZQTI4T2K.mjs.map +1 -0
  162. package/dist/config/env.d.mts +3 -0
  163. package/dist/config/env.d.ts +3 -0
  164. package/dist/config/env.js +12 -2
  165. package/dist/config/env.js.map +1 -1
  166. package/dist/config/env.mjs +1 -1
  167. package/dist/db/index.d.mts +3 -7
  168. package/dist/db/index.d.ts +3 -7
  169. package/dist/db/index.js +61 -12
  170. package/dist/db/index.js.map +1 -1
  171. package/dist/db/index.mjs +3 -3
  172. package/dist/db/schema.d.mts +1 -1
  173. package/dist/db/schema.d.ts +1 -1
  174. package/dist/db/schema.js +14 -4
  175. package/dist/db/schema.js.map +1 -1
  176. package/dist/db/schema.mjs +1 -1
  177. package/dist/errors.d.mts +2 -1
  178. package/dist/errors.d.ts +2 -1
  179. package/dist/errors.js +62 -13
  180. package/dist/errors.js.map +1 -1
  181. package/dist/errors.mjs +4 -4
  182. package/dist/marketing/index.d.mts +4 -3
  183. package/dist/marketing/index.d.ts +4 -3
  184. package/dist/marketing/index.js +14 -4
  185. package/dist/marketing/index.js.map +1 -1
  186. package/dist/marketing/index.mjs +3 -3
  187. package/dist/{email-template-passkey-change-F5Q2SXHD.mjs → passkey-changed-KEGNTIPE.mjs} +2 -2
  188. package/dist/passkey-changed-KEGNTIPE.mjs.map +1 -0
  189. package/dist/{email-template-reset-password-QTCQNXOD.mjs → reset-password-64VQEXBW.mjs} +2 -2
  190. package/dist/reset-password-64VQEXBW.mjs.map +1 -0
  191. package/dist/{schema-DzC5zdOq.d.mts → schema-BujGgvAy.d.mts} +35 -2
  192. package/dist/{schema-DzC5zdOq.d.ts → schema-BujGgvAy.d.ts} +35 -2
  193. package/dist/sessions/queries.js +61 -12
  194. package/dist/sessions/queries.js.map +1 -1
  195. package/dist/sessions/queries.mjs +3 -3
  196. package/dist/sessions/queries.mjs.map +1 -1
  197. package/dist/settings/queries.d.mts +11 -2
  198. package/dist/settings/queries.d.ts +11 -2
  199. package/dist/settings/queries.js +84 -13
  200. package/dist/settings/queries.js.map +1 -1
  201. package/dist/settings/queries.mjs +4 -4
  202. package/dist/users/queries.d.mts +41 -21
  203. package/dist/users/queries.d.ts +41 -21
  204. package/dist/users/queries.js +117 -23
  205. package/dist/users/queries.js.map +1 -1
  206. package/dist/users/queries.mjs +57 -17
  207. package/dist/users/queries.mjs.map +1 -1
  208. package/dist/{email-template-verify-email-WZDCCAKK.mjs → verify-email-4KMNGDKN.mjs} +2 -2
  209. package/dist/verify-email-4KMNGDKN.mjs.map +1 -0
  210. package/lib/{auth-client.ts → auth/client.ts} +22 -2
  211. package/lib/push/client.ts +39 -0
  212. package/lib/security/activity-severity.ts +57 -0
  213. package/lib/{request-info.ts → utils/request-info.ts} +7 -3
  214. package/package.json +177 -75
  215. package/scripts/check-deps.mjs +68 -0
  216. package/components/dashboard/admin/adminActivityLogsTable.tsx +0 -323
  217. package/components/dashboard/admin/adminUserStatusCard.tsx +0 -57
  218. package/components/dashboard/admin/systemSettingsForm.tsx +0 -289
  219. package/dist/chunk-2BJ3B4FR.mjs.map +0 -1
  220. package/dist/chunk-653GF7OT.mjs.map +0 -1
  221. package/dist/chunk-6OAHCEDJ.mjs.map +0 -1
  222. package/dist/chunk-EIS4SCQW.mjs.map +0 -1
  223. package/dist/chunk-H3XZTZ5K.mjs.map +0 -1
  224. package/dist/chunk-HUEDEAY3.mjs.map +0 -1
  225. package/dist/chunk-K62JYJRR.mjs +0 -30
  226. package/dist/chunk-K62JYJRR.mjs.map +0 -1
  227. package/dist/chunk-L242CZ64.mjs.map +0 -1
  228. package/dist/chunk-NQELV53D.mjs.map +0 -1
  229. package/dist/chunk-O5EQYHNC.mjs.map +0 -1
  230. package/dist/chunk-TE5BEAQB.mjs.map +0 -1
  231. package/dist/email-template-passkey-change-F5Q2SXHD.mjs.map +0 -1
  232. package/dist/email-template-reset-password-QTCQNXOD.mjs.map +0 -1
  233. package/dist/email-template-verify-email-WZDCCAKK.mjs.map +0 -1
  234. /package/components/dashboard/{heartbeat.tsx → common/heartbeat.tsx} +0 -0
  235. /package/components/email/{email-template-reset-password.tsx → auth/reset-password.tsx} +0 -0
  236. /package/components/email/{email-template-verify-email.tsx → auth/verify-email.tsx} +0 -0
  237. /package/components/email/{email-template-welcome.tsx → auth/welcome.tsx} +0 -0
  238. /package/components/email/{email-template.tsx → layout/base-layout.tsx} +0 -0
  239. /package/components/email/{email-template-2.tsx → marketing/general-announcement.tsx} +0 -0
  240. /package/components/email/{email-template-banned.tsx → security/account-banned.tsx} +0 -0
  241. /package/components/email/{email-template-new-device.tsx → security/new-device-alert.tsx} +0 -0
  242. /package/components/email/{email-template-passkey-change.tsx → security/passkey-changed.tsx} +0 -0
  243. /package/lib/{maintenance.ts → config/maintenance.ts} +0 -0
  244. /package/lib/{cookie-consent.ts → security/cookie-consent.ts} +0 -0
  245. /package/lib/{cookie-names.ts → security/cookie-names.ts} +0 -0
  246. /package/lib/{device-fingerprint.ts → security/device-fingerprint.ts} +0 -0
  247. /package/lib/{formatters.ts → utils/formatters.ts} +0 -0
  248. /package/lib/{recalculate-columns.ts → utils/recalculate-columns.ts} +0 -0
@@ -5,18 +5,18 @@ import { useEffect, useState } from "react"
5
5
 
6
6
  // Relative imports: this file ships raw in the npm package, where `@/` would
7
7
  // resolve against the consuming project instead.
8
- import { Button } from "../ui/button"
9
- import { Checkbox } from "../ui/checkbox"
10
- import { Label } from "../ui/label"
8
+ import { Button } from "../../ui/button"
9
+ import { Checkbox } from "../../ui/checkbox"
10
+ import { Label } from "../../ui/label"
11
11
  import {
12
12
  readConsent,
13
13
  setCookieConsent,
14
14
  useConsentRequired,
15
15
  useCookieConsent,
16
16
  type ConsentPurpose,
17
- } from "../../lib/cookie-consent"
18
- import { CONSENT_VERSION } from "../../lib/cookie-names"
19
- import { useSession } from "../../lib/auth-client"
17
+ } from "../../../lib/security/cookie-consent"
18
+ import { CONSENT_VERSION } from "../../../lib/security/cookie-names"
19
+ import { useSession } from "../../../lib/auth/client"
20
20
 
21
21
  // Last choice sent to app/api/consent from this browser, as
22
22
  // "userId|choice|version", so each choice is recorded once, not on every load.
@@ -0,0 +1,117 @@
1
+ 'use client'
2
+
3
+ import { useEffect, useState } from 'react'
4
+ import { toast } from 'sonner'
5
+ import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '../../ui/card'
6
+ import { Switch } from '../../ui/switch'
7
+ import { Label } from '../../ui/label'
8
+ import { Button } from '../../ui/button'
9
+ import {
10
+ PUSH_FLAG,
11
+ getRegistration,
12
+ pushSupported,
13
+ saveSubscription,
14
+ subscribe,
15
+ } from '../../../lib/push/client'
16
+
17
+ type State = 'loading' | 'unsupported' | 'no-worker' | 'denied' | 'off' | 'on'
18
+
19
+ // Example: turn push notifications on or off for this device and send a test.
20
+ // Hidden unless the VAPID keys are set (see .env.development.example).
21
+ export default function PushNotificationsCard() {
22
+ const [publicKey, setPublicKey] = useState('')
23
+ const [state, setState] = useState<State>('loading')
24
+ const [busy, setBusy] = useState(false)
25
+
26
+ useEffect(() => {
27
+ ; (async () => {
28
+ const res = await fetch('/api/push')
29
+ if (res.ok) setPublicKey((await res.json()).publicKey ?? '')
30
+ if (!pushSupported()) return setState('unsupported')
31
+ const reg = await getRegistration()
32
+ if (!reg) return setState('no-worker')
33
+ if (Notification.permission === 'denied') return setState('denied')
34
+ setState((await reg.pushManager.getSubscription()) ? 'on' : 'off')
35
+ })().catch(() => setState('unsupported'))
36
+ }, [])
37
+
38
+ if (!publicKey) return null
39
+
40
+ async function toggle(next: boolean) {
41
+ setBusy(true)
42
+ try {
43
+ const reg = await getRegistration()
44
+ if (!reg) throw new Error('Service worker not registered')
45
+ if (next) {
46
+ if ((await Notification.requestPermission()) !== 'granted') return setState('denied')
47
+ const res = await saveSubscription(await subscribe(reg, publicKey))
48
+ if (!res.ok) throw new Error((await res.json()).error || 'Failed to save subscription')
49
+ localStorage.setItem(PUSH_FLAG, '1')
50
+ setState('on')
51
+ } else {
52
+ localStorage.removeItem(PUSH_FLAG)
53
+ const sub = await reg.pushManager.getSubscription()
54
+ if (sub) {
55
+ await fetch('/api/push', {
56
+ method: 'DELETE',
57
+ headers: { 'Content-Type': 'application/json' },
58
+ body: JSON.stringify({ endpoint: sub.endpoint }),
59
+ })
60
+ await sub.unsubscribe()
61
+ }
62
+ setState('off')
63
+ }
64
+ } catch (e) {
65
+ toast.error(e instanceof Error ? e.message : 'Something went wrong')
66
+ } finally {
67
+ setBusy(false)
68
+ }
69
+ }
70
+
71
+ async function sendTest() {
72
+ setBusy(true)
73
+ try {
74
+ const res = await fetch('/api/push/test', { method: 'POST' })
75
+ const data = await res.json()
76
+ if (!res.ok) throw new Error(data.error || 'Failed to send')
77
+ if (!data.sent) toast.error('No active device found. Turn notifications off and on again.')
78
+ } catch (e) {
79
+ toast.error(e instanceof Error ? e.message : 'Failed to send')
80
+ } finally {
81
+ setBusy(false)
82
+ }
83
+ }
84
+
85
+ const note: Partial<Record<State, string>> = {
86
+ unsupported:
87
+ "This browser can't receive push notifications. On iPhone and iPad, install the app to your Home Screen first (see below), then open it from there.",
88
+ 'no-worker': 'Notifications are only available in production builds (bun run build && bun run start).',
89
+ denied: 'Notifications are blocked for this site. Allow them in your browser or system settings, then reload.',
90
+ }
91
+
92
+ return (
93
+ <Card>
94
+ <CardHeader>
95
+ <CardTitle>Push notifications</CardTitle>
96
+ <CardDescription>Get notified on this device, even when the app is closed.</CardDescription>
97
+ </CardHeader>
98
+ <CardContent className="space-y-3">
99
+ <div className="flex items-center justify-between gap-4">
100
+ <Label htmlFor="push-notifications">Notify me on this device</Label>
101
+ <Switch
102
+ id="push-notifications"
103
+ checked={state === 'on'}
104
+ disabled={busy || (state !== 'on' && state !== 'off')}
105
+ onCheckedChange={toggle}
106
+ />
107
+ </div>
108
+ {note[state] && <p className="text-sm text-muted-foreground">{note[state]}</p>}
109
+ {state === 'on' && (
110
+ <Button variant="outline" size="sm" disabled={busy} onClick={sendTest}>
111
+ Send test notification
112
+ </Button>
113
+ )}
114
+ </CardContent>
115
+ </Card>
116
+ )
117
+ }
@@ -0,0 +1,9 @@
1
+ "use client"
2
+
3
+ import { Collapsible as CollapsiblePrimitive } from "radix-ui"
4
+
5
+ const Collapsible = CollapsiblePrimitive.Root
6
+ const CollapsibleTrigger = CollapsiblePrimitive.Trigger
7
+ const CollapsibleContent = CollapsiblePrimitive.Content
8
+
9
+ export { Collapsible, CollapsibleTrigger, CollapsibleContent }
@@ -13,7 +13,7 @@ import {
13
13
  DropdownMenuSeparator,
14
14
  DropdownMenuTrigger,
15
15
  } from "./dropdown-menu"
16
- import type { Column } from "../../lib/recalculate-columns"
16
+ import type { Column } from "../../lib/utils/recalculate-columns"
17
17
 
18
18
  // Lets an app switch every table's "Columns" menu on/off in one place (e.g. from a feature flag).
19
19
  const ColumnPickerContext = React.createContext(true)
@@ -12,7 +12,7 @@ import {
12
12
  STICKY_BREAKPOINT,
13
13
  recalculateColumns,
14
14
  type Column,
15
- } from "../../lib/recalculate-columns"
15
+ } from "../../lib/utils/recalculate-columns"
16
16
  import {
17
17
  TableBody,
18
18
  TableCell,
@@ -3,39 +3,57 @@
3
3
  import * as React from "react"
4
4
  import { Dialog as DialogPrimitive } from "radix-ui"
5
5
  import { XIcon } from "lucide-react"
6
+ import { Drawer } from "vaul"
6
7
 
8
+ import { useIsMobile } from "../../hooks/use-mobile"
7
9
  import { cn } from "../../lib/utils"
8
10
 
11
+ // Below 768px (useIsMobile) the dialog renders as a vaul drawer: bottom sheet with a
12
+ // grab handle and swipe-down-to-dismiss. vaul has its own Radix instance, so every
13
+ // part must come from the same primitive set; the root picks it and shares it via context.
14
+ const MobileContext = React.createContext(false)
15
+ const usePrimitive = () => (React.useContext(MobileContext) ? Drawer : DialogPrimitive)
16
+
9
17
  function Dialog({
10
18
  ...props
11
19
  }: React.ComponentProps<typeof DialogPrimitive.Root>) {
12
- return <DialogPrimitive.Root data-slot="dialog" {...props} />
20
+ const isMobile = useIsMobile()
21
+ const Root = isMobile ? Drawer.Root : DialogPrimitive.Root
22
+ return (
23
+ <MobileContext.Provider value={isMobile}>
24
+ <Root data-slot="dialog" {...props} />
25
+ </MobileContext.Provider>
26
+ )
13
27
  }
14
28
 
15
29
  function DialogTrigger({
16
30
  ...props
17
31
  }: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
18
- return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
32
+ const P = usePrimitive()
33
+ return <P.Trigger data-slot="dialog-trigger" {...props} />
19
34
  }
20
35
 
21
36
  function DialogPortal({
22
37
  ...props
23
38
  }: React.ComponentProps<typeof DialogPrimitive.Portal>) {
24
- return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
39
+ const P = usePrimitive()
40
+ return <P.Portal data-slot="dialog-portal" {...props} />
25
41
  }
26
42
 
27
43
  function DialogClose({
28
44
  ...props
29
45
  }: React.ComponentProps<typeof DialogPrimitive.Close>) {
30
- return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
46
+ const P = usePrimitive()
47
+ return <P.Close data-slot="dialog-close" {...props} />
31
48
  }
32
49
 
33
50
  function DialogOverlay({
34
51
  className,
35
52
  ...props
36
53
  }: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
54
+ const P = usePrimitive()
37
55
  return (
38
- <DialogPrimitive.Overlay
56
+ <P.Overlay
39
57
  data-slot="dialog-overlay"
40
58
  className={cn(
41
59
  "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
@@ -54,28 +72,41 @@ function DialogContent({
54
72
  }: React.ComponentProps<typeof DialogPrimitive.Content> & {
55
73
  showCloseButton?: boolean
56
74
  }) {
75
+ const isMobile = React.useContext(MobileContext)
76
+ const P = usePrimitive()
57
77
  return (
58
78
  <DialogPortal data-slot="dialog-portal">
59
79
  <DialogOverlay />
60
- <DialogPrimitive.Content
80
+ <P.Content
61
81
  data-slot="dialog-content"
62
82
  className={cn(
63
- "bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border-(length:--surface-border-width) border-(--surface-border-color) p-6 shadow-(--dialog-shadow) duration-200 sm:max-w-lg",
83
+ "bg-background fixed z-50 grid gap-4 border-(length:--surface-border-width) border-(--surface-border-color) p-6 shadow-(--dialog-shadow)",
84
+ isMobile
85
+ ? "flex flex-col inset-x-0 bottom-0 max-h-[90dvh] rounded-t-xl pb-[max(1.5rem,env(safe-area-inset-bottom))]"
86
+ : "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 top-[50%] left-[50%] max-h-[calc(100dvh-2rem)] w-full max-w-[calc(100%-2rem)] overflow-y-auto translate-x-[-50%] translate-y-[-50%] rounded-lg duration-200 sm:max-w-lg",
64
87
  className
65
88
  )}
66
89
  {...props}
67
90
  >
68
- {children}
91
+ {isMobile && (
92
+ <div aria-hidden className="bg-muted-foreground/30 mx-auto -mt-2 h-1.5 w-12 shrink-0 rounded-full" />
93
+ )}
94
+ {isMobile ? (
95
+ // Only this wrapper scrolls, and only when the content is taller than the drawer.
96
+ <div className="grid min-h-0 gap-4 overflow-y-auto overscroll-contain">{children}</div>
97
+ ) : (
98
+ children
99
+ )}
69
100
  {showCloseButton && (
70
- <DialogPrimitive.Close
101
+ <P.Close
71
102
  data-slot="dialog-close"
72
103
  className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
73
104
  >
74
105
  <XIcon />
75
106
  <span className="sr-only">Close</span>
76
- </DialogPrimitive.Close>
107
+ </P.Close>
77
108
  )}
78
- </DialogPrimitive.Content>
109
+ </P.Content>
79
110
  </DialogPortal>
80
111
  )
81
112
  }
@@ -107,8 +138,9 @@ function DialogTitle({
107
138
  className,
108
139
  ...props
109
140
  }: React.ComponentProps<typeof DialogPrimitive.Title>) {
141
+ const P = usePrimitive()
110
142
  return (
111
- <DialogPrimitive.Title
143
+ <P.Title
112
144
  data-slot="dialog-title"
113
145
  className={cn("text-lg leading-none font-semibold", className)}
114
146
  {...props}
@@ -120,8 +152,9 @@ function DialogDescription({
120
152
  className,
121
153
  ...props
122
154
  }: React.ComponentProps<typeof DialogPrimitive.Description>) {
155
+ const P = usePrimitive()
123
156
  return (
124
- <DialogPrimitive.Description
157
+ <P.Description
125
158
  data-slot="dialog-description"
126
159
  className={cn("text-muted-foreground text-sm", className)}
127
160
  {...props}
@@ -0,0 +1,88 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { Drawer as DrawerPrimitive } from "vaul"
5
+
6
+ import { cn } from "../../lib/utils"
7
+
8
+ function Drawer({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Root>) {
9
+ return <DrawerPrimitive.Root data-slot="drawer" {...props} />
10
+ }
11
+
12
+ function DrawerTrigger({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Trigger>) {
13
+ return <DrawerPrimitive.Trigger data-slot="drawer-trigger" {...props} />
14
+ }
15
+
16
+ function DrawerPortal({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Portal>) {
17
+ return <DrawerPrimitive.Portal data-slot="drawer-portal" {...props} />
18
+ }
19
+
20
+ function DrawerClose({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Close>) {
21
+ return <DrawerPrimitive.Close data-slot="drawer-close" {...props} />
22
+ }
23
+
24
+ function DrawerOverlay({ className, ...props }: React.ComponentProps<typeof DrawerPrimitive.Overlay>) {
25
+ return (
26
+ <DrawerPrimitive.Overlay
27
+ data-slot="drawer-overlay"
28
+ className={cn("fixed inset-0 z-50 bg-black/50", className)}
29
+ {...props}
30
+ />
31
+ )
32
+ }
33
+
34
+ // Bottom sheet by default; pass direction="top|left|right" on <Drawer> for other edges.
35
+ function DrawerContent({ className, children, ...props }: React.ComponentProps<typeof DrawerPrimitive.Content>) {
36
+ return (
37
+ <DrawerPortal>
38
+ <DrawerOverlay />
39
+ <DrawerPrimitive.Content
40
+ data-slot="drawer-content"
41
+ className={cn(
42
+ "group/drawer-content bg-background fixed z-50 flex h-auto flex-col border-(length:--surface-border-width) border-(--surface-border-color)",
43
+ "data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[90dvh] data-[vaul-drawer-direction=bottom]:rounded-t-xl data-[vaul-drawer-direction=bottom]:pb-[env(safe-area-inset-bottom)]",
44
+ "data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[90dvh] data-[vaul-drawer-direction=top]:rounded-b-xl",
45
+ "data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:right-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=right]:sm:max-w-sm",
46
+ "data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:left-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=left]:sm:max-w-sm",
47
+ className
48
+ )}
49
+ {...props}
50
+ >
51
+ <div
52
+ aria-hidden
53
+ className="bg-muted-foreground/30 mx-auto mt-4 hidden h-1.5 w-12 shrink-0 rounded-full group-data-[vaul-drawer-direction=bottom]/drawer-content:block"
54
+ />
55
+ {children}
56
+ </DrawerPrimitive.Content>
57
+ </DrawerPortal>
58
+ )
59
+ }
60
+
61
+ function DrawerHeader({ className, ...props }: React.ComponentProps<"div">) {
62
+ return <div data-slot="drawer-header" className={cn("flex flex-col gap-1.5 p-4", className)} {...props} />
63
+ }
64
+
65
+ function DrawerFooter({ className, ...props }: React.ComponentProps<"div">) {
66
+ return <div data-slot="drawer-footer" className={cn("mt-auto flex flex-col gap-2 p-4", className)} {...props} />
67
+ }
68
+
69
+ function DrawerTitle({ className, ...props }: React.ComponentProps<typeof DrawerPrimitive.Title>) {
70
+ return <DrawerPrimitive.Title data-slot="drawer-title" className={cn("text-foreground font-semibold", className)} {...props} />
71
+ }
72
+
73
+ function DrawerDescription({ className, ...props }: React.ComponentProps<typeof DrawerPrimitive.Description>) {
74
+ return <DrawerPrimitive.Description data-slot="drawer-description" className={cn("text-muted-foreground text-sm", className)} {...props} />
75
+ }
76
+
77
+ export {
78
+ Drawer,
79
+ DrawerClose,
80
+ DrawerContent,
81
+ DrawerDescription,
82
+ DrawerFooter,
83
+ DrawerHeader,
84
+ DrawerOverlay,
85
+ DrawerPortal,
86
+ DrawerTitle,
87
+ DrawerTrigger,
88
+ }
@@ -0,0 +1,52 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { Tabs as TabsPrimitive } from "radix-ui"
5
+
6
+ import { cn } from "../../lib/utils"
7
+
8
+ const Tabs = TabsPrimitive.Root
9
+
10
+ const TabsList = React.forwardRef<
11
+ React.ElementRef<typeof TabsPrimitive.List>,
12
+ React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
13
+ >(({ className, ...props }, ref) => (
14
+ <TabsPrimitive.List
15
+ ref={ref}
16
+ className={cn(
17
+ "inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",
18
+ className
19
+ )}
20
+ {...props}
21
+ />
22
+ ))
23
+ TabsList.displayName = TabsPrimitive.List.displayName
24
+
25
+ const TabsTrigger = React.forwardRef<
26
+ React.ElementRef<typeof TabsPrimitive.Trigger>,
27
+ React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
28
+ >(({ className, ...props }, ref) => (
29
+ <TabsPrimitive.Trigger
30
+ ref={ref}
31
+ className={cn(
32
+ "inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",
33
+ className
34
+ )}
35
+ {...props}
36
+ />
37
+ ))
38
+ TabsTrigger.displayName = TabsPrimitive.Trigger.displayName
39
+
40
+ const TabsContent = React.forwardRef<
41
+ React.ElementRef<typeof TabsPrimitive.Content>,
42
+ React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
43
+ >(({ className, ...props }, ref) => (
44
+ <TabsPrimitive.Content
45
+ ref={ref}
46
+ className={cn("mt-4 focus-visible:outline-none", className)}
47
+ {...props}
48
+ />
49
+ ))
50
+ TabsContent.displayName = TabsPrimitive.Content.displayName
51
+
52
+ export { Tabs, TabsList, TabsTrigger, TabsContent }
@@ -17,4 +17,5 @@ interface LogActivityParams {
17
17
  type ActivityLogger = (entry: LogActivityParams) => Promise<void>;
18
18
  declare function logActivity({ userId, action, description, ipAddress, userAgent, metadata, referrerUrl, os, browser, deviceType, country, city, }: LogActivityParams): Promise<void>;
19
19
 
20
- export { type ActivityAction, type ActivityLogger, type LogActivityParams, logActivity };
20
+ export { logActivity };
21
+ export type { ActivityAction, ActivityLogger, LogActivityParams };
@@ -17,4 +17,5 @@ interface LogActivityParams {
17
17
  type ActivityLogger = (entry: LogActivityParams) => Promise<void>;
18
18
  declare function logActivity({ userId, action, description, ipAddress, userAgent, metadata, referrerUrl, os, browser, deviceType, country, city, }: LogActivityParams): Promise<void>;
19
19
 
20
- export { type ActivityAction, type ActivityLogger, type LogActivityParams, logActivity };
20
+ export { logActivity };
21
+ export type { ActivityAction, ActivityLogger, LogActivityParams };
@@ -1,16 +1,34 @@
1
1
  'use strict';
2
2
 
3
3
  require('server-only');
4
+ var drizzleOrm = require('drizzle-orm');
4
5
  var serverless = require('@neondatabase/serverless');
5
6
  var neonHttp = require('drizzle-orm/neon-http');
6
7
  var nodePostgres = require('drizzle-orm/node-postgres');
7
8
  var pg = require('pg');
8
9
  var pgCore = require('drizzle-orm/pg-core');
9
- var drizzleOrm = require('drizzle-orm');
10
10
  var cuid2 = require('@paralleldrive/cuid2');
11
11
  var zod = require('zod');
12
12
 
13
13
  var __defProp = Object.defineProperty;
14
+ var __defProps = Object.defineProperties;
15
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
16
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
17
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
18
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
19
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
20
+ var __spreadValues = (a, b) => {
21
+ for (var prop in b || (b = {}))
22
+ if (__hasOwnProp.call(b, prop))
23
+ __defNormalProp(a, prop, b[prop]);
24
+ if (__getOwnPropSymbols)
25
+ for (var prop of __getOwnPropSymbols(b)) {
26
+ if (__propIsEnum.call(b, prop))
27
+ __defNormalProp(a, prop, b[prop]);
28
+ }
29
+ return a;
30
+ };
31
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
14
32
  var __export = (target, all) => {
15
33
  for (var name in all)
16
34
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -36,7 +54,7 @@ __export(schema_exports, {
36
54
  verifications: () => verifications
37
55
  });
38
56
 
39
- // lib/maintenance.ts
57
+ // lib/config/maintenance.ts
40
58
  var DEFAULT_MAINTENANCE_EXEMPT_PATHS = [
41
59
  "/",
42
60
  "/features",
@@ -103,7 +121,10 @@ var sessions = pgCore.pgTable("session", {
103
121
  // Set by better-auth's admin plugin while this session is an admin
104
122
  // impersonating another user; holds the impersonating admin's user id.
105
123
  impersonatedBy: pgCore.text("impersonatedBy")
106
- });
124
+ }, (table) => [
125
+ // Read by userId on every login (session count), ban/delete and the admin sessions view.
126
+ pgCore.index("session_user_idx").on(table.userId)
127
+ ]);
107
128
  var accounts = pgCore.pgTable("account", {
108
129
  id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
109
130
  accountId: pgCore.text("accountId").notNull(),
@@ -152,7 +173,10 @@ var verifications = pgCore.pgTable("verification", {
152
173
  });
153
174
  var activityLogs = pgCore.pgTable("activity_log", {
154
175
  id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
155
- userId: pgCore.text("userId").notNull().references(() => users.id, { onDelete: "cascade" }),
176
+ // SET NULL, not cascade: deleting an admin must not erase the audit trail of
177
+ // what they did. actorEmail keeps who it was once the user row is gone.
178
+ userId: pgCore.text("userId").references(() => users.id, { onDelete: "set null" }),
179
+ actorEmail: pgCore.text("actorEmail"),
156
180
  action: ActivityActionEnum("action").notNull(),
157
181
  description: pgCore.text("description").notNull(),
158
182
  ipAddress: pgCore.text("ipAddress"),
@@ -168,7 +192,11 @@ var activityLogs = pgCore.pgTable("activity_log", {
168
192
  country: pgCore.text("country"),
169
193
  city: pgCore.text("city"),
170
194
  createdAt: pgCore.timestamp("createdAt").notNull().defaultNow()
171
- });
195
+ }, (table) => [
196
+ // Per-user history, and the admin log's newest-first ordering.
197
+ pgCore.index("activity_log_user_created_idx").on(table.userId, table.createdAt),
198
+ pgCore.index("activity_log_created_idx").on(table.createdAt)
199
+ ]);
172
200
  var deviceFingerprints = pgCore.pgTable("device_fingerprint", {
173
201
  id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
174
202
  userId: pgCore.text("userId").notNull().references(() => users.id, { onDelete: "cascade" }),
@@ -283,7 +311,9 @@ var envSchema = zod.z.object({
283
311
  RESEND_MARKETING_SEGMENT_ID: zod.z.string().default(""),
284
312
  // Sender for every transactional email. Must be on a domain verified in
285
313
  // your Resend account.
286
- EMAIL_FROM: zod.z.string().default("Acme <onboarding@xavierkhew.xyz>"),
314
+ // Resend's shared sandbox sender: works without a verified domain but only
315
+ // delivers to your own Resend account email. Set your verified domain for real use.
316
+ EMAIL_FROM: zod.z.string().default("Acme <onboarding@resend.dev>"),
287
317
  // Display name for this deployment — shown as the authenticator-app label
288
318
  // (2FA issuer) and the passkey relying-party name. Consuming projects set
289
319
  // this in their own .env; defaults to the template name.
@@ -293,6 +323,9 @@ var envSchema = zod.z.object({
293
323
  // a comma-separated list and sends through Resend (needs RESEND_API_KEY).
294
324
  FEEDBACK_DISCORD_WEBHOOK_URL: zod.z.string().default(""),
295
325
  FEEDBACK_EMAIL: zod.z.string().default(""),
326
+ // Seconds between feedback messages per user (default 30, 0 = off). Read
327
+ // straight from process.env in lib/feedback/route.ts; listed here for docs.
328
+ FEEDBACK_COOLDOWN_SECONDS: zod.z.string().default("30"),
296
329
  // Web Push (example, see lib/push.ts). Generate keys with
297
330
  // `bunx web-push generate-vapid-keys`. Blank = the notifications card is hidden.
298
331
  // The public key is also read in the browser as NEXT_PUBLIC_VAPID_PUBLIC_KEY.
@@ -309,7 +342,12 @@ var envSchema = zod.z.object({
309
342
  DB_DRIVER: zod.z.enum(["pg", "neon"]).default("pg"),
310
343
  // Only relevant when DB_DRIVER=pg — whether the target Postgres server has SSL
311
344
  // enabled. Self-hosted Postgres (e.g. via Docker/Dokploy) typically does not.
312
- DATABASE_SSL: zod.z.string().default("false").transform((val) => val === "true")
345
+ DATABASE_SSL: zod.z.string().default("false").transform((val) => val === "true"),
346
+ // With DATABASE_SSL=true the server certificate is verified. Set the CA (PEM,
347
+ // "\n" for newlines) for a self-signed or private CA; DATABASE_SSL_INSECURE=true
348
+ // skips verification (encrypts only). Both are read in config/pg-ssl.ts.
349
+ DATABASE_SSL_CA: zod.z.string().default(""),
350
+ DATABASE_SSL_INSECURE: zod.z.string().default("false")
313
351
  });
314
352
 
315
353
  // config/env.ts
@@ -323,27 +361,38 @@ if (!results.success) {
323
361
  }
324
362
  var config = results.data;
325
363
 
364
+ // config/pg-ssl.ts
365
+ function pgSslOptions() {
366
+ var _a;
367
+ if (process.env.DATABASE_SSL_INSECURE === "true") return { rejectUnauthorized: false };
368
+ const ca = (_a = process.env.DATABASE_SSL_CA) == null ? void 0 : _a.replace(/\\n/g, "\n");
369
+ return __spreadValues({ rejectUnauthorized: true }, ca ? { ca } : {});
370
+ }
371
+
326
372
  // server/db/index.ts
327
373
  var db;
328
374
  if (config.DB_DRIVER === "pg") {
329
375
  const pool = new pg.Pool({
330
376
  connectionString: config.DATABASE_URL,
331
- ssl: config.DATABASE_SSL ? { rejectUnauthorized: false } : void 0
377
+ ssl: config.DATABASE_SSL ? pgSslOptions() : void 0,
378
+ // pg waits forever by default; a hung DB would otherwise freeze every request (proxy reads settings).
379
+ connectionTimeoutMillis: 5e3,
380
+ query_timeout: 15e3
381
+ // roomy enough for the 10k-row exports
332
382
  });
333
383
  db = nodePostgres.drizzle(pool, {
334
384
  schema: schema_exports,
335
- logger: true
385
+ logger: process.env.NODE_ENV === "development"
336
386
  });
337
387
  console.log("\u{1F7E1} Using PostgreSQL (pg) driver");
338
- } else if (config.DB_DRIVER === "neon") {
339
- const sql2 = serverless.neon(config.DATABASE_URL);
340
- db = neonHttp.drizzle(sql2, { schema: schema_exports, logger: true });
341
- console.log("\u{1F7E2} Using Neon (HTTP) driver");
342
388
  } else {
343
- console.log("Database connection not established, unknown DB_DRIVER:", config.DB_DRIVER);
389
+ serverless.neonConfig.fetchFunction = (url, init) => fetch(url, __spreadProps(__spreadValues({}, init), { signal: AbortSignal.timeout(15e3) }));
390
+ const sql3 = serverless.neon(config.DATABASE_URL);
391
+ db = neonHttp.drizzle(sql3, { schema: schema_exports, logger: process.env.NODE_ENV === "development" });
392
+ console.log("\u{1F7E2} Using Neon (HTTP) driver");
344
393
  }
345
394
 
346
- // lib/activity-logger.ts
395
+ // lib/security/activity-logger.ts
347
396
  async function logActivity({
348
397
  userId,
349
398
  action,
@@ -361,6 +410,8 @@ async function logActivity({
361
410
  try {
362
411
  await db.insert(activityLogs).values({
363
412
  userId,
413
+ // Snapshot the email at write time; survives deletion of the user row.
414
+ actorEmail: drizzleOrm.sql`(select "email" from "user" where "id" = ${userId})`,
364
415
  action,
365
416
  description,
366
417
  ipAddress: ipAddress || null,