@workflow/web 5.0.0-beta.8 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +1 -0
  2. package/build/client/assets/app-BIKwaF7E.css +1 -0
  3. package/build/client/assets/arrow-up-right-jHPcOZmb.js +15 -0
  4. package/build/client/assets/{entry.client-DtOpLtMQ.js → entry.client-DmlDFlyx.js} +25 -185
  5. package/build/client/assets/{highlighted-body-B3W2YXNL-WHMd9MPa.js → highlighted-body-B3W2YXNL-CBBI0JQ-.js} +2 -2
  6. package/build/client/assets/{home-Cai0GqMt.js → home-BcIEUw9E.js} +1791 -291
  7. package/build/client/assets/index-HqNj_XIX.js +200 -0
  8. package/build/client/assets/{index-BsV8i_Jn.js → index-thGVuYbY.js} +19 -19
  9. package/build/client/assets/loader-circle-HeezuKOU.js +12 -0
  10. package/build/client/assets/manifest-a541ae9e.js +1 -0
  11. package/build/client/assets/{mermaid-3ZIDBTTL-TNUP6Q3m.js → mermaid-3ZIDBTTL-ClcCzUqi.js} +17543 -12877
  12. package/build/client/assets/mermaid-3ZIDBTTL-D8CjRQta.css +1 -0
  13. package/build/client/assets/{root-ORTTXEp6.js → root-DLS5V7HU.js} +17 -42
  14. package/build/client/assets/root-grl25rxS.css +1 -0
  15. package/build/client/assets/run-detail-CWoGxu_0.css +1 -0
  16. package/build/client/assets/{run-detail-DNZJxxPM.js → run-detail-DWoMKBqC.js} +3052 -2437
  17. package/build/client/assets/{workflow-graph-viewer-DKqOOMnz.js → workflow-graph-viewer-syfKq6DB.js} +5143 -5261
  18. package/build/client/assets/zstd-B5R2yJjB.wasm +0 -0
  19. package/build/client/assets/zstd-browser-decoder-D2p6f8lN.js +27 -0
  20. package/build/server/assets/{server-build-fc5Vuxba.js → app-CLF3fhv7.js} +102500 -73253
  21. package/build/server/assets/{highlighted-body-B3W2YXNL-BuIiME1D.js → highlighted-body-B3W2YXNL-D21NaJQ0.js} +22 -9
  22. package/build/server/assets/index-BfLBLRRi.js +204 -0
  23. package/build/server/assets/index-CETb4fkq.js +1164 -0
  24. package/build/server/assets/index-DnTW8Yiv.js +1262 -0
  25. package/build/server/assets/index-y9xp70jn.js +184 -0
  26. package/build/server/assets/{mermaid-3ZIDBTTL-TSh7T1Pv.js → mermaid-3ZIDBTTL-DlUUmZjL.js} +22 -9
  27. package/build/server/assets/{token--89oCxEK.js → token-DXiZgST4.js} +5 -2
  28. package/build/server/assets/{token-util-N0DDbkKZ.js → token-util-BvEnPXwK.js} +5 -2
  29. package/build/server/assets/wrapper-BsMfBV09.js +67 -0
  30. package/build/server/assets/zstd-browser-decoder-d2YJZBik.js +77 -0
  31. package/build/server/index.js +55 -3
  32. package/handler.d.ts +22 -0
  33. package/handler.js +103 -0
  34. package/package.json +28 -15
  35. package/registry.d.ts +29 -0
  36. package/registry.js +89 -0
  37. package/server.d.ts +5 -1
  38. package/server.js +32 -39
  39. package/static.js +86 -0
  40. package/build/client/assets/encryption-C69WMRfh.js +0 -34
  41. package/build/client/assets/index-Byi8AWfe.js +0 -280
  42. package/build/client/assets/manifest-127f70fe.js +0 -1
  43. package/build/client/assets/mermaid-3ZIDBTTL-DKxHcEOp.css +0 -1
  44. package/build/client/assets/root-COvK3yNk.css +0 -1
  45. package/build/client/assets/server-build-DzzvWTSG.css +0 -1
  46. package/build/client/assets/worker-CqHKTA7D.js +0 -115
  47. package/build/server/assets/app-BxqFvIap.js +0 -9213
  48. package/build/server/assets/index-CdMzuwNr.js +0 -89
  49. package/build/server/assets/index-meg9qk8y.js +0 -1282
