import {z} from 'zod' export type RenameConnectedAccountRequest = {accountName: string}; export type CreateApiConnectedAccountsAccountIdRenameArgs = {accountId: string, 'Idempotency-Key'?: string | undefined, body: RenameConnectedAccountRequest}; export type CreateApiConnectedAccountsAccountIdRenameOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const renameConnectedAccountResponse = z.enum(["SUCCESS", "UNAUTHORISED__USER", "UNAUTHORISED__DEVICE", "INVALID_UNMANAGED_WALLET", "INVALID_EXCHANGE_ACCOUNT", "NO_ACTIVE_ADMINS", "TIMEOUT", "INVALID_PARAMETERS", "INTERNAL_ERROR", "INVALID_CREDENTIALS", "INVALID_OTP", "INVALID_OTP_METHOD", "INVALID_NETWORK_CONNECTION", "NETWORK_CONNECTION_EXISTS", "INVALID_CREDENTIALS__UNSUPPORTED_PROVIDER", "UNSUPPORTED_ALGORITHM", "INVALID_CREDENTIALS__IP_WHITELISTING", "INVALID_CREDENTIALS__OTP_FAILED", "UNSUPPORTED_ASSET", "ASSET_ALREADY_EXISTS", "ENV_UNSUPPORTED_ASSET", "NO_CONFIG_CHANGE_NEEDED", "SIMILAR_REQUEST_ALREADY_PENDING", "CLOUD_COSIGNER_ALREADY_EXISTS", "ILLEGAL_OPERATION", "OVERRIDING_PENDING_REQUEST", "OWNER_NOT_IN_GROUP", "INVALID_THIRD_PARTY_ACCOUNT_HIERARCHY", "EXTERNAL_KEY_VALIDATION_FAILED", "NO_AVAILABLE_EXTERNAL_KEYS", "INVALID_PROOF_OF_OWNERSHIP_SIGNATURE", "USER_HAS_EXTERNAL_KEYS", "SCHEMA_ALREADY_EXISTS", "SCHEMA_ID_OUT_OF_RANGE", "FORBIDDEN_SSO_IDP_DOMAIN", "UNKNOWN_ERROR"]); 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 }; /** * Rename Connected Account * * POST /connected_accounts/{accountId}/rename */ export const createApiConnectedAccountsAccountIdRename = async (args: CreateApiConnectedAccountsAccountIdRenameArgs, options?: CreateApiConnectedAccountsAccountIdRenameOptions) => { const {baseUrl = "https://api.fireblocks.io/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) const url = `${baseUrl.replace(/\/+$/, '')}/connected_accounts/${encodeURIComponent(String(args.accountId))}/rename${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(renameConnectedAccountResponse, await res.json()) };