@storecraft/storage-google 1.0.0 → 1.0.2

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 CHANGED
@@ -1,5 +1,10 @@
1
1
  # Storecraft Google Cloud Storage
2
2
 
3
+ <div style="text-align:center">
4
+ <img src='https://storecraft.app/storecraft-color.svg'
5
+ width='90%' />
6
+ </div><hr/><br/>
7
+
3
8
  `fetch` ready support for an `GCP` **Storage**
4
9
 
5
10
  Features:
@@ -7,6 +12,10 @@ Features:
7
12
  - Supports streaming `Get` / `Put` / `Delete`
8
13
  - Supports `presigned` `Get` / `Put` requests to offload to client
9
14
 
15
+ ```bash
16
+ npm i @storecraft/storage-google
17
+ ```
18
+
10
19
  ## How-to
11
20
  1. Create a bucket at `GCP console` or even at `firebase`
12
21
  2. Download the `service json file`
@@ -35,11 +44,48 @@ await storage.putBlob(
35
44
 
36
45
  // read
37
46
  const { value } = await storage.getBlob('folder1/tomer.txt');
38
- const url = await storage.getSigned('folder1/tomer.txt');
47
+ const { url } = await storage.getSigned('folder1/tomer.txt');
39
48
  console.log('presign GET url ', url);
40
49
 
41
50
  ```
42
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
+
43
89
 
44
90
  ```text
45
91
  Author: Tomer Shalev (tomer.shalev@gmail.com)
package/adapter.js CHANGED
@@ -24,13 +24,13 @@ const infer_content_type = (name) => {
24
24
 
25
25
 
26
26
  /**
27
- * @typedef {import('./types.public.js').ServiceFile} ServiceFile
28
- * @typedef {import('./types.public.js').Config} Config
27
+ * @typedef {import('./types.public.d.ts').ServiceFile} ServiceFile
28
+ * @typedef {import('./types.public.d.ts').Config} Config
29
29
  */
30
30
 
31
31
  /**
32
32
  * Google Storage
33
- * @typedef {import('@storecraft/core/v-storage').storage_driver} storage
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/v-storage').StorageFeatures} */
69
+ /** @type {import('@storecraft/core/storage').StorageFeatures} */
70
70
  const f = {
71
71
  supports_signed_urls: true
72
72
  }
@@ -273,8 +273,9 @@ export class GoogleStorage {
273
273
  }
274
274
  );
275
275
 
276
+ // console.log(await r.text())
277
+
276
278
  return r.ok;
277
- // console.log(r)
278
279
  }
279
280
  }
280
281
 
package/adapter.utils.js CHANGED
@@ -1,13 +1,13 @@
1
- import { base64, jwt } from '@storecraft/core/v-crypto';
1
+ import { base64, jwt } from '@storecraft/core/crypto';
2
2
 
3
3
  /**
4
4
  *
5
- * @param {import('./types.public.js').ServiceFile} sf Google service account json
5
+ * @param {import('./types.public.d.ts').ServiceFile} sf Google service account json
6
6
  * @param {string} [aud]
7
7
  * @returns
8
8
  */
9
9
  export async function getJWTFromServiceAccount(sf, aud=undefined) {
10
- /** @type {Partial<import('@storecraft/core/v-crypto').jwt.JWTClaims> & Record<string, string>} */
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',
@@ -1,11 +1,7 @@
1
1
  {
2
- "compileOnSave": false,
3
2
  "compilerOptions": {
4
- "noEmit": true,
5
- "allowJs": true,
6
3
  "checkJs": true,
7
4
  "target": "ESNext",
8
- "resolveJsonModule": true,
9
5
  "moduleResolution": "NodeNext",
10
6
  "module": "NodeNext",
11
7
  "composite": true,
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@storecraft/storage-google",
3
- "version": "1.0.0",
4
- "description": "Google Storage support",
3
+ "version": "1.0.2",
4
+ "description": "Official Google Storage adapter for storecraft",
5
5
  "license": "MIT",
6
6
  "author": "Tomer Shalev (https://github.com/store-craft)",
7
7
  "homepage": "https://github.com/store-craft/storecraft",
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",
@@ -21,8 +21,8 @@
21
21
  "storage-google:publish": "npm publish --access public"
22
22
  },
23
23
  "type": "module",
24
- "main": "index.js",
25
- "types": "./types.public.d.ts",
24
+ "main": "adapter.js",
25
+ "types": "types.public.d.ts",
26
26
  "dependencies": {
27
27
  "@storecraft/core": "^1.0.0"
28
28
  },
@@ -1,8 +1,9 @@
1
1
  import 'dotenv/config';
2
2
  import { test } from 'uvu';
3
3
  import * as assert from 'uvu/assert';
4
- import { GoogleStorage } from '../adapter.js'
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
- test.before(async () => { await storage.init(undefined) });
19
+ const suite = storage_test_runner.create(storage);
19
20
 
20
- test('blob put/get/delete', async () => {
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
- test('blob put (presign)', async () => {
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
- test.run();
88
+ suite.run();
package/types.public.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './index.js';
1
+ export { GoogleStorage } from './adapter.js';
2
2
 
3
3
  export type ServiceFile = {
4
4
  type?: string;
package/index.js DELETED
@@ -1 +0,0 @@
1
- export * from './adapter.js'