@storecraft/storage-s3-compatible 1.0.14 → 1.0.16
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 +110 -33
- package/adapter.js +2 -0
- package/package.json +1 -1
- package/tests/storage.r2.test.js +1 -1
package/README.md
CHANGED
@@ -22,61 +22,138 @@ Features:
|
|
22
22
|
npm i @storecraft/storage-s3-compatible
|
23
23
|
```
|
24
24
|
|
25
|
-
##
|
25
|
+
## AWS S3
|
26
26
|
|
27
27
|
```js
|
28
|
-
import {
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
28
|
+
import { App } from '@storecraft/core';
|
29
|
+
import { S3 } from '@storecraft/storage-s3-compatible'
|
30
|
+
|
31
|
+
const app = new App()
|
32
|
+
.withPlatform(new NodePlatform())
|
33
|
+
.withDatabase(new MongoDB())
|
34
|
+
.withStorage(
|
35
|
+
new S3(
|
36
|
+
{
|
37
|
+
forcePathStyle: FORCE_PATH_STYLE,
|
38
|
+
bucket: process.env.S3_BUCKET,
|
39
|
+
region: process.env.S3_REGION,
|
40
|
+
accessKeyId: process.env.S3_ACCESS_KEY_ID,
|
41
|
+
secretAccessKey: process.env.S3_SECRET_KEY
|
42
|
+
}
|
43
|
+
)
|
41
44
|
);
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
46
|
+
await app.init();
|
47
|
+
```
|
48
|
+
|
49
|
+
## config
|
50
|
+
|
51
|
+
Storecraft will search the following `env` variables
|
52
|
+
|
53
|
+
```bash
|
54
|
+
S3_BUCKET=...
|
55
|
+
S3_REGION=...
|
56
|
+
S3_ACCESS_KEY_ID=...
|
57
|
+
S3_SECRET_KEY=...
|
58
|
+
```
|
59
|
+
|
60
|
+
So, you can instantiate with empty config
|
47
61
|
|
62
|
+
```ts
|
63
|
+
.withStorage(
|
64
|
+
new S3()
|
65
|
+
)
|
48
66
|
```
|
49
67
|
|
50
|
-
|
68
|
+
|
69
|
+
## Cloudflare R2
|
51
70
|
|
52
71
|
```js
|
53
72
|
import { App } from '@storecraft/core';
|
54
|
-
import { MongoDB, migrateToLatest } from '@storecraft/database-mongodb';
|
55
|
-
import { NodePlatform } from '@storecraft/core/platform/node';
|
56
73
|
import { R2 } from '@storecraft/storage-s3-compatible'
|
57
74
|
|
58
|
-
const app = new App(
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
75
|
+
const app = new App()
|
76
|
+
.withPlatform(new NodePlatform())
|
77
|
+
.withDatabase(new MongoDB())
|
78
|
+
.withStorage(
|
79
|
+
new R2(
|
80
|
+
{
|
81
|
+
account_id: process.env.CF_ACCOUNT_ID,
|
82
|
+
bucket: process.env.S3_BUCKET,
|
83
|
+
accessKeyId: process.env.S3_ACCESS_KEY_ID,
|
84
|
+
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY
|
85
|
+
}
|
86
|
+
)
|
87
|
+
);
|
88
|
+
|
89
|
+
await app.init();
|
90
|
+
```
|
91
|
+
|
92
|
+
## config
|
93
|
+
|
94
|
+
Storecraft will search the following `env` variables
|
95
|
+
|
96
|
+
```bash
|
97
|
+
CF_ACCOUNT_ID=...
|
98
|
+
S3_BUCKET=...
|
99
|
+
S3_ACCESS_KEY_ID=...
|
100
|
+
S3_SECRET_ACCESS_KEY=...
|
101
|
+
```
|
102
|
+
|
103
|
+
So, you can instantiate with empty config
|
104
|
+
|
105
|
+
```ts
|
106
|
+
.withStorage(
|
107
|
+
new R2()
|
68
108
|
)
|
109
|
+
```
|
110
|
+
|
111
|
+
### Any S3 compatible storage (minio for example)
|
112
|
+
|
113
|
+
```js
|
114
|
+
import { App } from '@storecraft/core';
|
115
|
+
import { S3CompatibleStorage } from '@storecraft/storage-s3-compatible'
|
116
|
+
|
117
|
+
const app = new App()
|
69
118
|
.withPlatform(new NodePlatform())
|
70
119
|
.withDatabase(new MongoDB())
|
71
120
|
.withStorage(
|
72
|
-
new
|
121
|
+
new S3CompatibleStorage(
|
122
|
+
{
|
123
|
+
endpoint: process.env.S3_ENDPOINT,
|
124
|
+
accessKeyId: process.env.S3_ACCESS_KEY_ID,
|
125
|
+
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
|
126
|
+
bucket: process.env.S3_BUCKET,
|
127
|
+
region: process.env.S3_REGION
|
128
|
+
forcePathStyle: true,
|
129
|
+
}
|
130
|
+
)
|
73
131
|
);
|
74
132
|
|
75
133
|
await app.init();
|
76
|
-
|
134
|
+
```
|
135
|
+
|
136
|
+
## config
|
77
137
|
|
138
|
+
Storecraft will search the following `env` variables
|
139
|
+
|
140
|
+
```bash
|
141
|
+
S3_ENDPOINT=...
|
142
|
+
S3_BUCKET=...
|
143
|
+
S3_REGION=...
|
144
|
+
S3_ACCESS_KEY_ID=...
|
145
|
+
S3_SECRET_KEY=...
|
78
146
|
```
|
79
147
|
|
148
|
+
So, you can instantiate with empty config
|
149
|
+
|
150
|
+
```ts
|
151
|
+
.withStorage(
|
152
|
+
new S3CompatibleStorage()
|
153
|
+
)
|
154
|
+
```
|
155
|
+
|
156
|
+
|
80
157
|
```text
|
81
158
|
Author: Tomer Shalev (tomer.shalev@gmail.com)
|
82
159
|
```
|
package/adapter.js
CHANGED
@@ -41,6 +41,7 @@ export class S3CompatibleStorage {
|
|
41
41
|
secretAccessKey: 'S3_SECRET_ACCESS_KEY',
|
42
42
|
bucket: 'S3_BUCKET',
|
43
43
|
region: 'S3_REGION',
|
44
|
+
endpoint: 'S3_ENDPOINT',
|
44
45
|
});
|
45
46
|
|
46
47
|
/** @type {AwsClient} */ #_client;
|
@@ -86,6 +87,7 @@ export class S3CompatibleStorage {
|
|
86
87
|
this.config.bucket ??= app.platform.env[S3CompatibleStorage.EnvConfig.bucket];
|
87
88
|
// @ts-ignore
|
88
89
|
this.config.region ??= app.platform.env[S3CompatibleStorage.EnvConfig.region];
|
90
|
+
this.config.endpoint ??= app.platform.env[S3CompatibleStorage.EnvConfig.endpoint];
|
89
91
|
return this;
|
90
92
|
}
|
91
93
|
|
package/package.json
CHANGED
package/tests/storage.r2.test.js
CHANGED
@@ -12,9 +12,9 @@ const areBlobsEqual = async (blob1, blob2) => {
|
|
12
12
|
};
|
13
13
|
|
14
14
|
const storage = new R2({
|
15
|
-
accessKeyId: process.env.S3_ACCESS_KEY_ID,
|
16
15
|
account_id: process.env.CF_ACCOUNT_ID,
|
17
16
|
bucket: process.env.S3_BUCKET,
|
17
|
+
accessKeyId: process.env.S3_ACCESS_KEY_ID,
|
18
18
|
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY
|
19
19
|
});
|
20
20
|
|