import {z} from 'zod' export type GetApiV1DomainsDomainIdAccountsAccountIdArgs = {domainId: string, accountId: string}; export type GetApiV1DomainsDomainIdAccountsAccountIdOptions = {baseUrl: string, httpAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const coreAccountKeyStrategy = z.enum(["VaultHard", "VaultSoft", "Random"]); export const coreAccountPublicKeyExtendedPublicKey = z.object({value: z.string(), chainCode: z.string(), type: z.literal("ExtendedPublicKey")}); export const coreAccountPublicKeyPublicKey = z.object({value: z.string(), type: z.literal("PublicKey")}); export const coreAccountPublicKey = z.discriminatedUnion("type", [coreAccountPublicKeyExtendedPublicKey, coreAccountPublicKeyPublicKey]); export const coreVaultAccountKeyInformationRandom = z.object({publicKey: coreAccountPublicKey.optional(), type: z.literal("Random")}); export const coreVaultAccountKeyInformationVaultDerived = z.object({publicKey: coreAccountPublicKey.optional(), derivationPath: z.string().min(1), type: z.literal("VaultDerived")}); export const coreVaultAccountKeyInformation = z.discriminatedUnion("type", [coreVaultAccountKeyInformationRandom, coreVaultAccountKeyInformationVaultDerived]); export const coreVaultAccountProviderInformationKeyId = z.enum(["SECP256K1_CUSTODY_1", "ED25519_CUSTODY_1", "ED25519_CUSTODY_2", "ED25519_STAKING_1"]); export const coreAccountPublicKeyExtendedOnly = z.object({value: z.string(), chainCode: z.string(), type: z.literal("ExtendedPublicKey")}); export const coreVaultAccountProviderInformationKeyVaultDerived = z.object({id: coreVaultAccountProviderInformationKeyId, derivationPath: z.string().min(1), publicKey: coreAccountPublicKeyExtendedOnly.optional(), type: z.literal("VaultDerived")}); export const coreAccountPublicKeyOnly = z.object({value: z.string(), type: z.literal("PublicKey")}); export const coreVaultAccountProviderInformationKeyVaultDerivedNonExtended = z.object({id: coreVaultAccountProviderInformationKeyId, derivationPath: z.string().min(1), publicKey: coreAccountPublicKeyOnly, type: z.literal("VaultDerivedNonExtended")}); export const coreVaultAccountProviderInformationKeyVaultRandom = z.object({id: coreVaultAccountProviderInformationKeyId, publicKey: coreAccountPublicKey.optional(), type: z.literal("VaultRandom")}); export const coreVaultAccountProviderInformationKey = z.discriminatedUnion("type", [coreVaultAccountProviderInformationKeyVaultDerived, coreVaultAccountProviderInformationKeyVaultDerivedNonExtended, coreVaultAccountProviderInformationKeyVaultRandom]); export const coreAccountProviderInformation = z.object({vaultId: z.string(), keyStrategy: coreAccountKeyStrategy, keyInformation: coreVaultAccountKeyInformation, keys: z.array(coreVaultAccountProviderInformationKey).optional(), type: z.literal("Vault")}); export const coreLockStatus = z.enum(["Unlocked", "Locked", "Archived"]); export const coreUserReference = z.object({id: z.string(), domainId: z.string()}); export const coreStringsMap = z.record(z.string(), z.string()); export const coreEntityMetadata = z.object({description: z.string().max(250).optional(), revision: z.number().int().gte(1), createdAt: z.string(), createdBy: coreUserReference.optional(), lastModifiedAt: z.string(), lastModifiedBy: coreUserReference.optional(), customProperties: coreStringsMap}); export const coreAccount = z.object({id: z.string(), domainId: z.string(), alias: z.string().min(1).max(75), ledgerId: z.string().min(1).max(100).optional(), providerDetails: coreAccountProviderInformation, lock: coreLockStatus, metadata: coreEntityMetadata}); export const coreAccountProcessingDetailsCompleted = z.object({status: z.literal("Completed")}); export const coreAccountProcessingDetailsInterrupted = z.object({reason: z.string().min(1).max(200), status: z.literal("Interrupted")}); export const coreApiPendingAccountProcessingHint = z.enum(["TransientIssue", "InternalError"]); export const coreAccountProcessingDetailsPending = z.object({hint: coreApiPendingAccountProcessingHint.optional(), status: z.literal("Pending")}); export const coreApiPreparingAccountProcessingHint = z.enum(["TransientIssue", "InternalError"]); export const coreAccountProcessingDetailsPreparing = z.object({hint: coreApiPreparingAccountProcessingHint.optional(), status: z.literal("Preparing")}); export const coreApiRecoveringAccountProcessingHint = z.enum(["TransientIssue", "InternalError"]); export const coreAccountProcessingDetailsRecovering = z.object({hint: coreApiRecoveringAccountProcessingHint.optional(), status: z.literal("Recovering")}); export const coreAccountProcessingDetailsTracked = z.object({status: z.literal("Tracked")}); export const coreAccountProcessingDetails = z.discriminatedUnion("status", [coreAccountProcessingDetailsCompleted, coreAccountProcessingDetailsInterrupted, coreAccountProcessingDetailsPending, coreAccountProcessingDetailsPreparing, coreAccountProcessingDetailsRecovering, coreAccountProcessingDetailsTracked]); export const coreApiAccountLedgerProcessingActivated = z.object({ledgerId: z.string().min(1).max(100), lastBalancesUpdateRequestedAt: z.string().optional(), lastBalancesUpdateProcessedAt: z.string().optional(), status: z.literal("Activated")}); export const coreAccountLedgerProcessingDetailsPendingHint = z.enum(["TransientIssue", "InternalError"]); export const coreAccountLedgerProcessingDetailsPending = z.object({hint: coreAccountLedgerProcessingDetailsPendingHint.optional(), status: z.literal("Pending")}); export const coreAccountLedgerProcessingDetailsPreparingHint = z.enum(["TransientIssue", "InternalError"]); export const coreAccountLedgerProcessingDetailsPreparing = z.object({hint: coreAccountLedgerProcessingDetailsPreparingHint.optional(), status: z.literal("Preparing")}); export const coreAccountLedgerProcessingDetailsRecoveringHint = z.enum(["TransientIssue", "InternalError"]); export const coreAccountLedgerProcessingDetailsRecovering = z.object({hint: coreAccountLedgerProcessingDetailsRecoveringHint.optional(), status: z.literal("Recovering")}); export const coreAccountLedgerProcessingDetailsTrackedHint = z.enum(["TransientIssue", "InternalError"]); export const coreAccountLedgerProcessingDetailsTracked = z.object({hint: coreAccountLedgerProcessingDetailsTrackedHint.optional(), status: z.literal("Tracked")}); export const coreAccountLedgerProcessingDetails = z.discriminatedUnion("status", [coreAccountLedgerProcessingDetailsPending, coreAccountLedgerProcessingDetailsPreparing, coreAccountLedgerProcessingDetailsRecovering, coreAccountLedgerProcessingDetailsTracked]); export const coreApiAccountLedgerProcessingActivating = z.object({ledgerId: z.string().min(1).max(100), processing: coreAccountLedgerProcessingDetails, status: z.literal("Activating")}); export const coreApiAccountLedgerProcessingAvailable = z.object({ledgerId: z.string().min(1).max(100), status: z.literal("Available")}); export const coreApiAccountLedgerProcessingAwaitingLedgerActivation = z.object({ledgerId: z.string().min(1).max(100), status: z.literal("AwaitingLedgerActivation")}); export const coreApiAccountLedgerProcessingUnavailable = z.object({ledgerId: z.string().min(1).max(100), status: z.literal("Unavailable")}); export const coreApiAccountLedgerProcessing = z.discriminatedUnion("status", [coreApiAccountLedgerProcessingActivated, coreApiAccountLedgerProcessingActivating, coreApiAccountLedgerProcessingAvailable, coreApiAccountLedgerProcessingAwaitingLedgerActivation, coreApiAccountLedgerProcessingUnavailable]); export const coreAccountAdditionalDetails = z.object({processing: coreAccountProcessingDetails, lastBalancesUpdateRequestedAt: z.string().optional(), lastBalancesUpdateProcessedAt: z.string().optional(), ledgers: z.array(coreApiAccountLedgerProcessing)}); export const coreApiAccount = z.object({data: coreAccount, signature: z.string(), signingKey: z.string(), additionalDetails: coreAccountAdditionalDetails.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 }; /** * Get account details * * GET /v1/domains/{domainId}/accounts/{accountId} */ export const getApiV1DomainsDomainIdAccountsAccountId = async (args: GetApiV1DomainsDomainIdAccountsAccountIdArgs, options: GetApiV1DomainsDomainIdAccountsAccountIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, httpAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (httpAuth !== undefined) headers.set('authorization', `Bearer ${httpAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/domains/${encodeURIComponent(String(args.domainId))}/accounts/${encodeURIComponent(String(args.accountId))}${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(coreApiAccount, await res.json()) };