import {z} from 'zod' export type TrusthubV1A2pBrandRegistrationRequest = {brandType: 'STANDARD' | 'SOLE_PROPRIETOR', themeSetId?: string | undefined, friendlyName?: string | undefined, notificationEmail: string, businessName?: string | undefined, businessRegistrationAuthority?: string | undefined, businessRegistrationNumber?: string | undefined, businessIndustry?: string | undefined, businessWebsite?: string | undefined, businessType?: string | undefined, businessStockSymbol?: string | undefined, businessStockExchange?: string | undefined, businessTaxExemptStatus?: string | undefined, brandExternalVettingToken?: string | undefined, businessStreetAddress?: string | undefined, businessStreetAddress2?: string | undefined, businessCity?: string | undefined, businessStateProvinceRegion?: string | undefined, businessPostalCode?: string | undefined, businessCountry?: string | undefined, businessContactFirstName?: string | undefined, businessContactLastName?: string | undefined, businessContactEmail?: string | undefined, businessContactPhone?: unknown | undefined, authorizedContactVerificationEmail?: string | undefined, authorizedContactMobilePhoneNumberE164?: unknown | undefined, isTest?: boolean | undefined, skipAutomaticSecVet?: boolean | undefined}; export type CreateApiV1A2PBrandRegistrationsArgs = {body: TrusthubV1A2pBrandRegistrationRequest}; export type CreateApiV1A2PBrandRegistrationsOptions = {baseUrl?: string | undefined, accountSidAuthToken?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const trusthubV1A2pEmbeddedSession = z.object({id: z.string(), sessionId: z.string(), sessionToken: z.string()}); 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 }; /** * Create an A2P Brand Registration * * POST /v1/A2PBrandRegistrations */ export const createApiV1A2PBrandRegistrations = async (args: CreateApiV1A2PBrandRegistrationsArgs, options?: CreateApiV1A2PBrandRegistrationsOptions) => { const {baseUrl = "https://trusthub.twilio.com", fetch: fetchFn = fetch, accountSidAuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (accountSidAuthToken !== undefined) headers.set('authorization', `Basic ${btoa(`${accountSidAuthToken.username}:${accountSidAuthToken.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/A2PBrandRegistrations${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 validateResponse(trusthubV1A2pEmbeddedSession, await res.json()) };