triangle-utils 1.4.114 → 1.4.116

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.
@@ -1,7 +1,14 @@
1
+ import { S3 } from "@aws-sdk/client-s3";
1
2
  import { Readable } from "stream";
3
+ interface S3Input {
4
+ Bucket: string;
5
+ Key: string;
6
+ }
7
+ export declare function get_s3_input(s3_id: string): S3Input | undefined;
2
8
  export declare class UtilsS3 {
3
9
  private readonly s3;
4
10
  constructor(region: string);
11
+ get_client(): Promise<S3>;
5
12
  get_headers(s3_id: string): Promise<{
6
13
  DeleteMarker?: boolean | undefined;
7
14
  AcceptRanges?: string | undefined;
@@ -15,6 +22,11 @@ export declare class UtilsS3 {
15
22
  ChecksumCRC64NVME?: string | undefined;
16
23
  ChecksumSHA1?: string | undefined;
17
24
  ChecksumSHA256?: string | undefined;
25
+ ChecksumSHA512?: string | undefined;
26
+ ChecksumMD5?: string | undefined;
27
+ ChecksumXXHASH64?: string | undefined;
28
+ ChecksumXXHASH3?: string | undefined;
29
+ ChecksumXXHASH128?: string | undefined;
18
30
  ChecksumType?: import("@aws-sdk/client-s3").ChecksumType | undefined;
19
31
  ETag?: string | undefined;
20
32
  MissingMeta?: number | undefined;
@@ -54,9 +66,13 @@ export declare class UtilsS3 {
54
66
  create(s3_id: string, content: string | Buffer | Readable, options?: {
55
67
  content_type_id?: string;
56
68
  }): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | undefined>;
69
+ upload(s3_id: string, content: string | Buffer | Readable, options?: {
70
+ content_type_id?: string;
71
+ }): Promise<void>;
57
72
  delete(s3_id: string): Promise<void>;
58
73
  get_download_url(s3_id: string): Promise<string | undefined>;
59
74
  get_upload_url(s3_id: string, options?: {
60
75
  content_type_id?: string;
61
76
  }): Promise<string | undefined>;
62
77
  }
78
+ export {};
@@ -1,7 +1,8 @@
1
1
  import { S3, NoSuchKey, GetObjectCommand, PutObjectCommand } from "@aws-sdk/client-s3";
2
2
  import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
3
+ import { Upload } from "@aws-sdk/lib-storage";
3
4
  import { Readable } from "stream";
4
- function get_s3_input(s3_id) {
5
+ export function get_s3_input(s3_id) {
5
6
  const [bucket, path] = (s3_id.match(/^s3\:\/\/([^\/]+)\/([^$]+)$/) || []).slice(1, 3);
6
7
  if (bucket === undefined || path === undefined) {
7
8
  return undefined;
@@ -13,6 +14,9 @@ export class UtilsS3 {
13
14
  constructor(region) {
14
15
  this.s3 = new S3({ region: region });
15
16
  }
17
+ async get_client() {
18
+ return this.s3;
19
+ }
16
20
  async get_headers(s3_id) {
17
21
  const s3_input = get_s3_input(s3_id);
18
22
  if (s3_input === undefined) {
@@ -146,6 +150,22 @@ export class UtilsS3 {
146
150
  ContentType: content_type_id
147
151
  });
148
152
  }
153
+ async upload(s3_id, content, options = {}) {
154
+ const content_type_id = options.content_type_id !== undefined ? options.content_type_id : undefined;
155
+ const s3_input = get_s3_input(s3_id);
156
+ if (s3_input === undefined) {
157
+ return undefined;
158
+ }
159
+ const upload = new Upload({
160
+ client: this.s3,
161
+ params: {
162
+ ...s3_input,
163
+ Body: content,
164
+ ContentType: content_type_id
165
+ }
166
+ });
167
+ await upload.done();
168
+ }
149
169
  async delete(s3_id) {
150
170
  const s3_input = get_s3_input(s3_id);
151
171
  if (s3_input === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.114",
3
+ "version": "1.4.116",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -20,11 +20,12 @@
20
20
  "@aws-sdk/client-bedrock-runtime": "^3.953.0",
21
21
  "@aws-sdk/client-cognito-identity-provider": "^3.1004.0",
22
22
  "@aws-sdk/client-dynamodb": "^3.953.0",
23
- "@aws-sdk/client-s3": "^3.953.0",
23
+ "@aws-sdk/client-s3": "^3.1106.0",
24
24
  "@aws-sdk/client-s3vectors": "^3.953.0",
25
25
  "@aws-sdk/client-secrets-manager": "^3.965.0",
26
26
  "@aws-sdk/client-ses": "^3.1032.0",
27
- "@aws-sdk/s3-request-presigner": "^3.953.0",
27
+ "@aws-sdk/lib-storage": "^3.1106.0",
28
+ "@aws-sdk/s3-request-presigner": "^3.1106.0",
28
29
  "@types/jsdom": "^28.0.1",
29
30
  "@types/node": "^25.2.3",
30
31
  "@types/nodemailer": "^7.0.9",
package/src/UtilsS3.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { S3, NoSuchKey, GetObjectCommand, PutObjectCommand, ListObjectsV2CommandOutput, ListObjectsV2CommandInput } from "@aws-sdk/client-s3"
2
2
  import { getSignedUrl } from "@aws-sdk/s3-request-presigner"
3
+ import { Upload } from "@aws-sdk/lib-storage"
3
4
  import { Readable } from "stream"
4
5
 
5
6
  interface S3Input {
@@ -7,7 +8,7 @@ interface S3Input {
7
8
  Key : string
8
9
  }
9
10
 
10
- function get_s3_input(s3_id : string) : S3Input | undefined {
11
+ export function get_s3_input(s3_id : string) : S3Input | undefined {
11
12
  const [bucket, path] = (s3_id.match(/^s3\:\/\/([^\/]+)\/([^$]+)$/) || []).slice(1, 3)
12
13
  if (bucket === undefined || path === undefined) {
13
14
  return undefined
@@ -23,6 +24,10 @@ export class UtilsS3 {
23
24
  this.s3 = new S3({ region : region })
24
25
  }
25
26
 
27
+ async get_client() {
28
+ return this.s3
29
+ }
30
+
26
31
  async get_headers(s3_id : string) {
27
32
  const s3_input = get_s3_input(s3_id)
28
33
  if (s3_input === undefined) {
@@ -161,6 +166,25 @@ export class UtilsS3 {
161
166
  })
162
167
  }
163
168
 
169
+ async upload(s3_id : string, content : string | Buffer | Readable, options : {
170
+ content_type_id? : string
171
+ } = {}) : Promise<void> {
172
+ const content_type_id = options.content_type_id !== undefined ? options.content_type_id : undefined
173
+ const s3_input = get_s3_input(s3_id)
174
+ if (s3_input === undefined) {
175
+ return undefined
176
+ }
177
+ const upload = new Upload({
178
+ client : this.s3,
179
+ params : {
180
+ ...s3_input,
181
+ Body : content,
182
+ ContentType : content_type_id
183
+ }
184
+ })
185
+ await upload.done()
186
+ }
187
+
164
188
  async delete(s3_id : string) : Promise<void>{
165
189
  const s3_input = get_s3_input(s3_id)
166
190
  if (s3_input === undefined) {