@twin.org/blob-storage-connector-ipfs 0.0.3-next.7 → 0.0.3-next.8
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 +4 -10
- package/dist/es/ipfsBlobStorageConnector.js +35 -1
- package/dist/es/ipfsBlobStorageConnector.js.map +1 -1
- package/dist/types/ipfsBlobStorageConnector.d.ts +6 -0
- package/docs/changelog.md +56 -42
- package/docs/examples.md +39 -1
- package/docs/reference/classes/IpfsBlobStorageConnector.md +24 -6
- package/docs/reference/interfaces/IIpfsBlobStorageConnectorConfig.md +3 -3
- package/docs/reference/interfaces/IIpfsBlobStorageConnectorConstructorOptions.md +3 -3
- package/locales/en.json +6 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# TWIN Blob Storage Connector IPFS
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
##
|
|
11
|
+
## Docker
|
|
12
12
|
|
|
13
|
-
|
|
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
|
|
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
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GeneralError, Guards, Is, StringHelper, Urn } from "@twin.org/core";
|
|
1
|
+
import { GeneralError, Guards, HealthStatus, Is, StringHelper, Urn } from "@twin.org/core";
|
|
2
2
|
import { HeaderHelper, HeaderTypes, MimeTypes } from "@twin.org/web";
|
|
3
3
|
/**
|
|
4
4
|
* Class for performing blob storage operations on IPFS.
|
|
@@ -42,6 +42,40 @@ export class IpfsBlobStorageConnector {
|
|
|
42
42
|
className() {
|
|
43
43
|
return IpfsBlobStorageConnector.CLASS_NAME;
|
|
44
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: "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
|
+
}
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch { }
|
|
70
|
+
return [
|
|
71
|
+
{
|
|
72
|
+
source: IpfsBlobStorageConnector.CLASS_NAME,
|
|
73
|
+
status: HealthStatus.Error,
|
|
74
|
+
description: "healthDescription",
|
|
75
|
+
message: "healthCheckFailed"
|
|
76
|
+
}
|
|
77
|
+
];
|
|
78
|
+
}
|
|
45
79
|
/**
|
|
46
80
|
* Set the blob.
|
|
47
81
|
* @param blob The data for the blob.
|
|
@@ -1 +1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,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 { GeneralError, Guards, Is, StringHelper, Urn } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HeaderHelper, HeaderTypes, 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 * 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: \"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: \"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: \"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"]}
|
|
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,SAAS,EAAE,MAAM,eAAe,CAAC;AAIrE;;;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,CA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,CAAC;YAEF,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;YAE/B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC3B,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, 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: \"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}\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}\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: \"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: \"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: \"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"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IBlobStorageConnector } from "@twin.org/blob-storage-models";
|
|
2
|
+
import { type IHealth } from "@twin.org/core";
|
|
2
3
|
import type { IIpfsBlobStorageConnectorConstructorOptions } from "./models/IIpfsBlobStorageConnectorConstructorOptions.js";
|
|
3
4
|
/**
|
|
4
5
|
* Class for performing blob storage operations on IPFS.
|
|
@@ -23,6 +24,11 @@ export declare class IpfsBlobStorageConnector implements IBlobStorageConnector {
|
|
|
23
24
|
* @returns The class name of the component.
|
|
24
25
|
*/
|
|
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[]>;
|
|
26
32
|
/**
|
|
27
33
|
* Set the blob.
|
|
28
34
|
* @param blob The data for the blob.
|
package/docs/changelog.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
2
|
|
|
3
|
-
## [0.0.3-next.
|
|
3
|
+
## [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)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* health checks ([#44](https://github.com/iotaledger/twin-blob-storage/issues/44)) ([4a4041c](https://github.com/iotaledger/twin-blob-storage/commit/4a4041c19b68c40ed1aba6d1cdb4318ac4208b7d))
|
|
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.7 to 0.0.3-next.8
|
|
16
|
+
|
|
17
|
+
## [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)
|
|
4
18
|
|
|
5
19
|
|
|
6
20
|
### Miscellaneous Chores
|
|
@@ -14,7 +28,7 @@
|
|
|
14
28
|
* dependencies
|
|
15
29
|
* @twin.org/blob-storage-models bumped from 0.0.3-next.6 to 0.0.3-next.7
|
|
16
30
|
|
|
17
|
-
## [0.0.3-next.6](https://github.com/
|
|
31
|
+
## [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)
|
|
18
32
|
|
|
19
33
|
|
|
20
34
|
### Miscellaneous Chores
|
|
@@ -28,7 +42,7 @@
|
|
|
28
42
|
* dependencies
|
|
29
43
|
* @twin.org/blob-storage-models bumped from 0.0.3-next.5 to 0.0.3-next.6
|
|
30
44
|
|
|
31
|
-
## [0.0.3-next.5](https://github.com/
|
|
45
|
+
## [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)
|
|
32
46
|
|
|
33
47
|
|
|
34
48
|
### Miscellaneous Chores
|
|
@@ -42,7 +56,7 @@
|
|
|
42
56
|
* dependencies
|
|
43
57
|
* @twin.org/blob-storage-models bumped from 0.0.3-next.4 to 0.0.3-next.5
|
|
44
58
|
|
|
45
|
-
## [0.0.3-next.4](https://github.com/
|
|
59
|
+
## [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)
|
|
46
60
|
|
|
47
61
|
|
|
48
62
|
### Miscellaneous Chores
|
|
@@ -56,7 +70,7 @@
|
|
|
56
70
|
* dependencies
|
|
57
71
|
* @twin.org/blob-storage-models bumped from 0.0.3-next.3 to 0.0.3-next.4
|
|
58
72
|
|
|
59
|
-
## [0.0.3-next.3](https://github.com/
|
|
73
|
+
## [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)
|
|
60
74
|
|
|
61
75
|
|
|
62
76
|
### Miscellaneous Chores
|
|
@@ -70,13 +84,13 @@
|
|
|
70
84
|
* dependencies
|
|
71
85
|
* @twin.org/blob-storage-models bumped from 0.0.3-next.2 to 0.0.3-next.3
|
|
72
86
|
|
|
73
|
-
## [0.0.3-next.2](https://github.com/
|
|
87
|
+
## [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)
|
|
74
88
|
|
|
75
89
|
|
|
76
90
|
### Bug Fixes
|
|
77
91
|
|
|
78
|
-
* missing dependency ([868717b](https://github.com/
|
|
79
|
-
* missing dependency ([9b7ec26](https://github.com/
|
|
92
|
+
* missing dependency ([868717b](https://github.com/iotaledger/twin-blob-storage/commit/868717b9d352af916c32df4d4f942d3bd8769c95))
|
|
93
|
+
* missing dependency ([9b7ec26](https://github.com/iotaledger/twin-blob-storage/commit/9b7ec2694468e75b4d3357b623e5031def82c920))
|
|
80
94
|
|
|
81
95
|
|
|
82
96
|
### Dependencies
|
|
@@ -85,19 +99,19 @@
|
|
|
85
99
|
* dependencies
|
|
86
100
|
* @twin.org/blob-storage-models bumped from 0.0.3-next.1 to 0.0.3-next.2
|
|
87
101
|
|
|
88
|
-
## [0.0.3-next.1](https://github.com/
|
|
102
|
+
## [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)
|
|
89
103
|
|
|
90
104
|
|
|
91
105
|
### Features
|
|
92
106
|
|
|
93
|
-
* add context id features ([#30](https://github.com/
|
|
94
|
-
* add validate-locales ([f20fcec](https://github.com/
|
|
95
|
-
* eslint migration to flat config ([e4239dd](https://github.com/
|
|
96
|
-
* update dependencies ([56f0094](https://github.com/
|
|
97
|
-
* update framework core ([ff339fe](https://github.com/
|
|
98
|
-
* use new createBearer method ([f87c550](https://github.com/
|
|
99
|
-
* use new createBearer method ([a965801](https://github.com/
|
|
100
|
-
* use shared store mechanism ([#12](https://github.com/
|
|
107
|
+
* add context id features ([#30](https://github.com/iotaledger/twin-blob-storage/issues/30)) ([fbf1c92](https://github.com/iotaledger/twin-blob-storage/commit/fbf1c9276424c841ef5ef3f4de8469ab3fba7e9c))
|
|
108
|
+
* add validate-locales ([f20fcec](https://github.com/iotaledger/twin-blob-storage/commit/f20fceced91e39a0c9edb770b2e43ce944c92f3c))
|
|
109
|
+
* eslint migration to flat config ([e4239dd](https://github.com/iotaledger/twin-blob-storage/commit/e4239dd1c721955cff7f0357255d2bba15319972))
|
|
110
|
+
* update dependencies ([56f0094](https://github.com/iotaledger/twin-blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
|
|
111
|
+
* update framework core ([ff339fe](https://github.com/iotaledger/twin-blob-storage/commit/ff339fe7e3f09ddff429907834bdf43617e9c05e))
|
|
112
|
+
* use new createBearer method ([f87c550](https://github.com/iotaledger/twin-blob-storage/commit/f87c5502fe3b5fee81257d7500f5d4500ea5ed28))
|
|
113
|
+
* use new createBearer method ([a965801](https://github.com/iotaledger/twin-blob-storage/commit/a96580160315c363fc0f06a1615cc92d4339a5e4))
|
|
114
|
+
* use shared store mechanism ([#12](https://github.com/iotaledger/twin-blob-storage/issues/12)) ([cae8110](https://github.com/iotaledger/twin-blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
|
|
101
115
|
|
|
102
116
|
|
|
103
117
|
### Dependencies
|
|
@@ -106,12 +120,12 @@
|
|
|
106
120
|
* dependencies
|
|
107
121
|
* @twin.org/blob-storage-models bumped from 0.0.3-next.0 to 0.0.3-next.1
|
|
108
122
|
|
|
109
|
-
## [0.0.2-next.5](https://github.com/
|
|
123
|
+
## [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)
|
|
110
124
|
|
|
111
125
|
|
|
112
126
|
### Features
|
|
113
127
|
|
|
114
|
-
* add validate-locales ([f20fcec](https://github.com/
|
|
128
|
+
* add validate-locales ([f20fcec](https://github.com/iotaledger/twin-blob-storage/commit/f20fceced91e39a0c9edb770b2e43ce944c92f3c))
|
|
115
129
|
|
|
116
130
|
|
|
117
131
|
### Dependencies
|
|
@@ -120,13 +134,13 @@
|
|
|
120
134
|
* dependencies
|
|
121
135
|
* @twin.org/blob-storage-models bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
122
136
|
|
|
123
|
-
## [0.0.2-next.4](https://github.com/
|
|
137
|
+
## [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)
|
|
124
138
|
|
|
125
139
|
|
|
126
140
|
### Features
|
|
127
141
|
|
|
128
|
-
* use new createBearer method ([f87c550](https://github.com/
|
|
129
|
-
* use new createBearer method ([a965801](https://github.com/
|
|
142
|
+
* use new createBearer method ([f87c550](https://github.com/iotaledger/twin-blob-storage/commit/f87c5502fe3b5fee81257d7500f5d4500ea5ed28))
|
|
143
|
+
* use new createBearer method ([a965801](https://github.com/iotaledger/twin-blob-storage/commit/a96580160315c363fc0f06a1615cc92d4339a5e4))
|
|
130
144
|
|
|
131
145
|
|
|
132
146
|
### Dependencies
|
|
@@ -135,12 +149,12 @@
|
|
|
135
149
|
* dependencies
|
|
136
150
|
* @twin.org/blob-storage-models bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
137
151
|
|
|
138
|
-
## [0.0.2-next.3](https://github.com/
|
|
152
|
+
## [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)
|
|
139
153
|
|
|
140
154
|
|
|
141
155
|
### Features
|
|
142
156
|
|
|
143
|
-
* eslint migration to flat config ([e4239dd](https://github.com/
|
|
157
|
+
* eslint migration to flat config ([e4239dd](https://github.com/iotaledger/twin-blob-storage/commit/e4239dd1c721955cff7f0357255d2bba15319972))
|
|
144
158
|
|
|
145
159
|
|
|
146
160
|
### Dependencies
|
|
@@ -149,12 +163,12 @@
|
|
|
149
163
|
* dependencies
|
|
150
164
|
* @twin.org/blob-storage-models bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
151
165
|
|
|
152
|
-
## [0.0.2-next.2](https://github.com/
|
|
166
|
+
## [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)
|
|
153
167
|
|
|
154
168
|
|
|
155
169
|
### Features
|
|
156
170
|
|
|
157
|
-
* update framework core ([ff339fe](https://github.com/
|
|
171
|
+
* update framework core ([ff339fe](https://github.com/iotaledger/twin-blob-storage/commit/ff339fe7e3f09ddff429907834bdf43617e9c05e))
|
|
158
172
|
|
|
159
173
|
|
|
160
174
|
### Dependencies
|
|
@@ -163,13 +177,13 @@
|
|
|
163
177
|
* dependencies
|
|
164
178
|
* @twin.org/blob-storage-models bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
165
179
|
|
|
166
|
-
## [0.0.2-next.1](https://github.com/
|
|
180
|
+
## [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)
|
|
167
181
|
|
|
168
182
|
|
|
169
183
|
### Features
|
|
170
184
|
|
|
171
|
-
* update dependencies ([56f0094](https://github.com/
|
|
172
|
-
* use shared store mechanism ([#12](https://github.com/
|
|
185
|
+
* update dependencies ([56f0094](https://github.com/iotaledger/twin-blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
|
|
186
|
+
* use shared store mechanism ([#12](https://github.com/iotaledger/twin-blob-storage/issues/12)) ([cae8110](https://github.com/iotaledger/twin-blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
|
|
173
187
|
|
|
174
188
|
|
|
175
189
|
### Dependencies
|
|
@@ -183,7 +197,7 @@
|
|
|
183
197
|
|
|
184
198
|
### Features
|
|
185
199
|
|
|
186
|
-
* release to production ([eacfe75](https://github.com/
|
|
200
|
+
* release to production ([eacfe75](https://github.com/iotaledger/twin-blob-storage/commit/eacfe754a0dcd9243d9e13d86422327d0a605164))
|
|
187
201
|
|
|
188
202
|
|
|
189
203
|
### Dependencies
|
|
@@ -192,7 +206,7 @@
|
|
|
192
206
|
* dependencies
|
|
193
207
|
* @twin.org/blob-storage-models bumped from ^0.0.0 to ^0.0.1
|
|
194
208
|
|
|
195
|
-
## [0.0.1-next.37](https://github.com/
|
|
209
|
+
## [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)
|
|
196
210
|
|
|
197
211
|
|
|
198
212
|
### Miscellaneous Chores
|
|
@@ -206,7 +220,7 @@
|
|
|
206
220
|
* dependencies
|
|
207
221
|
* @twin.org/blob-storage-models bumped from 0.0.1-next.36 to 0.0.1-next.37
|
|
208
222
|
|
|
209
|
-
## [0.0.1-next.36](https://github.com/
|
|
223
|
+
## [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)
|
|
210
224
|
|
|
211
225
|
|
|
212
226
|
### Miscellaneous Chores
|
|
@@ -220,7 +234,7 @@
|
|
|
220
234
|
* dependencies
|
|
221
235
|
* @twin.org/blob-storage-models bumped from 0.0.1-next.35 to 0.0.1-next.36
|
|
222
236
|
|
|
223
|
-
## [0.0.1-next.35](https://github.com/
|
|
237
|
+
## [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)
|
|
224
238
|
|
|
225
239
|
|
|
226
240
|
### Miscellaneous Chores
|
|
@@ -234,12 +248,12 @@
|
|
|
234
248
|
* dependencies
|
|
235
249
|
* @twin.org/blob-storage-models bumped from 0.0.1-next.34 to 0.0.1-next.35
|
|
236
250
|
|
|
237
|
-
## [0.0.1-next.34](https://github.com/
|
|
251
|
+
## [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)
|
|
238
252
|
|
|
239
253
|
|
|
240
254
|
### Features
|
|
241
255
|
|
|
242
|
-
* update dependencies ([56f0094](https://github.com/
|
|
256
|
+
* update dependencies ([56f0094](https://github.com/iotaledger/twin-blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
|
|
243
257
|
|
|
244
258
|
|
|
245
259
|
### Dependencies
|
|
@@ -248,7 +262,7 @@
|
|
|
248
262
|
* dependencies
|
|
249
263
|
* @twin.org/blob-storage-models bumped from 0.0.1-next.33 to 0.0.1-next.34
|
|
250
264
|
|
|
251
|
-
## [0.0.1-next.33](https://github.com/
|
|
265
|
+
## [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)
|
|
252
266
|
|
|
253
267
|
|
|
254
268
|
### Miscellaneous Chores
|
|
@@ -262,7 +276,7 @@
|
|
|
262
276
|
* dependencies
|
|
263
277
|
* @twin.org/blob-storage-models bumped from 0.0.1-next.32 to 0.0.1-next.33
|
|
264
278
|
|
|
265
|
-
## [0.0.1-next.32](https://github.com/
|
|
279
|
+
## [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)
|
|
266
280
|
|
|
267
281
|
|
|
268
282
|
### Miscellaneous Chores
|
|
@@ -276,7 +290,7 @@
|
|
|
276
290
|
* dependencies
|
|
277
291
|
* @twin.org/blob-storage-models bumped from 0.0.1-next.31 to 0.0.1-next.32
|
|
278
292
|
|
|
279
|
-
## [0.0.1-next.31](https://github.com/
|
|
293
|
+
## [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)
|
|
280
294
|
|
|
281
295
|
|
|
282
296
|
### Miscellaneous Chores
|
|
@@ -290,12 +304,12 @@
|
|
|
290
304
|
* dependencies
|
|
291
305
|
* @twin.org/blob-storage-models bumped from 0.0.1-next.30 to 0.0.1-next.31
|
|
292
306
|
|
|
293
|
-
## [0.0.1-next.30](https://github.com/
|
|
307
|
+
## [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)
|
|
294
308
|
|
|
295
309
|
|
|
296
310
|
### Features
|
|
297
311
|
|
|
298
|
-
* use shared store mechanism ([#12](https://github.com/
|
|
312
|
+
* use shared store mechanism ([#12](https://github.com/iotaledger/twin-blob-storage/issues/12)) ([cae8110](https://github.com/iotaledger/twin-blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
|
|
299
313
|
|
|
300
314
|
|
|
301
315
|
### Dependencies
|
|
@@ -304,7 +318,7 @@
|
|
|
304
318
|
* dependencies
|
|
305
319
|
* @twin.org/blob-storage-models bumped from 0.0.1-next.29 to 0.0.1-next.30
|
|
306
320
|
|
|
307
|
-
## [0.0.1-next.29](https://github.com/
|
|
321
|
+
## [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)
|
|
308
322
|
|
|
309
323
|
|
|
310
324
|
### Miscellaneous Chores
|
package/docs/examples.md
CHANGED
|
@@ -1 +1,39 @@
|
|
|
1
|
-
#
|
|
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,7 @@ Runtime name for the class.
|
|
|
45
45
|
|
|
46
46
|
## Methods
|
|
47
47
|
|
|
48
|
-
### className()
|
|
48
|
+
### className() {#classname}
|
|
49
49
|
|
|
50
50
|
> **className**(): `string`
|
|
51
51
|
|
|
@@ -63,7 +63,25 @@ The class name of the component.
|
|
|
63
63
|
|
|
64
64
|
***
|
|
65
65
|
|
|
66
|
-
###
|
|
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}
|
|
67
85
|
|
|
68
86
|
> **set**(`blob`): `Promise`\<`string`\>
|
|
69
87
|
|
|
@@ -89,7 +107,7 @@ The id of the stored blob in urn format.
|
|
|
89
107
|
|
|
90
108
|
***
|
|
91
109
|
|
|
92
|
-
### get()
|
|
110
|
+
### get() {#get}
|
|
93
111
|
|
|
94
112
|
> **get**(`id`): `Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`\>
|
|
95
113
|
|
|
@@ -115,7 +133,7 @@ The data for the blob if it can be found or undefined.
|
|
|
115
133
|
|
|
116
134
|
***
|
|
117
135
|
|
|
118
|
-
### remove()
|
|
136
|
+
### remove() {#remove}
|
|
119
137
|
|
|
120
138
|
> **remove**(`id`): `Promise`\<`boolean`\>
|
|
121
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
|
|
17
|
+
> `optional` **bearerToken?**: `string`
|
|
18
18
|
|
|
19
19
|
The bearer token for authentication to the API.
|
|
@@ -4,15 +4,15 @@ Options for the IPFS Blob Storage Connector constructor.
|
|
|
4
4
|
|
|
5
5
|
## Properties
|
|
6
6
|
|
|
7
|
-
### partitionContextIds?
|
|
7
|
+
### partitionContextIds? {#partitioncontextids}
|
|
8
8
|
|
|
9
|
-
> `optional` **partitionContextIds
|
|
9
|
+
> `optional` **partitionContextIds?**: `string`[]
|
|
10
10
|
|
|
11
11
|
The keys to use from the context ids to create partitions.
|
|
12
12
|
|
|
13
13
|
***
|
|
14
14
|
|
|
15
|
-
### config
|
|
15
|
+
### config {#config}
|
|
16
16
|
|
|
17
17
|
> **config**: [`IIpfsBlobStorageConnectorConfig`](IIpfsBlobStorageConnectorConfig.md)
|
|
18
18
|
|
package/locales/en.json
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
+
"health": {
|
|
3
|
+
"ipfsBlobStorageConnector": {
|
|
4
|
+
"healthDescription": "IPFS blob storage connector is healthy",
|
|
5
|
+
"healthCheckFailed": "Failed to connect to IPFS node"
|
|
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.3-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3-next.8",
|
|
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/
|
|
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,7 +14,7 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/blob-storage-models": "0.0.3-next.
|
|
17
|
+
"@twin.org/blob-storage-models": "0.0.3-next.8",
|
|
18
18
|
"@twin.org/core": "next",
|
|
19
19
|
"@twin.org/crypto": "next",
|
|
20
20
|
"@twin.org/nameof": "next",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"integration"
|
|
53
53
|
],
|
|
54
54
|
"bugs": {
|
|
55
|
-
"url": "git+https://github.com/
|
|
55
|
+
"url": "git+https://github.com/iotaledger/blob-storage/issues"
|
|
56
56
|
},
|
|
57
57
|
"homepage": "https://twindev.org"
|
|
58
58
|
}
|