@bymax-one/nest-storage 1.1.13 → 1.1.15
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 +34 -1
- package/README.md +5 -4
- package/dist/server/index.cjs +48 -19
- package/dist/server/index.mjs +48 -19
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -13,6 +13,37 @@ note on each entry is the compatibility contract — read it, not the number.
|
|
|
13
13
|
|
|
14
14
|
## [Unreleased]
|
|
15
15
|
|
|
16
|
+
## [1.1.15] - 2026-11-17
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- **A download body that fails after its headers no longer reaches the caller as the SDK's raw error.** A
|
|
21
|
+
connection reset in the middle of a body (`ECONNRESET`, message `aborted`) passed through unmapped: a
|
|
22
|
+
caller that caught only `StorageException` missed it, and a Nest handler answered 500 for it. With the idle
|
|
23
|
+
guard on (the default), a failure of the body is now mapped as any other failure of the provider
|
|
24
|
+
(`STORAGE_PROVIDER_ERROR`, **503** for a cut connection, with its fixed `reason`), and `downloadBuffer()`
|
|
25
|
+
maps it in both modes, with `STORAGE_REQUEST_ABORTED` when the caller's signal aborted. Nothing a client
|
|
26
|
+
receives carries the driver's text.
|
|
27
|
+
|
|
28
|
+
**Apply to a derived backend:** a host that caught the raw `ECONNRESET` from `download()` or
|
|
29
|
+
`downloadBuffer()` must catch `StorageException` instead (the status is 503 for a reset). With
|
|
30
|
+
`bodyIdleTimeoutMs: 0`, the stream `download()` returns is still the SDK's own and still errors with the
|
|
31
|
+
SDK's error, as documented; only `downloadBuffer()` changes there.
|
|
32
|
+
|
|
33
|
+
## [1.1.14] - 2026-11-16
|
|
34
|
+
|
|
35
|
+
### Changed
|
|
36
|
+
|
|
37
|
+
- **The provider-failure log masks more, and says less when nothing failed.** The warning that carries what
|
|
38
|
+
the driver or the provider said now also masks the credential scope and signature of an `Authorization`
|
|
39
|
+
header (`Credential=...`) and a bare access key id (`AKIA...`, `ASIA...`), still before it cuts the
|
|
40
|
+
message. A request the caller cancelled is no longer logged, and a multipart upload that fails opens its
|
|
41
|
+
line with `Multipart upload failed` (it was `Provider call failed`, which a failure of the caller's own
|
|
42
|
+
source stream is not). Nothing a client receives changes.
|
|
43
|
+
|
|
44
|
+
**Apply to a derived backend:** nothing, unless a log search matched the old line start for a multipart
|
|
45
|
+
failure or the cancelled-request warning.
|
|
46
|
+
|
|
16
47
|
## [1.1.13] - 2026-11-16
|
|
17
48
|
|
|
18
49
|
### Security
|
|
@@ -850,4 +881,6 @@ have regressed from. They are kept because the reasoning is worth having.
|
|
|
850
881
|
[1.1.11]: https://github.com/bymaxone/nest-storage/compare/v1.1.10...v1.1.11
|
|
851
882
|
[1.1.12]: https://github.com/bymaxone/nest-storage/compare/v1.1.11...v1.1.12
|
|
852
883
|
[1.1.13]: https://github.com/bymaxone/nest-storage/compare/v1.1.12...v1.1.13
|
|
853
|
-
[
|
|
884
|
+
[1.1.14]: https://github.com/bymaxone/nest-storage/compare/v1.1.13...v1.1.14
|
|
885
|
+
[1.1.15]: https://github.com/bymaxone/nest-storage/compare/v1.1.14...v1.1.15
|
|
886
|
+
[Unreleased]: https://github.com/bymaxone/nest-storage/compare/v1.1.15...HEAD
|
package/README.md
CHANGED
|
@@ -241,7 +241,7 @@ Options accepted by `forRoot` and `forRootAsync`:
|
|
|
241
241
|
|
|
242
242
|
**`uploadIdleTimeoutMs`** covers what `requestTimeoutMs` cannot: a multipart upload waiting for the next bytes of a stream has no request in flight, so a source that stops delivering would hold the upload open on the provider indefinitely. After this much silence the upload is aborted (the provider is sent `AbortMultipartUpload`), your stream is destroyed and `upload()` rejects with `STORAGE_TIMEOUT` and `details.phase` set to `'source-idle'`. The clock restarts on every chunk and runs only while the library is waiting for data, so a slow but live source succeeds and a slow provider does not trip it. It defaults to the value of `requestTimeoutMs`; `0` turns it off. It applies only to a stream on the multipart path: a single-shot upload is bounded by `requestTimeoutMs`, and a `Buffer` cannot stall.
|
|
243
243
|
|
|
244
|
-
**`bodyIdleTimeoutMs`** covers the other direction: `requestTimeoutMs` ends when the response headers arrive, so a provider that stops sending in the middle of a download would leave the stream, its connection and the caller waiting without limit. After this much silence while a read is pending, the stream fails with `STORAGE_TIMEOUT` and `details.phase` set to `'body-idle'`, and the connection is released. The clock runs only while the caller is waiting for data, so a consumer that is slow to read, for example a response piped to a slow client, never trips it, and every chunk restarts it. It defaults to the value of `requestTimeoutMs`; `0` turns it off. It applies to `download` and `downloadBuffer`.
|
|
244
|
+
**`bodyIdleTimeoutMs`** covers the other direction: `requestTimeoutMs` ends when the response headers arrive, so a provider that stops sending in the middle of a download would leave the stream, its connection and the caller waiting without limit. After this much silence while a read is pending, the stream fails with `STORAGE_TIMEOUT` and `details.phase` set to `'body-idle'`, and the connection is released. The clock runs only while the caller is waiting for data, so a consumer that is slow to read, for example a response piped to a slow client, never trips it, and every chunk restarts it. It defaults to the value of `requestTimeoutMs`; `0` turns it off. It applies to `download` and `downloadBuffer`. A body that fails after its headers arrived (a reset connection) ends as a `StorageException` like any other failure of the provider (`STORAGE_PROVIDER_ERROR`, **503** when the connection was cut); with the guard off only `download()` is the exception, its stream being the SDK's own and so erroring with the SDK's own error, while `downloadBuffer()` is mapped in both modes.
|
|
245
245
|
|
|
246
246
|
|
|
247
247
|
[aws-presigned-expiry]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html
|
|
@@ -444,8 +444,9 @@ await this.storage.upload({
|
|
|
444
444
|
same error and `details.stored: true`: the object is already stored. The scan carries on, and an
|
|
445
445
|
object it finds infected is still deleted.
|
|
446
446
|
- A **download** body that is being read when the signal aborts errors as `STORAGE_REQUEST_ABORTED`
|
|
447
|
-
while the idle guard is on (the default `bodyIdleTimeoutMs`)
|
|
448
|
-
|
|
447
|
+
while the idle guard is on (the default `bodyIdleTimeoutMs`), and `downloadBuffer()` rejects with it in
|
|
448
|
+
both modes. With `bodyIdleTimeoutMs: 0` the stream `download()` returns is the SDK's own and errors with
|
|
449
|
+
the SDK's own error, whichever it is where the abort lands.
|
|
449
450
|
- The library keeps no listener on your signal after a call, so one signal can be reused across many
|
|
450
451
|
calls.
|
|
451
452
|
- `copy`, `deleteMany` and the signed-URL methods take no `abortSignal`.
|
|
@@ -760,7 +761,7 @@ All errors are thrown as `StorageException extends HttpException`. The response
|
|
|
760
761
|
| `STORAGE_SCAN_INFECTED` | 422 | Scanner returned `'infected'` (`details.threat`); `details.cleanup: 'failed'` means the object is still stored |
|
|
761
762
|
| `STORAGE_SCAN_INCONCLUSIVE` | 422 | Scanner returned `'unknown'` and `rejectOnUnknown: true` |
|
|
762
763
|
| `STORAGE_OBJECT_NOT_FOUND` | 404 | `head()`, `download()`, or `copy()` on a nonexistent key |
|
|
763
|
-
| `STORAGE_PROVIDER_ERROR` | 502 | The provider rejected the request (`AccessControlListNotSupported`, an `AccessDenied` on an object, any other rejection). **503** when it could not be reached (connection refused or reset, DNS failure) or answered with a server error (`SlowDown`, 500, 502, 504; not 501), which is worth retrying; **500** when it refused the credentials (`InvalidAccessKeyId`, `SignatureDoesNotMatch`), a deployment fault that a retry does not fix. `details` carries `awsCode`, `httpStatus`, `requestId` and a fixed `reason` (`unreachable`, `provider-error`, `credentials-refused` or `rejected`; never the text of the driver or of the provider) plus the operation context (`op`, `bucket`, and `key` or `prefix`) |
|
|
764
|
+
| `STORAGE_PROVIDER_ERROR` | 502 | The provider rejected the request (`AccessControlListNotSupported`, an `AccessDenied` on an object, any other rejection). **503** when it could not be reached (connection refused or reset, DNS failure) or answered with a server error (`SlowDown`, 500, 502, 504; not 501), which is worth retrying; **500** when it refused the credentials (`InvalidAccessKeyId`, `SignatureDoesNotMatch`), a deployment fault that a retry does not fix (a `HEAD` answer carries no body and so no code: a refused `head()` stays **502** with reason `rejected`, and the credentials case is not told apart there). `details` carries `awsCode`, `httpStatus`, `requestId` and a fixed `reason` (`unreachable`, `provider-error`, `credentials-refused` or `rejected`; never the text of the driver or of the provider) plus the operation context (`op`, `bucket`, and `key` or `prefix`) |
|
|
764
765
|
| `STORAGE_SIGNED_URL_TTL_INVALID` | 400 | Per-request `ttlSeconds` ≤ 0 |
|
|
765
766
|
| `STORAGE_PART_TOO_SMALL` | 400 | Never thrown: a `multipart.partSizeBytes` below 5 MiB fails at init as `STORAGE_INVALID_CONFIG` |
|
|
766
767
|
| `STORAGE_INVALID_PART_COUNT` | 400 | `getMultipartUploadUrls()` with `parts` not an integer from 1 to 10 000 (`details.provided`, `details.reason`) |
|
package/dist/server/index.cjs
CHANGED
|
@@ -541,7 +541,8 @@ function logValue(value) {
|
|
|
541
541
|
}
|
|
542
542
|
|
|
543
543
|
// src/server/utils/provider-failure-log.ts
|
|
544
|
-
var SECRET_IN_MESSAGE = /(X-Amz-(?:Signature|Credential|Security-Token)|AWSAccessKeyId|Signature)=[^&\s"']+/gi;
|
|
544
|
+
var SECRET_IN_MESSAGE = /(X-Amz-(?:Signature|Credential|Security-Token)|AWSAccessKeyId|Credential|Signature)=[^&\s"']+/gi;
|
|
545
|
+
var BARE_ACCESS_KEY_ID = /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g;
|
|
545
546
|
var MAX_MESSAGE_LENGTH = 300;
|
|
546
547
|
var logger = new common.Logger("StorageProvider");
|
|
547
548
|
function field(value) {
|
|
@@ -549,7 +550,7 @@ function field(value) {
|
|
|
549
550
|
}
|
|
550
551
|
function describeProviderFailure(err) {
|
|
551
552
|
const failure = typeof err === "object" && err !== null ? err : {};
|
|
552
|
-
const message = describeError(err).replace(SECRET_IN_MESSAGE, "$1=[redacted]");
|
|
553
|
+
const message = describeError(err).replace(SECRET_IN_MESSAGE, "$1=[redacted]").replace(BARE_ACCESS_KEY_ID, "[redacted-key-id]");
|
|
553
554
|
return [
|
|
554
555
|
`name=${field(failure.name)}`,
|
|
555
556
|
`code=${field(failure.Code)}`,
|
|
@@ -558,10 +559,13 @@ function describeProviderFailure(err) {
|
|
|
558
559
|
`message=${logValue(message.slice(0, MAX_MESSAGE_LENGTH))}`
|
|
559
560
|
].join(" ");
|
|
560
561
|
}
|
|
561
|
-
function logProviderFailure(err, context) {
|
|
562
|
+
function logProviderFailure(err, context, label = "Provider call failed") {
|
|
563
|
+
if (err?.name === "AbortError") {
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
562
566
|
const op = typeof context?.op === "string" ? logValue(context.op) : "-";
|
|
563
567
|
const key = typeof context?.key === "string" ? logValue(context.key) : "-";
|
|
564
|
-
logger.warn(
|
|
568
|
+
logger.warn(`${label}: op=${op} key=${key} ${describeProviderFailure(err)}`);
|
|
565
569
|
}
|
|
566
570
|
var UNREACHABLE_CODES = /* @__PURE__ */ new Set([
|
|
567
571
|
"ECONNREFUSED",
|
|
@@ -630,10 +634,17 @@ function providerFailureStatus(err) {
|
|
|
630
634
|
}
|
|
631
635
|
|
|
632
636
|
// src/server/errors/aws-error-mapper.ts
|
|
637
|
+
function awsCodeOf(err) {
|
|
638
|
+
const e = err ?? {};
|
|
639
|
+
return e.Code ?? e.name;
|
|
640
|
+
}
|
|
641
|
+
function isNoSuchBucket(err) {
|
|
642
|
+
return awsCodeOf(err) === "NoSuchBucket";
|
|
643
|
+
}
|
|
633
644
|
function mapAwsError(err, context) {
|
|
634
645
|
const e = err ?? {};
|
|
635
646
|
const httpStatus = e.$metadata?.httpStatusCode;
|
|
636
|
-
const awsCode =
|
|
647
|
+
const awsCode = awsCodeOf(err);
|
|
637
648
|
const requestId = e.$metadata?.requestId;
|
|
638
649
|
const details = {
|
|
639
650
|
...context ?? {},
|
|
@@ -643,7 +654,7 @@ function mapAwsError(err, context) {
|
|
|
643
654
|
// A fixed word, never what the driver or the provider wrote.
|
|
644
655
|
reason: providerFailureReason(err)
|
|
645
656
|
};
|
|
646
|
-
if (
|
|
657
|
+
if (isNoSuchBucket(err)) {
|
|
647
658
|
return new StorageException(
|
|
648
659
|
STORAGE_ERROR_CODES.STORAGE_BUCKET_NOT_FOUND,
|
|
649
660
|
common.HttpStatus.NOT_FOUND,
|
|
@@ -673,11 +684,7 @@ function mapAwsError(err, context) {
|
|
|
673
684
|
}
|
|
674
685
|
if (e.name === "TimeoutError") {
|
|
675
686
|
logProviderFailure(err, context);
|
|
676
|
-
return new StorageException(
|
|
677
|
-
STORAGE_ERROR_CODES.STORAGE_TIMEOUT,
|
|
678
|
-
void 0,
|
|
679
|
-
details
|
|
680
|
-
);
|
|
687
|
+
return new StorageException(STORAGE_ERROR_CODES.STORAGE_TIMEOUT, void 0, details);
|
|
681
688
|
}
|
|
682
689
|
logProviderFailure(err, context);
|
|
683
690
|
return new StorageException(
|
|
@@ -1292,6 +1299,10 @@ var SourceIdleError = class extends Error {
|
|
|
1292
1299
|
}
|
|
1293
1300
|
idleMs;
|
|
1294
1301
|
};
|
|
1302
|
+
function isError(value) {
|
|
1303
|
+
const candidate = value;
|
|
1304
|
+
return typeof candidate?.name === "string" && typeof candidate.message === "string";
|
|
1305
|
+
}
|
|
1295
1306
|
function withinIdleTime(next, idleMs) {
|
|
1296
1307
|
return new Promise((resolve, reject) => {
|
|
1297
1308
|
const timer = setTimeout(() => {
|
|
@@ -1304,7 +1315,7 @@ function withinIdleTime(next, idleMs) {
|
|
|
1304
1315
|
},
|
|
1305
1316
|
(error) => {
|
|
1306
1317
|
clearTimeout(timer);
|
|
1307
|
-
reject(error
|
|
1318
|
+
reject(isError(error) ? error : new Error(describeError(error)));
|
|
1308
1319
|
}
|
|
1309
1320
|
);
|
|
1310
1321
|
});
|
|
@@ -1395,10 +1406,10 @@ function mapMultipartError(err, context) {
|
|
|
1395
1406
|
if (tooLong) {
|
|
1396
1407
|
return tooLong;
|
|
1397
1408
|
}
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
return bucketMissing;
|
|
1409
|
+
if (isNoSuchBucket(err)) {
|
|
1410
|
+
return mapAwsError(err, context);
|
|
1401
1411
|
}
|
|
1412
|
+
logProviderFailure(err, context, "Multipart upload failed");
|
|
1402
1413
|
return new StorageException(
|
|
1403
1414
|
STORAGE_ERROR_CODES.STORAGE_MULTIPART_ABORTED,
|
|
1404
1415
|
// An outage ends the upload as an outage; any other cause is a failure of the upload itself.
|
|
@@ -1708,9 +1719,15 @@ function guardDownloadBody(body, idleMs, context, signal) {
|
|
|
1708
1719
|
idleMs: error.idleMs
|
|
1709
1720
|
});
|
|
1710
1721
|
}
|
|
1711
|
-
return signal?.aborted ? requestAborted(signal, context) : error;
|
|
1722
|
+
return signal?.aborted ? requestAborted(signal, context) : mapAwsError(error, context);
|
|
1712
1723
|
});
|
|
1713
1724
|
}
|
|
1725
|
+
function mapBodyReadFailure(err, signal, context) {
|
|
1726
|
+
if (err instanceof StorageException) {
|
|
1727
|
+
return err;
|
|
1728
|
+
}
|
|
1729
|
+
return signal?.aborted ? requestAborted(signal, context) : mapAwsError(err, context);
|
|
1730
|
+
}
|
|
1714
1731
|
|
|
1715
1732
|
// src/server/utils/public-url.ts
|
|
1716
1733
|
function buildPublicUrl(options, finalKey, bucket) {
|
|
@@ -1800,7 +1817,7 @@ function assertMaxBytes(maxBytes) {
|
|
|
1800
1817
|
});
|
|
1801
1818
|
}
|
|
1802
1819
|
}
|
|
1803
|
-
async function
|
|
1820
|
+
async function readBody(stream, metadata, maxBytes) {
|
|
1804
1821
|
if (maxBytes === void 0) {
|
|
1805
1822
|
return readStream(stream);
|
|
1806
1823
|
}
|
|
@@ -1815,6 +1832,17 @@ async function readDownloadBody(stream, metadata, maxBytes) {
|
|
|
1815
1832
|
}
|
|
1816
1833
|
return buffer;
|
|
1817
1834
|
}
|
|
1835
|
+
async function readDownloadBody(stream, metadata, maxBytes, signal) {
|
|
1836
|
+
try {
|
|
1837
|
+
return await readBody(stream, metadata, maxBytes);
|
|
1838
|
+
} catch (err) {
|
|
1839
|
+
throw mapBodyReadFailure(err, signal, {
|
|
1840
|
+
key: metadata.key,
|
|
1841
|
+
bucket: metadata.bucket,
|
|
1842
|
+
op: "downloadBuffer"
|
|
1843
|
+
});
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1818
1846
|
|
|
1819
1847
|
// src/server/services/storage.service.ts
|
|
1820
1848
|
var MAX_LIST_KEYS = 1e3;
|
|
@@ -2088,7 +2116,7 @@ exports.StorageService = class StorageService {
|
|
|
2088
2116
|
const stream = guardDownloadBody(
|
|
2089
2117
|
response.Body,
|
|
2090
2118
|
this.options.bodyIdleTimeoutMs,
|
|
2091
|
-
|
|
2119
|
+
context,
|
|
2092
2120
|
options.abortSignal
|
|
2093
2121
|
);
|
|
2094
2122
|
return { stream, metadata: this.toObjectMetadata(response, finalKey, bucket) };
|
|
@@ -2111,7 +2139,8 @@ exports.StorageService = class StorageService {
|
|
|
2111
2139
|
async downloadBuffer(options) {
|
|
2112
2140
|
assertMaxBytes(options.maxBytes);
|
|
2113
2141
|
const { stream, metadata } = await this.download(options);
|
|
2114
|
-
|
|
2142
|
+
const buffer = await readDownloadBody(stream, metadata, options.maxBytes, options.abortSignal);
|
|
2143
|
+
return { buffer, metadata };
|
|
2115
2144
|
}
|
|
2116
2145
|
/**
|
|
2117
2146
|
* Deletes an object. Idempotent: a missing object is a no-op (logged as a
|
package/dist/server/index.mjs
CHANGED
|
@@ -539,7 +539,8 @@ function logValue(value) {
|
|
|
539
539
|
}
|
|
540
540
|
|
|
541
541
|
// src/server/utils/provider-failure-log.ts
|
|
542
|
-
var SECRET_IN_MESSAGE = /(X-Amz-(?:Signature|Credential|Security-Token)|AWSAccessKeyId|Signature)=[^&\s"']+/gi;
|
|
542
|
+
var SECRET_IN_MESSAGE = /(X-Amz-(?:Signature|Credential|Security-Token)|AWSAccessKeyId|Credential|Signature)=[^&\s"']+/gi;
|
|
543
|
+
var BARE_ACCESS_KEY_ID = /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g;
|
|
543
544
|
var MAX_MESSAGE_LENGTH = 300;
|
|
544
545
|
var logger = new Logger("StorageProvider");
|
|
545
546
|
function field(value) {
|
|
@@ -547,7 +548,7 @@ function field(value) {
|
|
|
547
548
|
}
|
|
548
549
|
function describeProviderFailure(err) {
|
|
549
550
|
const failure = typeof err === "object" && err !== null ? err : {};
|
|
550
|
-
const message = describeError(err).replace(SECRET_IN_MESSAGE, "$1=[redacted]");
|
|
551
|
+
const message = describeError(err).replace(SECRET_IN_MESSAGE, "$1=[redacted]").replace(BARE_ACCESS_KEY_ID, "[redacted-key-id]");
|
|
551
552
|
return [
|
|
552
553
|
`name=${field(failure.name)}`,
|
|
553
554
|
`code=${field(failure.Code)}`,
|
|
@@ -556,10 +557,13 @@ function describeProviderFailure(err) {
|
|
|
556
557
|
`message=${logValue(message.slice(0, MAX_MESSAGE_LENGTH))}`
|
|
557
558
|
].join(" ");
|
|
558
559
|
}
|
|
559
|
-
function logProviderFailure(err, context) {
|
|
560
|
+
function logProviderFailure(err, context, label = "Provider call failed") {
|
|
561
|
+
if (err?.name === "AbortError") {
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
560
564
|
const op = typeof context?.op === "string" ? logValue(context.op) : "-";
|
|
561
565
|
const key = typeof context?.key === "string" ? logValue(context.key) : "-";
|
|
562
|
-
logger.warn(
|
|
566
|
+
logger.warn(`${label}: op=${op} key=${key} ${describeProviderFailure(err)}`);
|
|
563
567
|
}
|
|
564
568
|
var UNREACHABLE_CODES = /* @__PURE__ */ new Set([
|
|
565
569
|
"ECONNREFUSED",
|
|
@@ -628,10 +632,17 @@ function providerFailureStatus(err) {
|
|
|
628
632
|
}
|
|
629
633
|
|
|
630
634
|
// src/server/errors/aws-error-mapper.ts
|
|
635
|
+
function awsCodeOf(err) {
|
|
636
|
+
const e = err ?? {};
|
|
637
|
+
return e.Code ?? e.name;
|
|
638
|
+
}
|
|
639
|
+
function isNoSuchBucket(err) {
|
|
640
|
+
return awsCodeOf(err) === "NoSuchBucket";
|
|
641
|
+
}
|
|
631
642
|
function mapAwsError(err, context) {
|
|
632
643
|
const e = err ?? {};
|
|
633
644
|
const httpStatus = e.$metadata?.httpStatusCode;
|
|
634
|
-
const awsCode =
|
|
645
|
+
const awsCode = awsCodeOf(err);
|
|
635
646
|
const requestId = e.$metadata?.requestId;
|
|
636
647
|
const details = {
|
|
637
648
|
...context ?? {},
|
|
@@ -641,7 +652,7 @@ function mapAwsError(err, context) {
|
|
|
641
652
|
// A fixed word, never what the driver or the provider wrote.
|
|
642
653
|
reason: providerFailureReason(err)
|
|
643
654
|
};
|
|
644
|
-
if (
|
|
655
|
+
if (isNoSuchBucket(err)) {
|
|
645
656
|
return new StorageException(
|
|
646
657
|
STORAGE_ERROR_CODES.STORAGE_BUCKET_NOT_FOUND,
|
|
647
658
|
HttpStatus.NOT_FOUND,
|
|
@@ -671,11 +682,7 @@ function mapAwsError(err, context) {
|
|
|
671
682
|
}
|
|
672
683
|
if (e.name === "TimeoutError") {
|
|
673
684
|
logProviderFailure(err, context);
|
|
674
|
-
return new StorageException(
|
|
675
|
-
STORAGE_ERROR_CODES.STORAGE_TIMEOUT,
|
|
676
|
-
void 0,
|
|
677
|
-
details
|
|
678
|
-
);
|
|
685
|
+
return new StorageException(STORAGE_ERROR_CODES.STORAGE_TIMEOUT, void 0, details);
|
|
679
686
|
}
|
|
680
687
|
logProviderFailure(err, context);
|
|
681
688
|
return new StorageException(
|
|
@@ -1290,6 +1297,10 @@ var SourceIdleError = class extends Error {
|
|
|
1290
1297
|
}
|
|
1291
1298
|
idleMs;
|
|
1292
1299
|
};
|
|
1300
|
+
function isError(value) {
|
|
1301
|
+
const candidate = value;
|
|
1302
|
+
return typeof candidate?.name === "string" && typeof candidate.message === "string";
|
|
1303
|
+
}
|
|
1293
1304
|
function withinIdleTime(next, idleMs) {
|
|
1294
1305
|
return new Promise((resolve, reject) => {
|
|
1295
1306
|
const timer = setTimeout(() => {
|
|
@@ -1302,7 +1313,7 @@ function withinIdleTime(next, idleMs) {
|
|
|
1302
1313
|
},
|
|
1303
1314
|
(error) => {
|
|
1304
1315
|
clearTimeout(timer);
|
|
1305
|
-
reject(error
|
|
1316
|
+
reject(isError(error) ? error : new Error(describeError(error)));
|
|
1306
1317
|
}
|
|
1307
1318
|
);
|
|
1308
1319
|
});
|
|
@@ -1393,10 +1404,10 @@ function mapMultipartError(err, context) {
|
|
|
1393
1404
|
if (tooLong) {
|
|
1394
1405
|
return tooLong;
|
|
1395
1406
|
}
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
return bucketMissing;
|
|
1407
|
+
if (isNoSuchBucket(err)) {
|
|
1408
|
+
return mapAwsError(err, context);
|
|
1399
1409
|
}
|
|
1410
|
+
logProviderFailure(err, context, "Multipart upload failed");
|
|
1400
1411
|
return new StorageException(
|
|
1401
1412
|
STORAGE_ERROR_CODES.STORAGE_MULTIPART_ABORTED,
|
|
1402
1413
|
// An outage ends the upload as an outage; any other cause is a failure of the upload itself.
|
|
@@ -1706,9 +1717,15 @@ function guardDownloadBody(body, idleMs, context, signal) {
|
|
|
1706
1717
|
idleMs: error.idleMs
|
|
1707
1718
|
});
|
|
1708
1719
|
}
|
|
1709
|
-
return signal?.aborted ? requestAborted(signal, context) : error;
|
|
1720
|
+
return signal?.aborted ? requestAborted(signal, context) : mapAwsError(error, context);
|
|
1710
1721
|
});
|
|
1711
1722
|
}
|
|
1723
|
+
function mapBodyReadFailure(err, signal, context) {
|
|
1724
|
+
if (err instanceof StorageException) {
|
|
1725
|
+
return err;
|
|
1726
|
+
}
|
|
1727
|
+
return signal?.aborted ? requestAborted(signal, context) : mapAwsError(err, context);
|
|
1728
|
+
}
|
|
1712
1729
|
|
|
1713
1730
|
// src/server/utils/public-url.ts
|
|
1714
1731
|
function buildPublicUrl(options, finalKey, bucket) {
|
|
@@ -1798,7 +1815,7 @@ function assertMaxBytes(maxBytes) {
|
|
|
1798
1815
|
});
|
|
1799
1816
|
}
|
|
1800
1817
|
}
|
|
1801
|
-
async function
|
|
1818
|
+
async function readBody(stream, metadata, maxBytes) {
|
|
1802
1819
|
if (maxBytes === void 0) {
|
|
1803
1820
|
return readStream(stream);
|
|
1804
1821
|
}
|
|
@@ -1813,6 +1830,17 @@ async function readDownloadBody(stream, metadata, maxBytes) {
|
|
|
1813
1830
|
}
|
|
1814
1831
|
return buffer;
|
|
1815
1832
|
}
|
|
1833
|
+
async function readDownloadBody(stream, metadata, maxBytes, signal) {
|
|
1834
|
+
try {
|
|
1835
|
+
return await readBody(stream, metadata, maxBytes);
|
|
1836
|
+
} catch (err) {
|
|
1837
|
+
throw mapBodyReadFailure(err, signal, {
|
|
1838
|
+
key: metadata.key,
|
|
1839
|
+
bucket: metadata.bucket,
|
|
1840
|
+
op: "downloadBuffer"
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1816
1844
|
|
|
1817
1845
|
// src/server/services/storage.service.ts
|
|
1818
1846
|
var MAX_LIST_KEYS = 1e3;
|
|
@@ -2086,7 +2114,7 @@ var StorageService = class {
|
|
|
2086
2114
|
const stream = guardDownloadBody(
|
|
2087
2115
|
response.Body,
|
|
2088
2116
|
this.options.bodyIdleTimeoutMs,
|
|
2089
|
-
|
|
2117
|
+
context,
|
|
2090
2118
|
options.abortSignal
|
|
2091
2119
|
);
|
|
2092
2120
|
return { stream, metadata: this.toObjectMetadata(response, finalKey, bucket) };
|
|
@@ -2109,7 +2137,8 @@ var StorageService = class {
|
|
|
2109
2137
|
async downloadBuffer(options) {
|
|
2110
2138
|
assertMaxBytes(options.maxBytes);
|
|
2111
2139
|
const { stream, metadata } = await this.download(options);
|
|
2112
|
-
|
|
2140
|
+
const buffer = await readDownloadBody(stream, metadata, options.maxBytes, options.abortSignal);
|
|
2141
|
+
return { buffer, metadata };
|
|
2113
2142
|
}
|
|
2114
2143
|
/**
|
|
2115
2144
|
* Deletes an object. Idempotent: a missing object is a no-op (logged as a
|
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.15",
|
|
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",
|