import type { EnvelopeItem } from '@prisma/client'; import { NEXT_PUBLIC_WEBAPP_URL } from '../constants/app'; export type EnvelopeItemPdfUrlOptions = | { type: 'download'; envelopeItem: Pick; token: string | undefined; version: 'original' | 'signed'; } | { type: 'view'; envelopeItem: Pick; token: string | undefined; }; export const getEnvelopeItemPdfUrl = (options: EnvelopeItemPdfUrlOptions) => { const { envelopeItem, token, type } = options; const { id, envelopeId } = envelopeItem; if (type === 'download') { const version = options.version; return token ? `${NEXT_PUBLIC_WEBAPP_URL()}/api/files/token/${token}/envelopeItem/${id}/download/${version}` : `${NEXT_PUBLIC_WEBAPP_URL()}/api/files/envelope/${envelopeId}/envelopeItem/${id}/download/${version}`; } return token ? `${NEXT_PUBLIC_WEBAPP_URL()}/api/files/token/${token}/envelopeItem/${id}` : `${NEXT_PUBLIC_WEBAPP_URL()}/api/files/envelope/${envelopeId}/envelopeItem/${id}`; };