@zuplo/cli 6.74.10 → 6.74.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/node_modules/@hono/node-server/README.md +47 -1
  2. package/node_modules/@hono/node-server/dist/early-hints.cjs +35 -0
  3. package/node_modules/@hono/node-server/dist/early-hints.d.cts +16 -0
  4. package/node_modules/@hono/node-server/dist/early-hints.d.mts +16 -0
  5. package/node_modules/@hono/node-server/dist/early-hints.mjs +33 -0
  6. package/node_modules/@hono/node-server/dist/index.cjs +4 -1
  7. package/node_modules/@hono/node-server/dist/index.mjs +4 -1
  8. package/node_modules/@hono/node-server/package.json +14 -1
  9. package/node_modules/@posthog/core/dist/featureFlagUtils.d.ts +1 -0
  10. package/node_modules/@posthog/core/dist/featureFlagUtils.d.ts.map +1 -1
  11. package/node_modules/@posthog/core/dist/featureFlagUtils.js +31 -0
  12. package/node_modules/@posthog/core/dist/featureFlagUtils.mjs +29 -1
  13. package/node_modules/@posthog/core/dist/index.d.ts +1 -1
  14. package/node_modules/@posthog/core/dist/index.d.ts.map +1 -1
  15. package/node_modules/@posthog/core/dist/index.js +9 -0
  16. package/node_modules/@posthog/core/dist/index.mjs +2 -2
  17. package/node_modules/@posthog/core/dist/utils/index.d.ts +1 -0
  18. package/node_modules/@posthog/core/dist/utils/index.d.ts.map +1 -1
  19. package/node_modules/@posthog/core/dist/utils/index.js +45 -18
  20. package/node_modules/@posthog/core/dist/utils/index.mjs +1 -0
  21. package/node_modules/@posthog/core/dist/utils/json-utils.d.ts +6 -0
  22. package/node_modules/@posthog/core/dist/utils/json-utils.d.ts.map +1 -0
  23. package/node_modules/@posthog/core/dist/utils/json-utils.js +128 -0
  24. package/node_modules/@posthog/core/dist/utils/json-utils.mjs +94 -0
  25. package/node_modules/@posthog/core/package.json +2 -2
  26. package/node_modules/@posthog/core/src/featureFlagUtils.ts +35 -0
  27. package/node_modules/@posthog/core/src/index.ts +1 -0
  28. package/node_modules/@posthog/core/src/utils/index.ts +1 -0
  29. package/node_modules/@posthog/core/src/utils/json-utils.spec.ts +115 -0
  30. package/node_modules/@posthog/core/src/utils/json-utils.ts +148 -0
  31. package/node_modules/@posthog/types/dist/posthog-config.d.ts +25 -1
  32. package/node_modules/@posthog/types/dist/posthog-config.d.ts.map +1 -1
  33. package/node_modules/@posthog/types/dist/posthog.d.ts +4 -0
  34. package/node_modules/@posthog/types/dist/posthog.d.ts.map +1 -1
  35. package/node_modules/@posthog/types/package.json +1 -1
  36. package/node_modules/@posthog/types/src/posthog-config.ts +26 -1
  37. package/node_modules/@posthog/types/src/posthog.ts +4 -0
  38. package/node_modules/@zuplo/core/customer.cli.minified.js +254 -254
  39. package/node_modules/@zuplo/core/index.minified.js +251 -251
  40. package/node_modules/@zuplo/core/package.json +1 -1
  41. package/node_modules/@zuplo/graphql/out/esm/index.js +12 -12
  42. package/node_modules/@zuplo/graphql/package.json +1 -1
  43. package/node_modules/@zuplo/openapi-tools/package.json +2 -2
  44. package/node_modules/@zuplo/otel/out/esm/{chunk-TXIQ6WNA.js → chunk-AHNBOCFU.js} +1 -1
  45. package/node_modules/@zuplo/otel/out/esm/index.js +1 -1
  46. package/node_modules/@zuplo/otel/package.json +1 -1
  47. package/node_modules/@zuplo/runtime/out/esm/{chunk-SMQPMERU.js → chunk-4CDML74A.js} +2 -2
  48. package/node_modules/@zuplo/runtime/out/esm/chunk-4POCC75H.js +37 -0
  49. package/node_modules/@zuplo/runtime/out/esm/chunk-4POCC75H.js.map +1 -0
  50. package/node_modules/@zuplo/runtime/out/esm/chunk-CJFLOF27.js +26 -0
  51. package/node_modules/@zuplo/runtime/out/esm/chunk-CJFLOF27.js.map +1 -0
  52. package/node_modules/@zuplo/runtime/out/esm/{chunk-2UG5Z76T.js → chunk-RAZK5G27.js} +2 -2
  53. package/node_modules/@zuplo/runtime/out/esm/{chunk-2EFTGELI.js → chunk-YFAVPQDX.js} +94 -92
  54. package/node_modules/@zuplo/runtime/out/esm/chunk-YFAVPQDX.js.map +1 -0
  55. package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
  56. package/node_modules/@zuplo/runtime/out/esm/index.js.map +1 -1
  57. package/node_modules/@zuplo/runtime/out/esm/internal/index.js +1 -1
  58. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
  59. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js.map +1 -1
  60. package/node_modules/@zuplo/runtime/out/esm/mocks/index.js +1 -1
  61. package/node_modules/@zuplo/runtime/out/esm/sdks/aws/index.js +1 -1
  62. package/node_modules/@zuplo/runtime/out/types/index.d.ts +177 -0
  63. package/node_modules/@zuplo/runtime/package.json +1 -1
  64. package/node_modules/express-rate-limit/dist/index.cjs +6 -1
  65. package/node_modules/express-rate-limit/dist/index.mjs +6 -1
  66. package/node_modules/express-rate-limit/package.json +6 -6
  67. package/node_modules/hono/dist/cjs/context.js +28 -13
  68. package/node_modules/hono/dist/cjs/hono-base.js +3 -2
  69. package/node_modules/hono/dist/cjs/jsx/base.js +26 -14
  70. package/node_modules/hono/dist/cjs/jsx/hooks/index.js +2 -2
  71. package/node_modules/hono/dist/cjs/middleware/cache/index.js +103 -8
  72. package/node_modules/hono/dist/cjs/middleware/compress/index.js +5 -0
  73. package/node_modules/hono/dist/cjs/middleware/cors/index.js +1 -1
  74. package/node_modules/hono/dist/cjs/middleware/etag/index.js +1 -1
  75. package/node_modules/hono/dist/cjs/middleware/jwk/jwk.js +9 -4
  76. package/node_modules/hono/dist/cjs/middleware/jwt/jwt.js +9 -4
  77. package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +90 -0
  78. package/node_modules/hono/dist/cjs/request.js +6 -8
  79. package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +55 -56
  80. package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +64 -85
  81. package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +13 -5
  82. package/node_modules/hono/dist/cjs/router.js +1 -1
  83. package/node_modules/hono/dist/cjs/utils/cookie.js +1 -1
  84. package/node_modules/hono/dist/cjs/utils/url.js +7 -7
  85. package/node_modules/hono/dist/context.js +28 -13
  86. package/node_modules/hono/dist/hono-base.js +3 -2
  87. package/node_modules/hono/dist/jsx/base.js +26 -14
  88. package/node_modules/hono/dist/jsx/hooks/index.js +2 -2
  89. package/node_modules/hono/dist/middleware/cache/index.js +103 -8
  90. package/node_modules/hono/dist/middleware/compress/index.js +5 -0
  91. package/node_modules/hono/dist/middleware/cors/index.js +1 -1
  92. package/node_modules/hono/dist/middleware/etag/index.js +1 -1
  93. package/node_modules/hono/dist/middleware/jwk/jwk.js +9 -4
  94. package/node_modules/hono/dist/middleware/jwt/jwt.js +9 -4
  95. package/node_modules/hono/dist/middleware/method-not-allowed/index.js +68 -0
  96. package/node_modules/hono/dist/request.js +7 -9
  97. package/node_modules/hono/dist/router/reg-exp-router/node.js +55 -56
  98. package/node_modules/hono/dist/router/reg-exp-router/router.js +64 -85
  99. package/node_modules/hono/dist/router/reg-exp-router/trie.js +13 -5
  100. package/node_modules/hono/dist/router.js +1 -1
  101. package/node_modules/hono/dist/types/client/types.d.ts +1 -1
  102. package/node_modules/hono/dist/types/hono-base.d.ts +4 -3
  103. package/node_modules/hono/dist/types/jsx/base.d.ts +4 -2
  104. package/node_modules/hono/dist/types/jsx/dom/index.d.ts +5 -5
  105. package/node_modules/hono/dist/types/jsx/dom/intrinsic-element/components.d.ts +2 -2
  106. package/node_modules/hono/dist/types/jsx/dom/server.d.ts +5 -5
  107. package/node_modules/hono/dist/types/jsx/hooks/index.d.ts +8 -6
  108. package/node_modules/hono/dist/types/jsx/index.d.ts +5 -5
  109. package/node_modules/hono/dist/types/middleware/cache/index.d.ts +6 -4
  110. package/node_modules/hono/dist/types/middleware/cors/index.d.ts +1 -1
  111. package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +2 -2
  112. package/node_modules/hono/dist/types/middleware/jwk/jwk.d.ts +2 -0
  113. package/node_modules/hono/dist/types/middleware/jwt/jwt.d.ts +2 -0
  114. package/node_modules/hono/dist/types/middleware/method-not-allowed/index.d.ts +49 -0
  115. package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +1 -1
  116. package/node_modules/hono/dist/types/router/reg-exp-router/trie.d.ts +2 -1
  117. package/node_modules/hono/dist/types/router.d.ts +1 -1
  118. package/node_modules/hono/dist/types/utils/headers.d.ts +2 -2
  119. package/node_modules/hono/dist/types/utils/url.d.ts +1 -0
  120. package/node_modules/hono/dist/utils/cookie.js +2 -2
  121. package/node_modules/hono/dist/utils/url.js +5 -6
  122. package/node_modules/hono/package.json +9 -1
  123. package/node_modules/tar/dist/commonjs/index.min.js +1 -1
  124. package/node_modules/tar/dist/commonjs/index.min.js.map +3 -3
  125. package/node_modules/tar/dist/commonjs/list.d.ts.map +1 -1
  126. package/node_modules/tar/dist/commonjs/list.js +10 -2
  127. package/node_modules/tar/dist/commonjs/list.js.map +1 -1
  128. package/node_modules/tar/dist/commonjs/options.d.ts +1 -1
  129. package/node_modules/tar/dist/commonjs/options.d.ts.map +1 -1
  130. package/node_modules/tar/dist/commonjs/options.js.map +1 -1
  131. package/node_modules/tar/dist/esm/index.min.js +2 -2
  132. package/node_modules/tar/dist/esm/index.min.js.map +3 -3
  133. package/node_modules/tar/dist/esm/list.d.ts.map +1 -1
  134. package/node_modules/tar/dist/esm/list.js +10 -2
  135. package/node_modules/tar/dist/esm/list.js.map +1 -1
  136. package/node_modules/tar/dist/esm/options.d.ts +1 -1
  137. package/node_modules/tar/dist/esm/options.d.ts.map +1 -1
  138. package/node_modules/tar/dist/esm/options.js.map +1 -1
  139. package/node_modules/tar/package.json +1 -1
  140. package/node_modules/undici/lib/core/request.js +12 -1
  141. package/node_modules/undici/lib/dispatcher/client-h1.js +11 -2
  142. package/node_modules/undici/lib/handler/retry-handler.js +34 -0
  143. package/node_modules/undici/lib/web/cookies/util.js +79 -9
  144. package/node_modules/undici/package.json +1 -1
  145. package/package.json +8 -8
  146. package/node_modules/@zuplo/runtime/out/esm/chunk-2EFTGELI.js.map +0 -1
  147. package/node_modules/@zuplo/runtime/out/esm/chunk-7AMMYBFQ.js +0 -37
  148. package/node_modules/@zuplo/runtime/out/esm/chunk-7AMMYBFQ.js.map +0 -1
  149. package/node_modules/@zuplo/runtime/out/esm/chunk-ZB7PAWBM.js +0 -26
  150. package/node_modules/@zuplo/runtime/out/esm/chunk-ZB7PAWBM.js.map +0 -1
  151. /package/node_modules/@zuplo/otel/out/esm/{chunk-TXIQ6WNA.js.map → chunk-AHNBOCFU.js.map} +0 -0
  152. /package/node_modules/@zuplo/runtime/out/esm/{chunk-SMQPMERU.js.map → chunk-4CDML74A.js.map} +0 -0
  153. /package/node_modules/@zuplo/runtime/out/esm/{chunk-7AMMYBFQ.js.LEGAL.txt → chunk-4POCC75H.js.LEGAL.txt} +0 -0
  154. /package/node_modules/@zuplo/runtime/out/esm/{chunk-2UG5Z76T.js.map → chunk-RAZK5G27.js.map} +0 -0
  155. /package/node_modules/@zuplo/runtime/out/esm/{chunk-2EFTGELI.js.LEGAL.txt → chunk-YFAVPQDX.js.LEGAL.txt} +0 -0
