@twin.org/blob-storage-connector-ipfs 0.0.2-next.5 → 0.0.3-next.10

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,6 +1,6 @@
1
1
  # TWIN Blob Storage Connector IPFS
2
2
 
3
- Blob Storage connector implementation using [IPFS](https://ipfs.tech/).
3
+ This package integrates blob workflows with [IPFS](https://ipfs.tech/) for decentralised, content-addressed storage and retrieval. It supports distributed scenarios where immutable content addressing is important.
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,18 +8,12 @@ Blob Storage connector implementation using [IPFS](https://ipfs.tech/).
8
8
  npm install @twin.org/blob-storage-connector-ipfs
9
9
  ```
10
10
 
11
- ## Testing
11
+ ## Docker
12
12
 
13
- The tests developed are functional tests and need an instance of IPFS up and running. To run IPFS locally:
13
+ To perform testing of this component it may be necessary to launch a local instance to communicate with.
14
14
 
15
15
  ```shell
16
- docker run -p 4001:4001 -p 4001:4001/udp -p 8080:8080 -p 5001:5001 --name twin-blob-ipfs --hostname ipfs -d ipfs/kubo:latest
17
- ```
18
-
19
- Afterwards you can run the tests as follows:
20
-
21
- ```shell
22
- npm run test
16
+ docker run -d --name twin-blob-storage-ipfs -p 4001:4001 -p 4001:4001/udp -p 8080:8080 -p 5001:5001 ipfs/kubo:latest
23
17
  ```
24
18
 
25
19
  ## Examples
@@ -0,0 +1,6 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export * from "./ipfsBlobStorageConnector.js";
4
+ export * from "./models/IIpfsBlobStorageConnectorConfig.js";
5
+ export * from "./models/IIpfsBlobStorageConnectorConstructorOptions.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6CAA6C,CAAC;AAC5D,cAAc,yDAAyD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./ipfsBlobStorageConnector.js\";\nexport * from \"./models/IIpfsBlobStorageConnectorConfig.js\";\nexport * from \"./models/IIpfsBlobStorageConnectorConstructorOptions.js\";\n"]}
@@ -1,11 +1,10 @@
1
- import { Guards, StringHelper, Urn, GeneralError, Is } from '@twin.org/core';
2
- import { MimeTypes, HeaderTypes, HeaderHelper } from '@twin.org/web';
3
-
1
+ import { GeneralError, Guards, HealthStatus, Is, StringHelper, Urn } from "@twin.org/core";
2
+ import { HeaderHelper, HeaderTypes, HttpMethod, MimeTypes } from "@twin.org/web";
4
3
  /**
5
4
  * Class for performing blob storage operations on IPFS.
6
5
  * See https://docs.ipfs.tech/reference/kubo/rpc/ for more information.
7
6
  */
8
- class IpfsBlobStorageConnector {
7
+ export class IpfsBlobStorageConnector {
9
8
  /**
10
9
  * The namespace for the items.
11
10
  */
@@ -19,6 +18,11 @@ class IpfsBlobStorageConnector {
19
18
  * @internal
20
19
  */
21
20
  _config;
21
+ /**
22
+ * The keys to use from the context ids to create partitions.
23
+ * @internal
24
+ */
25
+ _partitionContextIds;
22
26
  /**
23
27
  * Create a new instance of IpfsBlobStorageConnector.
24
28
  * @param options The options for the connector.
@@ -28,8 +32,56 @@ class IpfsBlobStorageConnector {
28
32
  Guards.object(IpfsBlobStorageConnector.CLASS_NAME, "options.config", options.config);
29
33
  Guards.stringValue(IpfsBlobStorageConnector.CLASS_NAME, "options.config.apiUrl", options.config.apiUrl);
30
34
  this._config = options.config;
35
+ this._partitionContextIds = options.partitionContextIds;
31
36
  this._config.apiUrl = StringHelper.trimTrailingSlashes(this._config.apiUrl);
32
37
  }
38
+ /**
39
+ * Returns the class name of the component.
40
+ * @returns The class name of the component.
41
+ */
42
+ className() {
43
+ return IpfsBlobStorageConnector.CLASS_NAME;
44
+ }
45
+ /**
46
+ * Returns the health status of the component.
47
+ * @returns The health status of the component.
48
+ */
49
+ async health() {
50
+ try {
51
+ const fetchOptions = {
52
+ method: HttpMethod.POST,
53
+ headers: {
54
+ accept: MimeTypes.Json
55
+ }
56
+ };
57
+ this.addSecurity(fetchOptions);
58
+ const response = await fetch(`${this._config.apiUrl}/version`, fetchOptions);
59
+ if (response.ok) {
60
+ return [
61
+ {
62
+ source: IpfsBlobStorageConnector.CLASS_NAME,
63
+ status: HealthStatus.Ok,
64
+ description: "healthDescription",
65
+ data: {
66
+ apiUrl: this._config.apiUrl
67
+ }
68
+ }
69
+ ];
70
+ }
71
+ }
72
+ catch { }
73
+ return [
74
+ {
75
+ source: IpfsBlobStorageConnector.CLASS_NAME,
76
+ status: HealthStatus.Error,
77
+ description: "healthDescription",
78
+ message: "healthCheckFailed",
79
+ data: {
80
+ apiUrl: this._config.apiUrl
81
+ }
82
+ }
83
+ ];
84
+ }
33
85
  /**
34
86
  * Set the blob.
35
87
  * @param blob The data for the blob.
@@ -42,7 +94,7 @@ class IpfsBlobStorageConnector {
42
94
  const formData = new FormData();
43
95
  formData.append("file", formBlob);
44
96
  const fetchOptions = {
45
- method: "POST",
97
+ method: HttpMethod.POST,
46
98
  body: formData,
47
99
  headers: {
48
100
  [HeaderTypes.Accept]: MimeTypes.Json,
@@ -78,12 +130,21 @@ class IpfsBlobStorageConnector {
78
130
  }
79
131
  try {
80
132
  const fetchOptions = {
81
- method: "POST",
133
+ method: HttpMethod.POST,
82
134
  headers: {
83
135
  accept: MimeTypes.Json
84
136
  }
85
137
  };
86
138
  this.addSecurity(fetchOptions);
139
+ const responseStat = await fetch(`${this._config.apiUrl}/block/stat?arg=${urnParsed.namespaceSpecific(1)}&local=true`, fetchOptions);
140
+ if (!responseStat.ok) {
141
+ const resp = await responseStat.json();
142
+ if (Is.object(resp) &&
143
+ Is.stringValue(resp.Message) &&
144
+ resp.Message.includes("not found")) {
145
+ return;
146
+ }
147
+ }
87
148
  const response = await fetch(`${this._config.apiUrl}/cat?arg=${urnParsed.namespaceSpecific(1)}`, fetchOptions);
88
149
  if (response.ok) {
89
150
  const result = await response.arrayBuffer();
@@ -112,7 +173,7 @@ class IpfsBlobStorageConnector {
112
173
  }
113
174
  try {
114
175
  const fetchOptions = {
115
- method: "POST",
176
+ method: HttpMethod.POST,
116
177
  headers: {
117
178
  accept: MimeTypes.Json
118
179
  }
@@ -143,5 +204,4 @@ class IpfsBlobStorageConnector {
143
204
  }
144
205
  }
145
206
  }
146
-
147
- export { IpfsBlobStorageConnector };
207
+ //# sourceMappingURL=ipfsBlobStorageConnector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ipfsBlobStorageConnector.js","sourceRoot":"","sources":["../../src/ipfsBlobStorageConnector.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,YAAY,EACZ,MAAM,EACN,YAAY,EACZ,EAAE,EACF,YAAY,EACZ,GAAG,EAEH,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAIjF;;;GAGG;AACH,MAAM,OAAO,wBAAwB;IACpC;;OAEG;IACI,MAAM,CAAU,SAAS,GAAW,MAAM,CAAC;IAElD;;OAEG;IACI,MAAM,CAAU,UAAU,8BAA8C;IAE/E;;;OAGG;IACc,OAAO,CAAkC;IAE1D;;;OAGG;IACc,oBAAoB,CAAY;IAEjD;;;OAGG;IACH,YAAY,OAAoD;QAC/D,MAAM,CAAC,MAAM,CAAC,wBAAwB,CAAC,UAAU,aAAmB,OAAO,CAAC,CAAC;QAC7E,MAAM,CAAC,MAAM,CACZ,wBAAwB,CAAC,UAAU,oBAEnC,OAAO,CAAC,MAAM,CACd,CAAC;QACF,MAAM,CAAC,WAAW,CACjB,wBAAwB,CAAC,UAAU,2BAEnC,OAAO,CAAC,MAAM,CAAC,MAAM,CACrB,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9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AC3B,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,eAAe,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,EACrE,YAAY,CACZ,CAAC;YAEF,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,OAAO,IAAI,CAAC;YACb,CAAC;YAED,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACpC,MAAM,IAAI,YAAY,CAAC,wBAAwB,CAAC,UAAU,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;QACjF,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,MAAM,IAAI,YAAY,CACrB,wBAAwB,CAAC,UAAU,EACnC,kBAAkB,EAClB,SAAS,EACT,GAAG,CACH,CAAC;QACH,CAAC;IACF,CAAC;IAED;;;;OAIG;IACK,WAAW,CAAC,WAAwB;QAC3C,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;YAC9C,WAAW,CAAC,OAAO,GAAG;gBACrB,GAAG,WAAW,CAAC,OAAO;gBACtB,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;aAChF,CAAC;QACH,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IBlobStorageConnector } from \"@twin.org/blob-storage-models\";\nimport {\n\tGeneralError,\n\tGuards,\n\tHealthStatus,\n\tIs,\n\tStringHelper,\n\tUrn,\n\ttype IHealth\n} from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HeaderHelper, HeaderTypes, HttpMethod, MimeTypes } from \"@twin.org/web\";\nimport type { IIpfsBlobStorageConnectorConfig } from \"./models/IIpfsBlobStorageConnectorConfig.js\";\nimport type { IIpfsBlobStorageConnectorConstructorOptions } from \"./models/IIpfsBlobStorageConnectorConstructorOptions.js\";\n\n/**\n * Class for performing blob storage operations on IPFS.\n * See https://docs.ipfs.tech/reference/kubo/rpc/ for more information.\n */\nexport class IpfsBlobStorageConnector implements IBlobStorageConnector {\n\t/**\n\t * The namespace for the items.\n\t */\n\tpublic static readonly NAMESPACE: string = \"ipfs\";\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<IpfsBlobStorageConnector>();\n\n\t/**\n\t * The configuration for the connector.\n\t * @internal\n\t */\n\tprivate readonly _config: IIpfsBlobStorageConnectorConfig;\n\n\t/**\n\t * The keys to use from the context ids to create partitions.\n\t * @internal\n\t */\n\tprivate readonly _partitionContextIds?: string[];\n\n\t/**\n\t * Create a new instance of IpfsBlobStorageConnector.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options: IIpfsBlobStorageConnectorConstructorOptions) {\n\t\tGuards.object(IpfsBlobStorageConnector.CLASS_NAME, nameof(options), options);\n\t\tGuards.object<IIpfsBlobStorageConnectorConfig>(\n\t\t\tIpfsBlobStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config),\n\t\t\toptions.config\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tIpfsBlobStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.apiUrl),\n\t\t\toptions.config.apiUrl\n\t\t);\n\n\t\tthis._config = options.config;\n\t\tthis._partitionContextIds = options.partitionContextIds;\n\t\tthis._config.apiUrl = StringHelper.trimTrailingSlashes(this._config.apiUrl);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn IpfsBlobStorageConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Returns the health status of the component.\n\t * @returns The health status of the component.\n\t */\n\tpublic async health(): Promise<IHealth[]> {\n\t\ttry {\n\t\t\tconst fetchOptions: RequestInit = {\n\t\t\t\tmethod: HttpMethod.POST,\n\t\t\t\theaders: {\n\t\t\t\t\taccept: MimeTypes.Json\n\t\t\t\t}\n\t\t\t};\n\t\t\tthis.addSecurity(fetchOptions);\n\t\t\tconst response = await fetch(`${this._config.apiUrl}/version`, fetchOptions);\n\t\t\tif (response.ok) {\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\tsource: IpfsBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\t\tstatus: HealthStatus.Ok,\n\t\t\t\t\t\tdescription: \"healthDescription\",\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\tapiUrl: this._config.apiUrl\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t];\n\t\t\t}\n\t\t} catch {}\n\t\treturn [\n\t\t\t{\n\t\t\t\tsource: IpfsBlobStorageConnector.CLASS_NAME,\n\t\t\t\tstatus: HealthStatus.Error,\n\t\t\t\tdescription: \"healthDescription\",\n\t\t\t\tmessage: \"healthCheckFailed\",\n\t\t\t\tdata: {\n\t\t\t\t\tapiUrl: this._config.apiUrl\n\t\t\t\t}\n\t\t\t}\n\t\t];\n\t}\n\n\t/**\n\t * Set the blob.\n\t * @param blob The data for the blob.\n\t * @returns The id of the stored blob in urn format.\n\t */\n\tpublic async set(blob: Uint8Array): Promise<string> {\n\t\tGuards.uint8Array(IpfsBlobStorageConnector.CLASS_NAME, nameof(blob), blob);\n\n\t\ttry {\n\t\t\tconst formBlob = new Blob([new Uint8Array(blob)], { type: MimeTypes.OctetStream });\n\t\t\tconst formData = new FormData();\n\t\t\tformData.append(\"file\", formBlob);\n\n\t\t\tconst fetchOptions: RequestInit = {\n\t\t\t\tmethod: HttpMethod.POST,\n\t\t\t\tbody: formData,\n\t\t\t\theaders: {\n\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.Json,\n\t\t\t\t\t[HeaderTypes.ContentDisposition]: \"form-data\"\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tthis.addSecurity(fetchOptions);\n\n\t\t\tconst response = await fetch(`${this._config.apiUrl}/add?pin=true`, fetchOptions);\n\n\t\t\tif (response.ok) {\n\t\t\t\tconst result = (await response.json()) as {\n\t\t\t\t\tName: string;\n\t\t\t\t\tHash: string;\n\t\t\t\t\tSize: string;\n\t\t\t\t};\n\n\t\t\t\treturn `blob:${new Urn(IpfsBlobStorageConnector.NAMESPACE, result.Hash).toString()}`;\n\t\t\t}\n\n\t\t\tconst error = await response.json();\n\t\t\tthrow new GeneralError(IpfsBlobStorageConnector.CLASS_NAME, \"fetchFail\", error);\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(IpfsBlobStorageConnector.CLASS_NAME, \"setBlobFailed\", undefined, err);\n\t\t}\n\t}\n\n\t/**\n\t * Get the blob.\n\t * @param id The id of the blob to get in urn format.\n\t * @returns The data for the blob if it can be found or undefined.\n\t */\n\tpublic async get(id: string): Promise<Uint8Array | undefined> {\n\t\tUrn.guard(IpfsBlobStorageConnector.CLASS_NAME, nameof(id), id);\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tif (urnParsed.namespaceMethod() !== IpfsBlobStorageConnector.NAMESPACE) {\n\t\t\tthrow new GeneralError(IpfsBlobStorageConnector.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: IpfsBlobStorageConnector.NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst fetchOptions: RequestInit = {\n\t\t\t\tmethod: HttpMethod.POST,\n\t\t\t\theaders: {\n\t\t\t\t\taccept: MimeTypes.Json\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tthis.addSecurity(fetchOptions);\n\n\t\t\tconst responseStat = await fetch(\n\t\t\t\t`${this._config.apiUrl}/block/stat?arg=${urnParsed.namespaceSpecific(1)}&local=true`,\n\t\t\t\tfetchOptions\n\t\t\t);\n\n\t\t\tif (!responseStat.ok) {\n\t\t\t\tconst resp = await responseStat.json();\n\t\t\t\tif (\n\t\t\t\t\tIs.object<{ Message: string }>(resp) &&\n\t\t\t\t\tIs.stringValue(resp.Message) &&\n\t\t\t\t\tresp.Message.includes(\"not found\")\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst response = await fetch(\n\t\t\t\t`${this._config.apiUrl}/cat?arg=${urnParsed.namespaceSpecific(1)}`,\n\t\t\t\tfetchOptions\n\t\t\t);\n\n\t\t\tif (response.ok) {\n\t\t\t\tconst result = await response.arrayBuffer();\n\t\t\t\treturn new Uint8Array(result);\n\t\t\t}\n\n\t\t\tconst error = await response.json();\n\t\t\tthrow new GeneralError(IpfsBlobStorageConnector.CLASS_NAME, \"fetchFail\", error);\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(IpfsBlobStorageConnector.CLASS_NAME, \"getBlobFailed\", undefined, err);\n\t\t}\n\t}\n\n\t/**\n\t * Remove the blob.\n\t * @param id The id of the blob to remove in urn format.\n\t * @returns True if the blob was found.\n\t */\n\tpublic async remove(id: string): Promise<boolean> {\n\t\tUrn.guard(IpfsBlobStorageConnector.CLASS_NAME, nameof(id), id);\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tif (urnParsed.namespaceMethod() !== IpfsBlobStorageConnector.NAMESPACE) {\n\t\t\tthrow new GeneralError(IpfsBlobStorageConnector.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: IpfsBlobStorageConnector.NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst fetchOptions: RequestInit = {\n\t\t\t\tmethod: HttpMethod.POST,\n\t\t\t\theaders: {\n\t\t\t\t\taccept: MimeTypes.Json\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tthis.addSecurity(fetchOptions);\n\n\t\t\tconst response = await fetch(\n\t\t\t\t`${this._config.apiUrl}/pin/rm?arg=${urnParsed.namespaceSpecific(1)}`,\n\t\t\t\tfetchOptions\n\t\t\t);\n\n\t\t\tif (response.ok) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tconst error = await response.json();\n\t\t\tthrow new GeneralError(IpfsBlobStorageConnector.CLASS_NAME, \"fetchFail\", error);\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIpfsBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\"removeBlobFailed\",\n\t\t\t\tundefined,\n\t\t\t\terr\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Add the security to the request.\n\t * @param requestInit The request options.\n\t * @internal\n\t */\n\tprivate addSecurity(requestInit: RequestInit): void {\n\t\tif (Is.stringValue(this._config.bearerToken)) {\n\t\t\trequestInit.headers = {\n\t\t\t\t...requestInit.headers,\n\t\t\t\t[HeaderTypes.Authorization]: HeaderHelper.createBearer(this._config.bearerToken)\n\t\t\t};\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=IIpfsBlobStorageConnectorConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IIpfsBlobStorageConnectorConfig.js","sourceRoot":"","sources":["../../../src/models/IIpfsBlobStorageConnectorConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for the IPFS Blob Storage Connector.\n */\nexport interface IIpfsBlobStorageConnectorConfig {\n\t/**\n\t * The url for API calls.\n\t */\n\tapiUrl: string;\n\n\t/**\n\t * The bearer token for authentication to the API.\n\t */\n\tbearerToken?: string;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IIpfsBlobStorageConnectorConstructorOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IIpfsBlobStorageConnectorConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IIpfsBlobStorageConnectorConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IIpfsBlobStorageConnectorConfig } from \"./IIpfsBlobStorageConnectorConfig.js\";\n\n/**\n * Options for the IPFS Blob Storage Connector constructor.\n */\nexport interface IIpfsBlobStorageConnectorConstructorOptions {\n\t/**\n\t * The keys to use from the context ids to create partitions.\n\t */\n\tpartitionContextIds?: string[];\n\n\t/**\n\t * The configuration for the connector.\n\t */\n\tconfig: IIpfsBlobStorageConnectorConfig;\n}\n"]}
@@ -1,3 +1,3 @@
1
- export * from "./ipfsBlobStorageConnector";
2
- export * from "./models/IIpfsBlobStorageConnectorConfig";
3
- export * from "./models/IIpfsBlobStorageConnectorConstructorOptions";
1
+ export * from "./ipfsBlobStorageConnector.js";
2
+ export * from "./models/IIpfsBlobStorageConnectorConfig.js";
3
+ export * from "./models/IIpfsBlobStorageConnectorConstructorOptions.js";
@@ -1,5 +1,6 @@
1
1
  import type { IBlobStorageConnector } from "@twin.org/blob-storage-models";
2
- import type { IIpfsBlobStorageConnectorConstructorOptions } from "./models/IIpfsBlobStorageConnectorConstructorOptions";
2
+ import { type IHealth } from "@twin.org/core";
3
+ import type { IIpfsBlobStorageConnectorConstructorOptions } from "./models/IIpfsBlobStorageConnectorConstructorOptions.js";
3
4
  /**
4
5
  * Class for performing blob storage operations on IPFS.
5
6
  * See https://docs.ipfs.tech/reference/kubo/rpc/ for more information.
@@ -18,6 +19,16 @@ export declare class IpfsBlobStorageConnector implements IBlobStorageConnector {
18
19
  * @param options The options for the connector.
19
20
  */
20
21
  constructor(options: IIpfsBlobStorageConnectorConstructorOptions);
22
+ /**
23
+ * Returns the class name of the component.
24
+ * @returns The class name of the component.
25
+ */
26
+ className(): string;
27
+ /**
28
+ * Returns the health status of the component.
29
+ * @returns The health status of the component.
30
+ */
31
+ health(): Promise<IHealth[]>;
21
32
  /**
22
33
  * Set the blob.
23
34
  * @param blob The data for the blob.
@@ -1,8 +1,12 @@
1
- import type { IIpfsBlobStorageConnectorConfig } from "./IIpfsBlobStorageConnectorConfig";
1
+ import type { IIpfsBlobStorageConnectorConfig } from "./IIpfsBlobStorageConnectorConfig.js";
2
2
  /**
3
3
  * Options for the IPFS Blob Storage Connector constructor.
4
4
  */
5
5
  export interface IIpfsBlobStorageConnectorConstructorOptions {
6
+ /**
7
+ * The keys to use from the context ids to create partitions.
8
+ */
9
+ partitionContextIds?: string[];
6
10
  /**
7
11
  * The configuration for the connector.
8
12
  */
package/docs/changelog.md CHANGED
@@ -1,11 +1,174 @@
1
- # @twin.org/blob-storage-connector-ipfs - Changelog
1
+ # Changelog
2
2
 
3
- ## [0.0.2-next.5](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-ipfs-v0.0.2-next.4...blob-storage-connector-ipfs-v0.0.2-next.5) (2025-10-09)
3
+ ## [0.0.3-next.10](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.3-next.9...blob-storage-connector-ipfs-v0.0.3-next.10) (2026-05-07)
4
4
 
5
5
 
6
6
  ### Features
7
7
 
8
- * add validate-locales ([f20fcec](https://github.com/twinfoundation/blob-storage/commit/f20fceced91e39a0c9edb770b2e43ce944c92f3c))
8
+ * additional information in health ([1ef83be](https://github.com/iotaledger/twin-blob-storage/commit/1ef83bef81148489b7950d5131a2af5121910e99))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/blob-storage-models bumped from 0.0.3-next.9 to 0.0.3-next.10
16
+
17
+ ## [0.0.3-next.9](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.3-next.8...blob-storage-connector-ipfs-v0.0.3-next.9) (2026-05-07)
18
+
19
+
20
+ ### Features
21
+
22
+ * add context id features ([#30](https://github.com/iotaledger/twin-blob-storage/issues/30)) ([fbf1c92](https://github.com/iotaledger/twin-blob-storage/commit/fbf1c9276424c841ef5ef3f4de8469ab3fba7e9c))
23
+ * add validate-locales ([f20fcec](https://github.com/iotaledger/twin-blob-storage/commit/f20fceced91e39a0c9edb770b2e43ce944c92f3c))
24
+ * eslint migration to flat config ([e4239dd](https://github.com/iotaledger/twin-blob-storage/commit/e4239dd1c721955cff7f0357255d2bba15319972))
25
+ * health checks ([#44](https://github.com/iotaledger/twin-blob-storage/issues/44)) ([4a4041c](https://github.com/iotaledger/twin-blob-storage/commit/4a4041c19b68c40ed1aba6d1cdb4318ac4208b7d))
26
+ * update dependencies ([56f0094](https://github.com/iotaledger/twin-blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
27
+ * update framework core ([ff339fe](https://github.com/iotaledger/twin-blob-storage/commit/ff339fe7e3f09ddff429907834bdf43617e9c05e))
28
+ * update health fetch ([6c86b51](https://github.com/iotaledger/twin-blob-storage/commit/6c86b51c2a034f680ccf290514dcb47e2ef91057))
29
+ * use new createBearer method ([f87c550](https://github.com/iotaledger/twin-blob-storage/commit/f87c5502fe3b5fee81257d7500f5d4500ea5ed28))
30
+ * use new createBearer method ([a965801](https://github.com/iotaledger/twin-blob-storage/commit/a96580160315c363fc0f06a1615cc92d4339a5e4))
31
+ * use shared store mechanism ([#12](https://github.com/iotaledger/twin-blob-storage/issues/12)) ([cae8110](https://github.com/iotaledger/twin-blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
32
+
33
+
34
+ ### Bug Fixes
35
+
36
+ * missing dependency ([868717b](https://github.com/iotaledger/twin-blob-storage/commit/868717b9d352af916c32df4d4f942d3bd8769c95))
37
+ * missing dependency ([9b7ec26](https://github.com/iotaledger/twin-blob-storage/commit/9b7ec2694468e75b4d3357b623e5031def82c920))
38
+
39
+
40
+ ### Dependencies
41
+
42
+ * The following workspace dependencies were updated
43
+ * dependencies
44
+ * @twin.org/blob-storage-models bumped from 0.0.3-next.8 to 0.0.3-next.9
45
+
46
+ ## [0.0.3-next.8](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.3-next.7...blob-storage-connector-ipfs-v0.0.3-next.8) (2026-05-07)
47
+
48
+
49
+ ### Features
50
+
51
+ * health checks ([#44](https://github.com/iotaledger/twin-blob-storage/issues/44)) ([4a4041c](https://github.com/iotaledger/twin-blob-storage/commit/4a4041c19b68c40ed1aba6d1cdb4318ac4208b7d))
52
+
53
+
54
+ ### Dependencies
55
+
56
+ * The following workspace dependencies were updated
57
+ * dependencies
58
+ * @twin.org/blob-storage-models bumped from 0.0.3-next.7 to 0.0.3-next.8
59
+
60
+ ## [0.0.3-next.7](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.3-next.6...blob-storage-connector-ipfs-v0.0.3-next.7) (2026-02-25)
61
+
62
+
63
+ ### Miscellaneous Chores
64
+
65
+ * **blob-storage-connector-ipfs:** Synchronize repo versions
66
+
67
+
68
+ ### Dependencies
69
+
70
+ * The following workspace dependencies were updated
71
+ * dependencies
72
+ * @twin.org/blob-storage-models bumped from 0.0.3-next.6 to 0.0.3-next.7
73
+
74
+ ## [0.0.3-next.6](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.3-next.5...blob-storage-connector-ipfs-v0.0.3-next.6) (2026-02-09)
75
+
76
+
77
+ ### Miscellaneous Chores
78
+
79
+ * **blob-storage-connector-ipfs:** Synchronize repo versions
80
+
81
+
82
+ ### Dependencies
83
+
84
+ * The following workspace dependencies were updated
85
+ * dependencies
86
+ * @twin.org/blob-storage-models bumped from 0.0.3-next.5 to 0.0.3-next.6
87
+
88
+ ## [0.0.3-next.5](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.3-next.4...blob-storage-connector-ipfs-v0.0.3-next.5) (2026-01-26)
89
+
90
+
91
+ ### Miscellaneous Chores
92
+
93
+ * **blob-storage-connector-ipfs:** Synchronize repo versions
94
+
95
+
96
+ ### Dependencies
97
+
98
+ * The following workspace dependencies were updated
99
+ * dependencies
100
+ * @twin.org/blob-storage-models bumped from 0.0.3-next.4 to 0.0.3-next.5
101
+
102
+ ## [0.0.3-next.4](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.3-next.3...blob-storage-connector-ipfs-v0.0.3-next.4) (2026-01-23)
103
+
104
+
105
+ ### Miscellaneous Chores
106
+
107
+ * **blob-storage-connector-ipfs:** Synchronize repo versions
108
+
109
+
110
+ ### Dependencies
111
+
112
+ * The following workspace dependencies were updated
113
+ * dependencies
114
+ * @twin.org/blob-storage-models bumped from 0.0.3-next.3 to 0.0.3-next.4
115
+
116
+ ## [0.0.3-next.3](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.3-next.2...blob-storage-connector-ipfs-v0.0.3-next.3) (2026-01-21)
117
+
118
+
119
+ ### Miscellaneous Chores
120
+
121
+ * **blob-storage-connector-ipfs:** Synchronize repo versions
122
+
123
+
124
+ ### Dependencies
125
+
126
+ * The following workspace dependencies were updated
127
+ * dependencies
128
+ * @twin.org/blob-storage-models bumped from 0.0.3-next.2 to 0.0.3-next.3
129
+
130
+ ## [0.0.3-next.2](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.3-next.1...blob-storage-connector-ipfs-v0.0.3-next.2) (2026-01-14)
131
+
132
+
133
+ ### Bug Fixes
134
+
135
+ * missing dependency ([868717b](https://github.com/iotaledger/twin-blob-storage/commit/868717b9d352af916c32df4d4f942d3bd8769c95))
136
+ * missing dependency ([9b7ec26](https://github.com/iotaledger/twin-blob-storage/commit/9b7ec2694468e75b4d3357b623e5031def82c920))
137
+
138
+
139
+ ### Dependencies
140
+
141
+ * The following workspace dependencies were updated
142
+ * dependencies
143
+ * @twin.org/blob-storage-models bumped from 0.0.3-next.1 to 0.0.3-next.2
144
+
145
+ ## [0.0.3-next.1](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.3-next.0...blob-storage-connector-ipfs-v0.0.3-next.1) (2025-11-11)
146
+
147
+
148
+ ### Features
149
+
150
+ * add context id features ([#30](https://github.com/iotaledger/twin-blob-storage/issues/30)) ([fbf1c92](https://github.com/iotaledger/twin-blob-storage/commit/fbf1c9276424c841ef5ef3f4de8469ab3fba7e9c))
151
+ * add validate-locales ([f20fcec](https://github.com/iotaledger/twin-blob-storage/commit/f20fceced91e39a0c9edb770b2e43ce944c92f3c))
152
+ * eslint migration to flat config ([e4239dd](https://github.com/iotaledger/twin-blob-storage/commit/e4239dd1c721955cff7f0357255d2bba15319972))
153
+ * update dependencies ([56f0094](https://github.com/iotaledger/twin-blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
154
+ * update framework core ([ff339fe](https://github.com/iotaledger/twin-blob-storage/commit/ff339fe7e3f09ddff429907834bdf43617e9c05e))
155
+ * use new createBearer method ([f87c550](https://github.com/iotaledger/twin-blob-storage/commit/f87c5502fe3b5fee81257d7500f5d4500ea5ed28))
156
+ * use new createBearer method ([a965801](https://github.com/iotaledger/twin-blob-storage/commit/a96580160315c363fc0f06a1615cc92d4339a5e4))
157
+ * use shared store mechanism ([#12](https://github.com/iotaledger/twin-blob-storage/issues/12)) ([cae8110](https://github.com/iotaledger/twin-blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
158
+
159
+
160
+ ### Dependencies
161
+
162
+ * The following workspace dependencies were updated
163
+ * dependencies
164
+ * @twin.org/blob-storage-models bumped from 0.0.3-next.0 to 0.0.3-next.1
165
+
166
+ ## [0.0.2-next.5](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.2-next.4...blob-storage-connector-ipfs-v0.0.2-next.5) (2025-10-09)
167
+
168
+
169
+ ### Features
170
+
171
+ * add validate-locales ([f20fcec](https://github.com/iotaledger/twin-blob-storage/commit/f20fceced91e39a0c9edb770b2e43ce944c92f3c))
9
172
 
10
173
 
11
174
  ### Dependencies
@@ -14,13 +177,13 @@
14
177
  * dependencies
15
178
  * @twin.org/blob-storage-models bumped from 0.0.2-next.4 to 0.0.2-next.5
16
179
 
17
- ## [0.0.2-next.4](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-ipfs-v0.0.2-next.3...blob-storage-connector-ipfs-v0.0.2-next.4) (2025-10-02)
180
+ ## [0.0.2-next.4](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.2-next.3...blob-storage-connector-ipfs-v0.0.2-next.4) (2025-10-02)
18
181
 
19
182
 
20
183
  ### Features
21
184
 
22
- * use new createBearer method ([f87c550](https://github.com/twinfoundation/blob-storage/commit/f87c5502fe3b5fee81257d7500f5d4500ea5ed28))
23
- * use new createBearer method ([a965801](https://github.com/twinfoundation/blob-storage/commit/a96580160315c363fc0f06a1615cc92d4339a5e4))
185
+ * use new createBearer method ([f87c550](https://github.com/iotaledger/twin-blob-storage/commit/f87c5502fe3b5fee81257d7500f5d4500ea5ed28))
186
+ * use new createBearer method ([a965801](https://github.com/iotaledger/twin-blob-storage/commit/a96580160315c363fc0f06a1615cc92d4339a5e4))
24
187
 
25
188
 
26
189
  ### Dependencies
@@ -29,12 +192,12 @@
29
192
  * dependencies
30
193
  * @twin.org/blob-storage-models bumped from 0.0.2-next.3 to 0.0.2-next.4
31
194
 
32
- ## [0.0.2-next.3](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-ipfs-v0.0.2-next.2...blob-storage-connector-ipfs-v0.0.2-next.3) (2025-08-29)
195
+ ## [0.0.2-next.3](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.2-next.2...blob-storage-connector-ipfs-v0.0.2-next.3) (2025-08-29)
33
196
 
34
197
 
35
198
  ### Features
36
199
 
37
- * eslint migration to flat config ([e4239dd](https://github.com/twinfoundation/blob-storage/commit/e4239dd1c721955cff7f0357255d2bba15319972))
200
+ * eslint migration to flat config ([e4239dd](https://github.com/iotaledger/twin-blob-storage/commit/e4239dd1c721955cff7f0357255d2bba15319972))
38
201
 
39
202
 
40
203
  ### Dependencies
@@ -43,12 +206,12 @@
43
206
  * dependencies
44
207
  * @twin.org/blob-storage-models bumped from 0.0.2-next.2 to 0.0.2-next.3
45
208
 
46
- ## [0.0.2-next.2](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-ipfs-v0.0.2-next.1...blob-storage-connector-ipfs-v0.0.2-next.2) (2025-08-20)
209
+ ## [0.0.2-next.2](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.2-next.1...blob-storage-connector-ipfs-v0.0.2-next.2) (2025-08-20)
47
210
 
48
211
 
49
212
  ### Features
50
213
 
51
- * update framework core ([ff339fe](https://github.com/twinfoundation/blob-storage/commit/ff339fe7e3f09ddff429907834bdf43617e9c05e))
214
+ * update framework core ([ff339fe](https://github.com/iotaledger/twin-blob-storage/commit/ff339fe7e3f09ddff429907834bdf43617e9c05e))
52
215
 
53
216
 
54
217
  ### Dependencies
@@ -57,13 +220,13 @@
57
220
  * dependencies
58
221
  * @twin.org/blob-storage-models bumped from 0.0.2-next.1 to 0.0.2-next.2
59
222
 
60
- ## [0.0.2-next.1](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-ipfs-v0.0.2-next.0...blob-storage-connector-ipfs-v0.0.2-next.1) (2025-07-24)
223
+ ## [0.0.2-next.1](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.2-next.0...blob-storage-connector-ipfs-v0.0.2-next.1) (2025-07-24)
61
224
 
62
225
 
63
226
  ### Features
64
227
 
65
- * update dependencies ([56f0094](https://github.com/twinfoundation/blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
66
- * use shared store mechanism ([#12](https://github.com/twinfoundation/blob-storage/issues/12)) ([cae8110](https://github.com/twinfoundation/blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
228
+ * update dependencies ([56f0094](https://github.com/iotaledger/twin-blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
229
+ * use shared store mechanism ([#12](https://github.com/iotaledger/twin-blob-storage/issues/12)) ([cae8110](https://github.com/iotaledger/twin-blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
67
230
 
68
231
 
69
232
  ### Dependencies
@@ -77,7 +240,7 @@
77
240
 
78
241
  ### Features
79
242
 
80
- * release to production ([eacfe75](https://github.com/twinfoundation/blob-storage/commit/eacfe754a0dcd9243d9e13d86422327d0a605164))
243
+ * release to production ([eacfe75](https://github.com/iotaledger/twin-blob-storage/commit/eacfe754a0dcd9243d9e13d86422327d0a605164))
81
244
 
82
245
 
83
246
  ### Dependencies
@@ -86,7 +249,7 @@
86
249
  * dependencies
87
250
  * @twin.org/blob-storage-models bumped from ^0.0.0 to ^0.0.1
88
251
 
89
- ## [0.0.1-next.37](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.36...blob-storage-connector-ipfs-v0.0.1-next.37) (2025-06-20)
252
+ ## [0.0.1-next.37](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.36...blob-storage-connector-ipfs-v0.0.1-next.37) (2025-06-20)
90
253
 
91
254
 
92
255
  ### Miscellaneous Chores
@@ -100,7 +263,7 @@
100
263
  * dependencies
101
264
  * @twin.org/blob-storage-models bumped from 0.0.1-next.36 to 0.0.1-next.37
102
265
 
103
- ## [0.0.1-next.36](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.35...blob-storage-connector-ipfs-v0.0.1-next.36) (2025-06-19)
266
+ ## [0.0.1-next.36](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.35...blob-storage-connector-ipfs-v0.0.1-next.36) (2025-06-19)
104
267
 
105
268
 
106
269
  ### Miscellaneous Chores
@@ -114,7 +277,7 @@
114
277
  * dependencies
115
278
  * @twin.org/blob-storage-models bumped from 0.0.1-next.35 to 0.0.1-next.36
116
279
 
117
- ## [0.0.1-next.35](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.34...blob-storage-connector-ipfs-v0.0.1-next.35) (2025-06-17)
280
+ ## [0.0.1-next.35](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.34...blob-storage-connector-ipfs-v0.0.1-next.35) (2025-06-17)
118
281
 
119
282
 
120
283
  ### Miscellaneous Chores
@@ -128,12 +291,12 @@
128
291
  * dependencies
129
292
  * @twin.org/blob-storage-models bumped from 0.0.1-next.34 to 0.0.1-next.35
130
293
 
131
- ## [0.0.1-next.34](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.33...blob-storage-connector-ipfs-v0.0.1-next.34) (2025-06-12)
294
+ ## [0.0.1-next.34](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.33...blob-storage-connector-ipfs-v0.0.1-next.34) (2025-06-12)
132
295
 
133
296
 
134
297
  ### Features
135
298
 
136
- * update dependencies ([56f0094](https://github.com/twinfoundation/blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
299
+ * update dependencies ([56f0094](https://github.com/iotaledger/twin-blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
137
300
 
138
301
 
139
302
  ### Dependencies
@@ -142,7 +305,7 @@
142
305
  * dependencies
143
306
  * @twin.org/blob-storage-models bumped from 0.0.1-next.33 to 0.0.1-next.34
144
307
 
145
- ## [0.0.1-next.33](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.32...blob-storage-connector-ipfs-v0.0.1-next.33) (2025-06-03)
308
+ ## [0.0.1-next.33](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.32...blob-storage-connector-ipfs-v0.0.1-next.33) (2025-06-03)
146
309
 
147
310
 
148
311
  ### Miscellaneous Chores
@@ -156,7 +319,7 @@
156
319
  * dependencies
157
320
  * @twin.org/blob-storage-models bumped from 0.0.1-next.32 to 0.0.1-next.33
158
321
 
159
- ## [0.0.1-next.32](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.31...blob-storage-connector-ipfs-v0.0.1-next.32) (2025-05-28)
322
+ ## [0.0.1-next.32](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.31...blob-storage-connector-ipfs-v0.0.1-next.32) (2025-05-28)
160
323
 
161
324
 
162
325
  ### Miscellaneous Chores
@@ -170,7 +333,7 @@
170
333
  * dependencies
171
334
  * @twin.org/blob-storage-models bumped from 0.0.1-next.31 to 0.0.1-next.32
172
335
 
173
- ## [0.0.1-next.31](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.30...blob-storage-connector-ipfs-v0.0.1-next.31) (2025-05-08)
336
+ ## [0.0.1-next.31](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.30...blob-storage-connector-ipfs-v0.0.1-next.31) (2025-05-08)
174
337
 
175
338
 
176
339
  ### Miscellaneous Chores
@@ -184,12 +347,12 @@
184
347
  * dependencies
185
348
  * @twin.org/blob-storage-models bumped from 0.0.1-next.30 to 0.0.1-next.31
186
349
 
187
- ## [0.0.1-next.30](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.29...blob-storage-connector-ipfs-v0.0.1-next.30) (2025-04-17)
350
+ ## [0.0.1-next.30](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.29...blob-storage-connector-ipfs-v0.0.1-next.30) (2025-04-17)
188
351
 
189
352
 
190
353
  ### Features
191
354
 
192
- * use shared store mechanism ([#12](https://github.com/twinfoundation/blob-storage/issues/12)) ([cae8110](https://github.com/twinfoundation/blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
355
+ * use shared store mechanism ([#12](https://github.com/iotaledger/twin-blob-storage/issues/12)) ([cae8110](https://github.com/iotaledger/twin-blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
193
356
 
194
357
 
195
358
  ### Dependencies
@@ -198,7 +361,7 @@
198
361
  * dependencies
199
362
  * @twin.org/blob-storage-models bumped from 0.0.1-next.29 to 0.0.1-next.30
200
363
 
201
- ## [0.0.1-next.29](https://github.com/twinfoundation/blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.28...blob-storage-connector-ipfs-v0.0.1-next.29) (2025-03-28)
364
+ ## [0.0.1-next.29](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-ipfs-v0.0.1-next.28...blob-storage-connector-ipfs-v0.0.1-next.29) (2025-03-28)
202
365
 
203
366
 
204
367
  ### Miscellaneous Chores
package/docs/examples.md CHANGED
@@ -1 +1,39 @@
1
- # @twin.org/blob-storage-connector-ipfs - Examples
1
+ # IPFS Connector Examples
2
+
3
+ Use these snippets to pin content, read it back by identifier, and remove it when it is no longer required.
4
+
5
+ ## IpfsBlobStorageConnector
6
+
7
+ ```typescript
8
+ import { IpfsBlobStorageConnector } from '@twin.org/blob-storage-connector-ipfs';
9
+
10
+ const connector = new IpfsBlobStorageConnector({
11
+ config: {
12
+ apiUrl: 'http://127.0.0.1:5001/api/v0',
13
+ bearerToken: 'dev-access-token'
14
+ }
15
+ });
16
+
17
+ console.log(connector.className()); // IpfsBlobStorageConnector
18
+ ```
19
+
20
+ ```typescript
21
+ import { Converter } from '@twin.org/core';
22
+ import { IpfsBlobStorageConnector } from '@twin.org/blob-storage-connector-ipfs';
23
+
24
+ const connector = new IpfsBlobStorageConnector({
25
+ config: {
26
+ apiUrl: 'http://127.0.0.1:5001/api/v0'
27
+ }
28
+ });
29
+
30
+ const blobData = Converter.utf8ToBytes('IPFS payload');
31
+ const blobId = await connector.set(blobData);
32
+ console.log(blobId); // blob:urn:blob:ipfs:...
33
+
34
+ const storedBlob = await connector.get(blobId);
35
+ console.log(storedBlob?.length); // 12
36
+
37
+ const removed = await connector.remove(blobId);
38
+ console.log(removed); // true
39
+ ```
@@ -29,7 +29,7 @@ The options for the connector.
29
29
 
30
30
  ## Properties
31
31
 
32
- ### NAMESPACE
32
+ ### NAMESPACE {#namespace}
33
33
 
34
34
  > `readonly` `static` **NAMESPACE**: `string` = `"ipfs"`
35
35
 
@@ -37,7 +37,7 @@ The namespace for the items.
37
37
 
38
38
  ***
39
39
 
40
- ### CLASS\_NAME
40
+ ### CLASS\_NAME {#class_name}
41
41
 
42
42
  > `readonly` `static` **CLASS\_NAME**: `string`
43
43
 
@@ -45,7 +45,43 @@ Runtime name for the class.
45
45
 
46
46
  ## Methods
47
47
 
48
- ### set()
48
+ ### className() {#classname}
49
+
50
+ > **className**(): `string`
51
+
52
+ Returns the class name of the component.
53
+
54
+ #### Returns
55
+
56
+ `string`
57
+
58
+ The class name of the component.
59
+
60
+ #### Implementation of
61
+
62
+ `IBlobStorageConnector.className`
63
+
64
+ ***
65
+
66
+ ### health() {#health}
67
+
68
+ > **health**(): `Promise`\<`IHealth`[]\>
69
+
70
+ Returns the health status of the component.
71
+
72
+ #### Returns
73
+
74
+ `Promise`\<`IHealth`[]\>
75
+
76
+ The health status of the component.
77
+
78
+ #### Implementation of
79
+
80
+ `IBlobStorageConnector.health`
81
+
82
+ ***
83
+
84
+ ### set() {#set}
49
85
 
50
86
  > **set**(`blob`): `Promise`\<`string`\>
51
87
 
@@ -71,9 +107,9 @@ The id of the stored blob in urn format.
71
107
 
72
108
  ***
73
109
 
74
- ### get()
110
+ ### get() {#get}
75
111
 
76
- > **get**(`id`): `Promise`\<`undefined` \| `Uint8Array`\<`ArrayBufferLike`\>\>
112
+ > **get**(`id`): `Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`\>
77
113
 
78
114
  Get the blob.
79
115
 
@@ -87,7 +123,7 @@ The id of the blob to get in urn format.
87
123
 
88
124
  #### Returns
89
125
 
90
- `Promise`\<`undefined` \| `Uint8Array`\<`ArrayBufferLike`\>\>
126
+ `Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`\>
91
127
 
92
128
  The data for the blob if it can be found or undefined.
93
129
 
@@ -97,7 +133,7 @@ The data for the blob if it can be found or undefined.
97
133
 
98
134
  ***
99
135
 
100
- ### remove()
136
+ ### remove() {#remove}
101
137
 
102
138
  > **remove**(`id`): `Promise`\<`boolean`\>
103
139
 
@@ -4,7 +4,7 @@ Configuration for the IPFS Blob Storage Connector.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### apiUrl
7
+ ### apiUrl {#apiurl}
8
8
 
9
9
  > **apiUrl**: `string`
10
10
 
@@ -12,8 +12,8 @@ The url for API calls.
12
12
 
13
13
  ***
14
14
 
15
- ### bearerToken?
15
+ ### bearerToken? {#bearertoken}
16
16
 
17
- > `optional` **bearerToken**: `string`
17
+ > `optional` **bearerToken?**: `string`
18
18
 
19
19
  The bearer token for authentication to the API.
@@ -4,7 +4,15 @@ Options for the IPFS Blob Storage Connector constructor.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### config
7
+ ### partitionContextIds? {#partitioncontextids}
8
+
9
+ > `optional` **partitionContextIds?**: `string`[]
10
+
11
+ The keys to use from the context ids to create partitions.
12
+
13
+ ***
14
+
15
+ ### config {#config}
8
16
 
9
17
  > **config**: [`IIpfsBlobStorageConnectorConfig`](IIpfsBlobStorageConnectorConfig.md)
10
18
 
package/locales/en.json CHANGED
@@ -1,4 +1,10 @@
1
1
  {
2
+ "health": {
3
+ "ipfsBlobStorageConnector": {
4
+ "healthDescription": "IPFS blob storage connector is healthy, connected to \"{apiUrl}\"",
5
+ "healthCheckFailed": "Failed to connect to IPFS node at \"{apiUrl}\""
6
+ }
7
+ },
2
8
  "error": {
3
9
  "ipfsBlobStorageConnector": {
4
10
  "namespaceMismatch": "The namespace in the urn \"{id}\" does not match the namespace of the blob storage \"{namespace}\"",
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/blob-storage-connector-ipfs",
3
- "version": "0.0.2-next.5",
4
- "description": "Blob Storage connector implementation using IPFS",
3
+ "version": "0.0.3-next.10",
4
+ "description": "Stores and retrieves blobs through IPFS for content-addressed and distributed workflows.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/twinfoundation/blob-storage.git",
7
+ "url": "git+https://github.com/iotaledger/blob-storage.git",
8
8
  "directory": "packages/blob-storage-connector-ipfs"
9
9
  },
10
10
  "author": "martyn.janes@iota.org",
@@ -14,26 +14,24 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/blob-storage-models": "0.0.2-next.5",
17
+ "@twin.org/blob-storage-models": "0.0.3-next.10",
18
18
  "@twin.org/core": "next",
19
19
  "@twin.org/crypto": "next",
20
20
  "@twin.org/nameof": "next",
21
21
  "@twin.org/web": "next"
22
22
  },
23
- "main": "./dist/cjs/index.cjs",
24
- "module": "./dist/esm/index.mjs",
23
+ "main": "./dist/es/index.js",
25
24
  "types": "./dist/types/index.d.ts",
26
25
  "exports": {
27
26
  ".": {
28
27
  "types": "./dist/types/index.d.ts",
29
- "require": "./dist/cjs/index.cjs",
30
- "import": "./dist/esm/index.mjs"
28
+ "import": "./dist/es/index.js",
29
+ "default": "./dist/es/index.js"
31
30
  },
32
31
  "./locales/*.json": "./locales/*.json"
33
32
  },
34
33
  "files": [
35
- "dist/cjs",
36
- "dist/esm",
34
+ "dist/es",
37
35
  "dist/types",
38
36
  "locales",
39
37
  "docs"
@@ -54,7 +52,7 @@
54
52
  "integration"
55
53
  ],
56
54
  "bugs": {
57
- "url": "git+https://github.com/twinfoundation/blob-storage/issues"
55
+ "url": "git+https://github.com/iotaledger/blob-storage/issues"
58
56
  },
59
57
  "homepage": "https://twindev.org"
60
58
  }
@@ -1,149 +0,0 @@
1
- 'use strict';
2
-
3
- var core = require('@twin.org/core');
4
- var web = require('@twin.org/web');
5
-
6
- /**
7
- * Class for performing blob storage operations on IPFS.
8
- * See https://docs.ipfs.tech/reference/kubo/rpc/ for more information.
9
- */
10
- class IpfsBlobStorageConnector {
11
- /**
12
- * The namespace for the items.
13
- */
14
- static NAMESPACE = "ipfs";
15
- /**
16
- * Runtime name for the class.
17
- */
18
- static CLASS_NAME = "IpfsBlobStorageConnector";
19
- /**
20
- * The configuration for the connector.
21
- * @internal
22
- */
23
- _config;
24
- /**
25
- * Create a new instance of IpfsBlobStorageConnector.
26
- * @param options The options for the connector.
27
- */
28
- constructor(options) {
29
- core.Guards.object(IpfsBlobStorageConnector.CLASS_NAME, "options", options);
30
- core.Guards.object(IpfsBlobStorageConnector.CLASS_NAME, "options.config", options.config);
31
- core.Guards.stringValue(IpfsBlobStorageConnector.CLASS_NAME, "options.config.apiUrl", options.config.apiUrl);
32
- this._config = options.config;
33
- this._config.apiUrl = core.StringHelper.trimTrailingSlashes(this._config.apiUrl);
34
- }
35
- /**
36
- * Set the blob.
37
- * @param blob The data for the blob.
38
- * @returns The id of the stored blob in urn format.
39
- */
40
- async set(blob) {
41
- core.Guards.uint8Array(IpfsBlobStorageConnector.CLASS_NAME, "blob", blob);
42
- try {
43
- const formBlob = new Blob([new Uint8Array(blob)], { type: web.MimeTypes.OctetStream });
44
- const formData = new FormData();
45
- formData.append("file", formBlob);
46
- const fetchOptions = {
47
- method: "POST",
48
- body: formData,
49
- headers: {
50
- [web.HeaderTypes.Accept]: web.MimeTypes.Json,
51
- [web.HeaderTypes.ContentDisposition]: "form-data"
52
- }
53
- };
54
- this.addSecurity(fetchOptions);
55
- const response = await fetch(`${this._config.apiUrl}/add?pin=true`, fetchOptions);
56
- if (response.ok) {
57
- const result = (await response.json());
58
- return `blob:${new core.Urn(IpfsBlobStorageConnector.NAMESPACE, result.Hash).toString()}`;
59
- }
60
- const error = await response.json();
61
- throw new core.GeneralError(IpfsBlobStorageConnector.CLASS_NAME, "fetchFail", error);
62
- }
63
- catch (err) {
64
- throw new core.GeneralError(IpfsBlobStorageConnector.CLASS_NAME, "setBlobFailed", undefined, err);
65
- }
66
- }
67
- /**
68
- * Get the blob.
69
- * @param id The id of the blob to get in urn format.
70
- * @returns The data for the blob if it can be found or undefined.
71
- */
72
- async get(id) {
73
- core.Urn.guard(IpfsBlobStorageConnector.CLASS_NAME, "id", id);
74
- const urnParsed = core.Urn.fromValidString(id);
75
- if (urnParsed.namespaceMethod() !== IpfsBlobStorageConnector.NAMESPACE) {
76
- throw new core.GeneralError(IpfsBlobStorageConnector.CLASS_NAME, "namespaceMismatch", {
77
- namespace: IpfsBlobStorageConnector.NAMESPACE,
78
- id
79
- });
80
- }
81
- try {
82
- const fetchOptions = {
83
- method: "POST",
84
- headers: {
85
- accept: web.MimeTypes.Json
86
- }
87
- };
88
- this.addSecurity(fetchOptions);
89
- const response = await fetch(`${this._config.apiUrl}/cat?arg=${urnParsed.namespaceSpecific(1)}`, fetchOptions);
90
- if (response.ok) {
91
- const result = await response.arrayBuffer();
92
- return new Uint8Array(result);
93
- }
94
- const error = await response.json();
95
- throw new core.GeneralError(IpfsBlobStorageConnector.CLASS_NAME, "fetchFail", error);
96
- }
97
- catch (err) {
98
- throw new core.GeneralError(IpfsBlobStorageConnector.CLASS_NAME, "getBlobFailed", undefined, err);
99
- }
100
- }
101
- /**
102
- * Remove the blob.
103
- * @param id The id of the blob to remove in urn format.
104
- * @returns True if the blob was found.
105
- */
106
- async remove(id) {
107
- core.Urn.guard(IpfsBlobStorageConnector.CLASS_NAME, "id", id);
108
- const urnParsed = core.Urn.fromValidString(id);
109
- if (urnParsed.namespaceMethod() !== IpfsBlobStorageConnector.NAMESPACE) {
110
- throw new core.GeneralError(IpfsBlobStorageConnector.CLASS_NAME, "namespaceMismatch", {
111
- namespace: IpfsBlobStorageConnector.NAMESPACE,
112
- id
113
- });
114
- }
115
- try {
116
- const fetchOptions = {
117
- method: "POST",
118
- headers: {
119
- accept: web.MimeTypes.Json
120
- }
121
- };
122
- this.addSecurity(fetchOptions);
123
- const response = await fetch(`${this._config.apiUrl}/pin/rm?arg=${urnParsed.namespaceSpecific(1)}`, fetchOptions);
124
- if (response.ok) {
125
- return true;
126
- }
127
- const error = await response.json();
128
- throw new core.GeneralError(IpfsBlobStorageConnector.CLASS_NAME, "fetchFail", error);
129
- }
130
- catch (err) {
131
- throw new core.GeneralError(IpfsBlobStorageConnector.CLASS_NAME, "removeBlobFailed", undefined, err);
132
- }
133
- }
134
- /**
135
- * Add the security to the request.
136
- * @param requestInit The request options.
137
- * @internal
138
- */
139
- addSecurity(requestInit) {
140
- if (core.Is.stringValue(this._config.bearerToken)) {
141
- requestInit.headers = {
142
- ...requestInit.headers,
143
- [web.HeaderTypes.Authorization]: web.HeaderHelper.createBearer(this._config.bearerToken)
144
- };
145
- }
146
- }
147
- }
148
-
149
- exports.IpfsBlobStorageConnector = IpfsBlobStorageConnector;