@storecraft/storage-google 1.0.10 → 1.0.11
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 +1 -8
- package/adapter.js +23 -20
- package/package.json +1 -1
- package/types.public.d.ts +8 -8
package/README.md
CHANGED
@@ -71,14 +71,7 @@ const app = new App(
|
|
71
71
|
.withPlatform(new NodePlatform())
|
72
72
|
.withDatabase(new MongoDB())
|
73
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
|
-
)
|
74
|
+
new GoogleStorage() // config inferred from env variables
|
82
75
|
);
|
83
76
|
|
84
77
|
await app.init();
|
package/adapter.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
/**
|
2
2
|
* @import { Config, ServiceFile } from './types.public.js'
|
3
|
+
* @import { ENV } from '@storecraft/core';
|
3
4
|
* @import { storage_driver, StorageFeatures } from '@storecraft/core/storage'
|
4
5
|
*/
|
5
6
|
|
@@ -35,12 +36,20 @@ const infer_content_type = (name) => {
|
|
35
36
|
*/
|
36
37
|
export class GoogleStorage {
|
37
38
|
|
39
|
+
/** @satisfies {ENV<Config>} */
|
40
|
+
static EnvConfig = /** @type{const} */ ({
|
41
|
+
bucket: 'GS_BUCKET',
|
42
|
+
client_email: 'GS_CLIENT_EMAIL',
|
43
|
+
private_key: 'GS_PRIVATE_KEY',
|
44
|
+
private_key_id: 'GS_PRIVATE_KEY_ID',
|
45
|
+
});
|
46
|
+
|
38
47
|
/** @type {Config} */ #_config;
|
39
48
|
|
40
49
|
/**
|
41
50
|
* @param {Config} [config]
|
42
51
|
*/
|
43
|
-
constructor(config) {
|
52
|
+
constructor(config={}) {
|
44
53
|
this.#_config = config;
|
45
54
|
}
|
46
55
|
|
@@ -54,12 +63,10 @@ export class GoogleStorage {
|
|
54
63
|
if(!app)
|
55
64
|
return this;
|
56
65
|
|
57
|
-
this.#_config
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
private_key_id: app.platform.env.GS_PRIVATE_KEY_ID,
|
62
|
-
}
|
66
|
+
this.#_config.bucket ??= app.platform.env[GoogleStorage.EnvConfig.bucket];
|
67
|
+
this.#_config.client_email ??= app.platform.env[GoogleStorage.EnvConfig.client_email];
|
68
|
+
this.#_config.private_key ??= app.platform.env[GoogleStorage.EnvConfig.private_key];
|
69
|
+
this.#_config.private_key_id ??= app.platform.env[GoogleStorage.EnvConfig.private_key_id];
|
63
70
|
|
64
71
|
return this;
|
65
72
|
}
|
@@ -112,8 +119,7 @@ export class GoogleStorage {
|
|
112
119
|
|
113
120
|
/**
|
114
121
|
*
|
115
|
-
* @
|
116
|
-
* @param {Blob} blob
|
122
|
+
* @type {storage_driver["putBlob"]}
|
117
123
|
*/
|
118
124
|
async putBlob(key, blob) {
|
119
125
|
return this.#put_internal(key, blob);
|
@@ -121,8 +127,7 @@ export class GoogleStorage {
|
|
121
127
|
|
122
128
|
/**
|
123
129
|
*
|
124
|
-
* @
|
125
|
-
* @param {ArrayBuffer} buffer
|
130
|
+
* @type {storage_driver["putArraybuffer"]}
|
126
131
|
*/
|
127
132
|
async putArraybuffer(key, buffer) {
|
128
133
|
return this.#put_internal(key, buffer);
|
@@ -130,8 +135,7 @@ export class GoogleStorage {
|
|
130
135
|
|
131
136
|
/**
|
132
137
|
*
|
133
|
-
* @
|
134
|
-
* @param {ReadableStream} stream
|
138
|
+
* @type {storage_driver["putStream"]}
|
135
139
|
*/
|
136
140
|
async putStream(key, stream) {
|
137
141
|
return this.#put_internal(key, stream);
|
@@ -139,7 +143,7 @@ export class GoogleStorage {
|
|
139
143
|
|
140
144
|
/**
|
141
145
|
*
|
142
|
-
* @
|
146
|
+
* @type {storage_driver["getSigned"]}
|
143
147
|
*/
|
144
148
|
async putSigned(key) {
|
145
149
|
const ct = infer_content_type(key);
|
@@ -189,7 +193,7 @@ export class GoogleStorage {
|
|
189
193
|
|
190
194
|
/**
|
191
195
|
*
|
192
|
-
* @
|
196
|
+
* @type {storage_driver["getArraybuffer"]}
|
193
197
|
*/
|
194
198
|
async getArraybuffer(key) {
|
195
199
|
const r = await this.#get_request(key);
|
@@ -204,7 +208,7 @@ export class GoogleStorage {
|
|
204
208
|
|
205
209
|
/**
|
206
210
|
*
|
207
|
-
* @
|
211
|
+
* @type {storage_driver["getBlob"]}
|
208
212
|
*/
|
209
213
|
async getBlob(key) {
|
210
214
|
const r = await this.#get_request(key);
|
@@ -221,8 +225,7 @@ export class GoogleStorage {
|
|
221
225
|
|
222
226
|
/**
|
223
227
|
*
|
224
|
-
* @
|
225
|
-
* @param {Response} key
|
228
|
+
* @type {storage_driver["getStream"]}
|
226
229
|
*/
|
227
230
|
async getStream(key) {
|
228
231
|
|
@@ -237,7 +240,7 @@ export class GoogleStorage {
|
|
237
240
|
|
238
241
|
/**
|
239
242
|
*
|
240
|
-
* @
|
243
|
+
* @type {storage_driver["getSigned"]}
|
241
244
|
*/
|
242
245
|
async getSigned(key) {
|
243
246
|
const sf = this.config;
|
@@ -259,7 +262,7 @@ export class GoogleStorage {
|
|
259
262
|
|
260
263
|
/**
|
261
264
|
*
|
262
|
-
* @
|
265
|
+
* @type {storage_driver["remove"]}
|
263
266
|
*/
|
264
267
|
async remove(key) {
|
265
268
|
const Authorization = 'Bearer ' + await getJWTFromServiceAccount(this.config);
|
package/package.json
CHANGED
package/types.public.d.ts
CHANGED
@@ -15,12 +15,12 @@ export type ServiceFile = {
|
|
15
15
|
}
|
16
16
|
|
17
17
|
export type Config = {
|
18
|
-
/** bucket name */
|
19
|
-
bucket
|
20
|
-
/** client email from the service file */
|
21
|
-
client_email
|
22
|
-
/** private key */
|
23
|
-
private_key
|
24
|
-
/** private key id */
|
25
|
-
private_key_id
|
18
|
+
/** bucket name, if missing will be inferred by env variable `GS_BUCKET` */
|
19
|
+
bucket?: string;
|
20
|
+
/** client email from the service file, if missing will be inferred by env variable `GS_CLIENT_EMAIL` */
|
21
|
+
client_email?: string;
|
22
|
+
/** private key, if missing will be inferred by env variable `GS_PRIVATE_KEY` */
|
23
|
+
private_key?: string;
|
24
|
+
/** private key id, if missing will be inferred by env variable `GS_PRIVATE_KEY_ID` */
|
25
|
+
private_key_id?: string;
|
26
26
|
}
|