import {z} from 'zod' export type CreateTeamRequest = {description?: (string | null) | undefined, name: string, timezone?: string | undefined}; export type CreateApiApiOrgIdOncallTeamsArgs = {org_id: string, body: CreateTeamRequest}; export type CreateApiApiOrgIdOncallTeamsOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const team = z.object({channel_destinations: z.array(z.string()).nullable().optional(), created_at: z.number().int(), description: z.string().nullable().optional(), id: z.string(), name: z.string(), org_id: z.string(), slack_channel_id: z.string().nullable().optional(), slack_channel_name: z.string().nullable().optional(), slack_enterprise_id: z.string().nullable().optional(), slack_same_room_destination: z.string().nullable().optional(), slack_workspace_id: z.string().nullable().optional(), timezone: z.string(), updated_at: z.number().int()}); 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 an on-call team * * POST /api/{org_id}/oncall/teams */ export const createApiApiOrgIdOncallTeams = async (args: CreateApiApiOrgIdOncallTeamsArgs, options: CreateApiApiOrgIdOncallTeamsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/oncall/teams${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(team, await res.json()) };