import {z} from 'zod' export type GetApiTexmlAccountsAccountSidConferencesArgs = {account_sid: string, Page?: number | undefined, PageSize?: number | undefined, PageToken?: string | undefined, FriendlyName?: string | undefined, Status?: ('init' | 'in-progress' | 'completed') | undefined, DateCreated?: string | undefined, DateUpdated?: string | undefined}; export type GetApiTexmlAccountsAccountSidConferencesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const conferenceResource = z.object({account_sid: z.string().optional(), api_version: z.string().optional(), call_sid_ending_conference: z.string().optional(), date_created: z.string().optional(), date_updated: z.string().optional(), friendly_name: z.string().optional(), reason_conference_ended: z.enum(["participant-with-end-conference-on-exit-left", "last-participant-left", "conference-ended-via-api", "time-exceeded"]).optional(), region: z.string().optional(), sid: z.string().optional(), status: z.enum(["init", "in-progress", "completed"]).optional(), subresource_uris: z.record(z.string(), z.unknown()).optional(), uri: z.string().optional()}); export const conferenceResourceIndex = z.object({conferences: z.array(conferenceResource).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 conference resources * * GET /texml/Accounts/{account_sid}/Conferences */ export const getApiTexmlAccountsAccountSidConferences = async (args: GetApiTexmlAccountsAccountSidConferencesArgs, options?: GetApiTexmlAccountsAccountSidConferencesOptions) => { 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.FriendlyName != null) query.append("FriendlyName", String(args.FriendlyName)) if (args.Status != null) query.append("Status", String(args.Status)) 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))}/Conferences${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(conferenceResourceIndex, await res.json()) };