/
105.index.js
315 lines (233 loc) · 10.2 KB
/
105.index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
"use strict";
exports.id = 105;
exports.ids = [105];
exports.modules = {
/***/ 8770:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
const fs = __webpack_require__(7147);
const os = __webpack_require__(2037);
const tempDirectorySymbol = Symbol.for('__RESOLVED_TEMP_DIRECTORY__');
if (!global[tempDirectorySymbol]) {
Object.defineProperty(global, tempDirectorySymbol, {
value: fs.realpathSync(os.tmpdir())
});
}
module.exports = global[tempDirectorySymbol];
/***/ }),
/***/ 4105:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
"rootTemporaryDirectory": () => (/* reexport */ temp_dir),
"temporaryDirectory": () => (/* binding */ temporaryDirectory),
"temporaryDirectoryTask": () => (/* binding */ temporaryDirectoryTask),
"temporaryFile": () => (/* binding */ temporaryFile),
"temporaryFileTask": () => (/* binding */ temporaryFileTask),
"temporaryWrite": () => (/* binding */ temporaryWrite),
"temporaryWriteSync": () => (/* binding */ temporaryWriteSync),
"temporaryWriteTask": () => (/* binding */ temporaryWriteTask)
});
// EXTERNAL MODULE: external "node:fs"
var external_node_fs_ = __webpack_require__(7561);
// EXTERNAL MODULE: external "node:fs/promises"
var promises_ = __webpack_require__(3977);
// EXTERNAL MODULE: external "node:path"
var external_node_path_ = __webpack_require__(9411);
// EXTERNAL MODULE: external "node:stream"
var external_node_stream_ = __webpack_require__(4492);
// EXTERNAL MODULE: external "node:util"
var external_node_util_ = __webpack_require__(7261);
// EXTERNAL MODULE: external "util"
var external_util_ = __webpack_require__(3837);
// EXTERNAL MODULE: external "crypto"
var external_crypto_ = __webpack_require__(6113);
;// CONCATENATED MODULE: ./node_modules/crypto-random-string/index.js
const randomBytesAsync = (0,external_util_.promisify)(external_crypto_.randomBytes);
const urlSafeCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~'.split('');
const numericCharacters = '0123456789'.split('');
const distinguishableCharacters = 'CDEHKMPRTUWXY012458'.split('');
const asciiPrintableCharacters = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'.split('');
const alphanumericCharacters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'.split('');
const generateForCustomCharacters = (length, characters) => {
// Generating entropy is faster than complex math operations, so we use the simplest way
const characterCount = characters.length;
const maxValidSelector = (Math.floor(0x10000 / characterCount) * characterCount) - 1; // Using values above this will ruin distribution when using modular division
const entropyLength = 2 * Math.ceil(1.1 * length); // Generating a bit more than required so chances we need more than one pass will be really low
let string = '';
let stringLength = 0;
while (stringLength < length) { // In case we had many bad values, which may happen for character sets of size above 0x8000 but close to it
const entropy = external_crypto_.randomBytes(entropyLength);
let entropyPosition = 0;
while (entropyPosition < entropyLength && stringLength < length) {
const entropyValue = entropy.readUInt16LE(entropyPosition);
entropyPosition += 2;
if (entropyValue > maxValidSelector) { // Skip values which will ruin distribution when using modular division
continue;
}
string += characters[entropyValue % characterCount];
stringLength++;
}
}
return string;
};
const generateForCustomCharactersAsync = async (length, characters) => {
// Generating entropy is faster than complex math operations, so we use the simplest way
const characterCount = characters.length;
const maxValidSelector = (Math.floor(0x10000 / characterCount) * characterCount) - 1; // Using values above this will ruin distribution when using modular division
const entropyLength = 2 * Math.ceil(1.1 * length); // Generating a bit more than required so chances we need more than one pass will be really low
let string = '';
let stringLength = 0;
while (stringLength < length) { // In case we had many bad values, which may happen for character sets of size above 0x8000 but close to it
const entropy = await randomBytesAsync(entropyLength); // eslint-disable-line no-await-in-loop
let entropyPosition = 0;
while (entropyPosition < entropyLength && stringLength < length) {
const entropyValue = entropy.readUInt16LE(entropyPosition);
entropyPosition += 2;
if (entropyValue > maxValidSelector) { // Skip values which will ruin distribution when using modular division
continue;
}
string += characters[entropyValue % characterCount];
stringLength++;
}
}
return string;
};
const generateRandomBytes = (byteLength, type, length) => external_crypto_.randomBytes(byteLength).toString(type).slice(0, length);
const generateRandomBytesAsync = async (byteLength, type, length) => {
const buffer = await randomBytesAsync(byteLength);
return buffer.toString(type).slice(0, length);
};
const allowedTypes = new Set([
undefined,
'hex',
'base64',
'url-safe',
'numeric',
'distinguishable',
'ascii-printable',
'alphanumeric'
]);
const createGenerator = (generateForCustomCharacters, generateRandomBytes) => ({length, type, characters}) => {
if (!(length >= 0 && Number.isFinite(length))) {
throw new TypeError('Expected a `length` to be a non-negative finite number');
}
if (type !== undefined && characters !== undefined) {
throw new TypeError('Expected either `type` or `characters`');
}
if (characters !== undefined && typeof characters !== 'string') {
throw new TypeError('Expected `characters` to be string');
}
if (!allowedTypes.has(type)) {
throw new TypeError(`Unknown type: ${type}`);
}
if (type === undefined && characters === undefined) {
type = 'hex';
}
if (type === 'hex' || (type === undefined && characters === undefined)) {
return generateRandomBytes(Math.ceil(length * 0.5), 'hex', length); // Need 0.5 byte entropy per character
}
if (type === 'base64') {
return generateRandomBytes(Math.ceil(length * 0.75), 'base64', length); // Need 0.75 byte of entropy per character
}
if (type === 'url-safe') {
return generateForCustomCharacters(length, urlSafeCharacters);
}
if (type === 'numeric') {
return generateForCustomCharacters(length, numericCharacters);
}
if (type === 'distinguishable') {
return generateForCustomCharacters(length, distinguishableCharacters);
}
if (type === 'ascii-printable') {
return generateForCustomCharacters(length, asciiPrintableCharacters);
}
if (type === 'alphanumeric') {
return generateForCustomCharacters(length, alphanumericCharacters);
}
if (characters.length === 0) {
throw new TypeError('Expected `characters` string length to be greater than or equal to 1');
}
if (characters.length > 0x10000) {
throw new TypeError('Expected `characters` string length to be less or equal to 65536');
}
return generateForCustomCharacters(length, characters.split(''));
};
const cryptoRandomString = createGenerator(generateForCustomCharacters, generateRandomBytes);
cryptoRandomString.async = createGenerator(generateForCustomCharactersAsync, generateRandomBytesAsync);
/* harmony default export */ const crypto_random_string = (cryptoRandomString);
;// CONCATENATED MODULE: ./node_modules/unique-string/index.js
function uniqueString() {
return crypto_random_string({length: 32});
}
// EXTERNAL MODULE: ./node_modules/temp-dir/index.js
var temp_dir = __webpack_require__(8770);
;// CONCATENATED MODULE: ./node_modules/tempy/node_modules/is-stream/index.js
function isStream(stream) {
return stream !== null
&& typeof stream === 'object'
&& typeof stream.pipe === 'function';
}
function isWritableStream(stream) {
return isStream(stream)
&& stream.writable !== false
&& typeof stream._write === 'function'
&& typeof stream._writableState === 'object';
}
function isReadableStream(stream) {
return isStream(stream)
&& stream.readable !== false
&& typeof stream._read === 'function'
&& typeof stream._readableState === 'object';
}
function isDuplexStream(stream) {
return isWritableStream(stream)
&& isReadableStream(stream);
}
function isTransformStream(stream) {
return isDuplexStream(stream)
&& typeof stream._transform === 'function';
}
;// CONCATENATED MODULE: ./node_modules/tempy/index.js
const pipeline = (0,external_node_util_.promisify)(external_node_stream_.pipeline); // TODO: Use `node:stream/promises` when targeting Node.js 16.
const getPath = (prefix = '') => external_node_path_.join(temp_dir, prefix + uniqueString());
const writeStream = async (filePath, data) => pipeline(data, external_node_fs_.createWriteStream(filePath));
async function runTask(temporaryPath, callback) {
try {
return await callback(temporaryPath);
} finally {
await promises_.rm(temporaryPath, {recursive: true, force: true});
}
}
function temporaryFile({name, extension} = {}) {
if (name) {
if (extension !== undefined && extension !== null) {
throw new Error('The `name` and `extension` options are mutually exclusive');
}
return external_node_path_.join(temporaryDirectory(), name);
}
return getPath() + (extension === undefined || extension === null ? '' : '.' + extension.replace(/^\./, ''));
}
const temporaryFileTask = async (callback, options) => runTask(temporaryFile(options), callback);
function temporaryDirectory({prefix = ''} = {}) {
const directory = getPath(prefix);
external_node_fs_.mkdirSync(directory);
return directory;
}
const temporaryDirectoryTask = async (callback, options) => runTask(temporaryDirectory(options), callback);
async function temporaryWrite(fileContent, options) {
const filename = temporaryFile(options);
const write = isStream(fileContent) ? writeStream : promises_.writeFile;
await write(filename, fileContent);
return filename;
}
const temporaryWriteTask = async (fileContent, callback, options) => runTask(await temporaryWrite(fileContent, options), callback);
function temporaryWriteSync(fileContent, options) {
const filename = temporaryFile(options);
external_node_fs_.writeFileSync(filename, fileContent);
return filename;
}
/***/ })
};
;