@twin.org/blob-storage-connector-gcp 0.0.1-next.9 → 0.0.2-next.1

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.
@@ -3,6 +3,7 @@
3
3
  var storage = require('@google-cloud/storage');
4
4
  var core = require('@twin.org/core');
5
5
  var crypto = require('@twin.org/crypto');
6
+ var loggingModels = require('@twin.org/logging-models');
6
7
  var web = require('@twin.org/web');
7
8
 
8
9
  // Copyright 2024 IOTA Stiftung.
@@ -33,7 +34,6 @@ class GcpBlobStorageConnector {
33
34
  /**
34
35
  * Create a new instance of GcpBlobStorageConnector.
35
36
  * @param options The options for the connector.
36
- * @param options.config The configuration for the connector.
37
37
  */
38
38
  constructor(options) {
39
39
  core.Guards.object(this.CLASS_NAME, "options", options);
@@ -52,6 +52,60 @@ class GcpBlobStorageConnector {
52
52
  credentials
53
53
  });
54
54
  }
55
+ /**
56
+ * Bootstrap the component by creating and initializing any resources it needs.
57
+ * @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
58
+ * @returns True if the bootstrapping process was successful.
59
+ */
60
+ async bootstrap(nodeLoggingConnectorType) {
61
+ const nodeLogging = loggingModels.LoggingConnectorFactory.getIfExists(nodeLoggingConnectorType ?? "node-logging");
62
+ try {
63
+ await nodeLogging?.log({
64
+ level: "info",
65
+ source: this.CLASS_NAME,
66
+ message: "bucketCreating",
67
+ data: {
68
+ bucket: this._config.bucketName
69
+ }
70
+ });
71
+ const [buckets] = await this._storage.getBuckets();
72
+ const bucketExists = buckets.some(bucket => bucket.name === this._config.bucketName);
73
+ if (bucketExists) {
74
+ await nodeLogging?.log({
75
+ level: "info",
76
+ source: this.CLASS_NAME,
77
+ message: "bucketExists",
78
+ data: {
79
+ bucket: this._config.bucketName
80
+ }
81
+ });
82
+ }
83
+ else {
84
+ await this._storage.createBucket(this._config.bucketName);
85
+ await nodeLogging?.log({
86
+ level: "info",
87
+ source: this.CLASS_NAME,
88
+ message: "bucketCreated",
89
+ data: {
90
+ bucket: this._config.bucketName
91
+ }
92
+ });
93
+ }
94
+ }
95
+ catch (err) {
96
+ await nodeLogging?.log({
97
+ level: "error",
98
+ source: this.CLASS_NAME,
99
+ message: "bucketCreateFailed",
100
+ data: {
101
+ bucket: this._config.bucketName
102
+ },
103
+ error: core.BaseError.fromError(err)
104
+ });
105
+ return false;
106
+ }
107
+ return true;
108
+ }
55
109
  /**
56
110
  * Set the blob.
57
111
  * @param blob The data for the blob.
@@ -1,6 +1,7 @@
1
1
  import { Storage } from '@google-cloud/storage';
2
- import { Guards, Is, ObjectHelper, Converter, Urn, GeneralError } from '@twin.org/core';
2
+ import { Guards, Is, ObjectHelper, Converter, BaseError, Urn, GeneralError } from '@twin.org/core';
3
3
  import { Sha256 } from '@twin.org/crypto';
4
+ import { LoggingConnectorFactory } from '@twin.org/logging-models';
4
5
  import { MimeTypes } from '@twin.org/web';
5
6
 
6
7
  // Copyright 2024 IOTA Stiftung.
@@ -31,7 +32,6 @@ class GcpBlobStorageConnector {
31
32
  /**
32
33
  * Create a new instance of GcpBlobStorageConnector.
33
34
  * @param options The options for the connector.
34
- * @param options.config The configuration for the connector.
35
35
  */
36
36
  constructor(options) {
37
37
  Guards.object(this.CLASS_NAME, "options", options);
@@ -50,6 +50,60 @@ class GcpBlobStorageConnector {
50
50
  credentials
51
51
  });
52
52
  }
