@suveren/gateway 0.7.4 → 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 (171) hide show
  1. package/dist/control-plane/index.mjs +248 -58
  2. package/dist/mcp-server/http.mjs +408 -65
  3. package/dist/ui/assets/{index-CkWaRck1.css → index-BYVb_0oG.css} +1 -1
  4. package/dist/ui/assets/index-CsrM6RQr.js +110 -0
  5. package/dist/ui/index.html +2 -2
  6. package/node_modules/@hap/core/dist/index.d.mts +258 -9
  7. package/node_modules/@hap/core/dist/index.d.ts +258 -9
  8. package/node_modules/@hap/core/dist/index.js +227 -5
  9. package/node_modules/@hap/core/dist/index.mjs +213 -4
  10. package/node_modules/@hap/core/package.json +3 -2
  11. package/node_modules/@hap/core/src/did-key.ts +126 -0
  12. package/node_modules/@hap/core/src/identity.ts +21 -5
  13. package/node_modules/@hap/core/src/index.ts +3 -0
  14. package/node_modules/@hap/core/src/mandate.ts +207 -0
  15. package/node_modules/@hap/core/src/receipt.ts +74 -0
  16. package/node_modules/@hap/core/src/types.ts +81 -5
  17. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/accept.js +54 -0
  18. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/charset.js +10 -34
  19. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/encoding.js +9 -30
  20. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/language.js +15 -36
  21. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/mediaType.js +16 -134
  22. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/LICENSE +22 -0
  23. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/README.md +71 -0
  24. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/dist/index.d.ts +46 -0
  25. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/dist/index.js +176 -0
  26. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/dist/index.js.map +1 -0
  27. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/package.json +52 -0
  28. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/package.json +16 -10
  29. package/node_modules/@types/node/README.md +1 -1
  30. package/node_modules/@types/node/buffer.buffer.d.ts +5 -5
  31. package/node_modules/@types/node/crypto.d.ts +2 -2
  32. package/node_modules/@types/node/http.d.ts +16 -0
  33. package/node_modules/@types/node/http2.d.ts +10 -2
  34. package/node_modules/@types/node/package.json +2 -2
  35. package/node_modules/@types/node/process.d.ts +52 -0
  36. package/node_modules/@types/node/quic.d.ts +210 -28
  37. package/node_modules/@types/node/sqlite.d.ts +6 -2
  38. package/node_modules/@types/node/test.d.ts +36 -0
  39. package/node_modules/fast-uri/index.js +201 -48
  40. package/node_modules/fast-uri/lib/schemes.js +9 -4
  41. package/node_modules/fast-uri/lib/utils.js +388 -91
  42. package/node_modules/fast-uri/package.json +1 -1
  43. package/node_modules/fast-uri/test/component-safe-serialization.test.js +105 -0
  44. package/node_modules/fast-uri/test/equal.test.js +31 -3
  45. package/node_modules/fast-uri/test/fixtures/uri-js-parse.json +2 -0
  46. package/node_modules/fast-uri/test/ipv6-canonical.test.js +34 -0
  47. package/node_modules/fast-uri/test/ipv6-validation.test.js +90 -0
  48. package/node_modules/fast-uri/test/malformed-percent.test.js +77 -0
  49. package/node_modules/fast-uri/test/malformed-urn.test.js +61 -0
  50. package/node_modules/fast-uri/test/parse.test.js +7 -3
  51. package/node_modules/fast-uri/test/query-fragment-normalization.test.js +33 -0
  52. package/node_modules/fast-uri/test/reserved-path-normalization.test.js +109 -0
  53. package/node_modules/fast-uri/test/scheme-validation.test.js +124 -0
  54. package/node_modules/fast-uri/test/security-normalization.test.js +101 -0
  55. package/node_modules/fast-uri/test/security.test.js +75 -3
  56. package/node_modules/fast-uri/test/urn-full-input.test.js +29 -0
  57. package/node_modules/fast-uri/test/websocket-query-preservation.test.js +24 -0
  58. package/node_modules/hono/dist/cjs/client/client.js +25 -11
  59. package/node_modules/hono/dist/cjs/client/utils.js +4 -1
  60. package/node_modules/hono/dist/cjs/context.js +4 -0
  61. package/node_modules/hono/dist/cjs/helper/accepts/accepts.js +36 -2
  62. package/node_modules/hono/dist/cjs/helper/ssg/ssg.js +1 -1
  63. package/node_modules/hono/dist/cjs/helper/ssg/utils.js +30 -10
  64. package/node_modules/hono/dist/cjs/jsx/dom/render.js +2 -0
  65. package/node_modules/hono/dist/cjs/middleware/cache/index.js +1 -1
  66. package/node_modules/hono/dist/cjs/middleware/cors/index.js +1 -1
  67. package/node_modules/hono/dist/cjs/middleware/csrf/index.js +1 -1
  68. package/node_modules/hono/dist/cjs/middleware/etag/digest.js +1 -1
  69. package/node_modules/hono/dist/cjs/middleware/etag/index.js +3 -3
  70. package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +3 -1
  71. package/node_modules/hono/dist/cjs/request.js +8 -4
  72. package/node_modules/hono/dist/cjs/router/linear-router/router.js +7 -2
  73. package/node_modules/hono/dist/cjs/router/pattern-router/router.js +3 -9
  74. package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +10 -3
  75. package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +47 -83
  76. package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +2 -1
  77. package/node_modules/hono/dist/cjs/router/trie-router/node.js +46 -69
  78. package/node_modules/hono/dist/cjs/router/trie-router/router.js +3 -11
  79. package/node_modules/hono/dist/cjs/router/utils.js +27 -0
  80. package/node_modules/hono/dist/cjs/utils/body.js +15 -3
  81. package/node_modules/hono/dist/cjs/utils/cookie.js +1 -1
  82. package/node_modules/hono/dist/cjs/utils/ipaddr.js +5 -3
  83. package/node_modules/hono/dist/cjs/utils/stream.js +7 -1
  84. package/node_modules/hono/dist/cjs/utils/url.js +9 -1
  85. package/node_modules/hono/dist/client/client.js +25 -11
  86. package/node_modules/hono/dist/client/utils.js +4 -1
  87. package/node_modules/hono/dist/context.js +4 -0
  88. package/node_modules/hono/dist/helper/accepts/accepts.js +36 -2
  89. package/node_modules/hono/dist/helper/ssg/ssg.js +1 -1
  90. package/node_modules/hono/dist/helper/ssg/utils.js +30 -10
  91. package/node_modules/hono/dist/jsx/dom/render.js +2 -0
  92. package/node_modules/hono/dist/middleware/cache/index.js +1 -1
  93. package/node_modules/hono/dist/middleware/cors/index.js +1 -1
  94. package/node_modules/hono/dist/middleware/csrf/index.js +1 -1
  95. package/node_modules/hono/dist/middleware/etag/digest.js +1 -1
  96. package/node_modules/hono/dist/middleware/etag/index.js +3 -3
  97. package/node_modules/hono/dist/middleware/pretty-json/index.js +3 -1
  98. package/node_modules/hono/dist/request.js +8 -4
  99. package/node_modules/hono/dist/router/linear-router/router.js +7 -2
  100. package/node_modules/hono/dist/router/pattern-router/router.js +3 -9
  101. package/node_modules/hono/dist/router/reg-exp-router/node.js +6 -2
  102. package/node_modules/hono/dist/router/reg-exp-router/router.js +53 -84
  103. package/node_modules/hono/dist/router/reg-exp-router/trie.js +2 -1
  104. package/node_modules/hono/dist/router/trie-router/node.js +46 -69
  105. package/node_modules/hono/dist/router/trie-router/router.js +3 -11
  106. package/node_modules/hono/dist/router/utils.js +5 -0
  107. package/node_modules/hono/dist/types/context.d.ts +4 -0
  108. package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +3 -0
  109. package/node_modules/hono/dist/types/router/trie-router/node.d.ts +1 -2
  110. package/node_modules/hono/dist/types/router/trie-router/router.d.ts +0 -1
  111. package/node_modules/hono/dist/types/router/utils.d.ts +1 -0
  112. package/node_modules/hono/dist/types/utils/url.d.ts +4 -0
  113. package/node_modules/hono/dist/utils/body.js +15 -3
  114. package/node_modules/hono/dist/utils/cookie.js +1 -1
  115. package/node_modules/hono/dist/utils/ipaddr.js +5 -3
  116. package/node_modules/hono/dist/utils/stream.js +7 -1
  117. package/node_modules/hono/dist/utils/url.js +9 -1
  118. package/node_modules/hono/package.json +1 -1
  119. package/node_modules/is-plain-object/README.md +39 -95
  120. package/node_modules/is-plain-object/dist/is-plain-object.js +0 -2
  121. package/node_modules/is-plain-object/is-plain-object.d.ts +6 -1
  122. package/node_modules/is-plain-object/package.json +8 -34
  123. package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +4 -3
  124. package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +4 -3
  125. package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +4 -3
  126. package/node_modules/jose/dist/types/jwks/remote.d.ts +4 -4
  127. package/node_modules/jose/dist/types/jws/general/verify.d.ts +3 -3
  128. package/node_modules/jose/dist/types/jwt/encrypt.d.ts +12 -17
  129. package/node_modules/jose/dist/types/jwt/sign.d.ts +8 -14
  130. package/node_modules/jose/dist/types/jwt/unsecured.d.ts +9 -15
  131. package/node_modules/jose/dist/types/types.d.ts +4 -2
  132. package/node_modules/jose/dist/webapi/jwe/compact/encrypt.js +30 -8
  133. package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +8 -4
  134. package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +6 -13
  135. package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +19 -19
  136. package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +32 -21
  137. package/node_modules/jose/dist/webapi/jwk/embedded.js +15 -1
  138. package/node_modules/jose/dist/webapi/jwk/thumbprint.js +11 -5
  139. package/node_modules/jose/dist/webapi/jwks/local.js +45 -53
  140. package/node_modules/jose/dist/webapi/jwks/remote.js +82 -103
  141. package/node_modules/jose/dist/webapi/jws/compact/sign.js +10 -9
  142. package/node_modules/jose/dist/webapi/jws/flattened/sign.js +2 -1
  143. package/node_modules/jose/dist/webapi/jws/flattened/verify.js +8 -7
  144. package/node_modules/jose/dist/webapi/jws/general/sign.js +5 -3
  145. package/node_modules/jose/dist/webapi/jws/general/verify.js +51 -21
  146. package/node_modules/jose/dist/webapi/jwt/decrypt.js +7 -9
  147. package/node_modules/jose/dist/webapi/jwt/encrypt.js +21 -50
  148. package/node_modules/jose/dist/webapi/jwt/sign.js +8 -41
  149. package/node_modules/jose/dist/webapi/jwt/unsecured.js +21 -42
  150. package/node_modules/jose/dist/webapi/key/generate_key_pair.js +6 -2
  151. package/node_modules/jose/dist/webapi/key/generate_secret.js +7 -6
  152. package/node_modules/jose/dist/webapi/key/import.js +16 -12
  153. package/node_modules/jose/dist/webapi/lib/asn1.js +7 -2
  154. package/node_modules/jose/dist/webapi/lib/content_encryption.js +7 -15
  155. package/node_modules/jose/dist/webapi/lib/deflate.js +8 -0
  156. package/node_modules/jose/dist/webapi/lib/helpers.js +1 -1
  157. package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +85 -28
  158. package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +45 -13
  159. package/node_modules/jose/dist/webapi/lib/jwk_metadata.js +20 -0
  160. package/node_modules/jose/dist/webapi/lib/jws_sign.js +47 -36
  161. package/node_modules/jose/dist/webapi/lib/jws_verify.js +77 -45
  162. package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +82 -47
  163. package/node_modules/jose/dist/webapi/lib/key.js +24 -9
  164. package/node_modules/jose/dist/webapi/lib/key_management.js +10 -4
  165. package/node_modules/jose/dist/webapi/lib/key_options.js +6 -0
  166. package/node_modules/jose/dist/webapi/lib/options.js +26 -0
  167. package/node_modules/jose/dist/webapi/lib/type_checks.js +11 -13
  168. package/node_modules/jose/package.json +1 -1
  169. package/package.json +2 -2
  170. package/dist/ui/assets/index-0Q2eNytX.js +0 -110
  171. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/HISTORY.md +0 -114
