1 import { put, takeEvery } from 'redux-saga/effects';
3 import { parseItemRevision } from '@proton/pass/lib/items/item.parser';
4 import { updateItemLastUseTime } from '@proton/pass/lib/items/item.requests';
5 import { itemAutofilled, itemsEditSync } from '@proton/pass/store/actions';
6 import type { RootSagaOptions } from '@proton/pass/store/types';
7 import type { ItemRevision, ItemRevisionContentsResponse } from '@proton/pass/types';
8 import { logId, logger } from '@proton/pass/utils/logger';
10 function* itemAutofilledWorker(
11 { onItemsUpdated }: RootSagaOptions,
12 { payload: { shareId, itemId } }: ReturnType<typeof itemAutofilled>
15 logger.info(`[Item::Autofill] used item ${logId(itemId)} on share ${logId(shareId)}`);
16 onItemsUpdated?.(); /* will re-order items for autofill suggestions */
18 const encryptedItem: ItemRevisionContentsResponse = yield updateItemLastUseTime(shareId, itemId);
19 const item: ItemRevision = yield parseItemRevision(shareId, encryptedItem);
20 yield put(itemsEditSync([item]));
21 } catch (err: unknown) {
23 `[Item::Autofill] lastUseTime update failed for item ${logId(itemId)} on share ${logId(shareId)}`,
29 export default function* watcher(options: RootSagaOptions) {
30 yield takeEvery(itemAutofilled.match, itemAutofilledWorker, options);