1 import { api } from '@proton/pass/lib/api/api';
2 import type { OrganizationState } from '@proton/pass/store/reducers/organization';
3 import type { MaybeNull, OrganizationGetResponse } from '@proton/pass/types';
4 import type { OrganizationSettings } from '@proton/pass/types/data/organization';
5 import { logger } from '@proton/pass/utils/logger';
6 import { getOrganization as coreGetOrganization } from '@proton/shared/lib/api/organization';
7 import type { Organization } from '@proton/shared/lib/interfaces';
9 export const getUserOrganization = async (): Promise<MaybeNull<Organization>> => {
11 logger.info(`[User] Syncing organization info`);
12 return (await api<{ Organization: Organization }>(coreGetOrganization())).Organization;
18 export const getOrganizationSettings = async (): Promise<OrganizationGetResponse> =>
19 (await api({ url: 'pass/v1/organization', method: 'get' })).Organization!;
21 export const setOrganizationSettings = async (
22 settings: Partial<OrganizationSettings>
23 ): Promise<OrganizationGetResponse> =>
26 url: 'pass/v1/organization/settings',
32 export const getOrganization = async (): Promise<MaybeNull<OrganizationState>> => {
33 const organization = await getUserOrganization();
34 if (!organization) return null;
36 const { Settings, CanUpdate }: OrganizationGetResponse = await getOrganizationSettings();