@docsxai/engine 0.3.0-rc.2 → 0.3.0-rc.5
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/README.md +45 -35
- package/dist/atomic-write.d.ts +19 -0
- package/dist/atomic-write.js +127 -0
- package/dist/auth/api-login.d.ts +9 -51
- package/dist/auth/api-login.js +3 -3
- package/dist/auth/browser-session.js +1 -1
- package/dist/auth/cookie-jar.d.ts +4 -4
- package/dist/auth/cookie-jar.js +4 -4
- package/dist/auth/email-otp.d.ts +11 -147
- package/dist/auth/email-otp.js +4 -4
- package/dist/auth/http-basic.js +1 -1
- package/dist/auth/index.js +3 -3
- package/dist/auth/jwt-injection.d.ts +7 -131
- package/dist/auth/jwt-injection.js +5 -5
- package/dist/auth/manual-capture.d.ts +3 -3
- package/dist/auth/manual-capture.js +2 -2
- package/dist/auth/mtls.d.ts +1 -6
- package/dist/auth/mtls.js +1 -1
- package/dist/auth/pat-header.d.ts +1 -9
- package/dist/auth/pat-header.js +1 -1
- package/dist/auth/storage-state-cache.d.ts +16 -6
- package/dist/auth/storage-state-cache.js +65 -15
- package/dist/auth/test-backdoor.d.ts +2 -13
- package/dist/auth/test-backdoor.js +3 -3
- package/dist/auth/totp.d.ts +1 -1
- package/dist/auth/totp.js +4 -4
- package/dist/auth/types.d.ts +3 -3
- package/dist/auth/types.js +4 -4
- package/dist/auth/ui-form.d.ts +24 -153
- package/dist/auth/ui-form.js +3 -3
- package/dist/auth/webauthn.d.ts +7 -67
- package/dist/auth/webauthn.js +3 -3
- package/dist/auth.js +1 -1
- package/dist/backend-client-contracts.d.ts +1 -1
- package/dist/backend-client-contracts.js +2 -2
- package/dist/backend-client-oauth-login.js +1 -1
- package/dist/backend-client-state-cache.d.ts +2 -2
- package/dist/backend-client-state-cache.js +8 -8
- package/dist/backend-client-token.js +5 -5
- package/dist/backend-client-transport.d.ts +2 -2
- package/dist/backend-client-transport.js +3 -3
- package/dist/backend-client.js +6 -6
- package/dist/browser-build.d.ts +6 -0
- package/dist/browser-build.js +12 -0
- package/dist/browser-launch-error.d.ts +18 -0
- package/dist/browser-launch-error.js +63 -0
- package/dist/browser-wait.d.ts +7 -0
- package/dist/browser-wait.js +12 -0
- package/dist/calibrate.d.ts +6 -2
- package/dist/calibrate.js +20 -13
- package/dist/cli-backend-errors.d.ts +5 -0
- package/dist/cli-backend-errors.js +28 -6
- package/dist/cli-commands-auth.d.ts +1 -0
- package/dist/cli-commands-auth.js +114 -0
- package/dist/cli-commands-authoring.d.ts +0 -1
- package/dist/cli-commands-authoring.js +124 -101
- package/dist/cli-commands-backend.d.ts +1 -1
- package/dist/cli-commands-backend.js +76 -21
- package/dist/cli-commands-docpack.d.ts +3 -1
- package/dist/cli-commands-docpack.js +145 -39
- package/dist/cli-commands-init.d.ts +1 -0
- package/dist/cli-commands-init.js +100 -0
- package/dist/cli-commands-pack.d.ts +1 -1
- package/dist/cli-commands-pack.js +6 -4
- package/dist/cli-commands-session.d.ts +1 -3
- package/dist/cli-commands-session.js +109 -180
- package/dist/cli-commands-site.d.ts +2 -0
- package/dist/cli-commands-site.js +77 -0
- package/dist/cli-commands-style.d.ts +1 -0
- package/dist/cli-commands-style.js +85 -0
- package/dist/cli-flags.d.ts +18 -0
- package/dist/cli-flags.js +77 -0
- package/dist/cli-help.d.ts +30 -0
- package/dist/cli-help.js +174 -0
- package/dist/cli-messages.d.ts +35 -0
- package/dist/cli-messages.js +104 -0
- package/dist/cli-node-guard.d.ts +1 -0
- package/dist/cli-node-guard.js +8 -0
- package/dist/cli-retired.js +6 -0
- package/dist/cli-run-stale.d.ts +2 -0
- package/dist/cli-run-stale.js +13 -0
- package/dist/cli-run-summary.js +7 -3
- package/dist/cli-shared.d.ts +30 -1
- package/dist/cli-shared.js +112 -12
- package/dist/cli-unexpected.d.ts +16 -0
- package/dist/cli-unexpected.js +76 -0
- package/dist/cli-usage.d.ts +1 -1
- package/dist/cli-usage.js +116 -66
- package/dist/cli-value-flags.d.ts +8 -0
- package/dist/cli-value-flags.js +34 -0
- package/dist/cli-version.d.ts +6 -0
- package/dist/cli-version.js +25 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +46 -20
- package/dist/deprecation.d.ts +2 -0
- package/dist/deprecation.js +2 -0
- package/dist/device-scale-factor.d.ts +14 -0
- package/dist/device-scale-factor.js +38 -0
- package/dist/diagnose.js +14 -13
- package/dist/diff-compute.js +22 -8
- package/dist/diff-report.js +3 -3
- package/dist/diff-types.js +1 -1
- package/dist/diff.js +3 -3
- package/dist/doc-pack-io.js +62 -47
- package/dist/doc-pack.d.ts +567 -3487
- package/dist/doc-pack.js +47 -33
- package/dist/doctor-checks-config.d.ts +12 -0
- package/dist/doctor-checks-config.js +229 -0
- package/dist/doctor-checks-plugins.js +2 -2
- package/dist/doctor-checks-site.d.ts +3 -0
- package/dist/doctor-checks-site.js +21 -0
- package/dist/doctor-checks.d.ts +13 -2
- package/dist/doctor-checks.js +95 -79
- package/dist/doctor-next.d.ts +5 -0
- package/dist/doctor-next.js +52 -0
- package/dist/doctor.d.ts +36 -2
- package/dist/doctor.js +88 -29
- package/dist/environment-spec.d.ts +36 -44
- package/dist/environment-spec.js +31 -3
- package/dist/export/adf.d.ts +1 -1
- package/dist/export/adf.js +16 -27
- package/dist/export/playwright-test.d.ts +1 -1
- package/dist/export/playwright-test.js +13 -15
- package/dist/flow-file.d.ts +1 -1
- package/dist/flow-file.js +22 -4
- package/dist/flow-halt.d.ts +1 -1
- package/dist/flow-halt.js +15 -3
- package/dist/flow-lint.d.ts +3 -1
- package/dist/flow-lint.js +39 -26
- package/dist/flow-matrix-lint.js +2 -2
- package/dist/flow-runtime.d.ts +17 -6
- package/dist/flow-runtime.js +48 -17
- package/dist/flow-success.js +4 -4
- package/dist/flow-tree.js +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/main-module.d.ts +1 -0
- package/dist/main-module.js +17 -0
- package/dist/matrix-spec.d.ts +33 -106
- package/dist/matrix-spec.js +12 -3
- package/dist/node-floor.d.ts +4 -0
- package/dist/node-floor.js +14 -0
- package/dist/obstacles.js +1 -1
- package/dist/open-in-browser.d.ts +22 -0
- package/dist/open-in-browser.js +37 -0
- package/dist/playwright-driver.d.ts +8 -12
- package/dist/playwright-driver.js +75 -70
- package/dist/playwright-instrumented-browser.d.ts +10 -7
- package/dist/playwright-instrumented-browser.js +35 -12
- package/dist/plugins/load.d.ts +1 -1
- package/dist/plugins/load.js +4 -4
- package/dist/plugins/lock.js +11 -8
- package/dist/plugins/manifest.d.ts +16 -35
- package/dist/plugins/manifest.js +5 -5
- package/dist/plugins/plan.d.ts +3 -3
- package/dist/plugins/plan.js +14 -14
- package/dist/plugins/registry.d.ts +1 -1
- package/dist/plugins/registry.js +1 -1
- package/dist/plugins/runtime.js +3 -3
- package/dist/plugins/types.d.ts +1 -1
- package/dist/plugins-cli.js +36 -28
- package/dist/posix-path.d.ts +2 -0
- package/dist/posix-path.js +7 -0
- package/dist/redact.js +2 -2
- package/dist/run-flows.d.ts +7 -0
- package/dist/run-flows.js +75 -27
- package/dist/style.d.ts +2 -2
- package/dist/style.js +13 -11
- package/dist/verify-determinism.js +2 -1
- package/dist/verify-next-step.d.ts +2 -0
- package/dist/verify-next-step.js +24 -0
- package/dist/verify-report.js +3 -2
- package/dist/viewer-bin.d.ts +9 -3
- package/dist/viewer-bin.js +35 -12
- package/dist/workspace-templates.d.ts +15 -0
- package/dist/workspace-templates.js +88 -0
- package/dist/workspace.d.ts +78 -5
- package/dist/workspace.js +47 -28
- package/dist/zip.d.ts +1 -1
- package/dist/zip.js +23 -6
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -6,66 +6,76 @@ The engine **never** calls a model API. Calibration-time inference is supplied b
|
|
|
6
6
|
|
|
7
7
|
## Surface
|
|
8
8
|
|
|
9
|
-
- **Flow-file
|
|
10
|
-
- **Execution environment
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
18
|
-
- **
|
|
9
|
+
- **Flow-file**: declarative YAML at `<workspace>/flows/<name>.flow.yaml`, with `prerequisites` + `locators` + `steps[]` (`action`, `target`, `wait_for`, `success`, `annotation` / `annotations`, per-step `redactions`, `timeout_ms`). Actions: `navigate`, `click`, `fill`, `upload`, `press`, `hover`, `select`, `check`, `uncheck`, `wait`, `hide`, `show`. Hand-editable; schema-validated. `extends:` composition for shared preambles (with `environment` merged per-key, child wins; `redactions` concatenated).
|
|
10
|
+
- **Execution environment**: optional `environment` block (`EnvironmentSpec`) with frozen `clock` (Playwright clock API), `locale`, `timezone`, `viewport` (`VIEWPORT_PRESETS`: desktop / tablet / mobile, or explicit size), `color_scheme`, `reduced_motion`. Applied at context creation by `launchPlaywrightSession({ environment })`; on CDP-attached sessions only the clock applies (one stderr warning lists skipped fields). `contextOptions` passes `httpCredentials` / `clientCertificates` / `extraHTTPHeaders` through to `browser.newContext`.
|
|
11
|
+
- **Device scale factor**: `docsxai run --device-scale-factor <1-4>` (or `DOCSX_DEVICE_SCALE_FACTOR`, flag wins; default 1, output unchanged) passes `deviceScaleFactor` to the browser context (`launchPlaywrightSession({ deviceScaleFactor })`), so the PNG is the CSS viewport times the factor. `bounding_box` and `obstacles` stay in the PNG's device pixels, and `annotations.json` records `device_scale_factor` above 1 so `docsxai burn` can derive its pixel ratio. Not combinable with `--cdp`.
|
|
12
|
+
- **Request guard (opt-in)**: `DOCSX_EGRESS_GUARD=1` (or `launchPlaywrightSession({ egressGuard })`) routes every request of the browser context through `egress-guard.ts`: a host that is, or resolves (`dns.lookup`, all addresses) to, a link-local or cloud-metadata address is aborted, redirect hops and WebSocket connections included, and a failed lookup aborts too (the printed reason is generic: `address not allowed`); `DOCSX_EGRESS_DENY_PRIVATE=1` adds loopback and private ranges. Both take `1`, `true` or `yes`. Off by default for a local `run`; the backend runner turns it on for webhook runs, and so does the MCP HTTP transport for the browser `run_flows` starts. It does not stop DNS rebinding (`SECURITY.md`). An `upload` step reads only regular files under the workspace (`upload-path.ts`). The address rules in `address-class.ts` are a byte-identical copy of the backend's.
|
|
13
|
+
- **Hiding + step timeouts**: `hide` sets `visibility: hidden !important` on every element its `target` matches until a `show` (no target lifts all, a target lifts the `hide` that used the same selector). `PlaywrightDriver` marks the elements with a data attribute and adopts a fixed stylesheet keyed on it (`page-hide.ts`, in-page and engine-owned; the selector is data, never CSS or script). The rule lives on each element's own root, so it reaches shadow trees, and constructable stylesheets are not blocked by a page's CSP. Visibility keeps the box, so nothing reflows; there is deliberately no `display: none` option and no general CSS-injection step. The driver keeps the selectors and re-marks before every screenshot (halt shots included), so the hiding survives navigations and re-renders. `hide` waits for the element to exist (`attached`) and throws when none does, so `optional: true` covers dev-only UI such as `nextjs-portal`. A step's `timeout_ms` (100 to 30000) is passed to the driver call (`click(selector, timeoutMs?)`, `hideElements(selector, timeoutMs?)`, …); unset, nothing is passed and Playwright's 30 s default applies, so existing flows and non-optional steps are unchanged. `optional` does not shorten the wait by itself, so a missing optional target costs 30 s unless `timeout_ms` is set; `lint` R011 says so. `BrowserDriver` gains optional `hideElements?` / `showElements?`; the runtime halts a step that needs a missing one. The pure `hiddenAtEachStep` (`flow-hidden.ts`) tells `lint` (R013) and `diagnose` which selectors an earlier `hide` hid.
|
|
14
|
+
- **Redactions**: flow-level + per-step `RedactionSpec[]` (`{ selector }` or `{ region }`, style `box` | `pixelate`) masked deterministically before any screenshot (halt shots included) hits disk. The pure pixel transform is `applyRedactions` in `redact.ts`.
|
|
15
|
+
- **`BrowserDriver`** interface: what the runtime needs from a browser. The `PlaywrightDriver` implementation includes the `actionable()` predicate (see [`docs/actionability-contract.md`](../../docs/actionability-contract.md)) that browser-bridge consumers can mirror, plus a real `element_stable` wait (bounding-box polling, 10 s best-effort budget). `waitForSettled?`, `hideElements?`, `showElements?` and `nearbyBoxes?` are **optional** methods (behind `wait_for: settled`, the `hide` and `show` actions and `annotations.obstacles`), so a driver written before they existed still compiles; the runtime halts a step that needs a missing method with a message naming it (`obstacles` only when the workspace turned it on), and never calls a method the flow does not use. `PlaywrightDriver` runs the fixed in-page poll in `page-settle.ts` (fonts loaded, visible images complete, viewport box geometry unchanged for two consecutive polls, every 50 ms, bounded by the step's `timeout_ms`, default 10 s) and rejects with `settled: page did not settle within N ms ...` naming what kept moving; `inferHaltCause` turns that into the `[page never settled: ...]` prefix.
|
|
16
|
+
- **Annotation obstacles**: opt-in (`.docsxai.json` → `"annotations": { "obstacles": true }`, default off). After a step's screenshot, `runFlow` asks the driver for `nearbyBoxes(selector, 320)`: the visible text (per rendered line) and interactive elements around the target, in screenshot pixels, the target's subtree and elements containing it excluded. The pure `selectObstacles` (`obstacles.ts`) rounds boxes outward to whole pixels, clips them to the screenshot, drops duplicates, boxes inside the target and boxes covered by another kept box, caps at the 40 nearest and sorts by y, x, width, height. The result lands as `obstacles` on the annotation record, where the viewer's `burn` uses it to keep callouts off page content. The scan reads the page's own DOM (no iframe or shadow-root content) and runs only through the driver, so any `BrowserDriver` must implement `nearbyBoxes`. Off or absent, records and screenshots are unchanged.
|
|
17
|
+
- **Per-annotation placement**: a step annotation takes an optional `placement` object (`AnnotationPlacement`: `inside`, `side`, `align`, `pin_arrow`, `max_width`, `obstacle_radius`, `obstacle_limit`), bounded like `obstacles` (finite numbers in range, `max_width` 120 to 560, `obstacle_radius` 0 to 2000 CSS px, `obstacle_limit` 1 to 40) and copied onto the annotation record when set. `runFlow` scans with the annotation's own `obstacle_radius` and keeps its own `obstacle_limit` nearest boxes; the burner reads the rest. Absent, records and scans are exactly as before.
|
|
18
|
+
- **Auth strategies**: `auth/strategy.yaml` descriptor + a catalogue of scripted strategies (`api-login`, `ui-form` with a TOTP hop, `email-otp`, `webauthn`, `jwt-injection`, `http-basic`, `pat-header`, `mtls`, `test-backdoor`) alongside the human-in-the-loop `manual-capture`. See [Auth strategies](#auth-strategies) below.
|
|
19
|
+
- **CLI**: `docsxai <command>`. See `--help` or the [top-level README](../../README.md) for the full surface; this package's `dist/cli.js` is the binary.
|
|
19
20
|
|
|
20
21
|
## CLI commands
|
|
21
22
|
|
|
22
23
|
```
|
|
23
24
|
init scaffold a workspace
|
|
24
25
|
capture-auth cache an authed session
|
|
25
|
-
|
|
26
|
+
add-flow extract a flow-file from a structured guide (formerly calibrate, removed in 0.5.0)
|
|
26
27
|
inspect discover [data-testid] locators on the live page
|
|
27
28
|
run execute flows headless; emit annotations + screenshots (`--verify-determinism` byte-compares N isolated runs)
|
|
28
|
-
render build the static viewer (spawns the @docsxai/viewer bin)
|
|
29
|
+
render build the static viewer (spawns the @docsxai/viewer bin; `--lang es` for Spanish page text)
|
|
29
30
|
burn bake annotations into PNG copies (spawns the same bin's `burn`)
|
|
31
|
+
site write an Astro Starlight docs site (spawns the same bin's `site`, same flags)
|
|
30
32
|
pack build the screenshot pack: burn, optimise, hash-name, manifest; `--check` compares a rebuild with the committed pack (spawns the viewer bin's `pack`)
|
|
31
|
-
lint static checks across flow-files (R001-
|
|
33
|
+
lint static checks across flow-files (R001-R017; `extraRules` injectable via `lintFlow`)
|
|
32
34
|
flow-tree visualise the `extends` graph
|
|
33
35
|
diagnose halt-context + recommendations after a halt
|
|
34
|
-
doctor environment + workspace health-check (
|
|
36
|
+
doctor environment + workspace health-check (one ok:/fail: line per check, each with a next: step; no plugin code runs)
|
|
35
37
|
style init/validate style.yaml; --check scans for jargon leaks
|
|
36
38
|
zip package the doc pack for hand-off
|
|
37
39
|
baseline snapshot the doc pack (flows, prose, annotations, screenshots, locators) for drift comparison
|
|
38
40
|
diff deterministic drift report against a baseline (--fail-on warn|fail gates CI)
|
|
39
|
-
export project the doc pack to a publisher format (`export adf
|
|
41
|
+
export project the doc pack to a publisher format (`export adf`: Confluence ADF; `export playwright`: Playwright specs)
|
|
40
42
|
plugins list / info / sync the workspace plugin set (see Plugins below)
|
|
41
43
|
login validate a backend bearer token (`--oauth` runs the OAuth 2.1 + PKCE flow)
|
|
42
44
|
push upload the doc pack to the backend as a new revision
|
|
43
45
|
pull fetch a backend revision's artifacts into the workspace
|
|
44
46
|
```
|
|
45
47
|
|
|
46
|
-
A
|
|
48
|
+
A flag a command does not take exits 2 (`run --flwo x` prints `unknown flag --flwo, did you mean --flow?`), as does a flag given twice (except `burn --flow` and `site --flow`) and a value flag with no value. A flag that takes no value never reads the next argument, so `run --pause <workspace>` keeps the workspace. The flag table is `src/cli-flags.ts`; `burn`, `pack`, `site` and `doctor` read their argv in their own loops, and `doctor` rejects an unknown or repeated flag the same way. `run --start-from` and `--stop-after` check the step id against the selected flows before the browser launches, and a step id no selected flow has exits 2. Ctrl-C (SIGINT) or SIGTERM stops a command with one `docsxai: interrupted` line and exits 130 or 143. While `render`, `burn`, `site` or `pack` runs, the signal goes to the viewer child and docsxai waits for it: the child gets SIGKILL after 10 s, and a second signal exits at once.
|
|
49
|
+
|
|
50
|
+
First-run failures print one reason and one `next:` line (`browser-launch-error.ts`, `cli-node-guard.ts`, `cli-shared.ts`). A missing Chromium gives the install command, a refused `--cdp` endpoint gives `cannot attach to the browser at <endpoint> (ECONNREFUSED)` and the `--remote-debugging-port` flag, and `run --cdp` skips the cached-session check. `init --app-url` and `login --backend-url` take only `http:` or `https:` URLs (`isHttpUrl`) and exit 2 otherwise; `run --base-url` also takes `file:` (`isRunnableUrl`, for a local static site) and exits 2 on any other scheme; an `app_url` in `.docsxai.json` that is not one stops `run` with exit 1. `init` on a file and a refused `mkdir` get their own message, `run`, `lint` and `flow-tree` on a workspace without `flows/` print `mkdir <dir>/flows` (`missingFlowsMessage`), a cached session that is not a valid session file is called corrupt (`cachedSessionIsCorrupt`), and a `.docsxai.json` that exists but cannot be read warns in `run` and `capture-auth` and fails `doctor` with `chmod u+r`. `doctor` exits 2 on an unknown flag. `cli-node-guard.ts` runs first in `cli.ts` and exits 1 with one line on Node 18 and older (`NODE_FLOOR_MAJOR`, 20), before Playwright loads.
|
|
51
|
+
|
|
52
|
+
A flow with a top-level `matrix:` (`locales`, `color_schemes`, `viewports`; at most 64 variants) expands at parse time (`expandFlow` in `flow-matrix.ts`, schema in `matrix-spec.ts`) into one flow per variant, each under its own `environment`, with `only`/`skip` on steps and annotations and `copy_by_locale` on annotations. `run` starts one session per variant (`run-flows.ts`) and writes `docs/<flow>/<variant>/{screenshots/, annotations.json, halts/}`; `annotations.json` records the variant, and a halt message names it. Without a matrix the layout and every output byte are unchanged. `lint` (R015, R016), `flow-tree` and `diagnose --variant` read the matrix.
|
|
47
53
|
|
|
48
54
|
`run` has a sub-3-second iteration mode for long-async flows: `--start-from <step-id> --cdp <endpoint>` skips every step before the target and attaches to an already-warm Chrome.
|
|
49
55
|
|
|
50
|
-
`zip` packages the doc pack in-process (via fflate)
|
|
56
|
+
`zip` packages the doc pack in-process (via fflate), no system `zip` binary required, and **deterministically**: entries are sorted, every entry's mtime is pinned to the zip epoch (1980-01-01), and the compression level is fixed, so the same doc pack always produces a byte-identical archive. Includes `flows/`, `docs/`, `.docsxai.json`, `auth/strategy.yaml`, `README.md`; excludes `.auth/`, `**/halts/`, and (unless `--include-viewer`) `.viewer/`. Symlinks that point outside the workspace are never followed into the archive, the fixed entries included, and the archive is written atomically.
|
|
51
57
|
|
|
52
|
-
`export adf` projects the doc pack to Confluence Cloud ADF (`projectDocPackToAdf` from the library surface)
|
|
58
|
+
`export adf` projects the doc pack to Confluence Cloud ADF (`projectDocPackToAdf` from the library surface), pure and deterministic, zero HTTP. Default `--mode single` emits one consolidated document (flows as anchored H2 sections); `--mode page-tree` emits a parent overview plus one document per flow. Output lands in `<workspace>/.export/adf/` as `projection.json` + `attachments.json` (file name, source path, sha256 per burned screenshot, falling back to the clean screenshot with a warning when no burned PNG exists). A host agent hands these to the Atlassian MCP, or the `@docsxai/plugin-confluence` publisher (`confluence:push`) consumes them; **all** Confluence HTTP lives in that capability-declared plugin, never in the engine.
|
|
53
59
|
|
|
54
|
-
`baseline` + `diff` are the drift-detection pair. `baseline` snapshots `flows/` + `docs/` (step `.md`s, `annotations.json`, `screenshots/`, `locators.yaml`) into `<workspace>/.baseline/` (or `--out <dir>`); `diff` compares the live workspace against it (`diffDocPacks` on the library surface) and emits a deterministic `docsxai/drift@1` report
|
|
60
|
+
`baseline` + `diff` are the drift-detection pair. `baseline` snapshots `flows/` + `docs/` (step `.md`s, `annotations.json`, `screenshots/`, `locators.yaml`) into `<workspace>/.baseline/` (or `--out <dir>`); `diff` compares the live workspace against it (`diffDocPacks` on the library surface) and emits a deterministic `docsxai/drift@1` report. Per flow: id-keyed step field deltas, annotation moves beyond a pixel tolerance, screenshot pixel diffs via pngjs (changed-pixel count / pct / changed-region bbox; dimension changes flagged distinctly; `ignore_regions` excluded), prose line-change counts, and locator changes. `--format md` (`formatDriftReportMarkdown`) is PR-comment-ready; `--fail-on warn|fail` exits 1 at/above the threshold (defaults: ≥1% changed pixels = warn, ≥5% = fail, structural change = warn). The engine detects and reports; proposing flow-file patches stays with the host agent (`diagnose`).
|
|
55
61
|
|
|
56
|
-
`run --verify-determinism [--runs <2-5>] [--format
|
|
62
|
+
`run --verify-determinism [--runs <2-5>] [--format text|md|json]` runs the selected flows N times (default 2) through the same flow loop as a plain `run` (`runFlowsInSessions`), each into its own output root under `<workspace>/.docsxai-verify/run-<k>/` (`PlaywrightSessionOptions.outputRoot` redirects the screenshots; `upload` sources still resolve against the workspace), then byte-compares every file under the roots (`compareRuns` in `verify-compare.ts`, exported). The first differing artefact is named by path with a cause: JSON key path, PNG changed-pixel count and region (the `diffPngBuffers` of `diff`), first differing text line, or sizes. A halt is recorded as `docs/<flow>/halts/halt-context.json` in the run root, so halt context is compared like any artefact; a halted flow makes the verdict `halted` (exit 1). Run 1's tree is copied into the workspace only when every run agrees and none halted; otherwise the workspace is untouched. The roots are removed by their listing (unlink each file, rmdir each directory deepest first; `verify-tree.ts`), never recursively. The `docsxai/verify-determinism@1` report has no timestamps or paths and is ordered by ordinal path then run: exit 0 identical, 1 differing or halted, 2 usage. Nightly recipes for GitHub Actions, GitLab CI and Woodpecker are in `docs/ci-recipes.md` and `examples/ci/`.
|
|
57
63
|
|
|
58
64
|
`export playwright` renders each flow (with `extends` resolved) as a self-contained Playwright `.spec.ts` (`exportFlowAsPlaywrightTest`) into `<workspace>/.export/tests/`: locator consts, steps as page actions, `wait_for` as waits, `success` as `expect()` assertions, `environment` as `test.use()` + `page.clock.setFixedTime`, `optional` steps in try/catch. Deterministic; generated files carry a "regenerate, don't hand-edit" header.
|
|
59
65
|
|
|
60
|
-
`render` and `
|
|
66
|
+
`render`, `burn`, `site` and `pack` locate the viewer bin in order: `DOCSX_VIEWER_BIN` (path to the viewer's bin script or an executable), the `@docsxai/viewer` package installed next to the engine (its `bin` run with the current Node), then `docsxai-viewer` on PATH. A launch failure reports all three attempts.
|
|
61
67
|
|
|
62
|
-
`burn <workspace-dir> [--flow <name>] [--out <dir>] [--report <file>] [--no-connector-outline]` bakes the annotations into PNG copies by running the viewer's `burn` through that same resolution (the engine does not depend on `@docsxai/viewer`). It checks the workspace has a `docs/` directory, passes the flags through, and returns the viewer's exit code; an unknown flag or a path-like `--flow` exits 2.
|
|
68
|
+
`burn <workspace-dir> [--flow <name>] [--out <dir>] [--report <file>] [--no-connector-outline] [--strict-glyphs]` bakes the annotations into PNG copies by running the viewer's `burn` through that same resolution (the engine does not depend on `@docsxai/viewer`). It checks the workspace has a `docs/` directory, passes the flags through, and returns the viewer's exit code; an unknown flag or a path-like `--flow` exits 2. The viewer skips an annotation whose `bounding_box` is off the image, has no area or holds `NaN` (a warning names the selector and step; `--report` marks it `skipped`) and clips one that overhangs an edge.
|
|
63
69
|
|
|
64
70
|
`pack <workspace-or-raw-dir> [--from-raw] [--out <dir>] [--public-prefix <path>] [--no-optimise] [--generated-for <text>]` and `pack <workspace-or-raw-dir> --check --against <pack-dir> [--from-raw] [--threshold <pct>]` (`cli-commands-pack.ts`) are the screenshot-pack pair. The old `drift` command is retired: `cli-retired.ts` maps it to `pack --check` with a deprecation warning (`deprecation.ts`). Like `burn`, the engine validates the argv edge (an unknown flag, a flag with no value, a second positional, no `--against`, a `--threshold` that is not a number >= 0 all exit 2), then runs the viewer's `pack` or `drift` through the same bin resolution (`runViewerBin` in `viewer-bin.ts`) and returns its exit code. The viewer owns the logic (burn, `oxipng`, hashing, manifest, drift); the engine does not import it. See the [viewer README](../viewer/README.md#screenshot-pack).
|
|
65
71
|
|
|
72
|
+
`push` reads the whole doc pack before it touches the backend, so an unreadable pack (an invalid `docs/style.json`) exits 1 with nothing created there, and it leaves out files that are symlinks to a file outside the workspace; the backend ids it records in `.docsxai.json` are written atomically. `pull` requests only the artifact names `flows`, `annotations`, `screenshots`, `style` and `locators` (a warning for any other name) and writes the doc pack as one transaction (`writeDocPack` in `doc-pack-io.ts`, staging through `atomic-write.ts`): every file is staged next to its target and renamed into place together, a failure while staging changes nothing, and a failed rename puts the swapped files back. `export adf` and `export playwright` skip a flow file, step markdown file or screenshot that is a symlink to a file outside the workspace; one that points inside it still works.
|
|
73
|
+
|
|
74
|
+
`lint` rule R017 warns when a flow's `name:` differs from its file name, because `extends`, `--flow` and `docs/<name>/` use the name. Two flow files with one `name:` stop `run`, `lint` and `flow-tree` with exit 1. A matrix viewport `name` may not be `screenshots`, `halts` or a Windows device name (`con`, `prn`, `aux`, `nul`, `com1` to `com9`, `lpt1` to `lpt9`), because it becomes a directory. `style` on a path that is not a directory exits 1 and writes nothing.
|
|
75
|
+
|
|
66
76
|
## Auth strategies
|
|
67
77
|
|
|
68
|
-
Target-site auth lives in `src/auth/` (one module per strategy) behind the `src/auth.ts` re-export shim. Every strategy implements `AuthStrategy.authenticate(ctx) → AuthResult` and reduces to the same universal artifact: a **`storageState`** (cookies + localStorage) the runtime seeds the browser context with, plus
|
|
78
|
+
Target-site auth lives in `src/auth/` (one module per strategy) behind the `src/auth.ts` re-export shim. Every strategy implements `AuthStrategy.authenticate(ctx) → AuthResult` and reduces to the same universal artifact: a **`storageState`** (cookies + localStorage) the runtime seeds the browser context with, plus, for connection-level schemes, `contextOptions` (`httpCredentials` / `extraHTTPHeaders` / `clientCertificates`) passed through to `browser.newContext`. Roles are declared in `<workspace>/auth/strategy.yaml` (`docsxai/auth-strategy@1`): per-role `strategy`, `creds_env` (credential **keys → env-var names**, never values), `options`, and `cache` (local/backend store, `ttl`, `auth_cookie` expiry pinning). The local cache is `<workspace>/.auth/<role>.json`, written with mode 0600 (`src/auth/storage-state-cache.ts`); a role name with characters outside `A-Za-z0-9_.-`, and `backend-token`, gets a hash suffix in the file name, so two roles never share a file and none overwrites the OAuth token file.
|
|
69
79
|
|
|
70
80
|
| Strategy | Scheme | Browser needed |
|
|
71
81
|
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------- |
|
|
@@ -85,12 +95,12 @@ Cross-cutting contracts:
|
|
|
85
95
|
- **Secrets stay out of band.** Strategies read env-var _names_ from the descriptor and resolve values at run time; error messages mask values as `<SET>`/`<UNSET>` and never echo them.
|
|
86
96
|
- **User pools.** Any credential env value may be comma-separated (`u1,u2,u3`); `resolveCreds({ workerIndex })` gives parallel worker N entry `N % len`, consistently across every pooled variable.
|
|
87
97
|
- **`expiresAt` when derivable.** From the named / lone real-expiry cookie (`jarAuthExpiry`), the JWT `exp` claim, or the token endpoint's `expires_in`; the cache's `auth_cookie` / `ttl` rules cover the rest.
|
|
88
|
-
- **Registries.** `registerAuthStrategy(name, impl)` adds or overrides a scheme (consulted before the built-ins
|
|
98
|
+
- **Registries.** `registerAuthStrategy(name, impl)` adds or overrides a scheme (consulted before the built-ins: the plugins-runtime hook); `registerInboxProvider(name, factory)` adds `email-otp` inbox shapes.
|
|
89
99
|
- **One Playwright import site.** Browser-driving strategies depend on the narrow `AuthPage` interface (`src/auth/browser-session.ts`); the default launcher routes through `launchPlaywrightSession`, so unit tests fake the page and `playwright-driver.ts` remains the engine's single Playwright integration point.
|
|
90
100
|
|
|
91
101
|
## Plugins
|
|
92
102
|
|
|
93
|
-
The engine hosts a workspace plugin runtime (v1) with four extension points: **publishers**, **renderers**, **lint-rules**, and **auth-strategies**. Plugins are normal npm packages: a `docsxai` field on `package.json` plus a module exporting `register(api)`. They run **in-process and unsandboxed
|
|
103
|
+
The engine hosts a workspace plugin runtime (v1) with four extension points: **publishers**, **renderers**, **lint-rules**, and **auth-strategies**. Plugins are normal npm packages: a `docsxai` field on `package.json` plus a module exporting `register(api)`. They run **in-process and unsandboxed**: `trust` is a review signal, not a boundary. The no-model-API rule binds them exactly as it binds the engine.
|
|
94
104
|
|
|
95
105
|
### Manifest (`package.json#docsxai`)
|
|
96
106
|
|
|
@@ -105,20 +115,20 @@ The engine hosts a workspace plugin runtime (v1) with four extension points: **p
|
|
|
105
115
|
"kinds": ["publisher"],
|
|
106
116
|
"capabilities": ["egress:*.atlassian.net"],
|
|
107
117
|
"dependsOn": [],
|
|
108
|
-
"trust": "
|
|
118
|
+
"trust": "example-org"
|
|
109
119
|
}
|
|
110
120
|
}
|
|
111
121
|
```
|
|
112
122
|
|
|
113
|
-
- `apiVersion
|
|
114
|
-
- `namespace
|
|
115
|
-
- `kinds
|
|
116
|
-
- `capabilities
|
|
117
|
-
- `dependsOn
|
|
123
|
+
- `apiVersion`: exact semver of the runtime contract the plugin codes against. Must share the engine's `RUNTIME_API_VERSION` major with minor ≤ the runtime's, or the plugin load-errors.
|
|
124
|
+
- `namespace`: mandatory, `/^[a-z][a-z0-9-]*$/`. Every registered artifact is exposed as `<namespace>:<name>` (the runtime prefixes; plugins pass bare names). Reserved: `site-docs`, `docsxai`, `core`, `plugins`. Two plugins claiming one namespace are **both** disabled.
|
|
125
|
+
- `kinds`: the extension points the plugin registers (≥1). Registering an undeclared kind throws and load-errors the plugin (capability-disclosure honesty).
|
|
126
|
+
- `capabilities`: `egress:<host-glob>` declarations, subset-checked against the workspace's `plugin_capabilities`. Mismatch disables the plugin (status, not fatal). Publisher plugins are the **only** wiki/VCS egress path in the engine.
|
|
127
|
+
- `dependsOn`: `{ plugin, version }` entries (package name + `^`/`~`/exact range). Load order is topological; cycles are rejected as a unit.
|
|
118
128
|
|
|
119
129
|
### `register(api)`
|
|
120
130
|
|
|
121
|
-
The register module exports a `register(api)` function (named or default). `api` exposes `namespace`, `declaredKinds`, `declaredCapabilities`, `registerPublisher(name, impl)`, `registerRenderer(name, impl)`, `registerLintRules(name, rules)`, `registerAuthStrategy(name, impl)`, a stderr logger (`api.log`, prefixed `[plugin:<ns>]`), and `api.workspacePath(...segments)
|
|
131
|
+
The register module exports a `register(api)` function (named or default). `api` exposes `namespace`, `declaredKinds`, `declaredCapabilities`, `registerPublisher(name, impl)`, `registerRenderer(name, impl)`, `registerLintRules(name, rules)`, `registerAuthStrategy(name, impl)`, a stderr logger (`api.log`, prefixed `[plugin:<ns>]`), and `api.workspacePath(...segments)`, the only filesystem root a plugin may touch (escape attempts throw). The extension-point contracts (`PublisherPlugin`, `RendererPlugin`, `AuthStrategyPlugin`, `PluginLintRule`) are exported from this package.
|
|
122
132
|
|
|
123
133
|
### Workspace config + lock
|
|
124
134
|
|
|
@@ -139,11 +149,11 @@ Two optional `.docsxai.json` keys wire plugins into a workspace (a third, `annot
|
|
|
139
149
|
|
|
140
150
|
```
|
|
141
151
|
docsxai plugins list <workspace> status table (loaded / disabled reasons); exit 1 if any plugin isn't loaded
|
|
142
|
-
docsxai plugins info <workspace> <namespace>
|
|
143
|
-
docsxai plugins sync <workspace> (re)write plugins-lock.json
|
|
152
|
+
docsxai plugins info <workspace> <namespace> manifest + registered artifact names
|
|
153
|
+
docsxai plugins sync <workspace> (re)write plugins-lock.json, never executes plugin code
|
|
144
154
|
```
|
|
145
155
|
|
|
146
|
-
All three accept `--format json`. Plugins are resolved once per CLI invocation
|
|
156
|
+
All three accept `--format json`. Plugins are resolved once per CLI invocation, so there is no hot reload.
|
|
147
157
|
|
|
148
158
|
## License
|
|
149
159
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write `data` to `target`: temp file next to it, then rename. An existing target keeps its mode.
|
|
3
|
+
* A target that is a symlink is written in place so the link survives. When the rename is refused
|
|
4
|
+
* (Windows, over an existing file) the write falls back to a plain `writeFile`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function writeFileAtomic(target: string, data: string | Uint8Array, encoding?: BufferEncoding): Promise<void>;
|
|
7
|
+
export interface StagedFile {
|
|
8
|
+
target: string;
|
|
9
|
+
data: string | Uint8Array;
|
|
10
|
+
encoding?: BufferEncoding;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Write several files all or nothing. Every file is first written to a temp file next to its
|
|
14
|
+
* target (any failure here removes the temp files and the directories created for them, and
|
|
15
|
+
* touches no target). Then each temp file is renamed over its target, the old file kept aside; if a
|
|
16
|
+
* rename fails, the files already swapped are put back. Targets that are symlinks keep the link:
|
|
17
|
+
* the file behind it is replaced. When two entries name one target, the last wins.
|
|
18
|
+
*/
|
|
19
|
+
export declare function writeFilesTransactional(files: StagedFile[]): Promise<void>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Write a file so a reader (or a crash, or a SIGINT) never sees half of it: the bytes go to a
|
|
2
|
+
// temp file in the target's directory and a rename swaps it in. A rename inside one directory is
|
|
3
|
+
// atomic on POSIX file systems.
|
|
4
|
+
import { randomBytes } from "node:crypto";
|
|
5
|
+
import { promises as fs } from "node:fs";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
/** Errors a Windows rename onto an existing (or open) file raises. */
|
|
8
|
+
const RENAME_BLOCKED = new Set(["EPERM", "EEXIST", "EBUSY", "EACCES"]);
|
|
9
|
+
/**
|
|
10
|
+
* Write `data` to `target`: temp file next to it, then rename. An existing target keeps its mode.
|
|
11
|
+
* A target that is a symlink is written in place so the link survives. When the rename is refused
|
|
12
|
+
* (Windows, over an existing file) the write falls back to a plain `writeFile`.
|
|
13
|
+
*/
|
|
14
|
+
export async function writeFileAtomic(target, data, encoding) {
|
|
15
|
+
const existing = await fs.lstat(target).catch(() => null);
|
|
16
|
+
if (existing?.isSymbolicLink()) {
|
|
17
|
+
await fs.writeFile(target, data, encoding);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const tmp = path.join(path.dirname(target), `.${path.basename(target)}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`);
|
|
21
|
+
try {
|
|
22
|
+
try {
|
|
23
|
+
await fs.writeFile(tmp, data, encoding);
|
|
24
|
+
if (existing)
|
|
25
|
+
await fs.chmod(tmp, existing.mode & 0o7777);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
// The temp file's name is an implementation detail; report the file the caller asked for.
|
|
29
|
+
if (e.path === tmp)
|
|
30
|
+
e.path = target;
|
|
31
|
+
throw e;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
await fs.rename(tmp, target);
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
if (!RENAME_BLOCKED.has(e.code ?? ""))
|
|
38
|
+
throw e;
|
|
39
|
+
await fs.writeFile(target, data, encoding);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
await fs.rm(tmp, { force: true });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function siblingTemp(target, tag) {
|
|
47
|
+
return path.join(path.dirname(target), `.${path.basename(target)}.${process.pid}.${randomBytes(4).toString("hex")}.${tag}`);
|
|
48
|
+
}
|
|
49
|
+
/** Keep the old bytes of `dest` under `backup`: a hard link when the file system has them, else a copy. */
|
|
50
|
+
async function keepBackup(dest, backup) {
|
|
51
|
+
try {
|
|
52
|
+
await fs.link(dest, backup);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
await fs.copyFile(dest, backup);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Write several files all or nothing. Every file is first written to a temp file next to its
|
|
60
|
+
* target (any failure here removes the temp files and the directories created for them, and
|
|
61
|
+
* touches no target). Then each temp file is renamed over its target, the old file kept aside; if a
|
|
62
|
+
* rename fails, the files already swapped are put back. Targets that are symlinks keep the link:
|
|
63
|
+
* the file behind it is replaced. When two entries name one target, the last wins.
|
|
64
|
+
*/
|
|
65
|
+
export async function writeFilesTransactional(files) {
|
|
66
|
+
const staged = [];
|
|
67
|
+
const createdDirs = [];
|
|
68
|
+
const cleanup = async () => {
|
|
69
|
+
for (const s of staged) {
|
|
70
|
+
await fs.rm(s.tmp, { force: true });
|
|
71
|
+
if (s.backup)
|
|
72
|
+
await fs.rm(s.backup, { force: true });
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
const byDest = new Map();
|
|
77
|
+
for (const f of files) {
|
|
78
|
+
const existing = await fs.lstat(f.target).catch(() => null);
|
|
79
|
+
const dest = existing?.isSymbolicLink()
|
|
80
|
+
? await fs.realpath(f.target).catch(() => f.target)
|
|
81
|
+
: f.target;
|
|
82
|
+
byDest.set(dest, f);
|
|
83
|
+
}
|
|
84
|
+
for (const [dest, f] of byDest) {
|
|
85
|
+
const made = await fs.mkdir(path.dirname(dest), { recursive: true });
|
|
86
|
+
if (made !== undefined)
|
|
87
|
+
createdDirs.push(made);
|
|
88
|
+
const tmp = siblingTemp(dest, "tmp");
|
|
89
|
+
staged.push({ tmp, dest, swapped: false });
|
|
90
|
+
await fs.writeFile(tmp, f.data, f.encoding);
|
|
91
|
+
const old = await fs.stat(dest).catch(() => null);
|
|
92
|
+
if (old?.isFile())
|
|
93
|
+
await fs.chmod(tmp, old.mode & 0o7777);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
await cleanup();
|
|
98
|
+
for (const d of createdDirs)
|
|
99
|
+
await fs.rm(d, { recursive: true, force: true });
|
|
100
|
+
throw e;
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
for (const s of staged) {
|
|
104
|
+
if (await fs.lstat(s.dest).then(() => true, () => false)) {
|
|
105
|
+
s.backup = siblingTemp(s.dest, "bak");
|
|
106
|
+
await keepBackup(s.dest, s.backup);
|
|
107
|
+
}
|
|
108
|
+
await fs.rename(s.tmp, s.dest);
|
|
109
|
+
s.swapped = true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
for (const s of [...staged].reverse()) {
|
|
114
|
+
if (!s.swapped)
|
|
115
|
+
continue;
|
|
116
|
+
if (s.backup)
|
|
117
|
+
await fs.rename(s.backup, s.dest).catch(() => undefined);
|
|
118
|
+
else
|
|
119
|
+
await fs.rm(s.dest, { force: true });
|
|
120
|
+
}
|
|
121
|
+
await cleanup();
|
|
122
|
+
for (const d of createdDirs)
|
|
123
|
+
await fs.rm(d, { recursive: true, force: true });
|
|
124
|
+
throw e;
|
|
125
|
+
}
|
|
126
|
+
await cleanup();
|
|
127
|
+
}
|
package/dist/auth/api-login.d.ts
CHANGED
|
@@ -1,63 +1,21 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { type AuthContext, type AuthResult, type AuthStrategy } from "./types.js";
|
|
3
3
|
export declare const ApiLoginOptions: z.ZodObject<{
|
|
4
|
-
/** Login endpoint; resolved against the target's base URL when relative. */
|
|
5
4
|
login_url: z.ZodString;
|
|
6
5
|
method: z.ZodDefault<z.ZodString>;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* the dotted path must equal `equals`. Default: final status < 400.
|
|
13
|
-
*/
|
|
14
|
-
success_check: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
6
|
+
body_format: z.ZodDefault<z.ZodEnum<{
|
|
7
|
+
json: "json";
|
|
8
|
+
form: "form";
|
|
9
|
+
}>>;
|
|
10
|
+
success_check: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
15
11
|
cookie: z.ZodString;
|
|
16
|
-
},
|
|
17
|
-
cookie: string;
|
|
18
|
-
}, {
|
|
19
|
-
cookie: string;
|
|
20
|
-
}>, z.ZodObject<{
|
|
12
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
21
13
|
status: z.ZodNumber;
|
|
22
|
-
},
|
|
23
|
-
status: number;
|
|
24
|
-
}, {
|
|
25
|
-
status: number;
|
|
26
|
-
}>, z.ZodObject<{
|
|
14
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
27
15
|
json_path: z.ZodString;
|
|
28
16
|
equals: z.ZodUnknown;
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
equals?: unknown;
|
|
32
|
-
}, {
|
|
33
|
-
json_path: string;
|
|
34
|
-
equals?: unknown;
|
|
35
|
-
}>]>>;
|
|
36
|
-
}, "strict", z.ZodTypeAny, {
|
|
37
|
-
method: string;
|
|
38
|
-
login_url: string;
|
|
39
|
-
body_format: "json" | "form";
|
|
40
|
-
success_check?: {
|
|
41
|
-
cookie: string;
|
|
42
|
-
} | {
|
|
43
|
-
status: number;
|
|
44
|
-
} | {
|
|
45
|
-
json_path: string;
|
|
46
|
-
equals?: unknown;
|
|
47
|
-
} | undefined;
|
|
48
|
-
}, {
|
|
49
|
-
login_url: string;
|
|
50
|
-
method?: string | undefined;
|
|
51
|
-
body_format?: "json" | "form" | undefined;
|
|
52
|
-
success_check?: {
|
|
53
|
-
cookie: string;
|
|
54
|
-
} | {
|
|
55
|
-
status: number;
|
|
56
|
-
} | {
|
|
57
|
-
json_path: string;
|
|
58
|
-
equals?: unknown;
|
|
59
|
-
} | undefined;
|
|
60
|
-
}>;
|
|
17
|
+
}, z.core.$strict>]>>;
|
|
18
|
+
}, z.core.$strict>;
|
|
61
19
|
export type ApiLoginOptions = z.infer<typeof ApiLoginOptions>;
|
|
62
20
|
/** Walk a dotted path (`a.b.c`) through a parsed JSON value. */
|
|
63
21
|
export declare function getJsonPath(value: unknown, dottedPath: string): unknown;
|
package/dist/auth/api-login.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// `api-login
|
|
1
|
+
// `api-login`: POST the role's credentials to the app's login endpoint and keep the session
|
|
2
2
|
// cookies. Pure node fetch; no browser. The strategy of choice when the target has a JSON or
|
|
3
3
|
// form login API the operator may call directly.
|
|
4
4
|
import { z } from "zod";
|
|
@@ -58,11 +58,11 @@ export class ApiLoginStrategy {
|
|
|
58
58
|
},
|
|
59
59
|
...(hasBody ? { body } : {}),
|
|
60
60
|
}, { fetchImpl: this.fetchImpl });
|
|
61
|
-
// Failure messages name the endpoint and the check
|
|
61
|
+
// Failure messages name the endpoint and the check, never the credential values.
|
|
62
62
|
const check = opts.success_check;
|
|
63
63
|
if (check === undefined) {
|
|
64
64
|
if (result.status >= 400) {
|
|
65
|
-
throw new AuthStrategyConfigError(`api-login: ${url.href} answered ${result.status}
|
|
65
|
+
throw new AuthStrategyConfigError(`api-login: ${url.href} answered ${result.status}, login rejected (credentials read from env; values not shown)`);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
else if ("cookie" in check) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The narrow page surface browser-driving auth strategies (ui-form, email-otp, webauthn) need.
|
|
2
2
|
//
|
|
3
3
|
// Mirrors the `InstrumentedBrowser` pattern: strategies depend on this interface so unit tests
|
|
4
|
-
// fake it; the Playwright-backed default launcher routes through `launchPlaywrightSession
|
|
4
|
+
// fake it; the Playwright-backed default launcher routes through `launchPlaywrightSession`,
|
|
5
5
|
// `playwright-driver.ts` stays the engine's one Playwright import site.
|
|
6
6
|
import { launchPlaywrightSession } from "../playwright-driver.js";
|
|
7
7
|
/** Default launcher: a fresh headless Chromium context via the engine's Playwright session. */
|
|
@@ -18,7 +18,7 @@ export declare class CookieJar {
|
|
|
18
18
|
get(name: string): StorageStateCookie | undefined;
|
|
19
19
|
has(name: string): boolean;
|
|
20
20
|
cookies(): StorageStateCookie[];
|
|
21
|
-
/** `Cookie:` header value for a request to `url
|
|
21
|
+
/** `Cookie:` header value for a request to `url`, domain/path/secure/expiry-matched. Empty string if none apply. */
|
|
22
22
|
cookieHeaderFor(url: URL, now?: number): string;
|
|
23
23
|
toStorageState(): StorageState;
|
|
24
24
|
}
|
|
@@ -41,7 +41,7 @@ export interface CollectingFetchResult {
|
|
|
41
41
|
/**
|
|
42
42
|
* Fetch with `redirect: "manual"`, following up to `maxRedirects` hops (default 5) while
|
|
43
43
|
* collecting `Set-Cookie` headers into a {@link CookieJar} and replaying matching cookies on
|
|
44
|
-
* each hop. 303
|
|
44
|
+
* each hop. 303, and 301/302 on a non-GET, switch the method to GET and drop the body,
|
|
45
45
|
* matching browser behaviour.
|
|
46
46
|
*/
|
|
47
47
|
export declare function fetchCollectingCookies(url: string | URL, init?: CollectingFetchInit, opts?: {
|
|
@@ -52,7 +52,7 @@ export declare function fetchCollectingCookies(url: string | URL, init?: Collect
|
|
|
52
52
|
}): Promise<CollectingFetchResult>;
|
|
53
53
|
/**
|
|
54
54
|
* The expiry a login strategy can credibly report: the named cookie's expiry when the caller
|
|
55
|
-
* knows which cookie is the session, else
|
|
56
|
-
* cookie
|
|
55
|
+
* knows which cookie is the session, else, only when the jar has exactly one real-expiry
|
|
56
|
+
* cookie: that one. Ambiguous jars report `undefined` (the cache's `ttl` takes over).
|
|
57
57
|
*/
|
|
58
58
|
export declare function jarAuthExpiry(state: StorageState, preferredCookie?: string): number | undefined;
|
package/dist/auth/cookie-jar.js
CHANGED
|
@@ -139,7 +139,7 @@ export class CookieJar {
|
|
|
139
139
|
cookies() {
|
|
140
140
|
return [...this.store.values()];
|
|
141
141
|
}
|
|
142
|
-
/** `Cookie:` header value for a request to `url
|
|
142
|
+
/** `Cookie:` header value for a request to `url`, domain/path/secure/expiry-matched. Empty string if none apply. */
|
|
143
143
|
cookieHeaderFor(url, now = Date.now()) {
|
|
144
144
|
const sendable = this.cookies().filter((c) => {
|
|
145
145
|
if (c.expires > 0 && c.expires * 1000 <= now)
|
|
@@ -157,7 +157,7 @@ export class CookieJar {
|
|
|
157
157
|
/**
|
|
158
158
|
* Fetch with `redirect: "manual"`, following up to `maxRedirects` hops (default 5) while
|
|
159
159
|
* collecting `Set-Cookie` headers into a {@link CookieJar} and replaying matching cookies on
|
|
160
|
-
* each hop. 303
|
|
160
|
+
* each hop. 303, and 301/302 on a non-GET, switch the method to GET and drop the body,
|
|
161
161
|
* matching browser behaviour.
|
|
162
162
|
*/
|
|
163
163
|
export async function fetchCollectingCookies(url, init = {}, opts = {}) {
|
|
@@ -199,8 +199,8 @@ export async function fetchCollectingCookies(url, init = {}, opts = {}) {
|
|
|
199
199
|
}
|
|
200
200
|
/**
|
|
201
201
|
* The expiry a login strategy can credibly report: the named cookie's expiry when the caller
|
|
202
|
-
* knows which cookie is the session, else
|
|
203
|
-
* cookie
|
|
202
|
+
* knows which cookie is the session, else, only when the jar has exactly one real-expiry
|
|
203
|
+
* cookie: that one. Ambiguous jars report `undefined` (the cache's `ttl` takes over).
|
|
204
204
|
*/
|
|
205
205
|
export function jarAuthExpiry(state, preferredCookie) {
|
|
206
206
|
if (preferredCookie) {
|