1 import { sendB2BEventsBundle } from '@proton/pass/lib/b2b/b2b.requests';
2 import type { AnyStorage } from '@proton/pass/types';
3 import type { B2BEvent } from '@proton/pass/types/data/b2b';
4 import type { EventDispatcher, EventDispatcherAlarm } from '@proton/pass/utils/event/dispatcher';
5 import { createEventDispatcher } from '@proton/pass/utils/event/dispatcher';
6 import { UNIX_HOUR, UNIX_MINUTE } from '@proton/pass/utils/time/constants';
7 import { getEpoch } from '@proton/pass/utils/time/epoch';
9 type B2BDispatcherOptions<StorageKey extends string> = {
10 alarm: EventDispatcherAlarm;
11 storage: AnyStorage<Record<StorageKey, string>>;
12 getEnabled: () => boolean;
13 getStorageKey: () => StorageKey;
16 export const createB2BEventDispatcher = <StorageKey extends string>({
21 }: B2BDispatcherOptions<StorageKey>) =>
22 createEventDispatcher<B2BEvent, StorageKey>({
27 dispatch: sendB2BEventsBundle,
29 getSendTime: () => getEpoch() + (ENV === 'production' ? UNIX_HOUR : UNIX_MINUTE),
33 export type B2BEventDispatcher = EventDispatcher<B2BEvent>;