@twin.org/blob-storage-connector-gcp 0.0.1-next.8 → 0.0.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,145 @@
1
1
  # @twin.org/blob-storage-connector-gcp - Changelog
2
2
 
3
- ## v0.0.1-next.8
3
+ ## 0.0.1 (2025-07-04)
4
+
5
+
6
+ ### Features
7
+
8
+ * release to production ([eacfe75](https://github.com/twinfoundation/blob-storage/commit/eacfe754a0dcd9243d9e13d86422327d0a605164))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/blob-storage-models bumped from ^0.0.0 to ^0.0.1
16
+
17
+ ## [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)
18
+
19
+
20
+ ### Miscellaneous Chores
21
+
22
+ * **blob-storage-connector-gcp:** Synchronize repo versions
23
+
24
+
25
+ ### Dependencies
26
+
27
+ * The following workspace dependencies were updated
28
+ * dependencies
29
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.36 to 0.0.1-next.37
30
+
31
+ ## [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)
32
+
33
+
34
+ ### Miscellaneous Chores
35
+
36
+ * **blob-storage-connector-gcp:** Synchronize repo versions
37
+
38
+
39
+ ### Dependencies
40
+
41
+ * The following workspace dependencies were updated
42
+ * dependencies
43
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.35 to 0.0.1-next.36
44
+
45
+ ## [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)
46
+
47
+
48
+ ### Miscellaneous Chores
49
+
50
+ * **blob-storage-connector-gcp:** Synchronize repo versions
51
+
52
+
53
+ ### Dependencies
54
+
55
+ * The following workspace dependencies were updated
56
+ * dependencies
57
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.34 to 0.0.1-next.35
58
+
59
+ ## [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)
60
+
61
+
62
+ ### Features
63
+
64
+ * update dependencies ([56f0094](https://github.com/twinfoundation/blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
65
+
66
+
67
+ ### Dependencies
68
+
69
+ * The following workspace dependencies were updated
70
+ * dependencies
71
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.33 to 0.0.1-next.34
72
+
73
+ ## [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)
74
+
75
+
76
+ ### Miscellaneous Chores
77
+
78
+ * **blob-storage-connector-gcp:** Synchronize repo versions
79
+
80
+
81
+ ### Dependencies
82
+
83
+ * The following workspace dependencies were updated
84
+ * dependencies
85
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.32 to 0.0.1-next.33
86
+
87
+ ## [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)
88
+
89
+
90
+ ### Miscellaneous Chores
91
+
92
+ * **blob-storage-connector-gcp:** Synchronize repo versions
93
+
94
+
95
+ ### Dependencies
96
+
97
+ * The following workspace dependencies were updated
98
+ * dependencies
99
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.31 to 0.0.1-next.32
100
+
101
+ ## [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)
102
+
103
+
104
+ ### Miscellaneous Chores
105
+
106
+ * **blob-storage-connector-gcp:** Synchronize repo versions
107
+
108
+
109
+ ### Dependencies
110
+
111
+ * The following workspace dependencies were updated
112
+ * dependencies
113
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.30 to 0.0.1-next.31
114
+
115
+ ## [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)
116
+
117
+
118
+ ### Features
119
+
120
+ * use shared store mechanism ([#12](https://github.com/twinfoundation/blob-storage/issues/12)) ([cae8110](https://github.com/twinfoundation/blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
121
+
122
+
123
+ ### Dependencies
124
+
125
+ * The following workspace dependencies were updated
126
+ * dependencies
127
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.29 to 0.0.1-next.30
128
+
129
+ ## [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)
130
+
131
+
132
+ ### Features
133
+
134
+ * Add GCP blob storage connector ([#8](https://github.com/twinfoundation/blob-storage/issues/8)) ([4f6d579](https://github.com/twinfoundation/blob-storage/commit/4f6d579c01b3ae13ebcd9029b279da62e4fde859))
135
+
136
+
137
+ ### Dependencies
138
+
139
+ * The following workspace dependencies were updated
140
+ * dependencies
141
+ * @twin.org/blob-storage-models bumped from 0.0.1-next.28 to 0.0.1-next.29
142
+
143
+ ## v0.0.1-next.28
4
144
 
5
145
  - 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.8",
3
+ "version": "0.0.1",
4
4
  "description": "Blob Storage connector implementation using Google Cloud Storage",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,23 +14,24 @@
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.8",
19
- "@twin.org/core": "next",
20
- "@twin.org/crypto": "next",
21
- "@twin.org/nameof": "next",
22
- "@twin.org/web": "next"
17
+ "@google-cloud/storage": "7.16.0",
18
+ "@twin.org/blob-storage-models": "^0.0.1",
19
+ "@twin.org/core": "^0.0.1",
20
+ "@twin.org/crypto": "^0.0.1",
21
+ "@twin.org/logging-models": "^0.0.1",
22
+ "@twin.org/nameof": "^0.0.1",
23
+ "@twin.org/web": "^0.0.1"
23
24
  },
24
25
  "main": "./dist/cjs/index.cjs",
25
26
  "module": "./dist/esm/index.mjs",
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",