import {z} from 'zod' export type CreateApiEnterprisesEnterpriseIdBrandedCallingArgs = {enterprise_id: string}; export type CreateApiEnterprisesEnterpriseIdBrandedCallingOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const organizationContact = z.object({first_name: z.string().max(255), last_name: z.string().max(255), email: z.string(), job_title: z.string().max(255), phone_number: z.string()}); export const billingContact = z.object({first_name: z.string().max(255), last_name: z.string().max(255), email: z.string(), phone_number: z.string()}); export const physicalAddress = z.object({country: z.string(), administrative_area: z.string(), city: z.string().max(100), postal_code: z.string().max(20), street_address: z.string().max(255), extended_address: z.string().max(255).nullable().optional()}); export const billingAddress = z.object({country: z.string(), administrative_area: z.string(), city: z.string().max(100), postal_code: z.string().max(20), street_address: z.string().max(255), extended_address: z.string().max(255).nullable().optional()}); export const enterprisePublic = z.object({id: z.string().optional(), legal_name: z.string().optional(), organization_type: z.string().optional(), country_code: z.string().optional(), role_type: z.enum(["enterprise", "bpo"]).optional(), website: z.string().optional(), fein: z.string().optional(), industry: z.string().optional(), number_of_employees: z.string().optional(), organization_legal_type: z.string().optional(), doing_business_as: z.string().optional(), jurisdiction_of_incorporation: z.string().optional(), customer_reference: z.string().optional(), primary_business_domain_sic_code: z.string().nullable().optional(), corporate_registration_number: z.string().nullable().optional(), professional_license_number: z.string().nullable().optional(), dun_bradstreet_number: z.string().nullable().optional(), organization_contact: organizationContact.optional(), billing_contact: billingContact.optional(), organization_physical_address: physicalAddress.optional(), billing_address: billingAddress.optional(), created_at: z.string().optional(), updated_at: z.string().optional(), branded_calling_enabled: z.boolean().optional(), number_reputation_enabled: z.boolean().optional(), bpo_verification_status: z.enum(["pending", "approved", "rejected"]).nullable().optional(), bpo_verification_rejection_reason: z.string().nullable().optional()}); export const enterprisePublicWrapped = z.object({data: enterprisePublic}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Activate Branded Calling on an enterprise * * POST /enterprises/{enterprise_id}/branded_calling */ export const createApiEnterprisesEnterpriseIdBrandedCalling = async (args: CreateApiEnterprisesEnterpriseIdBrandedCallingArgs, options?: CreateApiEnterprisesEnterpriseIdBrandedCallingOptions) => { const {baseUrl = "https://api.telnyx.com/v2", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/enterprises/${encodeURIComponent(String(args.enterprise_id))}/branded_calling${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(enterprisePublicWrapped, await res.json()) };