@ever-works/minio-plugin 1.0.0 → 1.0.3

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/dist/index.cjs ADDED
@@ -0,0 +1,1904 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var os = require('os');
6
+ var path = require('path');
7
+ var promises = require('fs/promises');
8
+ var crypto = require('crypto');
9
+ var clientS3 = require('@aws-sdk/client-s3');
10
+ var events = require('events');
11
+ var buffer = require('buffer');
12
+ var fs = require('fs');
13
+ var stream = require('stream');
14
+ var s3RequestPresigner = require('@aws-sdk/s3-request-presigner');
15
+
16
+ var __defProp = Object.defineProperty;
17
+ var __getOwnPropNames = Object.getOwnPropertyNames;
18
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
19
+ var __esm = (fn, res, err) => function __init() {
20
+ if (err) throw err[0];
21
+ try {
22
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
23
+ } catch (e) {
24
+ throw err = [e], e;
25
+ }
26
+ };
27
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
28
+
29
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/property-provider/ProviderError.js
30
+ var ProviderError;
31
+ var init_ProviderError = __esm({
32
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/property-provider/ProviderError.js"() {
33
+ ProviderError = class _ProviderError extends Error {
34
+ constructor(message, options = true) {
35
+ let logger;
36
+ let tryNextLink = true;
37
+ if (typeof options === "boolean") {
38
+ logger = void 0;
39
+ tryNextLink = options;
40
+ } else if (options != null && typeof options === "object") {
41
+ logger = options.logger;
42
+ tryNextLink = options.tryNextLink ?? true;
43
+ }
44
+ super(message);
45
+ __publicField(this, "name", "ProviderError");
46
+ __publicField(this, "tryNextLink");
47
+ this.tryNextLink = tryNextLink;
48
+ Object.setPrototypeOf(this, _ProviderError.prototype);
49
+ logger?.debug?.(`@smithy/property-provider ${tryNextLink ? "->" : "(!)"} ${message}`);
50
+ }
51
+ static from(error, options = true) {
52
+ return Object.assign(new this(error.message, options), error);
53
+ }
54
+ };
55
+ }
56
+ });
57
+
58
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/property-provider/CredentialsProviderError.js
59
+ var CredentialsProviderError;
60
+ var init_CredentialsProviderError = __esm({
61
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/property-provider/CredentialsProviderError.js"() {
62
+ init_ProviderError();
63
+ CredentialsProviderError = class _CredentialsProviderError extends ProviderError {
64
+ constructor(message, options = true) {
65
+ super(message, options);
66
+ __publicField(this, "name", "CredentialsProviderError");
67
+ Object.setPrototypeOf(this, _CredentialsProviderError.prototype);
68
+ }
69
+ };
70
+ }
71
+ });
72
+
73
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/property-provider/chain.js
74
+ var chain;
75
+ var init_chain = __esm({
76
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/property-provider/chain.js"() {
77
+ init_ProviderError();
78
+ chain = (...providers) => async () => {
79
+ if (providers.length === 0) {
80
+ throw new ProviderError("No providers in chain");
81
+ }
82
+ let lastProviderError;
83
+ for (const provider of providers) {
84
+ try {
85
+ const credentials = await provider();
86
+ return credentials;
87
+ } catch (err) {
88
+ lastProviderError = err;
89
+ if (err?.tryNextLink) {
90
+ continue;
91
+ }
92
+ throw err;
93
+ }
94
+ }
95
+ throw lastProviderError;
96
+ };
97
+ }
98
+ });
99
+
100
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/property-provider/fromValue.js
101
+ var fromValue;
102
+ var init_fromValue = __esm({
103
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/property-provider/fromValue.js"() {
104
+ fromValue = (staticValue) => () => Promise.resolve(staticValue);
105
+ }
106
+ });
107
+
108
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/property-provider/memoize.js
109
+ var memoize;
110
+ var init_memoize = __esm({
111
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/property-provider/memoize.js"() {
112
+ memoize = (provider, isExpired, requiresRefresh) => {
113
+ let resolved;
114
+ let pending;
115
+ let hasResult;
116
+ let isConstant = false;
117
+ const coalesceProvider = async () => {
118
+ if (!pending) {
119
+ pending = provider();
120
+ }
121
+ try {
122
+ resolved = await pending;
123
+ hasResult = true;
124
+ isConstant = false;
125
+ } finally {
126
+ pending = void 0;
127
+ }
128
+ return resolved;
129
+ };
130
+ if (isExpired === void 0) {
131
+ return async (options) => {
132
+ if (!hasResult || options?.forceRefresh) {
133
+ resolved = await coalesceProvider();
134
+ }
135
+ return resolved;
136
+ };
137
+ }
138
+ return async (options) => {
139
+ if (!hasResult || options?.forceRefresh) {
140
+ resolved = await coalesceProvider();
141
+ }
142
+ if (isConstant) {
143
+ return resolved;
144
+ }
145
+ if (requiresRefresh && !requiresRefresh(resolved)) {
146
+ isConstant = true;
147
+ return resolved;
148
+ }
149
+ if (isExpired(resolved)) {
150
+ await coalesceProvider();
151
+ return resolved;
152
+ }
153
+ return resolved;
154
+ };
155
+ };
156
+ }
157
+ });
158
+
159
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/util-config-provider/booleanSelector.js
160
+ var booleanSelector;
161
+ var init_booleanSelector = __esm({
162
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/util-config-provider/booleanSelector.js"() {
163
+ booleanSelector = (obj, key, type) => {
164
+ if (!(key in obj))
165
+ return void 0;
166
+ if (obj[key] === "true")
167
+ return true;
168
+ if (obj[key] === "false")
169
+ return false;
170
+ throw new Error(`Cannot load ${type} "${key}". Expected "true" or "false", got ${obj[key]}.`);
171
+ };
172
+ }
173
+ });
174
+
175
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/util-config-provider/types.js
176
+ var SelectorType;
177
+ var init_types = __esm({
178
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/util-config-provider/types.js"() {
179
+ (function(SelectorType2) {
180
+ SelectorType2["ENV"] = "env";
181
+ SelectorType2["CONFIG"] = "shared config entry";
182
+ })(SelectorType || (SelectorType = {}));
183
+ }
184
+ });
185
+ var homeDirCache, getHomeDirCacheKey, getHomeDir;
186
+ var init_getHomeDir = __esm({
187
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/shared-ini-file-loader/getHomeDir.js"() {
188
+ homeDirCache = {};
189
+ getHomeDirCacheKey = () => {
190
+ if (process && process.geteuid) {
191
+ return `${process.geteuid()}`;
192
+ }
193
+ return "DEFAULT";
194
+ };
195
+ getHomeDir = () => {
196
+ const { HOME, USERPROFILE, HOMEPATH, HOMEDRIVE = `C:${path.sep}` } = process.env;
197
+ if (HOME)
198
+ return HOME;
199
+ if (USERPROFILE)
200
+ return USERPROFILE;
201
+ if (HOMEPATH)
202
+ return `${HOMEDRIVE}${HOMEPATH}`;
203
+ const homeDirCacheKey = getHomeDirCacheKey();
204
+ if (!homeDirCache[homeDirCacheKey])
205
+ homeDirCache[homeDirCacheKey] = os.homedir();
206
+ return homeDirCache[homeDirCacheKey];
207
+ };
208
+ }
209
+ });
210
+
211
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/shared-ini-file-loader/getProfileName.js
212
+ var ENV_PROFILE, DEFAULT_PROFILE, getProfileName;
213
+ var init_getProfileName = __esm({
214
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/shared-ini-file-loader/getProfileName.js"() {
215
+ ENV_PROFILE = "AWS_PROFILE";
216
+ DEFAULT_PROFILE = "default";
217
+ getProfileName = (init) => init.profile || process.env[ENV_PROFILE] || DEFAULT_PROFILE;
218
+ }
219
+ });
220
+
221
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/shared-ini-file-loader/constants.js
222
+ var CONFIG_PREFIX_SEPARATOR;
223
+ var init_constants = __esm({
224
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/shared-ini-file-loader/constants.js"() {
225
+ CONFIG_PREFIX_SEPARATOR = ".";
226
+ }
227
+ });
228
+ var init_middleware = __esm({
229
+ "../../../node_modules/.pnpm/@smithy+types@4.18.0/node_modules/@smithy/types/dist-es/middleware.js"() {
230
+ }
231
+ });
232
+
233
+ // ../../../node_modules/.pnpm/@smithy+types@4.18.0/node_modules/@smithy/types/dist-es/profile.js
234
+ var IniSectionType;
235
+ var init_profile = __esm({
236
+ "../../../node_modules/.pnpm/@smithy+types@4.18.0/node_modules/@smithy/types/dist-es/profile.js"() {
237
+ (function(IniSectionType2) {
238
+ IniSectionType2["PROFILE"] = "profile";
239
+ IniSectionType2["SSO_SESSION"] = "sso-session";
240
+ IniSectionType2["SERVICES"] = "services";
241
+ })(IniSectionType || (IniSectionType = {}));
242
+ }
243
+ });
244
+
245
+ // ../../../node_modules/.pnpm/@smithy+types@4.18.0/node_modules/@smithy/types/dist-es/index.js
246
+ var init_dist_es = __esm({
247
+ "../../../node_modules/.pnpm/@smithy+types@4.18.0/node_modules/@smithy/types/dist-es/index.js"() {
248
+ init_middleware();
249
+ init_profile();
250
+ }
251
+ });
252
+
253
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/shared-ini-file-loader/getConfigData.js
254
+ var getConfigData;
255
+ var init_getConfigData = __esm({
256
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/shared-ini-file-loader/getConfigData.js"() {
257
+ init_dist_es();
258
+ init_constants();
259
+ getConfigData = (data) => Object.entries(data).filter(([key]) => {
260
+ const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR);
261
+ if (indexOfSeparator === -1) {
262
+ return false;
263
+ }
264
+ return Object.values(IniSectionType).includes(key.substring(0, indexOfSeparator));
265
+ }).reduce((acc, [key, value]) => {
266
+ const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR);
267
+ const updatedKey = key.substring(0, indexOfSeparator) === IniSectionType.PROFILE ? key.substring(indexOfSeparator + 1) : key;
268
+ acc[updatedKey] = value;
269
+ return acc;
270
+ }, {
271
+ ...data.default && { default: data.default }
272
+ });
273
+ }
274
+ });
275
+ var ENV_CONFIG_PATH, getConfigFilepath;
276
+ var init_getConfigFilepath = __esm({
277
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/shared-ini-file-loader/getConfigFilepath.js"() {
278
+ init_getHomeDir();
279
+ ENV_CONFIG_PATH = "AWS_CONFIG_FILE";
280
+ getConfigFilepath = () => process.env[ENV_CONFIG_PATH] || path.join(getHomeDir(), ".aws", "config");
281
+ }
282
+ });
283
+ var ENV_CREDENTIALS_PATH, getCredentialsFilepath;
284
+ var init_getCredentialsFilepath = __esm({
285
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/shared-ini-file-loader/getCredentialsFilepath.js"() {
286
+ init_getHomeDir();
287
+ ENV_CREDENTIALS_PATH = "AWS_SHARED_CREDENTIALS_FILE";
288
+ getCredentialsFilepath = () => process.env[ENV_CREDENTIALS_PATH] || path.join(getHomeDir(), ".aws", "credentials");
289
+ }
290
+ });
291
+
292
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/shared-ini-file-loader/parseIni.js
293
+ var prefixKeyRegex, profileNameBlockList, parseIni;
294
+ var init_parseIni = __esm({
295
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/shared-ini-file-loader/parseIni.js"() {
296
+ init_dist_es();
297
+ init_constants();
298
+ prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-@+.%:/]+)\2$/;
299
+ profileNameBlockList = ["__proto__", "profile __proto__"];
300
+ parseIni = (iniData) => {
301
+ const map = {};
302
+ let currentSection;
303
+ let currentSubSection;
304
+ for (const iniLine of iniData.split(/\r?\n/)) {
305
+ const trimmedLine = iniLine.split(/(^|\s)[;#]/)[0].trim();
306
+ const isSection = trimmedLine[0] === "[" && trimmedLine[trimmedLine.length - 1] === "]";
307
+ if (isSection) {
308
+ currentSection = void 0;
309
+ currentSubSection = void 0;
310
+ const sectionName = trimmedLine.substring(1, trimmedLine.length - 1);
311
+ const matches = prefixKeyRegex.exec(sectionName);
312
+ if (matches) {
313
+ const [, prefix, , name] = matches;
314
+ if (Object.values(IniSectionType).includes(prefix)) {
315
+ currentSection = [prefix, name].join(CONFIG_PREFIX_SEPARATOR);
316
+ }
317
+ } else {
318
+ currentSection = sectionName;
319
+ }
320
+ if (profileNameBlockList.includes(sectionName)) {
321
+ throw new Error(`Found invalid profile name "${sectionName}"`);
322
+ }
323
+ } else if (currentSection) {
324
+ const indexOfEqualsSign = trimmedLine.indexOf("=");
325
+ if (![0, -1].includes(indexOfEqualsSign)) {
326
+ const [name, value] = [
327
+ trimmedLine.substring(0, indexOfEqualsSign).trim(),
328
+ trimmedLine.substring(indexOfEqualsSign + 1).trim()
329
+ ];
330
+ if (value === "") {
331
+ currentSubSection = name;
332
+ } else {
333
+ if (currentSubSection && iniLine.trimStart() === iniLine) {
334
+ currentSubSection = void 0;
335
+ }
336
+ map[currentSection] = map[currentSection] || {};
337
+ const key = currentSubSection ? [currentSubSection, name].join(CONFIG_PREFIX_SEPARATOR) : name;
338
+ map[currentSection][key] = value;
339
+ }
340
+ }
341
+ }
342
+ }
343
+ return map;
344
+ };
345
+ }
346
+ });
347
+ var filePromises, fileIntercept, readFile;
348
+ var init_readFile = __esm({
349
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/shared-ini-file-loader/readFile.js"() {
350
+ filePromises = {};
351
+ fileIntercept = {};
352
+ readFile = (path, options) => {
353
+ if (fileIntercept[path] !== void 0) {
354
+ return fileIntercept[path];
355
+ }
356
+ if (!filePromises[path] || options?.ignoreCache) {
357
+ filePromises[path] = promises.readFile(path, "utf8");
358
+ }
359
+ return filePromises[path];
360
+ };
361
+ }
362
+ });
363
+ var swallowError, loadSharedConfigFiles;
364
+ var init_loadSharedConfigFiles = __esm({
365
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/shared-ini-file-loader/loadSharedConfigFiles.js"() {
366
+ init_getConfigData();
367
+ init_getConfigFilepath();
368
+ init_getCredentialsFilepath();
369
+ init_getHomeDir();
370
+ init_parseIni();
371
+ init_readFile();
372
+ swallowError = () => ({});
373
+ loadSharedConfigFiles = async (init = {}) => {
374
+ const { filepath = getCredentialsFilepath(), configFilepath = getConfigFilepath() } = init;
375
+ const homeDir = getHomeDir();
376
+ const relativeHomeDirPrefix = "~/";
377
+ let resolvedFilepath = filepath;
378
+ if (filepath.startsWith(relativeHomeDirPrefix)) {
379
+ resolvedFilepath = path.join(homeDir, filepath.slice(2));
380
+ }
381
+ let resolvedConfigFilepath = configFilepath;
382
+ if (configFilepath.startsWith(relativeHomeDirPrefix)) {
383
+ resolvedConfigFilepath = path.join(homeDir, configFilepath.slice(2));
384
+ }
385
+ const parsedFiles = await Promise.all([
386
+ readFile(resolvedConfigFilepath, {
387
+ ignoreCache: init.ignoreCache
388
+ }).then(parseIni).then(getConfigData).catch(swallowError),
389
+ readFile(resolvedFilepath, {
390
+ ignoreCache: init.ignoreCache
391
+ }).then(parseIni).catch(swallowError)
392
+ ]);
393
+ return {
394
+ configFile: parsedFiles[0],
395
+ credentialsFile: parsedFiles[1]
396
+ };
397
+ };
398
+ }
399
+ });
400
+
401
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/node-config-provider/getSelectorName.js
402
+ function getSelectorName(functionString) {
403
+ try {
404
+ const constants = new Set(Array.from(functionString.match(/([A-Z_]){3,}/g) ?? []));
405
+ constants.delete("CONFIG");
406
+ constants.delete("CONFIG_PREFIX_SEPARATOR");
407
+ constants.delete("ENV");
408
+ return [...constants].join(", ");
409
+ } catch (ignored) {
410
+ return functionString;
411
+ }
412
+ }
413
+ var init_getSelectorName = __esm({
414
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/node-config-provider/getSelectorName.js"() {
415
+ }
416
+ });
417
+
418
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/node-config-provider/fromEnv.js
419
+ var fromEnv;
420
+ var init_fromEnv = __esm({
421
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/node-config-provider/fromEnv.js"() {
422
+ init_CredentialsProviderError();
423
+ init_getSelectorName();
424
+ fromEnv = (envVarSelector, options) => async () => {
425
+ try {
426
+ const config = envVarSelector(process.env, options);
427
+ if (config === void 0) {
428
+ throw new Error();
429
+ }
430
+ return config;
431
+ } catch (e) {
432
+ throw new CredentialsProviderError(e.message || `Not found in ENV: ${getSelectorName(envVarSelector.toString())}`, { logger: options?.logger });
433
+ }
434
+ };
435
+ }
436
+ });
437
+
438
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/node-config-provider/fromSharedConfigFiles.js
439
+ var fromSharedConfigFiles;
440
+ var init_fromSharedConfigFiles = __esm({
441
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/node-config-provider/fromSharedConfigFiles.js"() {
442
+ init_CredentialsProviderError();
443
+ init_getProfileName();
444
+ init_loadSharedConfigFiles();
445
+ init_getSelectorName();
446
+ fromSharedConfigFiles = (configSelector, { preferredFile = "config", ...init } = {}) => async () => {
447
+ const profile = getProfileName(init);
448
+ const { configFile, credentialsFile } = await loadSharedConfigFiles(init);
449
+ const profileFromCredentials = credentialsFile[profile] || {};
450
+ const profileFromConfig = configFile[profile] || {};
451
+ const mergedProfile = preferredFile === "config" ? { ...profileFromCredentials, ...profileFromConfig } : { ...profileFromConfig, ...profileFromCredentials };
452
+ try {
453
+ const cfgFile = preferredFile === "config" ? configFile : credentialsFile;
454
+ const configValue = configSelector(mergedProfile, cfgFile);
455
+ if (configValue === void 0) {
456
+ throw new Error();
457
+ }
458
+ return configValue;
459
+ } catch (e) {
460
+ throw new CredentialsProviderError(e.message || `Not found in config files w/ profile [${profile}]: ${getSelectorName(configSelector.toString())}`, { logger: init.logger });
461
+ }
462
+ };
463
+ }
464
+ });
465
+
466
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/node-config-provider/fromStatic.js
467
+ var isFunction, fromStatic;
468
+ var init_fromStatic = __esm({
469
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/node-config-provider/fromStatic.js"() {
470
+ init_fromValue();
471
+ isFunction = (func) => typeof func === "function";
472
+ fromStatic = (defaultValue) => isFunction(defaultValue) ? async () => await defaultValue() : fromValue(defaultValue);
473
+ }
474
+ });
475
+
476
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/node-config-provider/configLoader.js
477
+ var loadConfig;
478
+ var init_configLoader = __esm({
479
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/node-config-provider/configLoader.js"() {
480
+ init_chain();
481
+ init_memoize();
482
+ init_fromEnv();
483
+ init_fromSharedConfigFiles();
484
+ init_fromStatic();
485
+ loadConfig = ({ environmentVariableSelector, configFileSelector, default: defaultValue }, configuration = {}) => {
486
+ const { signingName, logger } = configuration;
487
+ const envOptions = { signingName, logger };
488
+ return memoize(chain(fromEnv(environmentVariableSelector, envOptions), fromSharedConfigFiles(configFileSelector, configuration), fromStatic(defaultValue)));
489
+ };
490
+ }
491
+ });
492
+ var init_getSmithyContext = __esm({
493
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/transport/getSmithyContext.js"() {
494
+ init_dist_es();
495
+ }
496
+ });
497
+
498
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/transport/hasOwn.js
499
+ function hasOwn(o, k) {
500
+ return Object.prototype.hasOwnProperty.call(o, k);
501
+ }
502
+ var init_hasOwn = __esm({
503
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/transport/hasOwn.js"() {
504
+ }
505
+ });
506
+ var init_normalizeProvider = __esm({
507
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/transport/normalizeProvider.js"() {
508
+ }
509
+ });
510
+
511
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/transport/parseQueryString.js
512
+ function parseQueryString(querystring) {
513
+ const query = {};
514
+ querystring = querystring.replace(/^\?/, "");
515
+ if (querystring) {
516
+ for (const pair of querystring.split("&")) {
517
+ let [key, value = null] = pair.split("=");
518
+ key = decodeURIComponent(key);
519
+ if (value) {
520
+ value = decodeURIComponent(value);
521
+ }
522
+ if (!(key in query)) {
523
+ query[key] = value;
524
+ } else if (Array.isArray(query[key])) {
525
+ query[key].push(value);
526
+ } else {
527
+ query[key] = [query[key], value];
528
+ }
529
+ }
530
+ }
531
+ return query;
532
+ }
533
+ var init_parseQueryString = __esm({
534
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/transport/parseQueryString.js"() {
535
+ }
536
+ });
537
+
538
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/transport/parseUrl.js
539
+ var parseUrl;
540
+ var init_parseUrl = __esm({
541
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/transport/parseUrl.js"() {
542
+ init_parseQueryString();
543
+ parseUrl = (url) => {
544
+ if (typeof url === "string") {
545
+ return parseUrl(new URL(url));
546
+ }
547
+ const { hostname, pathname, port, protocol, search } = url;
548
+ let query;
549
+ if (search) {
550
+ query = parseQueryString(search);
551
+ }
552
+ return {
553
+ hostname,
554
+ port: port ? parseInt(port) : void 0,
555
+ protocol,
556
+ path: pathname,
557
+ query
558
+ };
559
+ };
560
+ }
561
+ });
562
+
563
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/transport/toEndpointV1.js
564
+ var toEndpointV1;
565
+ var init_toEndpointV1 = __esm({
566
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/transport/toEndpointV1.js"() {
567
+ init_hasOwn();
568
+ init_parseUrl();
569
+ toEndpointV1 = (endpoint) => {
570
+ if (typeof endpoint === "object") {
571
+ if ("url" in endpoint) {
572
+ const v1Endpoint = parseUrl(endpoint.url);
573
+ if (endpoint.headers) {
574
+ v1Endpoint.headers = {};
575
+ for (const name in endpoint.headers) {
576
+ if (!hasOwn(endpoint.headers, name))
577
+ continue;
578
+ v1Endpoint.headers[name.toLowerCase()] = endpoint.headers[name].join(", ");
579
+ }
580
+ }
581
+ return v1Endpoint;
582
+ }
583
+ return endpoint;
584
+ }
585
+ return parseUrl(endpoint);
586
+ };
587
+ }
588
+ });
589
+
590
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/transport/index.js
591
+ var init_transport = __esm({
592
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/transport/index.js"() {
593
+ init_getSmithyContext();
594
+ init_normalizeProvider();
595
+ init_toEndpointV1();
596
+ }
597
+ });
598
+
599
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/index.js
600
+ var init_config = __esm({
601
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/config/index.js"() {
602
+ init_booleanSelector();
603
+ init_types();
604
+ init_constants();
605
+ init_configLoader();
606
+ }
607
+ });
608
+
609
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/adaptors/getEndpointUrlConfig.js
610
+ var ENV_ENDPOINT_URL, CONFIG_ENDPOINT_URL, getEndpointUrlConfig;
611
+ var init_getEndpointUrlConfig = __esm({
612
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/adaptors/getEndpointUrlConfig.js"() {
613
+ init_config();
614
+ ENV_ENDPOINT_URL = "AWS_ENDPOINT_URL";
615
+ CONFIG_ENDPOINT_URL = "endpoint_url";
616
+ getEndpointUrlConfig = (serviceId) => ({
617
+ environmentVariableSelector: (env) => {
618
+ const serviceSuffixParts = serviceId.split(" ").map((w) => w.toUpperCase());
619
+ const serviceEndpointUrl = env[[ENV_ENDPOINT_URL, ...serviceSuffixParts].join("_")];
620
+ if (serviceEndpointUrl)
621
+ return serviceEndpointUrl;
622
+ const endpointUrl = env[ENV_ENDPOINT_URL];
623
+ if (endpointUrl)
624
+ return endpointUrl;
625
+ return void 0;
626
+ },
627
+ configFileSelector: (profile, config) => {
628
+ if (profile.services) {
629
+ const servicesSectionKey = ["services", profile.services].join(CONFIG_PREFIX_SEPARATOR);
630
+ if (!config || !config[servicesSectionKey]) {
631
+ throw new Error(`The services section "${profile.services}" specified in the profile is not present in the shared configuration file.`);
632
+ }
633
+ const servicesSection = config[servicesSectionKey];
634
+ const servicePrefixParts = serviceId.split(" ").map((w) => w.toLowerCase());
635
+ const endpointUrl2 = servicesSection[[servicePrefixParts.join("_"), CONFIG_ENDPOINT_URL].join(CONFIG_PREFIX_SEPARATOR)];
636
+ if (endpointUrl2)
637
+ return endpointUrl2;
638
+ }
639
+ const endpointUrl = profile[CONFIG_ENDPOINT_URL];
640
+ if (endpointUrl)
641
+ return endpointUrl;
642
+ return void 0;
643
+ },
644
+ default: void 0
645
+ });
646
+ }
647
+ });
648
+
649
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/adaptors/getIgnoreConfiguredEndpointUrls.js
650
+ var ENV_IGNORE_CONFIGURED_ENDPOINT_URLS, CONFIG_IGNORE_CONFIGURED_ENDPOINT_URLS, ignoreConfiguredEndpointUrlsConfigSelectors;
651
+ var init_getIgnoreConfiguredEndpointUrls = __esm({
652
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/adaptors/getIgnoreConfiguredEndpointUrls.js"() {
653
+ init_config();
654
+ ENV_IGNORE_CONFIGURED_ENDPOINT_URLS = "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS";
655
+ CONFIG_IGNORE_CONFIGURED_ENDPOINT_URLS = "ignore_configured_endpoint_urls";
656
+ ignoreConfiguredEndpointUrlsConfigSelectors = {
657
+ environmentVariableSelector: (env) => booleanSelector(env, ENV_IGNORE_CONFIGURED_ENDPOINT_URLS, SelectorType.ENV),
658
+ configFileSelector: (profile) => booleanSelector(profile, CONFIG_IGNORE_CONFIGURED_ENDPOINT_URLS, SelectorType.CONFIG),
659
+ default: false
660
+ };
661
+ }
662
+ });
663
+
664
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/adaptors/getEndpointFromConfig.js
665
+ var getEndpointFromConfig;
666
+ var init_getEndpointFromConfig = __esm({
667
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/adaptors/getEndpointFromConfig.js"() {
668
+ init_config();
669
+ init_getEndpointUrlConfig();
670
+ init_getIgnoreConfiguredEndpointUrls();
671
+ getEndpointFromConfig = async (serviceId) => {
672
+ const ignore = await loadConfig(ignoreConfiguredEndpointUrlsConfigSelectors)();
673
+ if (ignore) {
674
+ return void 0;
675
+ }
676
+ return loadConfig(getEndpointUrlConfig(serviceId ?? ""))();
677
+ };
678
+ }
679
+ });
680
+
681
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/service-customizations/s3.js
682
+ var resolveParamsForS3, DOMAIN_PATTERN, IP_ADDRESS_PATTERN, DOTS_PATTERN, isDnsCompatibleBucketName, isArnBucketName;
683
+ var init_s3 = __esm({
684
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/service-customizations/s3.js"() {
685
+ resolveParamsForS3 = async (endpointParams) => {
686
+ const bucket = endpointParams?.Bucket || "";
687
+ if (typeof endpointParams.Bucket === "string") {
688
+ endpointParams.Bucket = bucket.replace(/#/g, encodeURIComponent("#")).replace(/\?/g, encodeURIComponent("?"));
689
+ }
690
+ if (isArnBucketName(bucket)) {
691
+ if (endpointParams.ForcePathStyle === true) {
692
+ throw new Error("Path-style addressing cannot be used with ARN buckets");
693
+ }
694
+ } else if (!isDnsCompatibleBucketName(bucket) || bucket.indexOf(".") !== -1 && !String(endpointParams.Endpoint).startsWith("http:") || bucket.toLowerCase() !== bucket || bucket.length < 3) {
695
+ endpointParams.ForcePathStyle = true;
696
+ }
697
+ if (endpointParams.DisableMultiRegionAccessPoints) {
698
+ endpointParams.disableMultiRegionAccessPoints = true;
699
+ endpointParams.DisableMRAP = true;
700
+ }
701
+ return endpointParams;
702
+ };
703
+ DOMAIN_PATTERN = /^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/;
704
+ IP_ADDRESS_PATTERN = /(\d+\.){3}\d+/;
705
+ DOTS_PATTERN = /\.\./;
706
+ isDnsCompatibleBucketName = (bucketName) => DOMAIN_PATTERN.test(bucketName) && !IP_ADDRESS_PATTERN.test(bucketName) && !DOTS_PATTERN.test(bucketName);
707
+ isArnBucketName = (bucketName) => {
708
+ const [arn, partition, service, , , bucket] = bucketName.split(":");
709
+ const isArn = arn === "arn" && bucketName.split(":").length >= 6;
710
+ const isValidArn = Boolean(isArn && partition && service && bucket);
711
+ if (isArn && !isValidArn) {
712
+ throw new Error(`Invalid ARN: ${bucketName} was an invalid ARN.`);
713
+ }
714
+ return isValidArn;
715
+ };
716
+ }
717
+ });
718
+
719
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/service-customizations/index.js
720
+ var init_service_customizations = __esm({
721
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/service-customizations/index.js"() {
722
+ init_s3();
723
+ }
724
+ });
725
+
726
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/adaptors/createConfigValueProvider.js
727
+ var createConfigValueProvider;
728
+ var init_createConfigValueProvider = __esm({
729
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/adaptors/createConfigValueProvider.js"() {
730
+ createConfigValueProvider = (configKey, canonicalEndpointParamKey, config, isClientContextParam = false) => {
731
+ const configProvider = async () => {
732
+ let configValue;
733
+ if (isClientContextParam) {
734
+ const clientContextParams = config.clientContextParams;
735
+ const nestedValue = clientContextParams?.[configKey];
736
+ configValue = nestedValue ?? config[configKey] ?? config[canonicalEndpointParamKey];
737
+ } else {
738
+ configValue = config[configKey] ?? config[canonicalEndpointParamKey];
739
+ }
740
+ if (typeof configValue === "function") {
741
+ return configValue();
742
+ }
743
+ return configValue;
744
+ };
745
+ if (configKey === "credentialScope" || canonicalEndpointParamKey === "CredentialScope") {
746
+ return async () => {
747
+ const credentials = typeof config.credentials === "function" ? await config.credentials() : config.credentials;
748
+ const configValue = credentials?.credentialScope ?? credentials?.CredentialScope;
749
+ return configValue;
750
+ };
751
+ }
752
+ if (configKey === "accountId" || canonicalEndpointParamKey === "AccountId") {
753
+ return async () => {
754
+ const credentials = typeof config.credentials === "function" ? await config.credentials() : config.credentials;
755
+ const configValue = credentials?.accountId ?? credentials?.AccountId;
756
+ return configValue;
757
+ };
758
+ }
759
+ if (configKey === "endpoint" || canonicalEndpointParamKey === "endpoint") {
760
+ return async () => {
761
+ if (config.isCustomEndpoint === false) {
762
+ return void 0;
763
+ }
764
+ const endpoint = await configProvider();
765
+ if (endpoint && typeof endpoint === "object") {
766
+ if ("url" in endpoint) {
767
+ return endpoint.url.href;
768
+ }
769
+ if ("hostname" in endpoint) {
770
+ const { protocol, hostname, port, path } = endpoint;
771
+ return `${protocol}//${hostname}${port ? ":" + port : ""}${path}`;
772
+ }
773
+ }
774
+ return endpoint;
775
+ };
776
+ }
777
+ return configProvider;
778
+ };
779
+ }
780
+ });
781
+
782
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/adaptors/toEndpointV1.js
783
+ var init_toEndpointV12 = __esm({
784
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/adaptors/toEndpointV1.js"() {
785
+ init_transport();
786
+ }
787
+ });
788
+
789
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/adaptors/getEndpointFromInstructions.js
790
+ function bindGetEndpointFromInstructions(getEndpointFromConfig2) {
791
+ return async (commandInput, instructionsSupplier, clientConfig, context) => {
792
+ if (!clientConfig.isCustomEndpoint && !clientConfig.ignoreConfiguredEndpointUrls) {
793
+ let endpointFromConfig;
794
+ if (clientConfig.serviceConfiguredEndpoint) {
795
+ endpointFromConfig = await clientConfig.serviceConfiguredEndpoint();
796
+ } else {
797
+ endpointFromConfig = await getEndpointFromConfig2(clientConfig.serviceId);
798
+ }
799
+ if (endpointFromConfig) {
800
+ clientConfig.endpoint = () => Promise.resolve(toEndpointV1(endpointFromConfig));
801
+ clientConfig.isCustomEndpoint = true;
802
+ context?.logger?.debug?.(`@smithy/core/endpoints - resolved endpoint from config: ${endpointFromConfig}`);
803
+ }
804
+ }
805
+ const endpointParams = await resolveParams(commandInput, instructionsSupplier, clientConfig);
806
+ if (typeof clientConfig.endpointProvider !== "function") {
807
+ throw new Error("config.endpointProvider is not set.");
808
+ }
809
+ const endpoint = clientConfig.endpointProvider(endpointParams, context);
810
+ if (clientConfig.isCustomEndpoint && clientConfig.endpoint) {
811
+ const customEndpoint = await clientConfig.endpoint();
812
+ if (customEndpoint?.headers) {
813
+ endpoint.headers ??= {};
814
+ for (const [name, value] of Object.entries(customEndpoint.headers)) {
815
+ endpoint.headers[name] = Array.isArray(value) ? value : [value];
816
+ }
817
+ }
818
+ }
819
+ return endpoint;
820
+ };
821
+ }
822
+ var resolveParams;
823
+ var init_getEndpointFromInstructions = __esm({
824
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/adaptors/getEndpointFromInstructions.js"() {
825
+ init_service_customizations();
826
+ init_createConfigValueProvider();
827
+ init_toEndpointV12();
828
+ resolveParams = async (commandInput, instructionsSupplier, clientConfig) => {
829
+ const endpointParams = {};
830
+ const instructions = instructionsSupplier?.getEndpointParameterInstructions?.() || {};
831
+ for (const [name, instruction] of Object.entries(instructions)) {
832
+ switch (instruction.type) {
833
+ case "staticContextParams":
834
+ endpointParams[name] = instruction.value;
835
+ break;
836
+ case "contextParams":
837
+ endpointParams[name] = commandInput[instruction.name];
838
+ break;
839
+ case "clientContextParams":
840
+ case "builtInParams":
841
+ endpointParams[name] = await createConfigValueProvider(instruction.name, name, clientConfig, instruction.type !== "builtInParams")();
842
+ break;
843
+ case "operationContextParams":
844
+ endpointParams[name] = instruction.get(commandInput);
845
+ break;
846
+ default:
847
+ throw new Error("Unrecognized endpoint parameter instruction: " + JSON.stringify(instruction));
848
+ }
849
+ }
850
+ if (Object.keys(instructions).length === 0) {
851
+ Object.assign(endpointParams, clientConfig);
852
+ }
853
+ if (String(clientConfig.serviceId).toLowerCase() === "s3") {
854
+ await resolveParamsForS3(endpointParams);
855
+ }
856
+ return endpointParams;
857
+ };
858
+ }
859
+ });
860
+ var init_endpointMiddleware = __esm({
861
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/endpointMiddleware.js"() {
862
+ init_transport();
863
+ init_getEndpointFromInstructions();
864
+ }
865
+ });
866
+ var serializerMiddlewareOption;
867
+ var init_getEndpointPlugin = __esm({
868
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/getEndpointPlugin.js"() {
869
+ init_endpointMiddleware();
870
+ serializerMiddlewareOption = {
871
+ name: "serializerMiddleware",
872
+ step: "serialize",
873
+ tags: ["SERIALIZER"],
874
+ override: true
875
+ };
876
+ ({
877
+ step: "serialize",
878
+ tags: ["ENDPOINT_PARAMETERS", "ENDPOINT_V2", "ENDPOINT"],
879
+ name: "endpointV2Middleware",
880
+ override: true,
881
+ relation: "before",
882
+ toMiddleware: serializerMiddlewareOption.name
883
+ });
884
+ }
885
+ });
886
+ var init_resolveEndpointConfig = __esm({
887
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/middleware-endpoint/resolveEndpointConfig.js"() {
888
+ init_transport();
889
+ init_toEndpointV12();
890
+ }
891
+ });
892
+
893
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/index.js
894
+ var getEndpointFromInstructions;
895
+ var init_endpoints = __esm({
896
+ "../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/endpoints/index.js"() {
897
+ init_getEndpointFromConfig();
898
+ init_getEndpointFromInstructions();
899
+ init_endpointMiddleware();
900
+ init_getEndpointPlugin();
901
+ init_resolveEndpointConfig();
902
+ init_transport();
903
+ getEndpointFromInstructions = bindGetEndpointFromInstructions(getEndpointFromConfig);
904
+ }
905
+ });
906
+
907
+ // ../../../node_modules/.pnpm/@aws-sdk+lib-storage@3.1051.0_@aws-sdk+client-s3@3.1051.0/node_modules/@aws-sdk/lib-storage/dist-es/Upload.js
908
+ init_endpoints();
909
+
910
+ // ../../../node_modules/.pnpm/@smithy+core@3.34.1/node_modules/@smithy/core/dist-es/submodules/protocols/extended-encode-uri-component.js
911
+ function extendedEncodeURIComponent(str) {
912
+ return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
913
+ return "%" + c.charCodeAt(0).toString(16).toUpperCase();
914
+ });
915
+ }
916
+
917
+ // ../../../node_modules/.pnpm/@aws-sdk+lib-storage@3.1051.0_@aws-sdk+client-s3@3.1051.0/node_modules/@aws-sdk/lib-storage/dist-es/runtimeConfig.shared.js
918
+ var runtimeConfigShared = {
919
+ lstatSync: () => {
920
+ },
921
+ isFileReadStream(f) {
922
+ return false;
923
+ }
924
+ };
925
+
926
+ // ../../../node_modules/.pnpm/@aws-sdk+lib-storage@3.1051.0_@aws-sdk+client-s3@3.1051.0/node_modules/@aws-sdk/lib-storage/dist-es/runtimeConfig.js
927
+ var runtimeConfig = {
928
+ ...runtimeConfigShared,
929
+ runtime: "node",
930
+ lstatSync: fs.lstatSync,
931
+ isFileReadStream(f) {
932
+ return f instanceof fs.ReadStream;
933
+ }
934
+ };
935
+
936
+ // ../../../node_modules/.pnpm/@aws-sdk+lib-storage@3.1051.0_@aws-sdk+client-s3@3.1051.0/node_modules/@aws-sdk/lib-storage/dist-es/byteLength.js
937
+ var byteLength = (input) => {
938
+ if (input == null) {
939
+ return 0;
940
+ }
941
+ if (typeof input === "string") {
942
+ return buffer.Buffer.byteLength(input);
943
+ }
944
+ if (typeof input.byteLength === "number") {
945
+ return input.byteLength;
946
+ } else if (typeof input.length === "number") {
947
+ return input.length;
948
+ } else if (typeof input.size === "number") {
949
+ return input.size;
950
+ } else if (typeof input.start === "number" && typeof input.end === "number") {
951
+ return input.end + 1 - input.start;
952
+ } else if (runtimeConfig.isFileReadStream(input)) {
953
+ try {
954
+ return runtimeConfig.lstatSync(input.path).size;
955
+ } catch (error) {
956
+ return void 0;
957
+ }
958
+ }
959
+ return void 0;
960
+ };
961
+
962
+ // ../../../node_modules/.pnpm/@aws-sdk+lib-storage@3.1051.0_@aws-sdk+client-s3@3.1051.0/node_modules/@aws-sdk/lib-storage/dist-es/byteLengthSource.js
963
+ var BYTE_LENGTH_SOURCE;
964
+ (function(BYTE_LENGTH_SOURCE2) {
965
+ BYTE_LENGTH_SOURCE2["EMPTY_INPUT"] = "a null or undefined Body";
966
+ BYTE_LENGTH_SOURCE2["CONTENT_LENGTH"] = "the ContentLength property of the params set by the caller";
967
+ BYTE_LENGTH_SOURCE2["STRING_LENGTH"] = "the encoded byte length of the Body string";
968
+ BYTE_LENGTH_SOURCE2["TYPED_ARRAY"] = "the byteLength of a typed byte array such as Uint8Array";
969
+ BYTE_LENGTH_SOURCE2["LENGTH"] = "the value of Body.length";
970
+ BYTE_LENGTH_SOURCE2["SIZE"] = "the value of Body.size";
971
+ BYTE_LENGTH_SOURCE2["START_END_DIFF"] = "the numeric difference between Body.start and Body.end";
972
+ BYTE_LENGTH_SOURCE2["LSTAT"] = "the size of the file given by Body.path on disk as reported by lstatSync";
973
+ })(BYTE_LENGTH_SOURCE || (BYTE_LENGTH_SOURCE = {}));
974
+ var byteLengthSource = (input, override) => {
975
+ if (override != null) {
976
+ return BYTE_LENGTH_SOURCE.CONTENT_LENGTH;
977
+ }
978
+ if (input == null) {
979
+ return BYTE_LENGTH_SOURCE.EMPTY_INPUT;
980
+ }
981
+ if (typeof input === "string") {
982
+ return BYTE_LENGTH_SOURCE.STRING_LENGTH;
983
+ }
984
+ if (typeof input.byteLength === "number") {
985
+ return BYTE_LENGTH_SOURCE.TYPED_ARRAY;
986
+ } else if (typeof input.length === "number") {
987
+ return BYTE_LENGTH_SOURCE.LENGTH;
988
+ } else if (typeof input.size === "number") {
989
+ return BYTE_LENGTH_SOURCE.SIZE;
990
+ } else if (typeof input.start === "number" && typeof input.end === "number") {
991
+ return BYTE_LENGTH_SOURCE.START_END_DIFF;
992
+ } else if (runtimeConfig.isFileReadStream(input)) {
993
+ try {
994
+ runtimeConfig.lstatSync(input.path).size;
995
+ return BYTE_LENGTH_SOURCE.LSTAT;
996
+ } catch (error) {
997
+ return void 0;
998
+ }
999
+ }
1000
+ return void 0;
1001
+ };
1002
+ async function* getChunkStream(data, partSize, getNextData) {
1003
+ let partNumber = 1;
1004
+ const currentBuffer = { chunks: [], length: 0 };
1005
+ for await (const datum of getNextData(data)) {
1006
+ currentBuffer.chunks.push(datum);
1007
+ currentBuffer.length += datum.byteLength;
1008
+ while (currentBuffer.length > partSize) {
1009
+ const dataChunk = currentBuffer.chunks.length > 1 ? buffer.Buffer.concat(currentBuffer.chunks) : currentBuffer.chunks[0];
1010
+ yield {
1011
+ partNumber,
1012
+ data: dataChunk.subarray(0, partSize)
1013
+ };
1014
+ currentBuffer.chunks = [dataChunk.subarray(partSize)];
1015
+ currentBuffer.length = currentBuffer.chunks[0].byteLength;
1016
+ partNumber += 1;
1017
+ }
1018
+ }
1019
+ yield {
1020
+ partNumber,
1021
+ data: currentBuffer.chunks.length !== 1 ? buffer.Buffer.concat(currentBuffer.chunks) : currentBuffer.chunks[0],
1022
+ lastPart: true
1023
+ };
1024
+ }
1025
+
1026
+ // ../../../node_modules/.pnpm/@aws-sdk+lib-storage@3.1051.0_@aws-sdk+client-s3@3.1051.0/node_modules/@aws-sdk/lib-storage/dist-es/chunks/getChunkUint8Array.js
1027
+ async function* getChunkUint8Array(data, partSize) {
1028
+ let partNumber = 1;
1029
+ let startByte = 0;
1030
+ let endByte = partSize;
1031
+ while (endByte < data.byteLength) {
1032
+ yield {
1033
+ partNumber,
1034
+ data: data.subarray(startByte, endByte)
1035
+ };
1036
+ partNumber += 1;
1037
+ startByte = endByte;
1038
+ endByte = startByte + partSize;
1039
+ }
1040
+ yield {
1041
+ partNumber,
1042
+ data: data.subarray(startByte),
1043
+ lastPart: true
1044
+ };
1045
+ }
1046
+ async function* getDataReadable(data) {
1047
+ for await (const chunk of data) {
1048
+ if (buffer.Buffer.isBuffer(chunk) || chunk instanceof Uint8Array) {
1049
+ yield chunk;
1050
+ } else {
1051
+ yield buffer.Buffer.from(chunk);
1052
+ }
1053
+ }
1054
+ }
1055
+ async function* getDataReadableStream(data) {
1056
+ const reader = data.getReader();
1057
+ try {
1058
+ while (true) {
1059
+ const { done, value } = await reader.read();
1060
+ if (done) {
1061
+ return;
1062
+ }
1063
+ if (buffer.Buffer.isBuffer(value) || value instanceof Uint8Array) {
1064
+ yield value;
1065
+ } else {
1066
+ yield buffer.Buffer.from(value);
1067
+ }
1068
+ }
1069
+ } catch (e) {
1070
+ throw e;
1071
+ } finally {
1072
+ reader.releaseLock();
1073
+ }
1074
+ }
1075
+
1076
+ // ../../../node_modules/.pnpm/@aws-sdk+lib-storage@3.1051.0_@aws-sdk+client-s3@3.1051.0/node_modules/@aws-sdk/lib-storage/dist-es/chunker.js
1077
+ var getChunk = (data, partSize) => {
1078
+ if (data instanceof Uint8Array) {
1079
+ return getChunkUint8Array(data, partSize);
1080
+ }
1081
+ if (data instanceof stream.Readable) {
1082
+ return getChunkStream(data, partSize, getDataReadable);
1083
+ }
1084
+ if (data instanceof String || typeof data === "string") {
1085
+ return getChunkUint8Array(buffer.Buffer.from(data), partSize);
1086
+ }
1087
+ if (typeof data.stream === "function") {
1088
+ return getChunkStream(data.stream(), partSize, getDataReadableStream);
1089
+ }
1090
+ if (data instanceof ReadableStream) {
1091
+ return getChunkStream(data, partSize, getDataReadableStream);
1092
+ }
1093
+ throw new Error("Body Data is unsupported format, expected data to be one of: string | Uint8Array | Buffer | Readable | ReadableStream | Blob;.");
1094
+ };
1095
+
1096
+ // ../../../node_modules/.pnpm/@aws-sdk+lib-storage@3.1051.0_@aws-sdk+client-s3@3.1051.0/node_modules/@aws-sdk/lib-storage/dist-es/Upload.js
1097
+ var _Upload = class _Upload extends events.EventEmitter {
1098
+ constructor(options) {
1099
+ super();
1100
+ __publicField(this, "MAX_PARTS", 1e4);
1101
+ __publicField(this, "queueSize", 4);
1102
+ __publicField(this, "partSize");
1103
+ __publicField(this, "leavePartsOnError", false);
1104
+ __publicField(this, "tags", []);
1105
+ __publicField(this, "client");
1106
+ __publicField(this, "params");
1107
+ __publicField(this, "totalBytes");
1108
+ __publicField(this, "totalBytesSource");
1109
+ __publicField(this, "bytesUploadedSoFar");
1110
+ __publicField(this, "abortController");
1111
+ __publicField(this, "concurrentUploaders", []);
1112
+ __publicField(this, "createMultiPartPromise");
1113
+ __publicField(this, "abortMultipartUploadCommand", null);
1114
+ __publicField(this, "uploadedParts", []);
1115
+ __publicField(this, "uploadEnqueuedPartsCount", 0);
1116
+ __publicField(this, "expectedPartsCount");
1117
+ __publicField(this, "uploadId");
1118
+ __publicField(this, "uploadEvent");
1119
+ __publicField(this, "isMultiPart", true);
1120
+ __publicField(this, "singleUploadResult");
1121
+ __publicField(this, "sent", false);
1122
+ this.queueSize = options.queueSize || this.queueSize;
1123
+ this.leavePartsOnError = options.leavePartsOnError || this.leavePartsOnError;
1124
+ this.tags = options.tags || this.tags;
1125
+ this.client = options.client;
1126
+ this.params = options.params;
1127
+ if (!this.params) {
1128
+ throw new Error(`InputError: Upload requires params to be passed to upload.`);
1129
+ }
1130
+ this.totalBytes = this.params.ContentLength ?? byteLength(this.params.Body);
1131
+ this.totalBytesSource = byteLengthSource(this.params.Body, this.params.ContentLength);
1132
+ this.bytesUploadedSoFar = 0;
1133
+ this.abortController = options.abortController ?? new AbortController();
1134
+ this.partSize = options.partSize || Math.max(_Upload.MIN_PART_SIZE, Math.ceil((this.totalBytes || 0) / this.MAX_PARTS));
1135
+ if (this.totalBytes !== void 0) {
1136
+ this.expectedPartsCount = Math.ceil(this.totalBytes / this.partSize);
1137
+ }
1138
+ this.__validateInput();
1139
+ }
1140
+ async abort() {
1141
+ this.abortController.abort();
1142
+ }
1143
+ async done() {
1144
+ if (this.sent) {
1145
+ throw new Error("@aws-sdk/lib-storage: this instance of Upload has already executed .done(). Create a new instance.");
1146
+ }
1147
+ this.sent = true;
1148
+ return await Promise.race([this.__doMultipartUpload(), this.__abortTimeout(this.abortController.signal)]);
1149
+ }
1150
+ on(event, listener) {
1151
+ this.uploadEvent = event;
1152
+ return super.on(event, listener);
1153
+ }
1154
+ async __uploadUsingPut(dataPart) {
1155
+ this.isMultiPart = false;
1156
+ const params = { ...this.params, Body: dataPart.data };
1157
+ const clientConfig = this.client.config;
1158
+ const requestHandler = clientConfig.requestHandler;
1159
+ const eventEmitter = requestHandler instanceof events.EventEmitter ? requestHandler : null;
1160
+ const uploadEventListener = (event) => {
1161
+ this.bytesUploadedSoFar = event.loaded;
1162
+ this.totalBytes = event.total;
1163
+ this.__notifyProgress({
1164
+ loaded: this.bytesUploadedSoFar,
1165
+ total: this.totalBytes,
1166
+ part: dataPart.partNumber,
1167
+ Key: this.params.Key,
1168
+ Bucket: this.params.Bucket
1169
+ });
1170
+ };
1171
+ if (eventEmitter !== null) {
1172
+ eventEmitter.on("xhr.upload.progress", uploadEventListener);
1173
+ }
1174
+ const resolved = await Promise.all([this.client.send(new clientS3.PutObjectCommand(params)), clientConfig?.endpoint?.()]);
1175
+ const putResult = resolved[0];
1176
+ let endpoint = resolved[1];
1177
+ if (!endpoint) {
1178
+ endpoint = toEndpointV1(await getEndpointFromInstructions(params, clientS3.PutObjectCommand, {
1179
+ ...clientConfig
1180
+ }));
1181
+ }
1182
+ if (!endpoint) {
1183
+ throw new Error('Could not resolve endpoint from S3 "client.config.endpoint()" nor EndpointsV2.');
1184
+ }
1185
+ if (eventEmitter !== null) {
1186
+ eventEmitter.off("xhr.upload.progress", uploadEventListener);
1187
+ }
1188
+ const locationKey = this.params.Key.split("/").map((segment) => extendedEncodeURIComponent(segment)).join("/");
1189
+ const locationBucket = extendedEncodeURIComponent(this.params.Bucket);
1190
+ const Location = (() => {
1191
+ const endpointHostnameIncludesBucket = endpoint.hostname.startsWith(`${locationBucket}.`);
1192
+ const forcePathStyle = this.client.config.forcePathStyle;
1193
+ const optionalPort = endpoint.port ? `:${endpoint.port}` : ``;
1194
+ if (forcePathStyle) {
1195
+ return `${endpoint.protocol}//${endpoint.hostname}${optionalPort}/${locationBucket}/${locationKey}`;
1196
+ }
1197
+ if (endpointHostnameIncludesBucket) {
1198
+ return `${endpoint.protocol}//${endpoint.hostname}${optionalPort}/${locationKey}`;
1199
+ }
1200
+ return `${endpoint.protocol}//${locationBucket}.${endpoint.hostname}${optionalPort}/${locationKey}`;
1201
+ })();
1202
+ this.singleUploadResult = {
1203
+ ...putResult,
1204
+ Bucket: this.params.Bucket,
1205
+ Key: this.params.Key,
1206
+ Location
1207
+ };
1208
+ const totalSize = byteLength(dataPart.data);
1209
+ this.__notifyProgress({
1210
+ loaded: totalSize,
1211
+ total: totalSize,
1212
+ part: 1,
1213
+ Key: this.params.Key,
1214
+ Bucket: this.params.Bucket
1215
+ });
1216
+ }
1217
+ async __createMultipartUpload() {
1218
+ const requestChecksumCalculation = await this.client.config.requestChecksumCalculation();
1219
+ if (!this.createMultiPartPromise) {
1220
+ const createCommandParams = { ...this.params, Body: void 0 };
1221
+ if (requestChecksumCalculation === "WHEN_SUPPORTED") {
1222
+ createCommandParams.ChecksumAlgorithm = this.params.ChecksumAlgorithm || clientS3.ChecksumAlgorithm.CRC32;
1223
+ }
1224
+ this.createMultiPartPromise = this.client.send(new clientS3.CreateMultipartUploadCommand(createCommandParams)).then((createMpuResponse) => {
1225
+ this.abortMultipartUploadCommand = new clientS3.AbortMultipartUploadCommand({
1226
+ Bucket: this.params.Bucket,
1227
+ Key: this.params.Key,
1228
+ UploadId: createMpuResponse.UploadId
1229
+ });
1230
+ return createMpuResponse;
1231
+ });
1232
+ }
1233
+ return this.createMultiPartPromise;
1234
+ }
1235
+ async __doConcurrentUpload(dataFeeder) {
1236
+ for await (const dataPart of dataFeeder) {
1237
+ if (this.uploadEnqueuedPartsCount > this.MAX_PARTS) {
1238
+ throw new Error(`Exceeded ${this.MAX_PARTS} parts in multipart upload to Bucket: ${this.params.Bucket} Key: ${this.params.Key}.`);
1239
+ }
1240
+ if (this.abortController.signal.aborted) {
1241
+ return;
1242
+ }
1243
+ if (dataPart.partNumber === 1 && dataPart.lastPart) {
1244
+ return await this.__uploadUsingPut(dataPart);
1245
+ }
1246
+ if (!this.uploadId) {
1247
+ const { UploadId } = await this.__createMultipartUpload();
1248
+ this.uploadId = UploadId;
1249
+ if (this.abortController.signal.aborted) {
1250
+ return;
1251
+ }
1252
+ }
1253
+ const partSize = byteLength(dataPart.data) || 0;
1254
+ const requestHandler = this.client.config.requestHandler;
1255
+ const eventEmitter = requestHandler instanceof events.EventEmitter ? requestHandler : null;
1256
+ let lastSeenBytes = 0;
1257
+ const uploadEventListener = (event, request) => {
1258
+ const requestPartSize = Number(request.query["partNumber"]) || -1;
1259
+ if (requestPartSize !== dataPart.partNumber) {
1260
+ return;
1261
+ }
1262
+ if (event.total && partSize) {
1263
+ this.bytesUploadedSoFar += event.loaded - lastSeenBytes;
1264
+ lastSeenBytes = event.loaded;
1265
+ }
1266
+ this.__notifyProgress({
1267
+ loaded: this.bytesUploadedSoFar,
1268
+ total: this.totalBytes,
1269
+ part: dataPart.partNumber,
1270
+ Key: this.params.Key,
1271
+ Bucket: this.params.Bucket
1272
+ });
1273
+ };
1274
+ if (eventEmitter !== null) {
1275
+ eventEmitter.on("xhr.upload.progress", uploadEventListener);
1276
+ }
1277
+ this.uploadEnqueuedPartsCount += 1;
1278
+ this.__validateUploadPart(dataPart);
1279
+ const partResult = await this.client.send(new clientS3.UploadPartCommand({
1280
+ ...this.params,
1281
+ ContentLength: void 0,
1282
+ UploadId: this.uploadId,
1283
+ Body: dataPart.data,
1284
+ PartNumber: dataPart.partNumber
1285
+ }));
1286
+ if (eventEmitter !== null) {
1287
+ eventEmitter.off("xhr.upload.progress", uploadEventListener);
1288
+ }
1289
+ if (this.abortController.signal.aborted) {
1290
+ return;
1291
+ }
1292
+ if (!partResult.ETag) {
1293
+ throw new Error(`Part ${dataPart.partNumber} is missing ETag in UploadPart response. Missing Bucket CORS configuration for ETag header?`);
1294
+ }
1295
+ this.uploadedParts.push({
1296
+ PartNumber: dataPart.partNumber,
1297
+ ETag: partResult.ETag,
1298
+ ...partResult.ChecksumCRC32 && { ChecksumCRC32: partResult.ChecksumCRC32 },
1299
+ ...partResult.ChecksumCRC32C && { ChecksumCRC32C: partResult.ChecksumCRC32C },
1300
+ ...partResult.ChecksumSHA1 && { ChecksumSHA1: partResult.ChecksumSHA1 },
1301
+ ...partResult.ChecksumSHA256 && { ChecksumSHA256: partResult.ChecksumSHA256 }
1302
+ });
1303
+ if (eventEmitter === null) {
1304
+ this.bytesUploadedSoFar += partSize;
1305
+ }
1306
+ this.__notifyProgress({
1307
+ loaded: this.bytesUploadedSoFar,
1308
+ total: this.totalBytes,
1309
+ part: dataPart.partNumber,
1310
+ Key: this.params.Key,
1311
+ Bucket: this.params.Bucket
1312
+ });
1313
+ }
1314
+ }
1315
+ async __doMultipartUpload() {
1316
+ const dataFeeder = getChunk(this.params.Body, this.partSize);
1317
+ const concurrentUploaderFailures = [];
1318
+ for (let index = 0; index < this.queueSize; index++) {
1319
+ const currentUpload = this.__doConcurrentUpload(dataFeeder).catch((err) => {
1320
+ concurrentUploaderFailures.push(err);
1321
+ });
1322
+ this.concurrentUploaders.push(currentUpload);
1323
+ }
1324
+ await Promise.all(this.concurrentUploaders);
1325
+ if (concurrentUploaderFailures.length >= 1) {
1326
+ await this.markUploadAsAborted();
1327
+ throw concurrentUploaderFailures[0];
1328
+ }
1329
+ if (this.abortController.signal.aborted) {
1330
+ await this.markUploadAsAborted();
1331
+ throw Object.assign(new Error("Upload aborted."), { name: "AbortError" });
1332
+ }
1333
+ let result;
1334
+ if (this.isMultiPart) {
1335
+ const { expectedPartsCount, uploadedParts, totalBytes, totalBytesSource } = this;
1336
+ if (totalBytes !== void 0 && expectedPartsCount !== void 0 && uploadedParts.length !== expectedPartsCount) {
1337
+ throw new Error(`Expected ${expectedPartsCount} part(s) but uploaded ${uploadedParts.length} part(s).
1338
+ The expected part count is based on the byte-count of the input.params.Body,
1339
+ which was read from ${totalBytesSource} and is ${totalBytes}.
1340
+ If this is not correct, provide an override value by setting a number
1341
+ to input.params.ContentLength in bytes.
1342
+ `);
1343
+ }
1344
+ this.uploadedParts.sort((a, b) => a.PartNumber - b.PartNumber);
1345
+ const uploadCompleteParams = {
1346
+ ...this.params,
1347
+ Body: void 0,
1348
+ UploadId: this.uploadId,
1349
+ MultipartUpload: {
1350
+ Parts: this.uploadedParts
1351
+ }
1352
+ };
1353
+ result = await this.client.send(new clientS3.CompleteMultipartUploadCommand(uploadCompleteParams));
1354
+ if (typeof result?.Location === "string" && result.Location.includes("%2F")) {
1355
+ result.Location = result.Location.replace(/%2F/g, "/");
1356
+ }
1357
+ } else {
1358
+ result = this.singleUploadResult;
1359
+ }
1360
+ this.abortMultipartUploadCommand = null;
1361
+ if (this.tags.length) {
1362
+ await this.client.send(new clientS3.PutObjectTaggingCommand({
1363
+ ...this.params,
1364
+ Tagging: {
1365
+ TagSet: this.tags
1366
+ }
1367
+ }));
1368
+ }
1369
+ return result;
1370
+ }
1371
+ async markUploadAsAborted() {
1372
+ if (this.uploadId && !this.leavePartsOnError && null !== this.abortMultipartUploadCommand) {
1373
+ await this.client.send(this.abortMultipartUploadCommand);
1374
+ this.abortMultipartUploadCommand = null;
1375
+ }
1376
+ }
1377
+ __notifyProgress(progress) {
1378
+ if (this.uploadEvent) {
1379
+ this.emit(this.uploadEvent, progress);
1380
+ }
1381
+ }
1382
+ async __abortTimeout(abortSignal) {
1383
+ return new Promise((resolve, reject) => {
1384
+ abortSignal.onabort = () => {
1385
+ const abortError = new Error("Upload aborted.");
1386
+ abortError.name = "AbortError";
1387
+ reject(abortError);
1388
+ };
1389
+ });
1390
+ }
1391
+ __validateUploadPart(dataPart) {
1392
+ const actualPartSize = byteLength(dataPart.data);
1393
+ if (actualPartSize === void 0) {
1394
+ throw new Error(`A dataPart was generated without a measurable data chunk size for part number ${dataPart.partNumber}`);
1395
+ }
1396
+ if (dataPart.partNumber === 1 && dataPart.lastPart) {
1397
+ return;
1398
+ }
1399
+ if (!dataPart.lastPart && actualPartSize !== this.partSize) {
1400
+ throw new Error(`The byte size for part number ${dataPart.partNumber}, size ${actualPartSize} does not match expected size ${this.partSize}`);
1401
+ }
1402
+ }
1403
+ __validateInput() {
1404
+ if (!this.client) {
1405
+ throw new Error(`InputError: Upload requires a AWS client to do uploads with.`);
1406
+ }
1407
+ if (this.partSize < _Upload.MIN_PART_SIZE) {
1408
+ throw new Error(`EntityTooSmall: Your proposed upload part size [${this.partSize}] is smaller than the minimum allowed size [${_Upload.MIN_PART_SIZE}] (5MB)`);
1409
+ }
1410
+ if (this.queueSize < 1) {
1411
+ throw new Error(`Queue size: Must have at least one uploading queue.`);
1412
+ }
1413
+ }
1414
+ };
1415
+ __publicField(_Upload, "MIN_PART_SIZE", 1024 * 1024 * 5);
1416
+ var Upload = _Upload;
1417
+ var AwsS3StoragePlugin = class {
1418
+ constructor() {
1419
+ this.id = "aws-s3";
1420
+ this.name = "AWS S3";
1421
+ this.version = "1.0.0";
1422
+ this.category = "storage";
1423
+ this.capabilities = [
1424
+ "storage",
1425
+ "put-object",
1426
+ "get-object",
1427
+ "presigned-put",
1428
+ // AW-22 — multipart upload and streamed download, so an object whose
1429
+ // size is not known up front (a workspace-backup archive) is bounded
1430
+ // by the bucket rather than by the API process's memory.
1431
+ "put-object-stream",
1432
+ "get-object-stream"
1433
+ ];
1434
+ this.providerName = "aws-s3";
1435
+ this.settingsSchema = {
1436
+ type: "object",
1437
+ properties: {
1438
+ region: {
1439
+ type: "string",
1440
+ title: "AWS Region",
1441
+ description: "Region of the S3 bucket (e.g. us-east-1).",
1442
+ "x-envVar": "AWS_S3_REGION"
1443
+ },
1444
+ bucket: {
1445
+ type: "string",
1446
+ title: "S3 Bucket",
1447
+ description: "Bucket name.",
1448
+ "x-envVar": "AWS_S3_BUCKET"
1449
+ },
1450
+ accessKeyId: {
1451
+ type: "string",
1452
+ title: "AWS Access Key Id",
1453
+ description: "IAM access key (omit to use the default credential chain).",
1454
+ "x-secret": true,
1455
+ "x-envVar": "AWS_ACCESS_KEY_ID"
1456
+ },
1457
+ secretAccessKey: {
1458
+ type: "string",
1459
+ title: "AWS Secret Access Key",
1460
+ description: "IAM secret (omit to use the default credential chain).",
1461
+ "x-secret": true,
1462
+ "x-envVar": "AWS_SECRET_ACCESS_KEY"
1463
+ },
1464
+ presignExpiresSeconds: {
1465
+ type: "number",
1466
+ title: "Presign URL TTL (seconds)",
1467
+ description: "How long pre-signed upload URLs stay valid. Default 600 (10 min).",
1468
+ default: 600,
1469
+ minimum: 60,
1470
+ maximum: 3600,
1471
+ "x-envVar": "AWS_S3_PRESIGN_EXPIRES_SECONDS"
1472
+ }
1473
+ },
1474
+ required: ["region", "bucket"]
1475
+ };
1476
+ }
1477
+ async putObject(input) {
1478
+ const cfg = this.config();
1479
+ const client = this.client(cfg);
1480
+ const key = this.buildKey(input.buffer, input.filename, input.ownerId);
1481
+ await client.send(
1482
+ new clientS3.PutObjectCommand({
1483
+ Bucket: cfg.bucket,
1484
+ Key: key,
1485
+ Body: input.buffer,
1486
+ ContentType: input.mimeType,
1487
+ ContentLength: input.size
1488
+ })
1489
+ );
1490
+ const url = this.objectUrl(cfg, key);
1491
+ return { key, url };
1492
+ }
1493
+ /**
1494
+ * AW-22 — upload from a stream via S3 multipart, using the SDK's own
1495
+ * `Upload` helper rather than a hand-rolled part loop.
1496
+ *
1497
+ * The key is random rather than content-addressed, exactly as
1498
+ * `presignPut` already is and for the same reason: the sha256 of the
1499
+ * bytes is not known until the last one arrives, and round-tripping a
1500
+ * multi-gigabyte archive through memory to learn it is the thing this
1501
+ * method exists to avoid. The caller computes and records the digest as
1502
+ * it writes, so the archive is still verifiable — see
1503
+ * `checksums.txt` and the `sha256` on the backup record.
1504
+ *
1505
+ * `Upload` aborts the multipart upload on failure, so a torn write does
1506
+ * not leave billable orphan parts in the bucket.
1507
+ */
1508
+ async putObjectStream(input) {
1509
+ const cfg = this.config();
1510
+ const client = this.client(cfg);
1511
+ const key = this.buildRandomKey(input.filename, input.ownerId);
1512
+ const upload = new Upload({
1513
+ client,
1514
+ params: {
1515
+ Bucket: cfg.bucket,
1516
+ Key: key,
1517
+ Body: input.stream,
1518
+ ContentType: input.mimeType
1519
+ },
1520
+ // 8 MiB parts: comfortably above S3's 5 MiB minimum, and small
1521
+ // enough that the in-flight window below stays modest.
1522
+ partSize: 8 * 1024 * 1024,
1523
+ queueSize: 4,
1524
+ leavePartsOnError: false
1525
+ });
1526
+ await upload.done();
1527
+ const url = this.objectUrl(cfg, key);
1528
+ return { key, url };
1529
+ }
1530
+ /**
1531
+ * AW-22 — hand the object's body back as a stream so a large archive is
1532
+ * piped to the client and never buffered. `size` comes from
1533
+ * `ContentLength`, which lets the caller set its own `Content-Length`
1534
+ * before the first byte leaves.
1535
+ */
1536
+ async getObjectStream(key) {
1537
+ const cfg = this.config();
1538
+ const client = this.client(cfg);
1539
+ const out = await client.send(new clientS3.GetObjectCommand({ Bucket: cfg.bucket, Key: key }));
1540
+ const body = out.Body;
1541
+ if (!body) {
1542
+ throw new Error(`S3 GetObject returned no body for key ${key}`);
1543
+ }
1544
+ const result = {
1545
+ stream: body,
1546
+ mimeType: out.ContentType || guessMime(key)
1547
+ };
1548
+ return typeof out.ContentLength === "number" ? { ...result, size: out.ContentLength } : result;
1549
+ }
1550
+ async getObject(key) {
1551
+ const cfg = this.config();
1552
+ const client = this.client(cfg);
1553
+ const out = await client.send(new clientS3.GetObjectCommand({ Bucket: cfg.bucket, Key: key }));
1554
+ const body = out.Body;
1555
+ if (!body) {
1556
+ throw new Error(`S3 GetObject returned no body for key ${key}`);
1557
+ }
1558
+ const buffer = await streamToBuffer(body);
1559
+ return {
1560
+ buffer,
1561
+ mimeType: out.ContentType || guessMime(key)
1562
+ };
1563
+ }
1564
+ async deleteObject(key) {
1565
+ const cfg = this.config();
1566
+ const client = this.client(cfg);
1567
+ await client.send(new clientS3.DeleteObjectCommand({ Bucket: cfg.bucket, Key: key }));
1568
+ }
1569
+ async presignPut(input) {
1570
+ const cfg = this.config();
1571
+ const client = this.client(cfg);
1572
+ const key = this.buildRandomKey(input.filename, input.ownerId);
1573
+ const url = await s3RequestPresigner.getSignedUrl(
1574
+ client,
1575
+ new clientS3.PutObjectCommand({
1576
+ Bucket: cfg.bucket,
1577
+ Key: key,
1578
+ ContentType: input.mimeType,
1579
+ ContentLength: input.size
1580
+ }),
1581
+ { expiresIn: cfg.presignExpiresSeconds }
1582
+ );
1583
+ const expiresAt = new Date(Date.now() + cfg.presignExpiresSeconds * 1e3).toISOString();
1584
+ return { url, key, expiresAt };
1585
+ }
1586
+ async isAvailable() {
1587
+ try {
1588
+ const cfg = this.config();
1589
+ const client = this.client(cfg);
1590
+ await client.send(new clientS3.HeadBucketCommand({ Bucket: cfg.bucket }));
1591
+ return true;
1592
+ } catch {
1593
+ return false;
1594
+ }
1595
+ }
1596
+ /**
1597
+ * S3 keys (and MinIO via inheritance) follow `uploads/<ownerId>/<filename>` —
1598
+ * see `buildKey`. The API's owner-gated read route hands us the
1599
+ * `<ownerId>/<filename>` segment from the URL; we re-prepend `uploads/`
1600
+ * so the GetObject call hits the right key.
1601
+ *
1602
+ * Without this method, `UploadsService.readFile` would fall back to
1603
+ * the legacy bare `<ownerId>/<filename>` shape and 404 every S3
1604
+ * read (Codex P1 finding on PR #890).
1605
+ */
1606
+ deriveKey(ownerId, filename) {
1607
+ return `uploads/${ownerId}/${filename}`;
1608
+ }
1609
+ /**
1610
+ * Delete every object under `uploads/<ownerId>/` — called by the
1611
+ * anon cleanup schedule when an anon user TTL expires. S3's
1612
+ * `DeleteObjects` accepts up to 1000 keys per call; we paginate
1613
+ * via `ListObjectsV2` with `ContinuationToken` until the prefix
1614
+ * is empty, deleting in batches.
1615
+ *
1616
+ * The MinIO plugin inherits this method via `extends`.
1617
+ */
1618
+ async deleteAllByOwner(ownerId) {
1619
+ const cfg = this.config();
1620
+ const client = this.client(cfg);
1621
+ const prefix = `uploads/${sanitizeOwner(ownerId)}/`;
1622
+ let deleted = 0;
1623
+ let continuationToken;
1624
+ do {
1625
+ const listOut = await client.send(
1626
+ new clientS3.ListObjectsV2Command({
1627
+ Bucket: cfg.bucket,
1628
+ Prefix: prefix,
1629
+ ContinuationToken: continuationToken,
1630
+ MaxKeys: 1e3
1631
+ })
1632
+ );
1633
+ const objects = listOut.Contents ?? [];
1634
+ if (objects.length > 0) {
1635
+ const out = await client.send(
1636
+ new clientS3.DeleteObjectsCommand({
1637
+ Bucket: cfg.bucket,
1638
+ Delete: {
1639
+ Objects: objects.filter((o) => typeof o.Key === "string").map((o) => ({ Key: o.Key })),
1640
+ Quiet: true
1641
+ }
1642
+ })
1643
+ );
1644
+ const errors = out.Errors ?? [];
1645
+ deleted += objects.length - errors.length;
1646
+ if (errors.length > 0) {
1647
+ this.context?.logger.warn?.(
1648
+ `${this.id} deleteAllByOwner: ${errors.length} of ${objects.length} keys failed for ${ownerId}`
1649
+ );
1650
+ }
1651
+ }
1652
+ continuationToken = listOut.IsTruncated ? listOut.NextContinuationToken : void 0;
1653
+ } while (continuationToken);
1654
+ return { deleted };
1655
+ }
1656
+ async onLoad(context) {
1657
+ this.context = context;
1658
+ context.logger.log("AWS S3 storage plugin loaded");
1659
+ }
1660
+ async onUnload() {
1661
+ this.context = void 0;
1662
+ if (this.cachedClient) {
1663
+ try {
1664
+ this.cachedClient.destroy();
1665
+ } catch {
1666
+ }
1667
+ this.cachedClient = void 0;
1668
+ this.cachedClientKey = void 0;
1669
+ }
1670
+ }
1671
+ async healthCheck() {
1672
+ const available = await this.isAvailable();
1673
+ return {
1674
+ status: available ? "healthy" : "unhealthy",
1675
+ message: available ? "S3 bucket reachable" : "S3 bucket not reachable (missing config or invalid credentials)",
1676
+ checkedAt: Date.now()
1677
+ };
1678
+ }
1679
+ getManifest() {
1680
+ return {
1681
+ id: this.id,
1682
+ name: this.name,
1683
+ version: this.version,
1684
+ description: "Stores uploaded objects in AWS S3, with presigned-PUT support.",
1685
+ category: this.category,
1686
+ capabilities: [...this.capabilities],
1687
+ builtIn: false,
1688
+ systemPlugin: false,
1689
+ icon: { type: "lucide", value: "Cloud", backgroundColor: "#ff9900" }
1690
+ };
1691
+ }
1692
+ // ============================================================================
1693
+ // Helpers
1694
+ // ============================================================================
1695
+ envOverrides() {
1696
+ return {};
1697
+ }
1698
+ config() {
1699
+ const overrides = this.envOverrides();
1700
+ const region = overrides.region ?? process.env.AWS_S3_REGION ?? "";
1701
+ const bucket = overrides.bucket ?? process.env.AWS_S3_BUCKET ?? "";
1702
+ const accessKeyId = overrides.accessKeyId ?? process.env.AWS_ACCESS_KEY_ID;
1703
+ const secretAccessKey = overrides.secretAccessKey ?? process.env.AWS_SECRET_ACCESS_KEY;
1704
+ const endpoint = overrides.endpoint;
1705
+ const forcePathStyle = overrides.forcePathStyle ?? false;
1706
+ const presignExpiresSeconds = overrides.presignExpiresSeconds ?? (Number(process.env.AWS_S3_PRESIGN_EXPIRES_SECONDS) || 600);
1707
+ if (!region || !bucket) {
1708
+ throw new Error(
1709
+ `${this.id} storage plugin not configured: region=${region || "<empty>"} bucket=${bucket || "<empty>"}`
1710
+ );
1711
+ }
1712
+ return {
1713
+ region,
1714
+ bucket,
1715
+ accessKeyId,
1716
+ secretAccessKey,
1717
+ endpoint,
1718
+ forcePathStyle,
1719
+ presignExpiresSeconds
1720
+ };
1721
+ }
1722
+ client(cfg) {
1723
+ const credentials = cfg.accessKeyId && cfg.secretAccessKey ? {
1724
+ accessKeyId: cfg.accessKeyId,
1725
+ secretAccessKey: cfg.secretAccessKey
1726
+ } : void 0;
1727
+ const credKey = credentials ? `${credentials.accessKeyId}:${credentials.secretAccessKey.length}` : "<default-chain>";
1728
+ const key = `${cfg.region}|${cfg.endpoint || ""}|${cfg.forcePathStyle ? "1" : "0"}|${credKey}`;
1729
+ if (this.cachedClient && this.cachedClientKey === key) {
1730
+ return this.cachedClient;
1731
+ }
1732
+ if (this.cachedClient) {
1733
+ try {
1734
+ this.cachedClient.destroy();
1735
+ } catch {
1736
+ }
1737
+ }
1738
+ const client = new clientS3.S3Client({
1739
+ region: cfg.region,
1740
+ credentials,
1741
+ endpoint: cfg.endpoint,
1742
+ forcePathStyle: cfg.forcePathStyle
1743
+ });
1744
+ this.cachedClient = client;
1745
+ this.cachedClientKey = key;
1746
+ return client;
1747
+ }
1748
+ buildKey(buffer, filename, ownerId) {
1749
+ const hash = crypto.createHash("sha256").update(buffer).digest("hex");
1750
+ const ext = sanitizeExt(filename);
1751
+ const owner = sanitizeOwner(ownerId);
1752
+ return `uploads/${owner}/${hash}${ext}`;
1753
+ }
1754
+ buildRandomKey(filename, ownerId) {
1755
+ const ext = sanitizeExt(filename);
1756
+ const owner = sanitizeOwner(ownerId);
1757
+ return `uploads/${owner}/${crypto.randomUUID()}${ext}`;
1758
+ }
1759
+ objectUrl(cfg, key) {
1760
+ if (cfg.endpoint) {
1761
+ const base = cfg.endpoint.replace(/\/$/, "");
1762
+ return `${base}/${cfg.bucket}/${key}`;
1763
+ }
1764
+ return `https://${cfg.bucket}.s3.${cfg.region}.amazonaws.com/${key}`;
1765
+ }
1766
+ };
1767
+ function sanitizeExt(filename) {
1768
+ const e = path.extname(filename || "").toLowerCase();
1769
+ if (!/^\.[a-z0-9]{1,8}$/.test(e)) return "";
1770
+ return e;
1771
+ }
1772
+ function sanitizeOwner(ownerId) {
1773
+ if (!ownerId) return "_shared";
1774
+ if (!/^[A-Za-z0-9_-]{1,128}$/.test(ownerId)) {
1775
+ throw new Error("Invalid ownerId for S3 storage");
1776
+ }
1777
+ return ownerId;
1778
+ }
1779
+ function guessMime(key) {
1780
+ const ext = path.extname(key).toLowerCase();
1781
+ switch (ext) {
1782
+ case ".png":
1783
+ return "image/png";
1784
+ case ".jpg":
1785
+ case ".jpeg":
1786
+ return "image/jpeg";
1787
+ case ".gif":
1788
+ return "image/gif";
1789
+ case ".webp":
1790
+ return "image/webp";
1791
+ case ".pdf":
1792
+ return "application/pdf";
1793
+ case ".txt":
1794
+ return "text/plain";
1795
+ case ".json":
1796
+ return "application/json";
1797
+ default:
1798
+ return "application/octet-stream";
1799
+ }
1800
+ }
1801
+ async function streamToBuffer(stream) {
1802
+ const chunks = [];
1803
+ return await new Promise((resolveP, rejectP) => {
1804
+ stream.on("data", (chunk) => {
1805
+ chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
1806
+ });
1807
+ stream.on("end", () => resolveP(Buffer.concat(chunks)));
1808
+ stream.on("error", rejectP);
1809
+ });
1810
+ }
1811
+
1812
+ // src/minio.plugin.ts
1813
+ var MinioStoragePlugin = class extends AwsS3StoragePlugin {
1814
+ constructor() {
1815
+ super(...arguments);
1816
+ this.id = "minio";
1817
+ this.name = "MinIO";
1818
+ this.category = "storage";
1819
+ this.providerName = "minio";
1820
+ this.settingsSchema = {
1821
+ type: "object",
1822
+ properties: {
1823
+ endpoint: {
1824
+ type: "string",
1825
+ title: "MinIO Endpoint",
1826
+ description: "Full endpoint URL (e.g. https://minio.example.com:9000).",
1827
+ "x-envVar": "MINIO_ENDPOINT"
1828
+ },
1829
+ region: {
1830
+ type: "string",
1831
+ title: "Region Label",
1832
+ description: "Region string sent in S3 requests. MinIO ignores it (default us-east-1).",
1833
+ default: "us-east-1",
1834
+ "x-envVar": "MINIO_REGION"
1835
+ },
1836
+ bucket: {
1837
+ type: "string",
1838
+ title: "Bucket",
1839
+ description: "MinIO bucket name.",
1840
+ "x-envVar": "MINIO_BUCKET"
1841
+ },
1842
+ accessKey: {
1843
+ type: "string",
1844
+ title: "Access Key",
1845
+ description: "MinIO access key.",
1846
+ "x-secret": true,
1847
+ "x-envVar": "MINIO_ACCESS_KEY"
1848
+ },
1849
+ secretKey: {
1850
+ type: "string",
1851
+ title: "Secret Key",
1852
+ description: "MinIO secret key.",
1853
+ "x-secret": true,
1854
+ "x-envVar": "MINIO_SECRET_KEY"
1855
+ },
1856
+ presignExpiresSeconds: {
1857
+ type: "number",
1858
+ title: "Presign URL TTL (seconds)",
1859
+ description: "How long pre-signed upload URLs stay valid. Default 600 (10 min).",
1860
+ default: 600,
1861
+ minimum: 60,
1862
+ maximum: 3600,
1863
+ "x-envVar": "MINIO_PRESIGN_EXPIRES_SECONDS"
1864
+ }
1865
+ },
1866
+ required: ["endpoint", "bucket"]
1867
+ };
1868
+ }
1869
+ envOverrides() {
1870
+ const endpoint = process.env.MINIO_ENDPOINT;
1871
+ if (!endpoint) {
1872
+ throw new Error("MINIO_ENDPOINT is not set");
1873
+ }
1874
+ return {
1875
+ endpoint,
1876
+ region: process.env.MINIO_REGION || "us-east-1",
1877
+ bucket: process.env.MINIO_BUCKET || "",
1878
+ accessKeyId: process.env.MINIO_ACCESS_KEY,
1879
+ secretAccessKey: process.env.MINIO_SECRET_KEY,
1880
+ forcePathStyle: true,
1881
+ presignExpiresSeconds: Number(process.env.MINIO_PRESIGN_EXPIRES_SECONDS) || 600
1882
+ };
1883
+ }
1884
+ async onLoad(context) {
1885
+ await super.onLoad(context);
1886
+ context.logger.log("MinIO storage plugin loaded");
1887
+ }
1888
+ getManifest() {
1889
+ return {
1890
+ id: this.id,
1891
+ name: this.name,
1892
+ version: this.version,
1893
+ description: "Self-hosted S3-compatible storage backend (MinIO).",
1894
+ category: this.category,
1895
+ capabilities: [...this.capabilities],
1896
+ builtIn: false,
1897
+ systemPlugin: false,
1898
+ icon: { type: "lucide", value: "Server", backgroundColor: "#c72e29" }
1899
+ };
1900
+ }
1901
+ };
1902
+
1903
+ exports.MinioStoragePlugin = MinioStoragePlugin;
1904
+ exports.default = MinioStoragePlugin;