@dudousxd/nestjs-media-dashboard 0.11.0 → 0.12.1

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,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;AAGzC,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,15 @@
1
+ // The React tier of `@dudousxd/nestjs-media-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
+ // openMediaConsole(...) — no React at all (`./client`), you own everything
5
+ // useOpenMediaConsole(...) — state for a launcher UI, you own the markup
6
+ // <OpenMediaConsoleButton /> — drop-in, unstyled, forwards every button prop
7
+ //
8
+ // `openMediaConsoleMutationOptions` 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. Only the console-launcher
13
+ // primitives: `./client` also exports the console's own data client, which a launcher never needs.
14
+ export * from '../client/console-session.js';
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,wFAAwF;AACxF,EAAE;AACF,oFAAoF;AACpF,+EAA+E;AAC/E,iFAAiF;AACjF,EAAE;AACF,iGAAiG;AACjG,yBAAyB;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,4FAA4F;AAC5F,mGAAmG;AACnG,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 OpenMediaConsoleButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'children'>, OpenConsoleOptions {
4
+ /** Button label. Defaults to "Open Media console". */
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 useOpenMediaConsole}.
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 useOpenMediaConsole} (same behaviour,
20
+ * your markup) or to `openMediaConsole` (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 OpenMediaConsoleButton({ children, pendingLabel, renderError, basePath, apiBasePath, headers, fetch: fetchImpl, signal, navigate, disabled, ...buttonProps }: OpenMediaConsoleButtonProps): 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,2BACf,SAAQ,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC,EAC3E,kBAAkB;IACpB,sDAAsD;IACtD,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,sBAAsB,CAAC,EACrC,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,WAAW,EACX,OAAO,EACP,KAAK,EAAE,SAAS,EAChB,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,GAAG,WAAW,EACf,EAAE,2BAA2B,2CA4B7B"}
@@ -0,0 +1,29 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useOpenMediaConsole } 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 useOpenMediaConsole} (same behaviour,
9
+ * your markup) or to `openMediaConsole` (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 OpenMediaConsoleButton({ children, pendingLabel, renderError, basePath, apiBasePath, headers, fetch: fetchImpl, signal, navigate, disabled, ...buttonProps }) {
15
+ // Spread conditionally rather than passing `undefined`: `exactOptionalPropertyTypes` is on, and
16
+ // an explicit `undefined` is not the same as an absent key to the option defaulting downstream.
17
+ const { open, isPending, error } = useOpenMediaConsole({
18
+ ...(basePath !== undefined ? { basePath } : {}),
19
+ ...(apiBasePath !== undefined ? { apiBasePath } : {}),
20
+ ...(headers !== undefined ? { headers } : {}),
21
+ ...(fetchImpl !== undefined ? { fetch: fetchImpl } : {}),
22
+ ...(signal !== undefined ? { signal } : {}),
23
+ ...(navigate !== undefined ? { navigate } : {}),
24
+ });
25
+ return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", ...buttonProps, onClick: open, disabled: disabled || isPending, "aria-busy": isPending || undefined, children: isPending ? (pendingLabel ?? 'Opening…') : (children ?? 'Open Media console') }), error &&
26
+ renderError !== null &&
27
+ (renderError?.(error) ?? _jsx("p", { role: "alert", children: error.message }))] }));
28
+ }
29
+ //# 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,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAgB5D;;;;;;;;;;GAUG;AACH,MAAM,UAAU,sBAAsB,CAAC,EACrC,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,WAAW,EACX,OAAO,EACP,KAAK,EAAE,SAAS,EAChB,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,GAAG,WAAW,EACc;IAC5B,gGAAgG;IAChG,gGAAgG;IAChG,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,mBAAmB,CAAC;QACrD,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/C,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,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,oBAAoB,CAAC,GACvE,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,41 @@
1
+ import { type OpenConsoleOptions } from '../client/console-session.js';
2
+ /**
3
+ * React layer over `openMediaConsole` — the middle tier between the bare function
4
+ * (`../client/console-session.ts`) and the drop-in `<OpenMediaConsoleButton>`.
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 Media-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
+ /**
16
+ * The last refusal, or `null`. Cleared when `open()` is called again.
17
+ *
18
+ * Typed as `Error` rather than `ConsoleSessionError` because `ConsoleSessionError` carries the
19
+ * session endpoint it was refused by, and a failure that did not come from the mint (a `navigate`
20
+ * override that throws) has no endpoint to attribute — inventing one would be a lie. Every
21
+ * refusal from the mint itself IS a `ConsoleSessionError`, so `instanceof` narrows.
22
+ */
23
+ error: Error | null;
24
+ /** Drop a stale error without retrying — e.g. when a dialog closes. */
25
+ reset: () => void;
26
+ }
27
+ export declare function useOpenMediaConsole(options?: OpenConsoleOptions): UseOpenConsoleResult;
28
+ /**
29
+ * TanStack Query integration WITHOUT a TanStack dependency: the returned object is the shape
30
+ * `useMutation` takes, so a host that already uses Query wires the launcher into its own cache,
31
+ * devtools and error handling with no extra adapter — and a host that doesn't never pays for it.
32
+ *
33
+ * ```ts
34
+ * const { mutate, isPending } = useMutation(openMediaConsoleMutationOptions({ headers }));
35
+ * ```
36
+ */
37
+ export declare function openMediaConsoleMutationOptions(options?: OpenConsoleOptions): {
38
+ mutationKey: readonly unknown[];
39
+ mutationFn: () => Promise<void>;
40
+ };
41
+ //# 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,EAAE,KAAK,kBAAkB,EAAoB,MAAM,8BAA8B,CAAC;AAEzF;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,0EAA0E;IAC1E,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,0EAA0E;IAC1E,SAAS,EAAE,OAAO,CAAC;IACnB;;;;;;;OAOG;IACH,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,uEAAuE;IACvE,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,kBAAuB,GAAG,oBAAoB,CA2B1F;AAED;;;;;;;;GAQG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,GAAE,kBAAuB,GAAG;IACjF,WAAW,EAAE,SAAS,OAAO,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC,CAeA"}
@@ -0,0 +1,52 @@
1
+ import { useCallback, useRef, useState } from 'react';
2
+ import { openMediaConsole } from '../client/console-session.js';
3
+ export function useOpenMediaConsole(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 openMediaConsole(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 Error ? cause : new Error(String(cause)));
21
+ setIsPending(false);
22
+ });
23
+ }, []);
24
+ const reset = useCallback(() => setError(null), []);
25
+ return { open, isPending, error, reset };
26
+ }
27
+ /**
28
+ * TanStack Query integration WITHOUT a TanStack dependency: the returned object is the shape
29
+ * `useMutation` takes, so a host that already uses Query wires the launcher into its own cache,
30
+ * devtools and error handling with no extra adapter — and a host that doesn't never pays for it.
31
+ *
32
+ * ```ts
33
+ * const { mutate, isPending } = useMutation(openMediaConsoleMutationOptions({ headers }));
34
+ * ```
35
+ */
36
+ export function openMediaConsoleMutationOptions(options = {}) {
37
+ return {
38
+ // Both mounts points are in the key: `apiBasePath` decides which endpoint mints the session and
39
+ // is settable independently of `basePath` (flip mounts the console API under its own `/api`
40
+ // prefix), so two mounts differing only in it are two different calls and must not share cache
41
+ // state.
42
+ mutationKey: [
43
+ 'media',
44
+ 'console',
45
+ 'open',
46
+ options.basePath ?? null,
47
+ options.apiBasePath ?? null,
48
+ ],
49
+ mutationFn: () => openMediaConsole(options),
50
+ };
51
+ }
52
+ //# sourceMappingURL=use-open-console.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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,CAAC;AAC3C,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,+BAA+B,CAAC,UAA8B,EAAE;IAI9E,OAAO;QACL,gGAAgG;QAChG,4FAA4F;QAC5F,+FAA+F;QAC/F,SAAS;QACT,WAAW,EAAE;YACX,OAAO;YACP,SAAS;YACT,MAAM;YACN,OAAO,CAAC,QAAQ,IAAI,IAAI;YACxB,OAAO,CAAC,WAAW,IAAI,IAAI;SACnB;QACV,UAAU,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC;KAC5C,CAAC;AACJ,CAAC"}
@@ -1730,7 +1730,17 @@ var MediaDashboardModule = class _MediaDashboardModule {
1730
1730
  ...imports ?? [],
1731
1731
  MediaConsoleApiModule.register({
1732
1732
  actions,
1733
- cookiePath: apiBasePath,
1733
+ // `Path=/`, deliberately NOT scoped to `apiBasePath` (nor to `basePath`): the two mounts
1734
+ // are independently configurable and can live at unrelated paths (e.g. a `/media` UI
1735
+ // with a `/api/media/console` API). Scoped to the API base, the browser withheld the
1736
+ // cookie on the full-page navigation to `basePath`, so the freshly minted session could
1737
+ // not open the console it was minted for — the launcher landed on the unauthenticated
1738
+ // page. Scoping to `basePath` instead would just move the failure to the API calls.
1739
+ // The cookie is HttpOnly + signed + short-lived, so the broader scope is a reasonable
1740
+ // trade for being correct in any mount configuration. Matches nestjs-durable-dashboard
1741
+ // and nestjs-agent-dashboard; telescope can scope to its mount because its UI and API
1742
+ // always share one root.
1743
+ cookiePath: "/",
1734
1744
  authProvider,
1735
1745
  imports,
1736
1746
  ...options.guards ? {