@storecraft/storage-google 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 +38 -1
- package/adapter.js +6 -4
- package/adapter.utils.js +2 -2
- package/jsconfig.json +1 -0
- package/package.json +5 -4
- package/tests/storage.test.js +9 -6
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 `GCP` **Storage**
|
@@ -49,6 +49,43 @@ console.log('presign GET url ', url);
|
|
49
49
|
|
50
50
|
```
|
51
51
|
|
52
|
+
## In Storecraft App
|
53
|
+
|
54
|
+
```js
|
55
|
+
import { App } from '@storecraft/core';
|
56
|
+
import { MongoDB, migrateToLatest } from '@storecraft/database-mongodb';
|
57
|
+
import { NodePlatform } from '@storecraft/core/platform/node';
|
58
|
+
import { GoogleStorage } from '@storecraft/storage-google';
|
59
|
+
|
60
|
+
const app = new App(
|
61
|
+
{
|
62
|
+
storage_rewrite_urls: undefined,
|
63
|
+
general_store_name: 'Wush Wush Games',
|
64
|
+
general_store_description: 'We sell cool retro video games',
|
65
|
+
general_store_website: 'https://wush.games',
|
66
|
+
auth_secret_access_token: process.env.auth_secret_access_token,
|
67
|
+
auth_secret_refresh_token: process.env.auth_secret_refresh_token
|
68
|
+
auth_admins_emails: ['jonny@begood.com']
|
69
|
+
}
|
70
|
+
)
|
71
|
+
.withPlatform(new NodePlatform())
|
72
|
+
.withDatabase(new MongoDB())
|
73
|
+
.withStorage(
|
74
|
+
new GoogleStorage(
|
75
|
+
{
|
76
|
+
bucket: process.env.GS_BUCKET,
|
77
|
+
client_email: process.env.GS_CLIENT_EMAIL,
|
78
|
+
private_key: process.env.GS_PRIVATE_KEY,
|
79
|
+
private_key_id: process.env.GS_PRIVATE_KEY_ID
|
80
|
+
}
|
81
|
+
)
|
82
|
+
);
|
83
|
+
|
84
|
+
await app.init();
|
85
|
+
await migrateToLatest(app.db, false);
|
86
|
+
|
87
|
+
```
|
88
|
+
|
52
89
|
|
53
90
|
```text
|
54
91
|
Author: Tomer Shalev (tomer.shalev@gmail.com)
|
package/adapter.js
CHANGED
@@ -29,8 +29,8 @@ const infer_content_type = (name) => {
|
|
29
29
|
*/
|
30
30
|
|
31
31
|
/**
|
32
|
-
* Google Storage
|
33
|
-
* @typedef {import('@storecraft/core/
|
32
|
+
* @description Google Storage adapter
|
33
|
+
* @typedef {import('@storecraft/core/storage').storage_driver} storage
|
34
34
|
*
|
35
35
|
* @implements {storage}
|
36
36
|
*/
|
@@ -66,7 +66,7 @@ export class GoogleStorage {
|
|
66
66
|
}
|
67
67
|
|
68
68
|
features() {
|
69
|
-
/** @type {import('@storecraft/core/
|
69
|
+
/** @type {import('@storecraft/core/storage').StorageFeatures} */
|
70
70
|
const f = {
|
71
71
|
supports_signed_urls: true
|
72
72
|
}
|
@@ -101,6 +101,7 @@ export class GoogleStorage {
|
|
101
101
|
Authorization: auth,
|
102
102
|
'Content-Type': 'image/png'
|
103
103
|
},
|
104
|
+
// @ts-ignore
|
104
105
|
duplex: 'half'
|
105
106
|
}
|
106
107
|
);
|
@@ -273,8 +274,9 @@ export class GoogleStorage {
|
|
273
274
|
}
|
274
275
|
);
|
275
276
|
|
277
|
+
// console.log(await r.text())
|
278
|
+
|
276
279
|
return r.ok;
|
277
|
-
// console.log(r)
|
278
280
|
}
|
279
281
|
}
|
280
282
|
|
package/adapter.utils.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { base64, jwt } from '@storecraft/core/
|
1
|
+
import { base64, jwt } from '@storecraft/core/crypto';
|
2
2
|
|
3
3
|
/**
|
4
4
|
*
|
@@ -7,7 +7,7 @@ import { base64, jwt } from '@storecraft/core/v-crypto';
|
|
7
7
|
* @returns
|
8
8
|
*/
|
9
9
|
export async function getJWTFromServiceAccount(sf, aud=undefined) {
|
10
|
-
/** @type {Partial<import('@storecraft/core/
|
10
|
+
/** @type {Partial<import('@storecraft/core/crypto').jwt.JWTClaims> & Record<string, string>} */
|
11
11
|
const claims = {
|
12
12
|
scope: [
|
13
13
|
// 'https://www.googleapis.com/auth/cloud-platform',
|
package/jsconfig.json
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storecraft/storage-google",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.3",
|
4
4
|
"description": "Official Google 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-google"
|
11
|
+
"directory": "packages/storage/storage-google"
|
12
12
|
},
|
13
13
|
"keywords": [
|
14
14
|
"commerce",
|
@@ -18,13 +18,14 @@
|
|
18
18
|
],
|
19
19
|
"scripts": {
|
20
20
|
"storage-google:test": "uvu -c",
|
21
|
-
"
|
21
|
+
"test": "npm run storage-google:test",
|
22
|
+
"prepublishOnly": "npm version patch --force"
|
22
23
|
},
|
23
24
|
"type": "module",
|
24
25
|
"main": "adapter.js",
|
25
26
|
"types": "types.public.d.ts",
|
26
27
|
"dependencies": {
|
27
|
-
"@storecraft/core": "^1.0.
|
28
|
+
"@storecraft/core": "^1.0.11"
|
28
29
|
},
|
29
30
|
"devDependencies": {
|
30
31
|
"@types/node": "^20.11.0",
|
package/tests/storage.test.js
CHANGED
@@ -3,6 +3,7 @@ import { test } from 'uvu';
|
|
3
3
|
import * as assert from 'uvu/assert';
|
4
4
|
import { GoogleStorage } from '@storecraft/storage-google'
|
5
5
|
import { readFile } from 'node:fs/promises';
|
6
|
+
import { storage as storage_test_runner } from '@storecraft/core/test-runner'
|
6
7
|
|
7
8
|
const areBlobsEqual = async (blob1, blob2) => {
|
8
9
|
return !Buffer.from(await blob1.arrayBuffer()).compare(
|
@@ -15,16 +16,18 @@ const storage = new GoogleStorage({
|
|
15
16
|
private_key: process.env.GS_PRIVATE_KEY, private_key_id: process.env.GS_PRIVATE_KEY_ID
|
16
17
|
});
|
17
18
|
|
18
|
-
|
19
|
+
const suite = storage_test_runner.create(storage);
|
19
20
|
|
20
|
-
|
21
|
+
suite.before(async () => { await storage.init(undefined) });
|
22
|
+
|
23
|
+
suite('blob put/get/delete', async () => {
|
21
24
|
const data = [
|
22
25
|
// {
|
23
26
|
// key: 'folder1/tomer.txt',
|
24
27
|
// blob: new Blob(['this is some text from tomer :)']),
|
25
28
|
// },
|
26
29
|
{
|
27
|
-
key: 'node2222.png',
|
30
|
+
key: 'folder2/node2222.png',
|
28
31
|
blob: new Blob([await readFile('./node.png')])
|
29
32
|
}
|
30
33
|
];
|
@@ -49,14 +52,14 @@ test('blob put/get/delete', async () => {
|
|
49
52
|
|
50
53
|
});
|
51
54
|
|
52
|
-
|
55
|
+
suite('blob put (presign)', async () => {
|
53
56
|
const data = [
|
54
57
|
// {
|
55
58
|
// key: 'folder1/tomer.txt',
|
56
59
|
// blob: new Blob(['this is some text from tomer :)']),
|
57
60
|
// },
|
58
61
|
{
|
59
|
-
key: 'node_test2.png',
|
62
|
+
key: 'folder2/node_test2.png',
|
60
63
|
blob: new Blob([await readFile('./node.png')])
|
61
64
|
}
|
62
65
|
];
|
@@ -82,4 +85,4 @@ test('blob put (presign)', async () => {
|
|
82
85
|
|
83
86
|
});
|
84
87
|
|
85
|
-
|
88
|
+
suite.run();
|