import {z} from 'zod' export type DID = unknown; export type AssetIdentifier = string; export type PatchApiEntitiesEntityDIDRelationshipsArgs = {entityDID: DID, from?: string | undefined, to?: string | undefined, custodian?: string | undefined, asset?: Array | undefined, body: {proof?: ({status: 'pending' | 'rejected' | 'flagged' | 'verified', did: string, address: string, xpub?: string | undefined, chainSpecificData?: {[key: string]: unknown} | undefined, type: 'eip-191' | 'eip-712' | 'eip-1271' | 'bip-137' | 'bip-322' | 'tip-191' | 'ed25519' | 'xrp-ed25519' | 'xlm-ed25519' | 'cip-8' | 'siwe' | 'siwx', proof: string, attestation: string, wallet_provider?: (string | null) | undefined} | {status: 'pending' | 'rejected' | 'flagged' | 'verified', did: string, address: string, xpub?: string | undefined, chainSpecificData?: {[key: string]: unknown} | undefined, type: 'screenshot', url: string} | {status: 'pending' | 'rejected' | 'flagged' | 'verified', did: string, address: string, xpub?: string | undefined, chainSpecificData?: {[key: string]: unknown} | undefined, type: 'self-declaration', confirmed: boolean, attestation?: string | undefined} | {status: 'pending' | 'rejected' | 'flagged' | 'verified', did: string, address: string, xpub?: string | undefined, chainSpecificData?: {[key: string]: unknown} | undefined, type: 'microtransfer', proof?: string | undefined, chain?: string | undefined, destination?: string | undefined, amountSubunits?: number | undefined}) | undefined, from?: string | undefined, to?: string | undefined, custodian?: string | undefined, asset?: string | undefined}}; export type PatchApiEntitiesEntityDIDRelationshipsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiEntitiesEntityDIDRelationshipsResponse = z.object({success: z.boolean()}); 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 }; /** * Confirm a relationship * * PATCH /entities/{entityDID}/relationships */ export const patchApiEntitiesEntityDIDRelationships = async (args: PatchApiEntitiesEntityDIDRelationshipsArgs, options?: PatchApiEntitiesEntityDIDRelationshipsOptions) => { const {baseUrl = "https://api.eu1.notabene.id", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.custodian != null) query.append("custodian", String(args.custodian)) for (const item of args.asset ?? []) query.append("asset", String(item)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/entities/${encodeURIComponent(String(args.entityDID))}/relationships${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiEntitiesEntityDIDRelationshipsResponse, await res.json()) };