@redacto.io/consent-sdk-react 9.3.0 → 9.4.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 +12 -12
- package/CHANGELOG.md +13 -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 +5 -1
- package/dist/privacy-center.d.ts +5 -1
- package/dist/privacy-center.js +2958 -2583
- package/dist/privacy-center.mjs +2666 -2285
- 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/AppShell/AppShell.tsx +5 -0
- package/src/RedactoPrivacyCenter/components/AppShell/UserMenu.tsx +6 -16
- package/src/RedactoPrivacyCenter/components/AppShell/usePrivacyCenterExitAction.ts +36 -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/PrivacyCenterSessionExpired.tsx +97 -0
- package/src/RedactoPrivacyCenter/components/constant.ts +25 -0
- package/src/RedactoPrivacyCenter/components/types.ts +32 -1
- package/src/RedactoPrivacyCenter/context/AuthContext.tsx +23 -2
- package/src/RedactoPrivacyCenter/context/DataAvailabilityContext.session-expired.test.tsx +92 -0
- package/src/RedactoPrivacyCenter/context/DataAvailabilityContext.tsx +15 -3
- package/src/RedactoPrivacyCenter/context/types.ts +4 -0
- 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.session-expired.test.ts +109 -0
- package/src/RedactoPrivacyCenter/lib/utils.ts +265 -139
- package/src/RedactoPrivacyCenter/locales/as/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/bho/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/bn/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/brx/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/doi/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/en/translation.json +5 -0
- package/src/RedactoPrivacyCenter/locales/gom/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/gu/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/hi/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/kn/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/ks/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/mai/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/ml/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/mr/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/ne/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/or/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/pa/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/sa/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/sat/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/sd/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/ta/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/te/translation.json +2 -0
- package/src/RedactoPrivacyCenter/locales/ur/translation.json +2 -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
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
ensureValidToken,
|
|
4
|
+
resetRefreshCircuit,
|
|
5
|
+
setSessionExpiredListener,
|
|
6
|
+
} from './utils';
|
|
7
|
+
import { ApiError } from '../api/fetcher';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Regression tests for the terminal "session expired" signal.
|
|
11
|
+
*
|
|
12
|
+
* When the refresh token is expired/invalid, the refresh endpoint must be hit at
|
|
13
|
+
* most once (the circuit breaker) AND the React tree must be told the session is
|
|
14
|
+
* over exactly once (so it can show the terminal screen and stop all work). A
|
|
15
|
+
* transient (5xx/network) failure must NOT raise the terminal signal — those are
|
|
16
|
+
* retryable and the user is still signed in.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// Minimal JWT with a chosen `exp` (only the base64 payload is read).
|
|
20
|
+
const base64url = (obj: unknown) => btoa(JSON.stringify(obj)).replace(/=+$/, '');
|
|
21
|
+
const makeJwt = (expSeconds: number) =>
|
|
22
|
+
`${base64url({ alg: 'HS256', typ: 'JWT' })}.${base64url({ exp: expSeconds })}.sig`;
|
|
23
|
+
|
|
24
|
+
// `exp` in 1970 → always expired, so ensureValidToken always takes the refresh path.
|
|
25
|
+
const EXPIRED_ACCESS_TOKEN = makeJwt(1_000);
|
|
26
|
+
const ORG = 'org-uuid';
|
|
27
|
+
const WS = 'ws-uuid';
|
|
28
|
+
|
|
29
|
+
const makeConsentClient = (
|
|
30
|
+
refreshOtpToken: (orgId: string, wsId: string, refreshToken: string) => Promise<unknown>,
|
|
31
|
+
) => ({ refreshOtpToken: vi.fn(refreshOtpToken) }) as any;
|
|
32
|
+
|
|
33
|
+
const makeAuthContext = (refreshToken: string) => ({
|
|
34
|
+
accessToken: EXPIRED_ACCESS_TOKEN,
|
|
35
|
+
refreshToken,
|
|
36
|
+
// Return false (host handles its own navigation). The terminal signal must fire
|
|
37
|
+
// regardless of this return value — that is the behaviour under test.
|
|
38
|
+
onError: vi.fn(() => false),
|
|
39
|
+
updateTokens: vi.fn(),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('ensureValidToken — terminal session-expired signal', () => {
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
resetRefreshCircuit();
|
|
45
|
+
setSessionExpiredListener(null);
|
|
46
|
+
sessionStorage.clear();
|
|
47
|
+
vi.clearAllMocks();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
afterEach(() => {
|
|
51
|
+
setSessionExpiredListener(null);
|
|
52
|
+
vi.useRealTimers();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('fires the session-expired listener exactly once on a terminal failure', async () => {
|
|
56
|
+
const onExpired = vi.fn();
|
|
57
|
+
setSessionExpiredListener(onExpired);
|
|
58
|
+
|
|
59
|
+
const client = makeConsentClient(() =>
|
|
60
|
+
Promise.reject(new ApiError('Refresh token has expired', { status: 401 })),
|
|
61
|
+
);
|
|
62
|
+
const authContext = makeAuthContext('dead-refresh-token');
|
|
63
|
+
|
|
64
|
+
// Many triggers (pollers + API calls + effects) against the same dead token.
|
|
65
|
+
const results: Array<string | null> = [];
|
|
66
|
+
for (let i = 0; i < 10; i++) {
|
|
67
|
+
results.push(await ensureValidToken(ORG, WS, undefined, authContext, client));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
expect(results.every((r) => r === null)).toBe(true);
|
|
71
|
+
// Breaker: the dead refresh token is submitted at most once.
|
|
72
|
+
expect(client.refreshOtpToken).toHaveBeenCalledTimes(1);
|
|
73
|
+
// Terminal signal raised once, even though onError returned false.
|
|
74
|
+
expect(onExpired).toHaveBeenCalledTimes(1);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('does NOT fire the listener for a transient (5xx) failure', async () => {
|
|
78
|
+
vi.useFakeTimers();
|
|
79
|
+
vi.setSystemTime(new Date('2026-06-22T11:00:00Z'));
|
|
80
|
+
|
|
81
|
+
const onExpired = vi.fn();
|
|
82
|
+
setSessionExpiredListener(onExpired);
|
|
83
|
+
|
|
84
|
+
const client = makeConsentClient(() =>
|
|
85
|
+
Promise.reject(new ApiError('Service Unavailable', { status: 503 })),
|
|
86
|
+
);
|
|
87
|
+
const authContext = makeAuthContext('flaky-refresh-token');
|
|
88
|
+
|
|
89
|
+
await ensureValidToken(ORG, WS, undefined, authContext, client);
|
|
90
|
+
await ensureValidToken(ORG, WS, undefined, authContext, client);
|
|
91
|
+
|
|
92
|
+
// One attempt then backoff suppresses the rest — and the session is NOT
|
|
93
|
+
// declared terminally expired (the token may still be valid).
|
|
94
|
+
expect(client.refreshOtpToken).toHaveBeenCalledTimes(1);
|
|
95
|
+
expect(onExpired).not.toHaveBeenCalled();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('tolerates a terminal failure with no listener registered (no throw)', async () => {
|
|
99
|
+
const client = makeConsentClient(() =>
|
|
100
|
+
Promise.reject(new ApiError('Refresh token has expired', { status: 401 })),
|
|
101
|
+
);
|
|
102
|
+
const authContext = makeAuthContext('dead-refresh-token');
|
|
103
|
+
|
|
104
|
+
await expect(
|
|
105
|
+
ensureValidToken(ORG, WS, undefined, authContext, client),
|
|
106
|
+
).resolves.toBeNull();
|
|
107
|
+
expect(client.refreshOtpToken).toHaveBeenCalledTimes(1);
|
|
108
|
+
});
|
|
109
|
+
});
|