@osqd/bothandlerjs 0.3.0 → 0.5.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +157 -1
  2. package/README.md +1 -1
  3. package/dist/challenge/index.d.ts +18 -0
  4. package/dist/challenge/interaction.d.ts +215 -0
  5. package/dist/challenge/page.d.ts +18 -0
  6. package/dist/cli.cjs +829 -71
  7. package/dist/cli.cjs.map +1 -1
  8. package/dist/cli.js +829 -71
  9. package/dist/cli.js.map +1 -1
  10. package/dist/config.d.ts +10 -0
  11. package/dist/core.d.ts +15 -0
  12. package/dist/corpus/index.cjs +20 -0
  13. package/dist/corpus/index.cjs.map +1 -1
  14. package/dist/corpus/index.js +20 -0
  15. package/dist/corpus/index.js.map +1 -1
  16. package/dist/dashboard/client/actions.d.ts +17 -0
  17. package/dist/dashboard/client/actor.d.ts +5 -0
  18. package/dist/dashboard/client/api.d.ts +15 -0
  19. package/dist/dashboard/client/app.d.ts +37 -0
  20. package/dist/dashboard/client/bars.d.ts +4 -0
  21. package/dist/dashboard/client/boot.d.ts +5 -0
  22. package/dist/dashboard/client/charts.d.ts +25 -0
  23. package/dist/dashboard/client/css.d.ts +11 -0
  24. package/dist/dashboard/client/dom.d.ts +55 -0
  25. package/dist/dashboard/client/draft.d.ts +46 -0
  26. package/dist/dashboard/client/feed.d.ts +22 -0
  27. package/dist/dashboard/client/format.d.ts +37 -0
  28. package/dist/dashboard/client/guard.d.ts +3 -0
  29. package/dist/dashboard/client/index.d.ts +1 -0
  30. package/dist/dashboard/client/outcome.d.ts +33 -0
  31. package/dist/dashboard/client/pager.d.ts +32 -0
  32. package/dist/dashboard/client/panels.d.ts +40 -0
  33. package/dist/dashboard/client/policy.d.ts +25 -0
  34. package/dist/dashboard/client/query.d.ts +42 -0
  35. package/dist/dashboard/client/ranges.d.ts +2 -0
  36. package/dist/dashboard/client/registry.d.ts +4 -0
  37. package/dist/dashboard/client/replay.d.ts +14 -0
  38. package/dist/dashboard/client/result.d.ts +10 -0
  39. package/dist/dashboard/client/store.d.ts +128 -0
  40. package/dist/dashboard/client/stream.d.ts +14 -0
  41. package/dist/dashboard/client/tester.d.ts +1 -0
  42. package/dist/dashboard/client/types.d.ts +69 -0
  43. package/dist/dashboard/client.generated.d.ts +1 -1
  44. package/dist/dashboard/page.d.ts +25 -0
  45. package/dist/dashboard/sections.d.ts +92 -0
  46. package/dist/dashboard/types.d.ts +2 -82
  47. package/dist/detectors/crawler-verification.d.ts +34 -1
  48. package/dist/detectors/index.d.ts +4 -1
  49. package/dist/detectors/known-bots.d.ts +49 -1
  50. package/dist/element/config.d.ts +135 -0
  51. package/dist/element/index.cjs +5150 -0
  52. package/dist/element/index.cjs.map +1 -0
  53. package/dist/element/index.d.ts +137 -0
  54. package/dist/element/index.js +5131 -0
  55. package/dist/element/index.js.map +1 -0
  56. package/dist/index.cjs +820 -71
  57. package/dist/index.cjs.map +1 -1
  58. package/dist/index.d.ts +2 -0
  59. package/dist/index.js +811 -71
  60. package/dist/index.js.map +1 -1
  61. package/dist/metrics.d.ts +27 -0
  62. package/dist/policy/index.d.ts +1 -1
  63. package/dist/policy/presets.d.ts +47 -0
  64. package/dist/state.d.ts +1 -1
  65. package/docs/challenge/index.md +1 -0
  66. package/docs/challenge/interaction.md +325 -0
  67. package/docs/course/11-the-challenge.md +36 -1
  68. package/docs/course/13-operating-it.md +20 -2
  69. package/docs/detection/signatures.md +36 -0
  70. package/docs/index.md +2 -0
  71. package/docs/operations/dashboard.md +28 -0
  72. package/docs/operations/embedding.md +348 -0
  73. package/docs/operations/index.md +1 -0
  74. package/docs/policy/presets.md +53 -0
  75. package/docs/start/choosing-a-policy.md +1 -0
  76. package/package.json +8 -3