@@ -0,0 +1,184 @@
1
+ import { createRequire as __wkfCreateRequire } from "node:module";
2
+ if (typeof require === "undefined") {
3
+ globalThis.require = __wkfCreateRequire(import.meta.url);
4
+ }
5
+ import { H as HookSchema } from "./app-CLF3fhv7.js";
6
+ import { A, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, B, s, t, u, v, C, D, w, E, x, y, z, F, G, I, J, K, L, M, O, P, Q, R, S, T, U, V, W, X, Y, Z, _, $, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am, an, ao, ap, aq, ar, as, at, au, av, aw, ax, ay, az, aA, aB, aC, aD, aE, aF, aG, aH, aI, aJ, aK, aL, aM, aN, aO, aP, aQ, aR, aS, aT, aU, aV, aW, aX, aY, aZ, a_, a$, b0, b1, b2, b3, b4, b5, b6, b7, b8 } from "./app-CLF3fhv7.js";
7
+ import "node:stream";
8
+ import "stream";
9
+ import "util";
10
+ import "crypto";
11
+ import "async_hooks";
12
+ import "node:crypto";
13
+ import "node:process";
14
+ import "node:path";
15
+ import "node:url";
16
+ import "module";
17
+ import "node:fs/promises";
18
+ import "node:module";
19
+ import "node:util";
20
+ import "node:async_hooks";
21
+ import "node:fs";
22
+ import "node:os";
23
+ import "node:child_process";
24
+ import "node:timers/promises";
25
+ import "node:buffer";
26
+ import "node:http";
27
+ import "node:https";
28
+ import "node:zlib";
29
+ import "events";
30
+ import "node:assert";
31
+ import "node:net";
32
+ import "node:querystring";
33
+ import "node:events";
34
+ import "node:diagnostics_channel";
35
+ import "node:tls";
36
+ import "node:perf_hooks";
37
+ import "node:util/types";
38
+ import "node:sqlite";
39
+ import "node:worker_threads";
40
+ import "node:console";
41
+ import "node:timers";
42
+ import "node:dns";
43
+ import "path";
44
+ import "fs";
45
+ import "constants";
46
+ import "assert";
47
+ import "os";
48
+ import "assert/strict";
49
+ import "net";
50
+ import "node:assert/strict";
51
+ import "https";
52
+ import "http";
53
+ import "tls";
54
+ import "url";
55
+ import "zlib";
56
+ import "buffer";
57
+ export {
58
+ A as ANALYTICS_EVENTS_GET_MANY_LIMIT,
59
+ a as ANALYTICS_MAX_ATTRIBUTE_FILTERS,
60
+ b as ANALYTICS_PAGE_LIMIT,
61
+ c as ANALYTICS_RUN_SCOPED_PAGE_LIMIT,
62
+ d as ATTRIBUTE_EVENT_DATA_MAX_BYTES,
63
+ e as ATTRIBUTE_KEY_MAX_LENGTH,
64
+ f as ATTRIBUTE_MAX_PER_RUN,
65
+ g as ATTRIBUTE_VALUE_MAX_BYTES,
66
+ h as AnalyticsAttributeKeySchema,
67
+ i as AnalyticsEventSchema,
68
+ j as AnalyticsHookSchema,
69
+ k as AnalyticsRunSchema,
70
+ l as AnalyticsStepSchema,
71
+ m as AnalyticsWaitSchema,
72
+ n as AttributeChangeSchema,
73
+ o as AttributeChangesSchema,
74
+ p as AttributeKeySchema,
75
+ q as AttributeValidationError,
76
+ r as AttributeValueSchema,
77
+ B as BULK_CANCEL_MAX_RUN_IDS,
78
+ s as BaseEventSchema,
79
+ t as BulkCancelWorkflowRunResultSchema,
80
+ u as BulkCancelWorkflowRunsRequestSchema,
81
+ v as BulkCancelWorkflowRunsResultSchema,
82
+ C as CHILD_ENTITY_CREATION_EVENT_TYPES,
83
+ D as DEFAULT_TIMESTAMP_THRESHOLD_FUTURE_MS,
84
+ w as DEFAULT_TIMESTAMP_THRESHOLD_PAST_MS,
85
+ E as EVENT_ID_BODY_LENGTH,
86
+ x as EVENT_ID_PREFIX,
87
+ y as EventSchema,
88
+ z as EventTypeSchema,
89
+ F as FIRST_EVENT_SLOT,
90
+ G as HOOK_EVENTS_REQUIRING_EXISTENCE,
91
+ I as HOOK_LIFECYCLE_EVENT_TYPES,
92
+ J as HOOK_RESUME_DEDUP_VERSION,
93
+ K as HOOK_RESUME_INPUT_VERSION,
94
+ L as HealthCheckPayloadSchema,
95
+ M as HookClaimedFromSchema,
96
+ O as HookCreatedEventSchema,
97
+ P as HookResumeCapabilitiesSchema,
98
+ HookSchema,
99
+ Q as LegacySerializedDataSchemaV1,
100
+ R as MessageId,
101
+ S as NODE_HTTP_DEFAULT,
102
+ T as NODE_HTTP_ENV_VAR,
103
+ U as PARENT_RUN_ID_ATTRIBUTE,
104
+ V as PaginatedResponseSchema,
105
+ W as QueuePayloadSchema,
106
+ X as QueuePrefix,
107
+ Y as RESERVED_ATTRIBUTE_KEY_PREFIX,
108
+ Z as RETENTION_ATTRIBUTE,
109
+ _ as RETENTION_DEFAULT,
110
+ $ as RETENTION_ZERO,
111
+ a0 as ROOT_RUN_ID_ATTRIBUTE,
112
+ a1 as RUN_ENTITY_KEY,
113
+ a2 as RunInputSchema,
114
+ a3 as SEALED_LOG_ENV_VAR,
115
+ a4 as SPEC_VERSION_CURRENT,
116
+ a5 as SPEC_VERSION_LEGACY,
117
+ a6 as SPEC_VERSION_MAX_SUPPORTED,
118
+ a7 as SPEC_VERSION_SUPPORTS_ATTRIBUTES,
119
+ a8 as SPEC_VERSION_SUPPORTS_CBOR_QUEUE_TRANSPORT,
120
+ a9 as SPEC_VERSION_SUPPORTS_COMPRESSION,
121
+ aa as SPEC_VERSION_SUPPORTS_EVENT_SOURCING,
122
+ ab as SPEC_VERSION_SUPPORTS_HOOK_FORCE_CLAIM,
123
+ ac as SPEC_VERSION_SUPPORTS_SLOT_IDENTITY,
124
+ ad as STEP_EVENT_TYPES,
125
+ ae as SerializedDataSchema,
126
+ af as StepSchema,
127
+ ag as StepStatusSchema,
128
+ ah as StructuredErrorSchema,
129
+ ai as TERMINAL_EVENT_CLASSES,
130
+ aj as TERMINAL_RUN_EVENT_TYPES,
131
+ ak as TERMINAL_STEP_EVENT_TYPES,
132
+ al as TERMINAL_STEP_STATUSES,
133
+ am as TERMINAL_WORKFLOW_RUN_STATUSES,
134
+ an as TerminalRunEventTypeSchema,
135
+ ao as TerminalStepStatusSchema,
136
+ ap as TerminalWorkflowRunStatusSchema,
137
+ aq as ValidQueueName,
138
+ ar as WAIT_EVENT_TYPES,
139
+ as as WaitSchema,
140
+ at as WaitStatusSchema,
141
+ au as WorkflowInvokePayloadSchema,
142
+ av as WorkflowRunBaseSchema,
143
+ aw as WorkflowRunSchema,
144
+ ax as WorkflowRunStatusSchema,
145
+ ay as applyAttributeChanges,
146
+ az as classifyEntityEvent,
147
+ aA as entityEventClass,
148
+ aB as entityResolveData,
149
+ aC as envFlag,
150
+ aD as envNumber,
151
+ aE as eventIdToSlot,
152
+ aF as getEventDataPayloadField,
153
+ aG as getEventDataRefFields,
154
+ aH as getMaxEventsPerRun,
155
+ aI as getQueueTopicPrefix,
156
+ aJ as isChildEntityCreationEvent,
157
+ aK as isChildEntityCreationEventType,
158
+ aL as isHookEventRequiringExistence,
159
+ aM as isHookLifecycleEventType,
160
+ aN as isLegacySpecVersion,
161
+ aO as isNodeHttpEnabled,
162
+ aP as isSealedNoopEvent,
163
+ aQ as isSlotBody,
164
+ aR as isSlotEventId,
165
+ aS as isStepEventType,
166
+ aT as isTerminalRunEventType,
167
+ aU as isTerminalStepEventType,
168
+ aV as isTerminalStepStatus,
169
+ aW as isTerminalWorkflowRunStatus,
170
+ aX as isWaitEventType,
171
+ aY as mintedSpecVersion,
172
+ aZ as parseQueueName,
173
+ a_ as readRunRetention,
174
+ a$ as reenqueueActiveRuns,
175
+ b0 as requiresNewerWorld,
176
+ b1 as resolveQueueNamespace,
177
+ b2 as slotToEventId,
178
+ b3 as stripEventDataRefs,
179
+ b4 as ulidToDate,
180
+ b5 as validateAttributeChanges,
181
+ b6 as validateAttributeEventDataSize,
182
+ b7 as validateUlidTimestamp,
183
+ b8 as workflowRunIdSchema
184
+ };
@@ -1,8 +1,10 @@
1
- import { N as Nt } from "./server-build-fc5Vuxba.js";
2
- import "./app-BxqFvIap.js";
3
- import "stream";
4
- import "express";
1
+ import { createRequire as __wkfCreateRequire } from "node:module";
2
+ if (typeof require === "undefined") {
3
+ globalThis.require = __wkfCreateRequire(import.meta.url);
4
+ }
5
+ import { N as Nt } from "./app-CLF3fhv7.js";
5
6
  import "node:stream";
