@storecraft/storage-s3-compatible 1.0.14 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,61 +22,138 @@ Features:
22
22
  npm i @storecraft/storage-s3-compatible
23
23
  ```
24
24
 
25
- ## usage
25
+ ## AWS S3
26
26
 
27
27
  ```js
28
- import { R2, S3, DigitalOceanSpaces, S3CompatibleStorage } from '@storecraft/storage-s3-compatible'
29
-
30
- const storage = new R2({
31
- accessKeyId: process.env.S3_ACCESS_KEY_ID,
32
- account_id: process.env.CF_ACCOUNT_ID,
33
- bucket: process.env.S3_BUCKET,
34
- secretAccessKey: process.env.S3_SECRET_ACCESS_KEY
35
- });
36
-
37
- // write
38
- await storage.putBlob(
39
- 'folder1/tomer.txt',
40
- new Blob(['this is some text from tomer :)'])
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
- // read
44
- const { value } = await storage.getBlob('folder1/tomer.txt');
45
- const url = await storage.getSigned('folder1/tomer.txt');
46
- console.log('presign GET url ', url);
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
- ## In Storecraft App
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
- storage_rewrite_urls: undefined,
61
- general_store_name: 'Wush Wush Games',
62
- general_store_description: 'We sell cool retro video games',
63
- general_store_website: 'https://wush.games',
64
- auth_secret_access_token: process.env.auth_secret_access_token,
65
- auth_secret_refresh_token: process.env.auth_secret_refresh_token
66
- auth_admins_emails: ['jonny@begood.com']
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 R2() // config will be inferred by env variables
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
- await migrateToLatest(app.db, false);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storecraft/storage-s3-compatible",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Official S3-Compatible Storage adapter for storecraft",
5
5
  "license": "MIT",
6
6
  "author": "Tomer Shalev (https://github.com/store-craft)",
@@ -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