@dudousxd/nestjs-telescope-ui 1.17.0 → 1.19.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/CHANGELOG.md +84 -0
- package/dist/client/console-session.d.ts +66 -0
- package/dist/client/console-session.d.ts.map +1 -0
- package/dist/client/console-session.js +110 -0
- package/dist/client/console-session.js.map +1 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +3 -0
- package/dist/client/index.js.map +1 -1
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +6 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/open-console-button.d.ts +28 -0
- package/dist/react/open-console-button.d.ts.map +1 -0
- package/dist/react/open-console-button.js +28 -0
- package/dist/react/open-console-button.js.map +1 -0
- package/dist/react/use-open-console.d.ts +34 -0
- package/dist/react/use-open-console.d.ts.map +1 -0
- package/dist/react/use-open-console.js +46 -0
- package/dist/react/use-open-console.js.map +1 -0
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,89 @@
|
|
|
1
1
|
# @dudousxd/nestjs-telescope-ui
|
|
2
2
|
|
|
3
|
+
## 1.19.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#65](https://github.com/DavideCarvalho/nestjs-telescope/pull/65) [`be97836`](https://github.com/DavideCarvalho/nestjs-telescope/commit/be978365f716cbe9e120b4024abb5d0ff6129d3d) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - **React tier for the console launcher: `useOpenTelescopeConsole` and `<OpenTelescopeConsoleButton>`, exported from `@dudousxd/nestjs-telescope-ui/react`.**
|
|
8
|
+
|
|
9
|
+
The headless `openTelescopeConsole` gave hosts the mint-then-navigate call; every host then wrote the
|
|
10
|
+
same three lines of React around it — an `isPending` flag, an error slot, and a button that has to
|
|
11
|
+
remember not to fire twice. Three tiers now, pick the one that fits and drop a level when it stops
|
|
12
|
+
fitting:
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import {
|
|
16
|
+
OpenTelescopeConsoleButton,
|
|
17
|
+
useOpenTelescopeConsole,
|
|
18
|
+
openTelescopeConsoleMutationOptions,
|
|
19
|
+
} from "@dudousxd/nestjs-telescope-ui/react";
|
|
20
|
+
|
|
21
|
+
// 1. drop-in
|
|
22
|
+
<OpenTelescopeConsoleButton
|
|
23
|
+
className="btn btn-primary"
|
|
24
|
+
headers={authHeaders}
|
|
25
|
+
/>;
|
|
26
|
+
|
|
27
|
+
// 2. state only, your markup
|
|
28
|
+
const { open, isPending, error, reset } = useOpenTelescopeConsole({
|
|
29
|
+
headers: authHeaders,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// 3. openTelescopeConsole(...) from `/client` — no React at all
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- `open()` **never rejects**; the refusal lands in `error` as a `ConsoleSessionError` (with its
|
|
36
|
+
`status` and `url`). It deliberately does not clear `isPending` on success, because the navigation
|
|
37
|
+
is already underway and flipping back to idle flickers "ready to click again" on a page that is
|
|
38
|
+
leaving.
|
|
39
|
+
- `<OpenTelescopeConsoleButton>` is **unstyled on purpose** — a bare `<button>` that forwards
|
|
40
|
+
`className`/`style`/every other button prop, so it inherits the host's design system instead of
|
|
41
|
+
importing CSS that fights it. It renders inside the host app, not inside Telescope's own bundle.
|
|
42
|
+
It disables itself and sets `aria-busy` while in flight, and renders the refusal as
|
|
43
|
+
`<p role="alert">` by default: a launcher that silently does nothing reads as broken rather than
|
|
44
|
+
forbidden. `renderError` substitutes that node; `renderError={null}` opts out entirely.
|
|
45
|
+
- `openTelescopeConsoleMutationOptions()` returns the `{ mutationKey, mutationFn }` shape
|
|
46
|
+
`useMutation` takes, so a host already on TanStack Query gets the launcher in its cache, devtools
|
|
47
|
+
and error handling with no adapter — and this package still never imports `@tanstack/react-query`.
|
|
48
|
+
|
|
49
|
+
React stays an optional peer dependency: a host that only mounts the NestJS module pulls none of
|
|
50
|
+
this in. Additive only; nothing existing changes.
|
|
51
|
+
|
|
52
|
+
## 1.18.0
|
|
53
|
+
|
|
54
|
+
### Minor Changes
|
|
55
|
+
|
|
56
|
+
- [#63](https://github.com/DavideCarvalho/nestjs-telescope/pull/63) [`2d0e76e`](https://github.com/DavideCarvalho/nestjs-telescope/commit/2d0e76ee52e3a556c24b567fdb4b9e6cef25c067) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - **Headless console launcher: `openTelescopeConsole` / `mintTelescopeConsoleSession` / `telescopeConsoleSessionUrl`, exported from `@dudousxd/nestjs-telescope-ui/client`.**
|
|
57
|
+
|
|
58
|
+
The console is entered from the HOST's app: a browser navigation to it carries no identity, so
|
|
59
|
+
something inside the host has to mint the Mode A session cookie first (an XHR that _does_ carry the
|
|
60
|
+
host's auth), then navigate. Every host was writing that by hand, which meant hardcoding two things
|
|
61
|
+
this package owns:
|
|
62
|
+
|
|
63
|
+
- **the session endpoint's path** — `<path>/api/auth/session`. Nothing tells a host when that moves; the break
|
|
64
|
+
only shows up as a runtime 404 after a version bump.
|
|
65
|
+
- **`redirect: 'manual'`** — and this one is a real trap. `fetch` follows redirects by default, so a
|
|
66
|
+
host whose auth layer rewrites a 401 into a sign-in redirect gets a resolved 200 against the
|
|
67
|
+
sign-in HTML. `response.ok` reads true, the caller navigates, and the user lands in a console with
|
|
68
|
+
no session — indistinguishable from a permissions bug. The helper detects the redirect (browser
|
|
69
|
+
opaque response _and_ Node/undici 3xx) and throws a message naming the likely cause.
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { openTelescopeConsole } from "@dudousxd/nestjs-telescope-ui/client";
|
|
73
|
+
|
|
74
|
+
await openTelescopeConsole({
|
|
75
|
+
headers: () => ({ Authorization: `Bearer ${token()}` }),
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
No UI: the host owns the button, the page and the copy. `headers` accepts a sync or async function
|
|
80
|
+
so a refreshing token is read at call time rather than captured at wiring time. `fetch` and
|
|
81
|
+
`navigate` are injectable (tests, routers, non-browser callers). A refused mint throws
|
|
82
|
+
`ConsoleSessionError` (carrying `status` and `url`) and **does not navigate** — a denied user gets a
|
|
83
|
+
real error instead of the console's "no session" page.
|
|
84
|
+
|
|
85
|
+
Additive only: nothing existing changes.
|
|
86
|
+
|
|
3
87
|
## 1.17.0
|
|
4
88
|
|
|
5
89
|
### Minor Changes
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless client for opening the console from YOUR app.
|
|
3
|
+
*
|
|
4
|
+
* The console SPA is served at a literal path and knows nothing about your app's auth, so a plain
|
|
5
|
+
* browser navigation to it carries no identity. Mode A closes that gap: an XHR from inside your app
|
|
6
|
+
* — which DOES carry your auth — posts to the console's session endpoint, the `session` hook
|
|
7
|
+
* decides, and the library answers with its own signed cookie. The navigation that follows rides it.
|
|
8
|
+
*
|
|
9
|
+
* Telescope's mount is configured as `path` (no leading slash, e.g. `'telescope'`); this accepts either
|
|
10
|
+
* form and normalizes it.
|
|
11
|
+
*
|
|
12
|
+
* No UI here on purpose: you own the button, the page and the copy. This module owns the two things
|
|
13
|
+
* a host would otherwise have to rediscover — where the session endpoint actually lives, and how to
|
|
14
|
+
* call it without the failure mode below.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Where `POST` mints the console session cookie.
|
|
18
|
+
*
|
|
19
|
+
* Derived from `basePath` rather than hardcoded by the caller: this package owns the route (the auth
|
|
20
|
+
* controller lives under the configured mount), so a host that hardcodes it
|
|
21
|
+
* is guessing at something that can change under a version bump — with no compile error when it
|
|
22
|
+
* does, because the break only shows up as a 404 at runtime.
|
|
23
|
+
*/
|
|
24
|
+
export declare function telescopeConsoleSessionUrl(basePath?: string): string;
|
|
25
|
+
/** Where the console SPA itself is served. */
|
|
26
|
+
export declare function telescopeConsoleUrl(basePath?: string): string;
|
|
27
|
+
export interface OpenConsoleOptions {
|
|
28
|
+
/** Where the console is mounted. MUST match `TelescopeUiModule.forRoot({ path }) / TelescopeModule.forRoot({ path })`. */
|
|
29
|
+
basePath?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Headers for the mint request — in practice your app's `Authorization` header. A function (sync
|
|
32
|
+
* or async) is accepted so a token can be read at call time rather than captured at wiring time,
|
|
33
|
+
* which is what a refreshing token needs.
|
|
34
|
+
*/
|
|
35
|
+
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
36
|
+
/** Injected for tests and non-browser callers. Defaults to the global `fetch`. */
|
|
37
|
+
fetch?: typeof globalThis.fetch;
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
/**
|
|
40
|
+
* Performs the navigation after a successful mint. Defaults to `location.assign`. Override to
|
|
41
|
+
* route through your own router, or to open in a new tab.
|
|
42
|
+
*/
|
|
43
|
+
navigate?: (url: string) => void;
|
|
44
|
+
}
|
|
45
|
+
/** Thrown when the session could not be minted. Never thrown after a successful mint. */
|
|
46
|
+
export declare class ConsoleSessionError extends Error {
|
|
47
|
+
readonly url: string;
|
|
48
|
+
/** The HTTP status, or `undefined` when the request never produced one (network error). */
|
|
49
|
+
readonly status?: number | undefined;
|
|
50
|
+
constructor(message: string, url: string,
|
|
51
|
+
/** The HTTP status, or `undefined` when the request never produced one (network error). */
|
|
52
|
+
status?: number | undefined);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Mint the console session cookie. Resolves on success; throws {@link ConsoleSessionError} on
|
|
56
|
+
* refusal. Use this directly when you want to mint without navigating (a pre-flight check, or a
|
|
57
|
+
* link the user opens later).
|
|
58
|
+
*/
|
|
59
|
+
export declare function mintTelescopeConsoleSession(options?: OpenConsoleOptions): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Mint the session, then navigate to the console. Throws without navigating when the mint is
|
|
62
|
+
* refused, so a denied user gets a real error instead of landing on the console's
|
|
63
|
+
* "no session" page — which reads as a bug rather than a permission decision.
|
|
64
|
+
*/
|
|
65
|
+
export declare function openTelescopeConsole(options?: OpenConsoleOptions): Promise<void>;
|
|
66
|
+
//# sourceMappingURL=console-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-session.d.ts","sourceRoot":"","sources":["../../src/client/console-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAWH;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,GAAE,MAA0B,GAAG,MAAM,CAEvF;AAED,8CAA8C;AAC9C,wBAAgB,mBAAmB,CAAC,QAAQ,GAAE,MAA0B,GAAG,MAAM,CAEhF;AAED,MAAM,WAAW,kBAAkB;IACjC,0HAA0H;IAC1H,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACnE,kFAAkF;IAClF,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AAED,yFAAyF;AACzF,qBAAa,mBAAoB,SAAQ,KAAK;IAG1C,QAAQ,CAAC,GAAG,EAAE,MAAM;IACpB,2FAA2F;IAC3F,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;gBAHxB,OAAO,EAAE,MAAM,EACN,GAAG,EAAE,MAAM;IACpB,2FAA2F;IAClF,MAAM,CAAC,EAAE,MAAM,YAAA;CAK3B;AAOD;;;;GAIG;AACH,wBAAsB,2BAA2B,CAAC,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkDjG;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAK1F"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless client for opening the console from YOUR app.
|
|
3
|
+
*
|
|
4
|
+
* The console SPA is served at a literal path and knows nothing about your app's auth, so a plain
|
|
5
|
+
* browser navigation to it carries no identity. Mode A closes that gap: an XHR from inside your app
|
|
6
|
+
* — which DOES carry your auth — posts to the console's session endpoint, the `session` hook
|
|
7
|
+
* decides, and the library answers with its own signed cookie. The navigation that follows rides it.
|
|
8
|
+
*
|
|
9
|
+
* Telescope's mount is configured as `path` (no leading slash, e.g. `'telescope'`); this accepts either
|
|
10
|
+
* form and normalizes it.
|
|
11
|
+
*
|
|
12
|
+
* No UI here on purpose: you own the button, the page and the copy. This module owns the two things
|
|
13
|
+
* a host would otherwise have to rediscover — where the session endpoint actually lives, and how to
|
|
14
|
+
* call it without the failure mode below.
|
|
15
|
+
*/
|
|
16
|
+
/** The mount default; matches `TelescopeUiModule.forRoot()`'s own default. */
|
|
17
|
+
const DEFAULT_BASE_PATH = '/telescope';
|
|
18
|
+
function normalizeBasePath(basePath) {
|
|
19
|
+
const trimmed = basePath.trim().replace(/\/+$/, '');
|
|
20
|
+
if (trimmed === '')
|
|
21
|
+
return '';
|
|
22
|
+
return trimmed.startsWith('/') ? trimmed : `/${trimmed}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Where `POST` mints the console session cookie.
|
|
26
|
+
*
|
|
27
|
+
* Derived from `basePath` rather than hardcoded by the caller: this package owns the route (the auth
|
|
28
|
+
* controller lives under the configured mount), so a host that hardcodes it
|
|
29
|
+
* is guessing at something that can change under a version bump — with no compile error when it
|
|
30
|
+
* does, because the break only shows up as a 404 at runtime.
|
|
31
|
+
*/
|
|
32
|
+
export function telescopeConsoleSessionUrl(basePath = DEFAULT_BASE_PATH) {
|
|
33
|
+
return `${normalizeBasePath(basePath)}/api/auth/session`;
|
|
34
|
+
}
|
|
35
|
+
/** Where the console SPA itself is served. */
|
|
36
|
+
export function telescopeConsoleUrl(basePath = DEFAULT_BASE_PATH) {
|
|
37
|
+
return normalizeBasePath(basePath) || '/';
|
|
38
|
+
}
|
|
39
|
+
/** Thrown when the session could not be minted. Never thrown after a successful mint. */
|
|
40
|
+
export class ConsoleSessionError extends Error {
|
|
41
|
+
url;
|
|
42
|
+
status;
|
|
43
|
+
constructor(message, url,
|
|
44
|
+
/** The HTTP status, or `undefined` when the request never produced one (network error). */
|
|
45
|
+
status) {
|
|
46
|
+
super(message);
|
|
47
|
+
this.url = url;
|
|
48
|
+
this.status = status;
|
|
49
|
+
this.name = 'ConsoleSessionError';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function resolveHeaders(headers) {
|
|
53
|
+
if (headers === undefined)
|
|
54
|
+
return {};
|
|
55
|
+
return typeof headers === 'function' ? await headers() : headers;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Mint the console session cookie. Resolves on success; throws {@link ConsoleSessionError} on
|
|
59
|
+
* refusal. Use this directly when you want to mint without navigating (a pre-flight check, or a
|
|
60
|
+
* link the user opens later).
|
|
61
|
+
*/
|
|
62
|
+
export async function mintTelescopeConsoleSession(options = {}) {
|
|
63
|
+
const url = telescopeConsoleSessionUrl(options.basePath);
|
|
64
|
+
const doFetch = options.fetch ?? globalThis.fetch;
|
|
65
|
+
if (typeof doFetch !== 'function') {
|
|
66
|
+
throw new ConsoleSessionError('No `fetch` available; pass one via `options.fetch`.', url);
|
|
67
|
+
}
|
|
68
|
+
let response;
|
|
69
|
+
try {
|
|
70
|
+
response = await doFetch(url, {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
// The whole point: the response's Set-Cookie must stick, and the cookie must ride the
|
|
73
|
+
// navigation that follows.
|
|
74
|
+
credentials: 'include',
|
|
75
|
+
headers: await resolveHeaders(options.headers),
|
|
76
|
+
// Load-bearing, and the reason this helper exists rather than three lines at the call site.
|
|
77
|
+
// `fetch` FOLLOWS redirects by default, so an app whose auth layer rewrites a 401 into a
|
|
78
|
+
// "go to /signin" redirect makes this request resolve 200 against the sign-in HTML —
|
|
79
|
+
// `response.ok` reads true, the caller navigates, and the user lands in a console with no
|
|
80
|
+
// session, which looks exactly like a permissions bug. Handling the redirect explicitly turns
|
|
81
|
+
// that into a clear error instead of a silent false success.
|
|
82
|
+
redirect: 'manual',
|
|
83
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
catch (cause) {
|
|
87
|
+
throw new ConsoleSessionError(`Could not reach the console session endpoint at ${url}: ${String(cause)}`, url);
|
|
88
|
+
}
|
|
89
|
+
// `redirect: 'manual'` surfaces differently per runtime: browsers give an opaque response
|
|
90
|
+
// (`type: 'opaqueredirect'`, status 0), Node/undici gives the real 3xx. Both mean the same thing.
|
|
91
|
+
const redirected = response.type === 'opaqueredirect' || (response.status >= 300 && response.status < 400);
|
|
92
|
+
if (redirected) {
|
|
93
|
+
throw new ConsoleSessionError(`The console session endpoint at ${url} answered with a redirect instead of minting a session. Something in front of it — usually an auth middleware or exception filter that rewrites 401s into a sign-in redirect — is intercepting the response. Exempt this path from that rewrite so the real status reaches this caller.`, url, response.status || undefined);
|
|
94
|
+
}
|
|
95
|
+
if (!response.ok) {
|
|
96
|
+
throw new ConsoleSessionError(`The console refused to open (HTTP ${response.status}).`, url, response.status);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Mint the session, then navigate to the console. Throws without navigating when the mint is
|
|
101
|
+
* refused, so a denied user gets a real error instead of landing on the console's
|
|
102
|
+
* "no session" page — which reads as a bug rather than a permission decision.
|
|
103
|
+
*/
|
|
104
|
+
export async function openTelescopeConsole(options = {}) {
|
|
105
|
+
await mintTelescopeConsoleSession(options);
|
|
106
|
+
const target = telescopeConsoleUrl(options.basePath);
|
|
107
|
+
const navigate = options.navigate ?? ((url) => globalThis.location?.assign(url));
|
|
108
|
+
navigate(target);
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=console-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-session.js","sourceRoot":"","sources":["../../src/client/console-session.ts"],"names":[],"mappings":"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"}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { ConsoleSessionError, telescopeConsoleSessionUrl, telescopeConsoleUrl, mintTelescopeConsoleSession, openTelescopeConsole, type OpenConsoleOptions, } from './console-session.js';
|
|
1
2
|
export { createTelescopeClient } from './telescope-client.js';
|
|
2
3
|
export type { BulkActionName, JobActionName, TelescopeClient, TelescopeClientOptions, } from './telescope-client.js';
|
|
3
4
|
export type * from './types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACnB,0BAA0B,EAC1B,mBAAmB,EACnB,2BAA2B,EAC3B,oBAAoB,EACpB,KAAK,kBAAkB,GACxB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,YAAY,EACV,cAAc,EACd,aAAa,EACb,eAAe,EACf,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,mBAAmB,YAAY,CAAC"}
|
package/dist/client/index.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
// Headless console-launcher primitives (path derivation + mint-then-navigate). Re-exported here
|
|
2
|
+
// because `./client` resolves to this file — see the package's `exports` map.
|
|
3
|
+
export { ConsoleSessionError, telescopeConsoleSessionUrl, telescopeConsoleUrl, mintTelescopeConsoleSession, openTelescopeConsole, } from './console-session.js';
|
|
1
4
|
export { createTelescopeClient } from './telescope-client.js';
|
|
2
5
|
//# sourceMappingURL=index.js.map
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,8EAA8E;AAC9E,OAAO,EACL,mBAAmB,EACnB,0BAA0B,EAC1B,mBAAmB,EACnB,2BAA2B,EAC3B,oBAAoB,GAErB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from './telescope-context.js';
|
|
2
2
|
export * from './use-telescope-queries.js';
|
|
3
3
|
export * from './use-telescope-stream.js';
|
|
4
|
+
export * from './use-open-console.js';
|
|
5
|
+
export * from './open-console-button.js';
|
|
4
6
|
export * from './components/entry-types.js';
|
|
5
7
|
export * from './components/entries-table.js';
|
|
6
8
|
export * from './components/user-tag.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAK1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qCAAqC,CAAC;AACpD,cAAc,wBAAwB,CAAC;AACvC,cAAc,qCAAqC,CAAC;AACpD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC"}
|
package/dist/react/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export * from './telescope-context.js';
|
|
2
2
|
export * from './use-telescope-queries.js';
|
|
3
3
|
export * from './use-telescope-stream.js';
|
|
4
|
+
// Console launcher, three tiers: `openTelescopeConsole` (no React, from `./client`),
|
|
5
|
+
// `useOpenTelescopeConsole` (state only, your markup), `<OpenTelescopeConsoleButton>` (drop-in).
|
|
6
|
+
// `openTelescopeConsoleMutationOptions` wires the same call into TanStack Query without this
|
|
7
|
+
// package depending on TanStack.
|
|
8
|
+
export * from './use-open-console.js';
|
|
9
|
+
export * from './open-console-button.js';
|
|
4
10
|
export * from './components/entry-types.js';
|
|
5
11
|
export * from './components/entries-table.js';
|
|
6
12
|
export * from './components/user-tag.js';
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qCAAqC,CAAC;AACpD,cAAc,wBAAwB,CAAC;AACvC,cAAc,qCAAqC,CAAC;AACpD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,qFAAqF;AACrF,iGAAiG;AACjG,6FAA6F;AAC7F,iCAAiC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qCAAqC,CAAC;AACpD,cAAc,wBAAwB,CAAC;AACvC,cAAc,qCAAqC,CAAC;AACpD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
import type { OpenConsoleOptions } from '../client/console-session.js';
|
|
3
|
+
export interface OpenTelescopeConsoleButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'children'>, OpenConsoleOptions {
|
|
4
|
+
/** Button label. Defaults to "Open Telescope". */
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
/** Shown while the session is being minted. Defaults to "Opening…". */
|
|
7
|
+
pendingLabel?: ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* Render the refusal yourself. Omit and the button renders a plain `<p role="alert">` under
|
|
10
|
+
* itself; pass `null` to render nothing and read the error from {@link useOpenTelescopeConsole}.
|
|
11
|
+
*/
|
|
12
|
+
renderError?: ((error: Error) => ReactNode) | null;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Drop-in launcher: the top tier, for a host that just wants a working button.
|
|
16
|
+
*
|
|
17
|
+
* Deliberately unstyled — it emits a bare `<button>` and forwards `className`/`style`/every other
|
|
18
|
+
* button prop, so it inherits whatever design system the host already has instead of importing CSS
|
|
19
|
+
* that would fight it. That matters more here than for the dashboard's own components: this one
|
|
20
|
+
* renders inside the HOST's app, not inside Telescope's Tailwind bundle. When it doesn't fit, drop
|
|
21
|
+
* to {@link useOpenTelescopeConsole} (same behaviour, your markup) or to `openTelescopeConsole` (no
|
|
22
|
+
* React at all).
|
|
23
|
+
*
|
|
24
|
+
* The error is rendered by default rather than swallowed: a refused mint is the case a launcher most
|
|
25
|
+
* needs to surface, and a button that silently does nothing reads as broken rather than forbidden.
|
|
26
|
+
*/
|
|
27
|
+
export declare function OpenTelescopeConsoleButton({ children, pendingLabel, renderError, basePath, headers, fetch: fetchImpl, signal, navigate, disabled, ...buttonProps }: OpenTelescopeConsoleButtonProps): JSX.Element;
|
|
28
|
+
//# sourceMappingURL=open-console-button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-console-button.d.ts","sourceRoot":"","sources":["../../src/react/open-console-button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGvE,MAAM,WAAW,+BACf,SAAQ,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC,EAC3E,kBAAkB;IACpB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,uEAAuE;IACvE,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC,GAAG,IAAI,CAAC;CACpD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,OAAO,EACP,KAAK,EAAE,SAAS,EAChB,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,GAAG,WAAW,EACf,EAAE,+BAA+B,GAAG,GAAG,CAAC,OAAO,CAyB/C"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useOpenTelescopeConsole } from './use-open-console.js';
|
|
3
|
+
/**
|
|
4
|
+
* Drop-in launcher: the top tier, for a host that just wants a working button.
|
|
5
|
+
*
|
|
6
|
+
* Deliberately unstyled — it emits a bare `<button>` and forwards `className`/`style`/every other
|
|
7
|
+
* button prop, so it inherits whatever design system the host already has instead of importing CSS
|
|
8
|
+
* that would fight it. That matters more here than for the dashboard's own components: this one
|
|
9
|
+
* renders inside the HOST's app, not inside Telescope's Tailwind bundle. When it doesn't fit, drop
|
|
10
|
+
* to {@link useOpenTelescopeConsole} (same behaviour, your markup) or to `openTelescopeConsole` (no
|
|
11
|
+
* React at all).
|
|
12
|
+
*
|
|
13
|
+
* The error is rendered by default rather than swallowed: a refused mint is the case a launcher most
|
|
14
|
+
* needs to surface, and a button that silently does nothing reads as broken rather than forbidden.
|
|
15
|
+
*/
|
|
16
|
+
export function OpenTelescopeConsoleButton({ children, pendingLabel, renderError, basePath, headers, fetch: fetchImpl, signal, navigate, disabled, ...buttonProps }) {
|
|
17
|
+
const { open, isPending, error } = useOpenTelescopeConsole({
|
|
18
|
+
...(basePath !== undefined ? { basePath } : {}),
|
|
19
|
+
...(headers !== undefined ? { headers } : {}),
|
|
20
|
+
...(fetchImpl !== undefined ? { fetch: fetchImpl } : {}),
|
|
21
|
+
...(signal !== undefined ? { signal } : {}),
|
|
22
|
+
...(navigate !== undefined ? { navigate } : {}),
|
|
23
|
+
});
|
|
24
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", ...buttonProps, onClick: open, disabled: disabled || isPending, "aria-busy": isPending || undefined, children: isPending ? (pendingLabel ?? 'Opening…') : (children ?? 'Open Telescope') }), error &&
|
|
25
|
+
renderError !== null &&
|
|
26
|
+
(renderError?.(error) ?? _jsx("p", { role: "alert", children: error.message }))] }));
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=open-console-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-console-button.js","sourceRoot":"","sources":["../../src/react/open-console-button.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAgBhE;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,0BAA0B,CAAC,EACzC,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,OAAO,EACP,KAAK,EAAE,SAAS,EAChB,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,GAAG,WAAW,EACkB;IAChC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,uBAAuB,CAAC;QACzD,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/C,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7C,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACxD,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChD,CAAC,CAAC;IAEH,OAAO,CACL,8BACE,iBACE,IAAI,EAAC,QAAQ,KACT,WAAW,EACf,OAAO,EAAE,IAAI,EACb,QAAQ,EAAE,QAAQ,IAAI,SAAS,eACpB,SAAS,IAAI,SAAS,YAEhC,SAAS,CAAC,CAAC,CAAC,CAAC,YAAY,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,gBAAgB,CAAC,GACnE,EACR,KAAK;gBACJ,WAAW,KAAK,IAAI;gBACpB,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,IAAI,YAAG,IAAI,EAAC,OAAO,YAAE,KAAK,CAAC,OAAO,GAAK,CAAC,IAC9D,CACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ConsoleSessionError, type OpenConsoleOptions } from '../client/console-session.js';
|
|
2
|
+
/**
|
|
3
|
+
* React layer over `openTelescopeConsole` — the middle tier between the bare function
|
|
4
|
+
* (`../client/console-session.ts`) and the drop-in `<OpenTelescopeConsoleButton>`.
|
|
5
|
+
*
|
|
6
|
+
* You get the state a launcher UI actually needs (in-flight, error) and keep full control of the
|
|
7
|
+
* markup. Nothing here is Telescope-specific beyond the endpoint: it is a mint-then-navigate call
|
|
8
|
+
* with the two states that call can be in.
|
|
9
|
+
*/
|
|
10
|
+
export interface UseOpenConsoleResult {
|
|
11
|
+
/** Start the mint-then-navigate. Never rejects — read `error` instead. */
|
|
12
|
+
open: () => void;
|
|
13
|
+
/** True from the click until the navigation starts, or until it fails. */
|
|
14
|
+
isPending: boolean;
|
|
15
|
+
/** The last refusal, or `null`. Cleared when `open()` is called again. */
|
|
16
|
+
error: ConsoleSessionError | null;
|
|
17
|
+
/** Drop a stale error without retrying — e.g. when a dialog closes. */
|
|
18
|
+
reset: () => void;
|
|
19
|
+
}
|
|
20
|
+
export declare function useOpenTelescopeConsole(options?: OpenConsoleOptions): UseOpenConsoleResult;
|
|
21
|
+
/**
|
|
22
|
+
* TanStack Query integration WITHOUT a TanStack dependency: the returned object is the shape
|
|
23
|
+
* `useMutation` takes, so a host that already uses Query wires the launcher into its own cache,
|
|
24
|
+
* devtools and error handling with no extra adapter — and a host that doesn't never pays for it.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* const { mutate, isPending } = useMutation(openTelescopeConsoleMutationOptions({ headers }));
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function openTelescopeConsoleMutationOptions(options?: OpenConsoleOptions): {
|
|
31
|
+
mutationKey: readonly unknown[];
|
|
32
|
+
mutationFn: () => Promise<void>;
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=use-open-console.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-open-console.d.ts","sourceRoot":"","sources":["../../src/react/use-open-console.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,KAAK,kBAAkB,EAGxB,MAAM,8BAA8B,CAAC;AAEtC;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,0EAA0E;IAC1E,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,0EAA0E;IAC1E,SAAS,EAAE,OAAO,CAAC;IACnB,0EAA0E;IAC1E,KAAK,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAClC,uEAAuE;IACvE,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,kBAAuB,GAAG,oBAAoB,CAoC9F;AAED;;;;;;;;GAQG;AACH,wBAAgB,mCAAmC,CAAC,OAAO,GAAE,kBAAuB,GAAG;IACrF,WAAW,EAAE,SAAS,OAAO,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC,CAKA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useCallback, useRef, useState } from 'react';
|
|
2
|
+
import { ConsoleSessionError, openTelescopeConsole, telescopeConsoleSessionUrl, } from '../client/console-session.js';
|
|
3
|
+
export function useOpenTelescopeConsole(options = {}) {
|
|
4
|
+
const [isPending, setIsPending] = useState(false);
|
|
5
|
+
const [error, setError] = useState(null);
|
|
6
|
+
// Kept in a ref so a caller passing an inline object literal (the common case) doesn't change the
|
|
7
|
+
// identity of `open` on every render, which would defeat memoizing anything downstream.
|
|
8
|
+
const optionsRef = useRef(options);
|
|
9
|
+
optionsRef.current = options;
|
|
10
|
+
const open = useCallback(() => {
|
|
11
|
+
setIsPending(true);
|
|
12
|
+
setError(null);
|
|
13
|
+
void openTelescopeConsole(optionsRef.current)
|
|
14
|
+
.then(() => {
|
|
15
|
+
// Deliberately NOT clearing `isPending` on success: the navigation is already underway and
|
|
16
|
+
// this component is about to be torn down. Flipping the button back to idle first produces
|
|
17
|
+
// a visible flicker of "ready to click again" on a page that is leaving.
|
|
18
|
+
})
|
|
19
|
+
.catch((cause) => {
|
|
20
|
+
setError(cause instanceof ConsoleSessionError
|
|
21
|
+
? cause
|
|
22
|
+
: // A non-`ConsoleSessionError` can only come from the caller's own `navigate`, so name
|
|
23
|
+
// the endpoint this hook was pointed at rather than leaving `url` empty.
|
|
24
|
+
new ConsoleSessionError(String(cause), telescopeConsoleSessionUrl(optionsRef.current.basePath)));
|
|
25
|
+
setIsPending(false);
|
|
26
|
+
});
|
|
27
|
+
}, []);
|
|
28
|
+
const reset = useCallback(() => setError(null), []);
|
|
29
|
+
return { open, isPending, error, reset };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* TanStack Query integration WITHOUT a TanStack dependency: the returned object is the shape
|
|
33
|
+
* `useMutation` takes, so a host that already uses Query wires the launcher into its own cache,
|
|
34
|
+
* devtools and error handling with no extra adapter — and a host that doesn't never pays for it.
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* const { mutate, isPending } = useMutation(openTelescopeConsoleMutationOptions({ headers }));
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function openTelescopeConsoleMutationOptions(options = {}) {
|
|
41
|
+
return {
|
|
42
|
+
mutationKey: ['telescope', 'console', 'open', options.basePath ?? null],
|
|
43
|
+
mutationFn: () => openTelescopeConsole(options),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=use-open-console.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-open-console.js","sourceRoot":"","sources":["../../src/react/use-open-console.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EACL,mBAAmB,EAEnB,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,8BAA8B,CAAC;AAqBtC,MAAM,UAAU,uBAAuB,CAAC,UAA8B,EAAE;IACtE,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAA6B,IAAI,CAAC,CAAC;IAErE,kGAAkG;IAClG,wFAAwF;IACxF,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IAE7B,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,EAAE;QAC5B,YAAY,CAAC,IAAI,CAAC,CAAC;QACnB,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,KAAK,oBAAoB,CAAC,UAAU,CAAC,OAAO,CAAC;aAC1C,IAAI,CAAC,GAAG,EAAE;YACT,2FAA2F;YAC3F,2FAA2F;YAC3F,yEAAyE;QAC3E,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YACxB,QAAQ,CACN,KAAK,YAAY,mBAAmB;gBAClC,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,sFAAsF;oBACtF,yEAAyE;oBACzE,IAAI,mBAAmB,CACrB,MAAM,CAAC,KAAK,CAAC,EACb,0BAA0B,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CACxD,CACN,CAAC;YACF,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC,CAAC,CAAC;IACP,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IAEpD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC3C,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,mCAAmC,CAAC,UAA8B,EAAE;IAIlF,OAAO;QACL,WAAW,EAAE,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAU;QAChF,UAAU,EAAE,GAAG,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC;KAChD,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudousxd/nestjs-telescope-ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"description": "Bundled dashboard + composable React components for @dudousxd/nestjs-telescope.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -42,6 +42,9 @@
|
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@nestjs/common": ">=11.0.0",
|
|
44
44
|
"@nestjs/core": ">=11.0.0",
|
|
45
|
+
"react": ">=18.0.0",
|
|
46
|
+
"react-dom": ">=18.0.0",
|
|
47
|
+
"@tanstack/react-query": ">=5.0.0",
|
|
45
48
|
"@dudousxd/nestjs-telescope": "^1.24.0"
|
|
46
49
|
},
|
|
47
50
|
"peerDependenciesMeta": {
|