@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Htmlable, OrielError, ErrorKind, View as View$1, ViewFactory } from './contracts.js';
|
|
2
|
-
import { F as Facade, S as ServiceProvider } from './index.d-
|
|
2
|
+
import { F as Facade, S as ServiceProvider } from './index.d-lffxurFs.js';
|
|
3
3
|
|
|
4
4
|
/** Marks the objects jsx() returns (Symbol.for, so two copies of the package agree). */
|
|
5
5
|
declare const ELEMENT: unique symbol;
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { a as Fragment, H as HtmlAttributes, J as JSX, u as jsx, w as jsxs } from './jsx-runtime-
|
|
1
|
+
export { a as Fragment, H as HtmlAttributes, J as JSX, u as jsx, w as jsxs } from './jsx-runtime-Bc5KJzwb.js';
|
|
2
2
|
import './contracts.js';
|
|
3
|
-
import './index.d-
|
|
3
|
+
import './index.d-lffxurFs.js';
|
package/dist/jsx-runtime.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BusDispatcher, Job, PendingBatchOptions, Class, PendingChain, PendingBatch, Batch, EventDispatcher, Listener, MailManager, Mailable, Address, MailRecipient, Mailer, PendingMail, SentMessage, MailTransport, NotificationDispatcher, Notifiable, Notification, NotificationChannel, QueueManager, QueuePayload, Queue, QueueJob, FilesystemManager, Filesystem, PutOptions, UploadedFile, Application, Session, View, Authenticatable, Container, AuthFactory, InertiaPage, ServiceProvider, ServiceProviderClass, DatabaseManager, ModelInstance, Row, Encrypter, Token, ExceptionHandler, ViewFactory, RouteName, RouteArguments, Rules, InferValidatedType, MessageBag, LiveSnapshot, LiveEffects, OrielError, ErrorKind, Htmlable, LiveManager, HttpRequest, LiveUpdateRequest, LiveUpdateResponse, MiddlewareClass, Router } from './contracts.js';
|
|
2
|
-
import { S as ServiceProvider$1 } from './index.d-
|
|
2
|
+
import { S as ServiceProvider$1 } from './index.d-lffxurFs.js';
|
|
3
3
|
|
|
4
4
|
/** A date the tests travel to: a Date, an ISO string or milliseconds since the epoch. */
|
|
5
5
|
type TravelDate = Date | string | number;
|
|
@@ -77,6 +77,7 @@ declare class PendingCommand implements PromiseLike<number> {
|
|
|
77
77
|
private readonly app;
|
|
78
78
|
readonly command: string;
|
|
79
79
|
readonly parameters: Record<string, unknown>;
|
|
80
|
+
private readonly answers;
|
|
80
81
|
private readonly checks;
|
|
81
82
|
private result;
|
|
82
83
|
constructor(app: Application, command: string, parameters?: Record<string, unknown>);
|
|
@@ -91,6 +92,8 @@ declare class PendingCommand implements PromiseLike<number> {
|
|
|
91
92
|
assertSuccessful(): this;
|
|
92
93
|
assertOk(): this;
|
|
93
94
|
assertFailed(): this;
|
|
95
|
+
/** Answers the command's questions (ask(), secret(), confirm(), choice()), in order. A question beyond them fails. */
|
|
96
|
+
withAnswers(...answers: string[]): this;
|
|
94
97
|
/** Runs the command once and checks the expectations; resolves to the exit code. */
|
|
95
98
|
run(): Promise<number>;
|
|
96
99
|
then<R1 = number, R2 = never>(onfulfilled?: ((value: number) => R1 | PromiseLike<R1>) | null, onrejected?: ((reason: unknown) => R2 | PromiseLike<R2>) | null): Promise<R1 | R2>;
|
|
@@ -455,6 +458,10 @@ declare class HttpClient {
|
|
|
455
458
|
protected scopeSession(scope: Container): Session | undefined;
|
|
456
459
|
buildRequest(method: string, uri: string, options: RequestOptions): Request;
|
|
457
460
|
protected baseUrl(): string;
|
|
461
|
+
/** The cookies as EncryptCookies would leave them, since no middleware runs for a Live test. */
|
|
462
|
+
protected plainCookies(): Record<string, string>;
|
|
463
|
+
/** A cookie kept from a response is as it was sent: encrypted, unless the app excepts it. */
|
|
464
|
+
protected decrypted(name: string, value: string): string | undefined;
|
|
458
465
|
protected cookieHeader(): string;
|
|
459
466
|
/** Like a browser: cookies the app sets are sent back on later requests in the same test; deleted ones are dropped. */
|
|
460
467
|
protected rememberCookies(response: Response): void;
|
|
@@ -637,6 +644,16 @@ declare abstract class TestCase extends InteractsWithTime {
|
|
|
637
644
|
* already set (the shell, CI, vitest.config) win, like phpunit's non-forced <env>.
|
|
638
645
|
*/
|
|
639
646
|
declare const TESTING_ENVIRONMENT: Readonly<Record<string, string>>;
|
|
647
|
+
/**
|
|
648
|
+
* What a test run's vitest.config.ts spreads into `test`: the testing environment, and whether files run at the same time.
|
|
649
|
+
* The tests run on SQLite in memory, or on TEST_DATABASE_URL's database, one file at a time, as they share it. DB_URL and
|
|
650
|
+
* DB_CONNECTION never count: RefreshDatabase wipes the database it runs on, and Bun loads .env before the tests start, so
|
|
651
|
+
* honouring them could wipe a production database. It prints which database the run is on.
|
|
652
|
+
*/
|
|
653
|
+
declare function testingConfig(env?: NodeJS.ProcessEnv, log?: (line: string) => void, cwd?: string): {
|
|
654
|
+
env: Record<string, string>;
|
|
655
|
+
fileParallelism: boolean;
|
|
656
|
+
};
|
|
640
657
|
declare function applyEnvironment(values: Record<string, string>, env?: NodeJS.ProcessEnv): void;
|
|
641
658
|
|
|
642
659
|
/** The request scope's ViewFactory: records every view made, so TestResponse can assert on it (assertViewIs/Has). */
|
|
@@ -671,7 +688,7 @@ declare const RefreshDatabaseState: {
|
|
|
671
688
|
};
|
|
672
689
|
/** Runs a console command through the ConsoleKernel contract; a non-zero exit fails the test with its output. */
|
|
673
690
|
declare function runCommand(app: Application, command: string, parameters?: Record<string, unknown>): Promise<void>;
|
|
674
|
-
/** Laravel's usingInMemoryDatabase()
|
|
691
|
+
/** Laravel's usingInMemoryDatabase(), by the driver too: only SQLite has a database in memory, whatever DB_DATABASE says. */
|
|
675
692
|
declare function usingInMemoryDatabase(app: Application): boolean;
|
|
676
693
|
/**
|
|
677
694
|
* Laravel's RefreshDatabase.
|
|
@@ -1215,6 +1232,8 @@ declare class Testable<C extends Component = Component> {
|
|
|
1215
1232
|
html(): string;
|
|
1216
1233
|
/** The effects of the last request. */
|
|
1217
1234
|
effects(): LiveEffects;
|
|
1235
|
+
/** The cookies the last request queued, by name; null for one it deleted. */
|
|
1236
|
+
cookies(): Record<string, string | null>;
|
|
1218
1237
|
/**
|
|
1219
1238
|
* Sets public properties through an update. A file (a FakeFile) or an array of files is uploaded as `o:model` on a
|
|
1220
1239
|
* file input does it: the upload rules, the temporary disk, then a TemporaryUploadedFile (or an array) in the
|
|
@@ -1357,6 +1376,11 @@ declare class LiveComponentManager implements LiveManager {
|
|
|
1357
1376
|
|
|
1358
1377
|
/** The URI the client runtime posts updates to. */
|
|
1359
1378
|
declare const UPDATE_URI = "/oriel/live/update";
|
|
1379
|
+
/**
|
|
1380
|
+
* Where the client gets a session before its first update when the page came without one (a page cached at a CDN):
|
|
1381
|
+
* through the `web` middleware, so the answer sets the session and XSRF-TOKEN cookies (Sanctum's csrf-cookie route).
|
|
1382
|
+
*/
|
|
1383
|
+
declare const SESSION_URI = "/oriel/live/session";
|
|
1360
1384
|
/**
|
|
1361
1385
|
* Binds the LiveManager and the PaginationState that WithPagination components answer, merges the `live` config,
|
|
1362
1386
|
* registers POST /oriel/live/update (named `live.update`, in the `web` group: sessions and CSRF apply), the upload and
|
|
@@ -1430,6 +1454,12 @@ declare class FileNotPreviewableError extends LiveError {
|
|
|
1430
1454
|
readonly name: string;
|
|
1431
1455
|
constructor(extension: string);
|
|
1432
1456
|
}
|
|
1457
|
+
/** store() or temporaryUrl() on an upload that was stored already, so its temporary file has gone. */
|
|
1458
|
+
declare class UploadAlreadyStoredError extends LiveError {
|
|
1459
|
+
readonly path: string;
|
|
1460
|
+
readonly name: string;
|
|
1461
|
+
constructor(path: string);
|
|
1462
|
+
}
|
|
1433
1463
|
/** The errors an upload came back with (`_uploadErrored`): the component re-renders with them on the property. */
|
|
1434
1464
|
declare class UploadValidationError extends LiveError {
|
|
1435
1465
|
readonly errors: Record<string, string[]>;
|
|
@@ -1494,11 +1524,15 @@ declare class TemporaryUploadedFile implements UploadedFile {
|
|
|
1494
1524
|
text(): Promise<string>;
|
|
1495
1525
|
/** The file's bytes from the temporary disk, opened on the first read. */
|
|
1496
1526
|
stream(): ReadableStream<Uint8Array>;
|
|
1497
|
-
/**
|
|
1527
|
+
/**
|
|
1528
|
+
* Moves the file under a random name to `directory`, on `disk` (by default the temporary disk, as Livewire's), so no
|
|
1529
|
+
* temporary copy is left behind: on a public disk it could be fetched at its address. An upload stores once.
|
|
1530
|
+
*/
|
|
1498
1531
|
store(directory: string, disk?: string): Promise<string>;
|
|
1532
|
+
/** store(), under the name you give it. */
|
|
1499
1533
|
storeAs(directory: string, name: string, disk?: string): Promise<string>;
|
|
1500
1534
|
exists(): Promise<boolean>;
|
|
1501
|
-
/** Removes the temporary file
|
|
1535
|
+
/** Removes the temporary file, if it hasn't been stored. */
|
|
1502
1536
|
delete(): Promise<boolean>;
|
|
1503
1537
|
/** Whether temporaryUrl() serves this file: its type is in `live.temporary_file_upload.preview_mimes`. */
|
|
1504
1538
|
isPreviewable(): boolean;
|
|
@@ -1574,13 +1608,18 @@ interface PaginationProps {
|
|
|
1574
1608
|
paginator: PaginationSource;
|
|
1575
1609
|
/** Classes for the <nav>, such as its layout ("flex gap-2"); in your file, so Tailwind generates them. */
|
|
1576
1610
|
class?: string;
|
|
1611
|
+
/** Classes for Previous, Next and the page buttons, the kits' `btn btn-secondary` unless you say; '' for none. */
|
|
1612
|
+
buttonClass?: string;
|
|
1613
|
+
/** Classes for the current page's button, the kits' `btn` unless you say; '' for none. */
|
|
1614
|
+
currentClass?: string;
|
|
1577
1615
|
}
|
|
1578
1616
|
/**
|
|
1579
1617
|
* Livewire's pagination links for a WithPagination component: `<Pagination paginator={posts} />` in render(). A
|
|
1580
1618
|
* <nav aria-label="Pagination"> with « Previous, the page buttons and Next » as Live actions (previousPage,
|
|
1581
1619
|
* gotoPage(n), nextPage), the current page marked aria-current="page", the ends disabled, the kits' theme classes
|
|
1582
|
-
* (btn, btn-secondary). Nothing when everything fits on one page.
|
|
1620
|
+
* (btn, btn-secondary) unless `buttonClass` and `currentClass` say otherwise. Nothing when everything fits on one page.
|
|
1621
|
+
* The address bar is left alone.
|
|
1583
1622
|
*/
|
|
1584
|
-
declare function Pagination({ paginator, class: className }: PaginationProps): Htmlable;
|
|
1623
|
+
declare function Pagination({ paginator, class: className, buttonClass, currentClass }: PaginationProps): Htmlable;
|
|
1585
1624
|
|
|
1586
|
-
export { type
|
|
1625
|
+
export { type CountOrFilter as $, UPLOAD_URI as A, BusFake as B, Component as C, UploadAlreadyStoredError as D, EventFake as E, FileNotPreviewableError as F, UploadValidationError as G, WithPagination as H, InvalidLiveRequestError as I, componentName as J, live as K, Live as L, MailFake as M, NotificationFake as N, On as O, PERSISTENT_MIDDLEWARE as P, QueueFake as Q, persistentMiddleware as R, StorageFake as S, TEMPORARY_UPLOAD_DEFAULTS as T, UPDATE_URI as U, AnonymousNotifiable as V, WithFileUploads as W, AssertableInertia as X, AssertableJson as Y, type BatchRecord as Z, type BootOptions as _, type ComponentResult as a, DatabaseMigrations as a0, type DatabaseTestOptions as a1, DatabaseTransactions as a2, type DispatchedEvent as a3, type ExpectedErrors as a4, type ExpectedListener as a5, FakeDisk as a6, FakeFile as a7, HttpClient as a8, InteractsWithApplication as a9, applyEnvironment as aA, cookieHeader as aB, cookiePrefix as aC, decryptCookie as aD, encryptCookie as aE, flatten as aF, freezeSecond as aG, freezeTime as aH, guessMimeType as aI, inertiaPageOf as aJ, install as aK, isExpired as aL, matches as aM, nameOf as aN, recordingExceptionHandler as aO, recordingViewFactory as aP, responseCookies as aQ, runCommand as aR, testingConfig as aS, travel as aT, travelBack as aU, travelTo as aV, usingInMemoryDatabase as aW, InteractsWithConsole as aa, InteractsWithDatabase as ab, InteractsWithTime as ac, type JsonStructure as ad, MailRecord as ae, MakesHttpRequests as af, PendingCommand as ag, type PushedJob as ah, RefreshDatabase as ai, RefreshDatabaseState as aj, type RequestData as ak, type RequestOptions as al, type ResponseContext as am, type ResponseCookie as an, type SentNotification as ao, TESTING_ENVIRONMENT as ap, type TableOrModel as aq, type Target as ar, TestCase as as, type TestHooks as at, TestResponse as au, type TestTrait as av, type TravelDate as aw, Wormhole as ax, actingAsAuthFactory as ay, addresses as az, Computed as b, CorruptComponentPayloadError as c, ErrorBag as d, InvalidUploadSignatureError as e, LiveComponentManager as f, LiveComponentNotFoundError as g, LiveError as h, type LiveProps as i, LiveServiceProvider as j, Locked as k, MethodNotCallableError as l, PREVIEW_URI as m, type Paginated as n, Pagination as o, type PaginationProps as p, type PaginationSource as q, PendingEvent as r, type PersistentMiddleware as s, PropertyNotUpdatableError as t, SESSION_URI as u, type TemporaryFileData as v, TemporaryFileNotFoundError as w, TemporaryUploadedFile as x, TestRequestScope as y, Testable as z };
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { V as AnonymousNotifiable, X as AssertableInertia, Y as AssertableJson, Z as BatchRecord, _ as BootOptions, B as BusFake, $ as CountOrFilter, a0 as DatabaseMigrations, a1 as DatabaseTestOptions, a2 as DatabaseTransactions, a3 as DispatchedEvent, E as EventFake, a4 as ExpectedErrors, a5 as ExpectedListener, a6 as FakeDisk, a7 as FakeFile, a8 as HttpClient, a9 as InteractsWithApplication, aa as InteractsWithConsole, ab as InteractsWithDatabase, ac as InteractsWithTime, ad as JsonStructure, L as Live, M as MailFake, ae as MailRecord, af as MakesHttpRequests, N as NotificationFake, ag as PendingCommand, ah as PushedJob, Q as QueueFake, ai as RefreshDatabase, aj as RefreshDatabaseState, ak as RequestData, al as RequestOptions, am as ResponseContext, an as ResponseCookie, ao as SentNotification, S as StorageFake, ap as TESTING_ENVIRONMENT, aq as TableOrModel, ar as Target, as as TestCase, at as TestHooks, au as TestResponse, av as TestTrait, z as Testable, aw as TravelDate, ax as Wormhole, ay as actingAsAuthFactory, az as addresses, aA as applyEnvironment, aB as cookieHeader, aC as cookiePrefix, aD as decryptCookie, aE as encryptCookie, aF as flatten, aG as freezeSecond, aH as freezeTime, aI as guessMimeType, aJ as inertiaPageOf, aK as install, aL as isExpired, aM as matches, aN as nameOf, aO as recordingExceptionHandler, aP as recordingViewFactory, aQ as responseCookies, aR as runCommand, aS as testingConfig, aT as travel, aU as travelBack, aV as travelTo, aW as usingInMemoryDatabase } from './testing-CVpo7aRl.js';
|
|
2
2
|
import './contracts.js';
|
|
3
|
-
import './index.d-
|
|
3
|
+
import './index.d-lffxurFs.js';
|
package/dist/testing.js
CHANGED
|
@@ -48,13 +48,14 @@ import {
|
|
|
48
48
|
recordingViewFactory,
|
|
49
49
|
responseCookies,
|
|
50
50
|
runCommand,
|
|
51
|
+
testingConfig,
|
|
51
52
|
travel,
|
|
52
53
|
travelBack,
|
|
53
54
|
travelTo,
|
|
54
55
|
usingInMemoryDatabase
|
|
55
|
-
} from "./chunk-
|
|
56
|
-
import "./chunk-
|
|
57
|
-
import "./chunk-
|
|
56
|
+
} from "./chunk-UBSIBGXR.js";
|
|
57
|
+
import "./chunk-4NCMY3ZS.js";
|
|
58
|
+
import "./chunk-BKA5F3TH.js";
|
|
58
59
|
export {
|
|
59
60
|
AnonymousNotifiable,
|
|
60
61
|
AssertableInertia,
|
|
@@ -105,6 +106,7 @@ export {
|
|
|
105
106
|
recordingViewFactory,
|
|
106
107
|
responseCookies,
|
|
107
108
|
runCommand,
|
|
109
|
+
testingConfig,
|
|
108
110
|
travel,
|
|
109
111
|
travelBack,
|
|
110
112
|
travelTo,
|
package/docs/authentication.md
CHANGED
|
@@ -187,6 +187,8 @@ page, or to the path you give.
|
|
|
187
187
|
`attempt()` changes the session's id as it signs the user in, which protects against session fixation; the kits also
|
|
188
188
|
call `regenerate()`, as above.
|
|
189
189
|
|
|
190
|
+
To ask for a code after the password, by email or from an authenticator app, see [Two-factor login](two-factor.md).
|
|
191
|
+
|
|
190
192
|
#### Specifying additional conditions
|
|
191
193
|
|
|
192
194
|
Add any condition to the credentials. A list matches any of its values, and a function receives the query:
|
|
@@ -298,7 +300,44 @@ export class LogoutController extends Controller {
|
|
|
298
300
|
```
|
|
299
301
|
|
|
300
302
|
> [!NOTE]
|
|
301
|
-
> Laravel's
|
|
303
|
+
> Laravel's password confirmation pages (`password.confirm`) aren't in Oriel.
|
|
304
|
+
|
|
305
|
+
### Invalidating sessions on other devices
|
|
306
|
+
|
|
307
|
+
A new password usually means someone else may have the old one, so it should end the user's other sessions. The
|
|
308
|
+
`auth.session` middleware does that, on every session driver. It keeps a keyed hash of the user's password in the session
|
|
309
|
+
and signs the session out when the password no longer matches. The starter kits add it to the `web` group, so Live updates
|
|
310
|
+
are covered too. An existing app adds one line, in `bootstrap/app.ts`:
|
|
311
|
+
|
|
312
|
+
```ts
|
|
313
|
+
import { dirname } from 'node:path'
|
|
314
|
+
import { Application, AuthenticateSession } from '@orieljs/framework'
|
|
315
|
+
|
|
316
|
+
Application.configure({ basePath: dirname(import.meta.dirname) })
|
|
317
|
+
.withMiddleware((middleware) => {
|
|
318
|
+
middleware.web({ append: [AuthenticateSession] })
|
|
319
|
+
})
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
With it in place:
|
|
323
|
+
|
|
324
|
+
- A new password or a password reset ends the user's other sessions, on their next request.
|
|
325
|
+
- The session that changes the password stays signed in, and so does that device's "Remember me" cookie.
|
|
326
|
+
- A session from before you added the middleware has no hash yet. It stores one and carries on, so nobody is signed out by
|
|
327
|
+
upgrading, and rotating the app key signs nobody out either.
|
|
328
|
+
- A page cached [without a session](live.md#pages-cached-without-a-session) passes straight through.
|
|
329
|
+
|
|
330
|
+
To end the other sessions without a new password, such as for a "Sign out everywhere else" button, ask for the current
|
|
331
|
+
password and pass it to `logoutOtherDevices()`. It throws `InvalidPasswordError` when the password is wrong:
|
|
332
|
+
|
|
333
|
+
```ts
|
|
334
|
+
import { Auth, request } from '@orieljs/framework'
|
|
335
|
+
|
|
336
|
+
await Auth.logoutOtherDevices(String(request().input('password')))
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
It works by rehashing the password, so it needs the middleware to take effect. `Auth.logoutCurrentDevice()` signs out here
|
|
340
|
+
only: unlike `logout()`, it leaves the remember token alone, so the user's other remembered devices keep working.
|
|
302
341
|
|
|
303
342
|
## API tokens
|
|
304
343
|
|
|
@@ -481,6 +520,8 @@ Signing in and out dispatches these events, which you can [listen](events.md) fo
|
|
|
481
520
|
| `Failed` | The credentials didn't match |
|
|
482
521
|
| `Login` | A user signed in with `attempt()`, `login()`, `loginUsingId()` or the "Remember me" cookie (`once()` dispatches none) |
|
|
483
522
|
| `Logout` | A user signed out |
|
|
523
|
+
| `CurrentDeviceLogout` | `logoutCurrentDevice()` or `auth.session` signed a user out on this device |
|
|
524
|
+
| `OtherDeviceLogout` | `logoutOtherDevices()` rehashed the password, which ends the other sessions |
|
|
484
525
|
| `Lockout` | The kits' login throttle stopped a user |
|
|
485
526
|
| `Registered` | The kits registered a user (it sends the verification mail) |
|
|
486
527
|
| `Verified` | A user verified their email address |
|
package/docs/console.md
CHANGED
|
@@ -116,7 +116,7 @@ These are the commands every app has. A new app adds one of its own, `inspire`,
|
|
|
116
116
|
| `schedule:run` | Runs the scheduled tasks that are due |
|
|
117
117
|
| `schedule:work` | Runs the tasks that are due, every minute, until you stop it |
|
|
118
118
|
| `storage:link` | Links `public/storage` to `storage/app/public` |
|
|
119
|
-
| `vercel:build` | Writes your app's build for Vercel into `.vercel/output` ([Deploying to Vercel](deployment.md#deploying-to-vercel)) |
|
|
119
|
+
| `vercel:build` | Writes your app's build for Vercel into `.vercel/output` ([Deploying to Vercel](deployment.md#deploying-to-vercel)); `--cron=` sets when Vercel calls the scheduler ([Scheduled tasks](deployment.md#scheduled-tasks)) |
|
|
120
120
|
|
|
121
121
|
`node oriel help <command>` lists a command's options. A few that are worth knowing up front:
|
|
122
122
|
|
|
@@ -192,6 +192,8 @@ export class SendEmails extends Command {
|
|
|
192
192
|
}
|
|
193
193
|
```
|
|
194
194
|
|
|
195
|
+
Each run gets a new instance of your class, so its fields start fresh and `#private` members work.
|
|
196
|
+
|
|
195
197
|
Each run of a command has its own scope, as a request does, so `inject()`, the helpers and the facades work inside
|
|
196
198
|
`handle()`, and a scoped service lasts for that one run.
|
|
197
199
|
|
|
@@ -434,9 +436,8 @@ declare const command: Command
|
|
|
434
436
|
const password = await command.secret('What is the password?')
|
|
435
437
|
```
|
|
436
438
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
> terminal shows it as it is typed.
|
|
439
|
+
Nothing typed appears in a terminal, and the answer isn't trimmed, as a secret may start or end with a space. When the
|
|
440
|
+
input is a pipe, `secret()` takes the next line, as `ask()` does. Ctrl-C at any question ends the command with exit code 130.
|
|
440
441
|
|
|
441
442
|
#### Asking for confirmation
|
|
442
443
|
|
|
@@ -647,8 +648,18 @@ test('the mail is sent', async () => {
|
|
|
647
648
|
it; `doesntExpectOutput()` and `doesntExpectOutputToContain()` want the opposite. `assertSuccessful()` and
|
|
648
649
|
`assertFailed()` check the exit code is `0`, or isn't.
|
|
649
650
|
|
|
651
|
+
A command that asks questions gets its answers from `withAnswers()`, in order, whichever way it asks. A question beyond
|
|
652
|
+
them fails the test:
|
|
653
|
+
|
|
654
|
+
```ts
|
|
655
|
+
import { TestCase } from '@orieljs/framework/testing'
|
|
656
|
+
declare const t: TestCase
|
|
657
|
+
// ---cut---
|
|
658
|
+
await t.artisan('admin:create').withAnswers('a-password', 'a-password').assertExitCode(0)
|
|
659
|
+
```
|
|
660
|
+
|
|
650
661
|
> [!NOTE]
|
|
651
|
-
> Laravel's `expectsQuestion()` and `expectsConfirmation()` aren't in Oriel:
|
|
652
|
-
>
|
|
662
|
+
> Laravel's `expectsQuestion()` and `expectsConfirmation()` aren't in Oriel: `withAnswers()` gives the answers without
|
|
663
|
+
> checking how the questions are worded.
|
|
653
664
|
|
|
654
665
|
The [Testing](testing.md) pages cover the rest.
|
package/docs/database-testing.md
CHANGED
|
@@ -60,6 +60,27 @@ export class TestCase extends BaseTestCase {
|
|
|
60
60
|
> [!NOTE]
|
|
61
61
|
> Laravel's traits are PHP traits, added with `use RefreshDatabase;`. Oriel's are objects you list in `uses`.
|
|
62
62
|
|
|
63
|
+
### Running the tests on another database
|
|
64
|
+
|
|
65
|
+
`TEST_DATABASE_URL` runs the tests on a PostgreSQL or MySQL database, with its driver installed, one file at a time, as they
|
|
66
|
+
share it:
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
TEST_DATABASE_URL=postgres://oriel:secret@127.0.0.1:5432/oriel_test npm test
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The run prints `Tests run on pgsql at 127.0.0.1:5432/oriel_test (TEST_DATABASE_URL), one file at a time.`, without the user or
|
|
73
|
+
the password.
|
|
74
|
+
|
|
75
|
+
> [!WARNING]
|
|
76
|
+
> `RefreshDatabase` empties the database it runs on, so give the tests a database of their own. `DB_URL` and `DB_CONNECTION`
|
|
77
|
+
> never count for tests, so a production address in `.env` can't reach them, and `TEST_DATABASE_URL` is refused when it
|
|
78
|
+
> points at the app's own database, from `DB_URL` or from `DB_HOST`, `DB_PORT` and `DB_DATABASE`, in the environment or in
|
|
79
|
+
> `.env`. `localhost`, `127.0.0.1` and `::1` count as one host.
|
|
80
|
+
>
|
|
81
|
+
> As a last check, `RefreshDatabase` and `DatabaseMigrations` refuse to empty the database your `.env` points at, even
|
|
82
|
+
> when a `vitest.config.ts` of your own doesn't use `testingConfig()`.
|
|
83
|
+
|
|
63
84
|
## Model factories
|
|
64
85
|
|
|
65
86
|
[Factories](eloquent-factories.md) make the rows a test needs:
|
package/docs/database.md
CHANGED
|
@@ -152,6 +152,18 @@ const users = await DB.table('users').select(DB.raw('count(*) as user_count, sta
|
|
|
152
152
|
|
|
153
153
|
A raw expression is SQL you write, so never put a user's input in it: bind it with `?` instead.
|
|
154
154
|
|
|
155
|
+
|
|
156
|
+
### Drivers
|
|
157
|
+
|
|
158
|
+
Each connection's driver is a package of its own: `better-sqlite3` for SQLite on Node, which a new app has (Bun has SQLite
|
|
159
|
+
built in), `pg` for PostgreSQL and `mysql2` for MySQL. Install the one you use:
|
|
160
|
+
|
|
161
|
+
```sh
|
|
162
|
+
npm install pg
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
A driver that isn't installed says so the first time the connection is used: `The pgsql connection needs the pg package.
|
|
166
|
+
Install it with: npm install pg`, with the command for your package manager.
|
|
155
167
|
### Values in bindings
|
|
156
168
|
|
|
157
169
|
Oriel turns some values into what the database stores: `true` and `false` become `1` and `0` (except on PostgreSQL,
|
package/docs/deployment.md
CHANGED
|
@@ -19,7 +19,10 @@ when requests come: see [Deploying to Vercel](#deploying-to-vercel).
|
|
|
19
19
|
Your server needs **Node 22** or later, or **Bun 1.2** or later. On Node, your app's TypeScript runs through `tsx`,
|
|
20
20
|
which every app has as a dependency; Bun runs it as it is. There is no compile step for your server code.
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
Each database and disk needs its driver in your dependencies: `better-sqlite3` for SQLite on Node (a new Node app has it,
|
|
23
|
+
and Bun has SQLite built in), `pg` for PostgreSQL, `mysql2` for MySQL, `@aws-sdk/client-s3` and `@aws-sdk/s3-request-presigner`
|
|
24
|
+
for an `s3` disk, `@vercel/blob` for a `blob` disk. A driver that's missing says so the first time it's used, with the
|
|
25
|
+
command that installs it.
|
|
23
26
|
|
|
24
27
|
## Building your application
|
|
25
28
|
|
|
@@ -308,10 +311,13 @@ and each instance has its own, so:
|
|
|
308
311
|
headers itself, so the function trusts them when `trusted_proxies`, in `config/http.ts`, is empty: your URLs keep
|
|
309
312
|
the browser's `https`, and `request().ip()` is the visitor's (see
|
|
310
313
|
[Configuring trusted proxies](requests.md#configuring-trusted-proxies)).
|
|
311
|
-
- **Files your app stores** go on
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
314
|
+
- **Files your app stores** go on the `blob` disk, a Vercel Blob store, or an `s3` disk (see
|
|
315
|
+
[The Vercel Blob driver](storage.md#the-vercel-blob-driver)): the `local` and `public` disks write into `storage`,
|
|
316
|
+
which the function can't.
|
|
317
|
+
- **The function carries your `dependencies`**, so list `pg` (or `mysql2`) and `@vercel/blob` there, and move
|
|
318
|
+
`better-sqlite3` to `devDependencies` when your tests use it: then the function holds only the drivers it uses.
|
|
319
|
+
- **No queue worker runs.** With `QUEUE_CONNECTION=sync`, a job runs during the request that dispatches it. Your
|
|
320
|
+
scheduled tasks run through Vercel Cron (see [Scheduled tasks](#scheduled-tasks)).
|
|
315
321
|
- **Inertia pages render in the browser**, as they do when no SSR server answers: the SSR server doesn't run on
|
|
316
322
|
Vercel. `INERTIA_SSR_ENABLED=false` skips asking it.
|
|
317
323
|
|
|
@@ -331,7 +337,28 @@ Route.get('/pricing', () => view('pricing'))
|
|
|
331
337
|
|
|
332
338
|
`cache.headers` leaves a response that sets a cookie alone, so that the CDN never hands one visitor's cookies to the
|
|
333
339
|
next. The `web` group's `StartSession` and `VerifyCsrfToken` set cookies on every page: take them off the pages you
|
|
334
|
-
cache, as above. Those pages have no session, so they can't show who is signed in.
|
|
340
|
+
cache, as above. Those pages have no session, so they can't show who is signed in. Their Live components still work:
|
|
341
|
+
they get a session with their first update (see [Pages cached without a session](live.md#pages-cached-without-a-session)).
|
|
342
|
+
|
|
343
|
+
### Scheduled tasks
|
|
344
|
+
|
|
345
|
+
No `schedule:work` runs on Vercel, so Vercel Cron calls your app's scheduler instead. When your app schedules any task,
|
|
346
|
+
`vercel:build` adds a cron that calls `/_oriel/schedule`, daily at 03:00 UTC. Add a `CRON_SECRET` to the project's
|
|
347
|
+
environment variables (a long random string): Vercel sends it with every call, and without it the route answers 404,
|
|
348
|
+
so nobody else can run your tasks.
|
|
349
|
+
|
|
350
|
+
Each call runs every task that fell due since the previous call, once, however often it fell due in between: a task
|
|
351
|
+
scheduled every five minutes runs once a day, and a task at 04:00 runs at the next morning's call. The first call after
|
|
352
|
+
a deploy, with no earlier call recorded, covers one full period of the cron back, as every later call does: for a daily
|
|
353
|
+
cron, from the day before's run time. So a task due just before you deploy still runs. `vercel:build` names
|
|
354
|
+
the tasks due more often than the cron. Vercel's Hobby plan runs a cron at most once a day, sometime within the hour
|
|
355
|
+
you chose; a paid plan can call more often:
|
|
356
|
+
|
|
357
|
+
```sh
|
|
358
|
+
node oriel vercel:build --cron="*/10 * * * *"
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
`--cron=false` writes no cron.
|
|
335
362
|
|
|
336
363
|
## Debug mode
|
|
337
364
|
|
package/docs/encryption.md
CHANGED
|
@@ -15,6 +15,8 @@ The encrypter's key is `key` in `config/app.ts`, which reads `APP_KEY` from `.en
|
|
|
15
15
|
`node oriel key:generate` writes a new one: a random key for your cipher, written as `base64:` and its bytes (see
|
|
16
16
|
[The application key](configuration.md#the-application-key)).
|
|
17
17
|
|
|
18
|
+
A page that reads and writes no cookies works without a key, such as a page cached [without a session](live.md#pages-cached-without-a-session). A cookie that needs decrypting then reads as absent, and writing an encrypted cookie throws `MissingAppKeyError`.
|
|
19
|
+
|
|
18
20
|
`cipher` in `config/app.ts` names the cipher, `AES-256-GCM` in a new app. `AES-128-GCM`, `AES-256-CBC` and `AES-128-CBC`
|
|
19
21
|
are the others, in upper or lower case. The key must have the length the cipher takes: 32 bytes for AES-256 and 16 for
|
|
20
22
|
AES-128.
|
package/docs/installation.md
CHANGED
|
@@ -171,7 +171,8 @@ come from the `.env` file at the root of your app, which the config files read w
|
|
|
171
171
|
|
|
172
172
|
### Databases and migrations
|
|
173
173
|
|
|
174
|
-
A new app uses SQLite, in `database/database.sqlite`, which the installer created and migrated.
|
|
174
|
+
A new app uses SQLite, in `database/database.sqlite`, which the installer created and migrated. On Node it uses the
|
|
175
|
+
`better-sqlite3` package, which a new app has in its dependencies; Bun has SQLite built in, so a Bun app doesn't. To use PostgreSQL or
|
|
175
176
|
MySQL instead, install its driver, `pg` or `mysql2`:
|
|
176
177
|
|
|
177
178
|
```sh
|
package/docs/live-tests.md
CHANGED
|
@@ -189,6 +189,26 @@ component.assertRedirect('/posts').assertDispatched('post-created', { title: 'He
|
|
|
189
189
|
`assertRedirect()` with no URL passes on any redirect. `effects().redirectUsingNavigate` is `true` when the action
|
|
190
190
|
asked for `{ navigate: true }`.
|
|
191
191
|
|
|
192
|
+
## Testing cookies
|
|
193
|
+
|
|
194
|
+
A component sees the cookies you give the test, and `cookies()` shows what the last call queued, by name, with `null` for
|
|
195
|
+
one it deleted. Cookies it queues are sent on later requests in the test, as a browser would:
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
import { Live, Component } from '@orieljs/framework'
|
|
199
|
+
import { TestCase } from '@orieljs/framework/testing'
|
|
200
|
+
import { expect } from 'vitest'
|
|
201
|
+
declare const t: TestCase
|
|
202
|
+
declare const Theme: new () => Component
|
|
203
|
+
// ---cut---
|
|
204
|
+
t.withCookie('theme', 'dark')
|
|
205
|
+
|
|
206
|
+
const component = await Live.test(Theme)
|
|
207
|
+
await component.call('remember')
|
|
208
|
+
|
|
209
|
+
expect(component.cookies()).toEqual({ seen: '1' })
|
|
210
|
+
```
|
|
211
|
+
|
|
192
212
|
## Testing file uploads
|
|
193
213
|
|
|
194
214
|
In a `WithFileUploads` component, `set()` with a `FakeFile` uploads it as the browser would: through the upload rules,
|
package/docs/live.md
CHANGED
|
@@ -689,6 +689,26 @@ export default class PostCount extends Component {
|
|
|
689
689
|
`lazy={false}` turns `static lazy` off. Without `placeholder()`, the placeholder is the `live.lazy_placeholder` view,
|
|
690
690
|
or an empty `<div>`. Give the placeholder the same root element as `render()`.
|
|
691
691
|
|
|
692
|
+
## Pages cached without a session
|
|
693
|
+
|
|
694
|
+
A page that is the same for every visitor can be cached by a CDN (see
|
|
695
|
+
[Caching pages on the CDN](deployment.md#caching-pages-on-the-cdn)), and its Live components still work. Such a page
|
|
696
|
+
leaves `StartSession` and `VerifyCsrfToken` out, so it comes with no session and no `XSRF-TOKEN` cookie. Before its
|
|
697
|
+
first update, the client asks `/oriel/live/session` for both, once for the whole page, and then sends the update with
|
|
698
|
+
the token:
|
|
699
|
+
|
|
700
|
+
```ts title="routes/web.ts"
|
|
701
|
+
import { Route, StartSession, VerifyCsrfToken, view } from '@orieljs/framework'
|
|
702
|
+
|
|
703
|
+
Route.get('/docs/{page}', (page: string) => view('docs', { page }))
|
|
704
|
+
.middleware('cache.headers:public;s_maxage=86400;stale_while_revalidate=60')
|
|
705
|
+
.withoutMiddleware(StartSession, VerifyCsrfToken)
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
The cached HTML is the same for everyone, so render nothing there that belongs to one visitor: no name, no flashed
|
|
709
|
+
message, no CSRF field. A lazy component suits such a page: its placeholder is cached, and what it shows for this
|
|
710
|
+
visitor comes with its own load. `Live.start({ sessionUri })` moves the session route if you moved the update route.
|
|
711
|
+
|
|
692
712
|
## Pagination
|
|
693
713
|
|
|
694
714
|
`WithPagination` gives a component a page, which `paginate()` uses:
|
|
@@ -764,6 +784,8 @@ export default class ProfilePhoto extends WithFileUploads(Component) {
|
|
|
764
784
|
With `multiple`, the field is an array of files. A temporary file has the methods of an [uploaded
|
|
765
785
|
file](requests.md#files), such as `store()` and `storeAs()`, and `temporaryUrl()`, a signed link that previews an image,
|
|
766
786
|
audio or video.
|
|
787
|
+
`store()` moves the temporary file, so reset the property afterwards, as above: a second `store()`, or `temporaryUrl()`
|
|
788
|
+
after it, throws `UploadAlreadyStoredError`.
|
|
767
789
|
|
|
768
790
|
Temporary files go in `live-tmp` on your default disk, and [Storage](storage.md#live-uploads) explains how they are
|
|
769
791
|
cleaned up. `o:loading` shows while a file uploads, and these browser events follow it, on the input:
|
package/docs/navigation.json
CHANGED
package/docs/pagination.md
CHANGED
|
@@ -217,6 +217,16 @@ The page number is the component's `page`: its actions `nextPage`, `previousPage
|
|
|
217
217
|
move it. It isn't written to the address bar, so a reload shows page 1. `Pagination` takes `paginate()` and
|
|
218
218
|
`simplePaginate()` paginators, not cursor ones.
|
|
219
219
|
|
|
220
|
+
Its buttons have the starter kits' classes, `btn btn-secondary`, and `btn` on the current page. On a site with its own CSS,
|
|
221
|
+
give it yours, or `''` for none. Write them in your file, so Tailwind generates them. `class` is for the `<nav>` around them:
|
|
222
|
+
|
|
223
|
+
```tsx
|
|
224
|
+
import { Pagination, type PaginationSource } from '@orieljs/framework'
|
|
225
|
+
declare const posts: PaginationSource
|
|
226
|
+
// ---cut---
|
|
227
|
+
<Pagination paginator={posts} class="flex gap-2" buttonClass="pager" currentClass="pager is-current" />
|
|
228
|
+
```
|
|
229
|
+
|
|
220
230
|
## Converting results to JSON
|
|
221
231
|
|
|
222
232
|
A paginator returned from a route, or given to `JSON.stringify()`, becomes Laravel's JSON shape:
|
package/docs/routing.md
CHANGED
|
@@ -431,7 +431,7 @@ yourself. Until the first run, any name is accepted.
|
|
|
431
431
|
Your [Inertia](inertia.md#links-and-the-route-helper) pages build URLs with the same `route()`, from your adapter. It
|
|
432
432
|
takes the same names and parameters, and returns a path. The browser's route table leaves out the routes that
|
|
433
433
|
`types.except_routes` in `config/inertia.ts` names, with `*` as a wildcard. Unless you set it, it leaves out `live.*`,
|
|
434
|
-
Live's own routes.
|
|
434
|
+
Live's own routes, and `vercel.*`, the route Vercel Cron calls.
|
|
435
435
|
|
|
436
436
|
```tsx tab="React" title="resources/js/components/PostLink.tsx"
|
|
437
437
|
import { Link, route } from '@orieljs/inertia-react'
|
package/docs/scheduling.md
CHANGED
|
@@ -219,6 +219,9 @@ Add one cron entry to your server, which runs `schedule:run` every minute:
|
|
|
219
219
|
`schedule:run` runs each due task once, prints its name, and goes on to the next one when a task fails, after
|
|
220
220
|
printing the error. With nothing due, it prints "No scheduled commands are ready to run.".
|
|
221
221
|
|
|
222
|
+
On Vercel, which runs no cron of yours, Vercel Cron calls the scheduler instead (see
|
|
223
|
+
[Scheduled tasks on Vercel](deployment.md#scheduled-tasks)).
|
|
224
|
+
|
|
222
225
|
### Sub-minute tasks
|
|
223
226
|
|
|
224
227
|
A task that runs every few seconds, such as `everyTenSeconds()`, is due every minute. Its `schedule:run` runs it
|
package/docs/session.md
CHANGED
|
@@ -79,8 +79,25 @@ await Schema.create('sessions', (t) => {
|
|
|
79
79
|
})
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
Each row also records the signed-in user's id
|
|
83
|
-
|
|
82
|
+
Each row also records the signed-in user's id. `connection` names the database connection to use, the default one when
|
|
83
|
+
it is `null`, and `table` the table.
|
|
84
|
+
|
|
85
|
+
The `ip_address` and `user_agent` columns stay empty unless you turn on `client_details`, in `config/session.ts`:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { env } from '@orieljs/framework'
|
|
89
|
+
|
|
90
|
+
export default {
|
|
91
|
+
client_details: env('SESSION_CLIENT_DETAILS', false),
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The columns are there either way, so turning it on needs no migration. Turning it off clears a session's values the next
|
|
96
|
+
time that session is written.
|
|
97
|
+
|
|
98
|
+
> [!NOTE]
|
|
99
|
+
> Laravel stores both on every write. Oriel doesn't by default, because Live on a cached page gives anonymous readers a
|
|
100
|
+
> session, and storing them would keep every reader's address.
|
|
84
101
|
|
|
85
102
|
#### Redis
|
|
86
103
|
|
package/docs/starter-kits.md
CHANGED
|
@@ -12,6 +12,10 @@ need. There is nothing to keep in sync with the kit afterwards.
|
|
|
12
12
|
The kits sign users in with Oriel's own authentication, without a separate package such as Laravel's Fortify: the
|
|
13
13
|
controllers, or the Live components, are in your app.
|
|
14
14
|
|
|
15
|
+
A new password ends the user's other sessions, while the session that changed it stays signed in: the kits add the
|
|
16
|
+
[`auth.session` middleware](authentication.md#invalidating-sessions-on-other-devices) to the `web` group. An app made before
|
|
17
|
+
alpha.14 adds it with one line in `bootstrap/app.ts`, and nobody is signed out by doing so.
|
|
18
|
+
|
|
15
19
|
## Creating an application using a starter kit
|
|
16
20
|
|
|
17
21
|
The installer asks which kit you want, or takes it as an option (see
|