adonisjs-server-stats 1.14.1 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -1
- package/dist/core/debug/types.d.ts +14 -0
- package/dist/core/types.d.ts +140 -4
- package/dist/src/dashboard/dashboard_controller.d.ts +7 -0
- package/dist/src/dashboard/dashboard_controller.js +10 -3
- package/dist/src/debug/debug_store.d.ts +15 -1
- package/dist/src/debug/debug_store.js +32 -4
- package/dist/src/debug/types.d.ts +14 -0
- package/dist/src/define_config.js +49 -1
- package/dist/src/middleware/request_tracking_middleware.d.ts +2 -1
- package/dist/src/middleware/request_tracking_middleware.js +16 -1
- package/dist/src/provider/boot_helpers.d.ts +19 -1
- package/dist/src/provider/boot_helpers.js +51 -2
- package/dist/src/provider/dashboard_init.js +5 -1
- package/dist/src/provider/dashboard_setup.d.ts +10 -1
- package/dist/src/provider/dashboard_setup.js +47 -2
- package/dist/src/provider/server_stats_provider.d.ts +7 -0
- package/dist/src/provider/server_stats_provider.js +26 -8
- package/dist/src/provider/toolbar_setup.js +5 -1
- package/dist/src/routes/access_middleware.d.ts +7 -1
- package/dist/src/routes/access_middleware.js +6 -1
- package/dist/src/routes/dashboard_routes.d.ts +1 -0
- package/dist/src/routes/dashboard_routes.js +5 -3
- package/dist/src/routes/debug_routes.d.ts +1 -0
- package/dist/src/routes/debug_routes.js +5 -3
- package/dist/src/routes/register_routes.d.ts +18 -3
- package/dist/src/routes/register_routes.js +24 -2
- package/dist/src/routes/router_types.d.ts +15 -5
- package/dist/src/routes/stats_routes.d.ts +10 -1
- package/dist/src/routes/stats_routes.js +9 -2
- package/dist/src/stubs/config.stub +8 -0
- package/dist/src/types.d.ts +140 -4
- package/package.json +1 -1
package/dist/src/types.d.ts
CHANGED
|
@@ -435,6 +435,94 @@ export interface DashboardConfig {
|
|
|
435
435
|
*/
|
|
436
436
|
retentionDays?: number;
|
|
437
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* Access-control callback signature.
|
|
440
|
+
*
|
|
441
|
+
* May be sync or async — the route guard awaits it. An async guard is the usual
|
|
442
|
+
* shape once the check has to consult `ctx.auth` or the database.
|
|
443
|
+
*
|
|
444
|
+
* One caveat: the `@serverStats()` Edge tag evaluates the guard synchronously
|
|
445
|
+
* while rendering the template, so with an **async** guard the toolbar hides
|
|
446
|
+
* itself rather than risk showing when it shouldn't. The HTTP routes await it
|
|
447
|
+
* properly either way — only the cosmetic bar is affected.
|
|
448
|
+
*/
|
|
449
|
+
export type AccessGuard = (ctx: import('@adonisjs/core/http').HttpContext) => boolean | Promise<boolean>;
|
|
450
|
+
/**
|
|
451
|
+
* Which capture subsystems are active.
|
|
452
|
+
*
|
|
453
|
+
* Each one hooks a global: queries and events subscribe to the Lucid/app
|
|
454
|
+
* emitter, emails subscribe to the mail events, traces wrap every request in
|
|
455
|
+
* `AsyncLocalStorage`. Turning one off means its collector is never subscribed,
|
|
456
|
+
* so it costs nothing — its dashboard pane simply stays empty.
|
|
457
|
+
*
|
|
458
|
+
* Outside production every field defaults to `true`. In production every field
|
|
459
|
+
* defaults to **`false`** and must be opted into individually.
|
|
460
|
+
*/
|
|
461
|
+
export interface CaptureConfig {
|
|
462
|
+
/** SQL text, bindings, and timings for every query. */
|
|
463
|
+
queries?: boolean;
|
|
464
|
+
/** Application events (in-memory only — never persisted to SQLite). */
|
|
465
|
+
events?: boolean;
|
|
466
|
+
/** Sent mail, including subject and body. */
|
|
467
|
+
emails?: boolean;
|
|
468
|
+
/** Per-request spans and the request timeline. */
|
|
469
|
+
traces?: boolean;
|
|
470
|
+
/** Log lines written into the dashboard's SQLite store. */
|
|
471
|
+
logs?: boolean;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Opt in to running the dashboard in production.
|
|
475
|
+
*
|
|
476
|
+
* By default this package registers **no routes** when `NODE_ENV=production`
|
|
477
|
+
* and never builds the debug or dashboard stores. Setting `enabled: true` lifts
|
|
478
|
+
* that, but only with an {@link ServerStatsConfig.authorize} guard in place —
|
|
479
|
+
* `unsafeAllowNoAuth` is ignored in production.
|
|
480
|
+
*
|
|
481
|
+
* Data capture stays **off** unless you ask for it. Without any `capture`
|
|
482
|
+
* flags you still get the request list, the overview, and the charts (those
|
|
483
|
+
* come from request rows and 1-minute metric buckets), at a small fraction of
|
|
484
|
+
* the write volume of a full dev-mode capture.
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
487
|
+
* ```ts
|
|
488
|
+
* export default defineConfig({
|
|
489
|
+
* authorize: async (ctx) => (await ctx.auth.check()) && ctx.auth.user?.isAdmin === true,
|
|
490
|
+
* dashboard: true,
|
|
491
|
+
* production: {
|
|
492
|
+
* enabled: true,
|
|
493
|
+
* capture: { queries: true },
|
|
494
|
+
* retentionDays: 3,
|
|
495
|
+
* },
|
|
496
|
+
* })
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
499
|
+
export interface ProductionConfig {
|
|
500
|
+
/**
|
|
501
|
+
* Register routes and build the dashboard when `NODE_ENV=production`.
|
|
502
|
+
*
|
|
503
|
+
* Requires an `authorize` guard — without one the routes are still not
|
|
504
|
+
* registered, and a warning explains why.
|
|
505
|
+
*
|
|
506
|
+
* @default false
|
|
507
|
+
*/
|
|
508
|
+
enabled?: boolean;
|
|
509
|
+
/**
|
|
510
|
+
* Which capture subsystems to switch on. Every field defaults to `false` in
|
|
511
|
+
* production, so capture is opt-in one subsystem at a time.
|
|
512
|
+
*
|
|
513
|
+
* @see {@link CaptureConfig}
|
|
514
|
+
*/
|
|
515
|
+
capture?: CaptureConfig;
|
|
516
|
+
/**
|
|
517
|
+
* How many days of history to keep in SQLite, overriding the usual default
|
|
518
|
+
* of 7. Retention deletes rows hourly but never runs `VACUUM`, so the
|
|
519
|
+
* database file reuses pages rather than shrinking — watch actual size via
|
|
520
|
+
* the dashboard's storage panel.
|
|
521
|
+
*
|
|
522
|
+
* @default 3
|
|
523
|
+
*/
|
|
524
|
+
retentionDays?: number;
|
|
525
|
+
}
|
|
438
526
|
/**
|
|
439
527
|
* Advanced options that most users never need to touch.
|
|
440
528
|
*
|
|
@@ -699,7 +787,7 @@ export interface ServerStatsConfig {
|
|
|
699
787
|
*
|
|
700
788
|
* @deprecated Use {@link authorize} instead. Will be removed in the next major version.
|
|
701
789
|
*/
|
|
702
|
-
shouldShow?:
|
|
790
|
+
shouldShow?: AccessGuard;
|
|
703
791
|
/**
|
|
704
792
|
* How often (in **milliseconds**) to run all collectors and
|
|
705
793
|
* broadcast updated stats.
|
|
@@ -750,7 +838,7 @@ export interface ServerStatsConfig {
|
|
|
750
838
|
* authorize: () => process.env.NODE_ENV === 'development'
|
|
751
839
|
* ```
|
|
752
840
|
*/
|
|
753
|
-
authorize?:
|
|
841
|
+
authorize?: AccessGuard;
|
|
754
842
|
/**
|
|
755
843
|
* Register the sensitive dashboard/debug/stats routes WITHOUT any access
|
|
756
844
|
* guard when no {@link authorize} callback is provided.
|
|
@@ -804,6 +892,50 @@ export interface ServerStatsConfig {
|
|
|
804
892
|
* ```
|
|
805
893
|
*/
|
|
806
894
|
dashboard?: boolean | DashboardConfig;
|
|
895
|
+
/**
|
|
896
|
+
* Restrict all server-stats routes to a specific domain or subdomain.
|
|
897
|
+
*
|
|
898
|
+
* When set, routes are only matched when the request's `Host` header
|
|
899
|
+
* matches the given domain. Useful when admin routes live on a
|
|
900
|
+
* dedicated subdomain (e.g. `admin.example.com`).
|
|
901
|
+
*
|
|
902
|
+
* Supports dynamic subdomains using `:param` syntax
|
|
903
|
+
* (e.g. `':tenant.example.com'`).
|
|
904
|
+
*
|
|
905
|
+
* Pass a bare host — a protocol, path, or port (`'https://admin.example.com'`,
|
|
906
|
+
* `'admin.example.com:3333'`) yields routes that match nothing.
|
|
907
|
+
*
|
|
908
|
+
* Note that the `@serverStats()` toolbar and the React/Vue components request
|
|
909
|
+
* relative URLs, so they only work on pages served from this domain.
|
|
910
|
+
*
|
|
911
|
+
* @example
|
|
912
|
+
* ```ts
|
|
913
|
+
* // Fixed subdomain
|
|
914
|
+
* domain: 'admin.example.com'
|
|
915
|
+
* ```
|
|
916
|
+
*
|
|
917
|
+
* @example
|
|
918
|
+
* ```ts
|
|
919
|
+
* // Dynamic subdomain
|
|
920
|
+
* domain: ':tenant.example.com'
|
|
921
|
+
* ```
|
|
922
|
+
*/
|
|
923
|
+
domain?: string;
|
|
924
|
+
/**
|
|
925
|
+
* Opt in to running in production, where this package otherwise registers
|
|
926
|
+
* nothing at all.
|
|
927
|
+
*
|
|
928
|
+
* Requires an {@link authorize} guard, and leaves data capture off unless you
|
|
929
|
+
* enable it per subsystem.
|
|
930
|
+
*
|
|
931
|
+
* @see {@link ProductionConfig}
|
|
932
|
+
*
|
|
933
|
+
* @example
|
|
934
|
+
* ```ts
|
|
935
|
+
* production: { enabled: true, capture: { queries: true } }
|
|
936
|
+
* ```
|
|
937
|
+
*/
|
|
938
|
+
production?: ProductionConfig;
|
|
807
939
|
/**
|
|
808
940
|
* Advanced options for fine-tuning internal behavior.
|
|
809
941
|
*
|
|
@@ -849,7 +981,7 @@ export interface ResolvedServerStatsConfig {
|
|
|
849
981
|
/** Optional dev toolbar configuration. */
|
|
850
982
|
devToolbar?: DevToolbarOptions;
|
|
851
983
|
/** Optional access-control callback. */
|
|
852
|
-
shouldShow?:
|
|
984
|
+
shouldShow?: AccessGuard;
|
|
853
985
|
/** Collection interval in milliseconds (new name for {@link intervalMs}). */
|
|
854
986
|
pollInterval?: number;
|
|
855
987
|
/** Whether real-time (SSE) broadcasting is enabled (new name for {@link transport}). */
|
|
@@ -857,7 +989,7 @@ export interface ResolvedServerStatsConfig {
|
|
|
857
989
|
/** HTTP endpoint path or `false` to disable (new name for {@link endpoint}). */
|
|
858
990
|
statsEndpoint?: string | false;
|
|
859
991
|
/** Access-control callback (new name for {@link shouldShow}). */
|
|
860
|
-
authorize?:
|
|
992
|
+
authorize?: AccessGuard;
|
|
861
993
|
/**
|
|
862
994
|
* Escape hatch to register sensitive routes without an access guard.
|
|
863
995
|
* Exposes the dashboard without auth — local development only.
|
|
@@ -871,4 +1003,8 @@ export interface ResolvedServerStatsConfig {
|
|
|
871
1003
|
advanced?: AdvancedConfig;
|
|
872
1004
|
/** Whether verbose informational logging is enabled. Always present after `defineConfig()`. */
|
|
873
1005
|
verbose: boolean;
|
|
1006
|
+
/** Optional domain restriction for all routes. */
|
|
1007
|
+
domain?: string;
|
|
1008
|
+
/** Opt-in production behavior. Absent means this package is inert in production. */
|
|
1009
|
+
production?: ProductionConfig;
|
|
874
1010
|
}
|