export type SecureEmailForCardDetailsRequest = {recipient_email: string, sender_name: string, message?: (string | null) | undefined, expiry_days?: (number | null) | undefined}; export type CreateApiV2CardsIdSecureEmailArgs = {id: string, 'Idempotency-Key': string, body: SecureEmailForCardDetailsRequest}; export type CreateApiV2CardsIdSecureEmailOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * * Create secure email to send card number * * * POST /v2/cards/{id}/secure_email */ export const createApiV2CardsIdSecureEmail = async (args: CreateApiV2CardsIdSecureEmailArgs, options?: CreateApiV2CardsIdSecureEmailOptions) => { const {baseUrl = "https://api.brex.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/cards/${encodeURIComponent(String(args.id))}/secure_email${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };