import {z} from 'zod' export type PublicProjectStatusRequest = {id?: (string | null) | undefined, name?: (string | null) | undefined, internal_value?: (string | null) | undefined, order?: (number | null) | undefined}; export type PublicProjectRequest = {title?: (string | null) | undefined, description?: (string | null) | undefined, default?: (boolean | null) | undefined, statuses?: (Array | null) | undefined}; export type CreateApiV2PublicProjectsArgs = {workspace_id?: (string | null) | undefined, 'X-Language'?: (string | null) | undefined, 'Accept-Language'?: (string | null) | undefined, 'X-Workspace-Code'?: string | undefined, body: PublicProjectRequest}; export type CreateApiV2PublicProjectsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const publicProjectStatus = z.object({id: z.string().nullable().optional(), name: z.string(), internal_value: z.string(), order: z.number().int().optional()}); export const publicProject = z.object({id: z.string(), project_id: z.string(), title: z.string().nullable().optional(), description: z.string().nullable().optional(), default: z.boolean().optional(), statuses: z.array(publicProjectStatus).optional(), task_count: z.number().int().optional(), active_task_count: z.number().int().optional(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional()}); export const publicProjectMutationData = z.object({ok: z.boolean(), status: z.string(), id: z.string().nullable().optional(), project_id: z.string().nullable().optional(), project: publicProject.nullable().optional(), ctx_id: z.string().nullable().optional(), advisories: z.array(z.record(z.string(), z.unknown())).nullable().optional()}); export const paginationMeta = z.object({page: z.number().int().gte(1), page_size: z.number().int().gte(1).lte(500), total: z.number().int().gte(0), next_cursor: z.string().nullable().optional()}); export const toastMessageI18n = z.object({en: z.string(), ja: z.string()}); export const toastMessage = z.object({variant: z.enum(["success", "error", "info", "warning"]), code: z.string(), message: z.string(), i18n: toastMessageI18n}); export const envelopeMeta = z.object({ctx_id: z.string(), pagination: paginationMeta.optional(), toast: toastMessage.optional()}); export const createPublicProjectApiV2PublicProjectsPost200Envelope = z.object({success: z.literal(true), data: publicProjectMutationData, meta: envelopeMeta}); 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 Public Project * * POST /v2/public/projects */ export const createApiV2PublicProjects = async (args: CreateApiV2PublicProjectsArgs, options?: CreateApiV2PublicProjectsOptions) => { const {baseUrl = "https://api.sanka.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.workspace_id != null) query.append("workspace_id", String(args.workspace_id)) if (args['X-Language'] != null) headers.set("X-Language", String(args['X-Language'])) if (args['Accept-Language'] != null) headers.set("Accept-Language", String(args['Accept-Language'])) if (args['X-Workspace-Code'] != null) headers.set("X-Workspace-Code", String(args['X-Workspace-Code'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/public/projects${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(createPublicProjectApiV2PublicProjectsPost200Envelope, await res.json()) };