import {z} from 'zod' export type GetApiV1IpLicensesIpassetIdArgs = {'X-API-KEY': string, ipassetId: string}; export type GetApiV1IpLicensesIpassetIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const augmentedZodDto = z.array(z.object({id: z.string(), terms: z.object({transferable: z.boolean(), royaltyPolicy: z.string(), defaultMintingFee: z.number(), expiration: z.number(), commercialUse: z.boolean(), commercialAttribution: z.boolean(), commercializerChecker: z.string(), commercializerCheckerData: z.string(), commercialRevShare: z.number().gte(0).lte(100000000), commercialRevCeiling: z.number(), derivativesAllowed: z.boolean(), derivativesAttribution: z.boolean(), derivativesApproval: z.boolean(), derivativesReciprocal: z.boolean(), derivativeRevCeiling: z.number(), currency: z.string(), uri: z.string()}), disabled: z.boolean().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 IP Asset Licenses * * GET /v1/ip/licenses/{ipassetId} */ export const getApiV1IpLicensesIpassetId = async (args: GetApiV1IpLicensesIpassetIdArgs, options?: GetApiV1IpLicensesIpassetIdOptions) => { const {baseUrl = "https://staging.crossmint.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-API-KEY'] != null) headers.set("X-API-KEY", String(args['X-API-KEY'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/ip/licenses/${encodeURIComponent(String(args.ipassetId))}${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(augmentedZodDto, await res.json()) };