@storecraft/storage-s3-compatible 1.0.17 → 1.2.5
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 +3 -8
- package/adapter.js +60 -43
- package/package.json +1 -2
- package/types.public.d.ts +5 -3
package/README.md
CHANGED
@@ -41,9 +41,7 @@ const app = new App()
|
|
41
41
|
secretAccessKey: process.env.S3_SECRET_KEY
|
42
42
|
}
|
43
43
|
)
|
44
|
-
);
|
45
|
-
|
46
|
-
await app.init();
|
44
|
+
).init();
|
47
45
|
```
|
48
46
|
|
49
47
|
## config
|
@@ -84,9 +82,8 @@ const app = new App()
|
|
84
82
|
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY
|
85
83
|
}
|
86
84
|
)
|
87
|
-
);
|
85
|
+
).init();
|
88
86
|
|
89
|
-
await app.init();
|
90
87
|
```
|
91
88
|
|
92
89
|
## config
|
@@ -128,9 +125,7 @@ const app = new App()
|
|
128
125
|
forcePathStyle: true,
|
129
126
|
}
|
130
127
|
)
|
131
|
-
);
|
132
|
-
|
133
|
-
await app.init();
|
128
|
+
).init();
|
134
129
|
```
|
135
130
|
|
136
131
|
## config
|
package/adapter.js
CHANGED
@@ -36,7 +36,7 @@ const infer_content_type = (name) => {
|
|
36
36
|
export class S3CompatibleStorage {
|
37
37
|
|
38
38
|
/** @satisfies {ENV<Config>} */
|
39
|
-
static EnvConfig = /** @type{const} */ ({
|
39
|
+
static EnvConfig = /** @type {const} */ ({
|
40
40
|
accessKeyId: 'S3_ACCESS_KEY_ID',
|
41
41
|
secretAccessKey: 'S3_SECRET_ACCESS_KEY',
|
42
42
|
bucket: 'S3_BUCKET',
|
@@ -82,12 +82,22 @@ export class S3CompatibleStorage {
|
|
82
82
|
* @type {storage_driver["init"]}
|
83
83
|
*/
|
84
84
|
async init(app) {
|
85
|
-
this.config.accessKeyId ??=
|
86
|
-
|
87
|
-
|
85
|
+
this.config.accessKeyId ??=
|
86
|
+
app.env[S3CompatibleStorage.EnvConfig.accessKeyId];
|
87
|
+
|
88
|
+
this.config.secretAccessKey ??=
|
89
|
+
app.env[S3CompatibleStorage.EnvConfig.secretAccessKey];
|
90
|
+
|
91
|
+
this.config.bucket ??=
|
92
|
+
app.env[S3CompatibleStorage.EnvConfig.bucket];
|
93
|
+
|
88
94
|
// @ts-ignore
|
89
|
-
this.config.region ??=
|
90
|
-
|
95
|
+
this.config.region ??=
|
96
|
+
app.env[S3CompatibleStorage.EnvConfig.region];
|
97
|
+
|
98
|
+
this.config.endpoint ??=
|
99
|
+
app.env[S3CompatibleStorage.EnvConfig.endpoint];
|
100
|
+
|
91
101
|
return this;
|
92
102
|
}
|
93
103
|
|
@@ -284,7 +294,7 @@ export class S3CompatibleStorage {
|
|
284
294
|
export class R2 extends S3CompatibleStorage {
|
285
295
|
|
286
296
|
/** @satisfies {ENV<R2Config>} */
|
287
|
-
static R2EnvConfig = /** @type{const} */ ({
|
297
|
+
static R2EnvConfig = /** @type {const} */ ({
|
288
298
|
accessKeyId: 'S3_ACCESS_KEY_ID',
|
289
299
|
secretAccessKey: 'S3_SECRET_ACCESS_KEY',
|
290
300
|
bucket: 'S3_BUCKET',
|
@@ -295,26 +305,30 @@ export class R2 extends S3CompatibleStorage {
|
|
295
305
|
* @param {R2Config} config
|
296
306
|
*/
|
297
307
|
constructor(config={}) {
|
298
|
-
super(
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
);
|
308
|
+
super({
|
309
|
+
endpoint: config.account_id ?
|
310
|
+
`https://${config.account_id}.r2.cloudflarestorage.com` :
|
311
|
+
undefined,
|
312
|
+
accessKeyId: config.accessKeyId,
|
313
|
+
secretAccessKey:config.secretAccessKey,
|
314
|
+
bucket: config.bucket,
|
315
|
+
forcePathStyle: true,
|
316
|
+
region: 'auto'
|
317
|
+
});
|
318
|
+
|
310
319
|
this.r2_config = config;
|
311
320
|
}
|
312
321
|
|
313
322
|
/** @type {S3CompatibleStorage["init"]} */
|
314
323
|
init = async (app) => {
|
315
324
|
await super.init(app);
|
316
|
-
|
317
|
-
this.
|
325
|
+
|
326
|
+
this.r2_config.account_id ??=
|
327
|
+
app.env[R2.R2EnvConfig.account_id];
|
328
|
+
|
329
|
+
this.config.endpoint ??=
|
330
|
+
`https://${this.r2_config.account_id}.r2.cloudflarestorage.com`;
|
331
|
+
|
318
332
|
return this;
|
319
333
|
}
|
320
334
|
|
@@ -327,31 +341,34 @@ export class R2 extends S3CompatibleStorage {
|
|
327
341
|
export class S3 extends S3CompatibleStorage {
|
328
342
|
|
329
343
|
/** @satisfies {ENV<AwsS3Config>} */
|
330
|
-
static AWSS3EnvConfig = /** @type{const} */ ({
|
331
|
-
|
344
|
+
static AWSS3EnvConfig = /** @type {const} */ ({
|
345
|
+
accessKeyId: S3CompatibleStorage.EnvConfig.accessKeyId,
|
346
|
+
secretAccessKey: S3CompatibleStorage.EnvConfig.secretAccessKey,
|
347
|
+
bucket: S3CompatibleStorage.EnvConfig.bucket,
|
348
|
+
region: S3CompatibleStorage.EnvConfig.region,
|
332
349
|
});
|
333
350
|
|
334
351
|
/**
|
335
352
|
* @param {Partial<AwsS3Config>} config
|
336
353
|
*/
|
337
354
|
constructor(config = {}) {
|
338
|
-
super(
|
339
|
-
{
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
}
|
347
|
-
)
|
355
|
+
super({
|
356
|
+
endpoint: config.region ? `https://s3.${config.region}.amazonaws.com` : undefined,
|
357
|
+
accessKeyId: config.accessKeyId,
|
358
|
+
secretAccessKey: config.secretAccessKey,
|
359
|
+
bucket: config.bucket,
|
360
|
+
forcePathStyle: config.forcePathStyle ?? false,
|
361
|
+
region: config.region
|
362
|
+
})
|
348
363
|
}
|
349
364
|
|
350
365
|
/** @type {S3CompatibleStorage["init"]} */
|
351
366
|
init = async (app) => {
|
352
367
|
await super.init(app);
|
368
|
+
|
353
369
|
this.config.endpoint = `https://s3${this.config.region ?
|
354
370
|
('.'+this.config.region) : ''}.amazonaws.com`;
|
371
|
+
|
355
372
|
return this;
|
356
373
|
}
|
357
374
|
|
@@ -372,21 +389,21 @@ export class DigitalOceanSpaces extends S3CompatibleStorage {
|
|
372
389
|
* @param {Partial<Omit<Config, 'endpoint' | 'forcePathStyle'>>} config
|
373
390
|
*/
|
374
391
|
constructor(config = {}) {
|
375
|
-
super(
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
)
|
392
|
+
super({
|
393
|
+
endpoint: config.region ?
|
394
|
+
`https://${config.region}.digitaloceanspaces.com` : undefined,
|
395
|
+
accessKeyId: config.accessKeyId,
|
396
|
+
secretAccessKey: config.secretAccessKey,
|
397
|
+
bucket: config.bucket,
|
398
|
+
forcePathStyle: false,
|
399
|
+
region: 'auto'
|
400
|
+
})
|
385
401
|
}
|
386
402
|
|
387
403
|
/** @type {S3CompatibleStorage["init"]} */
|
388
404
|
init = async (app) => {
|
389
405
|
await super.init(app);
|
406
|
+
|
390
407
|
this.config.endpoint = this.config.region ?
|
391
408
|
`https://${this.config.region}.digitaloceanspaces.com` :
|
392
409
|
undefined;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storecraft/storage-s3-compatible",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.2.5",
|
4
4
|
"description": "Official S3-Compatible Storage adapter for storecraft",
|
5
5
|
"license": "MIT",
|
6
6
|
"author": "Tomer Shalev (https://github.com/store-craft)",
|
@@ -18,7 +18,6 @@
|
|
18
18
|
],
|
19
19
|
"scripts": {
|
20
20
|
"test": "node ./tests/storage.s3-compatible.test.js",
|
21
|
-
"prepublishOnly": "npm version patch --force",
|
22
21
|
"sc-publish": "npm publish"
|
23
22
|
},
|
24
23
|
"type": "module",
|
package/types.public.d.ts
CHANGED
@@ -10,7 +10,7 @@ export type Config = {
|
|
10
10
|
/** If missing, will be inferred by env variable `S3_SECRET_ACCESS_KEY` */
|
11
11
|
secretAccessKey?: string;
|
12
12
|
/** If missing, will be inferred by env variable `S3_REGION` */
|
13
|
-
region?: 'auto' |
|
13
|
+
region?: 'auto' | string;
|
14
14
|
forcePathStyle?: boolean;
|
15
15
|
}
|
16
16
|
|
@@ -22,9 +22,11 @@ export type R2Config = Omit<Config, 'region' | 'forcePathStyle' | 'endpoint'> &
|
|
22
22
|
};
|
23
23
|
|
24
24
|
|
25
|
-
export type AwsS3Config = Omit<Config, 'endpoint'
|
25
|
+
export type AwsS3Config = Omit<Config, 'endpoint'> & {
|
26
|
+
region?: AWSRegion;
|
27
|
+
};
|
26
28
|
|
27
|
-
type AWSRegion =
|
29
|
+
export type AWSRegion =
|
28
30
|
| "us-east-1"
|
29
31
|
| "us-east-2"
|
30
32
|
| "us-west-1"
|