@geekmidas/storage 9.0.2 → 10.0.0-alpha.1
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/aws.cjs +159 -4
- package/dist/aws.cjs.map +1 -0
- package/dist/aws.d.cts +51 -3
- package/dist/aws.d.cts.map +1 -0
- package/dist/aws.d.mts +51 -3
- package/dist/aws.d.mts.map +1 -0
- package/dist/aws.mjs +151 -3
- package/dist/aws.mjs.map +1 -0
- package/dist/chunk-B9dir_RE.mjs +11 -0
- package/dist/errors-Bce0CJ11.cjs +109 -0
- package/dist/errors-Bce0CJ11.cjs.map +1 -0
- package/dist/errors-D5UnAd-X.mjs +79 -0
- package/dist/errors-D5UnAd-X.mjs.map +1 -0
- package/dist/index.cjs +39 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +66 -2
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +66 -2
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +32 -0
- package/dist/index.mjs.map +1 -0
- package/dist/{StorageClient-COs9SOsU.d.cts → registry-DBsAUTT3.d.cts} +27 -2
- package/dist/registry-DBsAUTT3.d.cts.map +1 -0
- package/dist/{StorageClient-DH4tP-Mf.d.mts → registry-DEqSHjx-.d.mts} +27 -2
- package/dist/registry-DEqSHjx-.d.mts.map +1 -0
- package/dist/s3Url-BfztIltX.d.cts +39 -0
- package/dist/s3Url-BfztIltX.d.cts.map +1 -0
- package/dist/s3Url-Bo32UTTA.cjs +103 -0
- package/dist/s3Url-Bo32UTTA.cjs.map +1 -0
- package/dist/s3Url-C8FGPNrG.mjs +52 -0
- package/dist/s3Url-C8FGPNrG.mjs.map +1 -0
- package/dist/s3Url-COpMIgF9.d.mts +42 -0
- package/dist/s3Url-COpMIgF9.d.mts.map +1 -0
- package/dist/s3Url.cjs +5 -0
- package/dist/s3Url.d.cts +2 -0
- package/dist/s3Url.d.mts +2 -0
- package/dist/s3Url.mjs +4 -0
- package/package.json +16 -3
- package/CHANGELOG.md +0 -72
- package/dist/AmazonStorageClient-BHpWawGD.d.mts +0 -45
- package/dist/AmazonStorageClient-BHpWawGD.d.mts.map +0 -1
- package/dist/AmazonStorageClient-BNoY2PL6.d.cts +0 -45
- package/dist/AmazonStorageClient-BNoY2PL6.d.cts.map +0 -1
- package/dist/AmazonStorageClient-BvoZepKJ.cjs +0 -161
- package/dist/AmazonStorageClient-BvoZepKJ.cjs.map +0 -1
- package/dist/AmazonStorageClient-Dz-KCJ_4.mjs +0 -127
- package/dist/AmazonStorageClient-Dz-KCJ_4.mjs.map +0 -1
- package/dist/AmazonStorageClient.cjs +0 -5
- package/dist/AmazonStorageClient.d.cts +0 -3
- package/dist/AmazonStorageClient.d.mts +0 -3
- package/dist/AmazonStorageClient.mjs +0 -4
- package/dist/StorageClient-4ADnTPnJ.mjs +0 -11
- package/dist/StorageClient-4ADnTPnJ.mjs.map +0 -1
- package/dist/StorageClient-BDRVrMJj.cjs +0 -17
- package/dist/StorageClient-BDRVrMJj.cjs.map +0 -1
- package/dist/StorageClient-COs9SOsU.d.cts.map +0 -1
- package/dist/StorageClient-DH4tP-Mf.d.mts.map +0 -1
- package/dist/StorageClient.cjs +0 -3
- package/dist/StorageClient.d.cts +0 -2
- package/dist/StorageClient.d.mts +0 -2
- package/dist/StorageClient.mjs +0 -3
- package/src/AmazonStorageClient.ts +0 -207
- package/src/StorageClient.ts +0 -108
- package/src/__tests__/AmazonStorageClient.spec.ts +0 -606
- package/src/__tests__/StorageClient.spec.ts +0 -98
- package/src/aws.ts +0 -11
- package/src/index.ts +0 -1
- package/tsconfig.json +0 -9
- package/tsdown.config.ts +0 -9
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StorageClient-4ADnTPnJ.mjs","names":[],"sources":["../src/StorageClient.ts"],"sourcesContent":["import type { Cache } from '@geekmidas/cache';\nexport interface DocumentVersion {\n\tid: string;\n\tcreatedAt: Date;\n}\n\nexport enum StorageProvider {\n\tAWSS3 = 'geekimdas.toolbox.storage.aws.s3',\n\tGCP = 'geekimdas.toolbox.storage.gcp',\n\tAZURE = 'geekimdas.toolbox.storage.azure',\n}\n\nexport interface StorageClient {\n\treadonly provider: StorageProvider;\n\treadonly cache?: Cache;\n\t/**\n\t * Get a URL to upload a file to.\n\t *\n\t * @param params - The parameters to get the upload URL for.\n\t * @param expiresIn - The number of minutes the URL should be valid for.\n\t * Defaults to 60 * 60 (1 hour).\n\t * @returns A promise that resolves to the upload URL.\n\t */\n\tgetUploadURL(params: GetUploadParams, expiresIn?: number): Promise<string>;\n\n\t/**\n\t * Get a URL to download a file from.\n\t *\n\t * @param file - The file to get the download URL for.\n\t * @param expiresIn - The number of seconds the URL should be valid for.\n\t * Defaults to 60 * 60 (1 hour).\n\t * @returns A promise that resolves to the download URL.\n\t */\n\tgetDownloadURL(file: File, expiresIn?: number): Promise<string>;\n\t/**\n\t * Get the versions for a key.\n\t *\n\t * @param key - The key to get the versions for.\n\t */\n\tgetVersions(key: string): Promise<DocumentVersion[]>;\n\n\t/**\n\t * Get a URL to download a version of a file from.\n\t *\n\t * @param file - The file to get the download URL for.\n\t * @param versionId - The version ID to get the download URL for.\n\t */\n\tgetVersionDownloadURL(file: File, versionId: string): Promise<string>;\n\t/**\n\t *\n\t * @param key - The key to upload the file to.\n\t * @param data - The data to upload.\n\t * @param contentType - The content type of the data.\n\t */\n\tupload(\n\t\tkey: string,\n\t\tdata: string | Buffer,\n\t\tcontentType: string,\n\t): Promise<void>;\n\t/**\n\t * Get a URL to upload a file to.\n\t *\n\t * @param params - The parameters to get the upload URL for.\n\t * @param expiresIn - The number of minutes the URL should be valid for.\n\t */\n\tgetUpload(\n\t\tparams: GetUploadParams,\n\t\texpiresIn?: number,\n\t): Promise<GetUploadResponse>;\n\t/**\n\t * Delete a file from storage.\n\t *\n\t * @param key - The key (path) of the file to delete.\n\t */\n\tdelete(key: string): Promise<void>;\n}\n\nexport interface GetUploadParams {\n\tpath: string;\n\tcontentType: string;\n\tcontentLength: number;\n}\n\nexport type UploadField = {\n\tkey: string;\n\tvalue: string;\n};\n\nexport type GetUploadResponse = {\n\turl: string;\n\tfields: UploadField[];\n};\n\nexport interface File {\n\tname?: string;\n\tpath: string;\n\t/**\n\t * Override the Content-Type of the response.\n\t * Useful when the stored object's content type differs from what the browser should receive.\n\t */\n\tresponseContentType?: string;\n\t/**\n\t * Control how the browser handles the file.\n\t * - `'attachment'` — prompts download (default when `name` is set)\n\t * - `'inline'` — displays in the browser\n\t */\n\tdisposition?: 'inline' | 'attachment';\n}\n"],"mappings":";AAMA,IAAY,8DAAL;AACN;AACA;AACA;;AACA"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/StorageClient.ts
|
|
3
|
-
let StorageProvider = /* @__PURE__ */ function(StorageProvider$1) {
|
|
4
|
-
StorageProvider$1["AWSS3"] = "geekimdas.toolbox.storage.aws.s3";
|
|
5
|
-
StorageProvider$1["GCP"] = "geekimdas.toolbox.storage.gcp";
|
|
6
|
-
StorageProvider$1["AZURE"] = "geekimdas.toolbox.storage.azure";
|
|
7
|
-
return StorageProvider$1;
|
|
8
|
-
}({});
|
|
9
|
-
|
|
10
|
-
//#endregion
|
|
11
|
-
Object.defineProperty(exports, 'StorageProvider', {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () {
|
|
14
|
-
return StorageProvider;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
//# sourceMappingURL=StorageClient-BDRVrMJj.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StorageClient-BDRVrMJj.cjs","names":[],"sources":["../src/StorageClient.ts"],"sourcesContent":["import type { Cache } from '@geekmidas/cache';\nexport interface DocumentVersion {\n\tid: string;\n\tcreatedAt: Date;\n}\n\nexport enum StorageProvider {\n\tAWSS3 = 'geekimdas.toolbox.storage.aws.s3',\n\tGCP = 'geekimdas.toolbox.storage.gcp',\n\tAZURE = 'geekimdas.toolbox.storage.azure',\n}\n\nexport interface StorageClient {\n\treadonly provider: StorageProvider;\n\treadonly cache?: Cache;\n\t/**\n\t * Get a URL to upload a file to.\n\t *\n\t * @param params - The parameters to get the upload URL for.\n\t * @param expiresIn - The number of minutes the URL should be valid for.\n\t * Defaults to 60 * 60 (1 hour).\n\t * @returns A promise that resolves to the upload URL.\n\t */\n\tgetUploadURL(params: GetUploadParams, expiresIn?: number): Promise<string>;\n\n\t/**\n\t * Get a URL to download a file from.\n\t *\n\t * @param file - The file to get the download URL for.\n\t * @param expiresIn - The number of seconds the URL should be valid for.\n\t * Defaults to 60 * 60 (1 hour).\n\t * @returns A promise that resolves to the download URL.\n\t */\n\tgetDownloadURL(file: File, expiresIn?: number): Promise<string>;\n\t/**\n\t * Get the versions for a key.\n\t *\n\t * @param key - The key to get the versions for.\n\t */\n\tgetVersions(key: string): Promise<DocumentVersion[]>;\n\n\t/**\n\t * Get a URL to download a version of a file from.\n\t *\n\t * @param file - The file to get the download URL for.\n\t * @param versionId - The version ID to get the download URL for.\n\t */\n\tgetVersionDownloadURL(file: File, versionId: string): Promise<string>;\n\t/**\n\t *\n\t * @param key - The key to upload the file to.\n\t * @param data - The data to upload.\n\t * @param contentType - The content type of the data.\n\t */\n\tupload(\n\t\tkey: string,\n\t\tdata: string | Buffer,\n\t\tcontentType: string,\n\t): Promise<void>;\n\t/**\n\t * Get a URL to upload a file to.\n\t *\n\t * @param params - The parameters to get the upload URL for.\n\t * @param expiresIn - The number of minutes the URL should be valid for.\n\t */\n\tgetUpload(\n\t\tparams: GetUploadParams,\n\t\texpiresIn?: number,\n\t): Promise<GetUploadResponse>;\n\t/**\n\t * Delete a file from storage.\n\t *\n\t * @param key - The key (path) of the file to delete.\n\t */\n\tdelete(key: string): Promise<void>;\n}\n\nexport interface GetUploadParams {\n\tpath: string;\n\tcontentType: string;\n\tcontentLength: number;\n}\n\nexport type UploadField = {\n\tkey: string;\n\tvalue: string;\n};\n\nexport type GetUploadResponse = {\n\turl: string;\n\tfields: UploadField[];\n};\n\nexport interface File {\n\tname?: string;\n\tpath: string;\n\t/**\n\t * Override the Content-Type of the response.\n\t * Useful when the stored object's content type differs from what the browser should receive.\n\t */\n\tresponseContentType?: string;\n\t/**\n\t * Control how the browser handles the file.\n\t * - `'attachment'` — prompts download (default when `name` is set)\n\t * - `'inline'` — displays in the browser\n\t */\n\tdisposition?: 'inline' | 'attachment';\n}\n"],"mappings":";;AAMA,IAAY,8DAAL;AACN;AACA;AACA;;AACA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StorageClient-COs9SOsU.d.cts","names":[],"sources":["../src/StorageClient.ts"],"sourcesContent":[],"mappings":";;;UACiB,eAAA;;EAAA,SAAA,EAEL,IAFK;AAKjB;AAMiB,aANL,eAAA;EAMkB,KAAA,GAAA,kCAAA;EAAA,GACV,GAAA,+BAAA;EAAe,KACjB,GAAA,iCAAA;;AAS0C,UAX3C,aAAA,CAW2C;EAAO,SAU7C,QAAA,EApBF,eAoBE;EAAI,SAAuB,KAAA,CAAA,EAnB/B,KAmB+B;EAAO;;;;;;;;EAmC3B,YAAzB,CAAA,MAAA,EA7CkB,eA6ClB,EAAA,SAAA,CAAA,EAAA,MAAA,CAAA,EA7CwD,OA6CxD,CAAA,MAAA,CAAA;EAAO;AAMkB;AAG7B;AAMA;AAKA;AAKA;;;uBA5DsB,2BAA2B;;;;;;4BAMtB,QAAQ;;;;;;;8BAQN,0BAA0B;;;;;;;qCAStC,8BAEb;;;;;;;oBAQM,sCAEN,QAAQ;;;;;;uBAMU;;UAGL,eAAA;;;;;KAML,WAAA;;;;KAKA,iBAAA;;UAEH;;UAGQ,IAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StorageClient-DH4tP-Mf.d.mts","names":[],"sources":["../src/StorageClient.ts"],"sourcesContent":[],"mappings":";;;UACiB,eAAA;;EAAA,SAAA,EAEL,IAFK;AAKjB;AAMiB,aANL,eAAA;EAMkB,KAAA,GAAA,kCAAA;EAAA,GACV,GAAA,+BAAA;EAAe,KACjB,GAAA,iCAAA;;AAS0C,UAX3C,aAAA,CAW2C;EAAO,SAU7C,QAAA,EApBF,eAoBE;EAAI,SAAuB,KAAA,CAAA,EAnB/B,KAmB+B;EAAO;;;;;;;;EAmC3B,YAAzB,CAAA,MAAA,EA7CkB,eA6ClB,EAAA,SAAA,CAAA,EAAA,MAAA,CAAA,EA7CwD,OA6CxD,CAAA,MAAA,CAAA;EAAO;AAMkB;AAG7B;AAMA;AAKA;AAKA;;;uBA5DsB,2BAA2B;;;;;;4BAMtB,QAAQ;;;;;;;8BAQN,0BAA0B;;;;;;;qCAStC,8BAEb;;;;;;;oBAQM,sCAEN,QAAQ;;;;;;uBAMU;;UAGL,eAAA;;;;;KAML,WAAA;;;;KAKA,iBAAA;;UAEH;;UAGQ,IAAA"}
|
package/dist/StorageClient.cjs
DELETED
package/dist/StorageClient.d.cts
DELETED
package/dist/StorageClient.d.mts
DELETED
package/dist/StorageClient.mjs
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DeleteObjectCommand,
|
|
3
|
-
GetObjectCommand,
|
|
4
|
-
ListObjectVersionsCommand,
|
|
5
|
-
PutObjectCommand,
|
|
6
|
-
S3Client,
|
|
7
|
-
} from '@aws-sdk/client-s3';
|
|
8
|
-
import { createPresignedPost } from '@aws-sdk/s3-presigned-post';
|
|
9
|
-
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
10
|
-
|
|
11
|
-
import type { Cache } from '@geekmidas/cache';
|
|
12
|
-
import {
|
|
13
|
-
type DocumentVersion,
|
|
14
|
-
type File,
|
|
15
|
-
type GetUploadParams,
|
|
16
|
-
type GetUploadResponse,
|
|
17
|
-
type StorageClient,
|
|
18
|
-
StorageProvider,
|
|
19
|
-
} from './StorageClient';
|
|
20
|
-
|
|
21
|
-
export class AmazonStorageClient implements StorageClient {
|
|
22
|
-
readonly provider = StorageProvider.AWSS3;
|
|
23
|
-
|
|
24
|
-
static create(
|
|
25
|
-
options: AmazonStorageClientCreateOptions,
|
|
26
|
-
): AmazonStorageClient {
|
|
27
|
-
const {
|
|
28
|
-
bucket,
|
|
29
|
-
region,
|
|
30
|
-
accessKeyId,
|
|
31
|
-
acl,
|
|
32
|
-
endpoint,
|
|
33
|
-
secretAccessKey,
|
|
34
|
-
forcePathStyle = false,
|
|
35
|
-
cache,
|
|
36
|
-
} = options;
|
|
37
|
-
const hasCredentials = accessKeyId && secretAccessKey;
|
|
38
|
-
const credentials = hasCredentials
|
|
39
|
-
? { accessKeyId, secretAccessKey }
|
|
40
|
-
: undefined;
|
|
41
|
-
|
|
42
|
-
const client = new S3Client({
|
|
43
|
-
region,
|
|
44
|
-
credentials,
|
|
45
|
-
endpoint,
|
|
46
|
-
forcePathStyle,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
return new AmazonStorageClient(client, bucket, acl, cache);
|
|
50
|
-
}
|
|
51
|
-
constructor(
|
|
52
|
-
private readonly client: S3Client,
|
|
53
|
-
private readonly bucket: string,
|
|
54
|
-
private readonly acl = AmazonCannedAccessControlList.AuthenticatedRead,
|
|
55
|
-
readonly cache?: Cache,
|
|
56
|
-
) {}
|
|
57
|
-
|
|
58
|
-
private createGetObjectCommand(
|
|
59
|
-
file: File,
|
|
60
|
-
overrides?: { VersionId?: string },
|
|
61
|
-
): GetObjectCommand {
|
|
62
|
-
const disposition =
|
|
63
|
-
file.disposition ?? (file.name ? 'attachment' : undefined);
|
|
64
|
-
const ResponseContentDisposition = disposition
|
|
65
|
-
? file.name
|
|
66
|
-
? `${disposition}; filename=${encodeURIComponent(file.name)}`
|
|
67
|
-
: disposition
|
|
68
|
-
: undefined;
|
|
69
|
-
|
|
70
|
-
return new GetObjectCommand({
|
|
71
|
-
Bucket: this.bucket,
|
|
72
|
-
Key: file.path,
|
|
73
|
-
ResponseContentDisposition,
|
|
74
|
-
ResponseContentType: file.responseContentType,
|
|
75
|
-
...overrides,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
getVersionDownloadURL(file: File, versionId: string): Promise<string> {
|
|
80
|
-
const command = this.createGetObjectCommand(file, { VersionId: versionId });
|
|
81
|
-
return getSignedUrl(this.client, command, { expiresIn: 60 * 60 * 24 });
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async getVersions(key: string): Promise<DocumentVersion[]> {
|
|
85
|
-
const command = new ListObjectVersionsCommand({
|
|
86
|
-
Bucket: this.bucket,
|
|
87
|
-
Prefix: key,
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const { Versions = [] } = await this.client.send(command);
|
|
91
|
-
|
|
92
|
-
return Versions.map((version) => ({
|
|
93
|
-
id: version.VersionId || '',
|
|
94
|
-
createdAt: version.LastModified || new Date(),
|
|
95
|
-
}));
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async getDownloadURL(file: File, expiresIn = 60 * 60): Promise<string> {
|
|
99
|
-
const cacheKey = `download-url:${file.path}`;
|
|
100
|
-
const cachedURL = await this.cache?.get<string>(cacheKey);
|
|
101
|
-
|
|
102
|
-
if (cachedURL) {
|
|
103
|
-
return cachedURL;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const command = this.createGetObjectCommand(file);
|
|
107
|
-
const url = await getSignedUrl(this.client, command, { expiresIn });
|
|
108
|
-
const cacheExpiration = Math.max(expiresIn - 60, 0);
|
|
109
|
-
|
|
110
|
-
if (cacheExpiration) {
|
|
111
|
-
await this.cache?.set(cacheKey, url, cacheExpiration);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return url;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async getUploadURL(
|
|
118
|
-
params: GetUploadParams,
|
|
119
|
-
expiresIn = 60 * 60,
|
|
120
|
-
): Promise<string> {
|
|
121
|
-
const command = new PutObjectCommand({
|
|
122
|
-
Bucket: this.bucket,
|
|
123
|
-
Key: params.path,
|
|
124
|
-
ContentType: params.contentType,
|
|
125
|
-
ContentLength: params.contentLength,
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
return getSignedUrl(this.client, command, { expiresIn });
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
async getUpload(
|
|
132
|
-
params: GetUploadParams,
|
|
133
|
-
expiresIn = 5,
|
|
134
|
-
): Promise<GetUploadResponse> {
|
|
135
|
-
const { path } = params;
|
|
136
|
-
const { fields: values, url } = await createPresignedPost(this.client, {
|
|
137
|
-
Expires: expiresIn * 60,
|
|
138
|
-
Bucket: this.bucket,
|
|
139
|
-
Fields: {
|
|
140
|
-
acl: this.acl,
|
|
141
|
-
},
|
|
142
|
-
Conditions: [
|
|
143
|
-
// content length restrictions: 0-1MB]
|
|
144
|
-
// ['content-length-range', 0, contentLength],
|
|
145
|
-
// specify content-type to be more generic- images only
|
|
146
|
-
// ['starts-with', '$Content-Type', 'image/'],
|
|
147
|
-
// ['starts-with', '$Content-Type', contentType],
|
|
148
|
-
],
|
|
149
|
-
Key: path,
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
const keys = Object.keys(values);
|
|
153
|
-
const fields = keys.map((key) => ({ key, value: values[key] || '' }));
|
|
154
|
-
|
|
155
|
-
return { url, fields };
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
async upload(
|
|
159
|
-
key: string,
|
|
160
|
-
data: string | Buffer,
|
|
161
|
-
contentType: string,
|
|
162
|
-
): Promise<void> {
|
|
163
|
-
const Body = typeof data === 'string' ? Buffer.from(data, 'base64') : data;
|
|
164
|
-
|
|
165
|
-
const params = {
|
|
166
|
-
Bucket: this.bucket,
|
|
167
|
-
Key: key,
|
|
168
|
-
Body,
|
|
169
|
-
ContentType: contentType,
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
const command = new PutObjectCommand(params);
|
|
173
|
-
|
|
174
|
-
await this.client.send(command);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
async delete(key: string): Promise<void> {
|
|
178
|
-
const command = new DeleteObjectCommand({
|
|
179
|
-
Bucket: this.bucket,
|
|
180
|
-
Key: key,
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
await this.client.send(command);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export enum AmazonCannedAccessControlList {
|
|
188
|
-
AuthenticatedRead = 'authenticated-read',
|
|
189
|
-
Private = 'private',
|
|
190
|
-
PublicRead = 'public-read',
|
|
191
|
-
PublicReadWrite = 'public-read-write',
|
|
192
|
-
AwsExecRead = 'aws-exec-read',
|
|
193
|
-
BucketOwnerRead = 'bucket-owner-read',
|
|
194
|
-
BucketOwnerFullControl = 'bucket-owner-full-control',
|
|
195
|
-
LogDeliveryWrite = 'log-delivery-write',
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
interface AmazonStorageClientCreateOptions {
|
|
199
|
-
bucket: string;
|
|
200
|
-
region?: string;
|
|
201
|
-
acl?: AmazonCannedAccessControlList;
|
|
202
|
-
accessKeyId?: string;
|
|
203
|
-
secretAccessKey?: string;
|
|
204
|
-
endpoint?: string;
|
|
205
|
-
forcePathStyle?: boolean;
|
|
206
|
-
cache?: Cache;
|
|
207
|
-
}
|
package/src/StorageClient.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import type { Cache } from '@geekmidas/cache';
|
|
2
|
-
export interface DocumentVersion {
|
|
3
|
-
id: string;
|
|
4
|
-
createdAt: Date;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export enum StorageProvider {
|
|
8
|
-
AWSS3 = 'geekimdas.toolbox.storage.aws.s3',
|
|
9
|
-
GCP = 'geekimdas.toolbox.storage.gcp',
|
|
10
|
-
AZURE = 'geekimdas.toolbox.storage.azure',
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface StorageClient {
|
|
14
|
-
readonly provider: StorageProvider;
|
|
15
|
-
readonly cache?: Cache;
|
|
16
|
-
/**
|
|
17
|
-
* Get a URL to upload a file to.
|
|
18
|
-
*
|
|
19
|
-
* @param params - The parameters to get the upload URL for.
|
|
20
|
-
* @param expiresIn - The number of minutes the URL should be valid for.
|
|
21
|
-
* Defaults to 60 * 60 (1 hour).
|
|
22
|
-
* @returns A promise that resolves to the upload URL.
|
|
23
|
-
*/
|
|
24
|
-
getUploadURL(params: GetUploadParams, expiresIn?: number): Promise<string>;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Get a URL to download a file from.
|
|
28
|
-
*
|
|
29
|
-
* @param file - The file to get the download URL for.
|
|
30
|
-
* @param expiresIn - The number of seconds the URL should be valid for.
|
|
31
|
-
* Defaults to 60 * 60 (1 hour).
|
|
32
|
-
* @returns A promise that resolves to the download URL.
|
|
33
|
-
*/
|
|
34
|
-
getDownloadURL(file: File, expiresIn?: number): Promise<string>;
|
|
35
|
-
/**
|
|
36
|
-
* Get the versions for a key.
|
|
37
|
-
*
|
|
38
|
-
* @param key - The key to get the versions for.
|
|
39
|
-
*/
|
|
40
|
-
getVersions(key: string): Promise<DocumentVersion[]>;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Get a URL to download a version of a file from.
|
|
44
|
-
*
|
|
45
|
-
* @param file - The file to get the download URL for.
|
|
46
|
-
* @param versionId - The version ID to get the download URL for.
|
|
47
|
-
*/
|
|
48
|
-
getVersionDownloadURL(file: File, versionId: string): Promise<string>;
|
|
49
|
-
/**
|
|
50
|
-
*
|
|
51
|
-
* @param key - The key to upload the file to.
|
|
52
|
-
* @param data - The data to upload.
|
|
53
|
-
* @param contentType - The content type of the data.
|
|
54
|
-
*/
|
|
55
|
-
upload(
|
|
56
|
-
key: string,
|
|
57
|
-
data: string | Buffer,
|
|
58
|
-
contentType: string,
|
|
59
|
-
): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Get a URL to upload a file to.
|
|
62
|
-
*
|
|
63
|
-
* @param params - The parameters to get the upload URL for.
|
|
64
|
-
* @param expiresIn - The number of minutes the URL should be valid for.
|
|
65
|
-
*/
|
|
66
|
-
getUpload(
|
|
67
|
-
params: GetUploadParams,
|
|
68
|
-
expiresIn?: number,
|
|
69
|
-
): Promise<GetUploadResponse>;
|
|
70
|
-
/**
|
|
71
|
-
* Delete a file from storage.
|
|
72
|
-
*
|
|
73
|
-
* @param key - The key (path) of the file to delete.
|
|
74
|
-
*/
|
|
75
|
-
delete(key: string): Promise<void>;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export interface GetUploadParams {
|
|
79
|
-
path: string;
|
|
80
|
-
contentType: string;
|
|
81
|
-
contentLength: number;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export type UploadField = {
|
|
85
|
-
key: string;
|
|
86
|
-
value: string;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export type GetUploadResponse = {
|
|
90
|
-
url: string;
|
|
91
|
-
fields: UploadField[];
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export interface File {
|
|
95
|
-
name?: string;
|
|
96
|
-
path: string;
|
|
97
|
-
/**
|
|
98
|
-
* Override the Content-Type of the response.
|
|
99
|
-
* Useful when the stored object's content type differs from what the browser should receive.
|
|
100
|
-
*/
|
|
101
|
-
responseContentType?: string;
|
|
102
|
-
/**
|
|
103
|
-
* Control how the browser handles the file.
|
|
104
|
-
* - `'attachment'` — prompts download (default when `name` is set)
|
|
105
|
-
* - `'inline'` — displays in the browser
|
|
106
|
-
*/
|
|
107
|
-
disposition?: 'inline' | 'attachment';
|
|
108
|
-
}
|