@@ -8,6 +8,8 @@
8
8
 
9
9
  'use strict';
10
10
 
11
+ var parseAccept = require('./accept');
12
+
11
13
  /**
12
14
  * Module exports.
13
15
  * @public
@@ -21,55 +23,29 @@ module.exports.preferredCharsets = preferredCharsets;
21
23
  * @private
22
24
  */
23
25
 
24
- var simpleCharsetRegExp = /^\s*([^\s;]+)\s*(?:;(.*))?$/;
25
-
26
- /**
27
- * Parse the Accept-Charset header.
28
- * @private
29
- */
30
-
31
26
  function parseAcceptCharset(accept) {
32
- var accepts = accept.split(',');
27
+ var accepts = parseAccept(accept);
33
28
 
34
29
  for (var i = 0, j = 0; i < accepts.length; i++) {
35
- var charset = parseCharset(accepts[i].trim(), i);
36
-
37
- if (charset) {
38
- accepts[j++] = charset;
39
- }
30
+ var charset = formatCharset(accepts[i], i);
31
+ if (charset) accepts[j++] = charset;
40
32
  }
41
33
 
42
- // trim accepts
43
34
  accepts.length = j;
44
-
45
35
  return accepts;
46
36
  }
47
37
 
48
38
  /**
49
- * Parse a charset from the Accept-Charset header.
39
+ * Format a parsed charset for negotiation.
50
40
  * @private
51
41
  */
