@moinulmoin/eden-runtime-cloudflare 0.6.0 → 0.7.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.
@@ -3,8 +3,21 @@ export declare const EVE_HOST_DEFAULTS: {
3
3
  readonly healthPath: "/eve/v1/health";
4
4
  readonly internalPort: 8080;
5
5
  readonly instance: "standard-1";
6
- readonly sleepAfter: "24h";
6
+ readonly sleepAfter: "1h";
7
7
  };
8
+ /**
9
+ * Cloudflare stops a container at most 6 hours after its Durable Object goes
10
+ * inactive (`setInactivityTimeout` rejects longer values). The idle-sleep
11
+ * alarm must fire before that so it can snapshot first, and the inactivity
12
+ * timeout is `sleepAfter` plus this margin.
13
+ */
14
+ export declare const EVE_HOST_SLEEP_SNAPSHOT_MARGIN_MS: number;
15
+ export declare const EVE_HOST_MAX_SLEEP_AFTER_MS: number;
16
+ /**
17
+ * Parses a `sleepAfter` duration ("300ms", "30s", "15m", "1h", or a bare
18
+ * number of seconds) and enforces Cloudflare's inactivity ceiling.
19
+ */
20
+ export declare function parseEveSleepAfterMs(value: string): number;
8
21
  export declare const EVE_SCHEDULE_WAKE_TRIGGER_CRON = "* * * * *";
9
22
  /**
10
23
  * How far ahead of a tick the every-minute wake trigger starts the Container.
@@ -50,10 +63,10 @@ export declare function parseEveScheduleCron(cron: string): ParsedEveCron | unde
50
63
  export declare function eveScheduleCronFiresWithin(cron: string, nowMs: number, leadMs?: number): boolean;
51
64
  /** Queue and World RPC routes are private; webhooks and manifests stay forwarded. */
52
65
  export declare function isEveWorkflowInternalRoute(pathname: string): boolean;
53
- 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-started-deployment", "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-container-name", "x-eden-container-id", "cf-container-target-port"];
66
+ export declare const EVE_HOST_OWNED_HEADERS: readonly ["forwarded", "x-real-ip", "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"];
54
67
  export declare const WORKER_NAME_PATTERN: RegExp;
55
68
  export declare const IDENTIFIER_PATTERN: RegExp;