7
+ import "stream";
6
8
  import "util";
7
9
  import "crypto";
8
10
  import "async_hooks";
@@ -12,22 +14,24 @@ import "node:path";
12
14
  import "node:url";
13
15
  import "module";
14
16
  import "node:fs/promises";
17
+ import "node:module";
15
18
  import "node:util";
16
19
  import "node:async_hooks";
17
- import "node:module";
18
20
  import "node:fs";
21
+ import "node:os";
19
22
  import "node:child_process";
20
23
  import "node:timers/promises";
24
+ import "node:buffer";
25
+ import "node:http";
26
+ import "node:https";
27
+ import "node:zlib";
21
28
  import "events";
22
29
  import "node:assert";
23
30
  import "node:net";
24
- import "node:http";
25
31
  import "node:querystring";
26
32
  import "node:events";
27
33
  import "node:diagnostics_channel";
28
34
  import "node:tls";
29
- import "node:buffer";
30
- import "node:zlib";
31
35
  import "node:perf_hooks";
32
36
  import "node:util/types";
33
37
  import "node:sqlite";
@@ -37,9 +41,18 @@ import "node:timers";
37
41
  import "node:dns";
38
42
  import "path";
39
43
  import "fs";
44
+ import "constants";
45
+ import "assert";
40
46
  import "os";
