import {z} from 'zod' export type GetApiRestApiV1ProjectsProjectIdArgs = {projectId: string}; export type GetApiRestApiV1ProjectsProjectIdOptions = {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 }; /** * Get a project * * GET /rest/api/v1/projects/{projectId} */ export const getApiRestApiV1ProjectsProjectId = async (args: GetApiRestApiV1ProjectsProjectIdArgs, options?: GetApiRestApiV1ProjectsProjectIdOptions) => { const {baseUrl = "https://api.metacopier.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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: "GET", headers}) 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()) };