@gadicc/loom 1.34.0 → 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/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 +2806 -437
- 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/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 +2807 -437
- 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 +111 -18
- package/skills/loom-api-keys/SKILL.md +101 -7
- package/skills/loom-auth/SKILL.md +9 -0
- package/skills/loom-db/SKILL.md +3 -1
|
@@ -1,9 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.API_KEY_NO_TRANSPORT_MESSAGE = exports.DEFAULT_API_KEY_EXPIRY_PRESET_DAYS = exports.API_KEY_REVOKE_FAILED_MESSAGE = exports.API_KEY_RENAME_FAILED_MESSAGE = exports.API_KEY_CREATE_FAILED_MESSAGE = exports.API_KEY_AUDIT_OTHER_REASON_LABEL = void 0;
|
|
4
|
+
exports.apiKeyAuditReasonLabel = apiKeyAuditReasonLabel;
|
|
5
|
+
exports.getApiKeyAuditReason = getApiKeyAuditReason;
|
|
3
6
|
exports.countryCodeToFlagEmoji = countryCodeToFlagEmoji;
|
|
4
7
|
exports.formatApiKeyDate = formatApiKeyDate;
|
|
5
8
|
exports.getApiKeyStatus = getApiKeyStatus;
|
|
6
9
|
exports.getApiKeyVisibleColumnIds = getApiKeyVisibleColumnIds;
|
|
10
|
+
exports.resolveApiKeyCreateActionResult = resolveApiKeyCreateActionResult;
|
|
11
|
+
exports.resolveApiKeyMutationResult = resolveApiKeyMutationResult;
|
|
12
|
+
exports.getApiKeyTransportGuidanceCopy = getApiKeyTransportGuidanceCopy;
|
|
13
|
+
exports.resolveApiKeyThrownErrorMessage = resolveApiKeyThrownErrorMessage;
|
|
14
|
+
exports.getApiKeyExpiryOptions = getApiKeyExpiryOptions;
|
|
15
|
+
exports.getDefaultApiKeyExpiryChoice = getDefaultApiKeyExpiryChoice;
|
|
16
|
+
exports.toDateTimeLocalValue = toDateTimeLocalValue;
|
|
17
|
+
exports.getApiKeyCustomExpiryInputBounds = getApiKeyCustomExpiryInputBounds;
|
|
18
|
+
exports.resolveApiKeyCreateInput = resolveApiKeyCreateInput;
|
|
19
|
+
exports.resolveApiKeyRename = resolveApiKeyRename;
|
|
20
|
+
const limits_js_1 = require("../apiKeys/limits.js");
|
|
21
|
+
/** Shown for a reason code that `apiKeyAuditReasonLabel` does not know. */
|
|
22
|
+
exports.API_KEY_AUDIT_OTHER_REASON_LABEL = "Other reason";
|
|
23
|
+
/**
|
|
24
|
+
* Short user-facing labels for every reason code Loom records. `satisfies`
|
|
25
|
+
* makes a new code without a label fail type-checking.
|
|
26
|
+
*/
|
|
27
|
+
const API_KEY_AUDIT_REASON_LABELS = {
|
|
28
|
+
ambiguous_credentials: "More than one key sent",
|
|
29
|
+
audit_unavailable: "Audit unavailable",
|
|
30
|
+
credential_malformed: "Malformed key",
|
|
31
|
+
credential_missing: "No key sent",
|
|
32
|
+
credential_rejected: "Credential rejected",
|
|
33
|
+
credential_rejection_error: "Credential check failed",
|
|
34
|
+
forbidden: "Denied by policy",
|
|
35
|
+
// Recorded on the completion event of a handler that threw.
|
|
36
|
+
handler_error: "Handler failed",
|
|
37
|
+
insufficient_permission: "Key lacks this scope",
|
|
38
|
+
invalid_credential: "Invalid, revoked, or expired key",
|
|
39
|
+
policy_error: "Policy check failed",
|
|
40
|
+
rate_limited: "Rate limited",
|
|
41
|
+
verification_error: "Verification failed",
|
|
42
|
+
};
|
|
43
|
+
function isKnownApiKeyAuditReasonCode(code) {
|
|
44
|
+
// An own-property check, so prototype names such as `toString` never match.
|
|
45
|
+
return Object.prototype.hasOwnProperty.call(API_KEY_AUDIT_REASON_LABELS, code);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Maps an audit reason code to a short label. Only codes Loom records have
|
|
49
|
+
* labels. Any other code shows `API_KEY_AUDIT_OTHER_REASON_LABEL` and is never
|
|
50
|
+
* displayed itself: a stored code is not known to be free of secrets, and a
|
|
51
|
+
* Better Auth key without a prefix looks like any identifier. No code yields
|
|
52
|
+
* `null`; label an app-specific code by passing `reason` instead.
|
|
53
|
+
*/
|
|
54
|
+
function apiKeyAuditReasonLabel(code) {
|
|
55
|
+
if (typeof code !== "string" || !code.trim())
|
|
56
|
+
return null;
|
|
57
|
+
return isKnownApiKeyAuditReasonCode(code)
|
|
58
|
+
? API_KEY_AUDIT_REASON_LABELS[code]
|
|
59
|
+
: exports.API_KEY_AUDIT_OTHER_REASON_LABEL;
|
|
60
|
+
}
|
|
61
|
+
/** The reason to show for an audit row: its label, else its code's label. */
|
|
62
|
+
function getApiKeyAuditReason(row) {
|
|
63
|
+
const reason = typeof row.reason === "string" ? row.reason.trim() : "";
|
|
64
|
+
return reason ? reason : apiKeyAuditReasonLabel(row.reasonCode);
|
|
65
|
+
}
|
|
7
66
|
/** Converts an ISO alpha-2 country code to its Unicode regional flag. */
|
|
8
67
|
function countryCodeToFlagEmoji(countryCode) {
|
|
9
68
|
const normalized = countryCode?.trim().toUpperCase();
|
|
@@ -38,3 +97,235 @@ function getApiKeyVisibleColumnIds(admin = false) {
|
|
|
38
97
|
"actions",
|
|
39
98
|
];
|
|
40
99
|
}
|
|
100
|
+
exports.API_KEY_CREATE_FAILED_MESSAGE = "The key could not be created.";
|
|
101
|
+
exports.API_KEY_RENAME_FAILED_MESSAGE = "The key could not be renamed.";
|
|
102
|
+
exports.API_KEY_REVOKE_FAILED_MESSAGE = "The key could not be revoked.";
|
|
103
|
+
/** Expiry presets offered by the create dialog when none are configured. */
|
|
104
|
+
exports.DEFAULT_API_KEY_EXPIRY_PRESET_DAYS = Object
|
|
105
|
+
.freeze([7, 30]);
|
|
106
|
+
function isRecord(value) {
|
|
107
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
108
|
+
}
|
|
109
|
+
function failure(message, fallback) {
|
|
110
|
+
return {
|
|
111
|
+
message: typeof message === "string" && message.trim() ? message : fallback,
|
|
112
|
+
ok: false,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function isCreateResult(value) {
|
|
116
|
+
return isRecord(value) && typeof value.key === "string" &&
|
|
117
|
+
value.key.length > 0 && typeof value.name === "string";
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Normalizes what an `onCreate` callback resolved to.
|
|
121
|
+
*
|
|
122
|
+
* A value whose `ok` is a boolean is the result form; anything else is the
|
|
123
|
+
* original `ApiKeyCreateResult` form. A success without a usable key and name
|
|
124
|
+
* becomes a failure, so the secret dialog never opens empty.
|
|
125
|
+
*/
|
|
126
|
+
function resolveApiKeyCreateActionResult(value) {
|
|
127
|
+
if (isRecord(value) && typeof value.ok === "boolean") {
|
|
128
|
+
if (!value.ok)
|
|
129
|
+
return failure(value.message, exports.API_KEY_CREATE_FAILED_MESSAGE);
|
|
130
|
+
if (isCreateResult(value.created)) {
|
|
131
|
+
return { created: value.created, ok: true };
|
|
132
|
+
}
|
|
133
|
+
// An original-form result that happens to carry `ok: true` still holds
|
|
134
|
+
// the one-time secret; never drop it.
|
|
135
|
+
if (value.created === undefined && isCreateResult(value)) {
|
|
136
|
+
return { created: value, ok: true };
|
|
137
|
+
}
|
|
138
|
+
return failure(undefined, exports.API_KEY_CREATE_FAILED_MESSAGE);
|
|
139
|
+
}
|
|
140
|
+
return isCreateResult(value)
|
|
141
|
+
? { created: value, ok: true }
|
|
142
|
+
: failure(undefined, exports.API_KEY_CREATE_FAILED_MESSAGE);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Normalizes what an `onRename` or `onRevoke` callback resolved to.
|
|
146
|
+
*
|
|
147
|
+
* A value whose `ok` is a boolean is the result form. Anything else, such as
|
|
148
|
+
* the `void` of the original callback form, is a success, as before.
|
|
149
|
+
*/
|
|
150
|
+
function resolveApiKeyMutationResult(value, fallbackMessage) {
|
|
151
|
+
if (isRecord(value) && typeof value.ok === "boolean") {
|
|
152
|
+
return value.ok ? { ok: true } : failure(value.message, fallbackMessage);
|
|
153
|
+
}
|
|
154
|
+
return { ok: true };
|
|
155
|
+
}
|
|
156
|
+
exports.API_KEY_NO_TRANSPORT_MESSAGE = "This app does not currently accept API keys in requests.";
|
|
157
|
+
function transportLabel(transport, description) {
|
|
158
|
+
switch (transport) {
|
|
159
|
+
case "authorization-bearer":
|
|
160
|
+
return "the Authorization header (Bearer <key>)";
|
|
161
|
+
case "x-api-key":
|
|
162
|
+
return `the ${description.headerName} header`;
|
|
163
|
+
case "query":
|
|
164
|
+
return `the ${description.queryName} query parameter`;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function joinList(items) {
|
|
168
|
+
return items.length < 3
|
|
169
|
+
? items.join(" and ")
|
|
170
|
+
: `${items.slice(0, -1).join(", ")}, and ${items[items.length - 1]}`;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Builds transport guidance copy: the preferred transport, the other
|
|
174
|
+
* accepted ones, and a URL-leakage warning when query credentials are
|
|
175
|
+
* accepted. With no accepted transport it returns a plain fallback.
|
|
176
|
+
*/
|
|
177
|
+
function getApiKeyTransportGuidanceCopy(description) {
|
|
178
|
+
const preferred = description.preferred;
|
|
179
|
+
if (preferred === null) {
|
|
180
|
+
return {
|
|
181
|
+
alternatives: null,
|
|
182
|
+
primary: exports.API_KEY_NO_TRANSPORT_MESSAGE,
|
|
183
|
+
queryWarning: null,
|
|
184
|
+
severity: "warning",
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const others = description.accepted
|
|
188
|
+
.filter((transport) => transport !== preferred)
|
|
189
|
+
.map((transport) => transportLabel(transport, description));
|
|
190
|
+
const queryAccepted = description.queryName !== null;
|
|
191
|
+
return {
|
|
192
|
+
alternatives: others.length ? `Also accepted: ${joinList(others)}.` : null,
|
|
193
|
+
primary: `Send the key in ${transportLabel(preferred, description)}.`,
|
|
194
|
+
queryWarning: queryAccepted
|
|
195
|
+
? `Query-parameter keys can appear in browser history, access logs, copied links, and referrers. ${preferred === "query"
|
|
196
|
+
? "Do not share or log URLs that contain a key."
|
|
197
|
+
: "Use the query parameter only for clients that cannot send headers."}`
|
|
198
|
+
: null,
|
|
199
|
+
severity: queryAccepted ? "warning" : "info",
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/** The message to show for an error thrown by a lifecycle callback. */
|
|
203
|
+
function resolveApiKeyThrownErrorMessage(error, mode, fallbackMessage) {
|
|
204
|
+
return mode === "show" && error instanceof Error && error.message
|
|
205
|
+
? error.message
|
|
206
|
+
: fallbackMessage;
|
|
207
|
+
}
|
|
208
|
+
function formatPresetDays(days) {
|
|
209
|
+
return days === 1 ? "1 day" : `${days} days`;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Lists the create dialog's expiry choices: "Never" when allowed, presets
|
|
213
|
+
* within the expiry limits (invalid and duplicate presets are dropped), and
|
|
214
|
+
* "Custom date".
|
|
215
|
+
*/
|
|
216
|
+
function getApiKeyExpiryOptions(options = {}) {
|
|
217
|
+
const min = options.limits?.minExpiresInDays;
|
|
218
|
+
const max = options.limits?.maxExpiresInDays;
|
|
219
|
+
const presets = [
|
|
220
|
+
...new Set((options.expiryPresetDays ?? exports.DEFAULT_API_KEY_EXPIRY_PRESET_DAYS).filter((days) => typeof days === "number" && Number.isFinite(days) && days > 0 &&
|
|
221
|
+
(min === undefined || days >= min) &&
|
|
222
|
+
(max === undefined || days <= max))),
|
|
223
|
+
];
|
|
224
|
+
return [
|
|
225
|
+
...(options.allowNoExpiry === false
|
|
226
|
+
? []
|
|
227
|
+
: [{ label: "Never", value: "never" }]),
|
|
228
|
+
...presets.map((days) => ({
|
|
229
|
+
label: formatPresetDays(days),
|
|
230
|
+
value: String(days),
|
|
231
|
+
})),
|
|
232
|
+
{ label: "Custom date", value: "custom" },
|
|
233
|
+
];
|
|
234
|
+
}
|
|
235
|
+
/** The create dialog's initial expiry choice: "Never" when allowed. */
|
|
236
|
+
function getDefaultApiKeyExpiryChoice(options = {}) {
|
|
237
|
+
return getApiKeyExpiryOptions(options)[0].value;
|
|
238
|
+
}
|
|
239
|
+
const MINUTE_MS = 60_000;
|
|
240
|
+
/** Formats a time as a `datetime-local` input value in local time. */
|
|
241
|
+
function toDateTimeLocalValue(time) {
|
|
242
|
+
const date = new Date(time);
|
|
243
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
244
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* `min`/`max` attributes for the custom expiry input, in local time.
|
|
248
|
+
*
|
|
249
|
+
* The input has minute precision, so `min` is rounded up to a whole minute and
|
|
250
|
+
* `max` down; both therefore lie within the limits. `min` is always in the
|
|
251
|
+
* future.
|
|
252
|
+
*/
|
|
253
|
+
function getApiKeyCustomExpiryInputBounds(limits = {}, now = Date.now()) {
|
|
254
|
+
const dayMs = limits_js_1.API_KEY_SECONDS_PER_DAY * 1000;
|
|
255
|
+
const minTime = Math.ceil((now + Math.max((limits.minExpiresInDays ?? 0) * dayMs, 1000)) /
|
|
256
|
+
MINUTE_MS) * MINUTE_MS;
|
|
257
|
+
if (limits.maxExpiresInDays === undefined) {
|
|
258
|
+
return { min: toDateTimeLocalValue(minTime) };
|
|
259
|
+
}
|
|
260
|
+
// When rounding crosses equal limits, the server tolerance still accepts
|
|
261
|
+
// the rounded-up minimum.
|
|
262
|
+
const maxTime = Math.max(Math.floor((now + limits.maxExpiresInDays * dayMs) / MINUTE_MS) *
|
|
263
|
+
MINUTE_MS, minTime);
|
|
264
|
+
return {
|
|
265
|
+
max: toDateTimeLocalValue(maxTime),
|
|
266
|
+
min: toDateTimeLocalValue(minTime),
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Validates the create dialog's fields with the same validators and messages
|
|
271
|
+
* as server-side `validateApiKeyName` and `resolveApiKeyExpiresIn`, and builds
|
|
272
|
+
* the `onCreate` input. The server must still validate: this only spares the
|
|
273
|
+
* user a round trip.
|
|
274
|
+
*/
|
|
275
|
+
function resolveApiKeyCreateInput(values, options = {}) {
|
|
276
|
+
const limits = options.limits ?? {};
|
|
277
|
+
const messages = (0, limits_js_1.apiKeyLimitMessages)(limits);
|
|
278
|
+
const now = options.now ?? Date.now();
|
|
279
|
+
const name = (0, limits_js_1.validateApiKeyName)(values.name, limits);
|
|
280
|
+
if (!name.ok)
|
|
281
|
+
return name;
|
|
282
|
+
if (!values.scopeIds.length) {
|
|
283
|
+
return { message: "Choose at least one scope.", ok: false };
|
|
284
|
+
}
|
|
285
|
+
let expiresAt;
|
|
286
|
+
if (values.expiry === "never") {
|
|
287
|
+
expiresAt = null;
|
|
288
|
+
}
|
|
289
|
+
else if (values.expiry === "custom") {
|
|
290
|
+
if (!values.customExpiry) {
|
|
291
|
+
return { message: messages.expiryRequired, ok: false };
|
|
292
|
+
}
|
|
293
|
+
// A `datetime-local` value has no zone, so it is read as local time.
|
|
294
|
+
const chosen = new Date(values.customExpiry).valueOf();
|
|
295
|
+
if (!Number.isFinite(chosen)) {
|
|
296
|
+
return { message: messages.expiryInvalid, ok: false };
|
|
297
|
+
}
|
|
298
|
+
expiresAt = new Date(chosen).toISOString();
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
const days = Number(values.expiry);
|
|
302
|
+
if (!Number.isFinite(days) || days <= 0) {
|
|
303
|
+
return { message: messages.expiryInvalid, ok: false };
|
|
304
|
+
}
|
|
305
|
+
expiresAt = new Date(now + days * limits_js_1.API_KEY_SECONDS_PER_DAY * 1000)
|
|
306
|
+
.toISOString();
|
|
307
|
+
}
|
|
308
|
+
const expiry = (0, limits_js_1.resolveApiKeyExpiresIn)(expiresAt, limits, {
|
|
309
|
+
allowNoExpiry: options.allowNoExpiry,
|
|
310
|
+
now,
|
|
311
|
+
});
|
|
312
|
+
if (!expiry.ok)
|
|
313
|
+
return expiry;
|
|
314
|
+
return {
|
|
315
|
+
ok: true,
|
|
316
|
+
value: { expiresAt, name: name.value, scopeIds: [...values.scopeIds] },
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Validates a rename with the server's name rules. `unchanged` is `true` when
|
|
321
|
+
* the trimmed name equals the current one, so no call is needed.
|
|
322
|
+
*/
|
|
323
|
+
function resolveApiKeyRename(name, currentName, limits = {}) {
|
|
324
|
+
const result = (0, limits_js_1.validateApiKeyName)(name, limits);
|
|
325
|
+
if (!result.ok)
|
|
326
|
+
return result;
|
|
327
|
+
return {
|
|
328
|
+
ok: true,
|
|
329
|
+
value: { name: result.value, unchanged: result.value === currentName },
|
|
330
|
+
};
|
|
331
|
+
}
|
|
@@ -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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AO,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IACjE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,OAAO,CAAC,4BAA4B,CAAC,QAAQ,CAAC,CAAC,CAmBlD"}
|
|
@@ -50,6 +50,7 @@ async function authorizeApiKeyRequestWithContext(request, descriptor, dependenci
|
|
|
50
50
|
credentialOptions: dependencies.credentialOptions,
|
|
51
51
|
descriptor,
|
|
52
52
|
policy: dependencies.policy,
|
|
53
|
+
rejectCredential: dependencies.rejectCredential,
|
|
53
54
|
request: requestContext,
|
|
54
55
|
source: {
|
|
55
56
|
headers: request.headers,
|
|
@@ -155,7 +156,7 @@ function withApiKeyAuthorization(options, handler) {
|
|
|
155
156
|
try {
|
|
156
157
|
response = await handler(request, handlerAuthorization, routeContext);
|
|
157
158
|
}
|
|
158
|
-
catch
|
|
159
|
+
catch {
|
|
159
160
|
response = authorizationErrorResponse({ code: "verification_error", ok: false, status: 500 }, options.errorFormat ?? "json");
|
|
160
161
|
try {
|
|
161
162
|
await options.dependencies.audit.append({
|
|
@@ -173,7 +174,9 @@ function withApiKeyAuthorization(options, handler) {
|
|
|
173
174
|
operationOutcome: "failed",
|
|
174
175
|
ownerId: authorization.principal.ownerId,
|
|
175
176
|
pageName: descriptor.pageName,
|
|
176
|
-
|
|
177
|
+
// A fixed code: the error's class name is app-controlled (for
|
|
178
|
+
// example a database driver's) and owners can read this event.
|
|
179
|
+
reasonCode: "handler_error",
|
|
177
180
|
requestId: requestContext.requestId,
|
|
178
181
|
scopeAction: descriptor.permission.action,
|
|
179
182
|
scopeResource: descriptor.permission.resource,
|
package/skills/loom/SKILL.md
CHANGED
|
@@ -179,31 +179,124 @@ as more authoritative than a generic mapped error when deciding what failed.
|
|
|
179
179
|
for incompatible server versions or extensions.
|
|
180
180
|
|
|
181
181
|
- For local unpublished Loom package development, use `loom dev local <path>`.
|
|
182
|
-
Loom uses a managed `file:` override
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
Loom uses a managed `file:` override for pnpm projects and a local `links`
|
|
183
|
+
entry in the authoritative Deno config for Deno projects.
|
|
184
|
+
- The pnpm override goes where the project's pnpm version applies it
|
|
185
|
+
(`packageManager`, else the `pnpm --version` of the pnpm Loom runs; not
|
|
186
|
+
`npm_config_user_agent`, which names the pnpm running the current script), as
|
|
187
|
+
verified with real pnpm 9.7.0 to 11.25.0:
|
|
188
|
+
- pnpm before 10.5.1 reads overrides only from package.json `resolutions` and
|
|
189
|
+
`pnpm.overrides`; Loom adds its entry there, creating `resolutions` when
|
|
190
|
+
neither exists. pnpm 9 also needs `packages:` in any `pnpm-workspace.yaml`.
|
|
191
|
+
- pnpm 10.5.1 to 10.x reads `pnpm-workspace.yaml` `overrides` only while both
|
|
192
|
+
package.json maps are empty; otherwise the package.json maps replace (not
|
|
193
|
+
merge with) the workspace map, so Loom uses the package.json map there.
|
|
194
|
+
- pnpm 11 reads only `pnpm-workspace.yaml` overrides.
|
|
195
|
+
- An unknown version is treated as pnpm 10.5.1 or newer; pnpm 8 and older are
|
|
196
|
+
untested.
|
|
197
|
+
- An ignored override shows up as pnpm reporting "Lockfile is up to date" while
|
|
198
|
+
the app keeps the published package; `pnpm config get overrides` does not
|
|
199
|
+
reveal this. `loom dev sync` moves an override that is in the wrong place, and
|
|
200
|
+
fails with the detected pnpm version if pnpm still does not apply it.
|
|
185
201
|
- The managed flow keeps the committed dependency/import on a published Loom
|
|
186
|
-
version.
|
|
187
|
-
`project.tooling
|
|
202
|
+
version. `loom dev sync` refreshes with a plain `pnpm install` (or
|
|
203
|
+
`deno install`, according to `project.tooling`), which keeps every other
|
|
204
|
+
locked version. Do not link or refresh Loom with `pnpm update`; it re-resolves
|
|
205
|
+
Loom's dependency subtree and can leave duplicate peer variants of packages
|
|
206
|
+
such as `@better-auth/core`. To move to another published Loom version, set
|
|
207
|
+
the exact version in package.json and run `pnpm install`, which keeps other
|
|
208
|
+
locked versions. `pnpm add --save-exact @gadicc/loom@<version>` (with `-w` at
|
|
209
|
+
a workspace root with packages) gives the same lockfile but may re-sort
|
|
210
|
+
package.json; it is only needed to replace a local resolution an older
|
|
211
|
+
`pnpm update --no-save` link left under an unchanged pin. The sync fails if
|
|
212
|
+
pnpm-lock.yaml does not record the override afterwards and warns when the
|
|
213
|
+
install added duplicate peer variants.
|
|
214
|
+
- `loom dev sync` decides freshness by content: it rebuilds when the Loom
|
|
215
|
+
sources differ from the fingerprint stamped into the `npm/` build and
|
|
216
|
+
reinstalls when the app's installed copy differs from `npm/` by file list or
|
|
217
|
+
content, including after a `deno task build` run outside the sync. Use
|
|
218
|
+
`--force` only to rebuild and reinstall unconditionally.
|
|
219
|
+
- Concurrent Loom commands take turns through `.loom/dev-sync.lock`, and
|
|
220
|
+
`loom dev local` and `loom dev published` take the same lock: a second command
|
|
221
|
+
waits for the running sync, then re-reads the link and re-checks freshness
|
|
222
|
+
instead of rebuilding again (or re-adding an override removed meanwhile). If
|
|
223
|
+
the Loom package it had loaded was replaced while it waited, it treats that as
|
|
224
|
+
a refresh: `loom env` continues, other commands exit 75. The holder refreshes
|
|
225
|
+
the lock every 5 seconds and removes it on Ctrl-C, SIGTERM, or SIGHUP. A lock
|
|
226
|
+
nobody refreshed for a minute (a crash, `kill -9`, another machine) is broken,
|
|
227
|
+
after about 12 seconds when its process is gone on this host or it was already
|
|
228
|
+
a minute old, and after five minutes when its process still exists on this
|
|
229
|
+
host (a paused command); one waiter breaks it at a time under a short
|
|
230
|
+
`.loom/dev-sync.lock.break` lock. A holder that lost its lock stops before its
|
|
231
|
+
next build, install, or state write. After 10 minutes of waiting the command
|
|
232
|
+
fails and names the lock holder.
|
|
233
|
+
- Other Loom commands run the sync automatically while linked. When it refreshes
|
|
234
|
+
the package, `loom env -- <command>` (and so scripts such as `pnpm test` that
|
|
235
|
+
wrap it) still runs its command, with the sync's output on stderr; other
|
|
236
|
+
commands exit with status 75 and must be rerun so they do not run stale Loom
|
|
237
|
+
code.
|
|
188
238
|
- This still avoids the peer-resolution problems we observed with `pnpm link`
|
|
189
239
|
when Loom is consumed by React apps.
|
|
190
240
|
- Treat this as a workaround for current pnpm behavior, not a permanent
|
|
191
241
|
preference. If pnpm's local-link behavior changes enough to preserve peer
|
|
192
242
|
resolution cleanly for Loom, this workaround can be revisited or removed.
|
|
193
243
|
- Before committing app changes or preparing a published build, switch back with
|
|
194
|
-
`loom dev published`, then run
|
|
195
|
-
`
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
244
|
+
`loom dev published`, then run `pnpm install` or `deno install`. A lockfile
|
|
245
|
+
linked by an older Loom through `pnpm update --no-save` keeps its local
|
|
246
|
+
resolution through a plain install; restore that lockfile from git when it has
|
|
247
|
+
no other intended changes, as `loom dev published` explains.
|
|
248
|
+
- Each Loom build records its provenance in `npm/.loom-build.json` (kept out of
|
|
249
|
+
the packed package): the git commit it was built from, whether that checkout
|
|
250
|
+
was dirty, and a digest of the packed output. Dirty means tracked changes,
|
|
251
|
+
untracked files git does not ignore, files marked skip-worktree or
|
|
252
|
+
assume-unchanged, or a package-relevant file written while the build ran. The
|
|
253
|
+
last is judged by content, git state and modification times, so an edit
|
|
254
|
+
reverted before the build finished still counts; with whole-second timestamps
|
|
255
|
+
(FAT, HFS+), so does a file written a moment before the build started.
|
|
256
|
+
`loom dev sync` also records its sync in gitignored `.loom/dev-state.json` for
|
|
257
|
+
`loom status` and `loom check`; that record never gates a release.
|
|
258
|
+
- `loom dev published` proves what is actually installed, from that build
|
|
259
|
+
provenance, before it switches back:
|
|
260
|
+
- It collects every local Loom target: the managed pnpm override, any
|
|
261
|
+
hand-written `file:`/`link:` Loom entry in the `pnpm-workspace.yaml`
|
|
262
|
+
`overrides:` map, and any `file:`/`link:` resolution in `pnpm-lock.yaml`, or
|
|
263
|
+
every Deno link to Loom. It refuses when they name more than one package.
|
|
264
|
+
- The target's build must record a clean commit, and its npm/ output must
|
|
265
|
+
still match the recorded digest. An older build, one made without git, one
|
|
266
|
+
made from uncommitted changes, or output edited after the build is refused;
|
|
267
|
+
run `loom dev sync`, or commit the Loom changes and run
|
|
268
|
+
`loom dev sync --force`. A checkout whose own build script predates
|
|
269
|
+
provenance (an older tag, say, while bisecting) is rebuilt once per source
|
|
270
|
+
change and then always refused; relink to a newer checkout to switch back
|
|
271
|
+
with proof.
|
|
272
|
+
- The installed copy must match that build (pnpm `node_modules`, and a Deno
|
|
273
|
+
`node_modules` copy unless `nodeModulesDir` is `"none"`), and for pnpm
|
|
274
|
+
`pnpm-lock.yaml` must resolve Loom to it. Otherwise run `loom dev sync`.
|
|
275
|
+
- The build's commit must be reachable from `origin/main` and either included
|
|
276
|
+
in a semver release tag or package-equivalent to the latest semver release
|
|
277
|
+
because only non-package files changed after that tag. The app then switches
|
|
278
|
+
to the exact published Loom version that covers it.
|
|
279
|
+
- The checkout's current commit and working tree do not matter: later work in
|
|
280
|
+
it neither blocks nor passes a build that is already installed.
|
|
281
|
+
- A pnpm link that was never installed needs no proof: when pnpm-lock.yaml and
|
|
282
|
+
pnpm's record of node_modules still hold the published Loom and
|
|
283
|
+
`node_modules/@gadicc/loom` links pnpm's store entry for that version, the
|
|
284
|
+
overrides are removed and the pin stays. Anything less certain gets the full
|
|
285
|
+
proof: an interrupted install, or a layout without a `node_modules/.pnpm`
|
|
286
|
+
store entry to check (`node-linker=hoisted`, `enableGlobalVirtualStore`, a
|
|
287
|
+
custom `virtual-store-dir`). Deno links are always proved: Deno reads the
|
|
288
|
+
linked directory, or copies it into node_modules on its next install or run,
|
|
289
|
+
so a Deno link has no lasting never-installed state.
|
|
290
|
+
- Apps may pin Loom through a pnpm catalog (`"@gadicc/loom": "catalog:"` or
|
|
291
|
+
`"catalog:<name>"` in package.json, with the version in `pnpm-workspace.yaml`
|
|
292
|
+
`catalog:` or `catalogs:`, as block maps or single-line flow maps). Loom reads
|
|
293
|
+
the version from the catalog, and `loom dev published` pins the covering
|
|
294
|
+
version in that catalog entry while package.json keeps its `catalog:`
|
|
295
|
+
reference. Do not use `pnpm add` to change such a pin; it replaces the
|
|
296
|
+
reference. Edit the catalog and run `pnpm install`.
|
|
297
|
+
- `loom dev published` also removes Deno links and package.json overrides and
|
|
298
|
+
notices stale `pnpm-lock.yaml` resolutions that still point at local Loom
|
|
299
|
+
after the override has been removed.
|
|
207
300
|
- `loom check` should warn during normal development if a Deno link or pnpm
|
|
208
301
|
lockfile still resolves Loom locally, if the synced Loom commit is
|
|
209
302
|
unpublished, or if it is covered by a newer exact version than the app
|