@stacksjs/ts-cloud 0.2.17 → 0.2.19

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.
Files changed (3) hide show
  1. package/dist/bin/cli.js +151 -151
  2. package/dist/index.js +15 -10
  3. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -2041,12 +2041,13 @@ class S3Client2 {
2041
2041
  headers[`x-amz-meta-${key}`] = value;
2042
2042
  }
2043
2043
  }
2044
+ const encodedKey = options.key.split("/").map((seg) => encodeURIComponent(seg)).join("/");
2044
2045
  const normalizedBody = options.body instanceof Uint8Array && !Buffer.isBuffer(options.body) ? Buffer.from(options.body) : options.body;
2045
2046
  if (Buffer.isBuffer(normalizedBody) || normalizedBody instanceof Uint8Array) {
2046
2047
  const binaryBody = Buffer.isBuffer(normalizedBody) ? normalizedBody : Buffer.from(normalizedBody);
2047
2048
  const { accessKeyId, secretAccessKey, sessionToken } = this.getCredentials();
2048
2049
  const host = this.s3VirtualHost(options.bucket);
2049
- const url = `https://${host}/${options.key}`;
2050
+ const url = `https://${host}/${encodedKey}`;
2050
2051
  const now = new Date;
2051
2052
  const amzDate = now.toISOString().replace(/[:-]|\.\d{3}/g, "");
2052
2053
  const dateStamp = now.toISOString().slice(0, 10).replace(/-/g, "");
@@ -2065,7 +2066,7 @@ class S3Client2 {
2065
2066
  const signedHeaders = Object.keys(requestHeaders).sort().map((key) => key.toLowerCase()).join(";");
2066
2067
  const canonicalRequest = [
2067
2068
  "PUT",
2068
- `/${options.key}`,
2069
+ `/${encodedKey}`,
2069
2070
  "",
2070
2071
  canonicalHeaders,
2071
2072
  signedHeaders,
@@ -2105,18 +2106,19 @@ class S3Client2 {
2105
2106
  service: "s3",
2106
2107
  region: this.region,
2107
2108
  method: "PUT",
2108
- path: `/${options.key}`,
2109
+ path: `/${encodedKey}`,
2109
2110
  bucket: options.bucket,
2110
2111
  headers,
2111
2112
  body: options.body
2112
2113
  });
2113
2114
  }
2114
2115
  async getObject(bucket, key) {
2116
+ const encodedKey = key.split("/").map((seg) => encodeURIComponent(seg)).join("/");
2115
2117
  const result = await this.client.request({
2116
2118
  service: "s3",
2117
2119
  region: this.region,
2118
2120
  method: "GET",
2119
- path: `/${bucket}/${key}`,
2121
+ path: `/${bucket}/${encodedKey}`,
2120
2122
  rawResponse: true
2121
2123
  });
2122
2124
  return result;
@@ -2145,11 +2147,12 @@ class S3Client2 {
2145
2147
  });
2146
2148
  }
2147
2149
  async deleteObject(bucket, key) {
2150
+ const encodedKey = key.split("/").map((seg) => encodeURIComponent(seg)).join("/");
2148
2151
  await this.client.request({
2149
2152
  service: "s3",
2150
2153
  region: this.region,
2151
2154
  method: "DELETE",
2152
- path: `/${bucket}/${key}`
2155
+ path: `/${bucket}/${encodedKey}`
2153
2156
  });
2154
2157
  }
