Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(clients): import fromBase64 and toBase64 from util-base64 #4140

Merged
merged 2 commits into from
Nov 3, 2022

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Nov 2, 2022

Issue

Internal JS-3705
PR which adds util-base64 package #4137

Description

Imports fromBase64 and toBase64 from util-base64

Testing

The flexible checksums implementation was tested on Node.js and browser using aws-sdk-js-tests

Packed a tarball to be used for testing

$ client-s3> yarn build
...
Done in 3.89s.

$ client-s3> npm pack
...
aws-sdk-client-s3-3.202.0.tgz

Verified that flexible checksums works on Node.js and Browser runtimes with packed tarball.

$ aws-sdk-js-tests/packages/utils> yarn add ~/Downloads/aws-sdk-client-s3-3.202.0.tgz
...
➤ YN0000: Done with warnings in 7s 249ms

$ aws-sdk-js-tests/packages/utils> yarn add @aws-sdk/middleware-flexible-checksums
...
➤ YN0000: Done with warnings in 1s 398ms

$ aws-sdk-js-tests> git diff packages/utils/src/utils.js
diff --git a/packages/utils/src/utils.js b/packages/utils/src/utils.js
index 76eace2..da757be 100644
--- a/packages/utils/src/utils.js
+++ b/packages/utils/src/utils.js
@@ -2,7 +2,8 @@ import AWS from "aws-sdk";
 
 import { fromCognitoIdentityPool } from "@aws-sdk/credential-provider-cognito-identity";
 import { CognitoIdentityClient } from "@aws-sdk/client-cognito-identity";
-import { DynamoDB } from "@aws-sdk/client-dynamodb";
+import { S3 } from "@aws-sdk/client-s3";
+import { ChecksumAlgorithm } from "@aws-sdk/middleware-flexible-checksums";
 
 import { REGION, IDENTITY_POOL_ID } from "./config.js";
 
@@ -12,8 +13,41 @@ export const getV2Response = async (clientParams) => {
 };
 
 export const getV3Response = async (clientParams) => {
-  const client = new DynamoDB(clientParams);
-  return client.listTables({});
+  const client = new S3(clientParams);
+  const Bucket = "test-util-base64";
+  const Body = "Hello World";
+
+  const checksumAlgos = [
+    ChecksumAlgorithm.CRC32,
+    ChecksumAlgorithm.CRC32C,
+    ChecksumAlgorithm.SHA1,
+    ChecksumAlgorithm.SHA256,
+  ];
+
+  for (const checksumAlgo of checksumAlgos) {
+    await client.putObject({
+      Bucket,
+      Key: checksumAlgo,
+      Body,
+      ChecksumAlgorithm: checksumAlgo,
+    });
+  }
+
+  for (const checksumAlgo of checksumAlgos) {
+    const response = await client.getObject({
+      Bucket,
+      Key: checksumAlgo,
+      ChecksumMode: "ENABLED",
+    });
+    const bodyAsString = await response.Body.transformToString();
+    console.log({ checksumAlgo, bodyAsString });
+    await client.deleteObject({
+      Bucket,
+      Key: checksumAlgo,
+    });
+  }
+
+  return client.listObjects({ Bucket });
 };
 
 export const getV2BrowserResponse = async () => {
...

$ aws-sdk-js-tests> yarn start:node
...
{ checksumAlgo: 'CRC32', bodyAsString: 'Hello World' }
{ checksumAlgo: 'CRC32C', bodyAsString: 'Hello World' }
{ checksumAlgo: 'SHA1', bodyAsString: 'Hello World' }
{ checksumAlgo: 'SHA256', bodyAsString: 'Hello World' }
...

$ aws-sdk-js-tests> yarn start:web
# screenshot from browser console shared
Browser console screenshot

util-base64-browser-console-screenshot

Verified from Development build of vite, that base64Decoder and base64Encoder are not set in browser and node runtimeConfigs

build steps
$ aws-sdk-js-tests/packages/web> yarn vite build --mode development
vite v3.1.4 building for development...
✓ 1801 modules transformed.
dist/index.html                 0.48 KiB
dist/assets/index.392bf774.js   3599.02 KiB / gzip: 521.63 KiB
...
Screenshots

The base64Decoder and base64Encoder are not set in runtimeConfig.browser.ts
runtimeConfig-browser

The base64Decoder and base64Encoder are set in runtimeConfig.shared.ts
runtimeConfig-shared

Additional Context

smithy-ts smithy-lang/smithy-typescript#627


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Base automatically changed from util-base64 to main November 2, 2022 17:26
@trivikr trivikr force-pushed the clients-util-base64 branch from 2ed1bb6 to 4182f82 Compare November 2, 2022 17:38
@trivikr trivikr changed the title chore(clients): import fromUtf8 and toUtf8 from util-base64 chore(clients): import fromBase64 and toBase64 from util-base64 Nov 2, 2022
@trivikr
Copy link
Member Author

trivikr commented Nov 3, 2022

As an added step, I added console.log in transpiled code, and verified that code from dist-es/*.browser.js is called:

Code
$ aws-sdk-js-tests> grep -rnI console.log node_modules/@aws-sdk/util-base64/
node_modules/@aws-sdk/util-base64//dist-es/fromBase64.browser.js:3:    console.log("es.fromBase64.browser", input);
node_modules/@aws-sdk/util-base64//dist-es/fromBase64.js:4:    console.log("es.fromBase64.node", input);
node_modules/@aws-sdk/util-base64//dist-es/toBase64.browser.js:3:    console.log("es.toBase64.browser", input);
node_modules/@aws-sdk/util-base64//dist-es/toBase64.js:3:  console.log("es.toBase64.node", input);
node_modules/@aws-sdk/util-base64//dist-cjs/fromBase64.browser.js:6:    console.log("cjs.fromBase64.browser", input);
node_modules/@aws-sdk/util-base64//dist-cjs/fromBase64.js:7:    console.log("cjs.fromBase64.node", input);
node_modules/@aws-sdk/util-base64//dist-cjs/toBase64.browser.js:6:    console.log("cjs.toBase64.browser", input);
node_modules/@aws-sdk/util-base64//dist-cjs/toBase64.js:6:    console.log("cjs.toBase64.node", input);
Screenshot

browser-console-es-browser

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants