UNPKG

@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

82 lines (64 loc) • 4.96 kB
# examples Every file here is **a small, plausible collector with the SDK calls on top**: an inventory job, a watch handler, an operator script, a defensive snapshot. The system each one reads from (a cluster API, a watch stream) is stubbed with synthetic data, so the files run as they are. They ship with the package. Run one against the public API with your nullplatform API key: ```sh npm install @nullplatform/ingest NULLPLATFORM_API_KEY=… node node_modules/@nullplatform/ingest/examples/01-snapshot.cjs ``` `NP_API_KEY` works too. That is all they read: the SDK reads no environment variable, and its defaults are the public API (`https://api.nullplatform.com`). Each example starts with its organization's setup, done once (binding a type's mappings, or creating the organization's own source type): that step needs a key holding `organization:ingest_admin` at the organization's root. The rest is what a collector does, which a collector's key (`organization:machine:ingest`) holds. Every release runs each example against an in-memory fake of the API that is strict about the wire contract, so they keep working as the SDK changes. ## The files ### [`01-snapshot.cjs`](https://unpkg.com/@nullplatform/ingest@latest/examples/01-snapshot.cjs) — the full state of a system, as one run A cluster inventory job reports its deployments twice; the second pass misses a deployment removed in between, and finalize deletes exactly that one. Demonstrates: the organization binding the global `kubernetes` type's mapping to a destination once (`sourceTypes.find`, `mappings.listForSourceType`, `destinations.upsertForSourceType`: the collector defines no mappings), `sources.upsert` by slug (its result's `id` is what later calls take), `runs.open` with `types` and `onConflict: OnConflict.ABORT`, `run.add` with one `observedAt` for the listing, `run.finalize` (`RunStatus.COMPLETED`), `run.abort` on failure, `counters` and `reconciliation`. ### [`02-events.cjs`](https://unpkg.com/@nullplatform/ingest@latest/examples/02-events.cjs) — delta events as they happen A watch handler turns ADDED / MODIFIED / DELETED notifications into upserts and explicit deletes, observed at the cluster's time, and waits to see what became of them. Demonstrates: the same once-per-organization binding, `events.batcher`, `upsert` / `delete` with `observedAt`, `close()` on shutdown, `stats`, `inputs.wait`. ### [`03-follow-up.cjs`](https://unpkg.com/@nullplatform/ingest@latest/examples/03-follow-up.cjs) — inspect, page, fix a mapping, replay An operator script looks at where a destination can write, reads the input log page by page, previews and stores a mapping change, replays the owned entities' last records through it, and checks the owned entities for drift. Demonstrates: the upserts of an organization's own setup (`sourceTypes.upsert`, `sources.upsert`, `mappings.upsertForSource`, `destinations.upsertForSource`), `targets.list`, `endpoints.listForTarget` by slug, the `{ paging, results }` envelope and a page walk, `inputs.list` with filters, `mappings.findForSource`, a preview of a change (`mappingPreviews.create`), and `mappings.update` by id, `mappings.revisions`, `replays.create` and `replays.wait`, `inputs.waitIdle`, `entities.list`, `driftChecks.createAndWait`, `sources.list`. ### [`04-failures-and-guards.cjs`](https://unpkg.com/@nullplatform/ingest@latest/examples/04-failures-and-guards.cjs) — the defensive edges A dry run before deleting, a batch refused for a typo'd record type (the run stops and is aborted), telling API errors apart by code, UUIDv7 input ids, and a soft delete followed by a revival. Demonstrates: `finalize({ dryRun: true })`, guards, sticky batch failure, `IngestError` / `IngestErrorCode`, `retryable` (transient; the SDK retries it itself except on a POST a resend could repeat, such as opening a run), `uuidv7`, the id check, `sources.delete` (soft) and revival through `sources.upsert` (same id). ### [`05-kubernetes.cjs`](https://unpkg.com/@nullplatform/ingest@latest/examples/05-kubernetes.cjs) — everything a Kubernetes collector says, in order A Namespace, a Deployment and the Service in front of it, as the Kubernetes API returns them, reach the catalog; then the deployment scales out and the service is removed. Each numbered step is one SDK call, and its comment names the request: the organization binding the `kubernetes` type's mappings once, the collector upserting its source and reading what it applies, the backfill run, the events, their outcomes and what the source owns. Every request a Kubernetes collector makes to the ingest API, and nothing else. Demonstrates: `sourceTypes.find`, `mappings.listForSourceType`, `destinations.upsertForSourceType`, `sources.upsert` (with `attributes`), `destinations.listForSource`, `runs.open` / `add` / `finalize`, `events.batcher` (`upsert`, `delete`), `inputs.wait`, `entities.list`, and the `_refs` a collector adds to an object.