2155
2158
  async deleteObjects(bucket, keys) {
@@ -3009,6 +3012,7 @@ class S3Client2 {
3009
3012
  const dateStamp = now.toISOString().slice(0, 10).replace(/-/g, "");
3010
3013
  const credentialScope = `${dateStamp}/${this.region}/s3/aws4_request`;
3011
3014
  const credential = `${accessKeyId}/${credentialScope}`;
3015
+ const encodedKey = key.split("/").map((seg) => encodeURIComponent(seg)).join("/");
3012
3016
  const queryParams = new URLSearchParams({
3013
3017
  "X-Amz-Algorithm": "AWS4-HMAC-SHA256",
3014
3018
  "X-Amz-Credential": credential,
@@ -3018,7 +3022,7 @@ class S3Client2 {
3018
3022
  });
3019
3023
  const canonicalRequest = [
3020
3024
  "GET",
3021
- `/${key}`,
3025
+ `/${encodedKey}`,
3022
3026
  queryParams.toString(),
3023
3027
  `host:${host}
3024
3028
  `,
@@ -3039,7 +3043,7 @@ class S3Client2 {
3039
3043
  const kSigning = crypto3.createHmac("sha256", kService).update("aws4_request").digest();
3040
3044
  const signature = crypto3.createHmac("sha256", kSigning).update(stringToSign).digest("hex");
3041
3045
  queryParams.append("X-Amz-Signature", signature);
3042
- return `https://${host}/${key}?${queryParams.toString()}`;
3046
+ return `https://${host}/${encodedKey}?${queryParams.toString()}`;
3043
3047
  }
3044
3048
  generatePresignedPutUrl(bucket, key, contentType, expiresInSeconds = 3600) {
3045
3049
  const { accessKeyId, secretAccessKey } = this.getCredentials();
@@ -3049,6 +3053,7 @@ class S3Client2 {
3049
3053
  const dateStamp = now.toISOString().slice(0, 10).replace(/-/g, "");
3050
3054
  const credentialScope = `${dateStamp}/${this.region}/s3/aws4_request`;
3051
3055
  const credential = `${accessKeyId}/${credentialScope}`;
3056
+ const encodedKey = key.split("/").map((seg) => encodeURIComponent(seg)).join("/");
3052
3057
  const queryParams = new URLSearchParams({
3053
3058
  "X-Amz-Algorithm": "AWS4-HMAC-SHA256",
3054
3059
  "X-Amz-Credential": credential,
@@ -3058,7 +3063,7 @@ class S3Client2 {
3058
3063
  });
3059
3064
  const canonicalRequest = [
3060
3065
  "PUT",
3061
- `/${key}`,
3066
+ `/${encodedKey}`,
3062
3067
  queryParams.toString(),
3063
3068
  `content-type:${contentType}
3064
3069
  host:${host}
@@ -3080,7 +3085,7 @@ host:${host}
3080
3085
  const kSigning = crypto3.createHmac("sha256", kService).update("aws4_request").digest();
3081
3086
  const signature = crypto3.createHmac("sha256", kSigning).update(stringToSign).digest("hex");
3082
3087
  queryParams.append("X-Amz-Signature", signature);
3083
- return `https://${host}/${key}?${queryParams.toString()}`;
3088
+ return `https://${host}/${encodedKey}?${queryParams.toString()}`;
3084
3089
  }
3085
3090
  async createMultipartUpload(bucket, key, options) {
3086
3091
  const headers = {};
@@ -3275,7 +3280,7 @@ host:${host}
3275
3280
  }
3276
3281
  const sortedParams = Object.keys(queryParams).sort();
3277
3282
  const canonicalQuerystring = sortedParams.map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(queryParams[k])}`).join("&");
3278
- const canonicalUri = "/" + key;
3283
+ const canonicalUri = "/" + key.split("/").map((seg) => encodeURIComponent(seg)).join("/");
3279
3284
  const canonicalHeaders = `host:${host}
3280
3285
  `;
3281
3286
  const signedHeaders = "host";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/ts-cloud",
3
3
  "type": "module",
4
- "version": "0.2.17",
4
+ "version": "0.2.19",
5
5
  "description": "A lightweight, performant infrastructure-as-code library and CLI for deploying both server-based (EC2) and serverless applications.",
6
6
  "author": "Chris Breuer <chris@stacksjs.com>",
7
7
  "license": "MIT",
@@ -89,8 +89,8 @@
89
89
  "test": "bun test"
90
90
  },
91
91
  "dependencies": {
92
- "@ts-cloud/aws-types": "0.2.17",
93
- "@ts-cloud/core": "0.2.17",
92
+ "@ts-cloud/aws-types": "0.2.19",
93
+ "@ts-cloud/core": "0.2.19",
94
94
  "@stacksjs/ts-xml": "^0.1.0"
95
95
  },
96
96
  "devDependencies": {