@tumbaland/frontend-core 1.6.1 → 1.8.0

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.
@@ -1,5 +1,30 @@
1
1
  import { getCorrelationId, getSessionId, logger } from './monitoring';
2
+ import { clearSessionScopedStorage } from './sessionStorage';
2
3
  const AUTH_CACHE_TTL = 5 * 60 * 1000;
4
+ /**
5
+ * Tell the shell its session just ended.
6
+ *
7
+ * Each app runs in the shell's iframe with its own copy of this module, so a
8
+ * logout inside the frame clears only the frame's cache and reloads only the
9
+ * frame. The shell keeps serving its own five-minute-old `authenticated:
10
+ * true` from memory, which is why signing out and clicking home still showed
11
+ * the signed-in page instead of the landing page.
12
+ *
13
+ * The message carries nothing, so `'*'` gives nothing away; the shell is the
14
+ * side that authenticates it, by origin and by frame (see `useShellBridge`).
15
+ */
16
+ function notifyShellOfLogout() {
17
+ if (typeof window === 'undefined' || window.parent === window.self)
18
+ return;
19
+ try {
20
+ // Contract lives in @tumbaland/components `routing/messages` — a lower
21
+ // layer cannot import it, so the literal is repeated here.
22
+ window.parent.postMessage({ source: 'tumbaland-app', type: 'app:logout' }, '*');
23
+ }
24
+ catch (error) {
25
+ logger.warn('Failed to notify shell of logout', { error });
26
+ }
27
+ }
3
28
  function authHeaders() {
4
29
  return {
5
30
  'Content-Type': 'application/json',
@@ -81,6 +106,8 @@ export function createAuthService(config) {
81
106
  if (data.success) {
82
107
  authCache = null;
83
108
  authCacheTime = 0;
109
+ clearSessionScopedStorage();
110
+ notifyShellOfLogout();
84
111
  window.location.reload();
85
112
  }
86
113
  return data.success;
package/dist/index.d.ts CHANGED
@@ -5,5 +5,6 @@ export type { AuthServiceConfig, AuthService, AppAuthConfig } from './authServic
5
5
  export { createGroupService } from './groupService';
6
6
  export type { GroupServiceConfig, GroupService } from './groupService';
7
7
  export type { User, AuthResponse, Group, ApiResponse } from './types';
8
+ export { TENANT_STORAGE_KEY, clearSessionScopedStorage } from './sessionStorage';
8
9
  export { initMonitoring, captureException, captureMessage, setUser, setTag, startTransaction, recordMetric, initWebVitals, flushLogs, initConsoleInterception, generateCorrelationId, getCorrelationId, getSessionId, logger } from './monitoring';
9
10
  export type { MonitoringConfig } from './monitoring';
package/dist/index.js CHANGED
@@ -2,5 +2,6 @@
2
2
  export { createApiClient, ApiError } from './apiClient';
3
3
  export { createAuthService, createAppAuthService } from './authService';
4
4
  export { createGroupService } from './groupService';
5
+ export { TENANT_STORAGE_KEY, clearSessionScopedStorage } from './sessionStorage';
5
6
  // Monitoring: headless logging, error capture, correlation IDs, and web-vitals
6
7
  export { initMonitoring, captureException, captureMessage, setUser, setTag, startTransaction, recordMetric, initWebVitals, flushLogs, initConsoleInterception, generateCorrelationId, getCorrelationId, getSessionId, logger } from './monitoring';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Browser storage that belongs to the signed-in session rather than to the
3
+ * browser.
4
+ *
5
+ * localStorage is scoped per origin, so anything written here outlives a
6
+ * sign-out and is handed to whoever signs in next. For preferences that is
7
+ * fine — for anything the backend authorizes against, it is a bug: the
8
+ * incoming account sends the previous account's context and gets 403s it
9
+ * cannot explain, from a UI that looks correctly configured.
10
+ *
11
+ * `logout()` clears every key listed here. Add a key to this list rather than
12
+ * clearing it at the call site, so a new front or a second logout button
13
+ * cannot miss it.
14
+ */
15
+ /** Tenant (personal vs group) context — owned by `useTenant` in @tumbaland/components. */
16
+ export declare const TENANT_STORAGE_KEY = "selectedTenant";
17
+ export declare function clearSessionScopedStorage(): void;
@@ -0,0 +1,28 @@
1
+ import { logger } from './monitoring';
2
+ /**
3
+ * Browser storage that belongs to the signed-in session rather than to the
4
+ * browser.
5
+ *
6
+ * localStorage is scoped per origin, so anything written here outlives a
7
+ * sign-out and is handed to whoever signs in next. For preferences that is
8
+ * fine — for anything the backend authorizes against, it is a bug: the
9
+ * incoming account sends the previous account's context and gets 403s it
10
+ * cannot explain, from a UI that looks correctly configured.
11
+ *
12
+ * `logout()` clears every key listed here. Add a key to this list rather than
13
+ * clearing it at the call site, so a new front or a second logout button
14
+ * cannot miss it.
15
+ */
16
+ /** Tenant (personal vs group) context — owned by `useTenant` in @tumbaland/components. */
17
+ export const TENANT_STORAGE_KEY = 'selectedTenant';
18
+ const SESSION_SCOPED_KEYS = [TENANT_STORAGE_KEY];
19
+ export function clearSessionScopedStorage() {
20
+ for (const key of SESSION_SCOPED_KEYS) {
21
+ try {
22
+ localStorage.removeItem(key);
23
+ }
24
+ catch (err) {
25
+ logger.warn('Failed to clear session-scoped storage', { key, error: err });
26
+ }
27
+ }
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tumbaland/frontend-core",
3
- "version": "1.6.1",
3
+ "version": "1.8.0",
4
4
  "description": "Shared frontend auth/group/API-client logic for Tumbaland frontends",
5
5
  "author": "Tumbaland",
6
6
  "license": "MIT",
@@ -11,7 +11,7 @@
11
11
  ],
12
12
  "scripts": {
13
13
  "build": "tsc -p tsconfig.build.json",
14
- "release": "commit-and-tag-version && npm run build && npm publish --access public",
14
+ "release": "commit-and-tag-version && npm run build && npm publish --access public && node ../../scripts/sync-lib-versions.mjs",
15
15
  "release:beta": "commit-and-tag-version --prerelease beta && npm run build && npm publish --access public --tag beta",
16
16
  "test": "vitest run",
17
17
  "test:coverage": "vitest run --coverage",