56
- export type EveHostErrorCode = "HOST_ORIGIN_UNAVAILABLE" | "HOST_REQUEST_ABORTED" | "HOST_READINESS_UNPROVEN" | "HOST_TRANSPORT_UNTESTABLE" | "HOST_WEBSOCKET_UNSUPPORTED";
69
+ export type EveHostErrorCode = "HOST_ORIGIN_UNAVAILABLE" | "HOST_REQUEST_ABORTED" | "HOST_READINESS_UNPROVEN";
57
70
  export declare class EveHostError extends Error {
58
71
  readonly code: EveHostErrorCode;
59
72
  constructor(code: EveHostErrorCode, message: string);
@@ -66,8 +79,6 @@ export declare function resolveStableWorkersDevOrigin(request: StableWorkersDevO
66
79
  export interface EveHostIdentity {
67
80
  readonly workerName: string;
68
81
  readonly containerApplicationName: string;
69
- readonly containerClassName: string;
70
- readonly containerBindingName: string;
71
82
  readonly stableContainerInstanceName: string;
72
83
  readonly deploymentId: string;
73
84
  readonly generationId: string;
@@ -122,7 +133,6 @@ export interface EveHostWranglerConfig {
122
133
  readonly vars: {
123
134
  readonly EVE_PUBLIC_ORIGIN: string;
124
135
  readonly EVE_CONTAINER_INSTANCE_NAME: string;
125
- readonly EVE_CONTAINER_BINDING_NAME: string;
126
136
  readonly EDEN_EVE_DEPLOYMENT_ID: string;
127
137
  readonly EDEN_EVE_GENERATION_ID: string;
128
138
  readonly EVE_RUNTIME_VARIABLE_NAMES: readonly string[];
@@ -181,31 +191,11 @@ export interface EveHostForwardingMetadata {
181
191
  readonly runtimeRevisionHandle?: string;
182
192
  }
183
193
  export declare function createTrustedEveRequest(request: Request, metadata: EveHostForwardingMetadata): Request;
184
- export interface EveContainerTransport {
185
- readonly containerFetch: (request: Request) => Promise<Response>;
186
- readonly fetch: (request: Request) => Promise<Response>;
187
- }
188
- export interface EveHostProxyOptions extends EveHostForwardingMetadata {
189
- readonly transport: EveContainerTransport;
190
- readonly ensureReady: (signal: AbortSignal) => Promise<void>;
191
- }
192
- export declare function createEveHostProxy(options: EveHostProxyOptions): (request: Request) => Promise<Response>;
193
- export interface EveHostLifecycleEvent {
194
- readonly type: "start_requested" | "started" | "health_ready" | "stopped" | "errored" | "image_mismatch" | "replaced";
195
- readonly at: number;
196
- readonly safeStatus?: string;
197
- }
198
- export interface EveHostLifecycleObserver {
199
- readonly events: readonly EveHostLifecycleEvent[];
200
- record(type: EveHostLifecycleEvent["type"], safeStatus?: string): EveHostLifecycleEvent;
201
- }
202
- export declare function createEveHostLifecycleObserver(now?: () => number): EveHostLifecycleObserver;
203
194
  export interface EveHostContainerEnvironment {
204
195
  readonly [name: string]: unknown;
205
196
  readonly EVE_RUNTIME_VARIABLE_NAMES?: readonly string[];
206
197
  readonly EVE_PUBLIC_ORIGIN?: string;
207
198
  readonly EVE_CONTAINER_INSTANCE_NAME?: string;
208
- readonly EVE_CONTAINER_BINDING_NAME?: string;
209
199
  readonly EDEN_EVE_DEPLOYMENT_ID?: string;
210
200
  readonly EDEN_EVE_GENERATION_ID?: string;
211
201
  readonly EDEN_EVE_RUNTIME_REVISION?: string;
package/dist/eve-host.js CHANGED
@@ -3,8 +3,42 @@ export const EVE_HOST_DEFAULTS = {
3
3
  healthPath: "/eve/v1/health",
4
4
  internalPort: 8080,
5
5
  instance: "standard-1",
6
- sleepAfter: "24h",
6
+ sleepAfter: "1h",
7
7
  };
8
+ /**
9
+ * Cloudflare stops a container at most 6 hours after its Durable Object goes
10
+ * inactive (`setInactivityTimeout` rejects longer values). The idle-sleep
11
+ * alarm must fire before that so it can snapshot first, and the inactivity
12
+ * timeout is `sleepAfter` plus this margin.
13
+ */
14
+ export const EVE_HOST_SLEEP_SNAPSHOT_MARGIN_MS = 15 * 60_000;
15
+ export const EVE_HOST_MAX_SLEEP_AFTER_MS = 6 * 3_600_000 - EVE_HOST_SLEEP_SNAPSHOT_MARGIN_MS;
16
+ /**
17
+ * Parses a `sleepAfter` duration ("300ms", "30s", "15m", "1h", or a bare
18
+ * number of seconds) and enforces Cloudflare's inactivity ceiling.
19
+ */
20
+ export function parseEveSleepAfterMs(value) {
21
+ const match = /^([0-9]+)(ms|s|m|h|d)?$/u.exec(value.trim());
22
+ if (match === null) {
23
+ throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container sleepAfter override is not a parseable duration.");
24
+ }
25
+ const amount = Number.parseInt(match[1] ?? "", 10);
26
+ const unit = match[2] ?? "s";
27
+ const factor = unit === "ms"
28
+ ? 1
29
+ : unit === "s"
30
+ ? 1_000
31
+ : unit === "m"
32
+ ? 60_000
33
+ : unit === "h"
34
+ ? 3_600_000
35
+ : 86_400_000;
36
+ const ms = amount * factor;
37
+ if (ms > EVE_HOST_MAX_SLEEP_AFTER_MS) {
38
+ throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container sleepAfter override exceeds 345m (5 h 45 min); Cloudflare stops a container within 6 hours of its Durable Object going idle, so Eden must snapshot before then.");
39
+ }
40
+ return ms;
41
+ }
8
42
  export const EVE_SCHEDULE_WAKE_TRIGGER_CRON = "* * * * *";
9
43
  /**
10
44
  * How far ahead of a tick the every-minute wake trigger starts the Container.
@@ -167,15 +201,7 @@ export function isEveWorkflowInternalRoute(pathname) {
167
201
  }
168
202
  export const EVE_HOST_OWNED_HEADERS = [
169
203
  "forwarded",
170
- "x-forwarded-for",
171
- "x-forwarded-host",
172
- "x-forwarded-port",
173
- "x-forwarded-proto",
174
- "x-forwarded-server",
175
- "x-forwarded-scheme",
176
204
  "x-real-ip",
177
- "cf-connecting-ip",
178
- "cf-visitor",
179
205
  "true-client-ip",
180
206
  "x-original-host",
181
207
  "x-original-proto",
@@ -185,22 +211,10 @@ export const EVE_HOST_OWNED_HEADERS = [
185
211
  "x-host",
186
212
  "x-eve-public-origin",
187
213
  "x-workflow-local-base-url",
188
- "x-eden-eve-callback-base",
189
- "x-eden-eve-deployment-id",
190
- "x-eden-eve-generation-id",
191
- "x-eden-eve-started-deployment",
192
- "x-eden-eve-public-origin",
193
- "x-eden-eve-correlation-id",
194
- "x-eden-eve-container-name",
195
- "x-eden-eve-container-id",
196
- "x-eden-eve-runtime-revision",
197
- "x-eden-container-name",
198
- "x-eden-container-id",
199
- "cf-container-target-port",
200
214
  ];
201
215
  const EVE_HOST_OWNED_HEADER_SET = new Set(EVE_HOST_OWNED_HEADERS);
202
216
  export const WORKER_NAME_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/u;
203
- const SUBDOMAIN_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/u;
217
+ const SUBDOMAIN_PATTERN = WORKER_NAME_PATTERN;
204
218
  export const IDENTIFIER_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/u;
205
219
  const INSTANCE_NAME_PATTERN = /^[a-z0-9](?:[a-z0-9._-]{0,125}[a-z0-9])?$/u;
206
220
  const SHA256_IMAGE_PATTERN = /^(?:[a-z0-9.-]+\/)?[a-z0-9._/-]+@sha256:[0-9a-f]{64}$/u;
@@ -265,13 +279,9 @@ export function createEveHostConfig(request) {
265
279
  if (!WORKER_NAME_PATTERN.test(request.workerName)) {
266
280
  throw new EveHostError("HOST_ORIGIN_UNAVAILABLE", "The exact Worker name is not valid.");
267
281
  }
268
- if (!WORKER_NAME_PATTERN.test(request.containerApplicationName) ||
269
- !IDENTIFIER_PATTERN.test(request.containerClassName)) {
282
+ if (!WORKER_NAME_PATTERN.test(request.containerApplicationName)) {
270
283
  throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container application and class names must be stable safe identifiers.");
271
284
  }
272
- if (!IDENTIFIER_PATTERN.test(request.containerBindingName)) {
273
- throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container binding name must be a valid Worker environment identifier.");
274
- }
275
285
  if (!INSTANCE_NAME_PATTERN.test(request.stableContainerInstanceName)) {
276
286
  throw new EveHostError("HOST_READINESS_UNPROVEN", "The stable Container instance name must be a bounded logical identifier.");
277
287
  }
@@ -291,13 +301,11 @@ export function createEveHostConfig(request) {
291
301
  }
292
302
  }
293
303
  if (request.containerSleepAfter !== undefined) {
294
- if (!/^[0-9]+(?:ms|s|m|h|d)?$/u.test(request.containerSleepAfter)) {
295
- throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container sleepAfter override is not a parseable duration.");
296
- }
304
+ parseEveSleepAfterMs(request.containerSleepAfter);
297
305
  }
298
306
  const container = {
299
307
  name: request.containerApplicationName,
300
- class_name: request.containerClassName,
308
+ class_name: "EveHostDurableContainer",
301
309
  scheduling_policy: "durable_object",
302
310
  images: { eve: { image: request.containerImage } },
303
311
  };
@@ -316,8 +324,8 @@ export function createEveHostConfig(request) {
316
324
  }
317
325
  const bindings = [
318
326
  {
319
- name: request.containerBindingName,
320
- class_name: request.containerClassName,
327
+ name: "EVE_CONTAINER",
328
+ class_name: "EveHostDurableContainer",
321
329
  },
322
330
  ...(worldCloudflare
323
331
  ? [{ name: "EDEN_WORLD", class_name: "EdenWorldDurableObject" }]
@@ -368,7 +376,6 @@ export function createEveHostConfig(request) {
368
376
  vars: {
369
377
  EVE_PUBLIC_ORIGIN: request.stableWorkersDevOrigin,
370
378
  EVE_CONTAINER_INSTANCE_NAME: request.stableContainerInstanceName,
371
- EVE_CONTAINER_BINDING_NAME: request.containerBindingName,
372
379
  EDEN_EVE_DEPLOYMENT_ID: request.deploymentId,
373
380
  EDEN_EVE_GENERATION_ID: request.generationId,
374
381
  EVE_RUNTIME_VARIABLE_NAMES: request.runtimeVariableNames ?? [],
@@ -391,9 +398,9 @@ export function createEveHostConfig(request) {
391
398
  },
392
399
  container: {
393
400
  applicationName: request.containerApplicationName,
394
- className: request.containerClassName,
401
+ className: "EveHostDurableContainer",
395
402
  instanceName: request.stableContainerInstanceName,
396
- bindingName: request.containerBindingName,
403
+ bindingName: "EVE_CONTAINER",
397
404
  port: EVE_HOST_DEFAULTS.internalPort,
398
405
  publicOrigin: request.stableWorkersDevOrigin,
399
406
  deploymentId: request.deploymentId,
@@ -410,7 +417,6 @@ export function generateEveHostWorkerSource(request) {
410
417
  const workerOptions = {
411
418
  publicOrigin: request.config.container.publicOrigin,
412
419
  workerName: request.config.worker.name,
413
- containerBindingName: request.config.container.bindingName,
414
420
  deploymentId: request.config.container.deploymentId,
415
421
  generationId: request.config.container.generationId,
416
422
  stableContainerInstanceName: request.config.container.instanceName,
@@ -423,13 +429,10 @@ export function generateEveHostWorkerSource(request) {
423
429
  ? {}
424
430
  : { schedules: request.config.container.schedules }),
425
431
  };
426
- const exportContainerClass = request.config.container.className === "EveHostDurableContainer"
427
- ? "export { EveHostDurableContainer };"
428
- : `export { EveHostDurableContainer as ${request.config.container.className} };`;
429
432
  return [
430
433
  `import { EdenWorldDurableObject, EveHostDurableContainer, EveHostLoopback, createEveHostWorker } from ${JSON.stringify(moduleSpecifier)};`,
431
434
  `export { EveHostLoopback };`,
432
- exportContainerClass,
435
+ "export { EveHostDurableContainer };",
433
436
  "",
434
437
  ...(request.config.worker.vars.EDEN_EVE_WORLD_CLOUDFLARE === true ||
435
438
  request.config.worker.durable_objects.bindings.some((binding) => binding.class_name === "EdenWorldDurableObject") ||
@@ -504,40 +507,11 @@ export function createTrustedEveRequest(request, metadata) {
504
507
  };
505
508
  return new Request(targetUrl, init);
506
509
  }
507
- function isWebSocketUpgrade(request) {
508
- return request.headers.get("upgrade")?.toLowerCase() === "websocket";
509
- }
510
510
  function throwIfAborted(signal) {
511
511
  if (signal.aborted) {
512
512
  throw new EveHostError("HOST_REQUEST_ABORTED", "The client request was cancelled before Eve became ready.");
513
513
  }
514
514
  }
515
- export function createEveHostProxy(options) {
516
- return async (request) => {
517
- throwIfAborted(request.signal);
518
- await options.ensureReady(request.signal);
519
- throwIfAborted(request.signal);
520
- const forwarded = createTrustedEveRequest(request, options);
521
- return isWebSocketUpgrade(request)
522
- ? options.transport.fetch(forwarded)
523
- : options.transport.containerFetch(forwarded);
524
- };
525
- }
526
- export function createEveHostLifecycleObserver(now = Date.now) {
527
- const events = [];
528
- return {
529
- events,
530
- record(type, safeStatus) {
531
- const event = {
532
- type,
533
- at: now(),
534
- ...(safeStatus === undefined ? {} : { safeStatus }),
535
- };
536
- events.push(event);
537
- return event;
538
- },
539
- };
540
- }
541
515
  function responseBodyIsReady(value) {
542
516
  if (typeof value !== "object" || value === null)
543
517
  return false;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { EVE_HOST_DEFAULTS, EVE_SCHEDULE_WAKE_LEAD_MS, EVE_SCHEDULE_WAKE_TRIGGER_CRON, eveScheduleCronFiresWithin, expandEveCronField, parseEveScheduleCron, EVE_HOST_OWNED_HEADERS, EveHostError, createEveHostConfig, createEveHostLifecycleObserver, createEveHostProxy, createEveReadinessGate, createTrustedEveRequest, generateEveHostWorkerSource, resolveStableWorkersDevOrigin, } from "./eve-host.js";
2
- export type { EveDurableBinding, EveDurableMigration, EveContainerTransport, EveHostConfig, EveHostConfigRequest, EveHostContainerConfig, EveHostContainerEnvironment, EveHostErrorCode, EveScheduleCronEntry, EveHostForwardingMetadata, EveHostIdentity, EveHostLifecycleEvent, EveHostLifecycleObserver, EveHostProxyOptions, EveHostReadinessEvidence, EveHostReadinessOptions, EveReadinessGate, EveHostWranglerConfig, EveGeneratedWorkerSourceRequest, StableWorkersDevOriginRequest, } from "./eve-host.js";
1
+ export { createEveHostConfig, generateEveHostWorkerSource, parseEveScheduleCron, resolveStableWorkersDevOrigin, } from "./eve-host.js";
2
+ export type { EveDurableBinding, EveDurableMigration, EveHostConfig, EveScheduleCronEntry, } from "./eve-host.js";
3
3
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { EVE_HOST_DEFAULTS, EVE_SCHEDULE_WAKE_LEAD_MS, EVE_SCHEDULE_WAKE_TRIGGER_CRON, eveScheduleCronFiresWithin, expandEveCronField, parseEveScheduleCron, EVE_HOST_OWNED_HEADERS, EveHostError, createEveHostConfig, createEveHostLifecycleObserver, createEveHostProxy, createEveReadinessGate, createTrustedEveRequest, generateEveHostWorkerSource, resolveStableWorkersDevOrigin, } from "./eve-host.js";
1
+ export { createEveHostConfig, generateEveHostWorkerSource, parseEveScheduleCron, resolveStableWorkersDevOrigin, } from "./eve-host.js";
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moinulmoin/eden-runtime-cloudflare",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "Cloudflare Worker/Container host runtime for Eden's Eve deployments.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -20,7 +20,7 @@
20
20
  "NOTICE"
21
21
  ],
22
22
  "devDependencies": {
23
- "@moinulmoin/eden-world-cloudflare": "0.6.0",
23
+ "@moinulmoin/eden-world-cloudflare": "0.7.1",
24
24
  "@cloudflare/workers-types": "5.20261006.1"
25
25
  },
26
26
  "repository": {