import {z} from 'zod' export type PaymentsObject = {price?: string | undefined, recipientAddress?: string | undefined, currency?: string | undefined}; export type PatchApi20220609CollectionsCollectionIdArgs = {collectionId: string, body: {supplyLimit?: number | undefined, payments?: PaymentsObject | undefined}}; export type PatchApi20220609CollectionsCollectionIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const updateCollectionResponse = z.object({actionId: z.string().optional(), action: z.string().optional(), status: z.string().optional(), data: z.object({chain: z.string().optional(), collection: z.object({id: z.string().optional(), contractAddress: z.string().optional()}).optional(), changes: z.array(z.string()).optional()}).optional(), startedAt: z.string().optional(), resource: z.string().optional(), subscription: z.object({enabled: z.boolean().optional()}).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 Collection Info * * PATCH /2022-06-09/collections/{collectionId} */ export const patchApi20220609CollectionsCollectionId = async (args: PatchApi20220609CollectionsCollectionIdArgs, options?: PatchApi20220609CollectionsCollectionIdOptions) => { const {baseUrl = "https://staging.crossmint.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/2022-06-09/collections/${encodeURIComponent(String(args.collectionId))}${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(updateCollectionResponse, await res.json()) };