import {z} from 'zod' export type ContactBusinessAddressInfo = {country?: string | undefined, state?: string | undefined, city?: string | undefined, street?: string | undefined, zip?: string | undefined}; export type CountryInfoShortModel = {id?: string | undefined, uri?: string | undefined, name?: string | undefined, isoCode?: string | undefined, callingCode?: string | undefined}; export type TimezoneInfo = {id?: string | undefined, uri?: string | undefined, name?: string | undefined, description?: string | undefined, bias?: string | undefined}; export type RegionalLanguageInfo = {id?: string | undefined, localeCode?: string | undefined, name?: string | undefined}; export type GreetingLanguageInfo = {id?: string | undefined, localeCode?: string | undefined, name?: string | undefined}; export type FormattingLocaleInfo = {id?: string | undefined, localeCode?: string | undefined, name?: string | undefined}; export type RegionalSettings = {homeCountry?: CountryInfoShortModel | undefined, timezone?: TimezoneInfo | undefined, language?: RegionalLanguageInfo | undefined, greetingLanguage?: GreetingLanguageInfo | undefined, formattingLocale?: FormattingLocaleInfo | undefined, timeFormat?: ('12h' | '24h') | undefined}; export type SiteOperatorReference = {id?: string | undefined}; export type CreateSiteRequest = {name?: string | undefined, extensionNumber?: string | undefined, callerIdName?: string | undefined, email?: string | undefined, businessAddress?: ContactBusinessAddressInfo | undefined, regionalSettings?: RegionalSettings | undefined, operator?: SiteOperatorReference | undefined, code?: string | undefined}; export type CreateApiRestapiV10AccountAccountIdSitesArgs = {accountId: string, body: CreateSiteRequest}; export type CreateApiRestapiV10AccountAccountIdSitesOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const contactBusinessAddressInfo = z.object({country: z.string().optional(), state: z.string().optional(), city: z.string().optional(), street: z.string().optional(), zip: z.string().optional()}); export const countryInfoShortModel = z.object({id: z.string().optional(), uri: z.string().optional(), name: z.string().optional(), isoCode: z.string().optional(), callingCode: z.string().optional()}); export const timezoneInfo = z.object({id: z.string().optional(), uri: z.string().optional(), name: z.string().optional(), description: z.string().optional(), bias: z.string().optional()}); export const regionalLanguageInfo = z.object({id: z.string().optional(), localeCode: z.string().optional(), name: z.string().optional()}); export const greetingLanguageInfo = z.object({id: z.string().optional(), localeCode: z.string().optional(), name: z.string().optional()}); export const formattingLocaleInfo = z.object({id: z.string().optional(), localeCode: z.string().optional(), name: z.string().optional()}); export const regionalSettings = z.object({homeCountry: countryInfoShortModel.optional(), timezone: timezoneInfo.optional(), language: regionalLanguageInfo.optional(), greetingLanguage: greetingLanguageInfo.optional(), formattingLocale: formattingLocaleInfo.optional(), timeFormat: z.enum(["12h", "24h"]).optional()}); export const operatorInfo = z.object({id: z.string().optional(), uri: z.string().optional(), extensionNumber: z.string().optional(), name: z.string().optional()}); export const siteInfo = z.object({id: z.string().optional(), uri: z.string().optional(), name: z.string().optional(), extensionNumber: z.string().optional(), callerIdName: z.string().optional(), email: z.string().optional(), businessAddress: contactBusinessAddressInfo.optional(), regionalSettings: regionalSettings.optional(), operator: operatorInfo.optional(), code: 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 Site * * POST /restapi/v1.0/account/{accountId}/sites */ export const createApiRestapiV10AccountAccountIdSites = async (args: CreateApiRestapiV10AccountAccountIdSitesArgs, options?: CreateApiRestapiV10AccountAccountIdSitesOptions) => { 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))}/sites${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(siteInfo, await res.json()) };