@nullplatform/ingest
Version:
Client SDK for the nullplatform ingest API: push snapshots and delta events from a collector into the catalog and other targets, follow runs, replay and drift checks
1,151 lines • 61.6 kB
text/typescript
import { $ as Mapping, $t as EntityOrigin, A as DriftCheck, At as SourceSpec$1, B as EndpointReference, Bt as TargetSummary, C as Accepted, Ct as Sort, D as DestinationPatch, Dt as SourceFilter, E as DestinationFilter, Et as SourceFields, F as EndpointErrorRule, Ft as SourceTypeRevision, G as EntitySummary, Gt as ClearSemantics, H as Entity, Ht as Upserted, I as EndpointFilter, It as SourceTypeSpec, J as Input, Jt as DriftCheckStatus, K as EventSpec, Kt as DeletePolicy, L as EndpointGone, Lt as SourceTypeUpsertSpec, M as Endpoint, Mt as SourceType, N as EndpointAsWritten, Nt as SourceTypeFilter, O as DestinationRevision, Ot as SourcePatch, P as EndpointCall, Pt as SourceTypePatch, Q as InputSummary, Qt as Engine, R as EndpointPaging, Rt as SourceUpsertSpec, S as WatchContext, St as RunSettings, T as Destination, Tt as SourceDestinationFilter, U as EntityFilter, Ut as AdoptPolicy, V as EndpointSummary, Vt as TypeMappingCreate, W as EntityResult, Wt as AssignedBy, X as InputFilter, Xt as DriftType, Y as InputCreate, Yt as DriftPolicy, Z as InputSpec, Zt as EmptyLinkSet, _ as SnapshotContext, _n as TargetErrorOutcome, _t as Revision, a as CollectorEvents, an as MappingRevisionAction, at as MappingRevision, b as SourceSpec, bt as RunFilter, c as CollectorSource, cn as OperationBody, ct as MaybeNamedBy, d as IngestPort, dn as PagingStyle, dt as Page, en as EventOp, et as MappingCreate, f as LastRun, fn as ReplayStatus, ft as PageOptions, g as RunSource, gn as TargetDeletePolicy, gt as ReplayRequest, h as RunPort, hn as SourceTypeRevisionAction, ht as ReplayFilter, i as CollectorDefinition, in as InputStatus, it as MappingPreviewSpec, j as DriftCheckFilter, jt as SourceStats, k as DestinationSpec, kt as SourceRevision, l as DEFAULT_MAPPING_TARGET, ln as OperationName, lt as NamedBy, m as ObservedRecord, mn as SourceRevisionAction, mt as Replay, n as CollectedRecord, nn as FieldRule, nt as MappingPatch, o as CollectorMapping, on as OnConflict, ot as MappingSample, p as Logger, pn as RunStatus, pt as Paging, q as FinalizeOptions, qt as DestinationRevisionAction, r as CollectorContext, rn as HttpMethod, rt as MappingPreview, s as CollectorRunSettings, sn as OnDelete, st as MappingWriteOptions, t as CollectedEventOptions, tn as FieldComparison, tt as MappingFilter, u as EventPort, un as Outcome, ut as OwnRunSettings, v as SnapshotRecords, vn as UpsertOutcome, vt as Run, w as ApiError, wt as Source, x as UpsertedSource, xt as RunReconciliation, y as SnapshotResult, yt as RunCounters, z as EndpointReadOptions, zt as TargetFilter } from "./types-B500HM6G.cjs";
//#region src/inputs.d.ts
/** An input ready to send: id and observation time filled in. */
type PreparedInput = InputCreate & {
observedAt: string;
};
//#endregion
//#region src/batcher.d.ts
/** How inputs are batched (`IngestClientOptions.batching`, or a batcher's own). */
interface BatcherOptions {
/** Inputs per request (the API accepts up to 500). */
maxBatch: number;
/** Encoded bytes per request (the API accepts up to 8 MiB). */
maxBytes: number;
/** Flush automatically this often; 0 disables the timer. */
flushIntervalMs: number;
/** Concurrent requests while flushing. */
concurrency: number;
}
/** A batcher's counts so far. */
interface BatcherStats {
/** Inputs waiting to be sent. */
buffered: number;
/** Inputs sent. */
sent: number;
/** Inputs the API accepted (new). */
accepted: number;
/** Inputs the API had already (an id sent before): not applied twice. */
duplicates: number;
}
/** The batching behind run handles and event batchers (see the module comment). */
declare class Batcher {
#private;
/** What it buffered, sent and had accepted so far. */
readonly stats: BatcherStats;
/**
* @param options Batch bounds, timer and concurrency.
* @param send Sends one batch (the inputs are prepared: id and observation time set).
* @param stamp What `send` adds to every input, counted in its size.
* @throws {RangeError} For batching options out of range (see `checkBatching`).
*/
constructor(options: BatcherOptions, send: (batch: PreparedInput[]) => Promise<Accepted>, stamp?: Partial<InputSpec>);
/** The failure that stopped this batcher, if one did. */
get failure(): unknown;
/** Buffer one input; returns its id. Flushes when a limit is reached. */
add(input: InputSpec): string;
/** Send everything buffered so far; resolves when it has been accepted. */
flush(): Promise<void>;
/** Flush and refuse further inputs. */
close(): Promise<void>;
}
//#endregion
//#region src/event-batcher.d.ts
/** An event's options: when it was observed, and its input id. */
type EventOptions = Pick<InputSpec, 'id' | 'observedAt'>;
/**
* Events of one source, from `IngestClient.events.batcher`: buffered and sent
* in batches by count, bytes and time. `close` it on shutdown.
*/
declare class EventBatcher {
#private;
/** Made by `IngestClient.events.batcher`; not meant to be built by hand. */
constructor(send: (events: EventSpec[]) => Promise<Accepted>, batching: BatcherOptions);
/** What the batcher buffered, sent and had accepted so far. */
get stats(): BatcherStats;
/**
* Buffer an upsert of an entity's state.
* @param options `observedAt` (when the state was observed; now by default) and `id` (a UUIDv7).
* @returns Its input id.
* @throws {TypeError} For an id that is not a UUIDv7.
*/
upsert(type: string, payload: unknown, options?: EventOptions): string;
/**
* Buffer a delete: the entity the payload maps to is deleted (only one this source owns).
* @param options `observedAt` (when it was deleted; now by default) and `id` (a UUIDv7).
* @returns Its input id.
* @throws {TypeError} For an id that is not a UUIDv7.
*/
delete(type: string, payload: unknown, options?: EventOptions): string;
/** Send what is buffered now (events are otherwise sent about every second). */
flush(): Promise<void>;
/** Send what is buffered and refuse further events. Call it on shutdown. */
close(): Promise<void>;
}
//#endregion
//#region src/poll.d.ts
/** How a wait helper polls. */
interface WaitOptions {
/** Poll interval. Default 500 ms. */
intervalMs?: number;
/** Give up (with a `TimeoutError`) after this long. Default 10 minutes. */
timeoutMs?: number;
}
//#endregion
//#region src/run-handle.d.ts
/** The run calls a handle drives (`IngestClient.runs` provides them). */
interface RunOperations {
/** Read a run by id (`null` when there is none). */
get(runId: string): Promise<Run | null>;
/** Send one batch of records to an open run. */
sendRecords(sourceId: string, runId: string, records: InputSpec[]): Promise<Accepted>;
/** Finalize a run (or, with `dryRun`, assess it). */
finalize(runId: string, options?: FinalizeOptions): Promise<Run>;
/** Abort a run: nothing is deleted. */
abort(runId: string): Promise<Run>;
/** Wait until every input of the run is applied. */
waitApplied(runId: string, options?: WaitOptions): Promise<Run>;
/** Wait until the run is closed. */
waitClosed(runId: string, options?: WaitOptions): Promise<Run>;
/** Wait until a dry-run finalize is assessed. */
waitDryRun(runId: string, options?: WaitOptions): Promise<Run>;
}
/**
* A run in progress, from `IngestClient.runs.open`. `add` every record of the
* listing, then `finalize`; on any failure `abort` (it deletes nothing).
*
* @example
* const run = await ingest.runs.open(source.id, { onConflict: OnConflict.ABORT });
* try {
* items.forEach((item) => run.add({ type: 'deployment', observedAt, payload: item }));
* const done = await run.finalize();
* } catch (error) {
* await run.abort();
* throw error;
* }
*/
declare class RunHandle {
#private;
/** Made by `IngestClient.runs.open`; not meant to be built by hand. */
constructor(runs: RunOperations, run: Run, batching: BatcherOptions);
/** The run's id. */
get id(): string;
/** The id of the source the run belongs to. */
get sourceId(): string;
/** The run as last read from the API. */
get run(): Run;
/** What the handle buffered, sent and had accepted so far. */
get stats(): BatcherStats;
/**
* Buffer one record of the listing; it is sent in a batch.
* @returns Its input id: the given UUIDv7, or a generated one.
* @throws {TypeError} For an id that is not a UUIDv7.
* @throws {IngestError} The failure of an earlier batch: the run can no longer be finalized.
*/
add(record: Omit<InputSpec, 'op'>): string;
/**
* Send what is buffered now (records are otherwise sent as batches fill).
* @throws {IngestError} When a batch fails for good; the run can no longer be finalized.
*/
flush(): Promise<void>;
/** Read the run again from the API; {@link RunHandle.run} answers it after. */
refresh(): Promise<Run>;
/**
* Send what is buffered and wait until every record of the run is applied.
* @throws {TimeoutError} When it is not within `options.timeoutMs`.
*/
waitApplied(options?: WaitOptions): Promise<Run>;
/**
* Send what is buffered, finalize, and wait until the run is closed (or,
* for a dry run, assessed: it stays open).
* @param options Guard overrides for this run, and `dryRun`.
* @param wait How long to wait for it.
* @returns The run: `status` is `RunStatus.COMPLETED` or `RunStatus.GUARD_TRIPPED`
* (nothing deleted), and `reconciliation` says what was seen, stale and deleted.
* @throws {IngestError} When a batch failed: the run cannot be finalized; abort it.
*/
finalize(options?: FinalizeOptions, wait?: WaitOptions): Promise<Run>;
/** Close the run without reconciling: nothing is deleted. Call it on any failure. */
abort(): Promise<Run>;
}
//#endregion
//#region src/tokens/token-provider.d.ts
/**
* Where the client gets its bearer token. A collector normally holds a
* nullplatform API key (`ApiKeyToken`); a caller that already has a token, or
* its own way of getting one, uses `StaticToken` or `CallbackToken`.
*/
interface TokenProvider {
/** A bearer token (without the `Bearer ` prefix). */
get(): Promise<string>;
/** Forget the cached token after a 401. */
invalidate(): void;
/**
* Whether a 401 is worth a second try with a new token; `false` for a token
* that cannot change (a 401 then reaches the caller at once). Default true.
*/
readonly refreshable?: boolean;
}
//#endregion
//#region src/client.d.ts
/** Where API keys are exchanged for tokens unless `authBaseURL` says otherwise. */
declare const DEFAULT_AUTH_BASE_URL = "https://api.nullplatform.com";
/** The public ingest API, unless `baseURL` says otherwise. */
declare const DEFAULT_BASE_URL = "https://api.nullplatform.com/catalog/ingest";
/**
* How an `IngestClient` reaches the API: its credentials (an API key, a
* token, or a token callback), where the API is, and how requests are
* retried and inputs batched. Nothing is read from the environment.
*/
interface IngestClientOptions {
/**
* The ingest API. Default: the public one, https://api.nullplatform.com/catalog/ingest.
* Set it only to reach another installation (a local one, in development).
*/
baseURL?: string;
/** A nullplatform API key, exchanged for tokens at `authBaseURL`. */
apiKey?: string;
/** A ready token (with or without `Bearer `). */
token?: string;
/** Your own way to get a token; called again after a 401. */
getToken?: () => Promise<string> | string;
/** Where API keys are exchanged. Default: https://api.nullplatform.com */
authBaseURL?: string;
/** Override `fetch` (tests, proxies). Default: the global `fetch`. */
fetchImpl?: typeof fetch;
/** Per-request timeout. Default 30 s. */
timeoutMs?: number;
/** Retries of a 5xx or network failure. Default 4. */
maxRetries?: number;
/** Backoff base. Default 250 ms. */
retryBaseMs?: number;
/** Backoff ceiling. Default 10 s. */
retryMaxMs?: number;
/** How long a request may wait out 429s (backlog quota) before failing. Default 15 min. */
backpressureMs?: number;
/** Batching defaults for run handles and event batchers. */
batching?: Partial<BatcherOptions>;
}
/** How `runs.open` opens a run: the record types it covers, and what to do about a run already open. */
interface OpenRunOptions {
/** Record types the snapshot covers; all the source maps when omitted. */
types?: string[];
/** What to do when the source already has an open run: abort it and open a new one, or fail. */
onConflict?: OnConflict;
}
/** `endpoints.get`: as it runs by default, as it was written with `{ effective: false }`. */
interface EndpointGet {
(targetId: string, endpointId: string, options?: {
effective?: true;
}): Promise<Endpoint | null>;
(targetId: string, endpointId: string, options: {
effective: false;
}): Promise<EndpointAsWritten | null>;
(targetId: string, endpointId: string, options?: EndpointReadOptions): Promise<Endpoint | EndpointAsWritten | null>;
}
/**
* The client of the nullplatform ingest API. Create one per process and share
* it: it holds the token, the transport (retries, backpressure) and the
* batching defaults. Every resource is a namespace (`sources`, `sourceTypes`, `mappings`, `mappingPreviews`, `destinations`, `targets`, `endpoints`, `runs`, `events`, `inputs`, `replays`, `entities`, `driftChecks`); a resource that belongs to a source or to a
* source type is listed and created under it (`listForSource`, `listForSourceType`)
* and read, changed and deleted by its own id.
*
* @example
* const ingest = new IngestClient({ apiKey: process.env.NULLPLATFORM_API_KEY });
* const [source] = await ingest.sources.upsert([{ slug: 'prod-eu', name: 'Production EU', type: 'kubernetes' }]);
*/
declare class IngestClient {
#private;
/** Where the bearer of every request comes from (the API key's exchange, a token, or yours). */
readonly tokens: TokenProvider;
/**
* @param options Exactly one of `apiKey`, `token` or `getToken`; everything
* else has a default (the public API, 30 s timeouts, 4 retries).
* @throws {Error} When not exactly one of `apiKey`, `token`, `getToken` is given.
*/
constructor(options: IngestClientOptions);
/** Sources: one system of record each (a cluster, an account), the unit of ownership. */
readonly sources: {
/**
* Create a source. Creating a deleted slug revives it under the same id.
* Prefer {@link IngestClient.sources.upsert} in a collector.
* @param spec Its slug (unique in the organization), name and type; optionally its NRN,
* attributes and the run settings it overrides.
* @returns The source, with the id the API minted.
* @throws {IngestError} 409 when a live source has the slug; 400 for an unknown type.
*/
create: (spec: SourceSpec$1) => Promise<Source>;
/**
* Read a source by id, a deleted one too (`deletedAt` set).
* @returns The source, or `null` when there is none.
* @throws {IngestError} 403 when the token may not read it.
*/
get: (id: string) => Promise<Source | null>;
/**
* Find the live source of a slug, looked for at `nrn` (the organization's
* root by default): a key granted beneath the organization finds its
* sources only where it is granted.
* @returns The source, or `null` when there is none.
* @throws {IngestError} 403 when the token may not list sources.
*/
find: (slug: string, options?: {
nrn?: string;
}) => Promise<Source | null>;
/**
* List the organization's sources, narrowed by slug or NRN; deleted ones with `deleted`.
* @throws {IngestError} 400 for an unknown sort field; 403 when the token may not list sources.
*/
list: (filter?: SourceFilter) => Promise<Page<Source>>;
/**
* A source's revisions, newest first: every write (created or revived,
* changed, deleted), who made it, and what the source set itself then.
* @throws {IngestError} 404 when there is no such source; 403 when the token may not read it.
*/
revisions: (id: string, page?: PageOptions) => Promise<Page<SourceRevision>>;
/**
* The source at a glance: its backlog, last activity, and what became of
* the inputs settled since `since` (24 h by default).
* @throws {IngestError} 404 when there is no such source; 403 when the token may not read it.
*/
stats: (id: string, options?: {
since?: string;
}) => Promise<SourceStats>;
/**
* Change a source's name, description, attributes or run settings (a run
* setting set to `null` goes back to its type's). Needs `ingest:source:write`.
* @throws {IngestError} 400 for an invalid change; 404 when there is no such source; 403 when the token may not write it.
*/
update: (id: string, patch: SourcePatch) => Promise<Source>;
/**
* Soft-delete a source. Its input log, its entities and its runs are kept,
* and the entities it wrote are left in their targets.
* @returns The source, with `deletedAt` set.
* @throws {IngestError} 409 while a run is open; 404 when there is no such source; 403 when the token may not delete it.
*/
delete: (id: string) => Promise<Source>;
/**
* Sources as `specs` define them, each found by its slug (at its `nrn`,
* when it names one): created when missing (a deleted one revived where it
* lived), updated where its name, description, attributes (replaced whole)
* or a run setting it names differ, nothing sent when they match. Never
* deletes. A collector sends only what it owns: what it sends is set again
* on every start, over any change made in the console.
* @returns The sources, in the order of `specs`, each with what the upsert did
* (`upserted`: created, updated or unchanged); keep their ids, every other call takes them.
* @throws {Error} Before sending anything, when two specs name one slug; when
* a slug is a source of another type, or lives at another NRN (neither can change).
* @example
* const [source] = await ingest.sources.upsert([
* { slug: 'prod-eu', name: 'Production EU', type: 'kubernetes' },
* ]);
*/
upsert: (specs: SourceUpsertSpec[]) => Promise<Upserted<Source>[]>;
};
/** Source types: global ones (nullplatform's, such as `kubernetes`) and the organization's own. */
readonly sourceTypes: {
/**
* List the types the organization sees: the global ones and its own; `slug` finds one.
* @throws {IngestError} 403 when the token may not list source types.
*/
list: (filter?: SourceTypeFilter) => Promise<Page<SourceType>>;
/**
* Read a type by id.
* @returns The type, or `null` when there is none.
* @throws {IngestError} 403 when the token may not read it.
*/
get: (id: string) => Promise<SourceType | null>;
/**
* Find the live type a slug names for the organization (a global one, or its own).
* @returns The type, or `null` when there is none.
* @throws {IngestError} 403 when the token may not list source types.
*/
find: (slug: string) => Promise<SourceType | null>;
/**
* Create one of the organization's own types; a deleted one of the slug is
* revived under its id. Its run settings are every source's defaults.
* @throws {IngestError} 409 when the slug is taken, by the organization or by a global type.
*/
create: (spec: SourceTypeSpec) => Promise<SourceType>;
/**
* Change a type's name, description or run settings (only the settings named).
* @throws {IngestError} 400 for an invalid change; 404 when there is no such type; 403 for nullplatform's (global) types.
*/
update: (id: string, patch: SourceTypePatch) => Promise<SourceType>;
/**
* A type's revisions, newest first: every write, who made it, and what the type became.
* @throws {IngestError} 404 when there is no such type; 403 when the token may not read it.
*/
revisions: (id: string, page?: PageOptions) => Promise<Page<SourceTypeRevision>>;
/**
* Soft-delete a type.
* @throws {IngestError} 409 while a live source or mapping uses it.
*/
delete: (id: string) => Promise<SourceType>;
/**
* The organization's own types as `specs` define them, each found by its
* slug: created when missing (a deleted one revived), updated where its
* name, description or a run setting it names differ, nothing sent when
* they match. Never deletes.
* @returns The types, in the order of `specs`.
* @throws {Error} Before sending anything, when two specs name one slug.
* @throws {IngestError} 409 when a global type holds a slug; 403 when a
* slug names a global type that differs (nullplatform's are not the organization's to change).
* @example
* const [github] = await ingest.sourceTypes.upsert([
* { slug: 'github', name: 'GitHub org', runs: { maxDeleteRatio: 0.2 } },
* ]);
*/
upsert: (specs: SourceTypeUpsertSpec[]) => Promise<Upserted<SourceType>[]>;
};
/**
* Mappings: how a record type becomes entities (an expression), owned by a
* source type (shared by every source of it) or by one source. Where a
* mapping writes is its destinations'.
*/
readonly mappings: {
/**
* Create a mapping of a source type: the organization's own (with
* `global`, nullplatform's, an operator's call). Creating a deleted slug
* revives it.
* @param options `dryRun` checks it as it would be written and stores
* nothing. What it makes of a record is `mappingPreviews.create`.
* @throws {IngestError} 400 for an invalid expression; 409 when the slug is live.
*/
createForSourceType: (sourceTypeId: string, spec: TypeMappingCreate, options?: MappingWriteOptions) => Promise<Mapping>;
/**
* Create a source's own mapping: for a source whose type shares none for
* the record type, or to customize one (bind it where the type's is bound,
* and it shadows it). Creating a deleted slug revives it.
* @param options `dryRun` checks it as it would be written and stores
* nothing. What it makes of a record is `mappingPreviews.create`.
* @throws {IngestError} 400 for an invalid expression; 409 when the slug is live.
*/
createForSource: (sourceId: string, spec: MappingCreate, options?: MappingWriteOptions) => Promise<Mapping>;
/**
* Read a mapping by id (a type's or a source's).
* @returns The mapping, or `null` when there is none.
* @throws {IngestError} 403 when the token may not read it.
*/
get: (id: string) => Promise<Mapping | null>;
/**
* Find a source's own live mapping of a slug (its record type, unless named otherwise).
* @returns The mapping, or `null` when there is none.
* @throws {IngestError} 404 when there is no such source; 403 when the token may not list its mappings.
*/
findForSource: (sourceId: string, slug: string) => Promise<Mapping | null>;
/**
* Find a type's live mapping of a slug the organization sees: nullplatform's
* or its own (a slug names one of them on a type).
* @returns The mapping, or `null` when there is none.
* @throws {IngestError} 404 when there is no such type; 403 when the token may not list its mappings.
*/
findForSourceType: (sourceTypeId: string, slug: string) => Promise<Mapping | null>;
/**
* List a type's mappings the organization sees: the global ones and its own.
* @throws {IngestError} 404 when there is no such type; 403 when the token may not list its mappings.
*/
listForSourceType: (sourceTypeId: string, filter?: MappingFilter) => Promise<Page<Mapping>>;
/**
* List a source's own mappings.
* @throws {IngestError} 404 when there is no such source; 403 when the token may not list its mappings.
*/
listForSource: (sourceId: string, filter?: MappingFilter) => Promise<Page<Mapping>>;
/**
* Change a mapping's definition (engine, expression): a new revision, which
* every destination following the latest applies. A change of nothing
* writes nothing.
* @param options `dryRun` checks it as it would be written and stores
* nothing. What it makes of a record is `mappingPreviews.create`.
* @throws {IngestError} 400 for an expression that does not compile; 404 when there is no such mapping; 403 for nullplatform's (global) mappings.
*/
update: (id: string, patch: MappingPatch, options?: MappingWriteOptions) => Promise<Mapping>;
/**
* Soft-delete a mapping.
* @throws {IngestError} 409 while a live destination binds it.
*/
delete: (id: string) => Promise<Mapping>;
/**
* A mapping's revisions, newest first: every definition it had, kept for good.
* @throws {IngestError} 404 when there is no such mapping; 403 when the token may not read it.
*/
revisions: (id: string, page?: PageOptions) => Promise<Page<MappingRevision>>;
/**
* A type's mappings as `specs` define them (the organization's own), each
* found by its slug (the record type by default) among the ones the
* organization sees: created when missing (a deleted one revived), its
* definition updated where it differs, nothing sent when it matches.
* Never deletes. Where they are written is `destinations.upsertForSourceType`.
* @returns The mappings, in the order of `specs`.
* @throws {Error} Before sending anything, when two specs name one slug;
* when a slug's mapping maps another record type.
* @throws {IngestError} 403 when a slug is nullplatform's mapping and the
* spec differs from it (customize it under another slug); 400 for an invalid expression.
* @example
* const [pods] = await ingest.mappings.upsertForSourceType(type.id, [
* { slug: 'pod-team', recordType: 'pod', engine: Engine.JSONATA, expression },
* ]);
*/
upsertForSourceType: (sourceTypeId: string, specs: MappingCreate[]) => Promise<Upserted<Mapping>[]>;
/**
* A source's own mappings as `specs` define them, each found by its slug
* (the record type by default): created when missing (a deleted one
* revived), its definition updated where it differs, nothing sent when it
* matches. Never deletes. For a collector of the organization's own type
* (a collector of a global type, `kubernetes`, defines none); where they
* are written is `destinations.upsertForSource`.
* @returns The mappings, in the order of `specs`.
* @throws {Error} Before sending anything, when two specs name one slug;
* when a slug's mapping maps another record type.
* @throws {IngestError} 400 for an invalid expression.
* @example
* const mappings = await ingest.mappings.upsertForSource(source.id, [
* { recordType: 'repository', engine: Engine.JSONATA, expression },
* ]);
* await ingest.destinations.upsertForSource(source.id, mappings.map((mapping) => ({
* mappingId: mapping.id, target: 'catalog', endpoint: `github-${mapping.recordType}`,
* })));
*/
upsertForSource: (sourceId: string, specs: MappingCreate[]) => Promise<Upserted<Mapping>[]>;
};
/** Mapping previews: what a mapping makes of a record, nothing stored. */
readonly mappingPreviews: {
/**
* Evaluate a mapping on a sample: a stored one as it is (`mappingId`), a
* definition not written yet, or a stored one changed by `definition`.
* Nothing is written. With `sourceId`, it is evaluated as that source
* (`$source`) and each entity validated against what the source applies.
* @returns What was evaluated, its output, its entities, and what each
* endpoint would say; a runtime error is the preview's `errors`.
* @throws {IngestError} 400 for an expression that does not compile, or a
* sample that is not exactly one of `payload` and `inputId`.
* @example
* const preview = await ingest.mappingPreviews.create({
* mappingId: mapping.id,
* sourceId: source.id,
* sample: { payload: deployment },
* });
*/
create: (spec: MappingPreviewSpec) => Promise<MappingPreview>;
};
/**
* Destinations: a mapping bound to an endpoint of a target, for every source
* of a type (the organization's) or for one source (which shadows the
* organization's of the same record type, target and endpoint). Created and
* listed under their owner; read, changed and deleted by their own id.
*/
readonly destinations: {
/**
* Bind mappings for every source of a type in the organization: one
* batch, all or none (1–100). Re-binding a deleted one revives it.
* @returns The destinations, in the order given.
* @throws {IngestError} 404 for an unknown mapping, target or endpoint; 409 for a key
* bound already. A refusal names its item: `data[i]: …`.
* @example
* await ingest.destinations.createForSourceType(type.id, [
* { mappingId: deployments.id, target: 'catalog', endpoint: 'k8s-deployment' },
* ]);
*/
createForSourceType: (sourceTypeId: string, specs: DestinationSpec[]) => Promise<Destination[]>;
/**
* Bind mappings for one source: one batch, all or none (1–100). Each
* shadows the organization's of the same record type, target and endpoint.
* @returns The destinations, in the order given.
* @throws {IngestError} 404 for an unknown mapping, target or endpoint; 409 for a key
* bound already. A refusal names its item: `data[i]: …`.
*/
createForSource: (sourceId: string, specs: DestinationSpec[]) => Promise<Destination[]>;
/**
* Read a destination by id, a deleted one too.
* @returns The destination, or `null` when there is none.
* @throws {IngestError} 403 when the token may not read it.
*/
get: (id: string) => Promise<Destination | null>;
/**
* List the organization's destinations for every source of a type, newest first.
* @throws {IngestError} 404 when there is no such type; 403 when the token may not list its destinations.
*/
listForSourceType: (sourceTypeId: string, filter?: DestinationFilter) => Promise<Page<Destination>>;
/**
* List what a source applies: its own destinations and the organization's
* of its type, after shadowing (`effective`, the default); with
* `effective: false`, its own destinations only.
* @example
* const applied = await ingest.destinations.listForSource(source.id);
* const types = new Set(applied.results.map((destination) => destination.recordType));
* @throws {IngestError} 404 when there is no such source; 403 when the token may not list its destinations.
*/
listForSource: (sourceId: string, filter?: SourceDestinationFilter) => Promise<Page<Destination>>;
/**
* Change a destination's endpoint (within its target), the revision it
* pins (`null`: follow the latest), its switch or its `onDelete`.
* @throws {IngestError} 400 for an invalid change; 404 when there is no such destination or endpoint; 409 when `onDelete: OnDelete.RESTRICT` refuses to stop applying.
*/
update: (id: string, patch: DestinationPatch) => Promise<Destination>;
/**
* Soft-delete a destination; its `onDelete` decides what becomes of what
* it wrote.
* @throws {IngestError} 409 when its `onDelete` is `RESTRICT` and it owns live entities.
*/
delete: (id: string) => Promise<Destination>;
/**
* A destination's revisions, newest first.
* @throws {IngestError} 404 when there is no such destination; 403 when the token may not read it.
*/
revisions: (id: string, page?: PageOptions) => Promise<Page<DestinationRevision>>;
/**
* The organization's destinations for every source of a type, as `specs`
* define them, each found by its mapping, target and endpoint: created
* when missing (in one batch, all or none), updated where its pin,
* switch or `onDelete` differ, nothing sent when they match. Never deletes
* one the specs leave out.
* @returns The destinations, in the order of `specs`.
* @example
* await ingest.destinations.upsertForSourceType(type.id, [
* { mappingId: deployments.id, target: 'catalog', endpoint: 'k8s-deployment' },
* ]);
* @throws {Error} Before sending anything, when two specs name one destination (by slug or by id).
* @throws {IngestError} 404 for a mapping, target or endpoint that does not exist; 400 for a mapping of another type.
*/
upsertForSourceType: (sourceTypeId: string, specs: DestinationSpec[]) => Promise<Upserted<Destination>[]>;
/**
* One source's own destinations, as `specs` define them, each found by its
* mapping, target and endpoint: created when missing (in one batch, all or
* none), updated where its pin, switch or `onDelete` differ, nothing sent
* when they match. Never deletes one the specs leave out.
* @returns The destinations, in the order of `specs`.
* @throws {Error} Before sending anything, when two specs name one destination (by slug or by id).
* @throws {IngestError} 404 for a mapping, target or endpoint that does not exist; 400 for a mapping of another type.
*/
upsertForSource: (sourceId: string, specs: DestinationSpec[]) => Promise<Upserted<Destination>[]>;
};
/** Targets: the backends the platform configured (`catalog`, `core_entities`). Read only. */
readonly targets: {
/**
* List the targets, by slug: what a destination's `target` names; `slug` finds one.
* @throws {IngestError} 403 when the token may not list targets.
*/
list: (filter?: TargetFilter) => Promise<Page<TargetSummary>>;
/**
* Find the live target of a slug.
* @returns The target, or `null` when there is none.
* @throws {IngestError} 403 when the token may not list targets.
*/
find: (slug: string) => Promise<TargetSummary | null>;
};
/**
* Endpoints: the places in a target's API an entity is written to, listed
* under their target and read by its id and theirs. Read only.
*/
readonly endpoints: {
/**
* List a target's endpoints (declared, and for the catalog its
* specifications); `id` or `slug` finds one. At most 100 a page.
* @throws {IngestError} 404 when there is no such target; 503 when the target cannot be read now; 403 when it refused the token.
*/
listForTarget: (targetId: string, filter?: EndpointFilter) => Promise<Page<EndpointSummary>>;
/**
* Read one of a target's endpoints by its id (the organization's own id
* for it, what a destination's `endpointId` holds): as it runs, every
* section and key present; with `{ effective: false }`, as it was written.
* @returns The endpoint, or `null` when there is none.
* @throws {IngestError} 404 when there is no such target; 503 when the
* target cannot be read now.
* @example
* const endpoint = await ingest.endpoints.get(catalog.id, destination.endpointId);
*/
get: EndpointGet;
};
/**
* Runs: one complete listing of a source (a backfill or a resync). On
* finalize, what the source owned and the run did not report is deleted,
* behind its guards. Prefer {@link IngestClient.runs.open}.
*/
readonly runs: {
/**
* Open a run of the source, of some record types (all the source maps when omitted).
* @throws {RangeError} Before sending, for an empty `types` (omit it for all of them).
* @throws {IngestError} 409 when the source has an open run; 404 when there is no such source.
*/
create: (sourceId: string, types?: string[]) => Promise<Run>;
/**
* Read a run by id.
* @returns The run, or `null` when there is none.
* @throws {IngestError} 403 when the token may not read it.
*/
get: (runId: string) => Promise<Run | null>;
/**
* List the source's runs, newest first; of one status when asked.
* @throws {IngestError} 404 when there is no such source; 403 when the token may not read it.
*/
list: (sourceId: string, filter?: RunFilter) => Promise<Page<Run>>;
/**
* Send one batch of records to an open run (a run handle batches for
* you). Each record gets a UUIDv7 id unless it has one, which must be a
* UUIDv7.
* @throws {TypeError} Before sending, for an id that is not a UUIDv7.
*/
sendRecords: (sourceId: string, runId: string, records: InputSpec[]) => Promise<Accepted>;
/**
* Finalize a run: it reconciles once every record is applied, behind the
* source's guards. `dryRun` reports what would be deleted and leaves it open.
* @param options Guard overrides for this run (`maxDeleteRatio` needs `ingest:source:write`).
* @throws {IngestError} 409 when the run is not open; 404 when there is no such run; 403 when the token may not write its source.
*/
finalize: (runId: string, options?: FinalizeOptions) => Promise<Run>;
/**
* Abort a run: closed without reconciling, nothing deleted.
* @throws {IngestError} 409 when the run is not open; 404 when there is no such run; 403 when the token may not write its source.
*/
abort: (runId: string) => Promise<Run>;
/**
* Find the source's open run.
* @returns The run, or `null` when it has none.
* @throws {IngestError} 404 when there is no such source; 403 when the token may not read it.
*/
findOpen: (sourceId: string) => Promise<Run | null>;
/**
* Open a run and get a handle to feed it: `add` every record, then
* `finalize` (or `abort` on any failure: it deletes nothing).
* @param options `types` limits the run; `onConflict` (`OnConflict.ABORT` by
* default) aborts a run left open, `OnConflict.FAIL` throws its 409.
* @example
* const run = await ingest.runs.open(source.id, { types: ['deployment'], onConflict: OnConflict.ABORT });
* items.forEach((item) => run.add({ type: 'deployment', observedAt, payload: item }));
* const done = await run.finalize();
* @throws {RangeError} Before sending, for an empty `types`.
* @throws {IngestError} 404 when there is no such source; 409 when it has an open run and `onConflict` is `OnConflict.FAIL`.
*/
open: (sourceId: string, options?: OpenRunOptions) => Promise<RunHandle>;
/**
* Wait until every input of the run has been applied.
* @throws {TimeoutError} When it is not within `options.timeoutMs`.
*/
waitApplied: (runId: string, options?: WaitOptions) => Promise<Run>;
/**
* Wait until the run is closed: completed, guard tripped or aborted.
* @throws {TimeoutError} When it is not within `options.timeoutMs`.
*/
waitClosed: (runId: string, options?: WaitOptions) => Promise<Run>;
/**
* Wait until a dry-run finalize has been assessed (the run stays open).
* @throws {TimeoutError} When it is not within `options.timeoutMs`.
*/
waitDryRun: (runId: string, options?: WaitOptions) => Promise<Run>;
};
/** Events: a source's changes, one by one, between runs (the steady state). */
readonly events: {
/**
* Send one batch of events (an event batcher batches for you). `op`
* defaults to `EventOp.UPSERT`; each event gets a UUIDv7 id unless it has
* one, which must be a UUIDv7.
* @throws {TypeError} Before sending, for an id that is not a UUIDv7.
*/
send: (sourceId: string, events: EventSpec[]) => Promise<Accepted>;
/**
* A batcher that sends events as they come, batched by count, bytes and
* time. Close it on shutdown.
* @example
* const events = ingest.events.batcher(source.id);
* events.upsert('deployment', deployment, { observedAt: event.time });
* await events.close();
* @throws {RangeError} For batching options out of range.
*/
batcher: (sourceId: string, batching?: Partial<BatcherOptions>) => EventBatcher;
};
/** Inputs: every record and event a source sent, and what became of each. */
readonly inputs: {
/**
* Send one batch of inputs: records of the open runs they name (`runId`),
* or events. Run handles and event batchers batch for you. Each input gets
* a UUIDv7 id unless it has one, which must be a UUIDv7.
* @returns How many were accepted, and which were duplicates (an id sent before).
* @throws {TypeError} Before sending, for an id that is not a UUIDv7.
* @throws {IngestError} 409 when an id belongs to another source.
*/
create: (sourceId: string, inputs: InputSpec[]) => Promise<Accepted>;
/**
* List the source's input log, in arrival order, with what became of each input.
* @throws {IngestError} 400 for an `after` that is not the source's; 404 when there is no such source.
*/
list: (sourceId: string, filter?: InputFilter) => Promise<Page<InputSummary>>;
/**
* Read one input, its payload included.
* @returns The input, or `null` when there is none.
* @throws {IngestError} 403 when the token may not read the input log.
*/
get: (inputId: string) => Promise<Input | null>;
/**
* Wait until the given inputs are all settled.
* @returns The inputs, in the order of `ids`.
* @throws {TimeoutError} When they are not within `options.timeoutMs`.
*/
wait: (ids: string[], options?: WaitOptions) => Promise<Input[]>;
/**
* Wait until the source has no pending input.
* @throws {TimeoutError} When it does not within `options.timeoutMs`.
*/
waitIdle: (sourceId: string, options?: WaitOptions) => Promise<void>;
};
/** Replays: the current mappings applied again to what a source owns (after changing one). */
readonly replays: {
/**
* Create a replay: each live entity's last record is queued again, in the
* background. With an `idempotencyKey`, a resend answers the same replay.
* @param request Which record types (all when omitted).
* @throws {IngestError} 404 when there is no such source; 409 when the idempotency key names another request.
*/
create: (sourceId: string, request?: ReplayRequest, options?: {
idempotencyKey?: string;
}) => Promise<Replay>;
/**
* Read a replay by id: its status and progress.
* @returns The replay, or `null` when there is none.
* @throws {IngestError} 403 when the token may not read it.
*/
get: (replayId: string) => Promise<Replay | null>;
/**
* List the source's replays, newest first; of one status when asked.
* @throws {IngestError} 404 when there is no such source; 403 when the token may not read it.
*/
list: (sourceId: string, filter?: ReplayFilter) => Promise<Page<Replay>>;
/**
* Wait until the replay has queued everything (or failed); the inputs it
* queued may still be applying.
* @throws {TimeoutError} When it does not finish within `options.timeoutMs`.
*/
wait: (replayId: string, options?: WaitOptions) => Promise<Replay>;
};
/** Entities: what a source owns, and what was last written to each. */
readonly entities: {
/**
* List the entities the source owns, with the data last written (no raw records).
* @throws {IngestError} 404 when there is no such source; 403 when the token may not read it.
*/
list: (sourceId: string, filter?: EntityFilter) => Promise<Page<EntitySummary>>;
/**
* Read one owned entity by its id, with the raw record it was last mapped
* from (needs `ingest:input:read`).
* @returns The entry, or `null` when there is none.
* @throws {IngestError} 403 when the token may not read the input log (`ingest:input:read`).
*/
get: (entityId: string) => Promise<Entity | null>;
};
/** Drift checks: what a source owns compared with what its targets hold. */
readonly driftChecks: {
/**
* Create a drift check of the source: `DriftPolicy.REPORT` (the default)
* flags what changed or went missing; `DriftPolicy.RESTORE` writes it back.
* @throws {IngestError} 404 when there is no such source; 403 when the token may not write it.
*/
create: (sourceId: string, policy?: DriftPolicy) => Promise<DriftCheck>;
/**
* Read a drift check by id.
* @returns The drift check, or `null` when there is none.
* @throws {IngestError} 403 when the token may not read it.
*/
get: (checkId: string) => Promise<DriftCheck | null>;
/**
* List the source's drift checks, newest first; of one status when asked.
* @throws {IngestError} 404 when there is no such source; 403 when the token may not read it.
*/
list: (sourceId: string, filter?: DriftCheckFilter) => Promise<Page<DriftCheck>>;
/**
* Wait until a drift check is completed or failed.
* @throws {TimeoutError} When it is not within `options.timeoutMs`.
*/
wait: (checkId: string, options?: WaitOptions) => Promise<DriftCheck>;
/**
* Create a drift check and wait for it.
* @throws {TimeoutError} When it does not finish within `options.timeoutMs`.
*/
createAndWait: (sourceId: string, policy?: DriftPolicy, options?: WaitOptions) => Promise<DriftCheck>;
};
}
//#endregion
//#region src/ingest-error.d.ts
/**
* The error codes the API answers with (`IngestError.code`), by status:
* 400 VALIDATION (including an undeclared body property), 401 AUTHENTICATION,
* 403 AUTHORIZATION, 404 NOT_FOUND, 409 CONFLICT, 429 TOO_MANY_REQUESTS
* (with Retry-After), 502 TARGET_REJECTED (a target refused what the API
* asked it on the call's behalf) and 503 SERVICE_UNAVAILABLE.
*/
declare enum IngestErrorCode {
VALIDATION = "FST_ERR_VALIDATION",
AUTHENTICATION = "FST_ERR_AUTHENTICATION",
AUTHORIZATION = "FST_ERR_AUTHORIZATION",
NOT_FOUND = "FST_ERR_NOT_FOUND",
CONFLICT = "FST_ERR_CONFLICT",
TOO_MANY_REQUESTS = "FST_ERR_TOO_MANY_REQUESTS",
TARGET_REJECTED = "FST_ERR_TARGET_REJECTED",
SERVICE_UNAVAILABLE = "FST_ERR_SERVICE_UNAVAILABLE"
}
/**
* A request the API refused, or could not be reached for. Thrown by every
* client call, and kept by a batcher whose batch failed for good.
*/
declare class IngestError extends Error {
/** HTTP status; 0 when the API could not be reached. */
readonly status: number;
/** The API's error code (see `IngestErrorCode`), when the response carried one. */
readonly code: IngestErrorCode | string | undefined;
/** The response body, parsed when it was JSON. */
readonly body: unknown;
/**
* @param status HTTP status; 0 when the API could not be reached.
* @param message The API's message, or why it could not be reached.
* @param code The API's error code.
* @param body The response body.
*/
constructor(status: number, message: string, code?: string, body?: unknown);
/**
* True for the failures the SDK retries on its own: unreachable (0), 429 and
* 5xx (503 included). When one reaches you, the retries (or the backpressure
* budget) ran out. Every other 4xx — 403 included — is deterministic.
*/
get retryable(): boolean;
}
//#endregion
//#region src/timeout-error.d.ts
/** A wait helper gave up before the API reached the awaited state. */
declare class TimeoutError extends Error {
constructor(message: string);
}
//#endregion
//#region src/tokens/api-key-token.d.ts
/** How an API key is exchanged. */
interface ApiKeyTokenOptions {
/** The nullplatform API key. */
apiKey: string;
/** Where it is exchanged (`POST {authBaseURL}/token`). */
authBaseURL: string;
/** The `fetch` to use. */
fetchImpl: typeof fetch;
/** Timeout of one exchange. */
timeoutMs: number;
/** Refresh this long before the token expires. Default 60 s. */
expiryBufferMs?: number;
}
/** A token from a nullplatform API key: exchanged, cached and refreshed before it expires. */
declare class ApiKeyToken implements TokenProvider {
#private;
/** @param options The API key, where it is exchanged, and how. */
constructor(options: ApiKeyTokenOptions);
/**
* The current token: the cached one while it is fresh, otherwise a new one
* (refreshed, or exchanged from the key again when the refresh is refused).
* @throws {IngestError} When the exchange fails.
*/
get(): Promise<string>;
/** Drop the cached token (after a 401): the next `get` exchanges the key again. */
invalidate(): void;
}
//#endregion
//#region src/tokens/static-token.d.ts
/** A ready token. Nothing to refresh: a 401 surfaces to the caller. */
declare class StaticToken implements TokenProvider {
#private;
/** A static token never changes: a 401 is not tried again. */
readonly refreshable = false;
/** @param token A bearer token, with or without `Bearer `. */
constructor(token: string);
/** The token as given (without `Bearer `). */
get(): Promise<string>;
/** Nothing to do: a static token cannot be refreshed. */
invalidate(): void;
}
//#endregion
//#region src/tokens/callback-token.d.ts
/** Your own way to get a token: called once, then again after a 401. */
declare class CallbackToken implements TokenProvider {
#private;
/** @param getToken Answers a bearer token, with or without `Bearer `. */
constructor(getToken: () => Promise<string> | string);
/** The token `getToken` answered, cached until invalidated. */
get(): Promise<string>;
/** Drop the cached token (after a 401): the next `get` calls `getToken` again. */
invalidate(): void;
}
//#endregion
//#region src/uuid.d.ts
/**
* UUIDv7 via the Web Crypto API (Node ≥ 22, Bun, browsers, edge runtimes). A
* UUIDv7 starts with a big-endian Unix-millisecond timestamp, so ids sort by
* creation time. The API requires one as the id of every input.
* @param now The Unix-millisecond time it starts with (default: now).
* @returns A UUIDv7, lowercase.
*/
declare function uuidv7(now?: number): string;
/** True when `id` is a UUIDv7. */
declare const isUuidV7: (id: unknown) => id is string;
//#endregion
//#region src/pages.d.ts
/** How many values one filter takes in one request (`recordType: ['pod', 'node']`): the API's most. */
declare const MAX_FILTER_VALUES = 100;
//#endregion
//#region src/collector/runtime.d.ts
/** What one snapshot takes besides the collector and the port. */
interface RunSnapshotOptions {
/**
* The source it feeds: `slug`, its stable name, unique in the organization
* (one per deployment); `nrn`, where it lives and its key is granted (the
* organization's root unless given); `name`, over `definition.source.name`.
*/
source: RunSource;
/** Where the run says what it does (`console` will do). */
log: Logger;
/** Aborting it cancels the snapshot: the run is aborted, nothing deleted. */
signal?: AbortSignal;
/** Told the record types the source applies, each time a snapshot reads them. */
applied?: (types: string[]) => void;
}
/** What a long-running collector takes besides the collector and the port. */
interface RunCollectorOptions extends RunSnapshotOptions {
/** Stops the collector: `runCollector` resolves once everything in flight has stopped. */
signal: AbortSignal;
/**
* Seconds between the start of one snapshot and the next; 0 runs a single
* one, on start. Above 0, the first is due `intervalSeconds` after the
* source's last run started (any status), at once when it has none: a
* restart does not snapshot again before then.
*/
intervalSeconds: number;
/**
* Backoff bounds for restarting a failed watch or a failed setup (1 s to 60 s).
* A watch restarted after a failure has recovered once it runs `retryMaxMs`.
*/
retryMinMs?: number;
retryMaxMs?: number;
}
/** A source ready to be fed: its id, and the record types it applies (the only ones sent). */
interface PreparedSource extends UpsertedSource {
types: string[];
}
/**
* Records between two flushes the listing waits on. A full API batch: when
* the API pushes back (429, its worker is behind) the listing pauses here
* instead of buffering the rest of the system of record in memory.
*/
declare const FLUSH_EVERY = 500;
/** Resolves after `ms`, or as soon as `signal` aborts. */
declare function pause(ms: number, signal?: AbortSignal): Promise<void>;
/** The record types a collector produces: its `recordTypes` and its own mappings'. */
declare function declaredTypes(definition: CollectorDefinition): string[];
/**
* Refuses a collector that could never feed a source: no source type, no
* record types, a mapping with no endpoint, or no snapshot.
* @throws {Error} naming what is missing.
*/
declare function validateDefinition(definition: CollectorDefinition): void;
/**
* Creates or updates the source (by slug) and the collector's own mappings,
* then learns which of its record types the source applies (an organization
* binds a type's shared mappings once; a type it has not bound is not sent).
* @throws {Error} when the source applies none of them: there is nothing to feed.
*/
declare function prepareSource(definition: CollectorDefinition, port: IngestPort, options: RunSnapshotOptions): Promise<PreparedSource>;
/**
* Takes one full snapshot of the collector's system of record into its
* source: upserts the source and its own mappings, opens a run of the types
* the source applies, streams every record the snapshot yields (pausing on a
* flush every full batch), and finalizes. A snapshot that throws, yields a
* record of a type it does not declare, or is cancelled is aborted: nothing
* is deleted. A dry run is reported, then closed.
* @returns The run as the API closed it.
* @throws {Error} what made the snapshot fail, after aborting its run.
* @example
* const ingest = new ClientIngest(new IngestClient({ apiKey }));
* const result = await runSnapshot(collector, ingest, { source: { slug: 'eu-cluster' }, log });
* if (result.reconciliation?.guardTripped) {
* log.error('nothing deleted: a guard tripped');
* }
*/
declare function runSnapshot(definition: CollectorDefinition, port: IngestPort, options: RunSnapshotOptions, finalizeOptions?: FinalizeOptions): Promise<SnapshotResult>;
/**
* Runs a collector until `options.signal` aborts: sets its source up
* (retrying with a backoff), then a snapshot every `intervalSeconds` (never
* two at once; `0`: one, on start) and, when the collector watches, its
* watch, which starts at once. The first snapshot is due by the source's last
* run (the API's runs, any status): at once when it has none or it started
* more than `intervalSeconds` ago, else when the interval since it is over, so
* a restart or a crash loop does not backfill again; a last run that cannot
* be read is logged and the snapshot runs at once. The watch
* sends only the types the source applies and is restarted with a backoff
* when it fails or ends. A watch that failed and has then run `retryMaxMs`
* without failing makes a snapshot due at once (after the one running, if
* any): only a snapshot deletes what vanished while it was down. One per
* recovered outage, however many restarts it took, and none with an
* `intervalSeconds` of 0; the schedule continues from it. A failed snapshot
* is logged and the next one runs on schedule. Every scheduled snapshot finalizes with `finalizeOptions`
* (`{ dryRun: true }`: each is assessed and closed, nothing deleted).
* @returns Once everything in flight has stopped.
* @example
* const stop = new AbortController();
* process.on('SIGTERM', () => stop.abort());
* await runCollector(collector, new ClientIngest(new IngestClient({ apiKey })), {
* source: { slug: 'eu-cluster' },
* log: console,
* signal: stop.signal,
* intervalSeconds: 86400,
* });
*/
declare function runCollector(definition: CollectorDefinition, port: IngestPort, options: RunCollectorOptions, finalizeOptions?: FinalizeOptions): Promise<void>;
//#endregion
//#region src/collector/client-ingest.d.ts
/**
* Where a collector's API is and how it authenticates, and the client's
* tuning (timeouts, retries, backpressure, batching, `fetchImpl`), passed to
* it as given.
*/
interface ConnectOptions extends Omit<IngestClientOptions, 'authBaseURL' | 'baseURL' | 'apiKey' | 'token' | 'getToken'> {
/**
* The nullplatform API: where an API key is exchanged, and where the ingest
* API is served (`<authBaseURL>/catalog/ingest`) unless `baseURL` says
* otherwise. Default: https://api.nullplatform.com
*/
authBaseURL?: string;
/** The ingest API itself, when it is not under `authBaseURL` (a local one, in development). */
baseURL?: string;
/** A nullplatform API key. */
apiKey?: string;
/** A ready token (a local API); takes the place of the API key. */
token?: string;
}
/**
* The `IngestPort` of the real API, through an `IngestClient`: what a
* collector feeds outside tests and local runs.
* @example
* const ingest = new ClientIngest(new IngestClient({ apiKey: process.env.NP_API_KEY }));
* await runCollector(collector, ingest, { source: { slug: 'eu-cluster' }, log, signal, intervalSeconds: 86400 });
*/
declare class ClientIngest implements IngestPort {
#private;
constructor(client: IngestClient);
/**
* The port of the ingest API under `authBaseURL` (or at `baseURL`),
* authenticated by a token when given, else by the API key, its client
* tuned by the rest of `options`.
* @throws {Error} when neither an API key nor a token is given.
* @example
* const ingest = ClientIngest.connect({ apiKey: process.env.NP_API_KEY, timeoutMs: 60_000 });
*/
static connect(options: ConnectOptions): ClientIngest;
upsertSource(source: SourceSpec): Promise<UpsertedSource>;
/**
* The client's two upserts: the source's own mapping of each record type,
* then its destination at the target and endpoint it names. A destination
* of the mapping to another endpoint is left alone (a record type may go to
* several). What was written is what the upserts say they did: a mapping or
* destination created or updated.
*/
upsertMappings(sourceId: string, mappings: Record<string, CollectorMapping>): Promise<string[]>;
/** The types of `types` the source applies: what it applies (enabled only), queried by those types. */
appliedTypes(sourceId: string, types: string[]): Promise<string[]>;
/** The source's newest run, of any status: one run, asked newest first. */
lastRun(sourceId: string): Promise<LastRun | null>;
openRun(sourceId: string, types: string[]): Promise<RunPort>;
events(sourceId: string): EventPort;
}
//#endregion
export { type Accepted, AdoptPolicy, type ApiError, ApiKeyToken, type ApiKeyTokenOptions, AssignedBy, Batcher, type BatcherOptions, type BatcherStats, CallbackToken, ClearSemantics, ClientIngest, type CollectedEventOptions, type CollectedRecord, type CollectorContext, type CollectorDefinition, type CollectorEvents, type CollectorMapping, type CollectorRunSettings, type CollectorSource, type ConnectOptions, DEFAULT_AUTH_BASE_URL, DEFAULT_BASE_URL, DEFAULT_MAPPING_TARGET, DeletePolicy, type Destination, type DestinationFilter, type DestinationPatch, type DestinationRevision, DestinationRevisionAction, type DestinationSpec, type DriftCheck, type DriftCheckFilter, DriftCheckStatus, DriftPolicy, DriftType, EmptyLinkSet, type Endpoint, type EndpointAsWritten, type EndpointCall, type EndpointErrorRule, type EndpointFilter, type EndpointGone, type EndpointPaging, type EndpointReadOptions, type EndpointReference, type EndpointSummary, Engine, type Entity, type EntityFilter, EntityOrigin, type EntityResult, type EntitySummary, EventBatcher, EventOp, type EventOptions, type EventPort, type EventSpec, FLUSH_EVERY, FieldComparison, FieldRule, type FinalizeOptions, HttpMethod, IngestClient, type IngestClientOptions, IngestError, IngestErrorCode, type IngestPort, type Input, type InputCreate, type InputFilter, type InputSpec, InputStatus, type InputSummary, type LastRun, type Logger, MAX_FILTER_VALUES, type Mapping, type MappingCreate, type MappingFilter, type MappingPatch, type MappingPreview, type MappingPreviewSpec, type MappingRevision, MappingRevisionAction, type MappingSample, type MappingWriteOptions, type MaybeNamedBy, type NamedBy, type ObservedRecord, OnConflict, OnDelete, type OpenRunOptions, OperationBody, OperationName, Outcome, type OwnRunSettings, type Page, type PageOptions, type Paging, PagingStyle, type PreparedInput, type PreparedSource, type Replay, type ReplayFilter, type ReplayRequest, ReplayStatus, type Revision, type Run, type RunCollectorOptions, type RunCounters, type RunFilter, RunHandle, type RunOperations, type RunPort, type RunReconciliation, type RunSettings, type RunSnapshotOptions, type RunSource, RunStatus, type SnapshotContext, type SnapshotRecords, type SnapshotResult, type Sort, type Source, type SourceDestinationFilter, type SourceFields, type SourceFilter, type SourcePatch, type SourceRevision, SourceRevisionAction, type SourceSpec, type SourceStats, type SourceType, type SourceTypeFilter, type SourceTypePatch, type SourceTypeRevision, SourceTypeRevisionAction, type SourceTypeSpec, type SourceTypeUpsertSpec, type SourceUpsertSpec, StaticToken, TargetDeletePolicy, TargetErrorOutcome, type TargetFilter, type TargetSummary, TimeoutError, type TokenProvider, type TypeMappingCreate, UpsertOutcome, type Upserted, type UpsertedSource, type WaitOptions, type WatchContext, declaredTypes, isUuidV7, pause, prepareSource, runCollector, runSnapshot, uuidv7, validateDefinition };
//# sourceMappingURL=index.d.cts.map