import {z} from 'zod' export type ContactAddressInfo = {street?: string | undefined, city?: string | undefined, country?: string | undefined, state?: string | undefined, zip?: string | undefined}; export type PersonalContactRequest = {firstName?: string | undefined, lastName?: string | undefined, middleName?: string | undefined, nickName?: string | undefined, company?: string | undefined, jobTitle?: string | undefined, email?: string | undefined, email2?: string | undefined, email3?: string | undefined, birthday?: string | undefined, webPage?: string | undefined, notes?: 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, homeAddress?: ContactAddressInfo | undefined, businessAddress?: ContactAddressInfo | undefined, otherAddress?: ContactAddressInfo | undefined, ringtoneIndex?: string | undefined}; export type CreateApiRestapiV10AccountAccountIdExtensionExtensionIdAddressBookContactArgs = {accountId: string, extensionId: string, dialingPlan?: string | undefined, body: PersonalContactRequest}; export type CreateApiRestapiV10AccountAccountIdExtensionExtensionIdAddressBookContactOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const contactAddressInfo = z.object({street: z.string().optional(), city: z.string().optional(), country: z.string().optional(), state: z.string().optional(), zip: z.string().optional()}); export const personalContactResource = z.object({uri: z.string().optional(), availability: z.enum(["Alive", "Deleted", "Purged"]).optional(), email: z.string().optional(), id: z.number().int().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: contactAddressInfo.optional(), homeAddress: contactAddressInfo.optional(), otherAddress: contactAddressInfo.optional(), ringtoneIndex: 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 User Contact * * POST /restapi/v1.0/account/{accountId}/extension/{extensionId}/address-book/contact */ export const createApiRestapiV10AccountAccountIdExtensionExtensionIdAddressBookContact = async (args: CreateApiRestapiV10AccountAccountIdExtensionExtensionIdAddressBookContactArgs, options?: CreateApiRestapiV10AccountAccountIdExtensionExtensionIdAddressBookContactOptions) => { 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 (args.dialingPlan != null) query.append("dialingPlan", String(args.dialingPlan)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/restapi/v1.0/account/${encodeURIComponent(String(args.accountId))}/extension/${encodeURIComponent(String(args.extensionId))}/address-book/contact${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(personalContactResource, await res.json()) };