53
+ /**
54
+ * Bootstrap the component by creating and initializing any resources it needs.
55
+ * @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
56
+ * @returns True if the bootstrapping process was successful.
57
+ */
58
+ async bootstrap(nodeLoggingConnectorType) {
59
+ const nodeLogging = LoggingConnectorFactory.getIfExists(nodeLoggingConnectorType ?? "node-logging");
60
+ try {
61
+ await nodeLogging?.log({
62
+ level: "info",
63
+ source: this.CLASS_NAME,
64
+ message: "bucketCreating",
65
+ data: {
66
+ bucket: this._config.bucketName
67
+ }
68
+ });
69
+ const [buckets] = await this._storage.getBuckets();
70
+ const bucketExists = buckets.some(bucket => bucket.name === this._config.bucketName);
71
+ if (bucketExists) {
72
+ await nodeLogging?.log({
73
+ level: "info",
74
+ source: this.CLASS_NAME,
75
+ message: "bucketExists",
76
+ data: {
77
+ bucket: this._config.bucketName
78
+ }
79
+ });
80
+ }
81
+ else {
82
+ await this._storage.createBucket(this._config.bucketName);
83
+ await nodeLogging?.log({
84
+ level: "info",
85
+ source: this.CLASS_NAME,
86
+ message: "bucketCreated",
87
+ data: {
88
+ bucket: this._config.bucketName
89
+ }
90
+ });
91
+ }
92
+ }
93
+ catch (err) {
94
+ await nodeLogging?.log({
95
+ level: "error",
96
+ source: this.CLASS_NAME,
97
+ message: "bucketCreateFailed",
98
+ data: {
99
+ bucket: this._config.bucketName
100
+ },
101
+ error: BaseError.fromError(err)
102
+ });
103
+ return false;
104
+ }
105
+ return true;
106
+ }
53
107
  /**
54
108
  * Set the blob.
55
109
  * @param blob The data for the blob.
@@ -1,5 +1,5 @@
1
1
  import type { IBlobStorageConnector } from "@twin.org/blob-storage-models";
2
- import type { IGcpBlobStorageConnectorConfig } from "./models/IGcpBlobStorageConnectorConfig";
2
+ import type { IGcpBlobStorageConnectorConstructorOptions } from "./models/IGcpBlobStorageConnectorConstructorOptions";
3
3
  /**
4
4
  * Class for performing blob storage operations on GCP Storage.
5
5
  * See https://cloud.google.com/storage/docs/reference/libraries for more information.
@@ -16,11 +16,14 @@ export declare class GcpBlobStorageConnector implements IBlobStorageConnector {
16
16
  /**
17
17
  * Create a new instance of GcpBlobStorageConnector.
18
18
  * @param options The options for the connector.
19
- * @param options.config The configuration for the connector.
20
19
  */
21
- constructor(options: {
22
- config: IGcpBlobStorageConnectorConfig;
23
- });
20
+ constructor(options: IGcpBlobStorageConnectorConstructorOptions);
21
+ /**
22
+ * Bootstrap the component by creating and initializing any resources it needs.
23
+ * @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
24
+ * @returns True if the bootstrapping process was successful.
25
+ */
26
+ bootstrap(nodeLoggingConnectorType?: string): Promise<boolean>;
24
27
  /**
25
28
  * Set the blob.
26
29
  * @param blob The data for the blob.
@@ -1,2 +1,3 @@
1
1
  export * from "./gcpBlobStorageConnector";
2
2
  export * from "./models/IGcpBlobStorageConnectorConfig";
3
+ export * from "./models/IGcpBlobStorageConnectorConstructorOptions";
@@ -0,0 +1,10 @@
1
+ import type { IGcpBlobStorageConnectorConfig } from "./IGcpBlobStorageConnectorConfig";
2
+ /**
3
+ * Options for the GCP Blob Storage Connector constructor.
4
+ */
5
+ export interface IGcpBlobStorageConnectorConstructorOptions {
6
+ /**
7
+ * The configuration for the connector.
8
+ */
9
+ config: IGcpBlobStorageConnectorConfig;
10
+ }
package/docs/changelog.md CHANGED
@@ -1,5 +1,161 @@
1
1
  # @twin.org/blob-storage-connector-gcp - Changelog
2
2
 