52
42
 
53
- function parseCharset(str, i) {
54
- var match = simpleCharsetRegExp.exec(str);
55
- if (!match) return null;
56
-
57
- var charset = match[1];
58
- var q = 1;
59
- if (match[2]) {
60
- var params = match[2].split(';')
61
- for (var j = 0; j < params.length; j++) {
62
- var p = params[j].trim().split('=');
63
- if (p[0] === 'q') {
64
- q = parseFloat(p[1]);
65
- break;
66
- }
67
- }
68
- }
43
+ function formatCharset(parsed, i) {
44
+ if (!parsed.type) return null;
69
45
 
70
46
  return {
71
- charset: charset,
72
- q: q,
47
+ charset: parsed.type,
48
+ q: parsed.parameters.q ? parseFloat(parsed.parameters.q) : 1,
73
49
  i: i
74
50
  };
75
51
  }
@@ -8,6 +8,8 @@
8
8
 
9
9
  'use strict';
10
10
 
11
+ var parseAccept = require('./accept');
12
+
11
13
  /**
12
14
  * Module exports.
13
15
  * @public
@@ -21,20 +23,13 @@ module.exports.preferredEncodings = preferredEncodings;
21
23
  * @private
22
24
  */
23
25
 
24
- var simpleEncodingRegExp = /^\s*([^\s;]+)\s*(?:;(.*))?$/;
25
-
26
- /**
27
- * Parse the Accept-Encoding header.
28
- * @private
29
- */
30
-
31
26
  function parseAcceptEncoding(accept) {
32
- var accepts = accept.split(',');
27
+ var accepts = parseAccept(accept);
33
28
  var hasIdentity = false;
34
29
  var minQuality = 1;
35
30
 
36
31
  for (var i = 0, j = 0; i < accepts.length; i++) {
37
- var encoding = parseEncoding(accepts[i].trim(), i);
32
+ var encoding = formatEncoding(accepts[i], i);
38
33
 
39
34
  if (encoding) {
40
35
  accepts[j++] = encoding;
@@ -55,37 +50,21 @@ function parseAcceptEncoding(accept) {
55
50
  };
56
51
  }
57
52
 
58
- // trim accepts
59
53
  accepts.length = j;
60
-
61
54
  return accepts;
62
55
  }
63
56
 
64
57
  /**
65
- * Parse an encoding from the Accept-Encoding header.
58
+ * Format a parsed encoding for negotiation.
66
59
  * @private
67
60
  */
68
61
 
69
- function parseEncoding(str, i) {
70
- var match = simpleEncodingRegExp.exec(str);
71
- if (!match) return null;
72
-
73
- var encoding = match[1];
74
- var q = 1;
75
- if (match[2]) {
76
- var params = match[2].split(';');
77
- for (var j = 0; j < params.length; j++) {
78
- var p = params[j].trim().split('=');
79
- if (p[0] === 'q') {
80
- q = parseFloat(p[1]);
81
- break;
82
- }
83
- }
84
- }
62
+ function formatEncoding(parsed, i) {
63
+ if (!parsed.type) return null;
85
64
 
86
65
  return {
87
- encoding: encoding,
88
- q: q,
66
+ encoding: parsed.type,
67
+ q: parsed.parameters.q ? parseFloat(parsed.parameters.q) : 1,
89
68
  i: i
90
69
  };
91
70
  }
@@ -8,6 +8,9 @@
8
8
 
9
9
  'use strict';
10
10
 
11
+ var contentType = require('content-type');
12
+ var parseAccept = require('./accept');
13
+
11
14
  /**
12
15
  * Module exports.
13
16
  * @public
@@ -21,60 +24,36 @@ module.exports.preferredLanguages = preferredLanguages;
21
24
  * @private
22
25
  */
23
26
 
24
- var simpleLanguageRegExp = /^\s*([^\s\-;]+)(?:-([^\s;]+))?\s*(?:;(.*))?$/;
25
-
26
- /**
27
- * Parse the Accept-Language header.
28
- * @private
29
- */
30
-
31
27
  function parseAcceptLanguage(accept) {
32
- var accepts = accept.split(',');
28
+ var accepts = parseAccept(accept);
33
29
 
34
30
  for (var i = 0, j = 0; i < accepts.length; i++) {
35
- var language = parseLanguage(accepts[i].trim(), i);
36
-
37
- if (language) {
38
- accepts[j++] = language;
39
- }
31
+ var language = formatLanguage(accepts[i], i);
32
+ if (language) accepts[j++] = language;
40
33
  }
41
34
 
42
- // trim accepts
43
35
  accepts.length = j;
44
-
45
36
  return accepts;
46
37
  }
47
38
 
48
39
  /**
49
- * Parse a language from the Accept-Language header.
40
+ * Format a parsed language for negotiation.
50
41
  * @private
51
42
  */
52
43
 
53
- function parseLanguage(str, i) {
54
- var match = simpleLanguageRegExp.exec(str);
55
- if (!match) return null;
56
-
57
- var prefix = match[1]
58
- var suffix = match[2]
59
- var full = prefix
44
+ function formatLanguage(parsed, i) {
45
+ if (!parsed.type) return null;
60
46
 
61
- if (suffix) full += "-" + suffix;
62
-
63
- var q = 1;
64
- if (match[3]) {
65
- var params = match[3].split(';')
66
- for (var j = 0; j < params.length; j++) {
67
- var p = params[j].split('=');
68
- if (p[0] === 'q') q = parseFloat(p[1]);
69
- }
70
- }
47
+ var hyphen = parsed.type.indexOf('-');
48
+ var prefix = hyphen === -1 ? parsed.type : parsed.type.slice(0, hyphen);
49
+ var suffix = hyphen === -1 ? undefined : parsed.type.slice(hyphen + 1);
71
50
 
72
51
  return {
73
52
  prefix: prefix,
74
53
  suffix: suffix,
75
- q: q,
54
+ q: parsed.parameters.q ? parseFloat(parsed.parameters.q) : 1,
76
55
  i: i,
77
- full: full
56
+ full: parsed.type
78
57
  };
79
58
  }
80
59
 
@@ -103,7 +82,7 @@ function getLanguagePriority(language, accepted, index) {
103
82
  */
104
83
 
105
84
  function specify(language, spec, index) {
106
- var p = parseLanguage(language)
85
+ var p = formatLanguage(contentType.parse(language), 0)
107
86
  if (!p) return null;
108
87
  var s = 0;
109
88
  if(spec.full.toLowerCase() === p.full.toLowerCase()){
@@ -8,6 +8,9 @@
8
8
 
9
9
  'use strict';
10
10
 
11
+ var contentType = require('content-type');
12
+ var parseAcceptHeader = require('./accept');
13
+
11
14
  /**
12
15
  * Module exports.
13
16
  * @public
@@ -21,71 +24,35 @@ module.exports.preferredMediaTypes = preferredMediaTypes;
21
24
  * @private
22
25
  */
23
26
 
24
- var simpleMediaTypeRegExp = /^\s*([^\s\/;]+)\/([^;\s]+)\s*(?:;(.*))?$/;
25
-
26
- /**
27
- * Parse the Accept header.
28
- * @private
29
- */
30
-
31
27
  function parseAccept(accept) {
32
- var accepts = splitMediaTypes(accept);
28
+ var accepts = parseAcceptHeader(accept);
33
29
 
34
30
  for (var i = 0, j = 0; i < accepts.length; i++) {
35
- var mediaType = parseMediaType(accepts[i].trim(), i);
36
-
37
- if (mediaType) {
38
- accepts[j++] = mediaType;
39
- }
31
+ var mediaType = formatMediaType(accepts[i], i);
32
+ if (mediaType) accepts[j++] = mediaType;
40
33
  }
41
34
 
42
- // trim accepts
43
35
  accepts.length = j;
44
-
45
36
  return accepts;
46
37
  }
47
38
 
48
39
  /**
49
- * Parse a media type from the Accept header.
40
+ * Format a parsed content type for negotiation.
50
41
  * @private
51
42
  */
52
43
 
53
- function parseMediaType(str, i) {
54
- var match = simpleMediaTypeRegExp.exec(str);
55
- if (!match) return null;
56
-
57
- var params = Object.create(null);
58
- var q = 1;
59
- var subtype = match[2];
60
- var type = match[1];
61
-
62
- if (match[3]) {
63
- var kvps = splitParameters(match[3]).map(splitKeyValuePair);
64
-
65
- for (var j = 0; j < kvps.length; j++) {
66
- var pair = kvps[j];
67
- var key = pair[0].toLowerCase();
68
- var val = pair[1];
44
+ function formatMediaType(parsed, i) {
45
+ var slash = parsed.type.indexOf('/');
46
+ if (slash === -1) return null;
69
47
 
70
- // get the value, unwrapping quotes
71
- var value = val && val[0] === '"' && val[val.length - 1] === '"'
72
- ? val.slice(1, -1)
73
- : val;
48
+ var q = parsed.parameters.q ? parseFloat(parsed.parameters.q) : 1;
74
49
 
75
- if (key === 'q') {
76
- q = parseFloat(value);
77
- break;
78
- }
79
-
80
- // store parameter
81
- params[key] = value;
82
- }
83
- }
50
+ delete parsed.parameters.q;
84
51
 
85
52
  return {
86
- type: type,
87
- subtype: subtype,
88
- params: params,
53
+ type: parsed.type.slice(0, slash),
54
+ subtype: parsed.type.slice(slash + 1),
55
+ params: parsed.parameters,
89
56
  q: q,
90
57
  i: i
91
58
  };
@@ -116,7 +83,7 @@ function getMediaTypePriority(type, accepted, index) {
116
83
  */
117
84
 
118
85
  function specify(type, spec, index) {
119
- var p = parseMediaType(type);
86
+ var p = formatMediaType(contentType.parse(type), 0);
120
87
  var s = 0;
121
88
 
122
89
  if (!p) {
@@ -207,88 +174,3 @@ function getFullType(spec) {
207
174
  function isQuality(spec) {
208
175
  return spec.q > 0;
209
176
  }
210
-
211
- /**
212
- * Count the number of quotes in a string.
213
- * @private
214
- */
215
-
216
- function quoteCount(string) {
217
- var count = 0;
218
- var index = 0;
219
-
220
- while ((index = string.indexOf('"', index)) !== -1) {
221
- count++;
222
- index++;
223
- }
224
-
225
- return count;
226
- }
227
-
228
- /**
229
- * Split a key value pair.
230
- * @private
231
- */
232
-
233
- function splitKeyValuePair(str) {
234
- var index = str.indexOf('=');
235
- var key;
236
- var val;
237
-
238
- if (index === -1) {
239
- key = str;
240
- } else {
241
- key = str.slice(0, index);
242
- val = str.slice(index + 1);
243
- }
244
-
245
- return [key, val];
246
- }
247
-
248
- /**
249
- * Split an Accept header into media types.
250
- * @private
251
- */
252
-
253
- function splitMediaTypes(accept) {
254
- var accepts = accept.split(',');
255
-
256
- for (var i = 1, j = 0; i < accepts.length; i++) {
257
- if (quoteCount(accepts[j]) % 2 == 0) {
258
- accepts[++j] = accepts[i];
259
- } else {
260
- accepts[j] += ',' + accepts[i];
261
- }
262
- }
263
-
264
- // trim accepts
265
- accepts.length = j + 1;
266
-
267
- return accepts;
268
- }
269
-
270
- /**
271
- * Split a string of parameters.
272
- * @private
273
- */
274
-
275
- function splitParameters(str) {
276
- var parameters = str.split(';');
277
-
278
- for (var i = 1, j = 0; i < parameters.length; i++) {
279
- if (quoteCount(parameters[j]) % 2 == 0) {
280
- parameters[++j] = parameters[i];
281
- } else {
282
- parameters[j] += ';' + parameters[i];
283
- }
284
- }
285
-
286
- // trim parameters
287
- parameters.length = j + 1;
288
-
289
- for (var i = 0; i < parameters.length; i++) {
290
- parameters[i] = parameters[i].trim();
291
- }
292
-
293
- return parameters;
294
- }
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2015 Douglas Christopher Wilson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,71 @@
1
+ # content-type
2
+
3
+ [![NPM version][npm-image]][npm-url]
4
+ [![NPM downloads][downloads-image]][downloads-url]
5
+ [![Build status][build-image]][build-url]
6
+ [![Build coverage][coverage-image]][coverage-url]
7
+ [![License][license-image]][license-url]
8
+
9
+ Create and parse HTTP `Content-Type` header.
10
+
11
+ ## Installation
12
+
13
+ ```sh
14
+ npm install content-type
15
+ ```
16
+
17
+ ## API
18
+
19
+ ```js
20
+ const contentType = require("content-type");
21
+ ```
22
+
23
+ ### contentType.parse(string, options?)
24
+
25
+ ```js
26
+ const obj = contentType.parse("image/svg+xml; charset=utf-8");
27
+ ```
28
+
29
+ Parse a `Content-Type` header. This will return an object with the following properties (examples are shown for the string `'image/svg+xml; charset=utf-8'`):
30
+
31
+ - `type`: The media type. Example: `'image/svg+xml'`.
32
+ - `parameters`: An object of the parameters in the media type (parameter name is always lower case). Example: `{charset: 'utf-8'}`.
33
+
34
+ The parser is lenient and does not error. You should validate `type` and `parameters` before trusting them.
35
+
36
+ #### Options
37
+
38
+ - `parameters` (default: `true`): Set to `false` to skip parameters.
39
+ - `comma` (default: `false`): Set to `true` to stop on a comma. This can be used to parse the media range in an `Accept` header.
40
+ - `start` (default: `0`): Set index to start parsing from.
41
+
42
+ ### contentType.format(obj)
43
+
44
+ ```js
45
+ const str = contentType.format({
46
+ type: "image/svg+xml",
47
+ parameters: { charset: "utf-8" },
48
+ });
49
+ ```
50
+
51
+ Format an object into a `Content-Type` header. This will return a string of the content type for the given object with the following properties (examples are shown that produce the string `'image/svg+xml; charset=utf-8'`):
52
+
53
+ - `type`: The media type. Example: `'image/svg+xml'`.
54
+ - `parameters`: An optional object of the parameters in the media type. Example: `{charset: 'utf-8'}`.
55
+
56
+ Throws a `TypeError` if the object contains an invalid type or parameter names.
57
+
58
+ ## License
59
+
60
+ [MIT](LICENSE)
61
+
62
+ [npm-image]: https://img.shields.io/npm/v/content-type
63
+ [npm-url]: https://npmjs.org/package/content-type
64
+ [downloads-image]: https://img.shields.io/npm/dm/content-type
65
+ [downloads-url]: https://npmjs.org/package/content-type
66
+ [build-image]: https://img.shields.io/github/actions/workflow/status/jshttp/content-type/ci.yml?branch=master
67
+ [build-url]: https://github.com/jshttp/content-type/actions/workflows/ci.yml?query=branch%3Amaster
68
+ [coverage-image]: https://img.shields.io/codecov/c/gh/jshttp/content-type
69
+ [coverage-url]: https://codecov.io/gh/jshttp/content-type
70
+ [license-image]: http://img.shields.io/npm/l/content-type.svg?style=flat
71
+ [license-url]: LICENSE
@@ -0,0 +1,46 @@
1
+ /*!
2
+ * content-type
3
+ * Copyright(c) 2015 Douglas Christopher Wilson
4
+ * MIT Licensed
5
+ */
6
+ /**
7
+ * The content type object contains a type string and optional parameters.
8
+ */
9
+ export interface ContentType {
10
+ type: string;
11
+ index: number;
12
+ parameters: Record<string, string>;
13
+ }
14
+ /**
15
+ * Format an object into a `Content-Type` header.
16
+ */
17
+ export declare function format(obj: Partial<ContentType>): string;
18
+ /**
19
+ * Options for parsing a `Content-Type` header.
20
+ */
21
+ export interface ParseOptions {
22
+ /**
23
+ * Exit early on the first semicolon, returning only the type.
24
+ * This is useful for parsing the MIME from `Content-Type` headers.
25
+ *
26
+ * @default false
27
+ */
28
+ parameters?: boolean;
29
+ /**
30
+ * Exits early on a comma, returning the first value and parameters.
31
+ * This is useful for parsing `Accept` headers.
32
+ *
33
+ * @default false
34
+ */
35
+ comma?: boolean;
36
+ /**
37
+ * The index to start parsing from.
38
+ *
39
+ * @default 0
40
+ */
41
+ start?: number;
42
+ }
43
+ /**
44
+ * Parse a `Content-Type` header.
45
+ */
46
+ export declare function parse(header: string, options?: ParseOptions): ContentType;