import {z} from 'zod' export type EntityType = 'PRIVATE_PROFIT' | 'PUBLIC_PROFIT' | 'NON_PROFIT' | 'GOVERNMENT' | 'SOLE_PROPRIETOR'; export type StockExchange = 'NONE' | 'NASDAQ' | 'NYSE' | 'AMEX' | 'AMX' | 'ASX' | 'B3' | 'BME' | 'BSE' | 'FRA' | 'ICEX' | 'JPX' | 'JSE' | 'KRX' | 'LON' | 'NSE' | 'OMX' | 'SEHK' | 'SSE' | 'STO' | 'SWX' | 'SZSE' | 'TSX' | 'TWSE' | 'VSE'; export type Vertical = 'AGRICULTURE' | 'COMMUNICATION' | 'CONSTRUCTION' | 'EDUCATION' | 'ENERGY' | 'ENTERTAINMENT' | 'FINANCIAL' | 'GAMBLING' | 'GOVERNMENT' | 'HEALTHCARE' | 'HOSPITALITY' | 'HUMAN_RESOURCES' | 'INSURANCE' | 'LEGAL' | 'MANUFACTURING' | 'NGO' | 'POLITICAL' | 'POSTAL' | 'PROFESSIONAL' | 'REAL_ESTATE' | 'RETAIL' | 'TECHNOLOGY' | 'TRANSPORTATION'; export type AltBusinessIdType = 'NONE' | 'DUNS' | 'GIIN' | 'LEI'; export type BrandIdentityStatus = 'VERIFIED' | 'UNVERIFIED' | 'SELF_DECLARED' | 'VETTED_VERIFIED'; export type UpdateBrand = {entityType: EntityType, displayName: string, companyName?: string | undefined, firstName?: string | undefined, lastName?: string | undefined, ein?: string | undefined, phone?: string | undefined, street?: string | undefined, city?: string | undefined, state?: string | undefined, postalCode?: string | undefined, country: string, email: string, stockSymbol?: string | undefined, stockExchange?: StockExchange | undefined, ipAddress?: string | undefined, website?: string | undefined, vertical: Vertical, altBusinessIdType?: AltBusinessIdType | undefined, isReseller?: boolean | undefined, identityStatus?: BrandIdentityStatus | undefined, businessContactEmail?: string | undefined, webhookURL?: string | undefined, webhookFailoverURL?: string | undefined, altBusinessId?: string | undefined}; export type UpdateApi10dlcBrandBrandIdArgs = {brandId: string, body: UpdateBrand}; export type UpdateApi10dlcBrandBrandIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const entityType = z.enum(["PRIVATE_PROFIT", "PUBLIC_PROFIT", "NON_PROFIT", "GOVERNMENT", "SOLE_PROPRIETOR"]); export const stockExchange = z.enum(["NONE", "NASDAQ", "NYSE", "AMEX", "AMX", "ASX", "B3", "BME", "BSE", "FRA", "ICEX", "JPX", "JSE", "KRX", "LON", "NSE", "OMX", "SEHK", "SSE", "STO", "SWX", "SZSE", "TSX", "TWSE", "VSE"]); export const brandRelationship = z.enum(["BASIC_ACCOUNT", "SMALL_ACCOUNT", "MEDIUM_ACCOUNT", "LARGE_ACCOUNT", "KEY_ACCOUNT"]); export const altBusinessIdType = z.enum(["NONE", "DUNS", "GIIN", "LEI"]); export const brandIdentityStatus = z.enum(["VERIFIED", "UNVERIFIED", "SELF_DECLARED", "VETTED_VERIFIED"]); export const brandOptionalAttributes = z.object({taxExemptStatus: z.string().optional()}); export const telnyxBrand = z.object({entityType: entityType, cspId: z.string().optional(), brandId: z.string().optional(), tcrBrandId: z.string().optional(), displayName: z.string().max(100), companyName: z.string().max(100).optional(), firstName: z.string().max(100).optional(), lastName: z.string().max(100).optional(), ein: z.string().max(20).optional(), phone: z.string().max(20).optional(), street: z.string().max(100).optional(), city: z.string().max(100).optional(), state: z.string().max(20).optional(), postalCode: z.string().max(10).optional(), country: z.string().max(2), email: z.string().max(100), stockSymbol: z.string().max(10).optional(), stockExchange: stockExchange.optional(), ipAddress: z.string().max(50).optional(), website: z.string().max(100).optional(), brandRelationship: brandRelationship, vertical: z.string().max(50), altBusinessId: z.string().max(50).optional(), altBusinessIdType: altBusinessIdType.optional(), universalEin: z.string().optional(), referenceId: z.string().optional(), identityStatus: brandIdentityStatus.optional(), optionalAttributes: brandOptionalAttributes.optional(), mock: z.boolean().optional(), mobilePhone: z.string().max(20).optional(), isReseller: z.boolean().optional(), webhookURL: z.string().optional(), businessContactEmail: z.string().optional(), webhookFailoverURL: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), status: z.enum(["OK", "REGISTRATION_PENDING", "REGISTRATION_FAILED"]).optional(), failureReasons: z.string().optional()}); 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 }; /** * Update Brand * * PUT /10dlc/brand/{brandId} */ export const updateApi10dlcBrandBrandId = async (args: UpdateApi10dlcBrandBrandIdArgs, options?: UpdateApi10dlcBrandBrandIdOptions) => { const {baseUrl = "https://api.telnyx.com/v2", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/10dlc/brand/${encodeURIComponent(String(args.brandId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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 validateResponse(telnyxBrand, await res.json()) };