@dudousxd/nestjs-catalog-dashboard 0.2.3 → 0.3.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.
@@ -0,0 +1,63 @@
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
+ * No UI here on purpose: you own the button, the page and the copy. This module owns the two things
10
+ * a host would otherwise have to rediscover — where the session endpoint actually lives, and how to
11
+ * call it without the failure mode below.
12
+ */
13
+ /**
14
+ * Where `POST` mints the console session cookie.
15
+ *
16
+ * Derived from `basePath` rather than hardcoded by the caller: this package owns the route (the
17
+ * auth controller is mounted relative to `basePath` by `RouterModule`), so a host that hardcodes it
18
+ * is guessing at something that can change under a version bump — with no compile error when it
19
+ * does, because the break only shows up as a 404 at runtime.
20
+ */
21
+ export declare function catalogConsoleSessionUrl(basePath?: string): string;
22
+ /** Where the console SPA itself is served. */
23
+ export declare function catalogConsoleUrl(basePath?: string): string;
24
+ export interface OpenConsoleOptions {
25
+ /** Where the console is mounted. MUST match `DurableDashboardModule.forRoot({ basePath })`. */
26
+ basePath?: string;
27
+ /**
28
+ * Headers for the mint request — in practice your app's `Authorization` header. A function (sync
29
+ * or async) is accepted so a token can be read at call time rather than captured at wiring time,
30
+ * which is what a refreshing token needs.
31
+ */
32
+ headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
33
+ /** Injected for tests and non-browser callers. Defaults to the global `fetch`. */
34
+ fetch?: typeof globalThis.fetch;
35
+ signal?: AbortSignal;
36
+ /**
37
+ * Performs the navigation after a successful mint. Defaults to `location.assign`. Override to
38
+ * route through your own router, or to open in a new tab.
39
+ */
40
+ navigate?: (url: string) => void;
41
+ }
42
+ /** Thrown when the session could not be minted. Never thrown after a successful mint. */
43
+ export declare class ConsoleSessionError extends Error {
44
+ readonly url: string;
45
+ /** The HTTP status, or `undefined` when the request never produced one (network error). */
46
+ readonly status?: number | undefined;
47
+ constructor(message: string, url: string,
48
+ /** The HTTP status, or `undefined` when the request never produced one (network error). */
49
+ status?: number | undefined);
50
+ }
51
+ /**
52
+ * Mint the console session cookie. Resolves on success; throws {@link ConsoleSessionError} on
53
+ * refusal. Use this directly when you want to mint without navigating (a pre-flight check, or a
54
+ * link the user opens later).
55
+ */
56
+ export declare function mintCatalogConsoleSession(options?: OpenConsoleOptions): Promise<void>;
57
+ /**
58
+ * Mint the session, then navigate to the console. Throws without navigating when the mint is
59
+ * refused, so a denied user gets a real error instead of landing on the console's
60
+ * "no session" page — which reads as a bug rather than a permission decision.
61
+ */
62
+ export declare function openCatalogConsole(options?: OpenConsoleOptions): Promise<void>;
63
+ //# 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;;;;;;;;;;;GAWG;AAWH;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,GAAE,MAA0B,GAAG,MAAM,CAErF;AAED,8CAA8C;AAC9C,wBAAgB,iBAAiB,CAAC,QAAQ,GAAE,MAA0B,GAAG,MAAM,CAE9E;AAED,MAAM,WAAW,kBAAkB;IACjC,+FAA+F;IAC/F,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,yBAAyB,CAAC,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkD/F;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAKxF"}
@@ -0,0 +1,107 @@
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
+ * No UI here on purpose: you own the button, the page and the copy. This module owns the two things
10
+ * a host would otherwise have to rediscover — where the session endpoint actually lives, and how to
11
+ * call it without the failure mode below.
12
+ */
13
+ /** The mount default; matches `DurableDashboardModule.forRoot()`'s own `basePath` default. */
14
+ const DEFAULT_BASE_PATH = '/catalog';
15
+ function normalizeBasePath(basePath) {
16
+ const trimmed = basePath.trim().replace(/\/+$/, '');
17
+ if (trimmed === '')
18
+ return '';
19
+ return trimmed.startsWith('/') ? trimmed : `/${trimmed}`;
20
+ }
21
+ /**
22
+ * Where `POST` mints the console session cookie.
23
+ *
24
+ * Derived from `basePath` rather than hardcoded by the caller: this package owns the route (the
25
+ * auth controller is mounted relative to `basePath` by `RouterModule`), so a host that hardcodes it
26
+ * is guessing at something that can change under a version bump — with no compile error when it
27
+ * does, because the break only shows up as a 404 at runtime.
28
+ */
29
+ export function catalogConsoleSessionUrl(basePath = DEFAULT_BASE_PATH) {
30
+ return `${normalizeBasePath(basePath)}/session`;
31
+ }
32
+ /** Where the console SPA itself is served. */
33
+ export function catalogConsoleUrl(basePath = DEFAULT_BASE_PATH) {
34
+ return normalizeBasePath(basePath) || '/';
35
+ }
36
+ /** Thrown when the session could not be minted. Never thrown after a successful mint. */
37
+ export class ConsoleSessionError extends Error {
38
+ url;
39
+ status;
40
+ constructor(message, url,
41
+ /** The HTTP status, or `undefined` when the request never produced one (network error). */
42
+ status) {
43
+ super(message);
44
+ this.url = url;
45
+ this.status = status;
46
+ this.name = 'ConsoleSessionError';
47
+ }
48
+ }
49
+ async function resolveHeaders(headers) {
50
+ if (headers === undefined)
51
+ return {};
52
+ return typeof headers === 'function' ? await headers() : headers;
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 async function mintCatalogConsoleSession(options = {}) {
60
+ const url = catalogConsoleSessionUrl(options.basePath);
61
+ const doFetch = options.fetch ?? globalThis.fetch;
62
+ if (typeof doFetch !== 'function') {
63
+ throw new ConsoleSessionError('No `fetch` available; pass one via `options.fetch`.', url);
64
+ }
65
+ let response;
66
+ try {
67
+ response = await doFetch(url, {
68
+ method: 'POST',
69
+ // The whole point: the response's Set-Cookie must stick, and the cookie must ride the
70
+ // navigation that follows.
71
+ credentials: 'include',
72
+ headers: await resolveHeaders(options.headers),
73
+ // Load-bearing, and the reason this helper exists rather than three lines at the call site.
74
+ // `fetch` FOLLOWS redirects by default, so an app whose auth layer rewrites a 401 into a
75
+ // "go to /signin" redirect makes this request resolve 200 against the sign-in HTML —
76
+ // `response.ok` reads true, the caller navigates, and the user lands in a console with no
77
+ // session, which looks exactly like a permissions bug. Handling the redirect explicitly turns
78
+ // that into a clear error instead of a silent false success.
79
+ redirect: 'manual',
80
+ ...(options.signal ? { signal: options.signal } : {}),
81
+ });
82
+ }
83
+ catch (cause) {
84
+ throw new ConsoleSessionError(`Could not reach the console session endpoint at ${url}: ${String(cause)}`, url);
85
+ }
86
+ // `redirect: 'manual'` surfaces differently per runtime: browsers give an opaque response
87
+ // (`type: 'opaqueredirect'`, status 0), Node/undici gives the real 3xx. Both mean the same thing.
88
+ const redirected = response.type === 'opaqueredirect' || (response.status >= 300 && response.status < 400);
89
+ if (redirected) {
90
+ 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);
91
+ }
92
+ if (!response.ok) {
93
+ throw new ConsoleSessionError(`The console refused to open (HTTP ${response.status}).`, url, response.status);
94
+ }
95
+ }
96
+ /**
97
+ * Mint the session, then navigate to the console. Throws without navigating when the mint is
98
+ * refused, so a denied user gets a real error instead of landing on the console's
99
+ * "no session" page — which reads as a bug rather than a permission decision.
100
+ */
101
+ export async function openCatalogConsole(options = {}) {
102
+ await mintCatalogConsoleSession(options);
103
+ const target = catalogConsoleUrl(options.basePath);
104
+ const navigate = options.navigate ?? ((url) => globalThis.location?.assign(url));
105
+ navigate(target);
106
+ }
107
+ //# sourceMappingURL=console-session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console-session.js","sourceRoot":"","sources":["../../src/client/console-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,8FAA8F;AAC9F,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAErC,SAAS,iBAAiB,CAAC,QAAgB;IACzC,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACpD,IAAI,OAAO,KAAK,EAAE;QAAE,OAAO,EAAE,CAAC;IAC9B,OAAO,OAAO,CAAC,UAAU,CAAC,G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OAAO,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACzF,QAAQ,CAAC,MAAM,CAAC,CAAC;AACnB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './use-open-console.js';
2
+ export * from './open-console-button.js';
3
+ export * from '../client/console-session.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AASA,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AAEzC,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,14 @@
1
+ // The React tier of `@dudousxd/nestjs-catalog-dashboard`, published at the `./react` subpath so a
2
+ // host that only mounts the NestJS module never pulls React in. Three levels, pick one:
3
+ //
4
+ // openCatalogConsole(...) — no React at all (`./client`), you own everything
5
+ // useOpenCatalogConsole(...) — state for a launcher UI, you own the markup
6
+ // <OpenCatalogConsoleButton /> — drop-in, unstyled, forwards every button prop
7
+ //
8
+ // `openCatalogConsoleMutationOptions` wires the same call into TanStack Query without this package
9
+ // depending on TanStack.
10
+ export * from './use-open-console.js';
11
+ export * from './open-console-button.js';
12
+ // Re-exported so a React consumer needs one import path, not two.
13
+ export * from '../client/console-session.js';
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,wFAAwF;AACxF,EAAE;AACF,sFAAsF;AACtF,iFAAiF;AACjF,mFAAmF;AACnF,EAAE;AACF,mGAAmG;AACnG,yBAAyB;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,kEAAkE;AAClE,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { ButtonHTMLAttributes, ReactNode } from 'react';
2
+ import type { OpenConsoleOptions } from '../client/console-session.js';
3
+ export interface OpenCatalogConsoleButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'children'>, OpenConsoleOptions {
4
+ /** Button label. Defaults to "Open Catalog". */
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 useOpenCatalogConsole}.
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. When it doesn't fit, drop to {@link useOpenCatalogConsole} (same behaviour,
20
+ * your markup) or to `openCatalogConsole` (no React at all).
21
+ *
22
+ * The error is rendered by default rather than swallowed: a refused mint is the case a launcher most
23
+ * needs to surface, and a button that silently does nothing reads as broken rather than forbidden.
24
+ */
25
+ export declare function OpenCatalogConsoleButton({ children, pendingLabel, renderError, basePath, headers, fetch: fetchImpl, signal, navigate, disabled, ...buttonProps }: OpenCatalogConsoleButtonProps): import("react/jsx-runtime").JSX.Element;
26
+ //# 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,6BACf,SAAQ,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC,EAC3E,kBAAkB;IACpB,gDAAgD;IAChD,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;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,OAAO,EACP,KAAK,EAAE,SAAS,EAChB,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,GAAG,WAAW,EACf,EAAE,6BAA6B,2CAyB/B"}
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useOpenCatalogConsole } 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. When it doesn't fit, drop to {@link useOpenCatalogConsole} (same behaviour,
9
+ * your markup) or to `openCatalogConsole` (no React at all).
10
+ *
11
+ * The error is rendered by default rather than swallowed: a refused mint is the case a launcher most
12
+ * needs to surface, and a button that silently does nothing reads as broken rather than forbidden.
13
+ */
14
+ export function OpenCatalogConsoleButton({ children, pendingLabel, renderError, basePath, headers, fetch: fetchImpl, signal, navigate, disabled, ...buttonProps }) {
15
+ const { open, isPending, error } = useOpenCatalogConsole({
16
+ ...(basePath !== undefined ? { basePath } : {}),
17
+ ...(headers !== undefined ? { headers } : {}),
18
+ ...(fetchImpl !== undefined ? { fetch: fetchImpl } : {}),
19
+ ...(signal !== undefined ? { signal } : {}),
20
+ ...(navigate !== undefined ? { navigate } : {}),
21
+ });
22
+ return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", ...buttonProps, onClick: open, disabled: disabled || isPending, "aria-busy": isPending || undefined, children: isPending ? (pendingLabel ?? 'Opening…') : (children ?? 'Open Catalog') }), error &&
23
+ renderError !== null &&
24
+ (renderError?.(error) ?? _jsx("p", { role: "alert", children: error.message }))] }));
25
+ }
26
+ //# 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,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAgB9D;;;;;;;;;;GAUG;AACH,MAAM,UAAU,wBAAwB,CAAC,EACvC,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,OAAO,EACP,KAAK,EAAE,SAAS,EAChB,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,GAAG,WAAW,EACgB;IAC9B,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,qBAAqB,CAAC;QACvD,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,cAAc,CAAC,GACjE,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 `openCatalogConsole` — the middle tier between the bare function
4
+ * (`../client/console-session.ts`) and the drop-in `<OpenCatalogConsoleButton>`.
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 Catalog-specific beyond the endpoint: it is a mint-then-navigate call with
8
+ * 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 useOpenCatalogConsole(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(openCatalogConsoleMutationOptions({ headers }));
28
+ * ```
29
+ */
30
+ export declare function openCatalogConsoleMutationOptions(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,EAExB,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,qBAAqB,CAAC,OAAO,GAAE,kBAAuB,GAAG,oBAAoB,CAsD5F;AAED;;;;;;;;GAQG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,GAAE,kBAAuB,GAAG;IACnF,WAAW,EAAE,SAAS,OAAO,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC,CAKA"}
@@ -0,0 +1,68 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { ConsoleSessionError, openCatalogConsole, } from '../client/console-session.js';
3
+ export function useOpenCatalogConsole(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 openCatalogConsole(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
+ // The page leaving is not the same as the page dying — see the `pageshow` effect below,
20
+ // which is what un-sticks this flag when the user comes back.
21
+ })
22
+ .catch((cause) => {
23
+ setError(cause instanceof ConsoleSessionError
24
+ ? cause
25
+ : new ConsoleSessionError(String(cause), 'unknown'));
26
+ setIsPending(false);
27
+ });
28
+ }, []);
29
+ // The counterpart to leaving `isPending` set on success. That choice assumes the launcher page is
30
+ // discarded once the navigation completes — but with the browser's back/forward cache it is not:
31
+ // pressing Back restores this page from memory with React state intact, so the user lands back on
32
+ // a spinner that never stops, on a button `disabled` by that very flag. This is the one signal
33
+ // that says "you are looking at a restored page": browsers fire `pageshow` with
34
+ // `persisted === true` only on a bfcache restore.
35
+ //
36
+ // Guard on `persisted` rather than on `pageshow` alone. A plain `pageshow` also fires on every
37
+ // ordinary load, and clearing the flag there would resurrect the flicker this hook exists to
38
+ // avoid — a mint that is genuinely still in flight (the user never left) must keep its spinner.
39
+ useEffect(() => {
40
+ // No `window` under SSR — and nothing to restore there either.
41
+ if (typeof window === 'undefined')
42
+ return;
43
+ const onPageShow = (event) => {
44
+ if (event.persisted)
45
+ setIsPending(false);
46
+ };
47
+ window.addEventListener('pageshow', onPageShow);
48
+ return () => window.removeEventListener('pageshow', onPageShow);
49
+ }, []);
50
+ const reset = useCallback(() => setError(null), []);
51
+ return { open, isPending, error, reset };
52
+ }
53
+ /**
54
+ * TanStack Query integration WITHOUT a TanStack dependency: the returned object is the shape
55
+ * `useMutation` takes, so a host that already uses Query wires the launcher into its own cache,
56
+ * devtools and error handling with no extra adapter — and a host that doesn't never pays for it.
57
+ *
58
+ * ```ts
59
+ * const { mutate, isPending } = useMutation(openCatalogConsoleMutationOptions({ headers }));
60
+ * ```
61
+ */
62
+ export function openCatalogConsoleMutationOptions(options = {}) {
63
+ return {
64
+ mutationKey: ['catalog', 'console', 'open', options.basePath ?? null],
65
+ mutationFn: () => openCatalogConsole(options),
66
+ };
67
+ }
68
+ //# 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,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EACL,mBAAmB,EAEnB,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AAqBtC,MAAM,UAAU,qBAAqB,CAAC,UAA8B,EAAE;IACpE,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,kBAAkB,CAAC,UAAU,CAAC,OAAO,CAAC;aACxC,IAAI,CAAC,GAAG,EAAE;YACT,2FAA2F;YAC3F,2FAA2F;YAC3F,yEAAyE;YACzE,EAAE;YACF,wFAAwF;YACxF,8DAA8D;QAChE,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YACxB,QAAQ,CACN,KAAK,YAAY,mBAAmB;gBAClC,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,IAAI,mBAAmB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,CACtD,CAAC;YACF,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC,CAAC,CAAC;IACP,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,kGAAkG;IAClG,iGAAiG;IACjG,kGAAkG;IAClG,+FAA+F;IAC/F,gFAAgF;IAChF,kDAAkD;IAClD,EAAE;IACF,+FAA+F;IAC/F,6FAA6F;IAC7F,gGAAgG;IAChG,SAAS,CAAC,GAAG,EAAE;QACb,+DAA+D;QAC/D,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO;QAC1C,MAAM,UAAU,GAAG,CAAC,KAAY,EAAE,EAAE;YAClC,IAAK,KAA6B,CAAC,SAAS;gBAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QACpE,CAAC,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QAChD,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAClE,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,iCAAiC,CAAC,UAA8B,EAAE;IAIhF,OAAO;QACL,WAAW,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAU;QAC9E,UAAU,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,OAAO,CAAC;KAC9C,CAAC;AACJ,CAAC"}
@@ -684,10 +684,12 @@ var CatalogUiController = class {
684
684
  }
685
685
  basePath;
686
686
  apiBasePath;
687
+ auth;
687
688
  dir = spaDir();
688
- constructor(basePath, apiBasePath) {
689
+ constructor(basePath, apiBasePath, auth = null) {
689
690
  this.basePath = basePath;
690
691
  this.apiBasePath = apiBasePath;
692
+ this.auth = auth;
691
693
  }
692
694
  // index.html references hash-named bundles, so it MUST NOT be cached (stale bundle = the
693
695
  // classic "stuck loading after a deploy"). The hashed assets below are immutable.
@@ -697,7 +699,8 @@ var CatalogUiController = class {
697
699
  throw new import_common3.NotFoundException("Dashboard is not built. Run the package build.");
698
700
  }
699
701
  const html = (0, import_node_fs.readFileSync)(indexPath, "utf8").replaceAll(`="${BUILD_BASE}/`, `="${this.basePath}/`);
700
- const inject = `<script>window.__DURABLE_BASE__='${this.basePath}';window.__DURABLE_API__='${this.apiBasePath}';</script>`;
702
+ const hostAuth = this.auth ? "true" : "false";
703
+ const inject = `<script>window.__CATALOG_BASE__='${this.basePath}';window.__CATALOG_API__='${this.apiBasePath}';window.__CATALOG_HOST_AUTH__=${hostAuth};</script>`;
701
704
  return html.includes("</head>") ? html.replace("</head>", `${inject}</head>`) : inject + html;
702
705
  }
703
706
  asset(file) {
@@ -737,10 +740,13 @@ CatalogUiController = _ts_decorate3([
737
740
  (0, import_common3.Controller)(),
738
741
  _ts_param2(0, (0, import_common3.Inject)(DASHBOARD_BASE_PATH)),
739
742
  _ts_param2(1, (0, import_common3.Inject)(DASHBOARD_API_PATH)),
743
+ _ts_param2(2, (0, import_common3.Optional)()),
744
+ _ts_param2(2, (0, import_common3.Inject)(DASHBOARD_AUTH)),
740
745
  _ts_metadata2("design:type", Function),
741
746
  _ts_metadata2("design:paramtypes", [
742
747
  String,
743
- String
748
+ String,
749
+ Object
744
750
  ])
745
751
  ], CatalogUiController);
746
752