import {z} from 'zod' export type NFTMetadata = {name: string, image: string, description: string, animation_url?: string | undefined, attributes?: (Array<{display_type?: ('boost_number' | 'boost_percentage' | 'number') | undefined, trait_type: string, value: string}>) | undefined}; export type NFTMetadataSolana = {name: string, image: string, description: string, symbol?: string | undefined, attributes?: (Array<{display_type?: ('boost_number' | 'boost_percentage' | 'number') | undefined, trait_type: string, value: string}>) | undefined}; export type NFTMetadataOptions = NFTMetadata | string | NFTMetadataSolana | {uri: string, name: string}; export type Recipient = string; export type SendNotification = boolean; export type Locale = string; export type ReuploadLinkedFiles = boolean; export type Compressed = boolean; export type UpdateApi20220609CollectionsCollectionIdNftsIdArgs = {collectionId: string, id: string, body: {metadata: NFTMetadataOptions, recipient: Recipient, sendNotification?: SendNotification | undefined, locale?: Locale | undefined, reuploadLinkedFiles?: ReuploadLinkedFiles | undefined, compressed?: Compressed | undefined}}; export type UpdateApi20220609CollectionsCollectionIdNftsIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const mintResponseSolana200 = z.object({id: z.string().optional(), onChain: z.object({status: z.string().optional(), chain: z.string().optional()}).optional(), actionId: z.string().optional()}); export const mintResponseSolana200Subsequent = z.object({id: z.string().optional(), metadata: z.object({name: z.string().optional(), symbol: z.string().optional(), seller_fee_basis_points: z.number().int().optional(), properties: z.object({files: z.array(z.object({uri: z.string().optional(), type: z.string().optional()})).optional(), category: z.string().optional(), creators: z.array(z.object({address: z.string().optional(), verified: z.boolean().optional(), share: z.number().int().optional()})).optional()}).optional(), description: z.string().optional(), image: z.string().optional(), attributes: z.array(z.object({trait_type: z.string().optional(), value: z.string().optional()})).optional()}).optional(), onChain: z.object({status: z.string().optional(), mintHash: z.string().optional(), txId: z.string().optional(), owner: z.string().optional(), chain: z.string().optional()}).optional(), actionId: z.string().optional()}); export const mintResponseEVM200 = z.object({id: z.string().optional(), onChain: z.object({status: z.string().optional(), chain: z.string().optional(), contractAddress: z.string().optional(), subscription: z.object({expiresAt: z.string().optional()}).optional()}).optional(), actionId: z.string().optional()}); export const mintResponseEVM200Subsequent = z.object({id: z.string().optional(), metadata: z.object({name: z.string().optional(), image: z.string().optional(), description: z.string().optional()}).optional(), onChain: z.object({status: z.string().optional(), tokenId: z.string().optional(), owner: z.string().optional(), txId: z.string().optional(), contractAddress: z.string().optional(), chain: z.string().optional(), subscription: z.object({expiresAt: z.string().optional()}).optional()}).optional(), actionId: z.string().optional()}); export const updateApi20220609CollectionsCollectionIdNftsIdResponse = z.union([mintResponseSolana200, mintResponseSolana200Subsequent, mintResponseEVM200, mintResponseEVM200Subsequent]); 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 }; /** * Mint NFT with ID * * PUT /2022-06-09/collections/{collectionId}/nfts/{id} */ export const updateApi20220609CollectionsCollectionIdNftsId = async (args: UpdateApi20220609CollectionsCollectionIdNftsIdArgs, options?: UpdateApi20220609CollectionsCollectionIdNftsIdOptions) => { 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))}/nfts/${encodeURIComponent(String(args.id))}${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(updateApi20220609CollectionsCollectionIdNftsIdResponse, await res.json()) };