@suveren/gateway 0.7.3 → 0.7.6

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 (206) hide show
  1. package/content/integrations/gmail.json +3 -6
  2. package/dist/control-plane/index.mjs +294 -62
  3. package/dist/mcp-server/http.mjs +467 -73
  4. package/dist/ui/assets/{index-CkWaRck1.css → index-BYVb_0oG.css} +1 -1
  5. package/dist/ui/assets/index-CsrM6RQr.js +110 -0
  6. package/dist/ui/index.html +2 -2
  7. package/node_modules/@hap/core/dist/index.d.mts +258 -9
  8. package/node_modules/@hap/core/dist/index.d.ts +258 -9
  9. package/node_modules/@hap/core/dist/index.js +227 -5
  10. package/node_modules/@hap/core/dist/index.mjs +213 -4
  11. package/node_modules/@hap/core/package.json +3 -2
  12. package/node_modules/@hap/core/src/did-key.ts +126 -0
  13. package/node_modules/@hap/core/src/identity.ts +21 -5
  14. package/node_modules/@hap/core/src/index.ts +3 -0
  15. package/node_modules/@hap/core/src/mandate.ts +207 -0
  16. package/node_modules/@hap/core/src/receipt.ts +74 -0
  17. package/node_modules/@hap/core/src/types.ts +81 -5
  18. package/node_modules/@hono/node-server/dist/index.cjs +151 -9
  19. package/node_modules/@hono/node-server/dist/index.mjs +151 -9
  20. package/node_modules/@hono/node-server/package.json +1 -1
  21. package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/node_modules/content-type/README.md +2 -0
  22. package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/node_modules/content-type/dist/index.d.ts +20 -0
  23. package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/node_modules/content-type/dist/index.js +20 -14
  24. package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/node_modules/content-type/dist/index.js.map +1 -1
  25. package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/node_modules/content-type/package.json +1 -1
  26. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/accept.js +54 -0
  27. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/charset.js +10 -34
  28. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/encoding.js +9 -30
  29. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/language.js +15 -36
  30. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/mediaType.js +16 -134
  31. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/LICENSE +22 -0
  32. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/README.md +71 -0
  33. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/dist/index.d.ts +46 -0
  34. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/dist/index.js +176 -0
  35. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/dist/index.js.map +1 -0
  36. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/package.json +52 -0
  37. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/package.json +16 -10
  38. package/node_modules/@modelcontextprotocol/sdk/node_modules/type-is/node_modules/content-type/README.md +2 -0
  39. package/node_modules/@modelcontextprotocol/sdk/node_modules/type-is/node_modules/content-type/dist/index.d.ts +20 -0
  40. package/node_modules/@modelcontextprotocol/sdk/node_modules/type-is/node_modules/content-type/dist/index.js +20 -14
  41. package/node_modules/@modelcontextprotocol/sdk/node_modules/type-is/node_modules/content-type/dist/index.js.map +1 -1
  42. package/node_modules/@modelcontextprotocol/sdk/node_modules/type-is/node_modules/content-type/package.json +1 -1
  43. package/node_modules/@types/node/README.md +1 -1
  44. package/node_modules/@types/node/buffer.buffer.d.ts +5 -5
  45. package/node_modules/@types/node/crypto.d.ts +2 -2
  46. package/node_modules/@types/node/http.d.ts +16 -0
  47. package/node_modules/@types/node/http2.d.ts +10 -2
  48. package/node_modules/@types/node/package.json +2 -2
  49. package/node_modules/@types/node/process.d.ts +52 -0
  50. package/node_modules/@types/node/quic.d.ts +210 -28
  51. package/node_modules/@types/node/sqlite.d.ts +6 -2
  52. package/node_modules/@types/node/test.d.ts +36 -0
  53. package/node_modules/eventsource-parser/dist/index.cjs +2 -2
  54. package/node_modules/eventsource-parser/dist/index.cjs.map +1 -1
  55. package/node_modules/eventsource-parser/dist/index.js +2 -2
  56. package/node_modules/eventsource-parser/dist/index.js.map +1 -1
  57. package/node_modules/eventsource-parser/package.json +1 -1
  58. package/node_modules/eventsource-parser/src/parse.ts +4 -2
  59. package/node_modules/fast-uri/index.js +201 -48
  60. package/node_modules/fast-uri/lib/schemes.js +9 -4
  61. package/node_modules/fast-uri/lib/utils.js +388 -91
  62. package/node_modules/fast-uri/package.json +1 -1
  63. package/node_modules/fast-uri/test/component-safe-serialization.test.js +105 -0
  64. package/node_modules/fast-uri/test/equal.test.js +31 -3
  65. package/node_modules/fast-uri/test/fixtures/uri-js-parse.json +2 -0
  66. package/node_modules/fast-uri/test/ipv6-canonical.test.js +34 -0
  67. package/node_modules/fast-uri/test/ipv6-validation.test.js +90 -0
  68. package/node_modules/fast-uri/test/malformed-percent.test.js +77 -0
  69. package/node_modules/fast-uri/test/malformed-urn.test.js +61 -0
  70. package/node_modules/fast-uri/test/parse.test.js +7 -3
  71. package/node_modules/fast-uri/test/query-fragment-normalization.test.js +33 -0
  72. package/node_modules/fast-uri/test/reserved-path-normalization.test.js +109 -0
  73. package/node_modules/fast-uri/test/scheme-validation.test.js +124 -0
  74. package/node_modules/fast-uri/test/security-normalization.test.js +101 -0
  75. package/node_modules/fast-uri/test/security.test.js +75 -3
  76. package/node_modules/fast-uri/test/urn-full-input.test.js +29 -0
  77. package/node_modules/fast-uri/test/websocket-query-preservation.test.js +24 -0
  78. package/node_modules/hono/dist/cjs/client/client.js +27 -13
  79. package/node_modules/hono/dist/cjs/client/utils.js +4 -1
  80. package/node_modules/hono/dist/cjs/context.js +4 -0
  81. package/node_modules/hono/dist/cjs/helper/accepts/accepts.js +36 -2
  82. package/node_modules/hono/dist/cjs/helper/ssg/ssg.js +1 -1
  83. package/node_modules/hono/dist/cjs/helper/ssg/utils.js +30 -10
  84. package/node_modules/hono/dist/cjs/jsx/dom/render.js +2 -0
  85. package/node_modules/hono/dist/cjs/jsx/intrinsic-element/components.js +1 -1
  86. package/node_modules/hono/dist/cjs/middleware/cache/index.js +1 -1
  87. package/node_modules/hono/dist/cjs/middleware/cors/index.js +16 -13
  88. package/node_modules/hono/dist/cjs/middleware/csrf/index.js +1 -1
  89. package/node_modules/hono/dist/cjs/middleware/etag/digest.js +47 -1
  90. package/node_modules/hono/dist/cjs/middleware/etag/index.js +3 -3
  91. package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +3 -1
  92. package/node_modules/hono/dist/cjs/middleware/secure-headers/secure-headers.js +6 -3
  93. package/node_modules/hono/dist/cjs/request.js +8 -4
  94. package/node_modules/hono/dist/cjs/router/linear-router/router.js +7 -2
  95. package/node_modules/hono/dist/cjs/router/pattern-router/router.js +3 -9
  96. package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +10 -3
  97. package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +47 -83
  98. package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +2 -1
  99. package/node_modules/hono/dist/cjs/router/trie-router/node.js +46 -69
  100. package/node_modules/hono/dist/cjs/router/trie-router/router.js +3 -11
  101. package/node_modules/hono/dist/cjs/router/utils.js +27 -0
  102. package/node_modules/hono/dist/cjs/utils/body.js +15 -3
  103. package/node_modules/hono/dist/cjs/utils/cookie.js +1 -1
  104. package/node_modules/hono/dist/cjs/utils/ipaddr.js +5 -3
  105. package/node_modules/hono/dist/cjs/utils/stream.js +7 -1
  106. package/node_modules/hono/dist/cjs/utils/url.js +11 -3
  107. package/node_modules/hono/dist/client/client.js +27 -13
  108. package/node_modules/hono/dist/client/utils.js +4 -1
  109. package/node_modules/hono/dist/context.js +4 -0
  110. package/node_modules/hono/dist/helper/accepts/accepts.js +36 -2
  111. package/node_modules/hono/dist/helper/ssg/ssg.js +1 -1
  112. package/node_modules/hono/dist/helper/ssg/utils.js +30 -10
  113. package/node_modules/hono/dist/jsx/dom/render.js +2 -0
  114. package/node_modules/hono/dist/jsx/intrinsic-element/components.js +1 -1
  115. package/node_modules/hono/dist/middleware/cache/index.js +1 -1
  116. package/node_modules/hono/dist/middleware/cors/index.js +16 -13
  117. package/node_modules/hono/dist/middleware/csrf/index.js +1 -1
  118. package/node_modules/hono/dist/middleware/etag/digest.js +47 -1
  119. package/node_modules/hono/dist/middleware/etag/index.js +3 -3
  120. package/node_modules/hono/dist/middleware/pretty-json/index.js +3 -1
  121. package/node_modules/hono/dist/middleware/secure-headers/secure-headers.js +6 -3
  122. package/node_modules/hono/dist/request.js +8 -4
  123. package/node_modules/hono/dist/router/linear-router/router.js +7 -2
  124. package/node_modules/hono/dist/router/pattern-router/router.js +3 -9
  125. package/node_modules/hono/dist/router/reg-exp-router/node.js +6 -2
  126. package/node_modules/hono/dist/router/reg-exp-router/router.js +53 -84
  127. package/node_modules/hono/dist/router/reg-exp-router/trie.js +2 -1
  128. package/node_modules/hono/dist/router/trie-router/node.js +46 -69
  129. package/node_modules/hono/dist/router/trie-router/router.js +3 -11
  130. package/node_modules/hono/dist/router/utils.js +5 -0
  131. package/node_modules/hono/dist/types/context.d.ts +4 -0
  132. package/node_modules/hono/dist/types/middleware/secure-headers/permissions-policy.d.ts +3 -3
  133. package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +3 -0
  134. package/node_modules/hono/dist/types/router/trie-router/node.d.ts +1 -2
  135. package/node_modules/hono/dist/types/router/trie-router/router.d.ts +0 -1
  136. package/node_modules/hono/dist/types/router/utils.d.ts +1 -0
  137. package/node_modules/hono/dist/types/utils/url.d.ts +4 -0
  138. package/node_modules/hono/dist/utils/body.js +15 -3
  139. package/node_modules/hono/dist/utils/cookie.js +1 -1
  140. package/node_modules/hono/dist/utils/ipaddr.js +5 -3
  141. package/node_modules/hono/dist/utils/stream.js +7 -1
  142. package/node_modules/hono/dist/utils/url.js +11 -3
  143. package/node_modules/hono/package.json +1 -1
  144. package/node_modules/ip-address/README.md +134 -134
  145. package/node_modules/ip-address/dist/address-error.d.ts +11 -0
  146. package/node_modules/ip-address/dist/address-error.js.map +1 -1
  147. package/node_modules/ip-address/dist/ipv4.d.ts +22 -6
  148. package/node_modules/ip-address/dist/ipv4.js +22 -6
  149. package/node_modules/ip-address/dist/ipv4.js.map +1 -1
  150. package/node_modules/ip-address/dist/ipv6.d.ts +10 -3
  151. package/node_modules/ip-address/dist/ipv6.js +26 -17
  152. package/node_modules/ip-address/dist/ipv6.js.map +1 -1
  153. package/node_modules/ip-address/package.json +1 -1
  154. package/node_modules/is-plain-object/README.md +39 -95
  155. package/node_modules/is-plain-object/dist/is-plain-object.js +0 -2
  156. package/node_modules/is-plain-object/is-plain-object.d.ts +6 -1
  157. package/node_modules/is-plain-object/package.json +8 -34
  158. package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +4 -3
  159. package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +4 -3
  160. package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +4 -3
  161. package/node_modules/jose/dist/types/jwks/remote.d.ts +4 -4
  162. package/node_modules/jose/dist/types/jws/general/verify.d.ts +3 -3
  163. package/node_modules/jose/dist/types/jwt/encrypt.d.ts +12 -17
  164. package/node_modules/jose/dist/types/jwt/sign.d.ts +8 -14
  165. package/node_modules/jose/dist/types/jwt/unsecured.d.ts +9 -15
  166. package/node_modules/jose/dist/types/types.d.ts +4 -2
  167. package/node_modules/jose/dist/webapi/jwe/compact/encrypt.js +30 -8
  168. package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +8 -4
  169. package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +6 -13
  170. package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +19 -19
  171. package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +32 -21
  172. package/node_modules/jose/dist/webapi/jwk/embedded.js +15 -1
  173. package/node_modules/jose/dist/webapi/jwk/thumbprint.js +11 -5
  174. package/node_modules/jose/dist/webapi/jwks/local.js +45 -53
  175. package/node_modules/jose/dist/webapi/jwks/remote.js +82 -103
  176. package/node_modules/jose/dist/webapi/jws/compact/sign.js +10 -9
  177. package/node_modules/jose/dist/webapi/jws/flattened/sign.js +2 -1
  178. package/node_modules/jose/dist/webapi/jws/flattened/verify.js +8 -7
  179. package/node_modules/jose/dist/webapi/jws/general/sign.js +5 -3
  180. package/node_modules/jose/dist/webapi/jws/general/verify.js +51 -21
  181. package/node_modules/jose/dist/webapi/jwt/decrypt.js +7 -9
  182. package/node_modules/jose/dist/webapi/jwt/encrypt.js +21 -50
  183. package/node_modules/jose/dist/webapi/jwt/sign.js +8 -41
  184. package/node_modules/jose/dist/webapi/jwt/unsecured.js +21 -42
  185. package/node_modules/jose/dist/webapi/key/generate_key_pair.js +6 -2
  186. package/node_modules/jose/dist/webapi/key/generate_secret.js +7 -6
  187. package/node_modules/jose/dist/webapi/key/import.js +16 -12
  188. package/node_modules/jose/dist/webapi/lib/asn1.js +7 -2
  189. package/node_modules/jose/dist/webapi/lib/content_encryption.js +7 -15
  190. package/node_modules/jose/dist/webapi/lib/deflate.js +8 -0
  191. package/node_modules/jose/dist/webapi/lib/helpers.js +1 -1
  192. package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +85 -28
  193. package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +45 -13
  194. package/node_modules/jose/dist/webapi/lib/jwk_metadata.js +20 -0
  195. package/node_modules/jose/dist/webapi/lib/jws_sign.js +47 -36
  196. package/node_modules/jose/dist/webapi/lib/jws_verify.js +77 -45
  197. package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +82 -47
  198. package/node_modules/jose/dist/webapi/lib/key.js +24 -9
  199. package/node_modules/jose/dist/webapi/lib/key_management.js +10 -4
  200. package/node_modules/jose/dist/webapi/lib/key_options.js +6 -0
  201. package/node_modules/jose/dist/webapi/lib/options.js +26 -0
  202. package/node_modules/jose/dist/webapi/lib/type_checks.js +11 -13
  203. package/node_modules/jose/package.json +1 -1
  204. package/package.json +2 -2
  205. package/dist/ui/assets/index-DdJeSfV9.js +0 -110
  206. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/HISTORY.md +0 -114