@@ -0,0 +1,137 @@
1
+ /**
2
+ * `<bot-dashboard>` — the operator dashboard as an element you drop into your own page.
3
+ *
4
+ * ```html
5
+ * <bot-dashboard src="/_bots"></bot-dashboard>
6
+ * <script type="module">
7
+ * import { defineBotDashboard } from "@osqd/bothandlerjs/element";
8
+ * defineBotDashboard();
9
+ * </script>
10
+ * ```
11
+ *
12
+ * The data still comes from a mounted handler — `createDashboardHandler(botHandler, {
13
+ * basePath: "/_bots" })` — because there is nowhere else for it to come from. What the
14
+ * element removes is having to build, style and route a page around it.
15
+ *
16
+ * ## What running it in your page costs you
17
+ *
18
+ * This renders into a shadow root inside your document, which is what makes it sit in
19
+ * your layout rather than in a frame. The shadow root is a styling boundary and **not a
20
+ * security boundary**: any script that can run on the host page can reach into it, read
21
+ * every visitor address and verdict on screen, and call the dashboard's API with your
22
+ * credentials. On the standalone page an injected script in your application could do
23
+ * none of that.
24
+ *
25
+ * So mount it on a page that is already behind your admin authentication, and treat an
26
+ * XSS on that page as equivalent to handing over the dashboard. If you would rather have
27
+ * the isolation than the layout, serve the standalone page instead — it is the same
28
+ * dashboard, and `createDashboardHandler` already returns it.
29
+ */
30
+ import type { BotDashboardConfig, BotDashboardPanel, BotDashboardRows, BotDashboardTab, BotDashboardTabId, BotDashboardTheme } from "./config.js";
31
+ /** One screen of the dashboard. */
32
+ export type { BotDashboardConfig, BotDashboardPanel, BotDashboardRows, BotDashboardTab, BotDashboardTabId, BotDashboardTheme };
33
+ /**
34
+ * Registers `<bot-dashboard>`. Safe to call more than once.
35
+ *
36
+ * @param name - element name, if `bot-dashboard` is taken.
37
+ */
38
+ export declare function defineBotDashboard(name?: string): void;
39
+ /**
40
+ * `HTMLElement`, or a stand-in where there is no DOM.
41
+ *
42
+ * `class X extends HTMLElement` is evaluated when the module is *loaded*, not when the
43
+ * element is used — so on a server, where there is no `HTMLElement`, merely importing this
44
+ * file threw `ReferenceError` before a line of anyone's code ran. That is not an exotic
45
+ * case: it is what every framework with server rendering does with a top-level
46
+ * `import { defineBotDashboard } from "@osqd/bothandlerjs/element"`, which is exactly the
47
+ * line the documentation tells people to write.
48
+ *
49
+ * `defineBotDashboard` already declines to do anything without a `customElements`
50
+ * registry, so the intent was there; the class declaration simply ran first. With this the
51
+ * module imports anywhere, and does nothing at all until it is in a browser.
52
+ */
53
+ declare const ElementBase: typeof HTMLElement;
54
+ export declare class BotDashboardElement extends ElementBase {
55
+ private settings;
56
+ private booted;
57
+ /**
58
+ * Booted *and* finished drawing. Distinct from `booted`, which is set on the way in:
59
+ * `connectedCallback` replays a config assigned before the upgrade through the setter,
60
+ * and at that moment `booted` is already true — so a warning keyed on it fired on a
61
+ * perfectly ordinary mount, complaining that the config had changed when what had
62
+ * happened was that it had arrived.
63
+ */
64
+ private rendered;
65
+ /**
66
+ * Set before the element is attached, or pass the same things as attributes.
67
+ *
68
+ * An accessor rather than a field, and the difference is load-bearing. A page that
69
+ * writes `el.config = {...}` before the element is defined puts an *own property* on
70
+ * the instance, and a class field initialiser then runs at upgrade and overwrites it —
71
+ * so the configuration silently disappears and the dashboard renders its defaults. The
72
+ * accessor plus the upgrade dance in `connectedCallback` is the documented way round
73
+ * it, and the order it protects (write the config, then define the element) is the
74
+ * natural one to write.
75
+ */
76
+ get config(): BotDashboardConfig;
77
+ set config(value: BotDashboardConfig);
78
+ private timers;
79
+ /** Custom properties this element put on itself, so it can take them off again. */
80
+ private appliedTokens;
81
+ private warned;
82
+ static get observedAttributes(): string[];
83
+ connectedCallback(): void;
84
+ disconnectedCallback(): void;
85
+ attributeChangedCallback(attribute: string, previous: string | null, value: string | null): void;
86
+ /**
87
+ * Give up on this attempt without giving up on the element.
88
+ *
89
+ * Every way a boot can end early — it lost the one-at-a-time race, its `src` is
90
+ * cross-origin, its handler did not answer, it was unmounted mid-flight — is about this
91
+ * moment rather than about this element, and all four are things a remount can fix: the
92
+ * other dashboard has gone, the attribute was corrected, the server finished starting.
93
+ * Releasing ownership without clearing `booted` was the bug: `connectedCallback` returns
94
+ * early on a latched `booted`, so the element stayed dead for the life of the instance
95
+ * and a router that remounts it drew a stale error over a handler that now works.
96
+ */
97
+ private standDown;
98
+ /**
99
+ * Where the handler is mounted, from `config.src` or the attribute.
100
+ *
101
+ * A trailing slash is dropped, and so are a query string and a fragment — the element
102
+ * appends `/api/bootstrap` to this, so anything after the path cannot survive that
103
+ * concatenation and never could. Left in, `src="/_bots?token=x"` failed with "it
104
+ * answered text/html — is createDashboardHandler mounted at /_bots?token=x?", which
105
+ * sends somebody to check the one thing that was right.
106
+ */
107
+ private mountPath;
108
+ private boot;
109
+ private applyTheme;
110
+ /**
111
+ * `scheme` and `density` take two values each, and until now anything else was accepted
112
+ * in silence — a mis-typed `scheme` did nothing, and a mis-typed `density` was written
113
+ * onto the element as `data-density="cozy"`, matching no rule and looking, from the
114
+ * outside, exactly like a dashboard that ignores its configuration.
115
+ *
116
+ * Warned once per bad value per element, because `applyTheme` runs on every re-render
117
+ * and a typo that repeats a hundred times is a typo the console has stopped conveying.
118
+ */
119
+ private applyScheme;
120
+ private applyDensity;
121
+ private warnOnce;
122
+ /**
123
+ * Reorders and relabels the strip the client has just drawn.
124
+ *
125
+ * Only the tabs that survived: which screens *exist* was settled in the boot object
126
+ * before the client ran, because the client builds its list from there and looks each
127
+ * one up by id — deleting an element here instead crashed it with "no element
128
+ * #tab-actors", which is what this comment is standing in for.
129
+ */
130
+ private relabelTabs;
131
+ private renderPanels;
132
+ }
133
+ declare global {
134
+ interface HTMLElementTagNameMap {
135
+ "bot-dashboard": BotDashboardElement;
136
+ }
137
+ }