@jmruthers/pace-core 0.6.3 → 0.6.5

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 (103) hide show
  1. package/dist/{DataTable-THFPBKTP.js → DataTable-AOVNCPTX.js} +8 -8
  2. package/dist/{PublicPageProvider-DEMpysFR.d.ts → PublicPageProvider-QTFVrL-Z.d.ts} +65 -83
  3. package/dist/{UnifiedAuthProvider-KAGUYQ4J.js → UnifiedAuthProvider-4SBX4LU5.js} +4 -4
  4. package/dist/{api-IAGWF3ZG.js → api-O6HTBX5Y.js} +3 -3
  5. package/dist/{chunk-ZNIWI3UC.js → chunk-6COVEUS7.js} +141 -107
  6. package/dist/chunk-6COVEUS7.js.map +1 -0
  7. package/dist/{chunk-QRPVRXYT.js → chunk-AFVQODI2.js} +38 -1
  8. package/dist/{chunk-QRPVRXYT.js.map → chunk-AFVQODI2.js.map} +1 -1
  9. package/dist/{chunk-RWEBCB47.js → chunk-EFN2EIMK.js} +2 -2
  10. package/dist/{chunk-CNCQDFLN.js → chunk-G7QEZTYQ.js} +31 -31
  11. package/dist/{chunk-CNCQDFLN.js.map → chunk-G7QEZTYQ.js.map} +1 -1
  12. package/dist/{chunk-YDQHOZNA.js → chunk-HU2C6SSC.js} +29 -18
  13. package/dist/chunk-HU2C6SSC.js.map +1 -0
  14. package/dist/{chunk-DWUBLJJM.js → chunk-IHB5DR3H.js} +184 -53
  15. package/dist/chunk-IHB5DR3H.js.map +1 -0
  16. package/dist/{chunk-PQBSKX33.js → chunk-IVOFDYWT.js} +364 -208
  17. package/dist/chunk-IVOFDYWT.js.map +1 -0
  18. package/dist/{chunk-6SOIHG6Z.js → chunk-JGRYX5UX.js} +120 -20
  19. package/dist/chunk-JGRYX5UX.js.map +1 -0
  20. package/dist/{chunk-6Z7LTB3D.js → chunk-NTM7ZSB6.js} +4 -4
  21. package/dist/chunk-NTM7ZSB6.js.map +1 -0
  22. package/dist/{chunk-HFZBI76P.js → chunk-RGAWHO7N.js} +4 -4
  23. package/dist/chunk-RGAWHO7N.js.map +1 -0
  24. package/dist/{chunk-2T2IG7T7.js → chunk-UPPMRMYG.js} +3 -3
  25. package/dist/{chunk-2T2IG7T7.js.map → chunk-UPPMRMYG.js.map} +1 -1
  26. package/dist/components.d.ts +2 -3
  27. package/dist/components.js +24 -28
  28. package/dist/components.js.map +1 -1
  29. package/dist/{contextValidator-3JNZKUTX.js → contextValidator-5OGXSPKS.js} +2 -2
  30. package/dist/hooks.d.ts +3 -3
  31. package/dist/hooks.js +41 -139
  32. package/dist/hooks.js.map +1 -1
  33. package/dist/index.d.ts +27 -18
  34. package/dist/index.js +41 -50
  35. package/dist/index.js.map +1 -1
  36. package/dist/providers.js +3 -3
  37. package/dist/rbac/index.d.ts +16 -9
  38. package/dist/rbac/index.js +6 -6
  39. package/dist/{usePublicRouteParams-i3qtoBgg.d.ts → usePublicRouteParams-ClnV4tnv.d.ts} +8 -8
  40. package/dist/utils.js +1 -1
  41. package/docs/api/modules.md +210 -100
  42. package/package.json +8 -4
  43. package/scripts/audit/core/checks/dependencies.cjs +9 -0
  44. package/scripts/validate-master.js +1 -1
  45. package/src/components/DataTable/__tests__/keyboard.test.tsx +15 -2
  46. package/src/components/DataTable/components/ImportModal.tsx +4 -6
  47. package/src/components/DataTable/components/ViewRowModal.tsx +4 -4
  48. package/src/components/DataTable/components/__tests__/ImportModal.test.tsx +455 -96
  49. package/src/components/DataTable/components/__tests__/ViewRowModal.test.tsx +122 -58
  50. package/src/components/DataTable/core/DataTableContext.tsx +1 -1
  51. package/src/components/DateTimeField/DateTimeField.tsx +17 -19
  52. package/src/components/DateTimeField/README.md +5 -2
  53. package/src/components/Dialog/Dialog.test.tsx +248 -228
  54. package/src/components/Dialog/Dialog.tsx +455 -325
  55. package/src/components/Dialog/index.ts +3 -3
  56. package/src/components/FileDisplay/FileDisplay.test.tsx +41 -0
  57. package/src/components/FileDisplay/FileDisplay.tsx +5 -5
  58. package/src/components/Form/Form.test.tsx +3 -2
  59. package/src/components/Form/Form.tsx +4 -5
  60. package/src/components/InactivityWarningModal/InactivityWarningModal.test.tsx +28 -28
  61. package/src/components/InactivityWarningModal/InactivityWarningModal.tsx +40 -54
  62. package/src/components/LoginForm/LoginForm.tsx +2 -2
  63. package/src/components/NavigationMenu/NavigationMenu.tsx +2 -2
  64. package/src/components/PaceAppLayout/PaceAppLayout.tsx +54 -42
  65. package/src/components/PaceAppLayout/README.md +10 -9
  66. package/src/components/PaceAppLayout/test-setup.tsx +40 -31
  67. package/src/components/PasswordChange/PasswordChangeForm.test.tsx +61 -0
  68. package/src/components/PasswordChange/PasswordChangeForm.tsx +20 -13
  69. package/src/components/PublicLayout/PublicLayout.test.tsx +7 -3
  70. package/src/components/PublicLayout/PublicPageLayout.tsx +5 -8
  71. package/src/components/UserMenu/UserMenu.test.tsx +38 -6
  72. package/src/components/UserMenu/UserMenu.tsx +36 -34
  73. package/src/components/index.ts +3 -4
  74. package/src/hooks/useEventTheme.ts +4 -4
  75. package/src/hooks/useEvents.ts +11 -7
  76. package/src/hooks/useKeyboardShortcuts.ts +1 -1
  77. package/src/hooks/useOrganisationPermissions.ts +4 -4
  78. package/src/hooks/useOrganisations.ts +13 -7
  79. package/src/index.ts +11 -1
  80. package/src/rbac/README.md +20 -20
  81. package/src/rbac/hooks/useRBAC.test.ts +21 -3
  82. package/src/rbac/hooks/useRBAC.ts +4 -3
  83. package/src/rbac/hooks/useResourcePermissions.test.ts +125 -30
  84. package/src/rbac/hooks/useResourcePermissions.ts +57 -29
  85. package/src/rbac/permissions.ts +17 -17
  86. package/src/rbac/utils/contextValidator.ts +36 -0
  87. package/src/services/AuthService.ts +2 -5
  88. package/src/services/EventService.ts +99 -2
  89. package/src/services/InactivityService.ts +139 -58
  90. package/src/styles/core.css +4 -0
  91. package/src/utils/formatting/formatTime.test.ts +3 -2
  92. package/dist/chunk-6SOIHG6Z.js.map +0 -1
  93. package/dist/chunk-6Z7LTB3D.js.map +0 -1
  94. package/dist/chunk-DWUBLJJM.js.map +0 -1
  95. package/dist/chunk-HFZBI76P.js.map +0 -1
  96. package/dist/chunk-PQBSKX33.js.map +0 -1
  97. package/dist/chunk-YDQHOZNA.js.map +0 -1
  98. package/dist/chunk-ZNIWI3UC.js.map +0 -1
  99. /package/dist/{DataTable-THFPBKTP.js.map → DataTable-AOVNCPTX.js.map} +0 -0
  100. /package/dist/{UnifiedAuthProvider-KAGUYQ4J.js.map → UnifiedAuthProvider-4SBX4LU5.js.map} +0 -0
  101. /package/dist/{api-IAGWF3ZG.js.map → api-O6HTBX5Y.js.map} +0 -0
  102. /package/dist/{chunk-RWEBCB47.js.map → chunk-EFN2EIMK.js.map} +0 -0
  103. /package/dist/{contextValidator-3JNZKUTX.js.map → contextValidator-5OGXSPKS.js.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isRBACInitialized,
3
3
  setupRBAC
4
- } from "./chunk-RWEBCB47.js";
4
+ } from "./chunk-EFN2EIMK.js";
5
5
  import {
6
6
  assertOrganisationId,
7
7
  assertUserId
@@ -126,11 +126,6 @@ var _AuthService = class _AuthService extends BaseService {
126
126
  }
127
127
  // Auth state getters
128
128
  getUser() {
129
- if (this.user) {
130
- logger.debug("AuthService", `getUser() [ID:${this.instanceId}] returning user: ${this.user.id}`);
131
- } else {
132
- logger.debug("AuthService", `getUser() [ID:${this.instanceId}] returning null`);
133
- }
134
129
  return this.user;
135
130
  }
136
131
  getSession() {
@@ -1016,7 +1011,7 @@ var _OrganisationService = class _OrganisationService extends BaseService {
1016
1011
  let userIsSuperAdmin = false;
1017
1012
  if (this.user?.id) {
1018
1013
  try {
1019
- const { isSuperAdmin: checkSuperAdmin, isRBACInitialized: isRBACInitialized2, setupRBAC: setupRBAC2 } = await import("./api-IAGWF3ZG.js");
1014
+ const { isSuperAdmin: checkSuperAdmin, isRBACInitialized: isRBACInitialized2, setupRBAC: setupRBAC2 } = await import("./api-O6HTBX5Y.js");
1020
1015
  if (!isRBACInitialized2() && this.supabaseClient) {
1021
1016
  setupRBAC2(this.supabaseClient);
1022
1017
  }
@@ -1275,6 +1270,8 @@ var _EventService = class _EventService extends BaseService {
1275
1270
  this.resetInitialization();
1276
1271
  this.isInitializedRef = false;
1277
1272
  this.isFetchingRef = false;
1273
+ this.userClearedEventRef = false;
1274
+ this.hasAutoSelectedRef = false;
1278
1275
  logger.debug("EventService", `User changed [ID:${this.instanceId}]`, {
1279
1276
  previousUserId,
1280
1277
  newUserId,
@@ -1289,7 +1286,7 @@ var _EventService = class _EventService extends BaseService {
1289
1286
  this.setSelectedEventId = setSelectedEventId;
1290
1287
  if (user?.id) {
1291
1288
  try {
1292
- const { isRBACInitialized: isRBACInitialized2, isSuperAdmin: checkSuperAdmin, setupRBAC: setupRBAC2 } = await import("./api-IAGWF3ZG.js");
1289
+ const { isRBACInitialized: isRBACInitialized2, isSuperAdmin: checkSuperAdmin, setupRBAC: setupRBAC2 } = await import("./api-O6HTBX5Y.js");
1293
1290
  if (!isRBACInitialized2() && this.supabaseClient) {
1294
1291
  setupRBAC2(this.supabaseClient);
1295
1292
  }
@@ -1321,12 +1318,28 @@ var _EventService = class _EventService extends BaseService {
1321
1318
  this.isInitializedRef = false;
1322
1319
  this.isFetchingRef = false;
1323
1320
  const shouldClearEvents = !this.isSuperAdmin;
1324
- if (previousOrgId !== null && newOrgId !== null && previousOrgId !== newOrgId) {
1321
+ const isFirstOrgSet = (previousOrgId === null || previousOrgId === void 0) && newOrgId !== null && newOrgId !== void 0;
1322
+ if (isFirstOrgSet) {
1323
+ const hadAutoSelectedEvent = this.hasAutoSelectedRef && !!this.selectedEvent;
1324
+ this.userClearedEventRef = false;
1325
+ if (!hadAutoSelectedEvent) {
1326
+ this.hasAutoSelectedRef = false;
1327
+ }
1328
+ logger.debug("EventService", "Organisation first set - preserving event and resetting auto-selection flags", {
1329
+ organisationId: newOrgId,
1330
+ hasSelectedEvent: !!this.selectedEvent,
1331
+ selectedEventId: this.selectedEvent?.event_id,
1332
+ hadAutoSelectedEvent,
1333
+ preservingEvent: hadAutoSelectedEvent,
1334
+ previousOrgId,
1335
+ newOrgId
1336
+ });
1337
+ } else if (previousOrgId !== null && previousOrgId !== void 0 && newOrgId !== null && newOrgId !== void 0 && previousOrgId !== newOrgId) {
1325
1338
  if (shouldClearEvents) {
1326
1339
  this.events = [];
1327
1340
  this.setSelectedEvent(null);
1328
1341
  }
1329
- } else if (previousOrgId !== null && newOrgId === null) {
1342
+ } else if (previousOrgId !== null && previousOrgId !== void 0 && newOrgId === null) {
1330
1343
  if (shouldClearEvents) {
1331
1344
  this.events = [];
1332
1345
  this.setSelectedEvent(null);
@@ -1357,7 +1370,13 @@ var _EventService = class _EventService extends BaseService {
1357
1370
  logger.warn("EventService", "Failed to persist event selection:", error);
1358
1371
  });
1359
1372
  this.userClearedEventRef = false;
1373
+ logger.debug("EventService", "Event selected", {
1374
+ eventId: event.event_id,
1375
+ eventName: event.event_name,
1376
+ userClearedEventRef: this.userClearedEventRef
1377
+ });
1360
1378
  } else {
1379
+ const previousEventId = this.selectedEvent?.event_id;
1361
1380
  this.selectedEvent = null;
1362
1381
  this.setSelectedEventId?.(null);
1363
1382
  this.clearEventSelection().catch((error) => {
@@ -1365,6 +1384,11 @@ var _EventService = class _EventService extends BaseService {
1365
1384
  });
1366
1385
  this.hasAutoSelectedRef = false;
1367
1386
  this.userClearedEventRef = true;
1387
+ logger.debug("EventService", "Event cleared via setSelectedEvent(null)", {
1388
+ previousEventId,
1389
+ userClearedEventRef: this.userClearedEventRef,
1390
+ stackTrace: new Error().stack
1391
+ });
1368
1392
  }
1369
1393
  this.notify();
1370
1394
  }
@@ -1504,7 +1528,7 @@ var _EventService = class _EventService extends BaseService {
1504
1528
  let organisationIdForRpc = null;
1505
1529
  let userIsSuperAdmin = this.isSuperAdmin;
1506
1530
  try {
1507
- const { isRBACInitialized: isRBACInitialized2, isSuperAdmin: checkSuperAdmin, setupRBAC: setupRBAC2 } = await import("./api-IAGWF3ZG.js");
1531
+ const { isRBACInitialized: isRBACInitialized2, isSuperAdmin: checkSuperAdmin, setupRBAC: setupRBAC2 } = await import("./api-O6HTBX5Y.js");
1508
1532
  if (!isRBACInitialized2() && this.supabaseClient) {
1509
1533
  setupRBAC2(this.supabaseClient);
1510
1534
  }
@@ -1618,23 +1642,74 @@ var _EventService = class _EventService extends BaseService {
1618
1642
  });
1619
1643
  this.events = sortedEvents;
1620
1644
  this.error = null;
1645
+ if (this.selectedEvent) {
1646
+ const selectedEventId = this.selectedEvent.event_id;
1647
+ const eventStillExists = transformedEvents.some(
1648
+ (e) => e.event_id === selectedEventId
1649
+ );
1650
+ if (!eventStillExists) {
1651
+ const previousUserClearedRef = this.userClearedEventRef;
1652
+ this.selectedEvent = null;
1653
+ this.setSelectedEventId?.(null);
1654
+ this.userClearedEventRef = previousUserClearedRef;
1655
+ logger.debug("EventService", "Cleared selected event - no longer in events list", {
1656
+ previousEventId: selectedEventId,
1657
+ eventsCount: transformedEvents.length
1658
+ });
1659
+ }
1660
+ }
1621
1661
  this.hasAutoSelectedRef = false;
1622
1662
  if (!skipLoadPersisted) {
1623
1663
  const persistedEventLoaded = await this.loadPersistedEvent(transformedEvents);
1664
+ logger.debug("EventService", "Event selection check", {
1665
+ persistedEventLoaded,
1666
+ userClearedEventRef: this.userClearedEventRef,
1667
+ eventsCount: transformedEvents.length,
1668
+ hasSelectedEvent: !!this.selectedEvent
1669
+ });
1624
1670
  if (!persistedEventLoaded && !this.userClearedEventRef) {
1625
1671
  const nextEvent = this.getNextEventByDate(transformedEvents);
1672
+ logger.debug("EventService", "Auto-selection attempt", {
1673
+ nextEventFound: !!nextEvent,
1674
+ nextEventId: nextEvent?.event_id,
1675
+ nextEventDate: nextEvent?.event_date
1676
+ });
1626
1677
  if (nextEvent) {
1627
1678
  this.hasAutoSelectedRef = true;
1628
1679
  this.setSelectedEvent(nextEvent);
1680
+ logger.debug("EventService", "Auto-selected next event", {
1681
+ eventId: nextEvent.event_id,
1682
+ eventName: nextEvent.event_name,
1683
+ eventDate: nextEvent.event_date
1684
+ });
1685
+ } else {
1686
+ logger.debug("EventService", "No next event found for auto-selection", {
1687
+ eventsCount: transformedEvents.length,
1688
+ eventsWithDates: transformedEvents.filter((e) => e.event_date).length
1689
+ });
1629
1690
  }
1691
+ } else if (persistedEventLoaded) {
1692
+ logger.debug("EventService", "Skipped auto-selection - persisted event loaded");
1693
+ } else if (this.userClearedEventRef) {
1694
+ logger.debug("EventService", "Skipped auto-selection - user explicitly cleared event");
1630
1695
  }
1631
1696
  } else {
1632
1697
  if (!this.userClearedEventRef) {
1633
1698
  const nextEvent = this.getNextEventByDate(transformedEvents);
1699
+ logger.debug("EventService", "Auto-selection attempt (skip persisted)", {
1700
+ nextEventFound: !!nextEvent,
1701
+ nextEventId: nextEvent?.event_id
1702
+ });
1634
1703
  if (nextEvent) {
1635
1704
  this.hasAutoSelectedRef = true;
1636
1705
  this.setSelectedEvent(nextEvent);
1706
+ logger.debug("EventService", "Auto-selected next event (skip persisted)", {
1707
+ eventId: nextEvent.event_id,
1708
+ eventName: nextEvent.event_name
1709
+ });
1637
1710
  }
1711
+ } else {
1712
+ logger.debug("EventService", "Skipped auto-selection (skip persisted) - user explicitly cleared event");
1638
1713
  }
1639
1714
  }
1640
1715
  }
@@ -1990,27 +2065,34 @@ var InactivityService = class extends BaseService {
1990
2065
  }
1991
2066
  setupEventHandlers() {
1992
2067
  if (typeof window === "undefined") return;
1993
- let idleTimer = null;
1994
2068
  let warningTimer = null;
2069
+ let logoutTimer = null;
2070
+ let countdownInterval = null;
1995
2071
  let lastActivity = Date.now();
1996
- let pollInterval = null;
1997
2072
  let prevIsIdle = false;
1998
2073
  let prevShowWarning = false;
1999
2074
  let prevShowInactivityWarning = false;
2000
2075
  let prevInactivityTimeRemaining = 0;
2001
2076
  let prevTimeRemaining = this.idleTimeoutMs;
2002
- const pollInactivityState = () => {
2077
+ const getTimeUntilWarning = () => {
2078
+ const timeSinceActivity = Date.now() - lastActivity;
2079
+ return Math.max(0, this.idleTimeoutMs - this.warnBeforeMs - timeSinceActivity);
2080
+ };
2081
+ const getTimeUntilLogout = () => {
2082
+ const timeSinceActivity = Date.now() - lastActivity;
2083
+ return Math.max(0, this.idleTimeoutMs - timeSinceActivity);
2084
+ };
2085
+ const updateState = (forceNotify = false) => {
2003
2086
  const now = Date.now();
2004
2087
  const timeSinceActivity = now - lastActivity;
2005
2088
  const timeUntilIdle = this.idleTimeoutMs - timeSinceActivity;
2006
- const timeUntilWarning = this.idleTimeoutMs - this.warnBeforeMs - timeSinceActivity;
2007
- const newIsIdle = timeSinceActivity >= this.idleTimeoutMs - this.warnBeforeMs;
2008
- const newShowWarning = newIsIdle && timeSinceActivity < this.idleTimeoutMs;
2089
+ const newIsIdle = timeSinceActivity >= this.idleTimeoutMs;
2090
+ const newShowWarning = timeSinceActivity >= this.idleTimeoutMs - this.warnBeforeMs && !newIsIdle;
2009
2091
  const newShowInactivityWarning = newShowWarning;
2010
- const newInactivityTimeRemaining = newShowWarning ? Math.ceil((this.idleTimeoutMs - timeSinceActivity) / 1e3) : 0;
2092
+ const newInactivityTimeRemaining = newShowWarning ? Math.ceil(timeUntilIdle / 1e3) : 0;
2011
2093
  const newTimeRemaining = Math.max(0, timeUntilIdle);
2012
- const stateChanged = prevIsIdle !== newIsIdle || prevShowWarning !== newShowWarning || prevShowInactivityWarning !== newShowInactivityWarning || prevInactivityTimeRemaining !== newInactivityTimeRemaining || prevTimeRemaining !== newTimeRemaining;
2013
- if (stateChanged) {
2094
+ const stateChanged = prevIsIdle !== newIsIdle || prevShowWarning !== newShowWarning || prevShowInactivityWarning !== newShowInactivityWarning || newShowWarning && prevInactivityTimeRemaining !== newInactivityTimeRemaining || prevTimeRemaining !== newTimeRemaining;
2095
+ if (stateChanged || forceNotify) {
2014
2096
  this._isIdle = newIsIdle;
2015
2097
  this._showWarning = newShowWarning;
2016
2098
  this._showInactivityWarning = newShowInactivityWarning;
@@ -2021,73 +2103,123 @@ var InactivityService = class extends BaseService {
2021
2103
  prevShowInactivityWarning = newShowInactivityWarning;
2022
2104
  prevInactivityTimeRemaining = newInactivityTimeRemaining;
2023
2105
  prevTimeRemaining = newTimeRemaining;
2024
- this.notify();
2025
- if (newIsIdle && timeSinceActivity >= this.idleTimeoutMs) {
2106
+ if (stateChanged) {
2107
+ this.notify();
2108
+ }
2109
+ if (newIsIdle) {
2026
2110
  this.handleIdleLogout();
2027
2111
  }
2028
2112
  }
2029
- if (idleTimer) {
2030
- clearTimeout(idleTimer);
2031
- idleTimer = null;
2032
- }
2113
+ };
2114
+ const scheduleNextCheck = () => {
2033
2115
  if (warningTimer) {
2034
2116
  clearTimeout(warningTimer);
2035
2117
  warningTimer = null;
2036
2118
  }
2037
- if (!newIsIdle && timeUntilIdle > 0) {
2038
- idleTimer = setTimeout(() => {
2039
- pollInactivityState();
2040
- }, Math.min(1e4, timeUntilIdle));
2041
- }
2042
- if (newShowWarning && timeUntilIdle > 0) {
2043
- warningTimer = setTimeout(() => {
2119
+ if (logoutTimer) {
2120
+ clearTimeout(logoutTimer);
2121
+ logoutTimer = null;
2122
+ }
2123
+ if (countdownInterval) {
2124
+ clearInterval(countdownInterval);
2125
+ countdownInterval = null;
2126
+ }
2127
+ const timeUntilWarning = getTimeUntilWarning();
2128
+ const timeUntilLogout = getTimeUntilLogout();
2129
+ const timeSinceActivity = Date.now() - lastActivity;
2130
+ if (timeSinceActivity >= this.idleTimeoutMs) {
2131
+ return;
2132
+ }
2133
+ if (timeSinceActivity >= this.idleTimeoutMs - this.warnBeforeMs) {
2134
+ updateState();
2135
+ countdownInterval = setInterval(() => {
2136
+ updateState();
2137
+ if (Date.now() - lastActivity >= this.idleTimeoutMs) {
2138
+ if (countdownInterval) {
2139
+ clearInterval(countdownInterval);
2140
+ countdownInterval = null;
2141
+ }
2142
+ this.handleIdleLogout();
2143
+ }
2144
+ }, 1e3);
2145
+ logoutTimer = setTimeout(() => {
2146
+ if (countdownInterval) {
2147
+ clearInterval(countdownInterval);
2148
+ countdownInterval = null;
2149
+ }
2044
2150
  this.handleIdleLogout();
2045
- }, timeUntilIdle);
2151
+ }, timeUntilLogout);
2152
+ } else {
2153
+ const timeUntilWarningMs = timeUntilWarning;
2154
+ const adaptiveInterval = timeUntilWarningMs > 5 * 60 * 1e3 ? 60 * 1e3 : timeUntilWarningMs > 60 * 1e3 ? 10 * 1e3 : 1e3;
2155
+ warningTimer = setTimeout(() => {
2156
+ updateState();
2157
+ scheduleNextCheck();
2158
+ }, Math.min(adaptiveInterval, timeUntilWarningMs));
2046
2159
  }
2047
2160
  };
2048
2161
  const resetTimers = () => {
2049
2162
  lastActivity = Date.now();
2050
- if (idleTimer) {
2051
- clearTimeout(idleTimer);
2052
- idleTimer = null;
2053
- }
2054
2163
  if (warningTimer) {
2055
2164
  clearTimeout(warningTimer);
2056
2165
  warningTimer = null;
2057
2166
  }
2167
+ if (logoutTimer) {
2168
+ clearTimeout(logoutTimer);
2169
+ logoutTimer = null;
2170
+ }
2171
+ if (countdownInterval) {
2172
+ clearInterval(countdownInterval);
2173
+ countdownInterval = null;
2174
+ }
2175
+ const hadWarning = this._showWarning || this._showInactivityWarning;
2058
2176
  this._showInactivityWarning = false;
2059
2177
  this._inactivityTimeRemaining = 0;
2060
2178
  this._isIdle = false;
2061
2179
  this._showWarning = false;
2180
+ this._timeRemaining = this.idleTimeoutMs;
2062
2181
  prevIsIdle = false;
2063
2182
  prevShowWarning = false;
2064
2183
  prevShowInactivityWarning = false;
2065
2184
  prevInactivityTimeRemaining = 0;
2066
2185
  prevTimeRemaining = this.idleTimeoutMs;
2186
+ if (hadWarning) {
2187
+ this.notify();
2188
+ }
2189
+ scheduleNextCheck();
2067
2190
  };
2068
2191
  const activityEvents = ["mousedown", "mousemove", "keypress", "scroll", "touchstart", "click"];
2192
+ let activityThrottleTimer = null;
2069
2193
  const handleActivity = () => {
2070
- resetTimers();
2194
+ if (activityThrottleTimer) {
2195
+ return;
2196
+ }
2197
+ activityThrottleTimer = setTimeout(() => {
2198
+ activityThrottleTimer = null;
2199
+ resetTimers();
2200
+ }, 1e3);
2071
2201
  };
2072
2202
  activityEvents.forEach((event) => {
2073
2203
  document.addEventListener(event, handleActivity, true);
2074
2204
  });
2075
- pollInterval = setInterval(() => {
2076
- pollInactivityState();
2077
- }, 1e4);
2078
- pollInactivityState();
2205
+ updateState(true);
2206
+ scheduleNextCheck();
2079
2207
  this.cleanupHandlers = () => {
2080
- if (idleTimer) {
2081
- clearTimeout(idleTimer);
2082
- idleTimer = null;
2083
- }
2084
2208
  if (warningTimer) {
2085
2209
  clearTimeout(warningTimer);
2086
2210
  warningTimer = null;
2087
2211
  }
2088
- if (pollInterval) {
2089
- clearInterval(pollInterval);
2090
- pollInterval = null;
2212
+ if (logoutTimer) {
2213
+ clearTimeout(logoutTimer);
2214
+ logoutTimer = null;
2215
+ }
2216
+ if (countdownInterval) {
2217
+ clearInterval(countdownInterval);
2218
+ countdownInterval = null;
2219
+ }
2220
+ if (activityThrottleTimer) {
2221
+ clearTimeout(activityThrottleTimer);
2222
+ activityThrottleTimer = null;
2091
2223
  }
2092
2224
  activityEvents.forEach((event) => {
2093
2225
  document.removeEventListener(event, handleActivity, true);
@@ -2100,7 +2232,6 @@ var InactivityService = class extends BaseService {
2100
2232
  this._inactivityTimeRemaining = 0;
2101
2233
  };
2102
2234
  this._isTracking = true;
2103
- this.notify();
2104
2235
  }
2105
2236
  };
2106
2237
 
@@ -2414,7 +2545,7 @@ function UnifiedAuthContextProvider({
2414
2545
  resolvedUserIdRef.current = currentUserId;
2415
2546
  const userId = currentUserId;
2416
2547
  const appNameValue = appName;
2417
- import("./api-IAGWF3ZG.js").then(async ({ resolveAppContext, setupRBAC: setupRBAC2 }) => {
2548
+ import("./api-O6HTBX5Y.js").then(async ({ resolveAppContext, setupRBAC: setupRBAC2 }) => {
2418
2549
  try {
2419
2550
  setupRBAC2(supabase);
2420
2551
  const result = await resolveAppContext({
@@ -2881,4 +3012,4 @@ export {
2881
3012
  useUnifiedAuth,
2882
3013
  UnifiedAuthProvider
2883
3014
  };
2884
- //# sourceMappingURL=chunk-DWUBLJJM.js.map
3015
+ //# sourceMappingURL=chunk-IHB5DR3H.js.map