@@ -24,19 +24,11 @@ var import_url = require("../../utils/url");
24
24
  var import_node = require("./node");
25
25
  class TrieRouter {
26
26
  name = "TrieRouter";
27
- #node;
28
- constructor() {
29
- this.#node = new import_node.Node();
30
- }
27
+ #node = new import_node.Node();
31
28
  add(method, path, handler) {
32
- const results = (0, import_url.checkOptionalParameter)(path);
33
- if (results) {
34
- for (let i = 0, len = results.length; i < len; i++) {
35
- this.#node.insert(method, results[i], handler);
36
- }
37
- return;
29
+ for (const result of (0, import_url.checkOptionalParameter)(path) || [path]) {
30
+ this.#node.insert(method, result, handler);
38
31
  }
39
- this.#node.insert(method, path, handler);
40
32
  }
41
33
  match(method, path) {
42
34
  return this.#node.search(method, path);
@@ -0,0 +1,27 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var utils_exports = {};
19
+ __export(utils_exports, {
20
+ createNullObject: () => createNullObject
21
+ });
22
+ module.exports = __toCommonJS(utils_exports);
23
+ const createNullObject = () => /* @__PURE__ */ Object.create(null);
24
+ // Annotate the CommonJS export names for ESM import in node:
25
+ 0 && (module.exports = {
26
+ createNullObject
27
+ });
@@ -21,6 +21,8 @@ __export(body_exports, {
21
21
  });
22
22
  module.exports = __toCommonJS(body_exports);
23
23
  var import_buffer = require("./buffer");
24
+ const MAX_NESTING_DEPTH = 32;
25
+ const MAX_NESTED_OBJECTS = 1e4;
24
26
  const isRawRequest = (request) => "headers" in request;
25
27
  const parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
26
28
  const { all = false, dot = false } = options;
@@ -53,6 +55,7 @@ async function parseFormData(request, options) {
53
55
  }
54
56
  function convertFormDataToBodyData(formData, options) {
55
57
  const form = /* @__PURE__ */ Object.create(null);
58
+ const nestingState = { count: 0 };
56
59
  formData.forEach((value, key) => {
57
60
  const shouldParseAllValues = options.all || key.endsWith("[]");
58
61
  if (!shouldParseAllValues) {
@@ -65,7 +68,7 @@ function convertFormDataToBodyData(formData, options) {
65
68
  Object.entries(form).forEach(([key, value]) => {
66
69
  const shouldParseDotValues = key.includes(".");
67
70
  if (shouldParseDotValues) {
68
- handleParsingNestedValues(form, key, value);
71
+ handleParsingNestedValues(form, key, value, nestingState);
69
72
  delete form[key];
70
73
  }
71
74
  });
@@ -88,23 +91,32 @@ const handleParsingAllValues = (form, key, value) => {
88
91
  }
89
92
  }
90
93
  };
91
- const handleParsingNestedValues = (form, key, value) => {
94
+ const handleParsingNestedValues = (form, key, value, state) => {
92
95
  if (/(?:^|\.)__proto__\./.test(key)) {
93
96
  return;
94
97
  }
95
98
  let nestedForm = form;
96
- const keys = key.split(".");
99
+ const keys = key.split(".", MAX_NESTING_DEPTH + 2);
100
+ if (keys.length > MAX_NESTING_DEPTH + 1) {
101
+ throwNestingLimitExceeded();
102
+ }
97
103
  keys.forEach((key2, index) => {
98
104
  if (index === keys.length - 1) {
99
105
  nestedForm[key2] = value;
100
106
  } else {
101
107
  if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
108
+ if (state.count++ >= MAX_NESTED_OBJECTS) {
109
+ throwNestingLimitExceeded();
110
+ }
102
111
  nestedForm[key2] = /* @__PURE__ */ Object.create(null);
103
112
  }
104
113
  nestedForm = nestedForm[key2];
105
114
  }
106
115
  });
107
116
  };
117
+ const throwNestingLimitExceeded = () => {
118
+ throw new Error("Nesting limit exceeded");
119
+ };
108
120
  // Annotate the CommonJS export names for ESM import in node:
109
121
  0 && (module.exports = {
110
122
  parseBody
@@ -101,7 +101,7 @@ const parseSigned = async (cookie, secret, name) => {
101
101
  const secretKey = await getCryptoKey(secret);
102
102
  for (const [key, value] of Object.entries(parse(cookie, name))) {
103
103
  const signatureStartPos = value.lastIndexOf(".");
104
- if (signatureStartPos < 1) {
104
+ if (signatureStartPos < 0) {
105
105
  continue;
106
106
  }
107
107
  const signedValue = value.substring(0, signatureStartPos);
@@ -30,12 +30,14 @@ __export(ipaddr_exports, {
30
30
  module.exports = __toCommonJS(ipaddr_exports);
31
31
  const expandIPv6 = (ipV6) => {
32
32
  const sections = ipV6.split(":");
33
- if (IPV4_REGEX.test(sections.at(-1))) {
33
+ const lastSection = sections.at(-1);
34
+ if (IPV4_REGEX.test(lastSection)) {
35
+ const octets = lastSection.split(".").map(Number);
34
36
  sections.splice(
35
37
  -1,
36
38
  1,
37
- ...convertIPv6BinaryToString(convertIPv4ToBinary(sections.at(-1))).substring(2).split(":")
38
- // => ['7f00', '0001']
39
+ (octets[0] << 8 | octets[1]).toString(16),
40
+ (octets[2] << 8 | octets[3]).toString(16)
39
41
  );
40
42
  }
41
43
  for (let i = 0; i < sections.length; i++) {
@@ -96,7 +96,13 @@ class StreamingApi {
96
96
  abort() {
97
97
  if (!this.aborted) {
98
98
  this.aborted = true;
99
- this.abortSubscribers.forEach((subscriber) => subscriber());
99
+ this.abortSubscribers.forEach((subscriber) => {
100
+ try {
101
+ void Promise.resolve(subscriber()).catch(() => {
102
+ });
103
+ } catch {
104
+ }
105
+ });
100
106
  }
101
107
  }
102
108
  }
@@ -119,7 +119,11 @@ const getPath = (request) => {
119
119
  };
120
120
  const getQueryStrings = (url) => {
121
121
  const queryIndex = url.indexOf("?", 8);
122
- return queryIndex === -1 ? "" : "?" + url.slice(queryIndex + 1);
122
+ if (queryIndex === -1) {
123
+ return "";
124
+ }
125
+ const hashIndex = url.indexOf("#", 8);
126
+ return hashIndex === -1 ? url.slice(queryIndex) : queryIndex < hashIndex ? url.slice(queryIndex, hashIndex) : "";
123
127
  };
124
128
  const getPathNoStrict = (request) => {
125
129
  const result = getPath(request);
@@ -142,13 +146,13 @@ const checkOptionalParameter = (path) => {
142
146
  if (segment !== "" && !/\:/.test(segment)) {
143
147
  basePath += "/" + segment;
144
148
  } else if (/\:/.test(segment)) {
145
- if (/\?/.test(segment)) {
149
+ if (segment.charCodeAt(segment.length - 1) === 63) {
146
150
  if (results.length === 0 && basePath === "") {
147
151
  results.push("/");
148
152
  } else {
149
153
  results.push(basePath);
150
154
  }
151
- const optionalSegment = segment.replace("?", "");
155
+ const optionalSegment = segment.slice(0, -1);
152
156
  basePath += "/" + optionalSegment;
153
157
  results.push(basePath);
154
158
  } else {
@@ -166,6 +170,10 @@ const _decodeURI = (value) => {
166
170
  return tryDecodeURIComponent(value);
167
171
  };
168
172
  const _getQueryParam = (url, key, multiple) => {
173
+ const hashIndex = url.indexOf("#", 8);
174
+ if (hashIndex !== -1) {
175
+ url = url.slice(0, hashIndex);
176
+ }
169
177
  let encoded;
170
178
  if (!multiple && key && key.indexOf("%") === -1 && key.indexOf("+") === -1) {
171
179
  let keyIndex2 = url.indexOf("?", 8);
@@ -26,6 +26,10 @@ var createProxy = (callback, path) => {
26
26
  });
27
27
  return proxy;
28
28
  };
29
+ var appendQueryParams = (url, searchParams) => {
30
+ const queryString = searchParams.toString();
31
+ return queryString ? `${url}?${queryString}` : url;
32
+ };
29
33
  var ClientRequestImpl = class {
30
34
  url;
31
35
  method;
@@ -52,6 +56,9 @@ var ClientRequestImpl = class {
52
56
  }
53
57
  if (Array.isArray(v)) {
54
58
  for (const v2 of v) {
59
+ if (v2 === void 0) {
60
+ continue;
61
+ }
55
62
  form.append(k, v2);
56
63
  }
57
64
  } else {
@@ -60,7 +67,7 @@ var ClientRequestImpl = class {
60
67
  }
61
68
  this.rBody = form;
62
69
  }
63
- if (args.json) {
70
+ if (args.json !== void 0) {
64
71
  this.rBody = JSON.stringify(args.json);
65
72
  this.cType = "application/json";
66
73
  }
@@ -76,19 +83,29 @@ var ClientRequestImpl = class {
76
83
  if (args?.cookie) {
77
84
  const cookies = [];
78
85
  for (const [key, value] of Object.entries(args.cookie)) {
79
- cookies.push(serialize(key, value, { path: "/" }));
86
+ if (value === void 0) {
87
+ continue;
88
+ }
89
+ cookies.push(serialize(key, value));
90
+ }
91
+ if (cookies.length > 0) {
92
+ headerValues["Cookie"] = cookies.join("; ");
80
93
  }
81
- headerValues["Cookie"] = cookies.join(",");
82
94
  }
83
95
  if (this.cType) {
84
96
  headerValues["Content-Type"] = this.cType;
85
97
  }
86
- const headers = new Headers(headerValues ?? void 0);
98
+ const headers = new Headers();
99
+ for (const [key, value] of Object.entries(headerValues)) {
100
+ if (value !== void 0) {
101
+ headers.set(key, value);
102
+ }
103
+ }
87
104
  let url = this.url;
88
105
  url = removeIndexString(url);
89
106
  url = replaceUrlParam(url, this.pathParams);
90
107
  if (this.queryParams) {
91
- url = url + "?" + this.queryParams.toString();
108
+ url = appendQueryParams(url, this.queryParams);
92
109
  }
93
110
  methodUpperCase = this.method.toUpperCase();
94
111
  const setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
@@ -132,7 +149,7 @@ var hc = (baseUrl, options) => createProxy(function proxyCallback(opts) {
132
149
  result = replaceUrlParam(url, opts.args[0].param);
133
150
  }
134
151
  if (opts.args[0].query) {
135
- result = result + "?" + buildSearchParamsOption(opts.args[0].query).toString();
152
+ result = appendQueryParams(result, buildSearchParamsOption(opts.args[0].query));
136
153
  }
137
154
  }
138
155
  result = removeIndexString(result);
@@ -143,18 +160,15 @@ var hc = (baseUrl, options) => createProxy(function proxyCallback(opts) {
143
160
  }
144
161
  if (method === "ws") {
145
162
  const webSocketUrl = replaceUrlProtocol(
146
- opts.args[0] && opts.args[0].param ? replaceUrlParam(url, opts.args[0].param) : url,
163
+ opts.args[0]?.param ? replaceUrlParam(url, opts.args[0].param) : url,
147
164
  "ws"
148
165
  );
149
166
  const targetUrl = new URL(webSocketUrl);
150
167
  const queryParams = opts.args[0]?.query;
151
168
  if (queryParams) {
152
- Object.entries(queryParams).forEach(([key, value]) => {
153
- if (Array.isArray(value)) {
154
- value.forEach((item) => targetUrl.searchParams.append(key, item));
155
- } else {
156
- targetUrl.searchParams.set(key, value);
157
- }
169
+ const searchParams = buildSearchParamsOption(queryParams);
170
+ searchParams.forEach((value, key) => {
171
+ targetUrl.searchParams.append(key, value);
158
172
  });
159
173
  }
160
174
  const establishWebSocket = (...args) => {
@@ -9,7 +9,7 @@ var mergePath = (base, path) => {
9
9
  var replaceUrlParam = (urlString, params) => {
10
10
  for (const [k, v] of Object.entries(params)) {
11
11
  const reg = new RegExp("/:" + k + "(?:{[^/]+})?\\??(?=/|$)");
12
- urlString = urlString.replace(reg, v ? `/${v}` : "");
12
+ urlString = urlString.replace(reg, () => v ? `/${v}` : "");
13
13
  }
14
14
  return urlString;
15
15
  };
@@ -21,6 +21,9 @@ var buildSearchParams = (query) => {
21
21
  }
22
22
  if (Array.isArray(v)) {
23
23
  for (const v2 of v) {
24
+ if (v2 === void 0) {
25
+ continue;
26
+ }
24
27
  searchParams.append(k, v2);
25
28
  }
26
29
  } else {
@@ -202,6 +202,10 @@ var Context = class {
202
202
  * c.header('X-Message', 'Hello!')
203
203
  * c.header('Content-Type', 'text/plain')
204
204
  *
205
+ * // Append multiple headers using the append option (e.g. Vary)
206
+ * c.header('Vary', 'Accept-Encoding', { append: true })
207
+ * c.header('Vary', 'User-Agent', { append: true })
208
+ *
205
209
  * return c.body('Thank you for coming')
206
210
  * })
207
211
  * ```
@@ -1,9 +1,43 @@
1
1
  // src/helper/accepts/accepts.ts
2
2
  import { parseAccept } from "../../utils/accept.js";
3
+ var matchType = (acceptType, supportedType) => {
4
+ if (acceptType === supportedType) {
5
+ return true;
6
+ }
7
+ if (acceptType === "*/*" || acceptType === "*") {
8
+ return false;
9
+ }
10
+ if (acceptType.endsWith("/*")) {
11
+ const [acceptMain] = acceptType.split("/");
12
+ const [supportedMain] = supportedType.split("/");
13
+ return acceptMain === supportedMain;
14
+ }
15
+ return false;
16
+ };
17
+ var getSpecificity = (type) => {
18
+ if (type === "*/*" || type === "*") {
19
+ return 1;
20
+ }
21
+ if (type.endsWith("/*")) {
22
+ return 2;
23
+ }
24
+ return 3;
25
+ };
3
26
  var defaultMatch = (accepts2, config) => {
4
27
  const { supports, default: defaultSupport } = config;
5
- const accept = accepts2.sort((a, b) => b.q - a.q).find((accept2) => supports.includes(accept2.type));
6
- return accept ? accept.type : defaultSupport;
28
+ const sortedAccepts = accepts2.slice().sort((a, b) => {
29
+ if (b.q !== a.q) {
30
+ return b.q - a.q;
31
+ }
32
+ return getSpecificity(b.type) - getSpecificity(a.type);
33
+ });
34
+ for (const accept of sortedAccepts) {
35
+ const matched = supports.find((supported) => matchType(accept.type, supported));
36
+ if (matched) {
37
+ return matched;
38
+ }
39
+ }
40
+ return defaultSupport;
7
41
  };
8
42
  var accepts = (c, options) => {
9
43
  const acceptHeader = c.req.header(options.header);
@@ -184,7 +184,7 @@ var saveContentToFile = async (data, fsModule, outDir, extensionMap) => {
184
184
  const { routePath, content, mimeType } = awaitedData;
185
185
  const filePath = generateFilePath(routePath, outDir, mimeType, extensionMap);
186
186
  const dirPath = dirname(filePath);
187
- if (!createdDirs.has(dirPath)) {
187
+ if (dirPath !== "" && !createdDirs.has(dirPath)) {
188
188
  await fsModule.mkdir(dirPath, { recursive: true });
189
189
  createdDirs.add(dirPath);
190
190
  }
@@ -8,8 +8,14 @@ var dirname = (path) => {
8
8
  var normalizePath = (path) => {
9
9
  return path.replace(/(\\)/g, "/").replace(/\/$/g, "");
10
10
  };
11
- var handleParent = (resultPaths, beforeParentFlag) => {
12
- if (resultPaths.length === 0 || beforeParentFlag) {
11
+ var getUncRoot = (path) => {
12
+ const uncRoot = path.replace(/\\/g, "/").match(/^\/\/([^/]+)\/([^/]+)/);
13
+ if (uncRoot) {
14
+ return `${uncRoot[1].toLowerCase()}/${uncRoot[2].toLowerCase()}`;
15
+ }
16
+ };
17
+ var handleParent = (resultPaths) => {
18
+ if (resultPaths.length === 0 || resultPaths[resultPaths.length - 1] === "..") {
13
19
  resultPaths.push("..");
14
20
  } else {
15
21
  resultPaths.pop();
@@ -22,22 +28,20 @@ var handleNonDot = (path, resultPaths) => {
22
28
  }
23
29
  };
24
30
  var handleSegments = (paths, resultPaths) => {
25
- let beforeParentFlag = false;
26
31
  for (const path of paths) {
27
32
  if (path === "..") {
28
- handleParent(resultPaths, beforeParentFlag);
29
- beforeParentFlag = true;
33
+ handleParent(resultPaths);
30
34
  } else {
31
35
  handleNonDot(path, resultPaths);
32
- beforeParentFlag = false;
33
36
  }
34
37
  }
35
38
  };
36
39
  var joinPaths = (...paths) => {
40
+ const hasUncPrefix = getUncRoot(paths[0]) !== void 0;
37
41
  paths = paths.map(normalizePath);
38
42
  const resultPaths = [];
39
43
  handleSegments(paths.join("/").split("/"), resultPaths);
40
- return (paths[0][0] === "/" ? "/" : "") + resultPaths.join("/");
44
+ return (hasUncPrefix ? "//" : paths[0][0] === "/" ? "/" : "") + resultPaths.join("/");
41
45
  };
42
46
  var filterStaticGenerateRoutes = (hono) => {
43
47
  return hono.routes.reduce((acc, { method, handler, path }) => {
@@ -51,10 +55,26 @@ var filterStaticGenerateRoutes = (hono) => {
51
55
  var isDynamicRoute = (path) => {
52
56
  return path.split("/").some((segment) => segment.startsWith(":") || segment.includes("*"));
53
57
  };
58
+ var toSegments = (path) => path === "" ? [] : path.split("/");
59
+ var getPathRoot = (path) => {
60
+ const normalizedPath = path.replace(/\\/g, "/");
61
+ const uncRoot = getUncRoot(normalizedPath);
62
+ if (uncRoot) {
63
+ return `unc:${uncRoot}`;
64
+ }
65
+ const driveRoot = normalizedPath.match(/^([A-Za-z]):/);
66
+ if (driveRoot) {
67
+ const kind = normalizedPath[2] === "/" ? "drive-absolute" : "drive-relative";
68
+ return `${kind}:${driveRoot[1].toLowerCase()}`;
69
+ }
70
+ return normalizedPath.startsWith("/") ? "absolute" : "relative";
71
+ };
54
72
  var ensureWithinOutDir = (outDir, filePath) => {
55
- const normalizedOutDir = joinPaths("/", outDir);
56
- const normalizedFilePath = joinPaths("/", filePath);
57
- if (normalizedFilePath !== normalizedOutDir && !normalizedFilePath.startsWith(`${normalizedOutDir}/`)) {
73
+ const outDirSegments = toSegments(joinPaths(outDir));
74
+ const filePathSegments = toSegments(joinPaths(filePath));
75
+ const hasMismatchedPathRoot = getPathRoot(outDir) !== getPathRoot(filePath);
76
+ const climbsAboveOutDir = filePathSegments[outDirSegments.length] === "..";
77
+ if (hasMismatchedPathRoot || filePathSegments.length <= outDirSegments.length || !outDirSegments.every((segment, i) => segment === filePathSegments[i]) || climbsAboveOutDir) {
58
78
  throw new Error(`Path traversal detected: "${filePath}" is outside the output directory`);
59
79
  }
60
80
  };
@@ -78,6 +78,7 @@ var applyProps = (container, attributes, oldAttributes) => {
78
78
  } else if (key === "dangerouslySetInnerHTML" && value) {
79
79
  container.innerHTML = value.__html;
80
80
  } else if (key === "ref") {
81
+ refCleanupMap.get(container)?.();
81
82
  let cleanup;
82
83
  if (typeof value === "function") {
83
84
  cleanup = value(container) || (() => value(null));
@@ -142,6 +143,7 @@ var applyProps = (container, attributes, oldAttributes) => {
142
143
  container.removeEventListener(eventSpec[0], value, eventSpec[1]);
143
144
  } else if (key === "ref") {
144
145
  refCleanupMap.get(container)?.();
146
+ refCleanupMap.delete(container);
145
147
  } else {
146
148
  try {
147
149
  container.removeAttribute(toAttributeName(container, key));
@@ -78,7 +78,7 @@ var documentMetadataTag = (tag, children, props, sort) => {
78
78
  const string = new JSXNode(tag, restProps, toArray(children || [])).toString();
79
79
  if (string instanceof Promise) {
80
80
  return string.then(
81
- (resString) => raw(string, [
81
+ (resString) => raw(resString, [
82
82
  ...resString.callbacks || [],
83
83
  insertIntoHead(tag, resString, restProps, precedence)
84
84
  ])
@@ -23,7 +23,7 @@ var parseVaryDirectives = (vary) => {
23
23
  };
24
24
  var createCacheKey = (key, requestUrl, request, varyHeaders) => {
25
25
  const url = new URL(cacheKeyPath, requestUrl);
26
- url.searchParams.append(cacheKeyParameter, key.split("#", 1)[0]);
26
+ url.searchParams.append(cacheKeyParameter, key);
27
27
  url.searchParams.append(cacheMethodKeyParameter, request.method);
28
28
  if (request.method === "QUERY") {
29
29
  url.searchParams.append(queryDigestKeyParameter, request.digest);
@@ -7,6 +7,8 @@ var cors = (options) => {
7
7
  exposeHeaders: [],
8
8
  ...options
9
9
  };
10
+ const exposeHeadersStr = opts.exposeHeaders?.length ? opts.exposeHeaders.join(",") : void 0;
11
+ const allowHeadersStr = opts.allowHeaders?.length ? opts.allowHeaders.join(",") : void 0;
10
12
  const findAllowOrigin = ((optsOrigin) => {
11
13
  if (typeof optsOrigin === "string") {
12
14
  if (optsOrigin === "*") {
@@ -22,11 +24,12 @@ var cors = (options) => {
22
24
  })(opts.origin);
23
25
  const findAllowMethods = ((optsAllowMethods) => {
24
26
  if (typeof optsAllowMethods === "function") {
25
- return optsAllowMethods;
27
+ return async (origin, c) => (await optsAllowMethods(origin, c)).join(",");
26
28
  } else if (Array.isArray(optsAllowMethods)) {
27
- return () => optsAllowMethods;
29
+ const methodsStr = optsAllowMethods.join(",");
30
+ return () => methodsStr;
28
31
  } else {
29
- return () => [];
32
+ return () => "";
30
33
  }
31
34
  })(opts.allowMethods);
32
35
  return async function cors2(c, next) {
@@ -40,29 +43,29 @@ var cors = (options) => {
40
43
  if (opts.credentials) {
41
44
  set("Access-Control-Allow-Credentials", "true");
42
45
  }
43
- if (opts.exposeHeaders?.length) {
44
- set("Access-Control-Expose-Headers", opts.exposeHeaders.join(","));
46
+ if (exposeHeadersStr) {
47
+ set("Access-Control-Expose-Headers", exposeHeadersStr);
45
48
  }
46
49
  if (c.req.method === "OPTIONS") {
47
50
  if (opts.origin !== "*") {
48
- set("Vary", "Origin");
51
+ c.res.headers.append("Vary", "Origin");
49
52
  }
50
53
  if (opts.maxAge != null) {
51
54
  set("Access-Control-Max-Age", opts.maxAge.toString());
52
55
  }
53
56
  const allowMethods = await findAllowMethods(c.req.header("origin") || "", c);
54
- if (allowMethods.length) {
55
- set("Access-Control-Allow-Methods", allowMethods.join(","));
57
+ if (allowMethods) {
58
+ set("Access-Control-Allow-Methods", allowMethods);
56
59
  }
57
- let headers = opts.allowHeaders;
58
- if (!headers?.length) {
60
+ let headersStr = allowHeadersStr;
61
+ if (!headersStr) {
59
62
  const requestHeaders = c.req.header("Access-Control-Request-Headers");
60
63
  if (requestHeaders) {
61
- headers = requestHeaders.split(",").map((h) => h.trim());
64
+ headersStr = requestHeaders.split(",").map((h) => h.trim()).join(",");
62
65
  }
63
66
  }
64
- if (headers?.length) {
65
- set("Access-Control-Allow-Headers", headers.join(","));
67
+ if (headersStr) {
68
+ set("Access-Control-Allow-Headers", headersStr);
66
69
  c.res.headers.append("Vary", "Access-Control-Request-Headers");
67
70
  }
68
71
  c.res.headers.delete("Content-Length");
@@ -2,7 +2,7 @@
2
2
  import { HTTPException } from "../../http-exception.js";
3
3
  var secFetchSiteValues = ["same-origin", "same-site", "none", "cross-site"];
4
4
  var isSecFetchSite = (value) => secFetchSiteValues.includes(value);
5
- var isSafeMethodRe = /^(GET|HEAD)$/;
5
+ var isSafeMethodRe = /^(GET|HEAD|OPTIONS)$/;
6
6
  var isRequestedByFormElementRe = /^\b(application\/x-www-form-urlencoded|multipart\/form-data|text\/plain)\b/i;
7
7
  var csrf = (options) => {
8
8
  const originHandler = ((optsOrigin) => {
@@ -10,18 +10,64 @@ var mergeBuffers = (buffer1, buffer2) => {
10
10
  merged.set(buffer2, buffer1.byteLength);
11
11
  return merged;
12
12
  };
13
+ var CHUNK_SIZE = 256 * 1024;
13
14
  var generateDigest = async (stream, generator) => {
14
15
  if (!stream) {
15
16
  return null;
16
17
  }
17
18
  let result = void 0;
19
+ let chunk;
20
+ let chunkLength = 0;
21
+ const digest = async (body) => {
22
+ result = await generator(mergeBuffers(result, body));
23
+ };
18
24
  const reader = stream.getReader();
19
25
  for (; ; ) {
20
26
  const { value, done } = await reader.read();
21
27
  if (done) {
22
28
  break;
23
29
  }
24
- result = await generator(mergeBuffers(result, value));
30
+ let offset = 0;
31
+ while (offset < value.byteLength) {
32
+ const remaining = value.byteLength - offset;
33
+ if (chunkLength === 0 && remaining >= CHUNK_SIZE) {
34
+ await digest(value.subarray(offset, offset + CHUNK_SIZE));
35
+ offset += CHUNK_SIZE;
36
+ continue;
37
+ }
38
+ const requiredLength = chunkLength + remaining;
39
+ if (requiredLength < CHUNK_SIZE) {
40
+ if (!chunk) {
41
+ chunk = value.slice(offset);
42
+ } else {
43
+ if (chunk.byteLength < requiredLength) {
44
+ const nextChunk = new Uint8Array(
45
+ new ArrayBuffer(Math.min(CHUNK_SIZE, Math.max(requiredLength, chunk.byteLength * 2)))
46
+ );
47
+ nextChunk.set(chunk.subarray(0, chunkLength));
48
+ chunk = nextChunk;
49
+ }
50
+ chunk.set(value.subarray(offset), chunkLength);
51
+ }
52
+ chunkLength = requiredLength;
53
+ break;
54
+ }
55
+ const length = CHUNK_SIZE - chunkLength;
56
+ if (chunk?.byteLength !== CHUNK_SIZE) {
57
+ const nextChunk = new Uint8Array(new ArrayBuffer(CHUNK_SIZE));
58
+ if (chunk) {
59
+ nextChunk.set(chunk.subarray(0, chunkLength));
60
+ }
61
+ chunk = nextChunk;
62
+ }
63
+ chunk.set(value.subarray(offset, offset + length), chunkLength);
64
+ await digest(chunk);
65
+ chunkLength = 0;
66
+ offset += length;
67
+ }
68
+ }
69
+ if (chunk && chunkLength > 0) {
70
+ await digest(chunk.subarray(0, chunkLength));
25
71
  }
26
72
  if (!result) {
27
73
  return null;
@@ -10,7 +10,7 @@ var RETAINED_304_HEADERS = [
10
10
  ];
11
11
  var stripWeak = (tag) => tag.replace(/^W\//, "");
12
12
  function etagMatches(etag2, ifNoneMatch) {
13
- return ifNoneMatch != null && ifNoneMatch.split(/,\s*/).some((t) => stripWeak(t) === stripWeak(etag2));
13
+ return ifNoneMatch != null && ifNoneMatch.split(",").some((t) => stripWeak(t.trim()) === stripWeak(etag2));
14
14
  }
15
15
  function initializeGenerator(generator) {
16
16
  if (!generator) {
@@ -60,11 +60,11 @@ var etag = (options) => {
60
60
  ETag: etag3
61
61
  }
62
62
  });
63
- c.res.headers.forEach((_, key) => {
63
+ for (const key of Array.from(c.res.headers.keys())) {
64
64
  if (retainedHeaders.indexOf(key.toLowerCase()) === -1) {
65
65
  c.res.headers.delete(key);
66
66
  }
67
- });
67
+ }
68
68
  } else {
69
69
  c.res.headers.set("ETag", etag3);
70
70
  }