import {z} from 'zod' export type AddressBookBulkContactAddressInfo = {country?: string | undefined, state?: string | undefined, city?: string | undefined, street?: string | undefined, zip?: string | undefined}; export type AddressBookBulkContactResource = {email?: string | undefined, notes?: string | undefined, company?: string | undefined, firstName?: string | undefined, lastName?: string | undefined, jobTitle?: string | undefined, birthday?: string | undefined, webPage?: string | undefined, middleName?: string | undefined, nickName?: string | undefined, email2?: string | undefined, email3?: string | undefined, homePhone?: string | undefined, homePhone2?: string | undefined, businessPhone?: string | undefined, businessPhone2?: string | undefined, mobilePhone?: string | undefined, businessFax?: string | undefined, companyPhone?: string | undefined, assistantPhone?: string | undefined, carPhone?: string | undefined, otherPhone?: string | undefined, otherFax?: string | undefined, callbackPhone?: string | undefined, businessAddress?: AddressBookBulkContactAddressInfo | undefined, homeAddress?: AddressBookBulkContactAddressInfo | undefined, otherAddress?: AddressBookBulkContactAddressInfo | undefined}; export type AddressBookBulkUploadResource = {extensionId: string, contacts: Array}; export type AddressBookBulkUploadRequest = {records: Array}; export type CreateApiRestapiV10AccountAccountIdAddressBookBulkUploadArgs = {accountId: string, body: AddressBookBulkUploadRequest}; export type CreateApiRestapiV10AccountAccountIdAddressBookBulkUploadOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const addressBookBulkContactAddressInfo = z.object({country: z.string().optional(), state: z.string().optional(), city: z.string().optional(), street: z.string().optional(), zip: z.string().optional()}); export const addressBookBulkContactResource = z.object({email: z.string().optional(), notes: z.string().optional(), company: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), jobTitle: z.string().optional(), birthday: z.string().optional(), webPage: z.string().optional(), middleName: z.string().optional(), nickName: z.string().optional(), email2: z.string().optional(), email3: z.string().optional(), homePhone: z.string().optional(), homePhone2: z.string().optional(), businessPhone: z.string().optional(), businessPhone2: z.string().optional(), mobilePhone: z.string().optional(), businessFax: z.string().optional(), companyPhone: z.string().optional(), assistantPhone: z.string().optional(), carPhone: z.string().optional(), otherPhone: z.string().optional(), otherFax: z.string().optional(), callbackPhone: z.string().optional(), businessAddress: addressBookBulkContactAddressInfo.optional(), homeAddress: addressBookBulkContactAddressInfo.optional(), otherAddress: addressBookBulkContactAddressInfo.optional()}); export const addressBookBulkUploadResource = z.object({extensionId: z.string(), contacts: z.array(addressBookBulkContactResource)}); export const errorEntity = z.object({errorCode: z.string().optional(), message: z.string().optional(), parameterName: z.string().optional(), parameterValue: z.string().optional()}); export const addressBookBulkUploadTaskResult = z.object({affectedItems: z.array(addressBookBulkUploadResource).optional(), errors: z.array(errorEntity).optional()}); export const addressBookBulkUploadResponse = z.object({id: z.string(), uri: z.string(), status: z.enum(["Accepted", "InProgress", "Completed", "Failed"]), creationTime: z.string(), lastModifiedTime: z.string(), results: addressBookBulkUploadTaskResult.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 }; /** * Upload Multiple User Contacts * * POST /restapi/v1.0/account/{accountId}/address-book-bulk-upload */ export const createApiRestapiV10AccountAccountIdAddressBookBulkUpload = async (args: CreateApiRestapiV10AccountAccountIdAddressBookBulkUploadArgs, options?: CreateApiRestapiV10AccountAccountIdAddressBookBulkUploadOptions) => { const {baseUrl = "https://platform.ringcentral.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/restapi/v1.0/account/${encodeURIComponent(String(args.accountId))}/address-book-bulk-upload${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(addressBookBulkUploadResponse, await res.json()) };