import {z} from 'zod' export type Model19 = Record | null; export type Model20 = Array; export type Model21 = Array; export type Model22 = {type: string, name: string, description?: (string | null) | undefined, source?: (string | null) | undefined, metadata?: Model19 | undefined, bucketSids?: Model20 | undefined, environmentSids?: Model21 | undefined, startedAt?: string | undefined, endedAt?: (string | null) | undefined}; export type CreateApiV1AccountsAccountSidEventsArgs = {accountSid: string, body: Model22}; export type CreateApiV1AccountsAccountSidEventsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const bucketSids = z.array(z.string()); export const environmentSids = z.array(z.string()); export const metadata = z.object({}).nullable(); export const event = z.object({sid: z.string(), accountSid: z.string(), bucketSids: bucketSids, environmentSids: environmentSids, type: z.string(), name: z.string(), description: z.string().nullable().optional(), source: z.string().nullable().optional(), metadata: metadata.optional(), startedAt: z.string(), endedAt: z.string().nullable().optional(), createdAt: z.string(), updatedAt: z.string().nullable().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 }; /** * Creates a new event marker (e.g. deployment, incident, config change). * * POST /v1/accounts/{accountSid}/events */ export const createApiV1AccountsAccountSidEvents = async (args: CreateApiV1AccountsAccountSidEventsArgs, options?: CreateApiV1AccountsAccountSidEventsOptions) => { const {baseUrl = "https://api.apitraffic.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.accountSid))}/events${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(event, await res.json()) };