@twin.org/blob-storage-connector-azure 0.0.3-next.13 → 0.0.3-next.15
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.
|
@@ -231,7 +231,7 @@ export class AzureBlobStorageConnector {
|
|
|
231
231
|
}
|
|
232
232
|
/**
|
|
233
233
|
* Remove all blobs from the storage.
|
|
234
|
-
* @returns
|
|
234
|
+
* @returns A promise that resolves when all blobs in the current partition have been removed.
|
|
235
235
|
*/
|
|
236
236
|
async empty() {
|
|
237
237
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"azureBlobStorageConnector.js","sourceRoot":"","sources":["../../src/azureBlobStorageConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAIN,iBAAiB,EAGjB,0BAA0B,EAC1B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EACN,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,MAAM,EACN,YAAY,EACZ,EAAE,EACF,GAAG,EAEH,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAM1C;;;GAGG;AACH,MAAM,OAAO,yBAAyB;IACrC;;OAEG;IACI,MAAM,CAAU,SAAS,GAAW,OAAO,CAAC;IAEnD;;OAEG;IACI,MAAM,CAAU,UAAU,+BAA+C;IAEhF;;;OAGG;IACc,OAAO,CAAmC;IAE3D;;;OAGG;IACc,oBAAoB,CAAY;IAEjD;;;OAGG;IACc,uBAAuB,CAAoB;IAE5D;;;OAGG;IACc,qBAAqB,CAAkB;IAExD;;;OAGG;IACH,YAAY,OAAqD;QAChE,MAAM,CAAC,MAAM,CAAC,yBAAyB,CAAC,UAAU,aAAmB,OAAO,CAAC,CAAC;QAC9E,MAAM,CAAC,MAAM,CACZ,yBAA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AG,EAAE,CAClC,CAAC;YAEF,MAAM,OAAO,GAAsB;gBAClC,eAAe,EAAE,SAAS;aAC1B,CAAC;YACF,MAAM,kBAAkB,GAAuB,MAAM,eAAe,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAErF,IAAI,CAAC,kBAAkB,CAAC,SAAS,EAAE,CAAC;gBACnC,OAAO,IAAI,CAAC;YACb,CAAC;YACD,OAAO,KAAK,CAAC;QACd,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,IAAI,EAAE,CAAC,MAAM,CAAyB,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;gBACtE,OAAO,KAAK,CAAC;YACd,CAAC;YACD,MAAM,IAAI,YAAY,CAAC,yBAAyB,CAAC,UAAU,EAAE,kBAAkB,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;QAC/F,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\ttype BlobClient,\n\ttype BlobDeleteOptions,\n\ttype BlobDeleteResponse,\n\tBlobServiceClient,\n\ttype BlockBlobClient,\n\ttype ContainerClient,\n\tStorageSharedKeyCredential\n} from \"@azure/storage-blob\";\nimport type { IBlobStorageConnector } from \"@twin.org/blob-storage-models\";\nimport { ContextIdHelper, ContextIdStore } from \"@twin.org/context\";\nimport {\n\tBaseError,\n\tComponentFactory,\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tHealthStatus,\n\tIs,\n\tUrn,\n\ttype IHealth\n} from \"@twin.org/core\";\nimport { Sha256 } from \"@twin.org/crypto\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IAzureBlobStorageConnectorConfig } from \"./models/IAzureBlobStorageConnectorConfig.js\";\nimport type { IAzureBlobStorageConnectorConstructorOptions } from \"./models/IAzureBlobStorageConnectorConstructorOptions.js\";\n\n/**\n * Class for performing blob storage operations on Azure.\n * See https://learn.microsoft.com/en-us/azure/storage/common/storage-samples-javascript?toc=%2Fazure%2Fstorage%2Fblobs%2Ftoc.json for more information.\n */\nexport class AzureBlobStorageConnector implements IBlobStorageConnector {\n\t/**\n\t * The namespace for the items.\n\t */\n\tpublic static readonly NAMESPACE: string = \"azure\";\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<AzureBlobStorageConnector>();\n\n\t/**\n\t * The configuration for the connector.\n\t * @internal\n\t */\n\tprivate readonly _config: IAzureBlobStorageConnectorConfig;\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 * The Azure Service client.\n\t * @internal\n\t */\n\tprivate readonly _azureBlobServiceClient: BlobServiceClient;\n\n\t/**\n\t * The Azure Container client.\n\t * @internal\n\t */\n\tprivate readonly _azureContainerClient: ContainerClient;\n\n\t/**\n\t * Create a new instance of AzureBlobStorageConnector.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options: IAzureBlobStorageConnectorConstructorOptions) {\n\t\tGuards.object(AzureBlobStorageConnector.CLASS_NAME, nameof(options), options);\n\t\tGuards.object<IAzureBlobStorageConnectorConfig>(\n\t\t\tAzureBlobStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config),\n\t\t\toptions.config\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tAzureBlobStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.accountName),\n\t\t\toptions.config.accountName\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tAzureBlobStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.accountKey),\n\t\t\toptions.config.accountKey\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tAzureBlobStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.containerName),\n\t\t\toptions.config.containerName\n\t\t);\n\n\t\tthis._config = options.config;\n\t\tthis._partitionContextIds = options.partitionContextIds;\n\n\t\tthis._azureBlobServiceClient = new BlobServiceClient(\n\t\t\t(options.config.endpoint ?? \"https://{accountName}.blob.core.windows.net/\").replace(\n\t\t\t\t\"{accountName}\",\n\t\t\t\toptions.config.accountName\n\t\t\t),\n\t\t\tnew StorageSharedKeyCredential(options.config.accountName, options.config.accountKey)\n\t\t);\n\n\t\tthis._azureContainerClient = this._azureBlobServiceClient.getContainerClient(\n\t\t\toptions.config.containerName\n\t\t);\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 AzureBlobStorageConnector.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\tawait this._azureContainerClient.exists();\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tsource: AzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\tstatus: HealthStatus.Ok,\n\t\t\t\t\tdescription: \"healthDescription\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tcontainerName: this._config.containerName,\n\t\t\t\t\t\taccountName: this._config.accountName\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t];\n\t\t} catch {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tsource: AzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\tstatus: HealthStatus.Error,\n\t\t\t\t\tdescription: \"healthDescription\",\n\t\t\t\t\tmessage: \"healthCheckFailed\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tcontainerName: this._config.containerName,\n\t\t\t\t\t\taccountName: this._config.accountName\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\t}\n\n\t/**\n\t * Bootstrap the component by creating and initializing any resources it needs.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns True if the bootstrapping process was successful.\n\t */\n\tpublic async bootstrap(nodeLoggingComponentType?: string): Promise<boolean> {\n\t\tconst nodeLogging = ComponentFactory.getIfExists<ILoggingComponent>(nodeLoggingComponentType);\n\n\t\ttry {\n\t\t\tconst exists = await this._azureContainerClient.exists();\n\n\t\t\tif (exists) {\n\t\t\t\tawait nodeLogging?.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: AzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\tmessage: \"containerExists\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tcontainer: this._config.containerName\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tawait nodeLogging?.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: AzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\tmessage: \"containerCreating\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tcontainer: this._config.containerName\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tawait this._azureContainerClient.create();\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tawait nodeLogging?.log({\n\t\t\t\tlevel: \"error\",\n\t\t\t\tsource: AzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\tmessage: \"containerCreateFailed\",\n\t\t\t\tdata: {\n\t\t\t\t\tcontainer: this._config.containerName\n\t\t\t\t},\n\t\t\t\terror: BaseError.fromError(err)\n\t\t\t});\n\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\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(AzureBlobStorageConnector.CLASS_NAME, nameof(blob), blob);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\ttry {\n\t\t\tconst id = Converter.bytesToHex(Sha256.sum256(blob));\n\t\t\tconst blockBlobClient: BlockBlobClient = this._azureContainerClient.getBlockBlobClient(\n\t\t\t\t`${partitionKey ?? \"root\"}/${id}`\n\t\t\t);\n\t\t\tawait blockBlobClient.uploadData(blob);\n\n\t\t\treturn `blob:${new Urn(AzureBlobStorageConnector.NAMESPACE, id).toString()}`;\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(AzureBlobStorageConnector.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(AzureBlobStorageConnector.CLASS_NAME, nameof(id), id);\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tif (urnParsed.namespaceMethod() !== AzureBlobStorageConnector.NAMESPACE) {\n\t\t\tthrow new GeneralError(AzureBlobStorageConnector.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: AzureBlobStorageConnector.NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst key = urnParsed.namespaceSpecific(1);\n\t\t\tconst blobClient: BlobClient = this._azureContainerClient.getBlobClient(\n\t\t\t\t`${partitionKey ?? \"root\"}/${key}`\n\t\t\t);\n\t\t\tconst buffer = await blobClient.downloadToBuffer();\n\t\t\treturn new Uint8Array(buffer);\n\t\t} catch (err) {\n\t\t\tif (Is.object<{ statusCode: number }>(err) && err.statusCode === 404) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tAzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\"getBlobFailed\",\n\t\t\t\t{\n\t\t\t\t\tid,\n\t\t\t\t\tnamespace: AzureBlobStorageConnector.NAMESPACE\n\t\t\t\t},\n\t\t\t\terr\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Teardown the component and remove any resources it created.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns True if the teardown process was successful.\n\t */\n\tpublic async teardown(nodeLoggingComponentType?: string): Promise<boolean> {\n\t\tconst nodeLogging = ComponentFactory.getIfExists<ILoggingComponent>(nodeLoggingComponentType);\n\n\t\tawait nodeLogging?.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: AzureBlobStorageConnector.CLASS_NAME,\n\t\t\tmessage: \"containerDeleting\",\n\t\t\tdata: {\n\t\t\t\tcontainer: this._config.containerName\n\t\t\t}\n\t\t});\n\n\t\ttry {\n\t\t\tawait this._azureContainerClient.delete();\n\n\t\t\tawait nodeLogging?.log({\n\t\t\t\tlevel: \"info\",\n\t\t\t\tsource: AzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\tmessage: \"containerDeleted\",\n\t\t\t\tdata: {\n\t\t\t\t\tcontainer: this._config.containerName\n\t\t\t\t}\n\t\t\t});\n\n\t\t\treturn true;\n\t\t} catch (err) {\n\t\t\tawait nodeLogging?.log({\n\t\t\t\tlevel: \"error\",\n\t\t\t\tsource: AzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\tmessage: \"teardownFailed\",\n\t\t\t\tdata: {\n\t\t\t\t\tcontainer: this._config.containerName\n\t\t\t\t},\n\t\t\t\terror: BaseError.fromError(err)\n\t\t\t});\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Remove all blobs from the storage.\n\t * @returns Nothing.\n\t */\n\tpublic async empty(): Promise<void> {\n\t\ttry {\n\t\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\t\tconst partitionKey = ContextIdHelper.combinedContextKey(\n\t\t\t\tcontextIds,\n\t\t\t\tthis._partitionContextIds\n\t\t\t);\n\t\t\tconst prefix = `${partitionKey ?? \"root\"}/`;\n\n\t\t\tfor await (const blob of this._azureContainerClient.listBlobsFlat({ prefix })) {\n\t\t\t\tawait this._azureContainerClient.deleteBlob(blob.name);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tAzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\"emptyFailed\",\n\t\t\t\t{ containerName: this._config.containerName },\n\t\t\t\terr\n\t\t\t);\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(AzureBlobStorageConnector.CLASS_NAME, nameof(id), id);\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tif (urnParsed.namespaceMethod() !== AzureBlobStorageConnector.NAMESPACE) {\n\t\t\tthrow new GeneralError(AzureBlobStorageConnector.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: AzureBlobStorageConnector.NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst key = urnParsed.namespaceSpecific(1);\n\n\t\t\tconst blockBlobClient: BlockBlobClient = this._azureContainerClient.getBlockBlobClient(\n\t\t\t\t`${partitionKey ?? \"root\"}/${key}`\n\t\t\t);\n\n\t\t\tconst options: BlobDeleteOptions = {\n\t\t\t\tdeleteSnapshots: \"include\"\n\t\t\t};\n\t\t\tconst blobDeleteResponse: BlobDeleteResponse = await blockBlobClient.delete(options);\n\n\t\t\tif (!blobDeleteResponse.errorCode) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t} catch (err) {\n\t\t\tif (Is.object<{ statusCode: number }>(err) && err.statusCode === 404) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthrow new GeneralError(AzureBlobStorageConnector.CLASS_NAME, \"removeBlobFailed\", { id }, err);\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file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AAG,EAAE,CAAC;gBACtE,OAAO,KAAK,CAAC;YACd,CAAC;YACD,MAAM,IAAI,YAAY,CAAC,yBAAyB,CAAC,UAAU,EAAE,kBAAkB,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;QAC/F,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\ttype BlobClient,\n\ttype BlobDeleteOptions,\n\ttype BlobDeleteResponse,\n\tBlobServiceClient,\n\ttype BlockBlobClient,\n\ttype ContainerClient,\n\tStorageSharedKeyCredential\n} from \"@azure/storage-blob\";\nimport type { IBlobStorageConnector } from \"@twin.org/blob-storage-models\";\nimport { ContextIdHelper, ContextIdStore } from \"@twin.org/context\";\nimport {\n\tBaseError,\n\tComponentFactory,\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tHealthStatus,\n\tIs,\n\tUrn,\n\ttype IHealth\n} from \"@twin.org/core\";\nimport { Sha256 } from \"@twin.org/crypto\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IAzureBlobStorageConnectorConfig } from \"./models/IAzureBlobStorageConnectorConfig.js\";\nimport type { IAzureBlobStorageConnectorConstructorOptions } from \"./models/IAzureBlobStorageConnectorConstructorOptions.js\";\n\n/**\n * Class for performing blob storage operations on Azure.\n * See https://learn.microsoft.com/en-us/azure/storage/common/storage-samples-javascript?toc=%2Fazure%2Fstorage%2Fblobs%2Ftoc.json for more information.\n */\nexport class AzureBlobStorageConnector implements IBlobStorageConnector {\n\t/**\n\t * The namespace for the items.\n\t */\n\tpublic static readonly NAMESPACE: string = \"azure\";\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<AzureBlobStorageConnector>();\n\n\t/**\n\t * The configuration for the connector.\n\t * @internal\n\t */\n\tprivate readonly _config: IAzureBlobStorageConnectorConfig;\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 * The Azure Service client.\n\t * @internal\n\t */\n\tprivate readonly _azureBlobServiceClient: BlobServiceClient;\n\n\t/**\n\t * The Azure Container client.\n\t * @internal\n\t */\n\tprivate readonly _azureContainerClient: ContainerClient;\n\n\t/**\n\t * Create a new instance of AzureBlobStorageConnector.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options: IAzureBlobStorageConnectorConstructorOptions) {\n\t\tGuards.object(AzureBlobStorageConnector.CLASS_NAME, nameof(options), options);\n\t\tGuards.object<IAzureBlobStorageConnectorConfig>(\n\t\t\tAzureBlobStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config),\n\t\t\toptions.config\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tAzureBlobStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.accountName),\n\t\t\toptions.config.accountName\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tAzureBlobStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.accountKey),\n\t\t\toptions.config.accountKey\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tAzureBlobStorageConnector.CLASS_NAME,\n\t\t\tnameof(options.config.containerName),\n\t\t\toptions.config.containerName\n\t\t);\n\n\t\tthis._config = options.config;\n\t\tthis._partitionContextIds = options.partitionContextIds;\n\n\t\tthis._azureBlobServiceClient = new BlobServiceClient(\n\t\t\t(options.config.endpoint ?? \"https://{accountName}.blob.core.windows.net/\").replace(\n\t\t\t\t\"{accountName}\",\n\t\t\t\toptions.config.accountName\n\t\t\t),\n\t\t\tnew StorageSharedKeyCredential(options.config.accountName, options.config.accountKey)\n\t\t);\n\n\t\tthis._azureContainerClient = this._azureBlobServiceClient.getContainerClient(\n\t\t\toptions.config.containerName\n\t\t);\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 AzureBlobStorageConnector.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\tawait this._azureContainerClient.exists();\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tsource: AzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\tstatus: HealthStatus.Ok,\n\t\t\t\t\tdescription: \"healthDescription\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tcontainerName: this._config.containerName,\n\t\t\t\t\t\taccountName: this._config.accountName\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t];\n\t\t} catch {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tsource: AzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\tstatus: HealthStatus.Error,\n\t\t\t\t\tdescription: \"healthDescription\",\n\t\t\t\t\tmessage: \"healthCheckFailed\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tcontainerName: this._config.containerName,\n\t\t\t\t\t\taccountName: this._config.accountName\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\t}\n\n\t/**\n\t * Bootstrap the component by creating and initializing any resources it needs.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns True if the bootstrapping process was successful.\n\t */\n\tpublic async bootstrap(nodeLoggingComponentType?: string): Promise<boolean> {\n\t\tconst nodeLogging = ComponentFactory.getIfExists<ILoggingComponent>(nodeLoggingComponentType);\n\n\t\ttry {\n\t\t\tconst exists = await this._azureContainerClient.exists();\n\n\t\t\tif (exists) {\n\t\t\t\tawait nodeLogging?.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: AzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\tmessage: \"containerExists\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tcontainer: this._config.containerName\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tawait nodeLogging?.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: AzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\tmessage: \"containerCreating\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tcontainer: this._config.containerName\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tawait this._azureContainerClient.create();\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tawait nodeLogging?.log({\n\t\t\t\tlevel: \"error\",\n\t\t\t\tsource: AzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\tmessage: \"containerCreateFailed\",\n\t\t\t\tdata: {\n\t\t\t\t\tcontainer: this._config.containerName\n\t\t\t\t},\n\t\t\t\terror: BaseError.fromError(err)\n\t\t\t});\n\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\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(AzureBlobStorageConnector.CLASS_NAME, nameof(blob), blob);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\ttry {\n\t\t\tconst id = Converter.bytesToHex(Sha256.sum256(blob));\n\t\t\tconst blockBlobClient: BlockBlobClient = this._azureContainerClient.getBlockBlobClient(\n\t\t\t\t`${partitionKey ?? \"root\"}/${id}`\n\t\t\t);\n\t\t\tawait blockBlobClient.uploadData(blob);\n\n\t\t\treturn `blob:${new Urn(AzureBlobStorageConnector.NAMESPACE, id).toString()}`;\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(AzureBlobStorageConnector.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(AzureBlobStorageConnector.CLASS_NAME, nameof(id), id);\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tif (urnParsed.namespaceMethod() !== AzureBlobStorageConnector.NAMESPACE) {\n\t\t\tthrow new GeneralError(AzureBlobStorageConnector.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: AzureBlobStorageConnector.NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst key = urnParsed.namespaceSpecific(1);\n\t\t\tconst blobClient: BlobClient = this._azureContainerClient.getBlobClient(\n\t\t\t\t`${partitionKey ?? \"root\"}/${key}`\n\t\t\t);\n\t\t\tconst buffer = await blobClient.downloadToBuffer();\n\t\t\treturn new Uint8Array(buffer);\n\t\t} catch (err) {\n\t\t\tif (Is.object<{ statusCode: number }>(err) && err.statusCode === 404) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tAzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\"getBlobFailed\",\n\t\t\t\t{\n\t\t\t\t\tid,\n\t\t\t\t\tnamespace: AzureBlobStorageConnector.NAMESPACE\n\t\t\t\t},\n\t\t\t\terr\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Teardown the component and remove any resources it created.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns True if the teardown process was successful.\n\t */\n\tpublic async teardown(nodeLoggingComponentType?: string): Promise<boolean> {\n\t\tconst nodeLogging = ComponentFactory.getIfExists<ILoggingComponent>(nodeLoggingComponentType);\n\n\t\tawait nodeLogging?.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: AzureBlobStorageConnector.CLASS_NAME,\n\t\t\tmessage: \"containerDeleting\",\n\t\t\tdata: {\n\t\t\t\tcontainer: this._config.containerName\n\t\t\t}\n\t\t});\n\n\t\ttry {\n\t\t\tawait this._azureContainerClient.delete();\n\n\t\t\tawait nodeLogging?.log({\n\t\t\t\tlevel: \"info\",\n\t\t\t\tsource: AzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\tmessage: \"containerDeleted\",\n\t\t\t\tdata: {\n\t\t\t\t\tcontainer: this._config.containerName\n\t\t\t\t}\n\t\t\t});\n\n\t\t\treturn true;\n\t\t} catch (err) {\n\t\t\tawait nodeLogging?.log({\n\t\t\t\tlevel: \"error\",\n\t\t\t\tsource: AzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\tmessage: \"teardownFailed\",\n\t\t\t\tdata: {\n\t\t\t\t\tcontainer: this._config.containerName\n\t\t\t\t},\n\t\t\t\terror: BaseError.fromError(err)\n\t\t\t});\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Remove all blobs from the storage.\n\t * @returns A promise that resolves when all blobs in the current partition have been removed.\n\t */\n\tpublic async empty(): Promise<void> {\n\t\ttry {\n\t\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\t\tconst partitionKey = ContextIdHelper.combinedContextKey(\n\t\t\t\tcontextIds,\n\t\t\t\tthis._partitionContextIds\n\t\t\t);\n\t\t\tconst prefix = `${partitionKey ?? \"root\"}/`;\n\n\t\t\tfor await (const blob of this._azureContainerClient.listBlobsFlat({ prefix })) {\n\t\t\t\tawait this._azureContainerClient.deleteBlob(blob.name);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tAzureBlobStorageConnector.CLASS_NAME,\n\t\t\t\t\"emptyFailed\",\n\t\t\t\t{ containerName: this._config.containerName },\n\t\t\t\terr\n\t\t\t);\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(AzureBlobStorageConnector.CLASS_NAME, nameof(id), id);\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst partitionKey = ContextIdHelper.combinedContextKey(contextIds, this._partitionContextIds);\n\n\t\tif (urnParsed.namespaceMethod() !== AzureBlobStorageConnector.NAMESPACE) {\n\t\t\tthrow new GeneralError(AzureBlobStorageConnector.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: AzureBlobStorageConnector.NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst key = urnParsed.namespaceSpecific(1);\n\n\t\t\tconst blockBlobClient: BlockBlobClient = this._azureContainerClient.getBlockBlobClient(\n\t\t\t\t`${partitionKey ?? \"root\"}/${key}`\n\t\t\t);\n\n\t\t\tconst options: BlobDeleteOptions = {\n\t\t\t\tdeleteSnapshots: \"include\"\n\t\t\t};\n\t\t\tconst blobDeleteResponse: BlobDeleteResponse = await blockBlobClient.delete(options);\n\n\t\t\tif (!blobDeleteResponse.errorCode) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t} catch (err) {\n\t\t\tif (Is.object<{ statusCode: number }>(err) && err.statusCode === 404) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthrow new GeneralError(AzureBlobStorageConnector.CLASS_NAME, \"removeBlobFailed\", { id }, err);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -55,7 +55,7 @@ export declare class AzureBlobStorageConnector implements IBlobStorageConnector
|
|
|
55
55
|
teardown(nodeLoggingComponentType?: string): Promise<boolean>;
|
|
56
56
|
/**
|
|
57
57
|
* Remove all blobs from the storage.
|
|
58
|
-
* @returns
|
|
58
|
+
* @returns A promise that resolves when all blobs in the current partition have been removed.
|
|
59
59
|
*/
|
|
60
60
|
empty(): Promise<void>;
|
|
61
61
|
/**
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.15](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-azure-v0.0.3-next.14...blob-storage-connector-azure-v0.0.3-next.15) (2026-06-15)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* async getStore ([#59](https://github.com/iotaledger/twin-blob-storage/issues/59)) ([2de1ae5](https://github.com/iotaledger/twin-blob-storage/commit/2de1ae5c274b84a2320f75ac4628b81e9459c540))
|
|
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.14 to 0.0.3-next.15
|
|
16
|
+
|
|
17
|
+
## [0.0.3-next.14](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-azure-v0.0.3-next.13...blob-storage-connector-azure-v0.0.3-next.14) (2026-06-11)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Miscellaneous Chores
|
|
21
|
+
|
|
22
|
+
* **blob-storage-connector-azure:** Synchronize repo versions
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Dependencies
|
|
26
|
+
|
|
27
|
+
* The following workspace dependencies were updated
|
|
28
|
+
* dependencies
|
|
29
|
+
* @twin.org/blob-storage-models bumped from 0.0.3-next.13 to 0.0.3-next.14
|
|
30
|
+
|
|
3
31
|
## [0.0.3-next.13](https://github.com/iotaledger/twin-blob-storage/compare/blob-storage-connector-azure-v0.0.3-next.12...blob-storage-connector-azure-v0.0.3-next.13) (2026-05-20)
|
|
4
32
|
|
|
5
33
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/blob-storage-connector-azure",
|
|
3
|
-
"version": "0.0.3-next.
|
|
3
|
+
"version": "0.0.3-next.15",
|
|
4
4
|
"description": "Stores and retrieves blobs in Azure Blob Storage containers.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/iotaledger/blob-storage.git",
|
|
7
|
+
"url": "git+https://github.com/iotaledger/twin-blob-storage.git",
|
|
8
8
|
"directory": "packages/blob-storage-connector-azure"
|
|
9
9
|
},
|
|
10
10
|
"author": "adrian.sanchez.sequeira@iota.org",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@azure/storage-blob": "12.31.0",
|
|
18
|
-
"@twin.org/blob-storage-models": "0.0.3-next.
|
|
18
|
+
"@twin.org/blob-storage-models": "0.0.3-next.15",
|
|
19
19
|
"@twin.org/context": "next",
|
|
20
20
|
"@twin.org/core": "next",
|
|
21
21
|
"@twin.org/crypto": "next",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"integration"
|
|
55
55
|
],
|
|
56
56
|
"bugs": {
|
|
57
|
-
"url": "git+https://github.com/iotaledger/blob-storage/issues"
|
|
57
|
+
"url": "git+https://github.com/iotaledger/twin-blob-storage/issues"
|
|
58
58
|
},
|
|
59
59
|
"homepage": "https://twindev.org"
|
|
60
60
|
}
|