@storecraft/storage-google 1.0.13 → 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 +34 -42
- package/package.json +1 -1
package/README.md
CHANGED
@@ -5,17 +5,14 @@
|
|
5
5
|
width='90%' />
|
6
6
|
</div><hr/><br/>
|
7
7
|
|
8
|
-
`
|
8
|
+
**Storecraft** supports the `Google Storage` services. The service is
|
9
|
+
serverless friendly. Through the `@storecraft/storage-google` package.
|
9
10
|
|
10
11
|
Features:
|
11
12
|
- Works in any `js` runtime and platform that supports `fetch`
|
12
13
|
- Supports streaming `Get` / `Put` / `Delete`
|
13
14
|
- Supports `presigned` `Get` / `Put` requests to offload to client
|
14
15
|
|
15
|
-
```bash
|
16
|
-
npm i @storecraft/storage-google
|
17
|
-
```
|
18
|
-
|
19
16
|
## How-to
|
20
17
|
1. Create a bucket at `GCP console` or even at `firebase`
|
21
18
|
2. Download the `service json file`
|
@@ -26,59 +23,54 @@ Note:
|
|
26
23
|
- You can use an empty constructor and upon `StoreCraft` init, the platform
|
27
24
|
environment variables will be used by this storage if needed.
|
28
25
|
|
29
|
-
```js
|
30
|
-
import { GoogleStorage } from '@storecraft/storage-google';
|
31
|
-
|
32
|
-
const storage = new GoogleStorage({
|
33
|
-
bucket: process.env.GS_BUCKET,
|
34
|
-
client_email: process.env.GS_CLIENT_EMAIL,
|
35
|
-
private_key: process.env.GS_PRIVATE_KEY,
|
36
|
-
private_key_id: process.env.GS_PRIVATE_KEY_ID
|
37
|
-
});
|
38
|
-
|
39
|
-
// write
|
40
|
-
await storage.putBlob(
|
41
|
-
'folder1/tomer.txt',
|
42
|
-
new Blob(['this is some text from tomer :)'])
|
43
|
-
);
|
44
26
|
|
45
|
-
|
46
|
-
const { value } = await storage.getBlob('folder1/tomer.txt');
|
47
|
-
const { url } = await storage.getSigned('folder1/tomer.txt');
|
48
|
-
console.log('presign GET url ', url);
|
27
|
+
## Usage
|
49
28
|
|
29
|
+
```bash
|
30
|
+
npm i @storecraft/storage-google
|
50
31
|
```
|
32
|
+
|
33
|
+
then,
|
51
34
|
|
52
|
-
|
53
|
-
|
54
|
-
```js
|
35
|
+
```ts
|
55
36
|
import { App } from '@storecraft/core';
|
56
|
-
import { MongoDB, migrateToLatest } from '@storecraft/database-mongodb';
|
57
|
-
import { NodePlatform } from '@storecraft/core/platform/node';
|
58
37
|
import { GoogleStorage } from '@storecraft/storage-google';
|
59
38
|
|
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
|
-
)
|
39
|
+
const app = new App()
|
71
40
|
.withPlatform(new NodePlatform())
|
72
41
|
.withDatabase(new MongoDB())
|
73
42
|
.withStorage(
|
74
|
-
new GoogleStorage(
|
43
|
+
new GoogleStorage(
|
44
|
+
{
|
45
|
+
bucket: process.env.GS_BUCKET,
|
46
|
+
client_email: process.env.GS_CLIENT_EMAIL,
|
47
|
+
private_key: process.env.GS_PRIVATE_KEY,
|
48
|
+
private_key_id: process.env.GS_PRIVATE_KEY_ID
|
49
|
+
}
|
50
|
+
)
|
75
51
|
);
|
76
52
|
|
77
53
|
await app.init();
|
78
|
-
|
54
|
+
```
|
55
|
+
|
56
|
+
## config
|
57
|
+
|
58
|
+
Storecraft will search the following `env` variables
|
79
59
|
|
60
|
+
```bash
|
61
|
+
GS_BUCKET=...
|
62
|
+
GS_CLIENT_EMAIL=...
|
63
|
+
GS_PRIVATE_KEY=...
|
64
|
+
GS_PRIVATE_KEY_ID=...
|
80
65
|
```
|
81
66
|
|
67
|
+
So, you can instantiate with empty config
|
68
|
+
|
69
|
+
```ts
|
70
|
+
.withStorage(
|
71
|
+
new GoogleStorage()
|
72
|
+
)
|
73
|
+
```
|
82
74
|
|
83
75
|
```text
|
84
76
|
Author: Tomer Shalev (tomer.shalev@gmail.com)
|