@botim/mp-debug-sdk 0.7.1 → 0.8.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/README.md CHANGED
@@ -13,14 +13,14 @@ Mini-programs run on user devices in environments you can't easily attach a debu
13
13
 
14
14
  ## Install
15
15
 
16
- > **Heads-up registry override required in BOTIM repos.**
17
- > Most BOTIM mini-program repos pin the `@botim` scope to the internal Artifactory mirror (`@botim:registry=https://artifactory.corp.algento.com/artifactory/api/npm/bot-npm/`). This SDK is **published to public npm**, so a plain `npm install @botim/mp-debug-sdk` in those repos will hit Artifactory, not find the package, and 404. Use the public registry explicitly for this one package:
16
+ > **If your project's `.npmrc` pins the `@botim` scope to a private registry, override it for this package.**
17
+ > This SDK is published to public npm. If your `.npmrc` contains a line like `@botim:registry=<private-mirror-url>`, plain `npm install @botim/mp-debug-sdk` will route to the private mirror, not find the package, and fail. Use:
18
18
 
19
19
  ```bash
20
20
  npm install @botim/mp-debug-sdk --registry=https://registry.npmjs.org/
21
21
  ```
22
22
 
23
- If your repo doesn't have an `@botim` scope override (rare), the flag is harmless — npm uses `registry.npmjs.org` by default. **Don't** add `@botim:registry=https://registry.npmjs.org/` to your `.npmrc`: it would shadow the internal Artifactory registry that other `@botim/*` packages (mp-framework, etc.) need.
23
+ If your repo has no `@botim` scope override, the flag is harmless — npm uses `registry.npmjs.org` by default. Don't permanently re-pin the `@botim` scope to public npm in your `.npmrc`: it would shadow whatever private registry your other `@botim/*` packages come from.
24
24
 
25
25
  ## 1. Add the env config files
26
26
 
@@ -100,7 +100,14 @@ import { botimConfig } from 'virtual:botim/config';
100
100
  const handle = await enableRemoteDebug({
101
101
  // The relay URL the plugin baked in. Falls back to same-origin if you
102
102
  // didn't pass `relayUrl` to the plugin (e.g. you're using a dev proxy).
103
+ // For a gateway-hosted relay this is the gateway origin (optionally with a
104
+ // path prefix), e.g. 'https://proxy-uat-ae.botim.me/botim-cli-gateway'.
103
105
  endpoint: botimConfig.relayUrl ?? location.origin,
106
+ // Relay connect token (rdt_…). REQUIRED for gateway-hosted relays, which
107
+ // gate attach on `Authorization: Bearer rdt_…`. Mint one bound to this
108
+ // (mpId, env) with `botim-cli relay token --mp <id> --env uat` (24 h TTL).
109
+ // Omit for the legacy standalone relay, which ignores it.
110
+ token: import.meta.env.VITE_RELAY_TOKEN,
104
111
  config: botimConfig,
105
112
  // app is optional — plugin auto-fills from app_id + version in
106
113
  // botim.{env}.json. Override only when you want a different name/version
@@ -127,7 +134,7 @@ That's it — `console.*`, network calls, and uncaught errors now stream to the
127
134
 
128
135
  ### Cross-origin setup
129
136
 
130
- The SDK posts directly to `endpoint` — there's no proxy required. Your relay must allow the page's origin via CORS. The reference [`@botim/debug-relay`](https://github.com/botim/debug-relay) ships with `CORS_ORIGINS=*` by default; tighten via env when going to production:
137
+ The SDK posts directly to `endpoint` — there's no proxy required. Your relay must allow the page's origin via CORS. A reference debug-relay implementation typically defaults to `CORS_ORIGINS=*` for development; tighten via env when going to production:
131
138
 
132
139
  ```bash
133
140
  CORS_ORIGINS=https://my-mp.example.com,https://staging.example.com
@@ -139,7 +146,7 @@ Once `enableRemoteDebug` returns, an attached agent can send a JS snippet to the
139
146
 
140
147
  ```bash
141
148
  # From any terminal that can reach your relay:
142
- curl -sX POST "https://debug.botim.dev/v1/mp/<MP_ID>/devices/<DEVICE_ID>/commands" \
149
+ curl -sX POST "<RELAY_URL>/v1/mp/<MP_ID>/devices/<DEVICE_ID>/commands" \
143
150
  -H 'content-type: application/json' \
144
151
  -d '{"name":"exec","args":{"code":"console.log(\"hi\"); return window.location.href"}}'
145
152
  ```
@@ -222,7 +229,7 @@ console.log(handle.sid); // server-issued session id
222
229
 
223
230
  ## Debugging a live mini-program
224
231
 
225
- Once your build is wired and shipped, see **[`docs/live-debugging.md`](./docs/live-debugging.md)** for the end-to-end runbook against the shared demo relay at `https://aistudiodemo.ext.algento.com/mp-debug-relay`. It covers:
232
+ Once your build is wired and shipped, see **[`docs/live-debugging.md`](./docs/live-debugging.md)** for the end-to-end runbook against your debug-relay deployment. It covers:
226
233
 
227
234
  - pointing the Vite plugin at the live relay URL,
228
235
  - pulling errors and tailing sessions from the admin UI,
@@ -255,3 +262,4 @@ cp -r .claude/skills/botim-debug-relay ~/.claude/skills/
255
262
  ## License
256
263
 
257
264
  [ISC](./LICENSE) © BOTIM
265
+
package/dist/index.cjs CHANGED
@@ -440,7 +440,7 @@ function sleep(ms) {
440
440
  }
441
441
 
442
442
  // src/attach.ts
443
- async function attachDevice(endpoint, config, deviceInfo, consent) {
443
+ async function attachDevice(endpoint, config, deviceInfo, consent, token) {
444
444
  const base = endpoint.replace(/\/$/, "");
445
445
  const url = `${base}/v1/attach`;
446
446
  const body = {
@@ -451,9 +451,11 @@ async function attachDevice(endpoint, config, deviceInfo, consent) {
451
451
  consent,
452
452
  schemaVersion: SCHEMA_VERSION
453
453
  };
454
+ const headers = { "Content-Type": "application/json" };
455
+ if (token) headers.Authorization = `Bearer ${token}`;
454
456
  const res = await fetch(url, {
455
457
  method: "POST",
456
- headers: { "Content-Type": "application/json" },
458
+ headers,
457
459
  body: JSON.stringify(body)
458
460
  });
459
461
  if (!res.ok) {
@@ -1645,7 +1647,7 @@ async function enableRemoteDebug(options) {
1645
1647
  };
1646
1648
  const deviceInfo = detectDeviceInfo(app, options.device);
1647
1649
  const consent = options.consent ?? {};
1648
- const session = await attachDevice(options.endpoint, options.config, deviceInfo, consent);
1650
+ const session = await attachDevice(options.endpoint, options.config, deviceInfo, consent, options.token);
1649
1651
  const buffer = new RingBuffer({
1650
1652
  capacity: options.bufferSize ?? DEFAULT_BUFFER_SIZE
1651
1653
  });