@uptimizr/sdk-core 1.0.1 → 1.1.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/AGENTS.md CHANGED
@@ -58,6 +58,10 @@ Engine adapters are just collectors that translate engine events into `@uptimizr
58
58
  - Respect privacy: never set or persist a client identifier; honor `disabled` / Do-Not-Track.
59
59
  - Use `beforeSend` for filtering/redaction; use a custom `transport` for delivery changes.
60
60
  - New instrumentation = a new collector, not a core modification.
61
+ - `registerRegions(sceneId, regions, { endpoint, apiKey })` declares a scene's named regions
62
+ (the scene registry, not capture). It **replaces** the scene's set and is an authenticated
63
+ write needing an **`annotate`**-capable key (a `query`-only key gets `403`) — never emit the
64
+ API key into a public bundle; call it from build/deploy/admin code.
61
65
 
62
66
  ## Key options
63
67
 
package/README.md CHANGED
@@ -78,6 +78,39 @@ invalid payload can never succeed and would block later flushes) — and `false`
78
78
  failures (network error, 5xx, 408, 429), which the client re-queues. Provide your own via the `transport` option to integrate a
79
79
  different delivery mechanism.
80
80
 
81
+ ## Registering scene regions
82
+
83
+ `registerRegions(sceneId, regions, options)` declares the named places inside a scene — the
84
+ authoring counterpart to a connector's `scanSceneProxy`. A region is a labelled world-space box
85
+ (`{ id, label, bounds: [minX,minY,minZ,maxX,maxY,maxZ], description? }`); once registered, any
86
+ spatial query can be drilled into it by name with `?region=<id>`, and summaries can answer "the
87
+ checkout counter" instead of a voxel centre.
88
+
89
+ ```ts
90
+ import { registerRegions } from "@uptimizr/sdk-core";
91
+
92
+ await registerRegions(
93
+ "lobby",
94
+ [
95
+ { id: "entrance", label: "Entrance", bounds: [-5, 0, -5, 5, 3, 0] },
96
+ { id: "counter", label: "Checkout counter", bounds: [-1, 0, 1, 1, 2, 3] },
97
+ ],
98
+ { endpoint: "https://collect.example.com", apiKey: process.env.UPTIMIZR_API_KEY! },
99
+ );
100
+ ```
101
+
102
+ The call **replaces** the scene's whole set (leaving a region out removes it; `[]` clears them)
103
+ and validates locally before sending, so a bad box fails with a precise message.
104
+
105
+ > **Security.** Unlike event capture — which is deliberately keyless — this is an authenticated
106
+ > write that sends a project API key as `x-api-key`, exactly like the scene-proxy upload. The
107
+ > key must hold the **`annotate`** capability — mint one with
108
+ > `uptimizr new-key <projectId> --capabilities annotate` (or `query,annotate` if the same key
109
+ > reads the regions back); a `query`-only key is refused with `403`. Never
110
+ > bake that key into a public production bundle: call `registerRegions` from a build/deploy
111
+ > script, a server-side route, an internal admin tool, or a developer-only path. It is a one-off
112
+ > authoring step, not a per-page-load call.
113
+
81
114
  ## Offloading work to a Web Worker
82
115
 
83
116
  Capture (reading your 3D scene) always runs on the main thread, but the **processing** that
package/dist/index.d.ts CHANGED
@@ -9,6 +9,8 @@ export { EventQueue } from "./queue.js";
9
9
  export { createBeaconTransport } from "./transport.js";
10
10
  export { createMainProcessor, createWorkerProcessor, collectTransferables } from "./processor.js";
11
11
  export { randomId } from "./idgen.js";
12
+ export { registerRegions } from "./regions.js";
13
+ export type { RegisterRegionsOptions } from "./regions.js";
12
14
  export { SDK_VERSION } from "./version.js";
13
15
  export { resolveCadence } from "./sampling.js";
14
16
  export { classifyCameraGesture, DEFAULT_GESTURE_THRESHOLDS } from "./gesture.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CA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AAc,GACf,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACnG,OAAO,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnF,YAAY,EAAE,eAAe,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAE1F,YAAY,EACV,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ export { EventQueue } from "./queue.js";
9
9
  export { createBeaconTransport } from "./transport.js";
10
10
  export { createMainProcessor, createWorkerProcessor, collectTransferables } from "./processor.js";
11
11
  export { randomId } from "./idgen.js";
12
+ export { registerRegions } from "./regions.js";
12
13
  export { SDK_VERSION } from "./version.js";
13
14
  export { resolveCadence } from "./sampling.js";
14
15
  export { classifyCameraGesture, DEFAULT_GESTURE_THRESHOLDS } from "./gesture.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC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OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AACjF,OAAO,EACL,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,aAAa,EACb,sBAAsB,EACtB,SAAS,EACT,SAAS,EACT,SAAS,EACT,aAAa,EACb,mBAAmB,EACnB,OAAO,GACR,MAAM,wBAAwB,CAAC;AAmBhC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,EACvB,wBAAwB,EACxB,mBAAmB,EACnB,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,0BAA0B,CAAC;AAgClC,OAAO,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,71 @@
1
+ import type { SceneRegion } from "@uptimizr/schema";
2
+ /**
3
+ * Scene-region registration (ADR 0051 §2 / sketch §B.2) — the authoring
4
+ * counterpart to a connector's `scanSceneProxy`.
5
+ *
6
+ * A scene proxy tells Uptimizr what a scene *looks* like; regions tell it what
7
+ * the places in that scene are *called*. Declaring
8
+ * `[{ id: "entrance", label: "Entrance", bounds: [...] }]` lets every spatial
9
+ * query be drilled by name (`?region=entrance`) and lets summaries and agents
10
+ * answer in words instead of coordinates.
11
+ *
12
+ * ## Security — this is an authenticated write, unlike event capture
13
+ *
14
+ * Event capture is deliberately keyless: `navigator.sendBeacon` cannot attach
15
+ * secret headers, so the public `projectId` is the only credential (ADR 0003).
16
+ * The scene registry is the opposite — like the existing
17
+ * `PUT /scenes/:id/representation` proxy upload, it authenticates with a project
18
+ * **API key** sent as `x-api-key`. That key must therefore NOT be baked into a
19
+ * public production bundle. Call `registerRegions` from a build/deploy script,
20
+ * an internal admin tool, a server-side route, or a developer-only path in your
21
+ * app (the Uptimizr playground registers from its dev UI for exactly this
22
+ * reason). It is a one-off authoring step, not something to run per page load.
23
+ *
24
+ * The key needs the **`annotate`** capability — the dedicated metadata-write
25
+ * capability (ADR 0051 §5/§7), not `query`. Mint one with
26
+ * `uptimizr new-key <projectId> --capabilities annotate`, or
27
+ * `--capabilities query,annotate` if the same key also reads the regions back.
28
+ */
29
+ /** Transport/auth settings for a scene-registry write. */
30
+ export interface RegisterRegionsOptions {
31
+ /**
32
+ * Collector base URL — the same `endpoint` the capture client is configured
33
+ * with, with or without a trailing slash (e.g. `"http://localhost:4318"`).
34
+ */
35
+ endpoint: string;
36
+ /**
37
+ * Project API key, sent as `x-api-key`. It must hold the `annotate`
38
+ * capability. See the security note above: never ship this in a public
39
+ * bundle.
40
+ */
41
+ apiKey: string;
42
+ /** `fetch` implementation to use. Defaults to the global `fetch`. */
43
+ fetchImpl?: typeof fetch;
44
+ /** Abort signal, so a caller can cancel or time out the request. */
45
+ signal?: AbortSignal;
46
+ }
47
+ /**
48
+ * Declare `sceneId`'s regions, **replacing** whatever the registry holds for
49
+ * that scene — the call states what the scene's regions are, so removing one is
50
+ * leaving it out and `[]` clears them. Idempotent: registering the same set
51
+ * twice is a no-op in effect.
52
+ *
53
+ * Validates against `sceneRegionsSchema` before sending, so a bad box or a
54
+ * duplicate id fails locally with a precise message instead of a bare `400`.
55
+ * Rejects when the collector refuses the write (the error message carries the
56
+ * status and the response body, truncated).
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * await registerRegions(
61
+ * "lobby",
62
+ * [
63
+ * { id: "entrance", label: "Entrance", bounds: [-5, 0, -5, 5, 3, 0] },
64
+ * { id: "counter", label: "Checkout counter", bounds: [-1, 0, 1, 1, 2, 3] },
65
+ * ],
66
+ * { endpoint: "http://localhost:4318", apiKey: process.env.UPTIMIZR_API_KEY! },
67
+ * );
68
+ * ```
69
+ */
70
+ export declare function registerRegions(sceneId: string, regions: readonly SceneRegion[], options: RegisterRegionsOptions): Promise<void>;
71
+ //# sourceMappingURL=regions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regions.d.ts","sourceRoot":"","sources":["../src/regions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,0DAA0D;AAC1D,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,oEAAoE;IACpE,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,SAAS,WAAW,EAAE,EAC/B,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,IAAI,CAAC,CA2Bf"}
@@ -0,0 +1,52 @@
1
+ import { sceneRegionsSchema } from "@uptimizr/schema";
2
+ /**
3
+ * Declare `sceneId`'s regions, **replacing** whatever the registry holds for
4
+ * that scene — the call states what the scene's regions are, so removing one is
5
+ * leaving it out and `[]` clears them. Idempotent: registering the same set
6
+ * twice is a no-op in effect.
7
+ *
8
+ * Validates against `sceneRegionsSchema` before sending, so a bad box or a
9
+ * duplicate id fails locally with a precise message instead of a bare `400`.
10
+ * Rejects when the collector refuses the write (the error message carries the
11
+ * status and the response body, truncated).
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * await registerRegions(
16
+ * "lobby",
17
+ * [
18
+ * { id: "entrance", label: "Entrance", bounds: [-5, 0, -5, 5, 3, 0] },
19
+ * { id: "counter", label: "Checkout counter", bounds: [-1, 0, 1, 1, 2, 3] },
20
+ * ],
21
+ * { endpoint: "http://localhost:4318", apiKey: process.env.UPTIMIZR_API_KEY! },
22
+ * );
23
+ * ```
24
+ */
25
+ export async function registerRegions(sceneId, regions, options) {
26
+ const parsed = sceneRegionsSchema.parse(regions);
27
+ const doFetch = options.fetchImpl ?? globalThis.fetch;
28
+ if (typeof doFetch !== "function") {
29
+ throw new Error("registerRegions needs a fetch implementation (pass options.fetchImpl).");
30
+ }
31
+ // Trim trailing slashes with a loop rather than a `/\/+$/` regex: the greedy
32
+ // quantifier backtracks from every position, so an endpoint of many slashes
33
+ // costs quadratic time (CodeQL `js/polynomial-redos`). This is linear.
34
+ let base = options.endpoint;
35
+ while (base.endsWith("/"))
36
+ base = base.slice(0, -1);
37
+ const url = `${base}/api/v1/scenes/${encodeURIComponent(sceneId)}/regions`;
38
+ const response = await doFetch(url, {
39
+ method: "PUT",
40
+ headers: { "content-type": "application/json", "x-api-key": options.apiKey },
41
+ body: JSON.stringify({ regions: parsed }),
42
+ signal: options.signal,
43
+ });
44
+ if (!response.ok) {
45
+ // Surface the collector's own validation message; cap it so a stray HTML
46
+ // error page cannot flood the console.
47
+ const body = await response.text().catch(() => "");
48
+ throw new Error(`Uptimizr region registration failed for scene "${sceneId}" ` +
49
+ `(${response.status})${body ? `: ${body.slice(0, 300)}` : ""}`);
50
+ }
51
+ }
52
+ //# sourceMappingURL=regions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regions.js","sourceRoot":"","sources":["../src/regions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAkDtD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAAe,EACf,OAA+B,EAC/B,OAA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,CAAC,EAAE,EAAE,CACjE,CAAC;IACJ,CAAC;AACH,CAAC"}
package/llms.txt CHANGED
@@ -14,3 +14,6 @@
14
14
 
15
15
  - `UptimizrClient` — create, `start()`, `track(name, props)`, `use(collector)`, `stop()`.
16
16
  - `Collector` / `Transport` types — the extension points.
17
+ - `registerRegions(sceneId, regions, { endpoint, apiKey })` — declare a scene's named regions
18
+ in the scene registry (an authenticated write needing an `annotate`-capable key; keep the
19
+ API key out of public bundles).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uptimizr/sdk-core",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Framework-agnostic Uptimizr capture runtime — session, batching, cookieless transport, and a pluggable collector system.",
5
5
  "keywords": [
6
6
  "uptimizr",
@@ -46,7 +46,7 @@
46
46
  ],
47
47
  "sideEffects": false,
48
48
  "dependencies": {
49
- "@uptimizr/schema": "1.0.1"
49
+ "@uptimizr/schema": "1.1.0"
50
50
  },
51
51
  "devDependencies": {
52
52
  "vitest": "^4.1.11"