@suveren/gateway 0.20.2 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/content/integrations/erp.json +15 -3
- package/dist/control-plane/index.mjs +179 -46
- package/dist/mcp-server/http.mjs +623 -181
- package/dist/ui/assets/{index-blnpvM2g.css → index-BSAkn_Of.css} +1 -1
- package/dist/ui/assets/index-CBoGbefI.js +116 -0
- package/dist/ui/index.html +2 -2
- package/node_modules/@modelcontextprotocol/sdk/node_modules/content-disposition/README.md +105 -35
- package/node_modules/@modelcontextprotocol/sdk/node_modules/content-disposition/dist/index.d.ts +72 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/content-disposition/dist/index.js +388 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/content-disposition/dist/index.js.map +1 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/content-disposition/package.json +31 -19
- package/node_modules/@modelcontextprotocol/sdk/node_modules/express/Readme.md +15 -9
- package/node_modules/@modelcontextprotocol/sdk/node_modules/express/lib/application.js +2 -2
- package/node_modules/@modelcontextprotocol/sdk/node_modules/express/lib/request.js +32 -19
- package/node_modules/@modelcontextprotocol/sdk/node_modules/express/lib/response.js +27 -30
- package/node_modules/@modelcontextprotocol/sdk/node_modules/express/node_modules/content-type/LICENSE +22 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/express/node_modules/content-type/README.md +71 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/express/node_modules/content-type/dist/index.d.ts +46 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/express/node_modules/content-type/dist/index.js +176 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/express/node_modules/content-type/dist/index.js.map +1 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/express/node_modules/content-type/package.json +52 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/express/package.json +10 -10
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/package.json +2 -2
- package/node_modules/@types/node/util.d.ts +6 -3
- package/package.json +1 -1
- package/dist/ui/assets/index-1s1q-XLL.js +0 -116
- package/node_modules/@modelcontextprotocol/sdk/node_modules/content-disposition/index.js +0 -536
package/dist/ui/index.html
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
<meta name="apple-mobile-web-app-title" content="Suveren" />
|
|
15
15
|
<meta name="theme-color" content="#111111" />
|
|
16
16
|
<title>Suveren</title>
|
|
17
|
-
<script type="module" crossorigin src="/assets/index-
|
|
18
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
17
|
+
<script type="module" crossorigin src="/assets/index-CBoGbefI.js"></script>
|
|
18
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BSAkn_Of.css">
|
|
19
19
|
</head>
|
|
20
20
|
<body>
|
|
21
21
|
<div id="root"></div>
|
|
@@ -17,17 +17,17 @@ $ npm install content-disposition
|
|
|
17
17
|
## API
|
|
18
18
|
|
|
19
19
|
```js
|
|
20
|
-
|
|
20
|
+
import { create, parse, format } from 'content-disposition';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
###
|
|
23
|
+
### create(filename, options)
|
|
24
24
|
|
|
25
25
|
Create an attachment `Content-Disposition` header value using the given file name,
|
|
26
26
|
if supplied. The `filename` is optional and if no file name is desired, but you
|
|
27
27
|
want to specify `options`, set `filename` to `undefined`.
|
|
28
28
|
|
|
29
29
|
```js
|
|
30
|
-
res.setHeader('Content-Disposition',
|
|
30
|
+
res.setHeader('Content-Disposition', create('∫ maths.pdf'));
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
**note** HTTP headers are of the ISO-8859-1 character set. If you are writing this
|
|
@@ -40,73 +40,139 @@ the `'binary'` encoding in Node.js.
|
|
|
40
40
|
|
|
41
41
|
##### fallback
|
|
42
42
|
|
|
43
|
-
If the `filename` option is outside
|
|
43
|
+
If the `filename` option is outside US-ASCII, then the file name is actually
|
|
44
44
|
stored in a supplemental field for clients that support Unicode file names and
|
|
45
|
-
a
|
|
45
|
+
a US-ASCII version of the file name is automatically generated.
|
|
46
46
|
|
|
47
|
-
This specifies the
|
|
47
|
+
This specifies the US-ASCII file name to override the automatic generation or
|
|
48
48
|
disables the generation all together, defaults to `true`.
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
- A string will specify the US-ASCII file name to use in place of automatic
|
|
51
|
+
generation.
|
|
52
|
+
- `false` will disable including a US-ASCII file name and only include the
|
|
53
|
+
Unicode version (unless the file name is already US-ASCII).
|
|
54
|
+
- `true` will enable automatic generation if the file name is outside US-ASCII.
|
|
55
55
|
|
|
56
|
-
If the `filename` option is
|
|
56
|
+
If the `filename` option is US-ASCII and this option is specified and has a
|
|
57
57
|
different value, then the `filename` option is encoded in the extended field
|
|
58
|
-
and this set as the fallback field, even though they are both
|
|
58
|
+
and this set as the fallback field, even though they are both US-ASCII.
|
|
59
59
|
|
|
60
60
|
##### type
|
|
61
61
|
|
|
62
62
|
Specifies the disposition type, defaults to `"attachment"`. This can also be
|
|
63
63
|
`"inline"`, or any other value (all values except inline are treated like
|
|
64
64
|
`attachment`, but can convey additional information if both parties agree to
|
|
65
|
-
it).
|
|
65
|
+
it).
|
|
66
66
|
|
|
67
|
-
###
|
|
67
|
+
### parse(string, options)
|
|
68
68
|
|
|
69
69
|
```js
|
|
70
|
-
const disposition =
|
|
70
|
+
const disposition = parse(
|
|
71
|
+
'attachment; filename="EURO rates.txt"; filename*=UTF-8\'\'%e2%82%ac%20rates.txt',
|
|
72
|
+
);
|
|
71
73
|
```
|
|
72
74
|
|
|
73
75
|
Parse a `Content-Disposition` header string. This automatically handles extended
|
|
74
76
|
("Unicode") parameters by decoding them and providing them under the standard
|
|
75
|
-
parameter name. This will return an object with the following properties
|
|
76
|
-
are shown for the string `'attachment; filename="EURO rates.txt"; filename*=UTF-8\'\'%e2%82%ac%20rates.txt'`):
|
|
77
|
+
parameter name. This will return an object with the following properties:
|
|
77
78
|
|
|
78
|
-
|
|
79
|
+
- `type`: The disposition type (always lower case). Example: `'attachment'`
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
- `parameters`: An object of the parameters in the disposition (name of parameter
|
|
82
|
+
always lower case and extended versions replace non-extended versions). Example:
|
|
83
|
+
`{filename: "€ rates.txt"}`
|
|
84
|
+
|
|
85
|
+
#### Options
|
|
86
|
+
|
|
87
|
+
##### multipart
|
|
88
|
+
|
|
89
|
+
Parse parameters using browser `multipart/form-data` behavior.
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
parse('form-data; name="file"; filename="the %22plans%22.pdf"', {
|
|
93
|
+
multipart: true,
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
##### extended
|
|
98
|
+
|
|
99
|
+
Parse RFC 5987 extended header parameters automatically when decoding
|
|
100
|
+
parameters, defaults to `true`.
|
|
101
|
+
|
|
102
|
+
### format(obj, options)
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
const disposition = format({
|
|
106
|
+
type: 'attachment',
|
|
107
|
+
parameters: {
|
|
108
|
+
filename: '€ rates.txt',
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Formats an object to a `Content-Disposition` header string. This automatically
|
|
114
|
+
handles extended ("Unicode") parameters and returns a string. Example:
|
|
115
|
+
`'attachment; filename*=UTF-8''%E2%82%AC%20rates.txt'`
|
|
116
|
+
|
|
117
|
+
#### Options
|
|
118
|
+
|
|
119
|
+
##### multipart
|
|
120
|
+
|
|
121
|
+
Format parameters using browser `multipart/form-data` behavior. This quotes
|
|
122
|
+
parameter values, escapes `"` as `%22`, and writes Unicode values directly
|
|
123
|
+
instead of using extended parameters.
|
|
124
|
+
|
|
125
|
+
```js
|
|
126
|
+
format(
|
|
127
|
+
{
|
|
128
|
+
type: 'form-data',
|
|
129
|
+
parameters: { name: 'file', filename: '€ rates.txt' },
|
|
130
|
+
},
|
|
131
|
+
{ multipart: true },
|
|
132
|
+
);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
##### extended
|
|
136
|
+
|
|
137
|
+
Encode Unicode parameter values using RFC 5987 extended header parameters,
|
|
138
|
+
e.g. `filename*=`, defaults to `true`.
|
|
83
139
|
|
|
84
140
|
## Examples
|
|
85
141
|
|
|
86
142
|
### Send a file for download
|
|
87
143
|
|
|
88
144
|
```js
|
|
89
|
-
const contentDisposition = require('content-disposition')
|
|
90
|
-
const fs = require('fs')
|
|
91
|
-
const http = require('http')
|
|
92
|
-
const onFinished = require('on-finished')
|
|
145
|
+
const contentDisposition = require('content-disposition');
|
|
146
|
+
const fs = require('fs');
|
|
147
|
+
const http = require('http');
|
|
148
|
+
const onFinished = require('on-finished');
|
|
93
149
|
|
|
94
|
-
const filePath = '/path/to/public/plans.pdf'
|
|
150
|
+
const filePath = '/path/to/public/plans.pdf';
|
|
95
151
|
|
|
96
|
-
http.createServer(function onRequest
|
|
152
|
+
http.createServer(function onRequest(req, res) {
|
|
97
153
|
// set headers
|
|
98
|
-
res.setHeader('Content-Type', 'application/pdf')
|
|
99
|
-
res.setHeader('Content-Disposition', contentDisposition(filePath))
|
|
154
|
+
res.setHeader('Content-Type', 'application/pdf');
|
|
155
|
+
res.setHeader('Content-Disposition', contentDisposition(filePath));
|
|
100
156
|
|
|
101
157
|
// send file
|
|
102
|
-
const stream = fs.createReadStream(filePath)
|
|
103
|
-
stream.pipe(res)
|
|
158
|
+
const stream = fs.createReadStream(filePath);
|
|
159
|
+
stream.pipe(res);
|
|
104
160
|
onFinished(res, function () {
|
|
105
|
-
stream.destroy()
|
|
106
|
-
})
|
|
107
|
-
})
|
|
161
|
+
stream.destroy();
|
|
162
|
+
});
|
|
163
|
+
});
|
|
108
164
|
```
|
|
109
165
|
|
|
166
|
+
## Local demo
|
|
167
|
+
|
|
168
|
+
Run the upload inspector locally:
|
|
169
|
+
|
|
170
|
+
```sh
|
|
171
|
+
npm run demo
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Then open `http://127.0.0.1:3000` in your browser. The demo lets you upload files, inspect the multipart upload part headers sent by the browser, and compare them with the download `Content-Disposition` header generated by this package.
|
|
175
|
+
|
|
110
176
|
## Testing
|
|
111
177
|
|
|
112
178
|
```sh
|
|
@@ -118,11 +184,15 @@ $ npm test
|
|
|
118
184
|
- [RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1][rfc-2616]
|
|
119
185
|
- [RFC 5987: Character Set and Language Encoding for Hypertext Transfer Protocol (HTTP) Header Field Parameters][rfc-5987]
|
|
120
186
|
- [RFC 6266: Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)][rfc-6266]
|
|
187
|
+
- [RFC 8187: Indicating Character Encoding and Language for HTTP Header Field Parameters][rfc-8187]
|
|
188
|
+
- [HTML Living Standard: Multipart form data][html-form]
|
|
121
189
|
- [Test Cases for HTTP Content-Disposition header field (RFC 6266) and the Encodings defined in RFCs 2047, 2231 and 5987][tc-2231]
|
|
122
190
|
|
|
123
191
|
[rfc-2616]: https://datatracker.ietf.org/doc/html/rfc2616
|
|
124
192
|
[rfc-5987]: https://datatracker.ietf.org/doc/html/rfc5987
|
|
125
193
|
[rfc-6266]: https://datatracker.ietf.org/doc/html/rfc6266
|
|
194
|
+
[rfc-8187]: https://datatracker.ietf.org/doc/html/rfc8187
|
|
195
|
+
[html-form]: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data
|
|
126
196
|
[tc-2231]: http://greenbytes.de/tech/tc2231/
|
|
127
197
|
|
|
128
198
|
## License
|
package/node_modules/@modelcontextprotocol/sdk/node_modules/content-disposition/dist/index.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* content-disposition
|
|
3
|
+
* Copyright(c) 2014-2017 Douglas Christopher Wilson
|
|
4
|
+
* MIT Licensed
|
|
5
|
+
*/
|
|
6
|
+
export interface ContentDisposition {
|
|
7
|
+
/**
|
|
8
|
+
* Content-Disposition type, such as "attachment" or "inline"
|
|
9
|
+
*/
|
|
10
|
+
type: string;
|
|
11
|
+
/**
|
|
12
|
+
* Content-Disposition parameters, such as "filename"
|
|
13
|
+
*/
|
|
14
|
+
parameters: Record<string, string>;
|
|
15
|
+
}
|
|
16
|
+
export interface CreateOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Content-Disposition type, defaults to "attachment"
|
|
19
|
+
* @default "attachment"
|
|
20
|
+
*/
|
|
21
|
+
type?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Fallback filename for non-US-ASCII strings. If true, a fallback will be generated by replacing non-US-ASCII characters with "?". If false, no fallback will be generated.
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
fallback?: string | boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create an attachment Content-Disposition header.
|
|
30
|
+
*/
|
|
31
|
+
export declare function create(filename?: string, options?: CreateOptions): string;
|
|
32
|
+
export interface ParseOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Whether to decode RFC 8187 encoded parameters.
|
|
35
|
+
* @default true
|
|
36
|
+
*/
|
|
37
|
+
extended?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Parse parameters as sent by browsers in `multipart/form-data`.
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
multipart?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Parse Content-Disposition header string.
|
|
46
|
+
*/
|
|
47
|
+
export declare function parse(header: string, options?: ParseOptions): ContentDisposition;
|
|
48
|
+
/**
|
|
49
|
+
* Decode a RFC 8187 field value (gracefully).
|
|
50
|
+
*/
|
|
51
|
+
export declare function decodeExtended(str: string): string | undefined;
|
|
52
|
+
export interface FormatOptions {
|
|
53
|
+
/**
|
|
54
|
+
* Whether to use extended parameter encoding for non-ISO-8859-1 strings.
|
|
55
|
+
* If false, an error will be thrown when formatting such strings.
|
|
56
|
+
* @default true
|
|
57
|
+
*/
|
|
58
|
+
extended?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Format parameters as sent by browsers in `multipart/form-data`.
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
multipart?: boolean;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Format object to Content-Disposition header.
|
|
67
|
+
*/
|
|
68
|
+
export declare function format(obj: Partial<ContentDisposition>, options?: FormatOptions): string;
|
|
69
|
+
/**
|
|
70
|
+
* Encode a Unicode string for HTTP (RFC 8187).
|
|
71
|
+
*/
|
|
72
|
+
export declare function encodeExtended(str: string): string;
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* content-disposition
|
|
4
|
+
* Copyright(c) 2014-2017 Douglas Christopher Wilson
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.create = create;
|
|
9
|
+
exports.parse = parse;
|
|
10
|
+
exports.decodeExtended = decodeExtended;
|
|
11
|
+
exports.format = format;
|
|
12
|
+
exports.encodeExtended = encodeExtended;
|
|
13
|
+
/**
|
|
14
|
+
* Null object perf optimization. Faster than `Object.create(null)` and `{ __proto__: null }`.
|
|
15
|
+
*/
|
|
16
|
+
const NullObject = /* @__PURE__ */ (() => {
|
|
17
|
+
const C = function () { };
|
|
18
|
+
C.prototype = Object.create(null);
|
|
19
|
+
return C;
|
|
20
|
+
})();
|
|
21
|
+
/**
|
|
22
|
+
* Create an attachment Content-Disposition header.
|
|
23
|
+
*/
|
|
24
|
+
function create(filename, options) {
|
|
25
|
+
const type = options?.type || 'attachment';
|
|
26
|
+
const parameters = createParameters(filename, options?.fallback);
|
|
27
|
+
return format({ type, parameters }, { extended: false });
|
|
28
|
+
}
|
|
29
|
+
const SP = 32; // " "
|
|
30
|
+
const HTAB = 9; // "\t"
|
|
31
|
+
const SEMI = 59; // ";"
|
|
32
|
+
const EQ = 61; // "="
|
|
33
|
+
const DQUOTE = 34; // '"'
|
|
34
|
+
const BSLASH = 92; // "\\"
|
|
35
|
+
const ASTERISK = 42; // "*"
|
|
36
|
+
/**
|
|
37
|
+
* Parse Content-Disposition header string.
|
|
38
|
+
*/
|
|
39
|
+
function parse(header, options) {
|
|
40
|
+
const len = header.length;
|
|
41
|
+
const multipart = options?.multipart === true;
|
|
42
|
+
const extended = options?.extended !== false;
|
|
43
|
+
let index = skipOWS(header, 0, header.length);
|
|
44
|
+
const typeStart = index;
|
|
45
|
+
index = parseToken(header, index, len);
|
|
46
|
+
const typeEnd = trailingOWS(header, typeStart, index);
|
|
47
|
+
const type = header.slice(typeStart, typeEnd).toLowerCase();
|
|
48
|
+
const parameters = new NullObject();
|
|
49
|
+
parameter: while (index < len) {
|
|
50
|
+
index = skipOWS(header, index + 1, len); // Skip over semicolon.
|
|
51
|
+
const keyStart = index;
|
|
52
|
+
while (index < len) {
|
|
53
|
+
const char = header.charCodeAt(index);
|
|
54
|
+
if (char === SEMI)
|
|
55
|
+
continue parameter;
|
|
56
|
+
if (char === EQ) {
|
|
57
|
+
const keyEnd = trailingOWS(header, keyStart, index);
|
|
58
|
+
const key = header.slice(keyStart, keyEnd).toLowerCase();
|
|
59
|
+
index = skipOWS(header, index + 1, len);
|
|
60
|
+
if (index < len && header.charCodeAt(index) === DQUOTE) {
|
|
61
|
+
index++;
|
|
62
|
+
let value = '';
|
|
63
|
+
if (multipart) {
|
|
64
|
+
while (index < len) {
|
|
65
|
+
const code = header.charCodeAt(index++);
|
|
66
|
+
if (code === DQUOTE) {
|
|
67
|
+
index = parseToken(header, index, len);
|
|
68
|
+
if (parameters[key] === undefined)
|
|
69
|
+
parameters[key] = value;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
if (code === /* % */ 37 && index + 1 < len) {
|
|
73
|
+
const code2 = header.charCodeAt(index);
|
|
74
|
+
const code3 = header.charCodeAt(index + 1);
|
|
75
|
+
if (code2 === 50 /* "2" */ && code3 === 50 /* "2" */) {
|
|
76
|
+
value += '"';
|
|
77
|
+
index += 2;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (code2 === 48 /* "0" */) {
|
|
81
|
+
if (code3 === 100 /* "d" */ || code3 === 68 /* "D" */) {
|
|
82
|
+
value += '\r';
|
|
83
|
+
index += 2;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (code3 === 97 /* "a" */ || code3 === 65 /* "A" */) {
|
|
87
|
+
value += '\n';
|
|
88
|
+
index += 2;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
value += String.fromCharCode(code);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
while (index < len) {
|
|
98
|
+
const code = header.charCodeAt(index++);
|
|
99
|
+
if (code === DQUOTE) {
|
|
100
|
+
index = parseToken(header, index, len);
|
|
101
|
+
if (parameters[key] === undefined)
|
|
102
|
+
parameters[key] = value;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
if (code === BSLASH && index < len) {
|
|
106
|
+
value += header[index++];
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
value += String.fromCharCode(code);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
continue parameter;
|
|
113
|
+
}
|
|
114
|
+
const valueStart = index;
|
|
115
|
+
index = parseToken(header, index, len);
|
|
116
|
+
const valueEnd = trailingOWS(header, valueStart, index);
|
|
117
|
+
const value = header.slice(valueStart, valueEnd);
|
|
118
|
+
if (parameters[key] === undefined) {
|
|
119
|
+
parameters[key] = value;
|
|
120
|
+
if (extended && key.charCodeAt(key.length - 1) === ASTERISK) {
|
|
121
|
+
const normalizedKey = key.slice(0, -1);
|
|
122
|
+
const decoded = decodeExtended(value);
|
|
123
|
+
if (decoded !== undefined)
|
|
124
|
+
parameters[normalizedKey] = decoded;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
continue parameter;
|
|
128
|
+
}
|
|
129
|
+
index++;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return { type, parameters };
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* RegExp to match non attr-char, *after* encodeURIComponent (i.e. not including "%")
|
|
136
|
+
*/
|
|
137
|
+
const ENCODE_URL_ATTR_CHAR_REGEXP = /[\x00-\x20"'()*,/:;<=>?@[\\\]{}\x7f]/g; // eslint-disable-line no-control-regex
|
|
138
|
+
/**
|
|
139
|
+
* RegExp to match non-US-ASCII characters.
|
|
140
|
+
*/
|
|
141
|
+
const NON_ASCII_REGEXP = /[^\x20-\x7e]/g;
|
|
142
|
+
/**
|
|
143
|
+
* RegExp to match chars that must be quoted-pair in RFC 2616
|
|
144
|
+
*/
|
|
145
|
+
const QUOTE_REGEXP = /[\\"]/g;
|
|
146
|
+
/**
|
|
147
|
+
* Match chars that can't be used in the filename for compatibility.
|
|
148
|
+
*/
|
|
149
|
+
const INVALID_FILENAME_REGEXP = /%[0-9A-Fa-f]{2}/;
|
|
150
|
+
/**
|
|
151
|
+
* RegExp for various RFC 2616 grammar
|
|
152
|
+
*
|
|
153
|
+
* parameter = token "=" ( token | quoted-string )
|
|
154
|
+
* token = 1*<any CHAR except CTLs or separators>
|
|
155
|
+
* separators = "(" | ")" | "<" | ">" | "@"
|
|
156
|
+
* | "," | ";" | ":" | "\" | <">
|
|
157
|
+
* | "/" | "[" | "]" | "?" | "="
|
|
158
|
+
* | "{" | "}" | SP | HT
|
|
159
|
+
* quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )
|
|
160
|
+
* qdtext = <any TEXT except <">>
|
|
161
|
+
* quoted-pair = "\" CHAR
|
|
162
|
+
* CHAR = <any US-ASCII character (octets 0 - 127)>
|
|
163
|
+
* TEXT = <any OCTET except CTLs, but including LWS>
|
|
164
|
+
* LWS = [CRLF] 1*( SP | HT )
|
|
165
|
+
* CRLF = CR LF
|
|
166
|
+
* CR = <US-ASCII CR, carriage return (13)>
|
|
167
|
+
* LF = <US-ASCII LF, linefeed (10)>
|
|
168
|
+
* SP = <US-ASCII SP, space (32)>
|
|
169
|
+
* HT = <US-ASCII HT, horizontal-tab (9)>
|
|
170
|
+
* CTL = <any US-ASCII control character (octets 0 - 31) and DEL (127)>
|
|
171
|
+
* OCTET = <any 8-bit sequence of data>
|
|
172
|
+
*/
|
|
173
|
+
const TEXT_REGEXP = /^[\x20-\x7e\x80-\xff]*$/;
|
|
174
|
+
const ASCII_TEXT_REGEXP = /^[\x20-\x7e]*$/;
|
|
175
|
+
const TOKEN_REGEXP = /^[!#$%&'*+.0-9A-Z^_`a-z|~-]+$/;
|
|
176
|
+
/**
|
|
177
|
+
* Create parameters object from filename and fallback.
|
|
178
|
+
*/
|
|
179
|
+
function createParameters(filename, fallback = true) {
|
|
180
|
+
if (filename === undefined)
|
|
181
|
+
return;
|
|
182
|
+
if (typeof fallback === 'string') {
|
|
183
|
+
if (!ASCII_TEXT_REGEXP.test(fallback)) {
|
|
184
|
+
throw new TypeError('Fallback must be valid US-ASCII: ' + fallback);
|
|
185
|
+
}
|
|
186
|
+
if (fallback === filename)
|
|
187
|
+
return { filename };
|
|
188
|
+
return { filename: fallback, 'filename*': encodeExtended(filename) };
|
|
189
|
+
}
|
|
190
|
+
// Use `filename` when possible, otherwise use `filename*`.
|
|
191
|
+
if (ASCII_TEXT_REGEXP.test(filename) &&
|
|
192
|
+
!INVALID_FILENAME_REGEXP.test(filename)) {
|
|
193
|
+
return { filename };
|
|
194
|
+
}
|
|
195
|
+
if (fallback === false) {
|
|
196
|
+
return { 'filename*': encodeExtended(filename) };
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
filename: getAscii(filename),
|
|
200
|
+
'filename*': encodeExtended(filename),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Decode a RFC 8187 field value (gracefully).
|
|
205
|
+
*/
|
|
206
|
+
function decodeExtended(str) {
|
|
207
|
+
const charsetEnd = str.indexOf("'");
|
|
208
|
+
if (charsetEnd <= 0) {
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
const languageEnd = str.indexOf("'", charsetEnd + 1);
|
|
212
|
+
if (languageEnd === -1) {
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
const charset = str.slice(0, charsetEnd).toLowerCase();
|
|
216
|
+
const encoded = str.slice(languageEnd + 1);
|
|
217
|
+
switch (charset) {
|
|
218
|
+
case 'iso-8859-1': {
|
|
219
|
+
return decodeHexEscapes(encoded);
|
|
220
|
+
}
|
|
221
|
+
case 'utf-8':
|
|
222
|
+
case 'utf8': {
|
|
223
|
+
return tryDecodeURIComponent(encoded);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Decode URI component but return `undefined` on error.
|
|
230
|
+
*/
|
|
231
|
+
function tryDecodeURIComponent(str) {
|
|
232
|
+
try {
|
|
233
|
+
return decodeURIComponent(str);
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Parse a token starting at the provided index.
|
|
241
|
+
*/
|
|
242
|
+
function parseToken(str, index, len) {
|
|
243
|
+
while (index < len) {
|
|
244
|
+
const char = str.charCodeAt(index);
|
|
245
|
+
if (char === SEMI)
|
|
246
|
+
break;
|
|
247
|
+
index++;
|
|
248
|
+
}
|
|
249
|
+
return index;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Skip RFC 2616 linear whitespace (space / tab).
|
|
253
|
+
*/
|
|
254
|
+
function skipOWS(str, index, len) {
|
|
255
|
+
while (index < len) {
|
|
256
|
+
const char = str.charCodeAt(index);
|
|
257
|
+
if (char !== SP && char !== HTAB)
|
|
258
|
+
break;
|
|
259
|
+
index++;
|
|
260
|
+
}
|
|
261
|
+
return index;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Skip RFC 2616 linear whitespace (space / tab) from the end of a string.
|
|
265
|
+
*/
|
|
266
|
+
function trailingOWS(str, start, end) {
|
|
267
|
+
while (end > start) {
|
|
268
|
+
const char = str.charCodeAt(end - 1);
|
|
269
|
+
if (char !== SP && char !== HTAB)
|
|
270
|
+
break;
|
|
271
|
+
end--;
|
|
272
|
+
}
|
|
273
|
+
return end;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Format object to Content-Disposition header.
|
|
277
|
+
*/
|
|
278
|
+
function format(obj, options) {
|
|
279
|
+
const { type, parameters } = obj;
|
|
280
|
+
const multipart = options?.multipart === true;
|
|
281
|
+
const extended = options?.extended !== false;
|
|
282
|
+
if (!type || !TOKEN_REGEXP.test(type)) {
|
|
283
|
+
throw new TypeError('Invalid type: ' + type);
|
|
284
|
+
}
|
|
285
|
+
let result = type;
|
|
286
|
+
if (parameters) {
|
|
287
|
+
for (const param of Object.keys(parameters)) {
|
|
288
|
+
const value = parameters[param];
|
|
289
|
+
if (!TOKEN_REGEXP.test(param)) {
|
|
290
|
+
throw new TypeError('Invalid parameter name: ' + param);
|
|
291
|
+
}
|
|
292
|
+
if (multipart) {
|
|
293
|
+
result += '; ' + param + '=' + qmultipart(value);
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
if (TOKEN_REGEXP.test(value)) {
|
|
297
|
+
result += '; ' + param + '=' + value;
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
if (TEXT_REGEXP.test(value)) {
|
|
301
|
+
result += '; ' + param + '=' + qstring(value);
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (!extended) {
|
|
305
|
+
throw new TypeError('Invalid parameter value: ' + value);
|
|
306
|
+
}
|
|
307
|
+
result += '; ' + param + '*=' + encodeExtended(value);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return result;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Get US-ASCII version of string.
|
|
314
|
+
*/
|
|
315
|
+
function getAscii(val) {
|
|
316
|
+
// simple Unicode -> US-ASCII transformation
|
|
317
|
+
return val.replace(NON_ASCII_REGEXP, '?');
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Percent encode a single character.
|
|
321
|
+
*/
|
|
322
|
+
function pencode(char) {
|
|
323
|
+
return '%' + char.charCodeAt(0).toString(16).toUpperCase();
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Quote a string for HTTP.
|
|
327
|
+
*/
|
|
328
|
+
function qstring(str) {
|
|
329
|
+
return '"' + str.replace(QUOTE_REGEXP, '\\$&') + '"';
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Quote a string for multipart/form-data.
|
|
333
|
+
*
|
|
334
|
+
* @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data
|
|
335
|
+
*/
|
|
336
|
+
function qmultipart(str) {
|
|
337
|
+
return '"' + str.replace(/[\n\r"]/g, multipartEscape) + '"';
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Escape a multipart/form-data string character.
|
|
341
|
+
*/
|
|
342
|
+
function multipartEscape(char) {
|
|
343
|
+
if (char === '\n')
|
|
344
|
+
return '%0A';
|
|
345
|
+
if (char === '\r')
|
|
346
|
+
return '%0D';
|
|
347
|
+
return '%22';
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Encode a Unicode string for HTTP (RFC 8187).
|
|
351
|
+
*/
|
|
352
|
+
function encodeExtended(str) {
|
|
353
|
+
const encoded = encodeURIComponent(str).replace(ENCODE_URL_ATTR_CHAR_REGEXP, pencode);
|
|
354
|
+
return "UTF-8''" + encoded;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Check if a character is a hex digit [0-9A-Fa-f]
|
|
358
|
+
*/
|
|
359
|
+
function isHexDigit(char) {
|
|
360
|
+
const code = char.charCodeAt(0);
|
|
361
|
+
return ((code >= 48 && code <= 57) || // 0-9
|
|
362
|
+
(code >= 65 && code <= 70) || // A-F
|
|
363
|
+
(code >= 97 && code <= 102) // a-f
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Decode hex escapes in a string (e.g., %20 -> space)
|
|
368
|
+
*/
|
|
369
|
+
function decodeHexEscapes(str) {
|
|
370
|
+
const firstEscape = str.indexOf('%');
|
|
371
|
+
if (firstEscape === -1)
|
|
372
|
+
return str;
|
|
373
|
+
let result = str.slice(0, firstEscape);
|
|
374
|
+
for (let idx = firstEscape; idx < str.length; idx++) {
|
|
375
|
+
if (str[idx] === '%' &&
|
|
376
|
+
idx + 2 < str.length &&
|
|
377
|
+
isHexDigit(str[idx + 1]) &&
|
|
378
|
+
isHexDigit(str[idx + 2])) {
|
|
379
|
+
result += String.fromCharCode(Number.parseInt(str[idx + 1] + str[idx + 2], 16));
|
|
380
|
+
idx += 2;
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
result += str[idx];
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return result;
|
|
387
|
+
}
|
|
388
|
+
//# sourceMappingURL=index.js.map
|