1 import type { Reducer } from 'redux';
3 import { MAX_PASSWORD_HISTORY_RETENTION_WEEKS } from '@proton/pass/constants';
7 passwordHistoryGarbageCollect,
9 } from '@proton/pass/store/actions/creators/password';
10 import type { MaybeNull } from '@proton/pass/types';
11 import { UNIX_WEEK } from '@proton/pass/utils/time/constants';
12 import { getEpoch } from '@proton/pass/utils/time/epoch';
14 export type PasswordHistoryEntry = {
17 origin: MaybeNull<string>;
21 export type PasswordItem = Omit<PasswordHistoryEntry, 'createTime' | 'id'>;
23 export type PasswordHistoryState = PasswordHistoryEntry[];
25 const reducer: Reducer<PasswordHistoryState> = (state = [], action) => {
26 if (passwordSave.match(action)) return [action.payload, ...state];
27 if (passwordDelete.match(action)) return state.filter(({ id }) => id !== action.payload.id);
28 if (passwordHistoryClear.match(action)) return [];
30 if (passwordHistoryGarbageCollect.match(action)) {
31 const limit = getEpoch() - UNIX_WEEK * MAX_PASSWORD_HISTORY_RETENTION_WEEKS;
32 return state.filter(({ createTime }) => createTime > limit);
38 export default reducer;