@gadicc/loom 1.33.1 → 1.35.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/README.md +108 -41
- package/esm/src/apiKeys/authorize.d.ts.map +1 -1
- package/esm/src/apiKeys/authorize.js +71 -0
- package/esm/src/apiKeys/betterAuth.d.ts +123 -0
- package/esm/src/apiKeys/betterAuth.d.ts.map +1 -0
- package/esm/src/apiKeys/betterAuth.js +164 -0
- package/esm/src/apiKeys/credentials.d.ts +37 -2
- package/esm/src/apiKeys/credentials.d.ts.map +1 -1
- package/esm/src/apiKeys/credentials.js +69 -8
- package/esm/src/apiKeys/lifecycle.d.ts +41 -0
- package/esm/src/apiKeys/lifecycle.d.ts.map +1 -0
- package/esm/src/apiKeys/lifecycle.js +6 -0
- package/esm/src/apiKeys/limits.d.ts +132 -0
- package/esm/src/apiKeys/limits.d.ts.map +1 -0
- package/esm/src/apiKeys/limits.js +246 -0
- package/esm/src/apiKeys/mod.d.ts +4 -0
- package/esm/src/apiKeys/mod.d.ts.map +1 -1
- package/esm/src/apiKeys/mod.js +4 -0
- package/esm/src/apiKeys/permissions.d.ts +56 -0
- package/esm/src/apiKeys/permissions.d.ts.map +1 -0
- package/esm/src/apiKeys/permissions.js +128 -0
- package/esm/src/apiKeys/policy.d.ts +3 -1
- package/esm/src/apiKeys/policy.d.ts.map +1 -1
- package/esm/src/apiKeys/policy.js +3 -1
- package/esm/src/apiKeys/types.d.ts +68 -1
- package/esm/src/apiKeys/types.d.ts.map +1 -1
- package/esm/src/cli/localDb.d.ts +28 -0
- package/esm/src/cli/localDb.d.ts.map +1 -0
- package/esm/src/cli/localDb.js +366 -0
- package/esm/src/cli/localDevLock.d.ts +97 -0
- package/esm/src/cli/localDevLock.d.ts.map +1 -0
- package/esm/src/cli/localDevLock.js +312 -0
- package/esm/src/cli/localDevPackage.d.ts +172 -0
- package/esm/src/cli/localDevPackage.d.ts.map +1 -0
- package/esm/src/cli/localDevPackage.js +617 -0
- package/esm/src/cli/migrationEnv.d.ts +19 -0
- package/esm/src/cli/migrationEnv.d.ts.map +1 -1
- package/esm/src/cli/migrationEnv.js +44 -1
- package/esm/src/cli/mod.d.ts +69 -4
- package/esm/src/cli/mod.d.ts.map +1 -1
- package/esm/src/cli/mod.js +2822 -419
- package/esm/src/cli/projectTooling.d.ts +19 -1
- package/esm/src/cli/projectTooling.d.ts.map +1 -1
- package/esm/src/cli/projectTooling.js +142 -12
- package/esm/src/mui/apiKeys.d.ts +123 -17
- package/esm/src/mui/apiKeys.d.ts.map +1 -1
- package/esm/src/mui/apiKeys.js +219 -78
- package/esm/src/mui/apiKeysView.d.ts +145 -0
- package/esm/src/mui/apiKeysView.d.ts.map +1 -1
- package/esm/src/mui/apiKeysView.js +278 -0
- package/esm/src/next/apiKeys/mod.d.ts +8 -1
- package/esm/src/next/apiKeys/mod.d.ts.map +1 -1
- package/esm/src/next/apiKeys/mod.js +5 -2
- package/package.json +2 -6
- package/script/src/apiKeys/authorize.d.ts.map +1 -1
- package/script/src/apiKeys/authorize.js +71 -0
- package/script/src/apiKeys/betterAuth.d.ts +123 -0
- package/script/src/apiKeys/betterAuth.d.ts.map +1 -0
- package/script/src/apiKeys/betterAuth.js +169 -0
- package/script/src/apiKeys/credentials.d.ts +37 -2
- package/script/src/apiKeys/credentials.d.ts.map +1 -1
- package/script/src/apiKeys/credentials.js +71 -8
- package/script/src/apiKeys/lifecycle.d.ts +41 -0
- package/script/src/apiKeys/lifecycle.d.ts.map +1 -0
- package/script/src/apiKeys/lifecycle.js +7 -0
- package/script/src/apiKeys/limits.d.ts +132 -0
- package/script/src/apiKeys/limits.d.ts.map +1 -0
- package/script/src/apiKeys/limits.js +254 -0
- package/script/src/apiKeys/mod.d.ts +4 -0
- package/script/src/apiKeys/mod.d.ts.map +1 -1
- package/script/src/apiKeys/mod.js +4 -0
- package/script/src/apiKeys/permissions.d.ts +56 -0
- package/script/src/apiKeys/permissions.d.ts.map +1 -0
- package/script/src/apiKeys/permissions.js +136 -0
- package/script/src/apiKeys/policy.d.ts +3 -1
- package/script/src/apiKeys/policy.d.ts.map +1 -1
- package/script/src/apiKeys/policy.js +3 -1
- package/script/src/apiKeys/types.d.ts +68 -1
- package/script/src/apiKeys/types.d.ts.map +1 -1
- package/script/src/cli/localDb.d.ts +28 -0
- package/script/src/cli/localDb.d.ts.map +1 -0
- package/script/src/cli/localDb.js +370 -0
- package/script/src/cli/localDevLock.d.ts +97 -0
- package/script/src/cli/localDevLock.d.ts.map +1 -0
- package/script/src/cli/localDevLock.js +320 -0
- package/script/src/cli/localDevPackage.d.ts +172 -0
- package/script/src/cli/localDevPackage.d.ts.map +1 -0
- package/script/src/cli/localDevPackage.js +635 -0
- package/script/src/cli/migrationEnv.d.ts +19 -0
- package/script/src/cli/migrationEnv.d.ts.map +1 -1
- package/script/src/cli/migrationEnv.js +48 -1
- package/script/src/cli/mod.d.ts +69 -4
- package/script/src/cli/mod.d.ts.map +1 -1
- package/script/src/cli/mod.js +2823 -419
- package/script/src/cli/projectTooling.d.ts +19 -1
- package/script/src/cli/projectTooling.d.ts.map +1 -1
- package/script/src/cli/projectTooling.js +176 -12
- package/script/src/mui/apiKeys.d.ts +123 -17
- package/script/src/mui/apiKeys.d.ts.map +1 -1
- package/script/src/mui/apiKeys.js +220 -77
- package/script/src/mui/apiKeysView.d.ts +145 -0
- package/script/src/mui/apiKeysView.d.ts.map +1 -1
- package/script/src/mui/apiKeysView.js +291 -0
- package/script/src/next/apiKeys/mod.d.ts +8 -1
- package/script/src/next/apiKeys/mod.d.ts.map +1 -1
- package/script/src/next/apiKeys/mod.js +5 -2
- package/skills/loom/SKILL.md +116 -18
- package/skills/loom-api-keys/SKILL.md +101 -7
- package/skills/loom-auth/SKILL.md +9 -0
- package/skills/loom-db/SKILL.md +33 -1
|
@@ -1,3 +1,49 @@
|
|
|
1
|
+
import { API_KEY_SECONDS_PER_DAY, apiKeyLimitMessages, resolveApiKeyExpiresIn, validateApiKeyName, } from "../apiKeys/limits.js";
|
|
2
|
+
/** Shown for a reason code that `apiKeyAuditReasonLabel` does not know. */
|
|
3
|
+
export const API_KEY_AUDIT_OTHER_REASON_LABEL = "Other reason";
|
|
4
|
+
/**
|
|
5
|
+
* Short user-facing labels for every reason code Loom records. `satisfies`
|
|
6
|
+
* makes a new code without a label fail type-checking.
|
|
7
|
+
*/
|
|
8
|
+
const API_KEY_AUDIT_REASON_LABELS = {
|
|
9
|
+
ambiguous_credentials: "More than one key sent",
|
|
10
|
+
audit_unavailable: "Audit unavailable",
|
|
11
|
+
credential_malformed: "Malformed key",
|
|
12
|
+
credential_missing: "No key sent",
|
|
13
|
+
credential_rejected: "Credential rejected",
|
|
14
|
+
credential_rejection_error: "Credential check failed",
|
|
15
|
+
forbidden: "Denied by policy",
|
|
16
|
+
// Recorded on the completion event of a handler that threw.
|
|
17
|
+
handler_error: "Handler failed",
|
|
18
|
+
insufficient_permission: "Key lacks this scope",
|
|
19
|
+
invalid_credential: "Invalid, revoked, or expired key",
|
|
20
|
+
policy_error: "Policy check failed",
|
|
21
|
+
rate_limited: "Rate limited",
|
|
22
|
+
verification_error: "Verification failed",
|
|
23
|
+
};
|
|
24
|
+
function isKnownApiKeyAuditReasonCode(code) {
|
|
25
|
+
// An own-property check, so prototype names such as `toString` never match.
|
|
26
|
+
return Object.prototype.hasOwnProperty.call(API_KEY_AUDIT_REASON_LABELS, code);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Maps an audit reason code to a short label. Only codes Loom records have
|
|
30
|
+
* labels. Any other code shows `API_KEY_AUDIT_OTHER_REASON_LABEL` and is never
|
|
31
|
+
* displayed itself: a stored code is not known to be free of secrets, and a
|
|
32
|
+
* Better Auth key without a prefix looks like any identifier. No code yields
|
|
33
|
+
* `null`; label an app-specific code by passing `reason` instead.
|
|
34
|
+
*/
|
|
35
|
+
export function apiKeyAuditReasonLabel(code) {
|
|
36
|
+
if (typeof code !== "string" || !code.trim())
|
|
37
|
+
return null;
|
|
38
|
+
return isKnownApiKeyAuditReasonCode(code)
|
|
39
|
+
? API_KEY_AUDIT_REASON_LABELS[code]
|
|
40
|
+
: API_KEY_AUDIT_OTHER_REASON_LABEL;
|
|
41
|
+
}
|
|
42
|
+
/** The reason to show for an audit row: its label, else its code's label. */
|
|
43
|
+
export function getApiKeyAuditReason(row) {
|
|
44
|
+
const reason = typeof row.reason === "string" ? row.reason.trim() : "";
|
|
45
|
+
return reason ? reason : apiKeyAuditReasonLabel(row.reasonCode);
|
|
46
|
+
}
|
|
1
47
|
/** Converts an ISO alpha-2 country code to its Unicode regional flag. */
|
|
2
48
|
export function countryCodeToFlagEmoji(countryCode) {
|
|
3
49
|
const normalized = countryCode?.trim().toUpperCase();
|
|
@@ -32,3 +78,235 @@ export function getApiKeyVisibleColumnIds(admin = false) {
|
|
|
32
78
|
"actions",
|
|
33
79
|
];
|
|
34
80
|
}
|
|
81
|
+
export const API_KEY_CREATE_FAILED_MESSAGE = "The key could not be created.";
|
|
82
|
+
export const API_KEY_RENAME_FAILED_MESSAGE = "The key could not be renamed.";
|
|
83
|
+
export const API_KEY_REVOKE_FAILED_MESSAGE = "The key could not be revoked.";
|
|
84
|
+
/** Expiry presets offered by the create dialog when none are configured. */
|
|
85
|
+
export const DEFAULT_API_KEY_EXPIRY_PRESET_DAYS = Object
|
|
86
|
+
.freeze([7, 30]);
|
|
87
|
+
function isRecord(value) {
|
|
88
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
89
|
+
}
|
|
90
|
+
function failure(message, fallback) {
|
|
91
|
+
return {
|
|
92
|
+
message: typeof message === "string" && message.trim() ? message : fallback,
|
|
93
|
+
ok: false,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function isCreateResult(value) {
|
|
97
|
+
return isRecord(value) && typeof value.key === "string" &&
|
|
98
|
+
value.key.length > 0 && typeof value.name === "string";
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Normalizes what an `onCreate` callback resolved to.
|
|
102
|
+
*
|
|
103
|
+
* A value whose `ok` is a boolean is the result form; anything else is the
|
|
104
|
+
* original `ApiKeyCreateResult` form. A success without a usable key and name
|
|
105
|
+
* becomes a failure, so the secret dialog never opens empty.
|
|
106
|
+
*/
|
|
107
|
+
export function resolveApiKeyCreateActionResult(value) {
|
|
108
|
+
if (isRecord(value) && typeof value.ok === "boolean") {
|
|
109
|
+
if (!value.ok)
|
|
110
|
+
return failure(value.message, API_KEY_CREATE_FAILED_MESSAGE);
|
|
111
|
+
if (isCreateResult(value.created)) {
|
|
112
|
+
return { created: value.created, ok: true };
|
|
113
|
+
}
|
|
114
|
+
// An original-form result that happens to carry `ok: true` still holds
|
|
115
|
+
// the one-time secret; never drop it.
|
|
116
|
+
if (value.created === undefined && isCreateResult(value)) {
|
|
117
|
+
return { created: value, ok: true };
|
|
118
|
+
}
|
|
119
|
+
return failure(undefined, API_KEY_CREATE_FAILED_MESSAGE);
|
|
120
|
+
}
|
|
121
|
+
return isCreateResult(value)
|
|
122
|
+
? { created: value, ok: true }
|
|
123
|
+
: failure(undefined, API_KEY_CREATE_FAILED_MESSAGE);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Normalizes what an `onRename` or `onRevoke` callback resolved to.
|
|
127
|
+
*
|
|
128
|
+
* A value whose `ok` is a boolean is the result form. Anything else, such as
|
|
129
|
+
* the `void` of the original callback form, is a success, as before.
|
|
130
|
+
*/
|
|
131
|
+
export function resolveApiKeyMutationResult(value, fallbackMessage) {
|
|
132
|
+
if (isRecord(value) && typeof value.ok === "boolean") {
|
|
133
|
+
return value.ok ? { ok: true } : failure(value.message, fallbackMessage);
|
|
134
|
+
}
|
|
135
|
+
return { ok: true };
|
|
136
|
+
}
|
|
137
|
+
export const API_KEY_NO_TRANSPORT_MESSAGE = "This app does not currently accept API keys in requests.";
|
|
138
|
+
function transportLabel(transport, description) {
|
|
139
|
+
switch (transport) {
|
|
140
|
+
case "authorization-bearer":
|
|
141
|
+
return "the Authorization header (Bearer <key>)";
|
|
142
|
+
case "x-api-key":
|
|
143
|
+
return `the ${description.headerName} header`;
|
|
144
|
+
case "query":
|
|
145
|
+
return `the ${description.queryName} query parameter`;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function joinList(items) {
|
|
149
|
+
return items.length < 3
|
|
150
|
+
? items.join(" and ")
|
|
151
|
+
: `${items.slice(0, -1).join(", ")}, and ${items[items.length - 1]}`;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Builds transport guidance copy: the preferred transport, the other
|
|
155
|
+
* accepted ones, and a URL-leakage warning when query credentials are
|
|
156
|
+
* accepted. With no accepted transport it returns a plain fallback.
|
|
157
|
+
*/
|
|
158
|
+
export function getApiKeyTransportGuidanceCopy(description) {
|
|
159
|
+
const preferred = description.preferred;
|
|
160
|
+
if (preferred === null) {
|
|
161
|
+
return {
|
|
162
|
+
alternatives: null,
|
|
163
|
+
primary: API_KEY_NO_TRANSPORT_MESSAGE,
|
|
164
|
+
queryWarning: null,
|
|
165
|
+
severity: "warning",
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
const others = description.accepted
|
|
169
|
+
.filter((transport) => transport !== preferred)
|
|
170
|
+
.map((transport) => transportLabel(transport, description));
|
|
171
|
+
const queryAccepted = description.queryName !== null;
|
|
172
|
+
return {
|
|
173
|
+
alternatives: others.length ? `Also accepted: ${joinList(others)}.` : null,
|
|
174
|
+
primary: `Send the key in ${transportLabel(preferred, description)}.`,
|
|
175
|
+
queryWarning: queryAccepted
|
|
176
|
+
? `Query-parameter keys can appear in browser history, access logs, copied links, and referrers. ${preferred === "query"
|
|
177
|
+
? "Do not share or log URLs that contain a key."
|
|
178
|
+
: "Use the query parameter only for clients that cannot send headers."}`
|
|
179
|
+
: null,
|
|
180
|
+
severity: queryAccepted ? "warning" : "info",
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/** The message to show for an error thrown by a lifecycle callback. */
|
|
184
|
+
export function resolveApiKeyThrownErrorMessage(error, mode, fallbackMessage) {
|
|
185
|
+
return mode === "show" && error instanceof Error && error.message
|
|
186
|
+
? error.message
|
|
187
|
+
: fallbackMessage;
|
|
188
|
+
}
|
|
189
|
+
function formatPresetDays(days) {
|
|
190
|
+
return days === 1 ? "1 day" : `${days} days`;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Lists the create dialog's expiry choices: "Never" when allowed, presets
|
|
194
|
+
* within the expiry limits (invalid and duplicate presets are dropped), and
|
|
195
|
+
* "Custom date".
|
|
196
|
+
*/
|
|
197
|
+
export function getApiKeyExpiryOptions(options = {}) {
|
|
198
|
+
const min = options.limits?.minExpiresInDays;
|
|
199
|
+
const max = options.limits?.maxExpiresInDays;
|
|
200
|
+
const presets = [
|
|
201
|
+
...new Set((options.expiryPresetDays ?? DEFAULT_API_KEY_EXPIRY_PRESET_DAYS).filter((days) => typeof days === "number" && Number.isFinite(days) && days > 0 &&
|
|
202
|
+
(min === undefined || days >= min) &&
|
|
203
|
+
(max === undefined || days <= max))),
|
|
204
|
+
];
|
|
205
|
+
return [
|
|
206
|
+
...(options.allowNoExpiry === false
|
|
207
|
+
? []
|
|
208
|
+
: [{ label: "Never", value: "never" }]),
|
|
209
|
+
...presets.map((days) => ({
|
|
210
|
+
label: formatPresetDays(days),
|
|
211
|
+
value: String(days),
|
|
212
|
+
})),
|
|
213
|
+
{ label: "Custom date", value: "custom" },
|
|
214
|
+
];
|
|
215
|
+
}
|
|
216
|
+
/** The create dialog's initial expiry choice: "Never" when allowed. */
|
|
217
|
+
export function getDefaultApiKeyExpiryChoice(options = {}) {
|
|
218
|
+
return getApiKeyExpiryOptions(options)[0].value;
|
|
219
|
+
}
|
|
220
|
+
const MINUTE_MS = 60_000;
|
|
221
|
+
/** Formats a time as a `datetime-local` input value in local time. */
|
|
222
|
+
export function toDateTimeLocalValue(time) {
|
|
223
|
+
const date = new Date(time);
|
|
224
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
225
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* `min`/`max` attributes for the custom expiry input, in local time.
|
|
229
|
+
*
|
|
230
|
+
* The input has minute precision, so `min` is rounded up to a whole minute and
|
|
231
|
+
* `max` down; both therefore lie within the limits. `min` is always in the
|
|
232
|
+
* future.
|
|
233
|
+
*/
|
|
234
|
+
export function getApiKeyCustomExpiryInputBounds(limits = {}, now = Date.now()) {
|
|
235
|
+
const dayMs = API_KEY_SECONDS_PER_DAY * 1000;
|
|
236
|
+
const minTime = Math.ceil((now + Math.max((limits.minExpiresInDays ?? 0) * dayMs, 1000)) /
|
|
237
|
+
MINUTE_MS) * MINUTE_MS;
|
|
238
|
+
if (limits.maxExpiresInDays === undefined) {
|
|
239
|
+
return { min: toDateTimeLocalValue(minTime) };
|
|
240
|
+
}
|
|
241
|
+
// When rounding crosses equal limits, the server tolerance still accepts
|
|
242
|
+
// the rounded-up minimum.
|
|
243
|
+
const maxTime = Math.max(Math.floor((now + limits.maxExpiresInDays * dayMs) / MINUTE_MS) *
|
|
244
|
+
MINUTE_MS, minTime);
|
|
245
|
+
return {
|
|
246
|
+
max: toDateTimeLocalValue(maxTime),
|
|
247
|
+
min: toDateTimeLocalValue(minTime),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Validates the create dialog's fields with the same validators and messages
|
|
252
|
+
* as server-side `validateApiKeyName` and `resolveApiKeyExpiresIn`, and builds
|
|
253
|
+
* the `onCreate` input. The server must still validate: this only spares the
|
|
254
|
+
* user a round trip.
|
|
255
|
+
*/
|
|
256
|
+
export function resolveApiKeyCreateInput(values, options = {}) {
|
|
257
|
+
const limits = options.limits ?? {};
|
|
258
|
+
const messages = apiKeyLimitMessages(limits);
|
|
259
|
+
const now = options.now ?? Date.now();
|
|
260
|
+
const name = validateApiKeyName(values.name, limits);
|
|
261
|
+
if (!name.ok)
|
|
262
|
+
return name;
|
|
263
|
+
if (!values.scopeIds.length) {
|
|
264
|
+
return { message: "Choose at least one scope.", ok: false };
|
|
265
|
+
}
|
|
266
|
+
let expiresAt;
|
|
267
|
+
if (values.expiry === "never") {
|
|
268
|
+
expiresAt = null;
|
|
269
|
+
}
|
|
270
|
+
else if (values.expiry === "custom") {
|
|
271
|
+
if (!values.customExpiry) {
|
|
272
|
+
return { message: messages.expiryRequired, ok: false };
|
|
273
|
+
}
|
|
274
|
+
// A `datetime-local` value has no zone, so it is read as local time.
|
|
275
|
+
const chosen = new Date(values.customExpiry).valueOf();
|
|
276
|
+
if (!Number.isFinite(chosen)) {
|
|
277
|
+
return { message: messages.expiryInvalid, ok: false };
|
|
278
|
+
}
|
|
279
|
+
expiresAt = new Date(chosen).toISOString();
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
const days = Number(values.expiry);
|
|
283
|
+
if (!Number.isFinite(days) || days <= 0) {
|
|
284
|
+
return { message: messages.expiryInvalid, ok: false };
|
|
285
|
+
}
|
|
286
|
+
expiresAt = new Date(now + days * API_KEY_SECONDS_PER_DAY * 1000)
|
|
287
|
+
.toISOString();
|
|
288
|
+
}
|
|
289
|
+
const expiry = resolveApiKeyExpiresIn(expiresAt, limits, {
|
|
290
|
+
allowNoExpiry: options.allowNoExpiry,
|
|
291
|
+
now,
|
|
292
|
+
});
|
|
293
|
+
if (!expiry.ok)
|
|
294
|
+
return expiry;
|
|
295
|
+
return {
|
|
296
|
+
ok: true,
|
|
297
|
+
value: { expiresAt, name: name.value, scopeIds: [...values.scopeIds] },
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Validates a rename with the server's name rules. `unchanged` is `true` when
|
|
302
|
+
* the trimmed name equals the current one, so no call is needed.
|
|
303
|
+
*/
|
|
304
|
+
export function resolveApiKeyRename(name, currentName, limits = {}) {
|
|
305
|
+
const result = validateApiKeyName(name, limits);
|
|
306
|
+
if (!result.ok)
|
|
307
|
+
return result;
|
|
308
|
+
return {
|
|
309
|
+
ok: true,
|
|
310
|
+
value: { name: result.value, unchanged: result.value === currentName },
|
|
311
|
+
};
|
|
312
|
+
}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import "../../../_dnt.polyfills.js";
|
|
2
|
-
import { type ApiKeyAuditRepository, type ApiKeyAuthorizationDescriptor, type ApiKeyAuthorizationResult, type ApiKeyCountryResolver, type ApiKeyCredentialOptions, type ApiKeyCredentialTransport, type ApiKeyPolicy, type ApiKeyPrincipal, type ApiKeyRequestAuditContext, type ApiKeyVerifier } from "../../apiKeys/mod.js";
|
|
2
|
+
import { type ApiKeyAuditRepository, type ApiKeyAuthorizationDescriptor, type ApiKeyAuthorizationResult, type ApiKeyCountryResolver, type ApiKeyCredentialOptions, type ApiKeyCredentialRejector, type ApiKeyCredentialTransport, type ApiKeyPolicy, type ApiKeyPrincipal, type ApiKeyRequestAuditContext, type ApiKeyVerifier } from "../../apiKeys/mod.js";
|
|
3
3
|
export interface ApiKeyRequestDependencies {
|
|
4
4
|
audit: ApiKeyAuditRepository;
|
|
5
5
|
credentialOptions?: ApiKeyCredentialOptions;
|
|
6
6
|
policy: ApiKeyPolicy;
|
|
7
|
+
/**
|
|
8
|
+
* Denies specific credential values before they are fingerprinted,
|
|
9
|
+
* verified, or attributed; see `AuthorizeApiKeyOptions.rejectCredential`.
|
|
10
|
+
* Applies to `authorizeApiKeyRequest`, `withApiKeyAuthorization`, and
|
|
11
|
+
* `authorizeSessionOrApiKeyRequest`.
|
|
12
|
+
*/
|
|
13
|
+
rejectCredential?: ApiKeyCredentialRejector;
|
|
7
14
|
/** Optional offline resolver used to snapshot an IP's ISO country code. */
|
|
8
15
|
resolveCountryCode?: ApiKeyCountryResolver;
|
|
9
16
|
requestContext?: ApiKeyRequestAuditContext | ((request: Request) => ApiKeyRequestAuditContext | Promise<ApiKeyRequestAuditContext>);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/src/next/apiKeys/mod.ts"],"names":[],"mappings":"AAAA,OAAO,4BAA4B,CAAC;AACpC,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,6BAA6B,EAClC,KAAK,yBAAyB,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/src/next/apiKeys/mod.ts"],"names":[],"mappings":"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"}
|
|
@@ -43,6 +43,7 @@ async function authorizeApiKeyRequestWithContext(request, descriptor, dependenci
|
|
|
43
43
|
credentialOptions: dependencies.credentialOptions,
|
|
44
44
|
descriptor,
|
|
45
45
|
policy: dependencies.policy,
|
|
46
|
+
rejectCredential: dependencies.rejectCredential,
|
|
46
47
|
request: requestContext,
|
|
47
48
|
source: {
|
|
48
49
|
headers: request.headers,
|
|
@@ -148,7 +149,7 @@ export function withApiKeyAuthorization(options, handler) {
|
|
|
148
149
|
try {
|
|
149
150
|
response = await handler(request, handlerAuthorization, routeContext);
|
|
150
151
|
}
|
|
151
|
-
catch
|
|
152
|
+
catch {
|
|
152
153
|
response = authorizationErrorResponse({ code: "verification_error", ok: false, status: 500 }, options.errorFormat ?? "json");
|
|
153
154
|
try {
|
|
154
155
|
await options.dependencies.audit.append({
|
|
@@ -166,7 +167,9 @@ export function withApiKeyAuthorization(options, handler) {
|
|
|
166
167
|
operationOutcome: "failed",
|
|
167
168
|
ownerId: authorization.principal.ownerId,
|
|
168
169
|
pageName: descriptor.pageName,
|
|
169
|
-
|
|
170
|
+
// A fixed code: the error's class name is app-controlled (for
|
|
171
|
+
// example a database driver's) and owners can read this event.
|
|
172
|
+
reasonCode: "handler_error",
|
|
170
173
|
requestId: requestContext.requestId,
|
|
171
174
|
scopeAction: descriptor.permission.action,
|
|
172
175
|
scopeResource: descriptor.permission.resource,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gadicc/loom",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.35.0",
|
|
4
4
|
"description": "Deno-first shared helpers for extracting common Next.js app code.",
|
|
5
5
|
"homepage": "https://github.com/gadicc/loom#readme",
|
|
6
6
|
"repository": {
|
|
@@ -244,7 +244,7 @@
|
|
|
244
244
|
},
|
|
245
245
|
"scripts": {},
|
|
246
246
|
"loom": {
|
|
247
|
-
"gitCommit": "
|
|
247
|
+
"gitCommit": "722f1f0d162a04a0aead905a2014b8ab5c20a1bb"
|
|
248
248
|
},
|
|
249
249
|
"bin": {
|
|
250
250
|
"loom": "script/bin/loom.js"
|
|
@@ -344,12 +344,8 @@
|
|
|
344
344
|
"registry": "https://registry.npmjs.org/"
|
|
345
345
|
},
|
|
346
346
|
"dependencies": {
|
|
347
|
-
"@mui/material": "9.2.0",
|
|
348
347
|
"@next/env": "^16.2.10",
|
|
349
348
|
"jsonc-parser": "^3.3.1",
|
|
350
|
-
"postgres": "^3.4.9",
|
|
351
|
-
"react": "19.2.7",
|
|
352
|
-
"react-dom": "19.2.7",
|
|
353
349
|
"tsx": "^4.23.1",
|
|
354
350
|
"valibot-serialize": "^2.0.1"
|
|
355
351
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../../src/src/apiKeys/authorize.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,yBAAyB,
|
|
1
|
+
{"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../../src/src/apiKeys/authorize.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,yBAAyB,EAIzB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAwFpB,iFAAiF;AACjF,wBAAsB,eAAe,CACnC,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,yBAAyB,CAAC,CA+LpC"}
|
|
@@ -41,6 +41,30 @@ async function recordDenied(options, event) {
|
|
|
41
41
|
return undefined;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Audit attribution for a verifier denial: only an `insufficient_permission`
|
|
46
|
+
* denial with a well-formed principal names the key and its owner.
|
|
47
|
+
*/
|
|
48
|
+
function deniedKeyAuditFields(verification) {
|
|
49
|
+
const principal = verification.principal;
|
|
50
|
+
if (verification.code !== "insufficient_permission" || !principal ||
|
|
51
|
+
typeof principal.keyId !== "string" || !principal.keyId ||
|
|
52
|
+
typeof principal.ownerId !== "string" || !principal.ownerId) {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
// A custom verifier's snapshots are untrusted input to the audit insert;
|
|
56
|
+
// drop anything that is not a string rather than fail the denial's record.
|
|
57
|
+
return {
|
|
58
|
+
keyId: principal.keyId,
|
|
59
|
+
keyNameSnapshot: typeof principal.keyName === "string"
|
|
60
|
+
? principal.keyName
|
|
61
|
+
: undefined,
|
|
62
|
+
keyStartSnapshot: typeof principal.keyStart === "string"
|
|
63
|
+
? principal.keyStart
|
|
64
|
+
: undefined,
|
|
65
|
+
ownerId: principal.ownerId,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
44
68
|
function principalAuditFields(principal) {
|
|
45
69
|
return {
|
|
46
70
|
keyId: principal.keyId,
|
|
@@ -75,6 +99,52 @@ async function authorizeApiKey(options) {
|
|
|
75
99
|
status,
|
|
76
100
|
};
|
|
77
101
|
}
|
|
102
|
+
if (options.rejectCredential) {
|
|
103
|
+
let rejected;
|
|
104
|
+
try {
|
|
105
|
+
rejected = await options.rejectCredential(extracted.credential, {
|
|
106
|
+
descriptor: options.descriptor,
|
|
107
|
+
transport: extracted.transport,
|
|
108
|
+
}) !== false;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// Fail closed without fingerprinting a credential the app may have
|
|
112
|
+
// been about to reject.
|
|
113
|
+
const recorded = await recordDenied(options, {
|
|
114
|
+
...auditBase,
|
|
115
|
+
authorizationOutcome: "error",
|
|
116
|
+
eventType: "authorization",
|
|
117
|
+
httpStatus: 500,
|
|
118
|
+
// Distinct from a verifier outage for operators; the response is not.
|
|
119
|
+
reasonCode: "credential_rejection_error",
|
|
120
|
+
transport: extracted.transport,
|
|
121
|
+
});
|
|
122
|
+
return {
|
|
123
|
+
authorizationEventId: recorded?.id,
|
|
124
|
+
code: "verification_error",
|
|
125
|
+
ok: false,
|
|
126
|
+
status: 500,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (rejected) {
|
|
130
|
+
// Same result as an invalid key, so callers cannot tell a rejected
|
|
131
|
+
// value from a wrong one; only the audit reason differs.
|
|
132
|
+
const recorded = await recordDenied(options, {
|
|
133
|
+
...auditBase,
|
|
134
|
+
authorizationOutcome: "denied",
|
|
135
|
+
eventType: "authorization",
|
|
136
|
+
httpStatus: 401,
|
|
137
|
+
reasonCode: "credential_rejected",
|
|
138
|
+
transport: extracted.transport,
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
authorizationEventId: recorded?.id,
|
|
142
|
+
code: "invalid_credential",
|
|
143
|
+
ok: false,
|
|
144
|
+
status: 401,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
78
148
|
const credentialFingerprint = await (0, fingerprint_js_1.fingerprintApiKeyCredential)(extracted.credential);
|
|
79
149
|
let verification;
|
|
80
150
|
try {
|
|
@@ -109,6 +179,7 @@ async function authorizeApiKey(options) {
|
|
|
109
179
|
: 401);
|
|
110
180
|
const recorded = await recordDenied(options, {
|
|
111
181
|
...auditBase,
|
|
182
|
+
...deniedKeyAuditFields(verification),
|
|
112
183
|
authorizationOutcome: "denied",
|
|
113
184
|
credentialFingerprint,
|
|
114
185
|
eventType: "authorization",
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { ApiKeyScopeDefinitions, DefinedApiKeyScopes } from "./policy.js";
|
|
2
|
+
import type { ApiKeyVerifier } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The part of a Better Auth instance with the api-key plugin that the shared
|
|
5
|
+
* verifier calls. Loom never imports Better Auth; pass the app's `auth`
|
|
6
|
+
* instance. Method syntax keeps the parameter check bivariant, so Better
|
|
7
|
+
* Auth's richer endpoint signature remains assignable.
|
|
8
|
+
*/
|
|
9
|
+
export interface BetterAuthApiKeyVerifyApi {
|
|
10
|
+
api: {
|
|
11
|
+
verifyApiKey(input: {
|
|
12
|
+
body: {
|
|
13
|
+
configId?: string;
|
|
14
|
+
key: string;
|
|
15
|
+
};
|
|
16
|
+
}): Promise<unknown>;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A key record returned by a successful Better Auth `verifyApiKey` call, after
|
|
21
|
+
* Loom's shape checks. Fields beyond `id` are unvalidated plugin data.
|
|
22
|
+
*/
|
|
23
|
+
export interface BetterAuthVerifiedApiKey {
|
|
24
|
+
readonly [field: string]: unknown;
|
|
25
|
+
/** Non-empty key ID. */
|
|
26
|
+
readonly id: string;
|
|
27
|
+
/** `false` for a revoked key; re-checked as defense in depth. */
|
|
28
|
+
readonly enabled?: unknown;
|
|
29
|
+
/** Expiry; a past or unparseable value is re-checked as expired. */
|
|
30
|
+
readonly expiresAt?: unknown;
|
|
31
|
+
/** Display name, when the plugin returned a string. */
|
|
32
|
+
readonly name?: unknown;
|
|
33
|
+
/** Permissions as decoded once by Better Auth. Never decoded again. */
|
|
34
|
+
readonly permissions?: unknown;
|
|
35
|
+
/** Owner reference in current Better Auth api-key schemas. */
|
|
36
|
+
readonly referenceId?: unknown;
|
|
37
|
+
/** Non-secret key prefix, when the plugin returned a string. */
|
|
38
|
+
readonly start?: unknown;
|
|
39
|
+
}
|
|
40
|
+
/** Options for `createBetterAuthApiKeyVerifier`. */
|
|
41
|
+
export interface CreateBetterAuthApiKeyVerifierOptions<TDefinitions extends ApiKeyScopeDefinitions = ApiKeyScopeDefinitions> {
|
|
42
|
+
/** The app's Better Auth instance, configured with the api-key plugin. */
|
|
43
|
+
auth: BetterAuthApiKeyVerifyApi;
|
|
44
|
+
/**
|
|
45
|
+
* The plugin configuration to verify against, always sent to Better Auth.
|
|
46
|
+
* Use `"default"` for a plugin configured without a `configId`.
|
|
47
|
+
*/
|
|
48
|
+
configId: string;
|
|
49
|
+
/**
|
|
50
|
+
* Resolves the key owner. Defaults to `key.referenceId`. A missing or
|
|
51
|
+
* non-string owner fails closed as a verification error.
|
|
52
|
+
*/
|
|
53
|
+
ownerId?: (key: BetterAuthVerifiedApiKey) => string | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* The app's scope registry. When given, `principal.permissions` lists only
|
|
56
|
+
* registry permissions the key grants exactly; otherwise every exact grant
|
|
57
|
+
* stored on the key is listed.
|
|
58
|
+
*/
|
|
59
|
+
scopes?: DefinedApiKeyScopes<TDefinitions>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates a Loom `ApiKeyVerifier` that makes exactly one Better Auth
|
|
63
|
+
* `verifyApiKey` call per authorization and decides the requested permission
|
|
64
|
+
* locally.
|
|
65
|
+
*
|
|
66
|
+
* The plugin reports a valid key that lacks a requested permission as
|
|
67
|
+
* `KEY_NOT_FOUND`, indistinguishable from a forged or revoked key, so this
|
|
68
|
+
* verifier never sends `permissions`. Instead it checks the decoded grants
|
|
69
|
+
* with `hasApiKeyPermission` and reports a miss as `insufficient_permission`
|
|
70
|
+
* (403). Better Auth still owns hashing, config scoping, enablement, expiry,
|
|
71
|
+
* and usage accounting.
|
|
72
|
+
*
|
|
73
|
+
* Classification:
|
|
74
|
+
* - `valid: false` with code `RATE_LIMITED` (per-key rate limit) or
|
|
75
|
+
* `USAGE_EXCEEDED` (`remaining` quota spent; the plugin reports it as 429
|
|
76
|
+
* and deletes an exhausted key that has no refill) → `rate_limited` (429);
|
|
77
|
+
* - any other `valid: false`, `valid: true` without a key, or a returned key
|
|
78
|
+
* that is disabled or expired → `invalid_credential` (401);
|
|
79
|
+
* - a valid key without the exact permission → `insufficient_permission`
|
|
80
|
+
* (403), carrying the key's `principal` so Loom attributes the audit row
|
|
81
|
+
* to its owner;
|
|
82
|
+
* - a malformed result, key ID, or owner throws, which Loom records as
|
|
83
|
+
* `verification_error` (500). Exceptions from Better Auth propagate too.
|
|
84
|
+
*
|
|
85
|
+
* Caveats:
|
|
86
|
+
* - A scope miss now passes through the plugin's usage claim. It updates
|
|
87
|
+
* `lastRequest`/`requestCount`/`updatedAt` and, with per-key rate limits or
|
|
88
|
+
* `remaining` quotas enabled, would spend them and could delete an exhausted
|
|
89
|
+
* key. Keep those disabled or account for it.
|
|
90
|
+
* - The plugin catches internal failures such as a database outage and
|
|
91
|
+
* returns them as `INVALID_API_KEY`, so they deny as `invalid_credential`
|
|
92
|
+
* (fail closed) rather than `verification_error`. Monitor Better Auth's
|
|
93
|
+
* "Failed to validate API key" log to tell an outage from bad keys.
|
|
94
|
+
*/
|
|
95
|
+
export declare function createBetterAuthApiKeyVerifier<const TDefinitions extends ApiKeyScopeDefinitions = ApiKeyScopeDefinitions>(options: CreateBetterAuthApiKeyVerifierOptions<TDefinitions>): ApiKeyVerifier;
|
|
96
|
+
/**
|
|
97
|
+
* Better Auth api-key plugin endpoints served over HTTP, relative to the auth
|
|
98
|
+
* base path.
|
|
99
|
+
*
|
|
100
|
+
* Each is session-authenticated, so any signed-in user can call it for their
|
|
101
|
+
* own keys: `update` can re-enable an administratively revoked key or remove
|
|
102
|
+
* its expiry, `delete` hard-deletes the key row instead of soft-revoking it,
|
|
103
|
+
* and `create` skips the app's own validation. `verifyApiKey` and expired-key
|
|
104
|
+
* cleanup are server-only and are not listed.
|
|
105
|
+
*/
|
|
106
|
+
export declare const BETTER_AUTH_API_KEY_HTTP_PATHS: readonly ["/api-key/create", "/api-key/update", "/api-key/delete", "/api-key/get", "/api-key/list"];
|
|
107
|
+
/**
|
|
108
|
+
* Returns Better Auth `disabledPaths` that also block every api-key plugin
|
|
109
|
+
* HTTP endpoint, preserving `existing` entries first and removing duplicates.
|
|
110
|
+
*
|
|
111
|
+
* Use it in the app-owned `betterAuth()` options so key lifecycle only goes
|
|
112
|
+
* through server actions that call `auth.api.*`; server-side calls never pass
|
|
113
|
+
* through the HTTP router, so they keep working:
|
|
114
|
+
*
|
|
115
|
+
* ```ts
|
|
116
|
+
* export const auth = betterAuth({
|
|
117
|
+
* disabledPaths: withBetterAuthApiKeyHttpPathsDisabled(),
|
|
118
|
+
* plugins: [apiKey({ ... })],
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare function withBetterAuthApiKeyHttpPathsDisabled(existing?: readonly string[]): string[];
|
|
123
|
+
//# sourceMappingURL=betterAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"betterAuth.d.ts","sourceRoot":"","sources":["../../../src/src/apiKeys/betterAuth.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAwB,MAAM,YAAY,CAAC;AAEvE;;;;;GAKG;AACH,MAAM,WAAW,yBAAyB;IACxC,GAAG,EAAE;QACH,YAAY,CACV,KAAK,EAAE;YAAE,IAAI,EAAE;gBAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAAC,GAAG,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE,GAClD,OAAO,CAAC,OAAO,CAAC,CAAC;KACrB,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC,wBAAwB;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,iEAAiE;IACjE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,oEAAoE;IACpE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,uDAAuD;IACvD,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,uEAAuE;IACvE,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,8DAA8D;IAC9D,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,gEAAgE;IAChE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,oDAAoD;AACpD,MAAM,WAAW,qCAAqC,CACpD,YAAY,SAAS,sBAAsB,GAAG,sBAAsB;IAEpE,0EAA0E;IAC1E,IAAI,EAAE,yBAAyB,CAAC;IAChC;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,wBAAwB,KAAK,MAAM,GAAG,SAAS,CAAC;IAChE;;;;OAIG;IACH,MAAM,CAAC,EAAE,mBAAmB,CAAC,YAAY,CAAC,CAAC;CAC5C;AA0BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,8BAA8B,CAC5C,KAAK,CAAC,YAAY,SAAS,sBAAsB,GAAG,sBAAsB,EAE1E,OAAO,EAAE,qCAAqC,CAAC,YAAY,CAAC,GAC3D,cAAc,CA4EhB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,8BAA8B,qGAQ1C,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qCAAqC,CACnD,QAAQ,GAAE,SAAS,MAAM,EAAO,GAC/B,MAAM,EAAE,CAQV"}
|