jitsu-cli 2.14.0-beta.8 → 2.14.0-beta.85
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/bin/jitsu +3 -0
- package/build.mts +39 -0
- package/compiled/package.json +16 -22
- package/compiled/src/commands/build.js +16 -24
- package/compiled/src/commands/config/handlers.js +292 -0
- package/compiled/src/commands/config/index.js +148 -0
- package/compiled/src/commands/config/resources.js +88 -0
- package/compiled/src/commands/default-workspace.js +39 -0
- package/compiled/src/commands/deploy.js +3 -4
- package/compiled/src/commands/spec.js +31 -0
- package/compiled/src/index.js +21 -2
- package/compiled/src/lib/api-client.js +52 -0
- package/compiled/src/lib/auth-file.js +67 -0
- package/compiled/src/lib/body-builder.js +53 -0
- package/compiled/src/lib/body-fields.js +47 -0
- package/compiled/src/lib/compiled-function.js +23 -21
- package/compiled/src/lib/dotted.js +34 -0
- package/compiled/src/lib/renderer.js +33 -0
- package/compiled/src/lib/spec.js +11 -0
- package/dist/main.js +46358 -92868
- package/dist/main.js.map +7 -1
- package/package.json +16 -22
- package/src/commands/build.ts +21 -26
- package/src/commands/config/handlers.ts +339 -0
- package/src/commands/config/index.ts +171 -0
- package/src/commands/config/resources.ts +110 -0
- package/src/commands/default-workspace.ts +44 -0
- package/src/commands/deploy.ts +3 -2
- package/src/commands/spec.ts +32 -0
- package/src/index.ts +34 -17
- package/src/lib/api-client.ts +64 -0
- package/src/lib/auth-file.ts +83 -0
- package/src/lib/body-builder.ts +68 -0
- package/src/lib/body-fields.ts +61 -0
- package/src/lib/compiled-function.ts +30 -23
- package/src/lib/dotted.ts +43 -0
- package/src/lib/renderer.ts +44 -0
- package/src/lib/spec.ts +32 -0
- package/dist/140.js +0 -452
- package/dist/140.js.map +0 -1
- package/webpack.config.cjs +0 -53
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Parse a value string from a dotted-path flag.
|
|
2
|
+
// Heuristic: if it parses cleanly as JSON and starts with `[`, `{`, `"`, or is a
|
|
3
|
+
// number/boolean/null literal, take the JSON value. Otherwise treat as a plain string.
|
|
4
|
+
// This lets users pass arrays/objects without quoting hell while keeping bare strings
|
|
5
|
+
// (`--name=foo`) working without quoting them as `"foo"`.
|
|
6
|
+
export function parseScalar(raw: string): unknown {
|
|
7
|
+
if (raw === "") return "";
|
|
8
|
+
const trimmed = raw.trim();
|
|
9
|
+
const first = trimmed[0];
|
|
10
|
+
const looksLikeJson =
|
|
11
|
+
first === "{" ||
|
|
12
|
+
first === "[" ||
|
|
13
|
+
first === '"' ||
|
|
14
|
+
trimmed === "true" ||
|
|
15
|
+
trimmed === "false" ||
|
|
16
|
+
trimmed === "null" ||
|
|
17
|
+
/^-?\d/.test(trimmed);
|
|
18
|
+
if (looksLikeJson) {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(trimmed);
|
|
21
|
+
} catch {
|
|
22
|
+
// fall through to string
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return raw;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Build an object by setting `path` (e.g. "credentials.password") to `value`.
|
|
29
|
+
// Numeric path segments (`a.0.b`) are NOT special — kept as object keys. If you
|
|
30
|
+
// need arrays, pass them as JSON values (e.g. --keys='["a","b"]').
|
|
31
|
+
export function setDottedPath(target: any, path: string, value: unknown): any {
|
|
32
|
+
const parts = path.split(".");
|
|
33
|
+
let node = target;
|
|
34
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
35
|
+
const key = parts[i];
|
|
36
|
+
if (node[key] == null || typeof node[key] !== "object" || Array.isArray(node[key])) {
|
|
37
|
+
node[key] = {};
|
|
38
|
+
}
|
|
39
|
+
node = node[key];
|
|
40
|
+
}
|
|
41
|
+
node[parts[parts.length - 1]] = value;
|
|
42
|
+
return target;
|
|
43
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import yaml from "js-yaml";
|
|
2
|
+
|
|
3
|
+
export interface Renderer {
|
|
4
|
+
format: string;
|
|
5
|
+
render(value: unknown): string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const renderers: Record<string, Renderer> = {
|
|
9
|
+
yaml: {
|
|
10
|
+
format: "yaml",
|
|
11
|
+
render(value) {
|
|
12
|
+
if (value === undefined) return "";
|
|
13
|
+
// skipInvalid drops things like undefined/functions silently.
|
|
14
|
+
// noRefs avoids YAML anchors (`&id001`) which confuse readers and most YAML consumers.
|
|
15
|
+
return yaml.dump(value, { skipInvalid: true, noRefs: true, sortKeys: false, lineWidth: 120 });
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
json: {
|
|
19
|
+
format: "json",
|
|
20
|
+
render(value) {
|
|
21
|
+
return JSON.stringify(value, null, 2) + "\n";
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const SUPPORTED_OUTPUTS = Object.keys(renderers);
|
|
27
|
+
export const DEFAULT_OUTPUT = "yaml";
|
|
28
|
+
|
|
29
|
+
export function getRenderer(format?: string): Renderer {
|
|
30
|
+
const key = (format ?? DEFAULT_OUTPUT).toLowerCase();
|
|
31
|
+
const r = renderers[key];
|
|
32
|
+
if (!r) {
|
|
33
|
+
throw new Error(`Unsupported output format '${format}'. Supported: ${SUPPORTED_OUTPUTS.join(", ")}`);
|
|
34
|
+
}
|
|
35
|
+
return r;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function registerRenderer(r: Renderer) {
|
|
39
|
+
renderers[r.format.toLowerCase()] = r;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function print(value: unknown, format?: string) {
|
|
43
|
+
process.stdout.write(getRenderer(format).render(value));
|
|
44
|
+
}
|
package/src/lib/spec.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ApiClient } from "./api-client";
|
|
2
|
+
import { AuthInfo } from "./auth-file";
|
|
3
|
+
|
|
4
|
+
// Minimal subset of OpenAPI 3 we use. Avoids a runtime dep on openapi-types.
|
|
5
|
+
export type OpenApiSpec = {
|
|
6
|
+
openapi?: string;
|
|
7
|
+
info?: { title?: string; version?: string; description?: string };
|
|
8
|
+
paths?: Record<string, Record<string, OpenApiOperation>>;
|
|
9
|
+
components?: { schemas?: Record<string, any> };
|
|
10
|
+
};
|
|
11
|
+
export type OpenApiOperation = {
|
|
12
|
+
summary?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
tags?: string[];
|
|
15
|
+
parameters?: any[];
|
|
16
|
+
requestBody?: any;
|
|
17
|
+
responses?: Record<string, any>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export async function fetchSpec(auth: AuthInfo): Promise<OpenApiSpec> {
|
|
21
|
+
// /api/spec is public — no auth required, but reusing the client keeps host handling consistent.
|
|
22
|
+
const client = new ApiClient(auth);
|
|
23
|
+
return client.request<OpenApiSpec>({ method: "GET", path: "/api/spec" });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Resolves the operation that matches a (templated) path + method, e.g.
|
|
27
|
+
// ("/api/{workspaceId}/config/{type}", "post") → operation node with summary/description.
|
|
28
|
+
export function findOperation(spec: OpenApiSpec, path: string, method: string): OpenApiOperation | undefined {
|
|
29
|
+
const item = spec.paths?.[path];
|
|
30
|
+
if (!item) return undefined;
|
|
31
|
+
return item[method.toLowerCase()];
|
|
32
|
+
}
|
package/dist/140.js
DELETED
|
@@ -1,452 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
exports.id = 140;
|
|
3
|
-
exports.ids = [140];
|
|
4
|
-
exports.modules = {
|
|
5
|
-
|
|
6
|
-
/***/ 77140:
|
|
7
|
-
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
8
|
-
|
|
9
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
10
|
-
/* harmony export */ toFormData: () => (/* binding */ toFormData)
|
|
11
|
-
/* harmony export */ });
|
|
12
|
-
/* harmony import */ var fetch_blob_from_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(49605);
|
|
13
|
-
/* harmony import */ var formdata_polyfill_esm_min_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(14055);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
let s = 0;
|
|
18
|
-
const S = {
|
|
19
|
-
START_BOUNDARY: s++,
|
|
20
|
-
HEADER_FIELD_START: s++,
|
|
21
|
-
HEADER_FIELD: s++,
|
|
22
|
-
HEADER_VALUE_START: s++,
|
|
23
|
-
HEADER_VALUE: s++,
|
|
24
|
-
HEADER_VALUE_ALMOST_DONE: s++,
|
|
25
|
-
HEADERS_ALMOST_DONE: s++,
|
|
26
|
-
PART_DATA_START: s++,
|
|
27
|
-
PART_DATA: s++,
|
|
28
|
-
END: s++
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
let f = 1;
|
|
32
|
-
const F = {
|
|
33
|
-
PART_BOUNDARY: f,
|
|
34
|
-
LAST_BOUNDARY: f *= 2
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const LF = 10;
|
|
38
|
-
const CR = 13;
|
|
39
|
-
const SPACE = 32;
|
|
40
|
-
const HYPHEN = 45;
|
|
41
|
-
const COLON = 58;
|
|
42
|
-
const A = 97;
|
|
43
|
-
const Z = 122;
|
|
44
|
-
|
|
45
|
-
const lower = c => c | 0x20;
|
|
46
|
-
|
|
47
|
-
const noop = () => {};
|
|
48
|
-
|
|
49
|
-
class MultipartParser {
|
|
50
|
-
/**
|
|
51
|
-
* @param {string} boundary
|
|
52
|
-
*/
|
|
53
|
-
constructor(boundary) {
|
|
54
|
-
this.index = 0;
|
|
55
|
-
this.flags = 0;
|
|
56
|
-
|
|
57
|
-
this.onHeaderEnd = noop;
|
|
58
|
-
this.onHeaderField = noop;
|
|
59
|
-
this.onHeadersEnd = noop;
|
|
60
|
-
this.onHeaderValue = noop;
|
|
61
|
-
this.onPartBegin = noop;
|
|
62
|
-
this.onPartData = noop;
|
|
63
|
-
this.onPartEnd = noop;
|
|
64
|
-
|
|
65
|
-
this.boundaryChars = {};
|
|
66
|
-
|
|
67
|
-
boundary = '\r\n--' + boundary;
|
|
68
|
-
const ui8a = new Uint8Array(boundary.length);
|
|
69
|
-
for (let i = 0; i < boundary.length; i++) {
|
|
70
|
-
ui8a[i] = boundary.charCodeAt(i);
|
|
71
|
-
this.boundaryChars[ui8a[i]] = true;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
this.boundary = ui8a;
|
|
75
|
-
this.lookbehind = new Uint8Array(this.boundary.length + 8);
|
|
76
|
-
this.state = S.START_BOUNDARY;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @param {Uint8Array} data
|
|
81
|
-
*/
|
|
82
|
-
write(data) {
|
|
83
|
-
let i = 0;
|
|
84
|
-
const length_ = data.length;
|
|
85
|
-
let previousIndex = this.index;
|
|
86
|
-
let {lookbehind, boundary, boundaryChars, index, state, flags} = this;
|
|
87
|
-
const boundaryLength = this.boundary.length;
|
|
88
|
-
const boundaryEnd = boundaryLength - 1;
|
|
89
|
-
const bufferLength = data.length;
|
|
90
|
-
let c;
|
|
91
|
-
let cl;
|
|
92
|
-
|
|
93
|
-
const mark = name => {
|
|
94
|
-
this[name + 'Mark'] = i;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const clear = name => {
|
|
98
|
-
delete this[name + 'Mark'];
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const callback = (callbackSymbol, start, end, ui8a) => {
|
|
102
|
-
if (start === undefined || start !== end) {
|
|
103
|
-
this[callbackSymbol](ui8a && ui8a.subarray(start, end));
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const dataCallback = (name, clear) => {
|
|
108
|
-
const markSymbol = name + 'Mark';
|
|
109
|
-
if (!(markSymbol in this)) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (clear) {
|
|
114
|
-
callback(name, this[markSymbol], i, data);
|
|
115
|
-
delete this[markSymbol];
|
|
116
|
-
} else {
|
|
117
|
-
callback(name, this[markSymbol], data.length, data);
|
|
118
|
-
this[markSymbol] = 0;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
for (i = 0; i < length_; i++) {
|
|
123
|
-
c = data[i];
|
|
124
|
-
|
|
125
|
-
switch (state) {
|
|
126
|
-
case S.START_BOUNDARY:
|
|
127
|
-
if (index === boundary.length - 2) {
|
|
128
|
-
if (c === HYPHEN) {
|
|
129
|
-
flags |= F.LAST_BOUNDARY;
|
|
130
|
-
} else if (c !== CR) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
index++;
|
|
135
|
-
break;
|
|
136
|
-
} else if (index - 1 === boundary.length - 2) {
|
|
137
|
-
if (flags & F.LAST_BOUNDARY && c === HYPHEN) {
|
|
138
|
-
state = S.END;
|
|
139
|
-
flags = 0;
|
|
140
|
-
} else if (!(flags & F.LAST_BOUNDARY) && c === LF) {
|
|
141
|
-
index = 0;
|
|
142
|
-
callback('onPartBegin');
|
|
143
|
-
state = S.HEADER_FIELD_START;
|
|
144
|
-
} else {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (c !== boundary[index + 2]) {
|
|
152
|
-
index = -2;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (c === boundary[index + 2]) {
|
|
156
|
-
index++;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
break;
|
|
160
|
-
case S.HEADER_FIELD_START:
|
|
161
|
-
state = S.HEADER_FIELD;
|
|
162
|
-
mark('onHeaderField');
|
|
163
|
-
index = 0;
|
|
164
|
-
// falls through
|
|
165
|
-
case S.HEADER_FIELD:
|
|
166
|
-
if (c === CR) {
|
|
167
|
-
clear('onHeaderField');
|
|
168
|
-
state = S.HEADERS_ALMOST_DONE;
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
index++;
|
|
173
|
-
if (c === HYPHEN) {
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (c === COLON) {
|
|
178
|
-
if (index === 1) {
|
|
179
|
-
// empty header field
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
dataCallback('onHeaderField', true);
|
|
184
|
-
state = S.HEADER_VALUE_START;
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
cl = lower(c);
|
|
189
|
-
if (cl < A || cl > Z) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
break;
|
|
194
|
-
case S.HEADER_VALUE_START:
|
|
195
|
-
if (c === SPACE) {
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
mark('onHeaderValue');
|
|
200
|
-
state = S.HEADER_VALUE;
|
|
201
|
-
// falls through
|
|
202
|
-
case S.HEADER_VALUE:
|
|
203
|
-
if (c === CR) {
|
|
204
|
-
dataCallback('onHeaderValue', true);
|
|
205
|
-
callback('onHeaderEnd');
|
|
206
|
-
state = S.HEADER_VALUE_ALMOST_DONE;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
break;
|
|
210
|
-
case S.HEADER_VALUE_ALMOST_DONE:
|
|
211
|
-
if (c !== LF) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
state = S.HEADER_FIELD_START;
|
|
216
|
-
break;
|
|
217
|
-
case S.HEADERS_ALMOST_DONE:
|
|
218
|
-
if (c !== LF) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
callback('onHeadersEnd');
|
|
223
|
-
state = S.PART_DATA_START;
|
|
224
|
-
break;
|
|
225
|
-
case S.PART_DATA_START:
|
|
226
|
-
state = S.PART_DATA;
|
|
227
|
-
mark('onPartData');
|
|
228
|
-
// falls through
|
|
229
|
-
case S.PART_DATA:
|
|
230
|
-
previousIndex = index;
|
|
231
|
-
|
|
232
|
-
if (index === 0) {
|
|
233
|
-
// boyer-moore derrived algorithm to safely skip non-boundary data
|
|
234
|
-
i += boundaryEnd;
|
|
235
|
-
while (i < bufferLength && !(data[i] in boundaryChars)) {
|
|
236
|
-
i += boundaryLength;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
i -= boundaryEnd;
|
|
240
|
-
c = data[i];
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (index < boundary.length) {
|
|
244
|
-
if (boundary[index] === c) {
|
|
245
|
-
if (index === 0) {
|
|
246
|
-
dataCallback('onPartData', true);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
index++;
|
|
250
|
-
} else {
|
|
251
|
-
index = 0;
|
|
252
|
-
}
|
|
253
|
-
} else if (index === boundary.length) {
|
|
254
|
-
index++;
|
|
255
|
-
if (c === CR) {
|
|
256
|
-
// CR = part boundary
|
|
257
|
-
flags |= F.PART_BOUNDARY;
|
|
258
|
-
} else if (c === HYPHEN) {
|
|
259
|
-
// HYPHEN = end boundary
|
|
260
|
-
flags |= F.LAST_BOUNDARY;
|
|
261
|
-
} else {
|
|
262
|
-
index = 0;
|
|
263
|
-
}
|
|
264
|
-
} else if (index - 1 === boundary.length) {
|
|
265
|
-
if (flags & F.PART_BOUNDARY) {
|
|
266
|
-
index = 0;
|
|
267
|
-
if (c === LF) {
|
|
268
|
-
// unset the PART_BOUNDARY flag
|
|
269
|
-
flags &= ~F.PART_BOUNDARY;
|
|
270
|
-
callback('onPartEnd');
|
|
271
|
-
callback('onPartBegin');
|
|
272
|
-
state = S.HEADER_FIELD_START;
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
} else if (flags & F.LAST_BOUNDARY) {
|
|
276
|
-
if (c === HYPHEN) {
|
|
277
|
-
callback('onPartEnd');
|
|
278
|
-
state = S.END;
|
|
279
|
-
flags = 0;
|
|
280
|
-
} else {
|
|
281
|
-
index = 0;
|
|
282
|
-
}
|
|
283
|
-
} else {
|
|
284
|
-
index = 0;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (index > 0) {
|
|
289
|
-
// when matching a possible boundary, keep a lookbehind reference
|
|
290
|
-
// in case it turns out to be a false lead
|
|
291
|
-
lookbehind[index - 1] = c;
|
|
292
|
-
} else if (previousIndex > 0) {
|
|
293
|
-
// if our boundary turned out to be rubbish, the captured lookbehind
|
|
294
|
-
// belongs to partData
|
|
295
|
-
const _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);
|
|
296
|
-
callback('onPartData', 0, previousIndex, _lookbehind);
|
|
297
|
-
previousIndex = 0;
|
|
298
|
-
mark('onPartData');
|
|
299
|
-
|
|
300
|
-
// reconsider the current character even so it interrupted the sequence
|
|
301
|
-
// it could be the beginning of a new sequence
|
|
302
|
-
i--;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
break;
|
|
306
|
-
case S.END:
|
|
307
|
-
break;
|
|
308
|
-
default:
|
|
309
|
-
throw new Error(`Unexpected state entered: ${state}`);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
dataCallback('onHeaderField');
|
|
314
|
-
dataCallback('onHeaderValue');
|
|
315
|
-
dataCallback('onPartData');
|
|
316
|
-
|
|
317
|
-
// Update properties for the next call
|
|
318
|
-
this.index = index;
|
|
319
|
-
this.state = state;
|
|
320
|
-
this.flags = flags;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
end() {
|
|
324
|
-
if ((this.state === S.HEADER_FIELD_START && this.index === 0) ||
|
|
325
|
-
(this.state === S.PART_DATA && this.index === this.boundary.length)) {
|
|
326
|
-
this.onPartEnd();
|
|
327
|
-
} else if (this.state !== S.END) {
|
|
328
|
-
throw new Error('MultipartParser.end(): stream ended unexpectedly');
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
function _fileName(headerValue) {
|
|
334
|
-
// matches either a quoted-string or a token (RFC 2616 section 19.5.1)
|
|
335
|
-
const m = headerValue.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);
|
|
336
|
-
if (!m) {
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
const match = m[2] || m[3] || '';
|
|
341
|
-
let filename = match.slice(match.lastIndexOf('\\') + 1);
|
|
342
|
-
filename = filename.replace(/%22/g, '"');
|
|
343
|
-
filename = filename.replace(/&#(\d{4});/g, (m, code) => {
|
|
344
|
-
return String.fromCharCode(code);
|
|
345
|
-
});
|
|
346
|
-
return filename;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
async function toFormData(Body, ct) {
|
|
350
|
-
if (!/multipart/i.test(ct)) {
|
|
351
|
-
throw new TypeError('Failed to fetch');
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
const m = ct.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
|
|
355
|
-
|
|
356
|
-
if (!m) {
|
|
357
|
-
throw new TypeError('no or bad content-type header, no multipart boundary');
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
const parser = new MultipartParser(m[1] || m[2]);
|
|
361
|
-
|
|
362
|
-
let headerField;
|
|
363
|
-
let headerValue;
|
|
364
|
-
let entryValue;
|
|
365
|
-
let entryName;
|
|
366
|
-
let contentType;
|
|
367
|
-
let filename;
|
|
368
|
-
const entryChunks = [];
|
|
369
|
-
const formData = new formdata_polyfill_esm_min_js__WEBPACK_IMPORTED_MODULE_1__/* .FormData */ .fS();
|
|
370
|
-
|
|
371
|
-
const onPartData = ui8a => {
|
|
372
|
-
entryValue += decoder.decode(ui8a, {stream: true});
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
const appendToFile = ui8a => {
|
|
376
|
-
entryChunks.push(ui8a);
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
const appendFileToFormData = () => {
|
|
380
|
-
const file = new fetch_blob_from_js__WEBPACK_IMPORTED_MODULE_0__/* .File */ .ZH(entryChunks, filename, {type: contentType});
|
|
381
|
-
formData.append(entryName, file);
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
const appendEntryToFormData = () => {
|
|
385
|
-
formData.append(entryName, entryValue);
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
const decoder = new TextDecoder('utf-8');
|
|
389
|
-
decoder.decode();
|
|
390
|
-
|
|
391
|
-
parser.onPartBegin = function () {
|
|
392
|
-
parser.onPartData = onPartData;
|
|
393
|
-
parser.onPartEnd = appendEntryToFormData;
|
|
394
|
-
|
|
395
|
-
headerField = '';
|
|
396
|
-
headerValue = '';
|
|
397
|
-
entryValue = '';
|
|
398
|
-
entryName = '';
|
|
399
|
-
contentType = '';
|
|
400
|
-
filename = null;
|
|
401
|
-
entryChunks.length = 0;
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
parser.onHeaderField = function (ui8a) {
|
|
405
|
-
headerField += decoder.decode(ui8a, {stream: true});
|
|
406
|
-
};
|
|
407
|
-
|
|
408
|
-
parser.onHeaderValue = function (ui8a) {
|
|
409
|
-
headerValue += decoder.decode(ui8a, {stream: true});
|
|
410
|
-
};
|
|
411
|
-
|
|
412
|
-
parser.onHeaderEnd = function () {
|
|
413
|
-
headerValue += decoder.decode();
|
|
414
|
-
headerField = headerField.toLowerCase();
|
|
415
|
-
|
|
416
|
-
if (headerField === 'content-disposition') {
|
|
417
|
-
// matches either a quoted-string or a token (RFC 2616 section 19.5.1)
|
|
418
|
-
const m = headerValue.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);
|
|
419
|
-
|
|
420
|
-
if (m) {
|
|
421
|
-
entryName = m[2] || m[3] || '';
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
filename = _fileName(headerValue);
|
|
425
|
-
|
|
426
|
-
if (filename) {
|
|
427
|
-
parser.onPartData = appendToFile;
|
|
428
|
-
parser.onPartEnd = appendFileToFormData;
|
|
429
|
-
}
|
|
430
|
-
} else if (headerField === 'content-type') {
|
|
431
|
-
contentType = headerValue;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
headerValue = '';
|
|
435
|
-
headerField = '';
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
for await (const chunk of Body) {
|
|
439
|
-
parser.write(chunk);
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
parser.end();
|
|
443
|
-
|
|
444
|
-
return formData;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
/***/ })
|
|
449
|
-
|
|
450
|
-
};
|
|
451
|
-
;
|
|
452
|
-
//# sourceMappingURL=140.js.map
|
package/dist/140.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"140.js","mappings":";;;;;;;;;;;;;AAAwC;AACc;;AAEtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA,YAAY,QAAQ;AACpB;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,kBAAkB,qBAAqB;AACvC;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,YAAY,YAAY;AACxB;AACA;AACA;AACA;AACA;AACA,OAAO,0DAA0D;AACjE;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;;AAEA,cAAc,aAAa;AAC3B;;AAEA;AACA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;;AAEA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA,QAAQ;AACR;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA,QAAQ;AACR;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA,QAAQ;AACR;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA,QAAQ;AACR;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,kDAAkD,MAAM;AACxD;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;;AAEA;AACA;AACA,4DAA4D,YAAY,YAAY;AACpF;AACA;AACA;;AAEA;AACA;AACA;AACA,oCAAoC,EAAE,EAAE;AACxC;AACA,EAAE;AACF;AACA;;AAEO;AACP;AACA;AACA;;AAEA,+CAA+C;;AAE/C;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,4EAAQ;;AAE9B;AACA,sCAAsC,aAAa;AACnD;;AAEA;AACA;AACA;;AAEA;AACA,mBAAmB,8DAAI,yBAAyB,kBAAkB;AAClE;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,uCAAuC,aAAa;AACpD;;AAEA;AACA,uCAAuC,aAAa;AACpD;;AAEA;AACA;AACA;;AAEA;AACA;AACA,4DAA4D,YAAY;;AAExE;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA","sources":["webpack://jitsu-cli/../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/utils/multipart-parser.js"],"sourcesContent":["import {File} from 'fetch-blob/from.js';\nimport {FormData} from 'formdata-polyfill/esm.min.js';\n\nlet s = 0;\nconst S = {\n\tSTART_BOUNDARY: s++,\n\tHEADER_FIELD_START: s++,\n\tHEADER_FIELD: s++,\n\tHEADER_VALUE_START: s++,\n\tHEADER_VALUE: s++,\n\tHEADER_VALUE_ALMOST_DONE: s++,\n\tHEADERS_ALMOST_DONE: s++,\n\tPART_DATA_START: s++,\n\tPART_DATA: s++,\n\tEND: s++\n};\n\nlet f = 1;\nconst F = {\n\tPART_BOUNDARY: f,\n\tLAST_BOUNDARY: f *= 2\n};\n\nconst LF = 10;\nconst CR = 13;\nconst SPACE = 32;\nconst HYPHEN = 45;\nconst COLON = 58;\nconst A = 97;\nconst Z = 122;\n\nconst lower = c => c | 0x20;\n\nconst noop = () => {};\n\nclass MultipartParser {\n\t/**\n\t * @param {string} boundary\n\t */\n\tconstructor(boundary) {\n\t\tthis.index = 0;\n\t\tthis.flags = 0;\n\n\t\tthis.onHeaderEnd = noop;\n\t\tthis.onHeaderField = noop;\n\t\tthis.onHeadersEnd = noop;\n\t\tthis.onHeaderValue = noop;\n\t\tthis.onPartBegin = noop;\n\t\tthis.onPartData = noop;\n\t\tthis.onPartEnd = noop;\n\n\t\tthis.boundaryChars = {};\n\n\t\tboundary = '\\r\\n--' + boundary;\n\t\tconst ui8a = new Uint8Array(boundary.length);\n\t\tfor (let i = 0; i < boundary.length; i++) {\n\t\t\tui8a[i] = boundary.charCodeAt(i);\n\t\t\tthis.boundaryChars[ui8a[i]] = true;\n\t\t}\n\n\t\tthis.boundary = ui8a;\n\t\tthis.lookbehind = new Uint8Array(this.boundary.length + 8);\n\t\tthis.state = S.START_BOUNDARY;\n\t}\n\n\t/**\n\t * @param {Uint8Array} data\n\t */\n\twrite(data) {\n\t\tlet i = 0;\n\t\tconst length_ = data.length;\n\t\tlet previousIndex = this.index;\n\t\tlet {lookbehind, boundary, boundaryChars, index, state, flags} = this;\n\t\tconst boundaryLength = this.boundary.length;\n\t\tconst boundaryEnd = boundaryLength - 1;\n\t\tconst bufferLength = data.length;\n\t\tlet c;\n\t\tlet cl;\n\n\t\tconst mark = name => {\n\t\t\tthis[name + 'Mark'] = i;\n\t\t};\n\n\t\tconst clear = name => {\n\t\t\tdelete this[name + 'Mark'];\n\t\t};\n\n\t\tconst callback = (callbackSymbol, start, end, ui8a) => {\n\t\t\tif (start === undefined || start !== end) {\n\t\t\t\tthis[callbackSymbol](ui8a && ui8a.subarray(start, end));\n\t\t\t}\n\t\t};\n\n\t\tconst dataCallback = (name, clear) => {\n\t\t\tconst markSymbol = name + 'Mark';\n\t\t\tif (!(markSymbol in this)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (clear) {\n\t\t\t\tcallback(name, this[markSymbol], i, data);\n\t\t\t\tdelete this[markSymbol];\n\t\t\t} else {\n\t\t\t\tcallback(name, this[markSymbol], data.length, data);\n\t\t\t\tthis[markSymbol] = 0;\n\t\t\t}\n\t\t};\n\n\t\tfor (i = 0; i < length_; i++) {\n\t\t\tc = data[i];\n\n\t\t\tswitch (state) {\n\t\t\t\tcase S.START_BOUNDARY:\n\t\t\t\t\tif (index === boundary.length - 2) {\n\t\t\t\t\t\tif (c === HYPHEN) {\n\t\t\t\t\t\t\tflags |= F.LAST_BOUNDARY;\n\t\t\t\t\t\t} else if (c !== CR) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tindex++;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} else if (index - 1 === boundary.length - 2) {\n\t\t\t\t\t\tif (flags & F.LAST_BOUNDARY && c === HYPHEN) {\n\t\t\t\t\t\t\tstate = S.END;\n\t\t\t\t\t\t\tflags = 0;\n\t\t\t\t\t\t} else if (!(flags & F.LAST_BOUNDARY) && c === LF) {\n\t\t\t\t\t\t\tindex = 0;\n\t\t\t\t\t\t\tcallback('onPartBegin');\n\t\t\t\t\t\t\tstate = S.HEADER_FIELD_START;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (c !== boundary[index + 2]) {\n\t\t\t\t\t\tindex = -2;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (c === boundary[index + 2]) {\n\t\t\t\t\t\tindex++;\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\tcase S.HEADER_FIELD_START:\n\t\t\t\t\tstate = S.HEADER_FIELD;\n\t\t\t\t\tmark('onHeaderField');\n\t\t\t\t\tindex = 0;\n\t\t\t\t\t// falls through\n\t\t\t\tcase S.HEADER_FIELD:\n\t\t\t\t\tif (c === CR) {\n\t\t\t\t\t\tclear('onHeaderField');\n\t\t\t\t\t\tstate = S.HEADERS_ALMOST_DONE;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tindex++;\n\t\t\t\t\tif (c === HYPHEN) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (c === COLON) {\n\t\t\t\t\t\tif (index === 1) {\n\t\t\t\t\t\t\t// empty header field\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tdataCallback('onHeaderField', true);\n\t\t\t\t\t\tstate = S.HEADER_VALUE_START;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcl = lower(c);\n\t\t\t\t\tif (cl < A || cl > Z) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\tcase S.HEADER_VALUE_START:\n\t\t\t\t\tif (c === SPACE) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tmark('onHeaderValue');\n\t\t\t\t\tstate = S.HEADER_VALUE;\n\t\t\t\t\t// falls through\n\t\t\t\tcase S.HEADER_VALUE:\n\t\t\t\t\tif (c === CR) {\n\t\t\t\t\t\tdataCallback('onHeaderValue', true);\n\t\t\t\t\t\tcallback('onHeaderEnd');\n\t\t\t\t\t\tstate = S.HEADER_VALUE_ALMOST_DONE;\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\tcase S.HEADER_VALUE_ALMOST_DONE:\n\t\t\t\t\tif (c !== LF) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tstate = S.HEADER_FIELD_START;\n\t\t\t\t\tbreak;\n\t\t\t\tcase S.HEADERS_ALMOST_DONE:\n\t\t\t\t\tif (c !== LF) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tcallback('onHeadersEnd');\n\t\t\t\t\tstate = S.PART_DATA_START;\n\t\t\t\t\tbreak;\n\t\t\t\tcase S.PART_DATA_START:\n\t\t\t\t\tstate = S.PART_DATA;\n\t\t\t\t\tmark('onPartData');\n\t\t\t\t\t// falls through\n\t\t\t\tcase S.PART_DATA:\n\t\t\t\t\tpreviousIndex = index;\n\n\t\t\t\t\tif (index === 0) {\n\t\t\t\t\t\t// boyer-moore derrived algorithm to safely skip non-boundary data\n\t\t\t\t\t\ti += boundaryEnd;\n\t\t\t\t\t\twhile (i < bufferLength && !(data[i] in boundaryChars)) {\n\t\t\t\t\t\t\ti += boundaryLength;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\ti -= boundaryEnd;\n\t\t\t\t\t\tc = data[i];\n\t\t\t\t\t}\n\n\t\t\t\t\tif (index < boundary.length) {\n\t\t\t\t\t\tif (boundary[index] === c) {\n\t\t\t\t\t\t\tif (index === 0) {\n\t\t\t\t\t\t\t\tdataCallback('onPartData', true);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tindex++;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tindex = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (index === boundary.length) {\n\t\t\t\t\t\tindex++;\n\t\t\t\t\t\tif (c === CR) {\n\t\t\t\t\t\t\t// CR = part boundary\n\t\t\t\t\t\t\tflags |= F.PART_BOUNDARY;\n\t\t\t\t\t\t} else if (c === HYPHEN) {\n\t\t\t\t\t\t\t// HYPHEN = end boundary\n\t\t\t\t\t\t\tflags |= F.LAST_BOUNDARY;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tindex = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (index - 1 === boundary.length) {\n\t\t\t\t\t\tif (flags & F.PART_BOUNDARY) {\n\t\t\t\t\t\t\tindex = 0;\n\t\t\t\t\t\t\tif (c === LF) {\n\t\t\t\t\t\t\t\t// unset the PART_BOUNDARY flag\n\t\t\t\t\t\t\t\tflags &= ~F.PART_BOUNDARY;\n\t\t\t\t\t\t\t\tcallback('onPartEnd');\n\t\t\t\t\t\t\t\tcallback('onPartBegin');\n\t\t\t\t\t\t\t\tstate = S.HEADER_FIELD_START;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else if (flags & F.LAST_BOUNDARY) {\n\t\t\t\t\t\t\tif (c === HYPHEN) {\n\t\t\t\t\t\t\t\tcallback('onPartEnd');\n\t\t\t\t\t\t\t\tstate = S.END;\n\t\t\t\t\t\t\t\tflags = 0;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tindex = 0;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tindex = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (index > 0) {\n\t\t\t\t\t\t// when matching a possible boundary, keep a lookbehind reference\n\t\t\t\t\t\t// in case it turns out to be a false lead\n\t\t\t\t\t\tlookbehind[index - 1] = c;\n\t\t\t\t\t} else if (previousIndex > 0) {\n\t\t\t\t\t\t// if our boundary turned out to be rubbish, the captured lookbehind\n\t\t\t\t\t\t// belongs to partData\n\t\t\t\t\t\tconst _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);\n\t\t\t\t\t\tcallback('onPartData', 0, previousIndex, _lookbehind);\n\t\t\t\t\t\tpreviousIndex = 0;\n\t\t\t\t\t\tmark('onPartData');\n\n\t\t\t\t\t\t// reconsider the current character even so it interrupted the sequence\n\t\t\t\t\t\t// it could be the beginning of a new sequence\n\t\t\t\t\t\ti--;\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\tcase S.END:\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(`Unexpected state entered: ${state}`);\n\t\t\t}\n\t\t}\n\n\t\tdataCallback('onHeaderField');\n\t\tdataCallback('onHeaderValue');\n\t\tdataCallback('onPartData');\n\n\t\t// Update properties for the next call\n\t\tthis.index = index;\n\t\tthis.state = state;\n\t\tthis.flags = flags;\n\t}\n\n\tend() {\n\t\tif ((this.state === S.HEADER_FIELD_START && this.index === 0) ||\n\t\t\t(this.state === S.PART_DATA && this.index === this.boundary.length)) {\n\t\t\tthis.onPartEnd();\n\t\t} else if (this.state !== S.END) {\n\t\t\tthrow new Error('MultipartParser.end(): stream ended unexpectedly');\n\t\t}\n\t}\n}\n\nfunction _fileName(headerValue) {\n\t// matches either a quoted-string or a token (RFC 2616 section 19.5.1)\n\tconst m = headerValue.match(/\\bfilename=(\"(.*?)\"|([^()<>@,;:\\\\\"/[\\]?={}\\s\\t]+))($|;\\s)/i);\n\tif (!m) {\n\t\treturn;\n\t}\n\n\tconst match = m[2] || m[3] || '';\n\tlet filename = match.slice(match.lastIndexOf('\\\\') + 1);\n\tfilename = filename.replace(/%22/g, '\"');\n\tfilename = filename.replace(/&#(\\d{4});/g, (m, code) => {\n\t\treturn String.fromCharCode(code);\n\t});\n\treturn filename;\n}\n\nexport async function toFormData(Body, ct) {\n\tif (!/multipart/i.test(ct)) {\n\t\tthrow new TypeError('Failed to fetch');\n\t}\n\n\tconst m = ct.match(/boundary=(?:\"([^\"]+)\"|([^;]+))/i);\n\n\tif (!m) {\n\t\tthrow new TypeError('no or bad content-type header, no multipart boundary');\n\t}\n\n\tconst parser = new MultipartParser(m[1] || m[2]);\n\n\tlet headerField;\n\tlet headerValue;\n\tlet entryValue;\n\tlet entryName;\n\tlet contentType;\n\tlet filename;\n\tconst entryChunks = [];\n\tconst formData = new FormData();\n\n\tconst onPartData = ui8a => {\n\t\tentryValue += decoder.decode(ui8a, {stream: true});\n\t};\n\n\tconst appendToFile = ui8a => {\n\t\tentryChunks.push(ui8a);\n\t};\n\n\tconst appendFileToFormData = () => {\n\t\tconst file = new File(entryChunks, filename, {type: contentType});\n\t\tformData.append(entryName, file);\n\t};\n\n\tconst appendEntryToFormData = () => {\n\t\tformData.append(entryName, entryValue);\n\t};\n\n\tconst decoder = new TextDecoder('utf-8');\n\tdecoder.decode();\n\n\tparser.onPartBegin = function () {\n\t\tparser.onPartData = onPartData;\n\t\tparser.onPartEnd = appendEntryToFormData;\n\n\t\theaderField = '';\n\t\theaderValue = '';\n\t\tentryValue = '';\n\t\tentryName = '';\n\t\tcontentType = '';\n\t\tfilename = null;\n\t\tentryChunks.length = 0;\n\t};\n\n\tparser.onHeaderField = function (ui8a) {\n\t\theaderField += decoder.decode(ui8a, {stream: true});\n\t};\n\n\tparser.onHeaderValue = function (ui8a) {\n\t\theaderValue += decoder.decode(ui8a, {stream: true});\n\t};\n\n\tparser.onHeaderEnd = function () {\n\t\theaderValue += decoder.decode();\n\t\theaderField = headerField.toLowerCase();\n\n\t\tif (headerField === 'content-disposition') {\n\t\t\t// matches either a quoted-string or a token (RFC 2616 section 19.5.1)\n\t\t\tconst m = headerValue.match(/\\bname=(\"([^\"]*)\"|([^()<>@,;:\\\\\"/[\\]?={}\\s\\t]+))/i);\n\n\t\t\tif (m) {\n\t\t\t\tentryName = m[2] || m[3] || '';\n\t\t\t}\n\n\t\t\tfilename = _fileName(headerValue);\n\n\t\t\tif (filename) {\n\t\t\t\tparser.onPartData = appendToFile;\n\t\t\t\tparser.onPartEnd = appendFileToFormData;\n\t\t\t}\n\t\t} else if (headerField === 'content-type') {\n\t\t\tcontentType = headerValue;\n\t\t}\n\n\t\theaderValue = '';\n\t\theaderField = '';\n\t};\n\n\tfor await (const chunk of Body) {\n\t\tparser.write(chunk);\n\t}\n\n\tparser.end();\n\n\treturn formData;\n}\n"],"names":[],"sourceRoot":""}
|
package/webpack.config.cjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const path = require("path");
|
|
2
|
-
const webpack = require("webpack");
|
|
3
|
-
|
|
4
|
-
const config = {
|
|
5
|
-
entry: "./src/index.ts",
|
|
6
|
-
target: "node",
|
|
7
|
-
externals: {
|
|
8
|
-
figlet: "require('figlet')",
|
|
9
|
-
"@swc/core": "require('@swc/core')",
|
|
10
|
-
"@swc/wasm": "require('@swc/wasm')",
|
|
11
|
-
typescript: "require('typescript')",
|
|
12
|
-
//"isolated-vm": "require('isolated-vm')",
|
|
13
|
-
"jest-cli": "require('jest-cli')",
|
|
14
|
-
"../../package.json": "require('../package.json')",
|
|
15
|
-
},
|
|
16
|
-
node: {
|
|
17
|
-
__dirname: false,
|
|
18
|
-
},
|
|
19
|
-
devtool: "source-map",
|
|
20
|
-
output: {
|
|
21
|
-
path: path.resolve(__dirname, "dist"),
|
|
22
|
-
},
|
|
23
|
-
plugins: [
|
|
24
|
-
new webpack.IgnorePlugin({ resourceRegExp: /^fsevents$/ }), // Ignore MacOS-only module
|
|
25
|
-
],
|
|
26
|
-
module: {
|
|
27
|
-
rules: [
|
|
28
|
-
{
|
|
29
|
-
test: /\.(ts|tsx)$/i,
|
|
30
|
-
exclude: /node_modules/,
|
|
31
|
-
use: {
|
|
32
|
-
loader: "swc-loader",
|
|
33
|
-
options: {
|
|
34
|
-
configFile: path.resolve(__dirname, "../../libs/common-config/swc.config.json"),
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
test: /\.node$/,
|
|
40
|
-
loader: "node-loader",
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
},
|
|
44
|
-
optimization: {
|
|
45
|
-
minimize: false,
|
|
46
|
-
},
|
|
47
|
-
resolve: {
|
|
48
|
-
extensions: [".tsx", ".ts", ".jsx", ".js", ".node", "..."],
|
|
49
|
-
},
|
|
50
|
-
mode: "production",
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
module.exports = () => config;
|