@docsxai/engine 0.2.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/LICENSE +202 -0
- package/README.md +130 -0
- package/dist/auth/api-login.d.ts +69 -0
- package/dist/auth/api-login.js +95 -0
- package/dist/auth/browser-session.d.ts +28 -0
- package/dist/auth/browser-session.js +43 -0
- package/dist/auth/cookie-jar.d.ts +58 -0
- package/dist/auth/cookie-jar.js +212 -0
- package/dist/auth/email-otp.d.ts +210 -0
- package/dist/auth/email-otp.js +166 -0
- package/dist/auth/http-basic.d.ts +5 -0
- package/dist/auth/http-basic.js +17 -0
- package/dist/auth/index.d.ts +47 -0
- package/dist/auth/index.js +137 -0
- package/dist/auth/jwt-injection.d.ts +153 -0
- package/dist/auth/jwt-injection.js +136 -0
- package/dist/auth/manual-capture.d.ts +35 -0
- package/dist/auth/manual-capture.js +30 -0
- package/dist/auth/mtls.d.ts +15 -0
- package/dist/auth/mtls.js +53 -0
- package/dist/auth/pat-header.d.ts +19 -0
- package/dist/auth/pat-header.js +34 -0
- package/dist/auth/storage-state-cache.d.ts +38 -0
- package/dist/auth/storage-state-cache.js +143 -0
- package/dist/auth/test-backdoor.d.ts +25 -0
- package/dist/auth/test-backdoor.js +51 -0
- package/dist/auth/totp.d.ts +39 -0
- package/dist/auth/totp.js +108 -0
- package/dist/auth/types.d.ts +86 -0
- package/dist/auth/types.js +57 -0
- package/dist/auth/ui-form.d.ts +204 -0
- package/dist/auth/ui-form.js +153 -0
- package/dist/auth/webauthn.d.ts +88 -0
- package/dist/auth/webauthn.js +67 -0
- package/dist/auth.d.ts +1 -0
- package/dist/auth.js +3 -0
- package/dist/backend-client-contracts.d.ts +88 -0
- package/dist/backend-client-contracts.js +19 -0
- package/dist/backend-client-oauth-login.d.ts +7 -0
- package/dist/backend-client-oauth-login.js +90 -0
- package/dist/backend-client-state-cache.d.ts +73 -0
- package/dist/backend-client-state-cache.js +185 -0
- package/dist/backend-client-token.d.ts +18 -0
- package/dist/backend-client-token.js +94 -0
- package/dist/backend-client-transport.d.ts +66 -0
- package/dist/backend-client-transport.js +181 -0
- package/dist/backend-client.d.ts +5 -0
- package/dist/backend-client.js +18 -0
- package/dist/calibrate.d.ts +31 -0
- package/dist/calibrate.js +68 -0
- package/dist/cli-commands-authoring.d.ts +5 -0
- package/dist/cli-commands-authoring.js +403 -0
- package/dist/cli-commands-backend.d.ts +5 -0
- package/dist/cli-commands-backend.js +211 -0
- package/dist/cli-commands-docpack.d.ts +5 -0
- package/dist/cli-commands-docpack.js +280 -0
- package/dist/cli-commands-session.d.ts +4 -0
- package/dist/cli-commands-session.js +398 -0
- package/dist/cli-shared.d.ts +5 -0
- package/dist/cli-shared.js +45 -0
- package/dist/cli-usage.d.ts +1 -0
- package/dist/cli-usage.js +137 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +77 -0
- package/dist/diagnose.d.ts +50 -0
- package/dist/diagnose.js +168 -0
- package/dist/diff-compute.d.ts +13 -0
- package/dist/diff-compute.js +378 -0
- package/dist/diff-report.d.ts +7 -0
- package/dist/diff-report.js +125 -0
- package/dist/diff-types.d.ts +125 -0
- package/dist/diff-types.js +15 -0
- package/dist/diff.d.ts +3 -0
- package/dist/diff.js +16 -0
- package/dist/doc-pack-io.d.ts +30 -0
- package/dist/doc-pack-io.js +182 -0
- package/dist/doc-pack.d.ts +1814 -0
- package/dist/doc-pack.js +328 -0
- package/dist/doctor-checks-plugins.d.ts +2 -0
- package/dist/doctor-checks-plugins.js +136 -0
- package/dist/doctor-checks.d.ts +56 -0
- package/dist/doctor-checks.js +367 -0
- package/dist/doctor.d.ts +7 -0
- package/dist/doctor.js +62 -0
- package/dist/export/adf.d.ts +57 -0
- package/dist/export/adf.js +323 -0
- package/dist/export/playwright-test.d.ts +26 -0
- package/dist/export/playwright-test.js +221 -0
- package/dist/flow-file.d.ts +21 -0
- package/dist/flow-file.js +180 -0
- package/dist/flow-lint.d.ts +24 -0
- package/dist/flow-lint.js +203 -0
- package/dist/flow-runtime.d.ts +113 -0
- package/dist/flow-runtime.js +273 -0
- package/dist/flow-tree.d.ts +19 -0
- package/dist/flow-tree.js +104 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +31 -0
- package/dist/playwright-driver.d.ts +105 -0
- package/dist/playwright-driver.js +363 -0
- package/dist/playwright-instrumented-browser.d.ts +51 -0
- package/dist/playwright-instrumented-browser.js +189 -0
- package/dist/plugins/load.d.ts +22 -0
- package/dist/plugins/load.js +99 -0
- package/dist/plugins/lock.d.ts +40 -0
- package/dist/plugins/lock.js +122 -0
- package/dist/plugins/manifest.d.ts +70 -0
- package/dist/plugins/manifest.js +115 -0
- package/dist/plugins/plan.d.ts +51 -0
- package/dist/plugins/plan.js +279 -0
- package/dist/plugins/registry.d.ts +59 -0
- package/dist/plugins/registry.js +71 -0
- package/dist/plugins/runtime.d.ts +7 -0
- package/dist/plugins/runtime.js +27 -0
- package/dist/plugins/types.d.ts +58 -0
- package/dist/plugins/types.js +4 -0
- package/dist/plugins-cli.d.ts +1 -0
- package/dist/plugins-cli.js +191 -0
- package/dist/redact.d.ts +16 -0
- package/dist/redact.js +72 -0
- package/dist/style.d.ts +46 -0
- package/dist/style.js +151 -0
- package/dist/viewer-bin.d.ts +20 -0
- package/dist/viewer-bin.js +97 -0
- package/dist/workspace.d.ts +60 -0
- package/dist/workspace.js +172 -0
- package/dist/zip.d.ts +17 -0
- package/dist/zip.js +113 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# @docsxai/engine
|
|
2
|
+
|
|
3
|
+
LLM-agnostic engine: flow-file parser + runtime, calibration helpers, target-site auth strategies, and the full `docsxai` CLI.
|
|
4
|
+
|
|
5
|
+
The engine **never** calls a model API. Calibration-time inference is supplied by the host agent (Claude Code, Codex, anything that speaks MCP) through the plugin's skill surface; execution is deterministic and replays a doc pack through headless Playwright.
|
|
6
|
+
|
|
7
|
+
## Surface
|
|
8
|
+
|
|
9
|
+
- **Flow-file** — declarative YAML at `<workspace>/flows/<name>.flow.yaml`: `prerequisites` + `locators` + `steps[]` (`action`, `target`, `wait_for`, `success`, `annotation` / `annotations`, per-step `redactions`). 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`): 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
|
+
- **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`.
|
|
12
|
+
- **`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).
|
|
13
|
+
- **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.
|
|
14
|
+
- **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.
|
|
15
|
+
|
|
16
|
+
## CLI commands
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
init scaffold a workspace
|
|
20
|
+
capture-auth cache an authed session
|
|
21
|
+
calibrate extract a flow-file from a structured guide
|
|
22
|
+
inspect discover [data-testid] locators on the live page
|
|
23
|
+
run execute flows headless; emit annotations + screenshots
|
|
24
|
+
render build the static viewer (spawns the @docsxai/viewer bin)
|
|
25
|
+
lint static checks across flow-files (R001-R010; `extraRules` injectable via `lintFlow`)
|
|
26
|
+
flow-tree visualise the `extends` graph
|
|
27
|
+
diagnose halt-context + recommendations after a halt
|
|
28
|
+
doctor environment + workspace health-check (✓/✗ + one-line fixes; no plugin code runs)
|
|
29
|
+
style init/validate style.yaml; --check scans for jargon leaks
|
|
30
|
+
zip package the doc pack for hand-off
|
|
31
|
+
baseline snapshot the doc pack (flows, prose, annotations, screenshots, locators) for drift comparison
|
|
32
|
+
diff deterministic drift report against a baseline (--fail-on warn|fail gates CI)
|
|
33
|
+
export project the doc pack to a publisher format (`export adf` — Confluence ADF; `export playwright` — Playwright specs)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`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.
|
|
37
|
+
|
|
38
|
+
`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.
|
|
39
|
+
|
|
40
|
+
`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.
|
|
41
|
+
|
|
42
|
+
`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`).
|
|
43
|
+
|
|
44
|
+
`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.
|
|
45
|
+
|
|
46
|
+
`render` locates 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.
|
|
47
|
+
|
|
48
|
+
## Auth strategies
|
|
49
|
+
|
|
50
|
+
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).
|
|
51
|
+
|
|
52
|
+
| Strategy | Scheme | Browser needed |
|
|
53
|
+
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------- |
|
|
54
|
+
| `api-login` | POST creds to the login endpoint; cookies collected across the redirect chain (own RFC-6265 jar) | no |
|
|
55
|
+
| `ui-form` | drive the app's own login form: fill, submit, success marker, snapshot; `pre_steps` dismiss pre-login chrome; `options.totp` adds an RFC-6238 hop (dep-free `generateTotp`/`verifyTotp` primitives exported) | headless |
|
|
56
|
+
| `email-otp` | `ui-form` whose code arrives by mail; an `InboxProvider` polls the inbox (`http-json` built-in: Mailpit-style `{ messages: [{to, received_at, body}] }`); `code_pattern` extracts the code (default `\b(\d{6})\b`) | headless |
|
|
57
|
+
| `webauthn` | passkey via a CDP virtual authenticator (ctap2 / internal / user-verifying), attached **before** navigation; `trigger_selector` starts the ceremony | headless |
|
|
58
|
+
| `jwt-injection` | static token (`token_env`) or OAuth2 client-credentials mint (`token_url`); injected into localStorage and/or cookies via `{{token}}` templates | no |
|
|
59
|
+
| `http-basic` | connection-level `httpCredentials` | no |
|
|
60
|
+
| `pat-header` | token header via `extraHTTPHeaders` (`value_template`, default `Bearer {{token}}`) | no |
|
|
61
|
+
| `mtls` | client certificate via `clientCertificates` (`creds_env` maps `cert`/`key` to PEM file paths) | no |
|
|
62
|
+
| `test-backdoor` | POST a shared secret to a test-only endpoint | no |
|
|
63
|
+
| `manual-capture` | instrumented Chrome; a human logs in and triggers capture | headed |
|
|
64
|
+
|
|
65
|
+
Cross-cutting contracts:
|
|
66
|
+
|
|
67
|
+
- **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.
|
|
68
|
+
- **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.
|
|
69
|
+
- **`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.
|
|
70
|
+
- **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.
|
|
71
|
+
- **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.
|
|
72
|
+
|
|
73
|
+
## Plugins
|
|
74
|
+
|
|
75
|
+
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 — and the no-model-API rule binds them exactly as it binds the engine.
|
|
76
|
+
|
|
77
|
+
### Manifest (`package.json#docsxai`)
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"name": "@docsxai/plugin-confluence",
|
|
82
|
+
"version": "0.1.0",
|
|
83
|
+
"docsxai": {
|
|
84
|
+
"apiVersion": "1.0.0",
|
|
85
|
+
"namespace": "confluence",
|
|
86
|
+
"register": "./dist/register.js",
|
|
87
|
+
"kinds": ["publisher"],
|
|
88
|
+
"capabilities": ["egress:*.atlassian.net"],
|
|
89
|
+
"dependsOn": [],
|
|
90
|
+
"trust": "kalebtec"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
- `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.
|
|
96
|
+
- `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.
|
|
97
|
+
- `kinds` — the extension points the plugin registers (≥1). Registering an undeclared kind throws and load-errors the plugin (capability-disclosure honesty).
|
|
98
|
+
- `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.
|
|
99
|
+
- `dependsOn` — `{ plugin, version }` entries (package name + `^`/`~`/exact range). Load order is topological; cycles are rejected as a unit.
|
|
100
|
+
|
|
101
|
+
### `register(api)`
|
|
102
|
+
|
|
103
|
+
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.
|
|
104
|
+
|
|
105
|
+
### Workspace config + lock
|
|
106
|
+
|
|
107
|
+
Two optional `.docsxai.json` keys wire plugins into a workspace:
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"plugins": [{ "package": "@docsxai/plugin-confluence" }, { "path": "../my-local-plugin" }],
|
|
112
|
+
"plugin_capabilities": ["egress:*.atlassian.net"]
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`plugins-lock.json` (schema `docsxai/plugins-lock@1`, next to the config) pins each plugin's register-module sha256. When it exists, every resolve verifies the bytes **before** importing; a mismatch fails closed with a "run `docsxai plugins sync`" message.
|
|
117
|
+
|
|
118
|
+
### CLI
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
docsxai plugins list <workspace> status table (loaded / disabled reasons); exit 1 if any plugin isn't loaded
|
|
122
|
+
docsxai plugins info <workspace> <namespace> manifest + registered artifact names
|
|
123
|
+
docsxai plugins sync <workspace> (re)write plugins-lock.json — never executes plugin code
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
All three accept `--format json`. Plugins are resolved once per CLI invocation — there is no hot reload. See `docs/ai-context/plugin-runtime/lifecycle-and-namespacing.md` for the full lifecycle contract.
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
[Apache-2.0](../../LICENSE).
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type AuthContext, type AuthResult, type AuthStrategy } from "./types.js";
|
|
3
|
+
export declare const ApiLoginOptions: z.ZodObject<{
|
|
4
|
+
/** Login endpoint; resolved against the target's base URL when relative. */
|
|
5
|
+
login_url: z.ZodString;
|
|
6
|
+
method: z.ZodDefault<z.ZodString>;
|
|
7
|
+
/** How the creds map is encoded into the request body. */
|
|
8
|
+
body_format: z.ZodDefault<z.ZodEnum<["json", "form"]>>;
|
|
9
|
+
/**
|
|
10
|
+
* What "logged in" means. `cookie`: the jar must contain it after the redirect chain.
|
|
11
|
+
* `status`: the final response status must equal it. `json_path`: the final JSON body at
|
|
12
|
+
* the dotted path must equal `equals`. Default: final status < 400.
|
|
13
|
+
*/
|
|
14
|
+
success_check: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
15
|
+
cookie: z.ZodString;
|
|
16
|
+
}, "strict", z.ZodTypeAny, {
|
|
17
|
+
cookie: string;
|
|
18
|
+
}, {
|
|
19
|
+
cookie: string;
|
|
20
|
+
}>, z.ZodObject<{
|
|
21
|
+
status: z.ZodNumber;
|
|
22
|
+
}, "strict", z.ZodTypeAny, {
|
|
23
|
+
status: number;
|
|
24
|
+
}, {
|
|
25
|
+
status: number;
|
|
26
|
+
}>, z.ZodObject<{
|
|
27
|
+
json_path: z.ZodString;
|
|
28
|
+
equals: z.ZodUnknown;
|
|
29
|
+
}, "strict", z.ZodTypeAny, {
|
|
30
|
+
json_path: string;
|
|
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
|
+
}>;
|
|
61
|
+
export type ApiLoginOptions = z.infer<typeof ApiLoginOptions>;
|
|
62
|
+
/** Walk a dotted path (`a.b.c`) through a parsed JSON value. */
|
|
63
|
+
export declare function getJsonPath(value: unknown, dottedPath: string): unknown;
|
|
64
|
+
export declare class ApiLoginStrategy implements AuthStrategy {
|
|
65
|
+
private readonly fetchImpl;
|
|
66
|
+
readonly name: "api-login";
|
|
67
|
+
constructor(fetchImpl?: typeof fetch);
|
|
68
|
+
authenticate(ctx: AuthContext): Promise<AuthResult>;
|
|
69
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// `api-login` — POST the role's credentials to the app's login endpoint and keep the session
|
|
2
|
+
// cookies. Pure node fetch; no browser. The strategy of choice when the target has a JSON or
|
|
3
|
+
// form login API the operator may call directly.
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { fetchCollectingCookies, jarAuthExpiry } from "./cookie-jar.js";
|
|
6
|
+
import { AuthStrategyConfigError, parseStrategyOptions, } from "./types.js";
|
|
7
|
+
export const ApiLoginOptions = z
|
|
8
|
+
.object({
|
|
9
|
+
/** Login endpoint; resolved against the target's base URL when relative. */
|
|
10
|
+
login_url: z.string().min(1),
|
|
11
|
+
method: z.string().default("POST"),
|
|
12
|
+
/** How the creds map is encoded into the request body. */
|
|
13
|
+
body_format: z.enum(["json", "form"]).default("json"),
|
|
14
|
+
/**
|
|
15
|
+
* What "logged in" means. `cookie`: the jar must contain it after the redirect chain.
|
|
16
|
+
* `status`: the final response status must equal it. `json_path`: the final JSON body at
|
|
17
|
+
* the dotted path must equal `equals`. Default: final status < 400.
|
|
18
|
+
*/
|
|
19
|
+
success_check: z
|
|
20
|
+
.union([
|
|
21
|
+
z.object({ cookie: z.string().min(1) }).strict(),
|
|
22
|
+
z.object({ status: z.number().int() }).strict(),
|
|
23
|
+
z.object({ json_path: z.string().min(1), equals: z.unknown() }).strict(),
|
|
24
|
+
])
|
|
25
|
+
.optional(),
|
|
26
|
+
})
|
|
27
|
+
.strict();
|
|
28
|
+
/** Walk a dotted path (`a.b.c`) through a parsed JSON value. */
|
|
29
|
+
export function getJsonPath(value, dottedPath) {
|
|
30
|
+
let cur = value;
|
|
31
|
+
for (const segment of dottedPath.split(".")) {
|
|
32
|
+
if (cur === null || typeof cur !== "object")
|
|
33
|
+
return undefined;
|
|
34
|
+
cur = cur[segment];
|
|
35
|
+
}
|
|
36
|
+
return cur;
|
|
37
|
+
}
|
|
38
|
+
export class ApiLoginStrategy {
|
|
39
|
+
fetchImpl;
|
|
40
|
+
name = "api-login";
|
|
41
|
+
constructor(fetchImpl = fetch) {
|
|
42
|
+
this.fetchImpl = fetchImpl;
|
|
43
|
+
}
|
|
44
|
+
async authenticate(ctx) {
|
|
45
|
+
const opts = parseStrategyOptions(this.name, ApiLoginOptions, ctx.options);
|
|
46
|
+
const url = new URL(opts.login_url, ctx.baseURL);
|
|
47
|
+
const isJson = opts.body_format === "json";
|
|
48
|
+
const body = isJson ? JSON.stringify(ctx.creds) : new URLSearchParams(ctx.creds).toString();
|
|
49
|
+
const result = await fetchCollectingCookies(url, {
|
|
50
|
+
method: opts.method,
|
|
51
|
+
headers: {
|
|
52
|
+
"content-type": isJson ? "application/json" : "application/x-www-form-urlencoded",
|
|
53
|
+
accept: "application/json, text/html;q=0.9, */*;q=0.8",
|
|
54
|
+
},
|
|
55
|
+
body,
|
|
56
|
+
}, { fetchImpl: this.fetchImpl });
|
|
57
|
+
// Failure messages name the endpoint and the check — never the credential values.
|
|
58
|
+
const check = opts.success_check;
|
|
59
|
+
if (check === undefined) {
|
|
60
|
+
if (result.status >= 400) {
|
|
61
|
+
throw new AuthStrategyConfigError(`api-login: ${url.href} answered ${result.status} — login rejected (credentials read from env; values not shown)`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if ("cookie" in check) {
|
|
65
|
+
if (!result.jar.has(check.cookie)) {
|
|
66
|
+
const got = result.jar
|
|
67
|
+
.cookies()
|
|
68
|
+
.map((c) => c.name)
|
|
69
|
+
.join(", ");
|
|
70
|
+
throw new AuthStrategyConfigError(`api-login: expected cookie "${check.cookie}" was not set by ${url.href} (status ${result.status}; jar: ${got || "(empty)"})`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if ("status" in check) {
|
|
74
|
+
if (result.status !== check.status) {
|
|
75
|
+
throw new AuthStrategyConfigError(`api-login: expected status ${check.status} from ${url.href}, got ${result.status}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
let parsed;
|
|
80
|
+
try {
|
|
81
|
+
parsed = JSON.parse(result.body);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
throw new AuthStrategyConfigError(`api-login: success_check.json_path needs a JSON response, but ${result.url} (status ${result.status}) did not return valid JSON`);
|
|
85
|
+
}
|
|
86
|
+
const actual = getJsonPath(parsed, check.json_path);
|
|
87
|
+
if (JSON.stringify(actual) !== JSON.stringify(check.equals)) {
|
|
88
|
+
throw new AuthStrategyConfigError(`api-login: success_check json_path "${check.json_path}" is ${JSON.stringify(actual)}, expected ${JSON.stringify(check.equals)}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const storageState = result.jar.toStorageState();
|
|
92
|
+
const expiresAt = jarAuthExpiry(storageState, check && "cookie" in check ? check.cookie : undefined);
|
|
93
|
+
return { storageState, ...(expiresAt !== undefined ? { expiresAt } : {}) };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type StorageState } from "./types.js";
|
|
2
|
+
export interface AuthPageOptions {
|
|
3
|
+
baseURL: string;
|
|
4
|
+
/** Accept self-signed / invalid TLS (the target's local dev cert). Default false. */
|
|
5
|
+
ignoreHTTPSErrors?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface AuthPage {
|
|
8
|
+
/** Navigate (relative URLs resolve against the launch baseURL). */
|
|
9
|
+
goto(url: string): Promise<void>;
|
|
10
|
+
fill(selector: string, value: string): Promise<void>;
|
|
11
|
+
click(selector: string): Promise<void>;
|
|
12
|
+
/** Resolve when the selector is visible; reject on timeout. */
|
|
13
|
+
waitForSelector(selector: string, opts?: {
|
|
14
|
+
timeoutMs?: number;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
/** Resolve when the page URL matches; reject on timeout. */
|
|
17
|
+
waitForUrl(pattern: RegExp, opts?: {
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
/** Attach a CDP WebAuthn virtual authenticator (ctap2 / internal / user-verifying) to the page. */
|
|
21
|
+
enableVirtualAuthenticator(): Promise<void>;
|
|
22
|
+
/** Snapshot the context's storageState. */
|
|
23
|
+
storageState(): Promise<StorageState>;
|
|
24
|
+
close(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export type AuthPageLauncher = (opts: AuthPageOptions) => Promise<AuthPage>;
|
|
27
|
+
/** Default launcher: a fresh headless Chromium context via the engine's Playwright session. */
|
|
28
|
+
export declare const launchAuthPage: AuthPageLauncher;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// The narrow page surface browser-driving auth strategies (ui-form, email-otp, webauthn) need.
|
|
2
|
+
//
|
|
3
|
+
// Mirrors the `InstrumentedBrowser` pattern: strategies depend on this interface so unit tests
|
|
4
|
+
// fake it; the Playwright-backed default launcher routes through `launchPlaywrightSession` —
|
|
5
|
+
// `playwright-driver.ts` stays the engine's one Playwright import site.
|
|
6
|
+
import { launchPlaywrightSession } from "../playwright-driver.js";
|
|
7
|
+
/** Default launcher: a fresh headless Chromium context via the engine's Playwright session. */
|
|
8
|
+
export const launchAuthPage = async (opts) => {
|
|
9
|
+
const session = await launchPlaywrightSession({
|
|
10
|
+
baseURL: opts.baseURL,
|
|
11
|
+
...(opts.ignoreHTTPSErrors ? { ignoreHTTPSErrors: true } : {}),
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
goto: async (url) => {
|
|
15
|
+
await session.page.goto(url);
|
|
16
|
+
},
|
|
17
|
+
fill: (selector, value) => session.page.fill(selector, value),
|
|
18
|
+
click: (selector) => session.page.click(selector),
|
|
19
|
+
waitForSelector: async (selector, o) => {
|
|
20
|
+
await session.page.waitForSelector(selector, {
|
|
21
|
+
state: "visible",
|
|
22
|
+
...(o?.timeoutMs !== undefined ? { timeout: o.timeoutMs } : {}),
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
waitForUrl: (pattern, o) => session.page.waitForURL(pattern, o?.timeoutMs !== undefined ? { timeout: o.timeoutMs } : {}),
|
|
26
|
+
enableVirtualAuthenticator: async () => {
|
|
27
|
+
const cdp = await session.context.newCDPSession(session.page);
|
|
28
|
+
await cdp.send("WebAuthn.enable");
|
|
29
|
+
await cdp.send("WebAuthn.addVirtualAuthenticator", {
|
|
30
|
+
options: {
|
|
31
|
+
protocol: "ctap2",
|
|
32
|
+
transport: "internal",
|
|
33
|
+
hasResidentKey: true,
|
|
34
|
+
hasUserVerification: true,
|
|
35
|
+
isUserVerified: true,
|
|
36
|
+
automaticPresenceSimulation: true,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
storageState: () => session.storageState(),
|
|
41
|
+
close: () => session.close(),
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type StorageState, type StorageStateCookie } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parse one `Set-Cookie` header into a {@link StorageStateCookie}.
|
|
4
|
+
* Domain defaults to the request host (host-only); a `Domain` attribute gets the conventional
|
|
5
|
+
* leading dot (subdomain-matching, mirroring Playwright's representation). `Max-Age` beats
|
|
6
|
+
* `Expires`; absent both, the cookie is a session cookie (`expires: -1`).
|
|
7
|
+
* Returns `null` for an unparsable header.
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseSetCookie(header: string, requestUrl: URL, now?: number): StorageStateCookie | null;
|
|
10
|
+
export declare class CookieJar {
|
|
11
|
+
private readonly store;
|
|
12
|
+
private key;
|
|
13
|
+
/** Store a cookie; an already-expired one (`Max-Age=0` deletion) removes the match instead. */
|
|
14
|
+
add(cookie: StorageStateCookie, now?: number): void;
|
|
15
|
+
/** Parse + store every `Set-Cookie` header from one response. */
|
|
16
|
+
addFromHeaders(setCookieHeaders: string[], requestUrl: URL, now?: number): void;
|
|
17
|
+
/** First stored cookie with this name, regardless of domain/path. */
|
|
18
|
+
get(name: string): StorageStateCookie | undefined;
|
|
19
|
+
has(name: string): boolean;
|
|
20
|
+
cookies(): StorageStateCookie[];
|
|
21
|
+
/** `Cookie:` header value for a request to `url` — domain/path/secure/expiry-matched. Empty string if none apply. */
|
|
22
|
+
cookieHeaderFor(url: URL, now?: number): string;
|
|
23
|
+
toStorageState(): StorageState;
|
|
24
|
+
}
|
|
25
|
+
export interface CollectingFetchInit {
|
|
26
|
+
method?: string;
|
|
27
|
+
headers?: Record<string, string>;
|
|
28
|
+
body?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface CollectingFetchResult {
|
|
31
|
+
jar: CookieJar;
|
|
32
|
+
/** Final (post-redirect) response status. */
|
|
33
|
+
status: number;
|
|
34
|
+
/** Final URL after redirects. */
|
|
35
|
+
url: string;
|
|
36
|
+
/** Final response body text. */
|
|
37
|
+
body: string;
|
|
38
|
+
/** Redirect hops followed. */
|
|
39
|
+
hops: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Fetch with `redirect: "manual"`, following up to `maxRedirects` hops (default 5) while
|
|
43
|
+
* collecting `Set-Cookie` headers into a {@link CookieJar} and replaying matching cookies on
|
|
44
|
+
* each hop. 303 — and 301/302 on a non-GET — switch the method to GET and drop the body,
|
|
45
|
+
* matching browser behaviour.
|
|
46
|
+
*/
|
|
47
|
+
export declare function fetchCollectingCookies(url: string | URL, init?: CollectingFetchInit, opts?: {
|
|
48
|
+
maxRedirects?: number;
|
|
49
|
+
jar?: CookieJar;
|
|
50
|
+
fetchImpl?: typeof fetch;
|
|
51
|
+
now?: () => number;
|
|
52
|
+
}): Promise<CollectingFetchResult>;
|
|
53
|
+
/**
|
|
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 — only when the jar has exactly one real-expiry
|
|
56
|
+
* cookie — that one. Ambiguous jars report `undefined` (the cache's `ttl` takes over).
|
|
57
|
+
*/
|
|
58
|
+
export declare function jarAuthExpiry(state: StorageState, preferredCookie?: string): number | undefined;
|