import {z} from 'zod' export type GetApiTexmlAccountsAccountSidQueuesArgs = {account_sid: string, Page?: number | undefined, PageSize?: number | undefined, PageToken?: string | undefined, DateCreated?: string | undefined, DateUpdated?: string | undefined}; export type GetApiTexmlAccountsAccountSidQueuesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const queueResource = z.object({account_sid: z.string().optional(), average_wait_time: z.number().int().optional(), current_size: z.number().int().optional(), date_created: z.string().optional(), date_updated: z.string().optional(), max_size: z.number().int().optional(), sid: z.string().optional(), uri: z.string().optional(), subresource_uris: z.record(z.string(), z.unknown()).optional()}); export const queueResourceIndex = z.object({queues: z.array(queueResource).optional(), end: z.number().int().optional(), first_page_uri: z.string().optional(), next_page_uri: z.string().optional(), page: z.number().int().optional(), page_size: z.number().int().optional(), start: z.number().int().optional(), uri: 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 }; /** * List queue resources * * GET /texml/Accounts/{account_sid}/Queues */ export const getApiTexmlAccountsAccountSidQueues = async (args: GetApiTexmlAccountsAccountSidQueuesArgs, options?: GetApiTexmlAccountsAccountSidQueuesOptions) => { const {baseUrl = "https://api.telnyx.com/v2", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Page != null) query.append("Page", String(args.Page)) if (args.PageSize != null) query.append("PageSize", String(args.PageSize)) if (args.PageToken != null) query.append("PageToken", String(args.PageToken)) if (args.DateCreated != null) query.append("DateCreated", String(args.DateCreated)) if (args.DateUpdated != null) query.append("DateUpdated", String(args.DateUpdated)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/texml/Accounts/${encodeURIComponent(String(args.account_sid))}/Queues${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(queueResourceIndex, await res.json()) };