pipework 0.173.0 → 0.175.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/REFERENCE.md +23 -0
- package/dist/REFERENCE.md +195 -7
- package/dist/async/jobs/scheduler.js +1 -1
- package/dist/async/jobs/scheduler.js.map +1 -1
- package/dist/async/steps/graph.js +9 -9
- package/dist/async/steps/graph.js.map +1 -1
- package/dist/data/query/sql/sql.d.ts +10 -0
- package/dist/data/query/sql/sql.d.ts.map +1 -1
- package/dist/data/query/sql/sql.js +21 -0
- package/dist/data/query/sql/sql.js.map +1 -1
- package/dist/data/write/audit/verb-upsert.d.ts.map +1 -1
- package/dist/data/write/audit/verb-upsert.js +1 -0
- package/dist/data/write/audit/verb-upsert.js.map +1 -1
- package/dist/infra/access-links/handle.js +4 -4
- package/dist/infra/access-links/handle.js.map +1 -1
- package/dist/infra/alerts/namespace.d.ts +12 -1
- package/dist/infra/alerts/namespace.d.ts.map +1 -1
- package/dist/infra/alerts/namespace.js +12 -1
- package/dist/infra/alerts/namespace.js.map +1 -1
- package/dist/infra/alerts/sources.d.ts +64 -0
- package/dist/infra/alerts/sources.d.ts.map +1 -1
- package/dist/infra/alerts/sources.js +246 -161
- package/dist/infra/alerts/sources.js.map +1 -1
- package/dist/infra/alerts/subsystem-sources.d.ts +42 -0
- package/dist/infra/alerts/subsystem-sources.d.ts.map +1 -0
- package/dist/infra/alerts/subsystem-sources.js +152 -0
- package/dist/infra/alerts/subsystem-sources.js.map +1 -0
- package/dist/infra/webhook/outbound.d.ts +2 -0
- package/dist/infra/webhook/outbound.d.ts.map +1 -1
- package/dist/infra/webhook/outbound.js +3 -1
- package/dist/infra/webhook/outbound.js.map +1 -1
- package/dist/trace/partition/sync.js +2 -4
- package/dist/trace/partition/sync.js.map +1 -1
- package/package.json +1 -1
- package/dist/infra/email/sigv4.d.ts +0 -24
- package/dist/infra/email/sigv4.d.ts.map +0 -1
- package/dist/infra/email/sigv4.js +0 -55
- package/dist/infra/email/sigv4.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.175.0
|
|
4
|
+
|
|
5
|
+
- **Fixed: a worker surface with `schedules: []` failed every scheduler check** with `syntax error at or near ")"`. The scheduler built `name IN ()` from the empty list. **Added: `sql.inList(values, cast?)`**, the one safe way to match a column against a JS list. `` col ${sql.inList(ids, 'uuid')} `` renders `= ANY(...)` over one jsonb parameter, so an empty list matches nothing instead of failing to parse. A `Date` travels as ISO text. The scheduler, trace partition sync, access-link deletes and step-graph queries now use it; those other sites were already guarded against an empty list.
|
|
6
|
+
|
|
7
|
+
## 0.174.0
|
|
8
|
+
|
|
9
|
+
- **Added: build an alert from any recorded failure, and sources for outbox, webhook and credit failures** (follows #712). Two general builders:
|
|
10
|
+
- `alerts.source.query({ name, query, id, message, context?, subject? })` is for a condition that is true now. It raises `<name>:<id>` per row and resolves what the query stops returning.
|
|
11
|
+
- `alerts.source.newRows({ name, table, at, where?, groupBy, message, sum?, settleMs? })` is for rows recorded since the last tick. It keeps a shared cursor and raises one alert per group.
|
|
12
|
+
- Both work over an app's own tables. The existing sources are rebuilt on them, with the same keys and messages.
|
|
13
|
+
- New sources built on them:
|
|
14
|
+
- `alerts.source.deliveryFailed({ tables?, stuckAfterMs? })`: outbox rows that gave up, and rows stuck past their retry time. By default it watches the alert outbox itself; name `support_event_delivery` to add the support outbox.
|
|
15
|
+
- `alerts.source.webhookFailed({ table?, stalledAfterMs? })`: outbound webhook deliveries that gave up, and ones overdue for a retry.
|
|
16
|
+
- `alerts.source.credits({ heldOlderThanMs?, expiryGraceMs? })`: settlements that overdrew a tenant, holds left open, and expired grants nothing drained.
|
|
17
|
+
- **Fixed: `alerts.source.deadLetter` could miss a job forever.** A job stamped with its transaction's start time that committed after the cursor moved past that time was never read. New-row sources now read rows `settleMs` (default 30 s) after they are stamped, so dead-letter alerts arrive up to 30 s later. Its first evaluation also covers the 30 s before it.
|
|
18
|
+
|
|
3
19
|
## 0.173.0
|
|
4
20
|
|
|
5
21
|
- **Fixed: public APIs accept readonly arrays, tuples and `as const` values** (follows #714). A sweep found 20 parameters that refused a readonly value pipework never mutates. Each now accepts one:
|
package/REFERENCE.md
CHANGED
|
@@ -732,6 +732,7 @@ Expression helpers for `.set()`, `.values()` and `.where()` (a string or number
|
|
|
732
732
|
- `filter.strpos(a, b)`, `filter.textContains(a, b)`, `filter.startsWith(a, prefix)` — exact-text tests, no `%`/`_`/backslash wildcards (unlike `like`). `a`, `b`, `prefix` take a column, expression or string.
|
|
733
733
|
- `filter.left(a, n)`, `filter.right(a, n)`, `filter.length(a)` — text slices and length.
|
|
734
734
|
- `filter.concat(...parts)` — `(p1 || p2 || ...)`, at least two parts, each a string, column or expression (`scalar(...)` for a subquery). A null part makes the result null; wrap it in `coalesce` if not wanted.
|
|
735
|
+
- `pipe.sql.inList(values, cast?)` — list match for a JS list: `` sql`id ${sql.inList(ids, 'uuid')}` `` renders `= ANY(...)`, so an empty list matches nothing; never build `IN (${sql.join(...)})`, which is a syntax error when the list is empty. `cast` is the element type, default `text`.
|
|
735
736
|
- `filter.arrayReplace(col, from, to)` — `array_replace`, every `from` becomes `to`; `filter.arrayHas(col, value)` — `$value = ANY(col)`. `col` must be an array column; values are cast to its element type.
|
|
736
737
|
- `filter.jsonbMerge(col, object)` — same as `jsonb.merge`.
|
|
737
738
|
- `filter.jsonbRemove(col, ...keys)` — same as `jsonb.remove`.
|
|
@@ -1727,6 +1728,28 @@ Pass in `sources`; each raises with a fixed key on a tick and, where it can tell
|
|
|
1727
1728
|
- `alerts.source.backlog({ maxPending?, maxOldestAgeMs?, table?, severity? = 'warning', owner?, runbook? })` — `queue-backlog:<jobType>` while that type has more jobs ready to claim than `maxPending`, or the oldest has waited longer than `maxOldestAgeMs`; resolves when under both. The alert carries `owner`, `runbook` and a context `{ ready, running, oldestReadyWaitMs }`. A custom `AlertSource` condition may set `owner`, `runbook` and `context` too.
|
|
1728
1729
|
- `alerts.source.unitFault({ window, owner?, runbook?, severity? = 'error', units?, database? })` — `unit-fault:<unit>` while a systemd unit has stopped abnormally within `window` ms, message `<unit>: <lastResult> x<count> in <N> min`, context `{ count, lastResult, lastExitCode, lastExitStatus, firstAt, lastAt }`; resolves once the window passes with no new fault. Faults come from the unit itself, so a crash-looping or OOM-killed service (`MemoryMax=` gives `oom-kill`) is reported even though it cannot report its own death: add `ExecStopPost=pipework alerts unit-fault --unit %n` (optionally `--database <name>`) to the unit. The command reads `$SERVICE_RESULT`, `$EXIT_CODE` and `$EXIT_STATUS`, writes one row to `pipework_unit_faults` over one short connection (no manifold boot), and writes nothing for a clean stop. The table comes with the `alerts` blueprint flag.
|
|
1729
1730
|
- `alerts.source.quotaExhausted({ keys?, floor? = 0, severity? = 'error', owner?, runbook?, database? })` — `quota-exhausted:<key>` while a `quota` row has `remaining` at or under `floor` before its reset, or a `quota.call` was refused against it since it was last recorded; resolves when the row recovers or its reset passes. `keys` is a non-empty array or a RegExp. Needs `quota` configured. The alert carries `owner`, `runbook` and a context `{ key, remaining, limit, resetAt, refused }`; the message reads `github:installation:subseam 0/15000 until 18:33Z`.
|
|
1731
|
+
- `alerts.source.query({ name, query, id, message, context?, subject?, severity? = 'error', owner?, runbook?, database? })` — for a condition that is true right now, over any table (pipework's or the app's). `query` is an SQL fragment returning one row per subject; each row raises `<name>:<id>`, and an open alert under `<name>:` that a tick no longer returns is resolved. `name` is non-empty and has no `:`. The query runs as the system, across tenants.
|
|
1732
|
+
```ts
|
|
1733
|
+
alerts.source.query({
|
|
1734
|
+
name: 'invoice-stuck',
|
|
1735
|
+
query: pipe.sql`SELECT id, customer FROM invoices WHERE status = 'sending' AND updated_at < now() - interval '1 hour'`,
|
|
1736
|
+
id: r => String(r['id']),
|
|
1737
|
+
message: r => `invoice ${String(r['id'])} for ${String(r['customer'])} has been sending for over an hour`,
|
|
1738
|
+
})
|
|
1739
|
+
```
|
|
1740
|
+
- `alerts.source.newRows({ name, table, at, groupBy, message, where?, context?, subject?, sum?, settleMs? = 30_000, stateKey?, severity? = 'error', owner?, runbook?, database? })` — for a failure the app records and then moves on from. Raises `<name>:<group>` for each distinct `groupBy` value (a column, or an SQL expression over alias `t`) among rows whose `at` timestamp is newer than a cursor kept in `pipework_alert_source_state`; the callbacks get `{ id, count, last, sum }` where `last` is the newest row of the group as an object (column names as stored) and `sum` totals the `sum` column (0 without one). The first evaluation only stores the cursor, so history is not replayed. Each evaluation reads rows with `cursor < at <= now - settleMs` and moves the cursor to that bound, so a row stamped with its transaction's start time that commits within `settleMs` is still read; `settleMs` must exceed the longest transaction that writes the table. It has no `owns`: set `resolveAfterQuietMs` on `alerts.create` so the alert clears when new rows stop. `stateKey` (default `name`) names the cursor.
|
|
1741
|
+
```ts
|
|
1742
|
+
alerts.source.newRows({
|
|
1743
|
+
name: 'import-failed',
|
|
1744
|
+
table: 'imports',
|
|
1745
|
+
at: 'failed_at',
|
|
1746
|
+
groupBy: 'source',
|
|
1747
|
+
message: g => `${g.count} import(s) from ${g.id} failed; last: ${String(g.last['error'])}`,
|
|
1748
|
+
})
|
|
1749
|
+
```
|
|
1750
|
+
- `alerts.source.deliveryFailed({ tables? = ['pipework_alert_deliveries'], stuckAfterMs? = 900_000, settleMs?, severity? = 'error', owner?, runbook?, database? })` — outbox rows that gave up: `delivery-failed:<table>:<sink>`, message `<n> delivery(ies) to <sink> gave up; last error: <last_error>` (clears by the quiet period); and rows still pending more than `stuckAfterMs` past `next_attempt_at`: `delivery-stuck:<table>:<sink>` (resolves when they drain). Name `support_event_delivery` in `tables` to cover the support outbox.
|
|
1751
|
+
- `alerts.source.webhookFailed({ table? = '__pipework_webhook_deliveries', stalledAfterMs? = 900_000, settleMs?, severity?, owner?, runbook?, database? })` — outbound webhook deliveries (set `table` to your `deliveryTable`): `webhook-failed:<endpointId>` for deliveries that completed with no 2xx status, message `<n> webhook delivery(ies) to endpoint <id> gave up; last status <code|none>`; `webhook-stalled:<endpointId>` while deliveries are more than `stalledAfterMs` past `next_retry_at`.
|
|
1752
|
+
- `alerts.source.credits({ heldOlderThanMs? = 3_600_000, expiryGraceMs? = 3_600_000, settleMs?, severity?, owner?, runbook?, database? })` — `credit-overdraft:<tenantId>` for settlements that overdrew a tenant (`<n> settlement(s) overdrew <tenantId> by <sum>`); `credit-held:<tenantId>` while reservations stay held past `heldOlderThanMs`; `credit-expiry-undrained:all` while grants expired more than `expiryGraceMs` ago still have credit (`<n> expired grant(s) not drained; is the credits expiry job scheduled?`). Needs `credits` configured.
|
|
1730
1753
|
- `queue.totals(db)` — `{ overall, byType }`, each `{ ready, running, oldestReadyWaitMs }` (ready: pending and not waiting on a retry time; running: claimed or running; wait from `queued_at`, null when none is ready); `byType` omits a type with neither.
|
|
1731
1754
|
- `alerts.source.health(checks, { severity? = 'error' })` — `health:<name>` while a `HealthCheck` is unhealthy or throws; resolves when it recovers. Degraded is not a fault.
|
|
1732
1755
|
|
package/dist/REFERENCE.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Pipework API Reference
|
|
2
2
|
|
|
3
3
|
> Auto-generated from source JSDoc. Do not edit manually.
|
|
4
|
-
> Generated: 2026-10-
|
|
4
|
+
> Generated: 2026-10-20
|
|
5
5
|
|
|
6
6
|
## Contents
|
|
7
7
|
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
- [jobs — Background Jobs](#jobs-background-jobs)
|
|
11
11
|
- [pipeline — Multi-Step Pipelines](#pipeline-multi-step-pipelines)
|
|
12
12
|
- [state — State Machines](#state-state-machines)
|
|
13
|
+
- [steps](#steps)
|
|
13
14
|
- [auth — Authentication](#auth-authentication)
|
|
14
15
|
- [rbac — Access Control](#rbac-access-control)
|
|
15
16
|
- [tenant — Multi-Tenancy](#tenant-multi-tenancy)
|
|
@@ -30,7 +31,9 @@
|
|
|
30
31
|
- [cache — Caching](#cache-caching)
|
|
31
32
|
- [credits](#credits)
|
|
32
33
|
- [mail](#mail)
|
|
34
|
+
- [untrustedFetch](#untrustedfetch)
|
|
33
35
|
- [storage](#storage)
|
|
36
|
+
- [support](#support)
|
|
34
37
|
- [webhook — Inbound & Outbound Webhooks](#webhook-inbound-outbound-webhooks)
|
|
35
38
|
- [behavior — Resource Decorators](#behavior-resource-decorators)
|
|
36
39
|
- [fitting — Dependency Injection](#fitting-dependency-injection)
|
|
@@ -85,6 +88,18 @@ function createManifold<const TEnv extends EnvDefs = EnvDefs>( raw: Omit<Bluepri
|
|
|
85
88
|
interface Manifold<TEnv extends EnvDefs = EnvDefs>
|
|
86
89
|
```
|
|
87
90
|
|
|
91
|
+
**`ScriptOptions`** — Options for {@link Manifold.script}.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
interface ScriptOptions
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**`StartOptions`** — Options for {@link Manifold.start}.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
interface StartOptions
|
|
101
|
+
```
|
|
102
|
+
|
|
88
103
|
**`SeedOptions`** — ALS context the {@link Manifold.seed} callback runs under — tenant scope, auth principal, and job type.
|
|
89
104
|
|
|
90
105
|
```typescript
|
|
@@ -229,6 +244,14 @@ Creates a job queue with claim/complete/fail lifecycle, heartbeat, and dead lett
|
|
|
229
244
|
|
|
230
245
|
Executes a fitting handler as a background job with its own Flow context.
|
|
231
246
|
|
|
247
|
+
### `jobs.later`
|
|
248
|
+
|
|
249
|
+
The error to throw to end an attempt as "later": pending again after `delayMs`, no attempt counted.
|
|
250
|
+
|
|
251
|
+
### `jobs.permanent`
|
|
252
|
+
|
|
253
|
+
The error to throw to dead-letter the job now, whatever attempts remain.
|
|
254
|
+
|
|
232
255
|
### `jobs.parseCron`
|
|
233
256
|
|
|
234
257
|
Parses a 5-field cron expression into a CronSchedule (minute, hour, dom, month, dow).
|
|
@@ -269,6 +292,14 @@ Thrown when a transition is not allowed from the current state.
|
|
|
269
292
|
|
|
270
293
|
Thrown when the state machine definition is internally inconsistent.
|
|
271
294
|
|
|
295
|
+
## steps
|
|
296
|
+
|
|
297
|
+
Step graphs over a job queue: results recorded by their inputs, only missing steps run.
|
|
298
|
+
|
|
299
|
+
### `steps.define`
|
|
300
|
+
|
|
301
|
+
Defines a graph of named steps over a jobs Queue. Pass it to `createWorkerSurface({ graphs })` to run its steps.
|
|
302
|
+
|
|
272
303
|
## auth — Authentication
|
|
273
304
|
|
|
274
305
|
Authentication namespace — session management, multi-org support, auth chain resolution.
|
|
@@ -289,6 +320,10 @@ Hashes and verifies passwords with scrypt; reports when a stored hash needs reha
|
|
|
289
320
|
|
|
290
321
|
Guarded password sign-in that slows, then refuses, repeated failures per account and per client.
|
|
291
322
|
|
|
323
|
+
### `auth.emailLinks`
|
|
324
|
+
|
|
325
|
+
Emailed single-use links that prove control of an address: password reset and address verification; the token is never stored.
|
|
326
|
+
|
|
292
327
|
### `auth.runChain`
|
|
293
328
|
|
|
294
329
|
Executes an auth chain (strategy pipeline) to resolve auth + tenant from a request.
|
|
@@ -323,7 +358,7 @@ interface AuthContext
|
|
|
323
358
|
interface AuthStrategy<TAuth>
|
|
324
359
|
```
|
|
325
360
|
|
|
326
|
-
**`AuthRequest`** — Normalized request shape passed to auth strategies — headers,
|
|
361
|
+
**`AuthRequest`** — Normalized request shape passed to auth strategies — headers, the parsed `Cookie` header, and the upper-case HTTP method.
|
|
327
362
|
|
|
328
363
|
```typescript
|
|
329
364
|
interface AuthRequest
|
|
@@ -353,6 +388,18 @@ interface TenantResolver<TAuth>
|
|
|
353
388
|
interface AuthChainConfig<TAuth>
|
|
354
389
|
```
|
|
355
390
|
|
|
391
|
+
**`SessionAuth`** — What `sessions.strategy()` authenticates: the token's user and org, its roles, and where the token came from.
|
|
392
|
+
|
|
393
|
+
```typescript
|
|
394
|
+
type SessionAuth = BaseAuth &
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
**`SessionStrategyOptions`** — Options for `sessions.strategy()`.
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
interface SessionStrategyOptions
|
|
401
|
+
```
|
|
402
|
+
|
|
356
403
|
**`SessionConfig`** — Session configuration — signing keys, issuer, audience, token TTLs, refresh rotation.
|
|
357
404
|
|
|
358
405
|
```typescript
|
|
@@ -624,6 +671,10 @@ Base error class with code, statusCode, and suggestion fields.
|
|
|
624
671
|
|
|
625
672
|
403 — authenticated but insufficient permissions.
|
|
626
673
|
|
|
674
|
+
### `errors.CrossSiteRequest`
|
|
675
|
+
|
|
676
|
+
403 `CROSS_SITE_REQUEST` — a cookie-authenticated write that did not come from the app's own site.
|
|
677
|
+
|
|
627
678
|
### `errors.Validation`
|
|
628
679
|
|
|
629
680
|
422 — input validation failed, carries field-level details.
|
|
@@ -644,13 +695,17 @@ Base error class with code, statusCode, and suggestion fields.
|
|
|
644
695
|
|
|
645
696
|
415 — request body media type not accepted by the route.
|
|
646
697
|
|
|
698
|
+
### `errors.MalformedMultipart`
|
|
699
|
+
|
|
700
|
+
400 `MALFORMED_MULTIPART` — a multipart body that cannot be parsed or ends before its closing boundary.
|
|
701
|
+
|
|
647
702
|
## lifecycle — Startup & Shutdown
|
|
648
703
|
|
|
649
704
|
Application lifecycle namespace — startup orchestration with hooks and timeouts.
|
|
650
705
|
|
|
651
706
|
### `lifecycle.orchestrate`
|
|
652
707
|
|
|
653
|
-
Runs pre-start hooks (DB readiness checks, migrations, etc.) with a configurable timeout.
|
|
708
|
+
Runs pre-start hooks (DB readiness checks, migrations, etc.) with a configurable timeout. The hooks run in one trace that names the process; the trace-partition hook runs first, outside it.
|
|
654
709
|
|
|
655
710
|
## log — Structured Logging
|
|
656
711
|
|
|
@@ -690,7 +745,7 @@ Creates a worker surface — a long-running process that claims and executes job
|
|
|
690
745
|
|
|
691
746
|
### `surface.script`
|
|
692
747
|
|
|
693
|
-
Creates a script surface — a one-shot process that runs and exits (migrations, seeds, CLI tools).
|
|
748
|
+
Creates a script surface — a one-shot process that runs and exits (migrations, seeds, CLI tools). The run is traced as a job-kind trace that names the surface.
|
|
694
749
|
|
|
695
750
|
## pipe — Database
|
|
696
751
|
|
|
@@ -787,7 +842,7 @@ Pipework-owned UPDATE builder — the only consumer-facing way to update pipewor
|
|
|
787
842
|
|
|
788
843
|
### `pipe.insert`
|
|
789
844
|
|
|
790
|
-
Pipework-owned INSERT builder — the only consumer-facing way to insert into pipework-managed tables (Q8).
|
|
845
|
+
Pipework-owned INSERT builder — the only consumer-facing way to insert into pipework-managed tables (Q8). A list of any size is split into statements under Postgres's parameter limit, in one transaction.
|
|
791
846
|
|
|
792
847
|
### `pipe.delete`
|
|
793
848
|
|
|
@@ -795,7 +850,7 @@ Pipework-owned DELETE builder — the only consumer-facing way to delete from pi
|
|
|
795
850
|
|
|
796
851
|
### `pipe.upsert`
|
|
797
852
|
|
|
798
|
-
Pipework-owned UPSERT builder — insert with conflict resolution (Q8).
|
|
853
|
+
Pipework-owned UPSERT builder — insert with conflict resolution (Q8). A list of any size is split into statements under Postgres's parameter limit, in one transaction; rows repeating a conflict key across statements do not fail as one statement would.
|
|
799
854
|
|
|
800
855
|
### Types
|
|
801
856
|
|
|
@@ -947,6 +1002,14 @@ Query all versions of temporal records (no date filter).
|
|
|
947
1002
|
|
|
948
1003
|
Close the current version and create a new one with updated data.
|
|
949
1004
|
|
|
1005
|
+
### `temporal.setVersion`
|
|
1006
|
+
|
|
1007
|
+
Append the next version of an append-only-versions definition: serialised per scope, numbered, never back-dated, audited.
|
|
1008
|
+
|
|
1009
|
+
### `temporal.versionAt`
|
|
1010
|
+
|
|
1011
|
+
The version in force at a moment: the row with the greatest effectiveFrom at or before it.
|
|
1012
|
+
|
|
950
1013
|
## valve
|
|
951
1014
|
|
|
952
1015
|
Valve namespace — typed, directional, gated boundaries between code silos.
|
|
@@ -1129,6 +1192,18 @@ Alerts namespace — raise and resolve keyed conditions, grouped, delivered to s
|
|
|
1129
1192
|
|
|
1130
1193
|
Creates an alerts handle.
|
|
1131
1194
|
|
|
1195
|
+
### `alerts.http`
|
|
1196
|
+
|
|
1197
|
+
Routes for an operations agent: list, get, totals, delivery health, acknowledge, resolve, link; bearer credentials.
|
|
1198
|
+
|
|
1199
|
+
### `alerts.clientFaults`
|
|
1200
|
+
|
|
1201
|
+
One POST route that records failures reported by browser code as a trace step and an alert; answers 204, no session needed. Send with `reportClientFault` from `pipework/client`.
|
|
1202
|
+
|
|
1203
|
+
### `alerts.requestFaults`
|
|
1204
|
+
|
|
1205
|
+
An `onInternalError` hook for the HTTP server: raises `request-fault:<METHOD> <route>` for each internal 500.
|
|
1206
|
+
|
|
1132
1207
|
### `alerts.webhook`
|
|
1133
1208
|
|
|
1134
1209
|
A sink that POSTs the alert as signed JSON to a URL.
|
|
@@ -1161,6 +1236,10 @@ The newest record's `{ seq, hash }` in the tenant's audit hash chain (blueprint
|
|
|
1161
1236
|
|
|
1162
1237
|
Walks the tenant's audit hash chain and reports the first break (hash-mismatch, prev-mismatch, missing, head-mismatch, anchor-mismatch), or `{ ok: true }`.
|
|
1163
1238
|
|
|
1239
|
+
### `audit.removeTenant`
|
|
1240
|
+
|
|
1241
|
+
Deletes every audit record of one tenant and its hash chain, for the closure of that tenant's account. Irreversible; returns the number of records removed. Other tenants' records and chains are untouched.
|
|
1242
|
+
|
|
1164
1243
|
## cache — Caching
|
|
1165
1244
|
|
|
1166
1245
|
In-memory caching namespace — TTL-based with stats, preload, and tenant-aware variants.
|
|
@@ -1213,6 +1292,36 @@ Inbound source: SES receipt rule storing raw messages in S3 and notifying a sign
|
|
|
1213
1292
|
|
|
1214
1293
|
Inbound development source: `.eml` files dropped in a folder, received by `scan()`; refused in production.
|
|
1215
1294
|
|
|
1295
|
+
## untrustedFetch
|
|
1296
|
+
|
|
1297
|
+
Untrusted fetch — fetch one URL a stranger gave without letting them reach the app's private network.
|
|
1298
|
+
|
|
1299
|
+
### `untrustedFetch.get`
|
|
1300
|
+
|
|
1301
|
+
Fetches `url` with GET and returns `{ ok: true, url, status, contentType, body, bytes }`, or `{ ok: false, reason, message }`
|
|
1302
|
+
naming the rule that refused: `scheme`, `address`, `redirects`, `too_large`, `timeout`, `status`, `rejected` or `network`.
|
|
1303
|
+
It does not throw for these.
|
|
1304
|
+
|
|
1305
|
+
Rules, none of which can be switched off: only `http:` and `https:`; the name is resolved and every address is checked
|
|
1306
|
+
(loopback, private, link-local including cloud metadata, CGNAT, unique-local and site-local IPv6, multicast, reserved,
|
|
1307
|
+
unspecified, and IPv4-mapped or NAT64 forms of these; literal IP URLs likewise) and the connection goes to a checked
|
|
1308
|
+
address; redirects are followed up to `maxRedirects` and each hop is checked as the first, and the app's `headers` go only to the first origin;
|
|
1309
|
+
the body is stopped the moment it passes `maxBytes`, whatever Content-Length says; `timeoutMs` covers the whole fetch.
|
|
1310
|
+
`accept({ status, contentType, firstBytes })` sees the first 1024 bytes before the body is kept: return false, or a string
|
|
1311
|
+
(your own message), to refuse with `rejected`. Messages never contain an address or anything a server sent.
|
|
1312
|
+
|
|
1313
|
+
`resolve` and `connect` are for tests: `resolve(hostname)` replaces DNS and `connect(target)` replaces the socket after the
|
|
1314
|
+
address check passed, so a test sends a fake public address to a local server. The address check always runs on what `resolve` returns.
|
|
1315
|
+
|
|
1316
|
+
The call is the trace step `pipework/fetch:get`; its child `pipework/fetch:outcome` carries host, status, bytes and reason.
|
|
1317
|
+
The full URL is recorded only when `urlIsSafeToTrace` is true; otherwise only the host.
|
|
1318
|
+
|
|
1319
|
+
```ts
|
|
1320
|
+
const got = await untrustedFetch.get(pasted, { maxBytes: 5_000_000, timeoutMs: 10_000, maxRedirects: 3,
|
|
1321
|
+
accept: h => h.firstBytes[0] === 0x25 || 'That does not look like a PDF.' })
|
|
1322
|
+
if (!got.ok) return tell(got.message)
|
|
1323
|
+
```
|
|
1324
|
+
|
|
1216
1325
|
## storage
|
|
1217
1326
|
|
|
1218
1327
|
Storage namespace — tenant-scoped, content-addressed file storage with signed URLs and retention.
|
|
@@ -1229,6 +1338,18 @@ S3-compatible backend (AWS S3, MinIO, R2): SigV4 over `fetch`, multipart streami
|
|
|
1229
1338
|
|
|
1230
1339
|
Local-disk backend for development and tests; refused in production.
|
|
1231
1340
|
|
|
1341
|
+
## support
|
|
1342
|
+
|
|
1343
|
+
Support namespace — tickets from email (and later chat), with replies sent only after an approval.
|
|
1344
|
+
|
|
1345
|
+
### `support.create`
|
|
1346
|
+
|
|
1347
|
+
Creates the support handle: tickets, messages, notes, links, drafts, `approve`, `receiveEmail`, and the events job.
|
|
1348
|
+
|
|
1349
|
+
### `support.templates`
|
|
1350
|
+
|
|
1351
|
+
The reply template to spread into `mail.create({ templates })`; it renders the approved draft verbatim.
|
|
1352
|
+
|
|
1232
1353
|
## webhook — Inbound & Outbound Webhooks
|
|
1233
1354
|
|
|
1234
1355
|
Webhook namespace — inbound verification, outbound delivery with retries, HMAC signing.
|
|
@@ -1319,6 +1440,10 @@ Returns the current Flow or undefined — use for optional context detection.
|
|
|
1319
1440
|
|
|
1320
1441
|
Creates a Flow for test isolation with optional auth and tenant overrides.
|
|
1321
1442
|
|
|
1443
|
+
### `flow.actAs`
|
|
1444
|
+
|
|
1445
|
+
Runs `fn` as a tenant and user chosen inside a tenantless Flow (sign-up, a public sign-in): RLS, audit and trace under that tenant, on the request's transaction.
|
|
1446
|
+
|
|
1322
1447
|
## http — Server
|
|
1323
1448
|
|
|
1324
1449
|
HTTP namespace: `http.file()` builds a file response; the server itself is managed by manifold.start().
|
|
@@ -1343,6 +1468,36 @@ interface SecurityConfig
|
|
|
1343
1468
|
interface RateLimitConfig
|
|
1344
1469
|
```
|
|
1345
1470
|
|
|
1471
|
+
**`RateLimitWindow`** — One fixed window: at most `max` requests per `windowSeconds`.
|
|
1472
|
+
|
|
1473
|
+
```typescript
|
|
1474
|
+
interface RateLimitWindow
|
|
1475
|
+
```
|
|
1476
|
+
|
|
1477
|
+
**`RateLimitClass`** — A named limit class: any of a per-user, per-tenant and per-address window, each counted on its own.
|
|
1478
|
+
|
|
1479
|
+
```typescript
|
|
1480
|
+
interface RateLimitClass
|
|
1481
|
+
```
|
|
1482
|
+
|
|
1483
|
+
**`RateLimitRefusal`** — What `onRefused` is told about one refused window of one request.
|
|
1484
|
+
|
|
1485
|
+
```typescript
|
|
1486
|
+
interface RateLimitRefusal
|
|
1487
|
+
```
|
|
1488
|
+
|
|
1489
|
+
**`RateLimitClassesConfig`**
|
|
1490
|
+
|
|
1491
|
+
Named limit classes, checked after auth and counted in Postgres (`pipework_rate_limit_counts`, opted in
|
|
1492
|
+
with the blueprint's `rateLimits: {}`), so every server process on the same database shares one count.
|
|
1493
|
+
Windows are counted perUser, perTenant, perAddress in turn, up to the first one over its max, so one user's
|
|
1494
|
+
refused requests don't spend the tenant's budget. A route is in `signedIn` (auth required, or optional with
|
|
1495
|
+
a user), `public` (no auth, or optional without a user) or the class its fitting names with `.rateLimit(name)`.
|
|
1496
|
+
|
|
1497
|
+
```typescript
|
|
1498
|
+
interface RateLimitClassesConfig
|
|
1499
|
+
```
|
|
1500
|
+
|
|
1346
1501
|
**`InjectOptions`** — Options for server.inject() — method, url, headers, payload for testing without HTTP.
|
|
1347
1502
|
|
|
1348
1503
|
```typescript
|
|
@@ -1361,6 +1516,12 @@ interface InjectResponse
|
|
|
1361
1516
|
interface ServerConfig
|
|
1362
1517
|
```
|
|
1363
1518
|
|
|
1519
|
+
**`InternalErrorFault`** — What `onInternalError` is told about one request that ended in an internal error.
|
|
1520
|
+
|
|
1521
|
+
```typescript
|
|
1522
|
+
interface InternalErrorFault
|
|
1523
|
+
```
|
|
1524
|
+
|
|
1364
1525
|
**`HandlerResponse`** — Standard handler response shape — statusCode, headers, body.
|
|
1365
1526
|
|
|
1366
1527
|
```typescript
|
|
@@ -1419,7 +1580,7 @@ Generates an OpenAPI 3.1 document from route registrations — schemas derived f
|
|
|
1419
1580
|
|
|
1420
1581
|
## trace
|
|
1421
1582
|
|
|
1422
|
-
Trace namespace — hand the current trace to a process outside Node
|
|
1583
|
+
Trace namespace — hand the current trace to a process outside Node, record the steps it reports back, mark point events, and read a trace tree.
|
|
1423
1584
|
|
|
1424
1585
|
### `trace.traceparent`
|
|
1425
1586
|
|
|
@@ -1433,6 +1594,15 @@ W3C `traceparent` for the current trace and open step; `null` outside a traced f
|
|
|
1433
1594
|
|
|
1434
1595
|
Records steps reported as JSON lines (or objects) by an outside process under the step open now. Synchronous; never throws.
|
|
1435
1596
|
|
|
1597
|
+
### `trace.event`
|
|
1598
|
+
|
|
1599
|
+
Records one zero-length step `external:<name>` under the step open now, with an optional `capture` and `error`. A no-op outside a traced flow; never throws.
|
|
1600
|
+
|
|
1601
|
+
### `trace.tree`
|
|
1602
|
+
|
|
1603
|
+
Reads every hot trace sharing `rootId` (a request's trace and the jobs it queued) with their steps. Runs on the
|
|
1604
|
+
given `db`, so tenant policies apply: only an unrestricted connection (table owner, tests) sees every tenant's rows.
|
|
1605
|
+
|
|
1436
1606
|
### Types
|
|
1437
1607
|
|
|
1438
1608
|
**`FlowStepMeta`** — Trace metadata for one documented flow-step: its `path:symbol` graph node id and the per-argument capture projections.
|
|
@@ -1453,6 +1623,24 @@ type ExternalStepReport = z.infer<typeof externalStepReportSchema>
|
|
|
1453
1623
|
interface ExternalRecordResult
|
|
1454
1624
|
```
|
|
1455
1625
|
|
|
1626
|
+
**`TraceStepNode`** — One step of a trace. `ref` is the flow step's `path:symbol`, or `external:<name>` for a recorded or point-event step.
|
|
1627
|
+
|
|
1628
|
+
```typescript
|
|
1629
|
+
interface TraceStepNode
|
|
1630
|
+
```
|
|
1631
|
+
|
|
1632
|
+
**`TraceNode`** — One trace of the tree, with its steps ordered by `seq`.
|
|
1633
|
+
|
|
1634
|
+
```typescript
|
|
1635
|
+
interface TraceNode
|
|
1636
|
+
```
|
|
1637
|
+
|
|
1638
|
+
**`TraceTree`** — The traces that share a root id, ordered by when they opened.
|
|
1639
|
+
|
|
1640
|
+
```typescript
|
|
1641
|
+
interface TraceTree
|
|
1642
|
+
```
|
|
1643
|
+
|
|
1456
1644
|
## data
|
|
1457
1645
|
|
|
1458
1646
|
### `tap`
|
|
@@ -67,7 +67,7 @@ export function createScheduler(enqueuer, jobsTableQ) {
|
|
|
67
67
|
async function fireOneDue(db, names) {
|
|
68
68
|
return db.transaction(async (tx) => {
|
|
69
69
|
const filter = names !== undefined
|
|
70
|
-
? sql `AND name
|
|
70
|
+
? sql `AND name ${sql.inList(names)}`
|
|
71
71
|
: sql ``;
|
|
72
72
|
const due = await tx.execute(sql `
|
|
73
73
|
SELECT name, cron_expression, timezone, payload
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../../src/async/jobs/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAA;AAE1C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAqD/C,MAAM,UAAU,eAAe,CAAC,QAAkB,EAAE,UAAkB;IACpE,IAAI,cAAc,GAA0C,IAAI,CAAA;IAChE,IAAI,OAAO,GAAG,KAAK,CAAA;IAEnB,KAAK,UAAU,QAAQ,CAAC,EAAM,EAAE,IAAkB;QAChD,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACnC,MAAM,EAAE,GAAG,IAAI,CAAC,QAAQ,IAAI,KAAK,CAAA;QACjC,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,EAAE,IAAI,IAAI,EAAE,EAAE,EAAE,CAAC,CAAA;QAClD,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QAEpF,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,CAAA;;gBAER,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,EAAE,KAAK,WAAW,KAAK,IAAI,CAAC,CAAC,CAAC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|
259
259
|
UPDATE ${sql.raw(table)} SET status = 'cancelled', completed_at = now(), claim_token = NULL
|
|
260
260
|
WHERE id IN (SELECT id FROM ${sql.raw(table)}
|
|
261
|
-
WHERE id
|
|
261
|
+
WHERE id ${sql.inList(jobIds, 'uuid')} AND status = 'pending'
|
|
262
262
|
FOR UPDATE SKIP LOCKED)`);
|
|
263
263
|
}
|
|
264
264
|
async function lockRun(tx, runId) {
|
|
@@ -304,7 +304,7 @@ export function defineGraph(config) {
|
|
|
304
304
|
return out;
|
|
305
305
|
const rows = await tx.execute(sql `
|
|
306
306
|
SELECT id::text, value, value_hash FROM ${sql.raw(RESULT)}
|
|
307
|
-
WHERE id
|
|
307
|
+
WHERE id ${sql.inList(ids, 'uuid')}`);
|
|
308
308
|
for (const r of rows)
|
|
309
309
|
out.set(r['id'], { value: r['value'], hash: r['value_hash'] });
|
|
310
310
|
return out;
|
|
@@ -781,7 +781,7 @@ export function defineGraph(config) {
|
|
|
781
781
|
throw new Error(`[pipework] ${graph}.ended: limit must be a positive integer.\n`);
|
|
782
782
|
const only = tenant === null ? sql `` : sql ` AND tenant_id = ${tenant}::uuid`;
|
|
783
783
|
const byIds = opts?.ids === undefined ? sql `` : opts.ids.length === 0 ? sql ` AND false`
|
|
784
|
-
: sql ` AND id
|
|
784
|
+
: sql ` AND id ${sql.inList(opts.ids, 'uuid')}`;
|
|
785
785
|
const before = opts?.finishedBefore === undefined ? sql `` : sql ` AND finished_at < ${opts.finishedBefore.toISOString()}::timestamptz`;
|
|
786
786
|
const rows = await inTenantTx(db, tenant, tx => tx.execute(sql `
|
|
787
787
|
SELECT id::text, tenant_id::text, item, status, finished_at, notified FROM ${sql.raw(RUN)}
|
|
@@ -877,9 +877,9 @@ export function defineGraph(config) {
|
|
|
877
877
|
SELECT id::text FROM ${sql.raw(RUN)}
|
|
878
878
|
WHERE graph = ${graph} AND status <> 'running' AND finished_at < ${cutoff}::timestamptz${only}`);
|
|
879
879
|
if (old.length > 0) {
|
|
880
|
-
const ids = sql.
|
|
881
|
-
await tx.execute(sql `DELETE FROM ${sql.raw(TASK)} WHERE run_id
|
|
882
|
-
await tx.execute(sql `DELETE FROM ${sql.raw(RUN)} WHERE id
|
|
880
|
+
const ids = sql.inList(old.map(r => r['id']), 'uuid');
|
|
881
|
+
await tx.execute(sql `DELETE FROM ${sql.raw(TASK)} WHERE run_id ${ids}`);
|
|
882
|
+
await tx.execute(sql `DELETE FROM ${sql.raw(RUN)} WHERE id ${ids}`);
|
|
883
883
|
}
|
|
884
884
|
const rows = await tx.execute(sql `
|
|
885
885
|
DELETE FROM ${sql.raw(RESULT)} WHERE graph = ${graph} AND created_at < ${cutoff}::timestamptz${only} RETURNING id`);
|
|
@@ -938,9 +938,9 @@ export function defineGraph(config) {
|
|
|
938
938
|
}
|
|
939
939
|
let tasks = 0;
|
|
940
940
|
if (runs.length > 0) {
|
|
941
|
-
const ids = sql.
|
|
942
|
-
tasks = (await tx.execute(sql `DELETE FROM ${sql.raw(TASK)} WHERE run_id
|
|
943
|
-
await tx.execute(sql `DELETE FROM ${sql.raw(RUN)} WHERE id
|
|
941
|
+
const ids = sql.inList(runs.map(r => r['id']), 'uuid');
|
|
942
|
+
tasks = (await tx.execute(sql `DELETE FROM ${sql.raw(TASK)} WHERE run_id ${ids} RETURNING id`)).length;
|
|
943
|
+
await tx.execute(sql `DELETE FROM ${sql.raw(RUN)} WHERE id ${ids}`);
|
|
944
944
|
}
|
|
945
945
|
const gone = await tx.execute(sql `
|
|
946
946
|
DELETE FROM ${sql.raw(RESULT)} WHERE graph = ${graph} AND item = ${item} AND tenant_id = ${tenant}::uuid RETURNING id`);
|