import type { TransferCreateResult, TransferInfoByAppResult } from '@heroku/types/data'; import type { ResourceCtx } from '../../core/extend-resource.js'; import type { Poller } from '../../utils/poller.js'; import type { ResolvedPgDatabaseWithAttachment } from './internal/resolve-pg-database.js'; import type { WaitForTransferOptions } from './transfer/wait-for-transfer.js'; export type DatabaseCopyEndpoint = { /** Confirmation value and readable endpoint name used by the CLI. */ confirm: string; /** Present for Heroku Postgres attachments; absent for a raw external URL. */ database?: PublicResolvedPgDatabaseWithAttachment; name: string; }; type PublicResolvedPgDatabaseWithAttachment = { addon: Pick; attachment: Pick & { addon: Pick; }; }; /** * Progress callbacks are non-blocking: synchronous failures and async * rejections observed by transfer completion are reported, while pending * hooks cannot delay polling. Later rejections are handled but excluded from * the returned warning snapshot. Callback order is `beforeCopy`, credential * lookup, `onCredentialsChecked`, then `copyPoller.onStart`; transfer creation * follows, then polling and its callbacks. `beforeCopy` is awaited. Credential * lookup finishes (or times out) after `beforeCopy`; `onCredentialsChecked` * then runs before transfer creation, within the lookup's remaining timeout * budget. This ordering intentionally differs from the legacy `pg:copy` flow: * `beforeCopy` is the destructive-operation confirmation point, and the * advisory credential count is unavailable there so it cannot change what the * caller confirms. */ export type DatabaseCopyOptions = WaitForTransferOptions & { /** * Runs after resolving and validating both endpoints, before credential * lookup and transfer creation. This is the destructive confirmation point; * the advisory credential count is intentionally unavailable and cannot * affect the confirmation. The credential callback runs after this hook. */ beforeCopy?: (preview: { source: DatabaseCopyEndpoint; target: DatabaseCopyEndpoint; }) => Promise | void; /** Progress hooks around transfer creation. */ copyPoller?: Poller<{ source: DatabaseCopyEndpoint; target: DatabaseCopyEndpoint; }>; /** * Maximum combined time for advisory source credential lookup and callback. * Must be positive; capped at 60 seconds. Defaults to 10 seconds. If lookup * exhausts the deadline, its callback is invoked without waiting. */ credentialLookupTimeoutMs?: number; /** Legacy pg:copy token for Basic-auth source credential lookup only. */ credentialToken?: string; /** * Runs after source credential lookup settles or times out, before transfer * creation; shares the remaining timeout budget. If lookup consumes it, the * callback is invoked but not awaited. */ onCredentialsChecked?: (result: Pick & { warning?: string; }) => Promise | void; /** * Called after each transfer poll. Async work is observed for rejection but * never awaited, so a slow progress callback cannot delay timeout or abort. */ onPoll?: (transfer: TransferInfoByAppResult | undefined) => void; /** Progress hooks around transfer polling. */ waitPoller?: Poller; }; export type DatabaseCopyResult = { /** Number of credentials found on a Heroku source; undefined for external sources. */ credentialCount?: number; /** True when the CLI should display the additional-credentials warning. */ hasAdditionalCredentials: boolean; source: DatabaseCopyEndpoint; target: DatabaseCopyEndpoint; transfer: TransferInfoByAppResult; /** * Non-fatal credential lookup and progress callback failures observed before * transfer completion. Later async rejections are handled but excluded; this * snapshot is not mutated after return. */ warnings: string[]; }; /** A post-create failure that retains the remote transfer identity and outcome. */ export declare class DatabaseCopyTransferError extends Error { readonly transfer?: TransferInfoByAppResult; readonly transferId: string; constructor(transferId: string, message: string, transfer?: TransferInfoByAppResult, options?: { aborted?: boolean; cause?: Error; }); } /** * Resolve classic `pg:copy` inputs, create a v11 transfer, and wait for it to * finish. Raw PostgreSQL URLs remain supported alongside the attachment * resolver's identities (attachment/config-var names, attachment UUIDs, and * globally unique add-on names, optionally qualified as `app::identity`), but at least * one endpoint must resolve to a Heroku Postgres attachment. The SDK's data * service host follows the `heroku-fetch` `data` service configuration, * including its environment overrides and default host. An explicit * `clientOptionsByService.data.baseUrl` can also configure the data client. * Credential lookup uses the data client's normal * Bearer-token auth unless `credentialToken` is provided. That optional token * is used only for the legacy Basic-auth credential lookup; transfer and * polling requests always use the normal data client. */ export declare function copyDatabase(ctx: Pick, appIdentity: string, sourceIdentity: string, targetIdentity: string, options?: DatabaseCopyOptions): Promise; export declare const databaseCopyExtensions: import("../../core/extend-resource.js").ResourceExtension<"data", "database", { copyForApp: (appIdentity: string, sourceIdentity: string, targetIdentity: string, options?: DatabaseCopyOptions) => Promise; }>; export {};