import type { SniEndpoint } from '@heroku/types/3.sdk'; import type { ResourceCtx } from '../../../core/extend-resource.js'; import type { Poller } from '../../../utils/poller.js'; /** A PEM certificate chain (leaf first) and its private key. */ export type SniCertificate = { certificateChain: string; privateKey: string; }; type CreateAndAssociateCommonOptions = { /** * Progress hooks for the domain readiness wait after upload: `domainPoller.onStart()` * before polling begins, `domainPoller.onStop()` once the domains are ready. Not called * when there's nothing to wait for. If the wait throws, `onStop` isn't called (see `Poller`). */ domainPoller?: Poller; intervalMs?: number; signal?: AbortSignal; timeoutMs?: number; }; /** * Thrown when a step after the upload fails (the domain wait, `chooseDomains`, or an * association). The certificate exists on the app by then, so the error names the * created endpoint for cleanup; the original error is its `cause`, and its `statusCode` * is the cause's, when it has one. */ export declare class SniEndpointAssociationError extends Error { readonly appIdentity: string; readonly sniEndpoint: SniEndpoint; readonly id = "association_failed"; readonly statusCode: number | undefined; constructor(appIdentity: string, sniEndpoint: SniEndpoint, cause: unknown); get body(): { id: string; message: string; sni_endpoint: { id: string; name: string; }; }; } /** * How to choose the hostnames to associate. Pass at most one of: * - `domains`: a fixed list, checked before upload. * - `chooseDomains`: a callback that chooses from the matching hostnames after upload. * - neither: associate none, but only if the certificate covers none of the app's domains; * otherwise throws `CertificateDomainsRequiredError` before upload, listing them. */ export type CreateAndAssociateOptions = CreateAndAssociateCommonOptions & ({ /** Given the app hostnames the certificate covers, returns the subset to associate. */ chooseDomains: (candidates: string[]) => Promise; domains?: never; } | { chooseDomains?: never; /** * The hostnames to associate, for callers that can't prompt. Checked before * anything is uploaded: each must be one of the app's domains (case-insensitively) * and covered by the certificate (see `certificateNames`), or a * `CertificateDomainsMismatchError` is thrown. `[]` associates none. */ domains: string[]; } | { chooseDomains?: never; domains?: never; }); /** * Create an SNI endpoint (SSL certificate) on an app and associate it with the * app's matching domains. * * Which domains a certificate covers is read locally from the certificate (see * `certificateNames` and `certificateNameCovers`), so it can be checked before upload. * * Steps: * 1. Read the certificate's names. With `domains`, check the requested hostnames; * with neither option, check that the certificate covers none of the app's domains. * 2. Create the SNI endpoint. * 3. Wait for domains to reach ready status (`succeeded`/`none`): the requested ones * with `domains`, all of the app's pending domains with `chooseDomains`. `timeoutMs` * (default 30s) applies per pending domain, polling every `intervalMs` (default 1s). * 4. With `chooseDomains`: list the app's domains and, if the certificate covers any, * call `chooseDomains` with them to choose which to associate. * 5. Associate the chosen hostnames with the endpoint in parallel (`domain.update`). * * @throws `TypeError` (before upload) if both `domains` and `chooseDomains` are passed. * @throws `CertificateParseError` (before upload) if the certificate chain can't be read. * @throws `CertificateDomainsMismatchError` (before upload) if `domains` names a * hostname that isn't on the app or isn't covered by the certificate. * @throws `CertificateDomainsRequiredError` (before upload) if neither option is passed * and the certificate covers some of the app's domains. * @throws `SniEndpointAssociationError` (after upload, naming the created endpoint) if * the domain readiness wait times out or a domain fails, `chooseDomains` throws, or * an association call rejects. An abort is rethrown as is. * @returns the SNI endpoint. When domains were associated, it's re-fetched so its * `domains` list includes them; if that re-fetch fails, its error is thrown as is * (the associations were made). */ export declare function createAndAssociate(ctx: Pick, appIdentity: string, certificate: SniCertificate, options?: CreateAndAssociateOptions): Promise; export {};