@geekmidas/storage 0.0.1 → 0.0.2
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-C16fG3G4.d.cts +39 -0
- package/dist/AmazonStorageClient-CP8Tx5oE.d.mts +39 -0
- package/dist/AmazonStorageClient.d.cts +3 -0
- package/dist/AmazonStorageClient.d.mts +3 -0
- package/dist/StorageClient-CJbHRTVV.d.mts +77 -0
- package/dist/StorageClient-D-y4QLDq.d.cts +77 -0
- package/dist/StorageClient.d.cts +2 -0
- package/dist/StorageClient.d.mts +2 -0
- package/dist/__tests__/AmazonStorageClient.spec.d.cts +1 -0
- package/dist/__tests__/AmazonStorageClient.spec.d.mts +1 -0
- package/dist/__tests__/StorageClient.spec.d.cts +1 -0
- package/dist/__tests__/StorageClient.spec.d.mts +1 -0
- package/dist/aws.d.cts +3 -0
- package/dist/aws.d.mts +3 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/package.json +5 -5
- package/src/__tests__/StorageClient.spec.ts +5 -2
- package/src/aws.ts +11 -2
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider } from "./StorageClient-D-y4QLDq.cjs";
|
|
2
|
+
import { S3Client } from "@aws-sdk/client-s3";
|
|
3
|
+
|
|
4
|
+
//#region src/AmazonStorageClient.d.ts
|
|
5
|
+
declare class AmazonStorageClient implements StorageClient {
|
|
6
|
+
private readonly client;
|
|
7
|
+
private readonly bucket;
|
|
8
|
+
private readonly acl;
|
|
9
|
+
readonly provider = StorageProvider.AWSS3;
|
|
10
|
+
static create(options: AmazonStorageClientCreateOptions): AmazonStorageClient;
|
|
11
|
+
constructor(client: S3Client, bucket: string, acl?: AmazonCannedAccessControlList);
|
|
12
|
+
getVersionDownloadURL(file: File, versionId: string): Promise<string>;
|
|
13
|
+
getVersions(key: string): Promise<DocumentVersion[]>;
|
|
14
|
+
getDownloadURL(file: File, expiresIn?: number): Promise<string>;
|
|
15
|
+
getUploadURL(params: GetUploadParams, expiresIn?: number): Promise<string>;
|
|
16
|
+
getUpload(params: GetUploadParams, expiresIn?: number): Promise<GetUploadResponse>;
|
|
17
|
+
upload(key: string, data: string | Buffer, contentType: string): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
declare enum AmazonCannedAccessControlList {
|
|
20
|
+
AuthenticatedRead = "authenticated-read",
|
|
21
|
+
Private = "private",
|
|
22
|
+
PublicRead = "public-read",
|
|
23
|
+
PublicReadWrite = "public-read-write",
|
|
24
|
+
AwsExecRead = "aws-exec-read",
|
|
25
|
+
BucketOwnerRead = "bucket-owner-read",
|
|
26
|
+
BucketOwnerFullControl = "bucket-owner-full-control",
|
|
27
|
+
LogDeliveryWrite = "log-delivery-write",
|
|
28
|
+
}
|
|
29
|
+
interface AmazonStorageClientCreateOptions {
|
|
30
|
+
bucket: string;
|
|
31
|
+
region?: string;
|
|
32
|
+
acl?: AmazonCannedAccessControlList;
|
|
33
|
+
accessKeyId?: string;
|
|
34
|
+
secretAccessKey?: string;
|
|
35
|
+
endpoint?: string;
|
|
36
|
+
forcePathStyle?: boolean;
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider } from "./StorageClient-CJbHRTVV.mjs";
|
|
2
|
+
import { S3Client } from "@aws-sdk/client-s3";
|
|
3
|
+
|
|
4
|
+
//#region src/AmazonStorageClient.d.ts
|
|
5
|
+
declare class AmazonStorageClient implements StorageClient {
|
|
6
|
+
private readonly client;
|
|
7
|
+
private readonly bucket;
|
|
8
|
+
private readonly acl;
|
|
9
|
+
readonly provider = StorageProvider.AWSS3;
|
|
10
|
+
static create(options: AmazonStorageClientCreateOptions): AmazonStorageClient;
|
|
11
|
+
constructor(client: S3Client, bucket: string, acl?: AmazonCannedAccessControlList);
|
|
12
|
+
getVersionDownloadURL(file: File, versionId: string): Promise<string>;
|
|
13
|
+
getVersions(key: string): Promise<DocumentVersion[]>;
|
|
14
|
+
getDownloadURL(file: File, expiresIn?: number): Promise<string>;
|
|
15
|
+
getUploadURL(params: GetUploadParams, expiresIn?: number): Promise<string>;
|
|
16
|
+
getUpload(params: GetUploadParams, expiresIn?: number): Promise<GetUploadResponse>;
|
|
17
|
+
upload(key: string, data: string | Buffer, contentType: string): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
declare enum AmazonCannedAccessControlList {
|
|
20
|
+
AuthenticatedRead = "authenticated-read",
|
|
21
|
+
Private = "private",
|
|
22
|
+
PublicRead = "public-read",
|
|
23
|
+
PublicReadWrite = "public-read-write",
|
|
24
|
+
AwsExecRead = "aws-exec-read",
|
|
25
|
+
BucketOwnerRead = "bucket-owner-read",
|
|
26
|
+
BucketOwnerFullControl = "bucket-owner-full-control",
|
|
27
|
+
LogDeliveryWrite = "log-delivery-write",
|
|
28
|
+
}
|
|
29
|
+
interface AmazonStorageClientCreateOptions {
|
|
30
|
+
bucket: string;
|
|
31
|
+
region?: string;
|
|
32
|
+
acl?: AmazonCannedAccessControlList;
|
|
33
|
+
accessKeyId?: string;
|
|
34
|
+
secretAccessKey?: string;
|
|
35
|
+
endpoint?: string;
|
|
36
|
+
forcePathStyle?: boolean;
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { AmazonCannedAccessControlList, AmazonStorageClient };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//#region src/StorageClient.d.ts
|
|
2
|
+
interface DocumentVersion {
|
|
3
|
+
id: string;
|
|
4
|
+
createdAt: Date;
|
|
5
|
+
}
|
|
6
|
+
declare enum StorageProvider {
|
|
7
|
+
AWSS3 = "geekimdas.toolbox.storage.aws.s3",
|
|
8
|
+
GCP = "geekimdas.toolbox.storage.gcp",
|
|
9
|
+
AZURE = "geekimdas.toolbox.storage.azure",
|
|
10
|
+
}
|
|
11
|
+
interface StorageClient {
|
|
12
|
+
readonly provider: StorageProvider;
|
|
13
|
+
/**
|
|
14
|
+
* Get a URL to upload a file to.
|
|
15
|
+
*
|
|
16
|
+
* @param params - The parameters to get the upload URL for.
|
|
17
|
+
* @param expiresIn - The number of minutes the URL should be valid for.
|
|
18
|
+
* Defaults to 60 * 60 (1 hour).
|
|
19
|
+
* @returns A promise that resolves to the upload URL.
|
|
20
|
+
*/
|
|
21
|
+
getUploadURL(params: GetUploadParams, expiresIn?: number): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Get a URL to download a file from.
|
|
24
|
+
*
|
|
25
|
+
* @param file - The file to get the download URL for.
|
|
26
|
+
* @param expiresIn - The number of seconds the URL should be valid for.
|
|
27
|
+
* Defaults to 60 * 60 (1 hour).
|
|
28
|
+
* @returns A promise that resolves to the download URL.
|
|
29
|
+
*/
|
|
30
|
+
getDownloadURL(file: File, expiresIn?: number): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Get the versions for a key.
|
|
33
|
+
*
|
|
34
|
+
* @param key - The key to get the versions for.
|
|
35
|
+
*/
|
|
36
|
+
getVersions(key: string): Promise<DocumentVersion[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Get a URL to download a version of a file from.
|
|
39
|
+
*
|
|
40
|
+
* @param file - The file to get the download URL for.
|
|
41
|
+
* @param versionId - The version ID to get the download URL for.
|
|
42
|
+
*/
|
|
43
|
+
getVersionDownloadURL(file: File, versionId: string): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param key - The key to upload the file to.
|
|
47
|
+
* @param data - The data to upload.
|
|
48
|
+
* @param contentType - The content type of the data.
|
|
49
|
+
*/
|
|
50
|
+
upload(key: string, data: string | Buffer, contentType: string): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Get a URL to upload a file to.
|
|
53
|
+
*
|
|
54
|
+
* @param params - The parameters to get the upload URL for.
|
|
55
|
+
* @param expiresIn - The number of minutes the URL should be valid for.
|
|
56
|
+
*/
|
|
57
|
+
getUpload(params: GetUploadParams, expiresIn?: number): Promise<GetUploadResponse>;
|
|
58
|
+
}
|
|
59
|
+
interface GetUploadParams {
|
|
60
|
+
path: string;
|
|
61
|
+
contentType: string;
|
|
62
|
+
contentLength: number;
|
|
63
|
+
}
|
|
64
|
+
type UploadField = {
|
|
65
|
+
key: string;
|
|
66
|
+
value: string;
|
|
67
|
+
};
|
|
68
|
+
type GetUploadResponse = {
|
|
69
|
+
url: string;
|
|
70
|
+
fields: UploadField[];
|
|
71
|
+
};
|
|
72
|
+
interface File {
|
|
73
|
+
name?: string;
|
|
74
|
+
path: string;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//#region src/StorageClient.d.ts
|
|
2
|
+
interface DocumentVersion {
|
|
3
|
+
id: string;
|
|
4
|
+
createdAt: Date;
|
|
5
|
+
}
|
|
6
|
+
declare enum StorageProvider {
|
|
7
|
+
AWSS3 = "geekimdas.toolbox.storage.aws.s3",
|
|
8
|
+
GCP = "geekimdas.toolbox.storage.gcp",
|
|
9
|
+
AZURE = "geekimdas.toolbox.storage.azure",
|
|
10
|
+
}
|
|
11
|
+
interface StorageClient {
|
|
12
|
+
readonly provider: StorageProvider;
|
|
13
|
+
/**
|
|
14
|
+
* Get a URL to upload a file to.
|
|
15
|
+
*
|
|
16
|
+
* @param params - The parameters to get the upload URL for.
|
|
17
|
+
* @param expiresIn - The number of minutes the URL should be valid for.
|
|
18
|
+
* Defaults to 60 * 60 (1 hour).
|
|
19
|
+
* @returns A promise that resolves to the upload URL.
|
|
20
|
+
*/
|
|
21
|
+
getUploadURL(params: GetUploadParams, expiresIn?: number): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Get a URL to download a file from.
|
|
24
|
+
*
|
|
25
|
+
* @param file - The file to get the download URL for.
|
|
26
|
+
* @param expiresIn - The number of seconds the URL should be valid for.
|
|
27
|
+
* Defaults to 60 * 60 (1 hour).
|
|
28
|
+
* @returns A promise that resolves to the download URL.
|
|
29
|
+
*/
|
|
30
|
+
getDownloadURL(file: File, expiresIn?: number): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Get the versions for a key.
|
|
33
|
+
*
|
|
34
|
+
* @param key - The key to get the versions for.
|
|
35
|
+
*/
|
|
36
|
+
getVersions(key: string): Promise<DocumentVersion[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Get a URL to download a version of a file from.
|
|
39
|
+
*
|
|
40
|
+
* @param file - The file to get the download URL for.
|
|
41
|
+
* @param versionId - The version ID to get the download URL for.
|
|
42
|
+
*/
|
|
43
|
+
getVersionDownloadURL(file: File, versionId: string): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param key - The key to upload the file to.
|
|
47
|
+
* @param data - The data to upload.
|
|
48
|
+
* @param contentType - The content type of the data.
|
|
49
|
+
*/
|
|
50
|
+
upload(key: string, data: string | Buffer, contentType: string): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Get a URL to upload a file to.
|
|
53
|
+
*
|
|
54
|
+
* @param params - The parameters to get the upload URL for.
|
|
55
|
+
* @param expiresIn - The number of minutes the URL should be valid for.
|
|
56
|
+
*/
|
|
57
|
+
getUpload(params: GetUploadParams, expiresIn?: number): Promise<GetUploadResponse>;
|
|
58
|
+
}
|
|
59
|
+
interface GetUploadParams {
|
|
60
|
+
path: string;
|
|
61
|
+
contentType: string;
|
|
62
|
+
contentLength: number;
|
|
63
|
+
}
|
|
64
|
+
type UploadField = {
|
|
65
|
+
key: string;
|
|
66
|
+
value: string;
|
|
67
|
+
};
|
|
68
|
+
type GetUploadResponse = {
|
|
69
|
+
url: string;
|
|
70
|
+
fields: UploadField[];
|
|
71
|
+
};
|
|
72
|
+
interface File {
|
|
73
|
+
name?: string;
|
|
74
|
+
path: string;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient, StorageProvider, UploadField };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/aws.d.cts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient } from "./StorageClient-D-y4QLDq.cjs";
|
|
2
|
+
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-C16fG3G4.cjs";
|
|
3
|
+
export { AmazonCannedAccessControlList, AmazonStorageClient, DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient };
|
package/dist/aws.d.mts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient } from "./StorageClient-CJbHRTVV.mjs";
|
|
2
|
+
import { AmazonCannedAccessControlList, AmazonStorageClient } from "./AmazonStorageClient-CP8Tx5oE.mjs";
|
|
3
|
+
export { AmazonCannedAccessControlList, AmazonStorageClient, DocumentVersion, File, GetUploadParams, GetUploadResponse, StorageClient };
|
package/dist/index.d.cts
ADDED
package/dist/index.d.mts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/storage",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
"type": "module",
|
|
10
10
|
"exports": {
|
|
11
11
|
"./aws": {
|
|
12
|
+
"types": "./dist/aws.d.ts",
|
|
12
13
|
"import": "./dist/aws.mjs",
|
|
13
|
-
"require": "./dist/aws.cjs"
|
|
14
|
-
"types": "./src/aws.ts"
|
|
14
|
+
"require": "./dist/aws.cjs"
|
|
15
15
|
},
|
|
16
16
|
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
17
18
|
"import": "./dist/index.mjs",
|
|
18
|
-
"require": "./dist/index.cjs"
|
|
19
|
-
"types": "./src/index.ts"
|
|
19
|
+
"require": "./dist/index.cjs"
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
@@ -69,7 +69,10 @@ describe('StorageClient', () => {
|
|
|
69
69
|
|
|
70
70
|
expect(response.url).toBe('https://example.com/upload');
|
|
71
71
|
expect(response.fields).toHaveLength(2);
|
|
72
|
-
expect(response.fields[0]).toEqual({
|
|
72
|
+
expect(response.fields[0]).toEqual({
|
|
73
|
+
key: 'key',
|
|
74
|
+
value: 'test/path.txt',
|
|
75
|
+
});
|
|
73
76
|
expect(response.fields[1]).toEqual({ key: 'acl', value: 'public-read' });
|
|
74
77
|
});
|
|
75
78
|
|
|
@@ -83,4 +86,4 @@ describe('StorageClient', () => {
|
|
|
83
86
|
expect(field.value).toBe('test-value');
|
|
84
87
|
});
|
|
85
88
|
});
|
|
86
|
-
});
|
|
89
|
+
});
|
package/src/aws.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export {
|
|
2
|
+
AmazonStorageClient,
|
|
3
|
+
AmazonCannedAccessControlList,
|
|
4
|
+
} from './AmazonStorageClient';
|
|
5
|
+
export type {
|
|
6
|
+
StorageClient,
|
|
7
|
+
DocumentVersion,
|
|
8
|
+
File,
|
|
9
|
+
GetUploadParams,
|
|
10
|
+
GetUploadResponse,
|
|
11
|
+
} from './StorageClient';
|