import {z} from 'zod' export type CallQueueServiceLevelSettings = {slaGoal?: number | undefined, slaThresholdSeconds?: number | undefined, includeAbandonedCalls?: boolean | undefined, abandonedThresholdSeconds?: number | undefined}; export type CallQueueDetails = {uri?: string | undefined, id?: string | undefined, extensionNumber?: string | undefined, name?: string | undefined, status?: ('Enabled' | 'Disabled' | 'NotActivated') | undefined, subType?: 'Emergency' | undefined, serviceLevelSettings?: CallQueueServiceLevelSettings | undefined, editableMemberStatus?: boolean | undefined, alertTimer?: (5 | 10 | 15 | 20 | 30 | 45 | 60 | 120 | 180 | 240 | 300 | 360 | 420 | 480 | 540 | 600) | undefined}; export type UpdateApiRestapiV10AccountAccountIdCallQueuesGroupIdArgs = {accountId: string, groupId: string, body: CallQueueDetails}; export type UpdateApiRestapiV10AccountAccountIdCallQueuesGroupIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const callQueueServiceLevelSettings = z.object({slaGoal: z.number().int().optional(), slaThresholdSeconds: z.number().int().optional(), includeAbandonedCalls: z.boolean().optional(), abandonedThresholdSeconds: z.number().int().optional()}); export const callQueueDetails = z.object({uri: z.string().optional(), id: z.string().optional(), extensionNumber: z.string().optional(), name: z.string().optional(), status: z.enum(["Enabled", "Disabled", "NotActivated"]).optional(), subType: z.literal("Emergency").optional(), serviceLevelSettings: callQueueServiceLevelSettings.optional(), editableMemberStatus: z.boolean().optional(), alertTimer: z.union([z.literal(5), z.literal(10), z.literal(15), z.literal(20), z.literal(30), z.literal(45), z.literal(60), z.literal(120), z.literal(180), z.literal(240), z.literal(300), z.literal(360), z.literal(420), z.literal(480), z.literal(540), z.literal(600)]).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 }; /** * Update Call Queue * * PUT /restapi/v1.0/account/{accountId}/call-queues/{groupId} */ export const updateApiRestapiV10AccountAccountIdCallQueuesGroupId = async (args: UpdateApiRestapiV10AccountAccountIdCallQueuesGroupIdArgs, options?: UpdateApiRestapiV10AccountAccountIdCallQueuesGroupIdOptions) => { 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))}/call-queues/${encodeURIComponent(String(args.groupId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(callQueueDetails, await res.json()) };