@@ -88,7 +88,7 @@ const parse = (cookie, name) => {
88
88
  cookieValue = cookieValue.slice(1, -1);
89
89
  }
90
90
  if (validCookieValueRegEx.test(cookieValue)) {
91
- parsedCookie[cookieName] = cookieValue.indexOf("%") !== -1 ? (0, import_url.tryDecode)(cookieValue, import_url.decodeURIComponent_) : cookieValue;
91
+ parsedCookie[cookieName] = (0, import_url.tryDecodeURIComponent)(cookieValue);
92
92
  if (name) {
93
93
  break;
94
94
  }
@@ -29,7 +29,8 @@ __export(url_exports, {
29
29
  splitPath: () => splitPath,
30
30
  splitRoutingPath: () => splitRoutingPath,
31
31
  tryDecode: () => tryDecode,
32
- tryDecodeURI: () => tryDecodeURI
32
+ tryDecodeURI: () => tryDecodeURI,
33
+ tryDecodeURIComponent: () => tryDecodeURIComponent
33
34
  });
34
35
  module.exports = __toCommonJS(url_exports);
35
36
  const splitPath = (path) => {
@@ -157,18 +158,16 @@ const checkOptionalParameter = (path) => {
157
158
  });
158
159
  return results.filter((v, i, a) => a.indexOf(v) === i);
159
160
  };
