1 import { MAX_BATCH_PER_REQUEST } from '@proton/pass/constants';
2 import { api } from '@proton/pass/lib/api/api';
3 import type { ItemMarkAsReadRequest } from '@proton/pass/types';
4 import { type B2BEvent, B2BEventName } from '@proton/pass/types/data/b2b';
5 import { groupByKey } from '@proton/pass/utils/array/group-by-key';
6 import type { EventBundle } from '@proton/pass/utils/event/dispatcher';
7 import chunk from '@proton/utils/chunk';
9 import { isB2BEvent } from './b2b.utils';
11 export const sendItemReadEvents = async (events: B2BEvent<B2BEventName.ItemRead>[]) =>
13 groupByKey(events, 'shareId').map((events) => {
14 const batches = chunk(events, MAX_BATCH_PER_REQUEST);
17 batches.map((batch) => {
18 const { shareId } = batch[0];
20 const ItemTimes = batch.map<ItemMarkAsReadRequest>((event) => ({
22 Timestamp: event.timestamp,
26 url: `pass/v1/share/${shareId}/item/read`,
35 export const sendB2BEventsBundle = async ({ events }: EventBundle<B2BEvent>): Promise<void> => {
36 await sendItemReadEvents(events.filter(isB2BEvent(B2BEventName.ItemRead)));