arcway 0.4.12 → 0.4.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arcway",
3
- "version": "0.4.12",
3
+ "version": "0.4.13",
4
4
  "description": "A convention-based framework for building modular monoliths with strict domain boundaries.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -11,17 +11,53 @@ import {
11
11
  AbortMultipartUploadCommand,
12
12
  } from '@aws-sdk/client-s3';
13
13
  import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
14
+
15
+ function publicEndpoint(endpoint) {
16
+ if (typeof endpoint !== 'string') {
17
+ throw new Error('files.s3.publicEndpoint must be an HTTPS origin');
18
+ }
19
+
20
+ let url;
21
+ try {
22
+ url = new URL(endpoint);
23
+ } catch {
24
+ throw new Error('files.s3.publicEndpoint must be an HTTPS origin');
25
+ }
26
+
27
+ if (
28
+ url.protocol !== 'https:' ||
29
+ url.username ||
30
+ url.password ||
31
+ url.pathname !== '/' ||
32
+ url.search ||
33
+ url.hash
34
+ ) {
35
+ throw new Error('files.s3.publicEndpoint must be an HTTPS origin');
36
+ }
37
+
38
+ return url.origin;
39
+ }
40
+
14
41
  class S3FileDriver {
15
42
  client;
43
+ signingClient;
16
44
  bucket;
17
45
  constructor(config) {
18
46
  this.bucket = config.bucket;
19
- this.client = new S3Client({
47
+ const clientConfig = {
20
48
  region: config.region ?? 'us-east-1',
21
49
  ...(config.endpoint ? { endpoint: config.endpoint } : {}),
22
50
  ...(config.forcePathStyle ? { forcePathStyle: true } : {}),
23
51
  ...(config.credentials ? { credentials: config.credentials } : {}),
24
- });
52
+ };
53
+ this.client = new S3Client(clientConfig);
54
+ this.signingClient =
55
+ config.publicEndpoint === undefined
56
+ ? this.client
57
+ : new S3Client({
58
+ ...clientConfig,
59
+ endpoint: publicEndpoint(config.publicEndpoint),
60
+ });
25
61
  }
26
62
  async init() {}
27
63
 
@@ -158,7 +194,7 @@ class S3FileDriver {
158
194
  });
159
195
  return {
160
196
  method: 'PUT',
161
- url: await getSignedUrl(this.client, command, {
197
+ url: await getSignedUrl(this.signingClient, command, {
162
198
  expiresIn,
163
199
  signableHeaders: new Set([
164
200
  'content-type',
@@ -188,7 +224,7 @@ class S3FileDriver {
188
224
  bytes: part.bytes,
189
225
  method: 'PUT',
190
226
  url: await getSignedUrl(
191
- this.client,
227
+ this.signingClient,
192
228
  new UploadPartCommand({
193
229
  Bucket: this.bucket,
194
230
  Key: key,