@storecraft/storage-s3-compatible 1.0.1 → 1.0.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/README.md +36 -1
- package/adapter.js +6 -5
- package/jsconfig.json +1 -0
- package/package.json +4 -3
- package/tests/storage.aws-s3.test.js +11 -17
- package/tests/storage.r2.test.js +12 -17
package/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
<div style="text-align:center">
|
4
4
|
<img src='https://storecraft.app/storecraft-color.svg'
|
5
|
-
width='90%'
|
5
|
+
width='90%' />
|
6
6
|
</div><hr/><br/>
|
7
7
|
|
8
8
|
`fetch` ready support for an `S3` like storage:
|
@@ -45,6 +45,41 @@ console.log('presign GET url ', url);
|
|
45
45
|
|
46
46
|
```
|
47
47
|
|
48
|
+
## In Storecraft App
|
49
|
+
|
50
|
+
```js
|
51
|
+
import { App } from '@storecraft/core';
|
52
|
+
import { MongoDB, migrateToLatest } from '@storecraft/database-mongodb';
|
53
|
+
import { NodePlatform } from '@storecraft/core/platform/node';
|
54
|
+
import { R2 } from '@storecraft/storage-s3-compatible'
|
55
|
+
|
56
|
+
const app = new App(
|
57
|
+
{
|
58
|
+
storage_rewrite_urls: undefined,
|
59
|
+
general_store_name: 'Wush Wush Games',
|
60
|
+
general_store_description: 'We sell cool retro video games',
|
61
|
+
general_store_website: 'https://wush.games',
|
62
|
+
auth_secret_access_token: process.env.auth_secret_access_token,
|
63
|
+
auth_secret_refresh_token: process.env.auth_secret_refresh_token
|
64
|
+
auth_admins_emails: ['jonny@begood.com']
|
65
|
+
}
|
66
|
+
)
|
67
|
+
.withPlatform(new NodePlatform())
|
68
|
+
.withDatabase(new MongoDB())
|
69
|
+
.withStorage(
|
70
|
+
new R2(
|
71
|
+
process.env.R2_BUCKET,
|
72
|
+
process.env.R2_ACCOUNT_ID,
|
73
|
+
process.env.R2_ACCESS_KEY_ID,
|
74
|
+
process.env.R2_SECRET_ACCESS_KEY
|
75
|
+
)
|
76
|
+
);
|
77
|
+
|
78
|
+
await app.init();
|
79
|
+
await migrateToLatest(app.db, false);
|
80
|
+
|
81
|
+
```
|
82
|
+
|
48
83
|
```text
|
49
84
|
Author: Tomer Shalev (tomer.shalev@gmail.com)
|
50
85
|
```
|
package/adapter.js
CHANGED
@@ -29,8 +29,9 @@ const infer_content_type = (name) => {
|
|
29
29
|
*/
|
30
30
|
|
31
31
|
/**
|
32
|
-
* The base S3 compatible class
|
33
|
-
*
|
32
|
+
* @description The base S3 compatible class
|
33
|
+
*
|
34
|
+
* @typedef {import('@storecraft/core/storage').storage_driver} storage
|
34
35
|
*
|
35
36
|
* @implements {storage}
|
36
37
|
*/
|
@@ -74,7 +75,7 @@ export class S3CompatibleStorage {
|
|
74
75
|
get config() { return this.#_config; }
|
75
76
|
|
76
77
|
features() {
|
77
|
-
/** @type {import('@storecraft/core/
|
78
|
+
/** @type {import('@storecraft/core/storage').StorageFeatures} */
|
78
79
|
const f = {
|
79
80
|
supports_signed_urls: true
|
80
81
|
}
|
@@ -137,7 +138,7 @@ export class S3CompatibleStorage {
|
|
137
138
|
/**
|
138
139
|
*
|
139
140
|
* @param {string} key
|
140
|
-
* @returns {ReturnType<import('@storecraft/core/
|
141
|
+
* @returns {ReturnType<import('@storecraft/core/storage').storage_driver["putSigned"]>}
|
141
142
|
*/
|
142
143
|
async putSigned(key) {
|
143
144
|
const url = new URL(this.get_file_url(key));
|
@@ -218,7 +219,7 @@ export class S3CompatibleStorage {
|
|
218
219
|
/**
|
219
220
|
*
|
220
221
|
* @param {string} key
|
221
|
-
* @returns {ReturnType<import('@storecraft/core/
|
222
|
+
* @returns {ReturnType<import('@storecraft/core/storage').storage_driver["getSigned"]>}
|
222
223
|
*/
|
223
224
|
async getSigned(key) {
|
224
225
|
const url = new URL(this.get_file_url(key));
|
package/jsconfig.json
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storecraft/storage-s3-compatible",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.3",
|
4
4
|
"description": "Official S3-Compatible Storage adapter for storecraft",
|
5
5
|
"license": "MIT",
|
6
6
|
"author": "Tomer Shalev (https://github.com/store-craft)",
|
@@ -8,7 +8,7 @@
|
|
8
8
|
"repository": {
|
9
9
|
"type": "git",
|
10
10
|
"url": "https://github.com/store-craft/storecraft.git",
|
11
|
-
"directory": "packages/storage-s3-compatible"
|
11
|
+
"directory": "packages/storage/storage-s3-compatible"
|
12
12
|
},
|
13
13
|
"keywords": [
|
14
14
|
"commerce",
|
@@ -18,7 +18,8 @@
|
|
18
18
|
],
|
19
19
|
"scripts": {
|
20
20
|
"storage-s3-compatible:test": "uvu -c",
|
21
|
-
"
|
21
|
+
"test": "npm run storage-s3-compatible:test",
|
22
|
+
"prepublishOnly": "npm version patch --force"
|
22
23
|
},
|
23
24
|
"type": "module",
|
24
25
|
"main": "adapter.js",
|
@@ -1,10 +1,8 @@
|
|
1
1
|
import 'dotenv/config';
|
2
|
-
import { test } from 'uvu';
|
3
2
|
import * as assert from 'uvu/assert';
|
4
3
|
import { S3 } from '@storecraft/storage-s3-compatible'
|
5
4
|
import { readFile } from 'node:fs/promises';
|
6
|
-
import {
|
7
|
-
import * as path from 'node:path';
|
5
|
+
import { storage as storage_test_runner } from '@storecraft/core/test-runner'
|
8
6
|
|
9
7
|
const areBlobsEqual = async (blob1, blob2) => {
|
10
8
|
return !Buffer.from(await blob1.arrayBuffer()).compare(
|
@@ -22,16 +20,14 @@ const storage = new S3({
|
|
22
20
|
secretAccessKey: process.env.S3_SECRET_KEY
|
23
21
|
});
|
24
22
|
|
25
|
-
|
23
|
+
const suite = storage_test_runner.create(storage);
|
26
24
|
|
27
|
-
|
25
|
+
suite.before(async () => { await storage.init(undefined) });
|
26
|
+
|
27
|
+
suite('blob put/get/delete', async () => {
|
28
28
|
const data = [
|
29
|
-
// {
|
30
|
-
// key: 'folder1/tomer.txt',
|
31
|
-
// blob: new Blob(['this is some text from tomer :)']),
|
32
|
-
// },
|
33
29
|
{
|
34
|
-
key: 'node2222.png',
|
30
|
+
key: 'folder2/node2222.png',
|
35
31
|
blob: new Blob([await readFile('./node.png')])
|
36
32
|
}
|
37
33
|
];
|
@@ -56,14 +52,10 @@ test('blob put/get/delete', async () => {
|
|
56
52
|
|
57
53
|
});
|
58
54
|
|
59
|
-
|
55
|
+
suite('blob put (presign)', async () => {
|
60
56
|
const data = [
|
61
|
-
// {
|
62
|
-
// key: 'folder1/tomer.txt',
|
63
|
-
// blob: new Blob(['this is some text from tomer :)']),
|
64
|
-
// },
|
65
57
|
{
|
66
|
-
key: 'node_test2.png',
|
58
|
+
key: 'folder2/node_test2.png',
|
67
59
|
blob: new Blob([await readFile('./node.png')])
|
68
60
|
}
|
69
61
|
];
|
@@ -81,10 +73,12 @@ test('blob put (presign)', async () => {
|
|
81
73
|
}
|
82
74
|
);
|
83
75
|
|
76
|
+
console.log(url)
|
77
|
+
|
84
78
|
assert.ok(r.ok, 'upload failed')
|
85
79
|
}
|
86
80
|
);
|
87
81
|
|
88
82
|
});
|
89
83
|
|
90
|
-
|
84
|
+
suite.run();
|
package/tests/storage.r2.test.js
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
import 'dotenv/config';
|
2
|
-
import { test } from 'uvu';
|
3
2
|
import * as assert from 'uvu/assert';
|
4
3
|
import { R2 } from '../adapter.js'
|
5
4
|
import { readFile } from 'node:fs/promises';
|
6
|
-
import {
|
7
|
-
|
5
|
+
import { storage as storage_test_runner } from '@storecraft/core/test-runner'
|
6
|
+
|
8
7
|
|
9
8
|
const areBlobsEqual = async (blob1, blob2) => {
|
10
9
|
return !Buffer.from(await blob1.arrayBuffer()).compare(
|
@@ -19,16 +18,14 @@ const storage = new R2({
|
|
19
18
|
secretAccessKey: process.env.R2_SECRET_ACCESS_KEY
|
20
19
|
});
|
21
20
|
|
22
|
-
|
21
|
+
const suite = storage_test_runner.create(storage);
|
22
|
+
|
23
|
+
suite.before(async () => { await storage.init(undefined) });
|
23
24
|
|
24
|
-
|
25
|
+
suite('blob put/get/delete', async () => {
|
25
26
|
const data = [
|
26
|
-
// {
|
27
|
-
// key: 'folder1/tomer.txt',
|
28
|
-
// blob: new Blob(['this is some text from tomer :)']),
|
29
|
-
// },
|
30
27
|
{
|
31
|
-
key: 'node2222.png',
|
28
|
+
key: 'folder2/node2222.png',
|
32
29
|
blob: new Blob([await readFile('./node.png')])
|
33
30
|
}
|
34
31
|
];
|
@@ -53,14 +50,10 @@ test('blob put/get/delete', async () => {
|
|
53
50
|
|
54
51
|
});
|
55
52
|
|
56
|
-
|
53
|
+
suite('blob put (presign)', async () => {
|
57
54
|
const data = [
|
58
|
-
// {
|
59
|
-
// key: 'folder1/tomer.txt',
|
60
|
-
// blob: new Blob(['this is some text from tomer :)']),
|
61
|
-
// },
|
62
55
|
{
|
63
|
-
key: 'node_test2.png',
|
56
|
+
key: 'folder2/node_test2.png',
|
64
57
|
blob: new Blob([await readFile('./node.png')])
|
65
58
|
}
|
66
59
|
];
|
@@ -78,10 +71,12 @@ test('blob put (presign)', async () => {
|
|
78
71
|
}
|
79
72
|
);
|
80
73
|
|
74
|
+
console.log(url)
|
75
|
+
|
81
76
|
assert.ok(r.ok, 'upload failed')
|
82
77
|
}
|
83
78
|
);
|
84
79
|
|
85
80
|
});
|
86
81
|
|
87
|
-
|
82
|
+
suite.run();
|