@dudousxd/nestjs-durable-dashboard 0.54.0 → 0.55.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/dist/client/durable-client.d.ts +6 -1
- package/dist/client/durable-client.d.ts.map +1 -1
- package/dist/client/durable-client.js +9 -46
- package/dist/client/durable-client.js.map +1 -1
- package/dist/server/index.cjs +223 -1341
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +101 -388
- package/dist/server/index.d.ts +101 -388
- package/dist/server/index.js +208 -1320
- package/dist/server/index.js.map +1 -1
- package/dist/spa/assets/{bench-Dee6-QN_.js → bench-DCclNvcZ.js} +1 -1
- package/dist/spa/assets/index-B-wtX4GV.js +66 -0
- package/dist/spa/assets/{index-RjxbO7dU.js → index-ChjKRQZx.js} +1 -1
- package/dist/spa/assets/{preview-BscU9n0o.js → preview-CdsjvOrK.js} +1 -1
- package/dist/spa/bench.html +2 -2
- package/dist/spa/index.html +2 -2
- package/dist/spa/preview.html +2 -2
- package/package.json +5 -18
- package/dist/client/console-session.d.ts +0 -63
- package/dist/client/console-session.d.ts.map +0 -1
- package/dist/client/console-session.js +0 -107
- package/dist/client/console-session.js.map +0 -1
- package/dist/react/index.d.ts +0 -4
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react/index.js +0 -14
- package/dist/react/index.js.map +0 -1
- package/dist/react/open-console-button.d.ts +0 -26
- package/dist/react/open-console-button.d.ts.map +0 -1
- package/dist/react/open-console-button.js +0 -26
- package/dist/react/open-console-button.js.map +0 -1
- package/dist/react/use-open-console.d.ts +0 -40
- package/dist/react/use-open-console.d.ts.map +0 -1
- package/dist/react/use-open-console.js +0 -77
- package/dist/react/use-open-console.js.map +0 -1
- package/dist/spa/assets/index-VXNPW483.js +0 -66
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as t,c as r,j as e,r as s,Q as n,A as o}from"./index-
|
|
1
|
+
import{a as t,c as r,j as e,r as s,Q as n,A as o}from"./index-B-wtX4GV.js";const i=new t({defaultOptions:{queries:{refetchInterval:2e3,refetchOnWindowFocus:!1}}});r(document.getElementById("root")).render(e.jsx(s.StrictMode,{children:e.jsx(n,{client:i,children:e.jsx(o,{})})}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as b,c as x,j as u,r as I,Q as S,A as j,R as q}from"./index-
|
|
1
|
+
import{a as b,c as x,j as u,r as I,Q as S,A as j,R as q}from"./index-B-wtX4GV.js";const l=Date.parse("2026-07-29T09:14:00.000Z"),e=r=>new Date(l+r).toISOString(),h=[{id:"ord-9f2c1a4b",workflow:"checkout",workflowVersion:"4",status:"failed",namespace:"default",origin:"acme-storefront",createdAt:e(-62e4),updatedAt:e(-54e4),tags:["tier:pro","region:us-east"],searchAttributes:{amount:249,tier:"pro"},input:{orderId:"ord-9f2c1a4b",amount:249,currency:"USD"},error:{message:"charge declined: card_expired (stripe: card_error)"}},{id:"ord-77ab3012",workflow:"checkout",workflowVersion:"4",status:"completed",origin:"acme-storefront",createdAt:e(-18e5),updatedAt:e(-1744e3),tags:["tier:free"],input:{orderId:"ord-77ab3012",amount:19},output:{charged:!0}},{id:"inv-2b91ee70",workflow:"invoiceSettlement",workflowVersion:"2",status:"completed",createdAt:e(-21e5),updatedAt:e(-201e4),input:{invoice:"INV-4471"}},{id:"shp-01d4f7c9",workflow:"shipmentSync",workflowVersion:"1",status:"running",origin:"@dudousxd/nestjs-catalog-pipeline",createdAt:e(-9e4),updatedAt:e(-4e3),input:{carrier:"dhl"}},{id:"shp-55c2aa18",workflow:"shipmentSync",workflowVersion:"1",status:"completed",origin:"@dudousxd/nestjs-catalog-pipeline",createdAt:e(-34e5),updatedAt:e(-333e4),input:{carrier:"ups"}},{id:"rep-8812cd44",workflow:"nightlyReport",workflowVersion:"7",status:"suspended",namespace:"acme",origin:"@dudousxd/nestjs-agent",createdAt:e(-54e5),updatedAt:e(-3e5),waiting:{on:"signal",name:"approve"},input:{day:"2026-07-28"}},{id:"ord-1177fe22",workflow:"checkout",workflowVersion:"4",status:"completed",namespace:"acme",origin:"acme-storefront",createdAt:e(-72e5),updatedAt:e(-712e4),tags:["tier:pro"],input:{orderId:"ord-1177fe22",amount:640},output:{charged:!0}},{id:"bck-4410aa03",workflow:"backfillLedger",workflowVersion:"1",status:"cancelled",createdAt:e(-9e6),updatedAt:e(-888e4),input:{from:"2026-01-01"}},{id:"ord-6650bb91",workflow:"checkout",workflowVersion:"4",status:"pending",origin:"acme-storefront",createdAt:e(-12e3),updatedAt:e(-12e3),input:{orderId:"ord-6650bb91",amount:78}}],M=[{runId:"ord-9f2c1a4b",seq:1,name:"reserveInventory",kind:"remote",status:"completed",attempts:1,workerGroup:"inventory",enqueuedAt:e(-619e3),startedAt:e(-618200),finishedAt:e(-615900),input:{sku:"SKU-8823",qty:1},output:{reservationId:"rsv-77120"}},{runId:"ord-9f2c1a4b",seq:2,name:"quoteShipping",kind:"remote",status:"completed",attempts:1,workerGroup:"shipping",enqueuedAt:e(-615800),startedAt:e(-615100),finishedAt:e(-612400),output:{carrier:"dhl",cents:890}},{runId:"ord-9f2c1a4b",seq:3,name:"chargeCard",kind:"remote",status:"failed",attempts:3,workerGroup:"payments",enqueuedAt:e(-612300),startedAt:e(-611800),finishedAt:e(-54e4),input:{amount:249,currency:"USD"},error:{message:"charge declined: card_expired (stripe: card_error)"},events:[{at:l-611700,level:"info",message:"attempt 1 → gateway timeout, retrying"},{at:l-59e4,level:"warn",message:"attempt 2 → gateway timeout, retrying"},{at:l-540200,level:"error",message:"attempt 3 → card_expired, giving up"}]}],R=[{runId:"shp-01d4f7c9",seq:1,name:"fetchManifest",kind:"remote",status:"completed",attempts:1,workerGroup:"shipping",enqueuedAt:e(-89e3),startedAt:e(-88400),finishedAt:e(-84100),output:{parcels:42}},{runId:"shp-01d4f7c9",seq:2,name:"syncCarrier",kind:"remote",status:"pending",attempts:1,workerGroup:"shipping",enqueuedAt:e(-84e3),startedAt:e(-83600),finishedAt:e(-4e3),input:{carrier:"dhl",parcels:42}}],_={"shp-01d4f7c9":{run:h[3],timeline:R,children:[]},"ord-9f2c1a4b":{run:h[0],timeline:M,children:[]}},C=[{group:"checkout",kind:"workflow",depth:0,liveWorkers:[{group:"checkout",instanceId:"api-7f9c4d-2",lastBeatAt:l-2e3,status:{runtime:"node",concurrency:{mode:"adaptive",limit:16,min:4,max:32},inFlight:3,rssPct:41,cpuPct:22,throughputPerMin:118,p95Ms:740,lastAdjust:{at:l-61e3,from:12,to:16,reason:"grow"}}}]},{group:"payments",kind:"step",depth:2,liveWorkers:[{group:"payments",instanceId:"worker-payments-5b81",lastBeatAt:l-3500,status:{runtime:"node",concurrency:{mode:"fixed",limit:8},inFlight:7,rssPct:88,cpuPct:63,throughputPerMin:44,p95Ms:2310}}]},{group:"inventory",kind:"step",depth:0,liveWorkers:[{group:"inventory",instanceId:"worker-inventory-11ce",lastBeatAt:l-1200,status:{runtime:"python",concurrency:{mode:"fixed",limit:4},inFlight:1}}]},{group:"shipping",kind:"step",depth:6,liveWorkers:[]}],V={role:"control-plane"};function N(r){const t=new Map;for(const[n,s]of new URLSearchParams(r??"")){const i=/^filter\[where\]\[(\d+)\]\[(field|operator|value)\](?:\[(\d+)\])?$/.exec(n);if(!i)continue;const[,o,c,f]=i,a=t.get(o)??{field:"",operator:"",value:""};if(c==="value"&&f!==void 0){const d=Array.isArray(a.value)?a.value:[];d[Number(f)]=s,a.value=d}else c==="value"?a.value=s:a[c]=s;t.set(o,a)}return[...t.entries()].sort(([n],[s])=>Number(n)-Number(s)).map(([,n])=>n)}function v(r,t){var n;if(t==="tag")return r.tags??[];if(t==="namespace")return[r.namespace??"default"];if(t==="origin")return[r.origin??null];if(t==="status")return[r.status];if(t==="workflow")return[r.workflow];if(t==="attr")return Object.keys(r.searchAttributes??{});if(t.startsWith("attr.")){const s=(n=r.searchAttributes)==null?void 0:n[t.slice(5)];return s===void 0?[]:[String(s)]}return[]}function w(r){return h.filter(t=>N(r).every(n=>{const s=v(t,n.field);if(n.operator==="isNull")return s.includes(null);const i=Array.isArray(n.value)?n.value:[n.value];return s.some(o=>o!==null&&i.includes(o))}))}function P(r){var i;const[t,n]=r.split("?");if(t==="/runs")return w(n);if(t==="/runs/facets"){const o=new Map;for(const c of w(n)){const f=c.origin??null,a=`${c.status}|${f}`,d=o.get(a)??{status:c.status,origin:f,count:0};d.count+=1,o.set(a,d)}return[...o.values()]}if(t==="/runs/values"){const o=new URLSearchParams(n??""),c=o.get("groupByCount[field]")??"",f=Number(o.get("groupByCount[limit]")??100),a=new Map;for(const d of w(n))for(const g of v(d,c))a.set(g,(a.get(g)??0)+1);return[...a].map(([d,g])=>({value:d,count:g})).sort((d,g)=>g.count-d.count||String(d.value).localeCompare(String(g.value))).slice(0,f)}if(t==="/workers")return C;if(t==="/topology")return V;const s=(i=t==null?void 0:t.match(/^\/runs\/(.+)$/))==null?void 0:i[1];if(s){const o=decodeURIComponent(s);return _[o]??{run:h.find(c=>c.id===o),timeline:[],children:[]}}}function T(){const r=window.fetch.bind(window);window.fetch=async(t,n)=>{const i=(typeof t=="string"?t:t instanceof URL?t.href:t.url).match(/\/durable\/api(\/.*)$/),o=i!=null&&i[1]?P(i[1]):void 0;return o===void 0?r(t,n):new Response(JSON.stringify(o),{status:200,headers:{"content-type":"application/json"}})}}const p=r=>new Date(r).toISOString(),m=Date.parse("2026-06-22T14:00:00.000Z"),U="gather:1",O=[{name:"handle_AF_FLEET",start:2e3,end:8200},{name:"handle_MEL",start:2120,end:6900},{name:"handle_METADATA",start:2050,end:5400},{name:"handle_MVR",start:2300,end:9600,failed:!0},{name:"handle_SCHED_MX",start:2080,end:7300},{name:"handle_SUBWO",start:2260,end:8900},{name:"handle_UTIL",start:2010,end:4700}],D=O.map((r,t)=>({runId:"mock-run",seq:2+t,name:r.name,kind:"remote",status:r.failed?"failed":"completed",parallelGroup:U,attempts:1,workerGroup:"gather",startedAt:p(m+r.start),finishedAt:p(m+r.end),...r.failed?{error:{message:"MVR lookup timed out after 7s"}}:{}})),E=[{runId:"mock-run",seq:1,name:"setup",kind:"local",status:"completed",attempts:1,startedAt:p(m+0),finishedAt:p(m+1800)},...D,{runId:"mock-run",seq:9,name:"finalize",kind:"local",status:"completed",attempts:1,startedAt:p(m+9700),finishedAt:p(m+11200)}],A={run:{id:"mock-run",workflow:"gatherAircraftData",workflowVersion:"1",status:"completed",createdAt:p(m),updatedAt:p(m+11200)},timeline:E},F=new b({defaultOptions:{queries:{refetchInterval:!1,refetchOnWindowFocus:!1}}}),k=()=>{},y=new URLSearchParams(window.location.search).get("view")==="console";y&&T();x(document.getElementById("root")).render(u.jsx(I.StrictMode,{children:u.jsx(S,{client:F,children:y?u.jsx(j,{}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"app-bg"}),u.jsxs("div",{className:"relative z-10 mx-auto max-w-3xl p-8",children:[u.jsx("div",{className:"mb-3 mono text-[10px] uppercase tracking-[0.2em] text-zinc-500",children:"preview · parallel-fan timeline"}),u.jsx("div",{className:"rounded-lg border border-line bg-panel p-2",children:u.jsx(q,{run:A.run,timeline:A.timeline,depth:0,selectedKey:void 0,onSelect:k,onOpenRun:k,expanded:new Set,onToggleChild:k})})]})]})})}));
|
package/dist/spa/bench.html
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
<meta charset="utf-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
6
|
<title>durable · scale bench</title>
|
|
7
|
-
<script type="module" crossorigin src="/durable/assets/bench-
|
|
8
|
-
<link rel="modulepreload" crossorigin href="/durable/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/durable/assets/bench-DCclNvcZ.js"></script>
|
|
8
|
+
<link rel="modulepreload" crossorigin href="/durable/assets/index-B-wtX4GV.js">
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/durable/assets/index-CJdk28vt.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
package/dist/spa/index.html
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
rel="stylesheet"
|
|
11
11
|
/>
|
|
12
12
|
<title>durable · control plane</title>
|
|
13
|
-
<script type="module" crossorigin src="/durable/assets/index-
|
|
14
|
-
<link rel="modulepreload" crossorigin href="/durable/assets/index-
|
|
13
|
+
<script type="module" crossorigin src="/durable/assets/index-ChjKRQZx.js"></script>
|
|
14
|
+
<link rel="modulepreload" crossorigin href="/durable/assets/index-B-wtX4GV.js">
|
|
15
15
|
<link rel="stylesheet" crossorigin href="/durable/assets/index-CJdk28vt.css">
|
|
16
16
|
</head>
|
|
17
17
|
<body>
|
package/dist/spa/preview.html
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
rel="stylesheet"
|
|
11
11
|
/>
|
|
12
12
|
<title>durable · parallel-fan preview</title>
|
|
13
|
-
<script type="module" crossorigin src="/durable/assets/preview-
|
|
14
|
-
<link rel="modulepreload" crossorigin href="/durable/assets/index-
|
|
13
|
+
<script type="module" crossorigin src="/durable/assets/preview-CdsjvOrK.js"></script>
|
|
14
|
+
<link rel="modulepreload" crossorigin href="/durable/assets/index-B-wtX4GV.js">
|
|
15
15
|
<link rel="stylesheet" crossorigin href="/durable/assets/index-CJdk28vt.css">
|
|
16
16
|
</head>
|
|
17
17
|
<body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudousxd/nestjs-durable-dashboard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.55.0",
|
|
4
4
|
"description": "Embedded control plane (runs, step timeline, retry/cancel) for nestjs-durable — bundled React SPA served by NestJS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Davide Carvalho",
|
|
@@ -37,11 +37,6 @@
|
|
|
37
37
|
"types": "./dist/client/durable-client.d.ts",
|
|
38
38
|
"import": "./dist/client/durable-client.js",
|
|
39
39
|
"default": "./dist/client/durable-client.js"
|
|
40
|
-
},
|
|
41
|
-
"./react": {
|
|
42
|
-
"types": "./dist/react/index.d.ts",
|
|
43
|
-
"import": "./dist/react/index.js",
|
|
44
|
-
"default": "./dist/react/index.js"
|
|
45
40
|
}
|
|
46
41
|
},
|
|
47
42
|
"files": [
|
|
@@ -55,16 +50,16 @@
|
|
|
55
50
|
"@dudousxd/nestjs-filter": ">=1.33.0 <2.0.0",
|
|
56
51
|
"@nestjs/common": "^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
57
52
|
"@nestjs/core": "^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
58
|
-
"react": ">=18.0.0",
|
|
59
|
-
"react-dom": ">=18.0.0",
|
|
60
53
|
"reflect-metadata": "^0.2.0",
|
|
61
54
|
"rxjs": "^7.0.0"
|
|
62
55
|
},
|
|
63
56
|
"devDependencies": {
|
|
64
57
|
"@base-ui/react": "1.8.0",
|
|
65
58
|
"@dudousxd/nestjs-filter": "1.33.0",
|
|
59
|
+
"@nestjs/authorization": "0.1.3",
|
|
66
60
|
"@nestjs/common": "12.0.1",
|
|
67
61
|
"@nestjs/core": "12.0.1",
|
|
62
|
+
"@nestjs/idempotency": "0.0.4",
|
|
68
63
|
"@nestjs/platform-express": "12.0.1",
|
|
69
64
|
"@tanstack/react-query": "5.102.8",
|
|
70
65
|
"@tanstack/react-virtual": "3.14.13",
|
|
@@ -90,18 +85,10 @@
|
|
|
90
85
|
"tsup": "8.3.5",
|
|
91
86
|
"typescript": "5.9.3",
|
|
92
87
|
"vite": "5.4.21",
|
|
93
|
-
"@dudousxd/nestjs-durable-core": "^0.
|
|
94
|
-
},
|
|
95
|
-
"peerDependenciesMeta": {
|
|
96
|
-
"react": {
|
|
97
|
-
"optional": true
|
|
98
|
-
},
|
|
99
|
-
"react-dom": {
|
|
100
|
-
"optional": true
|
|
101
|
-
}
|
|
88
|
+
"@dudousxd/nestjs-durable-core": "^0.88.0"
|
|
102
89
|
},
|
|
103
90
|
"scripts": {
|
|
104
|
-
"build": "vite build && tsup && tsc -p tsconfig.client.json
|
|
91
|
+
"build": "vite build && tsup && tsc -p tsconfig.client.json",
|
|
105
92
|
"typecheck": "tsc -p tsconfig.server.json --noEmit && tsc -p tsconfig.app.json --noEmit"
|
|
106
93
|
}
|
|
107
94
|
}
|
|
@@ -1,63 +0,0 @@
|
|
|
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 durableConsoleSessionUrl(basePath?: string): string;
|
|
22
|
-
/** Where the console SPA itself is served. */
|
|
23
|
-
export declare function durableConsoleUrl(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 mintDurableConsoleSession(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 openDurableConsole(options?: OpenConsoleOptions): Promise<void>;
|
|
63
|
-
//# sourceMappingURL=console-session.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,107 +0,0 @@
|
|
|
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 = '/durable';
|
|
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 durableConsoleSessionUrl(basePath = DEFAULT_BASE_PATH) {
|
|
30
|
-
return `${normalizeBasePath(basePath)}/session`;
|
|
31
|
-
}
|
|
32
|
-
/** Where the console SPA itself is served. */
|
|
33
|
-
export function durableConsoleUrl(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 mintDurableConsoleSession(options = {}) {
|
|
60
|
-
const url = durableConsoleSessionUrl(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 openDurableConsole(options = {}) {
|
|
102
|
-
await mintDurableConsoleSession(options);
|
|
103
|
-
const target = durableConsoleUrl(options.basePath);
|
|
104
|
-
const navigate = options.navigate ?? ((url) => globalThis.location?.assign(url));
|
|
105
|
-
navigate(target);
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=console-session.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,OAA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,MAAM,yBAAyB,CAAC,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"}
|
package/dist/react/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/react/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// The React tier of `@dudousxd/nestjs-durable-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
|
-
// openDurableConsole(...) — no React at all (`./client`), you own everything
|
|
5
|
-
// useOpenDurableConsole(...) — state for a launcher UI, you own the markup
|
|
6
|
-
// <OpenDurableConsoleButton /> — drop-in, unstyled, forwards every button prop
|
|
7
|
-
//
|
|
8
|
-
// `openDurableConsoleMutationOptions` 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
|
package/dist/react/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { ButtonHTMLAttributes, ReactNode } from 'react';
|
|
2
|
-
import type { OpenConsoleOptions } from '../client/console-session.js';
|
|
3
|
-
export interface OpenDurableConsoleButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'children'>, OpenConsoleOptions {
|
|
4
|
-
/** Button label. Defaults to "Open Durable". */
|
|
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 useOpenDurableConsole}.
|
|
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 useOpenDurableConsole} (same behaviour,
|
|
20
|
-
* your markup) or to `openDurableConsole` (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 OpenDurableConsoleButton({ children, pendingLabel, renderError, basePath, headers, fetch: fetchImpl, signal, navigate, disabled, ...buttonProps }: OpenDurableConsoleButtonProps): import("react").JSX.Element;
|
|
26
|
-
//# sourceMappingURL=open-console-button.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,+BAyB/B"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useOpenDurableConsole } 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 useOpenDurableConsole} (same behaviour,
|
|
9
|
-
* your markup) or to `openDurableConsole` (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 OpenDurableConsoleButton({ children, pendingLabel, renderError, basePath, headers, fetch: fetchImpl, signal, navigate, disabled, ...buttonProps }) {
|
|
15
|
-
const { open, isPending, error } = useOpenDurableConsole({
|
|
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 Durable') }), error &&
|
|
23
|
-
renderError !== null &&
|
|
24
|
-
(renderError?.(error) ?? _jsx("p", { role: "alert", children: error.message }))] }));
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=open-console-button.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { ConsoleSessionError, type OpenConsoleOptions } from '../client/console-session.js';
|
|
2
|
-
/**
|
|
3
|
-
* React layer over `openDurableConsole` — the middle tier between the bare function
|
|
4
|
-
* (`../client/console-session.ts`) and the drop-in `<OpenDurableConsoleButton>`.
|
|
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 Durable-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
|
-
/**
|
|
14
|
-
* True from the click until the navigation starts, or until it fails.
|
|
15
|
-
*
|
|
16
|
-
* With the DEFAULT navigation it stays true afterwards, because the page is being replaced and
|
|
17
|
-
* flipping the button back to idle would flicker "ready to click again" on a document that is
|
|
18
|
-
* leaving. With a caller-supplied `navigate` it is cleared on success — see {@link open}.
|
|
19
|
-
*/
|
|
20
|
-
isPending: boolean;
|
|
21
|
-
/** The last refusal, or `null`. Cleared when `open()` is called again. */
|
|
22
|
-
error: ConsoleSessionError | null;
|
|
23
|
-
/** Drop a stale error without retrying — e.g. when a dialog closes. */
|
|
24
|
-
reset: () => void;
|
|
25
|
-
}
|
|
26
|
-
export declare function useOpenDurableConsole(options?: OpenConsoleOptions): UseOpenConsoleResult;
|
|
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(openDurableConsoleMutationOptions({ headers }));
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare function openDurableConsoleMutationOptions(options?: OpenConsoleOptions): {
|
|
37
|
-
mutationKey: readonly unknown[];
|
|
38
|
-
mutationFn: () => Promise<void>;
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=use-open-console.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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;;;;;;OAMG;IACH,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,CA8D5F;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"}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { ConsoleSessionError, openDurableConsole, } from '../client/console-session.js';
|
|
3
|
-
export function useOpenDurableConsole(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
|
-
// Whether success ends this page's life is decided by WHO navigates.
|
|
14
|
-
//
|
|
15
|
-
// The default navigation replaces the document, so `isPending` is deliberately left set: the
|
|
16
|
-
// component is about to be torn down, and flipping the button back to idle first shows a
|
|
17
|
-
// flicker of "ready to click again" on a page that is leaving.
|
|
18
|
-
//
|
|
19
|
-
// A caller-supplied `navigate` carries no such promise — the option's own documentation offers
|
|
20
|
-
// "open in a new tab" as a use for it, and that keeps this page alive and on screen. Assuming
|
|
21
|
-
// teardown there left the button `disabled` forever, with only a reload to clear it: the launcher
|
|
22
|
-
// worked exactly once per page. So when the caller navigates, the flag reports the truth (the
|
|
23
|
-
// mint finished) rather than a guess about the page.
|
|
24
|
-
const callerNavigates = optionsRef.current.navigate !== undefined;
|
|
25
|
-
void openDurableConsole(optionsRef.current)
|
|
26
|
-
.then(() => {
|
|
27
|
-
if (callerNavigates)
|
|
28
|
-
setIsPending(false);
|
|
29
|
-
})
|
|
30
|
-
.catch((cause) => {
|
|
31
|
-
setError(cause instanceof ConsoleSessionError
|
|
32
|
-
? cause
|
|
33
|
-
: new ConsoleSessionError(String(cause), 'unknown'));
|
|
34
|
-
setIsPending(false);
|
|
35
|
-
});
|
|
36
|
-
}, []);
|
|
37
|
-
// The counterpart to leaving `isPending` set on success under the DEFAULT navigation. That choice
|
|
38
|
-
// assumes the launcher page is discarded once the navigation completes — but with the browser's
|
|
39
|
-
// back/forward cache it is not:
|
|
40
|
-
// pressing Back restores this page from memory with React state intact, so the user lands back on
|
|
41
|
-
// a spinner that never stops, on a button `disabled` by that very flag. This is the one signal
|
|
42
|
-
// that says "you are looking at a restored page": browsers fire `pageshow` with
|
|
43
|
-
// `persisted === true` only on a bfcache restore.
|
|
44
|
-
//
|
|
45
|
-
// Guard on `persisted` rather than on `pageshow` alone. A plain `pageshow` also fires on every
|
|
46
|
-
// ordinary load, and clearing the flag there would resurrect the flicker this hook exists to
|
|
47
|
-
// avoid — a mint that is genuinely still in flight (the user never left) must keep its spinner.
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
// No `window` under SSR — and nothing to restore there either.
|
|
50
|
-
if (typeof window === 'undefined')
|
|
51
|
-
return;
|
|
52
|
-
const onPageShow = (event) => {
|
|
53
|
-
if (event.persisted)
|
|
54
|
-
setIsPending(false);
|
|
55
|
-
};
|
|
56
|
-
window.addEventListener('pageshow', onPageShow);
|
|
57
|
-
return () => window.removeEventListener('pageshow', onPageShow);
|
|
58
|
-
}, []);
|
|
59
|
-
const reset = useCallback(() => setError(null), []);
|
|
60
|
-
return { open, isPending, error, reset };
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* TanStack Query integration WITHOUT a TanStack dependency: the returned object is the shape
|
|
64
|
-
* `useMutation` takes, so a host that already uses Query wires the launcher into its own cache,
|
|
65
|
-
* devtools and error handling with no extra adapter — and a host that doesn't never pays for it.
|
|
66
|
-
*
|
|
67
|
-
* ```ts
|
|
68
|
-
* const { mutate, isPending } = useMutation(openDurableConsoleMutationOptions({ headers }));
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
export function openDurableConsoleMutationOptions(options = {}) {
|
|
72
|
-
return {
|
|
73
|
-
mutationKey: ['durable', 'console', 'open', options.basePath ?? null],
|
|
74
|
-
mutationFn: () => openDurableConsole(options),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=use-open-console.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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;AA2BtC,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,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