@open-mercato/ui 0.6.7-develop.6766.1.40c9011995 → 0.6.7-develop.6768.1.9d2c4efc43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/ui",
3
- "version": "0.6.7-develop.6766.1.40c9011995",
3
+ "version": "0.6.7-develop.6768.1.9d2c4efc43",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -155,13 +155,13 @@
155
155
  "remark-gfm": "^4.0.1"
156
156
  },
157
157
  "peerDependencies": {
158
- "@open-mercato/shared": "0.6.7-develop.6766.1.40c9011995",
158
+ "@open-mercato/shared": "0.6.7-develop.6768.1.9d2c4efc43",
159
159
  "react": ">=18.0.0",
160
160
  "react-dom": ">=18.0.0",
161
161
  "react-is": ">=18.0.0"
162
162
  },
163
163
  "devDependencies": {
164
- "@open-mercato/shared": "0.6.7-develop.6766.1.40c9011995",
164
+ "@open-mercato/shared": "0.6.7-develop.6768.1.9d2c4efc43",
165
165
  "@testing-library/dom": "^10.4.1",
166
166
  "@testing-library/jest-dom": "^6.9.1",
167
167
  "@testing-library/react": "^16.3.1",
@@ -552,6 +552,43 @@ export function writePerspectiveSnapshot(tableId: string, snapshot: PerspectiveS
552
552
  writeVersionedPreference(key, PERSPECTIVE_SNAPSHOT_VERSION, snapshot)
553
553
  }
554
554
 
555
+ /**
556
+ * Purge every browser-local DataTable perspective snapshot and active-view cookie
557
+ * across all tables in this origin. Snapshots persist the unsaved/live table state
558
+ * (column widths, order, visibility) keyed only by `tableId`, so they are shared by
559
+ * every account that signs in on the same browser profile. Call this at the auth
560
+ * identity boundary (login) so one user's unsaved layout never carries over to a
561
+ * different user — including a different tenant — reusing the same browser tab (#4185).
562
+ */
563
+ export function clearAllPerspectiveState(): void {
564
+ if (typeof window !== 'undefined') {
565
+ try {
566
+ const storage = window.localStorage
567
+ const staleKeys: string[] = []
568
+ for (let index = 0; index < storage.length; index += 1) {
569
+ const key = storage.key(index)
570
+ if (key && key.startsWith(`${PERSPECTIVE_STORAGE_PREFIX}:`)) staleKeys.push(key)
571
+ }
572
+ for (const key of staleKeys) storage.removeItem(key)
573
+ } catch {
574
+ // private mode / quota errors are non-fatal
575
+ }
576
+ }
577
+ if (typeof document !== 'undefined') {
578
+ try {
579
+ const cookies = document.cookie ? document.cookie.split(';') : []
580
+ for (const cookie of cookies) {
581
+ const name = cookie.split('=')[0]?.trim()
582
+ if (name && name.startsWith(`${PERSPECTIVE_COOKIE_PREFIX}:`)) {
583
+ document.cookie = `${name}=; Path=/; Max-Age=0; SameSite=Lax`
584
+ }
585
+ }
586
+ } catch {
587
+ // ignore — cookie access can throw in sandboxed contexts
588
+ }
589
+ }
590
+ }
591
+
555
592
  export function sanitizePerspectiveSettings(source?: PerspectiveSettings | null): PerspectiveSettings | null {
556
593
  if (!source || typeof source !== 'object') return null
557
594
  const forbidden = new Set(['__proto__', 'prototype', 'constructor'])
@@ -1,7 +1,8 @@
1
1
  /** @jest-environment jsdom */
2
- import { readPerspectiveSnapshot, writePerspectiveSnapshot } from '../DataTable'
2
+ import { clearAllPerspectiveState, readPerspectiveSnapshot, writePerspectiveSnapshot } from '../DataTable'
3
3
 
4
4
  const PREFIX = 'om_table_perspective_snapshot'
5
+ const COOKIE_PREFIX = 'om_table_perspective'
5
6
 
6
7
  describe('DataTable perspective snapshot storage (versioned envelope)', () => {
7
8
  beforeEach(() => {
@@ -52,3 +53,63 @@ describe('DataTable perspective snapshot storage (versioned envelope)', () => {
52
53
  expect(localStorage.getItem(`${PREFIX}:tbl5`)).toBeNull()
53
54
  })
54
55
  })
56
+
57
+ describe('clearAllPerspectiveState (tenant-isolation at the auth identity boundary, #4185)', () => {
58
+ beforeEach(() => {
59
+ localStorage.clear()
60
+ for (const cookie of document.cookie ? document.cookie.split(';') : []) {
61
+ const name = cookie.split('=')[0]?.trim()
62
+ if (name) document.cookie = `${name}=; Path=/; Max-Age=0`
63
+ }
64
+ })
65
+
66
+ it('removes every perspective snapshot across all tables', () => {
67
+ writePerspectiveSnapshot('customers-companies', {
68
+ perspectiveId: null,
69
+ settings: { columnSizing: { name: 210, status: 60 } },
70
+ updatedAt: 1,
71
+ })
72
+ writePerspectiveSnapshot('customers-people', {
73
+ perspectiveId: null,
74
+ settings: { columnSizing: { name: 300 } },
75
+ updatedAt: 2,
76
+ })
77
+
78
+ clearAllPerspectiveState()
79
+
80
+ expect(localStorage.getItem(`${PREFIX}:customers-companies`)).toBeNull()
81
+ expect(localStorage.getItem(`${PREFIX}:customers-people`)).toBeNull()
82
+ expect(readPerspectiveSnapshot('customers-companies')).toBeNull()
83
+ expect(readPerspectiveSnapshot('customers-people')).toBeNull()
84
+ })
85
+
86
+ it('leaves unrelated localStorage keys untouched', () => {
87
+ writePerspectiveSnapshot('customers-companies', {
88
+ perspectiveId: null,
89
+ settings: { columnSizing: { name: 210 } },
90
+ updatedAt: 1,
91
+ })
92
+ localStorage.setItem('om_login_tenant', 'acme')
93
+ localStorage.setItem('om:auth:identity', '123')
94
+
95
+ clearAllPerspectiveState()
96
+
97
+ expect(localStorage.getItem(`${PREFIX}:customers-companies`)).toBeNull()
98
+ expect(localStorage.getItem('om_login_tenant')).toBe('acme')
99
+ expect(localStorage.getItem('om:auth:identity')).toBe('123')
100
+ })
101
+
102
+ it('expires the active-view perspective cookies', () => {
103
+ document.cookie = `${COOKIE_PREFIX}:customers-companies=view-1; Path=/`
104
+ expect(document.cookie).toContain(`${COOKIE_PREFIX}:customers-companies=view-1`)
105
+
106
+ clearAllPerspectiveState()
107
+
108
+ expect(document.cookie).not.toContain(`${COOKIE_PREFIX}:customers-companies`)
109
+ })
110
+
111
+ it('is a no-op when nothing is stored', () => {
112
+ expect(() => clearAllPerspectiveState()).not.toThrow()
113
+ expect(localStorage.length).toBe(0)
114
+ })
115
+ })