@geekmidas/storage 0.0.5 → 0.1.0
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/dist/{AmazonStorageClient-tyGekctm.cjs → AmazonStorageClient-BKzXhCX0.cjs} +28 -5
- package/dist/AmazonStorageClient-BKzXhCX0.cjs.map +1 -0
- package/dist/{AmazonStorageClient-Bkw-x2o2.mjs → AmazonStorageClient-CwUey48q.mjs} +3 -2
- package/dist/AmazonStorageClient-CwUey48q.mjs.map +1 -0
- package/dist/{AmazonStorageClient-DaktozmE.d.mts → AmazonStorageClient-Gz0Fh1sy.d.mts} +3 -2
- package/dist/AmazonStorageClient-aduVU3_p.d.cts +2 -1
- package/dist/AmazonStorageClient.cjs +1 -1
- package/dist/AmazonStorageClient.d.mts +2 -2
- package/dist/AmazonStorageClient.mjs +2 -2
- package/dist/{StorageClient-CZGIC_fz.mjs → StorageClient-4ADnTPnJ.mjs} +2 -1
- package/dist/StorageClient-4ADnTPnJ.mjs.map +1 -0
- package/dist/StorageClient-BDRVrMJj.cjs +2 -1
- package/dist/StorageClient-BDRVrMJj.cjs.map +1 -0
- package/dist/StorageClient-CcOAW3YV.d.cts +2 -1
- package/dist/{StorageClient-CveQoxJa.d.mts → StorageClient-XgMsiUrd.d.mts} +2 -1
- package/dist/StorageClient.d.mts +1 -1
- package/dist/StorageClient.mjs +1 -1
- package/dist/aws.cjs +1 -1
- package/dist/aws.d.mts +2 -2
- package/dist/aws.mjs +2 -2
- package/dist/index.d.mts +1 -1
- package/package.json +29 -6
- package/dist/__tests__/AmazonStorageClient.spec.cjs +0 -348
- package/dist/__tests__/AmazonStorageClient.spec.d.cts +0 -1
- package/dist/__tests__/AmazonStorageClient.spec.d.mts +0 -1
- package/dist/__tests__/AmazonStorageClient.spec.mjs +0 -347
- package/dist/__tests__/StorageClient.spec.cjs +0 -81
- package/dist/__tests__/StorageClient.spec.d.cts +0 -1
- package/dist/__tests__/StorageClient.spec.d.mts +0 -1
- package/dist/__tests__/StorageClient.spec.mjs +0 -81
- package/dist/chunk-DWy1uDak.cjs +0 -39
- package/dist/magic-string.es-BvJNBYzY.mjs +0 -1014
- package/dist/magic-string.es-CKiDiYoS.cjs +0 -1015
- package/dist/vi.bdSIJ99Y-CucmVasy.mjs +0 -14928
- package/dist/vi.bdSIJ99Y-D0m6qImj.cjs +0 -14926
|
@@ -1,8 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
2
24
|
const require_StorageClient = require('./StorageClient-BDRVrMJj.cjs');
|
|
3
|
-
const __aws_sdk_client_s3 =
|
|
4
|
-
const __aws_sdk_s3_presigned_post =
|
|
5
|
-
const __aws_sdk_s3_request_presigner =
|
|
25
|
+
const __aws_sdk_client_s3 = __toESM(require("@aws-sdk/client-s3"));
|
|
26
|
+
const __aws_sdk_s3_presigned_post = __toESM(require("@aws-sdk/s3-presigned-post"));
|
|
27
|
+
const __aws_sdk_s3_request_presigner = __toESM(require("@aws-sdk/s3-request-presigner"));
|
|
6
28
|
|
|
7
29
|
//#region src/AmazonStorageClient.ts
|
|
8
30
|
var AmazonStorageClient = class AmazonStorageClient {
|
|
@@ -128,4 +150,5 @@ Object.defineProperty(exports, 'AmazonStorageClient', {
|
|
|
128
150
|
get: function () {
|
|
129
151
|
return AmazonStorageClient;
|
|
130
152
|
}
|
|
131
|
-
});
|
|
153
|
+
});
|
|
154
|
+
//# sourceMappingURL=AmazonStorageClient-BKzXhCX0.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AmazonStorageClient-BKzXhCX0.cjs","names":["StorageProvider","options: AmazonStorageClientCreateOptions","S3Client","client: S3Client","bucket: string","cache?: Cache<string>","file: File","versionId: string","GetObjectCommand","key: string","ListObjectVersionsCommand","params: GetUploadParams","PutObjectCommand","data: string | Buffer","contentType: string"],"sources":["../src/AmazonStorageClient.ts"],"sourcesContent":["import {\n GetObjectCommand,\n ListObjectVersionsCommand,\n PutObjectCommand,\n S3Client,\n} from '@aws-sdk/client-s3';\nimport { createPresignedPost } from '@aws-sdk/s3-presigned-post';\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner';\n\nimport type { Cache } from '@geekmidas/cache';\nimport {\n type DocumentVersion,\n type File,\n type GetUploadParams,\n type GetUploadResponse,\n type StorageClient,\n StorageProvider,\n} from './StorageClient';\n\nexport class AmazonStorageClient implements StorageClient {\n readonly provider = StorageProvider.AWSS3;\n\n static create(\n options: AmazonStorageClientCreateOptions,\n ): AmazonStorageClient {\n const {\n bucket,\n region,\n accessKeyId,\n acl,\n endpoint,\n secretAccessKey,\n forcePathStyle = false,\n cache,\n } = options;\n const hasCredentials = accessKeyId && secretAccessKey;\n const credentials = hasCredentials\n ? { accessKeyId, secretAccessKey }\n : undefined;\n\n const client = new S3Client({\n region,\n credentials,\n endpoint,\n forcePathStyle,\n });\n\n return new AmazonStorageClient(client, bucket, acl, cache);\n }\n constructor(\n private readonly client: S3Client,\n private readonly bucket: string,\n private readonly acl = AmazonCannedAccessControlList.AuthenticatedRead,\n readonly cache?: Cache<string>,\n ) {}\n\n getVersionDownloadURL(file: File, versionId: string): Promise<string> {\n const ResponseContentDisposition = file.name\n ? `attachment; filename=${encodeURIComponent(file.name)}`\n : undefined;\n\n const command = new GetObjectCommand({\n Bucket: this.bucket,\n Key: file.path,\n ResponseContentDisposition,\n VersionId: versionId,\n });\n\n return getSignedUrl(this.client, command, { expiresIn: 60 * 60 * 24 });\n }\n\n async getVersions(key: string): Promise<DocumentVersion[]> {\n const command = new ListObjectVersionsCommand({\n Bucket: this.bucket,\n Prefix: key,\n });\n\n const { Versions = [] } = await this.client.send(command);\n\n return Versions.map((version) => ({\n id: version.VersionId || '',\n createdAt: version.LastModified || new Date(),\n }));\n }\n\n async getDownloadURL(file: File, expiresIn = 60 * 60): Promise<string> {\n const cacheKey = `download-url:${file.path}`;\n const cachedURL = await this.cache?.get(cacheKey);\n\n if (cachedURL) {\n return cachedURL;\n }\n\n const ResponseContentDisposition = file.name\n ? `attachment; filename=${encodeURIComponent(file.name)}`\n : undefined;\n\n const command = new GetObjectCommand({\n Bucket: this.bucket,\n Key: file.path,\n ResponseContentDisposition,\n });\n\n const url = await getSignedUrl(this.client, command, { expiresIn });\n const cacheExpiration = Math.max(expiresIn - 60, 0);\n\n if (cacheExpiration) {\n await this.cache?.set(cacheKey, url, cacheExpiration);\n }\n\n return url;\n }\n\n async getUploadURL(\n params: GetUploadParams,\n expiresIn = 60 * 60,\n ): Promise<string> {\n const command = new PutObjectCommand({\n Bucket: this.bucket,\n Key: params.path,\n ContentType: params.contentType,\n ContentLength: params.contentLength,\n });\n\n return getSignedUrl(this.client, command, { expiresIn });\n }\n\n async getUpload(\n params: GetUploadParams,\n expiresIn = 5,\n ): Promise<GetUploadResponse> {\n const { path } = params;\n const { fields: values, url } = await createPresignedPost(this.client, {\n Expires: expiresIn * 60,\n Bucket: this.bucket,\n Fields: {\n acl: this.acl,\n },\n Conditions: [\n // content length restrictions: 0-1MB]\n // ['content-length-range', 0, contentLength],\n // specify content-type to be more generic- images only\n // ['starts-with', '$Content-Type', 'image/'],\n // ['starts-with', '$Content-Type', contentType],\n ],\n Key: path,\n });\n\n const keys = Object.keys(values);\n const fields = keys.map((key) => ({ key, value: values[key] || '' }));\n\n return { url, fields };\n }\n\n async upload(\n key: string,\n data: string | Buffer,\n contentType: string,\n ): Promise<void> {\n const Body = typeof data === 'string' ? Buffer.from(data, 'base64') : data;\n\n const params = {\n Bucket: this.bucket,\n Key: key,\n Body,\n ContentType: contentType,\n };\n\n const command = new PutObjectCommand(params);\n\n await this.client.send(command);\n }\n}\n\nexport enum AmazonCannedAccessControlList {\n AuthenticatedRead = 'authenticated-read',\n Private = 'private',\n PublicRead = 'public-read',\n PublicReadWrite = 'public-read-write',\n AwsExecRead = 'aws-exec-read',\n BucketOwnerRead = 'bucket-owner-read',\n BucketOwnerFullControl = 'bucket-owner-full-control',\n LogDeliveryWrite = 'log-delivery-write',\n}\n\ninterface AmazonStorageClientCreateOptions {\n bucket: string;\n region?: string;\n acl?: AmazonCannedAccessControlList;\n accessKeyId?: string;\n secretAccessKey?: string;\n endpoint?: string;\n forcePathStyle?: boolean;\n cache?: Cache<string>;\n}\n"],"mappings":"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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StorageProvider } from "./StorageClient-
|
|
1
|
+
import { StorageProvider } from "./StorageClient-4ADnTPnJ.mjs";
|
|
2
2
|
import { GetObjectCommand, ListObjectVersionsCommand, PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
|
3
3
|
import { createPresignedPost } from "@aws-sdk/s3-presigned-post";
|
|
4
4
|
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
@@ -116,4 +116,5 @@ let AmazonCannedAccessControlList = /* @__PURE__ */ function(AmazonCannedAccessC
|
|
|
116
116
|
}({});
|
|
117
117
|
|
|
118
118
|
//#endregion
|
|
119
|
-
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
119
|
+
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
120
|
+
//# sourceMappingURL=AmazonStorageClient-CwUey48q.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AmazonStorageClient-CwUey48q.mjs","names":["options: AmazonStorageClientCreateOptions","client: S3Client","bucket: string","cache?: Cache<string>","file: File","versionId: string","key: string","params: GetUploadParams","data: string | Buffer","contentType: string"],"sources":["../src/AmazonStorageClient.ts"],"sourcesContent":["import {\n GetObjectCommand,\n ListObjectVersionsCommand,\n PutObjectCommand,\n S3Client,\n} from '@aws-sdk/client-s3';\nimport { createPresignedPost } from '@aws-sdk/s3-presigned-post';\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner';\n\nimport type { Cache } from '@geekmidas/cache';\nimport {\n type DocumentVersion,\n type File,\n type GetUploadParams,\n type GetUploadResponse,\n type StorageClient,\n StorageProvider,\n} from './StorageClient';\n\nexport class AmazonStorageClient implements StorageClient {\n readonly provider = StorageProvider.AWSS3;\n\n static create(\n options: AmazonStorageClientCreateOptions,\n ): AmazonStorageClient {\n const {\n bucket,\n region,\n accessKeyId,\n acl,\n endpoint,\n secretAccessKey,\n forcePathStyle = false,\n cache,\n } = options;\n const hasCredentials = accessKeyId && secretAccessKey;\n const credentials = hasCredentials\n ? { accessKeyId, secretAccessKey }\n : undefined;\n\n const client = new S3Client({\n region,\n credentials,\n endpoint,\n forcePathStyle,\n });\n\n return new AmazonStorageClient(client, bucket, acl, cache);\n }\n constructor(\n private readonly client: S3Client,\n private readonly bucket: string,\n private readonly acl = AmazonCannedAccessControlList.AuthenticatedRead,\n readonly cache?: Cache<string>,\n ) {}\n\n getVersionDownloadURL(file: File, versionId: string): Promise<string> {\n const ResponseContentDisposition = file.name\n ? `attachment; filename=${encodeURIComponent(file.name)}`\n : undefined;\n\n const command = new GetObjectCommand({\n Bucket: this.bucket,\n Key: file.path,\n ResponseContentDisposition,\n VersionId: versionId,\n });\n\n return getSignedUrl(this.client, command, { expiresIn: 60 * 60 * 24 });\n }\n\n async getVersions(key: string): Promise<DocumentVersion[]> {\n const command = new ListObjectVersionsCommand({\n Bucket: this.bucket,\n Prefix: key,\n });\n\n const { Versions = [] } = await this.client.send(command);\n\n return Versions.map((version) => ({\n id: version.VersionId || '',\n createdAt: version.LastModified || new Date(),\n }));\n }\n\n async getDownloadURL(file: File, expiresIn = 60 * 60): Promise<string> {\n const cacheKey = `download-url:${file.path}`;\n const cachedURL = await this.cache?.get(cacheKey);\n\n if (cachedURL) {\n return cachedURL;\n }\n\n const ResponseContentDisposition = file.name\n ? `attachment; filename=${encodeURIComponent(file.name)}`\n : undefined;\n\n const command = new GetObjectCommand({\n Bucket: this.bucket,\n Key: file.path,\n ResponseContentDisposition,\n });\n\n const url = await getSignedUrl(this.client, command, { expiresIn });\n const cacheExpiration = Math.max(expiresIn - 60, 0);\n\n if (cacheExpiration) {\n await this.cache?.set(cacheKey, url, cacheExpiration);\n }\n\n return url;\n }\n\n async getUploadURL(\n params: GetUploadParams,\n expiresIn = 60 * 60,\n ): Promise<string> {\n const command = new PutObjectCommand({\n Bucket: this.bucket,\n Key: params.path,\n ContentType: params.contentType,\n ContentLength: params.contentLength,\n });\n\n return getSignedUrl(this.client, command, { expiresIn });\n }\n\n async getUpload(\n params: GetUploadParams,\n expiresIn = 5,\n ): Promise<GetUploadResponse> {\n const { path } = params;\n const { fields: values, url } = await createPresignedPost(this.client, {\n Expires: expiresIn * 60,\n Bucket: this.bucket,\n Fields: {\n acl: this.acl,\n },\n Conditions: [\n // content length restrictions: 0-1MB]\n // ['content-length-range', 0, contentLength],\n // specify content-type to be more generic- images only\n // ['starts-with', '$Content-Type', 'image/'],\n // ['starts-with', '$Content-Type', contentType],\n ],\n Key: path,\n });\n\n const keys = Object.keys(values);\n const fields = keys.map((key) => ({ key, value: values[key] || '' }));\n\n return { url, fields };\n }\n\n async upload(\n key: string,\n data: string | Buffer,\n contentType: string,\n ): Promise<void> {\n const Body = typeof data === 'string' ? Buffer.from(data, 'base64') : data;\n\n const params = {\n Bucket: this.bucket,\n Key: key,\n Body,\n ContentType: contentType,\n };\n\n const command = new PutObjectCommand(params);\n\n await this.client.send(command);\n }\n}\n\nexport enum AmazonCannedAccessControlList {\n AuthenticatedRead = 'authenticated-read',\n Private = 'private',\n PublicRead = 'public-read',\n PublicReadWrite = 'public-read-write',\n AwsExecRead = 'aws-exec-read',\n BucketOwnerRead = 'bucket-owner-read',\n BucketOwnerFullControl = 'bucket-owner-full-control',\n LogDeliveryWrite = 'log-delivery-write',\n}\n\ninterface AmazonStorageClientCreateOptions {\n bucket: string;\n region?: string;\n acl?: AmazonCannedAccessControlList;\n accessKeyId?: string;\n secretAccessKey?: string;\n endpoint?: string;\n forcePathStyle?: boolean;\n cache?: Cache<string>;\n}\n"],"mappings":"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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider } from "./StorageClient-
|
|
1
|
+
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider } from "./StorageClient-XgMsiUrd.mjs";
|
|
2
2
|
import { S3Client } from "@aws-sdk/client-s3";
|
|
3
3
|
import { Cache } from "@geekmidas/cache";
|
|
4
4
|
|
|
@@ -39,4 +39,5 @@ interface AmazonStorageClientCreateOptions {
|
|
|
39
39
|
cache?: Cache<string>;
|
|
40
40
|
}
|
|
41
41
|
//#endregion
|
|
42
|
-
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
42
|
+
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
43
|
+
//# sourceMappingURL=AmazonStorageClient-Gz0Fh1sy.d.mts.map
|
|
@@ -39,4 +39,5 @@ interface AmazonStorageClientCreateOptions {
|
|
|
39
39
|
cache?: Cache<string>;
|
|
40
40
|
}
|
|
41
41
|
//#endregion
|
|
42
|
-
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
42
|
+
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
43
|
+
//# sourceMappingURL=AmazonStorageClient-aduVU3_p.d.cts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
const require_AmazonStorageClient = require('./AmazonStorageClient-BKzXhCX0.cjs');
|
|
1
2
|
require('./StorageClient-BDRVrMJj.cjs');
|
|
2
|
-
const require_AmazonStorageClient = require('./AmazonStorageClient-tyGekctm.cjs');
|
|
3
3
|
|
|
4
4
|
exports.AmazonCannedAccessControlList = require_AmazonStorageClient.AmazonCannedAccessControlList;
|
|
5
5
|
exports.AmazonStorageClient = require_AmazonStorageClient.AmazonStorageClient;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./StorageClient-
|
|
2
|
-
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-
|
|
1
|
+
import "./StorageClient-XgMsiUrd.mjs";
|
|
2
|
+
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-Gz0Fh1sy.mjs";
|
|
3
3
|
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./StorageClient-
|
|
2
|
-
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-
|
|
1
|
+
import "./StorageClient-4ADnTPnJ.mjs";
|
|
2
|
+
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-CwUey48q.mjs";
|
|
3
3
|
|
|
4
4
|
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageClient-4ADnTPnJ.mjs","names":[],"sources":["../src/StorageClient.ts"],"sourcesContent":["import type { Cache } from '@geekmidas/cache';\nexport interface DocumentVersion {\n id: string;\n createdAt: Date;\n}\n\nexport enum StorageProvider {\n AWSS3 = 'geekimdas.toolbox.storage.aws.s3',\n GCP = 'geekimdas.toolbox.storage.gcp',\n AZURE = 'geekimdas.toolbox.storage.azure',\n}\n\nexport interface StorageClient {\n readonly provider: StorageProvider;\n readonly cache?: Cache<string>;\n /**\n * Get a URL to upload a file to.\n *\n * @param params - The parameters to get the upload URL for.\n * @param expiresIn - The number of minutes the URL should be valid for.\n * Defaults to 60 * 60 (1 hour).\n * @returns A promise that resolves to the upload URL.\n */\n getUploadURL(params: GetUploadParams, expiresIn?: number): Promise<string>;\n\n /**\n * Get a URL to download a file from.\n *\n * @param file - The file to get the download URL for.\n * @param expiresIn - The number of seconds the URL should be valid for.\n * Defaults to 60 * 60 (1 hour).\n * @returns A promise that resolves to the download URL.\n */\n getDownloadURL(file: File, expiresIn?: number): Promise<string>;\n /**\n * Get the versions for a key.\n *\n * @param key - The key to get the versions for.\n */\n getVersions(key: string): Promise<DocumentVersion[]>;\n\n /**\n * Get a URL to download a version of a file from.\n *\n * @param file - The file to get the download URL for.\n * @param versionId - The version ID to get the download URL for.\n */\n getVersionDownloadURL(file: File, versionId: string): Promise<string>;\n /**\n *\n * @param key - The key to upload the file to.\n * @param data - The data to upload.\n * @param contentType - The content type of the data.\n */\n upload(\n key: string,\n data: string | Buffer,\n contentType: string,\n ): Promise<void>;\n /**\n * Get a URL to upload a file to.\n *\n * @param params - The parameters to get the upload URL for.\n * @param expiresIn - The number of minutes the URL should be valid for.\n */\n getUpload(\n params: GetUploadParams,\n expiresIn?: number,\n ): Promise<GetUploadResponse>;\n}\n\nexport interface GetUploadParams {\n path: string;\n contentType: string;\n contentLength: number;\n}\n\nexport type UploadField = {\n key: string;\n value: string;\n};\n\nexport type GetUploadResponse = {\n url: string;\n fields: UploadField[];\n};\n\nexport interface File {\n name?: string;\n path: string;\n}\n"],"mappings":";AAMA,IAAY,8DAAL;AACL;AACA;AACA;;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageClient-BDRVrMJj.cjs","names":[],"sources":["../src/StorageClient.ts"],"sourcesContent":["import type { Cache } from '@geekmidas/cache';\nexport interface DocumentVersion {\n id: string;\n createdAt: Date;\n}\n\nexport enum StorageProvider {\n AWSS3 = 'geekimdas.toolbox.storage.aws.s3',\n GCP = 'geekimdas.toolbox.storage.gcp',\n AZURE = 'geekimdas.toolbox.storage.azure',\n}\n\nexport interface StorageClient {\n readonly provider: StorageProvider;\n readonly cache?: Cache<string>;\n /**\n * Get a URL to upload a file to.\n *\n * @param params - The parameters to get the upload URL for.\n * @param expiresIn - The number of minutes the URL should be valid for.\n * Defaults to 60 * 60 (1 hour).\n * @returns A promise that resolves to the upload URL.\n */\n getUploadURL(params: GetUploadParams, expiresIn?: number): Promise<string>;\n\n /**\n * Get a URL to download a file from.\n *\n * @param file - The file to get the download URL for.\n * @param expiresIn - The number of seconds the URL should be valid for.\n * Defaults to 60 * 60 (1 hour).\n * @returns A promise that resolves to the download URL.\n */\n getDownloadURL(file: File, expiresIn?: number): Promise<string>;\n /**\n * Get the versions for a key.\n *\n * @param key - The key to get the versions for.\n */\n getVersions(key: string): Promise<DocumentVersion[]>;\n\n /**\n * Get a URL to download a version of a file from.\n *\n * @param file - The file to get the download URL for.\n * @param versionId - The version ID to get the download URL for.\n */\n getVersionDownloadURL(file: File, versionId: string): Promise<string>;\n /**\n *\n * @param key - The key to upload the file to.\n * @param data - The data to upload.\n * @param contentType - The content type of the data.\n */\n upload(\n key: string,\n data: string | Buffer,\n contentType: string,\n ): Promise<void>;\n /**\n * Get a URL to upload a file to.\n *\n * @param params - The parameters to get the upload URL for.\n * @param expiresIn - The number of minutes the URL should be valid for.\n */\n getUpload(\n params: GetUploadParams,\n expiresIn?: number,\n ): Promise<GetUploadResponse>;\n}\n\nexport interface GetUploadParams {\n path: string;\n contentType: string;\n contentLength: number;\n}\n\nexport type UploadField = {\n key: string;\n value: string;\n};\n\nexport type GetUploadResponse = {\n url: string;\n fields: UploadField[];\n};\n\nexport interface File {\n name?: string;\n path: string;\n}\n"],"mappings":";;AAMA,IAAY,8DAAL;AACL;AACA;AACA;;AACD"}
|
|
@@ -77,4 +77,5 @@ interface File {
|
|
|
77
77
|
path: string;
|
|
78
78
|
}
|
|
79
79
|
//#endregion
|
|
80
|
-
export { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField };
|
|
80
|
+
export { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField };
|
|
81
|
+
//# sourceMappingURL=StorageClient-CcOAW3YV.d.cts.map
|
|
@@ -77,4 +77,5 @@ interface File {
|
|
|
77
77
|
path: string;
|
|
78
78
|
}
|
|
79
79
|
//#endregion
|
|
80
|
-
export { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField };
|
|
80
|
+
export { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField };
|
|
81
|
+
//# sourceMappingURL=StorageClient-XgMsiUrd.d.mts.map
|
package/dist/StorageClient.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField } from "./StorageClient-
|
|
1
|
+
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField } from "./StorageClient-XgMsiUrd.mjs";
|
|
2
2
|
export { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField };
|
package/dist/StorageClient.mjs
CHANGED
package/dist/aws.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
const require_AmazonStorageClient = require('./AmazonStorageClient-BKzXhCX0.cjs');
|
|
1
2
|
require('./StorageClient-BDRVrMJj.cjs');
|
|
2
|
-
const require_AmazonStorageClient = require('./AmazonStorageClient-tyGekctm.cjs');
|
|
3
3
|
|
|
4
4
|
exports.AmazonCannedAccessControlList = require_AmazonStorageClient.AmazonCannedAccessControlList;
|
|
5
5
|
exports.AmazonStorageClient = require_AmazonStorageClient.AmazonStorageClient;
|
package/dist/aws.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient } from "./StorageClient-
|
|
2
|
-
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-
|
|
1
|
+
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient } from "./StorageClient-XgMsiUrd.mjs";
|
|
2
|
+
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-Gz0Fh1sy.mjs";
|
|
3
3
|
export { AmazonCannedAccessControlList, AmazonStorageClient, DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient };
|
package/dist/aws.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./StorageClient-
|
|
2
|
-
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-
|
|
1
|
+
import "./StorageClient-4ADnTPnJ.mjs";
|
|
2
|
+
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-CwUey48q.mjs";
|
|
3
3
|
|
|
4
4
|
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { StorageClient } from "./StorageClient-
|
|
1
|
+
import { StorageClient } from "./StorageClient-XgMsiUrd.mjs";
|
|
2
2
|
export { StorageClient };
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/storage",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"private": false,
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/geekmidas/toolbox"
|
|
8
|
+
},
|
|
5
9
|
"publishConfig": {
|
|
6
10
|
"registry": "https://registry.npmjs.org/",
|
|
7
11
|
"access": "public"
|
|
@@ -19,14 +23,33 @@
|
|
|
19
23
|
"require": "./dist/index.cjs"
|
|
20
24
|
}
|
|
21
25
|
},
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@geekmidas/cache": "0.0.7"
|
|
24
|
-
},
|
|
26
|
+
"dependencies": {},
|
|
25
27
|
"peerDependencies": {
|
|
26
|
-
"zod": "~
|
|
28
|
+
"zod": "~4.1.13",
|
|
27
29
|
"@aws-sdk/client-s3": "~3.844.0",
|
|
28
30
|
"@aws-sdk/s3-presigned-post": "^3.844.0",
|
|
29
|
-
"@aws-sdk/s3-request-presigner": "~3.844.0"
|
|
31
|
+
"@aws-sdk/s3-request-presigner": "~3.844.0",
|
|
32
|
+
"@geekmidas/cache": "^0.1.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"@geekmidas/cache": {
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
38
|
+
"zod": {
|
|
39
|
+
"optional": true
|
|
40
|
+
},
|
|
41
|
+
"@aws-sdk/client-s3": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"@aws-sdk/s3-presigned-post": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"@aws-sdk/s3-request-presigner": {
|
|
48
|
+
"optional": true
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@geekmidas/cache": "^0.1.0"
|
|
30
53
|
},
|
|
31
54
|
"scripts": {}
|
|
32
55
|
}
|
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('../chunk-DWy1uDak.cjs');
|
|
2
|
-
const require_StorageClient = require('../StorageClient-BDRVrMJj.cjs');
|
|
3
|
-
const require_AmazonStorageClient = require('../AmazonStorageClient-tyGekctm.cjs');
|
|
4
|
-
const require_vi_bdSIJ99Y = require('../vi.bdSIJ99Y-D0m6qImj.cjs');
|
|
5
|
-
const __aws_sdk_client_s3 = require_chunk.__toESM(require("@aws-sdk/client-s3"));
|
|
6
|
-
const __geekmidas_cache_memory = require_chunk.__toESM(require("@geekmidas/cache/memory"));
|
|
7
|
-
|
|
8
|
-
//#region src/__tests__/AmazonStorageClient.spec.ts
|
|
9
|
-
require_vi_bdSIJ99Y.describe("AmazonStorageClient Integration Tests", () => {
|
|
10
|
-
let client;
|
|
11
|
-
const testBucket = "geekmidas";
|
|
12
|
-
const testKey = "test-files/test.txt";
|
|
13
|
-
const testContent = "Hello, World!";
|
|
14
|
-
const testContentType = "text/plain";
|
|
15
|
-
require_vi_bdSIJ99Y.beforeAll(async () => {
|
|
16
|
-
client = require_AmazonStorageClient.AmazonStorageClient.create({
|
|
17
|
-
bucket: testBucket,
|
|
18
|
-
region: "us-east-1",
|
|
19
|
-
accessKeyId: "geekmidas",
|
|
20
|
-
secretAccessKey: "geekmidas",
|
|
21
|
-
endpoint: "http://localhost:9000",
|
|
22
|
-
acl: require_AmazonStorageClient.AmazonCannedAccessControlList.PublicRead,
|
|
23
|
-
forcePathStyle: true
|
|
24
|
-
});
|
|
25
|
-
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
26
|
-
});
|
|
27
|
-
require_vi_bdSIJ99Y.describe("provider property", () => {
|
|
28
|
-
require_vi_bdSIJ99Y.it("should return AWS S3 provider", () => {
|
|
29
|
-
require_vi_bdSIJ99Y.globalExpect(client.provider).toBe(require_StorageClient.StorageProvider.AWSS3);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
require_vi_bdSIJ99Y.describe("upload and download workflow", () => {
|
|
33
|
-
require_vi_bdSIJ99Y.it.skip("should upload a file directly and generate download URL", async () => {
|
|
34
|
-
await client.upload(testKey, testContent, testContentType);
|
|
35
|
-
const downloadUrl = await client.getDownloadURL({ path: testKey });
|
|
36
|
-
require_vi_bdSIJ99Y.globalExpect(downloadUrl).toMatch(/^http:\/\/localhost:9000\/geekmidas\/test-files\/test\.txt/);
|
|
37
|
-
require_vi_bdSIJ99Y.globalExpect(downloadUrl).toContain("X-Amz-Algorithm=AWS4-HMAC-SHA256");
|
|
38
|
-
require_vi_bdSIJ99Y.globalExpect(downloadUrl).toContain("X-Amz-Credential=");
|
|
39
|
-
require_vi_bdSIJ99Y.globalExpect(downloadUrl).toContain("X-Amz-Date=");
|
|
40
|
-
require_vi_bdSIJ99Y.globalExpect(downloadUrl).toContain("X-Amz-SignedHeaders=");
|
|
41
|
-
require_vi_bdSIJ99Y.globalExpect(downloadUrl).toContain("X-Amz-Signature=");
|
|
42
|
-
const response = await fetch(downloadUrl);
|
|
43
|
-
require_vi_bdSIJ99Y.globalExpect(response.ok).toBe(true);
|
|
44
|
-
const downloadedContent = await response.text();
|
|
45
|
-
require_vi_bdSIJ99Y.globalExpect(downloadedContent).toBe(testContent);
|
|
46
|
-
});
|
|
47
|
-
require_vi_bdSIJ99Y.it("should upload a file with filename and generate download URL with content disposition", async () => {
|
|
48
|
-
const keyWithName = "test-files/named-file.txt";
|
|
49
|
-
const fileName = "my-document.txt";
|
|
50
|
-
await client.upload(keyWithName, testContent, testContentType);
|
|
51
|
-
const downloadUrl = await client.getDownloadURL({
|
|
52
|
-
path: keyWithName,
|
|
53
|
-
name: fileName
|
|
54
|
-
});
|
|
55
|
-
require_vi_bdSIJ99Y.globalExpect(downloadUrl).toContain("response-content-disposition=attachment%3B%20filename%3Dmy-document.txt");
|
|
56
|
-
});
|
|
57
|
-
require_vi_bdSIJ99Y.it("should handle binary data upload", async () => {
|
|
58
|
-
const binaryKey = "test-files/binary.bin";
|
|
59
|
-
const binaryData = Buffer.from([
|
|
60
|
-
72,
|
|
61
|
-
101,
|
|
62
|
-
108,
|
|
63
|
-
108,
|
|
64
|
-
111
|
|
65
|
-
]);
|
|
66
|
-
await client.upload(binaryKey, binaryData, "application/octet-stream");
|
|
67
|
-
const downloadUrl = await client.getDownloadURL({ path: binaryKey });
|
|
68
|
-
const response = await fetch(downloadUrl);
|
|
69
|
-
const downloadedBuffer = await response.arrayBuffer();
|
|
70
|
-
require_vi_bdSIJ99Y.globalExpect(new Uint8Array(downloadedBuffer)).toEqual(new Uint8Array(binaryData));
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
require_vi_bdSIJ99Y.describe("presigned upload URLs", () => {
|
|
74
|
-
require_vi_bdSIJ99Y.it("should generate presigned PUT upload URL", async () => {
|
|
75
|
-
const uploadKey = "test-files/presigned-upload.txt";
|
|
76
|
-
const uploadUrl = await client.getUploadURL({
|
|
77
|
-
path: uploadKey,
|
|
78
|
-
contentType: testContentType,
|
|
79
|
-
contentLength: testContent.length
|
|
80
|
-
});
|
|
81
|
-
require_vi_bdSIJ99Y.globalExpect(uploadUrl).toMatch(/^http:\/\/localhost:9000\/geekmidas\/test-files\/presigned-upload\.txt/);
|
|
82
|
-
require_vi_bdSIJ99Y.globalExpect(uploadUrl).toContain("X-Amz-Algorithm=AWS4-HMAC-SHA256");
|
|
83
|
-
const uploadResponse = await fetch(uploadUrl, {
|
|
84
|
-
method: "PUT",
|
|
85
|
-
headers: {
|
|
86
|
-
"Content-Type": testContentType,
|
|
87
|
-
"Content-Length": testContent.length.toString()
|
|
88
|
-
},
|
|
89
|
-
body: testContent
|
|
90
|
-
});
|
|
91
|
-
require_vi_bdSIJ99Y.globalExpect(uploadResponse.ok).toBe(true);
|
|
92
|
-
const downloadUrl = await client.getDownloadURL({ path: uploadKey });
|
|
93
|
-
const downloadResponse = await fetch(downloadUrl);
|
|
94
|
-
const downloadedContent = await downloadResponse.text();
|
|
95
|
-
require_vi_bdSIJ99Y.globalExpect(downloadedContent).toBe(testContent);
|
|
96
|
-
});
|
|
97
|
-
require_vi_bdSIJ99Y.it("should generate presigned POST upload with form fields", async () => {
|
|
98
|
-
const uploadKey = "test-files/presigned-post.txt";
|
|
99
|
-
const uploadData = await client.getUpload({
|
|
100
|
-
path: uploadKey,
|
|
101
|
-
contentType: testContentType,
|
|
102
|
-
contentLength: testContent.length
|
|
103
|
-
});
|
|
104
|
-
require_vi_bdSIJ99Y.globalExpect(uploadData.url).toBe("http://localhost:9000/geekmidas");
|
|
105
|
-
require_vi_bdSIJ99Y.globalExpect(uploadData.fields).toContainEqual({
|
|
106
|
-
key: "key",
|
|
107
|
-
value: uploadKey
|
|
108
|
-
});
|
|
109
|
-
require_vi_bdSIJ99Y.globalExpect(uploadData.fields).toContainEqual({
|
|
110
|
-
key: "acl",
|
|
111
|
-
value: "public-read"
|
|
112
|
-
});
|
|
113
|
-
const formData = new FormData();
|
|
114
|
-
uploadData.fields.forEach(({ key, value }) => {
|
|
115
|
-
formData.append(key, value);
|
|
116
|
-
});
|
|
117
|
-
formData.append("file", new Blob([testContent], { type: testContentType }));
|
|
118
|
-
const uploadResponse = await fetch(uploadData.url, {
|
|
119
|
-
method: "POST",
|
|
120
|
-
body: formData
|
|
121
|
-
});
|
|
122
|
-
require_vi_bdSIJ99Y.globalExpect(uploadResponse.ok).toBe(true);
|
|
123
|
-
const downloadUrl = await client.getDownloadURL({ path: uploadKey });
|
|
124
|
-
const downloadResponse = await fetch(downloadUrl);
|
|
125
|
-
const downloadedContent = await downloadResponse.blob();
|
|
126
|
-
require_vi_bdSIJ99Y.globalExpect(downloadedContent).toEqual(new Blob([testContent], { type: testContentType }));
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
require_vi_bdSIJ99Y.describe("versioning", () => {
|
|
130
|
-
require_vi_bdSIJ99Y.it("should handle file versions", async () => {
|
|
131
|
-
const versionKey = "test-files/versioned.txt";
|
|
132
|
-
const content1 = "Version 1";
|
|
133
|
-
const content2 = "Version 2";
|
|
134
|
-
await client.upload(versionKey, content1, testContentType);
|
|
135
|
-
await client.upload(versionKey, content2, testContentType);
|
|
136
|
-
const versions = await client.getVersions(versionKey);
|
|
137
|
-
require_vi_bdSIJ99Y.globalExpect(Array.isArray(versions)).toBe(true);
|
|
138
|
-
if (versions.length > 0) {
|
|
139
|
-
require_vi_bdSIJ99Y.globalExpect(versions[0]).toHaveProperty("id");
|
|
140
|
-
require_vi_bdSIJ99Y.globalExpect(versions[0]).toHaveProperty("createdAt");
|
|
141
|
-
require_vi_bdSIJ99Y.globalExpect(versions[0].createdAt).toBeInstanceOf(Date);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
require_vi_bdSIJ99Y.describe("error handling", () => {
|
|
146
|
-
require_vi_bdSIJ99Y.it("should handle download URL generation for non-existent files", async () => {
|
|
147
|
-
const downloadUrl = await client.getDownloadURL({ path: "non-existent/file.txt" });
|
|
148
|
-
require_vi_bdSIJ99Y.globalExpect(downloadUrl).toMatch(/^http:\/\/localhost:9000\/geekmidas\/non-existent\/file\.txt/);
|
|
149
|
-
const response = await fetch(downloadUrl);
|
|
150
|
-
require_vi_bdSIJ99Y.globalExpect(response.status).toBe(404);
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
require_vi_bdSIJ99Y.describe("custom expiration times", () => {
|
|
154
|
-
require_vi_bdSIJ99Y.it("should respect custom expiration for download URLs", async () => {
|
|
155
|
-
const key = "test-files/expiration-test.txt";
|
|
156
|
-
await client.upload(key, testContent, testContentType);
|
|
157
|
-
const shortExpirationUrl = await client.getDownloadURL({ path: key }, 1);
|
|
158
|
-
const longExpirationUrl = await client.getDownloadURL({ path: key }, 3600);
|
|
159
|
-
require_vi_bdSIJ99Y.globalExpect(shortExpirationUrl).toContain("X-Amz-Expires=1");
|
|
160
|
-
require_vi_bdSIJ99Y.globalExpect(longExpirationUrl).toContain("X-Amz-Expires=3600");
|
|
161
|
-
});
|
|
162
|
-
require_vi_bdSIJ99Y.it("should respect custom expiration for upload URLs", async () => {
|
|
163
|
-
const key = "test-files/upload-expiration-test.txt";
|
|
164
|
-
const shortExpirationUrl = await client.getUploadURL({
|
|
165
|
-
path: key,
|
|
166
|
-
contentType: testContentType,
|
|
167
|
-
contentLength: testContent.length
|
|
168
|
-
}, 1);
|
|
169
|
-
const longExpirationUrl = await client.getUploadURL({
|
|
170
|
-
path: key,
|
|
171
|
-
contentType: testContentType,
|
|
172
|
-
contentLength: testContent.length
|
|
173
|
-
}, 3600);
|
|
174
|
-
require_vi_bdSIJ99Y.globalExpect(shortExpirationUrl).toContain("X-Amz-Expires=1");
|
|
175
|
-
require_vi_bdSIJ99Y.globalExpect(longExpirationUrl).toContain("X-Amz-Expires=3600");
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
require_vi_bdSIJ99Y.describe("factory method", () => {
|
|
179
|
-
require_vi_bdSIJ99Y.it("should create client with minimal configuration", () => {
|
|
180
|
-
const minimalClient = require_AmazonStorageClient.AmazonStorageClient.create({ bucket: "geekmidas" });
|
|
181
|
-
require_vi_bdSIJ99Y.globalExpect(minimalClient).toBeInstanceOf(require_AmazonStorageClient.AmazonStorageClient);
|
|
182
|
-
require_vi_bdSIJ99Y.globalExpect(minimalClient.provider).toBe(require_StorageClient.StorageProvider.AWSS3);
|
|
183
|
-
});
|
|
184
|
-
require_vi_bdSIJ99Y.it("should create client with full configuration", () => {
|
|
185
|
-
const fullClient = require_AmazonStorageClient.AmazonStorageClient.create({
|
|
186
|
-
bucket: "geekmidas",
|
|
187
|
-
region: "us-west-2",
|
|
188
|
-
accessKeyId: "test-key",
|
|
189
|
-
secretAccessKey: "test-secret",
|
|
190
|
-
endpoint: "https://custom-s3.example.com",
|
|
191
|
-
acl: require_AmazonStorageClient.AmazonCannedAccessControlList.Private
|
|
192
|
-
});
|
|
193
|
-
require_vi_bdSIJ99Y.globalExpect(fullClient).toBeInstanceOf(require_AmazonStorageClient.AmazonStorageClient);
|
|
194
|
-
require_vi_bdSIJ99Y.globalExpect(fullClient.provider).toBe(require_StorageClient.StorageProvider.AWSS3);
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
require_vi_bdSIJ99Y.describe("different ACL configurations", () => {
|
|
198
|
-
require_vi_bdSIJ99Y.it("should work with different ACL settings", async () => {
|
|
199
|
-
const privateClient = require_AmazonStorageClient.AmazonStorageClient.create({
|
|
200
|
-
bucket: testBucket,
|
|
201
|
-
region: "us-east-1",
|
|
202
|
-
accessKeyId: "minioadmin",
|
|
203
|
-
secretAccessKey: "minioadmin",
|
|
204
|
-
endpoint: "http://localhost:9000",
|
|
205
|
-
acl: require_AmazonStorageClient.AmazonCannedAccessControlList.Private
|
|
206
|
-
});
|
|
207
|
-
const uploadData = await privateClient.getUpload({
|
|
208
|
-
path: "test-files/private.txt",
|
|
209
|
-
contentType: testContentType,
|
|
210
|
-
contentLength: testContent.length
|
|
211
|
-
});
|
|
212
|
-
require_vi_bdSIJ99Y.globalExpect(uploadData.fields).toContainEqual({
|
|
213
|
-
key: "acl",
|
|
214
|
-
value: "private"
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
require_vi_bdSIJ99Y.describe("S3Client integration", () => {
|
|
219
|
-
require_vi_bdSIJ99Y.it("should work with externally created S3Client", () => {
|
|
220
|
-
const s3Client = new __aws_sdk_client_s3.S3Client({
|
|
221
|
-
region: "us-east-1",
|
|
222
|
-
credentials: {
|
|
223
|
-
accessKeyId: "minioadmin",
|
|
224
|
-
secretAccessKey: "minioadmin"
|
|
225
|
-
},
|
|
226
|
-
endpoint: "http://localhost:9000"
|
|
227
|
-
});
|
|
228
|
-
const storageClient = new require_AmazonStorageClient.AmazonStorageClient(s3Client, testBucket, require_AmazonStorageClient.AmazonCannedAccessControlList.PublicRead);
|
|
229
|
-
require_vi_bdSIJ99Y.globalExpect(storageClient).toBeInstanceOf(require_AmazonStorageClient.AmazonStorageClient);
|
|
230
|
-
require_vi_bdSIJ99Y.globalExpect(storageClient.provider).toBe(require_StorageClient.StorageProvider.AWSS3);
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
require_vi_bdSIJ99Y.describe("cache functionality", () => {
|
|
234
|
-
require_vi_bdSIJ99Y.it("should cache download URLs", async () => {
|
|
235
|
-
const cache = new __geekmidas_cache_memory.InMemoryCache();
|
|
236
|
-
const clientWithCache = require_AmazonStorageClient.AmazonStorageClient.create({
|
|
237
|
-
bucket: testBucket,
|
|
238
|
-
region: "us-east-1",
|
|
239
|
-
accessKeyId: "geekmidas",
|
|
240
|
-
secretAccessKey: "geekmidas",
|
|
241
|
-
endpoint: "http://localhost:9000",
|
|
242
|
-
forcePathStyle: true,
|
|
243
|
-
cache
|
|
244
|
-
});
|
|
245
|
-
const key = "test-files/cache-test.txt";
|
|
246
|
-
await clientWithCache.upload(key, testContent, testContentType);
|
|
247
|
-
const url1 = await clientWithCache.getDownloadURL({ path: key });
|
|
248
|
-
const url2 = await clientWithCache.getDownloadURL({ path: key });
|
|
249
|
-
require_vi_bdSIJ99Y.globalExpect(url1).toBe(url2);
|
|
250
|
-
const cacheKey = `download-url:${key}`;
|
|
251
|
-
const cachedUrl = await cache.get(cacheKey);
|
|
252
|
-
require_vi_bdSIJ99Y.globalExpect(cachedUrl).toBe(url1);
|
|
253
|
-
});
|
|
254
|
-
require_vi_bdSIJ99Y.it("should respect cache expiration based on URL expiry", async () => {
|
|
255
|
-
const cache = new __geekmidas_cache_memory.InMemoryCache();
|
|
256
|
-
const clientWithCache = require_AmazonStorageClient.AmazonStorageClient.create({
|
|
257
|
-
bucket: testBucket,
|
|
258
|
-
region: "us-east-1",
|
|
259
|
-
accessKeyId: "geekmidas",
|
|
260
|
-
secretAccessKey: "geekmidas",
|
|
261
|
-
endpoint: "http://localhost:9000",
|
|
262
|
-
forcePathStyle: true,
|
|
263
|
-
cache
|
|
264
|
-
});
|
|
265
|
-
const key = "test-files/cache-expiry.txt";
|
|
266
|
-
await clientWithCache.upload(key, testContent, testContentType);
|
|
267
|
-
await clientWithCache.getDownloadURL({ path: key }, 30);
|
|
268
|
-
const cacheKey = `download-url:${key}`;
|
|
269
|
-
const cachedShortUrl = await cache.get(cacheKey);
|
|
270
|
-
require_vi_bdSIJ99Y.globalExpect(cachedShortUrl).toBeUndefined();
|
|
271
|
-
const longExpiryUrl = await clientWithCache.getDownloadURL({ path: key }, 3600);
|
|
272
|
-
const cachedLongUrl = await cache.get(cacheKey);
|
|
273
|
-
require_vi_bdSIJ99Y.globalExpect(cachedLongUrl).toBe(longExpiryUrl);
|
|
274
|
-
});
|
|
275
|
-
require_vi_bdSIJ99Y.it("should use cached URL when available", async () => {
|
|
276
|
-
const cache = new __geekmidas_cache_memory.InMemoryCache();
|
|
277
|
-
const clientWithCache = require_AmazonStorageClient.AmazonStorageClient.create({
|
|
278
|
-
bucket: testBucket,
|
|
279
|
-
region: "us-east-1",
|
|
280
|
-
accessKeyId: "geekmidas",
|
|
281
|
-
secretAccessKey: "geekmidas",
|
|
282
|
-
endpoint: "http://localhost:9000",
|
|
283
|
-
forcePathStyle: true,
|
|
284
|
-
cache
|
|
285
|
-
});
|
|
286
|
-
const key = "test-files/pre-cached.txt";
|
|
287
|
-
const cachedUrl = "https://pre-cached-url.example.com";
|
|
288
|
-
const cacheKey = `download-url:${key}`;
|
|
289
|
-
await cache.set(cacheKey, cachedUrl);
|
|
290
|
-
const url = await clientWithCache.getDownloadURL({ path: key });
|
|
291
|
-
require_vi_bdSIJ99Y.globalExpect(url).toBe(cachedUrl);
|
|
292
|
-
});
|
|
293
|
-
require_vi_bdSIJ99Y.it("should work without cache", async () => {
|
|
294
|
-
const clientNoCache = require_AmazonStorageClient.AmazonStorageClient.create({
|
|
295
|
-
bucket: testBucket,
|
|
296
|
-
region: "us-east-1",
|
|
297
|
-
accessKeyId: "geekmidas",
|
|
298
|
-
secretAccessKey: "geekmidas",
|
|
299
|
-
endpoint: "http://localhost:9000",
|
|
300
|
-
forcePathStyle: true
|
|
301
|
-
});
|
|
302
|
-
const key = "test-files/no-cache.txt";
|
|
303
|
-
await clientNoCache.upload(key, testContent, testContentType);
|
|
304
|
-
const url1 = await clientNoCache.getDownloadURL({ path: key });
|
|
305
|
-
const url2 = await clientNoCache.getDownloadURL({ path: key });
|
|
306
|
-
require_vi_bdSIJ99Y.globalExpect(url1).toMatch(/^http:\/\/localhost:9000\/geekmidas\/test-files\/no-cache\.txt/);
|
|
307
|
-
require_vi_bdSIJ99Y.globalExpect(url2).toMatch(/^http:\/\/localhost:9000\/geekmidas\/test-files\/no-cache\.txt/);
|
|
308
|
-
});
|
|
309
|
-
require_vi_bdSIJ99Y.it("should pass cache to constructor", () => {
|
|
310
|
-
const cache = new __geekmidas_cache_memory.InMemoryCache();
|
|
311
|
-
const s3Client = new __aws_sdk_client_s3.S3Client({
|
|
312
|
-
region: "us-east-1",
|
|
313
|
-
credentials: {
|
|
314
|
-
accessKeyId: "geekmidas",
|
|
315
|
-
secretAccessKey: "geekmidas"
|
|
316
|
-
},
|
|
317
|
-
endpoint: "http://localhost:9000",
|
|
318
|
-
forcePathStyle: true
|
|
319
|
-
});
|
|
320
|
-
const clientWithCache = new require_AmazonStorageClient.AmazonStorageClient(s3Client, testBucket, require_AmazonStorageClient.AmazonCannedAccessControlList.PublicRead, cache);
|
|
321
|
-
require_vi_bdSIJ99Y.globalExpect(clientWithCache.cache).toBe(cache);
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
require_vi_bdSIJ99Y.describe("getVersionDownloadURL", () => {
|
|
325
|
-
require_vi_bdSIJ99Y.it("should generate version-specific download URL", async () => {
|
|
326
|
-
const versionKey = "test-files/version-download.txt";
|
|
327
|
-
const versionId = "test-version-id";
|
|
328
|
-
await client.upload(versionKey, testContent, testContentType);
|
|
329
|
-
const downloadUrl = await client.getVersionDownloadURL({
|
|
330
|
-
path: versionKey,
|
|
331
|
-
name: "versioned-file.txt"
|
|
332
|
-
}, versionId);
|
|
333
|
-
require_vi_bdSIJ99Y.globalExpect(downloadUrl).toMatch(/^http:\/\/localhost:9000\/geekmidas\/test-files\/version-download\.txt/);
|
|
334
|
-
require_vi_bdSIJ99Y.globalExpect(downloadUrl).toContain("X-Amz-Algorithm=AWS4-HMAC-SHA256");
|
|
335
|
-
require_vi_bdSIJ99Y.globalExpect(downloadUrl).toContain("response-content-disposition=attachment%3B%20filename%3Dversioned-file.txt");
|
|
336
|
-
});
|
|
337
|
-
require_vi_bdSIJ99Y.it("should generate version URL without filename", async () => {
|
|
338
|
-
const versionKey = "test-files/version-no-name.txt";
|
|
339
|
-
const versionId = "test-version-id";
|
|
340
|
-
await client.upload(versionKey, testContent, testContentType);
|
|
341
|
-
const downloadUrl = await client.getVersionDownloadURL({ path: versionKey }, versionId);
|
|
342
|
-
require_vi_bdSIJ99Y.globalExpect(downloadUrl).toMatch(/^http:\/\/localhost:9000\/geekmidas\/test-files\/version-no-name\.txt/);
|
|
343
|
-
require_vi_bdSIJ99Y.globalExpect(downloadUrl).not.toContain("response-content-disposition");
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
//#endregion
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|