Skip to content

Commit

Permalink
JavaScript (v3): Use @smithy namespace for internal packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpyle0819 authored and rlhagerm committed Aug 10, 2023
1 parent 87a3e96 commit b68d298
Show file tree
Hide file tree
Showing 15 changed files with 219 additions and 68 deletions.
6 changes: 3 additions & 3 deletions javascriptv3/example_code/eventbridge/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"repository": "git@github.com/awsdocs/aws-doc-sdk-examples/tree/master/javascriptv3/example_code/eventbridge.git",
"author": "Brian Murray <brmur@amazon.com>",
"license": "Apache 2.0",
"type": "module",
"dependencies": {
"@aws-sdk/eventbridge": "^3.32.0"
},
"type": "module"
"@aws-sdk/client-eventbridge": "^3.387.0"
}
}
3 changes: 1 addition & 2 deletions javascriptv3/example_code/eventbridge/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"author": "Brian Murray <brmur@amazon.com>, Alex Forsyth <alex-git@amazon.com>",
"license": "Apache 2.0",
"dependencies": {
"@aws-sdk/eventbridge": "^3.32.0",
"@aws-sdk/node-http-handler": "^3.32.0"
"@aws-sdk/client-eventbridge": "^3.387.0"
},
"devDependencies": {
"@babel/preset-env": "^7.14.4",
Expand Down
1 change: 0 additions & 1 deletion javascriptv3/example_code/glacier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"license": "Apache 2.0",
"dependencies": {
"@aws-sdk/client-glacier": "^3.32.0",
"@aws-sdk/node-http-handler": "^3.32.0",
"@aws-sdk/types": "^3.32.0"
},
"devDependencies": {
Expand Down
9 changes: 4 additions & 5 deletions javascriptv3/example_code/kinesis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@
"license": "Apache 2.0",
"dependencies": {
"@aws-sdk/client-cognito-identity": "^3.32.0",
"@aws-sdk/credential-provider-cognito-identity": "^3.32.0",
"@aws-sdk/client-kinesis": "^3.32.0",
"@aws-sdk/node-http-handler": "^3.32.0",
"@aws-sdk/credential-provider-cognito-identity": "^3.32.0",
"@aws-sdk/types": "^3.32.0"
},
"devDependencies": {
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11",
"@aws-sdk/types": "^3.32.0",
"@types/node": "^14.0.23"
"@types/node": "^14.0.23",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11"
},
"module": "type"
}
5 changes: 2 additions & 3 deletions javascriptv3/example_code/mediaconvert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
"license": "Apache 2.0",
"dependencies": {
"@aws-sdk/client-mediaconvert": "^3.32.0",
"@aws-sdk/node-http-handler": "^3.32.0",
"@aws-sdk/types": "^3.32.0",
"node-fetch": "^2.6",
"jest": "^26.6.3"
"jest": "^26.6.3",
"node-fetch": "^2.6"
},
"devDependencies": {
"@types/node": "^14.0.23",
Expand Down
1 change: 0 additions & 1 deletion javascriptv3/example_code/nodegetstarted/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"main": "index.js",
"dependencies": {
"@aws-sdk/client-s3": "^3.32.0",
"@aws-sdk/node-http-handler": "^3.32.0",
"@aws-sdk/types": "^3.32.0"
},
"devDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions javascriptv3/example_code/personalize/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"@aws-sdk/client-personalize-events": "^3.51.0",
"@aws-sdk/client-personalize-runtime": "^3.51.0",
"dotenv": "^16.0.0",
"fs": "^0.0.1-security",
"@aws-sdk/node-http-handler": "^3.32.0"
"fs": "^0.0.1-security"
},
"devDependencies": {
"@babel/preset-env": "^7.14.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"license": "Apache 2.0",
"dependencies": {
"@aws-sdk/client-polly": "^3.32.0",
"@aws-sdk/node-http-handler": "^3.32.0",
"@aws-sdk/types": "^3.32.0"
},
"devDependencies": {
Expand Down
7 changes: 3 additions & 4 deletions javascriptv3/example_code/polly/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
"author": "Brian Murray <brmur@amazon.com>, Alex Forsyth <alex-git@amazon.com>",
"license": "Apache 2.0",
"scripts": {
"run":"webpack src/polly.js --mode development --libraryTarget commonjs2 --target web --devtool false -o src/dist/main.js"
"run": "webpack src/polly.js --mode development --libraryTarget commonjs2 --target web --devtool false -o src/dist/main.js"
},
"dependencies": {
"@aws-sdk/client-cognito-identity": "^3.32.0",
"@aws-sdk/credential-provider-cognito-identity": "^3.32.0",
"@aws-sdk/client-polly": "^3.32.0",
"@aws-sdk/polly-request-presigner": "^3.32.0",
"@aws-sdk/node-http-handler": "^3.32.0"
"@aws-sdk/credential-provider-cognito-identity": "^3.32.0",
"@aws-sdk/polly-request-presigner": "^3.32.0"
},
"devDependencies": {
"webpack": "^4.42.0",
Expand Down
1 change: 0 additions & 1 deletion javascriptv3/example_code/redshift/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"license": "Apache 2.0",
"dependencies": {
"@aws-sdk/client-redshift": "^3.32.0",
"@aws-sdk/node-http-handler": "^3.32.0",
"@aws-sdk/types": "^3.32.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
"author": "Brian Murray <brmur@amazon.com>",
"license": "Apache 2.0",
"dependencies": {
"@aws-sdk/client-cognito-identity": "^3.32.0",
"@aws-sdk/client-rekognition": "^3.32.0",
"@aws-sdk/node-http-handler": "^3.32.0",
"@aws-sdk/credential-provider-cognito-identity": "^3.32.0",
"@aws-sdk/client-cognito-identity": "^3.32.0",
"uuid": "^8.3.2",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11"
Expand Down
6 changes: 3 additions & 3 deletions javascriptv3/example_code/s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"@aws-crypto/sha256-browser": "^4.0.0",
"@aws-sdk/client-s3": "^3.272.0",
"@aws-sdk/credential-providers": "^3.276.0",
"@aws-sdk/hash-node": "^3.272.0",
"@aws-sdk/protocol-http": "^3.272.0",
"@aws-sdk/s3-request-presigner": "^3.276.0",
"@aws-sdk/url-parser": "^3.272.0",
"@aws-sdk/util-format-url": "^3.272.0",
"@smithy/hash-node": "^2.0.2",
"@smithy/protocol-http": "^2.0.2",
"@smithy/url-parser": "^2.0.2",
"libs": "*"
},
"devDependencies": {
Expand Down
29 changes: 13 additions & 16 deletions javascriptv3/example_code/s3/scenarios/presigned-url-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { fileURLToPath } from "url";
import {fileURLToPath} from "url";

// snippet-start:[s3.JavaScript.buckets.getpresignedurlv3]
import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3";
import { fromIni } from "@aws-sdk/credential-providers";
import { HttpRequest } from "@aws-sdk/protocol-http";
import {
getSignedUrl,
S3RequestPresigner,
} from "@aws-sdk/s3-request-presigner";
import { parseUrl } from "@aws-sdk/url-parser";
import { formatUrl } from "@aws-sdk/util-format-url";
import { Hash } from "@aws-sdk/hash-node";
import {GetObjectCommand, S3Client} from "@aws-sdk/client-s3";
import {fromIni} from "@aws-sdk/credential-providers";
import {HttpRequest} from "@smithy/protocol-http";
import {getSignedUrl, S3RequestPresigner} from "@aws-sdk/s3-request-presigner";
import {parseUrl} from "@smithy/url-parser";
import {formatUrl} from "@aws-sdk/util-format-url";
import {Hash} from "@smithy/hash-node";

const createPresignedUrlWithoutClient = async ({ region, bucket, key }) => {
const createPresignedUrlWithoutClient = async ({region, bucket, key}) => {
const url = parseUrl(`https://${bucket}.s3.${region}.amazonaws.com/${key}`);
const presigner = new S3RequestPresigner({
credentials: fromIni(),
Expand All @@ -29,10 +26,10 @@ const createPresignedUrlWithoutClient = async ({ region, bucket, key }) => {
return formatUrl(signedUrlObject);
};

const createPresignedUrlWithClient = ({ region, bucket, key }) => {
const client = new S3Client({ region });
const command = new GetObjectCommand({ Bucket: bucket, Key: key });
return getSignedUrl(client, command, { expiresIn: 3600 });
const createPresignedUrlWithClient = ({region, bucket, key}) => {
const client = new S3Client({region});
const command = new GetObjectCommand({Bucket: bucket, Key: key});
return getSignedUrl(client, command, {expiresIn: 3600});
};

export const main = async () => {
Expand Down
33 changes: 15 additions & 18 deletions javascriptv3/example_code/s3/scenarios/presigned-url-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { fileURLToPath } from "url";
import {fileURLToPath} from "url";

// snippet-start:[s3.JavaScript.buckets.presignedurlv3]
import https from "https";
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
import { fromIni } from "@aws-sdk/credential-providers";
import { HttpRequest } from "@aws-sdk/protocol-http";
import {
getSignedUrl,
S3RequestPresigner,
} from "@aws-sdk/s3-request-presigner";
import { parseUrl } from "@aws-sdk/url-parser";
import { formatUrl } from "@aws-sdk/util-format-url";
import { Hash } from "@aws-sdk/hash-node";
import {PutObjectCommand, S3Client} from "@aws-sdk/client-s3";
import {fromIni} from "@aws-sdk/credential-providers";
import {HttpRequest} from "@smithy/protocol-http";
import {getSignedUrl, S3RequestPresigner} from "@aws-sdk/s3-request-presigner";
import {parseUrl} from "@smithy/url-parser";
import {formatUrl} from "@aws-sdk/util-format-url";
import {Hash} from "@smithy/hash-node";

const createPresignedUrlWithoutClient = async ({ region, bucket, key }) => {
const createPresignedUrlWithoutClient = async ({region, bucket, key}) => {
const url = parseUrl(`https://${bucket}.s3.${region}.amazonaws.com/${key}`);
const presigner = new S3RequestPresigner({
credentials: fromIni(),
Expand All @@ -27,22 +24,22 @@ const createPresignedUrlWithoutClient = async ({ region, bucket, key }) => {
});

const signedUrlObject = await presigner.presign(
new HttpRequest({ ...url, method: "PUT" })
new HttpRequest({...url, method: "PUT"})
);
return formatUrl(signedUrlObject);
};

const createPresignedUrlWithClient = ({ region, bucket, key }) => {
const client = new S3Client({ region });
const command = new PutObjectCommand({ Bucket: bucket, Key: key });
return getSignedUrl(client, command, { expiresIn: 3600 });
const createPresignedUrlWithClient = ({region, bucket, key}) => {
const client = new S3Client({region});
const command = new PutObjectCommand({Bucket: bucket, Key: key});
return getSignedUrl(client, command, {expiresIn: 3600});
};

function put(url, data) {
return new Promise((resolve, reject) => {
const req = https.request(
url,
{ method: "PUT", headers: { "Content-Length": new Blob([data]).size } },
{method: "PUT", headers: {"Content-Length": new Blob([data]).size}},
(res) => {
let responseBody = "";
res.on("data", (chunk) => {
Expand Down
Loading

0 comments on commit b68d298

Please sign in to comment.