import {z} from 'zod' export type Recipient = string; export type SendNotification = boolean; export type Locale = string; export type CreateApi20220609CollectionsCollectionIdSftsArgs = {'x-idempotency-key'?: string | undefined, collectionId: string, body: {templateId: string, recipient: Recipient, sendNotification?: SendNotification | undefined, locale?: Locale | undefined, amount?: number | undefined}}; export type CreateApi20220609CollectionsCollectionIdSftsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApi20220609CollectionsCollectionIdSftsResponse = 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(), recipient: z.object({walletAddress: z.string().optional(), email: z.string().optional()}).optional(), token: z.object({id: z.string().optional()}).optional()}).optional(), startedAt: z.string().optional(), resource: z.string().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 }; /** * Mint SFT * * POST /2022-06-09/collections/{collectionId}/sfts */ export const createApi20220609CollectionsCollectionIdSfts = async (args: CreateApi20220609CollectionsCollectionIdSftsArgs, options?: CreateApi20220609CollectionsCollectionIdSftsOptions) => { 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") if (args['x-idempotency-key'] != null) headers.set("x-idempotency-key", String(args['x-idempotency-key'])) const url = `${baseUrl.replace(/\/+$/, '')}/2022-06-09/collections/${encodeURIComponent(String(args.collectionId))}/sfts${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApi20220609CollectionsCollectionIdSftsResponse, await res.json()) };