@botim/mp-debug-sdk 0.7.2 → 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/dist/auto.cjs +1874 -0
- package/dist/auto.d.cts +2 -0
- package/dist/auto.d.ts +2 -0
- package/dist/auto.js +1857 -0
- package/dist/index.cjs +32 -12
- package/dist/index.d.cts +21 -17
- package/dist/index.d.ts +21 -17
- package/dist/index.js +32 -13
- package/dist/vite/plugin.cjs +63 -29
- package/dist/vite/plugin.d.cts +7 -6
- package/dist/vite/plugin.d.ts +7 -6
- package/dist/vite/plugin.js +64 -30
- package/dist/vite/virtual-shim.d.ts +3 -3
- package/package.json +20 -7
- package/README.md +0 -258
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.cjs.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/vite/plugin.cjs.map +0 -1
- package/dist/vite/plugin.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -264,7 +264,7 @@ var RingBuffer = class {
|
|
|
264
264
|
// src/transport.ts
|
|
265
265
|
var DEFAULT_MAX_RETRIES = 3;
|
|
266
266
|
var DEFAULT_POLL_TIMEOUT_MS = 25e3;
|
|
267
|
-
var DEFAULT_MIN_BACKOFF_MS =
|
|
267
|
+
var DEFAULT_MIN_BACKOFF_MS = 2e3;
|
|
268
268
|
var DEFAULT_MAX_BACKOFF_MS = 3e4;
|
|
269
269
|
var Transport = class {
|
|
270
270
|
constructor(opts) {
|
|
@@ -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
|
|
458
|
+
headers,
|
|
457
459
|
body: JSON.stringify(body)
|
|
458
460
|
});
|
|
459
461
|
if (!res.ok) {
|
|
@@ -1570,7 +1572,7 @@ var DEFAULT_BODY_PATTERNS = [
|
|
|
1570
1572
|
/[A-Za-z0-9_-]{40,}/g
|
|
1571
1573
|
];
|
|
1572
1574
|
var DEFAULT_MAX_BODY_BYTES = 4096;
|
|
1573
|
-
var DEFAULT_FLUSH_INTERVAL_MS =
|
|
1575
|
+
var DEFAULT_FLUSH_INTERVAL_MS = 4e3;
|
|
1574
1576
|
var DEFAULT_BUFFER_SIZE = 1e3;
|
|
1575
1577
|
var DEFAULT_MAX_BATCH_SIZE = 50;
|
|
1576
1578
|
var NOOP_HANDLE = {
|
|
@@ -1585,6 +1587,10 @@ var NOOP_HANDLE = {
|
|
|
1585
1587
|
return false;
|
|
1586
1588
|
}
|
|
1587
1589
|
};
|
|
1590
|
+
var defaultBotimConfig = null;
|
|
1591
|
+
function setDefaultBotimConfig(config) {
|
|
1592
|
+
defaultBotimConfig = config;
|
|
1593
|
+
}
|
|
1588
1594
|
function assertConsent(config, consent) {
|
|
1589
1595
|
if (config.env !== "prod") return;
|
|
1590
1596
|
const hasHostToken = typeof consent?.hostToken === "string" && consent.hostToken.length > 0;
|
|
@@ -1597,7 +1603,7 @@ function assertConsent(config, consent) {
|
|
|
1597
1603
|
function assertConfig(config) {
|
|
1598
1604
|
if (!config || typeof config !== "object") {
|
|
1599
1605
|
throw new BotimConfigError(
|
|
1600
|
-
'
|
|
1606
|
+
'config is required \u2014 pass options.config, or register a default via "@botim/mp-debug-sdk/auto"',
|
|
1601
1607
|
{ code: "config-missing" }
|
|
1602
1608
|
);
|
|
1603
1609
|
}
|
|
@@ -1615,18 +1621,31 @@ function assertConfig(config) {
|
|
|
1615
1621
|
}
|
|
1616
1622
|
async function enableRemoteDebug(options) {
|
|
1617
1623
|
if (options.enabled === false) return NOOP_HANDLE;
|
|
1618
|
-
|
|
1624
|
+
if (!options.endpoint || typeof options.endpoint !== "string") {
|
|
1625
|
+
throw new BotimConfigError(
|
|
1626
|
+
'relay server URL is required \u2014 pass options.endpoint (e.g. "https://relay.example.com")',
|
|
1627
|
+
{ code: "endpoint-missing" }
|
|
1628
|
+
);
|
|
1629
|
+
}
|
|
1630
|
+
const resolvedConfig = options.config ?? defaultBotimConfig;
|
|
1631
|
+
if (!resolvedConfig) {
|
|
1632
|
+
throw new BotimConfigError(
|
|
1633
|
+
'no config provided and no default registered \u2014 import { enableRemoteDebug } from "@botim/mp-debug-sdk/auto" (Vite), or pass options.config',
|
|
1634
|
+
{ code: "config-missing" }
|
|
1635
|
+
);
|
|
1636
|
+
}
|
|
1637
|
+
assertConfig(resolvedConfig);
|
|
1619
1638
|
const consentInput = options.consent ?? {};
|
|
1620
1639
|
const hasExplicitConsent = consentInput.userOptIn === true || typeof consentInput.hostToken === "string" && consentInput.hostToken.length > 0;
|
|
1621
1640
|
const promptDisabled = consentInput.promptUser === false;
|
|
1622
1641
|
const canPrompt = typeof document !== "undefined" && typeof window !== "undefined";
|
|
1623
1642
|
const shouldPrompt = !hasExplicitConsent && !promptDisabled && canPrompt;
|
|
1624
1643
|
if (shouldPrompt) {
|
|
1625
|
-
const cached = readConsentDecision(
|
|
1644
|
+
const cached = readConsentDecision(resolvedConfig.miniProgramId);
|
|
1626
1645
|
let decision = cached;
|
|
1627
1646
|
if (decision === null) {
|
|
1628
1647
|
decision = await promptForConsent(
|
|
1629
|
-
|
|
1648
|
+
resolvedConfig.miniProgramId,
|
|
1630
1649
|
consentInput.promptCopy
|
|
1631
1650
|
);
|
|
1632
1651
|
}
|
|
@@ -1636,16 +1655,16 @@ async function enableRemoteDebug(options) {
|
|
|
1636
1655
|
consent: { ...consentInput, userOptIn: true }
|
|
1637
1656
|
};
|
|
1638
1657
|
}
|
|
1639
|
-
assertConsent(
|
|
1658
|
+
assertConsent(resolvedConfig, options.consent);
|
|
1640
1659
|
const onError = options.onError ?? (() => {
|
|
1641
1660
|
});
|
|
1642
1661
|
const app = options.app ?? {
|
|
1643
|
-
name:
|
|
1644
|
-
version:
|
|
1662
|
+
name: resolvedConfig.appName ?? resolvedConfig.miniProgramId,
|
|
1663
|
+
version: resolvedConfig.appVersion ?? "0.0.0"
|
|
1645
1664
|
};
|
|
1646
1665
|
const deviceInfo = detectDeviceInfo(app, options.device);
|
|
1647
1666
|
const consent = options.consent ?? {};
|
|
1648
|
-
const session = await attachDevice(options.endpoint,
|
|
1667
|
+
const session = await attachDevice(options.endpoint, resolvedConfig, deviceInfo, consent, options.token);
|
|
1649
1668
|
const buffer = new RingBuffer({
|
|
1650
1669
|
capacity: options.bufferSize ?? DEFAULT_BUFFER_SIZE
|
|
1651
1670
|
});
|
|
@@ -1843,6 +1862,7 @@ exports.enableRemoteDebug = enableRemoteDebug;
|
|
|
1843
1862
|
exports.getBOT = getBOT;
|
|
1844
1863
|
exports.promptForConsent = promptForConsent;
|
|
1845
1864
|
exports.readConsentDecision = readConsentDecision;
|
|
1865
|
+
exports.setDefaultBotimConfig = setDefaultBotimConfig;
|
|
1846
1866
|
exports.writeConsentDecision = writeConsentDecision;
|
|
1847
1867
|
//# sourceMappingURL=index.cjs.map
|
|
1848
1868
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
|
@@ -230,6 +230,12 @@ interface RemoteDebugOptions {
|
|
|
230
230
|
enabled?: boolean;
|
|
231
231
|
/** Relay base URL — your debug-relay deployment (e.g. "https://relay.example.com"). */
|
|
232
232
|
endpoint: string;
|
|
233
|
+
/**
|
|
234
|
+
* Relay connect token (rdt_…) minted with `botim-cli relay token --mp <id>`.
|
|
235
|
+
* REQUIRED when the relay is hosted by botim-gateway (token-gated attach);
|
|
236
|
+
* ignored by legacy standalone relays.
|
|
237
|
+
*/
|
|
238
|
+
token?: string;
|
|
233
239
|
/**
|
|
234
240
|
* Optional override for the app identity reported in events. When omitted
|
|
235
241
|
* the SDK falls back to `config.appName` / `config.appVersion` resolved by
|
|
@@ -237,11 +243,12 @@ interface RemoteDebugOptions {
|
|
|
237
243
|
*/
|
|
238
244
|
app?: AppInfo;
|
|
239
245
|
/**
|
|
240
|
-
* Build-time-resolved mini-program identity.
|
|
241
|
-
*
|
|
242
|
-
* `@botim/debug-sdk/
|
|
246
|
+
* Build-time-resolved mini-program identity. Optional: when omitted, the SDK
|
|
247
|
+
* uses the config registered via `setDefaultBotimConfig` — which the
|
|
248
|
+
* `@botim/mp-debug-sdk/auto` entry sets from `virtual:botim/config`. Pass it
|
|
249
|
+
* explicitly to override.
|
|
243
250
|
*/
|
|
244
|
-
config
|
|
251
|
+
config?: BotimConfig;
|
|
245
252
|
/**
|
|
246
253
|
* Consent for telemetry. Required in `prod`; implicit in non-prod builds.
|
|
247
254
|
*/
|
|
@@ -281,21 +288,18 @@ declare const DEFAULT_MAX_BODY_BYTES = 4096;
|
|
|
281
288
|
/**
|
|
282
289
|
* How often the transport drains the buffer to the relay.
|
|
283
290
|
*
|
|
284
|
-
*
|
|
285
|
-
* realtime one.
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
* The timer fully drains the buffer per tick (multiple POSTs back-to-back if
|
|
291
|
-
* needed, each capped at maxBatchSize), so the only cost of the longer
|
|
292
|
-
* interval is up to 8s of potential delay before an event reaches the relay.
|
|
293
|
-
*
|
|
294
|
-
* Hosts can opt for tighter latency by setting `flushIntervalMs` explicitly.
|
|
291
|
+
* 4 seconds balances latency against chattiness — this is a debug telemetry
|
|
292
|
+
* channel, not a realtime one. A much tighter cadence would make a busy session
|
|
293
|
+
* (~10 events/sec) fire many ingest POSTs/sec for little human-visible gain
|
|
294
|
+
* (admins poll at ~2s). The timer fully drains the buffer per tick (back-to-back
|
|
295
|
+
* POSTs, each capped at maxBatchSize), so the only cost is up to ~4s of delay
|
|
296
|
+
* before an event reaches the relay. Hosts can set `flushIntervalMs` to tune it.
|
|
295
297
|
*/
|
|
296
|
-
declare const DEFAULT_FLUSH_INTERVAL_MS =
|
|
298
|
+
declare const DEFAULT_FLUSH_INTERVAL_MS = 4000;
|
|
297
299
|
declare const DEFAULT_BUFFER_SIZE = 1000;
|
|
298
300
|
declare const DEFAULT_MAX_BATCH_SIZE = 50;
|
|
301
|
+
/** Register (or, with null, clear) the default BotimConfig used when `enableRemoteDebug` gets no `config`. */
|
|
302
|
+
declare function setDefaultBotimConfig(config: BotimConfig | null): void;
|
|
299
303
|
declare function enableRemoteDebug(options: RemoteDebugOptions): Promise<RemoteDebugHandle>;
|
|
300
304
|
|
|
301
|
-
export { type AppInfo, BotimConfig, BotimConfigError, BotimConsentError, type BuiltinHostHooks, CommandHandler, type ConsentDecision, ConsentInput, ConsentPromptCopy, ConsolePayload, DEFAULT_BODY_PATTERNS, DEFAULT_BUFFER_SIZE, DEFAULT_FLUSH_INTERVAL_MS, DEFAULT_MAX_BATCH_SIZE, DEFAULT_MAX_BODY_BYTES, DEFAULT_REDACT_HEADERS, type DedupOptions, DeviceInfo, ErrorPayload, EventLevel, EventType, type ExecOptions, NetworkPayload, type RedactionConfig, type RemoteDebugHandle, type RemoteDebugOptions, type SamplingConfig, type SuppressionSummary, clearConsentDecision, enableRemoteDebug, getBOT, promptForConsent, readConsentDecision, writeConsentDecision };
|
|
305
|
+
export { type AppInfo, BotimConfig, BotimConfigError, BotimConsentError, type BuiltinHostHooks, CommandHandler, type ConsentDecision, ConsentInput, ConsentPromptCopy, ConsolePayload, DEFAULT_BODY_PATTERNS, DEFAULT_BUFFER_SIZE, DEFAULT_FLUSH_INTERVAL_MS, DEFAULT_MAX_BATCH_SIZE, DEFAULT_MAX_BODY_BYTES, DEFAULT_REDACT_HEADERS, type DedupOptions, DeviceInfo, ErrorPayload, EventLevel, EventType, type ExecOptions, NetworkPayload, type RedactionConfig, type RemoteDebugHandle, type RemoteDebugOptions, type SamplingConfig, type SuppressionSummary, clearConsentDecision, enableRemoteDebug, getBOT, promptForConsent, readConsentDecision, setDefaultBotimConfig, writeConsentDecision };
|
package/dist/index.d.ts
CHANGED
|
@@ -230,6 +230,12 @@ interface RemoteDebugOptions {
|
|
|
230
230
|
enabled?: boolean;
|
|
231
231
|
/** Relay base URL — your debug-relay deployment (e.g. "https://relay.example.com"). */
|
|
232
232
|
endpoint: string;
|
|
233
|
+
/**
|
|
234
|
+
* Relay connect token (rdt_…) minted with `botim-cli relay token --mp <id>`.
|
|
235
|
+
* REQUIRED when the relay is hosted by botim-gateway (token-gated attach);
|
|
236
|
+
* ignored by legacy standalone relays.
|
|
237
|
+
*/
|
|
238
|
+
token?: string;
|
|
233
239
|
/**
|
|
234
240
|
* Optional override for the app identity reported in events. When omitted
|
|
235
241
|
* the SDK falls back to `config.appName` / `config.appVersion` resolved by
|
|
@@ -237,11 +243,12 @@ interface RemoteDebugOptions {
|
|
|
237
243
|
*/
|
|
238
244
|
app?: AppInfo;
|
|
239
245
|
/**
|
|
240
|
-
* Build-time-resolved mini-program identity.
|
|
241
|
-
*
|
|
242
|
-
* `@botim/debug-sdk/
|
|
246
|
+
* Build-time-resolved mini-program identity. Optional: when omitted, the SDK
|
|
247
|
+
* uses the config registered via `setDefaultBotimConfig` — which the
|
|
248
|
+
* `@botim/mp-debug-sdk/auto` entry sets from `virtual:botim/config`. Pass it
|
|
249
|
+
* explicitly to override.
|
|
243
250
|
*/
|
|
244
|
-
config
|
|
251
|
+
config?: BotimConfig;
|
|
245
252
|
/**
|
|
246
253
|
* Consent for telemetry. Required in `prod`; implicit in non-prod builds.
|
|
247
254
|
*/
|
|
@@ -281,21 +288,18 @@ declare const DEFAULT_MAX_BODY_BYTES = 4096;
|
|
|
281
288
|
/**
|
|
282
289
|
* How often the transport drains the buffer to the relay.
|
|
283
290
|
*
|
|
284
|
-
*
|
|
285
|
-
* realtime one.
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
* The timer fully drains the buffer per tick (multiple POSTs back-to-back if
|
|
291
|
-
* needed, each capped at maxBatchSize), so the only cost of the longer
|
|
292
|
-
* interval is up to 8s of potential delay before an event reaches the relay.
|
|
293
|
-
*
|
|
294
|
-
* Hosts can opt for tighter latency by setting `flushIntervalMs` explicitly.
|
|
291
|
+
* 4 seconds balances latency against chattiness — this is a debug telemetry
|
|
292
|
+
* channel, not a realtime one. A much tighter cadence would make a busy session
|
|
293
|
+
* (~10 events/sec) fire many ingest POSTs/sec for little human-visible gain
|
|
294
|
+
* (admins poll at ~2s). The timer fully drains the buffer per tick (back-to-back
|
|
295
|
+
* POSTs, each capped at maxBatchSize), so the only cost is up to ~4s of delay
|
|
296
|
+
* before an event reaches the relay. Hosts can set `flushIntervalMs` to tune it.
|
|
295
297
|
*/
|
|
296
|
-
declare const DEFAULT_FLUSH_INTERVAL_MS =
|
|
298
|
+
declare const DEFAULT_FLUSH_INTERVAL_MS = 4000;
|
|
297
299
|
declare const DEFAULT_BUFFER_SIZE = 1000;
|
|
298
300
|
declare const DEFAULT_MAX_BATCH_SIZE = 50;
|
|
301
|
+
/** Register (or, with null, clear) the default BotimConfig used when `enableRemoteDebug` gets no `config`. */
|
|
302
|
+
declare function setDefaultBotimConfig(config: BotimConfig | null): void;
|
|
299
303
|
declare function enableRemoteDebug(options: RemoteDebugOptions): Promise<RemoteDebugHandle>;
|
|
300
304
|
|
|
301
|
-
export { type AppInfo, BotimConfig, BotimConfigError, BotimConsentError, type BuiltinHostHooks, CommandHandler, type ConsentDecision, ConsentInput, ConsentPromptCopy, ConsolePayload, DEFAULT_BODY_PATTERNS, DEFAULT_BUFFER_SIZE, DEFAULT_FLUSH_INTERVAL_MS, DEFAULT_MAX_BATCH_SIZE, DEFAULT_MAX_BODY_BYTES, DEFAULT_REDACT_HEADERS, type DedupOptions, DeviceInfo, ErrorPayload, EventLevel, EventType, type ExecOptions, NetworkPayload, type RedactionConfig, type RemoteDebugHandle, type RemoteDebugOptions, type SamplingConfig, type SuppressionSummary, clearConsentDecision, enableRemoteDebug, getBOT, promptForConsent, readConsentDecision, writeConsentDecision };
|
|
305
|
+
export { type AppInfo, BotimConfig, BotimConfigError, BotimConsentError, type BuiltinHostHooks, CommandHandler, type ConsentDecision, ConsentInput, ConsentPromptCopy, ConsolePayload, DEFAULT_BODY_PATTERNS, DEFAULT_BUFFER_SIZE, DEFAULT_FLUSH_INTERVAL_MS, DEFAULT_MAX_BATCH_SIZE, DEFAULT_MAX_BODY_BYTES, DEFAULT_REDACT_HEADERS, type DedupOptions, DeviceInfo, ErrorPayload, EventLevel, EventType, type ExecOptions, NetworkPayload, type RedactionConfig, type RemoteDebugHandle, type RemoteDebugOptions, type SamplingConfig, type SuppressionSummary, clearConsentDecision, enableRemoteDebug, getBOT, promptForConsent, readConsentDecision, setDefaultBotimConfig, writeConsentDecision };
|
package/dist/index.js
CHANGED
|
@@ -262,7 +262,7 @@ var RingBuffer = class {
|
|
|
262
262
|
// src/transport.ts
|
|
263
263
|
var DEFAULT_MAX_RETRIES = 3;
|
|
264
264
|
var DEFAULT_POLL_TIMEOUT_MS = 25e3;
|
|
265
|
-
var DEFAULT_MIN_BACKOFF_MS =
|
|
265
|
+
var DEFAULT_MIN_BACKOFF_MS = 2e3;
|
|
266
266
|
var DEFAULT_MAX_BACKOFF_MS = 3e4;
|
|
267
267
|
var Transport = class {
|
|
268
268
|
constructor(opts) {
|
|
@@ -438,7 +438,7 @@ function sleep(ms) {
|
|
|
438
438
|
}
|
|
439
439
|
|
|
440
440
|
// src/attach.ts
|
|
441
|
-
async function attachDevice(endpoint, config, deviceInfo, consent) {
|
|
441
|
+
async function attachDevice(endpoint, config, deviceInfo, consent, token) {
|
|
442
442
|
const base = endpoint.replace(/\/$/, "");
|
|
443
443
|
const url = `${base}/v1/attach`;
|
|
444
444
|
const body = {
|
|
@@ -449,9 +449,11 @@ async function attachDevice(endpoint, config, deviceInfo, consent) {
|
|
|
449
449
|
consent,
|
|
450
450
|
schemaVersion: SCHEMA_VERSION
|
|
451
451
|
};
|
|
452
|
+
const headers = { "Content-Type": "application/json" };
|
|
453
|
+
if (token) headers.Authorization = `Bearer ${token}`;
|
|
452
454
|
const res = await fetch(url, {
|
|
453
455
|
method: "POST",
|
|
454
|
-
headers
|
|
456
|
+
headers,
|
|
455
457
|
body: JSON.stringify(body)
|
|
456
458
|
});
|
|
457
459
|
if (!res.ok) {
|
|
@@ -1568,7 +1570,7 @@ var DEFAULT_BODY_PATTERNS = [
|
|
|
1568
1570
|
/[A-Za-z0-9_-]{40,}/g
|
|
1569
1571
|
];
|
|
1570
1572
|
var DEFAULT_MAX_BODY_BYTES = 4096;
|
|
1571
|
-
var DEFAULT_FLUSH_INTERVAL_MS =
|
|
1573
|
+
var DEFAULT_FLUSH_INTERVAL_MS = 4e3;
|
|
1572
1574
|
var DEFAULT_BUFFER_SIZE = 1e3;
|
|
1573
1575
|
var DEFAULT_MAX_BATCH_SIZE = 50;
|
|
1574
1576
|
var NOOP_HANDLE = {
|
|
@@ -1583,6 +1585,10 @@ var NOOP_HANDLE = {
|
|
|
1583
1585
|
return false;
|
|
1584
1586
|
}
|
|
1585
1587
|
};
|
|
1588
|
+
var defaultBotimConfig = null;
|
|
1589
|
+
function setDefaultBotimConfig(config) {
|
|
1590
|
+
defaultBotimConfig = config;
|
|
1591
|
+
}
|
|
1586
1592
|
function assertConsent(config, consent) {
|
|
1587
1593
|
if (config.env !== "prod") return;
|
|
1588
1594
|
const hasHostToken = typeof consent?.hostToken === "string" && consent.hostToken.length > 0;
|
|
@@ -1595,7 +1601,7 @@ function assertConsent(config, consent) {
|
|
|
1595
1601
|
function assertConfig(config) {
|
|
1596
1602
|
if (!config || typeof config !== "object") {
|
|
1597
1603
|
throw new BotimConfigError(
|
|
1598
|
-
'
|
|
1604
|
+
'config is required \u2014 pass options.config, or register a default via "@botim/mp-debug-sdk/auto"',
|
|
1599
1605
|
{ code: "config-missing" }
|
|
1600
1606
|
);
|
|
1601
1607
|
}
|
|
@@ -1613,18 +1619,31 @@ function assertConfig(config) {
|
|
|
1613
1619
|
}
|
|
1614
1620
|
async function enableRemoteDebug(options) {
|
|
1615
1621
|
if (options.enabled === false) return NOOP_HANDLE;
|
|
1616
|
-
|
|
1622
|
+
if (!options.endpoint || typeof options.endpoint !== "string") {
|
|
1623
|
+
throw new BotimConfigError(
|
|
1624
|
+
'relay server URL is required \u2014 pass options.endpoint (e.g. "https://relay.example.com")',
|
|
1625
|
+
{ code: "endpoint-missing" }
|
|
1626
|
+
);
|
|
1627
|
+
}
|
|
1628
|
+
const resolvedConfig = options.config ?? defaultBotimConfig;
|
|
1629
|
+
if (!resolvedConfig) {
|
|
1630
|
+
throw new BotimConfigError(
|
|
1631
|
+
'no config provided and no default registered \u2014 import { enableRemoteDebug } from "@botim/mp-debug-sdk/auto" (Vite), or pass options.config',
|
|
1632
|
+
{ code: "config-missing" }
|
|
1633
|
+
);
|
|
1634
|
+
}
|
|
1635
|
+
assertConfig(resolvedConfig);
|
|
1617
1636
|
const consentInput = options.consent ?? {};
|
|
1618
1637
|
const hasExplicitConsent = consentInput.userOptIn === true || typeof consentInput.hostToken === "string" && consentInput.hostToken.length > 0;
|
|
1619
1638
|
const promptDisabled = consentInput.promptUser === false;
|
|
1620
1639
|
const canPrompt = typeof document !== "undefined" && typeof window !== "undefined";
|
|
1621
1640
|
const shouldPrompt = !hasExplicitConsent && !promptDisabled && canPrompt;
|
|
1622
1641
|
if (shouldPrompt) {
|
|
1623
|
-
const cached = readConsentDecision(
|
|
1642
|
+
const cached = readConsentDecision(resolvedConfig.miniProgramId);
|
|
1624
1643
|
let decision = cached;
|
|
1625
1644
|
if (decision === null) {
|
|
1626
1645
|
decision = await promptForConsent(
|
|
1627
|
-
|
|
1646
|
+
resolvedConfig.miniProgramId,
|
|
1628
1647
|
consentInput.promptCopy
|
|
1629
1648
|
);
|
|
1630
1649
|
}
|
|
@@ -1634,16 +1653,16 @@ async function enableRemoteDebug(options) {
|
|
|
1634
1653
|
consent: { ...consentInput, userOptIn: true }
|
|
1635
1654
|
};
|
|
1636
1655
|
}
|
|
1637
|
-
assertConsent(
|
|
1656
|
+
assertConsent(resolvedConfig, options.consent);
|
|
1638
1657
|
const onError = options.onError ?? (() => {
|
|
1639
1658
|
});
|
|
1640
1659
|
const app = options.app ?? {
|
|
1641
|
-
name:
|
|
1642
|
-
version:
|
|
1660
|
+
name: resolvedConfig.appName ?? resolvedConfig.miniProgramId,
|
|
1661
|
+
version: resolvedConfig.appVersion ?? "0.0.0"
|
|
1643
1662
|
};
|
|
1644
1663
|
const deviceInfo = detectDeviceInfo(app, options.device);
|
|
1645
1664
|
const consent = options.consent ?? {};
|
|
1646
|
-
const session = await attachDevice(options.endpoint,
|
|
1665
|
+
const session = await attachDevice(options.endpoint, resolvedConfig, deviceInfo, consent, options.token);
|
|
1647
1666
|
const buffer = new RingBuffer({
|
|
1648
1667
|
capacity: options.bufferSize ?? DEFAULT_BUFFER_SIZE
|
|
1649
1668
|
});
|
|
@@ -1827,6 +1846,6 @@ async function enableRemoteDebug(options) {
|
|
|
1827
1846
|
};
|
|
1828
1847
|
}
|
|
1829
1848
|
|
|
1830
|
-
export { BotimConfigError, BotimConsentError, DEFAULT_BODY_PATTERNS, DEFAULT_BUFFER_SIZE, DEFAULT_FLUSH_INTERVAL_MS, DEFAULT_MAX_BATCH_SIZE, DEFAULT_MAX_BODY_BYTES, DEFAULT_REDACT_HEADERS, SCHEMA_VERSION, clearConsentDecision, enableRemoteDebug, getBOT, promptForConsent, readConsentDecision, writeConsentDecision };
|
|
1849
|
+
export { BotimConfigError, BotimConsentError, DEFAULT_BODY_PATTERNS, DEFAULT_BUFFER_SIZE, DEFAULT_FLUSH_INTERVAL_MS, DEFAULT_MAX_BATCH_SIZE, DEFAULT_MAX_BODY_BYTES, DEFAULT_REDACT_HEADERS, SCHEMA_VERSION, clearConsentDecision, enableRemoteDebug, getBOT, promptForConsent, readConsentDecision, setDefaultBotimConfig, writeConsentDecision };
|
|
1831
1850
|
//# sourceMappingURL=index.js.map
|
|
1832
1851
|
//# sourceMappingURL=index.js.map
|
package/dist/vite/plugin.cjs
CHANGED
|
@@ -44,7 +44,7 @@ var BotimConfigError = class extends Error {
|
|
|
44
44
|
|
|
45
45
|
// src/vite/resolve-config.ts
|
|
46
46
|
var VALID_ENVS = ["dev", "uat", "beta", "prod"];
|
|
47
|
-
var ID_PATTERN = /^[a-z][a-z0-
|
|
47
|
+
var ID_PATTERN = /^[a-z][a-z0-9._-]{1,127}$/i;
|
|
48
48
|
function defaultMapMode(mode) {
|
|
49
49
|
if (mode === "development") return "dev";
|
|
50
50
|
if (mode === "production") return "prod";
|
|
@@ -66,30 +66,44 @@ function resolveBotimConfig(mode, root, opts = {}) {
|
|
|
66
66
|
}
|
|
67
67
|
const env = mapped;
|
|
68
68
|
const projectRoot = (0, import_node_path.isAbsolute)(root) ? root : (0, import_node_path.resolve)(process.cwd(), root);
|
|
69
|
-
const
|
|
70
|
-
const
|
|
69
|
+
const explicit = opts.configFileName !== void 0;
|
|
70
|
+
const candidates = explicit ? [
|
|
71
|
+
{
|
|
72
|
+
env,
|
|
73
|
+
path: (() => {
|
|
74
|
+
const fileName = resolveFileName(opts.configFileName, env, mode);
|
|
75
|
+
return (0, import_node_path.isAbsolute)(fileName) ? fileName : (0, import_node_path.resolve)(projectRoot, fileName);
|
|
76
|
+
})()
|
|
77
|
+
}
|
|
78
|
+
] : buildCandidatePaths(projectRoot, env);
|
|
71
79
|
const inline = opts.inlineConfig;
|
|
72
|
-
const inlineHasIdentity = typeof inline?.
|
|
80
|
+
const inlineHasIdentity = typeof inline?.app_id === "string" && inline.app_id.length > 0 || typeof inline?.miniProgramId === "string" && inline.miniProgramId.length > 0;
|
|
81
|
+
const source = candidates.find((c) => (0, import_node_fs.existsSync)(c.path));
|
|
73
82
|
let raw;
|
|
74
83
|
let parsedFromFile = {};
|
|
75
|
-
if (
|
|
76
|
-
raw = (0, import_node_fs.readFileSync)(
|
|
84
|
+
if (source) {
|
|
85
|
+
raw = (0, import_node_fs.readFileSync)(source.path, "utf8");
|
|
77
86
|
try {
|
|
78
87
|
parsedFromFile = JSON.parse(raw);
|
|
79
88
|
} catch (err) {
|
|
80
89
|
const detail = err instanceof Error ? err.message : String(err);
|
|
81
|
-
throw new BotimConfigError(`failed to parse JSON in ${
|
|
90
|
+
throw new BotimConfigError(`failed to parse JSON in ${source.path}: ${detail}`, {
|
|
82
91
|
code: "config-invalid-json",
|
|
83
|
-
path:
|
|
92
|
+
path: source.path
|
|
84
93
|
});
|
|
85
94
|
}
|
|
86
|
-
|
|
95
|
+
if (source.env !== env) {
|
|
96
|
+
console.warn(
|
|
97
|
+
`[@botim/debug-sdk] no config for env "${env}"; borrowed app_id from ${(0, import_node_path.basename)(source.path)} (env stays ${env})`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
} else if (explicit && !inlineHasIdentity) {
|
|
101
|
+
const wanted = candidates[0].path;
|
|
87
102
|
throw new BotimConfigError(
|
|
88
|
-
`expected config file not found: ${
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
{ code: "config-missing", path: filePath }
|
|
103
|
+
`expected config file not found: ${wanted}
|
|
104
|
+
Create it with at least { "app_id": "..." }, pass { configFileName },
|
|
105
|
+
or supply inlineConfig with app_id.`,
|
|
106
|
+
{ code: "config-missing", path: wanted }
|
|
93
107
|
);
|
|
94
108
|
}
|
|
95
109
|
const parsed = {
|
|
@@ -103,22 +117,28 @@ function resolveBotimConfig(mode, root, opts = {}) {
|
|
|
103
117
|
parsed.package_url = { ...parsedFromFile.package_url, ...inline?.package_url };
|
|
104
118
|
}
|
|
105
119
|
if (parsed.deleted === 1) {
|
|
120
|
+
const label = source?.path ?? "inlineConfig";
|
|
106
121
|
throw new BotimConfigError(
|
|
107
|
-
`${
|
|
108
|
-
{ code: "config-deleted", path:
|
|
122
|
+
`${label} reports the mini-program as deleted (deleted: 1). Cannot ship debug SDK against a retired mini-program.`,
|
|
123
|
+
{ code: "config-deleted", path: source?.path }
|
|
109
124
|
);
|
|
110
125
|
}
|
|
111
|
-
const idValue = parsed.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
126
|
+
const idValue = parsed.app_id ?? parsed.miniProgramId;
|
|
127
|
+
let miniProgramId;
|
|
128
|
+
if (typeof idValue === "string" && idValue.length > 0) {
|
|
129
|
+
if (!ID_PATTERN.test(idValue)) {
|
|
130
|
+
const label = source?.path ?? "inlineConfig";
|
|
131
|
+
throw new BotimConfigError(
|
|
132
|
+
`${label} field "app_id" must match ${ID_PATTERN.toString()} (got: ${JSON.stringify(idValue)})`,
|
|
133
|
+
{ code: "config-invalid-id", path: source?.path }
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
miniProgramId = idValue;
|
|
137
|
+
} else {
|
|
138
|
+
miniProgramId = synthesizeMiniProgramId(projectRoot, env);
|
|
139
|
+
const reason = source ? `config ${(0, import_node_path.basename)(source.path)} has no app_id` : "no botim_config.*.json found for any env";
|
|
140
|
+
console.warn(
|
|
141
|
+
`[@botim/debug-sdk] ${reason}; synthesized id ${miniProgramId} (env=${env})`
|
|
122
142
|
);
|
|
123
143
|
}
|
|
124
144
|
const md5 = typeof parsed.app?.md5 === "string" ? parsed.app.md5 : typeof parsed.package_url?.md5 === "string" ? parsed.package_url.md5 : void 0;
|
|
@@ -129,13 +149,13 @@ function resolveBotimConfig(mode, root, opts = {}) {
|
|
|
129
149
|
} else if (versionForSig && md5) {
|
|
130
150
|
buildSignature = `v${versionForSig}+md5:${md5.slice(0, 12)}`;
|
|
131
151
|
} else {
|
|
132
|
-
const sigSource = raw ?? JSON.stringify({
|
|
152
|
+
const sigSource = raw ?? JSON.stringify({ app_id: miniProgramId, env, version: versionForSig, app: parsed.app });
|
|
133
153
|
buildSignature = "sha256:" + (0, import_node_crypto.createHash)("sha256").update(sigSource).digest("hex").slice(0, 12);
|
|
134
154
|
}
|
|
135
155
|
const cfg = {
|
|
136
156
|
// Spread first so the canonical fields below override anything inherited.
|
|
137
157
|
...parsed,
|
|
138
|
-
miniProgramId
|
|
158
|
+
miniProgramId,
|
|
139
159
|
env,
|
|
140
160
|
buildSignature,
|
|
141
161
|
appName: typeof parsed.app_id === "string" ? parsed.app_id : parsed.appName,
|
|
@@ -168,6 +188,20 @@ function resolveFileName(override, env, mode) {
|
|
|
168
188
|
{ code: "config-invalid-filename" }
|
|
169
189
|
);
|
|
170
190
|
}
|
|
191
|
+
function synthesizeMiniProgramId(projectRoot, env) {
|
|
192
|
+
const dir = (0, import_node_path.basename)(projectRoot);
|
|
193
|
+
const hash = (0, import_node_crypto.createHash)("sha256").update(`${dir}:${env}`).digest("hex").slice(0, 8);
|
|
194
|
+
return `mp-${hash}`;
|
|
195
|
+
}
|
|
196
|
+
function buildCandidatePaths(projectRoot, selected) {
|
|
197
|
+
const order = [selected, ...VALID_ENVS.filter((e) => e !== selected)];
|
|
198
|
+
const out = [];
|
|
199
|
+
for (const e of order) {
|
|
200
|
+
out.push({ env: e, path: (0, import_node_path.resolve)(projectRoot, `botim_config.${e}.json`) });
|
|
201
|
+
out.push({ env: e, path: (0, import_node_path.resolve)(projectRoot, `botim.${e}.json`) });
|
|
202
|
+
}
|
|
203
|
+
return out;
|
|
204
|
+
}
|
|
171
205
|
|
|
172
206
|
// src/vite/plugin.ts
|
|
173
207
|
var VIRTUAL_ID = "virtual:botim/config";
|
package/dist/vite/plugin.d.cts
CHANGED
|
@@ -25,14 +25,14 @@ interface BotimConfig {
|
|
|
25
25
|
*
|
|
26
26
|
* external schema → SDK-internal `BotimConfig`
|
|
27
27
|
* ─────────────── ──────────────────────────
|
|
28
|
-
*
|
|
29
|
-
* app_id → appId (extra; preserved)
|
|
28
|
+
* app_id (canonical) | miniProgramId (legacy input alias) → miniProgramId
|
|
30
29
|
* version → appVersion
|
|
31
30
|
* app.md5 | package_url.md5 → buildSignature (deterministic per release)
|
|
32
31
|
* <env from filename> → env
|
|
33
32
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
33
|
+
* Prefers `botim_config.{env}.json`, falls back to legacy `botim.{env}.json`,
|
|
34
|
+
* and borrows app_id from a sibling env when the requested env has no file.
|
|
35
|
+
* Build-time only (Node fs/crypto) — never import from device code.
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -86,7 +86,7 @@ interface ResolveOptions {
|
|
|
86
86
|
* JSON (`{ mp_id: 'mbrx_p2p', version: process.env.VERSION }`).
|
|
87
87
|
*
|
|
88
88
|
* When no file exists at the resolved path, the resolver tolerates the
|
|
89
|
-
* miss as long as `inlineConfig` carries a usable `
|
|
89
|
+
* miss as long as `inlineConfig` carries a usable `app_id` (or its legacy
|
|
90
90
|
* `miniProgramId` alias). This is the file-less workflow — handy for
|
|
91
91
|
* monorepos / native hosts that synthesize identity from env vars.
|
|
92
92
|
*/
|
|
@@ -99,7 +99,8 @@ interface ResolveOptions {
|
|
|
99
99
|
* - unknown env after `mapMode` is applied
|
|
100
100
|
* - missing or unreadable file
|
|
101
101
|
* - invalid JSON
|
|
102
|
-
* - missing/invalid `
|
|
102
|
+
* - missing/invalid `app_id` (or its legacy `miniProgramId` alias); when
|
|
103
|
+
* absent on the default file path a stable id is synthesized instead of thrown
|
|
103
104
|
* - the platform marking the mini-program as deleted (`deleted: 1`)
|
|
104
105
|
*/
|
|
105
106
|
declare function resolveBotimConfig(mode: string, root: string, opts?: ResolveOptions): BotimConfig;
|
package/dist/vite/plugin.d.ts
CHANGED
|
@@ -25,14 +25,14 @@ interface BotimConfig {
|
|
|
25
25
|
*
|
|
26
26
|
* external schema → SDK-internal `BotimConfig`
|
|
27
27
|
* ─────────────── ──────────────────────────
|
|
28
|
-
*
|
|
29
|
-
* app_id → appId (extra; preserved)
|
|
28
|
+
* app_id (canonical) | miniProgramId (legacy input alias) → miniProgramId
|
|
30
29
|
* version → appVersion
|
|
31
30
|
* app.md5 | package_url.md5 → buildSignature (deterministic per release)
|
|
32
31
|
* <env from filename> → env
|
|
33
32
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
33
|
+
* Prefers `botim_config.{env}.json`, falls back to legacy `botim.{env}.json`,
|
|
34
|
+
* and borrows app_id from a sibling env when the requested env has no file.
|
|
35
|
+
* Build-time only (Node fs/crypto) — never import from device code.
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -86,7 +86,7 @@ interface ResolveOptions {
|
|
|
86
86
|
* JSON (`{ mp_id: 'mbrx_p2p', version: process.env.VERSION }`).
|
|
87
87
|
*
|
|
88
88
|
* When no file exists at the resolved path, the resolver tolerates the
|
|
89
|
-
* miss as long as `inlineConfig` carries a usable `
|
|
89
|
+
* miss as long as `inlineConfig` carries a usable `app_id` (or its legacy
|
|
90
90
|
* `miniProgramId` alias). This is the file-less workflow — handy for
|
|
91
91
|
* monorepos / native hosts that synthesize identity from env vars.
|
|
92
92
|
*/
|
|
@@ -99,7 +99,8 @@ interface ResolveOptions {
|
|
|
99
99
|
* - unknown env after `mapMode` is applied
|
|
100
100
|
* - missing or unreadable file
|
|
101
101
|
* - invalid JSON
|
|
102
|
-
* - missing/invalid `
|
|
102
|
+
* - missing/invalid `app_id` (or its legacy `miniProgramId` alias); when
|
|
103
|
+
* absent on the default file path a stable id is synthesized instead of thrown
|
|
103
104
|
* - the platform marking the mini-program as deleted (`deleted: 1`)
|
|
104
105
|
*/
|
|
105
106
|
declare function resolveBotimConfig(mode: string, root: string, opts?: ResolveOptions): BotimConfig;
|