3
- ## v0.0.1-next.9
3
+ ## [0.0.2-next.1](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-gcp-v0.0.2-next.0...blob-storage-connector-gcp-v0.0.2-next.1) (2025-07-24)
4
+
5
+
6
+ ### Features
7
+
8
+ * Add GCP blob storage connector ([#8](https://github.com/twinfoundation/blob-storage/issues/8)) ([4f6d579](https://github.com/twinfoundation/blob-storage/commit/4f6d579c01b3ae13ebcd9029b279da62e4fde859))
9
+ * update dependencies ([56f0094](https://github.com/twinfoundation/blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
10
+ * use shared store mechanism ([#12](https://github.com/twinfoundation/blob-storage/issues/12)) ([cae8110](https://github.com/twinfoundation/blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
11
+
12
+
13
+ ### Dependencies
14
+
15
+ * The following workspace dependencies were updated
16
+ * dependencies
17
+ * @twin.org/blob-storage-models bumped from 0.0.2-next.0 to 0.0.2-next.1
18
+
19
+ ## 0.0.1 (2025-07-04)
20
+
21
+
22
+ ### Features
23
+
24
+ * release to production ([eacfe75](https://github.com/twinfoundation/blob-storage/commit/eacfe754a0dcd9243d9e13d86422327d0a605164))
25
+
26
+
27
+ ### Dependencies
28
+
29
+ * The following workspace dependencies were updated
30
+ * dependencies
31
+ * @twin.org/blob-storage-models bumped from ^0.0.0 to ^0.0.1
32
+
33
+ ## [0.0.1-next.37](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-gcp-v0.0.1-next.36...blob-storage-connector-gcp-v0.0.1-next.37) (2025-06-20)
34
+
35
+
36
+ ### Miscellaneous Chores
37
+
38
+ * **blob-storage-connector-gcp:** Synchronize repo versions
39
+
40
+
41
+ ### Dependencies
42
+
43
+ * The following workspace dependencies were updated
44
+ * dependencies
45
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.36 to 0.0.1-next.37
46
+
47
+ ## [0.0.1-next.36](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-gcp-v0.0.1-next.35...blob-storage-connector-gcp-v0.0.1-next.36) (2025-06-19)
48
+
49
+
50
+ ### Miscellaneous Chores
51
+
52
+ * **blob-storage-connector-gcp:** Synchronize repo versions
53
+
54
+
55
+ ### Dependencies
56
+
57
+ * The following workspace dependencies were updated
58
+ * dependencies
59
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.35 to 0.0.1-next.36
60
+
61
+ ## [0.0.1-next.35](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-gcp-v0.0.1-next.34...blob-storage-connector-gcp-v0.0.1-next.35) (2025-06-17)
62
+
63
+
64
+ ### Miscellaneous Chores
65
+
66
+ * **blob-storage-connector-gcp:** Synchronize repo versions
67
+
68
+
69
+ ### Dependencies
70
+
71
+ * The following workspace dependencies were updated
72
+ * dependencies
73
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.34 to 0.0.1-next.35
74
+
75
+ ## [0.0.1-next.34](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-gcp-v0.0.1-next.33...blob-storage-connector-gcp-v0.0.1-next.34) (2025-06-12)
76
+
77
+
78
+ ### Features
79
+
80
+ * update dependencies ([56f0094](https://github.com/twinfoundation/blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
81
+
82
+
83
+ ### Dependencies
84
+
85
+ * The following workspace dependencies were updated
86
+ * dependencies
87
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.33 to 0.0.1-next.34
88
+
89
+ ## [0.0.1-next.33](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-gcp-v0.0.1-next.32...blob-storage-connector-gcp-v0.0.1-next.33) (2025-06-03)
90
+
91
+
92
+ ### Miscellaneous Chores
93
+
94
+ * **blob-storage-connector-gcp:** Synchronize repo versions
95
+
96
+
97
+ ### Dependencies
98
+
99
+ * The following workspace dependencies were updated
100
+ * dependencies
101
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.32 to 0.0.1-next.33
102
+
103
+ ## [0.0.1-next.32](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-gcp-v0.0.1-next.31...blob-storage-connector-gcp-v0.0.1-next.32) (2025-05-28)
104
+
105
+
106
+ ### Miscellaneous Chores
107
+
108
+ * **blob-storage-connector-gcp:** Synchronize repo versions
109
+
110
+
111
+ ### Dependencies
112
+
113
+ * The following workspace dependencies were updated
114
+ * dependencies
115
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.31 to 0.0.1-next.32
116
+
117
+ ## [0.0.1-next.31](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-gcp-v0.0.1-next.30...blob-storage-connector-gcp-v0.0.1-next.31) (2025-05-08)
118
+
119
+
120
+ ### Miscellaneous Chores
121
+
122
+ * **blob-storage-connector-gcp:** Synchronize repo versions
123
+
124
+
125
+ ### Dependencies
126
+
127
+ * The following workspace dependencies were updated
128
+ * dependencies
129
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.30 to 0.0.1-next.31
130
+
131
+ ## [0.0.1-next.30](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-gcp-v0.0.1-next.29...blob-storage-connector-gcp-v0.0.1-next.30) (2025-04-17)
132
+
133
+
134
+ ### Features
135
+
136
+ * use shared store mechanism ([#12](https://github.com/twinfoundation/blob-storage/issues/12)) ([cae8110](https://github.com/twinfoundation/blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
137
+
138
+
139
+ ### Dependencies
140
+
141
+ * The following workspace dependencies were updated
142
+ * dependencies
143
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.29 to 0.0.1-next.30
144
+
145
+ ## [0.0.1-next.29](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-gcp-v0.0.1-next.28...blob-storage-connector-gcp-v0.0.1-next.29) (2025-03-28)
146
+
147
+
148
+ ### Features
149
+
150
+ * Add GCP blob storage connector ([#8](https://github.com/twinfoundation/blob-storage/issues/8)) ([4f6d579](https://github.com/twinfoundation/blob-storage/commit/4f6d579c01b3ae13ebcd9029b279da62e4fde859))
151
+
152
+
153
+ ### Dependencies
154
+
155
+ * The following workspace dependencies were updated
156
+ * dependencies
157
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.28 to 0.0.1-next.29
158
+
159
+ ## v0.0.1-next.28
4
160
 
5
161
  - Initial Release
@@ -9,25 +9,23 @@ See https://cloud.google.com/storage/docs/reference/libraries for more informati
9
9
 
10
10
  ## Constructors
11
11
 
12
- ### new GcpBlobStorageConnector()
12
+ ### Constructor
13
13
 
14
- > **new GcpBlobStorageConnector**(`options`): [`GcpBlobStorageConnector`](GcpBlobStorageConnector.md)
14
+ > **new GcpBlobStorageConnector**(`options`): `GcpBlobStorageConnector`
15
15
 
16
16
  Create a new instance of GcpBlobStorageConnector.
17
17
 
18
18
  #### Parameters
19
19
 
20
- **options**
20
+ ##### options
21
21
 
22
- The options for the connector.
23
-
24
- • **options.config**: [`IGcpBlobStorageConnectorConfig`](../interfaces/IGcpBlobStorageConnectorConfig.md)
22
+ [`IGcpBlobStorageConnectorConstructorOptions`](../interfaces/IGcpBlobStorageConnectorConstructorOptions.md)
25
23
 
26
- The configuration for the connector.
24
+ The options for the connector.
27
25
 
28
26
  #### Returns
29
27
 
30
- [`GcpBlobStorageConnector`](GcpBlobStorageConnector.md)
28
+ `GcpBlobStorageConnector`
31
29
 
32
30
  ## Properties
33
31
 
@@ -51,6 +49,32 @@ Runtime name for the class.
51
49
 
52
50
  ## Methods
53
51
 
52
+ ### bootstrap()
53
+
54
+ > **bootstrap**(`nodeLoggingConnectorType?`): `Promise`\<`boolean`\>
55
+
56
+ Bootstrap the component by creating and initializing any resources it needs.
57
+
58
+ #### Parameters
59
+
60
+ ##### nodeLoggingConnectorType?
61
+
62
+ `string`
63
+
64
+ The node logging connector type, defaults to "node-logging".
65
+
66
+ #### Returns
67
+
68
+ `Promise`\<`boolean`\>
69
+
70
+ True if the bootstrapping process was successful.
71
+
72
+ #### Implementation of
73
+
74
+ `IBlobStorageConnector.bootstrap`
75
+
76
+ ***
77
+
54
78
  ### set()
55
79
 
56
80
  > **set**(`blob`): `Promise`\<`string`\>
@@ -59,7 +83,9 @@ Set the blob.
59
83
 
60
84
  #### Parameters
61
85
 
62
- **blob**: `Uint8Array`
86
+ ##### blob
87
+
88
+ `Uint8Array`
63
89
 
64
90
  The data for the blob.
65
91
 
@@ -77,19 +103,21 @@ The id of the stored blob in urn format.
77
103
 
78
104
  ### get()
79
105
 
80
- > **get**(`id`): `Promise`\<`undefined` \| `Uint8Array`\>
106
+ > **get**(`id`): `Promise`\<`undefined` \| `Uint8Array`\<`ArrayBufferLike`\>\>
81
107
 
82
108
  Get the blob.
83
109
 
84
110
  #### Parameters
85
111
 
86
- **id**: `string`
112
+ ##### id
113
+
114
+ `string`
87
115
 
88
116
  The id of the blob to get in urn format.
89
117
 
90
118
  #### Returns
91
119
 
92
- `Promise`\<`undefined` \| `Uint8Array`\>
120
+ `Promise`\<`undefined` \| `Uint8Array`\<`ArrayBufferLike`\>\>
93
121
 
94
122
  The data for the blob if it can be found or undefined.
95
123
 
@@ -107,7 +135,9 @@ Remove the blob.
107
135
 
108
136
  #### Parameters
109
137
 
110
- **id**: `string`
138
+ ##### id
139
+
140
+ `string`
111
141
 
112
142
  The id of the blob to remove in urn format.
113
143
 
@@ -7,3 +7,4 @@
7
7
  ## Interfaces
8
8
 
9
9
  - [IGcpBlobStorageConnectorConfig](interfaces/IGcpBlobStorageConnectorConfig.md)
10
+ - [IGcpBlobStorageConnectorConstructorOptions](interfaces/IGcpBlobStorageConnectorConstructorOptions.md)
@@ -0,0 +1,11 @@
1
+ # Interface: IGcpBlobStorageConnectorConstructorOptions
2
+
3
+ Options for the GCP Blob Storage Connector constructor.
4
+
5
+ ## Properties
6
+
7
+ ### config
8
+
9
+ > **config**: [`IGcpBlobStorageConnectorConfig`](IGcpBlobStorageConnectorConfig.md)
10
+
11
+ The configuration for the connector.
package/locales/en.json CHANGED
@@ -1,6 +1,14 @@
1
1
  {
2
+ "info": {
3
+ "gcpBlobStorageConnector": {
4
+ "bucketCreating": "Creating bucket \"{bucket}\"",
5
+ "bucketCreated": "Created bucket \"{bucket}\"",
6
+ "bucketExists": "Skipping create bucket \"{bucket}\" as it already exists"
7
+ }
8
+ },
2
9
  "error": {
3
10
  "gcpBlobStorageConnector": {
11
+ "bucketCreateFailed": "Creating bucket \"{bucket}\" failed",
4
12
  "namespaceMismatch": "The namespace in the urn \"{id}\" does not match the namespace of the blob storage \"{namespace}\"",
5
13
  "getBlobFailed": "Failed to get blob in GCP",
6
14
  "setBlobFailed": "Failed to set blob in GCP",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/blob-storage-connector-gcp",
3
- "version": "0.0.1-next.9",
3
+ "version": "0.0.2-next.1",
4
4
  "description": "Blob Storage connector implementation using Google Cloud Storage",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,10 +14,11 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@google-cloud/storage": "^7.13.0",
18
- "@twin.org/blob-storage-models": "0.0.1-next.9",
17
+ "@google-cloud/storage": "7.16.0",
18
+ "@twin.org/blob-storage-models": "0.0.2-next.1",
19
19
  "@twin.org/core": "next",
20
20
  "@twin.org/crypto": "next",
21
+ "@twin.org/logging-models": "next",
21
22
  "@twin.org/nameof": "next",
22
23
  "@twin.org/web": "next"
23
24
  },
@@ -26,11 +27,11 @@
26
27
  "types": "./dist/types/index.d.ts",
27
28
  "exports": {
28
29
  ".": {
30
+ "types": "./dist/types/index.d.ts",
29
31
  "require": "./dist/cjs/index.cjs",
30
- "import": "./dist/esm/index.mjs",
31
- "types": "./dist/types/index.d.ts"
32
+ "import": "./dist/esm/index.mjs"
32
33
  },
33
- "./locales": "./locales"
34
+ "./locales/*.json": "./locales/*.json"
34
35
  },
35
36
  "files": [
36
37
  "dist/cjs",