@directus/storage-driver-s3 9.22.1 → 9.22.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -10,12 +10,16 @@ export class DriverS3 {
10
10
  acl;
11
11
  serverSideEncryption;
12
12
  constructor(config) {
13
- const s3ClientConfig = {
14
- credentials: {
13
+ const s3ClientConfig = {};
14
+ if ((config.key && !config.secret) || (config.secret && !config.key)) {
15
+ throw new Error('Both `key` and `secret` are required when defined');
16
+ }
17
+ if (config.key && config.secret) {
18
+ s3ClientConfig.credentials = {
15
19
  accessKeyId: config.key,
16
20
  secretAccessKey: config.secret,
17
- },
18
- };
21
+ };
22
+ }
19
23
  if (config.endpoint) {
20
24
  const protocol = config.endpoint.startsWith('https://') ? 'https:' : 'http:';
21
25
  const hostname = config.endpoint.replace('https://', '').replace('http://', '');
@@ -24,11 +28,13 @@ export class DriverS3 {
24
28
  protocol,
25
29
  path: '/',
26
30
  };
27
- s3ClientConfig.forcePathStyle = true;
28
31
  }
29
32
  if (config.region) {
30
33
  s3ClientConfig.region = config.region;
31
34
  }
35
+ if (config.forcePathStyle !== undefined) {
36
+ s3ClientConfig.forcePathStyle = config.forcePathStyle;
37
+ }
32
38
  this.client = new S3Client(s3ClientConfig);
33
39
  this.bucket = config.bucket;
34
40
  this.acl = config.acl;
@@ -2,7 +2,7 @@ import { CopyObjectCommand, DeleteObjectCommand, GetObjectCommand, HeadObjectCom
2
2
  import { Upload } from '@aws-sdk/lib-storage';
3
3
  import { normalizePath } from '@directus/utils';
4
4
  import { isReadableStream } from '@directus/utils/node';
5
- import { randAlphaNumeric, randDirectoryPath, randDomainName, randFilePath, randFileType, randGitBranch as randBucket, randGitShortSha as randUnique, randNumber, randPastDate, randText, randWord, } from '@ngneat/falso';
5
+ import { randAlphaNumeric, randBoolean, randDirectoryPath, randDomainName, randFilePath, randFileType, randGitBranch as randBucket, randGitShortSha as randUnique, randNumber, randPastDate, randText, randWord, } from '@ngneat/falso';
6
6
  import { join } from 'node:path';
7
7
  import { PassThrough, Readable } from 'node:stream';
8
8
  import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
@@ -25,6 +25,7 @@ beforeEach(() => {
25
25
  root: randDirectoryPath(),
26
26
  endpoint: randDomainName(),
27
27
  region: randWord(),
28
+ forcePathStyle: randBoolean(),
28
29
  },
29
30
  path: {
30
31
  input: randUnique() + randFilePath(),
@@ -65,6 +66,29 @@ afterEach(() => {
65
66
  vi.resetAllMocks();
66
67
  });
67
68
  describe('#constructor', () => {
69
+ test('Throws error if key defined but secret missing', () => {
70
+ try {
71
+ new DriverS3({ key: 'key', bucket: 'bucket' });
72
+ }
73
+ catch (err) {
74
+ expect(err).toBeInstanceOf(Error);
75
+ expect(err.message).toBe('Both `key` and `secret` are required when defined');
76
+ }
77
+ });
78
+ test('Throws error if secret defined but key missing', () => {
79
+ try {
80
+ new DriverS3({ secret: 'secret', bucket: 'bucket' });
81
+ }
82
+ catch (err) {
83
+ expect(err).toBeInstanceOf(Error);
84
+ expect(err.message).toBe('Both `key` and `secret` are required when defined');
85
+ }
86
+ });
87
+ test('Creates S3Client without key / secret (based on machine config)', () => {
88
+ const driver = new DriverS3({ bucket: 'bucket' });
89
+ expect(S3Client).toHaveBeenCalledWith({});
90
+ expect(driver['client']).toBeInstanceOf(S3Client);
91
+ });
68
92
  test('Creates S3Client with key / secret configuration', () => {
69
93
  expect(S3Client).toHaveBeenCalledWith({
70
94
  credentials: {
@@ -108,7 +132,6 @@ describe('#constructor', () => {
108
132
  endpoint: sampleHttpEndpoint,
109
133
  });
110
134
  expect(S3Client).toHaveBeenCalledWith({
111
- forcePathStyle: true,
112
135
  endpoint: {
113
136
  hostname: sampleDomain,
114
137
  protocol: 'http:',
@@ -130,7 +153,6 @@ describe('#constructor', () => {
130
153
  endpoint: sampleHttpEndpoint,
131
154
  });
132
155
  expect(S3Client).toHaveBeenCalledWith({
133
- forcePathStyle: true,
134
156
  endpoint: {
135
157
  hostname: sampleDomain,
136
158
  protocol: 'https:',
@@ -157,6 +179,21 @@ describe('#constructor', () => {
157
179
  },
158
180
  });
159
181
  });
182
+ test('Sets force path style', () => {
183
+ new DriverS3({
184
+ key: sample.config.key,
185
+ secret: sample.config.secret,
186
+ bucket: sample.config.bucket,
187
+ forcePathStyle: sample.config.forcePathStyle,
188
+ });
189
+ expect(S3Client).toHaveBeenCalledWith({
190
+ forcePathStyle: sample.config.forcePathStyle,
191
+ credentials: {
192
+ accessKeyId: sample.config.key,
193
+ secretAccessKey: sample.config.secret,
194
+ },
195
+ });
196
+ });
160
197
  test('Normalizes config path when root is given', () => {
161
198
  const mockRoot = randDirectoryPath();
162
199
  vi.mocked(normalizePath).mockReturnValue(mockRoot);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@directus/storage-driver-s3",
3
- "version": "9.22.1",
3
+ "version": "9.22.3",
4
4
  "type": "module",
5
5
  "description": "S3 file storage abstraction for `@directus/storage`",
6
6
  "repository": {
@@ -25,17 +25,17 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@aws-sdk/abort-controller": "3.226.0",
28
- "@aws-sdk/client-s3": "3.224.0",
29
- "@aws-sdk/lib-storage": "3.234.0",
30
- "@directus/storage": "9.22.1",
31
- "@directus/utils": "9.22.1"
28
+ "@aws-sdk/client-s3": "3.236.0",
29
+ "@aws-sdk/lib-storage": "3.236.0",
30
+ "@directus/storage": "9.22.3",
31
+ "@directus/utils": "9.22.3"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@directus/tsconfig": "0.0.6",
35
- "@ngneat/falso": "6.3.0",
36
- "@vitest/coverage-c8": "0.25.3",
37
- "typescript": "4.9.3",
38
- "vitest": "0.25.3"
35
+ "@ngneat/falso": "6.3.2",
36
+ "@vitest/coverage-c8": "0.26.2",
37
+ "typescript": "4.9.4",
38
+ "vitest": "0.26.2"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "tsc --build",