apipost-cli 1.0.9 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,6 +19,10 @@ npm install -g apipost-cli
19
19
  apipost run 'https://v7-api-test.apipost.cc/api/cli/open?type=single&id=7e58e858-c1ce-4c97-a0bf-5c0a559d9422&token=pnaoakyf4ivnqmi905sj82e0j60y0w6l' -r json,html -n 2
20
20
  ```
21
21
 
22
+ ```console
23
+ apipost run data.json -r json,html -n 2
24
+ ```
25
+
22
26
  ## Options type:Object
23
27
 
24
28
  ```
@@ -0,0 +1,452 @@
1
+ "use strict";
2
+ exports.id = 37;
3
+ exports.ids = [37];
4
+ exports.modules = {
5
+
6
+ /***/ 94037:
7
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
8
+
9
+ __webpack_require__.r(__webpack_exports__);
10
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
11
+ /* harmony export */ "toFormData": () => (/* binding */ toFormData)
12
+ /* harmony export */ });
13
+ /* harmony import */ var fetch_blob_from_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(52185);
14
+ /* harmony import */ var formdata_polyfill_esm_min_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(68010);
15
+
16
+
17
+
18
+ let s = 0;
19
+ const S = {
20
+ START_BOUNDARY: s++,
21
+ HEADER_FIELD_START: s++,
22
+ HEADER_FIELD: s++,
23
+ HEADER_VALUE_START: s++,
24
+ HEADER_VALUE: s++,
25
+ HEADER_VALUE_ALMOST_DONE: s++,
26
+ HEADERS_ALMOST_DONE: s++,
27
+ PART_DATA_START: s++,
28
+ PART_DATA: s++,
29
+ END: s++
30
+ };
31
+
32
+ let f = 1;
33
+ const F = {
34
+ PART_BOUNDARY: f,
35
+ LAST_BOUNDARY: f *= 2
36
+ };
37
+
38
+ const LF = 10;
39
+ const CR = 13;
40
+ const SPACE = 32;
41
+ const HYPHEN = 45;
42
+ const COLON = 58;
43
+ const A = 97;
44
+ const Z = 122;
45
+
46
+ const lower = c => c | 0x20;
47
+
48
+ const noop = () => {};
49
+
50
+ class MultipartParser {
51
+ /**
52
+ * @param {string} boundary
53
+ */
54
+ constructor(boundary) {
55
+ this.index = 0;
56
+ this.flags = 0;
57
+
58
+ this.onHeaderEnd = noop;
59
+ this.onHeaderField = noop;
60
+ this.onHeadersEnd = noop;
61
+ this.onHeaderValue = noop;
62
+ this.onPartBegin = noop;
63
+ this.onPartData = noop;
64
+ this.onPartEnd = noop;
65
+
66
+ this.boundaryChars = {};
67
+
68
+ boundary = '\r\n--' + boundary;
69
+ const ui8a = new Uint8Array(boundary.length);
70
+ for (let i = 0; i < boundary.length; i++) {
71
+ ui8a[i] = boundary.charCodeAt(i);
72
+ this.boundaryChars[ui8a[i]] = true;
73
+ }
74
+
75
+ this.boundary = ui8a;
76
+ this.lookbehind = new Uint8Array(this.boundary.length + 8);
77
+ this.state = S.START_BOUNDARY;
78
+ }
79
+
80
+ /**
81
+ * @param {Uint8Array} data
82
+ */
83
+ write(data) {
84
+ let i = 0;
85
+ const length_ = data.length;
86
+ let previousIndex = this.index;
87
+ let {lookbehind, boundary, boundaryChars, index, state, flags} = this;
88
+ const boundaryLength = this.boundary.length;
89
+ const boundaryEnd = boundaryLength - 1;
90
+ const bufferLength = data.length;
91
+ let c;
92
+ let cl;
93
+
94
+ const mark = name => {
95
+ this[name + 'Mark'] = i;
96
+ };
97
+
98
+ const clear = name => {
99
+ delete this[name + 'Mark'];
100
+ };
101
+
102
+ const callback = (callbackSymbol, start, end, ui8a) => {
103
+ if (start === undefined || start !== end) {
104
+ this[callbackSymbol](ui8a && ui8a.subarray(start, end));
105
+ }
106
+ };
107
+
108
+ const dataCallback = (name, clear) => {
109
+ const markSymbol = name + 'Mark';
110
+ if (!(markSymbol in this)) {
111
+ return;
112
+ }
113
+
114
+ if (clear) {
115
+ callback(name, this[markSymbol], i, data);
116
+ delete this[markSymbol];
117
+ } else {
118
+ callback(name, this[markSymbol], data.length, data);
119
+ this[markSymbol] = 0;
120
+ }
121
+ };
122
+
123
+ for (i = 0; i < length_; i++) {
124
+ c = data[i];
125
+
126
+ switch (state) {
127
+ case S.START_BOUNDARY:
128
+ if (index === boundary.length - 2) {
129
+ if (c === HYPHEN) {
130
+ flags |= F.LAST_BOUNDARY;
131
+ } else if (c !== CR) {
132
+ return;
133
+ }
134
+
135
+ index++;
136
+ break;
137
+ } else if (index - 1 === boundary.length - 2) {
138
+ if (flags & F.LAST_BOUNDARY && c === HYPHEN) {
139
+ state = S.END;
140
+ flags = 0;
141
+ } else if (!(flags & F.LAST_BOUNDARY) && c === LF) {
142
+ index = 0;
143
+ callback('onPartBegin');
144
+ state = S.HEADER_FIELD_START;
145
+ } else {
146
+ return;
147
+ }
148
+
149
+ break;
150
+ }
151
+
152
+ if (c !== boundary[index + 2]) {
153
+ index = -2;
154
+ }
155
+
156
+ if (c === boundary[index + 2]) {
157
+ index++;
158
+ }
159
+
160
+ break;
161
+ case S.HEADER_FIELD_START:
162
+ state = S.HEADER_FIELD;
163
+ mark('onHeaderField');
164
+ index = 0;
165
+ // falls through
166
+ case S.HEADER_FIELD:
167
+ if (c === CR) {
168
+ clear('onHeaderField');
169
+ state = S.HEADERS_ALMOST_DONE;
170
+ break;
171
+ }
172
+
173
+ index++;
174
+ if (c === HYPHEN) {
175
+ break;
176
+ }
177
+
178
+ if (c === COLON) {
179
+ if (index === 1) {
180
+ // empty header field
181
+ return;
182
+ }
183
+
184
+ dataCallback('onHeaderField', true);
185
+ state = S.HEADER_VALUE_START;
186
+ break;
187
+ }
188
+
189
+ cl = lower(c);
190
+ if (cl < A || cl > Z) {
191
+ return;
192
+ }
193
+
194
+ break;
195
+ case S.HEADER_VALUE_START:
196
+ if (c === SPACE) {
197
+ break;
198
+ }
199
+
200
+ mark('onHeaderValue');
201
+ state = S.HEADER_VALUE;
202
+ // falls through
203
+ case S.HEADER_VALUE:
204
+ if (c === CR) {
205
+ dataCallback('onHeaderValue', true);
206
+ callback('onHeaderEnd');
207
+ state = S.HEADER_VALUE_ALMOST_DONE;
208
+ }
209
+
210
+ break;
211
+ case S.HEADER_VALUE_ALMOST_DONE:
212
+ if (c !== LF) {
213
+ return;
214
+ }
215
+
216
+ state = S.HEADER_FIELD_START;
217
+ break;
218
+ case S.HEADERS_ALMOST_DONE:
219
+ if (c !== LF) {
220
+ return;
221
+ }
222
+
223
+ callback('onHeadersEnd');
224
+ state = S.PART_DATA_START;
225
+ break;
226
+ case S.PART_DATA_START:
227
+ state = S.PART_DATA;
228
+ mark('onPartData');
229
+ // falls through
230
+ case S.PART_DATA:
231
+ previousIndex = index;
232
+
233
+ if (index === 0) {
234
+ // boyer-moore derrived algorithm to safely skip non-boundary data
235
+ i += boundaryEnd;
236
+ while (i < bufferLength && !(data[i] in boundaryChars)) {
237
+ i += boundaryLength;
238
+ }
239
+
240
+ i -= boundaryEnd;
241
+ c = data[i];
242
+ }
243
+
244
+ if (index < boundary.length) {
245
+ if (boundary[index] === c) {
246
+ if (index === 0) {
247
+ dataCallback('onPartData', true);
248
+ }
249
+
250
+ index++;
251
+ } else {
252
+ index = 0;
253
+ }
254
+ } else if (index === boundary.length) {
255
+ index++;
256
+ if (c === CR) {
257
+ // CR = part boundary
258
+ flags |= F.PART_BOUNDARY;
259
+ } else if (c === HYPHEN) {
260
+ // HYPHEN = end boundary
261
+ flags |= F.LAST_BOUNDARY;
262
+ } else {
263
+ index = 0;
264
+ }
265
+ } else if (index - 1 === boundary.length) {
266
+ if (flags & F.PART_BOUNDARY) {
267
+ index = 0;
268
+ if (c === LF) {
269
+ // unset the PART_BOUNDARY flag
270
+ flags &= ~F.PART_BOUNDARY;
271
+ callback('onPartEnd');
272
+ callback('onPartBegin');
273
+ state = S.HEADER_FIELD_START;
274
+ break;
275
+ }
276
+ } else if (flags & F.LAST_BOUNDARY) {
277
+ if (c === HYPHEN) {
278
+ callback('onPartEnd');
279
+ state = S.END;
280
+ flags = 0;
281
+ } else {
282
+ index = 0;
283
+ }
284
+ } else {
285
+ index = 0;
286
+ }
287
+ }
288
+
289
+ if (index > 0) {
290
+ // when matching a possible boundary, keep a lookbehind reference
291
+ // in case it turns out to be a false lead
292
+ lookbehind[index - 1] = c;
293
+ } else if (previousIndex > 0) {
294
+ // if our boundary turned out to be rubbish, the captured lookbehind
295
+ // belongs to partData
296
+ const _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);
297
+ callback('onPartData', 0, previousIndex, _lookbehind);
298
+ previousIndex = 0;
299
+ mark('onPartData');
300
+
301
+ // reconsider the current character even so it interrupted the sequence
302
+ // it could be the beginning of a new sequence
303
+ i--;
304
+ }
305
+
306
+ break;
307
+ case S.END:
308
+ break;
309
+ default:
310
+ throw new Error(`Unexpected state entered: ${state}`);
311
+ }
312
+ }
313
+
314
+ dataCallback('onHeaderField');
315
+ dataCallback('onHeaderValue');
316
+ dataCallback('onPartData');
317
+
318
+ // Update properties for the next call
319
+ this.index = index;
320
+ this.state = state;
321
+ this.flags = flags;
322
+ }
323
+
324
+ end() {
325
+ if ((this.state === S.HEADER_FIELD_START && this.index === 0) ||
326
+ (this.state === S.PART_DATA && this.index === this.boundary.length)) {
327
+ this.onPartEnd();
328
+ } else if (this.state !== S.END) {
329
+ throw new Error('MultipartParser.end(): stream ended unexpectedly');
330
+ }
331
+ }
332
+ }
333
+
334
+ function _fileName(headerValue) {
335
+ // matches either a quoted-string or a token (RFC 2616 section 19.5.1)
336
+ const m = headerValue.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);
337
+ if (!m) {
338
+ return;
339
+ }
340
+
341
+ const match = m[2] || m[3] || '';
342
+ let filename = match.slice(match.lastIndexOf('\\') + 1);
343
+ filename = filename.replace(/%22/g, '"');
344
+ filename = filename.replace(/&#(\d{4});/g, (m, code) => {
345
+ return String.fromCharCode(code);
346
+ });
347
+ return filename;
348
+ }
349
+
350
+ async function toFormData(Body, ct) {
351
+ if (!/multipart/i.test(ct)) {
352
+ throw new TypeError('Failed to fetch');
353
+ }
354
+
355
+ const m = ct.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
356
+
357
+ if (!m) {
358
+ throw new TypeError('no or bad content-type header, no multipart boundary');
359
+ }
360
+
361
+ const parser = new MultipartParser(m[1] || m[2]);
362
+
363
+ let headerField;
364
+ let headerValue;
365
+ let entryValue;
366
+ let entryName;
367
+ let contentType;
368
+ let filename;
369
+ const entryChunks = [];
370
+ const formData = new formdata_polyfill_esm_min_js__WEBPACK_IMPORTED_MODULE_1__/* .FormData */ .Ct();
371
+
372
+ const onPartData = ui8a => {
373
+ entryValue += decoder.decode(ui8a, {stream: true});
374
+ };
375
+
376
+ const appendToFile = ui8a => {
377
+ entryChunks.push(ui8a);
378
+ };
379
+
380
+ const appendFileToFormData = () => {
381
+ const file = new fetch_blob_from_js__WEBPACK_IMPORTED_MODULE_0__/* .File */ .$B(entryChunks, filename, {type: contentType});
382
+ formData.append(entryName, file);
383
+ };
384
+
385
+ const appendEntryToFormData = () => {
386
+ formData.append(entryName, entryValue);
387
+ };
388
+
389
+ const decoder = new TextDecoder('utf-8');
390
+ decoder.decode();
391
+
392
+ parser.onPartBegin = function () {
393
+ parser.onPartData = onPartData;
394
+ parser.onPartEnd = appendEntryToFormData;
395
+
396
+ headerField = '';
397
+ headerValue = '';
398
+ entryValue = '';
399
+ entryName = '';
400
+ contentType = '';
401
+ filename = null;
402
+ entryChunks.length = 0;
403
+ };
404
+
405
+ parser.onHeaderField = function (ui8a) {
406
+ headerField += decoder.decode(ui8a, {stream: true});
407
+ };
408
+
409
+ parser.onHeaderValue = function (ui8a) {
410
+ headerValue += decoder.decode(ui8a, {stream: true});
411
+ };
412
+
413
+ parser.onHeaderEnd = function () {
414
+ headerValue += decoder.decode();
415
+ headerField = headerField.toLowerCase();
416
+
417
+ if (headerField === 'content-disposition') {
418
+ // matches either a quoted-string or a token (RFC 2616 section 19.5.1)
419
+ const m = headerValue.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);
420
+
421
+ if (m) {
422
+ entryName = m[2] || m[3] || '';
423
+ }
424
+
425
+ filename = _fileName(headerValue);
426
+
427
+ if (filename) {
428
+ parser.onPartData = appendToFile;
429
+ parser.onPartEnd = appendFileToFormData;
430
+ }
431
+ } else if (headerField === 'content-type') {
432
+ contentType = headerValue;
433
+ }
434
+
435
+ headerValue = '';
436
+ headerField = '';
437
+ };
438
+
439
+ for await (const chunk of Body) {
440
+ parser.write(chunk);
441
+ }
442
+
443
+ parser.end();
444
+
445
+ return formData;
446
+ }
447
+
448
+
449
+ /***/ })
450
+
451
+ };
452
+ ;