@venizia/ignis-helpers 0.4.8-8 → 0.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/dist/esm/common/constants/app.d.ts +1 -3
- package/dist/esm/common/constants/app.js +1 -11
- package/dist/esm/common/constants/app.js.map +1 -1
- package/dist/esm/common/constants/http.d.ts +4 -0
- package/dist/esm/common/constants/http.js +5 -0
- package/dist/esm/common/constants/http.js.map +1 -1
- package/dist/esm/common/constants/mime.d.ts +0 -2
- package/dist/esm/common/constants/mime.js +0 -4
- package/dist/esm/common/constants/mime.js.map +1 -1
- package/dist/esm/common/redact.js.map +1 -1
- package/dist/esm/common/types/class.d.ts +14 -12
- package/dist/esm/common/types/class.js.map +1 -1
- package/dist/esm/common/types/const-value.d.ts +3 -3
- package/dist/esm/common/types/const-value.js.map +1 -1
- package/dist/esm/common/types/field-mapping.d.ts +6 -8
- package/dist/esm/common/types/field-mapping.js +0 -10
- package/dist/esm/common/types/field-mapping.js.map +1 -1
- package/dist/esm/common/types/index.d.ts +1 -0
- package/dist/esm/common/types/index.js +1 -0
- package/dist/esm/common/types/index.js.map +1 -1
- package/dist/esm/common/types/injection.d.ts +1 -1
- package/dist/esm/common/types/injection.js.map +1 -1
- package/dist/esm/common/types/json.d.ts +14 -0
- package/dist/esm/common/types/json.js +2 -0
- package/dist/esm/common/types/json.js.map +1 -0
- package/dist/esm/common/types/utility.d.ts +0 -4
- package/dist/esm/common/types/utility.js.map +1 -1
- package/dist/esm/modules/env/app-env.d.ts +17 -8
- package/dist/esm/modules/env/app-env.js +18 -15
- package/dist/esm/modules/env/app-env.js.map +1 -1
- package/dist/esm/modules/env/common/types.d.ts +22 -6
- package/dist/esm/modules/env/common/types.js.map +1 -1
- package/dist/esm/modules/logger/base/abstract.d.ts +6 -7
- package/dist/esm/modules/logger/base/abstract.js.map +1 -1
- package/dist/esm/modules/logger/base/base.d.ts +7 -8
- package/dist/esm/modules/logger/base/base.js.map +1 -1
- package/dist/esm/modules/logger/base/console.d.ts +6 -7
- package/dist/esm/modules/logger/base/console.js.map +1 -1
- package/dist/esm/modules/logger/common/types.d.ts +7 -7
- package/dist/esm/modules/logger/common/types.js.map +1 -1
- package/dist/esm/modules/logger/factory.js.map +1 -1
- package/dist/esm/modules/logger/hf/flusher.js.map +1 -1
- package/dist/esm/modules/logger/hf/logger.d.ts +6 -7
- package/dist/esm/modules/logger/hf/logger.js.map +1 -1
- package/dist/esm/modules/logger/pino/backing.js.map +1 -1
- package/dist/esm/modules/logger/pino/destination.d.ts +1 -1
- package/dist/esm/modules/logger/pino/destination.js.map +1 -1
- package/dist/esm/modules/logger/pino/logger.d.ts +1 -2
- package/dist/esm/modules/logger/pino/logger.js.map +1 -1
- package/dist/esm/modules/logger/winston/formats.js +2 -2
- package/dist/esm/modules/logger/winston/formats.js.map +1 -1
- package/dist/esm/modules/logger/winston/logger.d.ts +1 -2
- package/dist/esm/modules/logger/winston/logger.js.map +1 -1
- package/dist/esm/modules/logger/winston/transports/dgram.transport.d.ts +1 -1
- package/dist/esm/modules/logger/winston/transports/dgram.transport.js +1 -1
- package/dist/esm/modules/logger/winston/transports/dgram.transport.js.map +1 -1
- package/dist/esm/modules/network/http-request/common/constants.d.ts +0 -2
- package/dist/esm/modules/network/http-request/common/constants.js +0 -4
- package/dist/esm/modules/network/http-request/common/constants.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.d.ts +6 -6
- package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/base-fetcher.d.ts +2 -3
- package/dist/esm/modules/network/http-request/fetcher/base-fetcher.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/common/types.d.ts +1 -1
- package/dist/esm/modules/network/http-request/fetcher/common/types.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/node-fetcher.d.ts +1 -2
- package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js +5 -6
- package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js.map +1 -1
- package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.d.ts +4 -4
- package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js +1 -1
- package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js.map +1 -1
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.d.ts +3 -5
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js +0 -8
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
- package/dist/esm/modules/network/utilities/query-string.d.ts +2 -2
- package/dist/esm/modules/network/utilities/query-string.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/common/constants.d.ts +0 -2
- package/dist/esm/modules/network/utilities/url-safety/common/constants.js +0 -4
- package/dist/esm/modules/network/utilities/url-safety/common/constants.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/ingest.js.map +1 -1
- package/dist/esm/modules/queue/bullmq/helper.d.ts +23 -10
- package/dist/esm/modules/queue/bullmq/helper.js +57 -10
- package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
- package/dist/esm/modules/queue/common/constants.d.ts +6 -2
- package/dist/esm/modules/queue/common/constants.js +6 -4
- package/dist/esm/modules/queue/common/constants.js.map +1 -1
- package/dist/esm/modules/queue/internal/sequential/common/types.d.ts +2 -4
- package/dist/esm/modules/queue/internal/sequential/common/types.js +0 -4
- package/dist/esm/modules/queue/internal/sequential/common/types.js.map +1 -1
- package/dist/esm/modules/queue/kafka/base.d.ts +1 -1
- package/dist/esm/modules/queue/kafka/base.js +13 -2
- package/dist/esm/modules/queue/kafka/base.js.map +1 -1
- package/dist/esm/modules/queue/kafka/common/constants.d.ts +0 -4
- package/dist/esm/modules/queue/kafka/common/constants.js +0 -8
- package/dist/esm/modules/queue/kafka/common/constants.js.map +1 -1
- package/dist/esm/modules/redis/base/abstract.helper.d.ts +13 -2
- package/dist/esm/modules/redis/base/abstract.helper.js +53 -45
- package/dist/esm/modules/redis/base/abstract.helper.js.map +1 -1
- package/dist/esm/modules/redis/cluster/cluster.helper.d.ts +1 -2
- package/dist/esm/modules/redis/cluster/cluster.helper.js +21 -9
- package/dist/esm/modules/redis/cluster/cluster.helper.js.map +1 -1
- package/dist/esm/modules/redis/cluster/index.d.ts +1 -0
- package/dist/esm/modules/redis/cluster/index.js +1 -0
- package/dist/esm/modules/redis/cluster/index.js.map +1 -1
- package/dist/esm/modules/redis/cluster/types.d.ts +20 -0
- package/dist/esm/modules/redis/cluster/types.js +2 -0
- package/dist/esm/modules/redis/cluster/types.js.map +1 -0
- package/dist/esm/modules/redis/common/constants.d.ts +15 -19
- package/dist/esm/modules/redis/common/constants.js +16 -18
- package/dist/esm/modules/redis/common/constants.js.map +1 -1
- package/dist/esm/modules/redis/common/types.d.ts +10 -60
- package/dist/esm/modules/redis/common/types.js.map +1 -1
- package/dist/esm/modules/redis/factory.d.ts +7 -25
- package/dist/esm/modules/redis/factory.js +9 -18
- package/dist/esm/modules/redis/factory.js.map +1 -1
- package/dist/esm/modules/redis/sentinel/constants.d.ts +14 -0
- package/dist/esm/modules/redis/sentinel/constants.js +11 -0
- package/dist/esm/modules/redis/sentinel/constants.js.map +1 -0
- package/dist/esm/modules/redis/sentinel/index.d.ts +2 -0
- package/dist/esm/modules/redis/sentinel/index.js +2 -0
- package/dist/esm/modules/redis/sentinel/index.js.map +1 -1
- package/dist/esm/modules/redis/sentinel/sentinel.helper.d.ts +1 -2
- package/dist/esm/modules/redis/sentinel/sentinel.helper.js +25 -15
- package/dist/esm/modules/redis/sentinel/sentinel.helper.js.map +1 -1
- package/dist/esm/modules/redis/sentinel/types.d.ts +26 -0
- package/dist/esm/modules/redis/sentinel/types.js +2 -0
- package/dist/esm/modules/redis/sentinel/types.js.map +1 -0
- package/dist/esm/modules/redis/single/index.d.ts +1 -0
- package/dist/esm/modules/redis/single/index.js +1 -0
- package/dist/esm/modules/redis/single/index.js.map +1 -1
- package/dist/esm/modules/redis/single/single.helper.d.ts +1 -2
- package/dist/esm/modules/redis/single/single.helper.js +5 -6
- package/dist/esm/modules/redis/single/single.helper.js.map +1 -1
- package/dist/esm/modules/redis/single/types.d.ts +15 -0
- package/dist/esm/modules/redis/single/types.js +2 -0
- package/dist/esm/modules/redis/single/types.js.map +1 -0
- package/dist/esm/modules/secrets/base/abstract.helper.js +6 -1
- package/dist/esm/modules/secrets/base/abstract.helper.js.map +1 -1
- package/dist/esm/modules/secrets/common/types/registration.d.ts +25 -6
- package/dist/esm/modules/secrets/common/types/registration.js.map +1 -1
- package/dist/esm/modules/secrets/dotenv/dotenv.helper.js +1 -1
- package/dist/esm/modules/secrets/dotenv/dotenv.helper.js.map +1 -1
- package/dist/esm/modules/secrets/factory.js +7 -6
- package/dist/esm/modules/secrets/factory.js.map +1 -1
- package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.d.ts +12 -10
- package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js +50 -25
- package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js.map +1 -1
- package/dist/esm/modules/socket/socket-io/client/browser-helper.js.map +1 -1
- package/dist/esm/modules/socket/socket-io/common/types/client.d.ts +2 -2
- package/dist/esm/modules/socket/socket-io/common/types/client.js.map +1 -1
- package/dist/esm/modules/socket/socket-io/common/types/server.d.ts +3 -1
- package/dist/esm/modules/socket/socket-io/common/types/server.js.map +1 -1
- package/dist/esm/modules/socket/socket-io/server/helper.d.ts +2 -2
- package/dist/esm/modules/socket/socket-io/server/helper.js.map +1 -1
- package/dist/esm/modules/storage/base.d.ts +26 -57
- package/dist/esm/modules/storage/base.js +76 -127
- package/dist/esm/modules/storage/base.js.map +1 -1
- package/dist/esm/modules/storage/bun-s3/helper.d.ts +22 -37
- package/dist/esm/modules/storage/bun-s3/helper.js +131 -132
- package/dist/esm/modules/storage/bun-s3/helper.js.map +1 -1
- package/dist/esm/modules/storage/bun-s3/utility.d.ts +15 -8
- package/dist/esm/modules/storage/bun-s3/utility.js +66 -47
- package/dist/esm/modules/storage/bun-s3/utility.js.map +1 -1
- package/dist/esm/modules/storage/common/constants.d.ts +36 -2
- package/dist/esm/modules/storage/common/constants.js +34 -4
- package/dist/esm/modules/storage/common/constants.js.map +1 -1
- package/dist/esm/modules/storage/common/errors.d.ts +26 -0
- package/dist/esm/modules/storage/common/errors.js +23 -0
- package/dist/esm/modules/storage/common/errors.js.map +1 -1
- package/dist/esm/modules/storage/common/types.d.ts +99 -57
- package/dist/esm/modules/storage/common/types.js.map +1 -1
- package/dist/esm/modules/storage/common/utility.d.ts +8 -0
- package/dist/esm/modules/storage/common/utility.js +14 -2
- package/dist/esm/modules/storage/common/utility.js.map +1 -1
- package/dist/esm/modules/storage/disk/helper.d.ts +4 -8
- package/dist/esm/modules/storage/disk/helper.js +3 -1
- package/dist/esm/modules/storage/disk/helper.js.map +1 -1
- package/dist/esm/modules/storage/in-memory/helper.d.ts +2 -3
- package/dist/esm/modules/storage/in-memory/helper.js.map +1 -1
- package/dist/esm/modules/worker-thread/common/types.d.ts +2 -2
- package/dist/esm/modules/worker-thread/common/types.js.map +1 -1
- package/dist/esm/modules/worker-thread/thread/abstract.d.ts +2 -2
- package/dist/esm/modules/worker-thread/thread/abstract.js.map +1 -1
- package/dist/esm/modules/worker-thread/worker-pool.d.ts +1 -1
- package/dist/esm/modules/worker-thread/worker-pool.js.map +1 -1
- package/dist/esm/utilities/module.utility.d.ts +8 -5
- package/dist/esm/utilities/module.utility.js +5 -1
- package/dist/esm/utilities/module.utility.js.map +1 -1
- package/dist/esm/utilities/parse.utility.d.ts +34 -6
- package/dist/esm/utilities/parse.utility.js +82 -15
- package/dist/esm/utilities/parse.utility.js.map +1 -1
- package/dist/esm/utilities/performance.utility.d.ts +3 -3
- package/dist/esm/utilities/performance.utility.js.map +1 -1
- package/dist/esm/utilities/promise.utility.d.ts +1 -1
- package/dist/esm/utilities/promise.utility.js.map +1 -1
- package/dist/esm/utilities/request.utility.d.ts +9 -11
- package/dist/esm/utilities/request.utility.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { HTTP } from '../../../common/constants/http.js';
|
|
1
2
|
import { getError } from '../../error/index.js';
|
|
2
3
|
import { ErrorPrettier } from '../../logger/index.js';
|
|
3
4
|
import { EchoUtility } from '../../../utilities/echo.utility.js';
|
|
4
5
|
import { S3Client } from 'bun';
|
|
5
6
|
import { Readable } from 'node:stream';
|
|
6
7
|
import { BaseStorageHelper } from '../base.js';
|
|
7
|
-
import { S3Audiences, StorageUtility, StoragePresignDefaults } from '../common/index.js';
|
|
8
|
+
import { S3Audiences, S3Defaults, S3Headers, StorageErrors, StorageLimits, StorageTypes, StorageUtility, StoragePresignDefaults, } from '../common/index.js';
|
|
8
9
|
import { S3SignatureUtility } from './utility.js';
|
|
9
10
|
/** One lower-case DNS label: the only shape a bucket may have when it becomes part of a host. */
|
|
10
11
|
const S3_HOST_LABEL_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
@@ -15,6 +16,7 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
15
16
|
scope: options.scope ?? BunS3Helper.name,
|
|
16
17
|
identifier: options.identifier ?? BunS3Helper.name,
|
|
17
18
|
});
|
|
19
|
+
this.storageType = StorageTypes.BUN_S3;
|
|
18
20
|
this.credentials = {
|
|
19
21
|
accessKey: options.accessKey,
|
|
20
22
|
secretKey: options.secretKey,
|
|
@@ -23,7 +25,7 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
23
25
|
// Falls back to the default, so one reachable host still serves both audiences.
|
|
24
26
|
public: options.endpoint.public ?? options.endpoint.default,
|
|
25
27
|
},
|
|
26
|
-
region: options.region ??
|
|
28
|
+
region: options.region ?? S3Defaults.REGION,
|
|
27
29
|
sessionToken: options.sessionToken,
|
|
28
30
|
virtualHostedStyle: options.virtualHostedStyle ?? false,
|
|
29
31
|
};
|
|
@@ -60,7 +62,6 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
60
62
|
}
|
|
61
63
|
/** Per-call overrides, so one client serves every bucket in either addressing style. */
|
|
62
64
|
presignOptions(opts) {
|
|
63
|
-
const { virtualHostedStyle } = this.credentials;
|
|
64
65
|
const { endpoint } = this.objectEndpoint({
|
|
65
66
|
bucket: opts.bucket,
|
|
66
67
|
audience: S3Audiences.BROWSER,
|
|
@@ -68,7 +69,7 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
68
69
|
return {
|
|
69
70
|
bucket: opts.bucket,
|
|
70
71
|
endpoint,
|
|
71
|
-
|
|
72
|
+
virtualHostedStyle: this.credentials.virtualHostedStyle,
|
|
72
73
|
};
|
|
73
74
|
}
|
|
74
75
|
/**
|
|
@@ -101,19 +102,7 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
async getBuckets() {
|
|
104
|
-
|
|
105
|
-
const { accessKey, secretKey, region, sessionToken } = this.credentials;
|
|
106
|
-
const endpoint = this.credentials.endpoint.default;
|
|
107
|
-
const { url, headers } = await S3SignatureUtility.buildSignedRequest({
|
|
108
|
-
method: 'GET',
|
|
109
|
-
endpoint,
|
|
110
|
-
path: '/',
|
|
111
|
-
accessKey,
|
|
112
|
-
secretKey,
|
|
113
|
-
region,
|
|
114
|
-
sessionToken,
|
|
115
|
-
});
|
|
116
|
-
const response = await fetch(url, { method: 'GET', headers });
|
|
105
|
+
const response = await this.bucketFetch({ method: HTTP.Methods.GET, path: '/' });
|
|
117
106
|
const xml = await response.text();
|
|
118
107
|
if (!response.ok) {
|
|
119
108
|
throw getError({ message: `[getBuckets] S3 error: ${xml}` });
|
|
@@ -142,19 +131,7 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
142
131
|
if (!this.isValidBucketName(opts)) {
|
|
143
132
|
throw getError({ message: '[createBucket] Invalid name to create bucket!' });
|
|
144
133
|
}
|
|
145
|
-
|
|
146
|
-
const { accessKey, secretKey, region, sessionToken } = this.credentials;
|
|
147
|
-
const endpoint = this.credentials.endpoint.default;
|
|
148
|
-
const { url, headers } = await S3SignatureUtility.buildSignedRequest({
|
|
149
|
-
method: 'PUT',
|
|
150
|
-
endpoint,
|
|
151
|
-
path: `/${name}`,
|
|
152
|
-
accessKey: accessKey,
|
|
153
|
-
secretKey,
|
|
154
|
-
region,
|
|
155
|
-
sessionToken,
|
|
156
|
-
});
|
|
157
|
-
const response = await fetch(url, { method: 'PUT', headers });
|
|
134
|
+
const response = await this.bucketFetch({ method: HTTP.Methods.PUT, path: `/${name}` });
|
|
158
135
|
if (!response.ok) {
|
|
159
136
|
const xml = await response.text();
|
|
160
137
|
throw getError({ message: `[createBucket] S3 error: ${xml}` });
|
|
@@ -166,19 +143,7 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
166
143
|
if (!this.isValidBucketName(opts)) {
|
|
167
144
|
throw getError({ message: '[removeBucket] Invalid name to remove bucket!' });
|
|
168
145
|
}
|
|
169
|
-
|
|
170
|
-
const { accessKey, secretKey, region, sessionToken } = this.credentials;
|
|
171
|
-
const endpoint = this.credentials.endpoint.default;
|
|
172
|
-
const { url, headers } = await S3SignatureUtility.buildSignedRequest({
|
|
173
|
-
method: 'DELETE',
|
|
174
|
-
endpoint,
|
|
175
|
-
path: `/${name}`,
|
|
176
|
-
accessKey: accessKey,
|
|
177
|
-
secretKey: secretKey,
|
|
178
|
-
region,
|
|
179
|
-
sessionToken,
|
|
180
|
-
});
|
|
181
|
-
const response = await fetch(url, { method: 'DELETE', headers });
|
|
146
|
+
const response = await this.bucketFetch({ method: HTTP.Methods.DELETE, path: `/${name}` });
|
|
182
147
|
if (!response.ok) {
|
|
183
148
|
const xml = await response.text();
|
|
184
149
|
throw getError({ message: `[removeBucket] S3 error: ${xml}` });
|
|
@@ -186,48 +151,36 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
186
151
|
return true;
|
|
187
152
|
}
|
|
188
153
|
async copyObject(opts) {
|
|
189
|
-
const { bucket, source, destination } = opts;
|
|
190
|
-
const { accessKey, secretKey, region, sessionToken } = this.credentials;
|
|
191
|
-
const { endpoint, pathPrefix } = this.objectEndpoint({
|
|
192
|
-
bucket: bucket.name,
|
|
193
|
-
audience: S3Audiences.SERVER,
|
|
194
|
-
});
|
|
154
|
+
const { bucket, source, destination, ifMatch, sourceVersionId } = opts;
|
|
195
155
|
// `x-amz-copy-source` is what makes this server side: S3 reads the source itself, so a 500 MB
|
|
196
156
|
// object never travels through this process. The encoded value is both signed and sent.
|
|
197
|
-
const
|
|
198
|
-
method:
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
accessKey,
|
|
202
|
-
secretKey,
|
|
203
|
-
region,
|
|
204
|
-
sessionToken,
|
|
157
|
+
const response = await this.signedFetch({
|
|
158
|
+
method: HTTP.Methods.PUT,
|
|
159
|
+
bucket,
|
|
160
|
+
object: destination,
|
|
205
161
|
headers: {
|
|
206
|
-
|
|
162
|
+
[S3Headers.COPY_SOURCE]: S3SignatureUtility.buildCopySource({
|
|
207
163
|
bucket: bucket.name,
|
|
208
164
|
key: source.key,
|
|
165
|
+
versionId: sourceVersionId,
|
|
209
166
|
}),
|
|
167
|
+
[S3Headers.COPY_SOURCE_IF_MATCH]: BunS3Helper.quoteEtag({ etag: ifMatch }),
|
|
210
168
|
},
|
|
211
169
|
});
|
|
212
|
-
|
|
213
|
-
if (!response.ok) {
|
|
214
|
-
throw getError({
|
|
215
|
-
message: `[copyObject] Copy failed | bucket: ${EchoUtility.toSafeText({ value: bucket.name })} | source: ${EchoUtility.toSafeText({ value: source.key })} | status: ${response.status}`,
|
|
216
|
-
});
|
|
217
|
-
}
|
|
170
|
+
this.assertObjectResponse({ response, operation: 'copyObject', bucket, object: source });
|
|
218
171
|
}
|
|
219
172
|
async presignPost(opts) {
|
|
220
|
-
const { bucket,
|
|
173
|
+
const { bucket, object, maxBytes, contentType, expiresIn = StoragePresignDefaults.POST_EXPIRES_IN, } = opts;
|
|
221
174
|
const { accessKey, secretKey, region, sessionToken } = this.credentials;
|
|
222
|
-
// The browser posts to the BUCKET, not to an object - the key travels as a form field,
|
|
223
|
-
//
|
|
175
|
+
// The browser posts to the BUCKET, not to an object - the key travels as a form field, which the
|
|
176
|
+
// policy pins to this one value.
|
|
224
177
|
const { endpoint, pathPrefix } = this.objectEndpoint({
|
|
225
178
|
bucket: bucket.name,
|
|
226
179
|
audience: S3Audiences.BROWSER,
|
|
227
180
|
});
|
|
228
181
|
const { formData, expiresAt } = await S3SignatureUtility.buildPostPolicy({
|
|
229
182
|
bucket: bucket.name,
|
|
230
|
-
|
|
183
|
+
key: object.key,
|
|
231
184
|
maxBytes,
|
|
232
185
|
expiresInSeconds: StorageUtility.toExpirySeconds({ expiresIn, operation: 'presignPost' }),
|
|
233
186
|
accessKey,
|
|
@@ -248,7 +201,7 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
248
201
|
audience: S3Audiences.BROWSER,
|
|
249
202
|
});
|
|
250
203
|
return S3SignatureUtility.buildPresignedUrl({
|
|
251
|
-
method:
|
|
204
|
+
method: HTTP.Methods.PUT,
|
|
252
205
|
endpoint,
|
|
253
206
|
path: `${pathPrefix}/${object.key}`,
|
|
254
207
|
accessKey,
|
|
@@ -257,11 +210,9 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
257
210
|
sessionToken,
|
|
258
211
|
expiresInSeconds: StorageUtility.toExpirySeconds({ expiresIn, operation: 'presignPut' }),
|
|
259
212
|
headers: {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
...(contentLength === undefined ? {} : { 'content-length': String(contentLength) }),
|
|
264
|
-
...(contentType ? { 'content-type': contentType } : {}),
|
|
213
|
+
[S3Headers.TAGGING]: tagging && S3SignatureUtility.buildTaggingHeader({ tags: tagging }),
|
|
214
|
+
[HTTP.Headers.CONTENT_LENGTH]: contentLength?.toString(),
|
|
215
|
+
[HTTP.Headers.CONTENT_TYPE]: contentType || undefined,
|
|
265
216
|
},
|
|
266
217
|
});
|
|
267
218
|
}
|
|
@@ -271,31 +222,18 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
271
222
|
...this.presignOptions({ bucket: bucket.name }),
|
|
272
223
|
method: 'GET',
|
|
273
224
|
expiresIn: StorageUtility.toExpirySeconds({ expiresIn, operation: 'presignGet' }),
|
|
274
|
-
|
|
275
|
-
|
|
225
|
+
type: responseContentType,
|
|
226
|
+
contentDisposition: responseContentDisposition,
|
|
276
227
|
});
|
|
277
228
|
}
|
|
278
229
|
async getObjectTags(opts) {
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const { endpoint, pathPrefix } = this.objectEndpoint({
|
|
283
|
-
bucket: bucketName,
|
|
284
|
-
audience: S3Audiences.SERVER,
|
|
285
|
-
});
|
|
286
|
-
const { url, headers } = await S3SignatureUtility.buildSignedRequest({
|
|
287
|
-
method: 'GET',
|
|
288
|
-
endpoint,
|
|
289
|
-
path: `${pathPrefix}/${key}`,
|
|
290
|
-
accessKey,
|
|
291
|
-
secretKey,
|
|
292
|
-
region,
|
|
293
|
-
sessionToken,
|
|
230
|
+
const response = await this.signedFetch({
|
|
231
|
+
method: HTTP.Methods.GET,
|
|
232
|
+
...opts,
|
|
294
233
|
query: { tagging: '' },
|
|
295
234
|
});
|
|
296
|
-
const response = await fetch(url, { method: 'GET', headers });
|
|
297
235
|
// S3 answers a missing tag set with 404: the empty case, not a failure.
|
|
298
|
-
if (response.status ===
|
|
236
|
+
if (response.status === HTTP.ResultCodes.RS_4.NotFound) {
|
|
299
237
|
return {};
|
|
300
238
|
}
|
|
301
239
|
const body = await response.text();
|
|
@@ -307,27 +245,13 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
307
245
|
return S3SignatureUtility.parseTaggingXml({ xml: body });
|
|
308
246
|
}
|
|
309
247
|
async replaceObjectTags(opts) {
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const { endpoint, pathPrefix } = this.objectEndpoint({
|
|
315
|
-
bucket: bucketName,
|
|
316
|
-
audience: S3Audiences.SERVER,
|
|
317
|
-
});
|
|
318
|
-
const requestBody = S3SignatureUtility.buildTaggingXml({ tags });
|
|
319
|
-
const { url, headers } = await S3SignatureUtility.buildSignedRequest({
|
|
320
|
-
method: 'PUT',
|
|
321
|
-
endpoint,
|
|
322
|
-
path: `${pathPrefix}/${key}`,
|
|
323
|
-
accessKey,
|
|
324
|
-
secretKey,
|
|
325
|
-
region,
|
|
326
|
-
sessionToken,
|
|
248
|
+
const response = await this.signedFetch({
|
|
249
|
+
method: HTTP.Methods.PUT,
|
|
250
|
+
bucket: opts.bucket,
|
|
251
|
+
object: opts.object,
|
|
327
252
|
query: { tagging: '' },
|
|
328
|
-
body:
|
|
253
|
+
body: S3SignatureUtility.buildTaggingXml({ tags: opts.tags }),
|
|
329
254
|
});
|
|
330
|
-
const response = await fetch(url, { method: 'PUT', headers, body: requestBody });
|
|
331
255
|
if (!response.ok) {
|
|
332
256
|
const body = await response.text();
|
|
333
257
|
throw getError({
|
|
@@ -363,7 +287,7 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
363
287
|
const body = source instanceof ReadableStream ? new Response(source) : source;
|
|
364
288
|
await this.client.write(object.key, body, {
|
|
365
289
|
...this.callOptions({ bucket: bucket.name }),
|
|
366
|
-
|
|
290
|
+
type: contentType,
|
|
367
291
|
partSize: this.transfer.partSize,
|
|
368
292
|
queueSize: this.transfer.queueSize,
|
|
369
293
|
retry: this.transfer.retry,
|
|
@@ -381,6 +305,9 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
381
305
|
}
|
|
382
306
|
/** The conversion-free path a `Response` body wants. `slice` makes it a ranged GET, so only the requested bytes leave S3. */
|
|
383
307
|
async getObjectStream(opts) {
|
|
308
|
+
if (opts.ifMatch !== undefined || opts.versionId !== undefined) {
|
|
309
|
+
return this.getConditionalStream(opts);
|
|
310
|
+
}
|
|
384
311
|
const bucketName = opts.bucket.name;
|
|
385
312
|
const key = opts.object.key;
|
|
386
313
|
const { range } = opts;
|
|
@@ -392,27 +319,97 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
392
319
|
const window = range.end === undefined ? file.slice(range.start) : file.slice(range.start, range.end + 1);
|
|
393
320
|
return window.stream();
|
|
394
321
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
322
|
+
/** The ETag with the quotes S3 sends and expects in `If-Match`. */
|
|
323
|
+
static quoteEtag(opts) {
|
|
324
|
+
const { etag } = opts;
|
|
325
|
+
return etag === undefined || etag.startsWith('"') || etag.startsWith('W/') ? etag : `"${etag}"`;
|
|
326
|
+
}
|
|
327
|
+
/** Signs and sends one request: the one place credentials, signing and the verb's case meet. */
|
|
328
|
+
async send(opts) {
|
|
329
|
+
const { method, body } = opts;
|
|
330
|
+
const { accessKey, secretKey, region, sessionToken } = this.credentials;
|
|
331
|
+
const request = await S3SignatureUtility.buildSignedRequest({
|
|
332
|
+
...opts,
|
|
333
|
+
accessKey,
|
|
334
|
+
secretKey,
|
|
335
|
+
region,
|
|
336
|
+
sessionToken,
|
|
337
|
+
});
|
|
338
|
+
return fetch(request.url, { method: method.toUpperCase(), headers: request.headers, body });
|
|
339
|
+
}
|
|
340
|
+
/** A bucket operation is a call this process makes, so it goes to the default host. */
|
|
341
|
+
bucketFetch(opts) {
|
|
342
|
+
return this.send({ ...opts, endpoint: this.credentials.endpoint.default });
|
|
343
|
+
}
|
|
344
|
+
/** One object-level request, addressed in the configured style on the host this process talks to. */
|
|
345
|
+
signedFetch(opts) {
|
|
346
|
+
const { bucket, object, ...request } = opts;
|
|
347
|
+
const { endpoint, pathPrefix } = this.objectEndpoint({
|
|
348
|
+
bucket: bucket.name,
|
|
349
|
+
audience: S3Audiences.SERVER,
|
|
350
|
+
});
|
|
351
|
+
return this.send({ ...request, endpoint, path: `${pathPrefix}/${object.key}` });
|
|
352
|
+
}
|
|
353
|
+
/** The storage error a response stands for: 412 is a changed object, 404 a missing one, any other failure the backend's own. */
|
|
354
|
+
assertObjectResponse(opts) {
|
|
355
|
+
const { response, operation, bucket, object } = opts;
|
|
356
|
+
if (response.status === HTTP.ResultCodes.RS_4.PreconditionFailed) {
|
|
357
|
+
throw getError({
|
|
358
|
+
error: StorageErrors.PRECONDITION_FAILED,
|
|
359
|
+
message: `[${operation}] The object changed | bucket: ${EchoUtility.toSafeText({ value: bucket.name })} | key: ${EchoUtility.toSafeText({ value: object.key })}`,
|
|
360
|
+
});
|
|
407
361
|
}
|
|
408
|
-
|
|
362
|
+
if (response.status === HTTP.ResultCodes.RS_4.NotFound) {
|
|
409
363
|
throw this.asStorageError({
|
|
410
|
-
error,
|
|
411
|
-
operation
|
|
412
|
-
bucket
|
|
413
|
-
object
|
|
364
|
+
error: { status: response.status },
|
|
365
|
+
operation,
|
|
366
|
+
bucket,
|
|
367
|
+
object,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
if (!response.ok) {
|
|
371
|
+
throw getError({
|
|
372
|
+
message: `[${operation}] S3 error | bucket: ${EchoUtility.toSafeText({ value: bucket.name })} | key: ${EchoUtility.toSafeText({ value: object.key })} | status: ${response.status}`,
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/** `S3File` cannot send `If-Match` or a version id, so a conditional read is a signed GET. */
|
|
377
|
+
async getConditionalStream(opts) {
|
|
378
|
+
const { bucket, object, range, ifMatch, versionId } = opts;
|
|
379
|
+
const response = await this.signedFetch({
|
|
380
|
+
method: HTTP.Methods.GET,
|
|
381
|
+
bucket,
|
|
382
|
+
object,
|
|
383
|
+
query: { versionId },
|
|
384
|
+
headers: {
|
|
385
|
+
[HTTP.Headers.IF_MATCH]: BunS3Helper.quoteEtag({ etag: ifMatch }),
|
|
386
|
+
[HTTP.Headers.RANGE]: range && `${HTTP.HeaderValues.RANGE_UNIT_BYTES}=${range.start}-${range.end ?? ''}`,
|
|
387
|
+
},
|
|
388
|
+
});
|
|
389
|
+
this.assertObjectResponse({ response, operation: 'getObjectStream', bucket, object });
|
|
390
|
+
if (!response.body) {
|
|
391
|
+
throw getError({
|
|
392
|
+
message: `[getObjectStream] The response has no body | key: ${EchoUtility.toSafeText({ value: object.key })}`,
|
|
414
393
|
});
|
|
415
394
|
}
|
|
395
|
+
return response.body;
|
|
396
|
+
}
|
|
397
|
+
/** A signed HEAD rather than `client.stat`, because Bun's stat does not report the version id a pin needs. */
|
|
398
|
+
async getStat(opts) {
|
|
399
|
+
const { bucket, object } = opts;
|
|
400
|
+
const response = await this.signedFetch({ method: HTTP.Methods.HEAD, bucket, object });
|
|
401
|
+
this.assertObjectResponse({ response, operation: 'getStat', bucket, object });
|
|
402
|
+
const lastModified = response.headers.get(HTTP.Headers.LAST_MODIFIED);
|
|
403
|
+
return {
|
|
404
|
+
size: Number(response.headers.get(HTTP.Headers.CONTENT_LENGTH) ?? 0),
|
|
405
|
+
// One key, not two spellings. The served type comes from the object name; this is diagnostic.
|
|
406
|
+
metadata: { mimetype: response.headers.get(HTTP.Headers.CONTENT_TYPE) ?? undefined },
|
|
407
|
+
lastModified: lastModified === null ? undefined : new Date(lastModified),
|
|
408
|
+
etag: response.headers.get(HTTP.Headers.ETAG) ?? undefined,
|
|
409
|
+
versionId: StorageUtility.realVersionId({
|
|
410
|
+
value: response.headers.get(S3Headers.VERSION_ID),
|
|
411
|
+
}),
|
|
412
|
+
};
|
|
416
413
|
}
|
|
417
414
|
async removeObject(opts) {
|
|
418
415
|
const bucketName = opts.bucket.name;
|
|
@@ -452,8 +449,10 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
452
449
|
const response = await this.client.list({
|
|
453
450
|
prefix,
|
|
454
451
|
continuationToken,
|
|
455
|
-
|
|
456
|
-
|
|
452
|
+
delimiter: useRecursive ? undefined : '/',
|
|
453
|
+
maxKeys: Number.isFinite(remaining)
|
|
454
|
+
? Math.min(remaining, StorageLimits.MAX_LIST_KEYS)
|
|
455
|
+
: undefined,
|
|
457
456
|
}, this.callOptions({ bucket: bucketName }));
|
|
458
457
|
const responseContents = response.contents ?? [];
|
|
459
458
|
for (const entry of responseContents) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../src/modules/storage/bun-s3/helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAa5C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAEhF,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,iGAAiG;AACjG,MAAM,qBAAqB,GAAG,wCAAwC,CAAC;AA6BvE,iKAAiK;AACjK,MAAM,OAAO,WAAY,SAAQ,iBAAiB;IAchD,YAAY,OAA4B;QACtC,KAAK,CAAC;YACJ,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,WAAW,CAAC,IAAI;YACxC,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,WAAW,CAAC,IAAI;SACnD,CAAC,CAAC;QAEH,IAAI,CAAC,WAAW,GAAG;YACjB,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,QAAQ,EAAE;gBACR,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,OAAO;gBACjC,gFAAgF;gBAChF,MAAM,EAAE,OAAO,CAAC,QAAQ,CAA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C;gBAC3C,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC9E,EACD,IAAI,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CACzC,CAAC;YAEF,MAAM,gBAAgB,GAAG,QAAQ,CAAC,QAAQ,IAAI,EAAE,CAAC;YAEjD,KAAK,MAAM,KAAK,IAAI,gBAAgB,EAAE,CAAC;gBACrC,OAAO,CAAC,IAAI,CAAC;oBACX,IAAI,EAAE,KAAK,CAAC,GAAG;oBACf,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS;oBAC3E,IAAI,EAAE,KAAK,CAAC,IAAI;iBACjB,CAAC,CAAC;YACL,CAAC;YAED,iBAAiB,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC,CAAC,SAAS,CAAC;QACxF,CAAC,QAAQ,iBAAiB,IAAI,OAAO,CAAC,MAAM,GAAG,KAAK,EAAE;QAEtD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["import type { IDuration } from '@/common';\nimport { getError } from '@/modules/error';\nimport { ErrorPrettier } from '@/modules/logger';\nimport { EchoUtility } from '@/utilities/echo.utility';\nimport { S3Client } from 'bun';\nimport { Readable } from 'node:stream';\nimport { BaseStorageHelper } from '../base';\nimport type {\n IBucketInfo,\n IBucketRef,\n IFileStat,\n IListObjectsOptions,\n IObjectInfo,\n IObjectLocation,\n IObjectRef,\n IPostPolicy,\n IStorageHelperOptions,\n IUploadFile,\n} from '../common';\nimport { S3Audiences, StorageUtility, StoragePresignDefaults } from '../common';\nimport type { TS3Audience } from '../common';\nimport { S3SignatureUtility } from './utility';\n\n/** One lower-case DNS label: the only shape a bucket may have when it becomes part of a host. */\nconst S3_HOST_LABEL_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;\n\n/** Options for `BunS3Helper`. Unset `partSize`, `queueSize` and `retry` leave Bun defaults in force. */\nexport interface IBunS3HelperOptions extends IStorageHelperOptions {\n accessKey: string;\n secretKey: string;\n /** @default 'us-east-1' */\n region?: string;\n sessionToken?: string;\n /** `default` is the host THIS process talks to; `public` is the host a browser is handed. `host` is inside every SigV4 signature, so a URL signed against an internal name cannot be rewritten later - which is why the two are separate rather than one value patched afterwards. */\n endpoint: {\n default: string;\n /** @default endpoint.default */\n public?: string;\n };\n\n /**\n * `https://<bucket>.<endpoint>/<key>` instead of `<endpoint>/<bucket>/<key>`. AWS requires it; MinIO and R2 do not.\n *\n * @default false\n */\n virtualHostedStyle?: boolean;\n partSize?: number;\n queueSize?: number;\n\n /** Retries Bun performs on a failed part before the write fails. */\n retry?: number;\n}\n\n/** Storage helper for S3-compatible object stores through Bun's `S3Client`. Uses separate hosts for calls this process makes and for URLs handed to browsers. */\nexport class BunS3Helper extends BaseStorageHelper {\n private client: S3Client;\n private credentials: {\n accessKey: string;\n secretKey: string;\n endpoint: { default: string; public: string };\n region: string;\n sessionToken?: string;\n virtualHostedStyle: boolean;\n };\n\n /** Undefined leaves Bun's own defaults in force. */\n private transfer: { partSize?: number; queueSize?: number; retry?: number };\n\n constructor(options: IBunS3HelperOptions) {\n super({\n scope: options.scope ?? BunS3Helper.name,\n identifier: options.identifier ?? BunS3Helper.name,\n });\n\n this.credentials = {\n accessKey: options.accessKey,\n secretKey: options.secretKey,\n endpoint: {\n default: options.endpoint.default,\n // Falls back to the default, so one reachable host still serves both audiences.\n public: options.endpoint.public ?? options.endpoint.default,\n },\n region: options.region ?? 'us-east-1',\n sessionToken: options.sessionToken,\n virtualHostedStyle: options.virtualHostedStyle ?? false,\n };\n\n this.transfer = {\n partSize: options.partSize,\n queueSize: options.queueSize,\n retry: options.retry,\n };\n\n this.client = new S3Client({\n accessKeyId: options.accessKey,\n secretAccessKey: options.secretKey,\n endpoint: options.endpoint.default,\n region: options.region,\n sessionToken: options.sessionToken,\n virtualHostedStyle: options.virtualHostedStyle,\n });\n }\n\n /** One bucket's objects, in either addressing style. `audience` picks the host: `server` for a call this process makes, `browser` for a URL it hands out. Virtual-hosted derives the per-bucket host, because the bucket arrives per call. */\n private objectEndpoint(opts: { bucket: string; audience: TS3Audience }): {\n endpoint: string;\n pathPrefix: string;\n } {\n const { endpoint, virtualHostedStyle } = this.credentials;\n const host = opts.audience === S3Audiences.BROWSER ? endpoint.public : endpoint.default;\n\n if (!virtualHostedStyle) {\n return { endpoint: host, pathPrefix: `/${opts.bucket}` };\n }\n\n // The bucket becomes a label of the host, so it must be one: anything else (a dot, a slash, an `@`, a port) would steer the request to another host.\n if (!S3_HOST_LABEL_PATTERN.test(opts.bucket)) {\n throw getError({\n message: `[objectEndpoint] A bucket used in a host must be one lower-case DNS label (a-z, 0-9, hyphen; 1-63 characters) | bucket: '${EchoUtility.toSafeText({ value: opts.bucket })}'`,\n });\n }\n\n const parsed = new URL(host);\n parsed.hostname = `${opts.bucket}.${parsed.hostname}`;\n\n return { endpoint: parsed.origin, pathPrefix: '' };\n }\n\n /** Per-call overrides, so one client serves every bucket in either addressing style. */\n private presignOptions(opts: { bucket: string }): {\n bucket: string;\n endpoint: string;\n virtualHostedStyle?: boolean;\n } {\n const { virtualHostedStyle } = this.credentials;\n const { endpoint } = this.objectEndpoint({\n bucket: opts.bucket,\n audience: S3Audiences.BROWSER,\n });\n\n return {\n bucket: opts.bucket,\n endpoint,\n ...(virtualHostedStyle ? { virtualHostedStyle: true } : {}),\n };\n }\n\n /**\n * What a call this process makes on one bucket's objects (or its listing) passes to Bun's client. Path style needs only the\n * bucket. Virtual-hosted style needs the bucket's own host as well: Bun puts the bucket in neither the host nor the path in that\n * mode, so a call without it goes to the bare endpoint (`PUT /k.png` on the endpoint host) and never reaches the object.\n */\n private callOptions(opts: { bucket: string }): {\n bucket: string;\n endpoint?: string;\n virtualHostedStyle?: boolean;\n } {\n if (!this.credentials.virtualHostedStyle) {\n return { bucket: opts.bucket };\n }\n\n const { endpoint } = this.objectEndpoint({ bucket: opts.bucket, audience: S3Audiences.SERVER });\n\n return { bucket: opts.bucket, endpoint, virtualHostedStyle: true };\n }\n\n async hasBucket(opts: { bucket: IBucketRef }): Promise<boolean> {\n const { name } = opts.bucket;\n\n if (!this.isValidBucketName(opts)) {\n return false;\n }\n\n try {\n await this.client.list({ maxKeys: 1 }, this.callOptions({ bucket: name }));\n\n return true;\n } catch (error) {\n // A missing bucket is the answer; a credentials or network failure is not, and must not vanish.\n if (!StorageUtility.isNotFoundError({ error })) {\n this.logger.warn(\n '[hasBucket] Cannot determine bucket existence - reporting false | bucket: %s | %s',\n EchoUtility.toSafeEcho({ value: name }),\n ErrorPrettier.format({ error }),\n );\n }\n\n return false;\n }\n }\n\n async getBuckets(): Promise<IBucketInfo[]> {\n // A bucket operation is a call this process makes, so it goes to the default host.\n const { accessKey, secretKey, region, sessionToken } = this.credentials;\n const endpoint = this.credentials.endpoint.default;\n\n const { url, headers } = await S3SignatureUtility.buildSignedRequest({\n method: 'GET',\n endpoint,\n path: '/',\n accessKey,\n secretKey,\n region,\n sessionToken,\n });\n\n const response = await fetch(url, { method: 'GET', headers });\n const xml = await response.text();\n\n if (!response.ok) {\n throw getError({ message: `[getBuckets] S3 error: ${xml}` });\n }\n\n const buckets: IBucketInfo[] = [];\n const bucketMatches = xml.matchAll(\n /<Bucket>\\s*<Name>(.*?)<\\/Name>\\s*<CreationDate>(.*?)<\\/CreationDate>\\s*<\\/Bucket>/gs,\n );\n\n for (const match of bucketMatches) {\n buckets.push({\n name: match[1],\n creationDate: new Date(match[2]),\n });\n }\n\n return buckets;\n }\n\n /** S3 exposes a creation date only through `ListBuckets`, so one full listing is the cheapest correct answer. */\n async getBucket(opts: { bucket: IBucketRef }): Promise<IBucketInfo | null> {\n const { name } = opts.bucket;\n\n if (!this.isValidBucketName(opts)) {\n return null;\n }\n\n const buckets = await this.getBuckets();\n\n return buckets.find((bucket) => bucket.name === name) ?? null;\n }\n\n async createBucket(opts: { bucket: IBucketRef }): Promise<IBucketInfo | null> {\n const { name } = opts.bucket;\n\n if (!this.isValidBucketName(opts)) {\n throw getError({ message: '[createBucket] Invalid name to create bucket!' });\n }\n\n // A bucket operation is a call this process makes, so it goes to the default host.\n const { accessKey, secretKey, region, sessionToken } = this.credentials;\n const endpoint = this.credentials.endpoint.default;\n\n const { url, headers } = await S3SignatureUtility.buildSignedRequest({\n method: 'PUT',\n endpoint,\n path: `/${name}`,\n accessKey: accessKey,\n secretKey,\n region,\n sessionToken,\n });\n\n const response = await fetch(url, { method: 'PUT', headers });\n\n if (!response.ok) {\n const xml = await response.text();\n throw getError({ message: `[createBucket] S3 error: ${xml}` });\n }\n\n return this.getBucket(opts);\n }\n\n async removeBucket(opts: { bucket: IBucketRef }): Promise<boolean> {\n const { name } = opts.bucket;\n\n if (!this.isValidBucketName(opts)) {\n throw getError({ message: '[removeBucket] Invalid name to remove bucket!' });\n }\n\n // A bucket operation is a call this process makes, so it goes to the default host.\n const { accessKey, secretKey, region, sessionToken } = this.credentials;\n const endpoint = this.credentials.endpoint.default;\n\n const { url, headers } = await S3SignatureUtility.buildSignedRequest({\n method: 'DELETE',\n endpoint,\n path: `/${name}`,\n accessKey: accessKey,\n secretKey: secretKey,\n region,\n sessionToken,\n });\n\n const response = await fetch(url, { method: 'DELETE', headers });\n\n if (!response.ok) {\n const xml = await response.text();\n throw getError({ message: `[removeBucket] S3 error: ${xml}` });\n }\n\n return true;\n }\n\n override async copyObject(opts: {\n bucket: IBucketRef;\n source: IObjectRef;\n destination: IObjectRef;\n }): Promise<void> {\n const { bucket, source, destination } = opts;\n const { accessKey, secretKey, region, sessionToken } = this.credentials;\n const { endpoint, pathPrefix } = this.objectEndpoint({\n bucket: bucket.name,\n audience: S3Audiences.SERVER,\n });\n\n // `x-amz-copy-source` is what makes this server side: S3 reads the source itself, so a 500 MB\n // object never travels through this process. The encoded value is both signed and sent.\n const request = await S3SignatureUtility.buildSignedRequest({\n method: 'PUT',\n endpoint,\n path: `${pathPrefix}/${destination.key}`,\n accessKey,\n secretKey,\n region,\n sessionToken,\n headers: {\n 'x-amz-copy-source': S3SignatureUtility.buildCopySource({\n bucket: bucket.name,\n key: source.key,\n }),\n },\n });\n\n const response = await fetch(request.url, { method: 'PUT', headers: request.headers });\n\n if (!response.ok) {\n throw getError({\n message: `[copyObject] Copy failed | bucket: ${EchoUtility.toSafeText({ value: bucket.name })} | source: ${EchoUtility.toSafeText({ value: source.key })} | status: ${response.status}`,\n });\n }\n }\n\n override async presignPost(opts: {\n bucket: IBucketRef;\n keyPrefix: string;\n maxBytes: number;\n contentType?: string;\n expiresIn?: IDuration;\n }): Promise<IPostPolicy> {\n const {\n bucket,\n keyPrefix,\n maxBytes,\n contentType,\n expiresIn = StoragePresignDefaults.POST_EXPIRES_IN,\n } = opts;\n const { accessKey, secretKey, region, sessionToken } = this.credentials;\n\n // The browser posts to the BUCKET, not to an object - the key travels as a form field, because\n // the policy only constrains its prefix.\n const { endpoint, pathPrefix } = this.objectEndpoint({\n bucket: bucket.name,\n audience: S3Audiences.BROWSER,\n });\n const { formData, expiresAt } = await S3SignatureUtility.buildPostPolicy({\n bucket: bucket.name,\n keyPrefix,\n maxBytes,\n expiresInSeconds: StorageUtility.toExpirySeconds({ expiresIn, operation: 'presignPost' }),\n accessKey,\n secretKey,\n region,\n sessionToken,\n contentType,\n });\n\n return { postURL: `${endpoint.replace(/\\/$/, '')}${pathPrefix}`, formData, expiresAt };\n }\n\n override async presignPut(\n opts: IObjectLocation & {\n expiresIn?: IDuration;\n tagging?: Record<string, string>;\n contentLength?: number;\n contentType?: string;\n },\n ): Promise<string> {\n const {\n bucket,\n object,\n tagging,\n contentLength,\n contentType,\n expiresIn = StoragePresignDefaults.PUT_EXPIRES_IN,\n } = opts;\n const { accessKey, secretKey, region, sessionToken } = this.credentials;\n\n // Not `client.presign`: its options are method and expiry only, and a tag that is merely SENT\n // is a tag S3 ignores. These two have to be inside the signature to exist at all.\n const { endpoint, pathPrefix } = this.objectEndpoint({\n bucket: bucket.name,\n audience: S3Audiences.BROWSER,\n });\n\n return S3SignatureUtility.buildPresignedUrl({\n method: 'PUT',\n endpoint,\n path: `${pathPrefix}/${object.key}`,\n accessKey,\n secretKey,\n region,\n sessionToken,\n expiresInSeconds: StorageUtility.toExpirySeconds({ expiresIn, operation: 'presignPut' }),\n headers: {\n ...(tagging\n ? { 'x-amz-tagging': S3SignatureUtility.buildTaggingHeader({ tags: tagging }) }\n : {}),\n ...(contentLength === undefined ? {} : { 'content-length': String(contentLength) }),\n ...(contentType ? { 'content-type': contentType } : {}),\n },\n });\n }\n\n override async presignGet(\n opts: IObjectLocation & {\n expiresIn?: IDuration;\n responseContentType?: string;\n responseContentDisposition?: string;\n },\n ): Promise<string> {\n const {\n bucket,\n object,\n expiresIn = StoragePresignDefaults.GET_EXPIRES_IN,\n responseContentType,\n responseContentDisposition,\n } = opts;\n\n return this.client.presign(object.key, {\n ...this.presignOptions({ bucket: bucket.name }),\n method: 'GET',\n expiresIn: StorageUtility.toExpirySeconds({ expiresIn, operation: 'presignGet' }),\n ...(responseContentType ? { type: responseContentType } : {}),\n ...(responseContentDisposition ? { contentDisposition: responseContentDisposition } : {}),\n });\n }\n\n override async getObjectTags(opts: IObjectLocation): Promise<Record<string, string>> {\n const bucketName = opts.bucket.name;\n const key = opts.object.key;\n const { accessKey, secretKey, region, sessionToken } = this.credentials;\n const { endpoint, pathPrefix } = this.objectEndpoint({\n bucket: bucketName,\n audience: S3Audiences.SERVER,\n });\n\n const { url, headers } = await S3SignatureUtility.buildSignedRequest({\n method: 'GET',\n endpoint,\n path: `${pathPrefix}/${key}`,\n accessKey,\n secretKey,\n region,\n sessionToken,\n query: { tagging: '' },\n });\n\n const response = await fetch(url, { method: 'GET', headers });\n\n // S3 answers a missing tag set with 404: the empty case, not a failure.\n if (response.status === 404) {\n return {};\n }\n\n const body = await response.text();\n\n if (!response.ok) {\n throw getError({\n message: `[getObjectTags] S3 error | status: ${response.status} | body: ${body}`,\n });\n }\n\n return S3SignatureUtility.parseTaggingXml({ xml: body });\n }\n\n override async replaceObjectTags(\n opts: IObjectLocation & { tags: Record<string, string> },\n ): Promise<void> {\n const bucketName = opts.bucket.name;\n const key = opts.object.key;\n const { tags } = opts;\n const { accessKey, secretKey, region, sessionToken } = this.credentials;\n const { endpoint, pathPrefix } = this.objectEndpoint({\n bucket: bucketName,\n audience: S3Audiences.SERVER,\n });\n const requestBody = S3SignatureUtility.buildTaggingXml({ tags });\n\n const { url, headers } = await S3SignatureUtility.buildSignedRequest({\n method: 'PUT',\n endpoint,\n path: `${pathPrefix}/${key}`,\n accessKey,\n secretKey,\n region,\n sessionToken,\n query: { tagging: '' },\n body: requestBody,\n });\n\n const response = await fetch(url, { method: 'PUT', headers, body: requestBody });\n\n if (!response.ok) {\n const body = await response.text();\n throw getError({\n message: `[replaceObjectTags] S3 error | status: ${response.status} | body: ${body}`,\n });\n }\n }\n\n protected get defaultLinkPrefix(): string {\n return '/static-assets/';\n }\n\n protected async writeObject(opts: IObjectLocation & { file: IUploadFile }): Promise<void> {\n const { file } = opts;\n const bucketName = opts.bucket.name;\n const { mimetype: mimeType, buffer } = file;\n\n await this.client.write(opts.object.key, buffer, {\n ...this.callOptions({ bucket: bucketName }),\n type: mimeType,\n partSize: this.transfer.partSize,\n queueSize: this.transfer.queueSize,\n retry: this.transfer.retry,\n });\n }\n\n /** Streams without holding the object in memory. `upload` carries a `Buffer`, so it cannot; this is the path for anything large. */\n override async writeStream(\n opts: IObjectLocation & {\n source: ReadableStream<Uint8Array> | Blob | Response | Request;\n contentType?: string;\n maxFolderDepth?: number;\n },\n ): Promise<void> {\n const { bucket, object, source, contentType } = opts;\n\n // The same depth rule `upload` applies: one object, two doors, one answer.\n if (!this.isValidObjectKey({ object, maxDepth: opts.maxFolderDepth })) {\n throw getError({\n message: `[writeStream] Invalid object name | key: ${EchoUtility.toSafeText({ value: object.key })}`,\n });\n }\n\n // Bun's `write` takes a Response, not a bare ReadableStream; wrapping streams, never buffers.\n const body = source instanceof ReadableStream ? new Response(source) : source;\n\n await this.client.write(object.key, body, {\n ...this.callOptions({ bucket: bucket.name }),\n ...(contentType ? { type: contentType } : {}),\n partSize: this.transfer.partSize,\n queueSize: this.transfer.queueSize,\n retry: this.transfer.retry,\n });\n }\n\n /** `S3File.stream()` is lazy: it reaches the network on first read, so a `try` here never sees a 404 - the failure arrives on the stream. */\n async getObject(opts: IObjectLocation & { options?: any }): Promise<Readable> {\n const bucketName = opts.bucket.name;\n const key = opts.object.key;\n const source = this.client.file(key, this.callOptions({ bucket: bucketName })).stream();\n\n return Readable.fromWeb(source as ReadableStream<Uint8Array>, {\n // Keeps backpressure meaningful rather than draining S3 into memory.\n objectMode: false,\n });\n }\n\n /** The conversion-free path a `Response` body wants. `slice` makes it a ranged GET, so only the requested bytes leave S3. */\n override async getObjectStream(\n opts: IObjectLocation & { range?: { start: number; end?: number } },\n ): Promise<ReadableStream<Uint8Array>> {\n const bucketName = opts.bucket.name;\n const key = opts.object.key;\n const { range } = opts;\n const file = this.client.file(key, this.callOptions({ bucket: bucketName }));\n\n if (!range) {\n return file.stream() as ReadableStream<Uint8Array>;\n }\n\n // HTTP ranges include `end`; `slice` excludes it.\n const window =\n range.end === undefined ? file.slice(range.start) : file.slice(range.start, range.end + 1);\n\n return window.stream() as ReadableStream<Uint8Array>;\n }\n\n async getStat(opts: IObjectLocation): Promise<IFileStat> {\n const bucketName = opts.bucket.name;\n const key = opts.object.key;\n\n try {\n const stat = await this.client.stat(key, this.callOptions({ bucket: bucketName }));\n\n return {\n size: stat.size,\n // One key, not two spellings. The served type comes from the object name; this is diagnostic.\n metadata: { mimetype: stat.type },\n lastModified: stat.lastModified,\n etag: stat.etag,\n };\n } catch (error) {\n throw this.asStorageError({\n error,\n operation: 'getStat',\n bucket: opts.bucket,\n object: opts.object,\n });\n }\n }\n\n async removeObject(opts: IObjectLocation): Promise<void> {\n const bucketName = opts.bucket.name;\n const key = opts.object.key;\n\n try {\n await this.client.delete(key, this.callOptions({ bucket: bucketName }));\n } catch (error) {\n throw this.asStorageError({\n error,\n operation: 'removeObject',\n bucket: opts.bucket,\n object: opts.object,\n });\n }\n }\n\n async removeObjects(opts: { bucket: IBucketRef; objects: IObjectRef[] }): Promise<void> {\n const { bucket, objects } = opts;\n\n await this.mapWithConcurrency({\n items: objects,\n task: ({ item: object }) => this.removeObject({ bucket, object }),\n });\n }\n\n /** S3 caps a call at 1000 keys and continues through `nextContinuationToken`. `useRecursive: false` maps to `delimiter: '/'`. */\n async listObjects(opts: IListObjectsOptions): Promise<IObjectInfo[]> {\n const { prefix, useRecursive = false, maxKeys } = opts;\n const bucketName = opts.bucket.name;\n\n // `maxKeys: 0` means zero, not unlimited.\n const limit = maxKeys ?? Number.POSITIVE_INFINITY;\n\n if (limit <= 0) {\n return [];\n }\n\n const objects: IObjectInfo[] = [];\n let continuationToken: string | undefined;\n\n do {\n const remaining = limit - objects.length;\n const response = await this.client.list(\n {\n prefix,\n continuationToken,\n ...(useRecursive ? {} : { delimiter: '/' }),\n ...(Number.isFinite(remaining) ? { maxKeys: Math.min(remaining, 1000) } : {}),\n },\n this.callOptions({ bucket: bucketName }),\n );\n\n const responseContents = response.contents ?? [];\n\n for (const entry of responseContents) {\n objects.push({\n name: entry.key,\n size: entry.size,\n lastModified: entry.lastModified ? new Date(entry.lastModified) : undefined,\n etag: entry.eTag,\n });\n }\n\n continuationToken = response.isTruncated ? response.nextContinuationToken : undefined;\n } while (continuationToken && objects.length < limit);\n\n return objects;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../src/modules/storage/bun-s3/helper.ts"],"names":[],"mappings":"AAAA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B,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS;oBAC3E,IAAI,EAAE,KAAK,CAAC,IAAI;iBACjB,CAAC,CAAC;YACL,CAAC;YAED,iBAAiB,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC,CAAC,SAAS,CAAC;QACxF,CAAC,QAAQ,iBAAiB,IAAI,OAAO,CAAC,MAAM,GAAG,KAAK,EAAE;QAEtD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["import { HTTP, type THttpMethod } from '@/common/constants/http';\nimport { getError } from '@/modules/error';\nimport { ErrorPrettier } from '@/modules/logger';\nimport { EchoUtility } from '@/utilities/echo.utility';\nimport { S3Client } from 'bun';\nimport { Readable } from 'node:stream';\nimport { BaseStorageHelper } from '../base';\nimport type {\n IBucketInfo,\n IBucketRef,\n ICopyObjectOptions,\n IFileStat,\n IListObjectsOptions,\n IObjectInfo,\n IObjectLocation,\n IObjectRef,\n IPostPolicy,\n IPresignGetOptions,\n IPresignPostOptions,\n IPresignPutOptions,\n IStorageHelperOptions,\n IUploadFile,\n IWriteStreamOptions,\n TObjectStreamOptions,\n TS3Audience,\n} from '../common';\nimport {\n S3Audiences,\n S3Defaults,\n S3Headers,\n StorageErrors,\n StorageLimits,\n StorageTypes,\n StorageUtility,\n StoragePresignDefaults,\n} from '../common';\nimport { S3SignatureUtility } from './utility';\n\n/** One lower-case DNS label: the only shape a bucket may have when it becomes part of a host. */\nconst S3_HOST_LABEL_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;\n\n/** Options for `BunS3Helper`. Unset `partSize`, `queueSize` and `retry` leave Bun defaults in force. */\nexport interface IBunS3HelperOptions extends IStorageHelperOptions {\n accessKey: string;\n secretKey: string;\n /** @default 'us-east-1' */\n region?: string;\n sessionToken?: string;\n /** `default` is the host THIS process talks to; `public` is the host a browser is handed. `host` is inside every SigV4 signature, so a URL signed against an internal name cannot be rewritten later - which is why the two are separate rather than one value patched afterwards. */\n endpoint: {\n default: string;\n /** @default endpoint.default */\n public?: string;\n };\n\n /**\n * `https://<bucket>.<endpoint>/<key>` instead of `<endpoint>/<bucket>/<key>`. AWS requires it; MinIO and R2 do not.\n *\n * @default false\n */\n virtualHostedStyle?: boolean;\n partSize?: number;\n queueSize?: number;\n\n /** Retries Bun performs on a failed part before the write fails. */\n retry?: number;\n}\n\n/** Storage helper for S3-compatible object stores through Bun's `S3Client`. Uses separate hosts for calls this process makes and for URLs handed to browsers. */\nexport class BunS3Helper extends BaseStorageHelper {\n readonly storageType = StorageTypes.BUN_S3;\n\n private client: S3Client;\n private credentials: {\n accessKey: string;\n secretKey: string;\n endpoint: { default: string; public: string };\n region: string;\n sessionToken?: string;\n virtualHostedStyle: boolean;\n };\n\n /** Undefined leaves Bun's own defaults in force. */\n private transfer: { partSize?: number; queueSize?: number; retry?: number };\n\n constructor(options: IBunS3HelperOptions) {\n super({\n scope: options.scope ?? BunS3Helper.name,\n identifier: options.identifier ?? BunS3Helper.name,\n });\n\n this.credentials = {\n accessKey: options.accessKey,\n secretKey: options.secretKey,\n endpoint: {\n default: options.endpoint.default,\n // Falls back to the default, so one reachable host still serves both audiences.\n public: options.endpoint.public ?? options.endpoint.default,\n },\n region: options.region ?? S3Defaults.REGION,\n sessionToken: options.sessionToken,\n virtualHostedStyle: options.virtualHostedStyle ?? false,\n };\n\n this.transfer = {\n partSize: options.partSize,\n queueSize: options.queueSize,\n retry: options.retry,\n };\n\n this.client = new S3Client({\n accessKeyId: options.accessKey,\n secretAccessKey: options.secretKey,\n endpoint: options.endpoint.default,\n region: options.region,\n sessionToken: options.sessionToken,\n virtualHostedStyle: options.virtualHostedStyle,\n });\n }\n\n /** One bucket's objects, in either addressing style. `audience` picks the host: `server` for a call this process makes, `browser` for a URL it hands out. Virtual-hosted derives the per-bucket host, because the bucket arrives per call. */\n private objectEndpoint(opts: { bucket: string; audience: TS3Audience }): {\n endpoint: string;\n pathPrefix: string;\n } {\n const { endpoint, virtualHostedStyle } = this.credentials;\n const host = opts.audience === S3Audiences.BROWSER ? endpoint.public : endpoint.default;\n\n if (!virtualHostedStyle) {\n return { endpoint: host, pathPrefix: `/${opts.bucket}` };\n }\n\n // The bucket becomes a label of the host, so it must be one: anything else (a dot, a slash, an `@`, a port) would steer the request to another host.\n if (!S3_HOST_LABEL_PATTERN.test(opts.bucket)) {\n throw getError({\n message: `[objectEndpoint] A bucket used in a host must be one lower-case DNS label (a-z, 0-9, hyphen; 1-63 characters) | bucket: '${EchoUtility.toSafeText({ value: opts.bucket })}'`,\n });\n }\n\n const parsed = new URL(host);\n parsed.hostname = `${opts.bucket}.${parsed.hostname}`;\n\n return { endpoint: parsed.origin, pathPrefix: '' };\n }\n\n /** Per-call overrides, so one client serves every bucket in either addressing style. */\n private presignOptions(opts: { bucket: string }) {\n const { endpoint } = this.objectEndpoint({\n bucket: opts.bucket,\n audience: S3Audiences.BROWSER,\n });\n\n return {\n bucket: opts.bucket,\n endpoint,\n virtualHostedStyle: this.credentials.virtualHostedStyle,\n };\n }\n\n /**\n * What a call this process makes on one bucket's objects (or its listing) passes to Bun's client. Path style needs only the\n * bucket. Virtual-hosted style needs the bucket's own host as well: Bun puts the bucket in neither the host nor the path in that\n * mode, so a call without it goes to the bare endpoint (`PUT /k.png` on the endpoint host) and never reaches the object.\n */\n private callOptions(opts: { bucket: string }): {\n bucket: string;\n endpoint?: string;\n virtualHostedStyle?: boolean;\n } {\n if (!this.credentials.virtualHostedStyle) {\n return { bucket: opts.bucket };\n }\n\n const { endpoint } = this.objectEndpoint({ bucket: opts.bucket, audience: S3Audiences.SERVER });\n\n return { bucket: opts.bucket, endpoint, virtualHostedStyle: true };\n }\n\n async hasBucket(opts: { bucket: IBucketRef }): Promise<boolean> {\n const { name } = opts.bucket;\n\n if (!this.isValidBucketName(opts)) {\n return false;\n }\n\n try {\n await this.client.list({ maxKeys: 1 }, this.callOptions({ bucket: name }));\n\n return true;\n } catch (error) {\n // A missing bucket is the answer; a credentials or network failure is not, and must not vanish.\n if (!StorageUtility.isNotFoundError({ error })) {\n this.logger.warn(\n '[hasBucket] Cannot determine bucket existence - reporting false | bucket: %s | %s',\n EchoUtility.toSafeEcho({ value: name }),\n ErrorPrettier.format({ error }),\n );\n }\n\n return false;\n }\n }\n\n async getBuckets(): Promise<IBucketInfo[]> {\n const response = await this.bucketFetch({ method: HTTP.Methods.GET, path: '/' });\n const xml = await response.text();\n\n if (!response.ok) {\n throw getError({ message: `[getBuckets] S3 error: ${xml}` });\n }\n\n const buckets: IBucketInfo[] = [];\n const bucketMatches = xml.matchAll(\n /<Bucket>\\s*<Name>(.*?)<\\/Name>\\s*<CreationDate>(.*?)<\\/CreationDate>\\s*<\\/Bucket>/gs,\n );\n\n for (const match of bucketMatches) {\n buckets.push({\n name: match[1],\n creationDate: new Date(match[2]),\n });\n }\n\n return buckets;\n }\n\n /** S3 exposes a creation date only through `ListBuckets`, so one full listing is the cheapest correct answer. */\n async getBucket(opts: { bucket: IBucketRef }): Promise<IBucketInfo | null> {\n const { name } = opts.bucket;\n\n if (!this.isValidBucketName(opts)) {\n return null;\n }\n\n const buckets = await this.getBuckets();\n\n return buckets.find((bucket) => bucket.name === name) ?? null;\n }\n\n async createBucket(opts: { bucket: IBucketRef }): Promise<IBucketInfo | null> {\n const { name } = opts.bucket;\n\n if (!this.isValidBucketName(opts)) {\n throw getError({ message: '[createBucket] Invalid name to create bucket!' });\n }\n\n const response = await this.bucketFetch({ method: HTTP.Methods.PUT, path: `/${name}` });\n\n if (!response.ok) {\n const xml = await response.text();\n throw getError({ message: `[createBucket] S3 error: ${xml}` });\n }\n\n return this.getBucket(opts);\n }\n\n async removeBucket(opts: { bucket: IBucketRef }): Promise<boolean> {\n const { name } = opts.bucket;\n\n if (!this.isValidBucketName(opts)) {\n throw getError({ message: '[removeBucket] Invalid name to remove bucket!' });\n }\n\n const response = await this.bucketFetch({ method: HTTP.Methods.DELETE, path: `/${name}` });\n\n if (!response.ok) {\n const xml = await response.text();\n throw getError({ message: `[removeBucket] S3 error: ${xml}` });\n }\n\n return true;\n }\n\n override async copyObject(opts: ICopyObjectOptions): Promise<void> {\n const { bucket, source, destination, ifMatch, sourceVersionId } = opts;\n\n // `x-amz-copy-source` is what makes this server side: S3 reads the source itself, so a 500 MB\n // object never travels through this process. The encoded value is both signed and sent.\n const response = await this.signedFetch({\n method: HTTP.Methods.PUT,\n bucket,\n object: destination,\n headers: {\n [S3Headers.COPY_SOURCE]: S3SignatureUtility.buildCopySource({\n bucket: bucket.name,\n key: source.key,\n versionId: sourceVersionId,\n }),\n [S3Headers.COPY_SOURCE_IF_MATCH]: BunS3Helper.quoteEtag({ etag: ifMatch }),\n },\n });\n\n this.assertObjectResponse({ response, operation: 'copyObject', bucket, object: source });\n }\n\n override async presignPost(opts: IPresignPostOptions): Promise<IPostPolicy> {\n const {\n bucket,\n object,\n maxBytes,\n contentType,\n expiresIn = StoragePresignDefaults.POST_EXPIRES_IN,\n } = opts;\n const { accessKey, secretKey, region, sessionToken } = this.credentials;\n\n // The browser posts to the BUCKET, not to an object - the key travels as a form field, which the\n // policy pins to this one value.\n const { endpoint, pathPrefix } = this.objectEndpoint({\n bucket: bucket.name,\n audience: S3Audiences.BROWSER,\n });\n const { formData, expiresAt } = await S3SignatureUtility.buildPostPolicy({\n bucket: bucket.name,\n key: object.key,\n maxBytes,\n expiresInSeconds: StorageUtility.toExpirySeconds({ expiresIn, operation: 'presignPost' }),\n accessKey,\n secretKey,\n region,\n sessionToken,\n contentType,\n });\n\n return { postURL: `${endpoint.replace(/\\/$/, '')}${pathPrefix}`, formData, expiresAt };\n }\n\n override async presignPut(opts: IPresignPutOptions): Promise<string> {\n const {\n bucket,\n object,\n tagging,\n contentLength,\n contentType,\n expiresIn = StoragePresignDefaults.PUT_EXPIRES_IN,\n } = opts;\n const { accessKey, secretKey, region, sessionToken } = this.credentials;\n\n // Not `client.presign`: its options are method and expiry only, and a tag that is merely SENT\n // is a tag S3 ignores. These two have to be inside the signature to exist at all.\n const { endpoint, pathPrefix } = this.objectEndpoint({\n bucket: bucket.name,\n audience: S3Audiences.BROWSER,\n });\n\n return S3SignatureUtility.buildPresignedUrl({\n method: HTTP.Methods.PUT,\n endpoint,\n path: `${pathPrefix}/${object.key}`,\n accessKey,\n secretKey,\n region,\n sessionToken,\n expiresInSeconds: StorageUtility.toExpirySeconds({ expiresIn, operation: 'presignPut' }),\n headers: {\n [S3Headers.TAGGING]: tagging && S3SignatureUtility.buildTaggingHeader({ tags: tagging }),\n [HTTP.Headers.CONTENT_LENGTH]: contentLength?.toString(),\n [HTTP.Headers.CONTENT_TYPE]: contentType || undefined,\n },\n });\n }\n\n override async presignGet(opts: IPresignGetOptions): Promise<string> {\n const {\n bucket,\n object,\n expiresIn = StoragePresignDefaults.GET_EXPIRES_IN,\n responseContentType,\n responseContentDisposition,\n } = opts;\n\n return this.client.presign(object.key, {\n ...this.presignOptions({ bucket: bucket.name }),\n method: 'GET',\n expiresIn: StorageUtility.toExpirySeconds({ expiresIn, operation: 'presignGet' }),\n type: responseContentType,\n contentDisposition: responseContentDisposition,\n });\n }\n\n override async getObjectTags(opts: IObjectLocation): Promise<Record<string, string>> {\n const response = await this.signedFetch({\n method: HTTP.Methods.GET,\n ...opts,\n query: { tagging: '' },\n });\n\n // S3 answers a missing tag set with 404: the empty case, not a failure.\n if (response.status === HTTP.ResultCodes.RS_4.NotFound) {\n return {};\n }\n\n const body = await response.text();\n\n if (!response.ok) {\n throw getError({\n message: `[getObjectTags] S3 error | status: ${response.status} | body: ${body}`,\n });\n }\n\n return S3SignatureUtility.parseTaggingXml({ xml: body });\n }\n\n override async replaceObjectTags(\n opts: IObjectLocation & { tags: Record<string, string> },\n ): Promise<void> {\n const response = await this.signedFetch({\n method: HTTP.Methods.PUT,\n bucket: opts.bucket,\n object: opts.object,\n query: { tagging: '' },\n body: S3SignatureUtility.buildTaggingXml({ tags: opts.tags }),\n });\n\n if (!response.ok) {\n const body = await response.text();\n throw getError({\n message: `[replaceObjectTags] S3 error | status: ${response.status} | body: ${body}`,\n });\n }\n }\n\n protected get defaultLinkPrefix(): string {\n return '/static-assets/';\n }\n\n protected async writeObject(opts: IObjectLocation & { file: IUploadFile }): Promise<void> {\n const { file } = opts;\n const bucketName = opts.bucket.name;\n const { mimetype: mimeType, buffer } = file;\n\n await this.client.write(opts.object.key, buffer, {\n ...this.callOptions({ bucket: bucketName }),\n type: mimeType,\n partSize: this.transfer.partSize,\n queueSize: this.transfer.queueSize,\n retry: this.transfer.retry,\n });\n }\n\n /** Streams without holding the object in memory. `upload` carries a `Buffer`, so it cannot; this is the path for anything large. */\n override async writeStream(opts: IWriteStreamOptions): Promise<void> {\n const { bucket, object, source, contentType } = opts;\n\n // The same depth rule `upload` applies: one object, two doors, one answer.\n if (!this.isValidObjectKey({ object, maxDepth: opts.maxFolderDepth })) {\n throw getError({\n message: `[writeStream] Invalid object name | key: ${EchoUtility.toSafeText({ value: object.key })}`,\n });\n }\n\n // Bun's `write` takes a Response, not a bare ReadableStream; wrapping streams, never buffers.\n const body = source instanceof ReadableStream ? new Response(source) : source;\n\n await this.client.write(object.key, body, {\n ...this.callOptions({ bucket: bucket.name }),\n type: contentType,\n partSize: this.transfer.partSize,\n queueSize: this.transfer.queueSize,\n retry: this.transfer.retry,\n });\n }\n\n /** `S3File.stream()` is lazy: it reaches the network on first read, so a `try` here never sees a 404 - the failure arrives on the stream. */\n async getObject(opts: IObjectLocation & { options?: unknown }): Promise<Readable> {\n const bucketName = opts.bucket.name;\n const key = opts.object.key;\n const source = this.client.file(key, this.callOptions({ bucket: bucketName })).stream();\n\n return Readable.fromWeb(source as ReadableStream<Uint8Array>, {\n // Keeps backpressure meaningful rather than draining S3 into memory.\n objectMode: false,\n });\n }\n\n /** The conversion-free path a `Response` body wants. `slice` makes it a ranged GET, so only the requested bytes leave S3. */\n override async getObjectStream(opts: TObjectStreamOptions): Promise<ReadableStream<Uint8Array>> {\n if (opts.ifMatch !== undefined || opts.versionId !== undefined) {\n return this.getConditionalStream(opts);\n }\n\n const bucketName = opts.bucket.name;\n const key = opts.object.key;\n const { range } = opts;\n const file = this.client.file(key, this.callOptions({ bucket: bucketName }));\n\n if (!range) {\n return file.stream() as ReadableStream<Uint8Array>;\n }\n\n // HTTP ranges include `end`; `slice` excludes it.\n const window =\n range.end === undefined ? file.slice(range.start) : file.slice(range.start, range.end + 1);\n\n return window.stream() as ReadableStream<Uint8Array>;\n }\n\n /** The ETag with the quotes S3 sends and expects in `If-Match`. */\n private static quoteEtag(opts: { etag?: string }): string | undefined {\n const { etag } = opts;\n\n return etag === undefined || etag.startsWith('\"') || etag.startsWith('W/') ? etag : `\"${etag}\"`;\n }\n\n /** Signs and sends one request: the one place credentials, signing and the verb's case meet. */\n private async send(opts: {\n method: THttpMethod;\n endpoint: string;\n path: string;\n query?: Record<string, string | undefined>;\n headers?: Record<string, string | undefined>;\n body?: string;\n }): Promise<Response> {\n const { method, body } = opts;\n const { accessKey, secretKey, region, sessionToken } = this.credentials;\n\n const request = await S3SignatureUtility.buildSignedRequest({\n ...opts,\n accessKey,\n secretKey,\n region,\n sessionToken,\n });\n\n return fetch(request.url, { method: method.toUpperCase(), headers: request.headers, body });\n }\n\n /** A bucket operation is a call this process makes, so it goes to the default host. */\n private bucketFetch(opts: { method: THttpMethod; path: string }): Promise<Response> {\n return this.send({ ...opts, endpoint: this.credentials.endpoint.default });\n }\n\n /** One object-level request, addressed in the configured style on the host this process talks to. */\n private signedFetch(opts: {\n method: THttpMethod;\n bucket: IBucketRef;\n object: IObjectRef;\n query?: Record<string, string | undefined>;\n headers?: Record<string, string | undefined>;\n body?: string;\n }): Promise<Response> {\n const { bucket, object, ...request } = opts;\n const { endpoint, pathPrefix } = this.objectEndpoint({\n bucket: bucket.name,\n audience: S3Audiences.SERVER,\n });\n\n return this.send({ ...request, endpoint, path: `${pathPrefix}/${object.key}` });\n }\n\n /** The storage error a response stands for: 412 is a changed object, 404 a missing one, any other failure the backend's own. */\n private assertObjectResponse(opts: {\n response: Response;\n operation: string;\n bucket: IBucketRef;\n object: IObjectRef;\n }): void {\n const { response, operation, bucket, object } = opts;\n\n if (response.status === HTTP.ResultCodes.RS_4.PreconditionFailed) {\n throw getError({\n error: StorageErrors.PRECONDITION_FAILED,\n message: `[${operation}] The object changed | bucket: ${EchoUtility.toSafeText({ value: bucket.name })} | key: ${EchoUtility.toSafeText({ value: object.key })}`,\n });\n }\n\n if (response.status === HTTP.ResultCodes.RS_4.NotFound) {\n throw this.asStorageError({\n error: { status: response.status },\n operation,\n bucket,\n object,\n });\n }\n\n if (!response.ok) {\n throw getError({\n message: `[${operation}] S3 error | bucket: ${EchoUtility.toSafeText({ value: bucket.name })} | key: ${EchoUtility.toSafeText({ value: object.key })} | status: ${response.status}`,\n });\n }\n }\n\n /** `S3File` cannot send `If-Match` or a version id, so a conditional read is a signed GET. */\n private async getConditionalStream(\n opts: TObjectStreamOptions,\n ): Promise<ReadableStream<Uint8Array>> {\n const { bucket, object, range, ifMatch, versionId } = opts;\n\n const response = await this.signedFetch({\n method: HTTP.Methods.GET,\n bucket,\n object,\n query: { versionId },\n headers: {\n [HTTP.Headers.IF_MATCH]: BunS3Helper.quoteEtag({ etag: ifMatch }),\n [HTTP.Headers.RANGE]:\n range && `${HTTP.HeaderValues.RANGE_UNIT_BYTES}=${range.start}-${range.end ?? ''}`,\n },\n });\n\n this.assertObjectResponse({ response, operation: 'getObjectStream', bucket, object });\n\n if (!response.body) {\n throw getError({\n message: `[getObjectStream] The response has no body | key: ${EchoUtility.toSafeText({ value: object.key })}`,\n });\n }\n\n return response.body;\n }\n\n /** A signed HEAD rather than `client.stat`, because Bun's stat does not report the version id a pin needs. */\n async getStat(opts: IObjectLocation): Promise<IFileStat> {\n const { bucket, object } = opts;\n\n const response = await this.signedFetch({ method: HTTP.Methods.HEAD, bucket, object });\n this.assertObjectResponse({ response, operation: 'getStat', bucket, object });\n\n const lastModified = response.headers.get(HTTP.Headers.LAST_MODIFIED);\n\n return {\n size: Number(response.headers.get(HTTP.Headers.CONTENT_LENGTH) ?? 0),\n // One key, not two spellings. The served type comes from the object name; this is diagnostic.\n metadata: { mimetype: response.headers.get(HTTP.Headers.CONTENT_TYPE) ?? undefined },\n lastModified: lastModified === null ? undefined : new Date(lastModified),\n etag: response.headers.get(HTTP.Headers.ETAG) ?? undefined,\n versionId: StorageUtility.realVersionId({\n value: response.headers.get(S3Headers.VERSION_ID),\n }),\n };\n }\n\n async removeObject(opts: IObjectLocation): Promise<void> {\n const bucketName = opts.bucket.name;\n const key = opts.object.key;\n\n try {\n await this.client.delete(key, this.callOptions({ bucket: bucketName }));\n } catch (error) {\n throw this.asStorageError({\n error,\n operation: 'removeObject',\n bucket: opts.bucket,\n object: opts.object,\n });\n }\n }\n\n async removeObjects(opts: { bucket: IBucketRef; objects: IObjectRef[] }): Promise<void> {\n const { bucket, objects } = opts;\n\n await this.mapWithConcurrency({\n items: objects,\n task: ({ item: object }) => this.removeObject({ bucket, object }),\n });\n }\n\n /** S3 caps a call at 1000 keys and continues through `nextContinuationToken`. `useRecursive: false` maps to `delimiter: '/'`. */\n async listObjects(opts: IListObjectsOptions): Promise<IObjectInfo[]> {\n const { prefix, useRecursive = false, maxKeys } = opts;\n const bucketName = opts.bucket.name;\n\n // `maxKeys: 0` means zero, not unlimited.\n const limit = maxKeys ?? Number.POSITIVE_INFINITY;\n\n if (limit <= 0) {\n return [];\n }\n\n const objects: IObjectInfo[] = [];\n let continuationToken: string | undefined;\n\n do {\n const remaining = limit - objects.length;\n const response = await this.client.list(\n {\n prefix,\n continuationToken,\n delimiter: useRecursive ? undefined : '/',\n maxKeys: Number.isFinite(remaining)\n ? Math.min(remaining, StorageLimits.MAX_LIST_KEYS)\n : undefined,\n },\n this.callOptions({ bucket: bucketName }),\n );\n\n const responseContents = response.contents ?? [];\n\n for (const entry of responseContents) {\n objects.push({\n name: entry.key,\n size: entry.size,\n lastModified: entry.lastModified ? new Date(entry.lastModified) : undefined,\n etag: entry.eTag,\n });\n }\n\n continuationToken = response.isTruncated ? response.nextContinuationToken : undefined;\n } while (continuationToken && objects.length < limit);\n\n return objects;\n }\n}\n"]}
|