import {z} from 'zod' export type Object = {id?: string | undefined, name?: string | undefined}; export type Creator = {id?: string | undefined, email?: string | undefined, first_name?: string | undefined, last_name?: string | undefined, organization?: Object | undefined}; export type CreatedAt = string; export type ProjectUpdate = {id?: string | undefined, name?: string | undefined, description?: string | undefined, type?: 'public' | undefined, members?: number | undefined, networks?: number | undefined, creator?: Creator | undefined, created_at?: CreatedAt | undefined}; export type PatchApiV1ProjectsIdArgs = {body: ProjectUpdate}; export type PatchApiV1ProjectsIdOptions = {baseUrl?: string | undefined, APIKeyAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const projectTypeEnum = z.literal("public"); export const object = z.object({id: z.string().optional(), name: z.string().optional()}); export const creator = z.object({id: z.string().optional(), email: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional(), organization: object.optional()}); export const createdAt = z.string(); export const project = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), type: projectTypeEnum.optional(), members: z.number().int().optional(), networks: z.number().int().optional(), creator: creator.optional(), created_at: createdAt.optional()}); 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 }; /** * Update Project * * PATCH /v1/projects/{id}/ */ export const patchApiV1ProjectsId = async (args: PatchApiV1ProjectsIdArgs, options?: PatchApiV1ProjectsIdOptions) => { const {baseUrl = "https://api.chainstack.com", fetch: fetchFn = fetch, APIKeyAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APIKeyAuthentication !== undefined) headers.set('authorization', `Bearer ${APIKeyAuthentication}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.id))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(project, await res.json()) };