import {z} from 'zod' export type CreateApiV1TeamsTeamIdAttachmentsArgs = {team_id: string, lane?: string | undefined, authorization?: (string | null) | undefined, 'x-darwin-token'?: (string | null) | undefined, body: BodyInit}; export type CreateApiV1TeamsTeamIdAttachmentsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const createApiV1TeamsTeamIdAttachmentsResponse = z.record(z.string(), z.string()); 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 }; /** * Receive Attachment * * POST /v1/teams/{team_id}/attachments */ export const createApiV1TeamsTeamIdAttachments = async (args: CreateApiV1TeamsTeamIdAttachmentsArgs, options: CreateApiV1TeamsTeamIdAttachmentsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.lane != null) query.append("lane", String(args.lane)) if (args.authorization != null) headers.set("authorization", String(args.authorization)) if (args['x-darwin-token'] != null) headers.set("x-darwin-token", String(args['x-darwin-token'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/teams/${encodeURIComponent(String(args.team_id))}/attachments${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV1TeamsTeamIdAttachmentsResponse, await res.json()) };