import {z} from 'zod' export type V2CreateAddressBookEntryRequest = {address: string, displayName: string, network?: string | undefined, note?: string | undefined}; export type AddressBookBatchCreateUnsignedAddressBookEntriesBody = {requests: Array}; export type CreateApiV2VaultsVaultIdAddressBookEntriesUnsignedBatchCreateArgs = {vault_id: string, body: AddressBookBatchCreateUnsignedAddressBookEntriesBody}; export type CreateApiV2VaultsVaultIdAddressBookEntriesUnsignedBatchCreateOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const v2VaultActionStatusEnum = z.enum(["PENDING", "REJECTED", "AWAITING_SIGNATURE", "RUNNING", "FINISHED", "FAILED", "CANCELED", "EXPIRED"]); export const v2VaultAction = z.object({name: z.string().optional(), status: v2VaultActionStatusEnum.optional(), createTime: z.string().optional(), expireTime: z.string().optional()}); export const v2BatchCreateUnsignedAddressBookEntriesResponse = z.object({vaultAction: v2VaultAction.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 }; /** * BatchCreateUnsignedAddressBookEntries * * POST /v2/vaults/{vault_id}/addressBookEntries:unsignedBatchCreate */ export const createApiV2VaultsVaultIdAddressBookEntriesUnsignedBatchCreate = async (args: CreateApiV2VaultsVaultIdAddressBookEntriesUnsignedBatchCreateArgs, options?: CreateApiV2VaultsVaultIdAddressBookEntriesUnsignedBatchCreateOptions) => { const {baseUrl = "https://api.utila.io", 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/vaults/${encodeURIComponent(String(args.vault_id))}/addressBookEntries:unsignedBatchCreate${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(v2BatchCreateUnsignedAddressBookEntriesResponse, await res.json()) };