@oino-ts/blob-aws 1.0.5 → 1.0.7

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.
@@ -38,6 +38,7 @@ const blob_1 = require("@oino-ts/blob");
38
38
  * })
39
39
  * ```
40
40
  */
41
+ const BLOB_S3_UNSAFE_CHARS_REGEX = /[\x00-\x1f\x7f\\{}[\]^`|<>#%]/g;
41
42
  class OINOBlobAwsS3 extends blob_1.OINOBlob {
42
43
  _s3Client = null;
43
44
  constructor(params) {
@@ -46,6 +47,14 @@ class OINOBlobAwsS3 extends blob_1.OINOBlob {
46
47
  throw new Error("OINOBlobAwsS3: missing or invalid credentials (provide region, accessKeyId, secretAccessKey)");
47
48
  }
48
49
  }
50
+ /**
51
+ * Replace characters that are unsafe in S3 object key names
52
+ * (`\`, control characters, and shell/URL-special characters
53
+ * `{`, `}`, `[`, `]`, `^`, `` ` ``, `|`, `<`, `>`, `#`, `%`) with `_`.
54
+ */
55
+ sanitizeName(name) {
56
+ return name.replace(BLOB_S3_UNSAFE_CHARS_REGEX, "_");
57
+ }
49
58
  /**
50
59
  * Initialise the AWS SDK S3 client from the JSON-encoded `connectionStr`.
51
60
  * Does not perform any network call.
@@ -35,6 +35,7 @@ import { OINOBlob, OINOBlobDataModel } from "@oino-ts/blob";
35
35
  * })
36
36
  * ```
37
37
  */
38
+ const BLOB_S3_UNSAFE_CHARS_REGEX = /[\x00-\x1f\x7f\\{}[\]^`|<>#%]/g;
38
39
  export class OINOBlobAwsS3 extends OINOBlob {
39
40
  _s3Client = null;
40
41
  constructor(params) {
@@ -43,6 +44,14 @@ export class OINOBlobAwsS3 extends OINOBlob {
43
44
  throw new Error("OINOBlobAwsS3: missing or invalid credentials (provide region, accessKeyId, secretAccessKey)");
44
45
  }
45
46
  }
47
+ /**
48
+ * Replace characters that are unsafe in S3 object key names
49
+ * (`\`, control characters, and shell/URL-special characters
50
+ * `{`, `}`, `[`, `]`, `^`, `` ` ``, `|`, `<`, `>`, `#`, `%`) with `_`.
51
+ */
52
+ sanitizeName(name) {
53
+ return name.replace(BLOB_S3_UNSAFE_CHARS_REGEX, "_");
54
+ }
46
55
  /**
47
56
  * Initialise the AWS SDK S3 client from the JSON-encoded `connectionStr`.
48
57
  * Does not perform any network call.
@@ -1,37 +1,14 @@
1
1
  import { OINOApi, OINOResult, OINOQueryFilter } from "@oino-ts/common";
2
2
  import { OINOBlob, OINOBlobParams, type OINOBlobEntry, type OINOBlobFetchResult } from "@oino-ts/blob";
3
- /**
4
- * AWS S3 (and S3-compatible) implementation of `OINOBlob`.
5
- *
6
- * Authenticates using static access key credentials supplied via a JSON-encoded
7
- * connection string. Connection parameters map as:
8
- * - `params.url` → optional custom endpoint, e.g. `https://s3.eu-west-1.amazonaws.com`
9
- * or a compatible service such as MinIO / Cloudflare R2
10
- * - `params.container` → S3 bucket name
11
- * - `params.connectionStr` → JSON string: `{"region":"…","accessKeyId":"…","secretAccessKey":"…"}`
12
- *
13
- * Register and use via the factory:
14
- * ```ts
15
- * import { OINOBlobFactory } from "@oino-ts/blob"
16
- * import { OINOBlobAwsS3 } from "@oino-ts/blob-aws"
17
- *
18
- * OINOBlobFactory.registerBlob("OINOBlobAwsS3", OINOBlobAwsS3)
19
- *
20
- * const blob = await OINOBlobFactory.createBlob({
21
- * type: "OINOBlobAwsS3",
22
- * url: "", // leave empty for default AWS endpoint
23
- * container: "my-bucket",
24
- * connectionStr: JSON.stringify({
25
- * region: "us-east-1",
26
- * accessKeyId: process.env.AWS_ACCESS_KEY_ID,
27
- * secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
28
- * })
29
- * })
30
- * ```
31
- */
32
3
  export declare class OINOBlobAwsS3 extends OINOBlob {
33
4
  private _s3Client;
34
5
  constructor(params: OINOBlobParams);
6
+ /**
7
+ * Replace characters that are unsafe in S3 object key names
8
+ * (`\`, control characters, and shell/URL-special characters
9
+ * `{`, `}`, `[`, `]`, `^`, `` ` ``, `|`, `<`, `>`, `#`, `%`) with `_`.
10
+ */
11
+ sanitizeName(name: string): string;
35
12
  /**
36
13
  * Initialise the AWS SDK S3 client from the JSON-encoded `connectionStr`.
37
14
  * 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.5",
3
+ "version": "1.0.7",
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.5",
26
- "@oino-ts/common": "1.0.5"
25
+ "@oino-ts/blob": "1.0.7",
26
+ "@oino-ts/common": "1.0.7"
27
27
  },
28
28
  "devDependencies": {
29
- "@oino-ts/types": "1.0.5",
29
+ "@oino-ts/types": "1.0.7",
30
30
  "@types/bun": "^1.1.14",
31
31
  "@types/node": "^22.0.00",
32
32
  "typescript": "~5.9.0"
@@ -45,6 +45,8 @@ import { OINOBlob, OINOBlobParams, OINOBlobDataModel, OINOBlobApi, type OINOBlob
45
45
  * })
46
46
  * ```
47
47
  */
48
+ const BLOB_S3_UNSAFE_CHARS_REGEX = /[\x00-\x1f\x7f\\{}[\]^`|<>#%]/g
49
+
48
50
  export class OINOBlobAwsS3 extends OINOBlob {
49
51
  private _s3Client: S3Client | null = null
50
52
 
@@ -55,6 +57,15 @@ export class OINOBlobAwsS3 extends OINOBlob {
55
57
  }
56
58
  }
57
59
 
60
+ /**
61
+ * Replace characters that are unsafe in S3 object key names
62
+ * (`\`, control characters, and shell/URL-special characters
63
+ * `{`, `}`, `[`, `]`, `^`, `` ` ``, `|`, `<`, `>`, `#`, `%`) with `_`.
64
+ */
65
+ override sanitizeName(name: string): string {
66
+ return name.replace(BLOB_S3_UNSAFE_CHARS_REGEX, "_")
67
+ }
68
+
58
69
  /**
59
70
  * Initialise the AWS SDK S3 client from the JSON-encoded `connectionStr`.
60
71
  * Does not perform any network call.