@warlock.js/devtools 5.55.0 → 5.56.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/CHANGELOG.md +29 -0
- package/README.md +26 -13
- package/cjs/ai-source-DTpxumMA.cjs +381 -0
- package/cjs/ai-source-DTpxumMA.cjs.map +1 -0
- package/cjs/auth-DzU0gHDG.cjs +1655 -0
- package/cjs/auth-DzU0gHDG.cjs.map +1 -0
- package/cjs/boot-BQi0Etor.cjs +138 -0
- package/cjs/boot-BQi0Etor.cjs.map +1 -0
- package/cjs/capture-CqIiaznN.cjs +1342 -0
- package/cjs/capture-CqIiaznN.cjs.map +1 -0
- package/cjs/cascade-store-pHjKeSFm.cjs +863 -0
- package/cjs/cascade-store-pHjKeSFm.cjs.map +1 -0
- package/cjs/collector-CJbQbzzK.cjs +271 -0
- package/cjs/collector-CJbQbzzK.cjs.map +1 -0
- package/cjs/contracts-CVmplkNb.cjs +112 -0
- package/cjs/contracts-CVmplkNb.cjs.map +1 -0
- package/cjs/current-request-id-BoJJb3y7.cjs +37 -0
- package/cjs/current-request-id-BoJJb3y7.cjs.map +1 -0
- package/cjs/errors-CyZp5yS-.cjs +177 -0
- package/cjs/errors-CyZp5yS-.cjs.map +1 -0
- package/cjs/histogram-BaI-PnCv.cjs +102 -0
- package/cjs/histogram-BaI-PnCv.cjs.map +1 -0
- package/cjs/http-CabcUwBx.cjs +870 -0
- package/cjs/http-CabcUwBx.cjs.map +1 -0
- package/cjs/index.cjs +1 -1
- package/cjs/insights-BKtqxdnP.cjs +811 -0
- package/cjs/insights-BKtqxdnP.cjs.map +1 -0
- package/cjs/ip-DbNhPOzi.cjs +153 -0
- package/cjs/ip-DbNhPOzi.cjs.map +1 -0
- package/cjs/migrations-w7GMsrQw.cjs +297 -0
- package/cjs/migrations-w7GMsrQw.cjs.map +1 -0
- package/cjs/openapi-CC7OAUc6.cjs +52 -0
- package/cjs/openapi-CC7OAUc6.cjs.map +1 -0
- package/cjs/options-CWqFC5__.cjs +181 -0
- package/cjs/options-CWqFC5__.cjs.map +1 -0
- package/cjs/panels-B0dAfGbJ.cjs +298 -0
- package/cjs/panels-B0dAfGbJ.cjs.map +1 -0
- package/cjs/process-panel-DEOnLxoT.cjs +48 -0
- package/cjs/process-panel-DEOnLxoT.cjs.map +1 -0
- package/cjs/production/index.cjs +238 -0
- package/cjs/production/index.cjs.map +1 -0
- package/cjs/rolldown-runtime-Zuuoy_Rh.cjs +52 -0
- package/cjs/server-B6xdeKS8.cjs +184 -0
- package/cjs/server-B6xdeKS8.cjs.map +1 -0
- package/cjs/{src-Xwm3Eel9.cjs → src-Ce-3Lniv.cjs} +163 -295
- package/cjs/src-Ce-3Lniv.cjs.map +1 -0
- package/cjs/store-aq207T8v.cjs +9 -0
- package/cjs/stream-route-BGJa-zQu.cjs +875 -0
- package/cjs/stream-route-BGJa-zQu.cjs.map +1 -0
- package/esm/devtools-connector.d.mts +16 -13
- package/esm/devtools-connector.d.mts.map +1 -1
- package/esm/devtools-connector.mjs +127 -18
- package/esm/devtools-connector.mjs.map +1 -1
- package/esm/index.d.mts +3 -2
- package/esm/options.mjs +2 -1
- package/esm/options.mjs.map +1 -1
- package/esm/panels.mjs +50 -5
- package/esm/panels.mjs.map +1 -1
- package/esm/production/auth/common-passwords.mjs +303 -0
- package/esm/production/auth/common-passwords.mjs.map +1 -0
- package/esm/production/auth/default-crypto.mjs +19 -0
- package/esm/production/auth/default-crypto.mjs.map +1 -0
- package/esm/production/auth/helpers.mjs +77 -0
- package/esm/production/auth/helpers.mjs.map +1 -0
- package/esm/production/auth/index.mjs +6 -0
- package/esm/production/auth/passkeys.mjs +96 -0
- package/esm/production/auth/passkeys.mjs.map +1 -0
- package/esm/production/auth/service.mjs +1166 -0
- package/esm/production/auth/service.mjs.map +1 -0
- package/esm/production/boot.mjs +138 -0
- package/esm/production/boot.mjs.map +1 -0
- package/esm/production/capture/dev-stats.mjs +83 -0
- package/esm/production/capture/dev-stats.mjs.map +1 -0
- package/esm/production/capture/engine.mjs +442 -0
- package/esm/production/capture/engine.mjs.map +1 -0
- package/esm/production/capture/explain.mjs +271 -0
- package/esm/production/capture/explain.mjs.map +1 -0
- package/esm/production/capture/filter.mjs +24 -0
- package/esm/production/capture/filter.mjs.map +1 -0
- package/esm/production/capture/index.mjs +7 -0
- package/esm/production/capture/production-capture.mjs +134 -0
- package/esm/production/capture/production-capture.mjs.map +1 -0
- package/esm/production/capture/redact.mjs +109 -0
- package/esm/production/capture/redact.mjs.map +1 -0
- package/esm/production/capture/stats-stores.mjs +300 -0
- package/esm/production/capture/stats-stores.mjs.map +1 -0
- package/esm/production/cli/actions.mjs +151 -0
- package/esm/production/cli/actions.mjs.map +1 -0
- package/esm/production/cli/index.d.mts +17 -0
- package/esm/production/cli/index.d.mts.map +1 -0
- package/esm/production/cli/index.mjs +86 -0
- package/esm/production/cli/index.mjs.map +1 -0
- package/esm/production/contracts.d.mts +592 -0
- package/esm/production/contracts.d.mts.map +1 -0
- package/esm/production/contracts.mjs +95 -0
- package/esm/production/contracts.mjs.map +1 -0
- package/esm/production/errors.d.mts +31 -0
- package/esm/production/errors.d.mts.map +1 -0
- package/esm/production/errors.mjs +142 -0
- package/esm/production/errors.mjs.map +1 -0
- package/esm/production/http/access.mjs +124 -0
- package/esm/production/http/access.mjs.map +1 -0
- package/esm/production/http/auth-routes.mjs +280 -0
- package/esm/production/http/auth-routes.mjs.map +1 -0
- package/esm/production/http/client.mjs +57 -0
- package/esm/production/http/client.mjs.map +1 -0
- package/esm/production/http/constants.mjs +11 -0
- package/esm/production/http/constants.mjs.map +1 -0
- package/esm/production/http/context.mjs +14 -0
- package/esm/production/http/context.mjs.map +1 -0
- package/esm/production/http/cookie.mjs +39 -0
- package/esm/production/http/cookie.mjs.map +1 -0
- package/esm/production/http/headers.mjs +25 -0
- package/esm/production/http/headers.mjs.map +1 -0
- package/esm/production/http/index.mjs +10 -0
- package/esm/production/http/ip.mjs +130 -0
- package/esm/production/http/ip.mjs.map +1 -0
- package/esm/production/http/mount.mjs +300 -0
- package/esm/production/http/mount.mjs.map +1 -0
- package/esm/production/http/state.mjs +54 -0
- package/esm/production/http/state.mjs.map +1 -0
- package/esm/production/index.d.mts +6 -0
- package/esm/production/index.mjs +5 -0
- package/esm/production/insights/cap-report.mjs +67 -0
- package/esm/production/insights/cap-report.mjs.map +1 -0
- package/esm/production/insights/health.mjs +88 -0
- package/esm/production/insights/health.mjs.map +1 -0
- package/esm/production/insights/index.mjs +10 -0
- package/esm/production/insights/insights.mjs +167 -0
- package/esm/production/insights/insights.mjs.map +1 -0
- package/esm/production/insights/instance.mjs +24 -0
- package/esm/production/insights/instance.mjs.map +1 -0
- package/esm/production/insights/jobs.mjs +100 -0
- package/esm/production/insights/jobs.mjs.map +1 -0
- package/esm/production/insights/reporter.mjs +59 -0
- package/esm/production/insights/reporter.mjs.map +1 -0
- package/esm/production/insights/resources.mjs +139 -0
- package/esm/production/insights/resources.mjs.map +1 -0
- package/esm/production/insights/writer.mjs +72 -0
- package/esm/production/insights/writer.mjs.map +1 -0
- package/esm/production/openapi.mjs +52 -0
- package/esm/production/openapi.mjs.map +1 -0
- package/esm/production/options.d.mts +60 -0
- package/esm/production/options.d.mts.map +1 -0
- package/esm/production/options.mjs +170 -0
- package/esm/production/options.mjs.map +1 -0
- package/esm/production/stats/histogram.mjs +67 -0
- package/esm/production/stats/histogram.mjs.map +1 -0
- package/esm/production/stats/merge.mjs +106 -0
- package/esm/production/stats/merge.mjs.map +1 -0
- package/esm/production/store/cascade-store.mjs +322 -0
- package/esm/production/store/cascade-store.mjs.map +1 -0
- package/esm/production/store/index.mjs +5 -0
- package/esm/production/store/mapping.mjs +258 -0
- package/esm/production/store/mapping.mjs.map +1 -0
- package/esm/production/store/memory-store.mjs +291 -0
- package/esm/production/store/memory-store.mjs.map +1 -0
- package/esm/production/store/migrations.d.mts +11 -0
- package/esm/production/store/migrations.d.mts.map +1 -0
- package/esm/production/store/migrations.mjs +29 -0
- package/esm/production/store/migrations.mjs.map +1 -0
- package/esm/production/store/models/account.migration.mjs +34 -0
- package/esm/production/store/models/account.migration.mjs.map +1 -0
- package/esm/production/store/models/account.model.mjs +13 -0
- package/esm/production/store/models/account.model.mjs.map +1 -0
- package/esm/production/store/models/audit.migration.mjs +30 -0
- package/esm/production/store/models/audit.migration.mjs.map +1 -0
- package/esm/production/store/models/audit.model.mjs +13 -0
- package/esm/production/store/models/audit.model.mjs.map +1 -0
- package/esm/production/store/models/base.mjs +27 -0
- package/esm/production/store/models/base.mjs.map +1 -0
- package/esm/production/store/models/index.mjs +17 -0
- package/esm/production/store/models/invite.migration.mjs +26 -0
- package/esm/production/store/models/invite.migration.mjs.map +1 -0
- package/esm/production/store/models/invite.model.mjs +13 -0
- package/esm/production/store/models/invite.model.mjs.map +1 -0
- package/esm/production/store/models/report.migration.mjs +20 -0
- package/esm/production/store/models/report.migration.mjs.map +1 -0
- package/esm/production/store/models/report.model.mjs +13 -0
- package/esm/production/store/models/report.model.mjs.map +1 -0
- package/esm/production/store/models/sample.migration.mjs +25 -0
- package/esm/production/store/models/sample.migration.mjs.map +1 -0
- package/esm/production/store/models/sample.model.mjs +13 -0
- package/esm/production/store/models/sample.model.mjs.map +1 -0
- package/esm/production/store/models/session.migration.mjs +31 -0
- package/esm/production/store/models/session.migration.mjs.map +1 -0
- package/esm/production/store/models/session.model.mjs +13 -0
- package/esm/production/store/models/session.model.mjs.map +1 -0
- package/esm/production/store/models/state.migration.mjs +26 -0
- package/esm/production/store/models/state.migration.mjs.map +1 -0
- package/esm/production/store/models/state.model.mjs +13 -0
- package/esm/production/store/models/state.model.mjs.map +1 -0
- package/esm/query-shape.mjs +14 -1
- package/esm/query-shape.mjs.map +1 -1
- package/esm/server/explain-route.mjs +26 -1
- package/esm/server/explain-route.mjs.map +1 -1
- package/esm/server/index.mjs +9 -4
- package/esm/server/index.mjs.map +1 -1
- package/esm/server/insights-routes.mjs +62 -0
- package/esm/server/insights-routes.mjs.map +1 -0
- package/esm/server/log-routes.mjs +32 -5
- package/esm/server/log-routes.mjs.map +1 -1
- package/esm/server/openapi-routes.mjs +3 -2
- package/esm/server/openapi-routes.mjs.map +1 -1
- package/esm/server/requests-routes.mjs +125 -0
- package/esm/server/requests-routes.mjs.map +1 -1
- package/esm/server/session-routes.mjs +42 -0
- package/esm/server/session-routes.mjs.map +1 -0
- package/esm/server/stream-route.mjs +81 -11
- package/esm/server/stream-route.mjs.map +1 -1
- package/esm/server/ui-assets.mjs +34 -25
- package/esm/server/ui-assets.mjs.map +1 -1
- package/esm/sources/log-source.mjs +14 -1
- package/esm/sources/log-source.mjs.map +1 -1
- package/esm/types.d.mts +202 -1
- package/esm/types.d.mts.map +1 -1
- package/esm/ui-root.mjs +9 -4
- package/esm/ui-root.mjs.map +1 -1
- package/llms-full.txt +159 -21
- package/llms.txt +2 -2
- package/package.json +32 -8
- package/skills/SKILL.md +159 -21
- package/ui/dashboard/assets/app.css +3 -0
- package/ui/dashboard/assets/app.js +50 -0
- package/ui/dashboard/build-info.json +21 -0
- package/ui/dashboard/index.html +15 -0
- package/cjs/ai-source-Dz_3tlZ5.cjs +0 -703
- package/cjs/ai-source-Dz_3tlZ5.cjs.map +0 -1
- package/cjs/server-B11ShQYE.cjs +0 -628
- package/cjs/server-B11ShQYE.cjs.map +0 -1
- package/cjs/src-Xwm3Eel9.cjs.map +0 -1
- package/ui/app.css +0 -376
- package/ui/app.js +0 -1158
- package/ui/index.html +0 -28
package/esm/panels.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEVTOOLS_BUILT_IN_PANELS } from "./production/contracts.mjs";
|
|
1
2
|
import { createRequire } from "node:module";
|
|
2
3
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
3
4
|
import path from "node:path";
|
|
@@ -9,18 +10,26 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
9
10
|
* panel's routes live under `<path>/api/<id>`, so these would collide.
|
|
10
11
|
*/
|
|
11
12
|
const RESERVED_PANEL_IDS = /* @__PURE__ */ new Set([
|
|
13
|
+
"account",
|
|
14
|
+
"admin",
|
|
12
15
|
"agents",
|
|
13
16
|
"ai",
|
|
14
17
|
"api",
|
|
15
18
|
"assets",
|
|
19
|
+
"auth",
|
|
16
20
|
"background",
|
|
17
21
|
"docs",
|
|
22
|
+
"errors",
|
|
23
|
+
"health",
|
|
24
|
+
"instances",
|
|
25
|
+
"jobs",
|
|
18
26
|
"logs",
|
|
19
27
|
"mail",
|
|
20
28
|
"mails",
|
|
21
29
|
"panels",
|
|
22
30
|
"queries",
|
|
23
31
|
"requests",
|
|
32
|
+
"resources",
|
|
24
33
|
"routes",
|
|
25
34
|
"stream"
|
|
26
35
|
]);
|
|
@@ -99,7 +108,8 @@ function checkDevtoolsPanel(value, taken) {
|
|
|
99
108
|
title: panel.title,
|
|
100
109
|
view,
|
|
101
110
|
routes,
|
|
102
|
-
assets
|
|
111
|
+
assets,
|
|
112
|
+
production: panel.production === true
|
|
103
113
|
};
|
|
104
114
|
}
|
|
105
115
|
/** Validates a list of panels; the first invalid or duplicate one throws. */
|
|
@@ -175,8 +185,11 @@ function resolveWithRequire(entry, root) {
|
|
|
175
185
|
}
|
|
176
186
|
}
|
|
177
187
|
/** The panels a module's default export describes. */
|
|
178
|
-
async function panelsOf(exported, root) {
|
|
179
|
-
const value = typeof exported === "function" ? await exported({
|
|
188
|
+
async function panelsOf(exported, root, mode) {
|
|
189
|
+
const value = typeof exported === "function" ? await exported({
|
|
190
|
+
root,
|
|
191
|
+
mode
|
|
192
|
+
}) : exported;
|
|
180
193
|
return Array.isArray(value) ? value : [value];
|
|
181
194
|
}
|
|
182
195
|
/**
|
|
@@ -191,6 +204,7 @@ async function loadDevtoolsPanels(entries, options) {
|
|
|
191
204
|
return [];
|
|
192
205
|
}
|
|
193
206
|
const importModule = options.importModule ?? ((specifier) => import(specifier));
|
|
207
|
+
const mode = options.mode ?? "development";
|
|
194
208
|
const taken = new Map(options.taken ?? []);
|
|
195
209
|
const panels = [];
|
|
196
210
|
for (const entry of entries) {
|
|
@@ -199,7 +213,7 @@ async function loadDevtoolsPanels(entries, options) {
|
|
|
199
213
|
if (typeof entry === "string") {
|
|
200
214
|
const module = await importModule(resolvePanelSpecifier(entry, options.root));
|
|
201
215
|
if (module.default === void 0) throw new Error("the module has no default export");
|
|
202
|
-
candidates = await panelsOf(module.default, options.root);
|
|
216
|
+
candidates = await panelsOf(module.default, options.root, mode);
|
|
203
217
|
} else candidates = [entry];
|
|
204
218
|
} catch (error) {
|
|
205
219
|
options.warn(`Devtools panel module "${String(entry)}" could not be loaded: ${describe(error)}. Check that it is installed and listed correctly in the devtools "panels" option.`);
|
|
@@ -216,7 +230,38 @@ async function loadDevtoolsPanels(entries, options) {
|
|
|
216
230
|
function describe(error) {
|
|
217
231
|
return error instanceof Error ? error.message : String(error);
|
|
218
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Which tabs the production monitor shows. A built-in tab follows
|
|
235
|
+
* `DEVTOOLS_BUILT_IN_PANELS` unless `overrides[id]` says otherwise. A package
|
|
236
|
+
* panel (the Processes panel included) shows when it declares
|
|
237
|
+
* `production: true` or `overrides[id]` is `true`; `overrides[id]: false` turns
|
|
238
|
+
* any tab off.
|
|
239
|
+
*/
|
|
240
|
+
function productionPanels(packagePanels, overrides = {}) {
|
|
241
|
+
return {
|
|
242
|
+
builtIn: DEVTOOLS_BUILT_IN_PANELS.filter((tab) => overrides[tab.id] ?? tab.production).map((tab) => tab.id),
|
|
243
|
+
panels: packagePanels.filter((panel) => overrides[panel.id] ?? panel.production)
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* The tab list `GET api/panels` answers with: the built-in tabs in
|
|
248
|
+
* `builtIn` (default: every one), in display order, then the package panels
|
|
249
|
+
* in registration order.
|
|
250
|
+
*/
|
|
251
|
+
function listPanelInfos(panels, builtIn) {
|
|
252
|
+
const tabs = DEVTOOLS_BUILT_IN_PANELS.filter((tab) => builtIn === void 0 || builtIn.includes(tab.id)).map((tab) => ({
|
|
253
|
+
id: tab.id,
|
|
254
|
+
title: tab.title,
|
|
255
|
+
type: "built-in"
|
|
256
|
+
}));
|
|
257
|
+
for (const panel of panels) tabs.push({
|
|
258
|
+
id: panel.id,
|
|
259
|
+
title: panel.title,
|
|
260
|
+
type: "package"
|
|
261
|
+
});
|
|
262
|
+
return tabs;
|
|
263
|
+
}
|
|
219
264
|
|
|
220
265
|
//#endregion
|
|
221
|
-
export { checkDevtoolsPanel, checkDevtoolsPanels, loadDevtoolsPanels, panelContentType };
|
|
266
|
+
export { checkDevtoolsPanel, checkDevtoolsPanels, listPanelInfos, loadDevtoolsPanels, panelContentType, productionPanels };
|
|
222
267
|
//# sourceMappingURL=panels.mjs.map
|
package/esm/panels.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panels.mjs","names":[],"sources":["../../../../../../../packages/devtools/src/panels.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport type {\n DevtoolsPanel,\n DevtoolsPanelExport,\n DevtoolsPanelMethod,\n DevtoolsPanelRoute,\n} from \"./types\";\n\n/**\n * A validated panel: file paths are absolute strings and every list is\n * present, so the server never re-checks them per request.\n */\nexport type MountedDevtoolsPanel = {\n id: string;\n title: string;\n view: string;\n routes: readonly (DevtoolsPanelRoute & { method: DevtoolsPanelMethod })[];\n assets: Readonly<Record<string, string>>;\n};\n\n/**\n * Ids the dashboard already uses for its own tabs, API segments and URLs. A\n * panel's routes live under `<path>/api/<id>`, so these would collide.\n */\nconst RESERVED_PANEL_IDS = new Set([\n \"agents\",\n \"ai\",\n \"api\",\n \"assets\",\n \"background\",\n \"docs\",\n \"logs\",\n \"mail\",\n \"mails\",\n \"panels\",\n \"queries\",\n \"requests\",\n \"routes\",\n \"stream\",\n]);\n\nconst PANEL_ID = /^[a-z][a-z0-9-]*$/;\nconst ASSET_NAME = /^[A-Za-z0-9_][A-Za-z0-9._-]*$/;\nconst METHODS = new Set<DevtoolsPanelMethod>([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"]);\n\n/** Content types for the files a panel may serve; anything else is sent as bytes. */\nconst CONTENT_TYPES: Record<string, string> = {\n \".js\": \"text/javascript; charset=utf-8\",\n \".mjs\": \"text/javascript; charset=utf-8\",\n \".css\": \"text/css; charset=utf-8\",\n \".json\": \"application/json; charset=utf-8\",\n \".svg\": \"image/svg+xml\",\n \".png\": \"image/png\",\n \".woff2\": \"font/woff2\",\n};\n\n/** The content type a panel file is served with, from its served name. */\nexport function panelContentType(name: string): string {\n return CONTENT_TYPES[path.extname(name).toLowerCase()] ?? \"application/octet-stream\";\n}\n\n/** An absolute file path from a path or `file:` URL, or `undefined` for anything else. */\nfunction toFilePath(value: unknown): string | undefined {\n if (value instanceof URL) return value.protocol === \"file:\" ? fileURLToPath(value) : undefined;\n if (typeof value !== \"string\" || value === \"\") return undefined;\n if (value.startsWith(\"file:\")) return fileURLToPath(value);\n\n return path.isAbsolute(value) ? value : undefined;\n}\n\nfunction isFile(file: string): boolean {\n return existsSync(file) && statSync(file).isFile();\n}\n\n/**\n * Validates `value` as a panel and returns it ready to mount. Throws an\n * error that names the panel and what to change; `taken` maps the ids\n * already registered to their titles and receives this panel's id.\n */\nexport function checkDevtoolsPanel(\n value: unknown,\n taken: Map<string, string>,\n): MountedDevtoolsPanel {\n const panel = (value ?? {}) as Partial<DevtoolsPanel>;\n const id = panel.id;\n\n if (typeof id !== \"string\" || !PANEL_ID.test(id)) {\n throw new Error(\n `A devtools panel needs an \"id\" of lower-case letters, digits and dashes that starts with a letter; got ${JSON.stringify(id)}.`,\n );\n }\n\n if (RESERVED_PANEL_IDS.has(id)) {\n throw new Error(\n `Devtools panel id \"${id}\" is used by the dashboard itself; give the panel another id.`,\n );\n }\n\n const existing = taken.get(id);\n\n if (existing !== undefined) {\n throw new Error(\n `Devtools panel id \"${id}\" is already registered by the \"${existing}\" panel; each panel needs its own id.`,\n );\n }\n\n if (typeof panel.title !== \"string\" || panel.title.trim() === \"\") {\n throw new Error(`Devtools panel \"${id}\" needs a \"title\" for its tab.`);\n }\n\n const view = toFilePath(panel.view);\n\n if (view === undefined) {\n throw new Error(\n `Devtools panel \"${id}\" needs a \"view\": an absolute path or file: URL of its browser module.`,\n );\n }\n\n if (!isFile(view)) {\n throw new Error(`The view module of devtools panel \"${id}\" was not found at ${view}.`);\n }\n\n // Two routes on one method and path would make the server refuse to start.\n const seen = new Set<string>();\n const routes = (panel.routes ?? []).map((route) => {\n const method = route.method ?? \"GET\";\n\n if (!METHODS.has(method)) {\n throw new Error(\n `Devtools panel \"${id}\" has a route with method \"${String(method)}\"; use GET, POST, PUT, PATCH or DELETE.`,\n );\n }\n\n if (typeof route.path !== \"string\" || (route.path !== \"\" && !route.path.startsWith(\"/\"))) {\n throw new Error(\n `Devtools panel \"${id}\" has a route path ${JSON.stringify(route.path)}; use \"\" or a path starting with \"/\".`,\n );\n }\n\n if (typeof route.handler !== \"function\") {\n throw new Error(`Devtools panel \"${id}\" route ${method} \"${route.path}\" has no handler.`);\n }\n\n if (seen.has(`${method} ${route.path}`)) {\n throw new Error(\n `Devtools panel \"${id}\" lists route ${method} \"${route.path}\" twice; keep one.`,\n );\n }\n\n seen.add(`${method} ${route.path}`);\n\n return { ...route, method };\n });\n\n const assets: Record<string, string> = {};\n\n for (const [name, source] of Object.entries(panel.assets ?? {})) {\n if (!ASSET_NAME.test(name) || name === \"view.js\") {\n throw new Error(\n `Devtools panel \"${id}\" has an asset named ${JSON.stringify(name)}; use a plain file name other than \"view.js\".`,\n );\n }\n\n const file = toFilePath(source);\n\n if (file === undefined || !isFile(file)) {\n throw new Error(\n `The asset \"${name}\" of devtools panel \"${id}\" was not found at ${String(source)}; give an absolute path or file: URL.`,\n );\n }\n\n assets[name] = file;\n }\n\n taken.set(id, panel.title);\n\n return { id, title: panel.title, view, routes, assets };\n}\n\n/** Validates a list of panels; the first invalid or duplicate one throws. */\nexport function checkDevtoolsPanels(panels: readonly unknown[]): MountedDevtoolsPanel[] {\n const taken = new Map<string, string>();\n\n return panels.map((panel) => checkDevtoolsPanel(panel, taken));\n}\n\n/** Hooks `loadDevtoolsPanels` uses; replaced in specs. */\nexport type LoadDevtoolsPanelsOptions = {\n /** The app's root directory: bare specifiers resolve from here, `./` paths are relative to it. */\n root: string;\n /** Receives one line per entry that could not be loaded or was rejected. */\n warn: (message: string) => void;\n /** Ids already taken (the built-in panels), mapped to their titles. */\n taken?: ReadonlyMap<string, string>;\n /** Imports a module URL or specifier; defaults to a dynamic `import()`. */\n importModule?: (specifier: string) => Promise<unknown>;\n};\n\n/** The URL or specifier to import for a `panels` entry. */\nfunction resolvePanelSpecifier(entry: string, root: string): string {\n if (entry.startsWith(\"./\") || entry.startsWith(\"../\") || path.isAbsolute(entry)) {\n return pathToFileURL(path.resolve(root, entry)).href;\n }\n\n return resolveFromNodeModules(entry, root) ?? resolveWithRequire(entry, root) ?? entry;\n}\n\n/** Picks the file an `exports` target names: `import`, then `default`, then `node`. */\nfunction exportTarget(target: unknown): string | undefined {\n if (typeof target === \"string\") return target;\n\n if (Array.isArray(target)) {\n for (const item of target) {\n const found = exportTarget(item);\n\n if (found !== undefined) return found;\n }\n\n return undefined;\n }\n\n if (target !== null && typeof target === \"object\") {\n const conditions = target as Record<string, unknown>;\n\n for (const condition of [\"import\", \"node\", \"default\"]) {\n const found = exportTarget(conditions[condition]);\n\n if (found !== undefined) return found;\n }\n }\n\n return undefined;\n}\n\n/**\n * Resolves a package specifier by looking it up in the `node_modules` folders\n * above the app root and reading its `exports` map. `createRequire().resolve`\n * cannot do this for a package that only has an `import` condition.\n */\nfunction resolveFromNodeModules(entry: string, root: string): string | undefined {\n const parts = entry.split(\"/\");\n const nameLength = entry.startsWith(\"@\") ? 2 : 1;\n const name = parts.slice(0, nameLength).join(\"/\");\n const subpath = parts.length > nameLength ? `./${parts.slice(nameLength).join(\"/\")}` : \".\";\n\n if (!name) return undefined;\n\n let directory = path.resolve(root);\n\n for (;;) {\n const packageDirectory = path.join(directory, \"node_modules\", name);\n const manifestFile = path.join(packageDirectory, \"package.json\");\n\n if (existsSync(manifestFile)) {\n try {\n const manifest = JSON.parse(readFileSync(manifestFile, \"utf8\")) as {\n exports?: unknown;\n main?: string;\n };\n const exported = manifest.exports;\n const map =\n exported !== null && typeof exported === \"object\" && !Array.isArray(exported)\n ? (exported as Record<string, unknown>)\n : undefined;\n const hasSubpaths =\n map !== undefined && Object.keys(map).some((key) => key.startsWith(\".\"));\n const target =\n exported === undefined\n ? subpath === \".\"\n ? (manifest.main ?? \"index.js\")\n : subpath\n : hasSubpaths\n ? exportTarget(map?.[subpath])\n : subpath === \".\"\n ? exportTarget(exported)\n : undefined;\n\n if (target === undefined) return undefined;\n\n const file = path.resolve(packageDirectory, target);\n\n return isFile(file) ? pathToFileURL(file).href : undefined;\n } catch {\n return undefined;\n }\n }\n\n const parent = path.dirname(directory);\n\n if (parent === directory) return undefined;\n\n directory = parent;\n }\n}\n\n/** The `require` resolution, for packages the `node_modules` lookup does not understand. */\nfunction resolveWithRequire(entry: string, root: string): string | undefined {\n try {\n return pathToFileURL(createRequire(path.join(root, \"package.json\")).resolve(entry)).href;\n } catch {\n return undefined;\n }\n}\n\n/** The panels a module's default export describes. */\nasync function panelsOf(exported: DevtoolsPanelExport, root: string): Promise<readonly unknown[]> {\n const value = typeof exported === \"function\" ? await exported({ root }) : exported;\n\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Loads the devtools `panels` option: imports each module entry, reads its\n * default export, and validates every panel. An entry that fails to load and\n * a panel that is invalid or reuses an id are reported through `warn` and\n * skipped, so one broken panel never stops the dashboard.\n */\nexport async function loadDevtoolsPanels(\n entries: readonly (string | DevtoolsPanel)[],\n options: LoadDevtoolsPanelsOptions,\n): Promise<MountedDevtoolsPanel[]> {\n // `src/config/devtools.ts` is a plain object with no types: a single string would be read letter by letter.\n if (!Array.isArray(entries as unknown)) {\n options.warn(\n `The devtools \"panels\" option must be a list, such as panels: [\"@warlock.js/grimoire/devtools\"]; got ${JSON.stringify(entries)}. No panel was added.`,\n );\n\n return [];\n }\n\n const importModule = options.importModule ?? ((specifier: string) => import(specifier));\n const taken = new Map<string, string>(options.taken ?? []);\n const panels: MountedDevtoolsPanel[] = [];\n\n for (const entry of entries) {\n let candidates: readonly unknown[];\n\n try {\n if (typeof entry === \"string\") {\n const module = (await importModule(resolvePanelSpecifier(entry, options.root))) as {\n default?: DevtoolsPanelExport;\n };\n\n if (module.default === undefined) {\n throw new Error(\"the module has no default export\");\n }\n\n candidates = await panelsOf(module.default, options.root);\n } else {\n candidates = [entry];\n }\n } catch (error) {\n options.warn(\n `Devtools panel module \"${String(entry)}\" could not be loaded: ${describe(error)}. Check that it is installed and listed correctly in the devtools \"panels\" option.`,\n );\n continue;\n }\n\n for (const candidate of candidates) {\n try {\n panels.push(checkDevtoolsPanel(candidate, taken));\n } catch (error) {\n options.warn(`${describe(error)} The panel was not added.`);\n }\n }\n }\n\n return panels;\n}\n\nfunction describe(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"],"mappings":";;;;;;;;;;AA2BA,MAAM,qCAAqB,IAAI,IAAI;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,WAAW;AACjB,MAAM,aAAa;AACnB,MAAM,0BAAU,IAAI,IAAyB;CAAC;CAAO;CAAQ;CAAO;CAAS;AAAQ,CAAC;;AAGtF,MAAM,gBAAwC;CAC5C,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,UAAU;AACZ;;AAGA,SAAgB,iBAAiB,MAAsB;CACrD,OAAO,cAAc,KAAK,QAAQ,IAAI,CAAC,CAAC,YAAY,MAAM;AAC5D;;AAGA,SAAS,WAAW,O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U;IAC7B,MAAM,SAAU,MAAM,aAAa,sBAAsB,OAAO,QAAQ,IAAI,CAAC;IAI7E,IAAI,OAAO,YAAY,QACrB,MAAM,IAAI,MAAM,kCAAkC;IAGpD,aAAa,MAAM,SAAS,OAAO,SAAS,QAAQ,IAAI;GAC1D,OACE,aAAa,CAAC,KAAK;EAEvB,SAAS,OAAO;GACd,QAAQ,KACN,0BAA0B,OAAO,KAAK,EAAE,yBAAyB,SAAS,KAAK,EAAE,mFACnF;GACA;EACF;EAEA,KAAK,MAAM,aAAa,YACtB,IAAI;GACF,OAAO,KAAK,mBAAmB,WAAW,KAAK,CAAC;EAClD,SAAS,OAAO;GACd,QAAQ,KAAK,GAAG,SAAS,KAAK,EAAE,0BAA0B;EAC5D;CAEJ;CAEA,OAAO;AACT;AAEA,SAAS,SAAS,OAAwB;CACxC,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC9D"}
|
|
1
|
+
{"version":3,"file":"panels.mjs","names":[],"sources":["../../../../../../../packages/devtools/src/panels.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { DEVTOOLS_BUILT_IN_PANELS } from \"./production/contracts\";\nimport type { DevtoolsMode, DevtoolsPanelInfo } from \"./production/contracts\";\nimport type {\n DevtoolsPanel,\n DevtoolsPanelExport,\n DevtoolsPanelMethod,\n DevtoolsPanelRoute,\n} from \"./types\";\n\n/**\n * A validated panel: file paths are absolute strings and every list is\n * present, so the server never re-checks them per request.\n */\nexport type MountedDevtoolsPanel = {\n id: string;\n title: string;\n view: string;\n routes: readonly (DevtoolsPanelRoute & { method: DevtoolsPanelMethod })[];\n assets: Readonly<Record<string, string>>;\n /** Whether the panel declared itself safe for the production monitor. */\n production: boolean;\n};\n\n/**\n * Ids the dashboard already uses for its own tabs, API segments and URLs. A\n * panel's routes live under `<path>/api/<id>`, so these would collide.\n */\nconst RESERVED_PANEL_IDS = new Set([\n \"account\",\n \"admin\",\n \"agents\",\n \"ai\",\n \"api\",\n \"assets\",\n \"auth\",\n \"background\",\n \"docs\",\n \"errors\",\n \"health\",\n \"instances\",\n \"jobs\",\n \"logs\",\n \"mail\",\n \"mails\",\n \"panels\",\n \"queries\",\n \"requests\",\n \"resources\",\n \"routes\",\n \"stream\",\n]);\n\nconst PANEL_ID = /^[a-z][a-z0-9-]*$/;\nconst ASSET_NAME = /^[A-Za-z0-9_][A-Za-z0-9._-]*$/;\nconst METHODS = new Set<DevtoolsPanelMethod>([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"]);\n\n/** Content types for the files a panel may serve; anything else is sent as bytes. */\nconst CONTENT_TYPES: Record<string, string> = {\n \".js\": \"text/javascript; charset=utf-8\",\n \".mjs\": \"text/javascript; charset=utf-8\",\n \".css\": \"text/css; charset=utf-8\",\n \".json\": \"application/json; charset=utf-8\",\n \".svg\": \"image/svg+xml\",\n \".png\": \"image/png\",\n \".woff2\": \"font/woff2\",\n};\n\n/** The content type a panel file is served with, from its served name. */\nexport function panelContentType(name: string): string {\n return CONTENT_TYPES[path.extname(name).toLowerCase()] ?? \"application/octet-stream\";\n}\n\n/** An absolute file path from a path or `file:` URL, or `undefined` for anything else. */\nfunction toFilePath(value: unknown): string | undefined {\n if (value instanceof URL) return value.protocol === \"file:\" ? fileURLToPath(value) : undefined;\n if (typeof value !== \"string\" || value === \"\") return undefined;\n if (value.startsWith(\"file:\")) return fileURLToPath(value);\n\n return path.isAbsolute(value) ? value : undefined;\n}\n\nfunction isFile(file: string): boolean {\n return existsSync(file) && statSync(file).isFile();\n}\n\n/**\n * Validates `value` as a panel and returns it ready to mount. Throws an\n * error that names the panel and what to change; `taken` maps the ids\n * already registered to their titles and receives this panel's id.\n */\nexport function checkDevtoolsPanel(\n value: unknown,\n taken: Map<string, string>,\n): MountedDevtoolsPanel {\n const panel = (value ?? {}) as Partial<DevtoolsPanel>;\n const id = panel.id;\n\n if (typeof id !== \"string\" || !PANEL_ID.test(id)) {\n throw new Error(\n `A devtools panel needs an \"id\" of lower-case letters, digits and dashes that starts with a letter; got ${JSON.stringify(id)}.`,\n );\n }\n\n if (RESERVED_PANEL_IDS.has(id)) {\n throw new Error(\n `Devtools panel id \"${id}\" is used by the dashboard itself; give the panel another id.`,\n );\n }\n\n const existing = taken.get(id);\n\n if (existing !== undefined) {\n throw new Error(\n `Devtools panel id \"${id}\" is already registered by the \"${existing}\" panel; each panel needs its own id.`,\n );\n }\n\n if (typeof panel.title !== \"string\" || panel.title.trim() === \"\") {\n throw new Error(`Devtools panel \"${id}\" needs a \"title\" for its tab.`);\n }\n\n const view = toFilePath(panel.view);\n\n if (view === undefined) {\n throw new Error(\n `Devtools panel \"${id}\" needs a \"view\": an absolute path or file: URL of its browser module.`,\n );\n }\n\n if (!isFile(view)) {\n throw new Error(`The view module of devtools panel \"${id}\" was not found at ${view}.`);\n }\n\n // Two routes on one method and path would make the server refuse to start.\n const seen = new Set<string>();\n const routes = (panel.routes ?? []).map((route) => {\n const method = route.method ?? \"GET\";\n\n if (!METHODS.has(method)) {\n throw new Error(\n `Devtools panel \"${id}\" has a route with method \"${String(method)}\"; use GET, POST, PUT, PATCH or DELETE.`,\n );\n }\n\n if (typeof route.path !== \"string\" || (route.path !== \"\" && !route.path.startsWith(\"/\"))) {\n throw new Error(\n `Devtools panel \"${id}\" has a route path ${JSON.stringify(route.path)}; use \"\" or a path starting with \"/\".`,\n );\n }\n\n if (typeof route.handler !== \"function\") {\n throw new Error(`Devtools panel \"${id}\" route ${method} \"${route.path}\" has no handler.`);\n }\n\n if (seen.has(`${method} ${route.path}`)) {\n throw new Error(\n `Devtools panel \"${id}\" lists route ${method} \"${route.path}\" twice; keep one.`,\n );\n }\n\n seen.add(`${method} ${route.path}`);\n\n return { ...route, method };\n });\n\n const assets: Record<string, string> = {};\n\n for (const [name, source] of Object.entries(panel.assets ?? {})) {\n if (!ASSET_NAME.test(name) || name === \"view.js\") {\n throw new Error(\n `Devtools panel \"${id}\" has an asset named ${JSON.stringify(name)}; use a plain file name other than \"view.js\".`,\n );\n }\n\n const file = toFilePath(source);\n\n if (file === undefined || !isFile(file)) {\n throw new Error(\n `The asset \"${name}\" of devtools panel \"${id}\" was not found at ${String(source)}; give an absolute path or file: URL.`,\n );\n }\n\n assets[name] = file;\n }\n\n taken.set(id, panel.title);\n\n return { id, title: panel.title, view, routes, assets, production: panel.production === true };\n}\n\n/** Validates a list of panels; the first invalid or duplicate one throws. */\nexport function checkDevtoolsPanels(panels: readonly unknown[]): MountedDevtoolsPanel[] {\n const taken = new Map<string, string>();\n\n return panels.map((panel) => checkDevtoolsPanel(panel, taken));\n}\n\n/** Hooks `loadDevtoolsPanels` uses; replaced in specs. */\nexport type LoadDevtoolsPanelsOptions = {\n /** The app's root directory: bare specifiers resolve from here, `./` paths are relative to it. */\n root: string;\n /** Receives one line per entry that could not be loaded or was rejected. */\n warn: (message: string) => void;\n /** Ids already taken (the built-in panels), mapped to their titles. */\n taken?: ReadonlyMap<string, string>;\n /** Imports a module URL or specifier; defaults to a dynamic `import()`. */\n importModule?: (specifier: string) => Promise<unknown>;\n /** Where the dashboard runs; panel factories receive it as `context.mode`. @default \"development\" */\n mode?: DevtoolsMode;\n};\n\n/** The URL or specifier to import for a `panels` entry. */\nfunction resolvePanelSpecifier(entry: string, root: string): string {\n if (entry.startsWith(\"./\") || entry.startsWith(\"../\") || path.isAbsolute(entry)) {\n return pathToFileURL(path.resolve(root, entry)).href;\n }\n\n return resolveFromNodeModules(entry, root) ?? resolveWithRequire(entry, root) ?? entry;\n}\n\n/** Picks the file an `exports` target names: `import`, then `default`, then `node`. */\nfunction exportTarget(target: unknown): string | undefined {\n if (typeof target === \"string\") return target;\n\n if (Array.isArray(target)) {\n for (const item of target) {\n const found = exportTarget(item);\n\n if (found !== undefined) return found;\n }\n\n return undefined;\n }\n\n if (target !== null && typeof target === \"object\") {\n const conditions = target as Record<string, unknown>;\n\n for (const condition of [\"import\", \"node\", \"default\"]) {\n const found = exportTarget(conditions[condition]);\n\n if (found !== undefined) return found;\n }\n }\n\n return undefined;\n}\n\n/**\n * Resolves a package specifier by looking it up in the `node_modules` folders\n * above the app root and reading its `exports` map. `createRequire().resolve`\n * cannot do this for a package that only has an `import` condition.\n */\nfunction resolveFromNodeModules(entry: string, root: string): string | undefined {\n const parts = entry.split(\"/\");\n const nameLength = entry.startsWith(\"@\") ? 2 : 1;\n const name = parts.slice(0, nameLength).join(\"/\");\n const subpath = parts.length > nameLength ? `./${parts.slice(nameLength).join(\"/\")}` : \".\";\n\n if (!name) return undefined;\n\n let directory = path.resolve(root);\n\n for (;;) {\n const packageDirectory = path.join(directory, \"node_modules\", name);\n const manifestFile = path.join(packageDirectory, \"package.json\");\n\n if (existsSync(manifestFile)) {\n try {\n const manifest = JSON.parse(readFileSync(manifestFile, \"utf8\")) as {\n exports?: unknown;\n main?: string;\n };\n const exported = manifest.exports;\n const map =\n exported !== null && typeof exported === \"object\" && !Array.isArray(exported)\n ? (exported as Record<string, unknown>)\n : undefined;\n const hasSubpaths =\n map !== undefined && Object.keys(map).some((key) => key.startsWith(\".\"));\n const target =\n exported === undefined\n ? subpath === \".\"\n ? (manifest.main ?? \"index.js\")\n : subpath\n : hasSubpaths\n ? exportTarget(map?.[subpath])\n : subpath === \".\"\n ? exportTarget(exported)\n : undefined;\n\n if (target === undefined) return undefined;\n\n const file = path.resolve(packageDirectory, target);\n\n return isFile(file) ? pathToFileURL(file).href : undefined;\n } catch {\n return undefined;\n }\n }\n\n const parent = path.dirname(directory);\n\n if (parent === directory) return undefined;\n\n directory = parent;\n }\n}\n\n/** The `require` resolution, for packages the `node_modules` lookup does not understand. */\nfunction resolveWithRequire(entry: string, root: string): string | undefined {\n try {\n return pathToFileURL(createRequire(path.join(root, \"package.json\")).resolve(entry)).href;\n } catch {\n return undefined;\n }\n}\n\n/** The panels a module's default export describes. */\nasync function panelsOf(\n exported: DevtoolsPanelExport,\n root: string,\n mode: DevtoolsMode,\n): Promise<readonly unknown[]> {\n const value = typeof exported === \"function\" ? await exported({ root, mode }) : exported;\n\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Loads the devtools `panels` option: imports each module entry, reads its\n * default export, and validates every panel. An entry that fails to load and\n * a panel that is invalid or reuses an id are reported through `warn` and\n * skipped, so one broken panel never stops the dashboard.\n */\nexport async function loadDevtoolsPanels(\n entries: readonly (string | DevtoolsPanel)[],\n options: LoadDevtoolsPanelsOptions,\n): Promise<MountedDevtoolsPanel[]> {\n // `src/config/devtools.ts` is a plain object with no types: a single string would be read letter by letter.\n if (!Array.isArray(entries as unknown)) {\n options.warn(\n `The devtools \"panels\" option must be a list, such as panels: [\"@warlock.js/grimoire/devtools\"]; got ${JSON.stringify(entries)}. No panel was added.`,\n );\n\n return [];\n }\n\n const importModule = options.importModule ?? ((specifier: string) => import(specifier));\n const mode = options.mode ?? \"development\";\n const taken = new Map<string, string>(options.taken ?? []);\n const panels: MountedDevtoolsPanel[] = [];\n\n for (const entry of entries) {\n let candidates: readonly unknown[];\n\n try {\n if (typeof entry === \"string\") {\n const module = (await importModule(resolvePanelSpecifier(entry, options.root))) as {\n default?: DevtoolsPanelExport;\n };\n\n if (module.default === undefined) {\n throw new Error(\"the module has no default export\");\n }\n\n candidates = await panelsOf(module.default, options.root, mode);\n } else {\n candidates = [entry];\n }\n } catch (error) {\n options.warn(\n `Devtools panel module \"${String(entry)}\" could not be loaded: ${describe(error)}. Check that it is installed and listed correctly in the devtools \"panels\" option.`,\n );\n continue;\n }\n\n for (const candidate of candidates) {\n try {\n panels.push(checkDevtoolsPanel(candidate, taken));\n } catch (error) {\n options.warn(`${describe(error)} The panel was not added.`);\n }\n }\n }\n\n return panels;\n}\n\nfunction describe(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\n/** What `productionPanels` decides. */\nexport type DevtoolsProductionPanels = {\n /** Built-in tab ids shown, in display order. */\n builtIn: string[];\n /** Package panels shown. */\n panels: MountedDevtoolsPanel[];\n};\n\n/**\n * Which tabs the production monitor shows. A built-in tab follows\n * `DEVTOOLS_BUILT_IN_PANELS` unless `overrides[id]` says otherwise. A package\n * panel (the Processes panel included) shows when it declares\n * `production: true` or `overrides[id]` is `true`; `overrides[id]: false` turns\n * any tab off.\n */\nexport function productionPanels(\n packagePanels: readonly MountedDevtoolsPanel[],\n overrides: Readonly<Record<string, boolean>> = {},\n): DevtoolsProductionPanels {\n const builtIn = DEVTOOLS_BUILT_IN_PANELS.filter((tab) => overrides[tab.id] ?? tab.production).map(\n (tab) => tab.id,\n );\n const panels = packagePanels.filter((panel) => overrides[panel.id] ?? panel.production);\n\n return { builtIn, panels };\n}\n\n/**\n * The tab list `GET api/panels` answers with: the built-in tabs in\n * `builtIn` (default: every one), in display order, then the package panels\n * in registration order.\n */\nexport function listPanelInfos(\n panels: readonly Pick<MountedDevtoolsPanel, \"id\" | \"title\">[],\n builtIn?: readonly string[],\n): DevtoolsPanelInfo[] {\n const tabs: DevtoolsPanelInfo[] = DEVTOOLS_BUILT_IN_PANELS.filter(\n (tab) => builtIn === undefined || builtIn.includes(tab.id),\n ).map((tab) => ({ id: tab.id, title: tab.title, type: \"built-in\" as const }));\n\n for (const panel of panels)\n tabs.push({ id: panel.id, title: panel.title, type: \"package\" as const });\n\n return tabs;\n}\n"],"mappings":";;;;;;;;;;;AA+BA,MAAM,qCAAqB,IAAI,IAAI;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,WAAW;AACjB,MAAM,aAAa;AACnB,MAAM,0BAAU,IAAI,IAAyB;CAAC;CAAO;CAAQ;CAAO;CAAS;AAAQ,CAAC;;AAGtF,MAAM,gBAAwC;CAC5C,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,UAAU;AACZ;;AAGA,S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S,QAClB,KAAK,KAAK;EAAE,IAAI,MAAM;EAAI,OAAO,MAAM;EAAO,MAAM;CAAmB,CAAC;CAE1E,OAAO;AACT"}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
//#region ../../packages/devtools/src/production/auth/common-passwords.ts
|
|
2
|
+
/**
|
|
3
|
+
* Passwords the monitor refuses (compared lower-cased). Short entries are
|
|
4
|
+
* left out: the length rule already refuses them.
|
|
5
|
+
*/
|
|
6
|
+
const COMMON_PASSWORDS = /* @__PURE__ */ new Set([
|
|
7
|
+
"password",
|
|
8
|
+
"password1",
|
|
9
|
+
"password12",
|
|
10
|
+
"password123",
|
|
11
|
+
"password1234",
|
|
12
|
+
"passw0rd",
|
|
13
|
+
"p@ssw0rd",
|
|
14
|
+
"p@ssword",
|
|
15
|
+
"password!",
|
|
16
|
+
"password1!",
|
|
17
|
+
"password2",
|
|
18
|
+
"password3",
|
|
19
|
+
"password01",
|
|
20
|
+
"password11",
|
|
21
|
+
"password99",
|
|
22
|
+
"pa55word",
|
|
23
|
+
"pa$$word",
|
|
24
|
+
"12345678",
|
|
25
|
+
"123456789",
|
|
26
|
+
"1234567890",
|
|
27
|
+
"12345678910",
|
|
28
|
+
"123123123",
|
|
29
|
+
"1234qwer",
|
|
30
|
+
"1q2w3e4r",
|
|
31
|
+
"1q2w3e4r5t",
|
|
32
|
+
"1q2w3e4r5t6y",
|
|
33
|
+
"1qaz2wsx",
|
|
34
|
+
"1qaz2wsx3edc",
|
|
35
|
+
"1qazxsw2",
|
|
36
|
+
"qwertyui",
|
|
37
|
+
"qwertyuiop",
|
|
38
|
+
"qwerty123",
|
|
39
|
+
"qwerty1234",
|
|
40
|
+
"qwerty12",
|
|
41
|
+
"qwertyuio",
|
|
42
|
+
"qwerty123456",
|
|
43
|
+
"qwerty12345",
|
|
44
|
+
"asdfghjk",
|
|
45
|
+
"asdfghjkl",
|
|
46
|
+
"asdfgh123",
|
|
47
|
+
"zxcvbnm1",
|
|
48
|
+
"zxcvbnmasd",
|
|
49
|
+
"zxcvbnm123",
|
|
50
|
+
"abcd1234",
|
|
51
|
+
"abcd12345",
|
|
52
|
+
"abc12345",
|
|
53
|
+
"abc123456",
|
|
54
|
+
"abcdefgh",
|
|
55
|
+
"abcdefg1",
|
|
56
|
+
"abcdefgh1",
|
|
57
|
+
"abcdefghi",
|
|
58
|
+
"iloveyou",
|
|
59
|
+
"iloveyou1",
|
|
60
|
+
"iloveyou2",
|
|
61
|
+
"iloveyou123",
|
|
62
|
+
"letmein1",
|
|
63
|
+
"letmein123",
|
|
64
|
+
"letmein12",
|
|
65
|
+
"welcome1",
|
|
66
|
+
"welcome12",
|
|
67
|
+
"welcome123",
|
|
68
|
+
"welcome01",
|
|
69
|
+
"welcome2",
|
|
70
|
+
"monkey123",
|
|
71
|
+
"monkey12",
|
|
72
|
+
"dragon123",
|
|
73
|
+
"dragon12",
|
|
74
|
+
"master123",
|
|
75
|
+
"master12",
|
|
76
|
+
"shadow123",
|
|
77
|
+
"shadow12",
|
|
78
|
+
"sunshine",
|
|
79
|
+
"sunshine1",
|
|
80
|
+
"sunshine123",
|
|
81
|
+
"princess",
|
|
82
|
+
"princess1",
|
|
83
|
+
"princess123",
|
|
84
|
+
"football",
|
|
85
|
+
"football1",
|
|
86
|
+
"football123",
|
|
87
|
+
"baseball",
|
|
88
|
+
"baseball1",
|
|
89
|
+
"baseball123",
|
|
90
|
+
"basketball",
|
|
91
|
+
"soccer123",
|
|
92
|
+
"hockey123",
|
|
93
|
+
"superman",
|
|
94
|
+
"superman1",
|
|
95
|
+
"superman123",
|
|
96
|
+
"batman123",
|
|
97
|
+
"batman12",
|
|
98
|
+
"spiderman",
|
|
99
|
+
"spiderman1",
|
|
100
|
+
"trustno1",
|
|
101
|
+
"trustno123",
|
|
102
|
+
"trustnoone",
|
|
103
|
+
"whatever",
|
|
104
|
+
"whatever1",
|
|
105
|
+
"whatever123",
|
|
106
|
+
"freedom1",
|
|
107
|
+
"freedom123",
|
|
108
|
+
"starwars",
|
|
109
|
+
"starwars1",
|
|
110
|
+
"starwars123",
|
|
111
|
+
"pokemon1",
|
|
112
|
+
"pokemon123",
|
|
113
|
+
"charlie1",
|
|
114
|
+
"charlie123",
|
|
115
|
+
"michael1",
|
|
116
|
+
"michael123",
|
|
117
|
+
"jessica1",
|
|
118
|
+
"jessica123",
|
|
119
|
+
"jennifer",
|
|
120
|
+
"jennifer1",
|
|
121
|
+
"daniel123",
|
|
122
|
+
"daniel12",
|
|
123
|
+
"thomas123",
|
|
124
|
+
"hunter123",
|
|
125
|
+
"hunter12",
|
|
126
|
+
"hunter2hunter2",
|
|
127
|
+
"hello123",
|
|
128
|
+
"hello1234",
|
|
129
|
+
"hello12345",
|
|
130
|
+
"helloworld",
|
|
131
|
+
"helloworld1",
|
|
132
|
+
"hello@123",
|
|
133
|
+
"admin123",
|
|
134
|
+
"admin1234",
|
|
135
|
+
"admin12345",
|
|
136
|
+
"admin@123",
|
|
137
|
+
"admin@1234",
|
|
138
|
+
"administrator",
|
|
139
|
+
"administrator1",
|
|
140
|
+
"adminadmin",
|
|
141
|
+
"adminadmin1",
|
|
142
|
+
"admin2020",
|
|
143
|
+
"admin2021",
|
|
144
|
+
"admin2022",
|
|
145
|
+
"admin2023",
|
|
146
|
+
"admin2024",
|
|
147
|
+
"admin2025",
|
|
148
|
+
"admin2026",
|
|
149
|
+
"root1234",
|
|
150
|
+
"root12345",
|
|
151
|
+
"toor1234",
|
|
152
|
+
"test1234",
|
|
153
|
+
"test12345",
|
|
154
|
+
"test123456",
|
|
155
|
+
"testtest",
|
|
156
|
+
"testing123",
|
|
157
|
+
"testing1",
|
|
158
|
+
"guest123",
|
|
159
|
+
"guest1234",
|
|
160
|
+
"changeme",
|
|
161
|
+
"changeme1",
|
|
162
|
+
"changeme123",
|
|
163
|
+
"change123",
|
|
164
|
+
"default1",
|
|
165
|
+
"default123",
|
|
166
|
+
"secret123",
|
|
167
|
+
"secret1234",
|
|
168
|
+
"secretpassword",
|
|
169
|
+
"mypassword",
|
|
170
|
+
"mypassword1",
|
|
171
|
+
"mypassword123",
|
|
172
|
+
"mypass123",
|
|
173
|
+
"mysecret1",
|
|
174
|
+
"login123",
|
|
175
|
+
"login1234",
|
|
176
|
+
"access123",
|
|
177
|
+
"access14",
|
|
178
|
+
"qazwsxedc",
|
|
179
|
+
"qazwsx123",
|
|
180
|
+
"qazxswedc",
|
|
181
|
+
"qweasdzxc",
|
|
182
|
+
"qweasd123",
|
|
183
|
+
"qweqweqwe",
|
|
184
|
+
"asdasdasd",
|
|
185
|
+
"asdasd123",
|
|
186
|
+
"zaq12wsx",
|
|
187
|
+
"zaq1zaq1",
|
|
188
|
+
"zaq1xsw2",
|
|
189
|
+
"aaaaaaaa",
|
|
190
|
+
"aaaaaaa1",
|
|
191
|
+
"11111111",
|
|
192
|
+
"111111111",
|
|
193
|
+
"1111111111",
|
|
194
|
+
"00000000",
|
|
195
|
+
"000000000",
|
|
196
|
+
"0000000000",
|
|
197
|
+
"12341234",
|
|
198
|
+
"12121212",
|
|
199
|
+
"11223344",
|
|
200
|
+
"1122334455",
|
|
201
|
+
"123321123",
|
|
202
|
+
"12344321",
|
|
203
|
+
"123456789a",
|
|
204
|
+
"123456abc",
|
|
205
|
+
"1234567a",
|
|
206
|
+
"1234abcd",
|
|
207
|
+
"987654321",
|
|
208
|
+
"9876543210",
|
|
209
|
+
"98765432",
|
|
210
|
+
"88888888",
|
|
211
|
+
"66666666",
|
|
212
|
+
"55555555",
|
|
213
|
+
"77777777",
|
|
214
|
+
"99999999",
|
|
215
|
+
"22222222",
|
|
216
|
+
"33333333",
|
|
217
|
+
"44444444",
|
|
218
|
+
"pass1234",
|
|
219
|
+
"pass12345",
|
|
220
|
+
"pass123456",
|
|
221
|
+
"passpass",
|
|
222
|
+
"passpass1",
|
|
223
|
+
"pass@123",
|
|
224
|
+
"pass@1234",
|
|
225
|
+
"mustang1",
|
|
226
|
+
"mustang123",
|
|
227
|
+
"ranger123",
|
|
228
|
+
"harley123",
|
|
229
|
+
"ferrari1",
|
|
230
|
+
"porsche1",
|
|
231
|
+
"computer",
|
|
232
|
+
"computer1",
|
|
233
|
+
"computer123",
|
|
234
|
+
"internet",
|
|
235
|
+
"internet1",
|
|
236
|
+
"internet123",
|
|
237
|
+
"windows1",
|
|
238
|
+
"windows123",
|
|
239
|
+
"microsoft",
|
|
240
|
+
"linux123",
|
|
241
|
+
"ubuntu123",
|
|
242
|
+
"google123",
|
|
243
|
+
"google12",
|
|
244
|
+
"facebook",
|
|
245
|
+
"facebook1",
|
|
246
|
+
"facebook123",
|
|
247
|
+
"twitter1",
|
|
248
|
+
"youtube1",
|
|
249
|
+
"instagram",
|
|
250
|
+
"samsung1",
|
|
251
|
+
"samsung123",
|
|
252
|
+
"iphone123",
|
|
253
|
+
"android1",
|
|
254
|
+
"android123",
|
|
255
|
+
"liverpool",
|
|
256
|
+
"liverpool1",
|
|
257
|
+
"manchester",
|
|
258
|
+
"chelsea1",
|
|
259
|
+
"arsenal1",
|
|
260
|
+
"barcelona",
|
|
261
|
+
"realmadrid1",
|
|
262
|
+
"cheese123",
|
|
263
|
+
"chocolate",
|
|
264
|
+
"chocolate1",
|
|
265
|
+
"cookie123",
|
|
266
|
+
"banana123",
|
|
267
|
+
"butterfly",
|
|
268
|
+
"butterfly1",
|
|
269
|
+
"flower123",
|
|
270
|
+
"rainbow1",
|
|
271
|
+
"rainbow123",
|
|
272
|
+
"summer123",
|
|
273
|
+
"summer2024",
|
|
274
|
+
"summer2025",
|
|
275
|
+
"winter123",
|
|
276
|
+
"winter2024",
|
|
277
|
+
"winter2025",
|
|
278
|
+
"spring123",
|
|
279
|
+
"autumn123",
|
|
280
|
+
"january1",
|
|
281
|
+
"february1",
|
|
282
|
+
"december1",
|
|
283
|
+
"qwerty@123",
|
|
284
|
+
"abc@12345",
|
|
285
|
+
"p@55w0rd",
|
|
286
|
+
"p@$$w0rd",
|
|
287
|
+
"passw0rd1",
|
|
288
|
+
"passw0rd!",
|
|
289
|
+
"warlock123",
|
|
290
|
+
"warlock1",
|
|
291
|
+
"devtools",
|
|
292
|
+
"devtools1",
|
|
293
|
+
"devtools123",
|
|
294
|
+
"monitor123",
|
|
295
|
+
"monitor1",
|
|
296
|
+
"dashboard",
|
|
297
|
+
"dashboard1",
|
|
298
|
+
"dashboard123"
|
|
299
|
+
]);
|
|
300
|
+
|
|
301
|
+
//#endregion
|
|
302
|
+
export { COMMON_PASSWORDS };
|
|
303
|
+
//# sourceMappingURL=common-passwords.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common-passwords.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/auth/common-passwords.ts"],"sourcesContent":["/**\n * Passwords the monitor refuses (compared lower-cased). Short entries are\n * left out: the length rule already refuses them.\n */\nexport const COMMON_PASSWORDS: ReadonlySet<string> = new Set([\n \"password\",\n \"password1\",\n \"password12\",\n \"password123\",\n \"password1234\",\n \"passw0rd\",\n \"p@ssw0rd\",\n \"p@ssword\",\n \"password!\",\n \"password1!\",\n \"password2\",\n \"password3\",\n \"password01\",\n \"password11\",\n \"password99\",\n \"pa55word\",\n \"pa$$word\",\n \"12345678\",\n \"123456789\",\n \"1234567890\",\n \"12345678910\",\n \"123123123\",\n \"1234qwer\",\n \"1q2w3e4r\",\n \"1q2w3e4r5t\",\n \"1q2w3e4r5t6y\",\n \"1qaz2wsx\",\n \"1qaz2wsx3edc\",\n \"1qazxsw2\",\n \"qwertyui\",\n \"qwertyuiop\",\n \"qwerty123\",\n \"qwerty1234\",\n \"qwerty12\",\n \"qwertyuio\",\n \"qwerty123456\",\n \"qwerty12345\",\n \"asdfghjk\",\n \"asdfghjkl\",\n \"asdfgh123\",\n \"zxcvbnm1\",\n \"zxcvbnmasd\",\n \"zxcvbnm123\",\n \"abcd1234\",\n \"abcd12345\",\n \"abc12345\",\n \"abc123456\",\n \"abcdefgh\",\n \"abcdefg1\",\n \"abcdefgh1\",\n \"abcdefghi\",\n \"iloveyou\",\n \"iloveyou1\",\n \"iloveyou2\",\n \"iloveyou123\",\n \"letmein1\",\n \"letmein123\",\n \"letmein12\",\n \"welcome1\",\n \"welcome12\",\n \"welcome123\",\n \"welcome01\",\n \"welcome2\",\n \"monkey123\",\n \"monkey12\",\n \"dragon123\",\n \"dragon12\",\n \"master123\",\n \"master12\",\n \"shadow123\",\n \"shadow12\",\n \"sunshine\",\n \"sunshine1\",\n \"sunshine123\",\n \"princess\",\n \"princess1\",\n \"princess123\",\n \"football\",\n \"football1\",\n \"football123\",\n \"baseball\",\n \"baseball1\",\n \"baseball123\",\n \"basketball\",\n \"soccer123\",\n \"hockey123\",\n \"superman\",\n \"superman1\",\n \"superman123\",\n \"batman123\",\n \"batman12\",\n \"spiderman\",\n \"spiderman1\",\n \"trustno1\",\n \"trustno123\",\n \"trustnoone\",\n \"whatever\",\n \"whatever1\",\n \"whatever123\",\n \"freedom1\",\n \"freedom123\",\n \"starwars\",\n \"starwars1\",\n \"starwars123\",\n \"pokemon1\",\n \"pokemon123\",\n \"charlie1\",\n \"charlie123\",\n \"michael1\",\n \"michael123\",\n \"jessica1\",\n \"jessica123\",\n \"jennifer\",\n \"jennifer1\",\n \"daniel123\",\n \"daniel12\",\n \"thomas123\",\n \"hunter123\",\n \"hunter12\",\n \"hunter2hunter2\",\n \"hello123\",\n \"hello1234\",\n \"hello12345\",\n \"helloworld\",\n \"helloworld1\",\n \"hello@123\",\n \"admin123\",\n \"admin1234\",\n \"admin12345\",\n \"admin@123\",\n \"admin@1234\",\n \"administrator\",\n \"administrator1\",\n \"adminadmin\",\n \"adminadmin1\",\n \"admin2020\",\n \"admin2021\",\n \"admin2022\",\n \"admin2023\",\n \"admin2024\",\n \"admin2025\",\n \"admin2026\",\n \"root1234\",\n \"root12345\",\n \"toor1234\",\n \"test1234\",\n \"test12345\",\n \"test123456\",\n \"testtest\",\n \"testing123\",\n \"testing1\",\n \"guest123\",\n \"guest1234\",\n \"changeme\",\n \"changeme1\",\n \"changeme123\",\n \"change123\",\n \"default1\",\n \"default123\",\n \"secret123\",\n \"secret1234\",\n \"secretpassword\",\n \"mypassword\",\n \"mypassword1\",\n \"mypassword123\",\n \"mypass123\",\n \"mysecret1\",\n \"login123\",\n \"login1234\",\n \"access123\",\n \"access14\",\n \"qazwsxedc\",\n \"qazwsx123\",\n \"qazxswedc\",\n \"qweasdzxc\",\n \"qweasd123\",\n \"qweqweqwe\",\n \"asdasdasd\",\n \"asdasd123\",\n \"zaq12wsx\",\n \"zaq1zaq1\",\n \"zaq1xsw2\",\n \"aaaaaaaa\",\n \"aaaaaaa1\",\n \"11111111\",\n \"111111111\",\n \"1111111111\",\n \"00000000\",\n \"000000000\",\n \"0000000000\",\n \"12341234\",\n \"12121212\",\n \"11223344\",\n \"1122334455\",\n \"123321123\",\n \"12344321\",\n \"123456789a\",\n \"123456abc\",\n \"1234567a\",\n \"1234abcd\",\n \"987654321\",\n \"9876543210\",\n \"98765432\",\n \"88888888\",\n \"66666666\",\n \"55555555\",\n \"77777777\",\n \"99999999\",\n \"22222222\",\n \"33333333\",\n \"44444444\",\n \"pass1234\",\n \"pass12345\",\n \"pass123456\",\n \"passpass\",\n \"passpass1\",\n \"pass@123\",\n \"pass@1234\",\n \"mustang1\",\n \"mustang123\",\n \"ranger123\",\n \"harley123\",\n \"ferrari1\",\n \"porsche1\",\n \"computer\",\n \"computer1\",\n \"computer123\",\n \"internet\",\n \"internet1\",\n \"internet123\",\n \"windows1\",\n \"windows123\",\n \"microsoft\",\n \"linux123\",\n \"ubuntu123\",\n \"google123\",\n \"google12\",\n \"facebook\",\n \"facebook1\",\n \"facebook123\",\n \"twitter1\",\n \"youtube1\",\n \"instagram\",\n \"samsung1\",\n \"samsung123\",\n \"iphone123\",\n \"android1\",\n \"android123\",\n \"liverpool\",\n \"liverpool1\",\n \"manchester\",\n \"chelsea1\",\n \"arsenal1\",\n \"barcelona\",\n \"realmadrid1\",\n \"cheese123\",\n \"chocolate\",\n \"chocolate1\",\n \"cookie123\",\n \"banana123\",\n \"butterfly\",\n \"butterfly1\",\n \"flower123\",\n \"rainbow1\",\n \"rainbow123\",\n \"summer123\",\n \"summer2024\",\n \"summer2025\",\n \"winter123\",\n \"winter2024\",\n \"winter2025\",\n \"spring123\",\n \"autumn123\",\n \"january1\",\n \"february1\",\n \"december1\",\n \"qwerty@123\",\n \"abc@12345\",\n \"p@55w0rd\",\n \"p@$$w0rd\",\n \"passw0rd1\",\n \"passw0rd!\",\n \"warlock123\",\n \"warlock1\",\n \"devtools\",\n \"devtools1\",\n \"devtools123\",\n \"monitor123\",\n \"monitor1\",\n \"dashboard\",\n \"dashboard1\",\n \"dashboard123\",\n]);\n"],"mappings":";;;;;AAIA,MAAa,mCAAwC,IAAI,IAAI;CAC3D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region ../../packages/devtools/src/production/auth/default-crypto.ts
|
|
2
|
+
/** Core's password hashing, encryption and TOTP helpers, loaded lazily. */
|
|
3
|
+
async function defaultDevtoolsCrypto() {
|
|
4
|
+
const core = await import("@warlock.js/core");
|
|
5
|
+
return {
|
|
6
|
+
hashPassword: (password) => core.hashPassword(password),
|
|
7
|
+
verifyPassword: (password, hash) => core.verifyPassword(password, hash),
|
|
8
|
+
encrypt: (plain) => core.encrypt(plain),
|
|
9
|
+
decrypt: (cipher) => core.decrypt(cipher),
|
|
10
|
+
generateTotpSecret: () => core.generateTotpSecret(),
|
|
11
|
+
verifyTotp: (secret, code, at) => core.verifyTotp(secret, code, { at }),
|
|
12
|
+
totpUri: (input) => core.totpUri(input),
|
|
13
|
+
hmac: (value) => core.hmacHash(value)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { defaultDevtoolsCrypto };
|
|
19
|
+
//# sourceMappingURL=default-crypto.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-crypto.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/auth/default-crypto.ts"],"sourcesContent":["import type { DevtoolsCrypto } from \"./types\";\n\n/** Core's password hashing, encryption and TOTP helpers, loaded lazily. */\nexport async function defaultDevtoolsCrypto(): Promise<DevtoolsCrypto> {\n const core = await import(\"@warlock.js/core\");\n\n return {\n hashPassword: (password) => core.hashPassword(password),\n verifyPassword: (password, hash) => core.verifyPassword(password, hash),\n encrypt: (plain) => core.encrypt(plain),\n decrypt: (cipher) => core.decrypt(cipher),\n generateTotpSecret: () => core.generateTotpSecret(),\n verifyTotp: (secret, code, at) => core.verifyTotp(secret, code, { at }),\n totpUri: (input) => core.totpUri(input),\n hmac: (value) => core.hmacHash(value),\n };\n}\n"],"mappings":";;AAGA,eAAsB,wBAAiD;CACrE,MAAM,OAAO,MAAM,OAAO;CAE1B,OAAO;EACL,eAAe,aAAa,KAAK,aAAa,QAAQ;EACtD,iBAAiB,UAAU,SAAS,KAAK,eAAe,UAAU,IAAI;EACtE,UAAU,UAAU,KAAK,QAAQ,KAAK;EACtC,UAAU,WAAW,KAAK,QAAQ,MAAM;EACxC,0BAA0B,KAAK,mBAAmB;EAClD,aAAa,QAAQ,MAAM,OAAO,KAAK,WAAW,QAAQ,MAAM,EAAE,GAAG,CAAC;EACtE,UAAU,UAAU,KAAK,QAAQ,KAAK;EACtC,OAAO,UAAU,KAAK,SAAS,KAAK;CACtC;AACF"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { COMMON_PASSWORDS } from "./common-passwords.mjs";
|
|
2
|
+
import { createHash, randomBytes, randomInt, timingSafeEqual } from "node:crypto";
|
|
3
|
+
|
|
4
|
+
//#region ../../packages/devtools/src/production/auth/helpers.ts
|
|
5
|
+
const MIN_PASSWORD_LENGTH = 8;
|
|
6
|
+
const MAX_PASSWORD_BYTES = 72;
|
|
7
|
+
/** The alphabet of recovery codes and references: no 0, 1, 8, 9, I, L, O. */
|
|
8
|
+
const CODE_ALPHABET = "ABCDEFGHJKMNPQRSTUVWXYZ23456789";
|
|
9
|
+
/** Letters and digits that cannot be mistaken for each other. */
|
|
10
|
+
const TEMPORARY_ALPHABET = "ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789";
|
|
11
|
+
/**
|
|
12
|
+
* The password rules: at least 8 characters, at most 72 bytes (UTF-8), not in
|
|
13
|
+
* the built-in common list (compared lower-cased), not equal to the email
|
|
14
|
+
* (lower-cased). Returns the failing rule's error code, or `null`.
|
|
15
|
+
*/
|
|
16
|
+
function checkPasswordPolicy(password, email) {
|
|
17
|
+
if (typeof password !== "string" || [...password].length < MIN_PASSWORD_LENGTH) return "auth.password-too-short";
|
|
18
|
+
if (Buffer.byteLength(password, "utf8") > MAX_PASSWORD_BYTES) return "auth.password-too-long";
|
|
19
|
+
const lower = password.toLowerCase();
|
|
20
|
+
if (COMMON_PASSWORDS.has(lower)) return "auth.password-common";
|
|
21
|
+
if (email !== null && lower === email.trim().toLowerCase()) return "auth.password-same-as-email";
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
/** 32 random bytes, base64url (43 characters): session, CSRF and invite tokens. */
|
|
25
|
+
function generateToken() {
|
|
26
|
+
return randomBytes(32).toString("base64url");
|
|
27
|
+
}
|
|
28
|
+
/** SHA-256 hex of a token: what the store keeps. */
|
|
29
|
+
function hashToken(token) {
|
|
30
|
+
return createHash("sha256").update(token).digest("hex");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A random temporary password for `warlock devtools:reset-admin`: 20
|
|
34
|
+
* characters from an unambiguous alphabet, passes `checkPasswordPolicy`.
|
|
35
|
+
*/
|
|
36
|
+
function generateTemporaryPassword() {
|
|
37
|
+
for (;;) {
|
|
38
|
+
let password = "";
|
|
39
|
+
for (let index = 0; index < 20; index++) password += TEMPORARY_ALPHABET[randomInt(54)];
|
|
40
|
+
if (checkPasswordPolicy(password, null) === null) return password;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Compares two strings in constant time (both are hashed first, so lengths do not leak). */
|
|
44
|
+
function safeEqual(a, b) {
|
|
45
|
+
const left = createHash("sha256").update(String(a)).digest();
|
|
46
|
+
const right = createHash("sha256").update(String(b)).digest();
|
|
47
|
+
return timingSafeEqual(left, right);
|
|
48
|
+
}
|
|
49
|
+
/** Emails are compared trimmed and lower-cased. */
|
|
50
|
+
function normalizeEmail(email) {
|
|
51
|
+
return typeof email === "string" ? email.trim().toLowerCase() : "";
|
|
52
|
+
}
|
|
53
|
+
/** A deliberately plain shape check; the invite flow is the real proof of ownership. */
|
|
54
|
+
function isPlausibleEmail(email) {
|
|
55
|
+
return email.length <= 254 && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
56
|
+
}
|
|
57
|
+
/** One recovery code, `xxxxx-xxxxx` from the unambiguous alphabet. */
|
|
58
|
+
function generateRecoveryCode() {
|
|
59
|
+
let code = "";
|
|
60
|
+
for (let index = 0; index < 10; index++) {
|
|
61
|
+
if (index === 5) code += "-";
|
|
62
|
+
code += CODE_ALPHABET[randomInt(31)];
|
|
63
|
+
}
|
|
64
|
+
return code;
|
|
65
|
+
}
|
|
66
|
+
/** The form a recovery code is hashed in: upper case, letters and digits only. */
|
|
67
|
+
function normalizeRecoveryCode(code) {
|
|
68
|
+
return String(code).toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
69
|
+
}
|
|
70
|
+
/** SHA-256 hex of a normalized recovery code. */
|
|
71
|
+
function hashRecoveryCode(code) {
|
|
72
|
+
return hashToken(normalizeRecoveryCode(code));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { checkPasswordPolicy, generateRecoveryCode, generateTemporaryPassword, generateToken, hashRecoveryCode, hashToken, isPlausibleEmail, normalizeEmail, normalizeRecoveryCode, safeEqual };
|
|
77
|
+
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/auth/helpers.ts"],"sourcesContent":["import { createHash, randomBytes, randomInt, timingSafeEqual } from \"node:crypto\";\nimport type { DevtoolsErrorCode } from \"../contracts\";\nimport { COMMON_PASSWORDS } from \"./common-passwords\";\n\nconst MIN_PASSWORD_LENGTH = 8;\nconst MAX_PASSWORD_BYTES = 72;\n\n/** The alphabet of recovery codes and references: no 0, 1, 8, 9, I, L, O. */\nconst CODE_ALPHABET = \"ABCDEFGHJKMNPQRSTUVWXYZ23456789\";\n\n/** Letters and digits that cannot be mistaken for each other. */\nconst TEMPORARY_ALPHABET = \"ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789\";\n\n/**\n * The password rules: at least 8 characters, at most 72 bytes (UTF-8), not in\n * the built-in common list (compared lower-cased), not equal to the email\n * (lower-cased). Returns the failing rule's error code, or `null`.\n */\nexport function checkPasswordPolicy(\n password: string,\n email: string | null,\n): DevtoolsErrorCode | null {\n if (typeof password !== \"string\" || [...password].length < MIN_PASSWORD_LENGTH) {\n return \"auth.password-too-short\";\n }\n\n if (Buffer.byteLength(password, \"utf8\") > MAX_PASSWORD_BYTES) return \"auth.password-too-long\";\n\n const lower = password.toLowerCase();\n\n if (COMMON_PASSWORDS.has(lower)) return \"auth.password-common\";\n\n if (email !== null && lower === email.trim().toLowerCase()) return \"auth.password-same-as-email\";\n\n return null;\n}\n\n/** 32 random bytes, base64url (43 characters): session, CSRF and invite tokens. */\nexport function generateToken(): string {\n return randomBytes(32).toString(\"base64url\");\n}\n\n/** SHA-256 hex of a token: what the store keeps. */\nexport function hashToken(token: string): string {\n return createHash(\"sha256\").update(token).digest(\"hex\");\n}\n\n/**\n * A random temporary password for `warlock devtools:reset-admin`: 20\n * characters from an unambiguous alphabet, passes `checkPasswordPolicy`.\n */\nexport function generateTemporaryPassword(): string {\n for (;;) {\n let password = \"\";\n\n for (let index = 0; index < 20; index++) {\n password += TEMPORARY_ALPHABET[randomInt(TEMPORARY_ALPHABET.length)];\n }\n\n if (checkPasswordPolicy(password, null) === null) return password;\n }\n}\n\n/** Compares two strings in constant time (both are hashed first, so lengths do not leak). */\nexport function safeEqual(a: string, b: string): boolean {\n const left = createHash(\"sha256\").update(String(a)).digest();\n const right = createHash(\"sha256\").update(String(b)).digest();\n\n return timingSafeEqual(left, right);\n}\n\n/** Emails are compared trimmed and lower-cased. */\nexport function normalizeEmail(email: unknown): string {\n return typeof email === \"string\" ? email.trim().toLowerCase() : \"\";\n}\n\n/** A deliberately plain shape check; the invite flow is the real proof of ownership. */\nexport function isPlausibleEmail(email: string): boolean {\n return email.length <= 254 && /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email);\n}\n\n/** One recovery code, `xxxxx-xxxxx` from the unambiguous alphabet. */\nexport function generateRecoveryCode(): string {\n let code = \"\";\n\n for (let index = 0; index < 10; index++) {\n if (index === 5) code += \"-\";\n\n code += CODE_ALPHABET[randomInt(CODE_ALPHABET.length)];\n }\n\n return code;\n}\n\n/** The form a recovery code is hashed in: upper case, letters and digits only. */\nexport function normalizeRecoveryCode(code: string): string {\n return String(code)\n .toUpperCase()\n .replace(/[^A-Z0-9]/g, \"\");\n}\n\n/** SHA-256 hex of a normalized recovery code. */\nexport function hashRecoveryCode(code: string): string {\n return hashToken(normalizeRecoveryCode(code));\n}\n"],"mappings":";;;;AAIA,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB;;AAG3B,MAAM,gBAAgB;;AAGtB,MAAM,qBAAqB;;;;;;AAO3B,SAAgB,oBACd,UACA,OAC0B;CAC1B,IAAI,OAAO,aAAa,YAAY,CAAC,GAAG,QAAQ,CAAC,CAAC,SAAS,qBACzD,OAAO;CAGT,IAAI,OAAO,WAAW,UAAU,MAAM,IAAI,oBAAoB,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C,CAChB,YAAY,CAAC,CACb,QAAQ,cAAc,EAAE;AAC7B;;AAGA,SAAgB,iBAAiB,MAAsB;CACrD,OAAO,UAAU,sBAAsB,IAAI,CAAC;AAC9C"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { checkPasswordPolicy, generateTemporaryPassword, generateToken, hashToken } from "./helpers.mjs";
|
|
2
|
+
import { createDevtoolsAuth } from "./service.mjs";
|
|
3
|
+
import { defaultDevtoolsCrypto } from "./default-crypto.mjs";
|
|
4
|
+
import { loadDevtoolsPasskeys } from "./passkeys.mjs";
|
|
5
|
+
|
|
6
|
+
export { checkPasswordPolicy, createDevtoolsAuth, defaultDevtoolsCrypto, generateTemporaryPassword, generateToken, hashToken, loadDevtoolsPasskeys };
|