47
+ import "assert/strict";
41
48
  import "net";
42
- import "node:os";
49
+ import "node:assert/strict";
50
+ import "https";
51
+ import "http";
52
+ import "tls";
53
+ import "url";
54
+ import "zlib";
55
+ import "buffer";
43
56
  export {
44
57
  Nt as Mermaid
45
58
  };
@@ -1,5 +1,8 @@
1
- import { g as getDefaultExportFromCjs } from "./app-BxqFvIap.js";
2
- import { Y as requireTokenError, X as requireTokenUtil } from "./server-build-fc5Vuxba.js";
1
+ import { createRequire as __wkfCreateRequire } from "node:module";
2
+ if (typeof require === "undefined") {
3
+ globalThis.require = __wkfCreateRequire(import.meta.url);
4
+ }
5
+ import { bp as requireTokenError, bo as requireTokenUtil, bn as getDefaultExportFromCjs } from "./app-CLF3fhv7.js";
3
6
  function _mergeNamespaces(n, m) {
4
7
  for (var i = 0; i < m.length; i++) {
5
8
  const e = m[i];
@@ -1,5 +1,8 @@
1
- import { g as getDefaultExportFromCjs } from "./app-BxqFvIap.js";
2
- import { X as requireTokenUtil } from "./server-build-fc5Vuxba.js";
1
+ import { createRequire as __wkfCreateRequire } from "node:module";
2
+ if (typeof require === "undefined") {
3
+ globalThis.require = __wkfCreateRequire(import.meta.url);
4
+ }
5
+ import { bn as getDefaultExportFromCjs, bo as requireTokenUtil } from "./app-CLF3fhv7.js";
3
6
  function _mergeNamespaces(n, m) {
4
7
  for (var i = 0; i < m.length; i++) {
5
8
  const e = m[i];
@@ -0,0 +1,67 @@
1
+ import { createRequire as __wkfCreateRequire } from "node:module";
2
+ if (typeof require === "undefined") {
3
+ globalThis.require = __wkfCreateRequire(import.meta.url);
4
+ }
5
+ import { bf as WebSocket } from "./app-CLF3fhv7.js";
6
+ import { bg, bh, bi, bj, bk, bl, bm } from "./app-CLF3fhv7.js";
7
+ import "node:stream";
8
+ import "stream";
9
+ import "util";
10
+ import "crypto";
11
+ import "async_hooks";
12
+ import "node:crypto";
13
+ import "node:process";
14
+ import "node:path";
15
+ import "node:url";
16
+ import "module";
17
+ import "node:fs/promises";
18
+ import "node:module";
19
+ import "node:util";
20
+ import "node:async_hooks";
21
+ import "node:fs";
22
+ import "node:os";
23
+ import "node:child_process";
24
+ import "node:timers/promises";
25
+ import "node:buffer";
26
+ import "node:http";
27
+ import "node:https";
28
+ import "node:zlib";
29
+ import "events";
30
+ import "node:assert";
31
+ import "node:net";
32
+ import "node:querystring";
33
+ import "node:events";
34
+ import "node:diagnostics_channel";
35
+ import "node:tls";
36
+ import "node:perf_hooks";
37
+ import "node:util/types";
38
+ import "node:sqlite";
39
+ import "node:worker_threads";
40
+ import "node:console";
41
+ import "node:timers";
42
+ import "node:dns";
43
+ import "path";
44
+ import "fs";
45
+ import "constants";
46
+ import "assert";
47
+ import "os";
48
+ import "assert/strict";
49
+ import "net";
50
+ import "node:assert/strict";
51
+ import "https";
52
+ import "http";
53
+ import "tls";
54
+ import "url";
55
+ import "zlib";
56
+ import "buffer";
57
+ export {
58
+ bg as PerMessageDeflate,
59
+ bh as Receiver,
60
+ bi as Sender,
61
+ WebSocket,
62
+ bj as WebSocketServer,
63
+ bk as createWebSocketStream,
64
+ WebSocket as default,
65
+ bl as extension,
66
+ bm as subprotocol
67
+ };
@@ -0,0 +1,77 @@
1
+ import { createRequire as __wkfCreateRequire } from "node:module";
2
+ if (typeof require === "undefined") {
3
+ globalThis.require = __wkfCreateRequire(import.meta.url);
4
+ }
5
+ import { be as registerZstdDecoder } from "./app-CLF3fhv7.js";
6
+ import "node:stream";
7
+ import "stream";
8
+ import "util";
9
+ import "crypto";
10
+ import "async_hooks";
11
+ import "node:crypto";
12
+ import "node:process";
13
+ import "node:path";
14
+ import "node:url";
15
+ import "module";
16
+ import "node:fs/promises";
17
+ import "node:module";
18
+ import "node:util";
19
+ import "node:async_hooks";
20
+ import "node:fs";
21
+ import "node:os";
22
+ import "node:child_process";
23
+ import "node:timers/promises";
24
+ import "node:buffer";
25
+ import "node:http";
26
+ import "node:https";
27
+ import "node:zlib";
28
+ import "events";
29
+ import "node:assert";
30
+ import "node:net";
31
+ import "node:querystring";
32
+ import "node:events";
33
+ import "node:diagnostics_channel";
34
+ import "node:tls";
35
+ import "node:perf_hooks";
36
+ import "node:util/types";
37
+ import "node:sqlite";
38
+ import "node:worker_threads";
39
+ import "node:console";
40
+ import "node:timers";
41
+ import "node:dns";
42
+ import "path";
43
+ import "fs";
44
+ import "constants";
45
+ import "assert";
46
+ import "os";
47
+ import "assert/strict";
48
+ import "net";
49
+ import "node:assert/strict";
50
+ import "https";
51
+ import "http";
52
+ import "tls";
53
+ import "url";
54
+ import "zlib";
55
+ import "buffer";
56
+ let registered = false;
57
+ let modulePromise;
58
+ function loadWasmModule() {
59
+ if (!modulePromise) {
60
+ const url = new URL("@tootallnate/zstd-wasm/zstd.wasm", import.meta.url);
61
+ modulePromise = fetch(url).then((res) => res.arrayBuffer()).then((bytes) => WebAssembly.compile(bytes));
62
+ }
63
+ return modulePromise;
64
+ }
65
+ function ensureZstdDecoderRegistered() {
66
+ if (registered)
67
+ return;
68
+ registered = true;
69
+ registerZstdDecoder(async (payload) => {
70
+ const { decompressBytes } = await import("./index-BfLBLRRi.js");
71
+ const wasmModule = await loadWasmModule();
72
+ return decompressBytes(wasmModule, payload);
73
+ });
74
+ }
75
+ export {
76
+ ensureZstdDecoderRegistered
77
+ };
@@ -1,6 +1,58 @@
1
- import { n } from "./assets/app-BxqFvIap.js";
2
- import "express";
1
+ import { createRequire as __wkfCreateRequire } from "node:module";
2
+ if (typeof require === "undefined") {
3
+ globalThis.require = __wkfCreateRequire(import.meta.url);
4
+ }
5
+ import { bq } from "./assets/app-CLF3fhv7.js";
6
+ import "node:stream";
3
7
  import "stream";
8
+ import "util";
9
+ import "crypto";
10
+ import "async_hooks";
11
+ import "node:crypto";
12
+ import "node:process";
13
+ import "node:path";
14
+ import "node:url";
15
+ import "module";
16
+ import "node:fs/promises";
17
+ import "node:module";
18
+ import "node:util";
19
+ import "node:async_hooks";
20
+ import "node:fs";
21
+ import "node:os";
22
+ import "node:child_process";
23
+ import "node:timers/promises";
24
+ import "node:buffer";
25
+ import "node:http";
26
+ import "node:https";
27
+ import "node:zlib";
28
+ import "events";
29
+ import "node:assert";
30
+ import "node:net";
31
+ import "node:querystring";
32
+ import "node:events";
33
+ import "node:diagnostics_channel";
34
+ import "node:tls";
35
+ import "node:perf_hooks";
36
+ import "node:util/types";
37
+ import "node:sqlite";
38
+ import "node:worker_threads";
39
+ import "node:console";
40
+ import "node:timers";
41
+ import "node:dns";
42
+ import "path";
43
+ import "fs";
44
+ import "constants";
45
+ import "assert";
46
+ import "os";
47
+ import "assert/strict";
48
+ import "net";
49
+ import "node:assert/strict";
50
+ import "https";
51
+ import "http";
52
+ import "tls";
53
+ import "url";
54
+ import "zlib";
55
+ import "buffer";
4
56
  export {
5
- n as app
57
+ bq as createFetchHandler
6
58
  };
package/handler.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Options for {@link createWorkflowWebHandler}.
3
+ */
4
+ export interface CreateWorkflowWebHandlerOptions {
5
+ /**
6
+ * Mount path the dashboard is served under (e.g. `"/_workflow"`). Routing and
7
+ * asset URLs are reprefixed to this base. Defaults to `"/"` (root).
8
+ */
9
+ basename?: string;
10
+ }
11
+
12
+ /**
13
+ * Create a framework-agnostic Web `Request` -> `Response` handler that serves
14
+ * the Workflow observability UI (static client assets + React Router SSR)
15
+ * in-process, suitable for mounting inside another server under `basename`.
16
+ *
17
+ * Requires `@workflow/web` to have been built (`build/` must exist); throws
18
+ * otherwise.
19
+ */
20
+ export function createWorkflowWebHandler(
21
+ options?: CreateWorkflowWebHandlerOptions
22
+ ): Promise<(request: Request) => Promise<Response>>;
package/handler.js ADDED
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Framework-agnostic, in-process entry point for @workflow/web.
3
+ *
4
+ * Unlike `server.js` (which starts a standalone HTTP server of its own), this
5
+ * exports a single Web-standard fetch handler that another server can mount
6
+ * under an arbitrary base path — e.g. `@workflow/nitro` mounting the dashboard
7
+ * at `/_workflow` without spawning a second server/port.
8
+ *
9
+ * import { createWorkflowWebHandler } from "@workflow/web/handler";
10
+ * const handler = await createWorkflowWebHandler({ basename: "/_workflow" });
11
+ * const response = await handler(request); // (request: Request) => Response
12
+ *
13
+ * The handler serves both the prebuilt static client assets (from `build/client`)
14
+ * and the React Router SSR app. It reads the prebuilt `build/` as-is in every
15
+ * mode (it never runs Vite), so consumers must have built @workflow/web first
16
+ * (the published package ships `build/`).
17
+ */
18
+
19
+ import { existsSync } from 'node:fs';
20
+ import path from 'node:path';
21
+ import { fileURLToPath, pathToFileURL } from 'node:url';
22
+ import { recordDashboard } from './registry.js';
23
+ import { createStaticHandler } from './static.js';
24
+
25
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
26
+ const buildDir = path.resolve(__dirname, 'build');
27
+ const clientDir = path.join(buildDir, 'client');
28
+ const serverEntry = path.join(buildDir, 'server', 'index.js');
29
+
30
+ /** Normalize a mount path: `/` or empty -> "" (root); otherwise strip trailing slash. */
31
+ function normalizeBasename(basename) {
32
+ if (!basename || basename === '/') return '';
33
+ return basename.endsWith('/') ? basename.slice(0, -1) : basename;
34
+ }
35
+
36
+ // One handler per basename, lazily constructed and memoized so repeated
37
+ // requests reuse the same React Router handler and module import.
38
+ const handlerCache = new Map();
39
+
40
+ /**
41
+ * @param {{ basename?: string }} [options]
42
+ * @returns {Promise<(request: Request) => Promise<Response>>}
43
+ */
44
+ export async function createWorkflowWebHandler(options = {}) {
45
+ const basename = normalizeBasename(options.basename ?? '/');
46
+ let promise = handlerCache.get(basename);
47
+ if (!promise) {
48
+ promise = buildHandler(basename).catch((err) => {
49
+ handlerCache.delete(basename);
50
+ throw err;
51
+ });
52
+ handlerCache.set(basename, promise);
53
+ }
54
+ return promise;
55
+ }
56
+
57
+ async function buildHandler(basename) {
58
+ if (!existsSync(serverEntry) || !existsSync(clientDir)) {
59
+ throw new Error(
60
+ '@workflow/web has not been built (missing build/). ' +
61
+ 'Run `pnpm --filter @workflow/web build` before embedding the dashboard.'
62
+ );
63
+ }
64
+
65
+ const mod = await import(pathToFileURL(serverEntry).href);
66
+ if (typeof mod.createFetchHandler !== 'function') {
67
+ throw new Error(
68
+ '@workflow/web build does not export createFetchHandler; rebuild the package.'
69
+ );
70
+ }
71
+ const ssr = mod.createFetchHandler(basename || '/');
72
+ const serveStatic = createStaticHandler({
73
+ dir: clientDir,
74
+ basename,
75
+ // The host owns the connection and may compress the response itself. Even
76
+ // where it doesn't, this runs inside someone else's process — spending its
77
+ // CPU and libuv threads on brotli for what is almost always a localhost
78
+ // dev server is a bad trade. `server.js` leaves compression on, since it
79
+ // can be self-hosted over a real network.
80
+ compress: false,
81
+ });
82
+
83
+ return async (request) => {
84
+ // Advertise this dashboard so the CLI can defer to it (best-effort, once).
85
+ // Done on first request because that's when the public origin is known.
86
+ try {
87
+ const origin = new URL(request.url).origin;
88
+ recordDashboard({
89
+ url: origin + basename,
90
+ basename,
91
+ world:
92
+ process.env.WORKFLOW_TARGET_WORLD ||
93
+ (process.env.VERCEL_DEPLOYMENT_ID ? 'vercel' : 'local'),
94
+ });
95
+ } catch {
96
+ // ignore — registration must never affect request handling
97
+ }
98
+
99
+ const staticResponse = await serveStatic(request);
100
+ if (staticResponse) return staticResponse;
101
+ return ssr(request);
102
+ };
103
+ }