@qrvey/object-storage 0.0.4 → 0.0.6

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,7 +1,7 @@
1
1
  # @qrvey/object-storage
2
2
 
3
3
  ![install size](https://packagephobia.com/badge?p=%40qrvey%2Fobject-storage)
4
- ![coverage](https://img.shields.io/badge/unit_test_coverage-12%25-brightgreen)
4
+ ![coverage](https://img.shields.io/badge/unit_test_coverage-11%25-brightgreen)
5
5
 
6
6
  The `@qrvey/object-storage` package provides a unified interface for ...
7
7
 
package/dist/cjs/index.js CHANGED
@@ -52,6 +52,7 @@ var errorMessages = {
52
52
  SignatureDoesNotMatch: "The request signature we calculated does not match the signature you provided",
53
53
  SlowDown: "Please reduce your request rate",
54
54
  TemporaryRedirect: "Temporary redirect",
55
+ ObjectNotFound: "ObjectNotFound - The specified key does not exist. (404)",
55
56
  DEFAULT: "An unknown error occurred"
56
57
  };
57
58
  var ErrorHandler = class {
@@ -103,43 +104,23 @@ var BlobStorageService = class {
103
104
  createUploadWriteStream(key) {
104
105
  throw new Error("Method not implemented.");
105
106
  }
106
- getUploadUrl(key, expiresInMinutes) {
107
- throw new Error("Method not implemented.");
108
- }
109
107
  /**
110
108
  * Retrieves the properties of a blob from the container by its name.
111
109
  *
112
110
  * @param {string} blobName - The name of the blob.
113
111
  * @return {Promise<GetObjectResponse>} A promise that resolves to the blob properties.
114
112
  */
115
- getHeadObject(blobName) {
116
- return new Promise((resolve, reject) => {
117
- try {
118
- const containerClient = this.blobServiceClient.getContainerClient(
119
- this.containerName
120
- );
121
- const blockBlobClient = containerClient.getBlockBlobClient(blobName);
122
- blockBlobClient.getProperties().then((blobProperties) => {
123
- return resolve(
124
- BlobPropertiesResponseToObjectResponse(
125
- blobProperties
126
- )
127
- );
128
- }).catch(
129
- (error) => reject(
130
- ErrorHandler.handleError(
131
- "DEFAULT",
132
- "",
133
- error
134
- )
135
- )
136
- );
137
- } catch (error) {
138
- return reject(
139
- ErrorHandler.handleError("DEFAULT", "", error)
140
- );
141
- }
142
- });
113
+ async getHeadObject(blobName) {
114
+ try {
115
+ const containerClient = this.blobServiceClient.getContainerClient(
116
+ this.containerName
117
+ );
118
+ const blockBlobClient = containerClient.getBlockBlobClient(blobName);
119
+ const blobProperties = await blockBlobClient.getProperties();
120
+ return BlobPropertiesResponseToObjectResponse(blobProperties);
121
+ } catch (error) {
122
+ throw ErrorHandler.handleError("DEFAULT", "", error);
123
+ }
143
124
  }
144
125
  /**
145
126
  * Retrieves an object from the blob storage service.
@@ -147,35 +128,57 @@ var BlobStorageService = class {
147
128
  * @param {string} blobName - The name of the blob to retrieve.
148
129
  * @return {Promise<GetObjectResponse>} A promise that resolves to the object data, including the body, metadata, content type, and content length, or rejects with an error if there was an issue.
149
130
  */
150
- getObject(blobName) {
151
- return new Promise((resolve, reject) => {
152
- try {
153
- const containerClient = this.blobServiceClient.getContainerClient(
154
- this.containerName
155
- );
156
- const blockBlobClient = containerClient.getBlockBlobClient(blobName);
157
- blockBlobClient.download(0).then((downloadBlockBlobResponse) => {
158
- return resolve({
159
- body: downloadBlockBlobResponse.readableStreamBody,
160
- metadata: {},
161
- contentType: "",
162
- contentLength: 0
163
- });
164
- }).catch(
165
- (error) => reject(
166
- ErrorHandler.handleError(
167
- "DEFAULT",
168
- "",
169
- error
170
- )
171
- )
172
- );
173
- } catch (error) {
174
- return reject(
175
- ErrorHandler.handleError("DEFAULT", "", error)
176
- );
131
+ async getObject(blobName) {
132
+ var _a;
133
+ try {
134
+ const containerClient = this.blobServiceClient.getContainerClient(
135
+ this.containerName
136
+ );
137
+ const blockBlobClient = containerClient.getBlockBlobClient(blobName);
138
+ const downloadBlockBlobResponse = await blockBlobClient.download(0);
139
+ return {
140
+ body: downloadBlockBlobResponse.readableStreamBody,
141
+ metadata: downloadBlockBlobResponse.metadata,
142
+ contentType: downloadBlockBlobResponse.contentType,
143
+ contentLength: downloadBlockBlobResponse.contentLength
144
+ };
145
+ } catch (error) {
146
+ let errorKey = "DEFAULT";
147
+ if (((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.status) === 404) {
148
+ errorKey = "ObjectNotFound";
177
149
  }
178
- });
150
+ throw ErrorHandler.handleError(errorKey, "", error);
151
+ }
152
+ }
153
+ async getSignatureUrl(blobName, expiresInMinutes, permissions) {
154
+ try {
155
+ const containerClient = this.blobServiceClient.getContainerClient(
156
+ this.containerName
157
+ );
158
+ const blockBlobClient = containerClient.getBlockBlobClient(blobName);
159
+ const startDate = /* @__PURE__ */ new Date();
160
+ const expiryDate = new Date(startDate);
161
+ expiryDate.setMinutes(startDate.getMinutes() + expiresInMinutes);
162
+ return blockBlobClient.generateSasUrl({
163
+ permissions: storageBlob.BlobSASPermissions.parse(permissions),
164
+ startsOn: startDate,
165
+ expiresOn: expiryDate
166
+ });
167
+ } catch (error) {
168
+ throw ErrorHandler.handleError("DEFAULT", "", error);
169
+ }
170
+ }
171
+ async getUploadUrl(blobName, expiresInMinutes) {
172
+ try {
173
+ const sasUrl = await this.getSignatureUrl(
174
+ blobName,
175
+ expiresInMinutes,
176
+ "w"
177
+ );
178
+ return { key: blobName, signedUrl: sasUrl };
179
+ } catch (error) {
180
+ throw ErrorHandler.handleError("DEFAULT", "", error);
181
+ }
179
182
  }
180
183
  /**
181
184
  * Retrieves a signed URL for the blob with the specified name that expires after a certain period.
@@ -184,37 +187,17 @@ var BlobStorageService = class {
184
187
  * @param {number} expiresInMinutes - The duration in minutes until the signed URL expires.
185
188
  * @return {Promise<string>} A Promise that resolves with the signed URL.
186
189
  */
187
- getDownloadUrl(blobName, expiresInMinutes) {
188
- return new Promise((resolve, reject) => {
189
- try {
190
- const containerClient = this.blobServiceClient.getContainerClient(
191
- this.containerName
192
- );
193
- const blockBlobClient = containerClient.getBlockBlobClient(blobName);
194
- const startDate = /* @__PURE__ */ new Date();
195
- const expiryDate = new Date(startDate);
196
- expiryDate.setMinutes(
197
- startDate.getMinutes() + expiresInMinutes
198
- );
199
- blockBlobClient.generateSasUrl({
200
- permissions: storageBlob.BlobSASPermissions.parse("r"),
201
- startsOn: startDate,
202
- expiresOn: expiryDate
203
- }).then((sasUrl) => resolve(sasUrl)).catch(
204
- (error) => reject(
205
- ErrorHandler.handleError(
206
- "DEFAULT",
207
- "",
208
- error
209
- )
210
- )
211
- );
212
- } catch (error) {
213
- return reject(
214
- ErrorHandler.handleError("DEFAULT", "", error)
215
- );
216
- }
217
- });
190
+ async getDownloadUrl(blobName, expiresInMinutes) {
191
+ try {
192
+ const sasUrl = await this.getSignatureUrl(
193
+ blobName,
194
+ expiresInMinutes,
195
+ "r"
196
+ );
197
+ return sasUrl;
198
+ } catch (error) {
199
+ throw ErrorHandler.handleError("DEFAULT", "", error);
200
+ }
218
201
  }
219
202
  /**
220
203
  * Uploads a file to the blob storage service.
@@ -224,33 +207,22 @@ var BlobStorageService = class {
224
207
  * @param {{ [key: string]: string } | undefined} [metadata] - Optional metadata to associate with the blob.
225
208
  * @return {Promise<UploadResponse>} A promise that resolves to the response object containing the key of the uploaded blob, or rejects with an error if there was an issue.
226
209
  */
227
- upload(blobName, body, metadata) {
228
- return new Promise((resolve, reject) => {
229
- try {
230
- const containerClient = this.blobServiceClient.getContainerClient(
231
- this.containerName
232
- );
233
- const blockBlobClient = containerClient.getBlockBlobClient(blobName);
234
- blockBlobClient.uploadStream(
235
- body,
236
- void 0,
237
- void 0,
238
- metadata
239
- ).then(() => resolve({ key: blobName })).catch(
240
- (error) => reject(
241
- ErrorHandler.handleError(
242
- "DEFAULT",
243
- "",
244
- error
245
- )
246
- )
247
- );
248
- } catch (error) {
249
- return reject(
250
- ErrorHandler.handleError("DEFAULT", "", error)
251
- );
252
- }
253
- });
210
+ async upload(blobName, body, metadata = {}) {
211
+ try {
212
+ const containerClient = this.blobServiceClient.getContainerClient(
213
+ this.containerName
214
+ );
215
+ const blockBlobClient = containerClient.getBlockBlobClient(blobName);
216
+ Buffer.isBuffer(body) ? await blockBlobClient.upload(body, body.length, { metadata }) : await blockBlobClient.uploadStream(
217
+ body,
218
+ void 0,
219
+ void 0,
220
+ { metadata }
221
+ );
222
+ return { key: blobName };
223
+ } catch (error) {
224
+ throw ErrorHandler.handleError("DEFAULT", "", error);
225
+ }
254
226
  }
255
227
  /**
256
228
  * Deletes a blob from the blob storage service.
@@ -258,28 +230,15 @@ var BlobStorageService = class {
258
230
  * @param {string} blobName - The name of the blob to be deleted.
259
231
  * @return {Promise<boolean>} A promise that resolves to true if the blob is successfully deleted, or rejects with an error if there was an issue.
260
232
  */
261
- delete(blobName) {
262
- return new Promise((resolve, reject) => {
263
- try {
264
- const containerClient = this.blobServiceClient.getContainerClient(
265
- this.containerName
266
- );
267
- const blockBlobClient = containerClient.getBlockBlobClient(blobName);
268
- blockBlobClient.delete().then(() => resolve(true)).catch(
269
- (error) => reject(
270
- ErrorHandler.handleError(
271
- "DEFAULT",
272
- "",
273
- error
274
- )
275
- )
276
- );
277
- } catch (error) {
278
- return reject(
279
- ErrorHandler.handleError("DEFAULT", "", error)
280
- );
281
- }
282
- });
233
+ async delete(data) {
234
+ try {
235
+ const containerClient = this.blobServiceClient.getContainerClient(
236
+ this.containerName
237
+ );
238
+ return this.deleteObject(containerClient, data);
239
+ } catch (error) {
240
+ throw ErrorHandler.handleError("DEFAULT", "", error);
241
+ }
283
242
  }
284
243
  /**
285
244
  * Lists a chunk of blobs from the specified container client based on the provided options and continuation token.
@@ -380,6 +339,40 @@ var BlobStorageService = class {
380
339
  } while (pagination);
381
340
  return { items: allItems, count: allItems.length };
382
341
  }
342
+ /**
343
+ * Deletes a blob from the blob storage service.
344
+ *
345
+ * @param {string} blobName - The name of the blob to be deleted.
346
+ * @return {Promise<boolean>} A promise that resolves to true if the blob is successfully deleted, or rejects with an error if there was an issue.
347
+ */
348
+ async deleteObject(containerClient, blobName) {
349
+ try {
350
+ const blockBlobClient = containerClient.getBlockBlobClient(blobName);
351
+ await blockBlobClient.delete();
352
+ return true;
353
+ } catch (error) {
354
+ throw ErrorHandler.handleError("DEFAULT", "", error);
355
+ }
356
+ }
357
+ async deleteObjects(blobNames) {
358
+ const containerClient = this.blobServiceClient.getContainerClient(
359
+ this.containerName
360
+ );
361
+ const deleteBlobPromises = blobNames.map(async (blobName) => {
362
+ var _a;
363
+ try {
364
+ await this.deleteObject(containerClient, blobName);
365
+ return { key: blobName, deleted: true };
366
+ } catch (error) {
367
+ return {
368
+ key: blobName,
369
+ deleted: false,
370
+ error: (_a = error == null ? void 0 : error.message) != null ? _a : ""
371
+ };
372
+ }
373
+ });
374
+ return Promise.all(deleteBlobPromises);
375
+ }
383
376
  };
384
377
 
385
378
  // src/services/storage/s3/s3Helpers.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/services/storage/blob/blobStorage.service.ts","../../src/shared/utils/errorHandler.ts","../../src/services/storage/blob/blobHelpers.ts","../../src/services/storage/s3/s3Storage.service.ts","../../src/services/storage/s3/s3Helpers.ts","../../src/services/objectStorageFactory.service.ts","../../src/services/objectStorage.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAWA;AAAA,EACI;AAAA,EACA;AAAA,OAGG;;;ACdP,IAAM,gBAA2C;AAAA,EAC7C,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,mBAAmB;AAAA,EACnB,qBAAqB;AAAA,EACrB,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,eAAe;AAAA,EACf,oBACI;AAAA,EACJ,mBAAmB;AAAA,EACnB,oBACI;AAAA,EACJ,cAAc;AAAA,EACd,cAAc;AAAA,EACd,WAAW;AAAA,EACX,oBAAoB;AAAA,EACpB,gBAAgB;AAAA,EAChB,oBAAoB;AAAA,EACpB,uBACI;AAAA,EACJ,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,SAAS;AACb;AAEO,IAAM,eAAN,MAAmB;AAAA,EACtB,OAAO,YACH,WACA,cACA,UACW;AACX,UAAM,gBAA6B;AAAA,MAC/B,MAA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AO,KAAa,YAAuC;AACpE,WAAO,sBAAqB;AAAA,MACxB;AAAA,IACJ,EAAE,KAAK,CAAC,aAAa,SAAS,OAAO,GAAG,CAAC;AAAA,EAC7C;AACJ","sourcesContent":["import { IObjectStorage } from '../../../interfaces';\nimport {\n FileContent,\n ListResponse,\n UploadResponse,\n GetObjectResponse,\n ListRequestOptions,\n ListResponseItem,\n GetUploadUrlResponse,\n CreateUploadWriteStreamResponse,\n} from '../../../types';\nimport {\n BlobServiceClient,\n BlobSASPermissions,\n BlobItem,\n ContainerClient,\n} from '@azure/storage-blob';\n\nimport { Readable } from 'stream';\nimport { ErrorHandler } from '../../../shared/utils/errorHandler';\nimport { BlobPropertiesResponseToObjectResponse } from './blobHelpers';\nexport class BlobStorageService implements IObjectStorage {\n private blobServiceClient: BlobServiceClient;\n private containerName: string;\n\n /**\n * Retrieves the properties of a blob from the container by its name.\n *\n * @param {string} blobName - The name of the blob.\n * @return {Promise<GetObjectResponse>} A promise that resolves to the blob properties.\n */\n constructor(containerName: string) {\n this.containerName = containerName;\n this.blobServiceClient = BlobServiceClient.fromConnectionString(\n process.env.AZURE_STORAGE_CONNECTION_STRING!,\n );\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars\n createUploadWriteStream(key: string): CreateUploadWriteStreamResponse {\n throw new Error('Method not implemented.');\n }\n getUploadUrl(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars\n key: string,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars\n expiresInMinutes: number,\n ): Promise<GetUploadUrlResponse> {\n throw new Error('Method not implemented.');\n }\n\n /**\n * Retrieves the properties of a blob from the container by its name.\n *\n * @param {string} blobName - The name of the blob.\n * @return {Promise<GetObjectResponse>} A promise that resolves to the blob properties.\n */\n getHeadObject(blobName: string): Promise<GetObjectResponse> {\n return new Promise((resolve, reject) => {\n try {\n const containerClient =\n this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n blockBlobClient\n .getProperties()\n .then((blobProperties) => {\n return resolve(\n BlobPropertiesResponseToObjectResponse(\n blobProperties,\n ),\n );\n })\n .catch((error) =>\n reject(\n ErrorHandler.handleError(\n 'DEFAULT',\n '',\n error as Error,\n ),\n ),\n );\n } catch (error) {\n return reject(\n ErrorHandler.handleError('DEFAULT', '', error as Error),\n );\n }\n });\n }\n\n /**\n * Retrieves an object from the blob storage service.\n *\n * @param {string} blobName - The name of the blob to retrieve.\n * @return {Promise<GetObjectResponse>} A promise that resolves to the object data, including the body, metadata, content type, and content length, or rejects with an error if there was an issue.\n */\n getObject(blobName: string): Promise<GetObjectResponse> {\n return new Promise((resolve, reject) => {\n try {\n const containerClient =\n this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n blockBlobClient\n .download(0)\n .then((downloadBlockBlobResponse) => {\n return resolve({\n body: downloadBlockBlobResponse.readableStreamBody as Readable,\n metadata: {},\n contentType: '',\n contentLength: 0,\n });\n })\n .catch((error) =>\n reject(\n ErrorHandler.handleError(\n 'DEFAULT',\n '',\n error as Error,\n ),\n ),\n );\n } catch (error) {\n return reject(\n ErrorHandler.handleError('DEFAULT', '', error as Error),\n );\n }\n });\n }\n\n /**\n * Retrieves a signed URL for the blob with the specified name that expires after a certain period.\n *\n * @param {string} blobName - The name of the blob to generate the signed URL for.\n * @param {number} expiresInMinutes - The duration in minutes until the signed URL expires.\n * @return {Promise<string>} A Promise that resolves with the signed URL.\n */\n getDownloadUrl(\n blobName: string,\n expiresInMinutes: number,\n ): Promise<string> {\n return new Promise((resolve, reject) => {\n try {\n const containerClient =\n this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n\n const startDate = new Date();\n const expiryDate = new Date(startDate);\n expiryDate.setMinutes(\n startDate.getMinutes() + expiresInMinutes,\n );\n\n blockBlobClient\n .generateSasUrl({\n permissions: BlobSASPermissions.parse('r'),\n startsOn: startDate,\n expiresOn: expiryDate,\n })\n .then((sasUrl) => resolve(sasUrl))\n .catch((error) =>\n reject(\n ErrorHandler.handleError(\n 'DEFAULT',\n '',\n error as Error,\n ),\n ),\n );\n } catch (error) {\n return reject(\n ErrorHandler.handleError('DEFAULT', '', error as Error),\n );\n }\n });\n }\n\n /**\n * Uploads a file to the blob storage service.\n *\n * @param {string} blobName - The name of the blob to upload.\n * @param {FileContent} body - The content of the file to upload.\n * @param {{ [key: string]: string } | undefined} [metadata] - Optional metadata to associate with the blob.\n * @return {Promise<UploadResponse>} A promise that resolves to the response object containing the key of the uploaded blob, or rejects with an error if there was an issue.\n */\n upload(\n blobName: string,\n body: FileContent,\n metadata?: { [key: string]: string } | undefined,\n ): Promise<UploadResponse> {\n return new Promise((resolve, reject) => {\n try {\n const containerClient =\n this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n\n blockBlobClient\n .uploadStream(\n body as Readable,\n undefined,\n undefined,\n metadata,\n )\n .then(() => resolve({ key: blobName }))\n .catch((error) =>\n reject(\n ErrorHandler.handleError(\n 'DEFAULT',\n '',\n error as Error,\n ),\n ),\n );\n } catch (error) {\n return reject(\n ErrorHandler.handleError('DEFAULT', '', error as Error),\n );\n }\n });\n }\n\n /**\n * Deletes a blob from the blob storage service.\n *\n * @param {string} blobName - The name of the blob to be deleted.\n * @return {Promise<boolean>} A promise that resolves to true if the blob is successfully deleted, or rejects with an error if there was an issue.\n */\n delete(blobName: string): Promise<boolean> {\n return new Promise((resolve, reject) => {\n try {\n const containerClient =\n this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n blockBlobClient\n .delete()\n .then(() => resolve(true))\n .catch((error) =>\n reject(\n ErrorHandler.handleError(\n 'DEFAULT',\n '',\n error as Error,\n ),\n ),\n );\n } catch (error) {\n return reject(\n ErrorHandler.handleError('DEFAULT', '', error as Error),\n );\n }\n });\n }\n\n /**\n * Lists a chunk of blobs from the specified container client based on the provided options and continuation token.\n *\n * @param {ListRequestOptions} options - The options for listing the blobs.\n * @param {string | undefined} continuationToken - The continuation token for pagination.\n * @param {number} limit - The maximum number of blobs to list in a single page.\n * @param {ContainerClient} containerClient - The container client to list the blobs from.\n * @return {Promise<{ items: BlobItem[]; continuationToken?: string }>} - A promise that resolves to an object containing the list of blob items and an optional continuation token.\n */\n private async listChunk(\n options: ListRequestOptions,\n continuationToken: string | undefined,\n limit: number,\n containerClient: ContainerClient,\n ): Promise<{ items: BlobItem[]; continuationToken?: string }> {\n const iterator = containerClient\n .listBlobsFlat({\n prefix: options.prefix,\n })\n .byPage({\n maxPageSize: limit,\n continuationToken: continuationToken,\n });\n\n const items: BlobItem[] = [];\n const response = (await iterator.next()).value;\n items.push(...response.segment.blobItems);\n return {\n items,\n continuationToken: response.continuationToken,\n };\n }\n\n /**\n * Retrieves a list of blob contents based on the provided options.\n *\n * @param {ListRequestOptions} options - The options for listing the blob contents.\n * @return {Promise<{ contents: BlobItem[]; nextContinuationToken?: string }>} A promise that resolves to the list of blob contents and the next continuation token.\n */\n private async listContents(\n options: ListRequestOptions,\n ): Promise<{ contents: BlobItem[]; nextContinuationToken?: string }> {\n let responseContents: BlobItem[] = [];\n let continuationToken: string | undefined = options.pagination;\n const limit = options.limit ?? 1000;\n let continueListing = true;\n const containerClient = this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n while (continueListing) {\n const response = await this.listChunk(\n options,\n continuationToken,\n limit - responseContents.length,\n containerClient,\n );\n continuationToken = response.continuationToken;\n responseContents = responseContents.concat(response.items);\n\n if (responseContents.length >= limit || !continuationToken) {\n continueListing = false;\n }\n }\n\n return {\n contents: responseContents,\n nextContinuationToken: continuationToken,\n };\n }\n\n /**\n * Lists blobs in the Azure Blob Storage container with pagination.\n * @param options - The options for listing blobs.\n * @returns A promise that resolves to a paginated list of blob names.\n */\n async list(options: ListRequestOptions): Promise<ListResponse> {\n let items: ListResponseItem[] = [];\n const response = await this.listContents(options);\n\n items = response.contents.length\n ? response.contents.map((blob) => {\n return {\n key: blob.name,\n lastModified: blob.properties.lastModified,\n size: blob.properties.contentLength!,\n eTag: blob.properties.etag,\n };\n })\n : [];\n\n return {\n items,\n pagination: response.nextContinuationToken?.length\n ? response.nextContinuationToken\n : null,\n count: items.length,\n };\n }\n\n /**\n * Lists all blobs in the Azure Blob Storage container.\n * @param options - The options for listing blobs.\n * @returns A promise that resolves to list of blob names.\n */\n async listAll(options: ListRequestOptions): Promise<ListResponse> {\n let allItems: ListResponseItem[] = [];\n let pagination: string | undefined = undefined;\n\n do {\n const response: ListResponse = await this.list({\n ...options,\n pagination,\n });\n\n if (response.items?.length)\n allItems = [...allItems, ...response.items];\n\n pagination = response.pagination ?? undefined;\n } while (pagination);\n\n return { items: allItems, count: allItems.length };\n }\n}\n","import { CustomError } from '../../types/CustomError';\n\nconst errorMessages: { [key: string]: string } = {\n AccessDenied: 'Access denied',\n AccountProblem: 'There is a problem with your account',\n AllAccessDisabled: 'All access to this resource has been disabled',\n BucketAlreadyExists: 'The requested bucket name is not available',\n BucketNotEmpty: 'The bucket you tried to delete is not empty',\n EntityTooLarge: 'The entity you are trying to upload is too large',\n ExpiredToken: 'The provided token has expired',\n InternalError: 'An internal server error has occurred',\n InvalidAccessKeyId:\n 'The AWS access key ID you provided does not exist in our records',\n InvalidBucketName: 'The specified bucket name is not valid',\n InvalidObjectState:\n 'The operation is not valid for the current state of the object',\n InvalidToken: 'The provided token is invalid',\n NoSuchBucket: 'The specified bucket does not exist',\n NoSuchKey: 'The specified key does not exist',\n PreconditionFailed: 'The condition specified in the request is not met',\n RequestTimeout: 'The request timed out',\n ServiceUnavailable: 'The service is currently unavailable',\n SignatureDoesNotMatch:\n 'The request signature we calculated does not match the signature you provided',\n SlowDown: 'Please reduce your request rate',\n TemporaryRedirect: 'Temporary redirect',\n DEFAULT: 'An unknown error occurred',\n};\n\nexport class ErrorHandler {\n static handleError(\n errorCode: string,\n errorMessage?: string,\n errorObj?: Error,\n ): CustomError {\n const errorResponse: CustomError = {\n code: errorCode,\n message:\n errorMessage ||\n errorMessages[errorCode] ||\n errorMessages['DEFAULT'],\n timestamp: new Date().toISOString(),\n error: errorObj\n ? {\n name: errorObj.name,\n message: errorObj.message,\n stack: errorObj.stack || null,\n }\n : null,\n };\n\n // Return the structured object\n return errorResponse;\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { GetObjectResponse } from '../../../types';\nimport { BlobGetPropertiesResponse } from '@azure/storage-blob';\n\nexport function BlobPropertiesResponseToObjectResponse(\n blobProperties: BlobGetPropertiesResponse,\n): GetObjectResponse {\n return {\n lastModified: blobProperties.lastModified,\n contentLength: blobProperties.contentLength,\n contentType: blobProperties.contentType,\n eTag: blobProperties.etag,\n metadata: blobProperties.metadata,\n contentEncoding: blobProperties.contentEncoding,\n cacheControl: blobProperties.cacheControl,\n contentDisposition: blobProperties.contentDisposition,\n contentLanguage: blobProperties.contentLanguage,\n };\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n DeleteObjectCommand,\n GetObjectCommand,\n HeadObjectCommand,\n ListObjectsV2Command,\n ListObjectsV2CommandOutput,\n PutObjectAclCommandInput,\n PutObjectCommand,\n S3Client,\n} from '@aws-sdk/client-s3';\nimport { IObjectStorage } from '../../../interfaces';\nimport {\n CreateUploadWriteStreamResponse,\n FileContent,\n GetObjectResponse,\n GetUploadUrlResponse,\n ListRequestOptions,\n ListResponse,\n ListResponseItem,\n UploadResponse,\n} from '../../../types';\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner';\nimport {\n listResponseContentsToListResponseItems,\n s3ObjectToObjectResponse,\n} from './s3Helpers';\nimport stream from 'stream';\nimport { Upload } from '@aws-sdk/lib-storage';\n\nexport class S3StorageService implements IObjectStorage {\n private s3Client: S3Client = new S3Client({\n region: process.env.AWS_REGION,\n });\n private bucketName: string;\n\n constructor(bucketName: string) {\n this.bucketName = bucketName;\n }\n\n /**\n * Retrieves a chunk of objects from the S3 bucket based on the provided options.\n *\n * @param {ListRequestOptions} options - The options for listing the objects.\n * @param {string | undefined} continuationToken - The continuation token for pagination.\n * @param {number} limit - The maximum number of objects to retrieve.\n * @return {Promise<ListObjectsV2CommandOutput>} - A promise that resolves to the response containing the list of objects and metadata.\n */\n private async listChunk(\n options: ListRequestOptions,\n continuationToken: string | undefined,\n limit: number,\n ): Promise<ListObjectsV2CommandOutput> {\n const command = new ListObjectsV2Command({\n Bucket: this.bucketName,\n ContinuationToken: continuationToken || options.pagination,\n Prefix: options.prefix,\n MaxKeys: limit,\n });\n\n return this.s3Client.send(command);\n }\n\n /**\n * Retrieves a list of contents from the S3 bucket based on the provided options.\n *\n * @param {ListRequestOptions} options - The options for listing the contents.\n * @return {Promise<{ contents: unknown[]; nextContinuationToken?: string }>} - A promise that resolves to an object containing the list of contents and an optional next continuation token.\n */\n private async listContents(\n options: ListRequestOptions,\n ): Promise<{ contents: unknown[]; nextContinuationToken?: string }> {\n let responseContents: any[] = [];\n let continuationToken: string | undefined = undefined;\n const limit = options.limit ?? 1000;\n let continueListing = true;\n while (continueListing) {\n const listChunkLimit = limit - responseContents.length;\n const response = await this.listChunk(\n options,\n continuationToken,\n listChunkLimit,\n );\n continuationToken = response.NextContinuationToken;\n responseContents = responseContents.concat(response.Contents ?? []);\n\n if (responseContents.length >= limit || !continuationToken) {\n continueListing = false;\n }\n }\n\n return {\n contents: responseContents,\n nextContinuationToken: continuationToken,\n };\n }\n\n /**\n * Lists objects in the S3 bucket with pagination.\n * @param options - The options for listing objects.\n * @returns A promise that resolves to a paginated list of object keys.\n */\n async list(options: ListRequestOptions): Promise<ListResponse> {\n let items: ListResponseItem[] = [];\n const response = await this.listContents(options);\n\n items = response.contents.length\n ? listResponseContentsToListResponseItems(response.contents)\n : [];\n\n return {\n items,\n pagination: response.nextContinuationToken ?? null,\n count: items.length,\n };\n }\n\n /**\n * Lists all objects in the S3 bucket.\n * @param options - The options for listing objects.\n * @returns A promise that resolves to list of object keys.\n */\n\n async listAll(options: ListRequestOptions): Promise<ListResponse> {\n let allItems: ListResponseItem[] = [];\n let pagination: string | undefined = undefined;\n\n do {\n const response: ListResponse = await this.list({\n ...options,\n pagination,\n });\n\n if (response.items?.length)\n allItems = [...allItems, ...response.items];\n\n pagination =\n response.pagination === null ? undefined : response.pagination;\n } while (pagination);\n\n return { items: allItems, count: allItems.length };\n }\n\n /**\n * Retrieves an object from the S3 bucket.\n * @param key - The key of the object to retrieve.\n * @returns A promise that resolves to the content of the file.\n */\n async getHeadObject(key: string): Promise<GetObjectResponse> {\n const command = new HeadObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n });\n const response = await this.s3Client.send(command);\n return s3ObjectToObjectResponse(response);\n }\n\n /**\n * Retrieves an object from the S3 bucket.\n * @param key - The key of the object to retrieve.\n * @returns A promise that resolves to the content of the file.\n */\n async getObject(key: string): Promise<GetObjectResponse> {\n const command = new GetObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n });\n const response = await this.s3Client.send(command);\n return s3ObjectToObjectResponse(response);\n }\n\n /**\n * Generates a signed URL for accessing an object in the S3 bucket.\n * @param key - The key of the object.\n * @param expiresInMinutes - The number of minutes the signed URL should be valid for. Defaults to 60 minutes.\n * @returns A promise that resolves to the signed URL.\n */\n getDownloadUrl(\n key: string,\n expiresInMinutes: number = 60,\n ): Promise<string> {\n const expiresIn = expiresInMinutes * 60;\n const command = new GetObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n });\n return getSignedUrl(this.s3Client, command, { expiresIn });\n }\n\n /**\n * Retrieves a signed URL for uploading an object to the S3 bucket.\n *\n * @param {string} key - The key of the object to be uploaded.\n * @param {number} [expiresInMinutes=60] - The number of minutes the signed URL should be valid for. Defaults to 60 minutes.\n * @returns A promise that resolves to the signed URL.\n */\n async getUploadUrl(\n key: string,\n expiresInMinutes: number = 60,\n ): Promise<GetUploadUrlResponse> {\n const expiresIn = expiresInMinutes * 60;\n\n const putObjectCommandParams: PutObjectAclCommandInput = {\n Bucket: process.env.UPLOAD_BUCKET_NAME,\n Key: key,\n ACL: 'private',\n };\n\n const command = new PutObjectCommand(putObjectCommandParams);\n\n const signedUrl = await getSignedUrl(this.s3Client, command, {\n expiresIn,\n });\n\n return {\n signedUrl,\n key: `https://${process.env.UPLOAD_BUCKET_NAME}.s3.${process.env.AWS_DEFAULT_REGION}.amazonaws.com/${key}`,\n };\n }\n\n /**\n * Uploads an object to the S3 bucket.\n * @param key - The key of the object to upload.\n * @param body - The content of the object to upload.\n * @param metadata - Optional metadata to associate with the object.\n * @returns A promise that resolves to the response containing the key of the uploaded object.\n */\n async upload(\n key: string,\n body: FileContent,\n metadata?: { [key: string]: string },\n ): Promise<UploadResponse> {\n const command = new PutObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n Body: body,\n Metadata: metadata,\n });\n await this.s3Client.send(command);\n return { key };\n }\n\n /**\n * Creates a writable stream for uploading a file to the S3 bucket.\n *\n * @param {string} key - The key of the object to upload.\n * @return {CreateUploadWriteStreamResponse} An object containing the key of the uploaded object, the writable stream, and a promise that resolves when the upload is complete.\n */\n createUploadWriteStream(key: string): CreateUploadWriteStreamResponse {\n const streamPassThrough = new stream.PassThrough();\n const params = {\n Bucket: this.bucketName,\n Key: key,\n Body: streamPassThrough,\n };\n\n const upload = new Upload({\n client: this.s3Client,\n params,\n });\n\n return {\n key,\n stream: streamPassThrough,\n promise: upload.done(),\n };\n }\n\n /**\n * Deletes an object from the S3 bucket.\n * @param key - The key of the object to delete.\n * @returns A promise that resolves to true if the object was deleted successfully.\n */\n async delete(key: string): Promise<boolean> {\n const command = new DeleteObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n });\n await this.s3Client.send(command);\n return true;\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { GetObjectCommandOutput } from '@aws-sdk/client-s3';\nimport { GetObjectResponse, ListResponseItem } from '../../../types';\nimport { Readable } from 'stream';\n\n/**\n * Converts an array of S3 response contents into an array of ListResponseItem objects.\n *\n * @param {any[]} responseContents - The array of S3 response contents.\n * @return {ListResponseItem[]} The array of ListResponseItem objects.\n */\nexport function listResponseContentsToListResponseItems(\n responseContents: any[],\n): ListResponseItem[] {\n return responseContents.map((responseContent) => {\n return {\n key: responseContent.Key,\n lastModified: new Date(responseContent.LastModified),\n size: responseContent.Size,\n eTag: responseContent.ETag,\n };\n });\n}\n\n/**\n * Converts an S3 object response to a standardized object response.\n *\n * @param {GetObjectCommandOutput} s3Object - The S3 object response to convert.\n * @return {GetObjectResponse} The converted object response.\n */\nexport function s3ObjectToObjectResponse(\n s3Object: GetObjectCommandOutput,\n): GetObjectResponse {\n return {\n body: s3Object.Body as Readable,\n metadata: s3Object.Metadata,\n contentType: s3Object.ContentType,\n contentLength: s3Object.ContentLength as number,\n contentEncoding: s3Object.ContentEncoding,\n cacheControl: s3Object.CacheControl,\n contentDisposition: s3Object.ContentDisposition,\n contentLanguage: s3Object.ContentLanguage,\n eTag: s3Object.ETag,\n lastModified: s3Object.LastModified,\n };\n}\n","import { IObjectStorage } from '../interfaces';\nimport { S3StorageService, BlobStorageService } from './storage';\n\nexport class ObjectStorageFactory {\n static async instance(bucketName: string): Promise<IObjectStorage> {\n const isBlobStorageService =\n process.env.OBJECT_STORAGE_SERVICE?.toLowerCase() ===\n 'azure_blob_storage';\n\n if (isBlobStorageService) {\n return new BlobStorageService(bucketName);\n } else {\n return new S3StorageService(bucketName);\n }\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { IObjectStorage } from '../interfaces';\nimport {\n ListResponse,\n FileContent,\n UploadResponse,\n GetObjectResponse,\n ListRequestOptions,\n GetUploadUrlResponse,\n CreateUploadWriteStreamResponse,\n} from '../types';\nimport { ObjectStorageFactory } from '../services/objectStorageFactory.service';\n\nexport default class ObjectStorageService {\n static bucketName: string;\n\n constructor(bucketName: string) {\n ObjectStorageService.bucketName = bucketName;\n }\n\n static async getObjectStorageServiceInstance(\n bucketName: string = ObjectStorageService.bucketName,\n ): Promise<IObjectStorage> {\n if (!bucketName)\n throw new Error('Bucket name not provided or not valid value');\n return ObjectStorageFactory.instance(bucketName);\n }\n\n /**\n * Retrieves a list of objects from the object storage service.\n *\n * @param {ListRequestOptions} options - The options to apply to the list operation.\n * @param {string} [bucketName] - The name of the bucket to list objects from. If not provided, the default bucket name will be used.\n * @return {Promise<ListResponse>} A promise that resolves to the list of objects.\n */\n static async list(\n options: ListRequestOptions,\n bucketName?: string,\n ): Promise<ListResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.list(options));\n }\n\n /**\n * Retrieves a list of all objects from the object storage service.\n *\n * @param {ListRequestOptions} options - The options to apply to the list operation.\n * @param {string} [bucketName] - The name of the bucket to list objects from. If not provided, the default bucket name will be used.\n * @return {Promise<ListResponse>} A promise that resolves to the list of all objects.\n */\n static async listAll(\n options: ListRequestOptions,\n bucketName?: string,\n ): Promise<ListResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.listAll(options));\n }\n\n /**\n * Retrieves an object from the object storage service.\n *\n * @param {string} key - The key of the object to retrieve.\n * @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.\n * @return {Promise<GetObjectResponse>} A promise that resolves to the retrieved object.\n */\n static async getObject(\n key: string,\n bucketName?: string,\n ): Promise<GetObjectResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.getObject(key));\n }\n\n /**\n * Retrieves a signed URL for the specified object in the object storage service.\n *\n * @param {string} key - The key of the object for which to generate the signed URL.\n * @param {number} expiresInMinutes - The number of minutes until the signed URL expires.\n * @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.\n * @return {Promise<string>} A promise that resolves to the generated signed URL.\n */\n static async getDownloadUrl(\n key: string,\n expiresInMinutes: number,\n bucketName?: string,\n ): Promise<string> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.getDownloadUrl(key, expiresInMinutes));\n }\n\n /**\n * Retrieves an upload URL for the specified object in the object storage service.\n *\n * @param {string} key - The key of the object for which to generate the upload URL.\n * @param {number} expiresInMinutes - The number of minutes until the upload URL expires.\n * @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.\n * @return {Promise<string>} A promise that resolves to the generated upload URL.\n */\n static async getUploadUrl(\n key: string,\n expiresInMinutes: number,\n bucketName?: string,\n ): Promise<GetUploadUrlResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.getUploadUrl(key, expiresInMinutes));\n }\n\n /**\n * Uploads a file to the object storage service.\n *\n * @param {string} key - The key of the object to upload.\n * @param {FileContent} body - The content of the file to upload.\n * @param {Object} [metadata] - Optional metadata to associate with the object.\n * @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.\n * @return {Promise<UploadResponse>} A promise that resolves to the response of the upload operation.\n */\n static async upload(\n key: string,\n body: FileContent,\n metadata?: { [key: string]: string },\n bucketName?: string,\n ): Promise<UploadResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.upload(key, body, metadata));\n }\n\n /**\n * Creates an upload write stream for the specified key in the object storage service.\n *\n * @param {string} key - The key of the object to create the upload write stream for.\n * @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.\n * @return {Promise<CreateUploadWriteStreamResponse>} A promise that resolves to the response of the upload operation.\n */\n static async createUploadWriteStream(\n key: string,\n bucketName?: string,\n ): Promise<CreateUploadWriteStreamResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.createUploadWriteStream(key));\n }\n\n /**\n * Deletes an object from the object storage service.\n *\n * @param {string} key - The key of the object to delete.\n * @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.\n * @return {Promise<boolean>} A promise that resolves to true if the object was successfully deleted, or false otherwise.\n */\n static async delete(key: string, bucketName?: string): Promise<boolean> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.delete(key));\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/services/storage/blob/blobStorage.service.ts","../../src/shared/utils/errorHandler.ts","../../src/services/storage/blob/blobHelpers.ts","../../src/services/storage/s3/s3Storage.service.ts","../../src/services/storage/s3/s3Helpers.ts","../../src/services/objectStorageFactory.service.ts","../../src/services/objectStorage.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAWA;AAAA,EACI;AAAA,EACA;AAAA,OAGG;;;ACdP,IAAM,gBAA2C;AAAA,EAC7C,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,mBAAmB;AAAA,EACnB,qBAAqB;AAAA,EACrB,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,eAAe;AAAA,EACf,oBACI;AAAA,EACJ,mBAAmB;AAAA,EACnB,oBACI;AAAA,EACJ,cAAc;AAAA,EACd,cAAc;AAAA,EACd,WAAW;AAAA,EACX,oBAAoB;AAAA,EACpB,gBAAgB;AAAA,EAChB,oBAAoB;AAAA,EACpB,uBACI;AAAA,EACJ,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,gBAAgB;AAAA,EAChB,SAAS;AACb;AAEO,IAAM,eAAN,MAAmB;AAAA,EACtB,OAAO,YACH,WACA,cACA,UACW;AACX,UAAM,gBAA6B;AAAA,MAC/B,MAAM;AAAA,MACN,SACI,gBACA,cAAc,SAAS,KACvB,cAAc,SAAS;AAAA,MAC3B,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,MAClC,OAAO,WACD;AAAA,QACI,MAAM,SAAS;AAAA,QACf,SAAS,SAAS;AAAA,QAClB,OAAO,SAAS,SAAS;AAAA,MAC7B,IACA;AAAA,IACV;AAGA,WAAO;AAAA,EACX;AACJ;;;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aAAa,SAAS,OAAO,GAAG,CAAC;AAAA,EAC7C;AACJ","sourcesContent":["import { IObjectStorage } from '../../../interfaces';\nimport {\n FileContent,\n ListResponse,\n UploadResponse,\n GetObjectResponse,\n ListRequestOptions,\n ListResponseItem,\n GetUploadUrlResponse,\n CreateUploadWriteStreamResponse,\n} from '../../../types';\nimport {\n BlobServiceClient,\n BlobSASPermissions,\n BlobItem,\n ContainerClient,\n} from '@azure/storage-blob';\n\nimport { Readable } from 'stream';\nimport { ErrorHandler } from '../../../shared/utils/errorHandler';\nimport { BlobPropertiesResponseToObjectResponse } from './blobHelpers';\nexport class BlobStorageService implements IObjectStorage {\n private blobServiceClient: BlobServiceClient;\n private containerName: string;\n\n /**\n * Retrieves the properties of a blob from the container by its name.\n *\n * @param {string} blobName - The name of the blob.\n * @return {Promise<GetObjectResponse>} A promise that resolves to the blob properties.\n */\n constructor(containerName: string) {\n this.containerName = containerName;\n this.blobServiceClient = BlobServiceClient.fromConnectionString(\n process.env.AZURE_STORAGE_CONNECTION_STRING!,\n );\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars\n createUploadWriteStream(key: string): CreateUploadWriteStreamResponse {\n throw new Error('Method not implemented.');\n }\n\n /**\n * Retrieves the properties of a blob from the container by its name.\n *\n * @param {string} blobName - The name of the blob.\n * @return {Promise<GetObjectResponse>} A promise that resolves to the blob properties.\n */\n async getHeadObject(blobName: string): Promise<GetObjectResponse> {\n try {\n const containerClient = this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n const blobProperties = await blockBlobClient.getProperties();\n return BlobPropertiesResponseToObjectResponse(blobProperties);\n } catch (error) {\n throw ErrorHandler.handleError('DEFAULT', '', error as Error);\n }\n }\n\n /**\n * Retrieves an object from the blob storage service.\n *\n * @param {string} blobName - The name of the blob to retrieve.\n * @return {Promise<GetObjectResponse>} A promise that resolves to the object data, including the body, metadata, content type, and content length, or rejects with an error if there was an issue.\n */\n async getObject(blobName: string): Promise<GetObjectResponse> {\n try {\n const containerClient = this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n const downloadBlockBlobResponse = await blockBlobClient.download(0);\n return {\n body: downloadBlockBlobResponse.readableStreamBody as Readable,\n metadata: downloadBlockBlobResponse.metadata,\n contentType: downloadBlockBlobResponse.contentType,\n contentLength: downloadBlockBlobResponse.contentLength,\n };\n } catch (error: any) {\n let errorKey = 'DEFAULT';\n if (error?.response?.status === 404) {\n errorKey = 'ObjectNotFound';\n }\n throw ErrorHandler.handleError(errorKey, '', error as Error);\n }\n }\n\n private async getSignatureUrl(\n blobName: string,\n expiresInMinutes: number,\n permissions: string,\n ): Promise<string> {\n try {\n const containerClient = this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n\n const startDate = new Date();\n const expiryDate = new Date(startDate);\n expiryDate.setMinutes(startDate.getMinutes() + expiresInMinutes);\n\n return blockBlobClient.generateSasUrl({\n permissions: BlobSASPermissions.parse(permissions),\n startsOn: startDate,\n expiresOn: expiryDate,\n });\n } catch (error) {\n throw ErrorHandler.handleError('DEFAULT', '', error as Error);\n }\n }\n\n async getUploadUrl(\n blobName: string,\n expiresInMinutes: number,\n ): Promise<GetUploadUrlResponse> {\n try {\n const sasUrl = await this.getSignatureUrl(\n blobName,\n expiresInMinutes,\n 'w',\n );\n return { key: blobName, signedUrl: sasUrl };\n } catch (error) {\n throw ErrorHandler.handleError('DEFAULT', '', error as Error);\n }\n }\n\n /**\n * Retrieves a signed URL for the blob with the specified name that expires after a certain period.\n *\n * @param {string} blobName - The name of the blob to generate the signed URL for.\n * @param {number} expiresInMinutes - The duration in minutes until the signed URL expires.\n * @return {Promise<string>} A Promise that resolves with the signed URL.\n */\n async getDownloadUrl(\n blobName: string,\n expiresInMinutes: number,\n ): Promise<string> {\n try {\n const sasUrl = await this.getSignatureUrl(\n blobName,\n expiresInMinutes,\n 'r',\n );\n return sasUrl;\n } catch (error) {\n throw ErrorHandler.handleError('DEFAULT', '', error as Error);\n }\n }\n\n /**\n * Uploads a file to the blob storage service.\n *\n * @param {string} blobName - The name of the blob to upload.\n * @param {FileContent} body - The content of the file to upload.\n * @param {{ [key: string]: string } | undefined} [metadata] - Optional metadata to associate with the blob.\n * @return {Promise<UploadResponse>} A promise that resolves to the response object containing the key of the uploaded blob, or rejects with an error if there was an issue.\n */\n async upload(\n blobName: string,\n body: FileContent,\n metadata: { [key: string]: string } = {},\n ): Promise<UploadResponse> {\n try {\n const containerClient = this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n Buffer.isBuffer(body)\n ? await blockBlobClient.upload(body, body.length, { metadata })\n : await blockBlobClient.uploadStream(\n body as Readable,\n undefined,\n undefined,\n { metadata },\n );\n\n return { key: blobName };\n } catch (error) {\n throw ErrorHandler.handleError('DEFAULT', '', error as Error);\n }\n }\n\n /**\n * Deletes a blob from the blob storage service.\n *\n * @param {string} blobName - The name of the blob to be deleted.\n * @return {Promise<boolean>} A promise that resolves to true if the blob is successfully deleted, or rejects with an error if there was an issue.\n */\n async delete(data: string): Promise<boolean> {\n try {\n const containerClient = this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n return this.deleteObject(containerClient, data);\n } catch (error) {\n throw ErrorHandler.handleError('DEFAULT', '', error as Error);\n }\n }\n\n /**\n * Lists a chunk of blobs from the specified container client based on the provided options and continuation token.\n *\n * @param {ListRequestOptions} options - The options for listing the blobs.\n * @param {string | undefined} continuationToken - The continuation token for pagination.\n * @param {number} limit - The maximum number of blobs to list in a single page.\n * @param {ContainerClient} containerClient - The container client to list the blobs from.\n * @return {Promise<{ items: BlobItem[]; continuationToken?: string }>} - A promise that resolves to an object containing the list of blob items and an optional continuation token.\n */\n private async listChunk(\n options: ListRequestOptions,\n continuationToken: string | undefined,\n limit: number,\n containerClient: ContainerClient,\n ): Promise<{ items: BlobItem[]; continuationToken?: string }> {\n const iterator = containerClient\n .listBlobsFlat({\n prefix: options.prefix,\n })\n .byPage({\n maxPageSize: limit,\n continuationToken: continuationToken,\n });\n\n const items: BlobItem[] = [];\n const response = (await iterator.next()).value;\n items.push(...response.segment.blobItems);\n return {\n items,\n continuationToken: response.continuationToken,\n };\n }\n\n /**\n * Retrieves a list of blob contents based on the provided options.\n *\n * @param {ListRequestOptions} options - The options for listing the blob contents.\n * @return {Promise<{ contents: BlobItem[]; nextContinuationToken?: string }>} A promise that resolves to the list of blob contents and the next continuation token.\n */\n private async listContents(\n options: ListRequestOptions,\n ): Promise<{ contents: BlobItem[]; nextContinuationToken?: string }> {\n let responseContents: BlobItem[] = [];\n let continuationToken: string | undefined = options.pagination;\n const limit = options.limit ?? 1000;\n let continueListing = true;\n const containerClient = this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n while (continueListing) {\n const response = await this.listChunk(\n options,\n continuationToken,\n limit - responseContents.length,\n containerClient,\n );\n continuationToken = response.continuationToken;\n responseContents = responseContents.concat(response.items);\n\n if (responseContents.length >= limit || !continuationToken) {\n continueListing = false;\n }\n }\n\n return {\n contents: responseContents,\n nextContinuationToken: continuationToken,\n };\n }\n\n /**\n * Lists blobs in the Azure Blob Storage container with pagination.\n * @param options - The options for listing blobs.\n * @returns A promise that resolves to a paginated list of blob names.\n */\n async list(options: ListRequestOptions): Promise<ListResponse> {\n let items: ListResponseItem[] = [];\n const response = await this.listContents(options);\n\n items = response.contents.length\n ? response.contents.map((blob) => {\n return {\n key: blob.name,\n lastModified: blob.properties.lastModified,\n size: blob.properties.contentLength!,\n eTag: blob.properties.etag,\n };\n })\n : [];\n\n return {\n items,\n pagination: response.nextContinuationToken?.length\n ? response.nextContinuationToken\n : null,\n count: items.length,\n };\n }\n\n /**\n * Lists all blobs in the Azure Blob Storage container.\n * @param options - The options for listing blobs.\n * @returns A promise that resolves to list of blob names.\n */\n async listAll(options: ListRequestOptions): Promise<ListResponse> {\n let allItems: ListResponseItem[] = [];\n let pagination: string | undefined = undefined;\n\n do {\n const response: ListResponse = await this.list({\n ...options,\n pagination,\n });\n\n if (response.items?.length)\n allItems = [...allItems, ...response.items];\n\n pagination = response.pagination ?? undefined;\n } while (pagination);\n\n return { items: allItems, count: allItems.length };\n }\n\n /**\n * Deletes a blob from the blob storage service.\n *\n * @param {string} blobName - The name of the blob to be deleted.\n * @return {Promise<boolean>} A promise that resolves to true if the blob is successfully deleted, or rejects with an error if there was an issue.\n */\n async deleteObject(\n containerClient: ContainerClient,\n blobName: string,\n ): Promise<boolean> {\n try {\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n await blockBlobClient.delete();\n return true;\n } catch (error) {\n throw ErrorHandler.handleError('DEFAULT', '', error as Error);\n }\n }\n\n async deleteObjects(\n blobNames: string[],\n ): Promise<{ key: string; deleted: boolean; error?: string }[]> {\n const containerClient = this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const deleteBlobPromises = blobNames.map(async (blobName) => {\n try {\n await this.deleteObject(containerClient, blobName);\n return { key: blobName, deleted: true };\n } catch (error: any) {\n return {\n key: blobName,\n deleted: false,\n error: error?.message ?? '',\n };\n }\n });\n return Promise.all(deleteBlobPromises);\n }\n}\n","import { CustomError } from '../../types/CustomError';\n\nconst errorMessages: { [key: string]: string } = {\n AccessDenied: 'Access denied',\n AccountProblem: 'There is a problem with your account',\n AllAccessDisabled: 'All access to this resource has been disabled',\n BucketAlreadyExists: 'The requested bucket name is not available',\n BucketNotEmpty: 'The bucket you tried to delete is not empty',\n EntityTooLarge: 'The entity you are trying to upload is too large',\n ExpiredToken: 'The provided token has expired',\n InternalError: 'An internal server error has occurred',\n InvalidAccessKeyId:\n 'The AWS access key ID you provided does not exist in our records',\n InvalidBucketName: 'The specified bucket name is not valid',\n InvalidObjectState:\n 'The operation is not valid for the current state of the object',\n InvalidToken: 'The provided token is invalid',\n NoSuchBucket: 'The specified bucket does not exist',\n NoSuchKey: 'The specified key does not exist',\n PreconditionFailed: 'The condition specified in the request is not met',\n RequestTimeout: 'The request timed out',\n ServiceUnavailable: 'The service is currently unavailable',\n SignatureDoesNotMatch:\n 'The request signature we calculated does not match the signature you provided',\n SlowDown: 'Please reduce your request rate',\n TemporaryRedirect: 'Temporary redirect',\n ObjectNotFound: 'ObjectNotFound - The specified key does not exist. (404)',\n DEFAULT: 'An unknown error occurred',\n};\n\nexport class ErrorHandler {\n static handleError(\n errorCode: string,\n errorMessage?: string,\n errorObj?: Error,\n ): CustomError {\n const errorResponse: CustomError = {\n code: errorCode,\n message:\n errorMessage ||\n errorMessages[errorCode] ||\n errorMessages['DEFAULT'],\n timestamp: new Date().toISOString(),\n error: errorObj\n ? {\n name: errorObj.name,\n message: errorObj.message,\n stack: errorObj.stack || null,\n }\n : null,\n };\n\n // Return the structured object\n return errorResponse;\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { GetObjectResponse } from '../../../types';\nimport { BlobGetPropertiesResponse } from '@azure/storage-blob';\n\nexport function BlobPropertiesResponseToObjectResponse(\n blobProperties: BlobGetPropertiesResponse,\n): GetObjectResponse {\n return {\n lastModified: blobProperties.lastModified,\n contentLength: blobProperties.contentLength,\n contentType: blobProperties.contentType,\n eTag: blobProperties.etag,\n metadata: blobProperties.metadata,\n contentEncoding: blobProperties.contentEncoding,\n cacheControl: blobProperties.cacheControl,\n contentDisposition: blobProperties.contentDisposition,\n contentLanguage: blobProperties.contentLanguage,\n };\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n DeleteObjectCommand,\n GetObjectCommand,\n HeadObjectCommand,\n ListObjectsV2Command,\n ListObjectsV2CommandOutput,\n PutObjectAclCommandInput,\n PutObjectCommand,\n S3Client,\n} from '@aws-sdk/client-s3';\nimport { IObjectStorage } from '../../../interfaces';\nimport {\n CreateUploadWriteStreamResponse,\n FileContent,\n GetObjectResponse,\n GetUploadUrlResponse,\n ListRequestOptions,\n ListResponse,\n ListResponseItem,\n UploadResponse,\n} from '../../../types';\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner';\nimport {\n listResponseContentsToListResponseItems,\n s3ObjectToObjectResponse,\n} from './s3Helpers';\nimport stream from 'stream';\nimport { Upload } from '@aws-sdk/lib-storage';\n\nexport class S3StorageService implements IObjectStorage {\n private s3Client: S3Client = new S3Client({\n region: process.env.AWS_REGION,\n });\n private bucketName: string;\n\n constructor(bucketName: string) {\n this.bucketName = bucketName;\n }\n\n /**\n * Retrieves a chunk of objects from the S3 bucket based on the provided options.\n *\n * @param {ListRequestOptions} options - The options for listing the objects.\n * @param {string | undefined} continuationToken - The continuation token for pagination.\n * @param {number} limit - The maximum number of objects to retrieve.\n * @return {Promise<ListObjectsV2CommandOutput>} - A promise that resolves to the response containing the list of objects and metadata.\n */\n private async listChunk(\n options: ListRequestOptions,\n continuationToken: string | undefined,\n limit: number,\n ): Promise<ListObjectsV2CommandOutput> {\n const command = new ListObjectsV2Command({\n Bucket: this.bucketName,\n ContinuationToken: continuationToken || options.pagination,\n Prefix: options.prefix,\n MaxKeys: limit,\n });\n\n return this.s3Client.send(command);\n }\n\n /**\n * Retrieves a list of contents from the S3 bucket based on the provided options.\n *\n * @param {ListRequestOptions} options - The options for listing the contents.\n * @return {Promise<{ contents: unknown[]; nextContinuationToken?: string }>} - A promise that resolves to an object containing the list of contents and an optional next continuation token.\n */\n private async listContents(\n options: ListRequestOptions,\n ): Promise<{ contents: unknown[]; nextContinuationToken?: string }> {\n let responseContents: any[] = [];\n let continuationToken: string | undefined = undefined;\n const limit = options.limit ?? 1000;\n let continueListing = true;\n while (continueListing) {\n const listChunkLimit = limit - responseContents.length;\n const response = await this.listChunk(\n options,\n continuationToken,\n listChunkLimit,\n );\n continuationToken = response.NextContinuationToken;\n responseContents = responseContents.concat(response.Contents ?? []);\n\n if (responseContents.length >= limit || !continuationToken) {\n continueListing = false;\n }\n }\n\n return {\n contents: responseContents,\n nextContinuationToken: continuationToken,\n };\n }\n\n /**\n * Lists objects in the S3 bucket with pagination.\n * @param options - The options for listing objects.\n * @returns A promise that resolves to a paginated list of object keys.\n */\n async list(options: ListRequestOptions): Promise<ListResponse> {\n let items: ListResponseItem[] = [];\n const response = await this.listContents(options);\n\n items = response.contents.length\n ? listResponseContentsToListResponseItems(response.contents)\n : [];\n\n return {\n items,\n pagination: response.nextContinuationToken ?? null,\n count: items.length,\n };\n }\n\n /**\n * Lists all objects in the S3 bucket.\n * @param options - The options for listing objects.\n * @returns A promise that resolves to list of object keys.\n */\n\n async listAll(options: ListRequestOptions): Promise<ListResponse> {\n let allItems: ListResponseItem[] = [];\n let pagination: string | undefined = undefined;\n\n do {\n const response: ListResponse = await this.list({\n ...options,\n pagination,\n });\n\n if (response.items?.length)\n allItems = [...allItems, ...response.items];\n\n pagination =\n response.pagination === null ? undefined : response.pagination;\n } while (pagination);\n\n return { items: allItems, count: allItems.length };\n }\n\n /**\n * Retrieves an object from the S3 bucket.\n * @param key - The key of the object to retrieve.\n * @returns A promise that resolves to the content of the file.\n */\n async getHeadObject(key: string): Promise<GetObjectResponse> {\n const command = new HeadObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n });\n const response = await this.s3Client.send(command);\n return s3ObjectToObjectResponse(response);\n }\n\n /**\n * Retrieves an object from the S3 bucket.\n * @param key - The key of the object to retrieve.\n * @returns A promise that resolves to the content of the file.\n */\n async getObject(key: string): Promise<GetObjectResponse> {\n const command = new GetObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n });\n const response = await this.s3Client.send(command);\n return s3ObjectToObjectResponse(response);\n }\n\n /**\n * Generates a signed URL for accessing an object in the S3 bucket.\n * @param key - The key of the object.\n * @param expiresInMinutes - The number of minutes the signed URL should be valid for. Defaults to 60 minutes.\n * @returns A promise that resolves to the signed URL.\n */\n getDownloadUrl(\n key: string,\n expiresInMinutes: number = 60,\n ): Promise<string> {\n const expiresIn = expiresInMinutes * 60;\n const command = new GetObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n });\n return getSignedUrl(this.s3Client, command, { expiresIn });\n }\n\n /**\n * Retrieves a signed URL for uploading an object to the S3 bucket.\n *\n * @param {string} key - The key of the object to be uploaded.\n * @param {number} [expiresInMinutes=60] - The number of minutes the signed URL should be valid for. Defaults to 60 minutes.\n * @returns A promise that resolves to the signed URL.\n */\n async getUploadUrl(\n key: string,\n expiresInMinutes: number = 60,\n ): Promise<GetUploadUrlResponse> {\n const expiresIn = expiresInMinutes * 60;\n\n const putObjectCommandParams: PutObjectAclCommandInput = {\n Bucket: process.env.UPLOAD_BUCKET_NAME,\n Key: key,\n ACL: 'private',\n };\n\n const command = new PutObjectCommand(putObjectCommandParams);\n\n const signedUrl = await getSignedUrl(this.s3Client, command, {\n expiresIn,\n });\n\n return {\n signedUrl,\n key: `https://${process.env.UPLOAD_BUCKET_NAME}.s3.${process.env.AWS_DEFAULT_REGION}.amazonaws.com/${key}`,\n };\n }\n\n /**\n * Uploads an object to the S3 bucket.\n * @param key - The key of the object to upload.\n * @param body - The content of the object to upload.\n * @param metadata - Optional metadata to associate with the object.\n * @returns A promise that resolves to the response containing the key of the uploaded object.\n */\n async upload(\n key: string,\n body: FileContent,\n metadata?: { [key: string]: string },\n ): Promise<UploadResponse> {\n const command = new PutObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n Body: body,\n Metadata: metadata,\n });\n await this.s3Client.send(command);\n return { key };\n }\n\n /**\n * Creates a writable stream for uploading a file to the S3 bucket.\n *\n * @param {string} key - The key of the object to upload.\n * @return {CreateUploadWriteStreamResponse} An object containing the key of the uploaded object, the writable stream, and a promise that resolves when the upload is complete.\n */\n createUploadWriteStream(key: string): CreateUploadWriteStreamResponse {\n const streamPassThrough = new stream.PassThrough();\n const params = {\n Bucket: this.bucketName,\n Key: key,\n Body: streamPassThrough,\n };\n\n const upload = new Upload({\n client: this.s3Client,\n params,\n });\n\n return {\n key,\n stream: streamPassThrough,\n promise: upload.done(),\n };\n }\n\n /**\n * Deletes an object from the S3 bucket.\n * @param key - The key of the object to delete.\n * @returns A promise that resolves to true if the object was deleted successfully.\n */\n async delete(key: string): Promise<boolean> {\n const command = new DeleteObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n });\n await this.s3Client.send(command);\n return true;\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { GetObjectCommandOutput } from '@aws-sdk/client-s3';\nimport { GetObjectResponse, ListResponseItem } from '../../../types';\nimport { Readable } from 'stream';\n\n/**\n * Converts an array of S3 response contents into an array of ListResponseItem objects.\n *\n * @param {any[]} responseContents - The array of S3 response contents.\n * @return {ListResponseItem[]} The array of ListResponseItem objects.\n */\nexport function listResponseContentsToListResponseItems(\n responseContents: any[],\n): ListResponseItem[] {\n return responseContents.map((responseContent) => {\n return {\n key: responseContent.Key,\n lastModified: new Date(responseContent.LastModified),\n size: responseContent.Size,\n eTag: responseContent.ETag,\n };\n });\n}\n\n/**\n * Converts an S3 object response to a standardized object response.\n *\n * @param {GetObjectCommandOutput} s3Object - The S3 object response to convert.\n * @return {GetObjectResponse} The converted object response.\n */\nexport function s3ObjectToObjectResponse(\n s3Object: GetObjectCommandOutput,\n): GetObjectResponse {\n return {\n body: s3Object.Body as Readable,\n metadata: s3Object.Metadata,\n contentType: s3Object.ContentType,\n contentLength: s3Object.ContentLength as number,\n contentEncoding: s3Object.ContentEncoding,\n cacheControl: s3Object.CacheControl,\n contentDisposition: s3Object.ContentDisposition,\n contentLanguage: s3Object.ContentLanguage,\n eTag: s3Object.ETag,\n lastModified: s3Object.LastModified,\n };\n}\n","import { IObjectStorage } from '../interfaces';\nimport { S3StorageService, BlobStorageService } from './storage';\n\nexport class ObjectStorageFactory {\n static async instance(bucketName: string): Promise<IObjectStorage> {\n const isBlobStorageService =\n process.env.OBJECT_STORAGE_SERVICE?.toLowerCase() ===\n 'azure_blob_storage';\n\n if (isBlobStorageService) {\n return new BlobStorageService(bucketName);\n } else {\n return new S3StorageService(bucketName);\n }\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { IObjectStorage } from '../interfaces';\nimport {\n ListResponse,\n FileContent,\n UploadResponse,\n GetObjectResponse,\n ListRequestOptions,\n GetUploadUrlResponse,\n CreateUploadWriteStreamResponse,\n} from '../types';\nimport { ObjectStorageFactory } from '../services/objectStorageFactory.service';\n\nexport default class ObjectStorageService {\n static bucketName: string;\n\n constructor(bucketName: string) {\n ObjectStorageService.bucketName = bucketName;\n }\n\n static async getObjectStorageServiceInstance(\n bucketName: string = ObjectStorageService.bucketName,\n ): Promise<IObjectStorage> {\n if (!bucketName)\n throw new Error('Bucket name not provided or not valid value');\n return ObjectStorageFactory.instance(bucketName);\n }\n\n /**\n * Retrieves a list of objects from the object storage service.\n *\n * @param {ListRequestOptions} options - The options to apply to the list operation.\n * @param {string} [bucketName] - The name of the bucket to list objects from. If not provided, the default bucket name will be used.\n * @return {Promise<ListResponse>} A promise that resolves to the list of objects.\n */\n static async list(\n options: ListRequestOptions,\n bucketName?: string,\n ): Promise<ListResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.list(options));\n }\n\n /**\n * Retrieves a list of all objects from the object storage service.\n *\n * @param {ListRequestOptions} options - The options to apply to the list operation.\n * @param {string} [bucketName] - The name of the bucket to list objects from. If not provided, the default bucket name will be used.\n * @return {Promise<ListResponse>} A promise that resolves to the list of all objects.\n */\n static async listAll(\n options: ListRequestOptions,\n bucketName?: string,\n ): Promise<ListResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.listAll(options));\n }\n\n /**\n * Retrieves an object from the object storage service.\n *\n * @param {string} key - The key of the object to retrieve.\n * @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.\n * @return {Promise<GetObjectResponse>} A promise that resolves to the retrieved object.\n */\n static async getObject(\n key: string,\n bucketName?: string,\n ): Promise<GetObjectResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.getObject(key));\n }\n\n /**\n * Retrieves a signed URL for the specified object in the object storage service.\n *\n * @param {string} key - The key of the object for which to generate the signed URL.\n * @param {number} expiresInMinutes - The number of minutes until the signed URL expires.\n * @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.\n * @return {Promise<string>} A promise that resolves to the generated signed URL.\n */\n static async getDownloadUrl(\n key: string,\n expiresInMinutes: number,\n bucketName?: string,\n ): Promise<string> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.getDownloadUrl(key, expiresInMinutes));\n }\n\n /**\n * Retrieves an upload URL for the specified object in the object storage service.\n *\n * @param {string} key - The key of the object for which to generate the upload URL.\n * @param {number} expiresInMinutes - The number of minutes until the upload URL expires.\n * @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.\n * @return {Promise<string>} A promise that resolves to the generated upload URL.\n */\n static async getUploadUrl(\n key: string,\n expiresInMinutes: number,\n bucketName?: string,\n ): Promise<GetUploadUrlResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.getUploadUrl(key, expiresInMinutes));\n }\n\n /**\n * Uploads a file to the object storage service.\n *\n * @param {string} key - The key of the object to upload.\n * @param {FileContent} body - The content of the file to upload.\n * @param {Object} [metadata] - Optional metadata to associate with the object.\n * @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.\n * @return {Promise<UploadResponse>} A promise that resolves to the response of the upload operation.\n */\n static async upload(\n key: string,\n body: FileContent,\n metadata?: { [key: string]: string },\n bucketName?: string,\n ): Promise<UploadResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.upload(key, body, metadata));\n }\n\n /**\n * Creates an upload write stream for the specified key in the object storage service.\n *\n * @param {string} key - The key of the object to create the upload write stream for.\n * @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.\n * @return {Promise<CreateUploadWriteStreamResponse>} A promise that resolves to the response of the upload operation.\n */\n static async createUploadWriteStream(\n key: string,\n bucketName?: string,\n ): Promise<CreateUploadWriteStreamResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.createUploadWriteStream(key));\n }\n\n /**\n * Deletes an object from the object storage service.\n *\n * @param {string} key - The key of the object to delete.\n * @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.\n * @return {Promise<boolean>} A promise that resolves to true if the object was successfully deleted, or false otherwise.\n */\n static async delete(key: string, bucketName?: string): Promise<boolean> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.delete(key));\n }\n}\n"]}
@@ -4,7 +4,7 @@ type UploadResponse = {
4
4
  key: string;
5
5
  };
6
6
 
7
- type FileContent = Readable | ReadableStream | Blob;
7
+ type FileContent = Readable | ReadableStream | Blob | Buffer;
8
8
 
9
9
  type ListRequestOptions = {
10
10
  prefix?: string;
@@ -46,6 +46,7 @@ var errorMessages = {
46
46
  SignatureDoesNotMatch: "The request signature we calculated does not match the signature you provided",
47
47
  SlowDown: "Please reduce your request rate",
48
48
  TemporaryRedirect: "Temporary redirect",
49
+ ObjectNotFound: "ObjectNotFound - The specified key does not exist. (404)",
49
50
  DEFAULT: "An unknown error occurred"
50
51
  };
51
52
  var ErrorHandler = class {
@@ -97,43 +98,23 @@ var BlobStorageService = class {
97
98
  createUploadWriteStream(key) {
98
99
  throw new Error("Method not implemented.");
99
100
  }
100
- getUploadUrl(key, expiresInMinutes) {
101
- throw new Error("Method not implemented.");
102
- }
103
101
  /**
104
102
  * Retrieves the properties of a blob from the container by its name.
105
103
  *
106
104
  * @param {string} blobName - The name of the blob.
107
105
  * @return {Promise<GetObjectResponse>} A promise that resolves to the blob properties.
108
106
  */
109
- getHeadObject(blobName) {
110
- return new Promise((resolve, reject) => {
111
- try {
112
- const containerClient = this.blobServiceClient.getContainerClient(
113
- this.containerName
114
- );
115
- const blockBlobClient = containerClient.getBlockBlobClient(blobName);
116
- blockBlobClient.getProperties().then((blobProperties) => {
117
- return resolve(
118
- BlobPropertiesResponseToObjectResponse(
119
- blobProperties
120
- )
121
- );
122
- }).catch(
123
- (error) => reject(
124
- ErrorHandler.handleError(
125
- "DEFAULT",
126
- "",
127
- error
128
- )
129
- )
130
- );
131
- } catch (error) {
132
- return reject(
133
- ErrorHandler.handleError("DEFAULT", "", error)
134
- );
135
- }
136
- });
107
+ async getHeadObject(blobName) {
108
+ try {
109
+ const containerClient = this.blobServiceClient.getContainerClient(
110
+ this.containerName
111
+ );
112
+ const blockBlobClient = containerClient.getBlockBlobClient(blobName);
113
+ const blobProperties = await blockBlobClient.getProperties();
114
+ return BlobPropertiesResponseToObjectResponse(blobProperties);
115
+ } catch (error) {
116
+ throw ErrorHandler.handleError("DEFAULT", "", error);
117
+ }
137
118
  }
138
119
  /**
139
120
  * Retrieves an object from the blob storage service.
@@ -141,35 +122,57 @@ var BlobStorageService = class {
141
122
  * @param {string} blobName - The name of the blob to retrieve.
142
123
  * @return {Promise<GetObjectResponse>} A promise that resolves to the object data, including the body, metadata, content type, and content length, or rejects with an error if there was an issue.
143
124
  */
144
- getObject(blobName) {
145
- return new Promise((resolve, reject) => {
146
- try {
147
- const containerClient = this.blobServiceClient.getContainerClient(
148
- this.containerName
149
- );
150
- const blockBlobClient = containerClient.getBlockBlobClient(blobName);
151
- blockBlobClient.download(0).then((downloadBlockBlobResponse) => {
152
- return resolve({
153
- body: downloadBlockBlobResponse.readableStreamBody,
154
- metadata: {},
155
- contentType: "",
156
- contentLength: 0
157
- });
158
- }).catch(
159
- (error) => reject(
160
- ErrorHandler.handleError(
161
- "DEFAULT",
162
- "",
163
- error
164
- )
165
- )
166
- );
167
- } catch (error) {
168
- return reject(
169
- ErrorHandler.handleError("DEFAULT", "", error)
170
- );
125
+ async getObject(blobName) {
126
+ var _a;
127
+ try {
128
+ const containerClient = this.blobServiceClient.getContainerClient(
129
+ this.containerName
130
+ );
131
+ const blockBlobClient = containerClient.getBlockBlobClient(blobName);
132
+ const downloadBlockBlobResponse = await blockBlobClient.download(0);
133
+ return {
134
+ body: downloadBlockBlobResponse.readableStreamBody,
135
+ metadata: downloadBlockBlobResponse.metadata,
136
+ contentType: downloadBlockBlobResponse.contentType,
137
+ contentLength: downloadBlockBlobResponse.contentLength
138
+ };
139
+ } catch (error) {
140
+ let errorKey = "DEFAULT";
141
+ if (((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.status) === 404) {
142
+ errorKey = "ObjectNotFound";
171
143
  }
172
- });
144
+ throw ErrorHandler.handleError(errorKey, "", error);
145
+ }
146
+ }
147
+ async getSignatureUrl(blobName, expiresInMinutes, permissions) {
148
+ try {
149
+ const containerClient = this.blobServiceClient.getContainerClient(
150
+ this.containerName
151
+ );
152
+ const blockBlobClient = containerClient.getBlockBlobClient(blobName);
153
+ const startDate = /* @__PURE__ */ new Date();
154
+ const expiryDate = new Date(startDate);
155
+ expiryDate.setMinutes(startDate.getMinutes() + expiresInMinutes);
156
+ return blockBlobClient.generateSasUrl({
157
+ permissions: BlobSASPermissions.parse(permissions),
158
+ startsOn: startDate,
159
+ expiresOn: expiryDate
160
+ });
161
+ } catch (error) {
162
+ throw ErrorHandler.handleError("DEFAULT", "", error);
163
+ }
164
+ }
165
+ async getUploadUrl(blobName, expiresInMinutes) {
166
+ try {
167
+ const sasUrl = await this.getSignatureUrl(
168
+ blobName,
169
+ expiresInMinutes,
170
+ "w"
171
+ );
172
+ return { key: blobName, signedUrl: sasUrl };
173
+ } catch (error) {
174
+ throw ErrorHandler.handleError("DEFAULT", "", error);
175
+ }
173
176
  }
174
177
  /**
175
178
  * Retrieves a signed URL for the blob with the specified name that expires after a certain period.
@@ -178,37 +181,17 @@ var BlobStorageService = class {
178
181
  * @param {number} expiresInMinutes - The duration in minutes until the signed URL expires.
179
182
  * @return {Promise<string>} A Promise that resolves with the signed URL.
180
183
  */
181
- getDownloadUrl(blobName, expiresInMinutes) {
182
- return new Promise((resolve, reject) => {
183
- try {
184
- const containerClient = this.blobServiceClient.getContainerClient(
185
- this.containerName
186
- );
187
- const blockBlobClient = containerClient.getBlockBlobClient(blobName);
188
- const startDate = /* @__PURE__ */ new Date();
189
- const expiryDate = new Date(startDate);
190
- expiryDate.setMinutes(
191
- startDate.getMinutes() + expiresInMinutes
192
- );
193
- blockBlobClient.generateSasUrl({
194
- permissions: BlobSASPermissions.parse("r"),
195
- startsOn: startDate,
196
- expiresOn: expiryDate
197
- }).then((sasUrl) => resolve(sasUrl)).catch(
198
- (error) => reject(
199
- ErrorHandler.handleError(
200
- "DEFAULT",
201
- "",
202
- error
203
- )
204
- )
205
- );
206
- } catch (error) {
207
- return reject(
208
- ErrorHandler.handleError("DEFAULT", "", error)
209
- );
210
- }
211
- });
184
+ async getDownloadUrl(blobName, expiresInMinutes) {
185
+ try {
186
+ const sasUrl = await this.getSignatureUrl(
187
+ blobName,
188
+ expiresInMinutes,
189
+ "r"
190
+ );
191
+ return sasUrl;
192
+ } catch (error) {
193
+ throw ErrorHandler.handleError("DEFAULT", "", error);
194
+ }
212
195
  }
213
196
  /**
214
197
  * Uploads a file to the blob storage service.
@@ -218,33 +201,22 @@ var BlobStorageService = class {
218
201
  * @param {{ [key: string]: string } | undefined} [metadata] - Optional metadata to associate with the blob.
219
202
  * @return {Promise<UploadResponse>} A promise that resolves to the response object containing the key of the uploaded blob, or rejects with an error if there was an issue.
220
203
  */
221
- upload(blobName, body, metadata) {
222
- return new Promise((resolve, reject) => {
223
- try {
224
- const containerClient = this.blobServiceClient.getContainerClient(
225
- this.containerName
226
- );
227
- const blockBlobClient = containerClient.getBlockBlobClient(blobName);
228
- blockBlobClient.uploadStream(
229
- body,
230
- void 0,
231
- void 0,
232
- metadata
233
- ).then(() => resolve({ key: blobName })).catch(
234
- (error) => reject(
235
- ErrorHandler.handleError(
236
- "DEFAULT",
237
- "",
238
- error
239
- )
240
- )
241
- );
242
- } catch (error) {
243
- return reject(
244
- ErrorHandler.handleError("DEFAULT", "", error)
245
- );
246
- }
247
- });
204
+ async upload(blobName, body, metadata = {}) {
205
+ try {
206
+ const containerClient = this.blobServiceClient.getContainerClient(
207
+ this.containerName
208
+ );
209
+ const blockBlobClient = containerClient.getBlockBlobClient(blobName);
210
+ Buffer.isBuffer(body) ? await blockBlobClient.upload(body, body.length, { metadata }) : await blockBlobClient.uploadStream(
211
+ body,
212
+ void 0,
213
+ void 0,
214
+ { metadata }
215
+ );
216
+ return { key: blobName };
217
+ } catch (error) {
218
+ throw ErrorHandler.handleError("DEFAULT", "", error);
219
+ }
248
220
  }
249
221
  /**
250
222
  * Deletes a blob from the blob storage service.
@@ -252,28 +224,15 @@ var BlobStorageService = class {
252
224
  * @param {string} blobName - The name of the blob to be deleted.
253
225
  * @return {Promise<boolean>} A promise that resolves to true if the blob is successfully deleted, or rejects with an error if there was an issue.
254
226
  */
255
- delete(blobName) {
256
- return new Promise((resolve, reject) => {
257
- try {
258
- const containerClient = this.blobServiceClient.getContainerClient(
259
- this.containerName
260
- );
261
- const blockBlobClient = containerClient.getBlockBlobClient(blobName);
262
- blockBlobClient.delete().then(() => resolve(true)).catch(
263
- (error) => reject(
264
- ErrorHandler.handleError(
265
- "DEFAULT",
266
- "",
267
- error
268
- )
269
- )
270
- );
271
- } catch (error) {
272
- return reject(
273
- ErrorHandler.handleError("DEFAULT", "", error)
274
- );
275
- }
276
- });
227
+ async delete(data) {
228
+ try {
229
+ const containerClient = this.blobServiceClient.getContainerClient(
230
+ this.containerName
231
+ );
232
+ return this.deleteObject(containerClient, data);
233
+ } catch (error) {
234
+ throw ErrorHandler.handleError("DEFAULT", "", error);
235
+ }
277
236
  }
278
237
  /**
279
238
  * Lists a chunk of blobs from the specified container client based on the provided options and continuation token.
@@ -374,6 +333,40 @@ var BlobStorageService = class {
374
333
  } while (pagination);
375
334
  return { items: allItems, count: allItems.length };
376
335
  }
336
+ /**
337
+ * Deletes a blob from the blob storage service.
338
+ *
339
+ * @param {string} blobName - The name of the blob to be deleted.
340
+ * @return {Promise<boolean>} A promise that resolves to true if the blob is successfully deleted, or rejects with an error if there was an issue.
341
+ */
342
+ async deleteObject(containerClient, blobName) {
343
+ try {
344
+ const blockBlobClient = containerClient.getBlockBlobClient(blobName);
345
+ await blockBlobClient.delete();
346
+ return true;
347
+ } catch (error) {
348
+ throw ErrorHandler.handleError("DEFAULT", "", error);
349
+ }
350
+ }
351
+ async deleteObjects(blobNames) {
352
+ const containerClient = this.blobServiceClient.getContainerClient(
353
+ this.containerName
354
+ );
355
+ const deleteBlobPromises = blobNames.map(async (blobName) => {
356
+ var _a;
357
+ try {
358
+ await this.deleteObject(containerClient, blobName);
359
+ return { key: blobName, deleted: true };
360
+ } catch (error) {
361
+ return {
362
+ key: blobName,
363
+ deleted: false,
364
+ error: (_a = error == null ? void 0 : error.message) != null ? _a : ""
365
+ };
366
+ }
367
+ });
368
+ return Promise.all(deleteBlobPromises);
369
+ }
377
370
  };
378
371
 
379
372
  // src/services/storage/s3/s3Helpers.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/services/storage/blob/blobStorage.service.ts","../../src/shared/utils/errorHandler.ts","../../src/services/storage/blob/blobHelpers.ts","../../src/services/storage/s3/s3Storage.service.ts","../../src/services/storage/s3/s3Helpers.ts","../../src/services/objectStorageFactory.service.ts","../../src/services/objectStorage.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAWA;AAAA,EACI;AAAA,EACA;AAAA,OAGG;;;ACdP,IAAM,gBAA2C;AAAA,EAC7C,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,mBAAmB;AAAA,EACnB,qBAAqB;AAAA,EACrB,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,eAAe;AAAA,EACf,oBACI;AAAA,EACJ,mBAAmB;AAAA,EACnB,oBACI;AAAA,EACJ,cAAc;AAAA,EACd,cAAc;AAAA,EACd,WAAW;AAAA,EACX,oBAAoB;AAAA,EACpB,gBAAgB;AAAA,EAChB,oBAAoB;AAAA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C;AACxC,WAAO,sBAAqB;AAAA,MACxB;AAAA,IACJ,EAAE,KAAK,CAAC,aAAa,SAAS,wBAAwB,GAAG,CAAC;AAAA,EAC9D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,aAAa,OAAO,KAAa,YAAuC;AACpE,WAAO,sBAAqB;AAAA,MACxB;AAAA,IACJ,EAAE,KAAK,CAAC,aAAa,SAAS,OAAO,GAAG,CAAC;AAAA,EAC7C;AACJ","sourcesContent":["import { IObjectStorage } from '../../../interfaces';\nimport {\n FileContent,\n ListResponse,\n UploadResponse,\n GetObjectResponse,\n ListRequestOptions,\n ListResponseItem,\n GetUploadUrlResponse,\n CreateUploadWriteStreamResponse,\n} from '../../../types';\nimport {\n BlobServiceClient,\n BlobSASPermissions,\n BlobItem,\n ContainerClient,\n} from '@azure/storage-blob';\n\nimport { Readable } from 'stream';\nimport { ErrorHandler } from '../../../shared/utils/errorHandler';\nimport { BlobPropertiesResponseToObjectResponse } from './blobHelpers';\nexport class BlobStorageService implements IObjectStorage {\n private blobServiceClient: BlobServiceClient;\n private containerName: string;\n\n /**\n * Retrieves the properties of a blob from the container by its name.\n *\n * @param {string} blobName - The name of the blob.\n * @return {Promise<GetObjectResponse>} A promise that resolves to the blob properties.\n */\n constructor(containerName: string) {\n this.containerName = containerName;\n this.blobServiceClient = BlobServiceClient.fromConnectionString(\n process.env.AZURE_STORAGE_CONNECTION_STRING!,\n );\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars\n createUploadWriteStream(key: string): CreateUploadWriteStreamResponse {\n throw new Error('Method not implemented.');\n }\n getUploadUrl(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars\n key: string,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars\n expiresInMinutes: number,\n ): Promise<GetUploadUrlResponse> {\n throw new Error('Method not implemented.');\n }\n\n /**\n * Retrieves the properties of a blob from the container by its name.\n *\n * @param {string} blobName - The name of the blob.\n * @return {Promise<GetObjectResponse>} A promise that resolves to the blob properties.\n */\n getHeadObject(blobName: string): Promise<GetObjectResponse> {\n return new Promise((resolve, reject) => {\n try {\n const containerClient =\n this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n blockBlobClient\n .getProperties()\n .then((blobProperties) => {\n return resolve(\n BlobPropertiesResponseToObjectResponse(\n blobProperties,\n ),\n );\n })\n .catch((error) =>\n reject(\n ErrorHandler.handleError(\n 'DEFAULT',\n '',\n error as Error,\n ),\n ),\n );\n } catch (error) {\n return reject(\n ErrorHandler.handleError('DEFAULT', '', error as Error),\n );\n }\n });\n }\n\n /**\n * Retrieves an object from the blob storage service.\n *\n * @param {string} blobName - The name of the blob to retrieve.\n * @return {Promise<GetObjectResponse>} A promise that resolves to the object data, including the body, metadata, content type, and content length, or rejects with an error if there was an issue.\n */\n getObject(blobName: string): Promise<GetObjectResponse> {\n return new Promise((resolve, reject) => {\n try {\n const containerClient =\n this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n blockBlobClient\n .download(0)\n .then((downloadBlockBlobResponse) => {\n return resolve({\n body: downloadBlockBlobResponse.readableStreamBody as Readable,\n metadata: {},\n contentType: '',\n contentLength: 0,\n });\n })\n .catch((error) =>\n reject(\n ErrorHandler.handleError(\n 'DEFAULT',\n '',\n error as Error,\n ),\n ),\n );\n } catch (error) {\n return reject(\n ErrorHandler.handleError('DEFAULT', '', error as Error),\n );\n }\n });\n }\n\n /**\n * Retrieves a signed URL for the blob with the specified name that expires after a certain period.\n *\n * @param {string} blobName - The name of the blob to generate the signed URL for.\n * @param {number} expiresInMinutes - The duration in minutes until the signed URL expires.\n * @return {Promise<string>} A Promise that resolves with the signed URL.\n */\n getDownloadUrl(\n blobName: string,\n expiresInMinutes: number,\n ): Promise<string> {\n return new Promise((resolve, reject) => {\n try {\n const containerClient =\n this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n\n const startDate = new Date();\n const expiryDate = new Date(startDate);\n expiryDate.setMinutes(\n startDate.getMinutes() + expiresInMinutes,\n );\n\n blockBlobClient\n .generateSasUrl({\n permissions: BlobSASPermissions.parse('r'),\n startsOn: startDate,\n expiresOn: expiryDate,\n })\n .then((sasUrl) => resolve(sasUrl))\n .catch((error) =>\n reject(\n ErrorHandler.handleError(\n 'DEFAULT',\n '',\n error as Error,\n ),\n ),\n );\n } catch (error) {\n return reject(\n ErrorHandler.handleError('DEFAULT', '', error as Error),\n );\n }\n });\n }\n\n /**\n * Uploads a file to the blob storage service.\n *\n * @param {string} blobName - The name of the blob to upload.\n * @param {FileContent} body - The content of the file to upload.\n * @param {{ [key: string]: string } | undefined} [metadata] - Optional metadata to associate with the blob.\n * @return {Promise<UploadResponse>} A promise that resolves to the response object containing the key of the uploaded blob, or rejects with an error if there was an issue.\n */\n upload(\n blobName: string,\n body: FileContent,\n metadata?: { [key: string]: string } | undefined,\n ): Promise<UploadResponse> {\n return new Promise((resolve, reject) => {\n try {\n const containerClient =\n this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n\n blockBlobClient\n .uploadStream(\n body as Readable,\n undefined,\n undefined,\n metadata,\n )\n .then(() => resolve({ key: blobName }))\n .catch((error) =>\n reject(\n ErrorHandler.handleError(\n 'DEFAULT',\n '',\n error as Error,\n ),\n ),\n );\n } catch (error) {\n return reject(\n ErrorHandler.handleError('DEFAULT', '', error as Error),\n );\n }\n });\n }\n\n /**\n * Deletes a blob from the blob storage service.\n *\n * @param {string} blobName - The name of the blob to be deleted.\n * @return {Promise<boolean>} A promise that resolves to true if the blob is successfully deleted, or rejects with an error if there was an issue.\n */\n delete(blobName: string): Promise<boolean> {\n return new Promise((resolve, reject) => {\n try {\n const containerClient =\n this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n blockBlobClient\n .delete()\n .then(() => resolve(true))\n .catch((error) =>\n reject(\n ErrorHandler.handleError(\n 'DEFAULT',\n '',\n error as Error,\n ),\n ),\n );\n } catch (error) {\n return reject(\n ErrorHandler.handleError('DEFAULT', '', error as Error),\n );\n }\n });\n }\n\n /**\n * Lists a chunk of blobs from the specified container client based on the provided options and continuation token.\n *\n * @param {ListRequestOptions} options - The options for listing the blobs.\n * @param {string | undefined} continuationToken - The continuation token for pagination.\n * @param {number} limit - The maximum number of blobs to list in a single page.\n * @param {ContainerClient} containerClient - The container client to list the blobs from.\n * @return {Promise<{ items: BlobItem[]; continuationToken?: string }>} - A promise that resolves to an object containing the list of blob items and an optional continuation token.\n */\n private async listChunk(\n options: ListRequestOptions,\n continuationToken: string | undefined,\n limit: number,\n containerClient: ContainerClient,\n ): Promise<{ items: BlobItem[]; continuationToken?: string }> {\n const iterator = containerClient\n .listBlobsFlat({\n prefix: options.prefix,\n })\n .byPage({\n maxPageSize: limit,\n continuationToken: continuationToken,\n });\n\n const items: BlobItem[] = [];\n const response = (await iterator.next()).value;\n items.push(...response.segment.blobItems);\n return {\n items,\n continuationToken: response.continuationToken,\n };\n }\n\n /**\n * Retrieves a list of blob contents based on the provided options.\n *\n * @param {ListRequestOptions} options - The options for listing the blob contents.\n * @return {Promise<{ contents: BlobItem[]; nextContinuationToken?: string }>} A promise that resolves to the list of blob contents and the next continuation token.\n */\n private async listContents(\n options: ListRequestOptions,\n ): Promise<{ contents: BlobItem[]; nextContinuationToken?: string }> {\n let responseContents: BlobItem[] = [];\n let continuationToken: string | undefined = options.pagination;\n const limit = options.limit ?? 1000;\n let continueListing = true;\n const containerClient = this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n while (continueListing) {\n const response = await this.listChunk(\n options,\n continuationToken,\n limit - responseContents.length,\n containerClient,\n );\n continuationToken = response.continuationToken;\n responseContents = responseContents.concat(response.items);\n\n if (responseContents.length >= limit || !continuationToken) {\n continueListing = false;\n }\n }\n\n return {\n contents: responseContents,\n nextContinuationToken: continuationToken,\n };\n }\n\n /**\n * Lists blobs in the Azure Blob Storage container with pagination.\n * @param options - The options for listing blobs.\n * @returns A promise that resolves to a paginated list of blob names.\n */\n async list(options: ListRequestOptions): Promise<ListResponse> {\n let items: ListResponseItem[] = [];\n const response = await this.listContents(options);\n\n items = response.contents.length\n ? response.contents.map((blob) => {\n return {\n key: blob.name,\n lastModified: blob.properties.lastModified,\n size: blob.properties.contentLength!,\n eTag: blob.properties.etag,\n };\n })\n : [];\n\n return {\n items,\n pagination: response.nextContinuationToken?.length\n ? response.nextContinuationToken\n : null,\n count: items.length,\n };\n }\n\n /**\n * Lists all blobs in the Azure Blob Storage container.\n * @param options - The options for listing blobs.\n * @returns A promise that resolves to list of blob names.\n */\n async listAll(options: ListRequestOptions): Promise<ListResponse> {\n let allItems: ListResponseItem[] = [];\n let pagination: string | undefined = undefined;\n\n do {\n const response: ListResponse = await this.list({\n ...options,\n pagination,\n });\n\n if (response.items?.length)\n allItems = [...allItems, ...response.items];\n\n pagination = response.pagination ?? undefined;\n } while (pagination);\n\n return { items: allItems, count: allItems.length };\n }\n}\n","import { CustomError } from '../../types/CustomError';\n\nconst errorMessages: { [key: string]: string } = {\n AccessDenied: 'Access denied',\n AccountProblem: 'There is a problem with your account',\n AllAccessDisabled: 'All access to this resource has been disabled',\n BucketAlreadyExists: 'The requested bucket name is not available',\n BucketNotEmpty: 'The bucket you tried to delete is not empty',\n EntityTooLarge: 'The entity you are trying to upload is too large',\n ExpiredToken: 'The provided token has expired',\n InternalError: 'An internal server error has occurred',\n InvalidAccessKeyId:\n 'The AWS access key ID you provided does not exist in our records',\n InvalidBucketName: 'The specified bucket name is not valid',\n InvalidObjectState:\n 'The operation is not valid for the current state of the object',\n InvalidToken: 'The provided token is invalid',\n NoSuchBucket: 'The specified bucket does not exist',\n NoSuchKey: 'The specified key does not exist',\n PreconditionFailed: 'The condition specified in the request is not met',\n RequestTimeout: 'The request timed out',\n ServiceUnavailable: 'The service is currently unavailable',\n SignatureDoesNotMatch:\n 'The request signature we calculated does not match the signature you provided',\n SlowDown: 'Please reduce your request rate',\n TemporaryRedirect: 'Temporary redirect',\n DEFAULT: 'An unknown error occurred',\n};\n\nexport class ErrorHandler {\n static handleError(\n errorCode: string,\n errorMessage?: string,\n errorObj?: Error,\n ): CustomError {\n const errorResponse: CustomError = {\n code: errorCode,\n message:\n errorMessage ||\n errorMessages[errorCode] ||\n errorMessages['DEFAULT'],\n timestamp: new Date().toISOString(),\n error: errorObj\n ? {\n name: errorObj.name,\n message: errorObj.message,\n stack: errorObj.stack || null,\n }\n : null,\n };\n\n // Return the structured object\n return errorResponse;\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { GetObjectResponse } from '../../../types';\nimport { BlobGetPropertiesResponse } from '@azure/storage-blob';\n\nexport function BlobPropertiesResponseToObjectResponse(\n blobProperties: BlobGetPropertiesResponse,\n): GetObjectResponse {\n return {\n lastModified: blobProperties.lastModified,\n contentLength: blobProperties.contentLength,\n contentType: blobProperties.contentType,\n eTag: blobProperties.etag,\n metadata: blobProperties.metadata,\n contentEncoding: blobProperties.contentEncoding,\n cacheControl: blobProperties.cacheControl,\n contentDisposition: blobProperties.contentDisposition,\n contentLanguage: blobProperties.contentLanguage,\n };\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n DeleteObjectCommand,\n GetObjectCommand,\n HeadObjectCommand,\n ListObjectsV2Command,\n ListObjectsV2CommandOutput,\n PutObjectAclCommandInput,\n PutObjectCommand,\n S3Client,\n} from '@aws-sdk/client-s3';\nimport { IObjectStorage } from '../../../interfaces';\nimport {\n CreateUploadWriteStreamResponse,\n FileContent,\n GetObjectResponse,\n GetUploadUrlResponse,\n ListRequestOptions,\n ListResponse,\n ListResponseItem,\n UploadResponse,\n} from '../../../types';\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner';\nimport {\n listResponseContentsToListResponseItems,\n s3ObjectToObjectResponse,\n} from './s3Helpers';\nimport stream from 'stream';\nimport { Upload } from '@aws-sdk/lib-storage';\n\nexport class S3StorageService implements IObjectStorage {\n private s3Client: S3Client = new S3Client({\n region: process.env.AWS_REGION,\n });\n private bucketName: string;\n\n constructor(bucketName: string) {\n this.bucketName = bucketName;\n }\n\n /**\n * Retrieves a chunk of objects from the S3 bucket based on the provided options.\n *\n * @param {ListRequestOptions} options - The options for listing the objects.\n * @param {string | undefined} continuationToken - The continuation token for pagination.\n * @param {number} limit - The maximum number of objects to retrieve.\n * @return {Promise<ListObjectsV2CommandOutput>} - A promise that resolves to the response containing the list of objects and metadata.\n */\n private async listChunk(\n options: ListRequestOptions,\n continuationToken: string | undefined,\n limit: number,\n ): Promise<ListObjectsV2CommandOutput> {\n const command = new ListObjectsV2Command({\n Bucket: this.bucketName,\n ContinuationToken: continuationToken || options.pagination,\n Prefix: options.prefix,\n MaxKeys: limit,\n });\n\n return this.s3Client.send(command);\n }\n\n /**\n * Retrieves a list of contents from the S3 bucket based on the provided options.\n *\n * @param {ListRequestOptions} options - The options for listing the contents.\n * @return {Promise<{ contents: unknown[]; nextContinuationToken?: string }>} - A promise that resolves to an object containing the list of contents and an optional next continuation token.\n */\n private async listContents(\n options: ListRequestOptions,\n ): Promise<{ contents: unknown[]; nextContinuationToken?: string }> {\n let responseContents: any[] = [];\n let continuationToken: string | undefined = undefined;\n const limit = options.limit ?? 1000;\n let continueListing = true;\n while (continueListing) {\n const listChunkLimit = limit - responseContents.length;\n const response = await this.listChunk(\n options,\n continuationToken,\n listChunkLimit,\n );\n continuationToken = response.NextContinuationToken;\n responseContents = responseContents.concat(response.Contents ?? []);\n\n if (responseContents.length >= limit || !continuationToken) {\n continueListing = false;\n }\n }\n\n return {\n contents: responseContents,\n nextContinuationToken: continuationToken,\n };\n }\n\n /**\n * Lists objects in the S3 bucket with pagination.\n * @param options - The options for listing objects.\n * @returns A promise that resolves to a paginated list of object keys.\n */\n async list(options: ListRequestOptions): Promise<ListResponse> {\n let items: ListResponseItem[] = [];\n const response = await this.listContents(options);\n\n items = response.contents.length\n ? listResponseContentsToListResponseItems(response.contents)\n : [];\n\n return {\n items,\n pagination: response.nextContinuationToken ?? null,\n count: items.length,\n };\n }\n\n /**\n * Lists all objects in the S3 bucket.\n * @param options - The options for listing objects.\n * @returns A promise that resolves to list of object keys.\n */\n\n async listAll(options: ListRequestOptions): Promise<ListResponse> {\n let allItems: ListResponseItem[] = [];\n let pagination: string | undefined = undefined;\n\n do {\n const response: ListResponse = await this.list({\n ...options,\n pagination,\n });\n\n if (response.items?.length)\n allItems = [...allItems, ...response.items];\n\n pagination =\n response.pagination === null ? undefined : response.pagination;\n } while (pagination);\n\n return { items: allItems, count: allItems.length };\n }\n\n /**\n * Retrieves an object from the S3 bucket.\n * @param key - The key of the object to retrieve.\n * @returns A promise that resolves to the content of the file.\n */\n async getHeadObject(key: string): Promise<GetObjectResponse> {\n const command = new HeadObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n });\n const response = await this.s3Client.send(command);\n return s3ObjectToObjectResponse(response);\n }\n\n /**\n * Retrieves an object from the S3 bucket.\n * @param key - The key of the object to retrieve.\n * @returns A promise that resolves to the content of the file.\n */\n async getObject(key: string): Promise<GetObjectResponse> {\n const command = new GetObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n });\n const response = await this.s3Client.send(command);\n return s3ObjectToObjectResponse(response);\n }\n\n /**\n * Generates a signed URL for accessing an object in the S3 bucket.\n * @param key - The key of the object.\n * @param expiresInMinutes - The number of minutes the signed URL should be valid for. Defaults to 60 minutes.\n * @returns A promise that resolves to the signed URL.\n */\n getDownloadUrl(\n key: string,\n expiresInMinutes: number = 60,\n ): Promise<string> {\n const expiresIn = expiresInMinutes * 60;\n const command = new GetObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n });\n return getSignedUrl(this.s3Client, command, { expiresIn });\n }\n\n /**\n * Retrieves a signed URL for uploading an object to the S3 bucket.\n *\n * @param {string} key - The key of the object to be uploaded.\n * @param {number} [expiresInMinutes=60] - The number of minutes the signed URL should be valid for. Defaults to 60 minutes.\n * @returns A promise that resolves to the signed URL.\n */\n async getUploadUrl(\n key: string,\n expiresInMinutes: number = 60,\n ): Promise<GetUploadUrlResponse> {\n const expiresIn = expiresInMinutes * 60;\n\n const putObjectCommandParams: PutObjectAclCommandInput = {\n Bucket: process.env.UPLOAD_BUCKET_NAME,\n Key: key,\n ACL: 'private',\n };\n\n const command = new PutObjectCommand(putObjectCommandParams);\n\n const signedUrl = await getSignedUrl(this.s3Client, command, {\n expiresIn,\n });\n\n return {\n signedUrl,\n key: `https://${process.env.UPLOAD_BUCKET_NAME}.s3.${process.env.AWS_DEFAULT_REGION}.amazonaws.com/${key}`,\n };\n }\n\n /**\n * Uploads an object to the S3 bucket.\n * @param key - The key of the object to upload.\n * @param body - The content of the object to upload.\n * @param metadata - Optional metadata to associate with the object.\n * @returns A promise that resolves to the response containing the key of the uploaded object.\n */\n async upload(\n key: string,\n body: FileContent,\n metadata?: { [key: string]: string },\n ): Promise<UploadResponse> {\n const command = new PutObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n Body: body,\n Metadata: metadata,\n });\n await this.s3Client.send(command);\n return { key };\n }\n\n /**\n * Creates a writable stream for uploading a file to the S3 bucket.\n *\n * @param {string} key - The key of the object to upload.\n * @return {CreateUploadWriteStreamResponse} An object containing the key of the uploaded object, the writable stream, and a promise that resolves when the upload is complete.\n */\n createUploadWriteStream(key: string): CreateUploadWriteStreamResponse {\n const streamPassThrough = new stream.PassThrough();\n const params = {\n Bucket: this.bucketName,\n Key: key,\n Body: streamPassThrough,\n };\n\n const upload = new Upload({\n client: this.s3Client,\n params,\n });\n\n return {\n key,\n stream: streamPassThrough,\n promise: upload.done(),\n };\n }\n\n /**\n * Deletes an object from the S3 bucket.\n * @param key - The key of the object to delete.\n * @returns A promise that resolves to true if the object was deleted successfully.\n */\n async delete(key: string): Promise<boolean> {\n const command = new DeleteObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n });\n await this.s3Client.send(command);\n return true;\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { GetObjectCommandOutput } from '@aws-sdk/client-s3';\nimport { GetObjectResponse, ListResponseItem } from '../../../types';\nimport { Readable } from 'stream';\n\n/**\n * Converts an array of S3 response contents into an array of ListResponseItem objects.\n *\n * @param {any[]} responseContents - The array of S3 response contents.\n * @return {ListResponseItem[]} The array of ListResponseItem objects.\n */\nexport function listResponseContentsToListResponseItems(\n responseContents: any[],\n): ListResponseItem[] {\n return responseContents.map((responseContent) => {\n return {\n key: responseContent.Key,\n lastModified: new Date(responseContent.LastModified),\n size: responseContent.Size,\n eTag: responseContent.ETag,\n };\n });\n}\n\n/**\n * Converts an S3 object response to a standardized object response.\n *\n * @param {GetObjectCommandOutput} s3Object - The S3 object response to convert.\n * @return {GetObjectResponse} The converted object response.\n */\nexport function s3ObjectToObjectResponse(\n s3Object: GetObjectCommandOutput,\n): GetObjectResponse {\n return {\n body: s3Object.Body as Readable,\n metadata: s3Object.Metadata,\n contentType: s3Object.ContentType,\n contentLength: s3Object.ContentLength as number,\n contentEncoding: s3Object.ContentEncoding,\n cacheControl: s3Object.CacheControl,\n contentDisposition: s3Object.ContentDisposition,\n contentLanguage: s3Object.ContentLanguage,\n eTag: s3Object.ETag,\n lastModified: s3Object.LastModified,\n };\n}\n","import { IObjectStorage } from '../interfaces';\nimport { S3StorageService, BlobStorageService } from './storage';\n\nexport class ObjectStorageFactory {\n static async instance(bucketName: string): Promise<IObjectStorage> {\n const isBlobStorageService =\n process.env.OBJECT_STORAGE_SERVICE?.toLowerCase() ===\n 'azure_blob_storage';\n\n if (isBlobStorageService) {\n return new BlobStorageService(bucketName);\n } else {\n return new S3StorageService(bucketName);\n }\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { IObjectStorage } from '../interfaces';\nimport {\n ListResponse,\n FileContent,\n UploadResponse,\n GetObjectResponse,\n ListRequestOptions,\n GetUploadUrlResponse,\n CreateUploadWriteStreamResponse,\n} from '../types';\nimport { ObjectStorageFactory } from '../services/objectStorageFactory.service';\n\nexport default class ObjectStorageService {\n static bucketName: string;\n\n constructor(bucketName: string) {\n ObjectStorageService.bucketName = bucketName;\n }\n\n static async getObjectStorageServiceInstance(\n bucketName: string = ObjectStorageService.bucketName,\n ): Promise<IObjectStorage> {\n if (!bucketName)\n throw new Error('Bucket name not provided or not valid value');\n return ObjectStorageFactory.instance(bucketName);\n }\n\n /**\n * Retrieves a list of objects from the object storage service.\n *\n * @param {ListRequestOptions} options - The options to apply to the list operation.\n * @param {string} [bucketName] - The name of the bucket to list objects from. If not provided, the default bucket name will be used.\n * @return {Promise<ListResponse>} A promise that resolves to the list of objects.\n */\n static async list(\n options: ListRequestOptions,\n bucketName?: string,\n ): Promise<ListResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.list(options));\n }\n\n /**\n * Retrieves a list of all objects from the object storage service.\n *\n * @param {ListRequestOptions} options - The options to apply to the list operation.\n * @param {string} [bucketName] - The name of the bucket to list objects from. If not provided, the default bucket name will be used.\n * @return {Promise<ListResponse>} A promise that resolves to the list of all objects.\n */\n static async listAll(\n options: ListRequestOptions,\n bucketName?: string,\n ): Promise<ListResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.listAll(options));\n }\n\n /**\n * Retrieves an object from the object storage service.\n *\n * @param {string} key - The key of the object to retrieve.\n * @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.\n * @return {Promise<GetObjectResponse>} A promise that resolves to the retrieved object.\n */\n static async getObject(\n key: string,\n bucketName?: string,\n ): Promise<GetObjectResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.getObject(key));\n }\n\n /**\n * Retrieves a signed URL for the specified object in the object storage service.\n *\n * @param {string} key - The key of the object for which to generate the signed URL.\n * @param {number} expiresInMinutes - The number of minutes until the signed URL expires.\n * @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.\n * @return {Promise<string>} A promise that resolves to the generated signed URL.\n */\n static async getDownloadUrl(\n key: string,\n expiresInMinutes: number,\n bucketName?: string,\n ): Promise<string> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.getDownloadUrl(key, expiresInMinutes));\n }\n\n /**\n * Retrieves an upload URL for the specified object in the object storage service.\n *\n * @param {string} key - The key of the object for which to generate the upload URL.\n * @param {number} expiresInMinutes - The number of minutes until the upload URL expires.\n * @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.\n * @return {Promise<string>} A promise that resolves to the generated upload URL.\n */\n static async getUploadUrl(\n key: string,\n expiresInMinutes: number,\n bucketName?: string,\n ): Promise<GetUploadUrlResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.getUploadUrl(key, expiresInMinutes));\n }\n\n /**\n * Uploads a file to the object storage service.\n *\n * @param {string} key - The key of the object to upload.\n * @param {FileContent} body - The content of the file to upload.\n * @param {Object} [metadata] - Optional metadata to associate with the object.\n * @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.\n * @return {Promise<UploadResponse>} A promise that resolves to the response of the upload operation.\n */\n static async upload(\n key: string,\n body: FileContent,\n metadata?: { [key: string]: string },\n bucketName?: string,\n ): Promise<UploadResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.upload(key, body, metadata));\n }\n\n /**\n * Creates an upload write stream for the specified key in the object storage service.\n *\n * @param {string} key - The key of the object to create the upload write stream for.\n * @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.\n * @return {Promise<CreateUploadWriteStreamResponse>} A promise that resolves to the response of the upload operation.\n */\n static async createUploadWriteStream(\n key: string,\n bucketName?: string,\n ): Promise<CreateUploadWriteStreamResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.createUploadWriteStream(key));\n }\n\n /**\n * Deletes an object from the object storage service.\n *\n * @param {string} key - The key of the object to delete.\n * @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.\n * @return {Promise<boolean>} A promise that resolves to true if the object was successfully deleted, or false otherwise.\n */\n static async delete(key: string, bucketName?: string): Promise<boolean> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.delete(key));\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/services/storage/blob/blobStorage.service.ts","../../src/shared/utils/errorHandler.ts","../../src/services/storage/blob/blobHelpers.ts","../../src/services/storage/s3/s3Storage.service.ts","../../src/services/storage/s3/s3Helpers.ts","../../src/services/objectStorageFactory.service.ts","../../src/services/objectStorage.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAWA;AAAA,EACI;AAAA,EACA;AAAA,OAGG;;;ACdP,IAAM,gBAA2C;AAAA,EAC7C,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,mBAAmB;AAAA,EACnB,qBAAqB;AAAA,EACrB,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,eAAe;AAAA,EACf,oBACI;AAAA,EACJ,mBAAmB;AAAA,EACnB,oBACI;AAAA,EACJ,cAAc;AAAA,EACd,cAAc;AAAA,EACd,WAAW;AAAA,EACX,oBAAoB;AAAA,EACpB,gBAAgB;AAAA,EAChB,oBAAoB;AAAA,EACpB,uBACI;AAAA,EACJ,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,gBAAgB;AAAA,EAChB,SAAS;AACb;AAEO,IAAM,eAAN,MAAmB;AAAA,EACtB,OAAO,YACH,WACA,cACA,UACW;AACX,UAAM,gBAA6B;AAAA,MAC/B,MAAM;AAAA,MACN,SACI,gBACA,cAAc,SAAS,KACvB,cAAc,SAAS;AAAA,MAC3B,YAAW,oBAAI,KAAK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AAwB,GAAG,CAAC;AAAA,EAC9D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,aAAa,OAAO,KAAa,YAAuC;AACpE,WAAO,sBAAqB;AAAA,MACxB;AAAA,IACJ,EAAE,KAAK,CAAC,aAAa,SAAS,OAAO,GAAG,CAAC;AAAA,EAC7C;AACJ","sourcesContent":["import { IObjectStorage } from '../../../interfaces';\nimport {\n FileContent,\n ListResponse,\n UploadResponse,\n GetObjectResponse,\n ListRequestOptions,\n ListResponseItem,\n GetUploadUrlResponse,\n CreateUploadWriteStreamResponse,\n} from '../../../types';\nimport {\n BlobServiceClient,\n BlobSASPermissions,\n BlobItem,\n ContainerClient,\n} from '@azure/storage-blob';\n\nimport { Readable } from 'stream';\nimport { ErrorHandler } from '../../../shared/utils/errorHandler';\nimport { BlobPropertiesResponseToObjectResponse } from './blobHelpers';\nexport class BlobStorageService implements IObjectStorage {\n private blobServiceClient: BlobServiceClient;\n private containerName: string;\n\n /**\n * Retrieves the properties of a blob from the container by its name.\n *\n * @param {string} blobName - The name of the blob.\n * @return {Promise<GetObjectResponse>} A promise that resolves to the blob properties.\n */\n constructor(containerName: string) {\n this.containerName = containerName;\n this.blobServiceClient = BlobServiceClient.fromConnectionString(\n process.env.AZURE_STORAGE_CONNECTION_STRING!,\n );\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars\n createUploadWriteStream(key: string): CreateUploadWriteStreamResponse {\n throw new Error('Method not implemented.');\n }\n\n /**\n * Retrieves the properties of a blob from the container by its name.\n *\n * @param {string} blobName - The name of the blob.\n * @return {Promise<GetObjectResponse>} A promise that resolves to the blob properties.\n */\n async getHeadObject(blobName: string): Promise<GetObjectResponse> {\n try {\n const containerClient = this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n const blobProperties = await blockBlobClient.getProperties();\n return BlobPropertiesResponseToObjectResponse(blobProperties);\n } catch (error) {\n throw ErrorHandler.handleError('DEFAULT', '', error as Error);\n }\n }\n\n /**\n * Retrieves an object from the blob storage service.\n *\n * @param {string} blobName - The name of the blob to retrieve.\n * @return {Promise<GetObjectResponse>} A promise that resolves to the object data, including the body, metadata, content type, and content length, or rejects with an error if there was an issue.\n */\n async getObject(blobName: string): Promise<GetObjectResponse> {\n try {\n const containerClient = this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n const downloadBlockBlobResponse = await blockBlobClient.download(0);\n return {\n body: downloadBlockBlobResponse.readableStreamBody as Readable,\n metadata: downloadBlockBlobResponse.metadata,\n contentType: downloadBlockBlobResponse.contentType,\n contentLength: downloadBlockBlobResponse.contentLength,\n };\n } catch (error: any) {\n let errorKey = 'DEFAULT';\n if (error?.response?.status === 404) {\n errorKey = 'ObjectNotFound';\n }\n throw ErrorHandler.handleError(errorKey, '', error as Error);\n }\n }\n\n private async getSignatureUrl(\n blobName: string,\n expiresInMinutes: number,\n permissions: string,\n ): Promise<string> {\n try {\n const containerClient = this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n\n const startDate = new Date();\n const expiryDate = new Date(startDate);\n expiryDate.setMinutes(startDate.getMinutes() + expiresInMinutes);\n\n return blockBlobClient.generateSasUrl({\n permissions: BlobSASPermissions.parse(permissions),\n startsOn: startDate,\n expiresOn: expiryDate,\n });\n } catch (error) {\n throw ErrorHandler.handleError('DEFAULT', '', error as Error);\n }\n }\n\n async getUploadUrl(\n blobName: string,\n expiresInMinutes: number,\n ): Promise<GetUploadUrlResponse> {\n try {\n const sasUrl = await this.getSignatureUrl(\n blobName,\n expiresInMinutes,\n 'w',\n );\n return { key: blobName, signedUrl: sasUrl };\n } catch (error) {\n throw ErrorHandler.handleError('DEFAULT', '', error as Error);\n }\n }\n\n /**\n * Retrieves a signed URL for the blob with the specified name that expires after a certain period.\n *\n * @param {string} blobName - The name of the blob to generate the signed URL for.\n * @param {number} expiresInMinutes - The duration in minutes until the signed URL expires.\n * @return {Promise<string>} A Promise that resolves with the signed URL.\n */\n async getDownloadUrl(\n blobName: string,\n expiresInMinutes: number,\n ): Promise<string> {\n try {\n const sasUrl = await this.getSignatureUrl(\n blobName,\n expiresInMinutes,\n 'r',\n );\n return sasUrl;\n } catch (error) {\n throw ErrorHandler.handleError('DEFAULT', '', error as Error);\n }\n }\n\n /**\n * Uploads a file to the blob storage service.\n *\n * @param {string} blobName - The name of the blob to upload.\n * @param {FileContent} body - The content of the file to upload.\n * @param {{ [key: string]: string } | undefined} [metadata] - Optional metadata to associate with the blob.\n * @return {Promise<UploadResponse>} A promise that resolves to the response object containing the key of the uploaded blob, or rejects with an error if there was an issue.\n */\n async upload(\n blobName: string,\n body: FileContent,\n metadata: { [key: string]: string } = {},\n ): Promise<UploadResponse> {\n try {\n const containerClient = this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n Buffer.isBuffer(body)\n ? await blockBlobClient.upload(body, body.length, { metadata })\n : await blockBlobClient.uploadStream(\n body as Readable,\n undefined,\n undefined,\n { metadata },\n );\n\n return { key: blobName };\n } catch (error) {\n throw ErrorHandler.handleError('DEFAULT', '', error as Error);\n }\n }\n\n /**\n * Deletes a blob from the blob storage service.\n *\n * @param {string} blobName - The name of the blob to be deleted.\n * @return {Promise<boolean>} A promise that resolves to true if the blob is successfully deleted, or rejects with an error if there was an issue.\n */\n async delete(data: string): Promise<boolean> {\n try {\n const containerClient = this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n return this.deleteObject(containerClient, data);\n } catch (error) {\n throw ErrorHandler.handleError('DEFAULT', '', error as Error);\n }\n }\n\n /**\n * Lists a chunk of blobs from the specified container client based on the provided options and continuation token.\n *\n * @param {ListRequestOptions} options - The options for listing the blobs.\n * @param {string | undefined} continuationToken - The continuation token for pagination.\n * @param {number} limit - The maximum number of blobs to list in a single page.\n * @param {ContainerClient} containerClient - The container client to list the blobs from.\n * @return {Promise<{ items: BlobItem[]; continuationToken?: string }>} - A promise that resolves to an object containing the list of blob items and an optional continuation token.\n */\n private async listChunk(\n options: ListRequestOptions,\n continuationToken: string | undefined,\n limit: number,\n containerClient: ContainerClient,\n ): Promise<{ items: BlobItem[]; continuationToken?: string }> {\n const iterator = containerClient\n .listBlobsFlat({\n prefix: options.prefix,\n })\n .byPage({\n maxPageSize: limit,\n continuationToken: continuationToken,\n });\n\n const items: BlobItem[] = [];\n const response = (await iterator.next()).value;\n items.push(...response.segment.blobItems);\n return {\n items,\n continuationToken: response.continuationToken,\n };\n }\n\n /**\n * Retrieves a list of blob contents based on the provided options.\n *\n * @param {ListRequestOptions} options - The options for listing the blob contents.\n * @return {Promise<{ contents: BlobItem[]; nextContinuationToken?: string }>} A promise that resolves to the list of blob contents and the next continuation token.\n */\n private async listContents(\n options: ListRequestOptions,\n ): Promise<{ contents: BlobItem[]; nextContinuationToken?: string }> {\n let responseContents: BlobItem[] = [];\n let continuationToken: string | undefined = options.pagination;\n const limit = options.limit ?? 1000;\n let continueListing = true;\n const containerClient = this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n while (continueListing) {\n const response = await this.listChunk(\n options,\n continuationToken,\n limit - responseContents.length,\n containerClient,\n );\n continuationToken = response.continuationToken;\n responseContents = responseContents.concat(response.items);\n\n if (responseContents.length >= limit || !continuationToken) {\n continueListing = false;\n }\n }\n\n return {\n contents: responseContents,\n nextContinuationToken: continuationToken,\n };\n }\n\n /**\n * Lists blobs in the Azure Blob Storage container with pagination.\n * @param options - The options for listing blobs.\n * @returns A promise that resolves to a paginated list of blob names.\n */\n async list(options: ListRequestOptions): Promise<ListResponse> {\n let items: ListResponseItem[] = [];\n const response = await this.listContents(options);\n\n items = response.contents.length\n ? response.contents.map((blob) => {\n return {\n key: blob.name,\n lastModified: blob.properties.lastModified,\n size: blob.properties.contentLength!,\n eTag: blob.properties.etag,\n };\n })\n : [];\n\n return {\n items,\n pagination: response.nextContinuationToken?.length\n ? response.nextContinuationToken\n : null,\n count: items.length,\n };\n }\n\n /**\n * Lists all blobs in the Azure Blob Storage container.\n * @param options - The options for listing blobs.\n * @returns A promise that resolves to list of blob names.\n */\n async listAll(options: ListRequestOptions): Promise<ListResponse> {\n let allItems: ListResponseItem[] = [];\n let pagination: string | undefined = undefined;\n\n do {\n const response: ListResponse = await this.list({\n ...options,\n pagination,\n });\n\n if (response.items?.length)\n allItems = [...allItems, ...response.items];\n\n pagination = response.pagination ?? undefined;\n } while (pagination);\n\n return { items: allItems, count: allItems.length };\n }\n\n /**\n * Deletes a blob from the blob storage service.\n *\n * @param {string} blobName - The name of the blob to be deleted.\n * @return {Promise<boolean>} A promise that resolves to true if the blob is successfully deleted, or rejects with an error if there was an issue.\n */\n async deleteObject(\n containerClient: ContainerClient,\n blobName: string,\n ): Promise<boolean> {\n try {\n const blockBlobClient =\n containerClient.getBlockBlobClient(blobName);\n await blockBlobClient.delete();\n return true;\n } catch (error) {\n throw ErrorHandler.handleError('DEFAULT', '', error as Error);\n }\n }\n\n async deleteObjects(\n blobNames: string[],\n ): Promise<{ key: string; deleted: boolean; error?: string }[]> {\n const containerClient = this.blobServiceClient.getContainerClient(\n this.containerName,\n );\n const deleteBlobPromises = blobNames.map(async (blobName) => {\n try {\n await this.deleteObject(containerClient, blobName);\n return { key: blobName, deleted: true };\n } catch (error: any) {\n return {\n key: blobName,\n deleted: false,\n error: error?.message ?? '',\n };\n }\n });\n return Promise.all(deleteBlobPromises);\n }\n}\n","import { CustomError } from '../../types/CustomError';\n\nconst errorMessages: { [key: string]: string } = {\n AccessDenied: 'Access denied',\n AccountProblem: 'There is a problem with your account',\n AllAccessDisabled: 'All access to this resource has been disabled',\n BucketAlreadyExists: 'The requested bucket name is not available',\n BucketNotEmpty: 'The bucket you tried to delete is not empty',\n EntityTooLarge: 'The entity you are trying to upload is too large',\n ExpiredToken: 'The provided token has expired',\n InternalError: 'An internal server error has occurred',\n InvalidAccessKeyId:\n 'The AWS access key ID you provided does not exist in our records',\n InvalidBucketName: 'The specified bucket name is not valid',\n InvalidObjectState:\n 'The operation is not valid for the current state of the object',\n InvalidToken: 'The provided token is invalid',\n NoSuchBucket: 'The specified bucket does not exist',\n NoSuchKey: 'The specified key does not exist',\n PreconditionFailed: 'The condition specified in the request is not met',\n RequestTimeout: 'The request timed out',\n ServiceUnavailable: 'The service is currently unavailable',\n SignatureDoesNotMatch:\n 'The request signature we calculated does not match the signature you provided',\n SlowDown: 'Please reduce your request rate',\n TemporaryRedirect: 'Temporary redirect',\n ObjectNotFound: 'ObjectNotFound - The specified key does not exist. (404)',\n DEFAULT: 'An unknown error occurred',\n};\n\nexport class ErrorHandler {\n static handleError(\n errorCode: string,\n errorMessage?: string,\n errorObj?: Error,\n ): CustomError {\n const errorResponse: CustomError = {\n code: errorCode,\n message:\n errorMessage ||\n errorMessages[errorCode] ||\n errorMessages['DEFAULT'],\n timestamp: new Date().toISOString(),\n error: errorObj\n ? {\n name: errorObj.name,\n message: errorObj.message,\n stack: errorObj.stack || null,\n }\n : null,\n };\n\n // Return the structured object\n return errorResponse;\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { GetObjectResponse } from '../../../types';\nimport { BlobGetPropertiesResponse } from '@azure/storage-blob';\n\nexport function BlobPropertiesResponseToObjectResponse(\n blobProperties: BlobGetPropertiesResponse,\n): GetObjectResponse {\n return {\n lastModified: blobProperties.lastModified,\n contentLength: blobProperties.contentLength,\n contentType: blobProperties.contentType,\n eTag: blobProperties.etag,\n metadata: blobProperties.metadata,\n contentEncoding: blobProperties.contentEncoding,\n cacheControl: blobProperties.cacheControl,\n contentDisposition: blobProperties.contentDisposition,\n contentLanguage: blobProperties.contentLanguage,\n };\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n DeleteObjectCommand,\n GetObjectCommand,\n HeadObjectCommand,\n ListObjectsV2Command,\n ListObjectsV2CommandOutput,\n PutObjectAclCommandInput,\n PutObjectCommand,\n S3Client,\n} from '@aws-sdk/client-s3';\nimport { IObjectStorage } from '../../../interfaces';\nimport {\n CreateUploadWriteStreamResponse,\n FileContent,\n GetObjectResponse,\n GetUploadUrlResponse,\n ListRequestOptions,\n ListResponse,\n ListResponseItem,\n UploadResponse,\n} from '../../../types';\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner';\nimport {\n listResponseContentsToListResponseItems,\n s3ObjectToObjectResponse,\n} from './s3Helpers';\nimport stream from 'stream';\nimport { Upload } from '@aws-sdk/lib-storage';\n\nexport class S3StorageService implements IObjectStorage {\n private s3Client: S3Client = new S3Client({\n region: process.env.AWS_REGION,\n });\n private bucketName: string;\n\n constructor(bucketName: string) {\n this.bucketName = bucketName;\n }\n\n /**\n * Retrieves a chunk of objects from the S3 bucket based on the provided options.\n *\n * @param {ListRequestOptions} options - The options for listing the objects.\n * @param {string | undefined} continuationToken - The continuation token for pagination.\n * @param {number} limit - The maximum number of objects to retrieve.\n * @return {Promise<ListObjectsV2CommandOutput>} - A promise that resolves to the response containing the list of objects and metadata.\n */\n private async listChunk(\n options: ListRequestOptions,\n continuationToken: string | undefined,\n limit: number,\n ): Promise<ListObjectsV2CommandOutput> {\n const command = new ListObjectsV2Command({\n Bucket: this.bucketName,\n ContinuationToken: continuationToken || options.pagination,\n Prefix: options.prefix,\n MaxKeys: limit,\n });\n\n return this.s3Client.send(command);\n }\n\n /**\n * Retrieves a list of contents from the S3 bucket based on the provided options.\n *\n * @param {ListRequestOptions} options - The options for listing the contents.\n * @return {Promise<{ contents: unknown[]; nextContinuationToken?: string }>} - A promise that resolves to an object containing the list of contents and an optional next continuation token.\n */\n private async listContents(\n options: ListRequestOptions,\n ): Promise<{ contents: unknown[]; nextContinuationToken?: string }> {\n let responseContents: any[] = [];\n let continuationToken: string | undefined = undefined;\n const limit = options.limit ?? 1000;\n let continueListing = true;\n while (continueListing) {\n const listChunkLimit = limit - responseContents.length;\n const response = await this.listChunk(\n options,\n continuationToken,\n listChunkLimit,\n );\n continuationToken = response.NextContinuationToken;\n responseContents = responseContents.concat(response.Contents ?? []);\n\n if (responseContents.length >= limit || !continuationToken) {\n continueListing = false;\n }\n }\n\n return {\n contents: responseContents,\n nextContinuationToken: continuationToken,\n };\n }\n\n /**\n * Lists objects in the S3 bucket with pagination.\n * @param options - The options for listing objects.\n * @returns A promise that resolves to a paginated list of object keys.\n */\n async list(options: ListRequestOptions): Promise<ListResponse> {\n let items: ListResponseItem[] = [];\n const response = await this.listContents(options);\n\n items = response.contents.length\n ? listResponseContentsToListResponseItems(response.contents)\n : [];\n\n return {\n items,\n pagination: response.nextContinuationToken ?? null,\n count: items.length,\n };\n }\n\n /**\n * Lists all objects in the S3 bucket.\n * @param options - The options for listing objects.\n * @returns A promise that resolves to list of object keys.\n */\n\n async listAll(options: ListRequestOptions): Promise<ListResponse> {\n let allItems: ListResponseItem[] = [];\n let pagination: string | undefined = undefined;\n\n do {\n const response: ListResponse = await this.list({\n ...options,\n pagination,\n });\n\n if (response.items?.length)\n allItems = [...allItems, ...response.items];\n\n pagination =\n response.pagination === null ? undefined : response.pagination;\n } while (pagination);\n\n return { items: allItems, count: allItems.length };\n }\n\n /**\n * Retrieves an object from the S3 bucket.\n * @param key - The key of the object to retrieve.\n * @returns A promise that resolves to the content of the file.\n */\n async getHeadObject(key: string): Promise<GetObjectResponse> {\n const command = new HeadObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n });\n const response = await this.s3Client.send(command);\n return s3ObjectToObjectResponse(response);\n }\n\n /**\n * Retrieves an object from the S3 bucket.\n * @param key - The key of the object to retrieve.\n * @returns A promise that resolves to the content of the file.\n */\n async getObject(key: string): Promise<GetObjectResponse> {\n const command = new GetObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n });\n const response = await this.s3Client.send(command);\n return s3ObjectToObjectResponse(response);\n }\n\n /**\n * Generates a signed URL for accessing an object in the S3 bucket.\n * @param key - The key of the object.\n * @param expiresInMinutes - The number of minutes the signed URL should be valid for. Defaults to 60 minutes.\n * @returns A promise that resolves to the signed URL.\n */\n getDownloadUrl(\n key: string,\n expiresInMinutes: number = 60,\n ): Promise<string> {\n const expiresIn = expiresInMinutes * 60;\n const command = new GetObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n });\n return getSignedUrl(this.s3Client, command, { expiresIn });\n }\n\n /**\n * Retrieves a signed URL for uploading an object to the S3 bucket.\n *\n * @param {string} key - The key of the object to be uploaded.\n * @param {number} [expiresInMinutes=60] - The number of minutes the signed URL should be valid for. Defaults to 60 minutes.\n * @returns A promise that resolves to the signed URL.\n */\n async getUploadUrl(\n key: string,\n expiresInMinutes: number = 60,\n ): Promise<GetUploadUrlResponse> {\n const expiresIn = expiresInMinutes * 60;\n\n const putObjectCommandParams: PutObjectAclCommandInput = {\n Bucket: process.env.UPLOAD_BUCKET_NAME,\n Key: key,\n ACL: 'private',\n };\n\n const command = new PutObjectCommand(putObjectCommandParams);\n\n const signedUrl = await getSignedUrl(this.s3Client, command, {\n expiresIn,\n });\n\n return {\n signedUrl,\n key: `https://${process.env.UPLOAD_BUCKET_NAME}.s3.${process.env.AWS_DEFAULT_REGION}.amazonaws.com/${key}`,\n };\n }\n\n /**\n * Uploads an object to the S3 bucket.\n * @param key - The key of the object to upload.\n * @param body - The content of the object to upload.\n * @param metadata - Optional metadata to associate with the object.\n * @returns A promise that resolves to the response containing the key of the uploaded object.\n */\n async upload(\n key: string,\n body: FileContent,\n metadata?: { [key: string]: string },\n ): Promise<UploadResponse> {\n const command = new PutObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n Body: body,\n Metadata: metadata,\n });\n await this.s3Client.send(command);\n return { key };\n }\n\n /**\n * Creates a writable stream for uploading a file to the S3 bucket.\n *\n * @param {string} key - The key of the object to upload.\n * @return {CreateUploadWriteStreamResponse} An object containing the key of the uploaded object, the writable stream, and a promise that resolves when the upload is complete.\n */\n createUploadWriteStream(key: string): CreateUploadWriteStreamResponse {\n const streamPassThrough = new stream.PassThrough();\n const params = {\n Bucket: this.bucketName,\n Key: key,\n Body: streamPassThrough,\n };\n\n const upload = new Upload({\n client: this.s3Client,\n params,\n });\n\n return {\n key,\n stream: streamPassThrough,\n promise: upload.done(),\n };\n }\n\n /**\n * Deletes an object from the S3 bucket.\n * @param key - The key of the object to delete.\n * @returns A promise that resolves to true if the object was deleted successfully.\n */\n async delete(key: string): Promise<boolean> {\n const command = new DeleteObjectCommand({\n Bucket: this.bucketName,\n Key: key,\n });\n await this.s3Client.send(command);\n return true;\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { GetObjectCommandOutput } from '@aws-sdk/client-s3';\nimport { GetObjectResponse, ListResponseItem } from '../../../types';\nimport { Readable } from 'stream';\n\n/**\n * Converts an array of S3 response contents into an array of ListResponseItem objects.\n *\n * @param {any[]} responseContents - The array of S3 response contents.\n * @return {ListResponseItem[]} The array of ListResponseItem objects.\n */\nexport function listResponseContentsToListResponseItems(\n responseContents: any[],\n): ListResponseItem[] {\n return responseContents.map((responseContent) => {\n return {\n key: responseContent.Key,\n lastModified: new Date(responseContent.LastModified),\n size: responseContent.Size,\n eTag: responseContent.ETag,\n };\n });\n}\n\n/**\n * Converts an S3 object response to a standardized object response.\n *\n * @param {GetObjectCommandOutput} s3Object - The S3 object response to convert.\n * @return {GetObjectResponse} The converted object response.\n */\nexport function s3ObjectToObjectResponse(\n s3Object: GetObjectCommandOutput,\n): GetObjectResponse {\n return {\n body: s3Object.Body as Readable,\n metadata: s3Object.Metadata,\n contentType: s3Object.ContentType,\n contentLength: s3Object.ContentLength as number,\n contentEncoding: s3Object.ContentEncoding,\n cacheControl: s3Object.CacheControl,\n contentDisposition: s3Object.ContentDisposition,\n contentLanguage: s3Object.ContentLanguage,\n eTag: s3Object.ETag,\n lastModified: s3Object.LastModified,\n };\n}\n","import { IObjectStorage } from '../interfaces';\nimport { S3StorageService, BlobStorageService } from './storage';\n\nexport class ObjectStorageFactory {\n static async instance(bucketName: string): Promise<IObjectStorage> {\n const isBlobStorageService =\n process.env.OBJECT_STORAGE_SERVICE?.toLowerCase() ===\n 'azure_blob_storage';\n\n if (isBlobStorageService) {\n return new BlobStorageService(bucketName);\n } else {\n return new S3StorageService(bucketName);\n }\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { IObjectStorage } from '../interfaces';\nimport {\n ListResponse,\n FileContent,\n UploadResponse,\n GetObjectResponse,\n ListRequestOptions,\n GetUploadUrlResponse,\n CreateUploadWriteStreamResponse,\n} from '../types';\nimport { ObjectStorageFactory } from '../services/objectStorageFactory.service';\n\nexport default class ObjectStorageService {\n static bucketName: string;\n\n constructor(bucketName: string) {\n ObjectStorageService.bucketName = bucketName;\n }\n\n static async getObjectStorageServiceInstance(\n bucketName: string = ObjectStorageService.bucketName,\n ): Promise<IObjectStorage> {\n if (!bucketName)\n throw new Error('Bucket name not provided or not valid value');\n return ObjectStorageFactory.instance(bucketName);\n }\n\n /**\n * Retrieves a list of objects from the object storage service.\n *\n * @param {ListRequestOptions} options - The options to apply to the list operation.\n * @param {string} [bucketName] - The name of the bucket to list objects from. If not provided, the default bucket name will be used.\n * @return {Promise<ListResponse>} A promise that resolves to the list of objects.\n */\n static async list(\n options: ListRequestOptions,\n bucketName?: string,\n ): Promise<ListResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.list(options));\n }\n\n /**\n * Retrieves a list of all objects from the object storage service.\n *\n * @param {ListRequestOptions} options - The options to apply to the list operation.\n * @param {string} [bucketName] - The name of the bucket to list objects from. If not provided, the default bucket name will be used.\n * @return {Promise<ListResponse>} A promise that resolves to the list of all objects.\n */\n static async listAll(\n options: ListRequestOptions,\n bucketName?: string,\n ): Promise<ListResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.listAll(options));\n }\n\n /**\n * Retrieves an object from the object storage service.\n *\n * @param {string} key - The key of the object to retrieve.\n * @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.\n * @return {Promise<GetObjectResponse>} A promise that resolves to the retrieved object.\n */\n static async getObject(\n key: string,\n bucketName?: string,\n ): Promise<GetObjectResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.getObject(key));\n }\n\n /**\n * Retrieves a signed URL for the specified object in the object storage service.\n *\n * @param {string} key - The key of the object for which to generate the signed URL.\n * @param {number} expiresInMinutes - The number of minutes until the signed URL expires.\n * @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.\n * @return {Promise<string>} A promise that resolves to the generated signed URL.\n */\n static async getDownloadUrl(\n key: string,\n expiresInMinutes: number,\n bucketName?: string,\n ): Promise<string> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.getDownloadUrl(key, expiresInMinutes));\n }\n\n /**\n * Retrieves an upload URL for the specified object in the object storage service.\n *\n * @param {string} key - The key of the object for which to generate the upload URL.\n * @param {number} expiresInMinutes - The number of minutes until the upload URL expires.\n * @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.\n * @return {Promise<string>} A promise that resolves to the generated upload URL.\n */\n static async getUploadUrl(\n key: string,\n expiresInMinutes: number,\n bucketName?: string,\n ): Promise<GetUploadUrlResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.getUploadUrl(key, expiresInMinutes));\n }\n\n /**\n * Uploads a file to the object storage service.\n *\n * @param {string} key - The key of the object to upload.\n * @param {FileContent} body - The content of the file to upload.\n * @param {Object} [metadata] - Optional metadata to associate with the object.\n * @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.\n * @return {Promise<UploadResponse>} A promise that resolves to the response of the upload operation.\n */\n static async upload(\n key: string,\n body: FileContent,\n metadata?: { [key: string]: string },\n bucketName?: string,\n ): Promise<UploadResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.upload(key, body, metadata));\n }\n\n /**\n * Creates an upload write stream for the specified key in the object storage service.\n *\n * @param {string} key - The key of the object to create the upload write stream for.\n * @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.\n * @return {Promise<CreateUploadWriteStreamResponse>} A promise that resolves to the response of the upload operation.\n */\n static async createUploadWriteStream(\n key: string,\n bucketName?: string,\n ): Promise<CreateUploadWriteStreamResponse> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.createUploadWriteStream(key));\n }\n\n /**\n * Deletes an object from the object storage service.\n *\n * @param {string} key - The key of the object to delete.\n * @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.\n * @return {Promise<boolean>} A promise that resolves to true if the object was successfully deleted, or false otherwise.\n */\n static async delete(key: string, bucketName?: string): Promise<boolean> {\n return ObjectStorageService.getObjectStorageServiceInstance(\n bucketName,\n ).then((instance) => instance.delete(key));\n }\n}\n"]}
@@ -4,7 +4,7 @@ type UploadResponse = {
4
4
  key: string;
5
5
  };
6
6
 
7
- type FileContent = Readable | ReadableStream | Blob;
7
+ type FileContent = Readable | ReadableStream | Blob | Buffer;
8
8
 
9
9
  type ListRequestOptions = {
10
10
  prefix?: string;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@qrvey/object-storage",
3
3
  "types": "dist/types/index.d.ts",
4
4
  "main": "dist/cjs/index.js",
5
- "version": "0.0.4",
5
+ "version": "0.0.6",
6
6
  "license": "MIT",
7
7
  "exports": {
8
8
  ".": {
@@ -25,9 +25,9 @@
25
25
  "publish-package": "yarn prepare-publish && npm publish"
26
26
  },
27
27
  "dependencies": {
28
- "@aws-sdk/client-s3": "3.596.0",
29
- "@aws-sdk/lib-storage": "3.598.0",
30
- "@aws-sdk/s3-request-presigner": "3.596.0",
28
+ "@aws-sdk/client-s3": "3.x",
29
+ "@aws-sdk/lib-storage": "3.x",
30
+ "@aws-sdk/s3-request-presigner": "3.x",
31
31
  "@azure/storage-blob": "12.23.0"
32
32
  },
33
33
  "devDependencies": {