import {z} from 'zod' export type CorporationID = number; export type GetApiFreelanceJobsArgs = {after?: string | undefined, before?: string | undefined, limit?: number | undefined, corporation_id?: CorporationID | undefined, 'Accept-Language'?: ('en' | 'de' | 'fr' | 'ja' | 'ru' | 'zh' | 'ko' | 'es') | undefined, 'If-None-Match'?: string | undefined, 'X-Compatibility-Date': '2025-12-16', 'X-Tenant'?: string | undefined}; export type GetApiFreelanceJobsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const cursor = z.object({after: z.string().optional(), before: z.string().optional()}); export const uUID = z.string(); export const freelanceJobsDetailProgress = z.object({current: z.number().int(), desired: z.number().int()}); export const freelanceJobsDetailReward = z.object({initial: z.number(), remaining: z.number()}); export const freelanceJobsDetailFreelancejob = z.object({id: uUID, last_modified: z.string(), name: z.string(), progress: freelanceJobsDetailProgress, reward: freelanceJobsDetailReward.optional(), state: z.enum(["Unspecified", "Active", "Closed", "Completed", "Expired", "Deleted"])}); export const freelanceJobsListing = z.object({cursor: cursor.optional(), freelance_jobs: z.array(freelanceJobsDetailFreelancejob)}); 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 freelance jobs * * GET /freelance-jobs */ export const getApiFreelanceJobs = async (args: GetApiFreelanceJobsArgs, options?: GetApiFreelanceJobsOptions) => { const {baseUrl = "https://esi.evetech.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.after != null) query.append("after", String(args.after)) if (args.before != null) query.append("before", String(args.before)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.corporation_id != null) query.append("corporation_id", String(args.corporation_id)) if (args['Accept-Language'] != null) headers.set("Accept-Language", String(args['Accept-Language'])) if (args['If-None-Match'] != null) headers.set("If-None-Match", String(args['If-None-Match'])) if (args['X-Compatibility-Date'] != null) headers.set("X-Compatibility-Date", String(args['X-Compatibility-Date'])) if (args['X-Tenant'] != null) headers.set("X-Tenant", String(args['X-Tenant'])) const url = `${baseUrl.replace(/\/+$/, '')}/freelance-jobs${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(freelanceJobsListing, await res.json()) };