161
+ const tryDecodeURIComponent = (str) => str.indexOf("%") !== -1 ? tryDecode(str, decodeURIComponent_) : str;
160
162
  const _decodeURI = (value) => {
161
- if (!/[%+]/.test(value)) {
162
- return value;
163
- }
164
163
  if (value.indexOf("+") !== -1) {
165
164
  value = value.replace(/\+/g, " ");
166
165
  }
167
- return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
166
+ return tryDecodeURIComponent(value);
168
167
  };
169
168
  const _getQueryParam = (url, key, multiple) => {
170
169
  let encoded;
171
- if (!multiple && key && !/[%+]/.test(key)) {
170
+ if (!multiple && key && key.indexOf("%") === -1 && key.indexOf("+") === -1) {
172
171
  let keyIndex2 = url.indexOf("?", 8);
173
172
  if (keyIndex2 === -1) {
174
173
  return void 0;
@@ -252,5 +251,6 @@ const decodeURIComponent_ = decodeURIComponent;
252
251
  splitPath,
253
252
  splitRoutingPath,
254
253
  tryDecode,
255
- tryDecodeURI
254
+ tryDecodeURI,
255
+ tryDecodeURIComponent
256
256
  });
@@ -273,11 +273,11 @@ var Context = class {
273
273
  return Object.fromEntries(this.#var);
274
274
  }
275
275
  #newResponse(data, arg, headers) {
276
- const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers();
277
- if (typeof arg === "object" && "headers" in arg) {
278
- const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
279
- for (const [key, value] of argHeaders) {
280
- if (key.toLowerCase() === "set-cookie") {
276
+ let responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders;
277
+ if (typeof arg === "object" && arg.headers) {
278
+ responseHeaders ??= new Headers();
279
+ for (const [key, value] of new Headers(arg.headers)) {
280
+ if (key === "set-cookie") {
281
281
  responseHeaders.append(key, value);
282
282
  } else {
283
283
  responseHeaders.set(key, value);
@@ -285,19 +285,34 @@ var Context = class {
285
285
  }
286
286
  }
287
287
  if (headers) {
288
- for (const [k, v] of Object.entries(headers)) {
289
- if (typeof v === "string") {
290
- responseHeaders.set(k, v);
291
- } else {
292
- responseHeaders.delete(k);
293
- for (const v2 of v) {
294
- responseHeaders.append(k, v2);
288
+ if (!responseHeaders) {
289
+ let count = 0;
290
+ for (const k in headers) {
291
+ if (++count > 1 || typeof headers[k] !== "string") {
292
+ responseHeaders = new Headers();
293
+ break;
294
+ }
295
+ }
296
+ }
297
+ if (responseHeaders) {
298
+ for (const k in headers) {
299
+ const v = headers[k];
300
+ if (typeof v === "string") {
301
+ responseHeaders.set(k, v);
302
+ } else {
303
+ responseHeaders.delete(k);
304
+ for (const v2 of v) {
305
+ responseHeaders.append(k, v2);
306
+ }
295
307
  }
296
308
  }
297
309
  }
298
310
  }
299
311
  const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
300
- return createResponseInstance(data, { status, headers: responseHeaders });
312
+ return createResponseInstance(data, {
313
+ status,
314
+ headers: responseHeaders ?? headers
315
+ });
301
316
  }
302
317
  newResponse = (...args) => this.#newResponse(...args);
303
318
  /**
@@ -22,6 +22,7 @@ var Hono = class _Hono {
22
22
  delete;
23
23
  options;
24
24
  patch;
25
+ query;
25
26
  all;
26
27
  on;
27
28
  use;
@@ -321,8 +322,8 @@ var Hono = class _Hono {
321
322
  * @see {@link https://hono.dev/docs/api/hono#fetch}
322
323
  *
323
324
  * @param {Request} request - request Object of request
324
- * @param {Env} Env - env Object
325
- * @param {ExecutionContext} - context of execution
325
+ * @param {Env} env - env Object
326
+ * @param {ExecutionContext} executionCtx - context of execution
326
327
  * @returns {Response | Promise<Response>} response of request
327
328
  *
328
329
  */
@@ -69,6 +69,18 @@ var booleanAttributes = [
69
69
  "reversed",
70
70
  "selected"
71
71
  ];
72
+ var resolveFunctionComponentResult = (result, suspendedContext) => result.then((resolved) => {
73
+ if (!Array.isArray(resolved) && !(resolved instanceof JSXNode)) {
74
+ return resolved;
75
+ }
76
+ const children = Array.isArray(resolved) ? resolved : [resolved];
77
+ const render = () => {
78
+ const buffer = [""];
79
+ childrenToStringToBuffer(children, buffer);
80
+ return buffer.length === 1 ? raw(buffer[0], buffer.callbacks) : stringBufferToString(buffer, buffer.callbacks);
81
+ };
82
+ return suspendedContext ? suspendedContext(render) : runWithRenderContext(render);
83
+ });
72
84
  var childrenToStringToBuffer = (children, buffer) => {
73
85
  for (let i = 0, len = children.length; i < len; i++) {
74
86
  const child = children[i];
@@ -78,9 +90,17 @@ var childrenToStringToBuffer = (children, buffer) => {
78
90
  continue;
79
91
  } else if (child instanceof JSXNode) {
80
92
  child.toStringToBuffer(buffer);
81
- } else if (typeof child === "number" || child.isEscaped) {
93
+ } else if (typeof child === "number") {
94
+ ;
95
+ buffer[0] += child;
96
+ } else if (child.isEscaped) {
82
97
  ;
83
98
  buffer[0] += child;
99
+ const callbacks = child.callbacks;
100
+ if (callbacks) {
101
+ buffer.callbacks ||= [];
102
+ buffer.callbacks.push(...callbacks);
103
+ }
84
104
  } else if (child instanceof Promise) {
85
105
  buffer.unshift("", child);
86
106
  } else {
@@ -94,7 +114,6 @@ var JSXNode = class {
94
114
  key;
95
115
  children;
96
116
  isEscaped = true;
97
- suspendedContext;
98
117
  constructor(tag, props, children) {
99
118
  if (typeof tag !== "function" && !isValidTagName(tag)) {
100
119
  throw new Error(`Invalid JSX tag name: ${tag}`);
@@ -117,7 +136,7 @@ var JSXNode = class {
117
136
  this.toStringToBuffer(buffer);
118
137
  return buffer.length === 1 ? "callbacks" in buffer ? resolveCallbackSync(raw(buffer[0], buffer.callbacks)).toString() : buffer[0] : stringBufferToString(buffer, buffer.callbacks);
119
138
  };
120
- return this.suspendedContext ? this.suspendedContext(render) : runWithRenderContext(render);
139
+ return runWithRenderContext(render);
121
140
  }
122
141
  toStringToBuffer(buffer) {
123
142
  const tag = this.tag;
@@ -191,21 +210,14 @@ var JSXFunctionNode = class extends JSXNode {
191
210
  return;
192
211
  } else if (res instanceof Promise) {
193
212
  if (globalContexts.length === 0) {
194
- buffer.unshift("", res);
213
+ buffer.unshift("", resolveFunctionComponentResult(res));
195
214
  } else {
196
- const suspendedContext = captureRenderContext();
197
- buffer.unshift(
198
- "",
199
- res.then((childRes) => {
200
- if (childRes instanceof JSXNode) {
201
- childRes.suspendedContext = suspendedContext;
202
- }
203
- return childRes;
204
- })
205
- );
215
+ buffer.unshift("", resolveFunctionComponentResult(res, captureRenderContext()));
206
216
  }
207
217
  } else if (res instanceof JSXNode) {
208
218
  res.toStringToBuffer(buffer);
219
+ } else if (Array.isArray(res)) {
220
+ childrenToStringToBuffer(res, buffer);
209
221
  } else if (typeof res === "number" || res.isEscaped) {
210
222
  buffer[0] += res;
211
223
  if (res.callbacks) {
@@ -222,7 +222,7 @@ var useCallback = (callback, deps) => {
222
222
  }
223
223
  return callback;
224
224
  };
225
- var useRef = (initialValue) => {
225
+ function useRef(initialValue) {
226
226
  const buildData = buildDataStack.at(-1);
227
227
  if (!buildData) {
228
228
  return { current: initialValue };
@@ -231,7 +231,7 @@ var useRef = (initialValue) => {
231
231
  const refArray = node[DOM_STASH][1][STASH_REF] ||= [];
232
232
  const hookIndex = node[DOM_STASH][0]++;
233
233
  return refArray[hookIndex] ||= { current: initialValue };
234
- };
234
+ }
235
235
  var use = (promise) => {
236
236
  const cachedRes = resolvedPromiseValueMap.get(promise);
237
237
  if (cachedRes) {
@@ -1,5 +1,19 @@
1
1
  // src/middleware/cache/index.ts
2
+ import { cloneRawRequest } from "../../request.js";
3
+ import { sha256 } from "../../utils/crypto.js";
2
4
  var defaultCacheableStatusCodes = [200];
5
+ var defaultMaxQueryBodySize = 64 * 1024;
6
+ var cacheKeyPath = "/.hono/cache";
7
+ var cacheKeyParameter = "__hono_cache_key";
8
+ var cacheMethodKeyParameter = "__hono_cache_method";
9
+ var queryDigestKeyParameter = "__hono_query_digest";
10
+ var cacheVaryKeyParameter = "__hono_cache_vary";
11
+ var queryRepresentationMetadataHeaders = [
12
+ "content-type",
13
+ "content-encoding",
14
+ "content-language",
15
+ "content-location"
16
+ ];
3
17
  var shouldSkipCacheControl = (cacheControl) => !!cacheControl && /(?:^|,\s*)(?:private|no-(?:store|cache))(?:\s*(?:=|,|$))/i.test(cacheControl);
4
18
  var parseVaryDirectives = (vary) => {
5
19
  if (vary == null) {
@@ -7,17 +21,86 @@ var parseVaryDirectives = (vary) => {
7
21
  }
8
22
  return (Array.isArray(vary) ? vary : vary.split(",")).map((directive) => directive.trim().toLowerCase()).filter(Boolean);
9
23
  };
24
+ var createCacheKey = (key, requestUrl, request, varyHeaders) => {
25
+ const url = new URL(cacheKeyPath, requestUrl);
26
+ url.searchParams.append(cacheKeyParameter, key.split("#", 1)[0]);
27
+ url.searchParams.append(cacheMethodKeyParameter, request.method);
28
+ if (request.method === "QUERY") {
29
+ url.searchParams.append(queryDigestKeyParameter, request.digest);
30
+ }
31
+ for (const header of varyHeaders) {
32
+ url.searchParams.append(cacheVaryKeyParameter, JSON.stringify(header));
33
+ }
34
+ return url.href;
35
+ };
10
36
  var shouldSkipCache = (res, optionsVaryDirectives, responseVary) => responseVary.length && (!optionsVaryDirectives || responseVary.some((name) => !optionsVaryDirectives.has(name))) || shouldSkipCacheControl(res.headers.get("Cache-Control")) || res.headers.has("Set-Cookie");
37
+ var reportCacheNotAvailable = (onCacheNotAvailable, reason) => {
38
+ if (onCacheNotAvailable === false) {
39
+ } else if (onCacheNotAvailable) {
40
+ onCacheNotAvailable(reason);
41
+ } else {
42
+ console.log(reason);
43
+ }
44
+ };
45
+ var createQueryDigest = async (c, maxQueryBodySize) => {
46
+ if (!globalThis.crypto?.subtle) {
47
+ return void 0;
48
+ }
49
+ if (c.req.raw.bodyUsed && Object.keys(c.req.bodyCache)[0] === "formData") {
50
+ return void 0;
51
+ }
52
+ try {
53
+ const requestHeaders = c.req.raw.headers;
54
+ const metadata = new TextEncoder().encode(
55
+ JSON.stringify(
56
+ queryRepresentationMetadataHeaders.map((header) => [header, requestHeaders.get(header)])
57
+ )
58
+ );
59
+ const body = (await cloneRawRequest(c.req)).body;
60
+ const chunks = [];
61
+ let bodySize = 0;
62
+ if (body) {
63
+ const reader = body.getReader();
64
+ for (; ; ) {
65
+ const { done, value } = await reader.read();
66
+ if (done) {
67
+ break;
68
+ }
69
+ bodySize += value.byteLength;
70
+ if (bodySize > maxQueryBodySize) {
71
+ void reader.cancel().catch(() => {
72
+ });
73
+ return void 0;
74
+ }
75
+ chunks.push(value);
76
+ }
77
+ }
78
+ const data = new Uint8Array(metadata.byteLength + bodySize);
79
+ data.set(metadata);
80
+ let offset = metadata.byteLength;
81
+ for (const chunk of chunks) {
82
+ data.set(chunk, offset);
83
+ offset += chunk.byteLength;
84
+ }
85
+ return await sha256(data) ?? void 0;
86
+ } catch {
87
+ return void 0;
88
+ }
89
+ };
11
90
  var cache = (options) => {
12
91
  if (!globalThis.caches) {
13
- if (options.onCacheNotAvailable === false) {
14
- } else if (options.onCacheNotAvailable) {
15
- options.onCacheNotAvailable();
16
- } else {
17
- console.log("Cache Middleware is not enabled because caches is not defined.");
18
- }
92
+ reportCacheNotAvailable(
93
+ options.onCacheNotAvailable,
94
+ "Cache Middleware is not enabled because caches is not defined."
95
+ );
19
96
  return async (_c, next) => await next();
20
97
  }
98
+ if (!globalThis.crypto?.subtle) {
99
+ reportCacheNotAvailable(
100
+ options.onCacheNotAvailable,
101
+ "Cache Middleware cannot cache QUERY requests because Web Crypto is not available."
102
+ );
103
+ }
21
104
  if (options.wait === void 0) {
22
105
  options.wait = false;
23
106
  }
@@ -32,6 +115,7 @@ var cache = (options) => {
32
115
  const cacheableStatusCodes = new Set(
33
116
  options.cacheableStatusCodes ?? defaultCacheableStatusCodes
34
117
  );
118
+ const maxQueryBodySize = options.maxQueryBodySize ?? defaultMaxQueryBodySize;
35
119
  const addHeader = (c, responseVary) => {
36
120
  if (cacheControlDirectives) {
37
121
  const existingDirectives = c.res.headers.get("Cache-Control")?.split(",").map((d) => d.trim().split("=", 1)[0].toLowerCase()) ?? [];
@@ -60,20 +144,31 @@ var cache = (options) => {
60
144
  }
61
145
  };
62
146
  return async function cache2(c, next) {
63
- if (c.req.method !== "GET" || c.req.raw.headers.has("Authorization")) {
147
+ if (c.req.method !== "GET" && c.req.method !== "QUERY" || c.req.raw.headers.has("Authorization")) {
64
148
  await next();
65
149
  return;
66
150
  }
151
+ let cacheKeyRequest = { method: "GET" };
152
+ if (c.req.method === "QUERY") {
153
+ const digest = await createQueryDigest(c, maxQueryBodySize);
154
+ if (digest === void 0) {
155
+ await next();
156
+ return;
157
+ }
158
+ cacheKeyRequest = { method: "QUERY", digest };
159
+ }
67
160
  let key = c.req.url;
68
161
  if (options.keyGenerator) {
69
162
  key = await options.keyGenerator(c);
70
163
  }
164
+ const varyHeaders = [];
71
165
  if (varyDirectives) {
72
166
  for (const directive of varyDirectives) {
73
167
  const value = c.req.raw.headers.get(directive) ?? "";
74
- key += `::${directive}=${encodeURIComponent(value)}`;
168
+ varyHeaders.push([directive, value]);
75
169
  }
76
170
  }
171
+ key = createCacheKey(key, c.req.url, cacheKeyRequest, varyHeaders);
77
172
  const cacheName = typeof options.cacheName === "function" ? await options.cacheName(c) : options.cacheName;
78
173
  const cache3 = await caches.open(cacheName);
79
174
  const response = await cache3.match(key);
@@ -21,6 +21,7 @@ var selectEncoding = (header, candidates) => {
21
21
  }
22
22
  return best?.encoding;
23
23
  };
24
+ var varyAcceptEncodingRegExp = /(?:^|,)\s*accept-encoding\s*(?:,|$)/i;
24
25
  var compress = (options) => {
25
26
  const threshold = options?.threshold ?? 1024;
26
27
  const candidates = options?.encoding ? [options.encoding] : ENCODING_TYPES;
@@ -44,6 +45,10 @@ var compress = (options) => {
44
45
  !shouldTransform(ctx.res)) {
45
46
  return;
46
47
  }
48
+ const current = ctx.res.headers.get("Vary");
49
+ if (current !== "*" && !(current && varyAcceptEncodingRegExp.test(current))) {
50
+ ctx.header("Vary", current ? `${current}, Accept-Encoding` : "Accept-Encoding");
51
+ }
47
52
  const accepted = ctx.req.header("Accept-Encoding");
48
53
  const encoding = selectEncoding(accepted, candidates);
49
54
  if (!encoding || !ctx.res.body) {
@@ -2,7 +2,7 @@
2
2
  var cors = (options) => {
3
3
  const opts = {
4
4
  origin: "*",
5
- allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
5
+ allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH", "QUERY"],
6
6
  allowHeaders: [],
7
7
  exposeHeaders: [],
8
8
  ...options
@@ -48,7 +48,7 @@ var etag = (options) => {
48
48
  }
49
49
  etag3 = weak ? `W/"${hash}"` : `"${hash}"`;
50
50
  }
51
- const matched = ifNoneMatch === "*" ? (c.req.method === "GET" || c.req.method === "HEAD") && res.ok : etagMatches(etag3, ifNoneMatch);
51
+ const matched = ifNoneMatch === "*" ? (c.req.method === "GET" || c.req.method === "HEAD" || c.req.method === "QUERY") && res.ok : etagMatches(etag3, ifNoneMatch);
52
52
  if (matched) {
53
53
  c.res = new Response(null, {
54
54
  status: 304,
@@ -24,7 +24,8 @@ var jwk = (options, init) => {
24
24
  res: unauthorizedResponse({
25
25
  ctx,
26
26
  error: "invalid_request",
27
- errDescription
27
+ errDescription,
28
+ realm: options.realm
28
29
  })
29
30
  });
30
31
  } else {
@@ -62,7 +63,8 @@ var jwk = (options, init) => {
62
63
  res: unauthorizedResponse({
63
64
  ctx,
64
65
  error: "invalid_request",
65
- errDescription
66
+ errDescription,
67
+ realm: options.realm
66
68
  })
67
69
  });
68
70
  }
@@ -89,7 +91,8 @@ var jwk = (options, init) => {
89
91
  ctx,
90
92
  error: "invalid_token",
91
93
  statusText: "Unauthorized",
92
- errDescription: "token verification failure"
94
+ errDescription: "token verification failure",
95
+ realm: options.realm
93
96
  }),
94
97
  cause
95
98
  });
@@ -99,11 +102,13 @@ var jwk = (options, init) => {
99
102
  };
100
103
  };
101
104
  function unauthorizedResponse(opts) {
105
+ const realm = (opts.realm ?? opts.ctx.req.url).replace(/"/g, '\\"');
106
+ const errDescription = opts.errDescription.replace(/"/g, '\\"');
102
107
  return new Response("Unauthorized", {
103
108
  status: 401,
104
109
  statusText: opts.statusText,
105
110
  headers: {
106
- "WWW-Authenticate": `Bearer realm="${opts.ctx.req.url}",error="${opts.error}",error_description="${opts.errDescription}"`
111
+ "WWW-Authenticate": `Bearer realm="${realm}",error="${opts.error}",error_description="${errDescription}"`
107
112
  }
108
113
  });
109
114
  }
@@ -27,7 +27,8 @@ var jwt = (options) => {
27
27
  res: unauthorizedResponse({
28
28
  ctx,
29
29
  error: "invalid_request",
30
- errDescription
30
+ errDescription,
31
+ realm: options.realm
31
32
  })
32
33
  });
33
34
  } else {
@@ -62,7 +63,8 @@ var jwt = (options) => {
62
63
  res: unauthorizedResponse({
63
64
  ctx,
64
65
  error: "invalid_request",
65
- errDescription
66
+ errDescription,
67
+ realm: options.realm
66
68
  })
67
69
  });
68
70
  }
@@ -83,7 +85,8 @@ var jwt = (options) => {
83
85
  ctx,
84
86
  error: "invalid_token",
85
87
  statusText: "Unauthorized",
86
- errDescription: "token verification failure"
88
+ errDescription: "token verification failure",
89
+ realm: options.realm
87
90
  }),
88
91
  cause
89
92
  });
@@ -93,11 +96,13 @@ var jwt = (options) => {
93
96
  };
94
97
  };
95
98
  function unauthorizedResponse(opts) {
99
+ const realm = (opts.realm ?? opts.ctx.req.url).replace(/"/g, '\\"');
100
+ const errDescription = opts.errDescription.replace(/"/g, '\\"');
96
101
  return new Response("Unauthorized", {
97
102
  status: 401,
98
103
  statusText: opts.statusText,
99
104
  headers: {
100
- "WWW-Authenticate": `Bearer realm="${opts.ctx.req.url}",error="${opts.error}",error_description="${opts.errDescription}"`
105
+ "WWW-Authenticate": `Bearer realm="${realm}",error="${opts.error}",error_description="${errDescription}"`
101
106
  }
102
107
  });
103
108
  }
@@ -0,0 +1,68 @@
1
+ // src/middleware/method-not-allowed/index.ts
2
+ import { basePath, matchedRoutes } from "../../helper/route/index.js";
3
+ import { METHOD_NAME_ALL } from "../../router.js";
4
+ import { TrieRouter } from "../../router/trie-router/index.js";
5
+ var methodNotAllowed = (options) => {
6
+ let methodRouter;
7
+ return async function methodNotAllowed2(c, next) {
8
+ const routeIndex = c.req.routeIndex;
9
+ await next();
10
+ if (c.res.status !== 404) {
11
+ return;
12
+ }
13
+ if (c.error) {
14
+ return;
15
+ }
16
+ if (!methodRouter) {
17
+ const methodsByPath = /* @__PURE__ */ new Map();
18
+ for (const route of options.app.routes) {
19
+ if (route.method === METHOD_NAME_ALL || route.method === "HEAD") {
20
+ continue;
21
+ }
22
+ const methods2 = methodsByPath.get(route.path) ?? /* @__PURE__ */ new Set();
23
+ methods2.add(route.method);
24
+ if (route.method === "GET") {
25
+ methods2.add("HEAD");
26
+ }
27
+ methodsByPath.set(route.path, methods2);
28
+ }
29
+ methodRouter = new TrieRouter();
30
+ for (const [path, methods2] of methodsByPath) {
31
+ methodRouter.add(METHOD_NAME_ALL, path, [...methods2]);
32
+ }
33
+ }
34
+ let requestPath = c.req.path;
35
+ const routes = matchedRoutes(c);
36
+ const currentRoute = routes[routeIndex];
37
+ const sourceRoute = options.app.routes.find((route) => route.handler === methodNotAllowed2);
38
+ if (currentRoute && sourceRoute) {
39
+ const currentBasePathParts = basePath(c, routeIndex).split("/").filter(Boolean);
40
+ const sourceBasePathLength = sourceRoute.basePath.split("/").filter(Boolean).length;
41
+ const mountBasePathParts = currentBasePathParts.slice(
42
+ 0,
43
+ currentBasePathParts.length - sourceBasePathLength
44
+ );
45
+ if (mountBasePathParts.length > 0) {
46
+ const mountBasePath = `/${mountBasePathParts.join("/")}`;
47
+ requestPath = c.req.path.slice(mountBasePath.length) || "/";
48
+ }
49
+ }
50
+ const allowedMethods = /* @__PURE__ */ new Set();
51
+ for (const [methods2] of methodRouter.match(METHOD_NAME_ALL, requestPath)[0]) {
52
+ for (const method of methods2) {
53
+ allowedMethods.add(method);
54
+ }
55
+ }
56
+ if (allowedMethods.size === 0 || allowedMethods.has(c.req.method)) {
57
+ return;
58
+ }
59
+ c.res.headers.delete("Allow");
60
+ c.res.headers.delete("Content-Length");
61
+ const methods = [...allowedMethods];
62
+ const allow = methods.join(", ");
63
+ c.res = options.onMethodNotAllowed ? await options.onMethodNotAllowed(c, methods) : c.text("Method Not Allowed", 405, { Allow: allow });
64
+ };
65
+ };
66
+ export {
67
+ methodNotAllowed
68
+ };
@@ -2,8 +2,7 @@
2
2
  import { HTTPException } from "./http-exception.js";
3
3
  import { GET_MATCH_RESULT } from "./request/constants.js";
4
4
  import { parseBody } from "./utils/body.js";
5
- import { decodeURIComponent_, getQueryParam, getQueryParams, tryDecode } from "./utils/url.js";
6
- var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
5
+ import { getQueryParam, getQueryParams, tryDecodeURIComponent } from "./utils/url.js";
7
6
  var HonoRequest = class {
8
7
  /**
9
8
  * `.raw` can get the raw Request object.
@@ -42,7 +41,6 @@ var HonoRequest = class {
42
41
  this.raw = request;
43
42
  this.path = path;
44
43
  this.#matchResult = matchResult;
45
- this.#validatedData = {};
46
44
  }
47
45
  param(key) {
48
46
  return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
@@ -50,7 +48,7 @@ var HonoRequest = class {
50
48
  #getDecodedParam(key) {
51
49
  const paramKey = this.#matchResult[0][this.routeIndex][1][key];
52
50
  const param = this.#getParamValue(paramKey);
53
- return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
51
+ return param && tryDecodeURIComponent(param);
54
52
  }
55
53
  #getAllDecodedParams() {
56
54
  const decoded = {};
@@ -58,7 +56,7 @@ var HonoRequest = class {
58
56
  for (const key of keys) {
59
57
  const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
60
58
  if (value !== void 0) {
61
- decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
59
+ decoded[key] = tryDecodeURIComponent(value);
62
60
  }
63
61
  }
64
62
  return decoded;
@@ -91,8 +89,7 @@ var HonoRequest = class {
91
89
  if (cachedBody) {
92
90
  return cachedBody;
93
91
  }
94
- const anyCachedKey = Object.keys(bodyCache)[0];
95
- if (anyCachedKey) {
92
+ for (const anyCachedKey in bodyCache) {
96
93
  return bodyCache[anyCachedKey].then((body) => {
97
94
  if (anyCachedKey === "json") {
98
95
  body = JSON.stringify(body);
@@ -195,10 +192,11 @@ var HonoRequest = class {
195
192
  * @param data - The validated data to add.
196
193
  */
197
194
  addValidatedData(target, data) {
198
- this.#validatedData[target] = data;
195
+ ;
196
+ (this.#validatedData ??= {})[target] = data;
199
197
  }
200
198
  valid(target) {
201
- return this.#validatedData[target];
199
+ return this.#validatedData?.[target];
202
200
  }
203
201
  /**
204
202
  * `.url()` can get the request url strings.