@warlock.js/devtools 5.55.0 → 5.57.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 +52 -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-Dy5OqgTM.cjs +138 -0
- package/cjs/boot-Dy5OqgTM.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-DCfXQvw-.cjs +870 -0
- package/cjs/http-DCfXQvw-.cjs.map +1 -0
- package/cjs/index.cjs +2 -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-Rcmeitu3.cjs +318 -0
- package/cjs/panels-Rcmeitu3.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-ykxsOwob.cjs +184 -0
- package/cjs/server-ykxsOwob.cjs.map +1 -0
- package/cjs/{src-Xwm3Eel9.cjs → src-UPtTCI2j.cjs} +210 -293
- package/cjs/src-UPtTCI2j.cjs.map +1 -0
- package/cjs/store-aq207T8v.cjs +9 -0
- package/cjs/stream-route-CJTABkUy.cjs +875 -0
- package/cjs/stream-route-CJTABkUy.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 +4 -2
- package/esm/index.mjs +2 -1
- package/esm/options.mjs +2 -1
- package/esm/options.mjs.map +1 -1
- package/esm/panel-tokens.d.mts +13 -0
- package/esm/panel-tokens.d.mts.map +1 -0
- package/esm/panel-tokens.mjs +45 -0
- package/esm/panel-tokens.mjs.map +1 -0
- package/esm/panels.mjs +73 -8
- 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 +208 -3
- 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 +166 -21
- package/llms.txt +2 -2
- package/package.json +32 -8
- package/skills/SKILL.md +166 -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 +16 -0
- package/ui/panels/processes.js +12 -3
- 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
|
@@ -0,0 +1,863 @@
|
|
|
1
|
+
const require_errors = require("./errors-CyZp5yS-.cjs");
|
|
2
|
+
const require_ip = require("./ip-DbNhPOzi.cjs");
|
|
3
|
+
let node_crypto = require("node:crypto");
|
|
4
|
+
|
|
5
|
+
//#region ../../packages/devtools/src/production/store/mapping.ts
|
|
6
|
+
/** A number from a column that a driver may return as a string (PostgreSQL `bigint`). */
|
|
7
|
+
function toNumber(value) {
|
|
8
|
+
if (typeof value === "number") return value;
|
|
9
|
+
const parsed = Number(value);
|
|
10
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
11
|
+
}
|
|
12
|
+
/** Like `toNumber`, keeping `null` for a missing value. */
|
|
13
|
+
function toNumberOrNull(value) {
|
|
14
|
+
return value === null || value === void 0 ? null : toNumber(value);
|
|
15
|
+
}
|
|
16
|
+
function toStringOrNull(value) {
|
|
17
|
+
return typeof value === "string" ? value : null;
|
|
18
|
+
}
|
|
19
|
+
function toBoolean(value) {
|
|
20
|
+
return value === true || value === 1 || value === "true" || value === "t";
|
|
21
|
+
}
|
|
22
|
+
/** Parses JSON text; a value a driver already parsed passes through. */
|
|
23
|
+
function parseJson(value, fallback) {
|
|
24
|
+
if (typeof value === "string") try {
|
|
25
|
+
return JSON.parse(value);
|
|
26
|
+
} catch {
|
|
27
|
+
return fallback;
|
|
28
|
+
}
|
|
29
|
+
return value === null || value === void 0 ? fallback : value;
|
|
30
|
+
}
|
|
31
|
+
function toArray(value) {
|
|
32
|
+
const parsed = parseJson(value, []);
|
|
33
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
34
|
+
}
|
|
35
|
+
const ACCOUNT_COLUMNS = {
|
|
36
|
+
email: "email",
|
|
37
|
+
role: "role",
|
|
38
|
+
passwordHash: "password_hash",
|
|
39
|
+
passwordSource: "password_source",
|
|
40
|
+
mustChangePassword: "must_change_password",
|
|
41
|
+
totpSecret: "totp_secret",
|
|
42
|
+
totpEnabledAt: "totp_enabled_at",
|
|
43
|
+
totpLastStep: "totp_last_step",
|
|
44
|
+
recoveryCodes: "recovery_codes",
|
|
45
|
+
passkeys: "passkeys",
|
|
46
|
+
failuresResetAt: "failures_reset_at",
|
|
47
|
+
createdAt: "created_at",
|
|
48
|
+
updatedAt: "updated_at",
|
|
49
|
+
lastLoginAt: "last_login_at",
|
|
50
|
+
createdBy: "created_by",
|
|
51
|
+
version: "version"
|
|
52
|
+
};
|
|
53
|
+
function accountToRow(record) {
|
|
54
|
+
return {
|
|
55
|
+
id: record.id,
|
|
56
|
+
...fieldsToRow(ACCOUNT_COLUMNS, record)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function accountPatchToRow(patch) {
|
|
60
|
+
return fieldsToRow(ACCOUNT_COLUMNS, patch);
|
|
61
|
+
}
|
|
62
|
+
function rowToAccount(row) {
|
|
63
|
+
return {
|
|
64
|
+
id: String(row.id),
|
|
65
|
+
email: String(row.email),
|
|
66
|
+
role: row.role,
|
|
67
|
+
passwordHash: String(row.password_hash),
|
|
68
|
+
passwordSource: row.password_source,
|
|
69
|
+
mustChangePassword: toBoolean(row.must_change_password),
|
|
70
|
+
totpSecret: toStringOrNull(row.totp_secret),
|
|
71
|
+
totpEnabledAt: toNumberOrNull(row.totp_enabled_at),
|
|
72
|
+
totpLastStep: toNumberOrNull(row.totp_last_step),
|
|
73
|
+
recoveryCodes: toArray(row.recovery_codes),
|
|
74
|
+
passkeys: toArray(row.passkeys),
|
|
75
|
+
failuresResetAt: toNumberOrNull(row.failures_reset_at),
|
|
76
|
+
createdAt: toNumber(row.created_at),
|
|
77
|
+
updatedAt: toNumber(row.updated_at),
|
|
78
|
+
lastLoginAt: toNumberOrNull(row.last_login_at),
|
|
79
|
+
createdBy: toStringOrNull(row.created_by),
|
|
80
|
+
version: toNumber(row.version)
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const SESSION_COLUMNS = {
|
|
84
|
+
tokenHash: "token_hash",
|
|
85
|
+
accountId: "account_id",
|
|
86
|
+
stage: "stage",
|
|
87
|
+
csrfSecret: "csrf_secret",
|
|
88
|
+
createdAt: "created_at",
|
|
89
|
+
lastSeenAt: "last_seen_at",
|
|
90
|
+
expiresAt: "expires_at",
|
|
91
|
+
ip: "ip",
|
|
92
|
+
userAgent: "user_agent",
|
|
93
|
+
pendingTotpSecret: "pending_totp_secret",
|
|
94
|
+
challenge: "challenge",
|
|
95
|
+
challengeExpiresAt: "challenge_expires_at",
|
|
96
|
+
version: "version"
|
|
97
|
+
};
|
|
98
|
+
function sessionToRow(record) {
|
|
99
|
+
return {
|
|
100
|
+
id: record.id,
|
|
101
|
+
...fieldsToRow(SESSION_COLUMNS, record)
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function sessionPatchToRow(patch) {
|
|
105
|
+
return fieldsToRow(SESSION_COLUMNS, patch);
|
|
106
|
+
}
|
|
107
|
+
function rowToSession(row) {
|
|
108
|
+
return {
|
|
109
|
+
id: String(row.id),
|
|
110
|
+
tokenHash: String(row.token_hash),
|
|
111
|
+
accountId: String(row.account_id),
|
|
112
|
+
stage: row.stage,
|
|
113
|
+
csrfSecret: String(row.csrf_secret),
|
|
114
|
+
createdAt: toNumber(row.created_at),
|
|
115
|
+
lastSeenAt: toNumber(row.last_seen_at),
|
|
116
|
+
expiresAt: toNumber(row.expires_at),
|
|
117
|
+
ip: toStringOrNull(row.ip),
|
|
118
|
+
userAgent: toStringOrNull(row.user_agent),
|
|
119
|
+
pendingTotpSecret: toStringOrNull(row.pending_totp_secret),
|
|
120
|
+
challenge: toStringOrNull(row.challenge),
|
|
121
|
+
challengeExpiresAt: toNumberOrNull(row.challenge_expires_at),
|
|
122
|
+
version: toNumber(row.version)
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function inviteToRow(record) {
|
|
126
|
+
return {
|
|
127
|
+
id: record.id,
|
|
128
|
+
token_hash: record.tokenHash,
|
|
129
|
+
email: record.email,
|
|
130
|
+
role: record.role,
|
|
131
|
+
created_by: record.createdBy,
|
|
132
|
+
created_at: record.createdAt,
|
|
133
|
+
expires_at: record.expiresAt,
|
|
134
|
+
used_at: record.usedAt,
|
|
135
|
+
account_id: record.accountId
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function rowToInvite(row) {
|
|
139
|
+
return {
|
|
140
|
+
id: String(row.id),
|
|
141
|
+
tokenHash: String(row.token_hash),
|
|
142
|
+
email: String(row.email),
|
|
143
|
+
role: row.role,
|
|
144
|
+
createdBy: toStringOrNull(row.created_by),
|
|
145
|
+
createdAt: toNumber(row.created_at),
|
|
146
|
+
expiresAt: toNumber(row.expires_at),
|
|
147
|
+
usedAt: toNumberOrNull(row.used_at),
|
|
148
|
+
accountId: toStringOrNull(row.account_id)
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function auditToRow(entry) {
|
|
152
|
+
return {
|
|
153
|
+
id: entry.id,
|
|
154
|
+
type: entry.type,
|
|
155
|
+
occurred_at: entry.at,
|
|
156
|
+
account_id: entry.accountId,
|
|
157
|
+
email: entry.email,
|
|
158
|
+
ip: entry.ip,
|
|
159
|
+
ip_bucket: entry.ip === null ? null : require_ip.rateLimitClient(entry.ip),
|
|
160
|
+
user_agent: entry.userAgent,
|
|
161
|
+
detail: entry.detail,
|
|
162
|
+
ref: entry.ref
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function rowToAudit(row) {
|
|
166
|
+
return {
|
|
167
|
+
id: String(row.id),
|
|
168
|
+
at: toNumber(row.occurred_at),
|
|
169
|
+
type: row.type,
|
|
170
|
+
accountId: toStringOrNull(row.account_id),
|
|
171
|
+
email: toStringOrNull(row.email),
|
|
172
|
+
ip: toStringOrNull(row.ip),
|
|
173
|
+
userAgent: toStringOrNull(row.user_agent),
|
|
174
|
+
detail: parseJson(row.detail, {}),
|
|
175
|
+
ref: String(row.ref)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const STATE_COLUMNS = {
|
|
179
|
+
disabled: "disabled",
|
|
180
|
+
disabledPathHash: "disabled_path_hash",
|
|
181
|
+
disabledAt: "disabled_at",
|
|
182
|
+
disabledBy: "disabled_by",
|
|
183
|
+
lockedUntil: "locked_until",
|
|
184
|
+
failuresResetAt: "failures_reset_at",
|
|
185
|
+
updatedAt: "updated_at",
|
|
186
|
+
version: "version"
|
|
187
|
+
};
|
|
188
|
+
function stateToRow(record) {
|
|
189
|
+
return fieldsToRow(STATE_COLUMNS, record);
|
|
190
|
+
}
|
|
191
|
+
function statePatchToRow(patch) {
|
|
192
|
+
return fieldsToRow(STATE_COLUMNS, patch);
|
|
193
|
+
}
|
|
194
|
+
function rowToState(row) {
|
|
195
|
+
return {
|
|
196
|
+
disabled: toBoolean(row.disabled),
|
|
197
|
+
disabledPathHash: toStringOrNull(row.disabled_path_hash),
|
|
198
|
+
disabledAt: toNumberOrNull(row.disabled_at),
|
|
199
|
+
disabledBy: toStringOrNull(row.disabled_by),
|
|
200
|
+
lockedUntil: toNumberOrNull(row.locked_until),
|
|
201
|
+
failuresResetAt: toNumberOrNull(row.failures_reset_at),
|
|
202
|
+
updatedAt: toNumber(row.updated_at),
|
|
203
|
+
version: toNumber(row.version)
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* `detail` is JSON text, not a JSON column: a sample holds keys from request
|
|
208
|
+
* data (headers, query names) and MongoDB rejects or misreads field names
|
|
209
|
+
* that start with `$` or contain dots.
|
|
210
|
+
*/
|
|
211
|
+
function sampleToRow(sample) {
|
|
212
|
+
return {
|
|
213
|
+
id: sample.id,
|
|
214
|
+
instance: sample.instance,
|
|
215
|
+
started_at: sample.startedAt,
|
|
216
|
+
status: sample.summary.status ?? null,
|
|
217
|
+
method: sample.summary.method.toUpperCase(),
|
|
218
|
+
path: sample.summary.path,
|
|
219
|
+
summary: sample.summary,
|
|
220
|
+
detail: sample.detail === null ? null : JSON.stringify(sample.detail)
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function rowToSampleSummary(row) {
|
|
224
|
+
return parseJson(row.summary, {});
|
|
225
|
+
}
|
|
226
|
+
function rowToSample(row) {
|
|
227
|
+
const detail = row.detail;
|
|
228
|
+
return {
|
|
229
|
+
id: String(row.id),
|
|
230
|
+
instance: String(row.instance),
|
|
231
|
+
startedAt: toNumber(row.started_at),
|
|
232
|
+
summary: parseJson(row.summary, {}),
|
|
233
|
+
detail: detail === null || detail === void 0 ? null : parseJson(detail, null)
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
/** `data` is JSON text for the same reason as a sample's `detail`. */
|
|
237
|
+
function reportToRow(report) {
|
|
238
|
+
return {
|
|
239
|
+
id: report.instance.id,
|
|
240
|
+
seen_at: report.at,
|
|
241
|
+
data: JSON.stringify(report)
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function rowToReport(row) {
|
|
245
|
+
return parseJson(row.data, {});
|
|
246
|
+
}
|
|
247
|
+
/** Maps the defined fields of `source` to their columns. */
|
|
248
|
+
function fieldsToRow(columns, source) {
|
|
249
|
+
const row = {};
|
|
250
|
+
const values = source;
|
|
251
|
+
for (const [field, column] of Object.entries(columns)) {
|
|
252
|
+
const value = values[field];
|
|
253
|
+
if (value !== void 0) row[column] = value;
|
|
254
|
+
}
|
|
255
|
+
return row;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region ../../packages/devtools/src/production/store/memory-store.ts
|
|
260
|
+
/** A structural copy, so callers never hold the store's own objects. */
|
|
261
|
+
function copy(value) {
|
|
262
|
+
return structuredClone(value);
|
|
263
|
+
}
|
|
264
|
+
/** The state row before anything was written. */
|
|
265
|
+
function defaultStateRecord(now = 0) {
|
|
266
|
+
return {
|
|
267
|
+
disabled: false,
|
|
268
|
+
disabledPathHash: null,
|
|
269
|
+
disabledAt: null,
|
|
270
|
+
disabledBy: null,
|
|
271
|
+
lockedUntil: null,
|
|
272
|
+
failuresResetAt: null,
|
|
273
|
+
updatedAt: now,
|
|
274
|
+
version: 0
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
/** Whether `status` matches a sample filter value: `"5xx"`, `"4xx"`, `"404"`. */
|
|
278
|
+
function sampleStatusMatches(filter, status) {
|
|
279
|
+
if (status === void 0) return false;
|
|
280
|
+
const value = filter.trim().toLowerCase();
|
|
281
|
+
if (/^[1-5]xx$/.test(value)) return Math.floor(status / 100) === Number(value[0]);
|
|
282
|
+
return String(status) === value;
|
|
283
|
+
}
|
|
284
|
+
/** Whether a sample summary passes `filter` (everything but `limit`). */
|
|
285
|
+
function sampleMatches(summary, filter) {
|
|
286
|
+
if (filter.status !== void 0 && !sampleStatusMatches(filter.status, summary.status)) return false;
|
|
287
|
+
if (filter.method !== void 0 && summary.method.toUpperCase() !== filter.method.toUpperCase()) return false;
|
|
288
|
+
if (filter.route !== void 0) {
|
|
289
|
+
const needle = filter.route.toLowerCase();
|
|
290
|
+
if (!`${summary.route ?? ""} ${summary.path}`.toLowerCase().includes(needle)) return false;
|
|
291
|
+
}
|
|
292
|
+
if (filter.q !== void 0 && !summary.path.toLowerCase().includes(filter.q.toLowerCase())) return false;
|
|
293
|
+
if (filter.since !== void 0 && summary.startedAt < filter.since) return false;
|
|
294
|
+
if (filter.until !== void 0 && summary.startedAt > filter.until) return false;
|
|
295
|
+
if (filter.instance !== void 0 && summary.instance !== filter.instance) return false;
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* An in-process `DevtoolsStore` for specs (and nothing else: it is neither
|
|
300
|
+
* shared between processes nor kept across restarts). It follows the store
|
|
301
|
+
* contract exactly, compare-and-set included, so a spec written against it
|
|
302
|
+
* holds for the database store too.
|
|
303
|
+
*
|
|
304
|
+
* `now` is read for `updatedAt` stamps; pass a fake clock in specs.
|
|
305
|
+
*/
|
|
306
|
+
function createMemoryStore(options = {}) {
|
|
307
|
+
const now = options.now ?? Date.now;
|
|
308
|
+
const accounts = /* @__PURE__ */ new Map();
|
|
309
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
310
|
+
const invites = /* @__PURE__ */ new Map();
|
|
311
|
+
const audit = [];
|
|
312
|
+
const samples = /* @__PURE__ */ new Map();
|
|
313
|
+
const reports = /* @__PURE__ */ new Map();
|
|
314
|
+
let state = null;
|
|
315
|
+
return {
|
|
316
|
+
async verify() {},
|
|
317
|
+
accounts: {
|
|
318
|
+
async findByEmail(email) {
|
|
319
|
+
for (const account of accounts.values()) if (account.email === email) return copy(account);
|
|
320
|
+
return null;
|
|
321
|
+
},
|
|
322
|
+
async findById(id) {
|
|
323
|
+
const account = accounts.get(id);
|
|
324
|
+
return account ? copy(account) : null;
|
|
325
|
+
},
|
|
326
|
+
async list() {
|
|
327
|
+
return [...accounts.values()].sort((a, b) => a.createdAt - b.createdAt).map(copy);
|
|
328
|
+
},
|
|
329
|
+
async countAdmins() {
|
|
330
|
+
return [...accounts.values()].filter((account) => account.role === "admin").length;
|
|
331
|
+
},
|
|
332
|
+
async create(input) {
|
|
333
|
+
for (const account of accounts.values()) if (account.email === input.email) throw new require_errors.DevtoolsStoreConflictError("email");
|
|
334
|
+
const at = now();
|
|
335
|
+
const record = {
|
|
336
|
+
...copy(input),
|
|
337
|
+
id: (0, node_crypto.randomUUID)(),
|
|
338
|
+
createdAt: at,
|
|
339
|
+
updatedAt: at,
|
|
340
|
+
version: 1
|
|
341
|
+
};
|
|
342
|
+
accounts.set(record.id, record);
|
|
343
|
+
return copy(record);
|
|
344
|
+
},
|
|
345
|
+
async update(id, expectedVersion, patch) {
|
|
346
|
+
const current = accounts.get(id);
|
|
347
|
+
if (!current || current.version !== expectedVersion) return null;
|
|
348
|
+
if (patch.email !== void 0 && patch.email !== current.email) {
|
|
349
|
+
for (const account of accounts.values()) if (account.email === patch.email) throw new require_errors.DevtoolsStoreConflictError("email");
|
|
350
|
+
}
|
|
351
|
+
const next = {
|
|
352
|
+
...current,
|
|
353
|
+
...copy(patch),
|
|
354
|
+
id,
|
|
355
|
+
createdAt: current.createdAt,
|
|
356
|
+
updatedAt: now(),
|
|
357
|
+
version: current.version + 1
|
|
358
|
+
};
|
|
359
|
+
accounts.set(id, next);
|
|
360
|
+
return copy(next);
|
|
361
|
+
},
|
|
362
|
+
async remove(id) {
|
|
363
|
+
return accounts.delete(id);
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
sessions: {
|
|
367
|
+
async create(input) {
|
|
368
|
+
const record = {
|
|
369
|
+
...copy(input),
|
|
370
|
+
id: (0, node_crypto.randomUUID)(),
|
|
371
|
+
version: 1
|
|
372
|
+
};
|
|
373
|
+
sessions.set(record.id, record);
|
|
374
|
+
return copy(record);
|
|
375
|
+
},
|
|
376
|
+
async findByTokenHash(tokenHash) {
|
|
377
|
+
for (const session of sessions.values()) if (session.tokenHash === tokenHash) return copy(session);
|
|
378
|
+
return null;
|
|
379
|
+
},
|
|
380
|
+
async listForAccount(accountId) {
|
|
381
|
+
return [...sessions.values()].filter((session) => session.accountId === accountId).sort((a, b) => b.createdAt - a.createdAt).map(copy);
|
|
382
|
+
},
|
|
383
|
+
async update(id, expectedVersion, patch) {
|
|
384
|
+
const current = sessions.get(id);
|
|
385
|
+
if (!current || current.version !== expectedVersion) return null;
|
|
386
|
+
const next = {
|
|
387
|
+
...current,
|
|
388
|
+
...copy(patch),
|
|
389
|
+
id,
|
|
390
|
+
accountId: current.accountId,
|
|
391
|
+
version: current.version + 1
|
|
392
|
+
};
|
|
393
|
+
sessions.set(id, next);
|
|
394
|
+
return copy(next);
|
|
395
|
+
},
|
|
396
|
+
async remove(id) {
|
|
397
|
+
return sessions.delete(id);
|
|
398
|
+
},
|
|
399
|
+
async removeForAccount(accountId, exceptId) {
|
|
400
|
+
let removed = 0;
|
|
401
|
+
for (const session of [...sessions.values()]) if (session.accountId === accountId && session.id !== exceptId) {
|
|
402
|
+
sessions.delete(session.id);
|
|
403
|
+
removed++;
|
|
404
|
+
}
|
|
405
|
+
return removed;
|
|
406
|
+
},
|
|
407
|
+
async removeExpired(at) {
|
|
408
|
+
let removed = 0;
|
|
409
|
+
for (const session of [...sessions.values()]) if (session.expiresAt < at) {
|
|
410
|
+
sessions.delete(session.id);
|
|
411
|
+
removed++;
|
|
412
|
+
}
|
|
413
|
+
return removed;
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
invites: {
|
|
417
|
+
async create(input) {
|
|
418
|
+
const record = {
|
|
419
|
+
...copy(input),
|
|
420
|
+
id: (0, node_crypto.randomUUID)(),
|
|
421
|
+
usedAt: null,
|
|
422
|
+
accountId: null
|
|
423
|
+
};
|
|
424
|
+
invites.set(record.id, record);
|
|
425
|
+
return copy(record);
|
|
426
|
+
},
|
|
427
|
+
async findByTokenHash(tokenHash) {
|
|
428
|
+
for (const invite of invites.values()) if (invite.tokenHash === tokenHash) return copy(invite);
|
|
429
|
+
return null;
|
|
430
|
+
},
|
|
431
|
+
async list(listOptions = {}) {
|
|
432
|
+
return [...invites.values()].filter((invite) => listOptions.includeUsed === true || invite.usedAt === null).sort((a, b) => b.createdAt - a.createdAt).map(copy);
|
|
433
|
+
},
|
|
434
|
+
async markUsed(id, at, accountId) {
|
|
435
|
+
const invite = invites.get(id);
|
|
436
|
+
if (!invite || invite.usedAt !== null || at >= invite.expiresAt) return false;
|
|
437
|
+
invites.set(id, {
|
|
438
|
+
...invite,
|
|
439
|
+
usedAt: at,
|
|
440
|
+
accountId
|
|
441
|
+
});
|
|
442
|
+
return true;
|
|
443
|
+
},
|
|
444
|
+
async remove(id) {
|
|
445
|
+
return invites.delete(id);
|
|
446
|
+
},
|
|
447
|
+
async removeExpired(at) {
|
|
448
|
+
let removed = 0;
|
|
449
|
+
for (const invite of [...invites.values()]) if (invite.usedAt === null && invite.expiresAt < at) {
|
|
450
|
+
invites.delete(invite.id);
|
|
451
|
+
removed++;
|
|
452
|
+
}
|
|
453
|
+
return removed;
|
|
454
|
+
}
|
|
455
|
+
},
|
|
456
|
+
audit: {
|
|
457
|
+
async append(entry) {
|
|
458
|
+
const record = {
|
|
459
|
+
...copy(entry),
|
|
460
|
+
id: (0, node_crypto.randomUUID)()
|
|
461
|
+
};
|
|
462
|
+
audit.push(record);
|
|
463
|
+
return copy(record);
|
|
464
|
+
},
|
|
465
|
+
async list(filter) {
|
|
466
|
+
const limit = Math.max(1, Math.min(500, filter.limit));
|
|
467
|
+
return audit.filter((entry) => (filter.types === void 0 || filter.types.includes(entry.type)) && (filter.accountId === void 0 || entry.accountId === filter.accountId) && (filter.before === void 0 || entry.at < filter.before)).sort((a, b) => b.at - a.at).slice(0, limit).map(copy);
|
|
468
|
+
},
|
|
469
|
+
async count(filter) {
|
|
470
|
+
return audit.filter((entry) => filter.types.includes(entry.type) && entry.at >= filter.since && (filter.accountId === void 0 || entry.accountId === filter.accountId) && (filter.ip === void 0 || entry.ip !== null && require_ip.rateLimitClient(entry.ip) === require_ip.rateLimitClient(filter.ip))).length;
|
|
471
|
+
},
|
|
472
|
+
async prune(before) {
|
|
473
|
+
const kept = audit.filter((entry) => entry.at >= before);
|
|
474
|
+
const removed = audit.length - kept.length;
|
|
475
|
+
audit.splice(0, audit.length, ...kept);
|
|
476
|
+
return removed;
|
|
477
|
+
}
|
|
478
|
+
},
|
|
479
|
+
state: {
|
|
480
|
+
async read() {
|
|
481
|
+
return copy(state ?? defaultStateRecord(now()));
|
|
482
|
+
},
|
|
483
|
+
async update(expectedVersion, patch) {
|
|
484
|
+
const current = state ?? defaultStateRecord(now());
|
|
485
|
+
if (current.version !== expectedVersion) return null;
|
|
486
|
+
state = {
|
|
487
|
+
...current,
|
|
488
|
+
...copy(patch),
|
|
489
|
+
updatedAt: now(),
|
|
490
|
+
version: current.version + 1
|
|
491
|
+
};
|
|
492
|
+
return copy(state);
|
|
493
|
+
}
|
|
494
|
+
},
|
|
495
|
+
samples: {
|
|
496
|
+
async insert(list) {
|
|
497
|
+
for (const sample of list) samples.set(sample.id, copy(sample));
|
|
498
|
+
},
|
|
499
|
+
async list(filter) {
|
|
500
|
+
const limit = Math.max(1, Math.min(1e3, filter.limit));
|
|
501
|
+
return [...samples.values()].map((sample) => sample.summary).filter((summary) => sampleMatches(summary, filter)).sort((a, b) => b.startedAt - a.startedAt).slice(0, limit).map(copy);
|
|
502
|
+
},
|
|
503
|
+
async get(id) {
|
|
504
|
+
const sample = samples.get(id);
|
|
505
|
+
return sample ? copy(sample) : null;
|
|
506
|
+
},
|
|
507
|
+
async prune(before) {
|
|
508
|
+
let removed = 0;
|
|
509
|
+
for (const sample of [...samples.values()]) if (sample.startedAt < before) {
|
|
510
|
+
samples.delete(sample.id);
|
|
511
|
+
removed++;
|
|
512
|
+
}
|
|
513
|
+
return removed;
|
|
514
|
+
},
|
|
515
|
+
async clear() {
|
|
516
|
+
const removed = samples.size;
|
|
517
|
+
samples.clear();
|
|
518
|
+
return removed;
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
reports: {
|
|
522
|
+
async write(report) {
|
|
523
|
+
reports.set(report.instance.id, copy(report));
|
|
524
|
+
},
|
|
525
|
+
async list(seenSince) {
|
|
526
|
+
return [...reports.values()].filter((report) => report.at >= seenSince).sort((a, b) => b.at - a.at).map(copy);
|
|
527
|
+
},
|
|
528
|
+
async prune(seenBefore) {
|
|
529
|
+
let removed = 0;
|
|
530
|
+
for (const report of [...reports.values()]) if (report.at < seenBefore) {
|
|
531
|
+
reports.delete(report.instance.id);
|
|
532
|
+
removed++;
|
|
533
|
+
}
|
|
534
|
+
return removed;
|
|
535
|
+
},
|
|
536
|
+
async remove(instanceId) {
|
|
537
|
+
return reports.delete(instanceId);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
//#endregion
|
|
544
|
+
//#region ../../packages/devtools/src/production/store/cascade-store.ts
|
|
545
|
+
/** The most rows scanned for a sample filter the database cannot apply (route, text). */
|
|
546
|
+
const SAMPLE_SCAN_LIMIT = 5e3;
|
|
547
|
+
/** A plain-row query (no model instances). */
|
|
548
|
+
function rows(table) {
|
|
549
|
+
return table.query().lean();
|
|
550
|
+
}
|
|
551
|
+
/** A query for counting and deleting. */
|
|
552
|
+
function query(table) {
|
|
553
|
+
return table.query();
|
|
554
|
+
}
|
|
555
|
+
function byId(table, id) {
|
|
556
|
+
return rows(table).where("id", "=", id).first();
|
|
557
|
+
}
|
|
558
|
+
async function insert(table, row) {
|
|
559
|
+
await table.create(row);
|
|
560
|
+
}
|
|
561
|
+
async function removeWhere(table, field, value) {
|
|
562
|
+
return await query(table).where(field, "=", value).delete() > 0;
|
|
563
|
+
}
|
|
564
|
+
/** Applies `$set` to the row only while its `version` still equals `expected`. */
|
|
565
|
+
async function compareAndSet(table, id, expected, set) {
|
|
566
|
+
return await table.atomic({
|
|
567
|
+
id,
|
|
568
|
+
version: expected
|
|
569
|
+
}, { $set: set }) > 0;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* The production `DevtoolsStore`: the app's database through
|
|
573
|
+
* `@warlock.js/cascade` (MongoDB or SQL), using the models in `./models` and
|
|
574
|
+
* the tables `devtoolsMigrations` creates. Imports cascade lazily so loading
|
|
575
|
+
* this module never requires it.
|
|
576
|
+
*
|
|
577
|
+
* Throws `DevtoolsProductionConfigError("DT005")` when cascade is not
|
|
578
|
+
* installed or has no connection.
|
|
579
|
+
*/
|
|
580
|
+
async function createCascadeStore(options = {}) {
|
|
581
|
+
const now = options.now ?? Date.now;
|
|
582
|
+
let models;
|
|
583
|
+
try {
|
|
584
|
+
models = await Promise.resolve().then(() => require("./migrations-w7GMsrQw.cjs")).then((n) => n.models_exports);
|
|
585
|
+
models.DevtoolsAccountRow.getDataSource();
|
|
586
|
+
} catch (error) {
|
|
587
|
+
throw new require_errors.DevtoolsProductionConfigError("DT005", error instanceof Error ? `(${error.message})` : void 0);
|
|
588
|
+
}
|
|
589
|
+
const { DevtoolsAccountRow: Accounts, DevtoolsSessionRow: Sessions, DevtoolsInviteRow: Invites, DevtoolsAuditRow: Audit, DevtoolsStateRow: State, DevtoolsSampleRow: Samples, DevtoolsReportRow: Reports } = models;
|
|
590
|
+
const tables = [
|
|
591
|
+
Accounts,
|
|
592
|
+
Sessions,
|
|
593
|
+
Invites,
|
|
594
|
+
Audit,
|
|
595
|
+
State,
|
|
596
|
+
Samples,
|
|
597
|
+
Reports
|
|
598
|
+
];
|
|
599
|
+
const accountById = async (id) => {
|
|
600
|
+
const row = await byId(Accounts, id);
|
|
601
|
+
return row ? rowToAccount(row) : null;
|
|
602
|
+
};
|
|
603
|
+
const sessionById = async (id) => {
|
|
604
|
+
const row = await byId(Sessions, id);
|
|
605
|
+
return row ? rowToSession(row) : null;
|
|
606
|
+
};
|
|
607
|
+
return {
|
|
608
|
+
async verify() {
|
|
609
|
+
const blueprint = Accounts.getDriver().blueprint;
|
|
610
|
+
const missing = [];
|
|
611
|
+
for (const table of tables) if (!await blueprint.tableExists(table.table)) missing.push(table.table);
|
|
612
|
+
if (missing.length > 0) throw new require_errors.DevtoolsProductionConfigError("DT008", `(missing: ${missing.join(", ")})`);
|
|
613
|
+
},
|
|
614
|
+
accounts: {
|
|
615
|
+
async findByEmail(email) {
|
|
616
|
+
const row = await rows(Accounts).where("email", "=", email).first();
|
|
617
|
+
return row ? rowToAccount(row) : null;
|
|
618
|
+
},
|
|
619
|
+
findById: accountById,
|
|
620
|
+
async list() {
|
|
621
|
+
return (await rows(Accounts).orderBy("created_at", "asc").get()).map(rowToAccount);
|
|
622
|
+
},
|
|
623
|
+
async countAdmins() {
|
|
624
|
+
return query(Accounts).where("role", "=", "admin").count();
|
|
625
|
+
},
|
|
626
|
+
async create(input) {
|
|
627
|
+
const at = now();
|
|
628
|
+
const record = {
|
|
629
|
+
...structuredClone(input),
|
|
630
|
+
id: (0, node_crypto.randomUUID)(),
|
|
631
|
+
createdAt: at,
|
|
632
|
+
updatedAt: at,
|
|
633
|
+
version: 1
|
|
634
|
+
};
|
|
635
|
+
if (await rows(Accounts).where("email", "=", record.email).first()) throw new require_errors.DevtoolsStoreConflictError("email");
|
|
636
|
+
try {
|
|
637
|
+
await insert(Accounts, accountToRow(record));
|
|
638
|
+
} catch (error) {
|
|
639
|
+
if (await rows(Accounts).where("email", "=", record.email).first()) throw new require_errors.DevtoolsStoreConflictError("email");
|
|
640
|
+
throw error;
|
|
641
|
+
}
|
|
642
|
+
return record;
|
|
643
|
+
},
|
|
644
|
+
async update(id, expectedVersion, patch) {
|
|
645
|
+
const current = await accountById(id);
|
|
646
|
+
if (!current || current.version !== expectedVersion) return null;
|
|
647
|
+
if (patch.email !== void 0 && patch.email !== current.email) {
|
|
648
|
+
if (await rows(Accounts).where("email", "=", patch.email).first()) throw new require_errors.DevtoolsStoreConflictError("email");
|
|
649
|
+
}
|
|
650
|
+
const set = {
|
|
651
|
+
...accountPatchToRow(structuredClone(patch)),
|
|
652
|
+
updated_at: now(),
|
|
653
|
+
version: expectedVersion + 1
|
|
654
|
+
};
|
|
655
|
+
let won;
|
|
656
|
+
try {
|
|
657
|
+
won = await compareAndSet(Accounts, id, expectedVersion, set);
|
|
658
|
+
} catch (error) {
|
|
659
|
+
if (patch.email !== void 0 && await rows(Accounts).where("email", "=", patch.email).first()) throw new require_errors.DevtoolsStoreConflictError("email");
|
|
660
|
+
throw error;
|
|
661
|
+
}
|
|
662
|
+
return won ? accountById(id) : null;
|
|
663
|
+
},
|
|
664
|
+
async remove(id) {
|
|
665
|
+
return removeWhere(Accounts, "id", id);
|
|
666
|
+
}
|
|
667
|
+
},
|
|
668
|
+
sessions: {
|
|
669
|
+
async create(input) {
|
|
670
|
+
const record = {
|
|
671
|
+
...structuredClone(input),
|
|
672
|
+
id: (0, node_crypto.randomUUID)(),
|
|
673
|
+
version: 1
|
|
674
|
+
};
|
|
675
|
+
await insert(Sessions, sessionToRow(record));
|
|
676
|
+
return record;
|
|
677
|
+
},
|
|
678
|
+
async findByTokenHash(tokenHash) {
|
|
679
|
+
const row = await rows(Sessions).where("token_hash", "=", tokenHash).first();
|
|
680
|
+
return row ? rowToSession(row) : null;
|
|
681
|
+
},
|
|
682
|
+
async listForAccount(accountId) {
|
|
683
|
+
return (await rows(Sessions).where("account_id", "=", accountId).orderBy("created_at", "desc").get()).map(rowToSession);
|
|
684
|
+
},
|
|
685
|
+
async update(id, expectedVersion, patch) {
|
|
686
|
+
const set = {
|
|
687
|
+
...sessionPatchToRow(structuredClone(patch)),
|
|
688
|
+
version: expectedVersion + 1
|
|
689
|
+
};
|
|
690
|
+
if (!await compareAndSet(Sessions, id, expectedVersion, set)) return null;
|
|
691
|
+
return sessionById(id);
|
|
692
|
+
},
|
|
693
|
+
async remove(id) {
|
|
694
|
+
return removeWhere(Sessions, "id", id);
|
|
695
|
+
},
|
|
696
|
+
async removeForAccount(accountId, exceptId) {
|
|
697
|
+
const target = query(Sessions).where("account_id", "=", accountId);
|
|
698
|
+
if (exceptId !== void 0) target.where("id", "!=", exceptId);
|
|
699
|
+
return target.delete();
|
|
700
|
+
},
|
|
701
|
+
async removeExpired(at) {
|
|
702
|
+
return query(Sessions).where("expires_at", "<", at).delete();
|
|
703
|
+
}
|
|
704
|
+
},
|
|
705
|
+
invites: {
|
|
706
|
+
async create(input) {
|
|
707
|
+
const record = {
|
|
708
|
+
...structuredClone(input),
|
|
709
|
+
id: (0, node_crypto.randomUUID)(),
|
|
710
|
+
usedAt: null,
|
|
711
|
+
accountId: null
|
|
712
|
+
};
|
|
713
|
+
await insert(Invites, inviteToRow(record));
|
|
714
|
+
return record;
|
|
715
|
+
},
|
|
716
|
+
async findByTokenHash(tokenHash) {
|
|
717
|
+
const row = await rows(Invites).where("token_hash", "=", tokenHash).first();
|
|
718
|
+
return row ? rowToInvite(row) : null;
|
|
719
|
+
},
|
|
720
|
+
async list(listOptions = {}) {
|
|
721
|
+
const target = rows(Invites);
|
|
722
|
+
if (listOptions.includeUsed !== true) target.whereNull("used_at");
|
|
723
|
+
return (await target.orderBy("created_at", "desc").get()).map(rowToInvite);
|
|
724
|
+
},
|
|
725
|
+
async markUsed(id, at, accountId) {
|
|
726
|
+
return await Invites.atomic({
|
|
727
|
+
id,
|
|
728
|
+
used_at: null,
|
|
729
|
+
expires_at: { $gt: at }
|
|
730
|
+
}, { $set: {
|
|
731
|
+
used_at: at,
|
|
732
|
+
account_id: accountId
|
|
733
|
+
} }, { trustedFilter: true }) > 0;
|
|
734
|
+
},
|
|
735
|
+
async remove(id) {
|
|
736
|
+
return removeWhere(Invites, "id", id);
|
|
737
|
+
},
|
|
738
|
+
async removeExpired(at) {
|
|
739
|
+
return query(Invites).whereNull("used_at").where("expires_at", "<", at).delete();
|
|
740
|
+
}
|
|
741
|
+
},
|
|
742
|
+
audit: {
|
|
743
|
+
async append(entry) {
|
|
744
|
+
const record = {
|
|
745
|
+
...structuredClone(entry),
|
|
746
|
+
id: (0, node_crypto.randomUUID)()
|
|
747
|
+
};
|
|
748
|
+
await insert(Audit, auditToRow(record));
|
|
749
|
+
return record;
|
|
750
|
+
},
|
|
751
|
+
async list(filter) {
|
|
752
|
+
const limit = Math.max(1, Math.min(500, filter.limit));
|
|
753
|
+
const target = rows(Audit);
|
|
754
|
+
if (filter.types !== void 0) target.whereIn("type", [...filter.types]);
|
|
755
|
+
if (filter.accountId !== void 0) target.where("account_id", "=", filter.accountId);
|
|
756
|
+
if (filter.before !== void 0) target.where("occurred_at", "<", filter.before);
|
|
757
|
+
return (await target.orderBy("occurred_at", "desc").limit(limit).get()).map(rowToAudit);
|
|
758
|
+
},
|
|
759
|
+
async count(filter) {
|
|
760
|
+
const target = query(Audit).whereIn("type", [...filter.types]).where("occurred_at", ">=", filter.since);
|
|
761
|
+
if (filter.accountId !== void 0) target.where("account_id", "=", filter.accountId);
|
|
762
|
+
if (filter.ip !== void 0) target.where("ip_bucket", "=", require_ip.rateLimitClient(filter.ip));
|
|
763
|
+
return target.count();
|
|
764
|
+
},
|
|
765
|
+
async prune(before) {
|
|
766
|
+
return query(Audit).where("occurred_at", "<", before).delete();
|
|
767
|
+
}
|
|
768
|
+
},
|
|
769
|
+
state: {
|
|
770
|
+
async read() {
|
|
771
|
+
const row = await byId(State, "state");
|
|
772
|
+
return row ? rowToState(row) : defaultStateRecord(now());
|
|
773
|
+
},
|
|
774
|
+
async update(expectedVersion, patch) {
|
|
775
|
+
if (!await byId(State, "state")) {
|
|
776
|
+
if (expectedVersion !== 0) return null;
|
|
777
|
+
const record = {
|
|
778
|
+
...defaultStateRecord(now()),
|
|
779
|
+
...structuredClone(patch),
|
|
780
|
+
updatedAt: now(),
|
|
781
|
+
version: 1
|
|
782
|
+
};
|
|
783
|
+
try {
|
|
784
|
+
await insert(State, {
|
|
785
|
+
id: "state",
|
|
786
|
+
...stateToRow(record)
|
|
787
|
+
});
|
|
788
|
+
} catch {
|
|
789
|
+
return null;
|
|
790
|
+
}
|
|
791
|
+
return record;
|
|
792
|
+
}
|
|
793
|
+
const set = {
|
|
794
|
+
...statePatchToRow(structuredClone(patch)),
|
|
795
|
+
updated_at: now(),
|
|
796
|
+
version: expectedVersion + 1
|
|
797
|
+
};
|
|
798
|
+
if (!await compareAndSet(State, "state", expectedVersion, set)) return null;
|
|
799
|
+
const next = await byId(State, "state");
|
|
800
|
+
return next ? rowToState(next) : null;
|
|
801
|
+
}
|
|
802
|
+
},
|
|
803
|
+
samples: {
|
|
804
|
+
async insert(list) {
|
|
805
|
+
for (const sample of list) {
|
|
806
|
+
const { id, ...data } = sampleToRow(structuredClone(sample));
|
|
807
|
+
await Samples.upsert({ id }, data);
|
|
808
|
+
}
|
|
809
|
+
},
|
|
810
|
+
async list(filter) {
|
|
811
|
+
const limit = Math.max(1, Math.min(1e3, filter.limit));
|
|
812
|
+
const target = rows(Samples).select(["summary"]);
|
|
813
|
+
const exact = !(filter.route !== void 0 || filter.q !== void 0);
|
|
814
|
+
if (filter.status !== void 0) {
|
|
815
|
+
const status = filter.status.trim().toLowerCase();
|
|
816
|
+
if (/^[1-5]xx$/.test(status)) {
|
|
817
|
+
const base = Number(status[0]) * 100;
|
|
818
|
+
target.where("status", ">=", base).where("status", "<", base + 100);
|
|
819
|
+
} else if (/^\d+$/.test(status) && String(Number(status)) === status) target.where("status", "=", Number(status));
|
|
820
|
+
else return [];
|
|
821
|
+
}
|
|
822
|
+
if (filter.method !== void 0) target.where("method", "=", filter.method.toUpperCase());
|
|
823
|
+
if (filter.since !== void 0) target.where("started_at", ">=", filter.since);
|
|
824
|
+
if (filter.until !== void 0) target.where("started_at", "<=", filter.until);
|
|
825
|
+
if (filter.instance !== void 0) target.where("instance", "=", filter.instance);
|
|
826
|
+
return (await target.orderBy("started_at", "desc").limit(exact ? limit : SAMPLE_SCAN_LIMIT).get()).map(rowToSampleSummary).filter((summary) => sampleMatches(summary, filter)).slice(0, limit);
|
|
827
|
+
},
|
|
828
|
+
async get(id) {
|
|
829
|
+
const row = await byId(Samples, id);
|
|
830
|
+
return row ? rowToSample(row) : null;
|
|
831
|
+
},
|
|
832
|
+
async prune(before) {
|
|
833
|
+
return query(Samples).where("started_at", "<", before).delete();
|
|
834
|
+
},
|
|
835
|
+
async clear() {
|
|
836
|
+
return query(Samples).where("started_at", ">=", 0).delete();
|
|
837
|
+
}
|
|
838
|
+
},
|
|
839
|
+
reports: {
|
|
840
|
+
async write(report) {
|
|
841
|
+
const { id, ...data } = reportToRow(report);
|
|
842
|
+
await Reports.upsert({ id }, data);
|
|
843
|
+
},
|
|
844
|
+
async list(seenSince) {
|
|
845
|
+
return (await rows(Reports).where("seen_at", ">=", seenSince).orderBy("seen_at", "desc").get()).map(rowToReport);
|
|
846
|
+
},
|
|
847
|
+
async prune(seenBefore) {
|
|
848
|
+
return query(Reports).where("seen_at", "<", seenBefore).delete();
|
|
849
|
+
},
|
|
850
|
+
async remove(instanceId) {
|
|
851
|
+
return removeWhere(Reports, "id", instanceId);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
//#endregion
|
|
858
|
+
exports.createCascadeStore = createCascadeStore;
|
|
859
|
+
exports.createMemoryStore = createMemoryStore;
|
|
860
|
+
exports.defaultStateRecord = defaultStateRecord;
|
|
861
|
+
exports.sampleMatches = sampleMatches;
|
|
862
|
+
exports.sampleStatusMatches = sampleStatusMatches;
|
|
863
|
+
//# sourceMappingURL=cascade-store-pHjKeSFm.cjs.map
|