@debugkit/cli 0.6.0 → 0.6.1
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 +3 -3
- package/dist/cli.js +81 -17
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -108,9 +108,9 @@ Options: `--provider firebase|aws|local` skips the provider question, `--cwd <di
|
|
|
108
108
|
|---|---|
|
|
109
109
|
| Just this machine | Run end to end: the empty dashboard, then test events arriving |
|
|
110
110
|
| Firebase | Run end to end against a real project: function deployed, indexes added without touching existing ones, test events read back on the dashboard |
|
|
111
|
-
| Hosting the dashboard | Firebase: deployed to
|
|
111
|
+
| Hosting the dashboard | Firebase: deployed to two real projects, reading live data as the read-only service account. With ingest in africa-south1, Hosting couldn't reach a dashboard function there, so it runs in us-central1 (the retry now offers that first). AWS: the Lambda package runs locally; not yet deployed to a real account |
|
|
112
112
|
| AWS | Unit-tested (profile parsing, the "not found" handling, key merging) and the bundled Lambda run locally. Not yet run against a real account |
|
|
113
|
-
| Environments (`--env`) | Run end to end with "just this machine" in an Expo-style app: separate config and login, `.env` untouched, `debug.ts` with the on/off switch. `eas env:set`
|
|
113
|
+
| Environments (`--env`) | Run end to end with "just this machine" in an Expo-style app: separate config and login, `.env` untouched, `debug.ts` with the on/off switch. `eas env:set` has run against a real EAS project (Project Megatron Native's preview) |
|
|
114
114
|
| Platforms | Vite and React run for real. The Expo, React Native, Next.js, TanStack Start and Node templates are unit-tested |
|
|
115
115
|
|
|
116
116
|
## What it needs
|
|
@@ -125,7 +125,7 @@ Options: `--provider firebase|aws|local` skips the provider question, `--cwd <di
|
|
|
125
125
|
|
|
126
126
|
| Path | What it is | Commit it? |
|
|
127
127
|
|---|---|---|
|
|
128
|
-
| `.debugkit/config.json` | provider, endpoint, ingest key, resource names | yes |
|
|
128
|
+
| `.debugkit/config.json` | provider, endpoint, ingest key, resource names. No personal details (since 0.6.1 the Google account is kept in `dashboard.env`) | yes, or gitignore the whole `.debugkit/` folder if you prefer |
|
|
129
129
|
| `.debugkit/firebase/` | the ingest function source (Firebase), so you can redeploy it | yes |
|
|
130
130
|
| `.debugkit/firebase/dashboard/` | the hosted dashboard's function source (Firebase). Its `.env.<project>` holds secrets and is gitignored | yes, except `.env.*` |
|
|
131
131
|
| `.debugkit/dashboard.env` | the dashboard login (a password hash), session secret, API token | no, it's gitignored |
|
package/dist/cli.js
CHANGED
|
@@ -260,7 +260,7 @@ var dim = (s) => pc.dim(s);
|
|
|
260
260
|
var bold = (s) => pc.bold(s);
|
|
261
261
|
|
|
262
262
|
// src/dashboard.ts
|
|
263
|
-
var VERSION = true ? "0.6.
|
|
263
|
+
var VERSION = true ? "0.6.1" : "0.0.0-dev";
|
|
264
264
|
var DASHBOARD_VERSION = VERSION;
|
|
265
265
|
function hashPassword(password2) {
|
|
266
266
|
const salt = randomBytes(16);
|
|
@@ -862,8 +862,9 @@ async function setupFirebase(ctx) {
|
|
|
862
862
|
const endpoint = `https://${region}-${projectId}.cloudfunctions.net/${FUNCTION_NAME}`;
|
|
863
863
|
await ensureDashboardAccess(projectId);
|
|
864
864
|
return {
|
|
865
|
-
|
|
866
|
-
|
|
865
|
+
// The Google account is personal: it goes in the gitignored dashboard env, not config.json.
|
|
866
|
+
config: { provider: "firebase", endpoint, ingestKey: ctx.ingestKey, firebase: { projectId, region, location: location2 } },
|
|
867
|
+
dashboardEnv: { DEBUG_STORE: "firestore", GOOGLE_CLOUD_PROJECT: projectId, GCLOUD_PROJECT: projectId, DEBUGKIT_FIREBASE_ACCOUNT: account, ...adminEnv(endpoint, ctx) },
|
|
867
868
|
created: [
|
|
868
869
|
`Firestore database in ${code(projectId)} (${location2}), with indexes and 30-day expiry on raw events`,
|
|
869
870
|
`Cloud Function ${code(FUNCTION_NAME)} in ${region}: ${code(endpoint)}`,
|
|
@@ -1045,6 +1046,11 @@ async function waitLive(url, ms = 12e4) {
|
|
|
1045
1046
|
async function hostDashboard(cwd, cfg) {
|
|
1046
1047
|
const local = readEnv(paths(cwd).dashboardEnv);
|
|
1047
1048
|
const out = cfg.provider === "firebase" ? await hostFirebase(cwd, cfg, local) : cfg.provider === "aws" ? await hostAws(cfg, local) : bail("The dashboard can only be hosted on Firebase or AWS. On this setup, run it locally.");
|
|
1049
|
+
if (cfg.firebase?.account) {
|
|
1050
|
+
if (!local.DEBUGKIT_FIREBASE_ACCOUNT) upsertEnv(paths(cwd).dashboardEnv, { DEBUGKIT_FIREBASE_ACCOUNT: cfg.firebase.account });
|
|
1051
|
+
const { account: _a, ...firebase } = cfg.firebase;
|
|
1052
|
+
cfg = { ...cfg, firebase };
|
|
1053
|
+
}
|
|
1048
1054
|
writeConfig(cwd, { ...cfg, hosted: out.hosted });
|
|
1049
1055
|
await linkAlerts(local, cfg.appId, out.hosted.url);
|
|
1050
1056
|
const s = p.spinner();
|
|
@@ -1132,7 +1138,8 @@ function writeHostingConfig(dir, site, region) {
|
|
|
1132
1138
|
async function hostFirebase(cwd, cfg, local) {
|
|
1133
1139
|
const fbc = cfg.firebase ?? bail("This setup has no Firebase project saved. Run npx debugkit init again.");
|
|
1134
1140
|
const [fbCmd, fbPre] = await firebaseCli();
|
|
1135
|
-
const
|
|
1141
|
+
const account = local.DEBUGKIT_FIREBASE_ACCOUNT || fbc.account;
|
|
1142
|
+
const acct = account ? ["--account", account] : [];
|
|
1136
1143
|
const proj = ["--project", fbc.projectId, ...acct];
|
|
1137
1144
|
const fb = (args, o = {}) => capture(fbCmd, [...fbPre, ...args], o);
|
|
1138
1145
|
const fbLive = (args, o = {}) => interactive(fbCmd, [...fbPre, ...args], o);
|
|
@@ -1204,11 +1211,12 @@ async function hostFirebase(cwd, cfg, local) {
|
|
|
1204
1211
|
const choice = await choose(
|
|
1205
1212
|
"The deploy didn't finish (see the error above). What now?",
|
|
1206
1213
|
[
|
|
1207
|
-
|
|
1208
|
-
...region !== "us-central1" ? [{ value: "us", label: "Retry with the function in us-central1", hint: "
|
|
1214
|
+
// Hosting can't reach functions in some regions (africa-south1, for one): a plain retry fails the same way.
|
|
1215
|
+
...region !== "us-central1" ? [{ value: "us", label: "Retry with the function in us-central1", hint: "the usual fix when Hosting can't reach the function's region" }] : [],
|
|
1216
|
+
{ value: "retry", label: "Retry as it is" },
|
|
1209
1217
|
{ value: "stop", label: "Stop here" }
|
|
1210
1218
|
],
|
|
1211
|
-
"retry"
|
|
1219
|
+
region !== "us-central1" ? "us" : "retry"
|
|
1212
1220
|
);
|
|
1213
1221
|
if (choice === "stop") bail(`Fix the error above, then run ${code("npx debugkit deploy-dashboard")}.`);
|
|
1214
1222
|
if (choice === "us") {
|
|
@@ -1506,14 +1514,22 @@ function browserContext() {
|
|
|
1506
1514
|
// ../sdk/src/auto.ts
|
|
1507
1515
|
var g = globalThis;
|
|
1508
1516
|
var ID_SEGMENT = /^(?:\d+|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{16,}|(?=[^/]*\d)[\w-]{20,})$/i;
|
|
1517
|
+
var PERSONAL_SEGMENT = /\d(?:[\s().-]?\d){6,}|@|%40/;
|
|
1509
1518
|
function normaliseUrl(raw) {
|
|
1510
1519
|
const m = /^(?:([a-z][a-z0-9+.-]*:)?\/\/([^/?#]*))?([^?#]*)/i.exec(raw.trim());
|
|
1511
1520
|
let host = m?.[2] ?? "";
|
|
1512
|
-
const path2 = (m?.[3] || "/").split("/").map((s) => ID_SEGMENT.test(s) ? ":id" : s).join("/");
|
|
1521
|
+
const path2 = (m?.[3] || "/").split("/").map((s) => ID_SEGMENT.test(s) || PERSONAL_SEGMENT.test(safeDecode(s)) ? ":id" : s).join("/");
|
|
1513
1522
|
if (host.includes("@")) host = host.slice(host.lastIndexOf("@") + 1);
|
|
1514
1523
|
const here = typeof location !== "undefined" ? location.host : void 0;
|
|
1515
1524
|
return !host || host === here ? path2 : `${host}${path2.startsWith("/") ? "" : "/"}${path2}`;
|
|
1516
1525
|
}
|
|
1526
|
+
function safeDecode(s) {
|
|
1527
|
+
try {
|
|
1528
|
+
return decodeURIComponent(s);
|
|
1529
|
+
} catch {
|
|
1530
|
+
return s;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1517
1533
|
var insideFetch = 0;
|
|
1518
1534
|
function instrumentFetch(sink) {
|
|
1519
1535
|
const orig = g.fetch;
|
|
@@ -1665,7 +1681,7 @@ function instrumentWebLifecycle(sink) {
|
|
|
1665
1681
|
|
|
1666
1682
|
// ../sdk/src/client.ts
|
|
1667
1683
|
var SDK_NAME = "@debugkit/sdk";
|
|
1668
|
-
var SDK_VERSION = "0.
|
|
1684
|
+
var SDK_VERSION = typeof __DEBUGKIT_SDK_VERSION__ === "string" ? __DEBUGKIT_SDK_VERSION__ : "0.0.0-dev";
|
|
1669
1685
|
var QUEUE_KEY = "@debugkit/queue";
|
|
1670
1686
|
var ANON_KEY = "@debugkit/anonymousId";
|
|
1671
1687
|
function webStorage() {
|
|
@@ -1689,6 +1705,10 @@ var DebugClient = class {
|
|
|
1689
1705
|
user = { anonymousId: uid() };
|
|
1690
1706
|
timer;
|
|
1691
1707
|
flushing;
|
|
1708
|
+
/** The batch being uploaded: still saved, so a crash mid-upload doesn't lose it. */
|
|
1709
|
+
inflight = [];
|
|
1710
|
+
/** Saved events from the last run, read once; saves wait for it so they don't overwrite them. */
|
|
1711
|
+
restoring;
|
|
1692
1712
|
backoffUntil = 0;
|
|
1693
1713
|
failures = 0;
|
|
1694
1714
|
ready = false;
|
|
@@ -1715,7 +1735,7 @@ var DebugClient = class {
|
|
|
1715
1735
|
this.rawFetch = typeof globalThis.fetch === "function" ? globalThis.fetch.__raw ?? globalThis.fetch : void 0;
|
|
1716
1736
|
this.ready = true;
|
|
1717
1737
|
this.loadAnonymousId();
|
|
1718
|
-
|
|
1738
|
+
this.restoring = this.restore();
|
|
1719
1739
|
if (this.auto.errors && !this.handlersInstalled) this.installGlobalHandlers();
|
|
1720
1740
|
this.instrument();
|
|
1721
1741
|
if (this.auto.sessions) this.startSession();
|
|
@@ -1830,9 +1850,12 @@ var DebugClient = class {
|
|
|
1830
1850
|
if (this.flushing) return this.flushing;
|
|
1831
1851
|
if (!this.ready || this.queue.length === 0 || Date.now() < this.backoffUntil) return;
|
|
1832
1852
|
const batch = this.queue.splice(0, this.opts.maxBatch);
|
|
1853
|
+
this.inflight = batch;
|
|
1833
1854
|
this.flushing = this.send(batch).then(() => {
|
|
1834
1855
|
this.failures = 0;
|
|
1856
|
+
this.inflight = [];
|
|
1835
1857
|
}).catch((err) => {
|
|
1858
|
+
this.inflight = [];
|
|
1836
1859
|
this.queue.unshift(...batch);
|
|
1837
1860
|
this.failures++;
|
|
1838
1861
|
this.backoffUntil = Date.now() + Math.min(6e4, 1e3 * 2 ** this.failures);
|
|
@@ -1907,7 +1930,14 @@ var DebugClient = class {
|
|
|
1907
1930
|
/** Queue without sampling (sessions must be complete for crash-free rates to be right). */
|
|
1908
1931
|
push(e) {
|
|
1909
1932
|
if (!this.ready) return;
|
|
1910
|
-
|
|
1933
|
+
let out = e;
|
|
1934
|
+
if (this.opts.beforeSend) {
|
|
1935
|
+
try {
|
|
1936
|
+
out = this.opts.beforeSend(e);
|
|
1937
|
+
} catch (err) {
|
|
1938
|
+
this.log("beforeSend threw; sending the event unchanged", err);
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1911
1941
|
if (!out) return;
|
|
1912
1942
|
this.queue.push(out);
|
|
1913
1943
|
if (this.queue.length > MAX_QUEUE) this.queue.splice(0, this.queue.length - MAX_QUEUE);
|
|
@@ -1961,9 +1991,27 @@ var DebugClient = class {
|
|
|
1961
1991
|
}
|
|
1962
1992
|
if (!res.ok) throw new Error(`ingest responded ${res.status}`);
|
|
1963
1993
|
}
|
|
1994
|
+
/** What must survive a restart: the batch being uploaded, then the queue. */
|
|
1995
|
+
snapshot() {
|
|
1996
|
+
return JSON.stringify([...this.inflight, ...this.queue]);
|
|
1997
|
+
}
|
|
1964
1998
|
async persist() {
|
|
1999
|
+
const storage = this.opts.storage;
|
|
2000
|
+
if (!storage) return;
|
|
1965
2001
|
try {
|
|
1966
|
-
await this.
|
|
2002
|
+
await this.restoring;
|
|
2003
|
+
await storage.setItem(QUEUE_KEY, this.snapshot());
|
|
2004
|
+
} catch {
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
/** Save now, synchronously where the storage can: the app is about to die. */
|
|
2008
|
+
persistNow() {
|
|
2009
|
+
const storage = this.opts.storage;
|
|
2010
|
+
if (!storage) return;
|
|
2011
|
+
try {
|
|
2012
|
+
if (storage.setItemSync) storage.setItemSync(QUEUE_KEY, this.snapshot());
|
|
2013
|
+
else void storage.setItem(QUEUE_KEY, this.snapshot()).catch(() => {
|
|
2014
|
+
});
|
|
1967
2015
|
} catch {
|
|
1968
2016
|
}
|
|
1969
2017
|
}
|
|
@@ -1997,7 +2045,11 @@ var DebugClient = class {
|
|
|
1997
2045
|
async restore() {
|
|
1998
2046
|
try {
|
|
1999
2047
|
const raw = await this.opts.storage?.getItem(QUEUE_KEY);
|
|
2000
|
-
|
|
2048
|
+
const saved = raw ? JSON.parse(raw) : [];
|
|
2049
|
+
if (!Array.isArray(saved) || !saved.length) return;
|
|
2050
|
+
const have = new Set([...this.inflight, ...this.queue].map((e) => e.id));
|
|
2051
|
+
this.queue.unshift(...saved.filter((e) => e && typeof e === "object" && !have.has(e.id)));
|
|
2052
|
+
if (this.queue.length > MAX_QUEUE) this.queue.splice(0, this.queue.length - MAX_QUEUE);
|
|
2001
2053
|
} catch {
|
|
2002
2054
|
}
|
|
2003
2055
|
}
|
|
@@ -2007,8 +2059,13 @@ var DebugClient = class {
|
|
|
2007
2059
|
if (g2.ErrorUtils?.setGlobalHandler) {
|
|
2008
2060
|
const prev = g2.ErrorUtils.getGlobalHandler?.();
|
|
2009
2061
|
g2.ErrorUtils.setGlobalHandler((err, isFatal) => {
|
|
2010
|
-
|
|
2011
|
-
|
|
2062
|
+
try {
|
|
2063
|
+
this.error(err, { handled: false, fatal: !!isFatal, tags: { source: "global-handler" } });
|
|
2064
|
+
if (isFatal) this.persistNow();
|
|
2065
|
+
void this.flush();
|
|
2066
|
+
if (isFatal) this.persistNow();
|
|
2067
|
+
} catch {
|
|
2068
|
+
}
|
|
2012
2069
|
prev?.(err, isFatal);
|
|
2013
2070
|
});
|
|
2014
2071
|
}
|
|
@@ -2474,7 +2531,8 @@ export { deBug };
|
|
|
2474
2531
|
}
|
|
2475
2532
|
}
|
|
2476
2533
|
async function writeEasEnv(app, values, env) {
|
|
2477
|
-
const
|
|
2534
|
+
const globalOk = !!which("eas") && (await capture("eas", ["env:set", "--help"], { cwd: app.cwd })).code === 0;
|
|
2535
|
+
const [cmd, pre] = globalOk ? ["eas", []] : ["npx", ["-y", "eas-cli@latest"]];
|
|
2478
2536
|
const s = p.spinner();
|
|
2479
2537
|
s.start(`Setting ${Object.keys(values).length} variables in EAS's ${env} environment`);
|
|
2480
2538
|
for (const [name, value] of Object.entries(values)) {
|
|
@@ -2497,7 +2555,7 @@ async function wireApp(app, conn) {
|
|
|
2497
2555
|
let done = Object.keys(values).length === 0;
|
|
2498
2556
|
if (!done && usesEas && EAS_ENVIRONMENTS.includes(env) && await yes(`Set the endpoint and key in EAS's ${env} environment (eas env:set)?`)) done = await writeEasEnv(app, values, env);
|
|
2499
2557
|
if (!done) {
|
|
2500
|
-
|
|
2558
|
+
printValues(`Set these for your ${env} builds:`, values);
|
|
2501
2559
|
extra.push(usesEas ? `Set the variables above in EAS's ${code(env)} environment (${code(`eas env:set --environment ${env}`)})` : `Set the variables above wherever your ${code(env)} builds get their environment`);
|
|
2502
2560
|
}
|
|
2503
2561
|
} else {
|
|
@@ -2526,6 +2584,11 @@ ${dim(f.contents)}`);
|
|
|
2526
2584
|
}
|
|
2527
2585
|
return [...extra, ...f.then];
|
|
2528
2586
|
}
|
|
2587
|
+
function printValues(title, values) {
|
|
2588
|
+
p.log.info(title);
|
|
2589
|
+
for (const [k, v] of Object.entries(values)) console.log(`${k}=${v}`);
|
|
2590
|
+
console.log("");
|
|
2591
|
+
}
|
|
2529
2592
|
|
|
2530
2593
|
// src/cli.ts
|
|
2531
2594
|
var HELP = `${bold("debugkit")} ${VERSION}: set up deBug in your app
|
|
@@ -2643,6 +2706,7 @@ async function init(cwd, preset) {
|
|
|
2643
2706
|
const cfg = { ...result.config, ...existing?.provider === provider && existing.hosted ? { hosted: existing.hosted } : {}, appId: app.appId, dashboardPort, retentionDays, createdAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2644
2707
|
writeConfig(cwd, cfg);
|
|
2645
2708
|
p.note(result.created.map((l) => `\u2022 ${l}`).join("\n"), "Created");
|
|
2709
|
+
printValues("Your ingest endpoint and key (the key is public: it ships in your app):", { endpoint: cfg.endpoint, key: cfg.ingestKey });
|
|
2646
2710
|
const remaining = await wireApp(app, cfg);
|
|
2647
2711
|
await prepareDashboardEnv(cwd, result.dashboardEnv, dashboardPort);
|
|
2648
2712
|
let dash;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@debugkit/cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Set up deBug in your app: npx @debugkit/cli init (or npx debugkit init once @debugkit/sdk is installed). Deploys ingest to your own cloud, wires the SDK and walks you through the dashboard.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@aws-sdk/lib-dynamodb": "^3.700.0",
|
|
23
|
-
"@debugkit/adapters": "^0.6.
|
|
24
|
-
"@debugkit/
|
|
25
|
-
"@debugkit/
|
|
23
|
+
"@debugkit/adapters": "^0.6.1",
|
|
24
|
+
"@debugkit/ingest": "^0.6.1",
|
|
25
|
+
"@debugkit/sdk": "^0.6.1"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|
|
28
28
|
"node": ">=20.12"
|