@redacto.io/consent-sdk-react 9.3.0 → 9.4.0-beta.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.
- package/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +6 -0
- package/README.md +93 -12
- package/dist/index.d.mts +39 -1
- package/dist/index.d.ts +39 -1
- package/dist/index.js +4454 -334
- package/dist/index.mjs +4454 -335
- package/dist/privacy-center.d.mts +4 -1
- package/dist/privacy-center.d.ts +4 -1
- package/dist/privacy-center.js +3905 -3660
- package/dist/privacy-center.mjs +4172 -3921
- package/package.json +1 -1
- package/src/RedactoNoticeAssisted/RedactoNoticeAssisted.test.tsx +847 -0
- package/src/RedactoNoticeAssisted/RedactoNoticeAssisted.tsx +2133 -0
- package/src/RedactoNoticeAssisted/api/index.ts +269 -0
- package/src/RedactoNoticeAssisted/api/types.ts +180 -0
- package/src/RedactoNoticeAssisted/assets/redacto-logo.png +0 -0
- package/src/RedactoNoticeAssisted/constants.ts +51 -0
- package/src/RedactoNoticeAssisted/i18n.ts +1463 -0
- package/src/RedactoNoticeAssisted/index.ts +1 -0
- package/src/RedactoNoticeAssisted/injectStyles.ts +251 -0
- package/src/RedactoNoticeAssisted/styles.ts +730 -0
- package/src/RedactoNoticeAssisted/types.ts +24 -0
- package/src/RedactoNoticeAssisted/useMediaQuery.ts +36 -0
- package/src/RedactoPrivacyCenter/NotificationsPage.tsx +8 -0
- package/src/RedactoPrivacyCenter/api/actions.ts +6 -11
- package/src/RedactoPrivacyCenter/api/client.ts +15 -3
- package/src/RedactoPrivacyCenter/api/fetcher.ts +80 -1
- package/src/RedactoPrivacyCenter/components/ActivitiesList.tsx +193 -213
- package/src/RedactoPrivacyCenter/components/ActivityTimeline.tsx +239 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/MessagesTab.tsx +3 -1
- package/src/RedactoPrivacyCenter/components/CaseDetails/useMessagePolling.ts +8 -1
- package/src/RedactoPrivacyCenter/components/ConsentManager.tsx +23 -17
- package/src/RedactoPrivacyCenter/components/ConsentManagerCells.tsx +24 -10
- package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationBell.tsx +16 -3
- package/src/RedactoPrivacyCenter/components/constant.ts +25 -0
- package/src/RedactoPrivacyCenter/components/types.ts +32 -1
- package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +25 -23
- package/src/RedactoPrivacyCenter/lib/constants.ts +23 -10
- package/src/RedactoPrivacyCenter/lib/queries.ts +9 -2
- package/src/RedactoPrivacyCenter/lib/utils.refresh-circuit.test.ts +127 -0
- package/src/RedactoPrivacyCenter/lib/utils.refresh-storage.test.ts +85 -0
- package/src/RedactoPrivacyCenter/lib/utils.ts +213 -63
- package/src/RedactoPrivacyCenter/locales/en/translation.json +3 -0
- package/src/RedactoPrivacyCenter/styles/injectStyles.ts +16 -0
- package/src/index.ts +2 -0
- package/src/shared/api-errors.ts +9 -0
- package/src/RedactoPrivacyCenter/components/activitiesColumns.tsx +0 -141
|
@@ -167,21 +167,34 @@ export const DOCUMENT_REQUEST_STATUS_LABEL: Record<DocumentRequestStatus, Docume
|
|
|
167
167
|
replacement_requested: { labelKey: 'docStatusReplacementRequested', color: STATUS_COLORS.warning.color },
|
|
168
168
|
};
|
|
169
169
|
|
|
170
|
-
// Activity columns constants
|
|
171
|
-
export const ACTIVITY_COLUMN_SIZES = {
|
|
172
|
-
TITLE: 220,
|
|
173
|
-
ACTIVITY_TYPE: 160,
|
|
174
|
-
DESCRIPTION: 320,
|
|
175
|
-
TIMESTAMP: 200,
|
|
176
|
-
} as const;
|
|
177
|
-
|
|
178
|
-
export const ACTIVITY_DESCRIPTION_TRUNCATE_LENGTH = 100;
|
|
179
|
-
|
|
180
170
|
export const ACTIVITY_DATE_FORMATS = {
|
|
181
171
|
DISPLAY: 'MMM D, YYYY [at] h:mm A',
|
|
182
172
|
TOOLTIP: 'MMMM D, YYYY [at] h:mm:ss A',
|
|
173
|
+
DATE: 'MMM D, YYYY',
|
|
174
|
+
TIME: 'h:mm A',
|
|
183
175
|
} as const;
|
|
184
176
|
|
|
177
|
+
export const ACTIVITY_PAGE_SIZE = 10;
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
// ─── Token refresh ─────────────────────────────────────────────────────────
|
|
181
|
+
|
|
182
|
+
// Backoff window for *transient* OTP-refresh failures (network / 5xx). After a
|
|
183
|
+
// transient failure we wait at least MIN before the next attempt and grow the
|
|
184
|
+
// window exponentially up to MAX, so a flaky connection can't turn the
|
|
185
|
+
// proactive-refresh path into a request storm (incident 2026-06-22). Terminal
|
|
186
|
+
// failures (expired / already-used token) are handled by the circuit breaker in
|
|
187
|
+
// lib/utils.ts and are not retried at all.
|
|
188
|
+
export const MIN_REFRESH_BACKOFF_MS = 30_000; // 30s
|
|
189
|
+
export const MAX_REFRESH_BACKOFF_MS = 300_000; // 5m
|
|
190
|
+
|
|
191
|
+
// Where the privacy center persists the refresh token: localStorage (origin-
|
|
192
|
+
// scoped, no path matching) under a Redacto-namespaced key, so it is readable
|
|
193
|
+
// regardless of the host app's basePath and never collides with a host's own
|
|
194
|
+
// `refresh_token` cookie. LEGACY_REFRESH_TOKEN_COOKIE is the cookie name older
|
|
195
|
+
// SDK versions wrote (at path=/privacy-center); only that path is ever cleared.
|
|
196
|
+
export const REFRESH_TOKEN_STORAGE_KEY = 'redacto_pc_refresh_token';
|
|
197
|
+
export const LEGACY_REFRESH_TOKEN_COOKIE = 'refresh_token';
|
|
185
198
|
|
|
186
199
|
// ─── Notification Hub ──────────────────────────────────────────────────────
|
|
187
200
|
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from './api';
|
|
10
10
|
import { useBaseUrl } from '../context/BaseUrlContext';
|
|
11
11
|
import { useCurrentLanguage } from './useCurrentLanguage';
|
|
12
|
+
import { isTerminalRefreshError } from '../api/fetcher';
|
|
12
13
|
import type { SendCaseMessageInput, SubmitDocumentForRequestInput } from './types';
|
|
13
14
|
|
|
14
15
|
export const useCaseHistory = (
|
|
@@ -33,7 +34,10 @@ export const useCaseHistory = (
|
|
|
33
34
|
return response?.data || [];
|
|
34
35
|
},
|
|
35
36
|
enabled: !!organizationId && !!workspaceId && !!contact && !!consentClient,
|
|
36
|
-
retry
|
|
37
|
+
// Don't retry terminal auth failures — retrying a dead token only adds load
|
|
38
|
+
// (incident 2026-06-22). Transient failures get a single backed-off retry.
|
|
39
|
+
retry: (failureCount, error) => !isTerminalRefreshError(error) && failureCount < 1,
|
|
40
|
+
retryDelay: (attempt) => Math.min(1000 * 2 ** attempt, 30_000),
|
|
37
41
|
});
|
|
38
42
|
};
|
|
39
43
|
|
|
@@ -67,7 +71,10 @@ export const useCaseMessages = (
|
|
|
67
71
|
return ta - tb;
|
|
68
72
|
}),
|
|
69
73
|
enabled: !!organizationId && !!workspaceId && !!caseUuid && !!consentClient,
|
|
70
|
-
retry
|
|
74
|
+
// Don't retry terminal auth failures — retrying a dead token only adds load
|
|
75
|
+
// (incident 2026-06-22). Transient failures get a single backed-off retry.
|
|
76
|
+
retry: (failureCount, error) => !isTerminalRefreshError(error) && failureCount < 1,
|
|
77
|
+
retryDelay: (attempt) => Math.min(1000 * 2 ** attempt, 30_000),
|
|
71
78
|
});
|
|
72
79
|
};
|
|
73
80
|
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { ensureValidToken, isRefreshBlocked, resetRefreshCircuit } from './utils';
|
|
3
|
+
import { ApiError } from '../api/fetcher';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Regression tests for the OTP refresh circuit breaker.
|
|
7
|
+
*
|
|
8
|
+
* Production incident 2026-06-22: an embedded Privacy Center retry-looped a dead
|
|
9
|
+
* refresh token, sending ~9× the normal volume of `POST /otp/refresh` (all fast
|
|
10
|
+
* terminal rejections) and spiking consent-server CPU. ensureValidToken is the
|
|
11
|
+
* single chokepoint for every refresh — these tests pin the guarantee that a
|
|
12
|
+
* terminally-failed token is attempted exactly once until the user re-authenticates,
|
|
13
|
+
* and that transient failures back off instead of hammering.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
// Minimal JWT with a chosen `exp`. The signature is irrelevant — the SDK only
|
|
17
|
+
// base64-decodes the payload to read `exp`.
|
|
18
|
+
const base64url = (obj: unknown) => btoa(JSON.stringify(obj)).replace(/=+$/, '');
|
|
19
|
+
const makeJwt = (expSeconds: number) =>
|
|
20
|
+
`${base64url({ alg: 'HS256', typ: 'JWT' })}.${base64url({ exp: expSeconds })}.sig`;
|
|
21
|
+
|
|
22
|
+
// `exp` in 1970 — always treated as expired, so ensureValidToken always takes the
|
|
23
|
+
// refresh path regardless of wall-clock / fake timers.
|
|
24
|
+
const EXPIRED_ACCESS_TOKEN = makeJwt(1_000);
|
|
25
|
+
const ORG = 'org-uuid';
|
|
26
|
+
const WS = 'ws-uuid';
|
|
27
|
+
|
|
28
|
+
const makeConsentClient = (
|
|
29
|
+
refreshOtpToken: (orgId: string, wsId: string, refreshToken: string) => Promise<unknown>
|
|
30
|
+
) => ({ refreshOtpToken: vi.fn(refreshOtpToken) }) as any;
|
|
31
|
+
|
|
32
|
+
const makeAuthContext = (refreshToken: string) => ({
|
|
33
|
+
accessToken: EXPIRED_ACCESS_TOKEN,
|
|
34
|
+
refreshToken,
|
|
35
|
+
// Return false so the SDK suppresses navigation (jsdom can't navigate). The
|
|
36
|
+
// circuit breaker trips before onError is consulted, which is what we assert.
|
|
37
|
+
onError: vi.fn(() => false),
|
|
38
|
+
updateTokens: vi.fn(),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('ensureValidToken — OTP refresh circuit breaker (incident 2026-06-22)', () => {
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
resetRefreshCircuit();
|
|
44
|
+
sessionStorage.clear();
|
|
45
|
+
vi.clearAllMocks();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
afterEach(() => {
|
|
49
|
+
vi.useRealTimers();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('attempts a terminally-failed refresh token exactly once across many calls', async () => {
|
|
53
|
+
const client = makeConsentClient(() =>
|
|
54
|
+
Promise.reject(new ApiError('Token verification error: Refresh token has expired', { status: 401 }))
|
|
55
|
+
);
|
|
56
|
+
const authContext = makeAuthContext('dead-refresh-token');
|
|
57
|
+
|
|
58
|
+
// Simulate the 3 pollers + every API call + render-driven effects all hitting
|
|
59
|
+
// the path while the token is dead.
|
|
60
|
+
const results: Array<string | null> = [];
|
|
61
|
+
for (let i = 0; i < 25; i++) {
|
|
62
|
+
results.push(await ensureValidToken(ORG, WS, undefined, authContext, client));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
expect(results.every((r) => r === null)).toBe(true);
|
|
66
|
+
expect(client.refreshOtpToken).toHaveBeenCalledTimes(1);
|
|
67
|
+
expect(isRefreshBlocked(authContext)).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('treats "not found / already used" (T0) as terminal, not retryable', async () => {
|
|
71
|
+
const client = makeConsentClient(() =>
|
|
72
|
+
Promise.reject(new ApiError('Refresh token not found or already used', { status: 401 }))
|
|
73
|
+
);
|
|
74
|
+
const authContext = makeAuthContext('already-used-token');
|
|
75
|
+
|
|
76
|
+
await ensureValidToken(ORG, WS, undefined, authContext, client);
|
|
77
|
+
await ensureValidToken(ORG, WS, undefined, authContext, client);
|
|
78
|
+
|
|
79
|
+
expect(client.refreshOtpToken).toHaveBeenCalledTimes(1);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('resumes refreshing once a new refresh token value appears', async () => {
|
|
83
|
+
const validAccess = makeJwt(Math.floor(Date.now() / 1000) + 3600);
|
|
84
|
+
const client = makeConsentClient((_org, _ws, token) =>
|
|
85
|
+
token === 'dead-refresh-token'
|
|
86
|
+
? Promise.reject(new ApiError('Refresh token has expired', { status: 401 }))
|
|
87
|
+
: Promise.resolve({ access_token: validAccess, refresh_token: 'rotated' })
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const deadCtx = makeAuthContext('dead-refresh-token');
|
|
91
|
+
await ensureValidToken(ORG, WS, undefined, deadCtx, client);
|
|
92
|
+
await ensureValidToken(ORG, WS, undefined, deadCtx, client);
|
|
93
|
+
expect(client.refreshOtpToken).toHaveBeenCalledTimes(1); // breaker held the loop
|
|
94
|
+
|
|
95
|
+
// User re-authenticated → a *different* refresh token value re-arms the breaker.
|
|
96
|
+
const freshCtx = makeAuthContext('fresh-refresh-token');
|
|
97
|
+
const token = await ensureValidToken(ORG, WS, undefined, freshCtx, client);
|
|
98
|
+
|
|
99
|
+
expect(client.refreshOtpToken).toHaveBeenCalledTimes(2);
|
|
100
|
+
expect(token).toBe(validAccess);
|
|
101
|
+
expect(isRefreshBlocked(freshCtx)).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('backs off after a transient failure instead of retrying immediately', async () => {
|
|
105
|
+
vi.useFakeTimers();
|
|
106
|
+
vi.setSystemTime(new Date('2026-06-22T11:00:00Z'));
|
|
107
|
+
|
|
108
|
+
const client = makeConsentClient(() =>
|
|
109
|
+
Promise.reject(new ApiError('Service Unavailable', { status: 503 }))
|
|
110
|
+
);
|
|
111
|
+
const authContext = makeAuthContext('flaky-refresh-token');
|
|
112
|
+
|
|
113
|
+
await ensureValidToken(ORG, WS, undefined, authContext, client);
|
|
114
|
+
await ensureValidToken(ORG, WS, undefined, authContext, client);
|
|
115
|
+
await ensureValidToken(ORG, WS, undefined, authContext, client);
|
|
116
|
+
|
|
117
|
+
// One attempt, then the backoff window suppresses the rest (no token-marking —
|
|
118
|
+
// a 5xx is transient, so the token is NOT permanently dead).
|
|
119
|
+
expect(client.refreshOtpToken).toHaveBeenCalledTimes(1);
|
|
120
|
+
expect(isRefreshBlocked(authContext)).toBe(true);
|
|
121
|
+
|
|
122
|
+
// Once the backoff window elapses, a later call is allowed to retry.
|
|
123
|
+
vi.advanceTimersByTime(31_000); // > MIN_REFRESH_BACKOFF_MS (30s)
|
|
124
|
+
await ensureValidToken(ORG, WS, undefined, authContext, client);
|
|
125
|
+
expect(client.refreshOtpToken).toHaveBeenCalledTimes(2);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
setRefreshTokenCookie,
|
|
5
|
+
getStoredRefreshToken,
|
|
6
|
+
signOutPrivacyCenter,
|
|
7
|
+
} from './utils';
|
|
8
|
+
|
|
9
|
+
const STORAGE_KEY = 'redacto_pc_refresh_token';
|
|
10
|
+
|
|
11
|
+
const expireLegacyCookie = (): void => {
|
|
12
|
+
document.cookie =
|
|
13
|
+
'refresh_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT';
|
|
14
|
+
document.cookie =
|
|
15
|
+
'refresh_token=; path=/privacy-center; expires=Thu, 01 Jan 1970 00:00:00 GMT';
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe('privacy center refresh token persistence', () => {
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
window.localStorage.clear();
|
|
21
|
+
expireLegacyCookie();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
vi.restoreAllMocks();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('persists the refresh token in localStorage (path-independent) and writes no cookie', () => {
|
|
29
|
+
// A path-scoped cookie is unreadable when the host mounts under a basePath
|
|
30
|
+
// (e.g. consent-app at /consent), which strands rotated tokens and triggers
|
|
31
|
+
// the 401 refresh storm. localStorage is origin-scoped, so it is readable
|
|
32
|
+
// regardless of basePath.
|
|
33
|
+
setRefreshTokenCookie('tok123');
|
|
34
|
+
|
|
35
|
+
expect(window.localStorage.getItem(STORAGE_KEY)).toBe('tok123');
|
|
36
|
+
expect(getStoredRefreshToken()).toBe('tok123');
|
|
37
|
+
expect(document.cookie).not.toContain('refresh_token=tok123');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('returns null when no refresh token is stored', () => {
|
|
41
|
+
expect(getStoredRefreshToken()).toBeNull();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('does not ingest a host app refresh_token cookie', () => {
|
|
45
|
+
// A cookie read is name-only (JS cannot see the path), so the SDK cannot tell
|
|
46
|
+
// a host app's own refresh_token cookie from its own legacy one. It must not
|
|
47
|
+
// read the cookie at all: it neither migrates the value nor deletes the
|
|
48
|
+
// cookie. (Existing SDK sessions are preserved via the AuthProvider token
|
|
49
|
+
// prop, not the cookie.)
|
|
50
|
+
document.cookie = 'refresh_token=hosttoken; path=/';
|
|
51
|
+
|
|
52
|
+
const token = getStoredRefreshToken();
|
|
53
|
+
|
|
54
|
+
expect(token).toBeNull();
|
|
55
|
+
expect(window.localStorage.getItem(STORAGE_KEY)).toBeNull();
|
|
56
|
+
expect(document.cookie).toContain('refresh_token=hosttoken');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('clears the stored refresh token on sign out', () => {
|
|
60
|
+
setRefreshTokenCookie('tok123');
|
|
61
|
+
expect(window.localStorage.getItem(STORAGE_KEY)).toBe('tok123');
|
|
62
|
+
|
|
63
|
+
signOutPrivacyCenter();
|
|
64
|
+
|
|
65
|
+
expect(window.localStorage.getItem(STORAGE_KEY)).toBeNull();
|
|
66
|
+
expect(getStoredRefreshToken()).toBeNull();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('does not throw when localStorage.setItem is unavailable (private mode / quota)', () => {
|
|
70
|
+
vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {
|
|
71
|
+
throw new Error('QuotaExceededError');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
expect(() => setRefreshTokenCookie('tok123')).not.toThrow();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('returns null (no throw) when localStorage.getItem is unavailable', () => {
|
|
78
|
+
vi.spyOn(Storage.prototype, 'getItem').mockImplementation(() => {
|
|
79
|
+
throw new Error('SecurityError');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
expect(() => getStoredRefreshToken()).not.toThrow();
|
|
83
|
+
expect(getStoredRefreshToken()).toBeNull();
|
|
84
|
+
});
|
|
85
|
+
});
|