@biterra/challenge-wrapper 1.0.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 ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Biterra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # Biterra challenge wrapper
2
+
3
+ Open-source browser presence telemetry and a Docker parent image for HTTP challenges. Presence is approximate operational analytics, not a billing or security measurement.
4
+
5
+ ```dockerfile
6
+ FROM ghcr.io/biterra-co/challenge-wrapper-python:1.0.0
7
+ WORKDIR /app
8
+ COPY . .
9
+ ENV BITERRA_UPSTREAM_PORT=3000
10
+ CMD ["python", "app.py"]
11
+ ```
12
+
13
+ The inherited entrypoint launches the child `CMD`, listens on port 8080, proxies to the private upstream port, and injects the same-origin browser client into HTML. WebSockets and non-HTML traffic pass through unchanged.
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@biterra/challenge-wrapper",
3
+ "version": "1.0.0",
4
+ "description": "Biterra challenge presence wrapper",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/biterra-co/challenge-wrapper.git"
8
+ },
9
+ "license": "MIT",
10
+ "type": "module",
11
+ "exports": { ".": "./src/browser.js" },
12
+ "files": ["src/browser.js"],
13
+ "scripts": { "test": "node --test", "build": "go build ./cmd/wrapper" },
14
+ "publishConfig": { "access": "public" }
15
+ }
package/src/browser.js ADDED
@@ -0,0 +1,46 @@
1
+ const ENDPOINT = "/__biterra__/presence";
2
+ const HEARTBEAT_MS = 15_000;
3
+
4
+ async function report(action, keepalive = false) {
5
+ try {
6
+ await fetch(ENDPOINT, {
7
+ method: "POST",
8
+ credentials: "include",
9
+ headers: { "content-type": "application/json" },
10
+ body: JSON.stringify({ action }),
11
+ keepalive,
12
+ });
13
+ } catch {
14
+ // Presence telemetry must never interfere with the challenge.
15
+ }
16
+ }
17
+
18
+ export const open = () => report("open");
19
+ export const heartbeat = () => report("heartbeat");
20
+ export function close() {
21
+ const body = JSON.stringify({ action: "close" });
22
+ try {
23
+ if (navigator.sendBeacon?.(ENDPOINT, new Blob([body], { type: "application/json" }))) return;
24
+ } catch {}
25
+ void report("close", true);
26
+ }
27
+
28
+ export function autoStart() {
29
+ let timer;
30
+ const stop = () => { if (timer) clearInterval(timer); timer = undefined; };
31
+ const start = () => {
32
+ stop();
33
+ if (document.visibilityState !== "visible") return;
34
+ void open();
35
+ timer = setInterval(() => { if (document.visibilityState === "visible") void heartbeat(); }, HEARTBEAT_MS);
36
+ };
37
+ document.addEventListener("visibilitychange", () => {
38
+ if (document.visibilityState === "visible") start();
39
+ else { stop(); close(); }
40
+ });
41
+ addEventListener("pagehide", () => { stop(); close(); });
42
+ start();
43
+ return stop;
44
+ }
45
+
46
+ if (typeof document !== "undefined" && document.currentScript?.dataset.autostart !== "false") autoStart();