@moinulmoin/eden-runtime-cloudflare 0.3.0 → 0.4.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.
- package/NOTICE +8 -0
- package/dist/eden-eve-host-worker.mjs +24103 -231
- package/dist/eve-host-runtime.d.ts +7 -0
- package/dist/eve-host-runtime.js +83 -0
- package/dist/eve-host.d.ts +9 -8
- package/dist/eve-host.js +19 -4
- package/package.json +2 -1
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Container, ContainerProxy } from "@cloudflare/containers";
|
|
2
2
|
import { type EveHostContainerEnvironment, type EveHostForwardingMetadata, type EveHostReadinessEvidence, type EveScheduleCronEntry } from "./eve-host.js";
|
|
3
3
|
export { ContainerProxy };
|
|
4
|
+
/** The deployment's single SQLite-backed Workflow World. */
|
|
5
|
+
export declare class EdenWorldDurableObject {
|
|
6
|
+
private readonly core;
|
|
7
|
+
constructor(ctx: DurableObjectState, env: EveHostContainerEnvironment);
|
|
8
|
+
fetch(request: Request): Promise<Response>;
|
|
9
|
+
alarm(): Promise<void>;
|
|
10
|
+
}
|
|
4
11
|
/**
|
|
5
12
|
* Delivers the container's own HTTPS requests to its public workers.dev origin
|
|
6
13
|
* back into the container over the internal port instead of the public edge.
|
package/dist/eve-host-runtime.js
CHANGED
|
@@ -1,7 +1,78 @@
|
|
|
1
1
|
import { Container, ContainerProxy } from "@cloudflare/containers";
|
|
2
|
+
import { WorldCore } from "@moinulmoin/eden-world-cloudflare/core";
|
|
2
3
|
import { EVE_HOST_DEFAULTS, EVE_SCHEDULE_WAKE_LEAD_MS, EveHostError, assertNonEmpty, assertStableOrigin, createEveHostLifecycleObserver, createEveReadinessGate, createTrustedEveRequest, eveScheduleCronFiresWithin, IDENTIFIER_PATTERN, readProtectedRuntimeVariables, WORKER_NAME_PATTERN, isEveWorkflowInternalRoute, } from "./eve-host.js";
|
|
3
4
|
export { ContainerProxy };
|
|
4
5
|
const EVE_CLOUDFLARE_CONTAINERS_CA_PATH = "/etc/cloudflare/certs/cloudflare-containers-ca.crt";
|
|
6
|
+
/** The deployment's single SQLite-backed Workflow World. */
|
|
7
|
+
export class EdenWorldDurableObject {
|
|
8
|
+
core;
|
|
9
|
+
constructor(ctx, env) {
|
|
10
|
+
this.core = new WorldCore({
|
|
11
|
+
sql: {
|
|
12
|
+
exec: ctx.storage.sql.exec.bind(ctx.storage.sql),
|
|
13
|
+
transactionSync: ctx.storage.transactionSync.bind(ctx.storage),
|
|
14
|
+
},
|
|
15
|
+
scheduleAlarm: async (atMs) => {
|
|
16
|
+
if (atMs === null)
|
|
17
|
+
await ctx.storage.deleteAlarm();
|
|
18
|
+
else
|
|
19
|
+
await ctx.storage.setAlarm(atMs);
|
|
20
|
+
},
|
|
21
|
+
delivery: {
|
|
22
|
+
deliver: async (message) => {
|
|
23
|
+
const origin = env.EVE_PUBLIC_ORIGIN;
|
|
24
|
+
const binding = env.EVE_CONTAINER_BINDING_NAME;
|
|
25
|
+
const instance = env.EVE_CONTAINER_INSTANCE_NAME;
|
|
26
|
+
if (typeof origin !== "string" || typeof binding !== "string" ||
|
|
27
|
+
typeof instance !== "string") {
|
|
28
|
+
throw new Error("The World queue Container identity is unavailable.");
|
|
29
|
+
}
|
|
30
|
+
const namespace = env[binding];
|
|
31
|
+
const response = await namespace.getByName(instance).containerFetch(new Request(new URL(`/.well-known/workflow/v1/${message.path}`, origin), {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers: {
|
|
34
|
+
...message.headers,
|
|
35
|
+
"content-type": "application/json",
|
|
36
|
+
"x-vqs-queue-name": message.queueName,
|
|
37
|
+
"x-vqs-message-id": message.messageId,
|
|
38
|
+
"x-vqs-message-attempt": String(message.attempt),
|
|
39
|
+
},
|
|
40
|
+
body: message.body,
|
|
41
|
+
}), EVE_HOST_DEFAULTS.internalPort);
|
|
42
|
+
// Body transport errors must remain retryable; an HTTP status alone
|
|
43
|
+
// is not an acknowledgement of a streamed Container response.
|
|
44
|
+
const body = await response.text();
|
|
45
|
+
let result = null;
|
|
46
|
+
try {
|
|
47
|
+
result = JSON.parse(body);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// World-local also accepts successful non-JSON responses.
|
|
51
|
+
}
|
|
52
|
+
const timeout = result?.timeoutSeconds;
|
|
53
|
+
return {
|
|
54
|
+
ok: response.ok && timeout === undefined,
|
|
55
|
+
...(typeof timeout === "number" && timeout >= 0
|
|
56
|
+
? { retryAfterMs: timeout * 1_000 }
|
|
57
|
+
: {}),
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
void ctx.blockConcurrencyWhile(async () => this.core.migrate());
|
|
63
|
+
}
|
|
64
|
+
async fetch(request) {
|
|
65
|
+
if (request.method !== "POST")
|
|
66
|
+
return new Response(null, { status: 405 });
|
|
67
|
+
const result = await this.core.handleRpc(new Uint8Array(await request.arrayBuffer()));
|
|
68
|
+
return new Response(result, {
|
|
69
|
+
headers: { "content-type": "application/cbor" },
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async alarm() {
|
|
73
|
+
await this.core.runAlarm();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
5
76
|
/**
|
|
6
77
|
* Delivers the container's own HTTPS requests to its public workers.dev origin
|
|
7
78
|
* back into the container over the internal port instead of the public edge.
|
|
@@ -27,6 +98,12 @@ export async function routeEveOutboundRequest(request, env) {
|
|
|
27
98
|
if (hostname !== new URL(publicOrigin).hostname) {
|
|
28
99
|
return fetch(request);
|
|
29
100
|
}
|
|
101
|
+
if (new URL(request.url).pathname === "/__eden/world/rpc") {
|
|
102
|
+
const world = env.EDEN_WORLD;
|
|
103
|
+
if (world === undefined)
|
|
104
|
+
return new Response(null, { status: 404 });
|
|
105
|
+
return world.get(world.idFromName("world")).fetch(request);
|
|
106
|
+
}
|
|
30
107
|
const namespace = env[bindingName];
|
|
31
108
|
if (namespace === undefined) {
|
|
32
109
|
throw new EveHostError("HOST_READINESS_UNPROVEN", "The configured Container binding is unavailable to the outbound handler.");
|
|
@@ -69,6 +146,12 @@ export class EveHostContainer extends Container {
|
|
|
69
146
|
NODE_ENV: "production",
|
|
70
147
|
WORKFLOW_LOCAL_BASE_URL: publicOrigin,
|
|
71
148
|
EDEN_EVE_DEPLOYMENT_ID: deploymentId,
|
|
149
|
+
...(env.EDEN_EVE_WORLD_CLOUDFLARE
|
|
150
|
+
? {
|
|
151
|
+
EDEN_WORLD_URL: `${publicOrigin}/__eden/world/rpc`,
|
|
152
|
+
CBOR_NATIVE_ACCELERATION_DISABLED: "true",
|
|
153
|
+
}
|
|
154
|
+
: {}),
|
|
72
155
|
EDEN_EVE_GENERATION_ID: generationId,
|
|
73
156
|
// Trust the runtime-mounted Cloudflare Containers CA so the intercepted
|
|
74
157
|
// HTTPS deliveries to the public origin below complete TLS.
|
package/dist/eve-host.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ export declare function parseEveScheduleCron(cron: string): ParsedEveCron | unde
|
|
|
49
49
|
* minute-aligned UTC, matching Eve's minute-granularity schedules).
|
|
50
50
|
*/
|
|
51
51
|
export declare function eveScheduleCronFiresWithin(cron: string, nowMs: number, leadMs?: number): boolean;
|
|
52
|
-
/** Queue
|
|
52
|
+
/** Queue and World RPC routes are private; webhooks and manifests stay forwarded. */
|
|
53
53
|
export declare function isEveWorkflowInternalRoute(pathname: string): boolean;
|
|
54
54
|
export declare const EVE_HOST_OWNED_HEADERS: readonly ["forwarded", "x-forwarded-for", "x-forwarded-host", "x-forwarded-port", "x-forwarded-proto", "x-forwarded-server", "x-forwarded-scheme", "x-real-ip", "cf-connecting-ip", "cf-visitor", "true-client-ip", "x-original-host", "x-original-proto", "x-envoy-original-host", "x-envoy-original-proto", "x-proxy-host", "x-host", "x-eve-public-origin", "x-workflow-local-base-url", "x-eden-eve-callback-base", "x-eden-eve-deployment-id", "x-eden-eve-generation-id", "x-eden-eve-public-origin", "x-eden-eve-correlation-id", "x-eden-eve-container-name", "x-eden-eve-container-id", "x-eden-eve-runtime-revision", "x-eden-deployment-id", "x-eden-generation-id", "x-eden-container-name", "x-eden-container-id", "cf-container-target-port"];
|
|
55
55
|
export declare const WORKER_NAME_PATTERN: RegExp;
|
|
@@ -87,6 +87,7 @@ export interface EveHostConfigRequest extends EveHostIdentity {
|
|
|
87
87
|
readonly schedules?: readonly EveScheduleCronEntry[];
|
|
88
88
|
/** Overrides the Container `sleepAfter` (e.g. "30s") for testing. */
|
|
89
89
|
readonly containerSleepAfter?: string;
|
|
90
|
+
readonly workflowWorld?: string;
|
|
90
91
|
}
|
|
91
92
|
export interface EveHostWranglerConfig {
|
|
92
93
|
readonly account_id?: string;
|
|
@@ -103,6 +104,7 @@ export interface EveHostWranglerConfig {
|
|
|
103
104
|
readonly EVE_RUNTIME_VARIABLE_NAMES: readonly string[];
|
|
104
105
|
readonly EDEN_EVE_RUNTIME_REVISION?: string;
|
|
105
106
|
readonly EDEN_EVE_CONTAINER_SLEEP_AFTER?: string;
|
|
107
|
+
readonly EDEN_EVE_WORLD_CLOUDFLARE?: true;
|
|
106
108
|
};
|
|
107
109
|
readonly triggers?: {
|
|
108
110
|
readonly crons: readonly string[];
|
|
@@ -118,17 +120,15 @@ export interface EveHostWranglerConfig {
|
|
|
118
120
|
}
|
|
119
121
|
];
|
|
120
122
|
readonly durable_objects: {
|
|
121
|
-
readonly bindings: readonly
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
];
|
|
123
|
+
readonly bindings: readonly {
|
|
124
|
+
readonly name: string;
|
|
125
|
+
readonly class_name: string;
|
|
126
|
+
}[];
|
|
127
127
|
};
|
|
128
128
|
readonly migrations: readonly [
|
|
129
129
|
{
|
|
130
130
|
readonly tag: "v1";
|
|
131
|
-
readonly new_sqlite_classes: readonly [
|
|
131
|
+
readonly new_sqlite_classes: readonly string[];
|
|
132
132
|
}
|
|
133
133
|
];
|
|
134
134
|
}
|
|
@@ -192,6 +192,7 @@ export interface EveHostContainerEnvironment {
|
|
|
192
192
|
readonly EDEN_EVE_GENERATION_ID?: string;
|
|
193
193
|
readonly EDEN_EVE_RUNTIME_REVISION?: string;
|
|
194
194
|
readonly EDEN_EVE_CONTAINER_SLEEP_AFTER?: string;
|
|
195
|
+
readonly EDEN_EVE_WORLD_CLOUDFLARE?: boolean;
|
|
195
196
|
}
|
|
196
197
|
export interface EveHostReadinessEvidence {
|
|
197
198
|
readonly healthPath: "/eve/v1/health";
|
package/dist/eve-host.js
CHANGED
|
@@ -155,16 +155,16 @@ export function eveScheduleCronFiresWithin(cron, nowMs, leadMs = EVE_SCHEDULE_WA
|
|
|
155
155
|
}
|
|
156
156
|
return false;
|
|
157
157
|
}
|
|
158
|
-
/** Queue
|
|
158
|
+
/** Queue and World RPC routes are private; webhooks and manifests stay forwarded. */
|
|
159
159
|
export function isEveWorkflowInternalRoute(pathname) {
|
|
160
160
|
let decodedPath = pathname;
|
|
161
161
|
try {
|
|
162
162
|
decodedPath = decodeURIComponent(pathname);
|
|
163
163
|
}
|
|
164
164
|
catch {
|
|
165
|
-
//
|
|
165
|
+
// A malformed escape cannot identify an internal route.
|
|
166
166
|
}
|
|
167
|
-
return
|
|
167
|
+
return /^\/(?:\.well-known\/workflow\/v1\/(?:flow|step)|__eden\/world)(?:\/|$)/iu.test(decodedPath.replace(/\/+/gu, "/"));
|
|
168
168
|
}
|
|
169
169
|
export const EVE_HOST_OWNED_HEADERS = [
|
|
170
170
|
"forwarded",
|
|
@@ -329,6 +329,9 @@ export function createEveHostConfig(request) {
|
|
|
329
329
|
...(request.containerSleepAfter === undefined
|
|
330
330
|
? {}
|
|
331
331
|
: { EDEN_EVE_CONTAINER_SLEEP_AFTER: request.containerSleepAfter }),
|
|
332
|
+
...(request.workflowWorld === "@moinulmoin/eden-world-cloudflare"
|
|
333
|
+
? { EDEN_EVE_WORLD_CLOUDFLARE: true }
|
|
334
|
+
: {}),
|
|
332
335
|
},
|
|
333
336
|
...(schedules.length === 0
|
|
334
337
|
? {}
|
|
@@ -340,12 +343,20 @@ export function createEveHostConfig(request) {
|
|
|
340
343
|
name: request.containerBindingName,
|
|
341
344
|
class_name: request.containerClassName,
|
|
342
345
|
},
|
|
346
|
+
...(request.workflowWorld === "@moinulmoin/eden-world-cloudflare"
|
|
347
|
+
? [{ name: "EDEN_WORLD", class_name: "EdenWorldDurableObject" }]
|
|
348
|
+
: []),
|
|
343
349
|
],
|
|
344
350
|
},
|
|
345
351
|
migrations: [
|
|
346
352
|
{
|
|
347
353
|
tag: "v1",
|
|
348
|
-
new_sqlite_classes: [
|
|
354
|
+
new_sqlite_classes: [
|
|
355
|
+
request.containerClassName,
|
|
356
|
+
...(request.workflowWorld === "@moinulmoin/eden-world-cloudflare"
|
|
357
|
+
? ["EdenWorldDurableObject"]
|
|
358
|
+
: []),
|
|
359
|
+
],
|
|
349
360
|
},
|
|
350
361
|
],
|
|
351
362
|
},
|
|
@@ -389,6 +400,9 @@ export function generateEveHostWorkerSource(request) {
|
|
|
389
400
|
? "export { ContainerProxy, EveHostContainer };"
|
|
390
401
|
: `export { ContainerProxy, EveHostContainer as ${request.config.container.className} };`,
|
|
391
402
|
"",
|
|
403
|
+
...(request.config.worker.vars.EDEN_EVE_WORLD_CLOUDFLARE
|
|
404
|
+
? [`export { EdenWorldDurableObject } from ${JSON.stringify(moduleSpecifier)};`]
|
|
405
|
+
: []),
|
|
392
406
|
`EveHostContainer.outboundByHost = { ${JSON.stringify(new URL(request.config.container.publicOrigin).hostname)}: routeEveOutboundRequest };`,
|
|
393
407
|
"",
|
|
394
408
|
`export default createEveHostWorker(${JSON.stringify(workerOptions)});`,
|
|
@@ -511,6 +525,7 @@ const RESERVED_EVE_HOST_VARIABLES = new Set([
|
|
|
511
525
|
"NODE_ENV",
|
|
512
526
|
"NODE_EXTRA_CA_CERTS",
|
|
513
527
|
"WORKFLOW_LOCAL_BASE_URL",
|
|
528
|
+
"EDEN_WORLD_URL",
|
|
514
529
|
"EDEN_EVE_DEPLOYMENT_ID",
|
|
515
530
|
"EDEN_EVE_GENERATION_ID",
|
|
516
531
|
"EDEN_EVE_RUNTIME_REVISION",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moinulmoin/eden-runtime-cloudflare",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Cloudflare Worker/Container host runtime for Eden's Eve deployments.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
],
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@cloudflare/containers": "0.3.7",
|
|
24
|
+
"@moinulmoin/eden-world-cloudflare": "0.4.1",
|
|
24
25
|
"@cloudflare/workers-types": "5.20260810.1"
|
|
25
26
|
},
|
|
26
27
|
"repository": {
|