import {z} from 'zod' export type CustomerServiceRecordX = {id?: string | undefined, firstName?: string | undefined, middleInitial?: string | undefined, lastName?: string | undefined, businessName?: string | undefined, streetNumber?: string | undefined, streetNumberSuffix?: string | undefined, preDirectional?: ('' | 'N' | 'NE' | 'E' | 'SE' | 'S' | 'SW' | 'W' | 'NW') | undefined, streetName?: string | undefined, streetSuffix?: string | undefined, postDirectional?: ('' | 'N' | 'NE' | 'E' | 'SE' | 'S' | 'SW' | 'W' | 'NW') | undefined, city?: string | undefined, state?: string | undefined, country?: string | undefined, postalCode?: string | undefined, secondaryLocationDescription?: ('' | 'APARTMENT' | 'BUILDING' | 'BASEMENT' | 'DEPARTMENT' | 'FLOOR' | 'FRONT' | 'HANGER' | 'KEY' | 'LOBBY' | 'LOT' | 'LOWER' | 'OFFICE' | 'PENTHOUSE' | 'PIER' | 'REAR' | 'ROOM' | 'SIDE' | 'SLIP' | 'SPACE' | 'SUITE' | 'STOP' | 'TRAILER' | 'UNIT' | 'UPPER') | undefined, unit?: string | undefined, customerType?: ('BUSINESS' | 'RESIDENTIAL') | undefined, firstNameSecondary?: string | undefined, blockCustomerName?: boolean | undefined, customerName?: string | undefined}; export type E911AddressX = {id?: string | undefined, firstName?: string | undefined, middleInitial?: string | undefined, lastName?: string | undefined, businessName?: string | undefined, streetNumber?: string | undefined, streetNumberSuffix?: string | undefined, preDirectional?: ('' | 'N' | 'NE' | 'E' | 'SE' | 'S' | 'SW' | 'W' | 'NW') | undefined, streetName?: string | undefined, streetSuffix?: string | undefined, postDirectional?: ('' | 'N' | 'NE' | 'E' | 'SE' | 'S' | 'SW' | 'W' | 'NW') | undefined, city?: string | undefined, state?: string | undefined, country?: string | undefined, postalCode?: string | undefined, secondaryLocationDescription?: ('' | 'APARTMENT' | 'BUILDING' | 'BASEMENT' | 'DEPARTMENT' | 'FLOOR' | 'FRONT' | 'HANGER' | 'KEY' | 'LOBBY' | 'LOT' | 'LOWER' | 'OFFICE' | 'PENTHOUSE' | 'PIER' | 'REAR' | 'ROOM' | 'SIDE' | 'SLIP' | 'SPACE' | 'SUITE' | 'STOP' | 'TRAILER' | 'UNIT' | 'UPPER') | undefined, unit?: string | undefined, customerType?: ('BUSINESS' | 'RESIDENTIAL') | undefined, latitude?: string | undefined, longitude?: string | undefined, language?: string | undefined}; export type ExternalTnX = {phoneNumber?: string | undefined, partitionId?: string | undefined, accountId?: string | undefined, userId?: string | undefined, inboundCarrierId?: string | undefined, functionType?: string | undefined, cnam?: string | undefined, customerServiceRecord?: CustomerServiceRecordX | undefined, e911Address?: E911AddressX | undefined, callable?: boolean | undefined, id?: string | undefined}; export type CreateApiV2PartitionPartitionIdAccountAccountIdTelephonenumberExternalArgs = {accountId: string, partitionId: string, body: ExternalTnX}; export type CreateApiV2PartitionPartitionIdAccountAccountIdTelephonenumberExternalOptions = {baseUrl?: string | undefined, XAuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const customerServiceRecordX = z.object({id: z.string().optional(), firstName: z.string().min(1).max(256).optional(), middleInitial: z.string().max(256).optional(), lastName: z.string().max(256).optional(), businessName: z.string().max(256).optional(), streetNumber: z.string().optional(), streetNumberSuffix: z.string().optional(), preDirectional: z.enum(["", "N", "NE", "E", "SE", "S", "SW", "W", "NW"]).optional(), streetName: z.string().max(256).optional(), streetSuffix: z.string().optional(), postDirectional: z.enum(["", "N", "NE", "E", "SE", "S", "SW", "W", "NW"]).optional(), city: z.string().max(256).optional(), state: z.string().optional(), country: z.string().optional(), postalCode: z.string().optional(), secondaryLocationDescription: z.enum(["", "APARTMENT", "BUILDING", "BASEMENT", "DEPARTMENT", "FLOOR", "FRONT", "HANGER", "KEY", "LOBBY", "LOT", "LOWER", "OFFICE", "PENTHOUSE", "PIER", "REAR", "ROOM", "SIDE", "SLIP", "SPACE", "SUITE", "STOP", "TRAILER", "UNIT", "UPPER"]).optional(), unit: z.string().max(10).optional(), customerType: z.enum(["BUSINESS", "RESIDENTIAL"]).optional(), firstNameSecondary: z.string().optional(), blockCustomerName: z.boolean().optional(), customerName: z.string().optional()}); export const e911AddressX = z.object({id: z.string().optional(), firstName: z.string().optional(), middleInitial: z.string().optional(), lastName: z.string().optional(), businessName: z.string().optional(), streetNumber: z.string().optional(), streetNumberSuffix: z.string().optional(), preDirectional: z.enum(["", "N", "NE", "E", "SE", "S", "SW", "W", "NW"]).optional(), streetName: z.string().optional(), streetSuffix: z.string().optional(), postDirectional: z.enum(["", "N", "NE", "E", "SE", "S", "SW", "W", "NW"]).optional(), city: z.string().optional(), state: z.string().optional(), country: z.string().optional(), postalCode: z.string().optional(), secondaryLocationDescription: z.enum(["", "APARTMENT", "BUILDING", "BASEMENT", "DEPARTMENT", "FLOOR", "FRONT", "HANGER", "KEY", "LOBBY", "LOT", "LOWER", "OFFICE", "PENTHOUSE", "PIER", "REAR", "ROOM", "SIDE", "SLIP", "SPACE", "SUITE", "STOP", "TRAILER", "UNIT", "UPPER"]).optional(), unit: z.string().optional(), customerType: z.enum(["BUSINESS", "RESIDENTIAL"]).optional(), latitude: z.string().optional(), longitude: z.string().optional(), language: z.string().optional()}); export const externalTnX = z.object({phoneNumber: z.string().optional(), partitionId: z.string().optional(), accountId: z.string().optional(), userId: z.string().optional(), inboundCarrierId: z.string().optional(), functionType: z.string().optional(), cnam: z.string().optional(), customerServiceRecord: customerServiceRecordX.optional(), e911Address: e911AddressX.optional(), callable: z.boolean().optional(), id: 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 }; /** * Create or updates already activated telephone number to an account * * POST /v2/partition/{partitionId}/account/{accountId}/telephonenumber/external */ export const createApiV2PartitionPartitionIdAccountAccountIdTelephonenumberExternal = async (args: CreateApiV2PartitionPartitionIdAccountAccountIdTelephonenumberExternalArgs, options?: CreateApiV2PartitionPartitionIdAccountAccountIdTelephonenumberExternalOptions) => { const {baseUrl = "https://api.alianza.com", fetch: fetchFn = fetch, XAuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (XAuthToken !== undefined) headers.set("X-AUTH-TOKEN", XAuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/v2/partition/${encodeURIComponent(String(args.partitionId))}/account/${encodeURIComponent(String(args.accountId))}/telephonenumber/external${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(externalTnX, await res.json()) };