@dudousxd/nestjs-telescope-ui 2.0.1 → 3.0.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.
@@ -4,8 +4,8 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Telescope</title>
7
- <script type="module" crossorigin src="/telescope/assets/index-BPSlup7m.js"></script>
8
- <link rel="stylesheet" crossorigin href="/telescope/assets/index-DmsmJrlA.css">
7
+ <script type="module" crossorigin src="/telescope/assets/index-EBJiTdQF.js"></script>
8
+ <link rel="stylesheet" crossorigin href="/telescope/assets/index-BfyQ_2IN.css">
9
9
  </head>
10
10
  <body>
11
11
  <div id="root"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-telescope-ui",
3
- "version": "2.0.1",
3
+ "version": "3.0.0",
4
4
  "description": "Bundled dashboard + composable React components for @dudousxd/nestjs-telescope.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -62,7 +62,7 @@
62
62
  "react-router-dom": "^6.0.0 || ^7.0.0",
63
63
  "recharts": "^2.0.0 || ^3.0.0",
64
64
  "reflect-metadata": "^0.1.13 || ^0.2.0",
65
- "@dudousxd/nestjs-telescope": "^2.0.1"
65
+ "@dudousxd/nestjs-telescope": "^3.0.0"
66
66
  },
67
67
  "peerDependenciesMeta": {
68
68
  "react": {
@@ -122,7 +122,7 @@
122
122
  "typescript": "5.9.3",
123
123
  "vite": "5.4.21",
124
124
  "vitest": "3.2.7",
125
- "@dudousxd/nestjs-telescope": "2.0.1"
125
+ "@dudousxd/nestjs-telescope": "3.0.0"
126
126
  },
127
127
  "engines": {
128
128
  "node": ">=20"
@@ -3,12 +3,11 @@ name: telescope-ui-dashboard
3
3
  description: >-
4
4
  Serve and embed the nestjs-telescope dashboard with @dudousxd/nestjs-telescope-ui.
5
5
  Mount the bundled React SPA via TelescopeUiModule.forRoot({ path?, assetsDir?,
6
- decorators?, routes? }) / forRootAsync (the path is static in the async form,
7
- as are decorators and routes; the path must match TelescopeModule); with
8
- NODE_ENV=production mounting the page with no decorators fails the boot
9
- (routes:false always boots).
6
+ authorize?, decorators?, routes? }) / forRootAsync (the path is static in the
7
+ async form, as are decorators and routes; the path must match
8
+ TelescopeModule); without authorize the page answers 403 in production.
10
9
  call the headless API from any frontend with createTelescopeClient({ baseUrl?,
11
- fetch? }) from the /client subpath; build a custom console with the React
10
+ fetch?, onAccessDenied? }) from the /client subpath; build a custom console with the React
12
11
  components, hooks (TelescopeProvider, useTelescopeClient, useEntries, usePulse,
13
12
  useTimeseries) from the /react subpath. Use for "show the Telescope dashboard",
14
13
  "custom path", "call the Telescope API from React", "embed Telescope components".
@@ -16,7 +15,7 @@ license: MIT
16
15
  metadata:
17
16
  type: core
18
17
  library: "@dudousxd/nestjs-telescope-ui"
19
- library_version: "1.12.0"
18
+ library_version: "3.0.0"
20
19
  framework: nestjs
21
20
  ---
22
21
 
@@ -33,27 +32,31 @@ Import the UI module alongside the core module. The `path` must match
33
32
  `TelescopeModule` (default `telescope`):
34
33
 
35
34
  ```ts
36
- import { Module, UseGuards } from '@nestjs/common';
37
- import { AuthenticationGuard } from '@nestjs/authentication';
38
- import { Can } from '@nestjs/authorization';
35
+ import { type ExecutionContext, Module } from '@nestjs/common';
39
36
  import { TelescopeModule } from '@dudousxd/nestjs-telescope';
40
37
  import { TelescopeUiModule } from '@dudousxd/nestjs-telescope-ui';
41
38
 
42
- const protect = [UseGuards(AuthenticationGuard), Can(ConsolePolicy, 'view')];
39
+ const authorize = (ctx: ExecutionContext) =>
40
+ ctx.switchToHttp().getRequest().user?.isAdmin === true;
43
41
 
44
42
  @Module({
45
43
  imports: [
46
- TelescopeModule.forRoot({ enabled: true, decorators: protect }),
47
- TelescopeUiModule.forRoot({ decorators: protect }), // dashboard at /telescope
44
+ TelescopeModule.forRoot({ enabled: true, authorize }),
45
+ TelescopeUiModule.forRoot({ authorize }), // dashboard at /telescope
48
46
  ],
49
47
  })
50
48
  export class AppModule {}
51
49
  ```
52
50
 
53
- With `NODE_ENV=production`, mounting the page with no `decorators` (an empty
54
- array counts as none) fails the boot; `routes: false` always boots (serve the
55
- page from your own subclass of the exported `TelescopeUiController`). Outside
56
- production an undecorated page mounts open.
51
+ Without `authorize` the page is open outside production; with
52
+ `NODE_ENV=production` it answers 403 and the boot logs a warning. A denied
53
+ navigation gets an "Access denied" page (403), a "Sign in required" page (401),
54
+ or a 302 for `{ redirectTo }`; inside the SPA a 401 with `redirectTo` is
55
+ followed and a 403 shows an access-denied screen. `routes: false` mounts
56
+ nothing: serve the page from your own subclass of `TelescopeUiController` with
57
+ `@UseConsoleAuthorize()` listed ABOVE your auth guard (Nest applies class
58
+ decorators bottom-up, so the auth guard runs first). With no argument it runs
59
+ `TelescopeModule.forRoot({ authorize })`; `{ authorize }` overrides it.
57
60
 
58
61
  Source: `packages/ui/src/server/telescope-ui.module.ts`,
59
62
  `packages/ui/src/server/telescope-ui.options.ts` (`TelescopeUiModuleOptions`).
@@ -78,8 +81,8 @@ TelescopeUiModule.forRootAsync({
78
81
  });
79
82
  ```
80
83
 
81
- In production both modules still need `decorators` (or `routes: false`); the
82
- Setup section shows the protection.
84
+ In production both modules still need `authorize` (or `routes: false`); the
85
+ Setup section shows it.
83
86
 
84
87
  Source: `packages/ui/src/server/telescope-ui.module.ts`,
85
88
  `packages/ui/src/server/telescope-ui.options.ts`.
@@ -88,7 +91,9 @@ Source: `packages/ui/src/server/telescope-ui.module.ts`,
88
91
 
89
92
  `createTelescopeClient` (from the `/client` subpath) is a typed wrapper over the
90
93
  JSON API, usable in any frontend. `baseUrl` defaults to
91
- `window.__TELESCOPE_BASE__ + '/api'`, else `/telescope/api`.
94
+ `window.__TELESCOPE_BASE__ + '/api'`, else `/telescope/api`. `onAccessDenied`
95
+ runs when `authorize` refuses a call (default: follow `redirectTo`, else show
96
+ the access-denied screen).
92
97
 
93
98
  ```ts
94
99
  import { createTelescopeClient } from '@dudousxd/nestjs-telescope-ui/client';