import {z} from 'zod' export type CreateArtifactRequest = {kind: string, title: string, media_type: string, work_item_id?: (string | null) | undefined, source_execution_type?: (string | null) | undefined, source_execution_id?: (string | null) | undefined, metadata?: {[key: string]: unknown} | undefined, idempotency_key?: (string | null) | undefined, retention_class?: string | undefined, expires_at?: (string | null) | undefined, content_base64?: (string | null) | undefined, inline_text?: (string | null) | undefined, provider_source?: ({[key: string]: unknown} | null) | undefined, expect_upload?: boolean | undefined}; export type CreateApiV1TeamsTeamIdArtifactsArgs = {team_id: string, authorization?: (string | null) | undefined, 'x-darwin-token'?: (string | null) | undefined, 'x-darwin-run-id'?: (string | null) | undefined, body: CreateArtifactRequest}; export type CreateApiV1TeamsTeamIdArtifactsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const createApiV1TeamsTeamIdArtifactsResponse = z.record(z.string(), z.unknown()); 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 Artifact * * POST /v1/teams/{team_id}/artifacts */ export const createApiV1TeamsTeamIdArtifacts = async (args: CreateApiV1TeamsTeamIdArtifactsArgs, options: CreateApiV1TeamsTeamIdArtifactsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") 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'])) if (args['x-darwin-run-id'] != null) headers.set("x-darwin-run-id", String(args['x-darwin-run-id'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/teams/${encodeURIComponent(String(args.team_id))}/artifacts${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(createApiV1TeamsTeamIdArtifactsResponse, await res.json()) };