@bymax-one/nest-storage 1.1.19 → 1.1.20
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/CHANGELOG.md +70 -1
- package/README.md +26 -7
- package/dist/server/index.cjs +99 -42
- package/dist/server/index.d.cts +18 -5
- package/dist/server/index.d.ts +18 -5
- package/dist/server/index.mjs +99 -42
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -13,6 +13,74 @@ note on each entry is the compatibility contract — read it, not the number.
|
|
|
13
13
|
|
|
14
14
|
## [Unreleased]
|
|
15
15
|
|
|
16
|
+
## [1.1.20] - 2026-11-21
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- **A throwing `onProgress` no longer fails an upload that stored its object.** On the single-shot path the hook was
|
|
21
|
+
called in the upload's own `try` block, so a hook that threw made `upload()` reject with `STORAGE_PROVIDER_ERROR`
|
|
22
|
+
after `PutObject` had succeeded; on the multipart path a throw reached the uploader. An async hook that rejected was
|
|
23
|
+
an unhandled rejection that ends the Node process. Both paths now ignore what the hook throws or rejects with.
|
|
24
|
+
|
|
25
|
+
**Apply to a derived backend:** nothing to change. A hook that threw used to turn a stored upload into an error; it
|
|
26
|
+
now leaves the result alone, so an application that relied on a throwing hook to fail an upload must fail it itself.
|
|
27
|
+
|
|
28
|
+
- **An option that throws when it is read is refused with `STORAGE_INVALID_CONFIG`.** A getter or a Proxy of the
|
|
29
|
+
host's as the options object, a group or a validator, and a `then` that throws on the object a `useFactory` returns,
|
|
30
|
+
surfaced the host's own error from `forRoot` and `forRootAsync`. They now fail `STORAGE_INVALID_CONFIG`
|
|
31
|
+
(`reason: 'the options could not be read'`), the host's error is kept as the `cause` of the exception and none of
|
|
32
|
+
its text is in the response, and a whitelist or a validator list whose iterator throws is refused the same way instead
|
|
33
|
+
of as "must be an array of strings". `StorageException` takes an optional `cause`.
|
|
34
|
+
|
|
35
|
+
**Apply to a derived backend:** a factory that throws is now reported as `STORAGE_INVALID_CONFIG` with the
|
|
36
|
+
factory's error as the `cause`; read `cause` where you matched the raw error.
|
|
37
|
+
|
|
38
|
+
- **A lone surrogate in a logged value is escaped.** `escapeForLog` left a lone surrogate (`\ud800`) as it was, and a
|
|
39
|
+
logger writes it as an invalid character. It shows as `\ud800` now, like the other characters that cannot be shown;
|
|
40
|
+
a well-formed pair, an emoji, stays readable.
|
|
41
|
+
|
|
42
|
+
**Apply to a derived backend:** nothing to change; a log rule that matched the raw character reads the escape.
|
|
43
|
+
|
|
44
|
+
- **A very large sum of uploaded bytes no longer fails the metrics scrape.** `bymax_storage_bytes_uploaded_total` is
|
|
45
|
+
the sum of every object's size, and two finite sizes can add up past the largest number, to `Infinity`, which a
|
|
46
|
+
counter refuses: the whole `/metrics` answer then failed. The count in the tally now stops at the largest finite
|
|
47
|
+
number.
|
|
48
|
+
|
|
49
|
+
**Apply to a derived backend:** nothing to change; a scrape that failed on that sum now answers.
|
|
50
|
+
|
|
51
|
+
- **The README names what the multipart path does on a failure.** It said the SDK aborts the upload
|
|
52
|
+
(`leavePartsOnError: false`); the library passes `true` and sends `AbortMultipartUpload` itself, so a failing abort
|
|
53
|
+
cannot replace the error that caused it, and the outcome is in `details.abort`.
|
|
54
|
+
|
|
55
|
+
**Apply to a derived backend:** nothing to change; only the text was wrong.
|
|
56
|
+
|
|
57
|
+
### Changed
|
|
58
|
+
|
|
59
|
+
- **The span attributes are named, and the scan span takes the two scan modes.** `StorageSpanAttributes` was
|
|
60
|
+
`Readonly<Record<string, string>>`; it is now an interface naming the attributes the library sets, so a call site cannot add a key
|
|
61
|
+
that carries a bucket or a payload, and the scan span's `mode` parameter is `'pre-upload' | 'post-upload'` instead of
|
|
62
|
+
`string`.
|
|
63
|
+
|
|
64
|
+
**Apply to a derived backend:** code that calls the scan span with a mode the interface does not declare, that builds
|
|
65
|
+
attributes with another key, or that reads an attribute by a key it does not declare does not compile against the
|
|
66
|
+
interface; use the declared modes and names. Nothing changes at run time.
|
|
67
|
+
|
|
68
|
+
- **`defaultPublicRead` and `forcePathStyle` must be booleans, and so must a per-call `publicRead`.** A string from an
|
|
69
|
+
environment variable, `'false'`, is truthy: it passed the `??` default and made every upload `public-read`. A value
|
|
70
|
+
of another kind for either option is now refused at boot with `STORAGE_INVALID_CONFIG`, and a per-call `publicRead`
|
|
71
|
+
that is set and is not a boolean fails that call with `STORAGE_VALIDATION_FAILED` (`details.field: 'publicRead'`);
|
|
72
|
+
`null` is refused like any other non-boolean, and an absent value still takes the default.
|
|
73
|
+
|
|
74
|
+
**Apply to a derived backend:** a host that passes `process.env.X` straight into either option now gets a boot
|
|
75
|
+
refusal; compare it to `'true'` and pass the boolean.
|
|
76
|
+
|
|
77
|
+
- **`validation.mimeWhitelist` and `validation.customValidators` hold at most 1000 entries.** A longer array, or an
|
|
78
|
+
array whose reported length is not a count, is refused at boot with `STORAGE_INVALID_CONFIG` before any entry is
|
|
79
|
+
read, so a sparse array of billions of holes no longer stalls the start.
|
|
80
|
+
|
|
81
|
+
**Apply to a derived backend:** nothing to change unless a list holds more than 1000 entries; a whitelist that long
|
|
82
|
+
can use a wildcard instead.
|
|
83
|
+
|
|
16
84
|
## [1.1.19] - 2026-11-20
|
|
17
85
|
|
|
18
86
|
### Added
|
|
@@ -1183,4 +1251,5 @@ have regressed from. They are kept because the reasoning is worth having.
|
|
|
1183
1251
|
[1.1.17]: https://github.com/bymaxone/nest-storage/compare/v1.1.16...v1.1.17
|
|
1184
1252
|
[1.1.18]: https://github.com/bymaxone/nest-storage/compare/v1.1.17...v1.1.18
|
|
1185
1253
|
[1.1.19]: https://github.com/bymaxone/nest-storage/compare/v1.1.18...v1.1.19
|
|
1186
|
-
[
|
|
1254
|
+
[1.1.20]: https://github.com/bymaxone/nest-storage/compare/v1.1.19...v1.1.20
|
|
1255
|
+
[Unreleased]: https://github.com/bymaxone/nest-storage/compare/v1.1.20...HEAD
|
package/README.md
CHANGED
|
@@ -58,8 +58,8 @@ minimal.
|
|
|
58
58
|
|
|
59
59
|
## 🔥 Features
|
|
60
60
|
|
|
61
|
-
- ✅ **Multipart upload** — `@aws-sdk/lib-storage` with
|
|
62
|
-
|
|
61
|
+
- ✅ **Multipart upload** — `@aws-sdk/lib-storage` with an abort on failure that the library runs
|
|
62
|
+
itself, progress events, and a configurable threshold and part size
|
|
63
63
|
- ✅ **Content validation** — MIME allowlist with wildcards (`image/*`) and a size limit, then any
|
|
64
64
|
number of `IUploadValidator`s, all refused before a byte is stored
|
|
65
65
|
- ✅ **Virus scanning hook** — `IFileScanner` pre-upload or post-upload, for ClamAV, AWS Macie or
|
|
@@ -107,8 +107,8 @@ All subpaths ship ESM **and** CommonJS with declarations for each format, so a
|
|
|
107
107
|
|
|
108
108
|
| Subpath | Required peers |
|
|
109
109
|
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
110
|
-
| `.` (server) | `@nestjs/common ^11.0.16`, `@nestjs/core ^11.1.18`, `@aws-sdk/client-s3 ^3.700`, `@aws-sdk/lib-storage ^3.700`, `@aws-sdk/s3-request-presigner ^3.700`, `reflect-metadata ^0.2` |
|
|
111
|
-
| `./observability` | `@bymax-one/nest-core >=1.6.15`
|
|
110
|
+
| `.` (server) | `@nestjs/common ^11.0.16`, `@nestjs/core ^11.1.18`, `@aws-sdk/client-s3 ^3.700`, `@aws-sdk/lib-storage ^3.700`, `@aws-sdk/s3-request-presigner ^3.700`, `reflect-metadata ^0.2`; optional: `@opentelemetry/api ^1.9` (the spans start only when it is installed) |
|
|
111
|
+
| `./observability` | The peers of `.`, and `prom-client ^15` for the metrics; `@bymax-one/nest-core >=1.6.15` is how a host discovers the two classes. `prom-client` and `@bymax-one/nest-core` are optional for the package, needed only to use this subpath |
|
|
112
112
|
| `./shared` | None |
|
|
113
113
|
|
|
114
114
|
---
|
|
@@ -354,8 +354,9 @@ await storage.upload({
|
|
|
354
354
|
`onProgress` receives `{ loaded, total?, part? }`: the bytes sent so far, the total when it is known, and the
|
|
355
355
|
part number on a multipart upload. A single-shot upload reports once, when it ends; a multipart upload reports
|
|
356
356
|
as each part is sent.
|
|
357
|
+
A hook that throws, or an async one that rejects, is ignored: the upload still resolves with its result and the process is not ended.
|
|
357
358
|
|
|
358
|
-
Uploads are automatically routed to multipart when `size >= multipart.thresholdBytes` (default 5 MiB). A `Readable` without a `size` always uses multipart.
|
|
359
|
+
Uploads are automatically routed to multipart when `size >= multipart.thresholdBytes` (default 5 MiB). A `Readable` without a `size` always uses multipart. A failed multipart upload is aborted by the library, which tells the SDK to leave the parts (`leavePartsOnError: true`) and runs `AbortMultipartUpload` itself, so an abort that fails cannot replace the error that caused it; the outcome (`completed` or `failed`) is in the error's `details.abort`.
|
|
359
360
|
|
|
360
361
|
**What `body` may be.** A `Buffer`, a `Uint8Array`, an `ArrayBuffer`, a string or a Node `Readable`. Anything else (a `Blob`, an array of chunks, a plain object) fails with `STORAGE_VALIDATION_FAILED` (`details.field: 'body'`) before any request; it used to reach the upload as if it were a stream and fail as `STORAGE_MULTIPART_ABORTED` (500).
|
|
361
362
|
|
|
@@ -911,12 +912,23 @@ message is ever a label:
|
|
|
911
912
|
last byte. A result returned from the idempotency cache counts as an upload but adds no bytes. The bytes are the ones the transfer sent: a stream without a declared `size` is counted too, and a `size` the stream did not reach is not; a failed upload adds none. The counters start
|
|
912
913
|
with the module; the histogram starts when `StorageMetrics` registers.
|
|
913
914
|
|
|
915
|
+
`delete_many` reports how it ended as a call, not per key: `deleteMany()` returns the keys that failed instead of
|
|
916
|
+
throwing, so a call in which every key failed is counted as `success`; read `failed` in its result for that. A `head`
|
|
917
|
+
of a bucket that does not exist is answered 404 by the provider as it is for a missing object, and is counted as
|
|
918
|
+
`not_found`.
|
|
919
|
+
|
|
920
|
+
`StorageMetricsTally` is what the metrics read, and the library writes to it as it works: `operation(operation,
|
|
921
|
+
outcome, seconds)` and `scan(verdict)` count, `bytesUploaded(bytes)` adds to the byte counter, `onDuration(listener)`
|
|
922
|
+
hands the listener the duration of every operation that ends from then on, and `snapshot()` returns the counts so
|
|
923
|
+
far as copies. A host that publishes its own metrics reads `snapshot()`.
|
|
924
|
+
|
|
914
925
|
### Readiness
|
|
915
926
|
|
|
916
927
|
`StorageHealthIndicator` reports under the name `storage`. It asks `StorageService.checkBucket()` for one
|
|
917
928
|
`HeadBucket` and answers `up` or `down` with no detail, so nothing about the bucket, the region or the endpoint
|
|
918
929
|
leaves with it. The probe has its own deadline, the answer is kept, and checks that arrive
|
|
919
|
-
while one is running share it. The probe is counted as `check_bucket`.
|
|
930
|
+
while one is running share it. The probe is counted as `check_bucket`. The answer lags the bucket's real state by up to the 5 seconds it is kept plus the 2 seconds the probe may take,
|
|
931
|
+
so a bucket that stops answering can still read `up` for up to 7 seconds.
|
|
920
932
|
|
|
921
933
|
### Spans
|
|
922
934
|
|
|
@@ -1172,7 +1184,14 @@ supply through it first: the guard below, then `keyPrefix`.
|
|
|
1172
1184
|
`deleteMany` result all omit the prefix, so any of them can be passed straight back to `head`,
|
|
1173
1185
|
`download`, `delete`, `copy` or a signed-URL call, which prepend it once. `UploadResult.publicUrl`
|
|
1174
1186
|
is the one full value: it is a URL, and the prefix is part of the object's real path. Error
|
|
1175
|
-
`details` carry the
|
|
1187
|
+
`details` carry the `key` you passed, without the prefix (see "What `details` repeats").
|
|
1188
|
+
|
|
1189
|
+
**The fields of the results.** `UploadResult` holds `key`, `bucket`, `etag`, `contentType`, `publicUrl`, `multipart`
|
|
1190
|
+
and `fromIdempotencyCache`, and `size` and `versionId` when known (`versionId` only on a versioned bucket).
|
|
1191
|
+
`ObjectMetadata` (from `head` and `download`) holds `key`, `bucket`, `size`, `contentType`, `etag`, `lastModified`
|
|
1192
|
+
and `metadata` (the `x-amz-meta-*` pairs), and `cacheControl`, `contentDisposition`, `storageClass` and `versionId`
|
|
1193
|
+
when the provider reports them. A `ListedObject` holds `key`, `size`, `etag` and `lastModified`, and `storageClass`
|
|
1194
|
+
when reported.
|
|
1176
1195
|
|
|
1177
1196
|
### Exported types and constants
|
|
1178
1197
|
|
package/dist/server/index.cjs
CHANGED
|
@@ -130,7 +130,7 @@ var STORAGE_ERROR_STATUS = {
|
|
|
130
130
|
// src/server/errors/storage-exception.ts
|
|
131
131
|
var StorageException = class extends common.HttpException {
|
|
132
132
|
code;
|
|
133
|
-
constructor(code, statusCode = STORAGE_ERROR_STATUS[code], details, message = STORAGE_ERROR_MESSAGES[code]) {
|
|
133
|
+
constructor(code, statusCode = STORAGE_ERROR_STATUS[code], details, message = STORAGE_ERROR_MESSAGES[code], cause) {
|
|
134
134
|
super(
|
|
135
135
|
{
|
|
136
136
|
error: {
|
|
@@ -139,7 +139,8 @@ var StorageException = class extends common.HttpException {
|
|
|
139
139
|
...details ? { details } : {}
|
|
140
140
|
}
|
|
141
141
|
},
|
|
142
|
-
statusCode
|
|
142
|
+
statusCode,
|
|
143
|
+
{ cause }
|
|
143
144
|
);
|
|
144
145
|
this.code = code;
|
|
145
146
|
}
|
|
@@ -183,15 +184,31 @@ function assertMetadata(metadata) {
|
|
|
183
184
|
}
|
|
184
185
|
}
|
|
185
186
|
|
|
187
|
+
// src/server/config/option-array-bound.ts
|
|
188
|
+
var MAX_OPTION_ARRAY_LENGTH = 1e3;
|
|
189
|
+
function isBoundedLength(length) {
|
|
190
|
+
return typeof length === "number" && Number.isInteger(length) && length >= 0 && length <= MAX_OPTION_ARRAY_LENGTH;
|
|
191
|
+
}
|
|
192
|
+
|
|
186
193
|
// src/server/config/validate-options.ts
|
|
187
194
|
var MIN_PART_SIZE_BYTES = 5 * 1024 * 1024;
|
|
188
195
|
var MAX_PART_SIZE_BYTES = 5 * 1024 * 1024 * 1024;
|
|
189
196
|
var MAX_QUEUE_SIZE = 1e3;
|
|
190
197
|
var REGION_SHAPE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,62}$/;
|
|
198
|
+
var OWN_REFUSALS = /* @__PURE__ */ new WeakSet();
|
|
199
|
+
function isOwnRefusal(error) {
|
|
200
|
+
return typeof error === "object" && error !== null && OWN_REFUSALS.has(error);
|
|
201
|
+
}
|
|
191
202
|
function invalid(reason) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
203
|
+
const refusal = new StorageException(
|
|
204
|
+
STORAGE_ERROR_CODES.STORAGE_INVALID_CONFIG,
|
|
205
|
+
common.HttpStatus.INTERNAL_SERVER_ERROR,
|
|
206
|
+
{
|
|
207
|
+
reason
|
|
208
|
+
}
|
|
209
|
+
);
|
|
210
|
+
OWN_REFUSALS.add(refusal);
|
|
211
|
+
return refusal;
|
|
195
212
|
}
|
|
196
213
|
function isObject(value) {
|
|
197
214
|
return typeof value === "object" && value !== null;
|
|
@@ -262,32 +279,35 @@ function assertValidationKinds(validation) {
|
|
|
262
279
|
if (mimeWhitelist === null) {
|
|
263
280
|
throw invalid("validation.mimeWhitelist must not be null; omit it to allow every type");
|
|
264
281
|
}
|
|
282
|
+
assertBoundedArray("mimeWhitelist", mimeWhitelist);
|
|
265
283
|
if (mimeWhitelist !== void 0 && !isStringArray(mimeWhitelist)) {
|
|
266
284
|
throw invalid("validation.mimeWhitelist must be an array of strings");
|
|
267
285
|
}
|
|
268
286
|
if (customValidators === null) {
|
|
269
|
-
throw invalid(
|
|
287
|
+
throw invalid(
|
|
288
|
+
"validation.customValidators must not be null; omit it to run no custom validator"
|
|
289
|
+
);
|
|
270
290
|
}
|
|
271
291
|
if (customValidators !== void 0 && !Array.isArray(customValidators)) {
|
|
272
292
|
throw invalid("validation.customValidators must be an array");
|
|
273
293
|
}
|
|
294
|
+
assertBoundedArray("customValidators", customValidators);
|
|
274
295
|
if (customValidators !== void 0 && !isValidatorList(customValidators)) {
|
|
275
296
|
throw invalid("validation.customValidators must hold objects with a validate function");
|
|
276
297
|
}
|
|
277
298
|
}
|
|
278
|
-
function
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
} catch {
|
|
282
|
-
return false;
|
|
299
|
+
function assertBoundedArray(name, value) {
|
|
300
|
+
if (Array.isArray(value) && !isBoundedLength(value.length)) {
|
|
301
|
+
throw invalid(`validation.${name} must hold at most ${String(MAX_OPTION_ARRAY_LENGTH)} entries`);
|
|
283
302
|
}
|
|
284
303
|
}
|
|
304
|
+
function isStringArray(value) {
|
|
305
|
+
return Array.isArray(value) && Array.from(value).every((entry) => typeof entry === "string");
|
|
306
|
+
}
|
|
285
307
|
function isValidatorList(entries) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return false;
|
|
290
|
-
}
|
|
308
|
+
return Array.from(entries).every(
|
|
309
|
+
(entry) => isObject(entry) && typeof entry.validate === "function"
|
|
310
|
+
);
|
|
291
311
|
}
|
|
292
312
|
function assertGroupKinds(options) {
|
|
293
313
|
for (const group of ["signedUrls", "multipart", "validation"]) {
|
|
@@ -327,6 +347,11 @@ function assertLimitsAndEncryption(options) {
|
|
|
327
347
|
if (options.serverSideEncryption === "aws:kms" && !options.kmsKeyId) {
|
|
328
348
|
throw invalid('kmsKeyId is required when serverSideEncryption === "aws:kms"');
|
|
329
349
|
}
|
|
350
|
+
for (const name of ["defaultPublicRead", "forcePathStyle"]) {
|
|
351
|
+
if (options[name] !== void 0 && typeof options[name] !== "boolean") {
|
|
352
|
+
throw invalid(`options.${name} must be a boolean`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
330
355
|
for (const name of ["defaultCacheControl", "kmsKeyId"]) {
|
|
331
356
|
if (options[name] !== void 0 && !isHeaderValue(options[name])) {
|
|
332
357
|
throw invalid(`options.${name} must be a string of tab, space and printable ASCII characters`);
|
|
@@ -515,12 +540,7 @@ function pickGroup(value, keys) {
|
|
|
515
540
|
return isObject2(value) && !Array.isArray(value) ? pick(value, keys) : value;
|
|
516
541
|
}
|
|
517
542
|
function copyArray(value) {
|
|
518
|
-
|
|
519
|
-
try {
|
|
520
|
-
return Array.from(value);
|
|
521
|
-
} catch {
|
|
522
|
-
return value;
|
|
523
|
-
}
|
|
543
|
+
return Array.isArray(value) && isBoundedLength(value.length) ? Array.from(value) : value;
|
|
524
544
|
}
|
|
525
545
|
var GROUPS = {
|
|
526
546
|
credentials: CREDENTIAL_KEYS,
|
|
@@ -786,10 +806,14 @@ exports.StorageMetricsTally = class StorageMetricsTally {
|
|
|
786
806
|
__privateGet(this, _operations)[operation][outcome] += 1;
|
|
787
807
|
for (const listener of __privateGet(this, _listeners)) absorb(() => listener(operation, seconds));
|
|
788
808
|
}
|
|
789
|
-
/**
|
|
809
|
+
/**
|
|
810
|
+
* `bytes` of an object reached the provider; anything that is not a positive finite number is ignored. The
|
|
811
|
+
* count stops at the largest finite number: a sum of two finite sizes can overflow to `Infinity`, which no
|
|
812
|
+
* counter accepts, and a scrape that read it would fail whole.
|
|
813
|
+
*/
|
|
790
814
|
bytesUploaded(bytes) {
|
|
791
815
|
if (typeof bytes === "number" && Number.isFinite(bytes) && bytes > 0)
|
|
792
|
-
__privateSet(this, _bytesUploaded, __privateGet(this, _bytesUploaded) + bytes);
|
|
816
|
+
__privateSet(this, _bytesUploaded, Math.min(__privateGet(this, _bytesUploaded) + bytes, Number.MAX_VALUE));
|
|
793
817
|
}
|
|
794
818
|
/** A scan ended as `verdict`. */
|
|
795
819
|
scan(verdict) {
|
|
@@ -1100,7 +1124,7 @@ function describeError(value) {
|
|
|
1100
1124
|
}
|
|
1101
1125
|
|
|
1102
1126
|
// src/server/utils/log-value.ts
|
|
1103
|
-
var LEFT_LITERAL_BY_JSON = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu;
|
|
1127
|
+
var LEFT_LITERAL_BY_JSON = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Cs}]/gu;
|
|
1104
1128
|
var SHORT_ESCAPES = {
|
|
1105
1129
|
"\b": "\\b",
|
|
1106
1130
|
"\f": "\\f",
|
|
@@ -2431,6 +2455,12 @@ function buildSSE(perCall, perCallKmsKeyId, module) {
|
|
|
2431
2455
|
return { ServerSideEncryption: sse };
|
|
2432
2456
|
}
|
|
2433
2457
|
function buildACL(perCall, defaultValue) {
|
|
2458
|
+
if (perCall !== void 0 && typeof perCall !== "boolean") {
|
|
2459
|
+
throw new StorageException(STORAGE_ERROR_CODES.STORAGE_VALIDATION_FAILED, void 0, {
|
|
2460
|
+
field: "publicRead",
|
|
2461
|
+
reason: "must be a boolean"
|
|
2462
|
+
});
|
|
2463
|
+
}
|
|
2434
2464
|
return perCall ?? defaultValue ? "public-read" : void 0;
|
|
2435
2465
|
}
|
|
2436
2466
|
|
|
@@ -2581,11 +2611,14 @@ function buildUploadResult(keyResolver, options, params) {
|
|
|
2581
2611
|
};
|
|
2582
2612
|
}
|
|
2583
2613
|
function emitProgress(onProgress, loaded, total, part) {
|
|
2584
|
-
onProgress
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2614
|
+
const hook = onProgress;
|
|
2615
|
+
absorb(
|
|
2616
|
+
() => hook({
|
|
2617
|
+
loaded: loaded ?? 0,
|
|
2618
|
+
...total !== void 0 ? { total } : {},
|
|
2619
|
+
...part !== void 0 ? { part } : {}
|
|
2620
|
+
})
|
|
2621
|
+
);
|
|
2589
2622
|
}
|
|
2590
2623
|
function putObjectHeaders(options, resolved, finalKey, bucket) {
|
|
2591
2624
|
return {
|
|
@@ -2657,17 +2690,18 @@ function uploadedBytesOf(result) {
|
|
|
2657
2690
|
return result.fromIdempotencyCache ? void 0 : SENT.get(result) ?? result.size;
|
|
2658
2691
|
}
|
|
2659
2692
|
async function uploadSingleShot(context, options, finalKey, bucket, caller) {
|
|
2693
|
+
const { onProgress, contentType, abortSignal } = options;
|
|
2660
2694
|
const total = options.size ?? getBodySize(options.body);
|
|
2661
2695
|
const input = {
|
|
2662
2696
|
...putObjectHeaders(options, context.options, finalKey, bucket),
|
|
2663
2697
|
Body: normalizeSingleShotBody(options.body),
|
|
2664
2698
|
ContentLength: total
|
|
2665
2699
|
};
|
|
2666
|
-
const watch = abortOnBodyFailure(input.Body,
|
|
2700
|
+
const watch = abortOnBodyFailure(input.Body, abortSignal);
|
|
2667
2701
|
try {
|
|
2668
2702
|
const response = await context.s3Provider.getClient().send(new clientS3.PutObjectCommand(input), sendOptions(watch.signal));
|
|
2669
|
-
if (
|
|
2670
|
-
emitProgress(
|
|
2703
|
+
if (onProgress) {
|
|
2704
|
+
emitProgress(onProgress, total, total);
|
|
2671
2705
|
}
|
|
2672
2706
|
return buildUploadResult(context.keyResolver, context.options, {
|
|
2673
2707
|
finalKey,
|
|
@@ -2675,13 +2709,13 @@ async function uploadSingleShot(context, options, finalKey, bucket, caller) {
|
|
|
2675
2709
|
etag: response.ETag,
|
|
2676
2710
|
versionId: response.VersionId,
|
|
2677
2711
|
size: total,
|
|
2678
|
-
contentType
|
|
2712
|
+
contentType,
|
|
2679
2713
|
multipart: false
|
|
2680
2714
|
});
|
|
2681
2715
|
} catch (err) {
|
|
2682
2716
|
const context2 = { ...caller, op: "upload-single" };
|
|
2683
2717
|
const mapped = mapSizeLimitError(watch.failure(), context2) ?? mapAwsError(err, context2);
|
|
2684
|
-
throw failureOrAbort(
|
|
2718
|
+
throw failureOrAbort(abortSignal, context2, mapped);
|
|
2685
2719
|
}
|
|
2686
2720
|
}
|
|
2687
2721
|
|
|
@@ -3123,6 +3157,7 @@ exports.StorageService = class StorageService {
|
|
|
3123
3157
|
const destKey = this.keyResolver.normalize(options.destinationKey);
|
|
3124
3158
|
const sourceBucket = this.resolveBucket(options.sourceBucket);
|
|
3125
3159
|
const destBucket = this.resolveBucket(options.destinationBucket);
|
|
3160
|
+
const acl = buildACL(options.publicRead, this.options.defaultPublicRead);
|
|
3126
3161
|
try {
|
|
3127
3162
|
const response = await this.s3Provider.getClient().send(
|
|
3128
3163
|
new clientS3.CopyObjectCommand({
|
|
@@ -3133,7 +3168,7 @@ exports.StorageService = class StorageService {
|
|
|
3133
3168
|
CopySource: `/${sourceBucket}/${sourceKey.split("/").map(encodeURIComponent).join("/")}`,
|
|
3134
3169
|
CacheControl: options.cacheControl ?? this.options.defaultCacheControl,
|
|
3135
3170
|
// ACLs are a no-op on modern S3 (Object Ownership) and R2; see header-utils.
|
|
3136
|
-
ACL:
|
|
3171
|
+
ACL: acl,
|
|
3137
3172
|
MetadataDirective: "COPY"
|
|
3138
3173
|
})
|
|
3139
3174
|
);
|
|
@@ -3174,7 +3209,7 @@ exports.StorageService = class StorageService {
|
|
|
3174
3209
|
__decorateClass([
|
|
3175
3210
|
Observed("upload", {
|
|
3176
3211
|
span: "storage.upload",
|
|
3177
|
-
describe: (result) => ({ "bymax.storage.multipart":
|
|
3212
|
+
describe: (result) => ({ "bymax.storage.multipart": result.multipart ? "true" : "false" }),
|
|
3178
3213
|
bytes: uploadedBytesOf
|
|
3179
3214
|
})
|
|
3180
3215
|
], exports.StorageService.prototype, "upload", 1);
|
|
@@ -3507,7 +3542,31 @@ var IdempotencyCache = class {
|
|
|
3507
3542
|
};
|
|
3508
3543
|
|
|
3509
3544
|
// src/server/bymax-storage.module.ts
|
|
3545
|
+
function refuseUnreadable(error) {
|
|
3546
|
+
if (isOwnRefusal(error)) throw error;
|
|
3547
|
+
throw new StorageException(
|
|
3548
|
+
STORAGE_ERROR_CODES.STORAGE_INVALID_CONFIG,
|
|
3549
|
+
void 0,
|
|
3550
|
+
{ reason: "the options could not be read" },
|
|
3551
|
+
void 0,
|
|
3552
|
+
error
|
|
3553
|
+
);
|
|
3554
|
+
}
|
|
3510
3555
|
function resolveAsyncOptions(raw) {
|
|
3556
|
+
try {
|
|
3557
|
+
return resolveOptions(raw);
|
|
3558
|
+
} catch (error) {
|
|
3559
|
+
return refuseUnreadable(error);
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3562
|
+
async function resolveProducedOptions(produce) {
|
|
3563
|
+
try {
|
|
3564
|
+
return resolveOptions(await produce());
|
|
3565
|
+
} catch (error) {
|
|
3566
|
+
return refuseUnreadable(error);
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
function resolveOptions(raw) {
|
|
3511
3570
|
const options = snapshotOptions(raw);
|
|
3512
3571
|
validateOptions(options);
|
|
3513
3572
|
const resolved = applyDefaults(options);
|
|
@@ -3670,7 +3729,7 @@ exports.BymaxStorageModule = class BymaxStorageModule {
|
|
|
3670
3729
|
if (useFactory) {
|
|
3671
3730
|
return {
|
|
3672
3731
|
provide: BYMAX_STORAGE_OPTIONS,
|
|
3673
|
-
useFactory:
|
|
3732
|
+
useFactory: (...args) => resolveProducedOptions(() => useFactory(...args)),
|
|
3674
3733
|
inject: [...asyncOptions.inject ?? []]
|
|
3675
3734
|
};
|
|
3676
3735
|
}
|
|
@@ -3678,13 +3737,11 @@ exports.BymaxStorageModule = class BymaxStorageModule {
|
|
|
3678
3737
|
if (factoryToken) {
|
|
3679
3738
|
return {
|
|
3680
3739
|
provide: BYMAX_STORAGE_OPTIONS,
|
|
3681
|
-
useFactory:
|
|
3740
|
+
useFactory: (factory) => resolveProducedOptions(() => factory.createStorageOptions()),
|
|
3682
3741
|
inject: [factoryToken]
|
|
3683
3742
|
};
|
|
3684
3743
|
}
|
|
3685
|
-
throw new Error(
|
|
3686
|
-
"BymaxStorageModule.forRootAsync requires useFactory, useClass, or useExisting"
|
|
3687
|
-
);
|
|
3744
|
+
throw new Error("BymaxStorageModule.forRootAsync requires useFactory, useClass, or useExisting");
|
|
3688
3745
|
}
|
|
3689
3746
|
};
|
|
3690
3747
|
exports.BymaxStorageModule = __decorateClass([
|
package/dist/server/index.d.cts
CHANGED
|
@@ -694,7 +694,11 @@ declare class StorageMetricsTally {
|
|
|
694
694
|
#private;
|
|
695
695
|
/** An operation ended as `outcome` after `seconds`. */
|
|
696
696
|
operation(operation: StorageOperation, outcome: StorageOutcome, seconds: number): void;
|
|
697
|
-
/**
|
|
697
|
+
/**
|
|
698
|
+
* `bytes` of an object reached the provider; anything that is not a positive finite number is ignored. The
|
|
699
|
+
* count stops at the largest finite number: a sum of two finite sizes can overflow to `Infinity`, which no
|
|
700
|
+
* counter accepts, and a scrape that read it would fail whole.
|
|
701
|
+
*/
|
|
698
702
|
bytesUploaded(bytes: number | undefined): void;
|
|
699
703
|
/** A scan ended as `verdict`. */
|
|
700
704
|
scan(verdict: ScanVerdict): void;
|
|
@@ -710,8 +714,15 @@ declare class StorageMetricsTally {
|
|
|
710
714
|
|
|
711
715
|
/** The span names the library starts. */
|
|
712
716
|
type StorageSpanName = 'storage.upload' | 'storage.download_url' | 'storage.scan';
|
|
713
|
-
/**
|
|
714
|
-
|
|
717
|
+
/**
|
|
718
|
+
* The attributes a span carries, named one by one: the outcome, whether an upload was multipart, and when a scan
|
|
719
|
+
* runs. A key, a bucket or a payload has no member, so a call site cannot add one.
|
|
720
|
+
*/
|
|
721
|
+
interface StorageSpanAttributes {
|
|
722
|
+
readonly 'bymax.storage.outcome'?: StorageOutcome;
|
|
723
|
+
readonly 'bymax.storage.multipart'?: 'true' | 'false';
|
|
724
|
+
readonly 'bymax.storage.scan_mode'?: 'pre-upload' | 'post-upload';
|
|
725
|
+
}
|
|
715
726
|
/** What a span states of a result, once the operation succeeded. */
|
|
716
727
|
type ResultAttributes<T> = (result: T) => StorageSpanAttributes;
|
|
717
728
|
/**
|
|
@@ -781,7 +792,7 @@ declare class StorageObserver {
|
|
|
781
792
|
*/
|
|
782
793
|
scan<T extends {
|
|
783
794
|
readonly status: string;
|
|
784
|
-
}>(mode:
|
|
795
|
+
}>(mode: 'pre-upload' | 'post-upload', run: () => Promise<T>): Promise<T>;
|
|
785
796
|
}
|
|
786
797
|
|
|
787
798
|
/** Input shape for a scan request. */
|
|
@@ -1612,7 +1623,9 @@ declare class StorageException extends HttpException {
|
|
|
1612
1623
|
/** Defaults to `STORAGE_ERROR_STATUS[code]`. Pass only to override. */
|
|
1613
1624
|
statusCode?: number, details?: Record<string, unknown>,
|
|
1614
1625
|
/** Defaults to the message of `code`. Pass only when the situation is more specific than the code. */
|
|
1615
|
-
message?: string
|
|
1626
|
+
message?: string,
|
|
1627
|
+
/** What made the call fail, for a log or a debugger; it is never part of the response body. */
|
|
1628
|
+
cause?: unknown);
|
|
1616
1629
|
}
|
|
1617
1630
|
|
|
1618
1631
|
export { BYMAX_STORAGE_FILE_SCANNER, BYMAX_STORAGE_OPTIONS, BYMAX_STORAGE_S3_CLIENT, BYMAX_STORAGE_UPLOAD_VALIDATORS, BucketLifecycleService, BymaxStorageModule, NoOpFileScanner, NoOpUploadValidator, SCAN_VERDICTS, STORAGE_ERROR_CODES, STORAGE_OPERATIONS, STORAGE_OUTCOMES, SignedUrlService, StorageException, StorageMetricsTally, StorageService, providerRecipes };
|
package/dist/server/index.d.ts
CHANGED
|
@@ -694,7 +694,11 @@ declare class StorageMetricsTally {
|
|
|
694
694
|
#private;
|
|
695
695
|
/** An operation ended as `outcome` after `seconds`. */
|
|
696
696
|
operation(operation: StorageOperation, outcome: StorageOutcome, seconds: number): void;
|
|
697
|
-
/**
|
|
697
|
+
/**
|
|
698
|
+
* `bytes` of an object reached the provider; anything that is not a positive finite number is ignored. The
|
|
699
|
+
* count stops at the largest finite number: a sum of two finite sizes can overflow to `Infinity`, which no
|
|
700
|
+
* counter accepts, and a scrape that read it would fail whole.
|
|
701
|
+
*/
|
|
698
702
|
bytesUploaded(bytes: number | undefined): void;
|
|
699
703
|
/** A scan ended as `verdict`. */
|
|
700
704
|
scan(verdict: ScanVerdict): void;
|
|
@@ -710,8 +714,15 @@ declare class StorageMetricsTally {
|
|
|
710
714
|
|
|
711
715
|
/** The span names the library starts. */
|
|
712
716
|
type StorageSpanName = 'storage.upload' | 'storage.download_url' | 'storage.scan';
|
|
713
|
-
/**
|
|
714
|
-
|
|
717
|
+
/**
|
|
718
|
+
* The attributes a span carries, named one by one: the outcome, whether an upload was multipart, and when a scan
|
|
719
|
+
* runs. A key, a bucket or a payload has no member, so a call site cannot add one.
|
|
720
|
+
*/
|
|
721
|
+
interface StorageSpanAttributes {
|
|
722
|
+
readonly 'bymax.storage.outcome'?: StorageOutcome;
|
|
723
|
+
readonly 'bymax.storage.multipart'?: 'true' | 'false';
|
|
724
|
+
readonly 'bymax.storage.scan_mode'?: 'pre-upload' | 'post-upload';
|
|
725
|
+
}
|
|
715
726
|
/** What a span states of a result, once the operation succeeded. */
|
|
716
727
|
type ResultAttributes<T> = (result: T) => StorageSpanAttributes;
|
|
717
728
|
/**
|
|
@@ -781,7 +792,7 @@ declare class StorageObserver {
|
|
|
781
792
|
*/
|
|
782
793
|
scan<T extends {
|
|
783
794
|
readonly status: string;
|
|
784
|
-
}>(mode:
|
|
795
|
+
}>(mode: 'pre-upload' | 'post-upload', run: () => Promise<T>): Promise<T>;
|
|
785
796
|
}
|
|
786
797
|
|
|
787
798
|
/** Input shape for a scan request. */
|
|
@@ -1612,7 +1623,9 @@ declare class StorageException extends HttpException {
|
|
|
1612
1623
|
/** Defaults to `STORAGE_ERROR_STATUS[code]`. Pass only to override. */
|
|
1613
1624
|
statusCode?: number, details?: Record<string, unknown>,
|
|
1614
1625
|
/** Defaults to the message of `code`. Pass only when the situation is more specific than the code. */
|
|
1615
|
-
message?: string
|
|
1626
|
+
message?: string,
|
|
1627
|
+
/** What made the call fail, for a log or a debugger; it is never part of the response body. */
|
|
1628
|
+
cause?: unknown);
|
|
1616
1629
|
}
|
|
1617
1630
|
|
|
1618
1631
|
export { BYMAX_STORAGE_FILE_SCANNER, BYMAX_STORAGE_OPTIONS, BYMAX_STORAGE_S3_CLIENT, BYMAX_STORAGE_UPLOAD_VALIDATORS, BucketLifecycleService, BymaxStorageModule, NoOpFileScanner, NoOpUploadValidator, SCAN_VERDICTS, STORAGE_ERROR_CODES, STORAGE_OPERATIONS, STORAGE_OUTCOMES, SignedUrlService, StorageException, StorageMetricsTally, StorageService, providerRecipes };
|
package/dist/server/index.mjs
CHANGED
|
@@ -128,7 +128,7 @@ var STORAGE_ERROR_STATUS = {
|
|
|
128
128
|
// src/server/errors/storage-exception.ts
|
|
129
129
|
var StorageException = class extends HttpException {
|
|
130
130
|
code;
|
|
131
|
-
constructor(code, statusCode = STORAGE_ERROR_STATUS[code], details, message = STORAGE_ERROR_MESSAGES[code]) {
|
|
131
|
+
constructor(code, statusCode = STORAGE_ERROR_STATUS[code], details, message = STORAGE_ERROR_MESSAGES[code], cause) {
|
|
132
132
|
super(
|
|
133
133
|
{
|
|
134
134
|
error: {
|
|
@@ -137,7 +137,8 @@ var StorageException = class extends HttpException {
|
|
|
137
137
|
...details ? { details } : {}
|
|
138
138
|
}
|
|
139
139
|
},
|
|
140
|
-
statusCode
|
|
140
|
+
statusCode,
|
|
141
|
+
{ cause }
|
|
141
142
|
);
|
|
142
143
|
this.code = code;
|
|
143
144
|
}
|
|
@@ -181,15 +182,31 @@ function assertMetadata(metadata) {
|
|
|
181
182
|
}
|
|
182
183
|
}
|
|
183
184
|
|
|
185
|
+
// src/server/config/option-array-bound.ts
|
|
186
|
+
var MAX_OPTION_ARRAY_LENGTH = 1e3;
|
|
187
|
+
function isBoundedLength(length) {
|
|
188
|
+
return typeof length === "number" && Number.isInteger(length) && length >= 0 && length <= MAX_OPTION_ARRAY_LENGTH;
|
|
189
|
+
}
|
|
190
|
+
|
|
184
191
|
// src/server/config/validate-options.ts
|
|
185
192
|
var MIN_PART_SIZE_BYTES = 5 * 1024 * 1024;
|
|
186
193
|
var MAX_PART_SIZE_BYTES = 5 * 1024 * 1024 * 1024;
|
|
187
194
|
var MAX_QUEUE_SIZE = 1e3;
|
|
188
195
|
var REGION_SHAPE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,62}$/;
|
|
196
|
+
var OWN_REFUSALS = /* @__PURE__ */ new WeakSet();
|
|
197
|
+
function isOwnRefusal(error) {
|
|
198
|
+
return typeof error === "object" && error !== null && OWN_REFUSALS.has(error);
|
|
199
|
+
}
|
|
189
200
|
function invalid(reason) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
201
|
+
const refusal = new StorageException(
|
|
202
|
+
STORAGE_ERROR_CODES.STORAGE_INVALID_CONFIG,
|
|
203
|
+
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
204
|
+
{
|
|
205
|
+
reason
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
OWN_REFUSALS.add(refusal);
|
|
209
|
+
return refusal;
|
|
193
210
|
}
|
|
194
211
|
function isObject(value) {
|
|
195
212
|
return typeof value === "object" && value !== null;
|
|
@@ -260,32 +277,35 @@ function assertValidationKinds(validation) {
|
|
|
260
277
|
if (mimeWhitelist === null) {
|
|
261
278
|
throw invalid("validation.mimeWhitelist must not be null; omit it to allow every type");
|
|
262
279
|
}
|
|
280
|
+
assertBoundedArray("mimeWhitelist", mimeWhitelist);
|
|
263
281
|
if (mimeWhitelist !== void 0 && !isStringArray(mimeWhitelist)) {
|
|
264
282
|
throw invalid("validation.mimeWhitelist must be an array of strings");
|
|
265
283
|
}
|
|
266
284
|
if (customValidators === null) {
|
|
267
|
-
throw invalid(
|
|
285
|
+
throw invalid(
|
|
286
|
+
"validation.customValidators must not be null; omit it to run no custom validator"
|
|
287
|
+
);
|
|
268
288
|
}
|
|
269
289
|
if (customValidators !== void 0 && !Array.isArray(customValidators)) {
|
|
270
290
|
throw invalid("validation.customValidators must be an array");
|
|
271
291
|
}
|
|
292
|
+
assertBoundedArray("customValidators", customValidators);
|
|
272
293
|
if (customValidators !== void 0 && !isValidatorList(customValidators)) {
|
|
273
294
|
throw invalid("validation.customValidators must hold objects with a validate function");
|
|
274
295
|
}
|
|
275
296
|
}
|
|
276
|
-
function
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
} catch {
|
|
280
|
-
return false;
|
|
297
|
+
function assertBoundedArray(name, value) {
|
|
298
|
+
if (Array.isArray(value) && !isBoundedLength(value.length)) {
|
|
299
|
+
throw invalid(`validation.${name} must hold at most ${String(MAX_OPTION_ARRAY_LENGTH)} entries`);
|
|
281
300
|
}
|
|
282
301
|
}
|
|
302
|
+
function isStringArray(value) {
|
|
303
|
+
return Array.isArray(value) && Array.from(value).every((entry) => typeof entry === "string");
|
|
304
|
+
}
|
|
283
305
|
function isValidatorList(entries) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
return false;
|
|
288
|
-
}
|
|
306
|
+
return Array.from(entries).every(
|
|
307
|
+
(entry) => isObject(entry) && typeof entry.validate === "function"
|
|
308
|
+
);
|
|
289
309
|
}
|
|
290
310
|
function assertGroupKinds(options) {
|
|
291
311
|
for (const group of ["signedUrls", "multipart", "validation"]) {
|
|
@@ -325,6 +345,11 @@ function assertLimitsAndEncryption(options) {
|
|
|
325
345
|
if (options.serverSideEncryption === "aws:kms" && !options.kmsKeyId) {
|
|
326
346
|
throw invalid('kmsKeyId is required when serverSideEncryption === "aws:kms"');
|
|
327
347
|
}
|
|
348
|
+
for (const name of ["defaultPublicRead", "forcePathStyle"]) {
|
|
349
|
+
if (options[name] !== void 0 && typeof options[name] !== "boolean") {
|
|
350
|
+
throw invalid(`options.${name} must be a boolean`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
328
353
|
for (const name of ["defaultCacheControl", "kmsKeyId"]) {
|
|
329
354
|
if (options[name] !== void 0 && !isHeaderValue(options[name])) {
|
|
330
355
|
throw invalid(`options.${name} must be a string of tab, space and printable ASCII characters`);
|
|
@@ -513,12 +538,7 @@ function pickGroup(value, keys) {
|
|
|
513
538
|
return isObject2(value) && !Array.isArray(value) ? pick(value, keys) : value;
|
|
514
539
|
}
|
|
515
540
|
function copyArray(value) {
|
|
516
|
-
|
|
517
|
-
try {
|
|
518
|
-
return Array.from(value);
|
|
519
|
-
} catch {
|
|
520
|
-
return value;
|
|
521
|
-
}
|
|
541
|
+
return Array.isArray(value) && isBoundedLength(value.length) ? Array.from(value) : value;
|
|
522
542
|
}
|
|
523
543
|
var GROUPS = {
|
|
524
544
|
credentials: CREDENTIAL_KEYS,
|
|
@@ -784,10 +804,14 @@ var StorageMetricsTally = class {
|
|
|
784
804
|
__privateGet(this, _operations)[operation][outcome] += 1;
|
|
785
805
|
for (const listener of __privateGet(this, _listeners)) absorb(() => listener(operation, seconds));
|
|
786
806
|
}
|
|
787
|
-
/**
|
|
807
|
+
/**
|
|
808
|
+
* `bytes` of an object reached the provider; anything that is not a positive finite number is ignored. The
|
|
809
|
+
* count stops at the largest finite number: a sum of two finite sizes can overflow to `Infinity`, which no
|
|
810
|
+
* counter accepts, and a scrape that read it would fail whole.
|
|
811
|
+
*/
|
|
788
812
|
bytesUploaded(bytes) {
|
|
789
813
|
if (typeof bytes === "number" && Number.isFinite(bytes) && bytes > 0)
|
|
790
|
-
__privateSet(this, _bytesUploaded, __privateGet(this, _bytesUploaded) + bytes);
|
|
814
|
+
__privateSet(this, _bytesUploaded, Math.min(__privateGet(this, _bytesUploaded) + bytes, Number.MAX_VALUE));
|
|
791
815
|
}
|
|
792
816
|
/** A scan ended as `verdict`. */
|
|
793
817
|
scan(verdict) {
|
|
@@ -1098,7 +1122,7 @@ function describeError(value) {
|
|
|
1098
1122
|
}
|
|
1099
1123
|
|
|
1100
1124
|
// src/server/utils/log-value.ts
|
|
1101
|
-
var LEFT_LITERAL_BY_JSON = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu;
|
|
1125
|
+
var LEFT_LITERAL_BY_JSON = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Cs}]/gu;
|
|
1102
1126
|
var SHORT_ESCAPES = {
|
|
1103
1127
|
"\b": "\\b",
|
|
1104
1128
|
"\f": "\\f",
|
|
@@ -2429,6 +2453,12 @@ function buildSSE(perCall, perCallKmsKeyId, module) {
|
|
|
2429
2453
|
return { ServerSideEncryption: sse };
|
|
2430
2454
|
}
|
|
2431
2455
|
function buildACL(perCall, defaultValue) {
|
|
2456
|
+
if (perCall !== void 0 && typeof perCall !== "boolean") {
|
|
2457
|
+
throw new StorageException(STORAGE_ERROR_CODES.STORAGE_VALIDATION_FAILED, void 0, {
|
|
2458
|
+
field: "publicRead",
|
|
2459
|
+
reason: "must be a boolean"
|
|
2460
|
+
});
|
|
2461
|
+
}
|
|
2432
2462
|
return perCall ?? defaultValue ? "public-read" : void 0;
|
|
2433
2463
|
}
|
|
2434
2464
|
|
|
@@ -2579,11 +2609,14 @@ function buildUploadResult(keyResolver, options, params) {
|
|
|
2579
2609
|
};
|
|
2580
2610
|
}
|
|
2581
2611
|
function emitProgress(onProgress, loaded, total, part) {
|
|
2582
|
-
onProgress
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2612
|
+
const hook = onProgress;
|
|
2613
|
+
absorb(
|
|
2614
|
+
() => hook({
|
|
2615
|
+
loaded: loaded ?? 0,
|
|
2616
|
+
...total !== void 0 ? { total } : {},
|
|
2617
|
+
...part !== void 0 ? { part } : {}
|
|
2618
|
+
})
|
|
2619
|
+
);
|
|
2587
2620
|
}
|
|
2588
2621
|
function putObjectHeaders(options, resolved, finalKey, bucket) {
|
|
2589
2622
|
return {
|
|
@@ -2655,17 +2688,18 @@ function uploadedBytesOf(result) {
|
|
|
2655
2688
|
return result.fromIdempotencyCache ? void 0 : SENT.get(result) ?? result.size;
|
|
2656
2689
|
}
|
|
2657
2690
|
async function uploadSingleShot(context, options, finalKey, bucket, caller) {
|
|
2691
|
+
const { onProgress, contentType, abortSignal } = options;
|
|
2658
2692
|
const total = options.size ?? getBodySize(options.body);
|
|
2659
2693
|
const input = {
|
|
2660
2694
|
...putObjectHeaders(options, context.options, finalKey, bucket),
|
|
2661
2695
|
Body: normalizeSingleShotBody(options.body),
|
|
2662
2696
|
ContentLength: total
|
|
2663
2697
|
};
|
|
2664
|
-
const watch = abortOnBodyFailure(input.Body,
|
|
2698
|
+
const watch = abortOnBodyFailure(input.Body, abortSignal);
|
|
2665
2699
|
try {
|
|
2666
2700
|
const response = await context.s3Provider.getClient().send(new PutObjectCommand(input), sendOptions(watch.signal));
|
|
2667
|
-
if (
|
|
2668
|
-
emitProgress(
|
|
2701
|
+
if (onProgress) {
|
|
2702
|
+
emitProgress(onProgress, total, total);
|
|
2669
2703
|
}
|
|
2670
2704
|
return buildUploadResult(context.keyResolver, context.options, {
|
|
2671
2705
|
finalKey,
|
|
@@ -2673,13 +2707,13 @@ async function uploadSingleShot(context, options, finalKey, bucket, caller) {
|
|
|
2673
2707
|
etag: response.ETag,
|
|
2674
2708
|
versionId: response.VersionId,
|
|
2675
2709
|
size: total,
|
|
2676
|
-
contentType
|
|
2710
|
+
contentType,
|
|
2677
2711
|
multipart: false
|
|
2678
2712
|
});
|
|
2679
2713
|
} catch (err) {
|
|
2680
2714
|
const context2 = { ...caller, op: "upload-single" };
|
|
2681
2715
|
const mapped = mapSizeLimitError(watch.failure(), context2) ?? mapAwsError(err, context2);
|
|
2682
|
-
throw failureOrAbort(
|
|
2716
|
+
throw failureOrAbort(abortSignal, context2, mapped);
|
|
2683
2717
|
}
|
|
2684
2718
|
}
|
|
2685
2719
|
|
|
@@ -3121,6 +3155,7 @@ var StorageService = class {
|
|
|
3121
3155
|
const destKey = this.keyResolver.normalize(options.destinationKey);
|
|
3122
3156
|
const sourceBucket = this.resolveBucket(options.sourceBucket);
|
|
3123
3157
|
const destBucket = this.resolveBucket(options.destinationBucket);
|
|
3158
|
+
const acl = buildACL(options.publicRead, this.options.defaultPublicRead);
|
|
3124
3159
|
try {
|
|
3125
3160
|
const response = await this.s3Provider.getClient().send(
|
|
3126
3161
|
new CopyObjectCommand({
|
|
@@ -3131,7 +3166,7 @@ var StorageService = class {
|
|
|
3131
3166
|
CopySource: `/${sourceBucket}/${sourceKey.split("/").map(encodeURIComponent).join("/")}`,
|
|
3132
3167
|
CacheControl: options.cacheControl ?? this.options.defaultCacheControl,
|
|
3133
3168
|
// ACLs are a no-op on modern S3 (Object Ownership) and R2; see header-utils.
|
|
3134
|
-
ACL:
|
|
3169
|
+
ACL: acl,
|
|
3135
3170
|
MetadataDirective: "COPY"
|
|
3136
3171
|
})
|
|
3137
3172
|
);
|
|
@@ -3172,7 +3207,7 @@ var StorageService = class {
|
|
|
3172
3207
|
__decorateClass([
|
|
3173
3208
|
Observed("upload", {
|
|
3174
3209
|
span: "storage.upload",
|
|
3175
|
-
describe: (result) => ({ "bymax.storage.multipart":
|
|
3210
|
+
describe: (result) => ({ "bymax.storage.multipart": result.multipart ? "true" : "false" }),
|
|
3176
3211
|
bytes: uploadedBytesOf
|
|
3177
3212
|
})
|
|
3178
3213
|
], StorageService.prototype, "upload", 1);
|
|
@@ -3505,7 +3540,31 @@ var IdempotencyCache = class {
|
|
|
3505
3540
|
};
|
|
3506
3541
|
|
|
3507
3542
|
// src/server/bymax-storage.module.ts
|
|
3543
|
+
function refuseUnreadable(error) {
|
|
3544
|
+
if (isOwnRefusal(error)) throw error;
|
|
3545
|
+
throw new StorageException(
|
|
3546
|
+
STORAGE_ERROR_CODES.STORAGE_INVALID_CONFIG,
|
|
3547
|
+
void 0,
|
|
3548
|
+
{ reason: "the options could not be read" },
|
|
3549
|
+
void 0,
|
|
3550
|
+
error
|
|
3551
|
+
);
|
|
3552
|
+
}
|
|
3508
3553
|
function resolveAsyncOptions(raw) {
|
|
3554
|
+
try {
|
|
3555
|
+
return resolveOptions(raw);
|
|
3556
|
+
} catch (error) {
|
|
3557
|
+
return refuseUnreadable(error);
|
|
3558
|
+
}
|
|
3559
|
+
}
|
|
3560
|
+
async function resolveProducedOptions(produce) {
|
|
3561
|
+
try {
|
|
3562
|
+
return resolveOptions(await produce());
|
|
3563
|
+
} catch (error) {
|
|
3564
|
+
return refuseUnreadable(error);
|
|
3565
|
+
}
|
|
3566
|
+
}
|
|
3567
|
+
function resolveOptions(raw) {
|
|
3509
3568
|
const options = snapshotOptions(raw);
|
|
3510
3569
|
validateOptions(options);
|
|
3511
3570
|
const resolved = applyDefaults(options);
|
|
@@ -3668,7 +3727,7 @@ var BymaxStorageModule = class {
|
|
|
3668
3727
|
if (useFactory) {
|
|
3669
3728
|
return {
|
|
3670
3729
|
provide: BYMAX_STORAGE_OPTIONS,
|
|
3671
|
-
useFactory:
|
|
3730
|
+
useFactory: (...args) => resolveProducedOptions(() => useFactory(...args)),
|
|
3672
3731
|
inject: [...asyncOptions.inject ?? []]
|
|
3673
3732
|
};
|
|
3674
3733
|
}
|
|
@@ -3676,13 +3735,11 @@ var BymaxStorageModule = class {
|
|
|
3676
3735
|
if (factoryToken) {
|
|
3677
3736
|
return {
|
|
3678
3737
|
provide: BYMAX_STORAGE_OPTIONS,
|
|
3679
|
-
useFactory:
|
|
3738
|
+
useFactory: (factory) => resolveProducedOptions(() => factory.createStorageOptions()),
|
|
3680
3739
|
inject: [factoryToken]
|
|
3681
3740
|
};
|
|
3682
3741
|
}
|
|
3683
|
-
throw new Error(
|
|
3684
|
-
"BymaxStorageModule.forRootAsync requires useFactory, useClass, or useExisting"
|
|
3685
|
-
);
|
|
3742
|
+
throw new Error("BymaxStorageModule.forRootAsync requires useFactory, useClass, or useExisting");
|
|
3686
3743
|
}
|
|
3687
3744
|
};
|
|
3688
3745
|
BymaxStorageModule = __decorateClass([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bymax-one/nest-storage",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.20",
|
|
4
4
|
"description": "Provider-agnostic S3-compatible object storage for NestJS. Works with AWS S3, DigitalOcean Spaces, Cloudflare R2, Backblaze B2, MinIO, Wasabi.",
|
|
5
5
|
"author": "Bymax One <support@bymax.one>",
|
|
6
6
|
"license": "MIT",
|