@oino-ts/blob-aws 1.0.2 → 1.0.4
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/cjs/OINOBlobAwsS3.js +11 -31
- package/dist/esm/OINOBlobAwsS3.js +11 -31
- package/dist/types/OINOBlobAwsS3.d.ts +2 -2
- package/package.json +4 -4
- package/src/OINOBlobAwsS3.ts +12 -34
|
@@ -40,47 +40,27 @@ const blob_1 = require("@oino-ts/blob");
|
|
|
40
40
|
*/
|
|
41
41
|
class OINOBlobAwsS3 extends blob_1.OINOBlob {
|
|
42
42
|
_s3Client = null;
|
|
43
|
-
|
|
43
|
+
constructor(params) {
|
|
44
|
+
super(params);
|
|
45
|
+
if (!params.credentials || !params.credentials.region || !params.credentials.accessKeyId || !params.credentials.secretAccessKey) {
|
|
46
|
+
throw new Error("OINOBlobAwsS3: missing or invalid credentials (provide region, accessKeyId, secretAccessKey)");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
44
49
|
/**
|
|
45
50
|
* Initialise the AWS SDK S3 client from the JSON-encoded `connectionStr`.
|
|
46
51
|
* Does not perform any network call.
|
|
47
52
|
*/
|
|
48
53
|
async connect() {
|
|
49
|
-
if (!this.blobParams.connectionStr) {
|
|
50
|
-
return new common_1.OINOResult({
|
|
51
|
-
success: false,
|
|
52
|
-
status: 400,
|
|
53
|
-
statusText: "OINOBlobAwsS3: params.connectionStr is required (JSON with region, accessKeyId, secretAccessKey)"
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
let creds;
|
|
57
|
-
try {
|
|
58
|
-
creds = JSON.parse(this.blobParams.connectionStr);
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
return new common_1.OINOResult({
|
|
62
|
-
success: false,
|
|
63
|
-
status: 400,
|
|
64
|
-
statusText: "OINOBlobAwsS3: params.connectionStr must be a valid JSON string"
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if (!creds.region || !creds.accessKeyId || !creds.secretAccessKey) {
|
|
68
|
-
return new common_1.OINOResult({
|
|
69
|
-
success: false,
|
|
70
|
-
status: 400,
|
|
71
|
-
statusText: "OINOBlobAwsS3: connectionStr must include region, accessKeyId and secretAccessKey"
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
54
|
try {
|
|
75
55
|
const clientConfig = {
|
|
76
|
-
region:
|
|
56
|
+
region: this.blobParams.credentials.region,
|
|
77
57
|
credentials: {
|
|
78
|
-
accessKeyId:
|
|
79
|
-
secretAccessKey:
|
|
58
|
+
accessKeyId: this.blobParams.credentials.accessKeyId,
|
|
59
|
+
secretAccessKey: this.blobParams.credentials.secretAccessKey
|
|
80
60
|
}
|
|
81
61
|
};
|
|
82
|
-
if (this.blobParams.url) {
|
|
83
|
-
clientConfig.endpoint = this.blobParams.url;
|
|
62
|
+
if (this.blobParams.credentials.url) {
|
|
63
|
+
clientConfig.endpoint = this.blobParams.credentials.url;
|
|
84
64
|
clientConfig.forcePathStyle = true;
|
|
85
65
|
}
|
|
86
66
|
this._s3Client = new client_s3_1.S3Client(clientConfig);
|
|
@@ -37,47 +37,27 @@ import { OINOBlob, OINOBlobDataModel } from "@oino-ts/blob";
|
|
|
37
37
|
*/
|
|
38
38
|
export class OINOBlobAwsS3 extends OINOBlob {
|
|
39
39
|
_s3Client = null;
|
|
40
|
-
|
|
40
|
+
constructor(params) {
|
|
41
|
+
super(params);
|
|
42
|
+
if (!params.credentials || !params.credentials.region || !params.credentials.accessKeyId || !params.credentials.secretAccessKey) {
|
|
43
|
+
throw new Error("OINOBlobAwsS3: missing or invalid credentials (provide region, accessKeyId, secretAccessKey)");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
41
46
|
/**
|
|
42
47
|
* Initialise the AWS SDK S3 client from the JSON-encoded `connectionStr`.
|
|
43
48
|
* Does not perform any network call.
|
|
44
49
|
*/
|
|
45
50
|
async connect() {
|
|
46
|
-
if (!this.blobParams.connectionStr) {
|
|
47
|
-
return new OINOResult({
|
|
48
|
-
success: false,
|
|
49
|
-
status: 400,
|
|
50
|
-
statusText: "OINOBlobAwsS3: params.connectionStr is required (JSON with region, accessKeyId, secretAccessKey)"
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
let creds;
|
|
54
|
-
try {
|
|
55
|
-
creds = JSON.parse(this.blobParams.connectionStr);
|
|
56
|
-
}
|
|
57
|
-
catch {
|
|
58
|
-
return new OINOResult({
|
|
59
|
-
success: false,
|
|
60
|
-
status: 400,
|
|
61
|
-
statusText: "OINOBlobAwsS3: params.connectionStr must be a valid JSON string"
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
if (!creds.region || !creds.accessKeyId || !creds.secretAccessKey) {
|
|
65
|
-
return new OINOResult({
|
|
66
|
-
success: false,
|
|
67
|
-
status: 400,
|
|
68
|
-
statusText: "OINOBlobAwsS3: connectionStr must include region, accessKeyId and secretAccessKey"
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
51
|
try {
|
|
72
52
|
const clientConfig = {
|
|
73
|
-
region:
|
|
53
|
+
region: this.blobParams.credentials.region,
|
|
74
54
|
credentials: {
|
|
75
|
-
accessKeyId:
|
|
76
|
-
secretAccessKey:
|
|
55
|
+
accessKeyId: this.blobParams.credentials.accessKeyId,
|
|
56
|
+
secretAccessKey: this.blobParams.credentials.secretAccessKey
|
|
77
57
|
}
|
|
78
58
|
};
|
|
79
|
-
if (this.blobParams.url) {
|
|
80
|
-
clientConfig.endpoint = this.blobParams.url;
|
|
59
|
+
if (this.blobParams.credentials.url) {
|
|
60
|
+
clientConfig.endpoint = this.blobParams.credentials.url;
|
|
81
61
|
clientConfig.forcePathStyle = true;
|
|
82
62
|
}
|
|
83
63
|
this._s3Client = new S3Client(clientConfig);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { OINOApi, OINOResult, OINOQueryFilter } from "@oino-ts/common";
|
|
2
|
-
import { OINOBlob } from "@oino-ts/blob";
|
|
3
|
-
import { type OINOBlobEntry, type OINOBlobFetchResult } from "@oino-ts/blob";
|
|
2
|
+
import { OINOBlob, OINOBlobParams, type OINOBlobEntry, type OINOBlobFetchResult } from "@oino-ts/blob";
|
|
4
3
|
/**
|
|
5
4
|
* AWS S3 (and S3-compatible) implementation of `OINOBlob`.
|
|
6
5
|
*
|
|
@@ -32,6 +31,7 @@ import { type OINOBlobEntry, type OINOBlobFetchResult } from "@oino-ts/blob";
|
|
|
32
31
|
*/
|
|
33
32
|
export declare class OINOBlobAwsS3 extends OINOBlob {
|
|
34
33
|
private _s3Client;
|
|
34
|
+
constructor(params: OINOBlobParams);
|
|
35
35
|
/**
|
|
36
36
|
* Initialise the AWS SDK S3 client from the JSON-encoded `connectionStr`.
|
|
37
37
|
* Does not perform any network call.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oino-ts/blob-aws",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "OINO TS package for using AWS S3 (or S3-compatible) storage as a REST API.",
|
|
5
5
|
"author": "Matias Kiviniemi (pragmatta)",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"types": "./dist/types/index.d.ts",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@aws-sdk/client-s3": "^3.0.0",
|
|
25
|
-
"@oino-ts/blob": "1.0.
|
|
26
|
-
"@oino-ts/common": "1.0.
|
|
25
|
+
"@oino-ts/blob": "1.0.4",
|
|
26
|
+
"@oino-ts/common": "1.0.4"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@oino-ts/types": "1.0.
|
|
29
|
+
"@oino-ts/types": "1.0.4",
|
|
30
30
|
"@types/bun": "^1.1.14",
|
|
31
31
|
"@types/node": "^22.0.00",
|
|
32
32
|
"typescript": "~5.9.0"
|
package/src/OINOBlobAwsS3.ts
CHANGED
|
@@ -14,8 +14,7 @@ import {
|
|
|
14
14
|
} from "@aws-sdk/client-s3"
|
|
15
15
|
|
|
16
16
|
import { OINOApi, OINOResult, OINOQueryFilter, OINOStringDataField, OINONumberDataField, OINODatetimeDataField, type OINODataFieldParams } from "@oino-ts/common"
|
|
17
|
-
import { OINOBlob, OINOBlobDataModel, OINOBlobApi } from "@oino-ts/blob"
|
|
18
|
-
import { type OINOBlobEntry, type OINOBlobFetchResult } from "@oino-ts/blob"
|
|
17
|
+
import { OINOBlob, OINOBlobParams, OINOBlobDataModel, OINOBlobApi, type OINOBlobEntry, type OINOBlobFetchResult } from "@oino-ts/blob"
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
20
|
* AWS S3 (and S3-compatible) implementation of `OINOBlob`.
|
|
@@ -49,50 +48,29 @@ import { type OINOBlobEntry, type OINOBlobFetchResult } from "@oino-ts/blob"
|
|
|
49
48
|
export class OINOBlobAwsS3 extends OINOBlob {
|
|
50
49
|
private _s3Client: S3Client | null = null
|
|
51
50
|
|
|
52
|
-
|
|
51
|
+
constructor(params: OINOBlobParams) {
|
|
52
|
+
super(params)
|
|
53
|
+
if (!params.credentials || !params.credentials.region || !params.credentials.accessKeyId || !params.credentials.secretAccessKey) {
|
|
54
|
+
throw new Error("OINOBlobAwsS3: missing or invalid credentials (provide region, accessKeyId, secretAccessKey)")
|
|
55
|
+
}
|
|
56
|
+
}
|
|
53
57
|
|
|
54
58
|
/**
|
|
55
59
|
* Initialise the AWS SDK S3 client from the JSON-encoded `connectionStr`.
|
|
56
60
|
* Does not perform any network call.
|
|
57
61
|
*/
|
|
58
62
|
async connect(): Promise<OINOResult> {
|
|
59
|
-
if (!this.blobParams.connectionStr) {
|
|
60
|
-
return new OINOResult({
|
|
61
|
-
success: false,
|
|
62
|
-
status: 400,
|
|
63
|
-
statusText: "OINOBlobAwsS3: params.connectionStr is required (JSON with region, accessKeyId, secretAccessKey)"
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
let creds: { region: string; accessKeyId: string; secretAccessKey: string }
|
|
68
|
-
try {
|
|
69
|
-
creds = JSON.parse(this.blobParams.connectionStr)
|
|
70
|
-
} catch {
|
|
71
|
-
return new OINOResult({
|
|
72
|
-
success: false,
|
|
73
|
-
status: 400,
|
|
74
|
-
statusText: "OINOBlobAwsS3: params.connectionStr must be a valid JSON string"
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (!creds.region || !creds.accessKeyId || !creds.secretAccessKey) {
|
|
79
|
-
return new OINOResult({
|
|
80
|
-
success: false,
|
|
81
|
-
status: 400,
|
|
82
|
-
statusText: "OINOBlobAwsS3: connectionStr must include region, accessKeyId and secretAccessKey"
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
63
|
|
|
86
64
|
try {
|
|
87
65
|
const clientConfig: ConstructorParameters<typeof S3Client>[0] = {
|
|
88
|
-
region:
|
|
66
|
+
region: this.blobParams.credentials.region,
|
|
89
67
|
credentials: {
|
|
90
|
-
accessKeyId:
|
|
91
|
-
secretAccessKey:
|
|
68
|
+
accessKeyId: this.blobParams.credentials.accessKeyId,
|
|
69
|
+
secretAccessKey: this.blobParams.credentials.secretAccessKey
|
|
92
70
|
}
|
|
93
71
|
}
|
|
94
|
-
if (this.blobParams.url) {
|
|
95
|
-
clientConfig.endpoint = this.blobParams.url
|
|
72
|
+
if (this.blobParams.credentials.url) {
|
|
73
|
+
clientConfig.endpoint = this.blobParams.credentials.url
|
|
96
74
|
clientConfig.forcePathStyle = true
|
|
97
75
|
}
|
|
98
76
|
this._s3Client = new S3Client(clientConfig)
|