import {z} from 'zod' export type CurrencyTypeDTO = {id: number, name?: string | undefined}; export type WisePayoutDetailsDTO = {email: string}; export type PayoutDTO = {wiseDetails?: Array | undefined}; export type CustomerDTO = {blocked?: boolean | undefined, created?: string | undefined, email?: string | undefined, id?: number | undefined, kyc?: boolean | undefined, payoutMethod?: PayoutDTO | undefined, permissionType?: ('READ_WRITE' | 'READ_ONLY') | undefined, tos?: string | undefined}; export type PaymentMethodDTO = {created?: string | undefined, currency?: string | undefined, expirationDate?: string | undefined, id?: string | undefined, identifier?: string | undefined, number?: string | undefined, status?: boolean | undefined, statusMessage?: string | undefined, type?: string | undefined}; export type ProjectDTO = {b2b?: boolean | undefined, balance?: number | undefined, billingCity: string, billingCompanyName: string, billingCountry: string, billingCountryIsoAlpha2: string, billingIdentification: string, billingName: string, billingPostcode: string, billingRegion?: string | undefined, billingStreet: string, billingVatIdentification?: string | undefined, blocked?: boolean | undefined, currencyType: CurrencyTypeDTO, dedicated: boolean, id?: string | undefined, name: string, owner?: CustomerDTO | undefined, paymentMethod?: PaymentMethodDTO | undefined}; export type UpdateApiRestApiV1ProjectsProjectIdArgs = {projectId: string, body: ProjectDTO}; export type UpdateApiRestApiV1ProjectsProjectIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const currencyTypeDTO = z.object({id: z.number().int(), name: z.string().optional()}); export const wisePayoutDetailsDTO = z.object({email: z.string()}); export const payoutDTO = z.object({wiseDetails: z.array(wisePayoutDetailsDTO).optional()}); export const customerDTO = z.object({blocked: z.boolean().optional(), created: z.string().optional(), email: z.string().optional(), id: z.number().int().optional(), kyc: z.boolean().optional(), payoutMethod: payoutDTO.optional(), permissionType: z.enum(["READ_WRITE", "READ_ONLY"]).optional(), tos: z.string().optional()}); export const paymentMethodDTO = z.object({created: z.string().optional(), currency: z.string().optional(), expirationDate: z.string().optional(), id: z.string().optional(), identifier: z.string().optional(), number: z.string().optional(), status: z.boolean().optional(), statusMessage: z.string().optional(), type: z.string().optional()}); export const projectDTO = z.object({b2b: z.boolean().optional(), balance: z.number().optional(), billingCity: z.string().max(255), billingCompanyName: z.string().max(255), billingCountry: z.string().max(255), billingCountryIsoAlpha2: z.string().max(255), billingIdentification: z.string().max(255), billingName: z.string().max(255), billingPostcode: z.string().max(255), billingRegion: z.string().max(255).optional(), billingStreet: z.string().max(255), billingVatIdentification: z.string().optional(), blocked: z.boolean().optional(), currencyType: currencyTypeDTO, dedicated: z.boolean(), id: z.string().optional(), name: z.string().max(255), owner: customerDTO.optional(), paymentMethod: paymentMethodDTO.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 a project * * PUT /rest/api/v1/projects/{projectId} */ export const updateApiRestApiV1ProjectsProjectId = async (args: UpdateApiRestApiV1ProjectsProjectIdArgs, options?: UpdateApiRestApiV1ProjectsProjectIdOptions) => { const {baseUrl = "https://api.metacopier.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/rest/api/v1/projects/${encodeURIComponent(String(args.projectId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(projectDTO, await res.json()) };