@twin.org/blob-storage-connector-aws-s3 0.0.1-next.9 → 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 clientS3 = require('@aws-sdk/client-s3');
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
 
7
8
  // Copyright 2024 IOTA Stiftung.
8
9
  // SPDX-License-Identifier: Apache-2.0.
@@ -32,7 +33,6 @@ class S3BlobStorageConnector {
32
33
  /**
33
34
  * Create a new instance of S3BlobStorageConnector.
34
35
  * @param options The options for the connector.
35
- * @param options.config The configuration for the connector.
36
36
  */
37
37
  constructor(options) {
38
38
  core.Guards.object(this.CLASS_NAME, "options", options);
@@ -52,6 +52,61 @@ class S3BlobStorageConnector {
52
52
  forcePathStyle: true
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 listBucketsCommand = new clientS3.ListBucketsCommand({});
72
+ const bucketsList = await this._s3Client.send(listBucketsCommand);
73
+ const bucketExists = bucketsList.Buckets?.some(bucket => bucket.Name === this._config.bucketName);
74
+ if (bucketExists) {
75
+ await nodeLogging?.log({
76
+ level: "info",
77
+ source: this.CLASS_NAME,
78
+ message: "bucketExists",
79
+ data: {
80
+ bucket: this._config.bucketName
81
+ }
82
+ });
83
+ }
84
+ else {
85
+ await this._s3Client.send(new clientS3.CreateBucketCommand({ Bucket: this._config.bucketName }));
86
+ await nodeLogging?.log({
87
+ level: "info",
88
+ source: this.CLASS_NAME,
89
+ message: "bucketCreated",
90
+ data: {
91
+ bucket: this._config.bucketName
92
+ }
93
+ });
94
+ }
95
+ }
96
+ catch (err) {
97
+ await nodeLogging?.log({
98
+ level: "error",
99
+ source: this.CLASS_NAME,
100
+ message: "bucketCreateFailed",
101
+ data: {
102
+ bucket: this._config.bucketName
103
+ },
104
+ error: core.BaseError.fromError(err)
105
+ });
106
+ return false;
107
+ }
108
+ return true;
109
+ }
55
110
  /**
56
111
  * Set the blob.
57
112
  * @param blob The data for the blob.
@@ -1,6 +1,7 @@
1
- import { S3Client, PutObjectCommand, GetObjectCommand, HeadObjectCommand, DeleteObjectCommand } from '@aws-sdk/client-s3';
2
- import { Guards, Converter, Urn, GeneralError, BaseError } from '@twin.org/core';
1
+ import { S3Client, ListBucketsCommand, CreateBucketCommand, PutObjectCommand, GetObjectCommand, HeadObjectCommand, DeleteObjectCommand } from '@aws-sdk/client-s3';
2
+ import { Guards, BaseError, Converter, Urn, GeneralError } from '@twin.org/core';
3
3
  import { Sha256 } from '@twin.org/crypto';
4
+ import { LoggingConnectorFactory } from '@twin.org/logging-models';
4
5
 
5
6
  // Copyright 2024 IOTA Stiftung.
6
7
  // SPDX-License-Identifier: Apache-2.0.
@@ -30,7 +31,6 @@ class S3BlobStorageConnector {
30
31
  /**
31
32
  * Create a new instance of S3BlobStorageConnector.
32
33
  * @param options The options for the connector.
33
- * @param options.config The configuration for the connector.
34
34
  */
35
35
  constructor(options) {
36
36
  Guards.object(this.CLASS_NAME, "options", options);
@@ -50,6 +50,61 @@ class S3BlobStorageConnector {
50
50
  forcePathStyle: true
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 listBucketsCommand = new ListBucketsCommand({});
70
+ const bucketsList = await this._s3Client.send(listBucketsCommand);
71
+ const bucketExists = bucketsList.Buckets?.some(bucket => bucket.Name === this._config.bucketName);
72
+ if (bucketExists) {
73
+ await nodeLogging?.log({
74
+ level: "info",
75
+ source: this.CLASS_NAME,
76
+ message: "bucketExists",
77
+ data: {
78
+ bucket: this._config.bucketName
79
+ }
80
+ });
81
+ }
82
+ else {
83
+ await this._s3Client.send(new CreateBucketCommand({ Bucket: this._config.bucketName }));
84
+ await nodeLogging?.log({
85
+ level: "info",
86
+ source: this.CLASS_NAME,
87
+ message: "bucketCreated",
88
+ data: {
89
+ bucket: this._config.bucketName
90
+ }
91
+ });
92
+ }
93
+ }
94
+ catch (err) {
95
+ await nodeLogging?.log({
96
+ level: "error",
97
+ source: this.CLASS_NAME,
98
+ message: "bucketCreateFailed",
99
+ data: {
100
+ bucket: this._config.bucketName
101
+ },
102
+ error: BaseError.fromError(err)
103
+ });
104
+ return false;
105
+ }
106
+ return true;
107
+ }
53
108
  /**
54
109
  * Set the blob.
55
110
  * @param blob The data for the blob.
@@ -1,2 +1,3 @@
1
1
  export * from "./s3BlobStorageConnector";
2
2
  export * from "./models/IS3BlobStorageConnectorConfig";
3
+ export * from "./models/IS3BlobStorageConnectorConstructorOptions";
@@ -0,0 +1,10 @@
1
+ import type { IS3BlobStorageConnectorConfig } from "./IS3BlobStorageConnectorConfig";
2
+ /**
3
+ * Options for the S3 Blob Storage Connector constructor.
4
+ */
5
+ export interface IS3BlobStorageConnectorConstructorOptions {
6
+ /**
7
+ * The configuration for the connector.
8
+ */
9
+ config: IS3BlobStorageConnectorConfig;
10
+ }
@@ -1,5 +1,5 @@
1
1
  import type { IBlobStorageConnector } from "@twin.org/blob-storage-models";
2
- import type { IS3BlobStorageConnectorConfig } from "./models/IS3BlobStorageConnectorConfig";
2
+ import type { IS3BlobStorageConnectorConstructorOptions } from "./models/IS3BlobStorageConnectorConstructorOptions";
3
3
  /**
4
4
  * Class for performing blob storage operations on S3.
5
5
  * See https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/ for more information.
@@ -16,11 +16,14 @@ export declare class S3BlobStorageConnector implements IBlobStorageConnector {
16
16
  /**
17
17
  * Create a new instance of S3BlobStorageConnector.
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: IS3BlobStorageConnectorConfig;
23
- });
20
+ constructor(options: IS3BlobStorageConnectorConstructorOptions);
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.
package/docs/changelog.md CHANGED
@@ -1,5 +1,145 @@
1
1
  # @twin.org/blob-storage-connector-aws-s3 - Changelog
2
2
 
3
- ## v0.0.1-next.9
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-aws-s3-v0.0.1-next.36...blob-storage-connector-aws-s3-v0.0.1-next.37) (2025-06-20)
18
+
19
+
20
+ ### Miscellaneous Chores
21
+
22
+ * **blob-storage-connector-aws-s3:** 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-aws-s3-v0.0.1-next.35...blob-storage-connector-aws-s3-v0.0.1-next.36) (2025-06-19)
32
+
33
+
34
+ ### Miscellaneous Chores
35
+
36
+ * **blob-storage-connector-aws-s3:** 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-aws-s3-v0.0.1-next.34...blob-storage-connector-aws-s3-v0.0.1-next.35) (2025-06-17)
46
+
47
+
48
+ ### Miscellaneous Chores
49
+
50
+ * **blob-storage-connector-aws-s3:** 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-aws-s3-v0.0.1-next.33...blob-storage-connector-aws-s3-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-aws-s3-v0.0.1-next.32...blob-storage-connector-aws-s3-v0.0.1-next.33) (2025-06-03)
74
+
75
+
76
+ ### Miscellaneous Chores
77
+
78
+ * **blob-storage-connector-aws-s3:** 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-aws-s3-v0.0.1-next.31...blob-storage-connector-aws-s3-v0.0.1-next.32) (2025-05-28)
88
+
89
+
90
+ ### Features
91
+
92
+ * update to support fully qualified data type names ([3297d69](https://github.com/twinfoundation/blob-storage/commit/3297d69d332058b0f0141002087f56ba230620e1))
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-aws-s3-v0.0.1-next.30...blob-storage-connector-aws-s3-v0.0.1-next.31) (2025-05-08)
102
+
103
+
104
+ ### Miscellaneous Chores
105
+
106
+ * **blob-storage-connector-aws-s3:** 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-aws-s3-v0.0.1-next.29...blob-storage-connector-aws-s3-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-aws-s3-v0.0.1-next.28...blob-storage-connector-aws-s3-v0.0.1-next.29) (2025-03-28)
130
+
131
+
132
+ ### Features
133
+
134
+ * Blob storage connector for AWS S3 ([#7](https://github.com/twinfoundation/blob-storage/issues/7)) ([1d7f1e7](https://github.com/twinfoundation/blob-storage/commit/1d7f1e7d323926f7f31229d38eb5de429f6e1554))
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://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/ for more i
9
9
 
10
10
  ## Constructors
11
11
 
12
- ### new S3BlobStorageConnector()
12
+ ### Constructor
13
13
 
14
- > **new S3BlobStorageConnector**(`options`): [`S3BlobStorageConnector`](S3BlobStorageConnector.md)
14
+ > **new S3BlobStorageConnector**(`options`): `S3BlobStorageConnector`
15
15
 
16
16
  Create a new instance of S3BlobStorageConnector.
17
17
 
18
18
  #### Parameters
19
19
 
20
- **options**
20
+ ##### options
21
21
 
22
- The options for the connector.
23
-
24
- • **options.config**: [`IS3BlobStorageConnectorConfig`](../interfaces/IS3BlobStorageConnectorConfig.md)
22
+ [`IS3BlobStorageConnectorConstructorOptions`](../interfaces/IS3BlobStorageConnectorConstructorOptions.md)
25
23
 
26
- The configuration for the connector.
24
+ The options for the connector.
27
25
 
28
26
  #### Returns
29
27
 
30
- [`S3BlobStorageConnector`](S3BlobStorageConnector.md)
28
+ `S3BlobStorageConnector`
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
  - [IS3BlobStorageConnectorConfig](interfaces/IS3BlobStorageConnectorConfig.md)
10
+ - [IS3BlobStorageConnectorConstructorOptions](interfaces/IS3BlobStorageConnectorConstructorOptions.md)
@@ -0,0 +1,11 @@
1
+ # Interface: IS3BlobStorageConnectorConstructorOptions
2
+
3
+ Options for the S3 Blob Storage Connector constructor.
4
+
5
+ ## Properties
6
+
7
+ ### config
8
+
9
+ > **config**: [`IS3BlobStorageConnectorConfig`](IS3BlobStorageConnectorConfig.md)
10
+
11
+ The configuration for the connector.
package/locales/en.json CHANGED
@@ -1,6 +1,14 @@
1
1
  {
2
+ "info": {
3
+ "s3BlobStorageConnector": {
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
  "s3BlobStorageConnector": {
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 S3",
6
14
  "setBlobFailed": "Failed to set blob in S3",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/blob-storage-connector-aws-s3",
3
- "version": "0.0.1-next.9",
3
+ "version": "0.0.1",
4
4
  "description": "Blob Storage connector implementation using AWS S3",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,22 +14,23 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@aws-sdk/client-s3": "^3.667.0",
18
- "@twin.org/blob-storage-models": "0.0.1-next.9",
19
- "@twin.org/core": "next",
20
- "@twin.org/crypto": "next",
21
- "@twin.org/nameof": "next"
17
+ "@aws-sdk/client-s3": "3.828.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"
22
23
  },
23
24
  "main": "./dist/cjs/index.cjs",
24
25
  "module": "./dist/esm/index.mjs",
25
26
  "types": "./dist/types/index.d.ts",
26
27
  "exports": {
27
28
  ".": {
29
+ "types": "./dist/types/index.d.ts",
28
30
  "require": "./dist/cjs/index.cjs",
29
- "import": "./dist/esm/index.mjs",
30
- "types": "./dist/types/index.d.ts"
31
+ "import": "./dist/esm/index.mjs"
31
32
  },
32
- "./locales": "./locales"
33
+ "./locales/*.json": "./locales/*.json"
33
34
  },
34
35
  "files": [
35
36
  "dist/cjs",