import {z} from 'zod' export type GetApiStatusListsStatusListIdArgs = {statusListId: string, correlationId?: string | undefined}; export type GetApiStatusListsStatusListIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const verifiableCredential = z.object({"@context": z.array(z.string()).optional(), id: z.string().optional(), type: z.array(z.string()).optional(), issuer: z.string().optional(), issuanceDate: z.string().optional(), credentialSubject: z.record(z.string(), z.unknown()).optional()}); export const getApiStatusListsStatusListIdResponse = z.union([verifiableCredential, z.string()]); 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 status list credential. This is what a wallet or RP would call, as this value ends up in digital credentials * * GET /status-lists/{statusListId} */ export const getApiStatusListsStatusListId = async (args: GetApiStatusListsStatusListIdArgs, options?: GetApiStatusListsStatusListIdOptions) => { const {baseUrl = "https://agent.findynet.demo.sphereon.com/vc", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.correlationId != null) query.append("correlationId", String(args.correlationId)) const url = `${baseUrl.replace(/\/+$/, '')}/status-lists/${encodeURIComponent(String(args.statusListId))}${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(getApiStatusListsStatusListIdResponse, await res.json()) };