import {z} from 'zod' export type GetApiApiUtilitiesV0ContractInstrumentConfigurationAllOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const contractMeta = z.object({createdAt: z.string().optional(), contractId: z.string(), templateId: z.string(), synchronizerId: z.string().optional(), domainId: z.string().optional()}); export const instrumentIdentifier = z.object({source: z.string(), id: z.string(), scheme: z.string()}); export const partyCredentialRequirement = z.object({issuer: z.string(), requiredClaims: z.string()}); export const instrumentConfigurationPayload = z.object({operator: z.string(), provider: z.string(), registrar: z.string(), defaultIdentifier: instrumentIdentifier, additionalIdentifiers: z.array(instrumentIdentifier), issuerRequirements: z.array(partyCredentialRequirement), holderRequirements: z.array(partyCredentialRequirement)}); export const instrumentConfiguration = z.object({contract: contractMeta, payload: instrumentConfigurationPayload}); export const getAllInstrumentConfigurationsResponse = z.object({instrumentConfigurations: z.array(instrumentConfiguration)}); 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 /api/utilities/v0/contract/instrument-configuration/all */ export const getApiApiUtilitiesV0ContractInstrumentConfigurationAll = async (options?: GetApiApiUtilitiesV0ContractInstrumentConfigurationAllOptions) => { const {baseUrl = "https://api.utilities.digitalasset.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/utilities/v0/contract/instrument-configuration/all${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(getAllInstrumentConfigurationsResponse, await res.json()) };