@orieljs/framework 0.1.0-alpha.12 → 0.1.0-alpha.14
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/dist/{chunk-MURTCTRH.js → chunk-4NCMY3ZS.js} +48 -2
- package/dist/chunk-4NCMY3ZS.js.map +1 -0
- package/dist/{chunk-HTJKT2R2.js → chunk-BKA5F3TH.js} +1 -1
- package/dist/{chunk-HTJKT2R2.js.map → chunk-BKA5F3TH.js.map} +1 -1
- package/dist/{chunk-7NA4HALO.js → chunk-UBSIBGXR.js} +236 -54
- package/dist/chunk-UBSIBGXR.js.map +1 -0
- package/dist/{chunk-24673JQF.js → chunk-X4N74JDO.js} +98 -4
- package/dist/chunk-X4N74JDO.js.map +1 -0
- package/dist/contracts.d.ts +11 -1
- package/dist/contracts.js +1 -1
- package/dist/{index.d-WQpfdIbG.d.ts → index.d-lffxurFs.d.ts} +10 -1
- package/dist/index.d.ts +363 -19
- package/dist/index.js +1193 -189
- package/dist/index.js.map +1 -1
- package/dist/{jsx-runtime-6um4Mwfb.d.ts → jsx-runtime-Bc5KJzwb.d.ts} +1 -1
- package/dist/jsx-runtime.d.ts +2 -2
- package/dist/jsx-runtime.js +3 -3
- package/dist/{testing-CKwfWJGn.d.ts → testing-CVpo7aRl.d.ts} +46 -7
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +5 -3
- package/docs/authentication.md +42 -1
- package/docs/console.md +17 -6
- package/docs/database-testing.md +21 -0
- package/docs/database.md +12 -0
- package/docs/deployment.md +33 -6
- package/docs/encryption.md +2 -0
- package/docs/installation.md +2 -1
- package/docs/live-tests.md +20 -0
- package/docs/live.md +22 -0
- package/docs/navigation.json +4 -0
- package/docs/pagination.md +10 -0
- package/docs/routing.md +1 -1
- package/docs/scheduling.md +3 -0
- package/docs/session.md +19 -2
- package/docs/starter-kits.md +4 -0
- package/docs/storage.md +44 -5
- package/docs/testing.md +9 -6
- package/docs/two-factor.md +192 -0
- package/docs/views.md +2 -0
- package/docs/vite.md +1 -1
- package/package.json +56 -38
- package/dist/chunk-24673JQF.js.map +0 -1
- package/dist/chunk-7NA4HALO.js.map +0 -1
- package/dist/chunk-MURTCTRH.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
renderToString,
|
|
23
23
|
styleString,
|
|
24
24
|
view
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-X4N74JDO.js";
|
|
26
26
|
import {
|
|
27
27
|
API_ROUTES_STUB,
|
|
28
28
|
Application as Application2,
|
|
@@ -74,6 +74,7 @@ import {
|
|
|
74
74
|
QueueFake,
|
|
75
75
|
RenameClasses,
|
|
76
76
|
Repository,
|
|
77
|
+
SESSION_URI,
|
|
77
78
|
StorageFake,
|
|
78
79
|
TEMPORARY_UPLOAD_DEFAULTS,
|
|
79
80
|
TemporaryFileNotFoundError,
|
|
@@ -83,6 +84,7 @@ import {
|
|
|
83
84
|
TrimStrings,
|
|
84
85
|
UPDATE_URI,
|
|
85
86
|
UPLOAD_URI,
|
|
87
|
+
UploadAlreadyStoredError,
|
|
86
88
|
UploadValidationError,
|
|
87
89
|
Vite,
|
|
88
90
|
ViteError,
|
|
@@ -148,7 +150,7 @@ import {
|
|
|
148
150
|
vite,
|
|
149
151
|
viteReactRefresh,
|
|
150
152
|
writeResponse
|
|
151
|
-
} from "./chunk-
|
|
153
|
+
} from "./chunk-UBSIBGXR.js";
|
|
152
154
|
import {
|
|
153
155
|
Arr,
|
|
154
156
|
BindingResolutionError,
|
|
@@ -159,6 +161,7 @@ import {
|
|
|
159
161
|
ContainerNotAvailableError,
|
|
160
162
|
ItemNotFoundError,
|
|
161
163
|
LazyCollection,
|
|
164
|
+
MissingPackageError,
|
|
162
165
|
MultipleItemsFoundError,
|
|
163
166
|
ServiceProvider,
|
|
164
167
|
Str,
|
|
@@ -170,12 +173,13 @@ import {
|
|
|
170
173
|
currentContainer,
|
|
171
174
|
facade,
|
|
172
175
|
fileType_exports,
|
|
176
|
+
importOptional,
|
|
173
177
|
inject,
|
|
174
178
|
now,
|
|
175
179
|
retry,
|
|
176
180
|
tap,
|
|
177
181
|
value
|
|
178
|
-
} from "./chunk-
|
|
182
|
+
} from "./chunk-4NCMY3ZS.js";
|
|
179
183
|
import {
|
|
180
184
|
Application,
|
|
181
185
|
AuthFactory,
|
|
@@ -217,18 +221,26 @@ import {
|
|
|
217
221
|
ValidationFactory,
|
|
218
222
|
ViewFactory,
|
|
219
223
|
token
|
|
220
|
-
} from "./chunk-
|
|
224
|
+
} from "./chunk-BKA5F3TH.js";
|
|
221
225
|
|
|
222
226
|
// ../Auth/dist/index.js
|
|
223
227
|
import { createHash } from "crypto";
|
|
224
228
|
import { createHash as createHash2 } from "crypto";
|
|
225
229
|
import { timingSafeEqual } from "crypto";
|
|
226
230
|
import { createHash as createHash3 } from "crypto";
|
|
227
|
-
import { createHash as createHash4 } from "crypto";
|
|
228
231
|
import { createHmac } from "crypto";
|
|
232
|
+
import { createHash as createHash4 } from "crypto";
|
|
233
|
+
import { createHmac as createHmac2 } from "crypto";
|
|
229
234
|
import { readdir } from "fs/promises";
|
|
230
235
|
import { join } from "path";
|
|
231
236
|
import { pathToFileURL } from "url";
|
|
237
|
+
import { relative } from "path";
|
|
238
|
+
import { existsSync, mkdirSync, readdirSync, writeFileSync } from "fs";
|
|
239
|
+
import { join as join2 } from "path";
|
|
240
|
+
import { createHmac as createHmac4, randomBytes as randomBytes2, randomInt as randomInt2, timingSafeEqual as timingSafeEqual3 } from "crypto";
|
|
241
|
+
import { renderSVG } from "uqr";
|
|
242
|
+
import { randomInt } from "crypto";
|
|
243
|
+
import { createHmac as createHmac3, randomBytes, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
232
244
|
var AuthenticationError = class extends Error {
|
|
233
245
|
constructor(message = "Unauthenticated.", guards = [], redirectTo2) {
|
|
234
246
|
super(message);
|
|
@@ -241,6 +253,18 @@ var AuthenticationError = class extends Error {
|
|
|
241
253
|
status = 401;
|
|
242
254
|
name = "AuthenticationError";
|
|
243
255
|
};
|
|
256
|
+
var InvalidPasswordError = class extends Error {
|
|
257
|
+
name = "InvalidPasswordError";
|
|
258
|
+
constructor() {
|
|
259
|
+
super("The given password does not match the current password.");
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
var TwoFactorAppAlreadyEnabledError = class extends Error {
|
|
263
|
+
name = "TwoFactorAppAlreadyEnabledError";
|
|
264
|
+
constructor() {
|
|
265
|
+
super("This user's authenticator app is set up already. Call TwoFactor.disableApp(user) first to set up another.");
|
|
266
|
+
}
|
|
267
|
+
};
|
|
244
268
|
var AuthorizationError = class extends Error {
|
|
245
269
|
kind = "Authorization";
|
|
246
270
|
name = "AuthorizationError";
|
|
@@ -298,6 +322,22 @@ var Logout = class {
|
|
|
298
322
|
guard;
|
|
299
323
|
user;
|
|
300
324
|
};
|
|
325
|
+
var CurrentDeviceLogout = class {
|
|
326
|
+
constructor(guard2, user) {
|
|
327
|
+
this.guard = guard2;
|
|
328
|
+
this.user = user;
|
|
329
|
+
}
|
|
330
|
+
guard;
|
|
331
|
+
user;
|
|
332
|
+
};
|
|
333
|
+
var OtherDeviceLogout = class {
|
|
334
|
+
constructor(guard2, user) {
|
|
335
|
+
this.guard = guard2;
|
|
336
|
+
this.user = user;
|
|
337
|
+
}
|
|
338
|
+
guard;
|
|
339
|
+
user;
|
|
340
|
+
};
|
|
301
341
|
var PasswordReset = class {
|
|
302
342
|
constructor(user) {
|
|
303
343
|
this.user = user;
|
|
@@ -564,6 +604,13 @@ var EloquentUserProvider = class {
|
|
|
564
604
|
return this.model;
|
|
565
605
|
}
|
|
566
606
|
};
|
|
607
|
+
var passwordHashKey = (guard2) => `password_hash_${guard2}`;
|
|
608
|
+
function sessionPasswordHash(passwordHash, key) {
|
|
609
|
+
return createHmac("sha256", key).update(passwordHash).digest("hex");
|
|
610
|
+
}
|
|
611
|
+
function matchesSessionPasswordHash(passwordHash, stored, keys) {
|
|
612
|
+
return keys.some((key) => equals(sessionPasswordHash(passwordHash, key), stored));
|
|
613
|
+
}
|
|
567
614
|
var GUARD_HASH = createHash3("sha1").update("Oriel\\Auth\\SessionGuard").digest("hex");
|
|
568
615
|
var SessionGuard = class {
|
|
569
616
|
constructor(name, provider, container, options = {}) {
|
|
@@ -657,15 +704,74 @@ var SessionGuard = class {
|
|
|
657
704
|
/** Forgets the user, the session key and the remember cookie, and cycles the remember token. */
|
|
658
705
|
async logout() {
|
|
659
706
|
const user = await this.user();
|
|
660
|
-
this.#
|
|
661
|
-
const jar = this.#jar();
|
|
662
|
-
if (jar !== void 0 && this.#request()?.cookie(this.getRecallerName()) !== void 0) {
|
|
663
|
-
jar.queue(jar.forget(this.getRecallerName()));
|
|
664
|
-
}
|
|
707
|
+
this.#forget();
|
|
665
708
|
if (user !== void 0 && user.getRememberToken() !== void 0) await this.#cycleRememberToken(user);
|
|
666
709
|
await this.#dispatch(new Logout(this.name, user));
|
|
667
|
-
this.#
|
|
668
|
-
|
|
710
|
+
this.#signedOut();
|
|
711
|
+
}
|
|
712
|
+
/** Logs out here only: the remember token isn't cycled, so the user's other remembered devices keep working. */
|
|
713
|
+
async logoutCurrentDevice() {
|
|
714
|
+
const user = await this.user();
|
|
715
|
+
this.#forget();
|
|
716
|
+
await this.#dispatch(new CurrentDeviceLogout(this.name, user));
|
|
717
|
+
this.#signedOut();
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Ends the user's other sessions, on their next request through `auth.session`, by rehashing the password they gave.
|
|
721
|
+
* This session stays signed in, and so does this device's remember cookie. Undefined for a guest.
|
|
722
|
+
*/
|
|
723
|
+
async logoutOtherDevices(password) {
|
|
724
|
+
const user = await this.user();
|
|
725
|
+
if (user === void 0) return void 0;
|
|
726
|
+
if (!await this.container.make(Hasher).check(password, user.getAuthPassword())) throw new InvalidPasswordError();
|
|
727
|
+
const provider = this.provider;
|
|
728
|
+
if (provider.rehashPasswordIfRequired === void 0) throw new Error(`The [${this.name}] guard's user provider can't rehash a password.`);
|
|
729
|
+
await provider.rehashPasswordIfRequired(user, { password }, true);
|
|
730
|
+
this.keepPasswordHash();
|
|
731
|
+
const recaller = this.getRecallerName();
|
|
732
|
+
const mine = (value2) => value2?.split("|")[0] === String(user.getAuthIdentifier());
|
|
733
|
+
const remembered = mine(this.#request()?.cookie(recaller)) || this.#jar()?.queued().some((cookie2) => cookie2.name === recaller && mine(cookie2.value)) === true;
|
|
734
|
+
if (remembered) this.#queueRecallerCookie(user);
|
|
735
|
+
await this.#dispatch(new OtherDeviceLogout(this.name, user));
|
|
736
|
+
return user;
|
|
737
|
+
}
|
|
738
|
+
/** @internal Whether this request has a session: a cached page's route leaves StartSession out. */
|
|
739
|
+
hasStartedSession() {
|
|
740
|
+
const session2 = this.#session();
|
|
741
|
+
return session2 !== void 0 && (session2.isStarted?.() ?? true);
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* @internal For `auth.session`: whether the signed-in user's password is the one this session and this device's remember
|
|
745
|
+
* cookie were made with. A session with no stored hash stores one and carries on.
|
|
746
|
+
*/
|
|
747
|
+
passwordHashMatches() {
|
|
748
|
+
const user = this.#user;
|
|
749
|
+
if (user === void 0) return true;
|
|
750
|
+
if (this.#viaRemember) {
|
|
751
|
+
const remembered = this.#request()?.cookie(this.getRecallerName())?.split("|")[2];
|
|
752
|
+
if (remembered === void 0 || !equals(user.getAuthPassword(), remembered)) return false;
|
|
753
|
+
}
|
|
754
|
+
const stored = this.#session()?.get(passwordHashKey(this.name));
|
|
755
|
+
if (stored === void 0) {
|
|
756
|
+
this.keepPasswordHash();
|
|
757
|
+
return true;
|
|
758
|
+
}
|
|
759
|
+
return matchesSessionPasswordHash(user.getAuthPassword(), stored, this.#encryptionKeys());
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* @internal After a request: this session keeps the current password's hash, which covers a login and a new password,
|
|
763
|
+
* and `before` (the password the request began with) tells when this device's remember cookie needs the new one too.
|
|
764
|
+
*/
|
|
765
|
+
keepPasswordHash(before) {
|
|
766
|
+
const user = this.#user;
|
|
767
|
+
if (user === void 0) return;
|
|
768
|
+
const hash2 = user.getAuthPassword();
|
|
769
|
+
if (hash2 === "") return;
|
|
770
|
+
this.#session()?.put(passwordHashKey(this.name), sessionPasswordHash(hash2, this.#encryptionKeys()[0]));
|
|
771
|
+
const recaller = this.#request()?.cookie(this.getRecallerName());
|
|
772
|
+
if (before !== void 0 && before !== hash2 && recaller?.split("|")[0] === String(user.getAuthIdentifier())) {
|
|
773
|
+
this.#queueRecallerCookie(user);
|
|
774
|
+
}
|
|
669
775
|
}
|
|
670
776
|
hasUser() {
|
|
671
777
|
return this.#user !== void 0;
|
|
@@ -689,6 +795,23 @@ var SessionGuard = class {
|
|
|
689
795
|
getRecallerName() {
|
|
690
796
|
return `remember_${this.name}_${GUARD_HASH}`;
|
|
691
797
|
}
|
|
798
|
+
/** Forgets the session key and, when this request had one, the remember cookie. */
|
|
799
|
+
#forget() {
|
|
800
|
+
this.#session()?.forget(this.getName());
|
|
801
|
+
const jar = this.#jar();
|
|
802
|
+
if (jar !== void 0 && this.#request()?.cookie(this.getRecallerName()) !== void 0) {
|
|
803
|
+
jar.queue(jar.forget(this.getRecallerName()));
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
#signedOut() {
|
|
807
|
+
this.#user = void 0;
|
|
808
|
+
this.#loggedOut = true;
|
|
809
|
+
}
|
|
810
|
+
/** The app's keys, the current one first. */
|
|
811
|
+
#encryptionKeys() {
|
|
812
|
+
const encrypter = this.container.make(Encrypter);
|
|
813
|
+
return encrypter.getAllKeys?.() ?? [encrypter.getKey()];
|
|
814
|
+
}
|
|
692
815
|
async #hasValidCredentials(user, credentials) {
|
|
693
816
|
const valid = user !== void 0 && await this.provider.validateCredentials(user, credentials);
|
|
694
817
|
if (valid) await this.#dispatch(new Validated(this.name, user));
|
|
@@ -1057,6 +1180,14 @@ var AuthManager = class {
|
|
|
1057
1180
|
async logout() {
|
|
1058
1181
|
return this.#stateful().logout();
|
|
1059
1182
|
}
|
|
1183
|
+
/** Logs the default guard out on this device only (the remember token isn't cycled). */
|
|
1184
|
+
async logoutCurrentDevice() {
|
|
1185
|
+
return this.#deviceGuard().logoutCurrentDevice();
|
|
1186
|
+
}
|
|
1187
|
+
/** Ends the user's other sessions, on their next request through `auth.session`. This one stays signed in. */
|
|
1188
|
+
async logoutOtherDevices(password) {
|
|
1189
|
+
return this.#deviceGuard().logoutOtherDevices(password);
|
|
1190
|
+
}
|
|
1060
1191
|
viaRemember() {
|
|
1061
1192
|
const guard2 = this.guard();
|
|
1062
1193
|
return guard2.viaRemember?.() ?? false;
|
|
@@ -1119,6 +1250,13 @@ var AuthManager = class {
|
|
|
1119
1250
|
state.resolverInstalled = true;
|
|
1120
1251
|
container.make(HttpRequest).setUserResolver((guard2) => this.guardIn(container, guard2).user());
|
|
1121
1252
|
}
|
|
1253
|
+
#deviceGuard() {
|
|
1254
|
+
const guard2 = this.guard();
|
|
1255
|
+
if (typeof guard2.logoutOtherDevices !== "function") {
|
|
1256
|
+
throw new Error(`The [${guard2.name ?? this.#state(this.#container()).defaultGuard ?? this.getDefaultDriver()}] guard can't log out other devices.`);
|
|
1257
|
+
}
|
|
1258
|
+
return guard2;
|
|
1259
|
+
}
|
|
1122
1260
|
#stateful() {
|
|
1123
1261
|
const guard2 = this.guard();
|
|
1124
1262
|
if (typeof guard2.attempt !== "function") {
|
|
@@ -1468,7 +1606,7 @@ var DatabaseTokenRepository = class {
|
|
|
1468
1606
|
async create(user) {
|
|
1469
1607
|
const email = user.getEmailForPasswordReset();
|
|
1470
1608
|
await this.#query().where("email", email).delete();
|
|
1471
|
-
const token2 =
|
|
1609
|
+
const token2 = createHmac2("sha256", this.hashKey).update(Str.random(40)).digest("hex");
|
|
1472
1610
|
await this.#query().insert({ email, token: await this.hasher.make(token2), created_at: this.clock() });
|
|
1473
1611
|
return token2;
|
|
1474
1612
|
}
|
|
@@ -1583,6 +1721,11 @@ var PasswordBrokerManager = class {
|
|
|
1583
1721
|
return new PasswordBroker2(tokens, auth2.createUserProvider(settings.provider));
|
|
1584
1722
|
}
|
|
1585
1723
|
};
|
|
1724
|
+
function guestRedirect(request2, config2) {
|
|
1725
|
+
const target = config2.get("http.redirect_guests_to");
|
|
1726
|
+
if (typeof target === "function") return String(target(request2));
|
|
1727
|
+
return typeof target === "string" && target !== "" ? target : void 0;
|
|
1728
|
+
}
|
|
1586
1729
|
var Authenticate = class {
|
|
1587
1730
|
auth = inject(AuthFactory);
|
|
1588
1731
|
config = inject(ConfigRepository);
|
|
@@ -1604,9 +1747,25 @@ var Authenticate = class {
|
|
|
1604
1747
|
}
|
|
1605
1748
|
/** config('http.redirect_guests_to') (set by withMiddleware(m => m.redirectGuestsTo(...))); Http falls back to route('login'). */
|
|
1606
1749
|
redirectTo(request2) {
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1750
|
+
return guestRedirect(request2, this.config);
|
|
1751
|
+
}
|
|
1752
|
+
};
|
|
1753
|
+
var AuthenticateSession = class {
|
|
1754
|
+
auth = inject(AuthFactory);
|
|
1755
|
+
config = inject(ConfigRepository);
|
|
1756
|
+
async handle(request2, next) {
|
|
1757
|
+
const guard2 = this.auth.guard();
|
|
1758
|
+
if (guard2.hasStartedSession?.() !== true) return next(request2);
|
|
1759
|
+
const session2 = guard2;
|
|
1760
|
+
const before = (await session2.user())?.getAuthPassword();
|
|
1761
|
+
if (before !== void 0 && before !== "" && !session2.passwordHashMatches()) {
|
|
1762
|
+
await session2.logoutCurrentDevice();
|
|
1763
|
+
inject(Session).flush();
|
|
1764
|
+
throw new AuthenticationError("Unauthenticated.", [session2.name], request2.expectsJson() ? void 0 : guestRedirect(request2, this.config));
|
|
1765
|
+
}
|
|
1766
|
+
const response2 = await next(request2);
|
|
1767
|
+
session2.keepPasswordHash(before);
|
|
1768
|
+
return response2;
|
|
1610
1769
|
}
|
|
1611
1770
|
};
|
|
1612
1771
|
async function redirectTo(container, request2, url2, guest = false) {
|
|
@@ -1682,6 +1841,461 @@ function auth(guard2) {
|
|
|
1682
1841
|
const manager2 = inject(AuthFactory);
|
|
1683
1842
|
return guard2 === void 0 ? manager2 : manager2.guard(guard2);
|
|
1684
1843
|
}
|
|
1844
|
+
var TWO_FACTOR_DEFAULTS = {
|
|
1845
|
+
enabled: false,
|
|
1846
|
+
methods: ["email", "app"],
|
|
1847
|
+
default: "email",
|
|
1848
|
+
code_ttl: 600,
|
|
1849
|
+
pending_ttl: 600,
|
|
1850
|
+
max_attempts: 5,
|
|
1851
|
+
resend_after: 30,
|
|
1852
|
+
window: 1,
|
|
1853
|
+
recovery_codes: 8
|
|
1854
|
+
};
|
|
1855
|
+
function twoFactorConfig(config2) {
|
|
1856
|
+
return { ...TWO_FACTOR_DEFAULTS, ...config2.get("auth.two_factor", {}) };
|
|
1857
|
+
}
|
|
1858
|
+
var TWO_FACTOR_COLUMNS_MIGRATION = `import { Migration, Schema } from '@orieljs/framework'
|
|
1859
|
+
|
|
1860
|
+
export default class extends Migration {
|
|
1861
|
+
async up() {
|
|
1862
|
+
await Schema.table('users', (t) => {
|
|
1863
|
+
t.text('two_factor_secret').nullable()
|
|
1864
|
+
t.text('two_factor_recovery_codes').nullable()
|
|
1865
|
+
t.timestamp('two_factor_confirmed_at').nullable()
|
|
1866
|
+
t.string('two_factor_method', 10).nullable()
|
|
1867
|
+
})
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
async down() {
|
|
1871
|
+
await Schema.table('users', (t) => {
|
|
1872
|
+
t.dropColumn('two_factor_secret', 'two_factor_recovery_codes', 'two_factor_confirmed_at', 'two_factor_method')
|
|
1873
|
+
})
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
`;
|
|
1877
|
+
var NAME = "add_two_factor_columns_to_users_table";
|
|
1878
|
+
var pad = (value2) => String(value2).padStart(2, "0");
|
|
1879
|
+
function installTwoFactorMigration(directory, now5 = /* @__PURE__ */ new Date()) {
|
|
1880
|
+
if (existsSync(directory) && readdirSync(directory).some((file) => file.endsWith(`_${NAME}.ts`))) {
|
|
1881
|
+
throw new Error("The two-factor migration is there already: run `oriel migrate`.");
|
|
1882
|
+
}
|
|
1883
|
+
mkdirSync(directory, { recursive: true });
|
|
1884
|
+
const stamp = `${now5.getFullYear()}_${pad(now5.getMonth() + 1)}_${pad(now5.getDate())}_${pad(now5.getHours())}${pad(now5.getMinutes())}${pad(now5.getSeconds())}`;
|
|
1885
|
+
const path = join2(directory, `${stamp}_${NAME}.ts`);
|
|
1886
|
+
writeFileSync(path, TWO_FACTOR_COLUMNS_MIGRATION);
|
|
1887
|
+
return path;
|
|
1888
|
+
}
|
|
1889
|
+
var TwoFactorChallenged = class {
|
|
1890
|
+
constructor(user, method) {
|
|
1891
|
+
this.user = user;
|
|
1892
|
+
this.method = method;
|
|
1893
|
+
}
|
|
1894
|
+
user;
|
|
1895
|
+
method;
|
|
1896
|
+
};
|
|
1897
|
+
var TwoFactorFailed = class {
|
|
1898
|
+
constructor(user, method) {
|
|
1899
|
+
this.user = user;
|
|
1900
|
+
this.method = method;
|
|
1901
|
+
}
|
|
1902
|
+
user;
|
|
1903
|
+
method;
|
|
1904
|
+
};
|
|
1905
|
+
var TwoFactorAuthenticated = class {
|
|
1906
|
+
constructor(user, method) {
|
|
1907
|
+
this.user = user;
|
|
1908
|
+
this.method = method;
|
|
1909
|
+
}
|
|
1910
|
+
user;
|
|
1911
|
+
method;
|
|
1912
|
+
};
|
|
1913
|
+
var RecoveryCodeUsed = class {
|
|
1914
|
+
constructor(user) {
|
|
1915
|
+
this.user = user;
|
|
1916
|
+
}
|
|
1917
|
+
user;
|
|
1918
|
+
};
|
|
1919
|
+
var TwoFactorAppEnabled = class {
|
|
1920
|
+
constructor(user) {
|
|
1921
|
+
this.user = user;
|
|
1922
|
+
}
|
|
1923
|
+
user;
|
|
1924
|
+
};
|
|
1925
|
+
var TwoFactorAppDisabled = class {
|
|
1926
|
+
constructor(user) {
|
|
1927
|
+
this.user = user;
|
|
1928
|
+
}
|
|
1929
|
+
user;
|
|
1930
|
+
};
|
|
1931
|
+
function qrSvg(text4) {
|
|
1932
|
+
return renderSVG(text4);
|
|
1933
|
+
}
|
|
1934
|
+
var CHARACTERS = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
1935
|
+
var part = () => Array.from({ length: 5 }, () => CHARACTERS[randomInt(CHARACTERS.length)]).join("");
|
|
1936
|
+
function generateRecoveryCodes(count = 8) {
|
|
1937
|
+
const codes = /* @__PURE__ */ new Set();
|
|
1938
|
+
while (codes.size < count) codes.add(`${part()}-${part()}`);
|
|
1939
|
+
return [...codes];
|
|
1940
|
+
}
|
|
1941
|
+
function normalizeCode(input) {
|
|
1942
|
+
return input.replace(/[\s-]/g, "").toLowerCase();
|
|
1943
|
+
}
|
|
1944
|
+
var TwoFactorStore = class {
|
|
1945
|
+
constructor(encrypter, config2) {
|
|
1946
|
+
this.encrypter = encrypter;
|
|
1947
|
+
this.config = config2;
|
|
1948
|
+
}
|
|
1949
|
+
encrypter;
|
|
1950
|
+
config;
|
|
1951
|
+
secret(user) {
|
|
1952
|
+
const stored = user.getAttribute("two_factor_secret");
|
|
1953
|
+
return stored ? this.encrypter.decryptString(stored) : void 0;
|
|
1954
|
+
}
|
|
1955
|
+
/** A new secret (or none) is unconfirmed until confirm(). */
|
|
1956
|
+
async setSecret(user, secret) {
|
|
1957
|
+
user.setAttribute("two_factor_secret", secret === null ? null : this.encrypter.encryptString(secret));
|
|
1958
|
+
user.setAttribute("two_factor_confirmed_at", null);
|
|
1959
|
+
await user.save();
|
|
1960
|
+
}
|
|
1961
|
+
confirmedAt(user) {
|
|
1962
|
+
const stored = user.getAttribute("two_factor_confirmed_at");
|
|
1963
|
+
return stored ? new Date(stored) : void 0;
|
|
1964
|
+
}
|
|
1965
|
+
async confirm(user) {
|
|
1966
|
+
user.setAttribute("two_factor_confirmed_at", /* @__PURE__ */ new Date());
|
|
1967
|
+
await user.save();
|
|
1968
|
+
}
|
|
1969
|
+
recoveryCodes(user) {
|
|
1970
|
+
const stored = user.getAttribute("two_factor_recovery_codes");
|
|
1971
|
+
return stored ? JSON.parse(this.encrypter.decryptString(stored)) : [];
|
|
1972
|
+
}
|
|
1973
|
+
async setRecoveryCodes(user, codes) {
|
|
1974
|
+
user.setAttribute("two_factor_recovery_codes", this.encrypter.encryptString(JSON.stringify(codes)));
|
|
1975
|
+
await user.save();
|
|
1976
|
+
}
|
|
1977
|
+
/** Whether the user's authenticator counts: set up and confirmed. */
|
|
1978
|
+
hasApp(user) {
|
|
1979
|
+
return this.secret(user) !== void 0 && this.confirmedAt(user) !== void 0;
|
|
1980
|
+
}
|
|
1981
|
+
/** The methods open to the user now: the app's, of those the user can use. */
|
|
1982
|
+
methods(user) {
|
|
1983
|
+
return this.config().methods.filter((method) => method === "email" || this.hasApp(user));
|
|
1984
|
+
}
|
|
1985
|
+
/** The method the user is asked for: the one they chose if they can use it, else the app's default, else another. */
|
|
1986
|
+
method(user) {
|
|
1987
|
+
const open = this.methods(user);
|
|
1988
|
+
const chosen = user.getAttribute("two_factor_method");
|
|
1989
|
+
if (chosen && open.includes(chosen)) return chosen;
|
|
1990
|
+
return open.includes(this.config().default) ? this.config().default : open[0];
|
|
1991
|
+
}
|
|
1992
|
+
async setMethod(user, method) {
|
|
1993
|
+
user.setAttribute("two_factor_method", method);
|
|
1994
|
+
await user.save();
|
|
1995
|
+
}
|
|
1996
|
+
};
|
|
1997
|
+
var toMailCallback3;
|
|
1998
|
+
var TwoFactorCode = class {
|
|
1999
|
+
constructor(code, minutes) {
|
|
2000
|
+
this.code = code;
|
|
2001
|
+
this.minutes = minutes;
|
|
2002
|
+
}
|
|
2003
|
+
code;
|
|
2004
|
+
minutes;
|
|
2005
|
+
/** Build the mail yourself (e.g. a MailMessage from the Notifications component). */
|
|
2006
|
+
static toMailUsing(callback) {
|
|
2007
|
+
toMailCallback3 = callback;
|
|
2008
|
+
}
|
|
2009
|
+
via() {
|
|
2010
|
+
return ["mail"];
|
|
2011
|
+
}
|
|
2012
|
+
toMail(notifiable) {
|
|
2013
|
+
if (toMailCallback3 !== void 0) return toMailCallback3(notifiable, this.code, this.minutes);
|
|
2014
|
+
return {
|
|
2015
|
+
subject: "Your sign-in code",
|
|
2016
|
+
lines: [`Your sign-in code is ${this.code}.`, `It works once, for ${this.minutes} minutes.`],
|
|
2017
|
+
outroLines: ["If you didn't just try to sign in, someone else knows your password: change it."]
|
|
2018
|
+
};
|
|
2019
|
+
}
|
|
2020
|
+
};
|
|
2021
|
+
var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
2022
|
+
var STEP_SECONDS = 30;
|
|
2023
|
+
function base32Encode(bytes) {
|
|
2024
|
+
let bits = 0;
|
|
2025
|
+
let value2 = 0;
|
|
2026
|
+
let out = "";
|
|
2027
|
+
for (const byte of bytes) {
|
|
2028
|
+
value2 = value2 << 8 | byte;
|
|
2029
|
+
bits += 8;
|
|
2030
|
+
while (bits >= 5) {
|
|
2031
|
+
out += ALPHABET[value2 >>> bits - 5 & 31];
|
|
2032
|
+
bits -= 5;
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
if (bits > 0) out += ALPHABET[value2 << 5 - bits & 31];
|
|
2036
|
+
return out;
|
|
2037
|
+
}
|
|
2038
|
+
function base32Decode(text4) {
|
|
2039
|
+
const clean = text4.replace(/[\s=]/g, "").toUpperCase();
|
|
2040
|
+
const out = [];
|
|
2041
|
+
let bits = 0;
|
|
2042
|
+
let value2 = 0;
|
|
2043
|
+
for (const char of clean) {
|
|
2044
|
+
const index = ALPHABET.indexOf(char);
|
|
2045
|
+
if (index === -1) throw new Error("Not a base32 secret.");
|
|
2046
|
+
value2 = value2 << 5 | index;
|
|
2047
|
+
bits += 5;
|
|
2048
|
+
if (bits >= 8) {
|
|
2049
|
+
out.push(value2 >>> bits - 8 & 255);
|
|
2050
|
+
bits -= 8;
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
return new Uint8Array(out);
|
|
2054
|
+
}
|
|
2055
|
+
function generateSecret() {
|
|
2056
|
+
return base32Encode(new Uint8Array(randomBytes(20)));
|
|
2057
|
+
}
|
|
2058
|
+
function totpCode(secret, at, step = Math.floor(at / 1e3 / STEP_SECONDS)) {
|
|
2059
|
+
const counter = Buffer.alloc(8);
|
|
2060
|
+
counter.writeBigUInt64BE(BigInt(step));
|
|
2061
|
+
const hmac = createHmac3("sha1", base32Decode(secret)).update(counter).digest();
|
|
2062
|
+
const offset = hmac[hmac.length - 1] & 15;
|
|
2063
|
+
const binary = (hmac[offset] & 127) << 24 | hmac[offset + 1] << 16 | hmac[offset + 2] << 8 | hmac[offset + 3];
|
|
2064
|
+
return String(binary % 1e6).padStart(6, "0");
|
|
2065
|
+
}
|
|
2066
|
+
function verifyTotp(secret, code, at, window = 1) {
|
|
2067
|
+
if (!/^\d{6}$/.test(code)) return void 0;
|
|
2068
|
+
const now5 = Math.floor(at / 1e3 / STEP_SECONDS);
|
|
2069
|
+
let matched;
|
|
2070
|
+
for (let step = now5 - window; step <= now5 + window; step++) {
|
|
2071
|
+
if (timingSafeEqual2(Buffer.from(totpCode(secret, at, step)), Buffer.from(code)) && matched === void 0) matched = step;
|
|
2072
|
+
}
|
|
2073
|
+
return matched;
|
|
2074
|
+
}
|
|
2075
|
+
function otpauthUrl(options) {
|
|
2076
|
+
const issuer = encodeURIComponent(options.issuer);
|
|
2077
|
+
return `otpauth://totp/${issuer}:${encodeURIComponent(options.account)}?secret=${options.secret}&issuer=${issuer}&algorithm=SHA1&digits=6&period=${STEP_SECONDS}`;
|
|
2078
|
+
}
|
|
2079
|
+
var PENDING_LOGIN = "oriel.two_factor.login";
|
|
2080
|
+
var pendingKey = (nonce) => `oriel:two-factor:pending:${nonce}`;
|
|
2081
|
+
var emailKey = (id) => `oriel:two-factor:email:${String(id)}`;
|
|
2082
|
+
var stepKey = (id) => `oriel:two-factor:totp:${String(id)}`;
|
|
2083
|
+
function maskEmail(email) {
|
|
2084
|
+
const [name = "", domain = ""] = String(email ?? "").split("@");
|
|
2085
|
+
return `${name.slice(0, 1)}***@${domain}`;
|
|
2086
|
+
}
|
|
2087
|
+
var TwoFactorManager = class {
|
|
2088
|
+
#requireWhen;
|
|
2089
|
+
/** Who is asked for a second factor when two-factor is on. Default: everyone. */
|
|
2090
|
+
requireWhen(callback) {
|
|
2091
|
+
this.#requireWhen = callback;
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* Checks the credentials. `'authenticated'`: logged in (two-factor off, not required for this user, or no method
|
|
2095
|
+
* open to them). `'challenge'`: the password was right and the code is asked for (an email method's code is sent
|
|
2096
|
+
* now). `false`: wrong credentials.
|
|
2097
|
+
*/
|
|
2098
|
+
async attempt(credentials, remember = false) {
|
|
2099
|
+
const config2 = this.#config();
|
|
2100
|
+
const guard2 = this.#guard();
|
|
2101
|
+
if (!config2.enabled) return await guard2.attempt(credentials, remember) ? "authenticated" : false;
|
|
2102
|
+
const guardName = inject(ConfigRepository).get("auth.defaults.guard", "web");
|
|
2103
|
+
await this.#dispatch(new Attempting(guardName, credentials, remember));
|
|
2104
|
+
const valid = await guard2.validate(credentials);
|
|
2105
|
+
const user = guard2.getLastAttempted();
|
|
2106
|
+
if (!valid || user === void 0) {
|
|
2107
|
+
await this.#dispatch(new Failed(guardName, user, credentials));
|
|
2108
|
+
return false;
|
|
2109
|
+
}
|
|
2110
|
+
const method = this.#store().method(user);
|
|
2111
|
+
if (method === void 0 || !await (this.#requireWhen?.(user) ?? true)) {
|
|
2112
|
+
await guard2.login(user, remember);
|
|
2113
|
+
return "authenticated";
|
|
2114
|
+
}
|
|
2115
|
+
const nonce = randomBytes2(16).toString("hex");
|
|
2116
|
+
const record = { id: user.getAuthIdentifier(), remember, method, expires: Date.now() + config2.pending_ttl * 1e3, attempts: 0, nonce };
|
|
2117
|
+
inject(Session).put(PENDING_LOGIN, record);
|
|
2118
|
+
await inject(CacheManager).put(pendingKey(nonce), true, config2.pending_ttl);
|
|
2119
|
+
if (method === "email") await this.#sendCode(user);
|
|
2120
|
+
await this.#dispatch(new TwoFactorChallenged(user, method));
|
|
2121
|
+
return "challenge";
|
|
2122
|
+
}
|
|
2123
|
+
/** The pending login, for the challenge page: the method asked for, the others open, and where an email code went. */
|
|
2124
|
+
async challenge() {
|
|
2125
|
+
const pending = await this.#pending();
|
|
2126
|
+
if (pending === void 0) return void 0;
|
|
2127
|
+
return { method: pending.record.method, methods: this.#store().methods(pending.user), email: maskEmail(pending.user.getAttribute("email")) };
|
|
2128
|
+
}
|
|
2129
|
+
/** A 6-digit code for the pending method, or a recovery code. True: the user is logged in. */
|
|
2130
|
+
async verify(code) {
|
|
2131
|
+
const pending = await this.#pending();
|
|
2132
|
+
if (pending === void 0) return false;
|
|
2133
|
+
const { record, user } = pending;
|
|
2134
|
+
const typed = normalizeCode(code);
|
|
2135
|
+
let used;
|
|
2136
|
+
if (/^\d{6}$/.test(typed)) {
|
|
2137
|
+
if (record.method === "app" ? await this.#checkApp(user, typed) : await this.#checkEmail(user, typed)) used = record.method;
|
|
2138
|
+
} else if (/^[a-z0-9]{10}$/.test(typed) && await this.#checkRecovery(user, typed)) {
|
|
2139
|
+
used = "recovery";
|
|
2140
|
+
}
|
|
2141
|
+
if (used === void 0) {
|
|
2142
|
+
record.attempts++;
|
|
2143
|
+
await this.#dispatch(new TwoFactorFailed(user, record.method));
|
|
2144
|
+
if (record.attempts >= this.#config().max_attempts) await this.#end(record);
|
|
2145
|
+
else inject(Session).put(PENDING_LOGIN, record);
|
|
2146
|
+
return false;
|
|
2147
|
+
}
|
|
2148
|
+
await this.#end(record);
|
|
2149
|
+
await this.#guard().login(user, record.remember);
|
|
2150
|
+
await this.#dispatch(new TwoFactorAuthenticated(user, used));
|
|
2151
|
+
return true;
|
|
2152
|
+
}
|
|
2153
|
+
/** Asks for another of the user's methods; switching to email sends a code. */
|
|
2154
|
+
async useMethod(method) {
|
|
2155
|
+
const pending = await this.#pending();
|
|
2156
|
+
if (pending === void 0 || !this.#store().methods(pending.user).includes(method)) return;
|
|
2157
|
+
pending.record.method = method;
|
|
2158
|
+
inject(Session).put(PENDING_LOGIN, pending.record);
|
|
2159
|
+
if (method === "email") await this.#sendCode(pending.user);
|
|
2160
|
+
}
|
|
2161
|
+
/** Sends a new email code; false within `resend_after` seconds of the last one, or when the method isn't email. */
|
|
2162
|
+
async resend() {
|
|
2163
|
+
const pending = await this.#pending();
|
|
2164
|
+
if (pending === void 0 || pending.record.method !== "email") return false;
|
|
2165
|
+
const last = await inject(CacheManager).get(emailKey(pending.record.id));
|
|
2166
|
+
if (last !== void 0 && Date.now() - last.sent < this.#config().resend_after * 1e3) return false;
|
|
2167
|
+
await this.#sendCode(pending.user);
|
|
2168
|
+
return true;
|
|
2169
|
+
}
|
|
2170
|
+
/**
|
|
2171
|
+
* Starts setting up an authenticator app: a new secret (unconfirmed, so it doesn't count yet), the `otpauth://` URL
|
|
2172
|
+
* and a QR code of it for the app to scan. A user whose app already works must disableApp() first: a new secret would
|
|
2173
|
+
* stop the old app's codes without a word.
|
|
2174
|
+
*/
|
|
2175
|
+
async enableApp(user) {
|
|
2176
|
+
if (this.#store().hasApp(user)) throw new TwoFactorAppAlreadyEnabledError();
|
|
2177
|
+
const secret = generateSecret();
|
|
2178
|
+
await this.#store().setSecret(user, secret);
|
|
2179
|
+
const issuer = this.#config().issuer ?? inject(ConfigRepository).get("app.name", "Oriel");
|
|
2180
|
+
const url2 = otpauthUrl({ secret, issuer, account: String(user.getAttribute("email") ?? user.getAuthIdentifier()) });
|
|
2181
|
+
return { secret, url: url2, svg: qrSvg(url2) };
|
|
2182
|
+
}
|
|
2183
|
+
/** Whether the user's authenticator app works: set up and confirmed. */
|
|
2184
|
+
hasApp(user) {
|
|
2185
|
+
return this.#store().hasApp(user);
|
|
2186
|
+
}
|
|
2187
|
+
/** Confirms the app with a code from it: then it counts, becomes the user's method, and recovery codes are made. */
|
|
2188
|
+
async confirmApp(user, code) {
|
|
2189
|
+
const store = this.#store();
|
|
2190
|
+
const secret = store.secret(user);
|
|
2191
|
+
if (secret === void 0 || verifyTotp(secret, normalizeCode(code), Date.now(), this.#config().window) === void 0) return false;
|
|
2192
|
+
await store.confirm(user);
|
|
2193
|
+
await store.setMethod(user, "app");
|
|
2194
|
+
if (store.recoveryCodes(user).length === 0) await store.setRecoveryCodes(user, generateRecoveryCodes(this.#config().recovery_codes));
|
|
2195
|
+
await this.#dispatch(new TwoFactorAppEnabled(user));
|
|
2196
|
+
return true;
|
|
2197
|
+
}
|
|
2198
|
+
/** Removes the authenticator app: the secret is forgotten and the user is asked by email again. */
|
|
2199
|
+
async disableApp(user) {
|
|
2200
|
+
const store = this.#store();
|
|
2201
|
+
await store.setSecret(user, null);
|
|
2202
|
+
await store.setMethod(user, null);
|
|
2203
|
+
await this.#dispatch(new TwoFactorAppDisabled(user));
|
|
2204
|
+
}
|
|
2205
|
+
/** The method the user prefers; one they can't use (an unconfirmed app, one the app turned off) isn't asked for. */
|
|
2206
|
+
async setMethod(user, method) {
|
|
2207
|
+
await this.#store().setMethod(user, method);
|
|
2208
|
+
}
|
|
2209
|
+
/** The user's recovery codes, made on first ask (show them once, and offer to make new ones). */
|
|
2210
|
+
async recoveryCodes(user) {
|
|
2211
|
+
const store = this.#store();
|
|
2212
|
+
const codes = store.recoveryCodes(user);
|
|
2213
|
+
if (codes.length > 0) return codes;
|
|
2214
|
+
return this.regenerateRecoveryCodes(user);
|
|
2215
|
+
}
|
|
2216
|
+
/** New recovery codes; the old ones stop working. */
|
|
2217
|
+
async regenerateRecoveryCodes(user) {
|
|
2218
|
+
const codes = generateRecoveryCodes(this.#config().recovery_codes);
|
|
2219
|
+
await this.#store().setRecoveryCodes(user, codes);
|
|
2220
|
+
return codes;
|
|
2221
|
+
}
|
|
2222
|
+
#config() {
|
|
2223
|
+
return twoFactorConfig(inject(ConfigRepository));
|
|
2224
|
+
}
|
|
2225
|
+
#store() {
|
|
2226
|
+
return new TwoFactorStore(inject(Encrypter), () => this.#config());
|
|
2227
|
+
}
|
|
2228
|
+
#guard() {
|
|
2229
|
+
return inject(AuthFactory).guard();
|
|
2230
|
+
}
|
|
2231
|
+
async #dispatch(event2) {
|
|
2232
|
+
const container = currentContainer();
|
|
2233
|
+
if (container?.bound(EventDispatcher)) await container.make(EventDispatcher).dispatch(event2);
|
|
2234
|
+
}
|
|
2235
|
+
/** The live pending login and its user; an expired, replayed or orphaned one is forgotten. */
|
|
2236
|
+
async #pending() {
|
|
2237
|
+
const session2 = inject(Session);
|
|
2238
|
+
const record = session2.get(PENDING_LOGIN);
|
|
2239
|
+
if (record === void 0 || record === null) return void 0;
|
|
2240
|
+
const live2 = record.expires > Date.now() && await inject(CacheManager).get(pendingKey(record.nonce)) === true;
|
|
2241
|
+
const user = live2 ? await this.#guard().provider.retrieveById(record.id) : void 0;
|
|
2242
|
+
if (user === void 0) {
|
|
2243
|
+
session2.forget(PENDING_LOGIN);
|
|
2244
|
+
return void 0;
|
|
2245
|
+
}
|
|
2246
|
+
return { record, user };
|
|
2247
|
+
}
|
|
2248
|
+
async #end(record) {
|
|
2249
|
+
inject(Session).forget(PENDING_LOGIN);
|
|
2250
|
+
await inject(CacheManager).forget(pendingKey(record.nonce));
|
|
2251
|
+
}
|
|
2252
|
+
#hash(code) {
|
|
2253
|
+
return createHmac4("sha256", inject(Encrypter).getKey()).update(code).digest("hex");
|
|
2254
|
+
}
|
|
2255
|
+
async #sendCode(user) {
|
|
2256
|
+
const config2 = this.#config();
|
|
2257
|
+
const code = String(randomInt2(1e6)).padStart(6, "0");
|
|
2258
|
+
const now5 = Date.now();
|
|
2259
|
+
const stored = { hash: this.#hash(code), sent: now5, expires: now5 + config2.code_ttl * 1e3 };
|
|
2260
|
+
await inject(CacheManager).put(emailKey(user.getAuthIdentifier()), stored, config2.code_ttl);
|
|
2261
|
+
await sendNotification(user, new TwoFactorCode(code, Math.round(config2.code_ttl / 60)));
|
|
2262
|
+
}
|
|
2263
|
+
async #checkEmail(user, code) {
|
|
2264
|
+
const cache2 = inject(CacheManager);
|
|
2265
|
+
const stored = await cache2.get(emailKey(user.getAuthIdentifier()));
|
|
2266
|
+
if (stored === void 0 || stored.expires <= Date.now()) return false;
|
|
2267
|
+
if (!timingSafeEqual3(Buffer.from(stored.hash), Buffer.from(this.#hash(code)))) return false;
|
|
2268
|
+
await cache2.forget(emailKey(user.getAuthIdentifier()));
|
|
2269
|
+
return true;
|
|
2270
|
+
}
|
|
2271
|
+
async #checkApp(user, code) {
|
|
2272
|
+
const store = this.#store();
|
|
2273
|
+
const secret = store.secret(user);
|
|
2274
|
+
if (secret === void 0 || !store.hasApp(user)) return false;
|
|
2275
|
+
const step = verifyTotp(secret, code, Date.now(), this.#config().window);
|
|
2276
|
+
if (step === void 0) return false;
|
|
2277
|
+
const cache2 = inject(CacheManager);
|
|
2278
|
+
const last = await cache2.get(stepKey(user.getAuthIdentifier()));
|
|
2279
|
+
if (last !== void 0 && step <= last) return false;
|
|
2280
|
+
await cache2.put(stepKey(user.getAuthIdentifier()), step, 300);
|
|
2281
|
+
return true;
|
|
2282
|
+
}
|
|
2283
|
+
async #checkRecovery(user, code) {
|
|
2284
|
+
const store = this.#store();
|
|
2285
|
+
const codes = store.recoveryCodes(user);
|
|
2286
|
+
const index = codes.findIndex((candidate) => normalizeCode(candidate) === code);
|
|
2287
|
+
if (index === -1) return false;
|
|
2288
|
+
await store.setRecoveryCodes(user, codes.filter((_, i) => i !== index));
|
|
2289
|
+
await this.#dispatch(new RecoveryCodeUsed(user));
|
|
2290
|
+
return true;
|
|
2291
|
+
}
|
|
2292
|
+
};
|
|
2293
|
+
var TwoFactorChallenge = class {
|
|
2294
|
+
async handle(request2, next) {
|
|
2295
|
+
if (await inject(TwoFactorManager).challenge() === void 0) throw new AuthenticationError("Log in first.");
|
|
2296
|
+
return next(request2);
|
|
2297
|
+
}
|
|
2298
|
+
};
|
|
1685
2299
|
var AuthServiceProvider = class extends ServiceProvider {
|
|
1686
2300
|
register() {
|
|
1687
2301
|
this.mergeConfigFrom(
|
|
@@ -1693,7 +2307,8 @@ var AuthServiceProvider = class extends ServiceProvider {
|
|
|
1693
2307
|
},
|
|
1694
2308
|
providers: { users: { driver: "eloquent", model: null } },
|
|
1695
2309
|
passwords: { users: { provider: "users", table: "password_reset_tokens", expire: 60, throttle: 60 } },
|
|
1696
|
-
password_timeout: 10800
|
|
2310
|
+
password_timeout: 10800,
|
|
2311
|
+
two_factor: { ...TWO_FACTOR_DEFAULTS }
|
|
1697
2312
|
},
|
|
1698
2313
|
"auth"
|
|
1699
2314
|
);
|
|
@@ -1703,15 +2318,29 @@ var AuthServiceProvider = class extends ServiceProvider {
|
|
|
1703
2318
|
this.app.singleton(PasswordBrokerManager, (container) => new PasswordBrokerManager(container));
|
|
1704
2319
|
this.app.singleton(PasswordBroker, (container) => container.make(PasswordBrokerManager).broker());
|
|
1705
2320
|
this.app.singleton(TokenRepository, (container) => new TokenRepository(() => container.make(DatabaseManager)));
|
|
2321
|
+
this.app.singleton(TwoFactorManager, () => new TwoFactorManager());
|
|
1706
2322
|
}
|
|
1707
2323
|
async boot() {
|
|
1708
2324
|
if (this.app.bound(Router)) {
|
|
1709
|
-
this.app.make(Router).aliasMiddleware("auth", Authenticate).aliasMiddleware("guest", RedirectIfAuthenticated).aliasMiddleware("can", Authorize).aliasMiddleware("verified", EnsureEmailIsVerified);
|
|
2325
|
+
this.app.make(Router).aliasMiddleware("auth", Authenticate).aliasMiddleware("auth.session", AuthenticateSession).aliasMiddleware("guest", RedirectIfAuthenticated).aliasMiddleware("can", Authorize).aliasMiddleware("verified", EnsureEmailIsVerified).aliasMiddleware("two-factor.challenge", TwoFactorChallenge);
|
|
1710
2326
|
}
|
|
1711
2327
|
if (this.app.bound(EventDispatcher)) this.app.make(EventDispatcher).listen(Registered, SendEmailVerificationNotification);
|
|
1712
2328
|
await discoverPolicies(this.app.appPath("Policies"), this.app.make(Gate));
|
|
2329
|
+
if (this.app.bound(ConsoleKernel)) {
|
|
2330
|
+
const app2 = this.app;
|
|
2331
|
+
this.app.make(ConsoleKernel).command("two-factor:install", function() {
|
|
2332
|
+
try {
|
|
2333
|
+
this.info(`Wrote ${relative(app2.basePath(), installTwoFactorMigration(app2.databasePath("migrations")))}: run \`oriel migrate\`.`);
|
|
2334
|
+
return 0;
|
|
2335
|
+
} catch (error) {
|
|
2336
|
+
this.error(error instanceof Error ? error.message : String(error));
|
|
2337
|
+
return 1;
|
|
2338
|
+
}
|
|
2339
|
+
}).purpose("Write the migration for two-factor login's columns on users");
|
|
2340
|
+
}
|
|
1713
2341
|
}
|
|
1714
2342
|
};
|
|
2343
|
+
var TwoFactor = facade(TwoFactorManager);
|
|
1715
2344
|
|
|
1716
2345
|
// ../Bus/dist/index.js
|
|
1717
2346
|
var BusError = class extends Error {
|
|
@@ -2154,7 +2783,7 @@ var BusServiceProvider = class extends ServiceProvider {
|
|
|
2154
2783
|
import { setTimeout as sleep } from "timers/promises";
|
|
2155
2784
|
import { createHash as createHash5 } from "crypto";
|
|
2156
2785
|
import { link, mkdir, readFile, rename, rm, stat, writeFile } from "fs/promises";
|
|
2157
|
-
import { dirname, join as
|
|
2786
|
+
import { dirname, join as join3 } from "path";
|
|
2158
2787
|
import { setTimeout as sleep2 } from "timers/promises";
|
|
2159
2788
|
import { createHash as createHash22, randomUUID } from "crypto";
|
|
2160
2789
|
import Redis from "ioredis";
|
|
@@ -2430,7 +3059,7 @@ var FileStore = class {
|
|
|
2430
3059
|
keyPrefix;
|
|
2431
3060
|
path(key) {
|
|
2432
3061
|
const hash2 = createHash5("sha1").update(this.keyPrefix + key).digest("hex");
|
|
2433
|
-
return
|
|
3062
|
+
return join3(this.directory, hash2.slice(0, 2), hash2.slice(2, 4), hash2);
|
|
2434
3063
|
}
|
|
2435
3064
|
tempPath(path) {
|
|
2436
3065
|
return `${path}.tmp-${process.pid}-${Math.random().toString(36).slice(2)}`;
|
|
@@ -3234,18 +3863,19 @@ var CacheServiceProvider = class extends ServiceProvider {
|
|
|
3234
3863
|
};
|
|
3235
3864
|
|
|
3236
3865
|
// ../Console/dist/index.js
|
|
3237
|
-
import {
|
|
3238
|
-
import { mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
|
|
3239
|
-
import { dirname as dirname2, join as join3, relative, sep } from "path";
|
|
3866
|
+
import { Writable } from "stream";
|
|
3240
3867
|
import { existsSync as existsSync2 } from "fs";
|
|
3868
|
+
import { mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
|
|
3869
|
+
import { dirname as dirname2, join as join4, relative as relative2, sep } from "path";
|
|
3870
|
+
import { existsSync as existsSync22 } from "fs";
|
|
3241
3871
|
import { join as join22 } from "path";
|
|
3242
3872
|
import { existsSync as existsSync3 } from "fs";
|
|
3243
3873
|
import { mkdir as mkdir22, writeFile as writeFile22 } from "fs/promises";
|
|
3244
3874
|
import { dirname as dirname22, join as join32 } from "path";
|
|
3245
|
-
import { join as
|
|
3875
|
+
import { join as join42 } from "path";
|
|
3246
3876
|
import { spawn } from "child_process";
|
|
3247
3877
|
import { start as start2 } from "repl";
|
|
3248
|
-
import { existsSync as existsSync4, readdirSync } from "fs";
|
|
3878
|
+
import { existsSync as existsSync4, readdirSync as readdirSync2 } from "fs";
|
|
3249
3879
|
import { join as join5 } from "path";
|
|
3250
3880
|
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
3251
3881
|
import { createHash as createHash6 } from "crypto";
|
|
@@ -3269,6 +3899,12 @@ var ScheduleNameRequiredError = class extends Error {
|
|
|
3269
3899
|
super(`A scheduled event name is required to prevent overlapping. Use the 'name' method before '${method}'.`);
|
|
3270
3900
|
}
|
|
3271
3901
|
};
|
|
3902
|
+
var ConsoleAbortedError = class extends Error {
|
|
3903
|
+
name = "ConsoleAbortedError";
|
|
3904
|
+
constructor() {
|
|
3905
|
+
super("Aborted.");
|
|
3906
|
+
}
|
|
3907
|
+
};
|
|
3272
3908
|
var NodeConsoleOutput = class {
|
|
3273
3909
|
write(text4) {
|
|
3274
3910
|
process.stdout.write(text4);
|
|
@@ -3307,18 +3943,32 @@ var NodeConsoleInput = class {
|
|
|
3307
3943
|
lines = [];
|
|
3308
3944
|
waiting = [];
|
|
3309
3945
|
ended = false;
|
|
3310
|
-
|
|
3946
|
+
muted = false;
|
|
3947
|
+
async question(prompt, options = {}) {
|
|
3311
3948
|
const rl = await this.open();
|
|
3949
|
+
const hide = options.hidden === true && this.isTerminal() && !this.ended;
|
|
3312
3950
|
if (this.ended) {
|
|
3313
3951
|
this.output.write(prompt);
|
|
3952
|
+
} else if (hide) {
|
|
3953
|
+
this.output.write(prompt);
|
|
3954
|
+
this.muted = true;
|
|
3955
|
+
rl.setPrompt("");
|
|
3956
|
+
rl.prompt();
|
|
3314
3957
|
} else {
|
|
3315
3958
|
rl.setPrompt(prompt);
|
|
3316
3959
|
rl.prompt();
|
|
3317
3960
|
}
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3961
|
+
try {
|
|
3962
|
+
const line = this.lines.shift();
|
|
3963
|
+
if (line !== void 0) return line;
|
|
3964
|
+
if (this.ended) throw new ConsoleAbortedError();
|
|
3965
|
+
return await new Promise((resolve5, reject) => this.waiting.push({ resolve: resolve5, reject }));
|
|
3966
|
+
} finally {
|
|
3967
|
+
if (hide) {
|
|
3968
|
+
this.muted = false;
|
|
3969
|
+
this.output.write("\n");
|
|
3970
|
+
}
|
|
3971
|
+
}
|
|
3322
3972
|
}
|
|
3323
3973
|
close() {
|
|
3324
3974
|
const rl = this.rl;
|
|
@@ -3331,7 +3981,8 @@ var NodeConsoleInput = class {
|
|
|
3331
3981
|
if (this.rl) return this.rl;
|
|
3332
3982
|
const { createInterface } = await import("readline");
|
|
3333
3983
|
if (this.rl) return this.rl;
|
|
3334
|
-
const rl = createInterface({ input: this.input, output: this.
|
|
3984
|
+
const rl = createInterface({ input: this.input, output: this.screen(), terminal: this.isTerminal(), historySize: 0 });
|
|
3985
|
+
rl.on("SIGINT", () => rl.close());
|
|
3335
3986
|
rl.on("line", (line) => {
|
|
3336
3987
|
const next = this.waiting.shift();
|
|
3337
3988
|
if (next) next.resolve(line);
|
|
@@ -3340,18 +3991,32 @@ var NodeConsoleInput = class {
|
|
|
3340
3991
|
rl.on("close", () => {
|
|
3341
3992
|
if (this.rl !== rl) return;
|
|
3342
3993
|
this.ended = true;
|
|
3343
|
-
for (const { reject } of this.waiting.splice(0)) reject(new
|
|
3994
|
+
for (const { reject } of this.waiting.splice(0)) reject(new ConsoleAbortedError());
|
|
3344
3995
|
});
|
|
3345
3996
|
this.rl = rl;
|
|
3346
3997
|
return rl;
|
|
3347
3998
|
}
|
|
3999
|
+
isTerminal() {
|
|
4000
|
+
return this.input.isTTY === true;
|
|
4001
|
+
}
|
|
4002
|
+
/** What readline writes to: the real output, unless muted, with the width it wraps long lines at. */
|
|
4003
|
+
screen() {
|
|
4004
|
+
const screen = new Writable({
|
|
4005
|
+
write: (chunk, _encoding, done) => {
|
|
4006
|
+
if (!this.muted) this.output.write(chunk);
|
|
4007
|
+
done();
|
|
4008
|
+
}
|
|
4009
|
+
});
|
|
4010
|
+
Object.defineProperty(screen, "columns", { get: () => this.output.columns });
|
|
4011
|
+
return screen;
|
|
4012
|
+
}
|
|
3348
4013
|
};
|
|
3349
4014
|
var QueuedConsoleInput = class {
|
|
3350
4015
|
queue;
|
|
3351
4016
|
constructor(answers = []) {
|
|
3352
4017
|
this.queue = [...answers];
|
|
3353
4018
|
}
|
|
3354
|
-
async question(_prompt) {
|
|
4019
|
+
async question(_prompt, _options) {
|
|
3355
4020
|
if (this.queue.length === 0) throw new Error("QueuedConsoleInput ran out of answers.");
|
|
3356
4021
|
return this.queue.shift();
|
|
3357
4022
|
}
|
|
@@ -3420,9 +4085,9 @@ var Command = class {
|
|
|
3420
4085
|
const answer = (await this.consoleInput.question(`${question}${suffix2}: `)).trim();
|
|
3421
4086
|
return answer === "" && defaultValue !== void 0 ? defaultValue : answer;
|
|
3422
4087
|
}
|
|
3423
|
-
/**
|
|
4088
|
+
/** Asks without showing what's typed, in a terminal. Unlike ask(), the answer isn't trimmed: a secret may start or end with a space. */
|
|
3424
4089
|
async secret(question) {
|
|
3425
|
-
return this.
|
|
4090
|
+
return this.consoleInput.question(`${question}: `, { hidden: true });
|
|
3426
4091
|
}
|
|
3427
4092
|
async confirm(question, defaultValue = false) {
|
|
3428
4093
|
const hint = defaultValue ? "Y/n" : "y/N";
|
|
@@ -3703,7 +4368,7 @@ var GeneratorCommand = class extends Command {
|
|
|
3703
4368
|
async prepare(_rawName) {
|
|
3704
4369
|
}
|
|
3705
4370
|
qualifyClass(rawName) {
|
|
3706
|
-
const segments = rawName.split("/").filter(Boolean).map((
|
|
4371
|
+
const segments = rawName.split("/").filter(Boolean).map((part2) => Str.studly(part2));
|
|
3707
4372
|
const last = segments.pop();
|
|
3708
4373
|
if (!last) throw new Error("A name is required.");
|
|
3709
4374
|
const suffix2 = this.suffix();
|
|
@@ -3720,7 +4385,7 @@ var GeneratorCommand = class extends Command {
|
|
|
3720
4385
|
}
|
|
3721
4386
|
targetPath(rawName) {
|
|
3722
4387
|
const { directories, className } = this.qualifyClass(rawName);
|
|
3723
|
-
return
|
|
4388
|
+
return join4(this.root(this.type()), ...directories, this.fileName(className));
|
|
3724
4389
|
}
|
|
3725
4390
|
/** The singular kind of file for messages, like Laravel's `$type`: 'Http/Controllers' -> 'Controller'. */
|
|
3726
4391
|
kind() {
|
|
@@ -3728,13 +4393,13 @@ var GeneratorCommand = class extends Command {
|
|
|
3728
4393
|
}
|
|
3729
4394
|
/** The import specifier from the generated file to `target` (an absolute path without extension): './X', '../Y/X'. */
|
|
3730
4395
|
importPath(rawName, target) {
|
|
3731
|
-
const specifier =
|
|
4396
|
+
const specifier = relative2(dirname2(this.targetPath(rawName)), target).split(sep).join("/");
|
|
3732
4397
|
return specifier.startsWith(".") ? specifier : `./${specifier}`;
|
|
3733
4398
|
}
|
|
3734
4399
|
/** A --model value as studly segments: 'Admin/blog_post' -> ['Admin', 'BlogPost']; undefined when there is none. */
|
|
3735
4400
|
modelSegments(value2) {
|
|
3736
4401
|
if (typeof value2 !== "string") return void 0;
|
|
3737
|
-
const segments = value2.split(/[/\\]/).filter(Boolean).map((
|
|
4402
|
+
const segments = value2.split(/[/\\]/).filter(Boolean).map((part2) => Str.studly(part2));
|
|
3738
4403
|
return segments.length > 0 ? segments : void 0;
|
|
3739
4404
|
}
|
|
3740
4405
|
/** The model's file under app/Models, without the extension (Laravel's qualifyModel() into App\Models). */
|
|
@@ -3748,7 +4413,7 @@ var GeneratorCommand = class extends Command {
|
|
|
3748
4413
|
return 1;
|
|
3749
4414
|
}
|
|
3750
4415
|
const target = this.targetPath(rawName);
|
|
3751
|
-
if (
|
|
4416
|
+
if (existsSync2(target) && !this.option("force")) {
|
|
3752
4417
|
this.error(`${this.kind()} already exists.`);
|
|
3753
4418
|
return 1;
|
|
3754
4419
|
}
|
|
@@ -4279,7 +4944,7 @@ var MakeControllerCommand = class extends GeneratorCommand {
|
|
|
4279
4944
|
async prepare() {
|
|
4280
4945
|
const segments = this.modelSegments(this.option("model"));
|
|
4281
4946
|
if (!segments) return;
|
|
4282
|
-
if (!
|
|
4947
|
+
if (!existsSync22(`${this.modelPath(segments)}.ts`)) await this.call("make:model", { name: segments.join("/") });
|
|
4283
4948
|
if (this.option("requests")) {
|
|
4284
4949
|
const model = segments.at(-1);
|
|
4285
4950
|
await this.call("make:request", { name: `Store${model}Request` });
|
|
@@ -4343,7 +5008,7 @@ var MakeFactoryCommand = class extends GeneratorCommand {
|
|
|
4343
5008
|
extraPlaceholders(rawName) {
|
|
4344
5009
|
const option = this.option("model");
|
|
4345
5010
|
const modelName = typeof option === "string" ? option : this.qualifyClass(rawName).className.replace(/Factory$/, "");
|
|
4346
|
-
const segments = modelName.split("/").filter(Boolean).map((
|
|
5011
|
+
const segments = modelName.split("/").filter(Boolean).map((part2) => Str.studly(part2));
|
|
4347
5012
|
return {
|
|
4348
5013
|
model: segments.at(-1) ?? modelName,
|
|
4349
5014
|
modelImport: this.importPath(rawName, inject(Application).appPath(["Models", ...segments].join("/")))
|
|
@@ -4374,7 +5039,7 @@ var MakeListenerCommand = class extends GeneratorCommand {
|
|
|
4374
5039
|
extraPlaceholders(rawName) {
|
|
4375
5040
|
const event2 = this.option("event");
|
|
4376
5041
|
if (typeof event2 !== "string") return {};
|
|
4377
|
-
const segments = event2.split("/").filter(Boolean).map((
|
|
5042
|
+
const segments = event2.split("/").filter(Boolean).map((part2) => Str.studly(part2));
|
|
4378
5043
|
return {
|
|
4379
5044
|
event: segments.at(-1) ?? event2,
|
|
4380
5045
|
eventImport: this.importPath(rawName, inject(Application).appPath(["Events", ...segments].join("/")))
|
|
@@ -4404,7 +5069,7 @@ var MakeMailCommand = class extends GeneratorCommand {
|
|
|
4404
5069
|
viewName(rawName) {
|
|
4405
5070
|
const option = this.option("view");
|
|
4406
5071
|
if (typeof option === "string" && option !== "") return option;
|
|
4407
|
-
const parts = rawName.split("/").filter(Boolean).map((
|
|
5072
|
+
const parts = rawName.split("/").filter(Boolean).map((part2) => Str.kebab(Str.studly(part2)));
|
|
4408
5073
|
return ["mail", ...parts].join(".");
|
|
4409
5074
|
}
|
|
4410
5075
|
/** Laravel's writeView(): an existing view is reported and left alone, even with --force. */
|
|
@@ -4620,7 +5285,7 @@ var MakeTestCommand = class extends GeneratorCommand {
|
|
|
4620
5285
|
return TEST_STUB;
|
|
4621
5286
|
}
|
|
4622
5287
|
root(subpath) {
|
|
4623
|
-
return inject(Application).basePath(
|
|
5288
|
+
return inject(Application).basePath(join42("tests", subpath));
|
|
4624
5289
|
}
|
|
4625
5290
|
fileName(className) {
|
|
4626
5291
|
return `${className.replace(/(?<=.)Test$/, "")}.test.ts`;
|
|
@@ -4791,11 +5456,13 @@ var ScheduleWorkCommand = class extends Command {
|
|
|
4791
5456
|
};
|
|
4792
5457
|
var defaultSpawner = (command, args) => spawn(command, args, { stdio: "inherit", shell: process.platform === "win32" });
|
|
4793
5458
|
var TestCommand = class extends Command {
|
|
4794
|
-
constructor(spawner = defaultSpawner) {
|
|
5459
|
+
constructor(spawner = defaultSpawner, onBun = () => typeof process.versions.bun === "string") {
|
|
4795
5460
|
super();
|
|
4796
5461
|
this.spawner = spawner;
|
|
5462
|
+
this.onBun = onBun;
|
|
4797
5463
|
}
|
|
4798
5464
|
spawner;
|
|
5465
|
+
onBun;
|
|
4799
5466
|
/** Paths are passed on to vitest; so is everything after `--` (`oriel test -- --coverage`). */
|
|
4800
5467
|
signature = "test {args?*} {--filter=}";
|
|
4801
5468
|
description = "Run the test suite";
|
|
@@ -4806,7 +5473,7 @@ var TestCommand = class extends Command {
|
|
|
4806
5473
|
const extra = this.argument("args");
|
|
4807
5474
|
if (Array.isArray(extra)) args.push(...extra);
|
|
4808
5475
|
return new Promise((resolve5) => {
|
|
4809
|
-
const child = this.spawner("npx", args);
|
|
5476
|
+
const child = this.onBun() ? this.spawner("bun", ["--bun", ...args]) : this.spawner("npx", args);
|
|
4810
5477
|
child.on("error", (error) => {
|
|
4811
5478
|
this.error(error.message);
|
|
4812
5479
|
resolve5(1);
|
|
@@ -4835,7 +5502,7 @@ var TinkerCommand = class extends Command {
|
|
|
4835
5502
|
};
|
|
4836
5503
|
function sourceFiles(directory) {
|
|
4837
5504
|
const files3 = [];
|
|
4838
|
-
for (const entry of
|
|
5505
|
+
for (const entry of readdirSync2(directory, { withFileTypes: true })) {
|
|
4839
5506
|
const path = join5(directory, entry.name);
|
|
4840
5507
|
if (entry.isDirectory()) files3.push(...sourceFiles(path));
|
|
4841
5508
|
else if (/\.(ts|js|mts|mjs)$/.test(entry.name) && !/\.d\.[mc]?ts$/.test(entry.name)) files3.push(path);
|
|
@@ -4850,8 +5517,8 @@ async function discoverCommands(kernel, directory) {
|
|
|
4850
5517
|
if (typeof exported !== "function") continue;
|
|
4851
5518
|
const prototype = exported.prototype;
|
|
4852
5519
|
if (typeof prototype?.handle !== "function") continue;
|
|
4853
|
-
const
|
|
4854
|
-
if (typeof
|
|
5520
|
+
const commandClass = exported;
|
|
5521
|
+
if (typeof new commandClass().signature === "string") kernel.register(commandClass);
|
|
4855
5522
|
}
|
|
4856
5523
|
}
|
|
4857
5524
|
}
|
|
@@ -4932,12 +5599,25 @@ var Kernel2 = class {
|
|
|
4932
5599
|
defaultInput;
|
|
4933
5600
|
defaultOutput;
|
|
4934
5601
|
lastOutput = "";
|
|
5602
|
+
/** The classes of the commands registered as classes: each run makes a new one. */
|
|
5603
|
+
classes = /* @__PURE__ */ new Map();
|
|
4935
5604
|
running = 0;
|
|
5605
|
+
loader;
|
|
5606
|
+
bootstrapping;
|
|
5607
|
+
/** What bootstrap() runs once: the provider hands it the loading of the app's commands and routes/console.ts. */
|
|
5608
|
+
bootstrapWith(loader) {
|
|
5609
|
+
this.loader = loader;
|
|
5610
|
+
}
|
|
5611
|
+
bootstrap() {
|
|
5612
|
+
return this.bootstrapping ??= this.loader?.() ?? Promise.resolve();
|
|
5613
|
+
}
|
|
4936
5614
|
register(...commands) {
|
|
4937
5615
|
for (const entry of commands) {
|
|
4938
5616
|
const instance = typeof entry === "function" ? new entry() : entry;
|
|
4939
5617
|
const name = parseSignature(instance.signature).name;
|
|
4940
5618
|
this.commands.set(name, instance);
|
|
5619
|
+
if (typeof entry === "function") this.classes.set(name, entry);
|
|
5620
|
+
else this.classes.delete(name);
|
|
4941
5621
|
}
|
|
4942
5622
|
}
|
|
4943
5623
|
command(signature, handler3) {
|
|
@@ -4951,9 +5631,9 @@ var Kernel2 = class {
|
|
|
4951
5631
|
output() {
|
|
4952
5632
|
return this.lastOutput;
|
|
4953
5633
|
}
|
|
4954
|
-
async call(command, parameters = {}) {
|
|
5634
|
+
async call(command, parameters = {}, options = {}) {
|
|
4955
5635
|
const output = new BufferedConsoleOutput();
|
|
4956
|
-
const code = await this.callWithIo(command, parameters, { input: new QueuedConsoleInput(), output });
|
|
5636
|
+
const code = await this.callWithIo(command, parameters, { input: new QueuedConsoleInput(options.answers), output });
|
|
4957
5637
|
this.lastOutput = output.combined;
|
|
4958
5638
|
return code;
|
|
4959
5639
|
}
|
|
@@ -4979,6 +5659,11 @@ var Kernel2 = class {
|
|
|
4979
5659
|
}
|
|
4980
5660
|
}
|
|
4981
5661
|
reportTopLevelError(error, output) {
|
|
5662
|
+
if (error instanceof ConsoleAbortedError) {
|
|
5663
|
+
output.writeError(`${error.message}
|
|
5664
|
+
`);
|
|
5665
|
+
return 130;
|
|
5666
|
+
}
|
|
4982
5667
|
if (error instanceof CommandNotFoundError) {
|
|
4983
5668
|
output.writeError(`${error.message}
|
|
4984
5669
|
`);
|
|
@@ -5017,11 +5702,12 @@ var Kernel2 = class {
|
|
|
5017
5702
|
}
|
|
5018
5703
|
async execute(instance, signature, input, io) {
|
|
5019
5704
|
validateRequiredArguments(signature, input);
|
|
5020
|
-
const run = Object.create(instance);
|
|
5021
|
-
run.bind?.(resolveArguments(signature, input), resolveOptions(signature, input), io);
|
|
5022
5705
|
const scope = this.app.createScope();
|
|
5023
5706
|
scope.instance(ConsoleKernel, this);
|
|
5024
5707
|
return scope.run(async () => {
|
|
5708
|
+
const CommandClass = this.classes.get(signature.name);
|
|
5709
|
+
const run = CommandClass === void 0 ? Object.create(instance) : new CommandClass();
|
|
5710
|
+
run.bind?.(resolveArguments(signature, input), resolveOptions(signature, input), io);
|
|
5025
5711
|
try {
|
|
5026
5712
|
const result = await run.handle();
|
|
5027
5713
|
return typeof result === "number" ? result : 0;
|
|
@@ -5362,6 +6048,27 @@ var ScheduledEventImpl = class {
|
|
|
5362
6048
|
if (this.betweenWindow && !this.isWithinWindow(this.betweenWindow, now5)) return false;
|
|
5363
6049
|
return !this.unlessWindow || !this.isWithinWindow(this.unlessWindow, now5);
|
|
5364
6050
|
}
|
|
6051
|
+
/**
|
|
6052
|
+
* The latest minute after `from` and up to `to` at which this event was due, its between()/unlessBetween() windows
|
|
6053
|
+
* judged at that minute; undefined when there is none. Walks back from `to` (at most 10,000 due minutes).
|
|
6054
|
+
*/
|
|
6055
|
+
dueAt(from, to) {
|
|
6056
|
+
const end = Math.floor(to.getTime() / 6e4) * 6e4;
|
|
6057
|
+
const parsed = CronExpressionParser.parse(this.cronExpression, { tz: this.zone(), currentDate: new Date(end + 6e4) });
|
|
6058
|
+
for (let step = 0; step < 1e4; step++) {
|
|
6059
|
+
let minute;
|
|
6060
|
+
try {
|
|
6061
|
+
minute = parsed.prev().toDate();
|
|
6062
|
+
} catch {
|
|
6063
|
+
return void 0;
|
|
6064
|
+
}
|
|
6065
|
+
if (minute.getTime() <= from.getTime()) return void 0;
|
|
6066
|
+
if (this.betweenWindow && !this.isWithinWindow(this.betweenWindow, minute)) continue;
|
|
6067
|
+
if (this.unlessWindow && this.isWithinWindow(this.unlessWindow, minute)) continue;
|
|
6068
|
+
return minute;
|
|
6069
|
+
}
|
|
6070
|
+
return void 0;
|
|
6071
|
+
}
|
|
5365
6072
|
zone() {
|
|
5366
6073
|
if (this.tz !== void 0) return this.tz;
|
|
5367
6074
|
const container = currentContainer();
|
|
@@ -5482,6 +6189,9 @@ var ScheduleImpl = class {
|
|
|
5482
6189
|
dueEvents(now5) {
|
|
5483
6190
|
return this.scheduledEvents.filter((event2) => event2.isDue(now5));
|
|
5484
6191
|
}
|
|
6192
|
+
dueBetween(from, to) {
|
|
6193
|
+
return this.scheduledEvents.filter((event2) => event2.dueAt(from, to) !== void 0);
|
|
6194
|
+
}
|
|
5485
6195
|
push(event2) {
|
|
5486
6196
|
this.scheduledEvents.push(event2);
|
|
5487
6197
|
return event2;
|
|
@@ -5490,7 +6200,14 @@ var ScheduleImpl = class {
|
|
|
5490
6200
|
var ConsoleServiceProvider = class extends ServiceProvider {
|
|
5491
6201
|
register() {
|
|
5492
6202
|
this.mergeConfigFrom({ stubs: {} }, "console");
|
|
5493
|
-
this.app.singleton(ConsoleKernel, () =>
|
|
6203
|
+
this.app.singleton(ConsoleKernel, () => {
|
|
6204
|
+
const kernel = new Kernel2(this.app);
|
|
6205
|
+
kernel.bootstrapWith(async () => {
|
|
6206
|
+
await discoverCommands(kernel, this.app.appPath("Console/Commands"));
|
|
6207
|
+
await loadConsoleRoutes(this.app, kernel);
|
|
6208
|
+
});
|
|
6209
|
+
return kernel;
|
|
6210
|
+
});
|
|
5494
6211
|
this.app.singleton(Schedule, () => new ScheduleImpl());
|
|
5495
6212
|
}
|
|
5496
6213
|
boot() {
|
|
@@ -5527,9 +6244,7 @@ var ConsoleServiceProvider = class extends ServiceProvider {
|
|
|
5527
6244
|
);
|
|
5528
6245
|
this.app.booted(async (app2) => {
|
|
5529
6246
|
if (!app2.runningInConsole()) return;
|
|
5530
|
-
|
|
5531
|
-
await discoverCommands(kernel, app2.appPath("Console/Commands"));
|
|
5532
|
-
await loadConsoleRoutes(app2, kernel);
|
|
6247
|
+
await app2.make(ConsoleKernel).bootstrap();
|
|
5533
6248
|
});
|
|
5534
6249
|
}
|
|
5535
6250
|
};
|
|
@@ -5555,7 +6270,7 @@ async function runConsoleAndExit(app2, argv = process.argv.slice(2), exit = (cod
|
|
|
5555
6270
|
}
|
|
5556
6271
|
|
|
5557
6272
|
// ../Cookie/dist/index.js
|
|
5558
|
-
import { createHmac as
|
|
6273
|
+
import { createHmac as createHmac5, timingSafeEqual as timingSafeEqual4 } from "crypto";
|
|
5559
6274
|
var SAME_SITE = { lax: "Lax", strict: "Strict", none: "None" };
|
|
5560
6275
|
function serializeCookie(cookie2, now5 = Date.now()) {
|
|
5561
6276
|
const parts = [];
|
|
@@ -5593,12 +6308,12 @@ function parseSetCookie(header) {
|
|
|
5593
6308
|
}
|
|
5594
6309
|
function parseCookieHeader(header) {
|
|
5595
6310
|
const cookies = {};
|
|
5596
|
-
for (const
|
|
5597
|
-
const equals4 =
|
|
6311
|
+
for (const part2 of (header ?? "").split(";")) {
|
|
6312
|
+
const equals4 = part2.indexOf("=");
|
|
5598
6313
|
if (equals4 === -1) continue;
|
|
5599
|
-
const name =
|
|
6314
|
+
const name = part2.slice(0, equals4).trim();
|
|
5600
6315
|
if (name === "" || Object.hasOwn(cookies, name) || name === "__proto__") continue;
|
|
5601
|
-
cookies[name] = decode(
|
|
6316
|
+
cookies[name] = decode(part2.slice(equals4 + 1).trim());
|
|
5602
6317
|
}
|
|
5603
6318
|
return cookies;
|
|
5604
6319
|
}
|
|
@@ -5609,7 +6324,7 @@ function withHeaders(response2, change) {
|
|
|
5609
6324
|
}
|
|
5610
6325
|
var CookieValuePrefix = {
|
|
5611
6326
|
create(name, key) {
|
|
5612
|
-
return `${
|
|
6327
|
+
return `${createHmac5("sha1", key).update(`${name}v2`).digest("hex")}|`;
|
|
5613
6328
|
},
|
|
5614
6329
|
remove(value2) {
|
|
5615
6330
|
return value2.slice(41);
|
|
@@ -5619,7 +6334,7 @@ var CookieValuePrefix = {
|
|
|
5619
6334
|
const actual = Buffer.from(value2.slice(0, 41));
|
|
5620
6335
|
for (const key of keys) {
|
|
5621
6336
|
const expected = Buffer.from(CookieValuePrefix.create(name, key));
|
|
5622
|
-
if (actual.length === expected.length &&
|
|
6337
|
+
if (actual.length === expected.length && timingSafeEqual4(actual, expected)) return CookieValuePrefix.remove(value2);
|
|
5623
6338
|
}
|
|
5624
6339
|
return void 0;
|
|
5625
6340
|
}
|
|
@@ -5688,11 +6403,11 @@ var AddQueuedCookiesToResponse = class {
|
|
|
5688
6403
|
};
|
|
5689
6404
|
var neverEncrypt = /* @__PURE__ */ new Set();
|
|
5690
6405
|
function isDeletion(attributes, now5 = Date.now()) {
|
|
5691
|
-
for (const
|
|
5692
|
-
const equals4 =
|
|
6406
|
+
for (const part2 of attributes.split(";")) {
|
|
6407
|
+
const equals4 = part2.indexOf("=");
|
|
5693
6408
|
if (equals4 === -1) continue;
|
|
5694
|
-
const key =
|
|
5695
|
-
const value2 =
|
|
6409
|
+
const key = part2.slice(0, equals4).trim().toLowerCase();
|
|
6410
|
+
const value2 = part2.slice(equals4 + 1).trim();
|
|
5696
6411
|
if (key === "max-age" && Number(value2) <= 0) return true;
|
|
5697
6412
|
if (key === "expires" && Date.parse(value2) <= now5) return true;
|
|
5698
6413
|
}
|
|
@@ -5709,7 +6424,11 @@ var EncryptCookies = class {
|
|
|
5709
6424
|
}
|
|
5710
6425
|
/** Subclasses list cookie names that are not encrypted. */
|
|
5711
6426
|
except = [];
|
|
5712
|
-
encrypter
|
|
6427
|
+
#encrypter;
|
|
6428
|
+
/** Resolved when there's a cookie to read or write, so a page that uses none works without APP_KEY. */
|
|
6429
|
+
get encrypter() {
|
|
6430
|
+
return this.#encrypter ??= inject(Encrypter);
|
|
6431
|
+
}
|
|
5713
6432
|
isDisabled(name) {
|
|
5714
6433
|
return this.except.includes(name) || neverEncrypt.has(name);
|
|
5715
6434
|
}
|
|
@@ -5718,7 +6437,6 @@ var EncryptCookies = class {
|
|
|
5718
6437
|
return this.encrypt(await next(request2));
|
|
5719
6438
|
}
|
|
5720
6439
|
decrypt(request2) {
|
|
5721
|
-
const keys = this.encrypter.getAllKeys?.() ?? [this.encrypter.getKey()];
|
|
5722
6440
|
const decrypted = {};
|
|
5723
6441
|
for (const [name, value2] of Object.entries(parseCookieHeader(request2.header("cookie")))) {
|
|
5724
6442
|
if (this.isDisabled(name)) {
|
|
@@ -5726,6 +6444,7 @@ var EncryptCookies = class {
|
|
|
5726
6444
|
continue;
|
|
5727
6445
|
}
|
|
5728
6446
|
try {
|
|
6447
|
+
const keys = this.encrypter.getAllKeys?.() ?? [this.encrypter.getKey()];
|
|
5729
6448
|
const plain2 = CookieValuePrefix.validate(name, this.encrypter.decrypt(value2, false), keys);
|
|
5730
6449
|
if (plain2 !== void 0) decrypted[name] = plain2;
|
|
5731
6450
|
} catch {
|
|
@@ -5791,21 +6510,21 @@ import { sql as sql4 } from "kysely";
|
|
|
5791
6510
|
import { sql as sql5 } from "kysely";
|
|
5792
6511
|
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
5793
6512
|
import { isDeepStrictEqual } from "util";
|
|
5794
|
-
import { existsSync as existsSync5, readdirSync as
|
|
5795
|
-
import { join as
|
|
6513
|
+
import { existsSync as existsSync5, readdirSync as readdirSync3 } from "fs";
|
|
6514
|
+
import { join as join43 } from "path";
|
|
5796
6515
|
import { pathToFileURL as pathToFileURL3 } from "url";
|
|
5797
6516
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
5798
|
-
import { existsSync as
|
|
6517
|
+
import { existsSync as existsSync23, mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
5799
6518
|
import { join as join52 } from "path";
|
|
5800
6519
|
import { existsSync as existsSync32, readdirSync as readdirSync22 } from "fs";
|
|
5801
6520
|
import { basename, extname, join as join6 } from "path";
|
|
5802
6521
|
import { pathToFileURL as pathToFileURL22 } from "url";
|
|
5803
6522
|
import { existsSync as existsSync42 } from "fs";
|
|
5804
|
-
import { isAbsolute, join as join7, relative as
|
|
6523
|
+
import { isAbsolute, join as join7, relative as relative22 } from "path";
|
|
5805
6524
|
import { pathToFileURL as pathToFileURL32 } from "url";
|
|
5806
6525
|
import { mkdir as mkdir3, writeFile as writeFile3 } from "fs/promises";
|
|
5807
6526
|
import { dirname as dirname3, relative as relative3, sep as sep2 } from "path";
|
|
5808
|
-
import { existsSync as existsSync52, readdirSync as
|
|
6527
|
+
import { existsSync as existsSync52, readdirSync as readdirSync32, statSync } from "fs";
|
|
5809
6528
|
import { join as join8 } from "path";
|
|
5810
6529
|
import { pathToFileURL as pathToFileURL4 } from "url";
|
|
5811
6530
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
@@ -5914,9 +6633,11 @@ async function openSqlite(filename) {
|
|
|
5914
6633
|
/* @vite-ignore */
|
|
5915
6634
|
specifier
|
|
5916
6635
|
);
|
|
5917
|
-
|
|
6636
|
+
const database = new Database2(filename);
|
|
6637
|
+
database.prepare("PRAGMA busy_timeout = 5000").run();
|
|
6638
|
+
return new BunSqliteDatabase(database);
|
|
5918
6639
|
}
|
|
5919
|
-
const { default: Database } = await import("better-sqlite3");
|
|
6640
|
+
const { default: Database } = await importOptional("better-sqlite3", "The sqlite connection", () => import("better-sqlite3"));
|
|
5920
6641
|
return new Database(filename);
|
|
5921
6642
|
}
|
|
5922
6643
|
var PG_INT8 = 20;
|
|
@@ -5976,7 +6697,7 @@ function createDialect(config2) {
|
|
|
5976
6697
|
case "pgsql":
|
|
5977
6698
|
return new PostgresDialect({
|
|
5978
6699
|
pool: async () => {
|
|
5979
|
-
const { default: pg } = await import("pg");
|
|
6700
|
+
const { default: pg } = await importOptional("pg", "The pgsql connection", () => import("pg"));
|
|
5980
6701
|
return new pg.Pool({
|
|
5981
6702
|
connectionString: config2.url,
|
|
5982
6703
|
host: config2.host,
|
|
@@ -6004,7 +6725,7 @@ function createDialect(config2) {
|
|
|
6004
6725
|
case "mysql":
|
|
6005
6726
|
return new MysqlDialect({
|
|
6006
6727
|
pool: async () => {
|
|
6007
|
-
const { createPool } = await import("mysql2");
|
|
6728
|
+
const { createPool } = await importOptional("mysql2", "The mysql connection", () => import("mysql2"));
|
|
6008
6729
|
return createPool(mysqlPoolOptions(config2));
|
|
6009
6730
|
}
|
|
6010
6731
|
});
|
|
@@ -6217,9 +6938,9 @@ var Cursor = class _Cursor {
|
|
|
6217
6938
|
static fromEncoded(encoded) {
|
|
6218
6939
|
if (typeof encoded !== "string" || encoded === "") return void 0;
|
|
6219
6940
|
try {
|
|
6220
|
-
const
|
|
6221
|
-
if (typeof
|
|
6222
|
-
const { _pointsToNextItems: pointsToNext, ...parameters } =
|
|
6941
|
+
const json3 = JSON.parse(Buffer.from(encoded.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8"));
|
|
6942
|
+
if (typeof json3 !== "object" || json3 === null || Array.isArray(json3)) return void 0;
|
|
6943
|
+
const { _pointsToNextItems: pointsToNext, ...parameters } = json3;
|
|
6223
6944
|
if (typeof pointsToNext !== "boolean") return void 0;
|
|
6224
6945
|
return new _Cursor(parameters, pointsToNext);
|
|
6225
6946
|
} catch {
|
|
@@ -6436,9 +7157,9 @@ var Paginator = class extends AbstractPaginator {
|
|
|
6436
7157
|
};
|
|
6437
7158
|
}
|
|
6438
7159
|
};
|
|
6439
|
-
var
|
|
7160
|
+
var pad2 = (n, width = 2) => String(n).padStart(width, "0");
|
|
6440
7161
|
function formatDateTime(date) {
|
|
6441
|
-
return `${
|
|
7162
|
+
return `${pad2(date.getUTCFullYear(), 4)}-${pad2(date.getUTCMonth() + 1)}-${pad2(date.getUTCDate())} ${pad2(date.getUTCHours())}:${pad2(date.getUTCMinutes())}:${pad2(date.getUTCSeconds())}`;
|
|
6442
7163
|
}
|
|
6443
7164
|
function formatDate(date) {
|
|
6444
7165
|
return formatDateTime(date).slice(0, 10);
|
|
@@ -6470,7 +7191,7 @@ var OPERATORS = /* @__PURE__ */ new Set(["=", "<", ">", "<=", ">=", "<>", "!=",
|
|
|
6470
7191
|
var EMPTY = sql2.raw("");
|
|
6471
7192
|
var isSqlFragment = (value2) => typeof value2 === "object" && value2 !== null && typeof value2.toOperationNode === "function";
|
|
6472
7193
|
var join9 = (parts, separator = ", ") => sql2.join(parts, sql2.raw(separator));
|
|
6473
|
-
var clauses = (parts) => join9(parts.filter((
|
|
7194
|
+
var clauses = (parts) => join9(parts.filter((part2) => part2 !== void 0), " ");
|
|
6474
7195
|
function likeToGlob(pattern) {
|
|
6475
7196
|
return pattern.replaceAll("*", "[*]").replaceAll("?", "[?]").replaceAll("%", "*").replaceAll("_", "?");
|
|
6476
7197
|
}
|
|
@@ -6741,17 +7462,17 @@ function keyOf(item, alias) {
|
|
|
6741
7462
|
}
|
|
6742
7463
|
return value2;
|
|
6743
7464
|
}
|
|
6744
|
-
var
|
|
6745
|
-
function dateWhereValue(
|
|
7465
|
+
var pad22 = (value2, width = 2) => String(value2).padStart(width, "0");
|
|
7466
|
+
function dateWhereValue(part2, value2) {
|
|
6746
7467
|
if (value2 instanceof Expression) return value2;
|
|
6747
7468
|
if (value2 instanceof Date) {
|
|
6748
|
-
if (
|
|
6749
|
-
if (
|
|
6750
|
-
if (
|
|
6751
|
-
if (
|
|
7469
|
+
if (part2 === "date") return `${pad22(value2.getUTCFullYear(), 4)}-${pad22(value2.getUTCMonth() + 1)}-${pad22(value2.getUTCDate())}`;
|
|
7470
|
+
if (part2 === "time") return `${pad22(value2.getUTCHours())}:${pad22(value2.getUTCMinutes())}:${pad22(value2.getUTCSeconds())}`;
|
|
7471
|
+
if (part2 === "day") return pad22(value2.getUTCDate());
|
|
7472
|
+
if (part2 === "month") return pad22(value2.getUTCMonth() + 1);
|
|
6752
7473
|
return String(value2.getUTCFullYear());
|
|
6753
7474
|
}
|
|
6754
|
-
if (
|
|
7475
|
+
if (part2 === "day" || part2 === "month") return pad22(Math.trunc(Number(value2)) || 0);
|
|
6755
7476
|
return typeof value2 === "number" ? String(value2) : value2;
|
|
6756
7477
|
}
|
|
6757
7478
|
var isRow = (value2) => typeof value2 === "object" && value2 !== null && !(value2 instanceof Expression) && !(value2 instanceof Builder) && !Array.isArray(value2);
|
|
@@ -7361,10 +8082,10 @@ var Builder = class _Builder {
|
|
|
7361
8082
|
return this;
|
|
7362
8083
|
}
|
|
7363
8084
|
/** Laravel's addDateBasedWhere(): one value means '='; the operator is checked against the whitelist. */
|
|
7364
|
-
addDateBasedWhere(
|
|
8085
|
+
addDateBasedWhere(part2, column, args, boolean) {
|
|
7365
8086
|
const [operator, value2] = args.length === 1 ? ["=", args[0]] : [args[0].toLowerCase(), args[1]];
|
|
7366
8087
|
this.grammar.operator(operator);
|
|
7367
|
-
this.wheres.push({ type: "date", part, column, operator, value: dateWhereValue(
|
|
8088
|
+
this.wheres.push({ type: "date", part: part2, column, operator, value: dateWhereValue(part2, value2), boolean });
|
|
7368
8089
|
return this;
|
|
7369
8090
|
}
|
|
7370
8091
|
pushNull(column, not, boolean) {
|
|
@@ -7931,7 +8652,7 @@ var SchemaGrammar = class {
|
|
|
7931
8652
|
return sql4`${sql4.raw(type)} check (${sql4.id(column.name)} in (${allowed}))`;
|
|
7932
8653
|
}
|
|
7933
8654
|
};
|
|
7934
|
-
var present = (parts) => parts.filter((
|
|
8655
|
+
var present = (parts) => parts.filter((part2) => part2 !== void 0);
|
|
7935
8656
|
function mergeRebuilds(steps) {
|
|
7936
8657
|
const merged = [];
|
|
7937
8658
|
for (const step of steps) {
|
|
@@ -10710,9 +11431,9 @@ var Factory2 = class _Factory {
|
|
|
10710
11431
|
};
|
|
10711
11432
|
async function discoverFactories(path) {
|
|
10712
11433
|
if (!existsSync5(path)) return;
|
|
10713
|
-
for (const file of
|
|
11434
|
+
for (const file of readdirSync3(path).sort()) {
|
|
10714
11435
|
if (!/\.(ts|js|mts|mjs)$/.test(file) || /\.d\.[mc]?ts$/.test(file)) continue;
|
|
10715
|
-
const module = await import(pathToFileURL3(
|
|
11436
|
+
const module = await import(pathToFileURL3(join43(path, file)).href);
|
|
10716
11437
|
for (const exported of Object.values(module)) {
|
|
10717
11438
|
if (typeof exported === "function" && exported.prototype instanceof Factory2) {
|
|
10718
11439
|
Factory2.register(exported);
|
|
@@ -12482,9 +13203,9 @@ var MigrationCreator = class {
|
|
|
12482
13203
|
}
|
|
12483
13204
|
const stub = table === void 0 ? MIGRATION_STUB : create ? MIGRATION_CREATE_STUB : MIGRATION_UPDATE_STUB;
|
|
12484
13205
|
const file = join52(path, `${migrationDatePrefix(options.date)}_${snake}.ts`);
|
|
12485
|
-
if (
|
|
12486
|
-
|
|
12487
|
-
|
|
13206
|
+
if (existsSync23(file)) throw new LogicError(`Migration [${file}] already exists.`);
|
|
13207
|
+
mkdirSync2(path, { recursive: true });
|
|
13208
|
+
writeFileSync2(
|
|
12488
13209
|
file,
|
|
12489
13210
|
stub.replaceAll("{{ importSource }}", options.importSource ?? "@orieljs/framework").replaceAll("{{ table }}", table ?? "")
|
|
12490
13211
|
);
|
|
@@ -12879,7 +13600,7 @@ async function generateModelTypes(context) {
|
|
|
12879
13600
|
if (!context.models) return void 0;
|
|
12880
13601
|
const outputFile = context.app.basePath(join7("types", "models.d.ts"));
|
|
12881
13602
|
await new TypeGenerator({ outputFile, importSource: context.typesImportSource }).write((await context.models()).all());
|
|
12882
|
-
return
|
|
13603
|
+
return relative22(context.app.basePath(), outputFile);
|
|
12883
13604
|
}
|
|
12884
13605
|
async function writeModelTypes(context, command) {
|
|
12885
13606
|
if (context.app.isProduction() || !existsSync42(context.app.basePath("types"))) return;
|
|
@@ -12970,7 +13691,7 @@ function registerMigrationCommands(kernel, context) {
|
|
|
12970
13691
|
table: text(command.option("table")),
|
|
12971
13692
|
importSource: context.stubsImportSource
|
|
12972
13693
|
});
|
|
12973
|
-
command.info(`Migration [${
|
|
13694
|
+
command.info(`Migration [${relative22(context.app.basePath(), file)}] created successfully.`);
|
|
12974
13695
|
return 0;
|
|
12975
13696
|
});
|
|
12976
13697
|
}
|
|
@@ -13025,7 +13746,7 @@ var ModelRegistry = class {
|
|
|
13025
13746
|
function listFiles(directory) {
|
|
13026
13747
|
if (!existsSync52(directory)) return [];
|
|
13027
13748
|
const files3 = [];
|
|
13028
|
-
for (const entry of
|
|
13749
|
+
for (const entry of readdirSync32(directory).sort()) {
|
|
13029
13750
|
const path = join8(directory, entry);
|
|
13030
13751
|
if (statSync(path).isDirectory()) files3.push(...listFiles(path));
|
|
13031
13752
|
else if (MODEL_FILE.test(entry)) files3.push(path);
|
|
@@ -13505,7 +14226,7 @@ var DatabaseServiceProvider = class extends ServiceProvider {
|
|
|
13505
14226
|
};
|
|
13506
14227
|
|
|
13507
14228
|
// ../Encryption/dist/index.js
|
|
13508
|
-
import { createCipheriv, createDecipheriv, createHmac as
|
|
14229
|
+
import { createCipheriv, createDecipheriv, createHmac as createHmac6, randomBytes as randomBytes3, timingSafeEqual as timingSafeEqual5 } from "crypto";
|
|
13509
14230
|
import { readFile as readFile2, writeFile as writeFile4 } from "fs/promises";
|
|
13510
14231
|
var EncryptionFailure = class extends Error {
|
|
13511
14232
|
kind = "Server";
|
|
@@ -13541,7 +14262,7 @@ var cipherSpec = (cipher) => Object.hasOwn(CIPHERS, cipher.toLowerCase()) ? CIPH
|
|
|
13541
14262
|
function equals2(known, user) {
|
|
13542
14263
|
const a = Buffer.from(known);
|
|
13543
14264
|
const b = Buffer.from(user);
|
|
13544
|
-
return a.length === b.length &&
|
|
14265
|
+
return a.length === b.length && timingSafeEqual5(a, b);
|
|
13545
14266
|
}
|
|
13546
14267
|
function parseKey(key) {
|
|
13547
14268
|
if (typeof key !== "string" || key === "") throw new MissingAppKeyError();
|
|
@@ -13565,13 +14286,13 @@ var Encrypter2 = class _Encrypter {
|
|
|
13565
14286
|
static generateKey(cipher = "aes-256-gcm") {
|
|
13566
14287
|
const spec = cipherSpec(cipher);
|
|
13567
14288
|
if (spec === void 0) throw new UnsupportedCipherError();
|
|
13568
|
-
return new Uint8Array(
|
|
14289
|
+
return new Uint8Array(randomBytes3(spec.size));
|
|
13569
14290
|
}
|
|
13570
14291
|
encrypt(value2, serialize3 = true) {
|
|
13571
14292
|
const plain2 = serialize3 ? JSON.stringify(value2) : value2;
|
|
13572
14293
|
if (typeof plain2 !== "string") throw new EncryptError("Could not encrypt the data.");
|
|
13573
14294
|
const spec = CIPHERS[this.#cipher];
|
|
13574
|
-
const ivBytes =
|
|
14295
|
+
const ivBytes = randomBytes3(spec.ivLength);
|
|
13575
14296
|
let encrypted;
|
|
13576
14297
|
let tagBytes;
|
|
13577
14298
|
try {
|
|
@@ -13637,7 +14358,7 @@ var Encrypter2 = class _Encrypter {
|
|
|
13637
14358
|
return this;
|
|
13638
14359
|
}
|
|
13639
14360
|
#hash(iv, value2, key) {
|
|
13640
|
-
return
|
|
14361
|
+
return createHmac6("sha256", key).update(iv + value2).digest("hex");
|
|
13641
14362
|
}
|
|
13642
14363
|
#decryptWith(key, iv, value2, tag) {
|
|
13643
14364
|
try {
|
|
@@ -14067,7 +14788,6 @@ var EventServiceProvider = class extends ServiceProvider {
|
|
|
14067
14788
|
};
|
|
14068
14789
|
|
|
14069
14790
|
// ../Filesystem/dist/index.js
|
|
14070
|
-
import { S3Client } from "@aws-sdk/client-s3";
|
|
14071
14791
|
import { createReadStream, createWriteStream } from "fs";
|
|
14072
14792
|
import { chmod, copyFile, mkdir as mkdir4, readFile as readFile3, readdir as readdir2, rename as rename2, rm as rm2, stat as stat2, writeFile as writeFile5 } from "fs/promises";
|
|
14073
14793
|
import { dirname as dirname4, extname as extname2, resolve as resolve2 } from "path";
|
|
@@ -14075,15 +14795,7 @@ import { Readable } from "stream";
|
|
|
14075
14795
|
import { pipeline } from "stream/promises";
|
|
14076
14796
|
import { resolve, sep as sep3 } from "path";
|
|
14077
14797
|
import { posix } from "path";
|
|
14078
|
-
import {
|
|
14079
|
-
CopyObjectCommand,
|
|
14080
|
-
DeleteObjectCommand,
|
|
14081
|
-
GetObjectCommand,
|
|
14082
|
-
HeadObjectCommand,
|
|
14083
|
-
ListObjectsV2Command,
|
|
14084
|
-
PutObjectCommand
|
|
14085
|
-
} from "@aws-sdk/client-s3";
|
|
14086
|
-
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
14798
|
+
import { posix as posix2 } from "path";
|
|
14087
14799
|
import { lstat, mkdir as mkdir23, symlink, unlink } from "fs/promises";
|
|
14088
14800
|
import { dirname as dirname23, relative as relative4 } from "path";
|
|
14089
14801
|
var PathTraversalError = class extends Error {
|
|
@@ -14209,6 +14921,9 @@ function joinDiskPath(directory, name) {
|
|
|
14209
14921
|
function uniqueFileName(extension) {
|
|
14210
14922
|
return /^[a-z0-9]+$/i.test(extension) ? `${Str.random(40)}.${extension}` : Str.random(40);
|
|
14211
14923
|
}
|
|
14924
|
+
function encodeKey(key) {
|
|
14925
|
+
return key.split("/").map((segment) => encodeURIComponent(segment).replace(/[!'()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`)).join("/");
|
|
14926
|
+
}
|
|
14212
14927
|
var FILE_MODE = { public: 420, private: 384 };
|
|
14213
14928
|
var DIR_MODE = { public: 493, private: 448 };
|
|
14214
14929
|
var LocalFilesystem = class {
|
|
@@ -14369,9 +15084,7 @@ var LocalFilesystem = class {
|
|
|
14369
15084
|
await chmod(full, mode);
|
|
14370
15085
|
}
|
|
14371
15086
|
};
|
|
14372
|
-
|
|
14373
|
-
return key.split("/").map((segment) => encodeURIComponent(segment).replace(/[!'()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`)).join("/");
|
|
14374
|
-
}
|
|
15087
|
+
var loadSdk = () => importOptional("@aws-sdk/client-s3", "The s3 disk", () => import("@aws-sdk/client-s3"));
|
|
14375
15088
|
var isNotFound = (error) => {
|
|
14376
15089
|
const name = error.name;
|
|
14377
15090
|
const status = error.$metadata?.httpStatusCode;
|
|
@@ -14399,14 +15112,24 @@ async function collectStream(stream) {
|
|
|
14399
15112
|
return result;
|
|
14400
15113
|
}
|
|
14401
15114
|
var S3Filesystem = class {
|
|
15115
|
+
/** `client` is the client, or what builds it on the first operation. */
|
|
14402
15116
|
constructor(client, config2) {
|
|
14403
15117
|
this.client = client;
|
|
14404
15118
|
this.config = config2;
|
|
14405
15119
|
}
|
|
14406
15120
|
client;
|
|
14407
15121
|
config;
|
|
15122
|
+
#client;
|
|
15123
|
+
resolveClient() {
|
|
15124
|
+
const { client } = this;
|
|
15125
|
+
return this.#client ??= typeof client === "function" ? client() : Promise.resolve(client);
|
|
15126
|
+
}
|
|
15127
|
+
async send(command, input) {
|
|
15128
|
+
const sdk = await loadSdk();
|
|
15129
|
+
return (await this.resolveClient()).send(new sdk[command](input));
|
|
15130
|
+
}
|
|
14408
15131
|
async head(key) {
|
|
14409
|
-
return await this.
|
|
15132
|
+
return await this.send("HeadObjectCommand", { Bucket: this.config.bucket, Key: key });
|
|
14410
15133
|
}
|
|
14411
15134
|
async exists(path) {
|
|
14412
15135
|
try {
|
|
@@ -14422,7 +15145,7 @@ var S3Filesystem = class {
|
|
|
14422
15145
|
}
|
|
14423
15146
|
async getObject(path) {
|
|
14424
15147
|
try {
|
|
14425
|
-
return await this.
|
|
15148
|
+
return await this.send("GetObjectCommand", { Bucket: this.config.bucket, Key: path });
|
|
14426
15149
|
} catch (error) {
|
|
14427
15150
|
if (isNotFound(error)) throw new FileNotFoundError(path);
|
|
14428
15151
|
throw error;
|
|
@@ -14461,27 +15184,23 @@ var S3Filesystem = class {
|
|
|
14461
15184
|
return path;
|
|
14462
15185
|
}
|
|
14463
15186
|
async putObject(path, body, contentType, options) {
|
|
14464
|
-
await this.
|
|
14465
|
-
|
|
14466
|
-
|
|
14467
|
-
|
|
14468
|
-
|
|
14469
|
-
|
|
14470
|
-
|
|
14471
|
-
})
|
|
14472
|
-
);
|
|
15187
|
+
await this.send("PutObjectCommand", {
|
|
15188
|
+
Bucket: this.config.bucket,
|
|
15189
|
+
Key: path,
|
|
15190
|
+
Body: body,
|
|
15191
|
+
ContentType: contentType,
|
|
15192
|
+
ACL: options?.visibility === "public" ? "public-read" : void 0
|
|
15193
|
+
});
|
|
14473
15194
|
}
|
|
14474
15195
|
async delete(paths) {
|
|
14475
15196
|
for (const path of Array.isArray(paths) ? paths : [paths]) {
|
|
14476
|
-
await this.
|
|
15197
|
+
await this.send("DeleteObjectCommand", { Bucket: this.config.bucket, Key: path });
|
|
14477
15198
|
}
|
|
14478
15199
|
return true;
|
|
14479
15200
|
}
|
|
14480
15201
|
async copy(from, to) {
|
|
14481
15202
|
try {
|
|
14482
|
-
await this.
|
|
14483
|
-
new CopyObjectCommand({ Bucket: this.config.bucket, Key: to, CopySource: `${this.config.bucket}/${encodeURIComponent(from)}` })
|
|
14484
|
-
);
|
|
15203
|
+
await this.send("CopyObjectCommand", { Bucket: this.config.bucket, Key: to, CopySource: `${this.config.bucket}/${encodeURIComponent(from)}` });
|
|
14485
15204
|
} catch (error) {
|
|
14486
15205
|
if (isNotFound(error)) throw new FileNotFoundError(from);
|
|
14487
15206
|
throw error;
|
|
@@ -14532,9 +15251,11 @@ var S3Filesystem = class {
|
|
|
14532
15251
|
return this.config.usePathStyleEndpoint ? `${endpoint}/${this.config.bucket}/${key}` : `${endpoint.replace(/^https?:\/\//, (proto) => `${proto}${this.config.bucket}.`)}/${key}`;
|
|
14533
15252
|
}
|
|
14534
15253
|
async temporaryUrl(path, expiresAt) {
|
|
15254
|
+
const { GetObjectCommand } = await loadSdk();
|
|
15255
|
+
const { getSignedUrl } = await importOptional("@aws-sdk/s3-request-presigner", "The s3 disk's temporaryUrl()", () => import("@aws-sdk/s3-request-presigner"));
|
|
14535
15256
|
const command = new GetObjectCommand({ Bucket: this.config.bucket, Key: path });
|
|
14536
15257
|
const expiresIn = Math.max(1, Math.round((expiresAt.getTime() - Date.now()) / 1e3));
|
|
14537
|
-
return getSignedUrl(this.
|
|
15258
|
+
return getSignedUrl(await this.resolveClient(), command, { expiresIn });
|
|
14538
15259
|
}
|
|
14539
15260
|
async files(directory = "", recursive = false) {
|
|
14540
15261
|
const { objects } = await this.list(directory, recursive);
|
|
@@ -14546,13 +15267,13 @@ var S3Filesystem = class {
|
|
|
14546
15267
|
}
|
|
14547
15268
|
async makeDirectory(path) {
|
|
14548
15269
|
const key = path.endsWith("/") ? path : `${path}/`;
|
|
14549
|
-
await this.
|
|
15270
|
+
await this.send("PutObjectCommand", { Bucket: this.config.bucket, Key: key, Body: new Uint8Array() });
|
|
14550
15271
|
return true;
|
|
14551
15272
|
}
|
|
14552
15273
|
async deleteDirectory(path) {
|
|
14553
15274
|
const prefix = path === "" ? "" : path.endsWith("/") ? path : `${path}/`;
|
|
14554
15275
|
const keys = await this.listAllKeys(prefix);
|
|
14555
|
-
for (const key of keys) await this.
|
|
15276
|
+
for (const key of keys) await this.send("DeleteObjectCommand", { Bucket: this.config.bucket, Key: key });
|
|
14556
15277
|
return true;
|
|
14557
15278
|
}
|
|
14558
15279
|
path(_path) {
|
|
@@ -14562,9 +15283,7 @@ var S3Filesystem = class {
|
|
|
14562
15283
|
const keys = [];
|
|
14563
15284
|
let continuationToken;
|
|
14564
15285
|
do {
|
|
14565
|
-
const page = await this.
|
|
14566
|
-
new ListObjectsV2Command({ Bucket: this.config.bucket, Prefix: prefix, ContinuationToken: continuationToken })
|
|
14567
|
-
);
|
|
15286
|
+
const page = await this.send("ListObjectsV2Command", { Bucket: this.config.bucket, Prefix: prefix, ContinuationToken: continuationToken });
|
|
14568
15287
|
for (const object of page.Contents ?? []) if (object.Key) keys.push(object.Key);
|
|
14569
15288
|
continuationToken = page.IsTruncated ? page.NextContinuationToken : void 0;
|
|
14570
15289
|
} while (continuationToken);
|
|
@@ -14581,9 +15300,7 @@ var S3Filesystem = class {
|
|
|
14581
15300
|
const prefixes = [];
|
|
14582
15301
|
let continuationToken;
|
|
14583
15302
|
do {
|
|
14584
|
-
const page = await this.
|
|
14585
|
-
new ListObjectsV2Command({ Bucket: this.config.bucket, Prefix: prefix, Delimiter: "/", ContinuationToken: continuationToken })
|
|
14586
|
-
);
|
|
15303
|
+
const page = await this.send("ListObjectsV2Command", { Bucket: this.config.bucket, Prefix: prefix, Delimiter: "/", ContinuationToken: continuationToken });
|
|
14587
15304
|
for (const key of (page.Contents ?? []).map((o) => o.Key)) if (key && key !== prefix) objects2.push(key);
|
|
14588
15305
|
for (const p of (page.CommonPrefixes ?? []).map((c) => c.Prefix)) if (p) prefixes.push(p.replace(/\/$/, ""));
|
|
14589
15306
|
continuationToken = page.IsTruncated ? page.NextContinuationToken : void 0;
|
|
@@ -14605,6 +15322,177 @@ var S3Filesystem = class {
|
|
|
14605
15322
|
return { objects, prefixes: [...dirs] };
|
|
14606
15323
|
}
|
|
14607
15324
|
};
|
|
15325
|
+
var asBody = (body) => body instanceof Uint8Array && !Buffer.isBuffer(body) ? Buffer.from(body.buffer, body.byteOffset, body.byteLength) : body;
|
|
15326
|
+
var blob = () => importOptional("@vercel/blob", "The blob disk", () => import("@vercel/blob"));
|
|
15327
|
+
function vercelBlobClient(token2) {
|
|
15328
|
+
return {
|
|
15329
|
+
put: async (pathname, body, options) => (await blob()).put(pathname, asBody(body), { ...options, token: token2 }),
|
|
15330
|
+
head: async (pathname) => (await blob()).head(pathname, { token: token2 }),
|
|
15331
|
+
del: async (pathnames) => (await blob()).del(pathnames, { token: token2 }),
|
|
15332
|
+
list: async (options) => (await blob()).list({ ...options, token: token2 }),
|
|
15333
|
+
copy: async (from, to, options) => (await blob()).copy(from, to, { ...options, token: token2 }),
|
|
15334
|
+
fetch: (url2) => fetch(url2)
|
|
15335
|
+
};
|
|
15336
|
+
}
|
|
15337
|
+
function blobStoreUrl(token2) {
|
|
15338
|
+
const match = /^vercel_blob_rw_([A-Za-z0-9]+)_/.exec(token2 ?? "");
|
|
15339
|
+
return match === null ? void 0 : `https://${match[1].toLowerCase()}.public.blob.vercel-storage.com`;
|
|
15340
|
+
}
|
|
15341
|
+
var CREATE = { access: "public", addRandomSuffix: false, allowOverwrite: true };
|
|
15342
|
+
var isNotFound2 = (error) => error.name === "BlobNotFoundError";
|
|
15343
|
+
var VercelBlobFilesystem = class {
|
|
15344
|
+
constructor(client, config2) {
|
|
15345
|
+
this.client = client;
|
|
15346
|
+
this.config = config2;
|
|
15347
|
+
if (config2.visibility === "private") throw new UnsupportedOperationError("visibility", "Vercel Blob disks are public");
|
|
15348
|
+
this.root = (config2.root ?? "").replace(/^\/+|\/+$/g, "");
|
|
15349
|
+
}
|
|
15350
|
+
client;
|
|
15351
|
+
config;
|
|
15352
|
+
root;
|
|
15353
|
+
/** The pathname in the store: the disk's root, then the path. */
|
|
15354
|
+
key(path) {
|
|
15355
|
+
return joinDiskPath(this.root, path.replace(/^\/+/, ""));
|
|
15356
|
+
}
|
|
15357
|
+
/** A store pathname back to the disk's path. */
|
|
15358
|
+
unroot(pathname) {
|
|
15359
|
+
return this.root === "" ? pathname : pathname.slice(this.root.length + 1);
|
|
15360
|
+
}
|
|
15361
|
+
async head(path) {
|
|
15362
|
+
try {
|
|
15363
|
+
return await this.client.head(this.key(path));
|
|
15364
|
+
} catch (error) {
|
|
15365
|
+
if (isNotFound2(error)) throw new FileNotFoundError(path);
|
|
15366
|
+
throw error;
|
|
15367
|
+
}
|
|
15368
|
+
}
|
|
15369
|
+
async exists(path) {
|
|
15370
|
+
try {
|
|
15371
|
+
await this.head(path);
|
|
15372
|
+
return true;
|
|
15373
|
+
} catch (error) {
|
|
15374
|
+
if (error instanceof FileNotFoundError) return false;
|
|
15375
|
+
throw error;
|
|
15376
|
+
}
|
|
15377
|
+
}
|
|
15378
|
+
async missing(path) {
|
|
15379
|
+
return !await this.exists(path);
|
|
15380
|
+
}
|
|
15381
|
+
async read(path) {
|
|
15382
|
+
const response2 = await this.client.fetch((await this.head(path)).url);
|
|
15383
|
+
if (response2.status === 404) throw new FileNotFoundError(path);
|
|
15384
|
+
if (!response2.ok) throw new Error(`Vercel Blob answered ${response2.status} reading ${path}`);
|
|
15385
|
+
return response2;
|
|
15386
|
+
}
|
|
15387
|
+
async get(path) {
|
|
15388
|
+
return (await this.read(path)).text();
|
|
15389
|
+
}
|
|
15390
|
+
async getBytes(path) {
|
|
15391
|
+
return new Uint8Array(await (await this.read(path)).arrayBuffer());
|
|
15392
|
+
}
|
|
15393
|
+
async readStream(path) {
|
|
15394
|
+
const body = (await this.read(path)).body;
|
|
15395
|
+
return body ?? new ReadableStream({ start: (controller) => controller.close() });
|
|
15396
|
+
}
|
|
15397
|
+
async put(path, contents, options) {
|
|
15398
|
+
await this.store(path, contents, options?.mimeType ?? mimeFromExtension(posix2.extname(path)), options);
|
|
15399
|
+
return true;
|
|
15400
|
+
}
|
|
15401
|
+
async putFile(directory, file, options) {
|
|
15402
|
+
return this.putFileAs(directory, file, uniqueFileName(file.extension()), options);
|
|
15403
|
+
}
|
|
15404
|
+
/** Sends the upload's own type (its extension()), as the s3 disk does, never the type the client claimed. */
|
|
15405
|
+
async putFileAs(directory, file, name, options) {
|
|
15406
|
+
const path = joinDiskPath(directory, name);
|
|
15407
|
+
await this.store(path, new Uint8Array(await file.arrayBuffer()), options?.mimeType ?? mimeFromExtension(file.extension()), options);
|
|
15408
|
+
return path;
|
|
15409
|
+
}
|
|
15410
|
+
async store(path, body, contentType, options) {
|
|
15411
|
+
if (options?.visibility === "private") throw new UnsupportedOperationError("put", "Vercel Blob disks are public");
|
|
15412
|
+
await this.client.put(this.key(path), body, { ...CREATE, ...contentType === void 0 ? {} : { contentType } });
|
|
15413
|
+
}
|
|
15414
|
+
async delete(paths) {
|
|
15415
|
+
const list5 = Array.isArray(paths) ? paths : [paths];
|
|
15416
|
+
if (list5.length > 0) await this.client.del(list5.map((path) => this.key(path)));
|
|
15417
|
+
return true;
|
|
15418
|
+
}
|
|
15419
|
+
async copy(from, to) {
|
|
15420
|
+
try {
|
|
15421
|
+
await this.client.copy(this.key(from), this.key(to), CREATE);
|
|
15422
|
+
} catch (error) {
|
|
15423
|
+
if (isNotFound2(error)) throw new FileNotFoundError(from);
|
|
15424
|
+
throw error;
|
|
15425
|
+
}
|
|
15426
|
+
return true;
|
|
15427
|
+
}
|
|
15428
|
+
async move(from, to) {
|
|
15429
|
+
await this.copy(from, to);
|
|
15430
|
+
await this.delete(from);
|
|
15431
|
+
return true;
|
|
15432
|
+
}
|
|
15433
|
+
async size(path) {
|
|
15434
|
+
return (await this.head(path)).size;
|
|
15435
|
+
}
|
|
15436
|
+
async lastModified(path) {
|
|
15437
|
+
return new Date((await this.head(path)).uploadedAt);
|
|
15438
|
+
}
|
|
15439
|
+
async mimeType(path) {
|
|
15440
|
+
return (await this.head(path)).contentType || void 0;
|
|
15441
|
+
}
|
|
15442
|
+
url(path) {
|
|
15443
|
+
const base = this.config.url ?? blobStoreUrl(this.config.token);
|
|
15444
|
+
if (base === void 0) throw new UnsupportedOperationError("url", "set the disk's token (BLOB_READ_WRITE_TOKEN) or its url");
|
|
15445
|
+
return `${base.replace(/\/+$/, "")}/${encodeKey(this.key(path))}`;
|
|
15446
|
+
}
|
|
15447
|
+
/** A public store's files need no signature: the public URL. */
|
|
15448
|
+
async temporaryUrl(path, _expiresAt) {
|
|
15449
|
+
return this.url(path);
|
|
15450
|
+
}
|
|
15451
|
+
async files(directory = "", recursive = false) {
|
|
15452
|
+
const { blobs } = await this.list(directory, recursive);
|
|
15453
|
+
return blobs.map((pathname) => this.unroot(pathname)).sort();
|
|
15454
|
+
}
|
|
15455
|
+
async directories(directory = "", recursive = false) {
|
|
15456
|
+
if (!recursive) return (await this.list(directory, false)).folders.map((folder) => this.unroot(folder.replace(/\/+$/, ""))).sort();
|
|
15457
|
+
const found = /* @__PURE__ */ new Set();
|
|
15458
|
+
const start3 = this.key(directory).replace(/\/+$/, "");
|
|
15459
|
+
for (const pathname of (await this.list(directory, true)).blobs) {
|
|
15460
|
+
const parts = pathname.split("/").slice(0, -1);
|
|
15461
|
+
for (let i = 1; i <= parts.length; i++) {
|
|
15462
|
+
const folder = parts.slice(0, i).join("/");
|
|
15463
|
+
if (folder.length > start3.length && (start3 === "" || folder.startsWith(`${start3}/`))) found.add(this.unroot(folder));
|
|
15464
|
+
}
|
|
15465
|
+
}
|
|
15466
|
+
return [...found].sort();
|
|
15467
|
+
}
|
|
15468
|
+
/** Blob folders exist through their files, so there's nothing to create. */
|
|
15469
|
+
async makeDirectory(_path) {
|
|
15470
|
+
return true;
|
|
15471
|
+
}
|
|
15472
|
+
async deleteDirectory(path) {
|
|
15473
|
+
const { blobs } = await this.list(path, true);
|
|
15474
|
+
for (let i = 0; i < blobs.length; i += 1e3) await this.client.del(blobs.slice(i, i + 1e3));
|
|
15475
|
+
return true;
|
|
15476
|
+
}
|
|
15477
|
+
path(_path) {
|
|
15478
|
+
throw new UnsupportedOperationError("path", "vercel-blob disks have no local filesystem path");
|
|
15479
|
+
}
|
|
15480
|
+
/** Every page of a listing: the store's pathnames, and in folded mode its folders (`prefix/name/`). */
|
|
15481
|
+
async list(directory, recursive) {
|
|
15482
|
+
const base = this.key(directory).replace(/\/+$/, "");
|
|
15483
|
+
const prefix = base === "" ? void 0 : `${base}/`;
|
|
15484
|
+
const blobs = [];
|
|
15485
|
+
const folders = [];
|
|
15486
|
+
let cursor;
|
|
15487
|
+
do {
|
|
15488
|
+
const page = await this.client.list({ prefix, cursor, mode: recursive ? "expanded" : "folded" });
|
|
15489
|
+
blobs.push(...page.blobs.map((blob2) => blob2.pathname));
|
|
15490
|
+
folders.push(...page.folders ?? []);
|
|
15491
|
+
cursor = page.hasMore ? page.cursor : void 0;
|
|
15492
|
+
} while (cursor !== void 0);
|
|
15493
|
+
return { blobs, folders };
|
|
15494
|
+
}
|
|
15495
|
+
};
|
|
14608
15496
|
var FilesystemManager2 = class {
|
|
14609
15497
|
constructor(container) {
|
|
14610
15498
|
this.container = container;
|
|
@@ -14616,12 +15504,22 @@ var FilesystemManager2 = class {
|
|
|
14616
15504
|
visibility: config2.visibility
|
|
14617
15505
|
})
|
|
14618
15506
|
);
|
|
14619
|
-
this.drivers.set("s3", (config2) => new S3Filesystem(this.buildS3Client(config2), this.s3Config(config2)));
|
|
15507
|
+
this.drivers.set("s3", (config2) => new S3Filesystem(() => this.buildS3Client(config2), this.s3Config(config2)));
|
|
15508
|
+
this.drivers.set("vercel-blob", (config2) => {
|
|
15509
|
+
const token2 = config2.token ?? process.env.BLOB_READ_WRITE_TOKEN;
|
|
15510
|
+
return new VercelBlobFilesystem(vercelBlobClient(token2), {
|
|
15511
|
+
token: token2,
|
|
15512
|
+
url: config2.url,
|
|
15513
|
+
root: config2.root,
|
|
15514
|
+
visibility: config2.visibility
|
|
15515
|
+
});
|
|
15516
|
+
});
|
|
14620
15517
|
}
|
|
14621
15518
|
container;
|
|
14622
15519
|
disks = /* @__PURE__ */ new Map();
|
|
14623
15520
|
drivers = /* @__PURE__ */ new Map();
|
|
14624
|
-
buildS3Client(config2) {
|
|
15521
|
+
async buildS3Client(config2) {
|
|
15522
|
+
const { S3Client } = await importOptional("@aws-sdk/client-s3", "The s3 disk", () => import("@aws-sdk/client-s3"));
|
|
14625
15523
|
const key = config2.key;
|
|
14626
15524
|
const secret = config2.secret;
|
|
14627
15525
|
return new S3Client({
|
|
@@ -14980,11 +15878,11 @@ var HashingServiceProvider = class extends ServiceProvider {
|
|
|
14980
15878
|
import { existsSync as existsSync7, readdirSync as readdirSync5 } from "fs";
|
|
14981
15879
|
import { join as join11, relative as relative5, sep as sep4 } from "path";
|
|
14982
15880
|
import { createHash as createHash7 } from "crypto";
|
|
14983
|
-
import { existsSync as
|
|
15881
|
+
import { existsSync as existsSync24, readFileSync } from "fs";
|
|
14984
15882
|
import { spawn as spawn2 } from "child_process";
|
|
14985
15883
|
import { existsSync as existsSync33 } from "fs";
|
|
14986
15884
|
import { mkdir as mkdir5, writeFile as writeFile6 } from "fs/promises";
|
|
14987
|
-
import { dirname as dirname5, isAbsolute as isAbsolute2, join as join24, relative as
|
|
15885
|
+
import { dirname as dirname5, isAbsolute as isAbsolute2, join as join24, relative as relative23 } from "path";
|
|
14988
15886
|
import { existsSync as existsSync43, readFileSync as readFileSync2 } from "fs";
|
|
14989
15887
|
var Header = {
|
|
14990
15888
|
INERTIA: "X-Inertia",
|
|
@@ -15862,7 +16760,7 @@ var InertiaMiddleware = class {
|
|
|
15862
16760
|
if (typeof assetUrl === "string" && assetUrl !== "") return md5(assetUrl);
|
|
15863
16761
|
const app2 = this.container.make(Application);
|
|
15864
16762
|
const manifest = app2.publicPath("build/manifest.json");
|
|
15865
|
-
return
|
|
16763
|
+
return existsSync24(manifest) ? md5(readFileSync(manifest)) : null;
|
|
15866
16764
|
}
|
|
15867
16765
|
/** Props shared with every page. Override and spread `await super.share(request)` into your own. */
|
|
15868
16766
|
async share(request2) {
|
|
@@ -16143,7 +17041,7 @@ export class {{ class }} extends InertiaMiddleware {
|
|
|
16143
17041
|
}
|
|
16144
17042
|
}
|
|
16145
17043
|
`;
|
|
16146
|
-
var DEFAULT_EXCEPT_ROUTES = ["live.*"];
|
|
17044
|
+
var DEFAULT_EXCEPT_ROUTES = ["live.*", "vercel.*"];
|
|
16147
17045
|
async function loadPageTypes() {
|
|
16148
17046
|
const specifier = "@orieljs/vite/types";
|
|
16149
17047
|
try {
|
|
@@ -16172,7 +17070,7 @@ function registerInertiaCommands(kernel, app2, gateway, options = {}) {
|
|
|
16172
17070
|
await writeFile6(output, renderRoutesModule(table));
|
|
16173
17071
|
await mkdir5(dirname5(server), { recursive: true });
|
|
16174
17072
|
await writeFile6(server, renderServerRouteTypes(routeTable(app2.make(Router).getRoutes())));
|
|
16175
|
-
this.info(`Route types for ${Object.keys(table).length} named routes written to ${
|
|
17073
|
+
this.info(`Route types for ${Object.keys(table).length} named routes written to ${relative23(app2.basePath(), output)}.`);
|
|
16176
17074
|
return 0;
|
|
16177
17075
|
}
|
|
16178
17076
|
).purpose("Generate the route table and route name types for the frontend");
|
|
@@ -16185,7 +17083,7 @@ function registerInertiaCommands(kernel, app2, gateway, options = {}) {
|
|
|
16185
17083
|
const output = absolute(optionText(this.option("output")) ?? config2("inertia.types.pages", "resources/js/oriel/pages.d.ts"));
|
|
16186
17084
|
const result = await module.generatePageTypes({ root: app2.basePath(), output });
|
|
16187
17085
|
for (const warning of result.warnings) this.warn(warning);
|
|
16188
|
-
this.info(`Page types for ${result.pages} pages written to ${
|
|
17086
|
+
this.info(`Page types for ${result.pages} pages written to ${relative23(app2.basePath(), result.output)}.`);
|
|
16189
17087
|
return 0;
|
|
16190
17088
|
}).purpose("Generate TypeScript types for the Inertia page props");
|
|
16191
17089
|
kernel.command("inertia:middleware {name=HandleInertiaRequests : The middleware class name} {--force : Overwrite an existing file}", async function() {
|
|
@@ -16196,12 +17094,12 @@ function registerInertiaCommands(kernel, app2, gateway, options = {}) {
|
|
|
16196
17094
|
}
|
|
16197
17095
|
const file = app2.appPath(join24("Http", "Middleware", `${name}.ts`));
|
|
16198
17096
|
if (existsSync33(file) && this.option("force") !== true) {
|
|
16199
|
-
this.error(`Middleware [${
|
|
17097
|
+
this.error(`Middleware [${relative23(app2.basePath(), file)}] already exists.`);
|
|
16200
17098
|
return 1;
|
|
16201
17099
|
}
|
|
16202
17100
|
await mkdir5(dirname5(file), { recursive: true });
|
|
16203
17101
|
await writeFile6(file, MIDDLEWARE_STUB2.replace("{{ class }}", () => name));
|
|
16204
|
-
this.info(`Middleware [${
|
|
17102
|
+
this.info(`Middleware [${relative23(app2.basePath(), file)}] created successfully.`);
|
|
16205
17103
|
return 0;
|
|
16206
17104
|
}).purpose("Create a new Inertia middleware");
|
|
16207
17105
|
kernel.command("inertia:start-ssr {--runtime= : The runtime that runs the SSR bundle (node or bun)}", async function() {
|
|
@@ -16400,9 +17298,9 @@ var InertiaServiceProvider = class extends ServiceProvider {
|
|
|
16400
17298
|
|
|
16401
17299
|
// ../Log/dist/index.js
|
|
16402
17300
|
import pino2 from "pino";
|
|
16403
|
-
import { createWriteStream as createWriteStream2, mkdirSync as
|
|
17301
|
+
import { createWriteStream as createWriteStream2, mkdirSync as mkdirSync3, readdirSync as readdirSync6, rmSync } from "fs";
|
|
16404
17302
|
import { basename as basename2, dirname as dirname6, extname as extname3, join as join12 } from "path";
|
|
16405
|
-
import { Writable } from "stream";
|
|
17303
|
+
import { Writable as Writable2 } from "stream";
|
|
16406
17304
|
import "pino";
|
|
16407
17305
|
var rootKey = {};
|
|
16408
17306
|
var contexts = /* @__PURE__ */ new WeakMap();
|
|
@@ -16522,14 +17420,14 @@ function localDay(date) {
|
|
|
16522
17420
|
return `${date.getFullYear()}-${month}-${day}`;
|
|
16523
17421
|
}
|
|
16524
17422
|
var DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
16525
|
-
var DailyRotatingStream = class extends
|
|
17423
|
+
var DailyRotatingStream = class extends Writable2 {
|
|
16526
17424
|
constructor(basePath, days, now5 = () => /* @__PURE__ */ new Date()) {
|
|
16527
17425
|
super();
|
|
16528
17426
|
this.days = days;
|
|
16529
17427
|
this.now = now5;
|
|
16530
17428
|
this.dir = dirname6(basePath);
|
|
16531
17429
|
this.stem = basename2(basePath, extname3(basePath) || void 0);
|
|
16532
|
-
|
|
17430
|
+
mkdirSync3(this.dir, { recursive: true });
|
|
16533
17431
|
}
|
|
16534
17432
|
days;
|
|
16535
17433
|
now;
|
|
@@ -18440,7 +19338,7 @@ async function restoreValue(value2, registry2) {
|
|
|
18440
19338
|
}
|
|
18441
19339
|
function normalizeBackoff(backoff) {
|
|
18442
19340
|
if (typeof backoff === "number") return [backoff];
|
|
18443
|
-
if (typeof backoff === "string" && backoff !== "") return backoff.split(",").map((
|
|
19341
|
+
if (typeof backoff === "string" && backoff !== "") return backoff.split(",").map((part2) => Number(part2.trim()));
|
|
18444
19342
|
if (Array.isArray(backoff)) return backoff.map(Number);
|
|
18445
19343
|
return void 0;
|
|
18446
19344
|
}
|
|
@@ -20229,7 +21127,7 @@ var QueueServiceProvider = class extends ServiceProvider {
|
|
|
20229
21127
|
};
|
|
20230
21128
|
|
|
20231
21129
|
// ../Routing/dist/index.js
|
|
20232
|
-
import { createHmac as
|
|
21130
|
+
import { createHmac as createHmac7, timingSafeEqual as timingSafeEqual6 } from "crypto";
|
|
20233
21131
|
import { pathToFileURL as pathToFileURL7 } from "url";
|
|
20234
21132
|
import { createHash as createHash10 } from "crypto";
|
|
20235
21133
|
import { createHash as createHash23 } from "crypto";
|
|
@@ -20690,7 +21588,7 @@ async function dispatchRoute(router, request2, container) {
|
|
|
20690
21588
|
}
|
|
20691
21589
|
var ALL_VERBS = ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"];
|
|
20692
21590
|
function mergeGroup(parent, child) {
|
|
20693
|
-
const prefix = [parent.prefix, child.prefix].map((
|
|
21591
|
+
const prefix = [parent.prefix, child.prefix].map((part2) => (part2 ?? "").replace(/^\/+|\/+$/g, "")).filter((part2) => part2 !== "").join("/");
|
|
20694
21592
|
const merged = {
|
|
20695
21593
|
middleware: [...parent.middleware ?? [], ...child.middleware ?? []]
|
|
20696
21594
|
};
|
|
@@ -20845,7 +21743,7 @@ var BaseRouter = class {
|
|
|
20845
21743
|
}
|
|
20846
21744
|
const prefix = (group.prefix ?? "").replace(/^\/+|\/+$/g, "");
|
|
20847
21745
|
const path = uri.replace(/^\/+|\/+$/g, "");
|
|
20848
|
-
const route2 = new RouteDefinition(verbs, [prefix, path].filter((
|
|
21746
|
+
const route2 = new RouteDefinition(verbs, [prefix, path].filter((part2) => part2 !== "").join("/"), action, {
|
|
20849
21747
|
...group.as !== void 0 && { namePrefix: group.as },
|
|
20850
21748
|
...group.middleware !== void 0 && { middleware: group.middleware },
|
|
20851
21749
|
...group.controller !== void 0 && { controller: group.controller },
|
|
@@ -21070,12 +21968,12 @@ function routeKey(value2, field) {
|
|
|
21070
21968
|
return typeof model.getRouteKey === "function" ? model.getRouteKey() : value2;
|
|
21071
21969
|
}
|
|
21072
21970
|
function sign(url2, key) {
|
|
21073
|
-
return
|
|
21971
|
+
return createHmac7("sha256", key).update(url2).digest("hex");
|
|
21074
21972
|
}
|
|
21075
21973
|
function safeEquals(expected, given) {
|
|
21076
21974
|
const a = Buffer.from(expected);
|
|
21077
21975
|
const b = Buffer.from(given);
|
|
21078
|
-
return a.length === b.length &&
|
|
21976
|
+
return a.length === b.length && timingSafeEqual6(a, b);
|
|
21079
21977
|
}
|
|
21080
21978
|
function availableAt(expiration) {
|
|
21081
21979
|
return expiration instanceof Date ? Math.floor(expiration.getTime() / 1e3) : Math.floor(Date.now() / 1e3) + expiration;
|
|
@@ -21446,8 +22344,8 @@ var RoutingServiceProvider = class extends ServiceProvider {
|
|
|
21446
22344
|
import { mkdir as mkdir6, readdir as readdir3, readFile as readFile4, rename as rename3, rm as rm3, stat as stat3, writeFile as writeFile7 } from "fs/promises";
|
|
21447
22345
|
import { join as join14 } from "path";
|
|
21448
22346
|
import { Redis as Redis3 } from "ioredis";
|
|
21449
|
-
import { randomInt } from "crypto";
|
|
21450
|
-
import { timingSafeEqual as
|
|
22347
|
+
import { randomInt as randomInt3 } from "crypto";
|
|
22348
|
+
import { timingSafeEqual as timingSafeEqual7 } from "crypto";
|
|
21451
22349
|
var unique = (values) => [...new Set(values)];
|
|
21452
22350
|
var Store = class {
|
|
21453
22351
|
#id = "";
|
|
@@ -21714,18 +22612,20 @@ var FileSessionHandler = class {
|
|
|
21714
22612
|
}
|
|
21715
22613
|
};
|
|
21716
22614
|
var DatabaseSessionHandler = class {
|
|
21717
|
-
constructor(connection, table, minutes, container = () => void 0, clock = Date.now) {
|
|
22615
|
+
constructor(connection, table, minutes, container = () => void 0, clock = Date.now, options = {}) {
|
|
21718
22616
|
this.connection = connection;
|
|
21719
22617
|
this.table = table;
|
|
21720
22618
|
this.minutes = minutes;
|
|
21721
22619
|
this.container = container;
|
|
21722
22620
|
this.clock = clock;
|
|
22621
|
+
this.options = options;
|
|
21723
22622
|
}
|
|
21724
22623
|
connection;
|
|
21725
22624
|
table;
|
|
21726
22625
|
minutes;
|
|
21727
22626
|
container;
|
|
21728
22627
|
clock;
|
|
22628
|
+
options;
|
|
21729
22629
|
#exists = false;
|
|
21730
22630
|
async read(id) {
|
|
21731
22631
|
const session2 = await this.#query().where("id", id).first();
|
|
@@ -21767,7 +22667,10 @@ var DatabaseSessionHandler = class {
|
|
|
21767
22667
|
const payload = { payload: Buffer.from(data, "utf8").toString("base64"), last_activity: this.#now() };
|
|
21768
22668
|
const container = this.container();
|
|
21769
22669
|
if (container === void 0) return payload;
|
|
21770
|
-
if (
|
|
22670
|
+
if (this.options.clientDetails !== true) {
|
|
22671
|
+
payload.ip_address = null;
|
|
22672
|
+
payload.user_agent = null;
|
|
22673
|
+
} else if (container.bound(HttpRequest)) {
|
|
21771
22674
|
const request2 = container.make(HttpRequest);
|
|
21772
22675
|
payload.ip_address = request2.ip() ?? null;
|
|
21773
22676
|
payload.user_agent = (request2.header("user-agent") ?? "").slice(0, 500);
|
|
@@ -21899,7 +22802,9 @@ var SessionManager = class {
|
|
|
21899
22802
|
() => container.make(DatabaseManager).connection(config2.connection ?? void 0),
|
|
21900
22803
|
config2.table ?? "sessions",
|
|
21901
22804
|
lifetime,
|
|
21902
|
-
() => container
|
|
22805
|
+
() => container,
|
|
22806
|
+
void 0,
|
|
22807
|
+
{ clientDetails: config2.client_details === true }
|
|
21903
22808
|
);
|
|
21904
22809
|
case "cookie":
|
|
21905
22810
|
return new CookieSessionHandler(
|
|
@@ -22004,7 +22909,7 @@ var StartSession = class {
|
|
|
22004
22909
|
/** Laravel's lottery: on average lottery[0] requests out of lottery[1] clean up expired sessions. */
|
|
22005
22910
|
async #collectGarbage(session2, config2) {
|
|
22006
22911
|
const [chances, outOf] = config2.lottery ?? [2, 100];
|
|
22007
|
-
if (session2.getHandler !== void 0 &&
|
|
22912
|
+
if (session2.getHandler !== void 0 && randomInt3(1, outOf + 1) <= chances) {
|
|
22008
22913
|
await session2.getHandler().gc((config2.lifetime ?? 120) * 60);
|
|
22009
22914
|
}
|
|
22010
22915
|
}
|
|
@@ -22016,7 +22921,7 @@ var StartSession = class {
|
|
|
22016
22921
|
function equals3(known, user) {
|
|
22017
22922
|
const a = Buffer.from(known);
|
|
22018
22923
|
const b = Buffer.from(user);
|
|
22019
|
-
return a.length === b.length &&
|
|
22924
|
+
return a.length === b.length && timingSafeEqual7(a, b);
|
|
22020
22925
|
}
|
|
22021
22926
|
var VerifyCsrfToken = class {
|
|
22022
22927
|
/** URIs (wildcards allowed) excluded from the check, in addition to config('http.csrf_except'). */
|
|
@@ -22154,7 +23059,8 @@ var SessionServiceProvider = class extends ServiceProvider {
|
|
|
22154
23059
|
domain: null,
|
|
22155
23060
|
secure: null,
|
|
22156
23061
|
http_only: true,
|
|
22157
|
-
same_site: "lax"
|
|
23062
|
+
same_site: "lax",
|
|
23063
|
+
client_details: false
|
|
22158
23064
|
},
|
|
22159
23065
|
"session"
|
|
22160
23066
|
);
|
|
@@ -24344,17 +25250,17 @@ function buildNested(flat) {
|
|
|
24344
25250
|
const created = /* @__PURE__ */ new Set([root]);
|
|
24345
25251
|
for (const [path, value2] of Object.entries(flat)) {
|
|
24346
25252
|
const parts = path.split(".");
|
|
24347
|
-
if (parts.some((
|
|
25253
|
+
if (parts.some((part2) => UNSAFE_KEYS.has(part2))) continue;
|
|
24348
25254
|
let current = root;
|
|
24349
|
-
for (const
|
|
24350
|
-
const existing = Object.hasOwn(current,
|
|
25255
|
+
for (const part2 of parts.slice(0, -1)) {
|
|
25256
|
+
const existing = Object.hasOwn(current, part2) ? current[part2] : void 0;
|
|
24351
25257
|
if (typeof existing === "object" && existing !== null && created.has(existing)) {
|
|
24352
25258
|
current = existing;
|
|
24353
25259
|
continue;
|
|
24354
25260
|
}
|
|
24355
25261
|
const container = cloneContainer(existing);
|
|
24356
25262
|
created.add(container);
|
|
24357
|
-
current[
|
|
25263
|
+
current[part2] = container;
|
|
24358
25264
|
current = container;
|
|
24359
25265
|
}
|
|
24360
25266
|
current[parts.at(-1)] = value2;
|
|
@@ -24383,15 +25289,15 @@ function withoutPaths(data, paths) {
|
|
|
24383
25289
|
const parts = path.split(".");
|
|
24384
25290
|
const leaf = parts.pop();
|
|
24385
25291
|
let node = root;
|
|
24386
|
-
for (const
|
|
24387
|
-
const child = Object.hasOwn(node,
|
|
25292
|
+
for (const part2 of parts) {
|
|
25293
|
+
const child = Object.hasOwn(node, part2) ? node[part2] : void 0;
|
|
24388
25294
|
if (!isPlainContainer(child)) {
|
|
24389
25295
|
node = void 0;
|
|
24390
25296
|
break;
|
|
24391
25297
|
}
|
|
24392
25298
|
const copy = copies.has(child) ? child : Array.isArray(child) ? [...child] : { ...child };
|
|
24393
25299
|
copies.add(copy);
|
|
24394
|
-
node[
|
|
25300
|
+
node[part2] = copy;
|
|
24395
25301
|
node = copy;
|
|
24396
25302
|
}
|
|
24397
25303
|
if (node === void 0 || !Object.hasOwn(node, leaf)) continue;
|
|
@@ -24676,6 +25582,52 @@ var ValidationServiceProvider = class extends ServiceProvider {
|
|
|
24676
25582
|
import { existsSync as existsSync9, readdirSync as readdirSync8, readFileSync as readFileSync3, realpathSync, statSync as statSync4 } from "fs";
|
|
24677
25583
|
import { cp, mkdir as mkdir7, rm as rm4, writeFile as writeFile8 } from "fs/promises";
|
|
24678
25584
|
import { basename as basename3, dirname as dirname7, join as join15, relative as relative6, resolve as resolve4 } from "path";
|
|
25585
|
+
import { CronExpressionParser as CronExpressionParser2 } from "cron-parser";
|
|
25586
|
+
import { timingSafeEqual as timingSafeEqual8 } from "crypto";
|
|
25587
|
+
import { CronExpressionParser as CronExpressionParser3 } from "cron-parser";
|
|
25588
|
+
var SCHEDULE_PATH = "/_oriel/schedule";
|
|
25589
|
+
var DEFAULT_CRON = "0 3 * * *";
|
|
25590
|
+
var LAST_RUN = "oriel:vercel:schedule:last";
|
|
25591
|
+
var LOCK = "oriel:vercel:schedule";
|
|
25592
|
+
var json2 = (body, status = 200) => Response.json(body, { status, headers: { "cache-control": "no-store" } });
|
|
25593
|
+
function authorized(header, secret) {
|
|
25594
|
+
const expected = Buffer.from(`Bearer ${secret}`);
|
|
25595
|
+
const given = Buffer.from(header ?? "");
|
|
25596
|
+
return given.length === expected.length && timingSafeEqual8(given, expected);
|
|
25597
|
+
}
|
|
25598
|
+
function previousTrigger(expression, now5) {
|
|
25599
|
+
const parsed = CronExpressionParser3.parse(expression, { currentDate: new Date(now5.getTime() + 6e4), tz: "UTC" });
|
|
25600
|
+
parsed.prev();
|
|
25601
|
+
return parsed.prev().toDate();
|
|
25602
|
+
}
|
|
25603
|
+
async function runVercelSchedule(authorization, options = {}) {
|
|
25604
|
+
const secret = process.env.CRON_SECRET;
|
|
25605
|
+
if (!secret) return new Response("Not Found", { status: 404 });
|
|
25606
|
+
if (!authorized(authorization, secret)) return json2({ error: "Unauthorized" }, 401);
|
|
25607
|
+
const cache2 = inject(CacheManager);
|
|
25608
|
+
const lock = cache2.lock(LOCK, 900);
|
|
25609
|
+
if (!await lock.get()) return json2({ ran: 0, failed: 0, skipped: "busy" });
|
|
25610
|
+
try {
|
|
25611
|
+
await inject(ConsoleKernel).bootstrap();
|
|
25612
|
+
const now5 = options.now?.() ?? /* @__PURE__ */ new Date();
|
|
25613
|
+
const last = await cache2.get(LAST_RUN);
|
|
25614
|
+
const from = last === void 0 ? previousTrigger(options.trigger ?? process.env.ORIEL_VERCEL_CRON ?? DEFAULT_CRON, now5) : new Date(last);
|
|
25615
|
+
const due = inject(Schedule).dueBetween(from, now5);
|
|
25616
|
+
let failed = 0;
|
|
25617
|
+
for (const event2 of due) {
|
|
25618
|
+
try {
|
|
25619
|
+
await event2.run();
|
|
25620
|
+
} catch (error) {
|
|
25621
|
+
failed++;
|
|
25622
|
+
await inject(ExceptionHandler).report(error);
|
|
25623
|
+
}
|
|
25624
|
+
}
|
|
25625
|
+
await cache2.forever(LAST_RUN, now5.toISOString());
|
|
25626
|
+
return json2({ ran: due.length, failed }, failed > 0 ? 500 : 200);
|
|
25627
|
+
} finally {
|
|
25628
|
+
await lock.release();
|
|
25629
|
+
}
|
|
25630
|
+
}
|
|
24679
25631
|
var LAUNCHER = `// Oriel on Vercel: boots the app once per function instance and hands it each request.
|
|
24680
25632
|
import { fileURLToPath } from 'node:url'
|
|
24681
25633
|
|
|
@@ -24758,8 +25710,10 @@ async function buildVercelOutput(app2, options = {}) {
|
|
|
24758
25710
|
const vcConfig = { runtime: options.runtime ?? "nodejs22.x", handler: "index.mjs", launcherType: "Nodejs", shouldAddHelpers: false, supportsResponseStreaming: true };
|
|
24759
25711
|
await writeFile8(join15(fn, ".vc-config.json"), `${JSON.stringify(vcConfig, null, 2)}
|
|
24760
25712
|
`);
|
|
25713
|
+
const { crons, cronWarnings } = await scheduleCron(app2, options.cron);
|
|
24761
25714
|
const config2 = {
|
|
24762
25715
|
version: 3,
|
|
25716
|
+
...crons === void 0 ? {} : { crons },
|
|
24763
25717
|
routes: [
|
|
24764
25718
|
// The built assets' names change with their content, so they're cached for a year, as serve() does.
|
|
24765
25719
|
{ src: "^/build/assets/(.*)$", headers: { "cache-control": "public, max-age=31536000, immutable" }, continue: true },
|
|
@@ -24778,7 +25732,26 @@ async function buildVercelOutput(app2, options = {}) {
|
|
|
24778
25732
|
const warnings = platform === "linux" ? [] : [
|
|
24779
25733
|
`Built on ${PLATFORM_NAMES[platform] ?? platform}: the function's native packages (such as esbuild, which tsx needs) only run on this kind of machine, and Vercel's functions run on Linux. Let Vercel run the build, or build on Linux.`
|
|
24780
25734
|
];
|
|
24781
|
-
return { functionBytes, staticFiles: countFiles(staticFolder), warnings };
|
|
25735
|
+
return { functionBytes, staticFiles: countFiles(staticFolder), warnings: [...warnings, ...cronWarnings] };
|
|
25736
|
+
}
|
|
25737
|
+
async function scheduleCron(app2, cron) {
|
|
25738
|
+
if (cron === false) return { cronWarnings: [] };
|
|
25739
|
+
if (app2.bound(ConsoleKernel)) await app2.make(ConsoleKernel).bootstrap();
|
|
25740
|
+
if (!app2.bound(Schedule)) return { cronWarnings: [] };
|
|
25741
|
+
const schedule = app2.make(Schedule);
|
|
25742
|
+
if (schedule.events().length === 0) return { cronWarnings: [] };
|
|
25743
|
+
const expression = cron ?? DEFAULT_CRON;
|
|
25744
|
+
const fires = CronExpressionParser2.parse(expression, { tz: "UTC" });
|
|
25745
|
+
const start3 = fires.next().toDate();
|
|
25746
|
+
const end = fires.next().toDate();
|
|
25747
|
+
const middle = new Date((start3.getTime() + end.getTime()) / 2);
|
|
25748
|
+
const later = new Set(schedule.dueBetween(middle, end));
|
|
25749
|
+
const often = schedule.dueBetween(start3, middle).filter((event2) => later.has(event2));
|
|
25750
|
+
const plan = cron === void 0 ? " (once a day on Vercel's Hobby plan)" : "";
|
|
25751
|
+
return {
|
|
25752
|
+
crons: [{ path: SCHEDULE_PATH, schedule: expression }],
|
|
25753
|
+
cronWarnings: often.map((event2) => `"${event2.getSummaryForDisplay()}" (${event2.expression}) is due more often than the cron "${expression}", so it runs once per trigger${plan}.`)
|
|
25754
|
+
};
|
|
24782
25755
|
}
|
|
24783
25756
|
async function copyDependencies(base, fn) {
|
|
24784
25757
|
const manifest = JSON.parse(readFileSync3(join15(base, "package.json"), "utf8"));
|
|
@@ -24823,11 +25796,19 @@ var megabytes = (bytes) => `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
|
24823
25796
|
var megabytes2 = (bytes) => `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
24824
25797
|
var VercelServiceProvider = class extends ServiceProvider {
|
|
24825
25798
|
boot() {
|
|
25799
|
+
if (this.app.bound(Router)) {
|
|
25800
|
+
this.app.make(Router).get(SCHEDULE_PATH, () => {
|
|
25801
|
+
const request2 = inject(HttpRequest);
|
|
25802
|
+
return runVercelSchedule(request2.header("authorization"), { trigger: request2.header("x-vercel-cron-schedule") });
|
|
25803
|
+
}).name("vercel.schedule");
|
|
25804
|
+
}
|
|
24826
25805
|
if (!this.app.bound(ConsoleKernel)) return;
|
|
24827
25806
|
const app2 = this.app;
|
|
24828
|
-
this.app.make(ConsoleKernel).command("vercel:build", async function() {
|
|
25807
|
+
this.app.make(ConsoleKernel).command("vercel:build {--cron= : When Vercel calls the scheduler, as a cron expression (UTC), or false for never}", async function() {
|
|
24829
25808
|
try {
|
|
24830
|
-
const
|
|
25809
|
+
const option = this.option("cron");
|
|
25810
|
+
const cron = typeof option === "string" && option !== "" ? option === "false" ? false : option : void 0;
|
|
25811
|
+
const { staticFiles, functionBytes, warnings } = await buildVercelOutput(app2, { cron });
|
|
24831
25812
|
const files3 = staticFiles === 1 ? "1 static file" : `${staticFiles} static files`;
|
|
24832
25813
|
this.info(`Wrote .vercel/output: ${files3}, a function of ${megabytes2(functionBytes)}.`);
|
|
24833
25814
|
for (const warning of warnings) this.warn(warning);
|
|
@@ -24851,7 +25832,7 @@ import { parse as parse2 } from "dotenv";
|
|
|
24851
25832
|
var SECRET = /key|secret|password|token|credential|salt|private/i;
|
|
24852
25833
|
var CREDENTIALS = /^[a-z][a-z0-9+.-]*:\/\/[^/?#\s]*@/i;
|
|
24853
25834
|
var byName = (a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
|
|
24854
|
-
var
|
|
25835
|
+
var posix3 = (path) => path.split(sep5).join("/");
|
|
24855
25836
|
function commandSection(all) {
|
|
24856
25837
|
return Object.entries(all).map(([name, command]) => {
|
|
24857
25838
|
const signature = parseSignature(command.signature);
|
|
@@ -24893,8 +25874,8 @@ function viewSection(paths, hints, extensions, basePath) {
|
|
|
24893
25874
|
const extension = extensions.find((candidate) => item.name.endsWith(`.${candidate}`));
|
|
24894
25875
|
if (extension === void 0) continue;
|
|
24895
25876
|
const file = join16(item.parentPath, item.name);
|
|
24896
|
-
const name = prefix +
|
|
24897
|
-
if (!views.has(name)) views.set(name,
|
|
25877
|
+
const name = prefix + posix3(relative7(root, file)).slice(0, -(extension.length + 1)).split("/").join(".");
|
|
25878
|
+
if (!views.has(name)) views.set(name, posix3(relative7(basePath, file)));
|
|
24898
25879
|
}
|
|
24899
25880
|
};
|
|
24900
25881
|
for (const path of paths) collect2(path, "");
|
|
@@ -24903,7 +25884,7 @@ function viewSection(paths, hints, extensions, basePath) {
|
|
|
24903
25884
|
}
|
|
24904
25885
|
|
|
24905
25886
|
// ide/IdeInfoCommand.ts
|
|
24906
|
-
var
|
|
25887
|
+
var posix4 = (path) => path.split(sep6).join("/");
|
|
24907
25888
|
var read = (file) => existsSync11(file) ? readFileSync4(file, "utf8") : null;
|
|
24908
25889
|
var IdeInfoCommand = class extends Command {
|
|
24909
25890
|
signature = "ide:info {--pretty : Indent the JSON}";
|
|
@@ -24935,7 +25916,7 @@ function describe(app2, container) {
|
|
|
24935
25916
|
const basePath = app2.basePath();
|
|
24936
25917
|
const config2 = optional(ConfigRepository);
|
|
24937
25918
|
const get = (key, fallback) => config2 ? config2.get(key, fallback) : fallback;
|
|
24938
|
-
const relativeTo = (file) =>
|
|
25919
|
+
const relativeTo = (file) => posix4(relative8(basePath, file));
|
|
24939
25920
|
const configDirectory = app2.configPath();
|
|
24940
25921
|
const configFiles = existsSync11(configDirectory) ? readdirSync10(configDirectory).filter((file) => /\.(ts|js|mjs)$/.test(file)).map((file) => relativeTo(join17(configDirectory, file))) : [];
|
|
24941
25922
|
const factory = optional(ViewFactory);
|
|
@@ -25052,6 +26033,7 @@ export {
|
|
|
25052
26033
|
AuthServiceProvider,
|
|
25053
26034
|
AuthenticatableModel,
|
|
25054
26035
|
Authenticate,
|
|
26036
|
+
AuthenticateSession,
|
|
25055
26037
|
AuthenticationError,
|
|
25056
26038
|
Authorizable,
|
|
25057
26039
|
AuthorizationError,
|
|
@@ -25100,6 +26082,7 @@ export {
|
|
|
25100
26082
|
Computed,
|
|
25101
26083
|
Config,
|
|
25102
26084
|
Connection,
|
|
26085
|
+
ConsoleAbortedError,
|
|
25103
26086
|
Kernel2 as ConsoleKernelImpl,
|
|
25104
26087
|
ConsoleServiceProvider,
|
|
25105
26088
|
Container2 as Container,
|
|
@@ -25114,6 +26097,7 @@ export {
|
|
|
25114
26097
|
CookieValuePrefix,
|
|
25115
26098
|
CorruptComponentPayloadError,
|
|
25116
26099
|
Crypt,
|
|
26100
|
+
CurrentDeviceLogout,
|
|
25117
26101
|
Cursor,
|
|
25118
26102
|
CursorPaginator,
|
|
25119
26103
|
DB,
|
|
@@ -25220,6 +26204,7 @@ export {
|
|
|
25220
26204
|
InvalidListenerError,
|
|
25221
26205
|
InvalidLiveRequestError,
|
|
25222
26206
|
InvalidLogLevelError,
|
|
26207
|
+
InvalidPasswordError,
|
|
25223
26208
|
InvalidRuleParameterError,
|
|
25224
26209
|
InvalidSignatureError,
|
|
25225
26210
|
InvalidUploadSignatureError,
|
|
@@ -25300,6 +26285,7 @@ export {
|
|
|
25300
26285
|
Migrator,
|
|
25301
26286
|
MissingAppKeyError,
|
|
25302
26287
|
MissingModelError,
|
|
26288
|
+
MissingPackageError,
|
|
25303
26289
|
MissingRecipientError,
|
|
25304
26290
|
Model,
|
|
25305
26291
|
ModelNotFoundError,
|
|
@@ -25329,6 +26315,7 @@ export {
|
|
|
25329
26315
|
On,
|
|
25330
26316
|
OnceProp,
|
|
25331
26317
|
OptionalProp,
|
|
26318
|
+
OtherDeviceLogout,
|
|
25332
26319
|
PERSISTENT_MIDDLEWARE,
|
|
25333
26320
|
PERSONAL_ACCESS_TOKENS_MIGRATION,
|
|
25334
26321
|
PREVIEW_URI,
|
|
@@ -25369,6 +26356,7 @@ export {
|
|
|
25369
26356
|
QueuedMailSender,
|
|
25370
26357
|
RESTART_CACHE_KEY,
|
|
25371
26358
|
RateLimiter2 as RateLimiter,
|
|
26359
|
+
RecoveryCodeUsed,
|
|
25372
26360
|
RedirectIfAuthenticated,
|
|
25373
26361
|
RedisJob,
|
|
25374
26362
|
RedisLock,
|
|
@@ -25395,6 +26383,7 @@ export {
|
|
|
25395
26383
|
Rule,
|
|
25396
26384
|
S3Filesystem,
|
|
25397
26385
|
SCHEDULE_INTERRUPT_KEY,
|
|
26386
|
+
SESSION_URI,
|
|
25398
26387
|
SSR_RENDER_FAILED,
|
|
25399
26388
|
STORAGE_LINK_SIGNATURE,
|
|
25400
26389
|
Schedule5 as Schedule,
|
|
@@ -25436,6 +26425,7 @@ export {
|
|
|
25436
26425
|
SyncJob,
|
|
25437
26426
|
SyncQueue,
|
|
25438
26427
|
TEMPORARY_UPLOAD_DEFAULTS,
|
|
26428
|
+
TWO_FACTOR_COLUMNS_MIGRATION,
|
|
25439
26429
|
TagsNotSupportedError,
|
|
25440
26430
|
TemporaryFileNotFoundError,
|
|
25441
26431
|
TemporaryUploadedFile,
|
|
@@ -25451,6 +26441,16 @@ export {
|
|
|
25451
26441
|
TokenRepository,
|
|
25452
26442
|
TrimStrings,
|
|
25453
26443
|
TsxView,
|
|
26444
|
+
TwoFactor,
|
|
26445
|
+
TwoFactorAppAlreadyEnabledError,
|
|
26446
|
+
TwoFactorAppDisabled,
|
|
26447
|
+
TwoFactorAppEnabled,
|
|
26448
|
+
TwoFactorAuthenticated,
|
|
26449
|
+
TwoFactorChallenge,
|
|
26450
|
+
TwoFactorChallenged,
|
|
26451
|
+
TwoFactorCode,
|
|
26452
|
+
TwoFactorFailed,
|
|
26453
|
+
TwoFactorManager,
|
|
25454
26454
|
TypeGenerator,
|
|
25455
26455
|
UNIQUE,
|
|
25456
26456
|
UNIQUE_LOCK,
|
|
@@ -25475,6 +26475,7 @@ export {
|
|
|
25475
26475
|
UnrenderableNotificationMailError,
|
|
25476
26476
|
UnsupportedCipherError,
|
|
25477
26477
|
UnsupportedOperationError,
|
|
26478
|
+
UploadAlreadyStoredError,
|
|
25478
26479
|
UploadValidationError,
|
|
25479
26480
|
UrlGenerationError,
|
|
25480
26481
|
VERCEL_FUNCTION_LIMIT,
|
|
@@ -25486,6 +26487,7 @@ export {
|
|
|
25486
26487
|
ValidationServiceProvider,
|
|
25487
26488
|
Validator,
|
|
25488
26489
|
ValidatorImpl,
|
|
26490
|
+
VercelBlobFilesystem,
|
|
25489
26491
|
VercelServiceProvider,
|
|
25490
26492
|
Verified,
|
|
25491
26493
|
VerifyCsrfToken,
|
|
@@ -25517,6 +26519,7 @@ export {
|
|
|
25517
26519
|
auth,
|
|
25518
26520
|
back,
|
|
25519
26521
|
bcrypt3 as bcrypt,
|
|
26522
|
+
blobStoreUrl,
|
|
25520
26523
|
buildVercelOutput,
|
|
25521
26524
|
builtinRules,
|
|
25522
26525
|
bunRuntime,
|
|
@@ -25721,6 +26724,7 @@ export {
|
|
|
25721
26724
|
toResponse,
|
|
25722
26725
|
toWebRequest,
|
|
25723
26726
|
tokenableType,
|
|
26727
|
+
totpCode,
|
|
25724
26728
|
transformLeaves,
|
|
25725
26729
|
url,
|
|
25726
26730
|
usePaginationResolvers,
|