miniflare 0.0.0-05973bba4 → 0.0.0-05b1e8391

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/src/index.js CHANGED
@@ -254,17 +254,17 @@ var require_ignore = __commonJS({
254
254
  var throwError = (message, Ctor) => {
255
255
  throw new Ctor(message);
256
256
  };
257
- var checkPath = (path30, originalPath, doThrow) => {
258
- if (!isString(path30)) {
257
+ var checkPath = (path33, originalPath, doThrow) => {
258
+ if (!isString(path33)) {
259
259
  return doThrow(
260
260
  `path must be a string, but got \`${originalPath}\``,
261
261
  TypeError
262
262
  );
263
263
  }
264
- if (!path30) {
264
+ if (!path33) {
265
265
  return doThrow(`path must not be empty`, TypeError);
266
266
  }
267
- if (checkPath.isNotRelative(path30)) {
267
+ if (checkPath.isNotRelative(path33)) {
268
268
  const r = "`path.relative()`d";
269
269
  return doThrow(
270
270
  `path should be a ${r} string, but got "${originalPath}"`,
@@ -273,7 +273,7 @@ var require_ignore = __commonJS({
273
273
  }
274
274
  return true;
275
275
  };
276
- var isNotRelative = (path30) => REGEX_TEST_INVALID_PATH.test(path30);
276
+ var isNotRelative = (path33) => REGEX_TEST_INVALID_PATH.test(path33);
277
277
  checkPath.isNotRelative = isNotRelative;
278
278
  checkPath.convert = (p) => p;
279
279
  var Ignore = class {
@@ -332,7 +332,7 @@ var require_ignore = __commonJS({
332
332
  // setting `checkUnignored` to `false` could reduce additional
333
333
  // path matching.
334
334
  // @returns {TestResult} true if a file is ignored
335
- _testOne(path30, checkUnignored) {
335
+ _testOne(path33, checkUnignored) {
336
336
  let ignored2 = false;
337
337
  let unignored = false;
338
338
  this._rules.forEach((rule) => {
@@ -340,7 +340,7 @@ var require_ignore = __commonJS({
340
340
  if (unignored === negative && ignored2 !== unignored || negative && !ignored2 && !unignored && !checkUnignored) {
341
341
  return;
342
342
  }
343
- const matched = rule.regex.test(path30);
343
+ const matched = rule.regex.test(path33);
344
344
  if (matched) {
345
345
  ignored2 = !negative;
346
346
  unignored = negative;
@@ -353,24 +353,24 @@ var require_ignore = __commonJS({
353
353
  }
354
354
  // @returns {TestResult}
355
355
  _test(originalPath, cache, checkUnignored, slices) {
356
- const path30 = originalPath && checkPath.convert(originalPath);
356
+ const path33 = originalPath && checkPath.convert(originalPath);
357
357
  checkPath(
358
- path30,
358
+ path33,
359
359
  originalPath,
360
360
  this._allowRelativePaths ? RETURN_FALSE : throwError
361
361
  );
362
- return this._t(path30, cache, checkUnignored, slices);
362
+ return this._t(path33, cache, checkUnignored, slices);
363
363
  }
364
- _t(path30, cache, checkUnignored, slices) {
365
- if (path30 in cache) {
366
- return cache[path30];
364
+ _t(path33, cache, checkUnignored, slices) {
365
+ if (path33 in cache) {
366
+ return cache[path33];
367
367
  }
368
368
  if (!slices) {
369
- slices = path30.split(SLASH);
369
+ slices = path33.split(SLASH);
370
370
  }
371
371
  slices.pop();
372
372
  if (!slices.length) {
373
- return cache[path30] = this._testOne(path30, checkUnignored);
373
+ return cache[path33] = this._testOne(path33, checkUnignored);
374
374
  }
375
375
  const parent = this._t(
376
376
  slices.join(SLASH) + SLASH,
@@ -378,24 +378,24 @@ var require_ignore = __commonJS({
378
378
  checkUnignored,
379
379
  slices
380
380
  );
381
- return cache[path30] = parent.ignored ? parent : this._testOne(path30, checkUnignored);
381
+ return cache[path33] = parent.ignored ? parent : this._testOne(path33, checkUnignored);
382
382
  }
383
- ignores(path30) {
384
- return this._test(path30, this._ignoreCache, false).ignored;
383
+ ignores(path33) {
384
+ return this._test(path33, this._ignoreCache, false).ignored;
385
385
  }
386
386
  createFilter() {
387
- return (path30) => !this.ignores(path30);
387
+ return (path33) => !this.ignores(path33);
388
388
  }
389
389
  filter(paths) {
390
390
  return makeArray(paths).filter(this.createFilter());
391
391
  }
392
392
  // @returns {TestResult}
393
- test(path30) {
394
- return this._test(path30, this._testCache, true);
393
+ test(path33) {
394
+ return this._test(path33, this._testCache, true);
395
395
  }
396
396
  };
397
397
  var factory = (options) => new Ignore(options);
398
- var isPathValid = (path30) => checkPath(path30 && checkPath.convert(path30), path30, RETURN_FALSE);
398
+ var isPathValid = (path33) => checkPath(path33 && checkPath.convert(path33), path33, RETURN_FALSE);
399
399
  factory.isPathValid = isPathValid;
400
400
  factory.default = factory;
401
401
  module2.exports = factory;
@@ -406,7 +406,7 @@ var require_ignore = __commonJS({
406
406
  const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
407
407
  checkPath.convert = makePosix;
408
408
  const REGIX_IS_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
409
- checkPath.isNotRelative = (path30) => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path30) || isNotRelative(path30);
409
+ checkPath.isNotRelative = (path33) => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path33) || isNotRelative(path33);
410
410
  }
411
411
  }
412
412
  });
@@ -449,11 +449,11 @@ var require_Mime = __commonJS({
449
449
  }
450
450
  }
451
451
  };
452
- Mime.prototype.getType = function(path30) {
453
- path30 = String(path30);
454
- let last = path30.replace(/^.*[/\\]/, "").toLowerCase();
452
+ Mime.prototype.getType = function(path33) {
453
+ path33 = String(path33);
454
+ let last = path33.replace(/^.*[/\\]/, "").toLowerCase();
455
455
  let ext = last.replace(/^.*\./, "").toLowerCase();
456
- let hasPath = last.length < path30.length;
456
+ let hasPath = last.length < path33.length;
457
457
  let hasDot = ext.length < last.length - 1;
458
458
  return (hasDot || !hasPath) && this._types[ext] || null;
459
459
  };
@@ -520,6 +520,9 @@ __export(src_exports, {
520
520
  DispatchFetchDispatcher: () => DispatchFetchDispatcher,
521
521
  DurableObjectsOptionsSchema: () => DurableObjectsOptionsSchema,
522
522
  DurableObjectsSharedOptionsSchema: () => DurableObjectsSharedOptionsSchema,
523
+ EMAIL_PLUGIN: () => EMAIL_PLUGIN,
524
+ EMAIL_PLUGIN_NAME: () => EMAIL_PLUGIN_NAME,
525
+ EmailOptionsSchema: () => EmailOptionsSchema,
523
526
  ErrorEvent: () => ErrorEvent,
524
527
  File: () => import_undici4.File,
525
528
  FormData: () => import_undici4.FormData,
@@ -541,6 +544,7 @@ __export(src_exports, {
541
544
  LiteralSchema: () => LiteralSchema,
542
545
  Log: () => Log,
543
546
  LogLevel: () => LogLevel,
547
+ MAX_BULK_GET_KEYS: () => MAX_BULK_GET_KEYS,
544
548
  MessageEvent: () => MessageEvent,
545
549
  Miniflare: () => Miniflare2,
546
550
  MiniflareCoreError: () => MiniflareCoreError,
@@ -589,11 +593,15 @@ __export(src_exports, {
589
593
  Response: () => Response,
590
594
  RouterError: () => RouterError,
591
595
  Runtime: () => Runtime,
596
+ SECRET_STORE_PLUGIN: () => SECRET_STORE_PLUGIN,
597
+ SECRET_STORE_PLUGIN_NAME: () => SECRET_STORE_PLUGIN_NAME,
592
598
  SERVICE_ENTRY: () => SERVICE_ENTRY,
593
599
  SERVICE_LOOPBACK: () => SERVICE_LOOPBACK,
594
600
  SITES_NO_CACHE_PREFIX: () => SITES_NO_CACHE_PREFIX,
595
601
  SOCKET_ENTRY: () => SOCKET_ENTRY,
596
602
  SOCKET_ENTRY_LOCAL: () => SOCKET_ENTRY_LOCAL,
603
+ SecretsStoreSecretsOptionsSchema: () => SecretsStoreSecretsOptionsSchema,
604
+ SecretsStoreSecretsSharedOptionsSchema: () => SecretsStoreSecretsSharedOptionsSchema,
597
605
  SharedBindings: () => SharedBindings,
598
606
  SharedHeaders: () => SharedHeaders,
599
607
  SiteBindings: () => SiteBindings,
@@ -628,7 +636,7 @@ __export(src_exports, {
628
636
  deserialiseRegExps: () => deserialiseRegExps,
629
637
  deserialiseSiteRegExps: () => deserialiseSiteRegExps,
630
638
  encodeSitesKey: () => encodeSitesKey,
631
- fetch: () => fetch3,
639
+ fetch: () => fetch4,
632
640
  formatZodError: () => formatZodError,
633
641
  getAccessibleHosts: () => getAccessibleHosts,
634
642
  getAssetsBindingsNames: () => getAssetsBindingsNames,
@@ -683,11 +691,12 @@ __export(src_exports, {
683
691
  module.exports = __toCommonJS(src_exports);
684
692
  var import_assert12 = __toESM(require("assert"));
685
693
  var import_crypto3 = __toESM(require("crypto"));
686
- var import_fs24 = __toESM(require("fs"));
694
+ var import_fs27 = __toESM(require("fs"));
695
+ var import_promises13 = require("fs/promises");
687
696
  var import_http6 = __toESM(require("http"));
688
697
  var import_net = __toESM(require("net"));
689
698
  var import_os2 = __toESM(require("os"));
690
- var import_path28 = __toESM(require("path"));
699
+ var import_path31 = __toESM(require("path"));
691
700
  var import_web5 = require("stream/web");
692
701
  var import_util5 = __toESM(require("util"));
693
702
  var import_zlib = __toESM(require("zlib"));
@@ -770,8 +779,8 @@ function zod_worker_default() {
770
779
  }
771
780
 
772
781
  // src/index.ts
773
- var import_ws3 = require("ws");
774
- var import_zod23 = require("zod");
782
+ var import_ws5 = require("ws");
783
+ var import_zod25 = require("zod");
775
784
 
776
785
  // src/cf.ts
777
786
  var import_assert = __toESM(require("assert"));
@@ -909,7 +918,9 @@ var CoreBindings = {
909
918
  DATA_LIVE_RELOAD_SCRIPT: "MINIFLARE_LIVE_RELOAD_SCRIPT",
910
919
  DURABLE_OBJECT_NAMESPACE_PROXY: "MINIFLARE_PROXY",
911
920
  DATA_PROXY_SECRET: "MINIFLARE_PROXY_SECRET",
912
- DATA_PROXY_SHARED_SECRET: "MINIFLARE_PROXY_SHARED_SECRET"
921
+ DATA_PROXY_SHARED_SECRET: "MINIFLARE_PROXY_SHARED_SECRET",
922
+ TRIGGER_HANDLERS: "TRIGGER_HANDLERS",
923
+ LOG_REQUESTS: "LOG_REQUESTS"
913
924
  };
914
925
  var ProxyOps = {
915
926
  // Get the target or a property of the target
@@ -1354,12 +1365,12 @@ function createHTTPRevivers(impl) {
1354
1365
  },
1355
1366
  Request(value) {
1356
1367
  (0, import_node_assert.default)(Array.isArray(value));
1357
- const [method, url20, headers, cf, body] = value;
1368
+ const [method, url23, headers, cf, body] = value;
1358
1369
  (0, import_node_assert.default)(typeof method === "string");
1359
- (0, import_node_assert.default)(typeof url20 === "string");
1370
+ (0, import_node_assert.default)(typeof url23 === "string");
1360
1371
  (0, import_node_assert.default)(headers instanceof impl.Headers);
1361
1372
  (0, import_node_assert.default)(body === null || impl.isReadableStream(body));
1362
- return new impl.Request(url20, {
1373
+ return new impl.Request(url23, {
1363
1374
  method,
1364
1375
  headers,
1365
1376
  cf,
@@ -1485,19 +1496,19 @@ function parseWithReadableStreams(impl, stringified, revivers2) {
1485
1496
  }
1486
1497
 
1487
1498
  // src/workers/core/routing.ts
1488
- function matchRoutes(routes, url20) {
1499
+ function matchRoutes(routes, url23) {
1489
1500
  for (const route of routes) {
1490
- if (route.protocol && route.protocol !== url20.protocol) continue;
1501
+ if (route.protocol && route.protocol !== url23.protocol) continue;
1491
1502
  if (route.allowHostnamePrefix) {
1492
- if (!url20.hostname.endsWith(route.hostname)) continue;
1503
+ if (!url23.hostname.endsWith(route.hostname)) continue;
1493
1504
  } else {
1494
- if (url20.hostname !== route.hostname) continue;
1505
+ if (url23.hostname !== route.hostname) continue;
1495
1506
  }
1496
- const path30 = url20.pathname + url20.search;
1507
+ const path33 = url23.pathname + url23.search;
1497
1508
  if (route.allowPathSuffix) {
1498
- if (!path30.startsWith(route.path)) continue;
1509
+ if (!path33.startsWith(route.path)) continue;
1499
1510
  } else {
1500
- if (path30 !== route.path) continue;
1511
+ if (path33 !== route.path) continue;
1501
1512
  }
1502
1513
  return route.target;
1503
1514
  }
@@ -1697,7 +1708,8 @@ var KVLimits = {
1697
1708
  MAX_KEY_SIZE: 512,
1698
1709
  MAX_VALUE_SIZE: 25 * 1024 * 1024,
1699
1710
  MAX_VALUE_SIZE_TEST: 1024,
1700
- MAX_METADATA_SIZE: 1024
1711
+ MAX_METADATA_SIZE: 1024,
1712
+ MAX_BULK_SIZE: 25 * 1024 * 1024
1701
1713
  };
1702
1714
  var KVParams = {
1703
1715
  URL_ENCODED: "urlencoded",
@@ -1718,6 +1730,7 @@ var SiteBindings = {
1718
1730
  JSON_SITE_FILTER: "MINIFLARE_SITE_FILTER"
1719
1731
  };
1720
1732
  var SITES_NO_CACHE_PREFIX = "$__MINIFLARE_SITES__$/";
1733
+ var MAX_BULK_GET_KEYS = 100;
1721
1734
  function encodeSitesKey(key) {
1722
1735
  return SITES_NO_CACHE_PREFIX + encodeURIComponent(key);
1723
1736
  }
@@ -1725,8 +1738,8 @@ function decodeSitesKey(key) {
1725
1738
  return key.startsWith(SITES_NO_CACHE_PREFIX) ? decodeURIComponent(key.substring(SITES_NO_CACHE_PREFIX.length)) : key;
1726
1739
  }
1727
1740
  function isSitesRequest(request) {
1728
- const url20 = new URL(request.url);
1729
- return url20.pathname.startsWith(`/${SITES_NO_CACHE_PREFIX}`);
1741
+ const url23 = new URL(request.url);
1742
+ return url23.pathname.startsWith(`/${SITES_NO_CACHE_PREFIX}`);
1730
1743
  }
1731
1744
  function serialiseRegExp(regExp) {
1732
1745
  const str = regExp.toString();
@@ -1877,8 +1890,8 @@ var Response = class _Response extends import_undici3.Response {
1877
1890
  Object.setPrototypeOf(response, _Response.prototype);
1878
1891
  return response;
1879
1892
  }
1880
- static redirect(url20, status) {
1881
- const response = import_undici3.Response.redirect(url20, status);
1893
+ static redirect(url23, status) {
1894
+ const response = import_undici3.Response.redirect(url23, status);
1882
1895
  Object.setPrototypeOf(response, _Response.prototype);
1883
1896
  return response;
1884
1897
  }
@@ -2359,18 +2372,18 @@ function headersFromIncomingRequest(req) {
2359
2372
  );
2360
2373
  return new undici.Headers(Object.fromEntries(entries));
2361
2374
  }
2362
- async function fetch3(input, init2) {
2375
+ async function fetch4(input, init2) {
2363
2376
  const requestInit = init2;
2364
2377
  const request = new Request(input, requestInit);
2365
2378
  if (request.method === "GET" && request.headers.get("upgrade") === "websocket") {
2366
- const url20 = new URL(request.url);
2367
- if (url20.protocol !== "http:" && url20.protocol !== "https:") {
2379
+ const url23 = new URL(request.url);
2380
+ if (url23.protocol !== "http:" && url23.protocol !== "https:") {
2368
2381
  throw new TypeError(
2369
- `Fetch API cannot load: ${url20.toString()}.
2382
+ `Fetch API cannot load: ${url23.toString()}.
2370
2383
  Make sure you're using http(s):// URLs for WebSocket requests via fetch.`
2371
2384
  );
2372
2385
  }
2373
- url20.protocol = url20.protocol.replace("http", "ws");
2386
+ url23.protocol = url23.protocol.replace("http", "ws");
2374
2387
  const headers = {};
2375
2388
  let protocols;
2376
2389
  for (const [key, value] of request.headers.entries()) {
@@ -2382,10 +2395,10 @@ Make sure you're using http(s):// URLs for WebSocket requests via fetch.`
2382
2395
  }
2383
2396
  let rejectUnauthorized;
2384
2397
  if (requestInit.dispatcher instanceof DispatchFetchDispatcher) {
2385
- requestInit.dispatcher.addHeaders(headers, url20.pathname + url20.search);
2398
+ requestInit.dispatcher.addHeaders(headers, url23.pathname + url23.search);
2386
2399
  rejectUnauthorized = { rejectUnauthorized: false };
2387
2400
  }
2388
- const ws = new import_ws2.default(url20, protocols, {
2401
+ const ws = new import_ws2.default(url23, protocols, {
2389
2402
  followRedirects: request.redirect === "follow",
2390
2403
  headers,
2391
2404
  ...rejectUnauthorized
@@ -2441,8 +2454,8 @@ var DispatchFetchDispatcher = class extends undici.Dispatcher {
2441
2454
  if (cfBlob !== void 0) this.cfBlobJson = JSON.stringify(cfBlob);
2442
2455
  }
2443
2456
  cfBlobJson;
2444
- addHeaders(headers, path30) {
2445
- const originalURL = this.userRuntimeOrigin + path30;
2457
+ addHeaders(headers, path33) {
2458
+ const originalURL = this.userRuntimeOrigin + path33;
2446
2459
  addHeader(headers, CoreHeaders.ORIGINAL_URL, originalURL);
2447
2460
  addHeader(headers, CoreHeaders.DISABLE_PRETTY_ERROR, "true");
2448
2461
  if (this.cfBlobJson !== void 0) {
@@ -2454,16 +2467,16 @@ var DispatchFetchDispatcher = class extends undici.Dispatcher {
2454
2467
  if (origin === this.userRuntimeOrigin) origin = this.actualRuntimeOrigin;
2455
2468
  if (origin === this.actualRuntimeOrigin) {
2456
2469
  options.origin = origin;
2457
- let path30 = options.path;
2470
+ let path33 = options.path;
2458
2471
  if (options.query !== void 0) {
2459
- const url20 = new URL(path30, "http://placeholder/");
2472
+ const url23 = new URL(path33, "http://placeholder/");
2460
2473
  for (const [key, value] of Object.entries(options.query)) {
2461
- url20.searchParams.append(key, value);
2474
+ url23.searchParams.append(key, value);
2462
2475
  }
2463
- path30 = url20.pathname + url20.search;
2476
+ path33 = url23.pathname + url23.search;
2464
2477
  }
2465
2478
  options.headers ??= {};
2466
- this.addHeaders(options.headers, path30);
2479
+ this.addHeaders(options.headers, path33);
2467
2480
  return this.runtimeDispatcher.dispatch(options, handler);
2468
2481
  } else {
2469
2482
  return this.globalDispatcher.dispatch(options, handler);
@@ -2558,8 +2571,8 @@ function valueOrFile(value, filePath) {
2558
2571
  var import_os = require("os");
2559
2572
  function getAccessibleHosts(ipv4Only = false) {
2560
2573
  const hosts = [];
2561
- Object.values((0, import_os.networkInterfaces)()).forEach((net2) => {
2562
- net2?.forEach(({ family, address }) => {
2574
+ Object.values((0, import_os.networkInterfaces)()).forEach((net3) => {
2575
+ net3?.forEach(({ family, address }) => {
2563
2576
  if (family === "IPv4" || family === 4) {
2564
2577
  hosts.push(address);
2565
2578
  } else if (!ipv4Only) {
@@ -2816,13 +2829,14 @@ ${invalidHeaderRulesList}`
2816
2829
  }
2817
2830
  const rules = {};
2818
2831
  for (const rule of headers.rules) {
2819
- rules[rule.path] = {};
2832
+ const configuredRule = {};
2820
2833
  if (Object.keys(rule.headers).length) {
2821
- rules[rule.path].set = rule.headers;
2834
+ configuredRule.set = rule.headers;
2822
2835
  }
2823
2836
  if (rule.unsetHeaders.length) {
2824
- rules[rule.path].unset = rule.unsetHeaders;
2837
+ configuredRule.unset = rule.unsetHeaders;
2825
2838
  }
2839
+ rules[rule.path] = configuredRule;
2826
2840
  }
2827
2841
  return {
2828
2842
  headers: {
@@ -2833,12 +2847,12 @@ ${invalidHeaderRulesList}`
2833
2847
  }
2834
2848
 
2835
2849
  // ../workers-shared/utils/configuration/validateURL.ts
2836
- var extractPathname = (path30 = "/", includeSearch, includeHash) => {
2837
- if (!path30.startsWith("/")) {
2838
- path30 = `/${path30}`;
2850
+ var extractPathname = (path33 = "/", includeSearch, includeHash) => {
2851
+ if (!path33.startsWith("/")) {
2852
+ path33 = `/${path33}`;
2839
2853
  }
2840
- const url20 = new URL(`//${path30}`, "relative://");
2841
- return `${url20.pathname}${includeSearch ? url20.search : ""}${includeHash ? url20.hash : ""}`;
2854
+ const url23 = new URL(`//${path33}`, "relative://");
2855
+ return `${url23.pathname}${includeSearch ? url23.search : ""}${includeHash ? url23.hash : ""}`;
2842
2856
  };
2843
2857
  var URL_REGEX = /^https:\/\/+(?<host>[^/]+)\/?(?<path>.*)/;
2844
2858
  var HOST_WITH_PORT_REGEX = /.*:\d+$/;
@@ -2870,8 +2884,8 @@ var validateUrl = (token, onlyRelative = false, disallowPorts = false, includeSe
2870
2884
  if (!token.startsWith("/") && onlyRelative) {
2871
2885
  token = `/${token}`;
2872
2886
  }
2873
- const path30 = PATH_REGEX.exec(token);
2874
- if (path30) {
2887
+ const path33 = PATH_REGEX.exec(token);
2888
+ if (path33) {
2875
2889
  try {
2876
2890
  return [extractPathname(token, includeSearch, includeHash), void 0];
2877
2891
  } catch {
@@ -2891,26 +2905,29 @@ function urlHasHost(token) {
2891
2905
 
2892
2906
  // ../workers-shared/utils/configuration/parseHeaders.ts
2893
2907
  var LINE_IS_PROBABLY_A_PATH = new RegExp(/^([^\s]+:\/\/|^\/)/);
2894
- function parseHeaders(input) {
2908
+ function parseHeaders(input, {
2909
+ maxRules = MAX_HEADER_RULES,
2910
+ maxLineLength = MAX_LINE_LENGTH
2911
+ } = {}) {
2895
2912
  const lines = input.split("\n");
2896
2913
  const rules = [];
2897
2914
  const invalid = [];
2898
2915
  let rule = void 0;
2899
2916
  for (let i = 0; i < lines.length; i++) {
2900
- const line = lines[i].trim();
2917
+ const line = (lines[i] || "").trim();
2901
2918
  if (line.length === 0 || line.startsWith("#")) {
2902
2919
  continue;
2903
2920
  }
2904
- if (line.length > MAX_LINE_LENGTH) {
2921
+ if (line.length > maxLineLength) {
2905
2922
  invalid.push({
2906
- message: `Ignoring line ${i + 1} as it exceeds the maximum allowed length of ${MAX_LINE_LENGTH}.`
2923
+ message: `Ignoring line ${i + 1} as it exceeds the maximum allowed length of ${maxLineLength}.`
2907
2924
  });
2908
2925
  continue;
2909
2926
  }
2910
2927
  if (LINE_IS_PROBABLY_A_PATH.test(line)) {
2911
- if (rules.length >= MAX_HEADER_RULES) {
2928
+ if (rules.length >= maxRules) {
2912
2929
  invalid.push({
2913
- message: `Maximum number of rules supported is ${MAX_HEADER_RULES}. Skipping remaining ${lines.length - i} lines of file.`
2930
+ message: `Maximum number of rules supported is ${maxRules}. Skipping remaining ${lines.length - i} lines of file.`
2914
2931
  });
2915
2932
  break;
2916
2933
  }
@@ -2929,7 +2946,7 @@ function parseHeaders(input) {
2929
2946
  });
2930
2947
  }
2931
2948
  }
2932
- const [path30, pathError] = validateUrl(line, false, true);
2949
+ const [path33, pathError] = validateUrl(line, false, true);
2933
2950
  if (pathError) {
2934
2951
  invalid.push({
2935
2952
  line,
@@ -2940,7 +2957,7 @@ function parseHeaders(input) {
2940
2957
  continue;
2941
2958
  }
2942
2959
  rule = {
2943
- path: path30,
2960
+ path: path33,
2944
2961
  line,
2945
2962
  headers: {},
2946
2963
  unsetHeaders: []
@@ -2968,7 +2985,7 @@ function parseHeaders(input) {
2968
2985
  continue;
2969
2986
  }
2970
2987
  const [rawName, ...rawValue] = line.split(HEADER_SEPARATOR);
2971
- const name = rawName.trim().toLowerCase();
2988
+ const name = (rawName || "").trim().toLowerCase();
2972
2989
  if (name.includes(" ")) {
2973
2990
  invalid.push({
2974
2991
  line,
@@ -3026,7 +3043,11 @@ function isValidRule(rule) {
3026
3043
  }
3027
3044
 
3028
3045
  // ../workers-shared/utils/configuration/parseRedirects.ts
3029
- function parseRedirects(input) {
3046
+ function parseRedirects(input, {
3047
+ maxStaticRules = MAX_STATIC_REDIRECT_RULES,
3048
+ maxDynamicRules = MAX_DYNAMIC_REDIRECT_RULES,
3049
+ maxLineLength = MAX_LINE_LENGTH
3050
+ } = {}) {
3030
3051
  const lines = input.split("\n");
3031
3052
  const rules = [];
3032
3053
  const seen_paths = /* @__PURE__ */ new Set();
@@ -3035,13 +3056,13 @@ function parseRedirects(input) {
3035
3056
  let dynamicRules = 0;
3036
3057
  let canCreateStaticRule = true;
3037
3058
  for (let i = 0; i < lines.length; i++) {
3038
- const line = lines[i].trim();
3059
+ const line = (lines[i] || "").trim();
3039
3060
  if (line.length === 0 || line.startsWith("#")) {
3040
3061
  continue;
3041
3062
  }
3042
- if (line.length > MAX_LINE_LENGTH) {
3063
+ if (line.length > maxLineLength) {
3043
3064
  invalid.push({
3044
- message: `Ignoring line ${i + 1} as it exceeds the maximum allowed length of ${MAX_LINE_LENGTH}.`
3065
+ message: `Ignoring line ${i + 1} as it exceeds the maximum allowed length of ${maxLineLength}.`
3045
3066
  });
3046
3067
  continue;
3047
3068
  }
@@ -3067,18 +3088,18 @@ function parseRedirects(input) {
3067
3088
  const from = fromResult[0];
3068
3089
  if (canCreateStaticRule && !from.match(SPLAT_REGEX) && !from.match(PLACEHOLDER_REGEX)) {
3069
3090
  staticRules += 1;
3070
- if (staticRules > MAX_STATIC_REDIRECT_RULES) {
3091
+ if (staticRules > maxStaticRules) {
3071
3092
  invalid.push({
3072
- message: `Maximum number of static rules supported is ${MAX_STATIC_REDIRECT_RULES}. Skipping line.`
3093
+ message: `Maximum number of static rules supported is ${maxStaticRules}. Skipping line.`
3073
3094
  });
3074
3095
  continue;
3075
3096
  }
3076
3097
  } else {
3077
3098
  dynamicRules += 1;
3078
3099
  canCreateStaticRule = false;
3079
- if (dynamicRules > MAX_DYNAMIC_REDIRECT_RULES) {
3100
+ if (dynamicRules > maxDynamicRules) {
3080
3101
  invalid.push({
3081
- message: `Maximum number of dynamic rules supported is ${MAX_DYNAMIC_REDIRECT_RULES}. Skipping remaining ${lines.length - i} lines of file.`
3102
+ message: `Maximum number of dynamic rules supported is ${maxDynamicRules}. Skipping remaining ${lines.length - i} lines of file.`
3082
3103
  });
3083
3104
  break;
3084
3105
  }
@@ -10093,11 +10114,11 @@ var kUnsafeEphemeralUniqueKey = Symbol.for(
10093
10114
  var import_url12 = require("url");
10094
10115
  var RouterError = class extends MiniflareError {
10095
10116
  };
10096
- function routeSpecificity(url20) {
10097
- const hostParts = url20.host.split(".");
10117
+ function routeSpecificity(url23) {
10118
+ const hostParts = url23.host.split(".");
10098
10119
  let hostScore = hostParts.length;
10099
10120
  if (hostParts[0] === "*") hostScore -= 2;
10100
- const pathParts = url20.pathname.split("/");
10121
+ const pathParts = url23.pathname.split("/");
10101
10122
  let pathScore = pathParts.length;
10102
10123
  if (pathParts[pathParts.length - 1] === "*") pathScore -= 2;
10103
10124
  return hostScore * 26 + pathScore;
@@ -10109,30 +10130,30 @@ function parseRoutes(allRoutes) {
10109
10130
  const hasProtocol = /^[a-z0-9+\-.]+:\/\//i.test(route);
10110
10131
  let urlInput = route;
10111
10132
  if (!hasProtocol) urlInput = `https://${urlInput}`;
10112
- const url20 = new import_url12.URL(urlInput);
10113
- const specificity = routeSpecificity(url20);
10114
- const protocol = hasProtocol ? url20.protocol : void 0;
10115
- const internationalisedAllowHostnamePrefix = url20.hostname.startsWith("xn--*");
10116
- const allowHostnamePrefix = url20.hostname.startsWith("*") || internationalisedAllowHostnamePrefix;
10117
- const anyHostname = url20.hostname === "*";
10133
+ const url23 = new import_url12.URL(urlInput);
10134
+ const specificity = routeSpecificity(url23);
10135
+ const protocol = hasProtocol ? url23.protocol : void 0;
10136
+ const internationalisedAllowHostnamePrefix = url23.hostname.startsWith("xn--*");
10137
+ const allowHostnamePrefix = url23.hostname.startsWith("*") || internationalisedAllowHostnamePrefix;
10138
+ const anyHostname = url23.hostname === "*";
10118
10139
  if (allowHostnamePrefix && !anyHostname) {
10119
- let hostname = url20.hostname;
10140
+ let hostname = url23.hostname;
10120
10141
  if (internationalisedAllowHostnamePrefix) {
10121
10142
  hostname = (0, import_url12.domainToUnicode)(hostname);
10122
10143
  }
10123
- url20.hostname = hostname.substring(1);
10144
+ url23.hostname = hostname.substring(1);
10124
10145
  }
10125
- const allowPathSuffix = url20.pathname.endsWith("*");
10146
+ const allowPathSuffix = url23.pathname.endsWith("*");
10126
10147
  if (allowPathSuffix) {
10127
- url20.pathname = url20.pathname.substring(0, url20.pathname.length - 1);
10148
+ url23.pathname = url23.pathname.substring(0, url23.pathname.length - 1);
10128
10149
  }
10129
- if (url20.search) {
10150
+ if (url23.search) {
10130
10151
  throw new RouterError(
10131
10152
  "ERR_QUERY_STRING",
10132
10153
  `Route "${route}" for "${target}" contains a query string. This is not allowed.`
10133
10154
  );
10134
10155
  }
10135
- if (url20.toString().includes("*") && !anyHostname) {
10156
+ if (url23.toString().includes("*") && !anyHostname) {
10136
10157
  throw new RouterError(
10137
10158
  "ERR_INFIX_WILDCARD",
10138
10159
  `Route "${route}" for "${target}" contains an infix wildcard. This is not allowed.`
@@ -10144,8 +10165,8 @@ function parseRoutes(allRoutes) {
10144
10165
  specificity,
10145
10166
  protocol,
10146
10167
  allowHostnamePrefix,
10147
- hostname: anyHostname ? "" : url20.hostname,
10148
- path: url20.pathname,
10168
+ hostname: anyHostname ? "" : url23.hostname,
10169
+ path: url23.pathname,
10149
10170
  allowPathSuffix
10150
10171
  });
10151
10172
  }
@@ -10186,10 +10207,10 @@ function namespaceEntries(namespaces) {
10186
10207
  return [];
10187
10208
  }
10188
10209
  }
10189
- function maybeParseURL(url20) {
10190
- if (typeof url20 !== "string" || import_path15.default.isAbsolute(url20)) return;
10210
+ function maybeParseURL(url23) {
10211
+ if (typeof url23 !== "string" || import_path15.default.isAbsolute(url23)) return;
10191
10212
  try {
10192
- return new URL(url20);
10213
+ return new URL(url23);
10193
10214
  } catch {
10194
10215
  }
10195
10216
  }
@@ -10198,16 +10219,16 @@ function getPersistPath(pluginName, tmpPath, persist) {
10198
10219
  if (persist === void 0 || persist === false) {
10199
10220
  return memoryishPath;
10200
10221
  }
10201
- const url20 = maybeParseURL(persist);
10202
- if (url20 !== void 0) {
10203
- if (url20.protocol === "memory:") {
10222
+ const url23 = maybeParseURL(persist);
10223
+ if (url23 !== void 0) {
10224
+ if (url23.protocol === "memory:") {
10204
10225
  return memoryishPath;
10205
- } else if (url20.protocol === "file:") {
10206
- return (0, import_url13.fileURLToPath)(url20);
10226
+ } else if (url23.protocol === "file:") {
10227
+ return (0, import_url13.fileURLToPath)(url23);
10207
10228
  }
10208
10229
  throw new MiniflareCoreError(
10209
10230
  "ERR_PERSIST_UNSUPPORTED",
10210
- `Unsupported "${url20.protocol}" persistence protocol for storage: ${url20.href}`
10231
+ `Unsupported "${url23.protocol}" persistence protocol for storage: ${url23.href}`
10211
10232
  );
10212
10233
  }
10213
10234
  return persist === true ? import_path15.default.join(DEFAULT_PERSIST_ROOT, pluginName) : persist;
@@ -10541,7 +10562,7 @@ function parseNodeCompatibilityFlags(compatibilityFlags) {
10541
10562
 
10542
10563
  // src/plugins/core/modules.ts
10543
10564
  var SUGGEST_BUNDLE = "If you're trying to import an npm package, you'll need to bundle your Worker first.";
10544
- var SUGGEST_NODE = "If you're trying to import a Node.js built-in module, or an npm package that uses Node.js built-ins, you'll either need to:\n- Bundle your Worker, configuring your bundler to polyfill Node.js built-ins\n- Configure your bundler to load Workers-compatible builds by changing the main fields/conditions\n- Enable the `nodejs_compat` compatibility flag and use the `NodeJsCompatModule` module type\n- Find an alternative package that doesn't require Node.js built-ins";
10565
+ var SUGGEST_NODE = "If you're trying to import a Node.js built-in module, or an npm package that uses Node.js built-ins, you'll either need to:\n- Bundle your Worker, configuring your bundler to polyfill Node.js built-ins\n- Configure your bundler to load Workers-compatible builds by changing the main fields/conditions\n- Enable the `nodejs_compat` compatibility flag\n- Find an alternative package that doesn't require Node.js built-ins";
10545
10566
  var builtinModulesWithPrefix = import_module.builtinModules.concat(
10546
10567
  import_module.builtinModules.map((module2) => `node:${module2}`)
10547
10568
  );
@@ -10556,7 +10577,6 @@ function maybeGetStringScriptPathIndex(scriptPath) {
10556
10577
  var ModuleRuleTypeSchema = import_zod9.z.enum([
10557
10578
  "ESModule",
10558
10579
  "CommonJS",
10559
- "NodeJsCompatModule",
10560
10580
  "Text",
10561
10581
  "Data",
10562
10582
  "CompiledWasm",
@@ -10736,12 +10756,11 @@ ${dim(modulesConfig)}`;
10736
10756
  throw new MiniflareCoreError("ERR_MODULE_DYNAMIC_SPEC", message);
10737
10757
  }
10738
10758
  const spec = specExpression.value;
10739
- const isNodeJsCompatModule = referencingType === "NodeJsCompatModule";
10740
10759
  if (
10741
10760
  // `cloudflare:` and `workerd:` imports don't need to be included explicitly
10742
10761
  spec.startsWith("cloudflare:") || spec.startsWith("workerd:") || // Node.js compat v1 requires imports to be prefixed with `node:`
10743
10762
  this.#nodejsCompatMode === "v1" && spec.startsWith("node:") || // Node.js compat modules and v2 can also handle non-prefixed imports
10744
- (this.#nodejsCompatMode === "v2" || isNodeJsCompatModule) && builtinModulesWithPrefix.includes(spec) || // Async Local Storage mode (node_als) only deals with `node:async_hooks` imports
10763
+ this.#nodejsCompatMode === "v2" && builtinModulesWithPrefix.includes(spec) || // Async Local Storage mode (node_als) only deals with `node:async_hooks` imports
10745
10764
  this.#nodejsCompatMode === "als" && spec === "node:async_hooks" || // Any "additional" external modules can be ignored
10746
10765
  this.additionalModuleNames.includes(spec)
10747
10766
  ) {
@@ -10775,7 +10794,6 @@ ${suggestion}`
10775
10794
  switch (rule.type) {
10776
10795
  case "ESModule":
10777
10796
  case "CommonJS":
10778
- case "NodeJsCompatModule":
10779
10797
  const code = data.toString("utf8");
10780
10798
  this.#visitJavaScriptModule(code, identifier, rule.type);
10781
10799
  break;
@@ -10806,61 +10824,56 @@ function createJavaScriptModule(code, name, modulePath, type) {
10806
10824
  return { name, esModule: code };
10807
10825
  } else if (type === "CommonJS") {
10808
10826
  return { name, commonJsModule: code };
10809
- } else if (type === "NodeJsCompatModule") {
10810
- return { name, nodeJsCompatModule: code };
10811
10827
  }
10812
10828
  const exhaustive = type;
10813
10829
  import_assert5.default.fail(`Unreachable: ${exhaustive} JavaScript modules are unsupported`);
10814
10830
  }
10815
10831
  var encoder = new import_util.TextEncoder();
10816
10832
  var decoder = new import_util.TextDecoder();
10817
- function contentsToString(contents20) {
10818
- return typeof contents20 === "string" ? contents20 : decoder.decode(contents20);
10833
+ function contentsToString(contents23) {
10834
+ return typeof contents23 === "string" ? contents23 : decoder.decode(contents23);
10819
10835
  }
10820
- function contentsToArray(contents20) {
10821
- return typeof contents20 === "string" ? encoder.encode(contents20) : contents20;
10836
+ function contentsToArray(contents23) {
10837
+ return typeof contents23 === "string" ? encoder.encode(contents23) : contents23;
10822
10838
  }
10823
10839
  function convertModuleDefinition(modulesRoot, def) {
10824
10840
  const name = moduleName(modulesRoot, def.path);
10825
- const contents20 = def.contents ?? (0, import_fs13.readFileSync)(def.path);
10841
+ const contents23 = def.contents ?? (0, import_fs13.readFileSync)(def.path);
10826
10842
  switch (def.type) {
10827
10843
  case "ESModule":
10828
10844
  case "CommonJS":
10829
- case "NodeJsCompatModule":
10830
10845
  return createJavaScriptModule(
10831
- contentsToString(contents20),
10846
+ contentsToString(contents23),
10832
10847
  name,
10833
10848
  import_path16.default.resolve(modulesRoot, def.path),
10834
10849
  def.type
10835
10850
  );
10836
10851
  case "Text":
10837
- return { name, text: contentsToString(contents20) };
10852
+ return { name, text: contentsToString(contents23) };
10838
10853
  case "Data":
10839
- return { name, data: contentsToArray(contents20) };
10854
+ return { name, data: contentsToArray(contents23) };
10840
10855
  case "CompiledWasm":
10841
- return { name, wasm: contentsToArray(contents20) };
10856
+ return { name, wasm: contentsToArray(contents23) };
10842
10857
  case "PythonModule":
10843
- return { name, pythonModule: contentsToString(contents20) };
10858
+ return { name, pythonModule: contentsToString(contents23) };
10844
10859
  case "PythonRequirement":
10845
- return { name, pythonRequirement: contentsToString(contents20) };
10860
+ return { name, pythonRequirement: contentsToString(contents23) };
10846
10861
  default:
10847
10862
  const exhaustive = def.type;
10848
10863
  import_assert5.default.fail(`Unreachable: ${exhaustive} modules are unsupported`);
10849
10864
  }
10850
10865
  }
10851
10866
  function convertWorkerModule(mod) {
10852
- const path30 = mod.name;
10853
- (0, import_assert5.default)(path30 !== void 0);
10867
+ const path33 = mod.name;
10868
+ (0, import_assert5.default)(path33 !== void 0);
10854
10869
  const m = mod;
10855
- if ("esModule" in m) return { path: path30, type: "ESModule" };
10856
- else if ("commonJsModule" in m) return { path: path30, type: "CommonJS" };
10857
- else if ("nodeJsCompatModule" in m)
10858
- return { path: path30, type: "NodeJsCompatModule" };
10859
- else if ("text" in m) return { path: path30, type: "Text" };
10860
- else if ("data" in m) return { path: path30, type: "Data" };
10861
- else if ("wasm" in m) return { path: path30, type: "CompiledWasm" };
10862
- else if ("pythonModule" in m) return { path: path30, type: "PythonModule" };
10863
- else if ("pythonRequirement" in m) return { path: path30, type: "PythonRequirement" };
10870
+ if ("esModule" in m) return { path: path33, type: "ESModule" };
10871
+ else if ("commonJsModule" in m) return { path: path33, type: "CommonJS" };
10872
+ else if ("text" in m) return { path: path33, type: "Text" };
10873
+ else if ("data" in m) return { path: path33, type: "Data" };
10874
+ else if ("wasm" in m) return { path: path33, type: "CompiledWasm" };
10875
+ else if ("pythonModule" in m) return { path: path33, type: "PythonModule" };
10876
+ else if ("pythonRequirement" in m) return { path: path33, type: "PythonRequirement" };
10864
10877
  (0, import_assert5.default)(
10865
10878
  !("json" in m || "fallbackService" in m),
10866
10879
  "Unreachable: json or fallbackService modules aren't generated"
@@ -11061,8 +11074,8 @@ function getSourceMapper() {
11061
11074
  // src/plugins/core/errors/index.ts
11062
11075
  function maybeGetDiskFile(filePath) {
11063
11076
  try {
11064
- const contents20 = import_fs14.default.readFileSync(filePath, "utf8");
11065
- return { path: filePath, contents: contents20 };
11077
+ const contents23 = import_fs14.default.readFileSync(filePath, "utf8");
11078
+ return { path: filePath, contents: contents23 };
11066
11079
  } catch (e) {
11067
11080
  if (e.code !== "ENOENT") throw e;
11068
11081
  }
@@ -11076,8 +11089,8 @@ function maybeGetFile2(workerSrcOpts, fileSpecifier) {
11076
11089
  const modulesRoot = srcOpts.modulesRoot ?? "";
11077
11090
  for (const module2 of srcOpts.modules) {
11078
11091
  if (module2.contents !== void 0 && import_path17.default.resolve(modulesRoot, module2.path) === filePath) {
11079
- const contents20 = contentsToString(module2.contents);
11080
- return { path: filePath, contents: contents20 };
11092
+ const contents23 = contentsToString(module2.contents);
11093
+ return { path: filePath, contents: contents23 };
11081
11094
  }
11082
11095
  }
11083
11096
  } else if ("script" in srcOpts && "scriptPath" in srcOpts && srcOpts.script !== void 0 && srcOpts.scriptPath !== void 0) {
@@ -11256,7 +11269,7 @@ var SynchronousFetcher = class {
11256
11269
  transferList: [this.#channel.port2]
11257
11270
  });
11258
11271
  }
11259
- fetch(url20, init2) {
11272
+ fetch(url23, init2) {
11260
11273
  this.#ensureWorker();
11261
11274
  Atomics.store(
11262
11275
  this.#notifyHandle,
@@ -11269,7 +11282,7 @@ var SynchronousFetcher = class {
11269
11282
  this.#channel.port1.postMessage({
11270
11283
  id,
11271
11284
  method: init2.method,
11272
- url: url20.toString(),
11285
+ url: url23.toString(),
11273
11286
  headers: init2.headers,
11274
11287
  body: init2.body
11275
11288
  });
@@ -11389,8 +11402,8 @@ var ProxyClient = class {
11389
11402
  }
11390
11403
  };
11391
11404
  var ProxyClientBridge = class {
11392
- constructor(url20, dispatchFetch) {
11393
- this.url = url20;
11405
+ constructor(url23, dispatchFetch) {
11406
+ this.url = url23;
11394
11407
  this.dispatchFetch = dispatchFetch;
11395
11408
  this.#finalizationRegistry = new FinalizationRegistry(this.#finalizeProxy);
11396
11409
  }
@@ -11884,6 +11897,7 @@ var CoreOptionsSchemaInput = import_zod12.z.intersection(
11884
11897
  rootPath: UnusableStringSchema.optional(),
11885
11898
  compatibilityDate: import_zod12.z.string().optional(),
11886
11899
  compatibilityFlags: import_zod12.z.string().array().optional(),
11900
+ unsafeInspectorProxy: import_zod12.z.boolean().optional(),
11887
11901
  routes: import_zod12.z.string().array().optional(),
11888
11902
  bindings: import_zod12.z.record(JsonSchema).optional(),
11889
11903
  wasmBindings: import_zod12.z.record(import_zod12.z.union([PathSchema, import_zod12.z.instanceof(Uint8Array)])).optional(),
@@ -11902,8 +11916,7 @@ var CoreOptionsSchemaInput = import_zod12.z.intersection(
11902
11916
  (If there are assets but we're not using vitest, the miniflare entry worker can point directly to
11903
11917
  Router Worker)
11904
11918
  */
11905
- hasAssetsAndIsVitest: import_zod12.z.boolean().optional(),
11906
- unsafeEnableAssetsRpc: import_zod12.z.boolean().optional()
11919
+ hasAssetsAndIsVitest: import_zod12.z.boolean().optional()
11907
11920
  })
11908
11921
  );
11909
11922
  var CoreOptionsSchema = CoreOptionsSchemaInput.transform((value) => {
@@ -11916,7 +11929,7 @@ var CoreOptionsSchema = CoreOptionsSchemaInput.transform((value) => {
11916
11929
  );
11917
11930
  }
11918
11931
  value.fetchMock = void 0;
11919
- value.outboundService = (req) => fetch3(req, { dispatcher: fetchMock });
11932
+ value.outboundService = (req) => fetch4(req, { dispatcher: fetchMock });
11920
11933
  }
11921
11934
  return value;
11922
11935
  });
@@ -11944,7 +11957,10 @@ var CoreSharedOptionsSchema = import_zod12.z.object({
11944
11957
  unsafeModuleFallbackService: ServiceFetchSchema.optional(),
11945
11958
  // Keep blobs when deleting/overwriting keys, required for stacked storage
11946
11959
  unsafeStickyBlobs: import_zod12.z.boolean().optional(),
11947
- unsafeEnableAssetsRpc: import_zod12.z.boolean().optional()
11960
+ // Enable directly triggering user Worker handlers with paths like `/cdn-cgi/handler/scheduled`
11961
+ unsafeTriggerHandlers: import_zod12.z.boolean().optional(),
11962
+ // Enable logging requests
11963
+ logRequests: import_zod12.z.boolean().default(true)
11948
11964
  });
11949
11965
  var CORE_PLUGIN_NAME2 = "core";
11950
11966
  var LIVE_RELOAD_SCRIPT_TEMPLATE = (port) => `<script defer type="application/javascript">
@@ -11970,7 +11986,7 @@ var SCRIPT_CUSTOM_SERVICE = `addEventListener("fetch", (event) => {
11970
11986
  request.headers.set("${CoreHeaders.ORIGINAL_URL}", request.url);
11971
11987
  event.respondWith(${CoreBindings.SERVICE_LOOPBACK}.fetch(request));
11972
11988
  })`;
11973
- function getCustomServiceDesignator(refererName, workerIndex, kind, name, service, hasAssetsAndIsVitest = false, unsafeEnableAssetsRpc = false) {
11989
+ function getCustomServiceDesignator(refererName, workerIndex, kind, name, service, hasAssetsAndIsVitest = false) {
11974
11990
  let serviceName;
11975
11991
  let entrypoint;
11976
11992
  if (typeof service === "function") {
@@ -11987,7 +12003,7 @@ function getCustomServiceDesignator(refererName, workerIndex, kind, name, servic
11987
12003
  serviceName = getBuiltinServiceName(workerIndex, kind, name);
11988
12004
  }
11989
12005
  } else if (service === kCurrentWorker) {
11990
- serviceName = hasAssetsAndIsVitest ? unsafeEnableAssetsRpc ? `${RPC_PROXY_SERVICE_NAME}:${refererName}` : `${ROUTER_SERVICE_NAME}:${refererName}` : getUserServiceName(refererName);
12006
+ serviceName = hasAssetsAndIsVitest ? `${RPC_PROXY_SERVICE_NAME}:${refererName}` : getUserServiceName(refererName);
11991
12007
  } else {
11992
12008
  serviceName = getUserServiceName(service);
11993
12009
  }
@@ -12085,7 +12101,7 @@ var CORE_PLUGIN = {
12085
12101
  if (options.textBlobBindings !== void 0) {
12086
12102
  bindings.push(
12087
12103
  ...Object.entries(options.textBlobBindings).map(
12088
- ([name, path30]) => import_promises6.default.readFile(path30, "utf8").then((text) => ({ name, text }))
12104
+ ([name, path33]) => import_promises6.default.readFile(path33, "utf8").then((text) => ({ name, text }))
12089
12105
  )
12090
12106
  );
12091
12107
  }
@@ -12108,8 +12124,7 @@ var CORE_PLUGIN = {
12108
12124
  "#" /* UNKNOWN */,
12109
12125
  name,
12110
12126
  service,
12111
- options.hasAssetsAndIsVitest,
12112
- options.unsafeEnableAssetsRpc
12127
+ options.hasAssetsAndIsVitest
12113
12128
  )
12114
12129
  };
12115
12130
  })
@@ -12159,7 +12174,7 @@ var CORE_PLUGIN = {
12159
12174
  if (options.textBlobBindings !== void 0) {
12160
12175
  bindingEntries3.push(
12161
12176
  ...Object.entries(options.textBlobBindings).map(
12162
- ([name, path30]) => import_promises6.default.readFile(path30, "utf8").then((text) => [name, text])
12177
+ ([name, path33]) => import_promises6.default.readFile(path33, "utf8").then((text) => [name, text])
12163
12178
  )
12164
12179
  );
12165
12180
  }
@@ -12332,8 +12347,7 @@ Ensure ${stringName} doesn't include unbundled \`import\`s.`
12332
12347
  "$" /* KNOWN */,
12333
12348
  CUSTOM_SERVICE_KNOWN_OUTBOUND,
12334
12349
  options.outboundService,
12335
- options.hasAssetsAndIsVitest,
12336
- options.unsafeEnableAssetsRpc
12350
+ options.hasAssetsAndIsVitest
12337
12351
  ),
12338
12352
  cacheApiOutbound: { name: getCacheServiceName(workerIndex) },
12339
12353
  moduleFallback: options.unsafeUseModuleFallbackService && sharedOptions.unsafeModuleFallbackService !== void 0 ? `localhost:${loopbackPort}` : void 0
@@ -12377,6 +12391,14 @@ function getGlobalServices({
12377
12391
  WORKER_BINDING_SERVICE_LOOPBACK,
12378
12392
  // For converting stack-traces to pretty-error pages
12379
12393
  { name: CoreBindings.JSON_ROUTES, json: JSON.stringify(routes) },
12394
+ {
12395
+ name: CoreBindings.TRIGGER_HANDLERS,
12396
+ json: JSON.stringify(!!sharedOptions.unsafeTriggerHandlers)
12397
+ },
12398
+ {
12399
+ name: CoreBindings.LOG_REQUESTS,
12400
+ json: JSON.stringify(!!sharedOptions.logRequests)
12401
+ },
12380
12402
  { name: CoreBindings.JSON_CF_BLOB, json: JSON.stringify(sharedOptions.cf) },
12381
12403
  { name: CoreBindings.JSON_LOG_LEVEL, json: JSON.stringify(log.level) },
12382
12404
  {
@@ -12426,13 +12448,8 @@ function getGlobalServices({
12426
12448
  name: SERVICE_ENTRY,
12427
12449
  worker: {
12428
12450
  modules: [{ name: "entry.worker.js", esModule: entry_worker_default() }],
12429
- compatibilityDate: "2023-04-04",
12430
- compatibilityFlags: [
12431
- "nodejs_compat",
12432
- "service_binding_extra_handlers",
12433
- "brotli_content_encoding",
12434
- "rpc"
12435
- ],
12451
+ compatibilityDate: "2025-03-17",
12452
+ compatibilityFlags: ["nodejs_compat", "service_binding_extra_handlers"],
12436
12453
  bindings: serviceEntryBindings,
12437
12454
  durableObjectNamespaces: [
12438
12455
  {
@@ -12515,8 +12532,13 @@ var AssetsOptionsSchema = import_zod13.z.object({
12515
12532
  directory: PathSchema,
12516
12533
  binding: import_zod13.z.string().optional(),
12517
12534
  routerConfig: RouterConfigSchema.optional(),
12518
- assetConfig: AssetConfigSchema.optional()
12519
- }).optional()
12535
+ assetConfig: AssetConfigSchema.omit({
12536
+ compatibility_date: true,
12537
+ compatibility_flags: true
12538
+ }).optional()
12539
+ }).optional(),
12540
+ compatibilityDate: import_zod13.z.string().optional(),
12541
+ compatibilityFlags: import_zod13.z.string().array().optional()
12520
12542
  });
12521
12543
 
12522
12544
  // src/plugins/assets/index.ts
@@ -12544,14 +12566,18 @@ var ASSETS_PLUGIN = {
12544
12566
  [options.assets.binding]: new ProxyNodeBinding()
12545
12567
  };
12546
12568
  },
12547
- async getServices({ options, unsafeEnableAssetsRpc }) {
12569
+ async getServices({ options }) {
12548
12570
  if (!options.assets) {
12549
12571
  return [];
12550
12572
  }
12551
12573
  const storageServiceName = `${ASSETS_PLUGIN_NAME}:storage`;
12552
12574
  const storageService = {
12553
12575
  name: storageServiceName,
12554
- disk: { path: options.assets.directory, writable: true }
12576
+ disk: {
12577
+ path: options.assets.directory,
12578
+ writable: true,
12579
+ allowDotfiles: true
12580
+ }
12555
12581
  };
12556
12582
  const { encodedAssetManifest, assetsReverseMap } = await buildAssetManifest(
12557
12583
  options.assets.directory
@@ -12591,6 +12617,8 @@ var ASSETS_PLUGIN = {
12591
12617
  );
12592
12618
  }
12593
12619
  const assetConfig = {
12620
+ compatibility_date: options.compatibilityDate,
12621
+ compatibility_flags: options.compatibilityFlags,
12594
12622
  ...options.assets.assetConfig,
12595
12623
  redirects: parsedRedirects,
12596
12624
  headers: parsedHeaders
@@ -12679,36 +12707,39 @@ var ASSETS_PLUGIN = {
12679
12707
  ]
12680
12708
  }
12681
12709
  };
12682
- const services = [
12710
+ const assetsProxyService = {
12711
+ name: `${RPC_PROXY_SERVICE_NAME}:${id}`,
12712
+ worker: {
12713
+ compatibilityDate: "2024-08-01",
12714
+ modules: [
12715
+ {
12716
+ name: "assets-proxy-worker.mjs",
12717
+ esModule: rpc_proxy_worker_default()
12718
+ }
12719
+ ],
12720
+ bindings: [
12721
+ {
12722
+ name: "ROUTER_WORKER",
12723
+ service: {
12724
+ name: `${ROUTER_SERVICE_NAME}:${id}`
12725
+ }
12726
+ },
12727
+ {
12728
+ name: "USER_WORKER",
12729
+ service: {
12730
+ name: getUserServiceName(id)
12731
+ }
12732
+ }
12733
+ ]
12734
+ }
12735
+ };
12736
+ return [
12683
12737
  storageService,
12684
12738
  namespaceService,
12685
12739
  assetService,
12686
- routerService
12740
+ routerService,
12741
+ assetsProxyService
12687
12742
  ];
12688
- if (unsafeEnableAssetsRpc) {
12689
- const assetsProxyService = {
12690
- name: `${RPC_PROXY_SERVICE_NAME}:${id}`,
12691
- worker: {
12692
- compatibilityDate: "2024-08-01",
12693
- modules: [
12694
- {
12695
- name: "assets-proxy-worker.mjs",
12696
- esModule: rpc_proxy_worker_default()
12697
- }
12698
- ],
12699
- bindings: [
12700
- {
12701
- name: "ROUTER_WORKER",
12702
- service: {
12703
- name: `${ROUTER_SERVICE_NAME}:${id}`
12704
- }
12705
- }
12706
- ]
12707
- }
12708
- };
12709
- services.push(assetsProxyService);
12710
- }
12711
- return services;
12712
12743
  }
12713
12744
  };
12714
12745
  var buildAssetManifest = async (dir) => {
@@ -12814,9 +12845,9 @@ var encodeManifest = (manifest) => {
12814
12845
  var bytesToHex = (buffer) => {
12815
12846
  return [...new Uint8Array(buffer)].map((b) => b.toString(16).padStart(2, "0")).join("");
12816
12847
  };
12817
- var hashPath = async (path30) => {
12848
+ var hashPath = async (path33) => {
12818
12849
  const encoder3 = new TextEncoder();
12819
- const data = encoder3.encode(path30);
12850
+ const data = encoder3.encode(path33);
12820
12851
  const hashBuffer = await import_node_crypto.default.subtle.digest(
12821
12852
  "SHA-256",
12822
12853
  data.buffer
@@ -12955,67 +12986,181 @@ var D1_PLUGIN = {
12955
12986
  }
12956
12987
  };
12957
12988
 
12989
+ // embed-worker:/home/runner/work/workers-sdk/workers-sdk/packages/miniflare/src/workers/email/email.worker.ts
12990
+ var import_fs17 = __toESM(require("fs"));
12991
+ var import_path20 = __toESM(require("path"));
12992
+ var import_url17 = __toESM(require("url"));
12993
+ var contents13;
12994
+ function email_worker_default() {
12995
+ if (contents13 !== void 0) return contents13;
12996
+ const filePath = import_path20.default.join(__dirname, "workers", "email/email.worker.js");
12997
+ contents13 = import_fs17.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url17.default.pathToFileURL(filePath);
12998
+ return contents13;
12999
+ }
13000
+
13001
+ // embed-worker:/home/runner/work/workers-sdk/workers-sdk/packages/miniflare/src/workers/email/send_email.worker.ts
13002
+ var import_fs18 = __toESM(require("fs"));
13003
+ var import_path21 = __toESM(require("path"));
13004
+ var import_url18 = __toESM(require("url"));
13005
+ var contents14;
13006
+ function send_email_worker_default() {
13007
+ if (contents14 !== void 0) return contents14;
13008
+ const filePath = import_path21.default.join(__dirname, "workers", "email/send_email.worker.js");
13009
+ contents14 = import_fs18.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url18.default.pathToFileURL(filePath);
13010
+ return contents14;
13011
+ }
13012
+
13013
+ // src/plugins/email/index.ts
13014
+ var import_zod15 = require("zod");
13015
+ var EmailBindingOptionsSchema = import_zod15.z.object({
13016
+ name: import_zod15.z.string()
13017
+ }).and(
13018
+ import_zod15.z.union([
13019
+ import_zod15.z.object({
13020
+ destination_address: import_zod15.z.string().optional(),
13021
+ allowed_destination_addresses: import_zod15.z.never().optional()
13022
+ }),
13023
+ import_zod15.z.object({
13024
+ allowed_destination_addresses: import_zod15.z.array(import_zod15.z.string()).optional(),
13025
+ destination_address: import_zod15.z.never().optional()
13026
+ })
13027
+ ])
13028
+ );
13029
+ var EmailOptionsSchema = import_zod15.z.object({
13030
+ email: import_zod15.z.object({
13031
+ send_email: import_zod15.z.array(EmailBindingOptionsSchema).optional()
13032
+ }).optional()
13033
+ });
13034
+ var EMAIL_PLUGIN_NAME = "email";
13035
+ var SERVICE_SEND_EMAIL_WORKER_PREFIX = `SEND-EMAIL-WORKER`;
13036
+ function buildJsonBindings(bindings) {
13037
+ return Object.entries(bindings).map(([name, value]) => ({
13038
+ name,
13039
+ json: JSON.stringify(value)
13040
+ }));
13041
+ }
13042
+ var EMAIL_PLUGIN = {
13043
+ options: EmailOptionsSchema,
13044
+ getBindings(options) {
13045
+ if (!options.email?.send_email) {
13046
+ return [];
13047
+ }
13048
+ const sendEmailBindings = options.email.send_email;
13049
+ return sendEmailBindings.map(({ name }) => ({
13050
+ name,
13051
+ service: {
13052
+ entrypoint: "SendEmailBinding",
13053
+ name: `${SERVICE_SEND_EMAIL_WORKER_PREFIX}:${name}`
13054
+ }
13055
+ }));
13056
+ },
13057
+ getNodeBindings(_options) {
13058
+ return {};
13059
+ },
13060
+ async getServices(args) {
13061
+ const extensions = [];
13062
+ const services = [];
13063
+ if (args.workerIndex === 0) {
13064
+ extensions.push({
13065
+ modules: [
13066
+ {
13067
+ name: "cloudflare-internal:email",
13068
+ esModule: email_worker_default(),
13069
+ internal: true
13070
+ }
13071
+ ]
13072
+ });
13073
+ }
13074
+ for (const { name, ...config } of args.options.email?.send_email ?? []) {
13075
+ services.push({
13076
+ name: `${SERVICE_SEND_EMAIL_WORKER_PREFIX}:${name}`,
13077
+ worker: {
13078
+ compatibilityDate: "2025-03-17",
13079
+ modules: [
13080
+ {
13081
+ name: "send_email.mjs",
13082
+ esModule: send_email_worker_default()
13083
+ }
13084
+ ],
13085
+ bindings: [
13086
+ ...buildJsonBindings(config),
13087
+ WORKER_BINDING_SERVICE_LOOPBACK
13088
+ ]
13089
+ }
13090
+ });
13091
+ }
13092
+ return {
13093
+ services,
13094
+ extensions
13095
+ };
13096
+ }
13097
+ };
13098
+
12958
13099
  // src/plugins/hyperdrive/index.ts
12959
13100
  var import_node_assert3 = __toESM(require("node:assert"));
12960
- var import_zod15 = require("zod");
13101
+ var import_zod16 = require("zod");
12961
13102
  var HYPERDRIVE_PLUGIN_NAME = "hyperdrive";
12962
- function hasPostgresProtocol(url20) {
12963
- return url20.protocol === "postgresql:" || url20.protocol === "postgres:";
13103
+ function hasPostgresProtocol(url23) {
13104
+ return url23.protocol === "postgresql:" || url23.protocol === "postgres:";
13105
+ }
13106
+ function hasMysqlProtocol(url23) {
13107
+ return url23.protocol === "mysql:";
12964
13108
  }
12965
- function getPort(url20) {
12966
- if (url20.port !== "") return url20.port;
12967
- if (hasPostgresProtocol(url20)) return "5432";
12968
- import_node_assert3.default.fail(`Expected known protocol, got ${url20.protocol}`);
13109
+ function getPort(url23) {
13110
+ if (url23.port !== "") return url23.port;
13111
+ if (hasPostgresProtocol(url23)) return "5432";
13112
+ if (hasMysqlProtocol(url23)) return "3306";
13113
+ import_node_assert3.default.fail(`Expected known protocol, got ${url23.protocol}`);
12969
13114
  }
12970
- var HyperdriveSchema = import_zod15.z.union([import_zod15.z.string().url(), import_zod15.z.instanceof(URL)]).transform((url20, ctx) => {
12971
- if (typeof url20 === "string") url20 = new URL(url20);
12972
- if (url20.protocol === "") {
13115
+ var HyperdriveSchema = import_zod16.z.union([import_zod16.z.string().url(), import_zod16.z.instanceof(URL)]).transform((url23, ctx) => {
13116
+ if (typeof url23 === "string") url23 = new URL(url23);
13117
+ if (url23.protocol === "") {
12973
13118
  ctx.addIssue({
12974
- code: import_zod15.z.ZodIssueCode.custom,
12975
- message: "You must specify the database protocol - e.g. 'postgresql'."
13119
+ code: import_zod16.z.ZodIssueCode.custom,
13120
+ message: "You must specify the database protocol - e.g. 'postgresql'/'mysql'."
12976
13121
  });
12977
- } else if (!hasPostgresProtocol(url20)) {
13122
+ } else if (!hasPostgresProtocol(url23) && !hasMysqlProtocol(url23)) {
12978
13123
  ctx.addIssue({
12979
- code: import_zod15.z.ZodIssueCode.custom,
12980
- message: "Only PostgreSQL or PostgreSQL compatible databases are currently supported."
13124
+ code: import_zod16.z.ZodIssueCode.custom,
13125
+ message: "Only PostgreSQL-compatible or MySQL-compatible databases are currently supported."
12981
13126
  });
12982
13127
  }
12983
- if (url20.host === "") {
13128
+ if (url23.host === "") {
12984
13129
  ctx.addIssue({
12985
- code: import_zod15.z.ZodIssueCode.custom,
13130
+ code: import_zod16.z.ZodIssueCode.custom,
12986
13131
  message: "You must provide a hostname or IP address in your connection string - e.g. 'user:password@database-hostname.example.com:5432/databasename"
12987
13132
  });
12988
13133
  }
12989
- if (url20.pathname === "") {
13134
+ if (url23.pathname === "") {
12990
13135
  ctx.addIssue({
12991
- code: import_zod15.z.ZodIssueCode.custom,
13136
+ code: import_zod16.z.ZodIssueCode.custom,
12992
13137
  message: "You must provide a database name as the path component - e.g. /postgres"
12993
13138
  });
12994
13139
  }
12995
- if (url20.username === "") {
13140
+ if (url23.username === "") {
12996
13141
  ctx.addIssue({
12997
- code: import_zod15.z.ZodIssueCode.custom,
13142
+ code: import_zod16.z.ZodIssueCode.custom,
12998
13143
  message: "You must provide a username - e.g. 'user:password@database.example.com:port/databasename'"
12999
13144
  });
13000
13145
  }
13001
- if (url20.password === "") {
13146
+ if (url23.password === "") {
13002
13147
  ctx.addIssue({
13003
- code: import_zod15.z.ZodIssueCode.custom,
13148
+ code: import_zod16.z.ZodIssueCode.custom,
13004
13149
  message: "You must provide a password - e.g. 'user:password@database.example.com:port/databasename' "
13005
13150
  });
13006
13151
  }
13007
- return url20;
13152
+ return url23;
13008
13153
  });
13009
- var HyperdriveInputOptionsSchema = import_zod15.z.object({
13010
- hyperdrives: import_zod15.z.record(import_zod15.z.string(), HyperdriveSchema).optional()
13154
+ var HyperdriveInputOptionsSchema = import_zod16.z.object({
13155
+ hyperdrives: import_zod16.z.record(import_zod16.z.string(), HyperdriveSchema).optional()
13011
13156
  });
13012
13157
  var HYPERDRIVE_PLUGIN = {
13013
13158
  options: HyperdriveInputOptionsSchema,
13014
13159
  getBindings(options) {
13015
13160
  return Object.entries(options.hyperdrives ?? {}).map(
13016
- ([name, url20]) => {
13017
- const database = url20.pathname.replace("/", "");
13018
- const scheme = url20.protocol.replace(":", "");
13161
+ ([name, url23]) => {
13162
+ const database = url23.pathname.replace("/", "");
13163
+ const scheme = url23.protocol.replace(":", "");
13019
13164
  return {
13020
13165
  name,
13021
13166
  hyperdrive: {
@@ -13023,8 +13168,8 @@ var HYPERDRIVE_PLUGIN = {
13023
13168
  name: `${HYPERDRIVE_PLUGIN_NAME}:${name}`
13024
13169
  },
13025
13170
  database: decodeURIComponent(database),
13026
- user: decodeURIComponent(url20.username),
13027
- password: decodeURIComponent(url20.password),
13171
+ user: decodeURIComponent(url23.username),
13172
+ password: decodeURIComponent(url23.password),
13028
13173
  scheme
13029
13174
  }
13030
13175
  };
@@ -13033,11 +13178,11 @@ var HYPERDRIVE_PLUGIN = {
13033
13178
  },
13034
13179
  getNodeBindings(options) {
13035
13180
  return Object.fromEntries(
13036
- Object.entries(options.hyperdrives ?? {}).map(([name, url20]) => {
13181
+ Object.entries(options.hyperdrives ?? {}).map(([name, url23]) => {
13037
13182
  const connectionOverrides = {
13038
- connectionString: `${url20}`,
13039
- port: Number.parseInt(url20.port),
13040
- host: url20.hostname
13183
+ connectionString: `${url23}`,
13184
+ port: Number.parseInt(url23.port),
13185
+ host: url23.hostname
13041
13186
  };
13042
13187
  const proxyNodeBinding = new ProxyNodeBinding({
13043
13188
  get(target, prop) {
@@ -13050,10 +13195,10 @@ var HYPERDRIVE_PLUGIN = {
13050
13195
  },
13051
13196
  async getServices({ options }) {
13052
13197
  return Object.entries(options.hyperdrives ?? {}).map(
13053
- ([name, url20]) => ({
13198
+ ([name, url23]) => ({
13054
13199
  name: `${HYPERDRIVE_PLUGIN_NAME}:${name}`,
13055
13200
  external: {
13056
- address: `${url20.hostname}:${getPort(url20)}`,
13201
+ address: `${url23.hostname}:${getPort(url23)}`,
13057
13202
  tcp: {}
13058
13203
  }
13059
13204
  })
@@ -13065,19 +13210,19 @@ var HYPERDRIVE_PLUGIN = {
13065
13210
  var import_promises10 = __toESM(require("fs/promises"));
13066
13211
 
13067
13212
  // embed-worker:/home/runner/work/workers-sdk/workers-sdk/packages/miniflare/src/workers/kv/namespace.worker.ts
13068
- var import_fs17 = __toESM(require("fs"));
13069
- var import_path20 = __toESM(require("path"));
13070
- var import_url17 = __toESM(require("url"));
13071
- var contents13;
13213
+ var import_fs19 = __toESM(require("fs"));
13214
+ var import_path22 = __toESM(require("path"));
13215
+ var import_url19 = __toESM(require("url"));
13216
+ var contents15;
13072
13217
  function namespace_worker_default() {
13073
- if (contents13 !== void 0) return contents13;
13074
- const filePath = import_path20.default.join(__dirname, "workers", "kv/namespace.worker.js");
13075
- contents13 = import_fs17.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url17.default.pathToFileURL(filePath);
13076
- return contents13;
13218
+ if (contents15 !== void 0) return contents15;
13219
+ const filePath = import_path22.default.join(__dirname, "workers", "kv/namespace.worker.js");
13220
+ contents15 = import_fs19.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url19.default.pathToFileURL(filePath);
13221
+ return contents15;
13077
13222
  }
13078
13223
 
13079
13224
  // src/plugins/kv/index.ts
13080
- var import_zod16 = require("zod");
13225
+ var import_zod17 = require("zod");
13081
13226
 
13082
13227
  // src/plugins/kv/constants.ts
13083
13228
  var KV_PLUGIN_NAME = "kv";
@@ -13085,25 +13230,25 @@ var KV_PLUGIN_NAME = "kv";
13085
13230
  // src/plugins/kv/sites.ts
13086
13231
  var import_assert10 = __toESM(require("assert"));
13087
13232
  var import_promises9 = __toESM(require("fs/promises"));
13088
- var import_path22 = __toESM(require("path"));
13233
+ var import_path24 = __toESM(require("path"));
13089
13234
 
13090
13235
  // embed-worker:/home/runner/work/workers-sdk/workers-sdk/packages/miniflare/src/workers/kv/sites.worker.ts
13091
- var import_fs18 = __toESM(require("fs"));
13092
- var import_path21 = __toESM(require("path"));
13093
- var import_url18 = __toESM(require("url"));
13094
- var contents14;
13236
+ var import_fs20 = __toESM(require("fs"));
13237
+ var import_path23 = __toESM(require("path"));
13238
+ var import_url20 = __toESM(require("url"));
13239
+ var contents16;
13095
13240
  function sites_worker_default() {
13096
- if (contents14 !== void 0) return contents14;
13097
- const filePath = import_path21.default.join(__dirname, "workers", "kv/sites.worker.js");
13098
- contents14 = import_fs18.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url18.default.pathToFileURL(filePath);
13099
- return contents14;
13241
+ if (contents16 !== void 0) return contents16;
13242
+ const filePath = import_path23.default.join(__dirname, "workers", "kv/sites.worker.js");
13243
+ contents16 = import_fs20.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url20.default.pathToFileURL(filePath);
13244
+ return contents16;
13100
13245
  }
13101
13246
 
13102
13247
  // src/plugins/kv/sites.ts
13103
13248
  async function* listKeysInDirectoryInner(rootPath2, currentPath) {
13104
13249
  const fileEntries = await import_promises9.default.readdir(currentPath, { withFileTypes: true });
13105
13250
  for (const fileEntry of fileEntries) {
13106
- const filePath = import_path22.default.posix.join(currentPath, fileEntry.name);
13251
+ const filePath = import_path24.default.posix.join(currentPath, fileEntry.name);
13107
13252
  if (fileEntry.isDirectory()) {
13108
13253
  yield* listKeysInDirectoryInner(rootPath2, filePath);
13109
13254
  } else {
@@ -13112,7 +13257,7 @@ async function* listKeysInDirectoryInner(rootPath2, currentPath) {
13112
13257
  }
13113
13258
  }
13114
13259
  function listKeysInDirectory(rootPath2) {
13115
- rootPath2 = import_path22.default.resolve(rootPath2);
13260
+ rootPath2 = import_path24.default.resolve(rootPath2);
13116
13261
  return listKeysInDirectoryInner(rootPath2, rootPath2);
13117
13262
  }
13118
13263
  var sitesRegExpsCache = /* @__PURE__ */ new WeakMap();
@@ -13163,7 +13308,7 @@ function getSitesServices(options) {
13163
13308
  const siteRegExps = sitesRegExpsCache.get(options);
13164
13309
  (0, import_assert10.default)(siteRegExps !== void 0);
13165
13310
  const serialisedSiteRegExps = serialiseSiteRegExps(siteRegExps);
13166
- const persist = import_path22.default.resolve(options.sitePath);
13311
+ const persist = import_path24.default.resolve(options.sitePath);
13167
13312
  const storageServiceName = `${SERVICE_NAMESPACE_SITE}:storage`;
13168
13313
  const storageService = {
13169
13314
  name: storageServiceName,
@@ -13196,14 +13341,14 @@ function getSitesServices(options) {
13196
13341
  }
13197
13342
 
13198
13343
  // src/plugins/kv/index.ts
13199
- var KVOptionsSchema = import_zod16.z.object({
13200
- kvNamespaces: import_zod16.z.union([import_zod16.z.record(import_zod16.z.string()), import_zod16.z.string().array()]).optional(),
13344
+ var KVOptionsSchema = import_zod17.z.object({
13345
+ kvNamespaces: import_zod17.z.union([import_zod17.z.record(import_zod17.z.string()), import_zod17.z.string().array()]).optional(),
13201
13346
  // Workers Sites
13202
13347
  sitePath: PathSchema.optional(),
13203
- siteInclude: import_zod16.z.string().array().optional(),
13204
- siteExclude: import_zod16.z.string().array().optional()
13348
+ siteInclude: import_zod17.z.string().array().optional(),
13349
+ siteExclude: import_zod17.z.string().array().optional()
13205
13350
  });
13206
- var KVSharedOptionsSchema = import_zod16.z.object({
13351
+ var KVSharedOptionsSchema = import_zod17.z.object({
13207
13352
  kvPersist: PersistenceSchema
13208
13353
  });
13209
13354
  var SERVICE_NAMESPACE_PREFIX = `${KV_PLUGIN_NAME}:ns`;
@@ -13307,21 +13452,21 @@ var KV_PLUGIN = {
13307
13452
  };
13308
13453
 
13309
13454
  // embed-worker:/home/runner/work/workers-sdk/workers-sdk/packages/miniflare/src/workers/pipelines/pipeline.worker.ts
13310
- var import_fs19 = __toESM(require("fs"));
13311
- var import_path23 = __toESM(require("path"));
13312
- var import_url19 = __toESM(require("url"));
13313
- var contents15;
13455
+ var import_fs21 = __toESM(require("fs"));
13456
+ var import_path25 = __toESM(require("path"));
13457
+ var import_url21 = __toESM(require("url"));
13458
+ var contents17;
13314
13459
  function pipeline_worker_default() {
13315
- if (contents15 !== void 0) return contents15;
13316
- const filePath = import_path23.default.join(__dirname, "workers", "pipelines/pipeline.worker.js");
13317
- contents15 = import_fs19.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url19.default.pathToFileURL(filePath);
13318
- return contents15;
13460
+ if (contents17 !== void 0) return contents17;
13461
+ const filePath = import_path25.default.join(__dirname, "workers", "pipelines/pipeline.worker.js");
13462
+ contents17 = import_fs21.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url21.default.pathToFileURL(filePath);
13463
+ return contents17;
13319
13464
  }
13320
13465
 
13321
13466
  // src/plugins/pipelines/index.ts
13322
- var import_zod17 = require("zod");
13323
- var PipelineOptionsSchema = import_zod17.z.object({
13324
- pipelines: import_zod17.z.union([import_zod17.z.record(import_zod17.z.string()), import_zod17.z.string().array()]).optional()
13467
+ var import_zod18 = require("zod");
13468
+ var PipelineOptionsSchema = import_zod18.z.object({
13469
+ pipelines: import_zod18.z.union([import_zod18.z.record(import_zod18.z.string()), import_zod18.z.string().array()]).optional()
13325
13470
  });
13326
13471
  var PIPELINES_PLUGIN_NAME = "pipelines";
13327
13472
  var SERVICE_PIPELINE_PREFIX = `${PIPELINES_PLUGIN_NAME}:pipeline`;
@@ -13374,32 +13519,32 @@ function bindingEntries(namespaces) {
13374
13519
  }
13375
13520
 
13376
13521
  // embed-worker:/home/runner/work/workers-sdk/workers-sdk/packages/miniflare/src/workers/queues/broker.worker.ts
13377
- var import_fs20 = __toESM(require("fs"));
13378
- var import_path24 = __toESM(require("path"));
13379
- var import_url20 = __toESM(require("url"));
13380
- var contents16;
13522
+ var import_fs22 = __toESM(require("fs"));
13523
+ var import_path26 = __toESM(require("path"));
13524
+ var import_url22 = __toESM(require("url"));
13525
+ var contents18;
13381
13526
  function broker_worker_default() {
13382
- if (contents16 !== void 0) return contents16;
13383
- const filePath = import_path24.default.join(__dirname, "workers", "queues/broker.worker.js");
13384
- contents16 = import_fs20.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url20.default.pathToFileURL(filePath);
13385
- return contents16;
13527
+ if (contents18 !== void 0) return contents18;
13528
+ const filePath = import_path26.default.join(__dirname, "workers", "queues/broker.worker.js");
13529
+ contents18 = import_fs22.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url22.default.pathToFileURL(filePath);
13530
+ return contents18;
13386
13531
  }
13387
13532
 
13388
13533
  // src/plugins/queues/index.ts
13389
- var import_zod18 = require("zod");
13534
+ var import_zod19 = require("zod");
13390
13535
 
13391
13536
  // src/plugins/queues/errors.ts
13392
13537
  var QueuesError = class extends MiniflareError {
13393
13538
  };
13394
13539
 
13395
13540
  // src/plugins/queues/index.ts
13396
- var QueuesOptionsSchema = import_zod18.z.object({
13397
- queueProducers: import_zod18.z.union([
13398
- import_zod18.z.record(QueueProducerOptionsSchema),
13399
- import_zod18.z.string().array(),
13400
- import_zod18.z.record(import_zod18.z.string())
13541
+ var QueuesOptionsSchema = import_zod19.z.object({
13542
+ queueProducers: import_zod19.z.union([
13543
+ import_zod19.z.record(QueueProducerOptionsSchema),
13544
+ import_zod19.z.string().array(),
13545
+ import_zod19.z.record(import_zod19.z.string())
13401
13546
  ]).optional(),
13402
- queueConsumers: import_zod18.z.union([import_zod18.z.record(QueueConsumerOptionsSchema), import_zod18.z.string().array()]).optional()
13547
+ queueConsumers: import_zod19.z.union([import_zod19.z.record(QueueConsumerOptionsSchema), import_zod19.z.string().array()]).optional()
13403
13548
  });
13404
13549
  var QUEUES_PLUGIN_NAME = "queues";
13405
13550
  var SERVICE_QUEUE_PREFIX = `${QUEUES_PLUGIN_NAME}:queue`;
@@ -13515,23 +13660,23 @@ function bindingKeys(namespaces) {
13515
13660
  var import_promises11 = __toESM(require("fs/promises"));
13516
13661
 
13517
13662
  // embed-worker:/home/runner/work/workers-sdk/workers-sdk/packages/miniflare/src/workers/r2/bucket.worker.ts
13518
- var import_fs21 = __toESM(require("fs"));
13519
- var import_path25 = __toESM(require("path"));
13520
- var import_url21 = __toESM(require("url"));
13521
- var contents17;
13663
+ var import_fs23 = __toESM(require("fs"));
13664
+ var import_path27 = __toESM(require("path"));
13665
+ var import_url23 = __toESM(require("url"));
13666
+ var contents19;
13522
13667
  function bucket_worker_default() {
13523
- if (contents17 !== void 0) return contents17;
13524
- const filePath = import_path25.default.join(__dirname, "workers", "r2/bucket.worker.js");
13525
- contents17 = import_fs21.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url21.default.pathToFileURL(filePath);
13526
- return contents17;
13668
+ if (contents19 !== void 0) return contents19;
13669
+ const filePath = import_path27.default.join(__dirname, "workers", "r2/bucket.worker.js");
13670
+ contents19 = import_fs23.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url23.default.pathToFileURL(filePath);
13671
+ return contents19;
13527
13672
  }
13528
13673
 
13529
13674
  // src/plugins/r2/index.ts
13530
- var import_zod19 = require("zod");
13531
- var R2OptionsSchema = import_zod19.z.object({
13532
- r2Buckets: import_zod19.z.union([import_zod19.z.record(import_zod19.z.string()), import_zod19.z.string().array()]).optional()
13675
+ var import_zod20 = require("zod");
13676
+ var R2OptionsSchema = import_zod20.z.object({
13677
+ r2Buckets: import_zod20.z.union([import_zod20.z.record(import_zod20.z.string()), import_zod20.z.string().array()]).optional()
13533
13678
  });
13534
- var R2SharedOptionsSchema = import_zod19.z.object({
13679
+ var R2SharedOptionsSchema = import_zod20.z.object({
13535
13680
  r2Persist: PersistenceSchema
13536
13681
  });
13537
13682
  var R2_PLUGIN_NAME = "r2";
@@ -13625,38 +13770,38 @@ var R2_PLUGIN = {
13625
13770
  };
13626
13771
 
13627
13772
  // embed-worker:/home/runner/work/workers-sdk/workers-sdk/packages/miniflare/src/workers/ratelimit/ratelimit.worker.ts
13628
- var import_fs22 = __toESM(require("fs"));
13629
- var import_path26 = __toESM(require("path"));
13630
- var import_url22 = __toESM(require("url"));
13631
- var contents18;
13773
+ var import_fs24 = __toESM(require("fs"));
13774
+ var import_path28 = __toESM(require("path"));
13775
+ var import_url24 = __toESM(require("url"));
13776
+ var contents20;
13632
13777
  function ratelimit_worker_default() {
13633
- if (contents18 !== void 0) return contents18;
13634
- const filePath = import_path26.default.join(__dirname, "workers", "ratelimit/ratelimit.worker.js");
13635
- contents18 = import_fs22.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url22.default.pathToFileURL(filePath);
13636
- return contents18;
13778
+ if (contents20 !== void 0) return contents20;
13779
+ const filePath = import_path28.default.join(__dirname, "workers", "ratelimit/ratelimit.worker.js");
13780
+ contents20 = import_fs24.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url24.default.pathToFileURL(filePath);
13781
+ return contents20;
13637
13782
  }
13638
13783
 
13639
13784
  // src/plugins/ratelimit/index.ts
13640
- var import_zod20 = require("zod");
13785
+ var import_zod21 = require("zod");
13641
13786
  var PeriodType = /* @__PURE__ */ ((PeriodType2) => {
13642
13787
  PeriodType2[PeriodType2["TENSECONDS"] = 10] = "TENSECONDS";
13643
13788
  PeriodType2[PeriodType2["MINUTE"] = 60] = "MINUTE";
13644
13789
  return PeriodType2;
13645
13790
  })(PeriodType || {});
13646
- var RatelimitConfigSchema = import_zod20.z.object({
13647
- simple: import_zod20.z.object({
13648
- limit: import_zod20.z.number().gt(0),
13791
+ var RatelimitConfigSchema = import_zod21.z.object({
13792
+ simple: import_zod21.z.object({
13793
+ limit: import_zod21.z.number().gt(0),
13649
13794
  // may relax this to be any number in the future
13650
- period: import_zod20.z.nativeEnum(PeriodType).optional()
13795
+ period: import_zod21.z.nativeEnum(PeriodType).optional()
13651
13796
  })
13652
13797
  });
13653
- var RatelimitOptionsSchema = import_zod20.z.object({
13654
- ratelimits: import_zod20.z.record(RatelimitConfigSchema).optional()
13798
+ var RatelimitOptionsSchema = import_zod21.z.object({
13799
+ ratelimits: import_zod21.z.record(RatelimitConfigSchema).optional()
13655
13800
  });
13656
13801
  var RATELIMIT_PLUGIN_NAME = "ratelimit";
13657
13802
  var SERVICE_RATELIMIT_PREFIX = `${RATELIMIT_PLUGIN_NAME}`;
13658
13803
  var SERVICE_RATELIMIT_MODULE = `cloudflare-internal:${SERVICE_RATELIMIT_PREFIX}:module`;
13659
- function buildJsonBindings(bindings) {
13804
+ function buildJsonBindings2(bindings) {
13660
13805
  return Object.entries(bindings).map(([name, value]) => ({
13661
13806
  name,
13662
13807
  json: JSON.stringify(value)
@@ -13673,7 +13818,7 @@ var RATELIMIT_PLUGIN = {
13673
13818
  name,
13674
13819
  wrapped: {
13675
13820
  moduleName: SERVICE_RATELIMIT_MODULE,
13676
- innerBindings: buildJsonBindings({
13821
+ innerBindings: buildJsonBindings2({
13677
13822
  namespaceId: name,
13678
13823
  limit: config.simple.limit,
13679
13824
  period: config.simple.period
@@ -13715,33 +13860,164 @@ var RATELIMIT_PLUGIN = {
13715
13860
  }
13716
13861
  };
13717
13862
 
13863
+ // embed-worker:/home/runner/work/workers-sdk/workers-sdk/packages/miniflare/src/workers/secrets-store/secret.worker.ts
13864
+ var import_fs25 = __toESM(require("fs"));
13865
+ var import_path29 = __toESM(require("path"));
13866
+ var import_url25 = __toESM(require("url"));
13867
+ var contents21;
13868
+ function secret_worker_default() {
13869
+ if (contents21 !== void 0) return contents21;
13870
+ const filePath = import_path29.default.join(__dirname, "workers", "secrets-store/secret.worker.js");
13871
+ contents21 = import_fs25.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url25.default.pathToFileURL(filePath);
13872
+ return contents21;
13873
+ }
13874
+
13875
+ // src/plugins/secret-store/index.ts
13876
+ var import_zod22 = require("zod");
13877
+ var SecretsStoreSecretsSchema = import_zod22.z.record(
13878
+ import_zod22.z.object({
13879
+ store_id: import_zod22.z.string(),
13880
+ secret_name: import_zod22.z.string()
13881
+ })
13882
+ );
13883
+ var SecretsStoreSecretsOptionsSchema = import_zod22.z.object({
13884
+ secretsStoreSecrets: SecretsStoreSecretsSchema.optional()
13885
+ });
13886
+ var SecretsStoreSecretsSharedOptionsSchema = import_zod22.z.object({
13887
+ secretsStorePersist: PersistenceSchema
13888
+ });
13889
+ var SECRET_STORE_PLUGIN_NAME = "secrets-store";
13890
+ function getkvNamespacesOptions(secretsStoreSecrets) {
13891
+ const storeIds = new Set(
13892
+ Object.values(secretsStoreSecrets).map((store) => store.store_id)
13893
+ );
13894
+ const storeIdKvNamespaceEntries = Array.from(storeIds).map((storeId) => [
13895
+ storeId,
13896
+ `${SECRET_STORE_PLUGIN_NAME}:${storeId}`
13897
+ ]);
13898
+ return {
13899
+ kvNamespaces: Object.fromEntries(storeIdKvNamespaceEntries)
13900
+ };
13901
+ }
13902
+ function isKvBinding(binding) {
13903
+ return "kvNamespace" in binding;
13904
+ }
13905
+ var SECRET_STORE_PLUGIN = {
13906
+ options: SecretsStoreSecretsOptionsSchema,
13907
+ sharedOptions: SecretsStoreSecretsSharedOptionsSchema,
13908
+ async getBindings(options) {
13909
+ if (!options.secretsStoreSecrets) {
13910
+ return [];
13911
+ }
13912
+ const bindings = Object.entries(
13913
+ options.secretsStoreSecrets
13914
+ ).map(([name, config]) => {
13915
+ return {
13916
+ name,
13917
+ service: {
13918
+ name: `${SECRET_STORE_PLUGIN_NAME}:${config.store_id}:${config.secret_name}`,
13919
+ entrypoint: "SecretsStoreSecret"
13920
+ }
13921
+ };
13922
+ });
13923
+ return bindings;
13924
+ },
13925
+ getNodeBindings(options) {
13926
+ if (!options.secretsStoreSecrets) {
13927
+ return {};
13928
+ }
13929
+ return Object.fromEntries(
13930
+ Object.keys(options.secretsStoreSecrets).map((name) => [
13931
+ name,
13932
+ new ProxyNodeBinding()
13933
+ ])
13934
+ );
13935
+ },
13936
+ async getServices({ options, sharedOptions, ...restOptions }) {
13937
+ if (!options.secretsStoreSecrets) {
13938
+ return [];
13939
+ }
13940
+ const kvServices = await KV_PLUGIN.getServices({
13941
+ options: getkvNamespacesOptions(options.secretsStoreSecrets),
13942
+ sharedOptions: {
13943
+ kvPersist: sharedOptions.secretsStorePersist
13944
+ },
13945
+ ...restOptions
13946
+ });
13947
+ const kvBindings = await KV_PLUGIN.getBindings(
13948
+ getkvNamespacesOptions(options.secretsStoreSecrets),
13949
+ restOptions.workerIndex
13950
+ );
13951
+ if (!kvBindings || !kvBindings.every(isKvBinding)) {
13952
+ throw new Error(
13953
+ "Expected KV plugin to return bindings with kvNamespace defined"
13954
+ );
13955
+ }
13956
+ if (!Array.isArray(kvServices)) {
13957
+ throw new Error("Expected KV plugin to return an array of services");
13958
+ }
13959
+ return [
13960
+ ...kvServices,
13961
+ ...Object.entries(options.secretsStoreSecrets).map(
13962
+ ([_, config]) => {
13963
+ return {
13964
+ name: `${SECRET_STORE_PLUGIN_NAME}:${config.store_id}:${config.secret_name}`,
13965
+ worker: {
13966
+ compatibilityDate: "2025-01-01",
13967
+ modules: [
13968
+ {
13969
+ name: "secret.worker.js",
13970
+ esModule: secret_worker_default()
13971
+ }
13972
+ ],
13973
+ bindings: [
13974
+ {
13975
+ name: "store",
13976
+ kvNamespace: kvBindings.find(
13977
+ // Look up the corresponding KV namespace for the store id
13978
+ (binding) => binding.name === config.store_id
13979
+ )?.kvNamespace
13980
+ },
13981
+ {
13982
+ name: "secret_name",
13983
+ json: JSON.stringify(config.secret_name)
13984
+ }
13985
+ ]
13986
+ }
13987
+ };
13988
+ }
13989
+ )
13990
+ ];
13991
+ }
13992
+ };
13993
+
13718
13994
  // src/plugins/workflows/index.ts
13719
13995
  var import_promises12 = __toESM(require("fs/promises"));
13720
13996
 
13721
13997
  // embed-worker:/home/runner/work/workers-sdk/workers-sdk/packages/miniflare/src/workers/workflows/binding.worker.ts
13722
- var import_fs23 = __toESM(require("fs"));
13723
- var import_path27 = __toESM(require("path"));
13724
- var import_url23 = __toESM(require("url"));
13725
- var contents19;
13998
+ var import_fs26 = __toESM(require("fs"));
13999
+ var import_path30 = __toESM(require("path"));
14000
+ var import_url26 = __toESM(require("url"));
14001
+ var contents22;
13726
14002
  function binding_worker_default() {
13727
- if (contents19 !== void 0) return contents19;
13728
- const filePath = import_path27.default.join(__dirname, "workers", "workflows/binding.worker.js");
13729
- contents19 = import_fs23.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url23.default.pathToFileURL(filePath);
13730
- return contents19;
14003
+ if (contents22 !== void 0) return contents22;
14004
+ const filePath = import_path30.default.join(__dirname, "workers", "workflows/binding.worker.js");
14005
+ contents22 = import_fs26.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url26.default.pathToFileURL(filePath);
14006
+ return contents22;
13731
14007
  }
13732
14008
 
13733
14009
  // src/plugins/workflows/index.ts
13734
- var import_zod21 = require("zod");
13735
- var WorkflowsOptionsSchema = import_zod21.z.object({
13736
- workflows: import_zod21.z.record(
13737
- import_zod21.z.object({
13738
- name: import_zod21.z.string(),
13739
- className: import_zod21.z.string(),
13740
- scriptName: import_zod21.z.string().optional()
14010
+ var import_zod23 = require("zod");
14011
+ var WorkflowsOptionsSchema = import_zod23.z.object({
14012
+ workflows: import_zod23.z.record(
14013
+ import_zod23.z.object({
14014
+ name: import_zod23.z.string(),
14015
+ className: import_zod23.z.string(),
14016
+ scriptName: import_zod23.z.string().optional()
13741
14017
  })
13742
14018
  ).optional()
13743
14019
  });
13744
- var WorkflowsSharedOptionsSchema = import_zod21.z.object({
14020
+ var WorkflowsSharedOptionsSchema = import_zod23.z.object({
13745
14021
  workflowsPersist: PersistenceSchema
13746
14022
  });
13747
14023
  var WORKFLOWS_PLUGIN_NAME = "workflows";
@@ -13846,10 +14122,446 @@ var PLUGINS = {
13846
14122
  [RATELIMIT_PLUGIN_NAME]: RATELIMIT_PLUGIN,
13847
14123
  [ASSETS_PLUGIN_NAME]: ASSETS_PLUGIN,
13848
14124
  [WORKFLOWS_PLUGIN_NAME]: WORKFLOWS_PLUGIN,
13849
- [PIPELINES_PLUGIN_NAME]: PIPELINE_PLUGIN
14125
+ [PIPELINES_PLUGIN_NAME]: PIPELINE_PLUGIN,
14126
+ [SECRET_STORE_PLUGIN_NAME]: SECRET_STORE_PLUGIN,
14127
+ [EMAIL_PLUGIN_NAME]: EMAIL_PLUGIN
13850
14128
  };
13851
14129
  var PLUGIN_ENTRIES = Object.entries(PLUGINS);
13852
14130
 
14131
+ // src/plugins/core/inspector-proxy/inspector-proxy-controller.ts
14132
+ var import_node_crypto2 = __toESM(require("node:crypto"));
14133
+ var import_node_http = require("node:http");
14134
+
14135
+ // ../../node_modules/.pnpm/get-port@7.1.0/node_modules/get-port/index.js
14136
+ var import_node_net = __toESM(require("node:net"), 1);
14137
+ var import_node_os = __toESM(require("node:os"), 1);
14138
+ var Locked = class extends Error {
14139
+ constructor(port) {
14140
+ super(`${port} is locked`);
14141
+ }
14142
+ };
14143
+ var lockedPorts = {
14144
+ old: /* @__PURE__ */ new Set(),
14145
+ young: /* @__PURE__ */ new Set()
14146
+ };
14147
+ var releaseOldLockedPortsIntervalMs = 1e3 * 15;
14148
+ var timeout;
14149
+ var getLocalHosts = () => {
14150
+ const interfaces = import_node_os.default.networkInterfaces();
14151
+ const results = /* @__PURE__ */ new Set([void 0, "0.0.0.0"]);
14152
+ for (const _interface of Object.values(interfaces)) {
14153
+ for (const config of _interface) {
14154
+ results.add(config.address);
14155
+ }
14156
+ }
14157
+ return results;
14158
+ };
14159
+ var checkAvailablePort = (options) => new Promise((resolve2, reject) => {
14160
+ const server = import_node_net.default.createServer();
14161
+ server.unref();
14162
+ server.on("error", reject);
14163
+ server.listen(options, () => {
14164
+ const { port } = server.address();
14165
+ server.close(() => {
14166
+ resolve2(port);
14167
+ });
14168
+ });
14169
+ });
14170
+ var getAvailablePort = async (options, hosts) => {
14171
+ if (options.host || options.port === 0) {
14172
+ return checkAvailablePort(options);
14173
+ }
14174
+ for (const host of hosts) {
14175
+ try {
14176
+ await checkAvailablePort({ port: options.port, host });
14177
+ } catch (error) {
14178
+ if (!["EADDRNOTAVAIL", "EINVAL"].includes(error.code)) {
14179
+ throw error;
14180
+ }
14181
+ }
14182
+ }
14183
+ return options.port;
14184
+ };
14185
+ var portCheckSequence = function* (ports) {
14186
+ if (ports) {
14187
+ yield* ports;
14188
+ }
14189
+ yield 0;
14190
+ };
14191
+ async function getPorts(options) {
14192
+ let ports;
14193
+ let exclude = /* @__PURE__ */ new Set();
14194
+ if (options) {
14195
+ if (options.port) {
14196
+ ports = typeof options.port === "number" ? [options.port] : options.port;
14197
+ }
14198
+ if (options.exclude) {
14199
+ const excludeIterable = options.exclude;
14200
+ if (typeof excludeIterable[Symbol.iterator] !== "function") {
14201
+ throw new TypeError("The `exclude` option must be an iterable.");
14202
+ }
14203
+ for (const element of excludeIterable) {
14204
+ if (typeof element !== "number") {
14205
+ throw new TypeError("Each item in the `exclude` option must be a number corresponding to the port you want excluded.");
14206
+ }
14207
+ if (!Number.isSafeInteger(element)) {
14208
+ throw new TypeError(`Number ${element} in the exclude option is not a safe integer and can't be used`);
14209
+ }
14210
+ }
14211
+ exclude = new Set(excludeIterable);
14212
+ }
14213
+ }
14214
+ if (timeout === void 0) {
14215
+ timeout = setTimeout(() => {
14216
+ timeout = void 0;
14217
+ lockedPorts.old = lockedPorts.young;
14218
+ lockedPorts.young = /* @__PURE__ */ new Set();
14219
+ }, releaseOldLockedPortsIntervalMs);
14220
+ if (timeout.unref) {
14221
+ timeout.unref();
14222
+ }
14223
+ }
14224
+ const hosts = getLocalHosts();
14225
+ for (const port of portCheckSequence(ports)) {
14226
+ try {
14227
+ if (exclude.has(port)) {
14228
+ continue;
14229
+ }
14230
+ let availablePort = await getAvailablePort({ ...options, port }, hosts);
14231
+ while (lockedPorts.old.has(availablePort) || lockedPorts.young.has(availablePort)) {
14232
+ if (port !== 0) {
14233
+ throw new Locked(port);
14234
+ }
14235
+ availablePort = await getAvailablePort({ ...options, port }, hosts);
14236
+ }
14237
+ lockedPorts.young.add(availablePort);
14238
+ return availablePort;
14239
+ } catch (error) {
14240
+ if (!["EADDRINUSE", "EACCES"].includes(error.code) && !(error instanceof Locked)) {
14241
+ throw error;
14242
+ }
14243
+ }
14244
+ }
14245
+ throw new Error("No available ports found");
14246
+ }
14247
+
14248
+ // src/plugins/core/inspector-proxy/inspector-proxy-controller.ts
14249
+ var import_ws4 = __toESM(require("ws"));
14250
+
14251
+ // package.json
14252
+ var version = "0.0.0-05b1e8391";
14253
+
14254
+ // src/plugins/core/inspector-proxy/inspector-proxy.ts
14255
+ var import_node_assert4 = __toESM(require("node:assert"));
14256
+ var import_ws3 = __toESM(require("ws"));
14257
+
14258
+ // src/plugins/core/inspector-proxy/devtools.ts
14259
+ function isDevToolsEvent(event, name) {
14260
+ return typeof event === "object" && event !== null && "method" in event && event.method === name;
14261
+ }
14262
+
14263
+ // src/plugins/core/inspector-proxy/inspector-proxy.ts
14264
+ var InspectorProxy = class {
14265
+ #workerName;
14266
+ #runtimeWs;
14267
+ #devtoolsWs;
14268
+ #devtoolsHaveFileSystemAccess = false;
14269
+ constructor(workerName, runtimeWs) {
14270
+ this.#workerName = workerName;
14271
+ this.#runtimeWs = runtimeWs;
14272
+ this.#runtimeWs.once("open", () => this.#handleRuntimeWebSocketOpen());
14273
+ }
14274
+ get workerName() {
14275
+ return this.#workerName;
14276
+ }
14277
+ get path() {
14278
+ return `/${this.#workerName}`;
14279
+ }
14280
+ onDevtoolsConnected(devtoolsWs, devtoolsHaveFileSystemAccess) {
14281
+ if (this.#devtoolsWs) {
14282
+ devtoolsWs.close(
14283
+ 1013,
14284
+ "Too many clients; only one can be connected at a time"
14285
+ );
14286
+ return;
14287
+ }
14288
+ this.#devtoolsWs = devtoolsWs;
14289
+ this.#devtoolsHaveFileSystemAccess = devtoolsHaveFileSystemAccess;
14290
+ (0, import_node_assert4.default)(this.#devtoolsWs?.readyState === import_ws3.default.OPEN);
14291
+ this.#devtoolsWs.on("error", console.error);
14292
+ this.#devtoolsWs.once("close", () => {
14293
+ if (this.#runtimeWs?.OPEN) {
14294
+ this.#sendMessageToRuntime({
14295
+ method: "Debugger.disable",
14296
+ id: this.#nextCounter()
14297
+ });
14298
+ }
14299
+ this.#devtoolsWs = void 0;
14300
+ });
14301
+ this.#devtoolsWs.on("message", (data) => {
14302
+ const message = JSON.parse(data.toString());
14303
+ (0, import_node_assert4.default)(this.#runtimeWs?.OPEN);
14304
+ this.#sendMessageToRuntime(message);
14305
+ });
14306
+ }
14307
+ #runtimeMessageCounter = 1e8;
14308
+ #nextCounter() {
14309
+ return ++this.#runtimeMessageCounter;
14310
+ }
14311
+ #runtimeKeepAliveInterval;
14312
+ #handleRuntimeWebSocketOpen() {
14313
+ (0, import_node_assert4.default)(this.#runtimeWs?.OPEN);
14314
+ this.#runtimeWs.on("message", (data) => {
14315
+ const message = JSON.parse(data.toString());
14316
+ if (!this.#devtoolsWs) {
14317
+ return;
14318
+ }
14319
+ if (isDevToolsEvent(message, "Debugger.scriptParsed")) {
14320
+ return this.#handleRuntimeScriptParsed(message);
14321
+ }
14322
+ return this.#sendMessageToDevtools(message);
14323
+ });
14324
+ clearInterval(this.#runtimeKeepAliveInterval);
14325
+ this.#runtimeKeepAliveInterval = setInterval(() => {
14326
+ if (this.#runtimeWs?.OPEN) {
14327
+ this.#sendMessageToRuntime({
14328
+ method: "Runtime.getIsolateId",
14329
+ id: this.#nextCounter()
14330
+ });
14331
+ }
14332
+ }, 1e4);
14333
+ }
14334
+ #handleRuntimeScriptParsed(message) {
14335
+ if (!this.#devtoolsHaveFileSystemAccess && message.params.sourceMapURL !== void 0 && // Don't try to find a sourcemap for e.g. node-internal: scripts
14336
+ message.params.url.startsWith("file:")) {
14337
+ const url23 = new URL(message.params.sourceMapURL, message.params.url);
14338
+ if (url23.protocol === "file:") {
14339
+ message.params.sourceMapURL = url23.href.replace(
14340
+ "file:",
14341
+ "wrangler-file:"
14342
+ );
14343
+ }
14344
+ }
14345
+ return this.#sendMessageToDevtools(message);
14346
+ }
14347
+ #sendMessageToDevtools(message) {
14348
+ (0, import_node_assert4.default)(this.#devtoolsWs);
14349
+ if (!this.#devtoolsWs.OPEN) {
14350
+ this.#devtoolsWs.once(
14351
+ "open",
14352
+ () => this.#devtoolsWs?.send(JSON.stringify(message))
14353
+ );
14354
+ return;
14355
+ }
14356
+ this.#devtoolsWs.send(JSON.stringify(message));
14357
+ }
14358
+ #sendMessageToRuntime(message) {
14359
+ (0, import_node_assert4.default)(this.#runtimeWs?.OPEN);
14360
+ this.#runtimeWs.send(JSON.stringify(message));
14361
+ }
14362
+ async dispose() {
14363
+ clearInterval(this.#runtimeKeepAliveInterval);
14364
+ this.#devtoolsWs?.close();
14365
+ }
14366
+ };
14367
+
14368
+ // src/plugins/core/inspector-proxy/inspector-proxy-controller.ts
14369
+ var InspectorProxyController = class {
14370
+ constructor(inspectorPortOption, log, workerNamesToProxy) {
14371
+ this.inspectorPortOption = inspectorPortOption;
14372
+ this.log = log;
14373
+ this.workerNamesToProxy = workerNamesToProxy;
14374
+ this.#inspectorPort = this.#getInspectorPortToUse();
14375
+ this.#server = this.#initializeServer();
14376
+ this.#runtimeConnectionEstablished = new DeferredPromise();
14377
+ }
14378
+ #runtimeConnectionEstablished;
14379
+ #proxies = [];
14380
+ #server;
14381
+ #inspectorPort;
14382
+ async #getInspectorPortToUse() {
14383
+ return this.inspectorPortOption !== 0 ? this.inspectorPortOption : await getPorts();
14384
+ }
14385
+ async #initializeServer() {
14386
+ const server = (0, import_node_http.createServer)(async (req, res) => {
14387
+ const maybeJson = await this.#handleDevToolsJsonRequest(
14388
+ req.headers.host ?? "localhost",
14389
+ req.url ?? "/"
14390
+ );
14391
+ if (maybeJson !== null) {
14392
+ res.setHeader("Content-Type", "application/json");
14393
+ res.end(JSON.stringify(maybeJson));
14394
+ return;
14395
+ }
14396
+ res.statusCode = 404;
14397
+ res.end(null);
14398
+ });
14399
+ this.#initializeWebSocketServer(server);
14400
+ const listeningPromise = new Promise(
14401
+ (resolve2) => server.once("listening", resolve2)
14402
+ );
14403
+ server.listen(await this.#inspectorPort);
14404
+ await listeningPromise;
14405
+ return server;
14406
+ }
14407
+ async #restartServer() {
14408
+ const server = await this.#server;
14409
+ server.closeAllConnections();
14410
+ await new Promise((resolve2, reject) => {
14411
+ server.close((err) => err ? reject(err) : resolve2());
14412
+ });
14413
+ const listeningPromise = new Promise(
14414
+ (resolve2) => server.once("listening", resolve2)
14415
+ );
14416
+ server.listen(await this.#inspectorPort);
14417
+ await listeningPromise;
14418
+ }
14419
+ #initializeWebSocketServer(server) {
14420
+ const devtoolsWebSocketServer = new import_ws4.WebSocketServer({ server });
14421
+ devtoolsWebSocketServer.on("connection", (devtoolsWs, upgradeRequest) => {
14422
+ const validationError = this.#validateDevToolsWebSocketUpgradeRequest(upgradeRequest);
14423
+ if (validationError !== null) {
14424
+ devtoolsWs.close();
14425
+ return;
14426
+ }
14427
+ const proxy = this.#proxies.find(
14428
+ ({ path: path33 }) => upgradeRequest.url === path33
14429
+ );
14430
+ if (!proxy) {
14431
+ this.log.warn(
14432
+ `Warning: An inspector connection was requested for the ${upgradeRequest.url} path but no such inspector exists`
14433
+ );
14434
+ devtoolsWs.close();
14435
+ return;
14436
+ }
14437
+ proxy.onDevtoolsConnected(
14438
+ devtoolsWs,
14439
+ this.#checkIfDevtoolsHaveFileSystemAccess(upgradeRequest)
14440
+ );
14441
+ });
14442
+ }
14443
+ #validateDevToolsWebSocketUpgradeRequest(req) {
14444
+ const hostHeader = req.headers.host;
14445
+ if (hostHeader == null) return { statusText: null, status: 400 };
14446
+ try {
14447
+ const host = new URL(`http://${hostHeader}`);
14448
+ if (!ALLOWED_HOST_HOSTNAMES.includes(host.hostname)) {
14449
+ return { statusText: "Disallowed `Host` header", status: 401 };
14450
+ }
14451
+ } catch {
14452
+ return { statusText: "Expected `Host` header", status: 400 };
14453
+ }
14454
+ let originHeader = req.headers.origin;
14455
+ if (!originHeader && !req.headers["user-agent"]) {
14456
+ originHeader = "http://localhost";
14457
+ }
14458
+ if (!originHeader) {
14459
+ return { statusText: "Expected `Origin` header", status: 400 };
14460
+ }
14461
+ try {
14462
+ const origin = new URL(originHeader);
14463
+ const allowed = ALLOWED_ORIGIN_HOSTNAMES.some((rule) => {
14464
+ if (typeof rule === "string") return origin.hostname === rule;
14465
+ else return rule.test(origin.hostname);
14466
+ });
14467
+ if (!allowed) {
14468
+ return { statusText: "Disallowed `Origin` header", status: 401 };
14469
+ }
14470
+ } catch {
14471
+ return { statusText: "Expected `Origin` header", status: 400 };
14472
+ }
14473
+ return null;
14474
+ }
14475
+ #checkIfDevtoolsHaveFileSystemAccess(req) {
14476
+ const userAgent = req.headers["user-agent"] ?? "";
14477
+ const hasFileSystemAccess = !/mozilla/i.test(userAgent);
14478
+ return hasFileSystemAccess;
14479
+ }
14480
+ #inspectorId = import_node_crypto2.default.randomUUID();
14481
+ async #handleDevToolsJsonRequest(host, path33) {
14482
+ if (path33 === "/json/version") {
14483
+ return {
14484
+ Browser: `miniflare/v${version}`,
14485
+ // TODO: (someday): The DevTools protocol should match that of workerd.
14486
+ // This could be exposed by the preview API.
14487
+ "Protocol-Version": "1.3"
14488
+ };
14489
+ }
14490
+ if (path33 === "/json" || path33 === "/json/list") {
14491
+ return this.#proxies.map(({ workerName }) => {
14492
+ const localHost = `${host}/${workerName}`;
14493
+ const devtoolsFrontendUrl = `https://devtools.devprod.cloudflare.dev/js_app?theme=systemPreferred&debugger=true&ws=${localHost}`;
14494
+ return {
14495
+ id: `${this.#inspectorId}-${workerName}`,
14496
+ type: "node",
14497
+ // TODO: can we specify different type?
14498
+ description: "workers",
14499
+ webSocketDebuggerUrl: `ws://${localHost}`,
14500
+ devtoolsFrontendUrl,
14501
+ devtoolsFrontendUrlCompat: devtoolsFrontendUrl,
14502
+ // Below are fields that are visible in the DevTools UI.
14503
+ title: workerName.length === 0 || this.#proxies.length === 1 ? `Cloudflare Worker` : `Cloudflare Worker: ${workerName}`,
14504
+ faviconUrl: "https://workers.cloudflare.com/favicon.ico"
14505
+ // url: "http://" + localHost, // looks unnecessary
14506
+ };
14507
+ });
14508
+ }
14509
+ return null;
14510
+ }
14511
+ async getInspectorURL() {
14512
+ return getWebsocketURL(await this.#inspectorPort);
14513
+ }
14514
+ async updateConnection(inspectorPortOption, runtimeInspectorPort) {
14515
+ if (this.inspectorPortOption !== inspectorPortOption) {
14516
+ this.inspectorPortOption = inspectorPortOption;
14517
+ this.#inspectorPort = this.#getInspectorPortToUse();
14518
+ await this.#restartServer();
14519
+ }
14520
+ const workerdInspectorJson = await fetch(
14521
+ `http://127.0.0.1:${runtimeInspectorPort}/json`
14522
+ ).then((resp) => resp.json());
14523
+ this.#proxies = workerdInspectorJson.map(({ id }) => {
14524
+ if (!id.startsWith("core:user:")) {
14525
+ return;
14526
+ }
14527
+ const workerName = id.replace(/^core:user:/, "");
14528
+ if (!this.workerNamesToProxy.has(workerName)) {
14529
+ return;
14530
+ }
14531
+ return new InspectorProxy(
14532
+ workerName,
14533
+ new import_ws4.default(`ws://127.0.0.1:${runtimeInspectorPort}/${id}`)
14534
+ );
14535
+ }).filter(Boolean);
14536
+ this.#runtimeConnectionEstablished.resolve();
14537
+ }
14538
+ async #waitForReady() {
14539
+ await this.#runtimeConnectionEstablished;
14540
+ }
14541
+ get ready() {
14542
+ return this.#waitForReady();
14543
+ }
14544
+ async dispose() {
14545
+ await Promise.all(this.#proxies.map((proxy) => proxy.dispose()));
14546
+ const server = await this.#server;
14547
+ return new Promise((resolve2, reject) => {
14548
+ server.close((err) => err ? reject(err) : resolve2());
14549
+ });
14550
+ }
14551
+ };
14552
+ function getWebsocketURL(port) {
14553
+ return new URL(`ws://127.0.0.1:${port}`);
14554
+ }
14555
+ var ALLOWED_HOST_HOSTNAMES = ["127.0.0.1", "[::1]", "localhost"];
14556
+ var ALLOWED_ORIGIN_HOSTNAMES = [
14557
+ "devtools.devprod.cloudflare.dev",
14558
+ "cloudflare-devtools.pages.dev",
14559
+ /^[a-z0-9]+\.cloudflare-devtools\.pages\.dev$/,
14560
+ "127.0.0.1",
14561
+ "[::1]",
14562
+ "localhost"
14563
+ ];
14564
+
13853
14565
  // src/shared/mime-types.ts
13854
14566
  var compressedByCloudflareFL = /* @__PURE__ */ new Set([
13855
14567
  // list copied from https://developers.cloudflare.com/speed/optimization/content/brotli/content-compression/#:~:text=If%20supported%20by%20visitors%E2%80%99%20web%20browsers%2C%20Cloudflare%20will%20return%20Gzip%20or%20Brotli%2Dencoded%20responses%20for%20the%20following%20content%20types%3A
@@ -13907,6 +14619,9 @@ function isCompressedByCloudflareFL(contentTypeHeader) {
13907
14619
  return compressedByCloudflareFL.has(contentType);
13908
14620
  }
13909
14621
 
14622
+ // src/workers/secrets-store/constants.ts
14623
+ var ADMIN_API = "SecretsStoreSecret::admin_api";
14624
+
13910
14625
  // src/zod-format.ts
13911
14626
  var import_assert11 = __toESM(require("assert"));
13912
14627
  var import_util4 = __toESM(require("util"));
@@ -13945,8 +14660,8 @@ function hasMultipleDistinctMessages(issues, atDepth) {
13945
14660
  }
13946
14661
  return false;
13947
14662
  }
13948
- function annotate(groupCounts, annotated, input, issue, path30, groupId) {
13949
- if (path30.length === 0) {
14663
+ function annotate(groupCounts, annotated, input, issue, path33, groupId) {
14664
+ if (path33.length === 0) {
13950
14665
  if (issue.code === "invalid_union") {
13951
14666
  const unionIssues = issue.unionErrors.flatMap(({ issues }) => issues);
13952
14667
  let newGroupId;
@@ -13992,7 +14707,7 @@ function annotate(groupCounts, annotated, input, issue, path30, groupId) {
13992
14707
  [kGroupId]: groupId
13993
14708
  };
13994
14709
  }
13995
- const [head, ...tail] = path30;
14710
+ const [head, ...tail] = path33;
13996
14711
  (0, import_assert11.default)(isRecord(input), "Expected object/array input for nested issue");
13997
14712
  if (annotated === void 0) {
13998
14713
  if (Array.isArray(input)) {
@@ -14197,7 +14912,7 @@ function validateOptions(opts) {
14197
14912
  );
14198
14913
  const sharedRootPath = multipleWorkers ? getRootPath(sharedOpts) : "";
14199
14914
  const workerRootPaths = workerOpts.map(
14200
- (opts2) => import_path28.default.resolve(sharedRootPath, getRootPath(opts2))
14915
+ (opts2) => import_path31.default.resolve(sharedRootPath, getRootPath(opts2))
14201
14916
  );
14202
14917
  try {
14203
14918
  for (const [key, plugin] of PLUGIN_ENTRIES) {
@@ -14213,7 +14928,7 @@ function validateOptions(opts) {
14213
14928
  }
14214
14929
  }
14215
14930
  } catch (e) {
14216
- if (e instanceof import_zod23.z.ZodError) {
14931
+ if (e instanceof import_zod25.z.ZodError) {
14217
14932
  let formatted;
14218
14933
  try {
14219
14934
  formatted = formatZodError(e, opts);
@@ -14589,18 +15304,45 @@ var Miniflare2 = class _Miniflare {
14589
15304
  #liveReloadServer;
14590
15305
  #webSocketServer;
14591
15306
  #webSocketExtraHeaders;
15307
+ #maybeInspectorProxyController;
15308
+ #previousRuntimeInspectorPort;
14592
15309
  constructor(opts) {
14593
15310
  const [sharedOpts, workerOpts] = validateOptions(opts);
14594
15311
  this.#sharedOpts = sharedOpts;
14595
15312
  this.#workerOpts = workerOpts;
15313
+ const workerNamesToProxy = new Set(
15314
+ this.#workerOpts.filter(({ core: { unsafeInspectorProxy } }) => !!unsafeInspectorProxy).map((w) => w.core.name ?? "")
15315
+ );
15316
+ const enableInspectorProxy = workerNamesToProxy.size > 0;
15317
+ if (enableInspectorProxy) {
15318
+ if (this.#sharedOpts.core.inspectorPort === void 0) {
15319
+ throw new MiniflareCoreError(
15320
+ "ERR_MISSING_INSPECTOR_PROXY_PORT",
15321
+ "inspector proxy requested but without an inspectorPort specified"
15322
+ );
15323
+ }
15324
+ }
14596
15325
  if (maybeInstanceRegistry !== void 0) {
14597
15326
  const object = { name: "Miniflare", stack: "" };
14598
15327
  Error.captureStackTrace(object, _Miniflare);
14599
15328
  maybeInstanceRegistry.set(this, object.stack);
14600
15329
  }
14601
15330
  this.#log = this.#sharedOpts.core.log ?? new NoOpLog();
14602
- this.#liveReloadServer = new import_ws3.WebSocketServer({ noServer: true });
14603
- this.#webSocketServer = new import_ws3.WebSocketServer({
15331
+ if (enableInspectorProxy) {
15332
+ if (this.#sharedOpts.core.inspectorPort === void 0) {
15333
+ throw new MiniflareCoreError(
15334
+ "ERR_MISSING_INSPECTOR_PROXY_PORT",
15335
+ "inspector proxy requested but without an inspectorPort specified"
15336
+ );
15337
+ }
15338
+ this.#maybeInspectorProxyController = new InspectorProxyController(
15339
+ this.#sharedOpts.core.inspectorPort,
15340
+ this.#log,
15341
+ workerNamesToProxy
15342
+ );
15343
+ }
15344
+ this.#liveReloadServer = new import_ws5.WebSocketServer({ noServer: true });
15345
+ this.#webSocketServer = new import_ws5.WebSocketServer({
14604
15346
  noServer: true,
14605
15347
  // Disable automatic handling of `Sec-WebSocket-Protocol` header,
14606
15348
  // Cloudflare Workers require users to include this header themselves in
@@ -14619,7 +15361,7 @@ var Miniflare2 = class _Miniflare {
14619
15361
  }
14620
15362
  }
14621
15363
  });
14622
- this.#tmpPath = import_path28.default.join(
15364
+ this.#tmpPath = import_path31.default.join(
14623
15365
  import_os2.default.tmpdir(),
14624
15366
  `miniflare-${import_crypto3.default.randomBytes(16).toString("hex")}`
14625
15367
  );
@@ -14627,7 +15369,7 @@ var Miniflare2 = class _Miniflare {
14627
15369
  this.#removeExitHook = (0, import_exit_hook.default)(() => {
14628
15370
  void this.#runtime?.dispose();
14629
15371
  try {
14630
- import_fs24.default.rmSync(this.#tmpPath, { force: true, recursive: true });
15372
+ import_fs27.default.rmSync(this.#tmpPath, { force: true, recursive: true });
14631
15373
  } catch (e) {
14632
15374
  this.#log.debug(`Unable to remove temporary directory: ${String(e)}`);
14633
15375
  }
@@ -14664,7 +15406,7 @@ var Miniflare2 = class _Miniflare {
14664
15406
  if (!(response instanceof Response)) {
14665
15407
  response = new Response(response.body, response);
14666
15408
  }
14667
- return import_zod23.z.instanceof(Response).parse(response);
15409
+ return import_zod25.z.instanceof(Response).parse(response);
14668
15410
  } catch (e) {
14669
15411
  return new Response(e?.stack ?? e, { status: 500 });
14670
15412
  }
@@ -14687,11 +15429,11 @@ var Miniflare2 = class _Miniflare {
14687
15429
  (0, import_assert12.default)(!Array.isArray(cfBlob));
14688
15430
  const cf = cfBlob ? JSON.parse(cfBlob) : void 0;
14689
15431
  const originalUrl = headers.get(CoreHeaders.ORIGINAL_URL);
14690
- const url20 = new URL(originalUrl ?? req.url ?? "", "http://localhost");
15432
+ const url23 = new URL(originalUrl ?? req.url ?? "", "http://localhost");
14691
15433
  headers.delete(CoreHeaders.ORIGINAL_URL);
14692
15434
  const noBody = req.method === "GET" || req.method === "HEAD";
14693
15435
  const body = noBody ? void 0 : safeReadableStreamFrom(req);
14694
- const request = new Request(url20, {
15436
+ const request = new Request(url23, {
14695
15437
  method: req.method,
14696
15438
  headers,
14697
15439
  body,
@@ -14712,13 +15454,13 @@ var Miniflare2 = class _Miniflare {
14712
15454
  request,
14713
15455
  this
14714
15456
  );
14715
- } else if (url20.pathname === "/core/error") {
15457
+ } else if (url23.pathname === "/core/error") {
14716
15458
  response = await handlePrettyErrorRequest(
14717
15459
  this.#log,
14718
15460
  this.#workerSrcOpts,
14719
15461
  request
14720
15462
  );
14721
- } else if (url20.pathname === "/core/log") {
15463
+ } else if (url23.pathname === "/core/log") {
14722
15464
  const level = parseInt(request.headers.get(SharedHeaders.LOG_LEVEL));
14723
15465
  (0, import_assert12.default)(
14724
15466
  0 /* NONE */ <= level && level <= 5 /* VERBOSE */,
@@ -14729,6 +15471,17 @@ var Miniflare2 = class _Miniflare {
14729
15471
  if (!$.enabled) message = stripAnsi(message);
14730
15472
  this.#log.logWithLevel(logLevel, message);
14731
15473
  response = new Response(null, { status: 204 });
15474
+ } else if (url23.pathname === "/core/store-temp-file") {
15475
+ const prefix = url23.searchParams.get("prefix");
15476
+ const folder = prefix ? `files/${prefix}` : "files";
15477
+ await (0, import_promises13.mkdir)(import_path31.default.join(this.#tmpPath, folder), { recursive: true });
15478
+ const filePath = import_path31.default.join(
15479
+ this.#tmpPath,
15480
+ folder,
15481
+ `${import_crypto3.default.randomUUID()}.${url23.searchParams.get("extension") ?? "txt"}`
15482
+ );
15483
+ await (0, import_promises13.writeFile)(filePath, await request.text());
15484
+ response = new Response(filePath, { status: 200 });
14732
15485
  }
14733
15486
  } catch (e) {
14734
15487
  this.#log.error(e);
@@ -14911,14 +15664,13 @@ var Miniflare2 = class _Miniflare {
14911
15664
  );
14912
15665
  if (maybeAssetTargetService && !binding.service?.entrypoint) {
14913
15666
  (0, import_assert12.default)(binding.service?.name);
14914
- binding.service.name = this.#sharedOpts.core.unsafeEnableAssetsRpc ? `${RPC_PROXY_SERVICE_NAME}:${targetWorkerName}` : `${ROUTER_SERVICE_NAME}:${targetWorkerName}`;
15667
+ binding.service.name = `${RPC_PROXY_SERVICE_NAME}:${targetWorkerName}`;
14915
15668
  }
14916
15669
  }
14917
15670
  }
14918
15671
  }
14919
15672
  }
14920
15673
  const unsafeStickyBlobs = sharedOpts.core.unsafeStickyBlobs ?? false;
14921
- const unsafeEnableAssetsRpc = sharedOpts.core.unsafeEnableAssetsRpc ?? false;
14922
15674
  const unsafeEphemeralDurableObjects = workerOpts.core.unsafeEphemeralDurableObjects ?? false;
14923
15675
  const pluginServicesOptionsBase = {
14924
15676
  log: this.#log,
@@ -14933,8 +15685,7 @@ var Miniflare2 = class _Miniflare {
14933
15685
  durableObjectClassNames,
14934
15686
  unsafeEphemeralDurableObjects,
14935
15687
  queueProducers,
14936
- queueConsumers,
14937
- unsafeEnableAssetsRpc
15688
+ queueConsumers
14938
15689
  };
14939
15690
  for (const [key, plugin] of PLUGIN_ENTRIES) {
14940
15691
  const pluginServicesExtensions = await plugin.getServices({
@@ -14982,13 +15733,16 @@ var Miniflare2 = class _Miniflare {
14982
15733
  directSocket.host,
14983
15734
  directSocket.port
14984
15735
  );
15736
+ const service = workerOpts.assets.assets && entrypoint === "default" ? {
15737
+ name: `${RPC_PROXY_SERVICE_NAME}:${workerOpts.core.name}`
15738
+ } : {
15739
+ name: getUserServiceName(workerName),
15740
+ entrypoint: entrypoint === "default" ? void 0 : entrypoint
15741
+ };
14985
15742
  sockets.push({
14986
15743
  name,
14987
15744
  address,
14988
- service: {
14989
- name: getUserServiceName(workerName),
14990
- entrypoint: entrypoint === "default" ? void 0 : entrypoint
14991
- },
15745
+ service,
14992
15746
  http: {
14993
15747
  style: directSocket.proxy ? HttpOptions_Style.PROXY : void 0,
14994
15748
  cfBlobHeader: CoreHeaders.CF_BLOB,
@@ -15001,15 +15755,15 @@ var Miniflare2 = class _Miniflare {
15001
15755
  sharedOptions: sharedOpts.core,
15002
15756
  allWorkerRoutes,
15003
15757
  /*
15004
- * - if Workers + Assets project but NOT Vitest, point to Router Worker or
15005
- * Proxy Worker depending on whether experimental flag `unsafeEnableAssetsRpc`
15006
- * was set
15007
- * - if Vitest with assets, the self binding on the test runner will point to
15008
- * Router Worker
15758
+ * - if Workers + Assets project but NOT Vitest, the fallback Worker (see
15759
+ * `MINIFLARE_USER_FALLBACK`) should point to the (assets) RPC Proxy Worker
15760
+ * - if Vitest with assets, the fallback Worker should point to the Vitest
15761
+ * runner Worker, while the SELF binding on the test runner will point to
15762
+ * the (assets) RPC Proxy Worker
15009
15763
  */
15010
15764
  fallbackWorkerName: this.#workerOpts[0].assets.assets && !this.#workerOpts[0].core.name?.startsWith(
15011
15765
  "vitest-pool-workers-runner-"
15012
- ) ? this.#sharedOpts.core.unsafeEnableAssetsRpc ? `${RPC_PROXY_SERVICE_NAME}:${this.#workerOpts[0].core.name}` : `${ROUTER_SERVICE_NAME}:${this.#workerOpts[0].core.name}` : getUserServiceName(this.#workerOpts[0].core.name),
15766
+ ) ? `${RPC_PROXY_SERVICE_NAME}:${this.#workerOpts[0].core.name}` : getUserServiceName(this.#workerOpts[0].core.name),
15013
15767
  loopbackPort,
15014
15768
  log: this.#log,
15015
15769
  proxyBindings
@@ -15060,14 +15814,19 @@ var Miniflare2 = class _Miniflare {
15060
15814
  configuredHost,
15061
15815
  this.#sharedOpts.core.port
15062
15816
  );
15063
- let inspectorAddress;
15817
+ let runtimeInspectorAddress;
15064
15818
  if (this.#sharedOpts.core.inspectorPort !== void 0) {
15065
- inspectorAddress = this.#getSocketAddress(
15819
+ let runtimeInspectorPort = this.#sharedOpts.core.inspectorPort;
15820
+ if (this.#maybeInspectorProxyController !== void 0) {
15821
+ runtimeInspectorPort = 0;
15822
+ }
15823
+ runtimeInspectorAddress = this.#getSocketAddress(
15066
15824
  kInspectorSocket,
15067
- this.#previousSharedOpts?.core.inspectorPort,
15825
+ this.#previousRuntimeInspectorPort,
15068
15826
  "localhost",
15069
- this.#sharedOpts.core.inspectorPort
15827
+ runtimeInspectorPort
15070
15828
  );
15829
+ this.#previousRuntimeInspectorPort = runtimeInspectorPort;
15071
15830
  }
15072
15831
  const loopbackAddress = `${maybeGetLocallyAccessibleHost(configuredHost) ?? getURLSafeHost(configuredHost)}:${loopbackPort}`;
15073
15832
  const runtimeOpts = {
@@ -15075,7 +15834,7 @@ var Miniflare2 = class _Miniflare {
15075
15834
  entryAddress,
15076
15835
  loopbackAddress,
15077
15836
  requiredSockets,
15078
- inspectorAddress,
15837
+ inspectorAddress: runtimeInspectorAddress,
15079
15838
  verbose: this.#sharedOpts.core.verbose,
15080
15839
  handleRuntimeStdio: this.#sharedOpts.core.handleRuntimeStdio
15081
15840
  };
@@ -15091,6 +15850,20 @@ var Miniflare2 = class _Miniflare {
15091
15850
  );
15092
15851
  }
15093
15852
  this.#socketPorts = maybeSocketPorts;
15853
+ if (this.#maybeInspectorProxyController !== void 0 && this.#sharedOpts.core.inspectorPort !== void 0) {
15854
+ const maybePort = this.#socketPorts.get(kInspectorSocket);
15855
+ if (maybePort === void 0) {
15856
+ throw new MiniflareCoreError(
15857
+ "ERR_RUNTIME_FAILURE",
15858
+ "Unable to access the runtime inspector socket."
15859
+ );
15860
+ } else {
15861
+ await this.#maybeInspectorProxyController.updateConnection(
15862
+ this.#sharedOpts.core.inspectorPort,
15863
+ maybePort
15864
+ );
15865
+ }
15866
+ }
15094
15867
  const entrySocket = config.sockets?.[0];
15095
15868
  const secure = entrySocket !== void 0 && "https" in entrySocket;
15096
15869
  const previousEntryURL = this.#runtimeEntryURL;
@@ -15122,10 +15895,12 @@ var Miniflare2 = class _Miniflare {
15122
15895
  if (!this.#runtimeMutex.hasWaiting) {
15123
15896
  const ready = initial ? "Ready" : "Updated and ready";
15124
15897
  const urlSafeHost = getURLSafeHost(configuredHost);
15125
- this.#log.info(
15126
- `${ready} on ${secure ? "https" : "http"}://${urlSafeHost}:${entryPort}`
15127
- );
15128
- if (initial) {
15898
+ if (this.#sharedOpts.core.logRequests) {
15899
+ this.#log.info(
15900
+ `${ready} on ${secure ? "https" : "http"}://${urlSafeHost}:${entryPort}`
15901
+ );
15902
+ }
15903
+ if (initial && this.#sharedOpts.core.logRequests) {
15129
15904
  const hosts = [];
15130
15905
  if (configuredHost === "::" || configuredHost === "*") {
15131
15906
  hosts.push("localhost");
@@ -15145,6 +15920,7 @@ var Miniflare2 = class _Miniflare {
15145
15920
  await this.#initPromise;
15146
15921
  await this.#runtimeMutex.drained();
15147
15922
  if (disposing) return new URL("http://[100::]/");
15923
+ await this.#maybeInspectorProxyController?.ready;
15148
15924
  this.#checkDisposed();
15149
15925
  (0, import_assert12.default)(this.#runtimeEntryURL !== void 0);
15150
15926
  return new URL(this.#runtimeEntryURL.toString());
@@ -15160,6 +15936,9 @@ var Miniflare2 = class _Miniflare {
15160
15936
  async getInspectorURL() {
15161
15937
  this.#checkDisposed();
15162
15938
  await this.ready;
15939
+ if (this.#maybeInspectorProxyController !== void 0) {
15940
+ return this.#maybeInspectorProxyController.getInspectorURL();
15941
+ }
15163
15942
  (0, import_assert12.default)(this.#socketPorts !== void 0);
15164
15943
  const maybePort = this.#socketPorts.get(kInspectorSocket);
15165
15944
  if (maybePort === void 0) {
@@ -15220,11 +15999,11 @@ var Miniflare2 = class _Miniflare {
15220
15999
  (0, import_assert12.default)(this.#runtimeEntryURL !== void 0);
15221
16000
  (0, import_assert12.default)(this.#runtimeDispatcher !== void 0);
15222
16001
  const forward = new Request(input, init2);
15223
- const url20 = new URL(forward.url);
16002
+ const url23 = new URL(forward.url);
15224
16003
  const actualRuntimeOrigin = this.#runtimeEntryURL.origin;
15225
- const userRuntimeOrigin = url20.origin;
15226
- url20.protocol = this.#runtimeEntryURL.protocol;
15227
- url20.host = this.#runtimeEntryURL.host;
16004
+ const userRuntimeOrigin = url23.origin;
16005
+ url23.protocol = this.#runtimeEntryURL.protocol;
16006
+ url23.host = this.#runtimeEntryURL.host;
15228
16007
  if (forward.body !== null && forward.headers.get("Content-Length") === "0") {
15229
16008
  forward.headers.delete("Content-Length");
15230
16009
  }
@@ -15238,7 +16017,7 @@ var Miniflare2 = class _Miniflare {
15238
16017
  );
15239
16018
  const forwardInit = forward;
15240
16019
  forwardInit.dispatcher = dispatcher;
15241
- const response = await fetch3(url20, forwardInit);
16020
+ const response = await fetch4(url23, forwardInit);
15242
16021
  const stack = response.headers.get(CoreHeaders.ERROR_STACK);
15243
16022
  if (response.status === 500 && stack !== null) {
15244
16023
  const caught = JsonErrorSchema.parse(await response.json());
@@ -15354,6 +16133,18 @@ var Miniflare2 = class _Miniflare {
15354
16133
  getKVNamespace(bindingName, workerName) {
15355
16134
  return this.#getProxy(KV_PLUGIN_NAME, bindingName, workerName);
15356
16135
  }
16136
+ getSecretsStoreSecretAPI(bindingName, workerName) {
16137
+ return this.#getProxy(
16138
+ SECRET_STORE_PLUGIN_NAME,
16139
+ bindingName,
16140
+ workerName
16141
+ ).then((binding) => {
16142
+ return binding[ADMIN_API];
16143
+ });
16144
+ }
16145
+ getSecretsStoreSecret(bindingName, workerName) {
16146
+ return this.#getProxy(SECRET_STORE_PLUGIN_NAME, bindingName, workerName);
16147
+ }
15357
16148
  getQueueProducer(bindingName, workerName) {
15358
16149
  return this.#getProxy(QUEUES_PLUGIN_NAME, bindingName, workerName);
15359
16150
  }
@@ -15386,7 +16177,8 @@ var Miniflare2 = class _Miniflare {
15386
16177
  await this.#proxyClient?.dispose();
15387
16178
  await this.#runtime?.dispose();
15388
16179
  await this.#stopLoopbackServer();
15389
- await import_fs24.default.promises.rm(this.#tmpPath, { force: true, recursive: true });
16180
+ await import_fs27.default.promises.rm(this.#tmpPath, { force: true, recursive: true });
16181
+ await this.#maybeInspectorProxyController?.dispose();
15390
16182
  maybeInstanceRegistry?.delete(this);
15391
16183
  }
15392
16184
  }
@@ -15420,6 +16212,9 @@ var Miniflare2 = class _Miniflare {
15420
16212
  DispatchFetchDispatcher,
15421
16213
  DurableObjectsOptionsSchema,
15422
16214
  DurableObjectsSharedOptionsSchema,
16215
+ EMAIL_PLUGIN,
16216
+ EMAIL_PLUGIN_NAME,
16217
+ EmailOptionsSchema,
15423
16218
  ErrorEvent,
15424
16219
  File,
15425
16220
  FormData,
@@ -15441,6 +16236,7 @@ var Miniflare2 = class _Miniflare {
15441
16236
  LiteralSchema,
15442
16237
  Log,
15443
16238
  LogLevel,
16239
+ MAX_BULK_GET_KEYS,
15444
16240
  MessageEvent,
15445
16241
  Miniflare,
15446
16242
  MiniflareCoreError,
@@ -15489,11 +16285,15 @@ var Miniflare2 = class _Miniflare {
15489
16285
  Response,
15490
16286
  RouterError,
15491
16287
  Runtime,
16288
+ SECRET_STORE_PLUGIN,
16289
+ SECRET_STORE_PLUGIN_NAME,
15492
16290
  SERVICE_ENTRY,
15493
16291
  SERVICE_LOOPBACK,
15494
16292
  SITES_NO_CACHE_PREFIX,
15495
16293
  SOCKET_ENTRY,
15496
16294
  SOCKET_ENTRY_LOCAL,
16295
+ SecretsStoreSecretsOptionsSchema,
16296
+ SecretsStoreSecretsSharedOptionsSchema,
15497
16297
  SharedBindings,
15498
16298
  SharedHeaders,
15499
16299
  SiteBindings,