1 import type { APP_NAMES } from '@proton/shared/lib/constants';
2 import { APPS } from '@proton/shared/lib/constants';
4 import { captureMessage } from '../helpers/sentry';
6 export const otherProductParamValues = ['generic', 'business'] as const;
7 export type OtherProductParam = (typeof otherProductParamValues)[number];
8 export type ProductParam = APP_NAMES | OtherProductParam | undefined;
10 export const normalizeProduct = (product: ProductParam) => {
15 // proton-mail -> mail
16 // proton-vpn-settings -> vpn
17 if (product === APPS.PROTONVPN_SETTINGS) {
20 // Docs is a sub-product of drive and doesn't have its own attribution as of now, so use drive
21 if (product === APPS.PROTONDOCS) {
24 return product.replace('proton-', '');
27 export interface ProductHeaderContext {
30 emptyProduct?: boolean;
33 function notifySentry(normalizedProduct: string | undefined, context?: ProductHeaderContext) {
34 const isAllowed = ['generic', 'mail', 'drive', 'calendar', 'vpn', 'business', 'pass', 'wallet'].includes(
35 '' + normalizedProduct
38 captureMessage('Wrong product header', { level: 'error', extra: { normalizedProduct, context } });
42 export const getProductHeaders = (product: ProductParam, context?: ProductHeaderContext) => {
44 notifySentry(undefined, {
50 const normalizedProduct = normalizeProduct(product);
51 notifySentry(normalizedProduct, context);
53 return { 'x-pm-product': normalizedProduct };