@botim/mp-debug-sdk 1.0.0 → 1.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.
@@ -247,6 +247,41 @@ export const botimConfig = Object.freeze(${JSON.stringify(resolved)});
247
247
  export default botimConfig;
248
248
  `;
249
249
  return { code: body, map: null };
250
+ },
251
+ // Enable relay debugging from vite.config alone: when `relayToken` is set,
252
+ // inject an `enableRemoteDebug(...)` bootstrap into index.html. This hook
253
+ // runs in BOTH dev (`serve`) and `build`, so the same call ships to the
254
+ // built/deployed bundle. App source is never touched; removing the option
255
+ // (or the plugin) removes the injection.
256
+ transformIndexHtml: {
257
+ order: "pre",
258
+ handler() {
259
+ const token = options.relayToken;
260
+ if (typeof token !== "string" || token.length === 0) return void 0;
261
+ if (!resolved) return void 0;
262
+ const endpoint = (options.relayUrl ?? resolved.relayUrl ?? "").replace(/\/+$/, "");
263
+ if (!endpoint) {
264
+ console.warn(
265
+ "[@botim/debug-sdk:vite] relayToken set but no relayUrl \u2014 debug bootstrap NOT injected (pass relayUrl)."
266
+ );
267
+ return void 0;
268
+ }
269
+ const debugOptions = {
270
+ endpoint,
271
+ token,
272
+ config: { miniProgramId: resolved.miniProgramId, env: resolved.env },
273
+ consent: { userOptIn: true }
274
+ };
275
+ return [
276
+ {
277
+ tag: "script",
278
+ attrs: { type: "module" },
279
+ children: `import { enableRemoteDebug } from '@botim/mp-debug-sdk';
280
+ enableRemoteDebug(${JSON.stringify(debugOptions)}).catch(() => {});`,
281
+ injectTo: "head-prepend"
282
+ }
283
+ ];
284
+ }
250
285
  }
251
286
  };
252
287
  }
@@ -197,6 +197,15 @@ interface BotimDebugPluginOptions {
197
197
  * shallow-merged so patching `app.md5` keeps `app.version` from the file.
198
198
  */
199
199
  config?: InlineBotimConfigInput;
200
+ /**
201
+ * Relay token (rdt_…) from `botim-cli relay token --appId <id> --env <env>`.
202
+ * When set, the plugin injects an `enableRemoteDebug(...)` bootstrap into
203
+ * index.html (runs in BOTH dev and build) so relay debugging is enabled purely
204
+ * from vite.config — no app-source changes. Remove this option (or the plugin)
205
+ * to disable. Rotating 24h secret: pass via env (e.g. `relayToken: env.VITE_RELAY_TOKEN`),
206
+ * don't commit it. Gate to non-prod yourself by only passing it for the builds you want.
207
+ */
208
+ relayToken?: string;
200
209
  }
201
210
  declare function botimDebug(options?: BotimDebugPluginOptions): Plugin;
202
211
 
@@ -197,6 +197,15 @@ interface BotimDebugPluginOptions {
197
197
  * shallow-merged so patching `app.md5` keeps `app.version` from the file.
198
198
  */
199
199
  config?: InlineBotimConfigInput;
200
+ /**
201
+ * Relay token (rdt_…) from `botim-cli relay token --appId <id> --env <env>`.
202
+ * When set, the plugin injects an `enableRemoteDebug(...)` bootstrap into
203
+ * index.html (runs in BOTH dev and build) so relay debugging is enabled purely
204
+ * from vite.config — no app-source changes. Remove this option (or the plugin)
205
+ * to disable. Rotating 24h secret: pass via env (e.g. `relayToken: env.VITE_RELAY_TOKEN`),
206
+ * don't commit it. Gate to non-prod yourself by only passing it for the builds you want.
207
+ */
208
+ relayToken?: string;
200
209
  }
201
210
  declare function botimDebug(options?: BotimDebugPluginOptions): Plugin;
202
211
 
@@ -219,6 +219,41 @@ export const botimConfig = Object.freeze(${JSON.stringify(resolved)});
219
219
  export default botimConfig;
220
220
  `;
221
221
  return { code: body, map: null };
222
+ },
223
+ // Enable relay debugging from vite.config alone: when `relayToken` is set,
224
+ // inject an `enableRemoteDebug(...)` bootstrap into index.html. This hook
225
+ // runs in BOTH dev (`serve`) and `build`, so the same call ships to the
226
+ // built/deployed bundle. App source is never touched; removing the option
227
+ // (or the plugin) removes the injection.
228
+ transformIndexHtml: {
229
+ order: "pre",
230
+ handler() {
231
+ const token = options.relayToken;
232
+ if (typeof token !== "string" || token.length === 0) return void 0;
233
+ if (!resolved) return void 0;
234
+ const endpoint = (options.relayUrl ?? resolved.relayUrl ?? "").replace(/\/+$/, "");
235
+ if (!endpoint) {
236
+ console.warn(
237
+ "[@botim/debug-sdk:vite] relayToken set but no relayUrl \u2014 debug bootstrap NOT injected (pass relayUrl)."
238
+ );
239
+ return void 0;
240
+ }
241
+ const debugOptions = {
242
+ endpoint,
243
+ token,
244
+ config: { miniProgramId: resolved.miniProgramId, env: resolved.env },
245
+ consent: { userOptIn: true }
246
+ };
247
+ return [
248
+ {
249
+ tag: "script",
250
+ attrs: { type: "module" },
251
+ children: `import { enableRemoteDebug } from '@botim/mp-debug-sdk';
252
+ enableRemoteDebug(${JSON.stringify(debugOptions)}).catch(() => {});`,
253
+ injectTo: "head-prepend"
254
+ }
255
+ ];
256
+ }
222
257
  }
223
258
  };
224
259
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botim/mp-debug-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Remote-debug SDK for BOTIM mini-programs — streams console, network, and error events to a BOTIM debug-relay for live inspection, with an AI-observable command channel.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",